Skip to content

Commit

Permalink
Merge pull request #152 from firedrakeproject/Modified_terminal_fix
Browse files Browse the repository at this point in the history
Fix multiple derivatives in modified terminals.
  • Loading branch information
dham authored Oct 6, 2017
2 parents 020e55b + b35cc1b commit e3368d6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions tsfc/modified_terminals.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
from ufl.classes import (ReferenceValue, ReferenceGrad,
NegativeRestricted, PositiveRestricted,
Restricted, FacetAvg, CellAvg, ConstantValue,
Jacobian, SpatialCoordinate)
Jacobian, SpatialCoordinate, Zero)
from ufl.checks import is_cellwise_constant


class ModifiedTerminal(object):
Expand Down Expand Up @@ -175,8 +176,16 @@ def construct_modified_terminal(mt, terminal):
if mt.reference_value:
expr = ReferenceValue(expr)

dim = expr.ufl_domain().topological_dimension()
for n in range(mt.local_derivatives):
expr = ReferenceGrad(expr)
# Return zero if expression is trivially constant. This has to
# happen here because ReferenceGrad has no access to the
# topological dimension of a literal zero.
if is_cellwise_constant(expr):
expr = Zero(expr.ufl_shape + (dim,), expr.ufl_free_indices,
expr.ufl_index_dimensions)
else:
expr = ReferenceGrad(expr)

if mt.averaged == "cell":
expr = CellAvg(expr)
Expand Down

0 comments on commit e3368d6

Please sign in to comment.