Skip to content

Commit

Permalink
add clear_all() to callbacks in order to remove all callbacks at fi…
Browse files Browse the repository at this point in the history
…nalize
  • Loading branch information
roelof-groenewald committed Jul 21, 2023
1 parent 77d5116 commit a66bef2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def initialize_inputs(self):
self.decompose_matrix()

callbacks.installpoissonsolver(self._run_solve)
callbacks.installafterstep(self._get_rho_ions)

def decompose_matrix(self):
"""Function to build the superLU object used to solve the linear
Expand Down Expand Up @@ -347,6 +346,7 @@ def run_sim(self):
self.sim.step(self.max_steps - self.diag_steps)

self.rho_wrapper = fields.RhoFPWrapper(0, False)
callbacks.installafterstep(self._get_rho_ions)

self.sim.step(self.diag_steps)

Expand Down
5 changes: 4 additions & 1 deletion Python/pywarpx/_libwarpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ def finalize(self, finalize_mpi=1):
#self.libwarpx_so.warpx_finalize()
self.libwarpx_so.amrex_finalize()

from pywarpx import callbacks
callbacks.clear_all()

def getistep(self, level=0):
'''
Get the current time step number for the specified level
Expand Down Expand Up @@ -215,7 +218,7 @@ def evolve(self, num_steps=-1):
The number of steps to take
'''

self.warpx.evolve(num_steps);
self.warpx.evolve(num_steps)

def getProbLo(self, direction):
'''
Expand Down
4 changes: 4 additions & 0 deletions Python/pywarpx/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ def isinstalled(name, f):
"Checks if the function is called by this callback"
return callback_instances[name].isinstalledfuncinlist(f)

def clear_all():
for key, val in callback_instances.items():
val.clearlist()

#=============================================================================

def printcallbacktimers(tmin=1.,lminmax=False,ff=None):
Expand Down

0 comments on commit a66bef2

Please sign in to comment.