Skip to content

Commit 455ebab

Browse files
committed
Extend shape derivative to complex mode
1 parent da69e3c commit 455ebab

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

ufl/algorithms/apply_derivatives.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Apply derivatives algorithm which computes the derivatives of a form of expression."""
22

3-
# Copyright (C) 2008-2016 Martin Sandve Alnæs
3+
# Copyright (C) 2008-2026 Martin Sandve Alnæs
44
#
55
# This file is part of UFL (https://www.fenicsproject.org)
66
#
@@ -17,6 +17,7 @@
1717
from ufl.action import Action
1818
from ufl.algorithms.analysis import extract_arguments, extract_coefficients
1919
from ufl.algorithms.map_integrands import map_integrands
20+
from ufl.algorithms.remove_complex_nodes import remove_complex_nodes
2021
from ufl.algorithms.replace_derivative_nodes import replace_derivative_nodes
2122
from ufl.argument import Argument, BaseArgument, Coargument
2223
from ufl.averaging import CellAvg, FacetAvg
@@ -2204,10 +2205,13 @@ def _(self, o: Expr) -> Expr:
22042205
# d (grad_X(x))/d x => grad_X(Argument(x.function_space())
22052206
for w, v in zip(self._w, self._v):
22062207
if extract_unique_domain(o) == extract_unique_domain(w) and isinstance(
2207-
v.ufl_operands[0], # type: ignore
2208+
remove_complex_nodes(v).ufl_operands[0], # type: ignore
22082209
FormArgument,
22092210
):
2210-
return ReferenceGrad(v)
2211+
if isinstance(v, Conj):
2212+
return Conj(ReferenceGrad(remove_complex_nodes(v)))
2213+
else:
2214+
return ReferenceGrad(v)
22112215
return self.independent_terminal(o)
22122216

22132217

0 commit comments

Comments
 (0)