Skip to content

Commit bffe57a

Browse files
committed
k
1 parent b154ee8 commit bffe57a

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

ufl/algorithms/apply_derivatives.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -2021,10 +2021,11 @@ def compute_gprimeterm(ngrads, vval, vcomp, wshape, wcomp):
20212021
return gprimesum
20222022

20232023
@process.register(CoordinateDerivative)
2024-
def _(self, o: Expr) -> Expr:
2024+
@DAGTraverser.postorder_only_children([0])
2025+
def _(self, o: Expr, o0) -> Expr:
20252026
"""Differentiate a coordinate_derivative."""
2026-
o = o.ufl_operands
2027-
return CoordinateDerivative(map_expr_dag(self, o[0]), o[1], o[2], o[3])
2027+
_, o1, o2, o3 = o.ufl_operands
2028+
return CoordinateDerivative(o0, o1, o2, o3)
20282029

20292030
@process.register(BaseFormOperator)
20302031
@DAGTraverser.postorder

ufl/corealg/dag_traverser.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,29 @@ def postorder(method):
8888
wrappong them in this decorator.
8989
9090
"""
91-
9291
@wraps(method)
9392
def wrapper(self, o, *args):
9493
processed_operands = [self(operand) for operand in o.ufl_operands]
9594
return method(self, o, *processed_operands, *args)
9695

9796
return wrapper
97+
98+
@staticmethod
99+
def postorder_only_children(indices):
100+
"""Insert processed operands after ``o`` and before ``*args``.
101+
102+
Users can write a post-order singledispatch method that takes
103+
``o``, processed operands, and additional arguments ``*args`` (if any),
104+
wrappong them in this decorator.
105+
106+
"""
107+
def postorder(method):
108+
109+
@wraps(method)
110+
def wrapper(self, o, *args):
111+
processed_operands = [self(o.ufl_operands[i]) for i in indices]
112+
return method(self, o, *processed_operands, *args)
113+
114+
return wrapper
115+
116+
return postorder

0 commit comments

Comments
 (0)