Skip to content

Commit c85d2b6

Browse files
committed
TSFC: avoid setup of unused domains
1 parent 56ddeed commit c85d2b6

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

tests/firedrake/submesh/test_submesh_solve.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ def _test_submesh_solve_3d_2d_poisson(simplex, direction, nref, degree):
592592
mesh12 = Submesh(mesh2, dim - 1, label_interf)
593593
dx1 = Measure("dx", mesh1)
594594
dx2 = Measure("dx", mesh2)
595-
ds1_ds2 = Measure("ds", mesh1, intersect_measures=(Measure("ds", mesh2),))
595+
ds1_ds2 = Measure("ds", mesh1, intersect_measures=(Measure("ds", mesh2), Measure("dx", mesh12)))
596596
dx12_ds1_ds2 = Measure(
597597
"dx", mesh12,
598598
intersect_measures=(

tsfc/kernel_interface/common.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -505,12 +505,13 @@ def prepare_coefficient(coefficient, name, domain_integral_type_map):
505505
shape = finat_element.index_shape
506506
size = numpy.prod(shape, dtype=int)
507507
domain = extract_unique_domain(coefficient)
508-
integral_type = domain_integral_type_map[domain]
509-
if integral_type is None:
508+
try:
509+
integral_type = domain_integral_type_map[domain]
510+
except KeyError:
510511
# This means that this coefficient does not exist in the DAG,
511512
# so corresponding gem expression will never be needed.
512-
expression = None
513-
elif integral_type.startswith("interior_facet"):
513+
return None
514+
if integral_type.startswith("interior_facet"):
514515
varexp = gem.Variable(name, (2 * size,))
515516
plus = gem.view(varexp, slice(size))
516517
minus = gem.view(varexp, slice(size, 2 * size))

tsfc/kernel_interface/firedrake_loopy.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,12 @@ def set_cell_orientations(self, domains):
127127
# Cell orientation
128128
self._cell_orientations = {}
129129
for i, domain in enumerate(domains):
130-
integral_type = self._domain_integral_type_map[domain]
131-
if integral_type is None:
132-
# See comment in prepare_coefficient.
133-
self._cell_orientations[domain] = None
134-
elif integral_type.startswith("interior_facet"):
130+
try:
131+
integral_type = self._domain_integral_type_map[domain]
132+
except KeyError:
133+
# skip unused domain
134+
continue
135+
if integral_type.startswith("interior_facet"):
135136
cell_orientations = gem.Variable(f"cell_orientations_{i}", (2,), dtype=gem.uint_type)
136137
self._cell_orientations[domain] = (gem.Indexed(cell_orientations, (0,)),
137138
gem.Indexed(cell_orientations, (1,)))
@@ -157,6 +158,9 @@ def set_cell_sizes(self, domains):
157158
"""
158159
self._cell_sizes = {}
159160
for i, domain in enumerate(domains):
161+
if domain not in self._domain_integral_type_map:
162+
# skip unused domain
163+
continue
160164
if domain.ufl_cell().topological_dimension > 0:
161165
# Can't create P1 since only P0 is a valid finite element if
162166
# topological_dimension is 0 and the concept of "cell size"
@@ -326,13 +330,13 @@ def set_entity_numbers(self, domains):
326330
self._entity_numbers = {}
327331
self._entity_ids = {}
328332
for i, domain in enumerate(domains):
333+
try:
334+
integral_type = self.integral_data_info.domain_integral_type_map[domain]
335+
except KeyError:
336+
# skip unused domain
337+
continue
329338
fiat_cell = as_fiat_cell(domain.ufl_cell())
330-
integral_type = self.integral_data_info.domain_integral_type_map[domain]
331-
if integral_type is None:
332-
# Set placeholder for unused domain.
333-
entity_ids = None
334-
else:
335-
_, entity_ids = lower_integral_type(fiat_cell, integral_type)
339+
_, entity_ids = lower_integral_type(fiat_cell, integral_type)
336340
self._entity_ids[domain] = entity_ids
337341
if integral_type in ['exterior_facet', 'exterior_facet_vert']:
338342
facet = gem.Variable(f'facet_{i}', (1,), dtype=gem.uint_type)
@@ -359,7 +363,11 @@ def set_entity_orientations(self, domains):
359363
"""
360364
self._entity_orientations = {}
361365
for i, domain in enumerate(domains):
362-
integral_type = self.integral_data_info.domain_integral_type_map[domain]
366+
try:
367+
integral_type = self.integral_data_info.domain_integral_type_map[domain]
368+
except KeyError:
369+
# skip unused domain
370+
continue
363371
variable_name = f"entity_orientations_{i}"
364372
if integral_type in ['exterior_facet', 'exterior_facet_vert']:
365373
o = gem.Variable(variable_name, (1,), dtype=gem.uint_type)

0 commit comments

Comments
 (0)