|
| 1 | +import pytest |
| 2 | + |
| 3 | + |
| 4 | +@pytest.mark.mpi4py |
| 5 | +@pytest.mark.parametrize('nx', [16, 32]) |
| 6 | +@pytest.mark.parametrize('ny', [16, 32]) |
| 7 | +@pytest.mark.parametrize('nz', [0]) |
| 8 | +@pytest.mark.parametrize('f', [1, 3]) |
| 9 | +@pytest.mark.parametrize('direction', [0, 1, 10]) |
| 10 | +def test_derivative(nx, ny, nz, f, direction): |
| 11 | + from pySDC.implementations.problem_classes.generic_MPIFFT_Laplacian import IMEX_Laplacian_MPIFFT |
| 12 | + |
| 13 | + nvars = (nx, ny) |
| 14 | + if nz > 0: |
| 15 | + nvars.append(nz) |
| 16 | + prob = IMEX_Laplacian_MPIFFT(nvars=nvars) |
| 17 | + |
| 18 | + xp = prob.xp |
| 19 | + |
| 20 | + if direction == 0: |
| 21 | + u = xp.sin(f * prob.X[0]) |
| 22 | + du_expect = -(f**2) * xp.sin(f * prob.X[0]) |
| 23 | + elif direction == 1: |
| 24 | + u = xp.sin(f * prob.X[1]) |
| 25 | + du_expect = -(f**2) * xp.sin(f * prob.X[1]) |
| 26 | + elif direction == 10: |
| 27 | + u = xp.sin(f * prob.X[1]) + xp.cos(f * prob.X[0]) |
| 28 | + du_expect = -(f**2) * xp.sin(f * prob.X[1]) - f**2 * xp.cos(f * prob.X[0]) |
| 29 | + else: |
| 30 | + raise |
| 31 | + |
| 32 | + du = prob.eval_f(u, 0).impl |
| 33 | + assert xp.allclose(du, du_expect), 'Got unexpected derivative' |
| 34 | + |
| 35 | + _u = prob.solve_system(du, factor=1e8, u0=du, t=0) * -1e8 |
| 36 | + assert xp.allclose(_u, u, atol=1e-7), 'Got unexpected inverse derivative' |
| 37 | + |
| 38 | + |
| 39 | +if __name__ == '__main__': |
| 40 | + test_derivative(32, 32, 0, 1, 1) |
0 commit comments