From a66bef2de53087a328a980824d985c0b843fe5ca Mon Sep 17 00:00:00 2001 From: Roelof Groenewald Date: Thu, 20 Jul 2023 18:50:33 -0700 Subject: [PATCH] add `clear_all()` to callbacks in order to remove all callbacks at finalize --- .../capacitive_discharge/PICMI_inputs_1d.py | 2 +- Python/pywarpx/_libwarpx.py | 5 ++++- Python/pywarpx/callbacks.py | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Examples/Physics_applications/capacitive_discharge/PICMI_inputs_1d.py b/Examples/Physics_applications/capacitive_discharge/PICMI_inputs_1d.py index c95987476c0..766e7693b6d 100644 --- a/Examples/Physics_applications/capacitive_discharge/PICMI_inputs_1d.py +++ b/Examples/Physics_applications/capacitive_discharge/PICMI_inputs_1d.py @@ -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 @@ -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) diff --git a/Python/pywarpx/_libwarpx.py b/Python/pywarpx/_libwarpx.py index 6691ea09d92..2be10faffe5 100755 --- a/Python/pywarpx/_libwarpx.py +++ b/Python/pywarpx/_libwarpx.py @@ -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 @@ -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): ''' diff --git a/Python/pywarpx/callbacks.py b/Python/pywarpx/callbacks.py index 01d7ea3ebf5..b8824d0ef16 100644 --- a/Python/pywarpx/callbacks.py +++ b/Python/pywarpx/callbacks.py @@ -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):