From d058083c5a822bd5484d2e62f27735aed82f3f5e Mon Sep 17 00:00:00 2001 From: ksagiyam <46749170+ksagiyam@users.noreply.github.com> Date: Wed, 8 May 2024 16:15:59 +0100 Subject: [PATCH] hex: allow for Real function space (#3549) --- firedrake/functionspaceimpl.py | 4 ++-- tests/regression/test_real_space.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/firedrake/functionspaceimpl.py b/firedrake/functionspaceimpl.py index 5308cf4cdf..f97afd857c 100644 --- a/firedrake/functionspaceimpl.py +++ b/firedrake/functionspaceimpl.py @@ -50,8 +50,8 @@ def check_element(element, top=True): If the element is illegal. """ if element.cell.cellname() == "hexahedron" and \ - element.family() not in ["Q", "DQ"]: - raise NotImplementedError("Currently can only use 'Q' and/or 'DQ' elements on hexahedral meshes, not", element.family()) + element.family() not in ["Q", "DQ", "Real"]: + raise NotImplementedError("Currently can only use 'Q', 'DQ', and/or 'Real' elements on hexahedral meshes, not", element.family()) if type(element) in (finat.ufl.BrokenElement, finat.ufl.RestrictedElement, finat.ufl.HDivElement, finat.ufl.HCurlElement): inner = (element._element, ) diff --git a/tests/regression/test_real_space.py b/tests/regression/test_real_space.py index 9f66349f1d..bc796f4ba4 100644 --- a/tests/regression/test_real_space.py +++ b/tests/regression/test_real_space.py @@ -301,3 +301,17 @@ def test_real_interpolate(): R = FunctionSpace(mesh, "R", 0) a_int = assemble(interpolate(Constant(1.0), R)) assert np.allclose(float(a_int), 1.0) + + +def test_real_space_hex(): + mesh = BoxMesh(2, 1, 1, 2., 1., 1., hexahedral=True) + DG = FunctionSpace(mesh, "DQ", 0) + R = FunctionSpace(mesh, "R", 0) + dg = Function(DG).assign(1.) + r = Function(R).assign(1.) + val = assemble(r * dx) + assert abs(val - 2.) < 1.e-14 + val = assemble(inner(dg, TestFunction(R)) * dx) + assert np.allclose(val.dat.data_ro, [2.]) + val = assemble(inner(r, TestFunction(DG)) * dx) + assert np.allclose(val.dat.data, [1., 1.])