Skip to content

Commit

Permalink
check free indices after calling fem.compile_ufl (#241)
Browse files Browse the repository at this point in the history
Add asserts that we get the free indices we expect after calling
fem.compile_ufl. This is based on the understanding that GEM can
optimise away unnecessary free indices early, e.g. when interpolating an
expression which has no spatial variation (a ufl Constant).
  • Loading branch information
ReubenHill authored Feb 18, 2021
1 parent b693a09 commit fe07cb5
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tsfc/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@ def compile_expression_dual_evaluation(expression, to_element, *,
config["quadrature_rule"] = quad_rule

expr, = fem.compile_ufl(expression, **config, point_sum=False)
# In some cases point_set.indices may be dropped from expr, but nothing
# new should now appear
assert set(expr.free_indices) <= set(chain(point_set.indices, *argument_multiindices))
shape_indices = tuple(gem.Index() for _ in expr.shape)
basis_indices = point_set.indices
ir = gem.Indexed(expr, shape_indices)
Expand All @@ -396,6 +399,9 @@ def compile_expression_dual_evaluation(expression, to_element, *,
config = kernel_cfg.copy()
config.update(point_set=point_set)
expr, = fem.compile_ufl(expression, **config, point_sum=False)
# In some cases point_set.indices may be dropped from expr, but
# nothing new should now appear
assert set(expr.free_indices) <= set(chain(point_set.indices, *argument_multiindices))
expr = gem.partial_indexed(expr, shape_indices)
expr_cache[pts] = expr, point_set
weights = collections.defaultdict(list)
Expand Down

0 comments on commit fe07cb5

Please sign in to comment.