Skip to content

Commit 68f1c26

Browse files
committed
Fix BaseForm.__add__ simplification of Zero
1 parent fbd288e commit 68f1c26

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

test/test_duals.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ def test_addition():
101101
V = FunctionSpace(domain_2d, f_2d)
102102
V_dual = V.dual()
103103

104+
fvector_2d = FiniteElement("Lagrange", triangle, 1, (2, ), identity_pullback, H1)
105+
W = FunctionSpace(domain_2d, fvector_2d)
106+
104107
u = TrialFunction(V)
105108
v = TestFunction(V)
106109

@@ -132,6 +135,11 @@ def test_addition():
132135
res -= ZeroBaseForm((v,))
133136
assert res == L
134137

138+
# Simplification with respect to ufl.Zero
139+
a_W = Matrix(W, W)
140+
res = a_W + Zero(W.ufl_element().value_shape)
141+
assert res == a_W
142+
135143

136144
def test_scalar_mult():
137145
domain_2d = Mesh(FiniteElement("Lagrange", triangle, 1, (2, ), identity_pullback, H1))

ufl/form.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def __add__(self, other):
137137
if isinstance(other, (int, float)) and other == 0:
138138
# Allow adding 0 or 0.0 as a no-op, needed for sum([a,b])
139139
return self
140-
elif isinstance(other, Zero) and not (other.ufl_shape or other.ufl_free_indices):
140+
elif isinstance(other, Zero):
141141
# Allow adding ufl Zero as a no-op, needed for sum([a,b])
142142
return self
143143

0 commit comments

Comments
 (0)