Skip to content

Commit 760acc4

Browse files
authored
Add return hatch for empty adjoint (#392)
1 parent 6e94c2a commit 760acc4

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

test/test_duals.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ def test_mixed_functionspace(self):
6767
assert is_dual(V_mixed_dual)
6868

6969

70+
def test_empty_adjoint():
71+
domain_2d = Mesh(LagrangeElement(triangle, 1, (2,)))
72+
f_2d = LagrangeElement(triangle, 1)
73+
V = FunctionSpace(domain_2d, f_2d)
74+
u = Coefficient(V)
75+
f = Coefficient(V)
76+
J = inner(u, f) * dx
77+
d2Jdu2 = derivative(derivative(J, u), u)
78+
d2Jdu2_adj = adjoint(d2Jdu2)
79+
assert d2Jdu2_adj.empty()
80+
81+
7082
def test_dual_coefficients():
7183
domain_2d = Mesh(LagrangeElement(triangle, 1, (2,)))
7284
f_2d = LagrangeElement(triangle, 1)

ufl/algorithms/formtransformations.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,8 @@ def compute_form_adjoint(form, reordered_arguments=None):
497497
but keeping their elements and places in the integrand expressions.
498498
"""
499499
arguments = form.arguments()
500-
500+
if form.empty():
501+
return form
501502
parts = [arg.part() for arg in arguments]
502503
if set(parts) - {None}:
503504
J = extract_blocks(form, arity=2)

0 commit comments

Comments
 (0)