Skip to content

Commit b99a902

Browse files
committed
k
1 parent b154ee8 commit b99a902

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
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
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,23 @@ def wrapper(self, o, *args):
9595
return method(self, o, *processed_operands, *args)
9696

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

0 commit comments

Comments
 (0)