Skip to content

Commit

Permalink
add after diagnostic python callback (#3043)
Browse files Browse the repository at this point in the history
  • Loading branch information
roelof-groenewald authored Apr 20, 2022
1 parent a45bc79 commit e538399
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
17 changes: 17 additions & 0 deletions Python/pywarpx/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
- afterdeposition <installafterdeposition>: after particle deposition (for charge and/or current)
- beforestep <installbeforestep>: before the time step
- afterstep <installafterstep>: after the time step
- afterdiagnostics <installafterdiagnostics>: after diagnostic output
- particlescraper <installparticlescraper>: just after the particle boundary conditions are applied
but before lost particles are processed
- particleloader <installparticleloader>: at the time that the standard particle loader is called
Expand Down Expand Up @@ -261,6 +262,7 @@ def callfuncsinlist(self,*args,**kw):
_particleloader = CallbackFunctions('particleloader')
_beforestep = CallbackFunctions('beforestep')
_afterstep = CallbackFunctions('afterstep')
_afterdiagnostics = CallbackFunctions('afterdiagnostics')
_afterrestart = CallbackFunctions('afterrestart',lcallonce=1)
_particleinjection = CallbackFunctions('particleinjection')
_appliedfields = CallbackFunctions('appliedfields')
Expand All @@ -279,6 +281,7 @@ def printcallbacktimers(tmin=1.,lminmax=False,ff=None):
_particlescraper,
_particleloader,
_beforestep,_afterstep,
_afterdiagnostics,
_afterrestart,
_particleinjection,
_appliedfields]:
Expand Down Expand Up @@ -471,6 +474,20 @@ def isinstalledafterstep(f):
"Checks if the function is called after a step"
return _afterstep.isinstalledfuncinlist(f)

# ----------------------------------------------------------------------------
def callfromafterdiagnostics(f):
installafterdiagnostics(f)
return f
def installafterdiagnostics(f):
"Adds a function to the list of functions called after diagnostic output"
_afterdiagnostics.installfuncinlist(f)
def uninstallafterdiagnostics(f):
"Removes the function from the list of functions called after diagnostic output"
_afterdiagnostics.uninstallfuncinlist(f)
def isinstalledafterdiagnostics(f):
"Checks if the function is called after diagnostic output"
return _afterdiagnostics.isinstalledfuncinlist(f)

# ----------------------------------------------------------------------------
def callfromafterrestart(f):
raise Exception('restart call back not implemented yet')
Expand Down
3 changes: 3 additions & 0 deletions Source/Evolve/WarpXEvolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@ WarpX::Evolve (int numsteps)
}
multi_diags->FilterComputePackFlush( step );

// execute afterdiagnostic callbacks
ExecutePythonCallback("afterdiagnostics");

// inputs: unused parameters (e.g. typos) check after step 1 has finished
if (!early_params_checked) {
amrex::Print() << "\n"; // better: conditional \n based on return value
Expand Down
4 changes: 2 additions & 2 deletions Source/Python/WarpX_py.H
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
* functions will be called. Currently supported keys (callback points) are
* afterinit, beforecollisions, aftercollisions, beforeEsolve, poissonsolver,
* afterEsolve, beforedeposition, afterdeposition, particlescraper,
* particleloader, beforestep, afterstep, afterrestart, particleinjection and
* appliedfields.
* particleloader, beforestep, afterstep, afterdiagnostics, afterrestart,
* particleinjection and appliedfields.
*/
extern std::map< std::string, WARPX_CALLBACK_PY_FUNC_0 > warpx_callback_py_map;

Expand Down

0 comments on commit e538399

Please sign in to comment.