@@ -126,7 +126,7 @@ def _make_core(self):
126126 if self .field_data .initial_guess .exprs :
127127 self ._make_initial_guess ()
128128 # Make the callback used to constrain boundary nodes
129- if self .field_data .constrain_bc . exprs :
129+ if self .field_data .constrain_bc :
130130 self ._make_constrain_bc ()
131131 self ._make_user_struct_callback ()
132132
@@ -658,7 +658,6 @@ def _make_constrain_bc(self):
658658 exprs , options = {'mpi' : False }, sregistry = self .sregistry ,
659659 concretize_mapper = self .concretize_mapper
660660 )
661- # from IPython import embed; embed()
662661 body = self ._create_constrain_bc_body (
663662 List (body = irs .uiet .body )
664663 )
@@ -669,7 +668,60 @@ def _make_constrain_bc(self):
669668 self ._efuncs [cb .name ] = cb
670669
671670 def _create_constrain_bc_body (self , body ):
672- return body
671+ linsolve_expr = self .inject_solve .expr .rhs
672+ objs = self .objs
673+ sobjs = self .solver_objs
674+ target = self .target
675+
676+ dmda = sobjs ['callbackdm' ]
677+ ctx = objs ['dummyctx' ]
678+
679+ x_arr = self .field_data .arrays [target ]['x' ]
680+
681+ vec_get_array = petsc_call (
682+ 'VecGetArray' , [objs ['xloc' ], Byref (x_arr ._C_symbol )]
683+ )
684+
685+ dm_get_local_info = petsc_call (
686+ 'DMDAGetLocalInfo' , [dmda , Byref (linsolve_expr .localinfo )]
687+ )
688+
689+ body = self .time_dependence .uxreplace_time (body )
690+
691+ fields = get_user_struct_fields (body )
692+ self ._struct_params .extend (fields )
693+
694+ dm_get_app_context = petsc_call (
695+ 'DMGetApplicationContext' , [dmda , Byref (ctx ._C_symbol )]
696+ )
697+
698+ vec_restore_array = petsc_call (
699+ 'VecRestoreArray' , [objs ['xloc' ], Byref (x_arr ._C_symbol )]
700+ )
701+
702+ body = body ._rebuild (body = body .body + (vec_restore_array ,))
703+
704+ stacks = (
705+ vec_get_array ,
706+ dm_get_local_info
707+ )
708+
709+ # Dereference function data in struct
710+ derefs = dereference_funcs (ctx , fields )
711+
712+ # Force the struct definition to appear at the very start, since
713+ # stacks, allocs etc may rely on its information
714+ struct_definition = [Definition (ctx ), dm_get_app_context ]
715+
716+ body = self ._make_callable_body (
717+ body , standalones = struct_definition , stacks = stacks + derefs
718+ )
719+
720+ # Replace non-function data with pointer to data in struct
721+ subs = {i ._C_symbol : FieldFromPointer (i ._C_symbol , ctx ) for
722+ i in fields if not isinstance (i .function , AbstractFunction )}
723+
724+ return Uxreplace (subs ).visit (body )
673725
674726 def _make_user_struct_callback (self ):
675727 """
0 commit comments