Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix is_cellwise_constant(ReferenceGrad(x)) #334

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/test_change_to_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
def test_change_to_reference_grad():
cell = triangle
domain = Mesh(FiniteElement("Lagrange", cell, 1, (2,), identity_pullback, H1))
U = FunctionSpace(domain, FiniteElement("Lagrange", cell, 1, (), identity_pullback, H1))
V = FunctionSpace(domain, FiniteElement("Lagrange", cell, 1, (2,), identity_pullback, H1))
U = FunctionSpace(domain, FiniteElement("Lagrange", cell, 3, (), identity_pullback, H1))
V = FunctionSpace(domain, FiniteElement("Lagrange", cell, 3, (2,), identity_pullback, H1))
u = Coefficient(U)
v = Coefficient(V)
Jinv = JacobianInverse(domain)
Expand Down
18 changes: 16 additions & 2 deletions ufl/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from ufl.core.expr import Expr
from ufl.core.terminal import FormArgument
from ufl.corealg.traversal import traverse_unique_terminals
from ufl.geometry import GeometricQuantity
from ufl.domain import extract_unique_domain
from ufl.geometry import GeometricQuantity, SpatialCoordinate
from ufl.sobolevspace import H1


Expand All @@ -34,7 +35,20 @@ def is_true_ufl_scalar(expression):

def is_cellwise_constant(expr):
"""Return whether expression is constant over a single cell."""
# TODO: Implement more accurately considering e.g. derivatives?
from ufl.coefficient import Coefficient
from ufl.differentiation import ReferenceGrad

if isinstance(expr, ReferenceGrad):
(expr,) = expr.ufl_operands
if is_cellwise_constant(expr):
return True
elif isinstance(expr, SpatialCoordinate):
domain = extract_unique_domain(expr)
return domain.is_piecewise_linear_simplex_domain()
elif isinstance(expr, Coefficient):
element = expr.ufl_element()
return element.embedded_superdegree <= 1

return all(e.is_cellwise_constant() for e in traverse_unique_terminals(expr))


Expand Down
Loading