10
10
from firedrake .bcs import DirichletBC , EquationBCSplit
11
11
from firedrake .petsc import PETSc
12
12
from firedrake .utils import cached_property
13
+ from firedrake .function import Function
14
+ from firedrake .cofunction import Cofunction
13
15
14
16
15
17
__all__ = ("ImplicitMatrixContext" , )
@@ -107,23 +109,22 @@ def __init__(self, a, row_bcs=[], col_bcs=[],
107
109
108
110
# create functions from test and trial space to help
109
111
# with 1-form assembly
110
- test_space , trial_space = [
111
- a .arguments ()[i ].function_space () for i in (0 , 1 )
112
- ]
113
- from firedrake import function , cofunction
112
+ test_space , trial_space = (
113
+ arg .function_space () for arg in a .arguments ()
114
+ )
114
115
# Need a cofunction since y receives the assembled result of Ax
115
- self ._ystar = cofunction . Cofunction (test_space .dual ())
116
- self ._y = function . Function (test_space )
117
- self ._x = function . Function (trial_space )
118
- self ._xstar = cofunction . Cofunction (trial_space .dual ())
116
+ self ._ystar = Cofunction (test_space .dual ())
117
+ self ._y = Function (test_space )
118
+ self ._x = Function (trial_space )
119
+ self ._xstar = Cofunction (trial_space .dual ())
119
120
120
121
# These are temporary storage for holding the BC
121
122
# values during matvec application. _xbc is for
122
123
# the action and ._ybc is for transpose.
123
124
if len (self .bcs ) > 0 :
124
- self ._xbc = cofunction . Cofunction (trial_space .dual ())
125
+ self ._xbc = Cofunction (trial_space .dual ())
125
126
if len (self .col_bcs ) > 0 :
126
- self ._ybc = cofunction . Cofunction (test_space .dual ())
127
+ self ._ybc = Cofunction (test_space .dual ())
127
128
128
129
# Get size information from template vecs on test and trial spaces
129
130
trial_vec = trial_space .dof_dset .layout_vec
@@ -135,6 +136,11 @@ def __init__(self, a, row_bcs=[], col_bcs=[],
135
136
136
137
self .action = action (self .a , self ._x )
137
138
self .actionT = action (self .aT , self ._y )
139
+ # TODO prevent action from returning empty Forms
140
+ if self .action .empty ():
141
+ self .action = Cofunction (test_space .dual ())
142
+ if self .actionT .empty ():
143
+ self .action = Cofunction (trial_space .dual ())
138
144
139
145
# For assembling action(f, self._x)
140
146
self .bcs_action = []
@@ -170,7 +176,6 @@ def __init__(self, a, row_bcs=[], col_bcs=[],
170
176
171
177
@cached_property
172
178
def _diagonal (self ):
173
- from firedrake import Cofunction
174
179
assert self .on_diag
175
180
return Cofunction (self ._x .function_space ().dual ())
176
181
0 commit comments