@@ -195,7 +195,7 @@ def inject_on_restrict(fine, restriction, rscale, injection, coarse):
195195 for bc in cctx ._problem .dirichlet_bcs ():
196196 bc .apply (cctx ._x )
197197
198- dm = problem .u .function_space ().dm
198+ dm = problem .u_restrict .function_space ().dm
199199 if not dm .getAttr ("_coarsen_hook" ):
200200 # The hook is persistent and cumulative, but also problem-independent.
201201 # Therefore, we are only adding it once.
@@ -209,7 +209,7 @@ def inject_on_restrict(fine, restriction, rscale, injection, coarse):
209209 F = self (problem .F , self , coefficient_mapping = coefficient_mapping )
210210 J = self (problem .J , self , coefficient_mapping = coefficient_mapping )
211211 Jp = self (problem .Jp , self , coefficient_mapping = coefficient_mapping )
212- u = coefficient_mapping [problem .u ]
212+ u = coefficient_mapping [problem .u_restrict ]
213213
214214 fine = problem
215215 problem = firedrake .NonlinearVariationalProblem (F , u , bcs = bcs , J = J , Jp = Jp , is_linear = problem .is_linear ,
@@ -283,7 +283,7 @@ def coarsen_snescontext(context, self, coefficient_mapping=None):
283283 if isinstance (val , (firedrake .Function , firedrake .Cofunction )):
284284 V = val .function_space ()
285285 coarseneddm = V .dm
286- parentdm = get_parent (context ._problem .u .function_space ().dm )
286+ parentdm = get_parent (context ._problem .u_restrict .function_space ().dm )
287287
288288 # Now attach the hook to the parent DM
289289 if get_appctx (coarseneddm ) is None :
@@ -303,11 +303,11 @@ def coarsen_snescontext(context, self, coefficient_mapping=None):
303303
304304
305305class Interpolation (object ):
306- def __init__ (self , coarse , fine , manager , cbcs = None , fbcs = None ):
307- self .cprimal = coarse
308- self .fprimal = fine
309- self .cdual = coarse . riesz_representation ( riesz_map = "l2" )
310- self .fdual = fine . riesz_representation ( riesz_map = "l2" )
306+ def __init__ (self , Vcoarse , Vfine , manager , cbcs = None , fbcs = None ):
307+ self .cprimal = firedrake . Function ( Vcoarse )
308+ self .fprimal = firedrake . Function ( Vfine )
309+ self .cdual = firedrake . Cofunction ( Vcoarse . dual () )
310+ self .fdual = firedrake . Cofunction ( Vfine . dual () )
311311 self .cbcs = cbcs or []
312312 self .fbcs = fbcs or []
313313 self .manager = manager
@@ -352,9 +352,9 @@ def multTransposeAdd(self, mat, x, y, w):
352352
353353
354354class Injection (object ):
355- def __init__ (self , cfn , ffn , manager , cbcs = None ):
356- self .cfn = cfn
357- self .ffn = ffn
355+ def __init__ (self , Vcoarse , Vfine , manager , cbcs = None ):
356+ self .cfn = firedrake . Function ( Vcoarse )
357+ self .ffn = firedrake . Function ( Vfine )
358358 self .cbcs = cbcs or []
359359 self .manager = manager
360360
@@ -374,18 +374,15 @@ def create_interpolation(dmc, dmf):
374374
375375 manager = get_transfer_manager (dmf )
376376
377- V_c = cctx ._problem .u .function_space ()
378- V_f = fctx ._problem .u .function_space ()
377+ V_c = cctx ._problem .u_restrict .function_space ()
378+ V_f = fctx ._problem .u_restrict .function_space ()
379379
380380 row_size = V_f .dof_dset .layout_vec .getSizes ()
381381 col_size = V_c .dof_dset .layout_vec .getSizes ()
382-
383- cfn = firedrake .Function (V_c )
384- ffn = firedrake .Function (V_f )
385382 cbcs = tuple (cctx ._problem .dirichlet_bcs ())
386383 fbcs = tuple (fctx ._problem .dirichlet_bcs ())
387384
388- ctx = Interpolation (cfn , ffn , manager , cbcs , fbcs )
385+ ctx = Interpolation (V_c , V_f , manager , cbcs , fbcs )
389386 mat = PETSc .Mat ().create (comm = dmc .comm )
390387 mat .setSizes ((row_size , col_size ))
391388 mat .setType (mat .Type .PYTHON )
@@ -400,16 +397,13 @@ def create_injection(dmc, dmf):
400397
401398 manager = get_transfer_manager (dmf )
402399
403- V_c = cctx ._problem .u .function_space ()
404- V_f = fctx ._problem .u .function_space ()
400+ V_c = cctx ._problem .u_restrict .function_space ()
401+ V_f = fctx ._problem .u_restrict .function_space ()
405402
406403 row_size = V_c .dof_dset .layout_vec .getSizes ()
407404 col_size = V_f .dof_dset .layout_vec .getSizes ()
408405
409- cfn = firedrake .Function (V_c )
410- ffn = firedrake .Function (V_f )
411-
412- ctx = Injection (cfn , ffn , manager )
406+ ctx = Injection (V_c , V_f , manager )
413407 mat = PETSc .Mat ().create (comm = dmc .comm )
414408 mat .setSizes ((row_size , col_size ))
415409 mat .setType (mat .Type .PYTHON )
0 commit comments