Skip to content

Commit 4bb8288

Browse files
committed
skip unused domain
1 parent f00cfd6 commit 4bb8288

2 files changed

Lines changed: 25 additions & 17 deletions

File tree

tsfc/kernel_interface/common.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ def coefficient(self, ufl_coefficient, restriction):
5757
expressions."""
5858
kernel_arg = self.coefficient_map[ufl_coefficient]
5959
domain = extract_unique_domain(ufl_coefficient)
60-
assert self._domain_integral_type_map[domain] is not None
6160
if ufl_coefficient.ufl_element().family() == 'Real':
6261
return kernel_arg
6362
elif not self._domain_integral_type_map[domain].startswith("interior_facet"):
@@ -505,12 +504,13 @@ def prepare_coefficient(coefficient, name, domain_integral_type_map):
505504
shape = finat_element.index_shape
506505
size = numpy.prod(shape, dtype=int)
507506
domain = extract_unique_domain(coefficient)
508-
integral_type = domain_integral_type_map[domain]
509-
if integral_type is None:
507+
try:
508+
integral_type = domain_integral_type_map[domain]
509+
except KeyError:
510510
# This means that this coefficient does not exist in the DAG,
511511
# so corresponding gem expression will never be needed.
512-
expression = None
513-
elif integral_type.startswith("interior_facet"):
512+
return None
513+
if integral_type.startswith("interior_facet"):
514514
varexp = gem.Variable(name, (2 * size,))
515515
plus = gem.view(varexp, slice(size))
516516
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)