Skip to content

Commit

Permalink
Fix complex mode tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgensd committed Oct 19, 2024
1 parent 71eee1e commit 4298710
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion tests/test_point_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_midpoint():
"quadrature_rule": "custom",
},
)
ref_L = dolfinx.fem.form(v / abs(ufl.JacobianDeterminant(mesh)) * dx)
ref_L = dolfinx.fem.form(ufl.conj(v) / abs(ufl.JacobianDeterminant(mesh)) * dx)
dolfinx.fem.assemble_vector(b_ref.x.array, ref_L)
b_ref.x.scatter_reverse(dolfinx.la.InsertMode.add)
b_ref.x.scatter_forward()
Expand Down
24 changes: 13 additions & 11 deletions tests/test_real_functionspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ def test_real_function_space_vector(cell_type, dtype):
assert num_local_rows == 0


@pytest.mark.parametrize("dtype", [PETSc.RealType])
@pytest.mark.parametrize("dtype", [(PETSc.RealType, PETSc.ScalarType)])
@pytest.mark.parametrize("tensor", [0, 1, 2])
@pytest.mark.parametrize("degree", range(1, 5))
def test_singular_poisson(tensor, degree, dtype):
M = 25

rtype, stype = dtype
mesh = dolfinx.mesh.create_unit_square(
MPI.COMM_WORLD, M, M, dolfinx.mesh.CellType.triangle, dtype=dtype
MPI.COMM_WORLD, M, M, dolfinx.mesh.CellType.triangle, dtype=rtype
)

if tensor == 0:
Expand All @@ -106,15 +108,15 @@ def test_singular_poisson(tensor, degree, dtype):
pol = x[0] ** degree - 2 * x[1] ** degree
# Compute average value of polynomial to make mean 0
C = mesh.comm.allreduce(
dolfinx.fem.assemble_scalar(dolfinx.fem.form(pol * ufl.dx, dtype=dtype)), op=MPI.SUM
dolfinx.fem.assemble_scalar(dolfinx.fem.form(pol * ufl.dx, dtype=stype)), op=MPI.SUM
)
u_scalar = pol - dolfinx.fem.Constant(mesh, dtype(C))
u_scalar = pol - dolfinx.fem.Constant(mesh, stype(C))
if tensor == 0:
u_ex = u_scalar
zero = dolfinx.fem.Constant(mesh, dtype(0.0))
zero = dolfinx.fem.Constant(mesh, stype(0.0))
elif tensor == 1:
u_ex = ufl.as_vector([u_scalar, -u_scalar])
zero = dolfinx.fem.Constant(mesh, dtype((0.0, 0.0)))
zero = dolfinx.fem.Constant(mesh, stype((0.0, 0.0)))
else:
u_ex = ufl.as_tensor(
[
Expand All @@ -123,7 +125,7 @@ def test_singular_poisson(tensor, degree, dtype):
[u_scalar, 2 * u_scalar],
]
)
zero = dolfinx.fem.Constant(mesh, dtype(((0.0, 0.0), (0.0, 0.0), (0.0, 0.0))))
zero = dolfinx.fem.Constant(mesh, stype(((0.0, 0.0), (0.0, 0.0), (0.0, 0.0))))

dx = ufl.Measure("dx", domain=mesh)
f = -ufl.div(ufl.grad(u_ex))
Expand All @@ -136,8 +138,8 @@ def test_singular_poisson(tensor, degree, dtype):
L0 = ufl.inner(f, v) * dx + ufl.inner(g, v) * ufl.ds
L1 = ufl.inner(zero, d) * dx

a = dolfinx.fem.form([[a00, a01], [a10, None]], dtype=dtype)
L = dolfinx.fem.form([L0, L1], dtype=dtype)
a = dolfinx.fem.form([[a00, a01], [a10, None]], dtype=stype)
L = dolfinx.fem.form([L0, L1], dtype=stype)

A = dolfinx.fem.petsc.assemble_matrix_block(a)
A.assemble()
Expand All @@ -164,10 +166,10 @@ def test_singular_poisson(tensor, degree, dtype):
uh.x.array[: len(x_local[0])] = x_local[0]
uh.x.scatter_forward()

error = dolfinx.fem.form(ufl.inner(u_ex - uh, u_ex - uh) * dx, dtype=dtype)
error = dolfinx.fem.form(ufl.inner(u_ex - uh, u_ex - uh) * dx, dtype=stype)

e_local = dolfinx.fem.assemble_scalar(error)
tol = 1e4 * np.finfo(dtype).eps
tol = 1e4 * np.finfo(stype).eps
e_global = np.sqrt(mesh.comm.allreduce(e_local, op=MPI.SUM))
assert np.isclose(e_global, 0, atol=tol)

Expand Down

0 comments on commit 4298710

Please sign in to comment.