Skip to content

Commit 4664e57

Browse files
authored
Fix BaseFormOperator.ufl_function_space (#377)
* Fix BaseFormOperator.ufl_function_space * retrigger CI
1 parent e491e30 commit 4664e57

2 files changed

Lines changed: 18 additions & 22 deletions

File tree

test/test_interpolate.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,8 @@ def V2(domain_2d):
5656

5757

5858
def test_symbolic(V1, V2):
59-
# Set dual of V2
60-
V2_dual = V2.dual()
61-
6259
u = Coefficient(V1)
63-
vstar = Argument(V2_dual, 0)
60+
vstar = Argument(V2.dual(), 0)
6461
Iu = Interpolate(u, vstar)
6562

6663
assert Iu == Interpolate(u, V2)
@@ -71,17 +68,17 @@ def test_symbolic(V1, V2):
7168

7269

7370
def test_symbolic_adjoint(V1, V2):
74-
# Set dual of V2
75-
V2_dual = V2.dual()
76-
7771
u = Argument(V1, 1)
78-
vstar = Cofunction(V2_dual)
79-
Iu = Interpolate(u, vstar)
72+
form = inner(1, Argument(V2, 0)) * dx
73+
cofun = Cofunction(V2.dual())
8074

81-
assert Iu.ufl_function_space() == V2_dual
82-
assert Iu.argument_slots() == (vstar, u)
83-
assert Iu.arguments() == (u,)
84-
assert Iu.ufl_operands == (u,)
75+
for vstar in (form, cofun):
76+
Iu = Interpolate(u, vstar)
77+
78+
assert Iu.ufl_function_space() == V1.dual()
79+
assert Iu.argument_slots() == (vstar, u)
80+
assert Iu.arguments() == (u,)
81+
assert Iu.ufl_operands == (u,)
8582

8683

8784
def test_action_adjoint(V1, V2):

ufl/core/base_form_operator.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from numbers import Number
1818

1919
from ufl.argument import Argument, Coargument
20-
from ufl.coefficient import BaseCoefficient
2120
from ufl.constantvalue import as_ufl
2221
from ufl.core.operator import Operator
2322
from ufl.core.ufl_type import ufl_type
@@ -135,21 +134,21 @@ def count(self):
135134

136135
@property
137136
def ufl_shape(self):
138-
"""Return the UFL shape of the coefficient.produced by the operator."""
139-
arg, *_ = self.argument_slots()
140-
if not isinstance(arg, BaseCoefficient) and isinstance(arg, (BaseForm, Coargument)):
141-
arg, *_ = arg.arguments()
137+
"""Return the UFL shape of the coefficient produced by the operator."""
138+
if len(self.arguments()) == 0:
139+
return ()
140+
arg, *_ = self.arguments()
142141
return arg._ufl_shape
143142

144143
def ufl_function_space(self):
145144
"""Return the function space associated to the operator.
146145
147146
I.e. return the dual of the base form operator's Coargument space.
148147
"""
149-
arg, *_ = self.argument_slots()
150-
if not isinstance(arg, BaseCoefficient) and isinstance(arg, (BaseForm, Coargument)):
151-
arg, *_ = arg.arguments()
152-
return arg.ufl_function_space()
148+
if len(self.arguments()) == 0:
149+
return None
150+
arg, *_ = self.arguments()
151+
return arg.ufl_function_space().dual()
153152

154153
def _ufl_expr_reconstruct_(
155154
self, *operands, function_space=None, derivatives=None, argument_slots=None

0 commit comments

Comments
 (0)