Skip to content

Commit

Permalink
Merge pull request #222 from firedrakeproject/wence/fix/compile-expre…
Browse files Browse the repository at this point in the history
…ssion-domain

Add optional domain argument to expression compilation
  • Loading branch information
wence- authored Jul 14, 2020
2 parents 456cae6 + 120377a commit 34a6c43
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 4 additions & 2 deletions tsfc/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ def name_multiindex(multiindex, name):
return builder.construct_kernel(kernel_name, impero_c, index_names, quad_rule)


def compile_expression_dual_evaluation(expression, to_element, coordinates, interface=None,
def compile_expression_dual_evaluation(expression, to_element, coordinates, *,
domain=None, interface=None,
parameters=None, coffee=False):
"""Compile a UFL expression to be evaluated against a compile-time known reference element's dual basis.
Expand All @@ -276,6 +277,7 @@ def compile_expression_dual_evaluation(expression, to_element, coordinates, inte
:arg expression: UFL expression
:arg to_element: A FIAT FiniteElement for the target space
:arg coordinates: the coordinate function
:arg domain: optional UFL domain the expression is defined on (useful when expression contains no domain).
:arg interface: backend module for the kernel interface
:arg parameters: parameters object
:arg coffee: compile coffee kernel instead of loopy kernel
Expand All @@ -300,7 +302,7 @@ def compile_expression_dual_evaluation(expression, to_element, coordinates, inte
mapping, = set(to_element.mapping())
except ValueError:
raise NotImplementedError("Don't know how to interpolate onto zany spaces, sorry")
expression = apply_mapping(expression, mapping)
expression = apply_mapping(expression, mapping, domain)

# Apply UFL preprocessing
expression = ufl_utils.preprocess_expression(expression,
Expand Down
9 changes: 5 additions & 4 deletions tsfc/ufl_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def simplify_abs(expression, complex_mode):
return mapper(expression, False)


def apply_mapping(expression, mapping):
def apply_mapping(expression, mapping, domain):
"""
This applies the appropriate transformation to the
given expression for interpolation to a specific
Expand Down Expand Up @@ -387,6 +387,10 @@ def apply_mapping(expression, mapping):
"""

mesh = expression.ufl_domain()
if mesh is None:
mesh = domain
if domain is not None and mesh != domain:
raise NotImplementedError("Multiple domains not supported")
rank = len(expression.ufl_shape)
if mapping == "affine":
return expression
Expand All @@ -396,18 +400,15 @@ def apply_mapping(expression, mapping):
expression = Indexed(expression, MultiIndex((*i, k)))
return as_tensor(J.T[j, k] * expression, (*i, j))
elif mapping == "contravariant piola":
mesh = expression.ufl_domain()
K = JacobianInverse(mesh)
detJ = JacobianDeterminant(mesh)
*i, j, k = indices(len(expression.ufl_shape) + 1)
expression = Indexed(expression, MultiIndex((*i, k)))
return as_tensor(detJ * K[j, k] * expression, (*i, j))
elif mapping == "double covariant piola" and rank == 2:
mesh = expression.ufl_domain()
J = Jacobian(mesh)
return J.T * expression * J
elif mapping == "double contravariant piola" and rank == 2:
mesh = expression.ufl_domain()
K = JacobianInverse(mesh)
detJ = JacobianDeterminant(mesh)
return (detJ)**2 * K * expression * K.T
Expand Down

0 comments on commit 34a6c43

Please sign in to comment.