@@ -42,14 +42,12 @@ def __init__(self, **kwargs):
4242 self ._struct_params = []
4343
4444 self ._main_matvec_callback = None
45- self ._main_formfunc_callback = None
4645 self ._user_struct_callback = None
47- # TODO: Test pickling. The mutability of these lists
48- # could cause issues when pickling?
46+ self ._F_efunc = None
47+ self ._b_efunc = None
48+
4949 self ._J_efuncs = []
50- self ._F_efuncs = []
51- self ._b_efuncs = []
52- self ._initialguesses = []
50+ self ._initial_guesses = []
5351
5452 self ._make_core ()
5553 self ._efuncs = self ._uxreplace_efuncs ()
@@ -69,31 +67,26 @@ def filtered_struct_params(self):
6967 @property
7068 def main_matvec_callback (self ):
7169 """
72- This is the matvec callback associated with the whole Jacobian i.e
73- is set in the main kernel via
74- `PetscCall(MatShellSetOperation(J,MATOP_MULT,(void (*)(void))...));`
70+ The matrix-vector callback for the full Jacobian.
71+ This is the function set in the main Kernel via:
72+ PetscCall(MatShellSetOperation(J, MATOP_MULT, (void (*)(void))...));
73+ The callback has the signature `(Mat, Vec, Vec)`.
7574 """
7675 return self ._J_efuncs [0 ]
7776
78- @property
79- def main_formfunc_callback (self ):
80- return self ._F_efuncs [0 ]
81-
8277 @property
8378 def J_efuncs (self ):
79+ """
80+ List of matrix-vector callbacks.
81+ Each callback has the signature `(Mat, Vec, Vec)`. Typically, this list
82+ contains a single element, but in mixed systems it can include multiple
83+ callbacks, one for each subblock.
84+ """
8485 return self ._J_efuncs
8586
8687 @property
87- def F_efuncs (self ):
88- return self ._F_efuncs
89-
90- @property
91- def b_efuncs (self ):
92- return self ._b_efuncs
93-
94- @property
95- def initialguesses (self ):
96- return self ._initialguesses
88+ def initial_guesses (self ):
89+ return self ._initial_guesses
9790
9891 @property
9992 def user_struct_callback (self ):
@@ -284,7 +277,7 @@ def _make_formfunc(self):
284277 retval = objs ['err' ],
285278 parameters = (objs ['snes' ], objs ['X' ], objs ['F' ], objs ['dummyptr' ])
286279 )
287- self ._F_efuncs . append ( cb )
280+ self ._F_efunc = cb
288281 self ._efuncs [cb .name ] = cb
289282
290283 def _create_formfunc_body (self , body ):
@@ -422,7 +415,7 @@ def _make_formrhs(self):
422415 retval = objs ['err' ],
423416 parameters = (sobjs ['callbackdm' ], objs ['B' ])
424417 )
425- self ._b_efuncs . append ( cb )
418+ self ._b_efunc = cb
426419 self ._efuncs [cb .name ] = cb
427420
428421 def _create_form_rhs_body (self , body ):
@@ -534,7 +527,7 @@ def _make_initialguess(self):
534527 retval = objs ['err' ],
535528 parameters = (sobjs ['callbackdm' ], objs ['xloc' ])
536529 )
537- self ._initialguesses .append (cb )
530+ self ._initial_guesses .append (cb )
538531 self ._efuncs [cb .name ] = cb
539532
540533 def _create_initial_guess_body (self , body ):
@@ -660,16 +653,12 @@ def jacobian(self):
660653 @property
661654 def main_matvec_callback (self ):
662655 """
663- This is the matvec callback associated with the whole Jacobian i.e
656+ This is the matrix-vector callback associated with the whole Jacobian i.e
664657 is set in the main kernel via
665658 `PetscCall(MatShellSetOperation(J,MATOP_MULT,(void (*)(void))MyMatShellMult));`
666659 """
667660 return self ._main_matvec_callback
668661
669- @property
670- def main_formfunc_callback (self ):
671- return self ._main_formfunc_callback
672-
673662 def _make_core (self ):
674663 for sm in self .fielddata .jacobian .nonzero_submatrices :
675664 self ._make_matvec (sm , prefix = f'{ sm .name } _MatMult' )
@@ -757,7 +746,7 @@ def _make_whole_formfunc(self):
757746 retval = objs ['err' ],
758747 parameters = (objs ['snes' ], objs ['X' ], objs ['F' ], objs ['dummyptr' ])
759748 )
760- self ._main_formfunc_callback = cb
749+ self ._F_efunc = cb
761750 self ._efuncs [cb .name ] = cb
762751
763752 def _whole_formfunc_body (self , body ):
@@ -1310,7 +1299,7 @@ def _setup(self):
13101299 'MatShellSetOperation' ,
13111300 [sobjs ['Jac' ], 'MATOP_MULT' , MatShellSetOp (matvec .name , void , void )]
13121301 )
1313- formfunc = self .cbbuilder .main_formfunc_callback
1302+ formfunc = self .cbbuilder ._F_efunc
13141303 formfunc_operation = petsc_call (
13151304 'SNESSetFunction' ,
13161305 [sobjs ['snes' ], objs ['Null' ], FormFunctionCallback (formfunc .name , void , void ),
@@ -1477,7 +1466,7 @@ def _setup(self):
14771466 'MatShellSetOperation' ,
14781467 [sobjs ['Jac' ], 'MATOP_MULT' , MatShellSetOp (matvec .name , void , void )]
14791468 )
1480- formfunc = self .cbbuilder .main_formfunc_callback
1469+ formfunc = self .cbbuilder ._F_efunc
14811470 formfunc_operation = petsc_call (
14821471 'SNESSetFunction' ,
14831472 [sobjs ['snes' ], objs ['Null' ], FormFunctionCallback (formfunc .name , void , void ),
@@ -1593,16 +1582,16 @@ def _execute_solve(self):
15931582
15941583 struct_assignment = self .timedep .assign_time_iters (sobjs ['userctx' ])
15951584
1596- b_efunc = self .cbbuilder .b_efuncs [ 0 ]
1585+ b_efunc = self .cbbuilder ._b_efunc
15971586
15981587 dmda = sobjs ['dmda' ]
15991588
16001589 rhs_call = petsc_call (b_efunc .name , [sobjs ['dmda' ], sobjs ['bglobal' ]])
16011590
16021591 vec_place_array = self .timedep .place_array (target )
16031592
1604- if self .cbbuilder .initialguesses :
1605- initguess = self .cbbuilder .initialguesses [0 ]
1593+ if self .cbbuilder .initial_guesses :
1594+ initguess = self .cbbuilder .initial_guesses [0 ]
16061595 initguess_call = petsc_call (initguess .name , [dmda , sobjs ['xlocal' ]])
16071596 else :
16081597 initguess_call = None
0 commit comments