22from firedrake .preconditioners .base import PCBase
33import firedrake .dmhooks as dmhooks
44
5+ from firedrake .parameters import parameters
6+ from firedrake .interpolation import Interpolate
7+ from firedrake .solving_utils import _SNESContext
8+ from firedrake .matrix_free .operators import ImplicitMatrixContext
9+
510
611__all__ = ['GTMGPC' ]
712
@@ -12,11 +17,6 @@ class GTMGPC(PCBase):
1217 _prefix = "gt_"
1318
1419 def initialize (self , pc ):
15- from firedrake import TestFunction , parameters
16- from firedrake .assemble import get_assembler
17- from firedrake .interpolation import Interpolator
18- from firedrake .solving_utils import _SNESContext
19- from firedrake .matrix_free .operators import ImplicitMatrixContext
2020
2121 _ , P = pc .getOperators ()
2222 appctx = self .get_appctx (pc )
@@ -37,6 +37,7 @@ def initialize(self, pc):
3737
3838 # Handle the fine operator if type is python
3939 if P .getType () == "python" :
40+ from firedrake .assemble import get_assembler
4041 ictx = P .getPythonContext ()
4142 if ictx is None :
4243 raise ValueError ("No context found on matrix" )
@@ -102,11 +103,12 @@ def initialize(self, pc):
102103
103104 interp_petscmat = appctx .get ("interpolation_matrix" , None )
104105 if interp_petscmat is None :
106+ from firedrake .assemble import assemble
105107 # Create interpolation matrix from coarse space to fine space
106108 fine_space = ctx .J .arguments ()[0 ].function_space ()
107- interpolator = Interpolator ( TestFunction ( coarse_space ), fine_space )
108- interpolation_matrix = interpolator . callable ( )
109- interp_petscmat = interpolation_matrix . handle
109+ coarse_test , coarse_trial = coarse_operator . arguments ( )
110+ interp = assemble ( Interpolate ( coarse_trial , fine_space ) )
111+ interp_petscmat = interp . petscmat
110112
111113 # We set up a PCMG object that uses the constructed interpolation
112114 # matrix to generate the restriction/prolongation operators.
0 commit comments