Skip to content

Commit ed89971

Browse files
committed
Make clear if using manufactured coordinates coefficient
So that caller can replace if necessary
1 parent 649a451 commit ed89971

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

tests/test_dual_evaluation.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ def test_ufl_only_simple():
1111
expr = ufl.inner(v, v)
1212
W = V
1313
to_element = create_element(W.ufl_element())
14-
ast, oriented, needs_cell_sizes, coefficients, _ = compile_expression_dual_evaluation(expr, to_element, coffee=False)
14+
ast, oriented, needs_cell_sizes, coefficients, first_coeff_fake_coords, _ = compile_expression_dual_evaluation(expr, to_element, coffee=False)
15+
assert first_coeff_fake_coords is False
1516

1617

1718
def test_ufl_only_spatialcoordinate():
@@ -21,7 +22,8 @@ def test_ufl_only_spatialcoordinate():
2122
expr = x*y - y**2 + x
2223
W = V
2324
to_element = create_element(W.ufl_element())
24-
ast, oriented, needs_cell_sizes, coefficients, _ = compile_expression_dual_evaluation(expr, to_element, coffee=False)
25+
ast, oriented, needs_cell_sizes, coefficients, first_coeff_fake_coords, _ = compile_expression_dual_evaluation(expr, to_element, coffee=False)
26+
assert first_coeff_fake_coords is True
2527

2628

2729
def test_ufl_only_from_contravariant_piola():
@@ -31,7 +33,8 @@ def test_ufl_only_from_contravariant_piola():
3133
expr = ufl.inner(v, v)
3234
W = ufl.FunctionSpace(mesh, ufl.FiniteElement("P", ufl.triangle, 2))
3335
to_element = create_element(W.ufl_element())
34-
ast, oriented, needs_cell_sizes, coefficients, _ = compile_expression_dual_evaluation(expr, to_element, coffee=False)
36+
ast, oriented, needs_cell_sizes, coefficients, first_coeff_fake_coords, _ = compile_expression_dual_evaluation(expr, to_element, coffee=False)
37+
assert first_coeff_fake_coords is True
3538

3639

3740
def test_ufl_only_to_contravariant_piola():
@@ -41,7 +44,8 @@ def test_ufl_only_to_contravariant_piola():
4144
expr = ufl.as_vector([v, v])
4245
W = ufl.FunctionSpace(mesh, ufl.FiniteElement("RT", ufl.triangle, 1))
4346
to_element = create_element(W.ufl_element())
44-
ast, oriented, needs_cell_sizes, coefficients, _ = compile_expression_dual_evaluation(expr, to_element, coffee=False)
47+
ast, oriented, needs_cell_sizes, coefficients, first_coeff_fake_coords, _ = compile_expression_dual_evaluation(expr, to_element, coffee=False)
48+
assert first_coeff_fake_coords is True
4549

4650

4751
def test_ufl_only_shape_mismatch():
@@ -54,4 +58,4 @@ def test_ufl_only_shape_mismatch():
5458
to_element = create_element(W.ufl_element())
5559
assert to_element.value_shape == (2,)
5660
with pytest.raises(ValueError):
57-
ast, oriented, needs_cell_sizes, coefficients, _ = compile_expression_dual_evaluation(expr, to_element, coffee=False)
61+
ast, oriented, needs_cell_sizes, coefficients, first_coeff_fake_coords, _ = compile_expression_dual_evaluation(expr, to_element, coffee=False)

tsfc/driver.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,15 +332,16 @@ def compile_expression_dual_evaluation(expression, to_element, *,
332332
domain = expression.ufl_domain()
333333
assert domain is not None
334334

335-
# Create a fake coordinate coefficient for a domain.
336-
coords_coefficient = ufl.Coefficient(ufl.FunctionSpace(domain, domain.ufl_coordinate_element()))
337-
builder.domain_coordinate[domain] = coords_coefficient
338-
builder.set_cell_sizes(domain)
339-
340335
# Collect required coefficients
336+
first_coefficient_fake_coords = False
341337
coefficients = extract_coefficients(expression)
342338
if has_type(expression, GeometricQuantity) or any(fem.needs_coordinate_mapping(c.ufl_element()) for c in coefficients):
339+
# Create a fake coordinate coefficient for a domain.
340+
coords_coefficient = ufl.Coefficient(ufl.FunctionSpace(domain, domain.ufl_coordinate_element()))
341+
builder.domain_coordinate[domain] = coords_coefficient
342+
builder.set_cell_sizes(domain)
343343
coefficients = [coords_coefficient] + coefficients
344+
first_coefficient_fake_coords = True
344345
builder.set_coefficients(coefficients)
345346

346347
# Split mixed coefficients
@@ -433,7 +434,7 @@ def compile_expression_dual_evaluation(expression, to_element, *,
433434
# Handle kernel interface requirements
434435
builder.register_requirements([ir])
435436
# Build kernel tuple
436-
return builder.construct_kernel(return_arg, impero_c, index_names)
437+
return builder.construct_kernel(return_arg, impero_c, index_names, first_coefficient_fake_coords)
437438

438439

439440
def lower_integral_type(fiat_cell, integral_type):

tsfc/kernel_interface/firedrake_loopy.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818

1919
# Expression kernel description type
20-
ExpressionKernel = namedtuple('ExpressionKernel', ['ast', 'oriented', 'needs_cell_sizes', 'coefficients', 'tabulations'])
20+
ExpressionKernel = namedtuple('ExpressionKernel', ['ast', 'oriented', 'needs_cell_sizes', 'coefficients', 'first_coefficient_fake_coords', 'tabulations'])
2121

2222

2323
def make_builder(*args, **kwargs):
@@ -153,12 +153,14 @@ def register_requirements(self, ir):
153153
provided by the kernel interface."""
154154
self.oriented, self.cell_sizes, self.tabulations = check_requirements(ir)
155155

156-
def construct_kernel(self, return_arg, impero_c, index_names):
156+
def construct_kernel(self, return_arg, impero_c, index_names, first_coefficient_fake_coords):
157157
"""Constructs an :class:`ExpressionKernel`.
158158
159159
:arg return_arg: loopy.GlobalArg for the return value
160160
:arg impero_c: gem.ImperoC object that represents the kernel
161161
:arg index_names: pre-assigned index names
162+
:arg first_coefficient_fake_coords: If true, the kernel's first
163+
coefficient is a constructed UFL coordinate field
162164
:returns: :class:`ExpressionKernel` object
163165
"""
164166
args = [return_arg]
@@ -173,7 +175,8 @@ def construct_kernel(self, return_arg, impero_c, index_names):
173175
loopy_kernel = generate_loopy(impero_c, args, self.scalar_type,
174176
"expression_kernel", index_names)
175177
return ExpressionKernel(loopy_kernel, self.oriented, self.cell_sizes,
176-
self.coefficients, self.tabulations)
178+
self.coefficients, first_coefficient_fake_coords,
179+
self.tabulations)
177180

178181

179182
class KernelBuilder(KernelBuilderBase):

0 commit comments

Comments
 (0)