Skip to content

Commit fda580f

Browse files
authored
TSFC: Dual evaluation for nodal EnrichedElement (#5184)
Enable xfailed H(div) and H(curl) tests
1 parent d27eded commit fda580f

3 files changed

Lines changed: 27 additions & 13 deletions

File tree

tests/firedrake/regression/test_interpolate.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,23 @@ def test_compound_expression():
175175
assert np.allclose(g.dat.data, h.dat.data)
176176

177177

178+
def test_restricted_extruded_interval():
179+
mesh = ExtrudedMesh(UnitIntervalMesh(1), 1)
180+
element = FiniteElement("Q", degree=4)
181+
VF = FunctionSpace(mesh, element["facet"])
182+
VI = FunctionSpace(mesh, element["interior"])
183+
uf = Function(VF)
184+
ui = Function(VI)
185+
186+
x = SpatialCoordinate(mesh)
187+
exprs = [Constant(1), x[0], x[1], x[0]*x[1]]
188+
189+
for expr in exprs:
190+
uf.interpolate(expr)
191+
ui.interpolate(expr)
192+
assert norm(expr - (uf + ui)) < 1E-12
193+
194+
178195
def test_hdiv_extruded_interval():
179196
mesh = ExtrudedMesh(UnitIntervalMesh(10), 10, 0.1)
180197
x = SpatialCoordinate(mesh)
@@ -209,8 +226,6 @@ def test_dpc_into_dq_extruded_interval():
209226
assert errornorm(u2, u1) < 1E-12
210227

211228

212-
# Requires the relevant FInAT or FIAT duals to be defined
213-
@pytest.mark.xfail(raises=NotImplementedError, reason="Requires the relevant FInAT or FIAT duals to be defined")
214229
def test_hdiv_2d():
215230
mesh = UnitCubedSphereMesh(2)
216231
x = SpatialCoordinate(mesh)
@@ -230,7 +245,6 @@ def test_hdiv_2d():
230245
assert np.allclose(g.dat.data, h.dat.data)
231246

232247

233-
@pytest.mark.xfail(raises=NotImplementedError, reason="Requires the relevant FInAT or FIAT duals to be defined")
234248
def test_hcurl_2d():
235249
mesh = UnitCubedSphereMesh(2)
236250
x = SpatialCoordinate(mesh)

tests/firedrake/vertexonly/test_interpolation_from_parent.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import numpy as np
44
from functools import reduce
55
from operator import add
6-
import subprocess
76

87

98
# Utility Functions and Fixtures
@@ -70,12 +69,9 @@ def fs(request):
7069
("N2curl", 2, FunctionSpace),
7170
("N1div", 2, FunctionSpace),
7271
("N2div", 2, FunctionSpace),
73-
pytest.param(("RTCE", 2, FunctionSpace),
74-
marks=pytest.mark.xfail(raises=(subprocess.CalledProcessError, NotImplementedError),
75-
reason="EnrichedElement dual basis not yet defined and FIAT duals don't have a point_dict")),
76-
pytest.param(("RTCF", 2, FunctionSpace),
77-
marks=pytest.mark.xfail(raises=(subprocess.CalledProcessError, NotImplementedError),
78-
reason="EnrichedElement dual basis not yet defined and FIAT duals don't have a point_dict"))],
72+
("RTCE", 2, FunctionSpace),
73+
("RTCF", 2, FunctionSpace),
74+
],
7975
ids=lambda x: f"{x[2].__name__}({x[0]}{x[1]})")
8076
def vfs(request, parentmesh):
8177
family = request.param[0]

tsfc/driver.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import time
33
import sys
44
from itertools import chain
5+
import numpy
56
from finat.physically_mapped import NeedsCoordinateMappingElement
67

78
import ufl
@@ -13,6 +14,7 @@
1314

1415
import gem
1516
import gem.impero_utils as impero_utils
17+
from gem.unconcatenate import unconcatenate
1618

1719
import finat
1820
from finat.element_factory import as_fiat_cell
@@ -367,13 +369,15 @@ def predicate(index):
367369
# Build kernel body
368370
return_indices = tuple(chain.from_iterable(argument_multiindices.values()))
369371
return_shape = tuple(i.extent for i in return_indices)
370-
return_var = gem.Variable('A', return_shape or (1,))
371-
return_expr = gem.Indexed(return_var, return_indices or (0,))
372+
return_var = gem.Variable('A', (numpy.prod(return_shape, dtype=int),))
373+
return_expr = gem.Indexed(gem.reshape(return_var, return_shape), return_indices)
374+
return_expr, = gem.optimise.remove_componenttensors([return_expr])
372375

373376
# TODO: one should apply some GEM optimisations as in assembly,
374377
# but we don't for now.
375378
evaluation, = impero_utils.preprocess_gem([evaluation])
376-
impero_c = impero_utils.compile_gem([(return_expr, evaluation)], return_indices)
379+
pairs = unconcatenate([(return_expr, evaluation)])
380+
impero_c = impero_utils.compile_gem(pairs, return_indices)
377381
index_names = {idx: f"p{i}" for (i, idx) in enumerate(basis_indices)}
378382
# Handle kernel interface requirements
379383
builder.register_requirements([evaluation])

0 commit comments

Comments
 (0)