diff options
author | 2022-01-19 09:01:47 -0800 | |
---|---|---|
committer | 2022-01-19 09:01:47 -0800 | |
commit | 4e9d98c528dfebf05aa9d07edf451eff29f37f65 (patch) | |
tree | 2a3ed3586aa7895455f40ec4f40d7b1bb2156ef6 /Source/Python/WarpX_py.H | |
parent | 73858579e90701b5f1fc1ef9009a8067294aa975 (diff) | |
download | WarpX-4e9d98c528dfebf05aa9d07edf451eff29f37f65.tar.gz WarpX-4e9d98c528dfebf05aa9d07edf451eff29f37f65.tar.zst WarpX-4e9d98c528dfebf05aa9d07edf451eff29f37f65.zip |
Refactor python callback handling (#2703)
* added support to uninstall an external Poisson solver and return to using the default MLMG solver; also updated some callbacks.py calls to Python3
* refactor callback handling - use a map to handle all the different callbacks
* warpx_callback_py_map does not need to link to C
* Apply suggestions from code review
Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja>
* further suggested changes from code review
* added function ExecutePythonCallback to reduce code duplication
* moved ExecutePythonCallback to WarpX_py
* added function IsPythonCallbackInstalled
Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja>
Diffstat (limited to 'Source/Python/WarpX_py.H')
-rw-r--r-- | Source/Python/WarpX_py.H | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/Source/Python/WarpX_py.H b/Source/Python/WarpX_py.H index 42697fbac..efc248591 100644 --- a/Source/Python/WarpX_py.H +++ b/Source/Python/WarpX_py.H @@ -9,24 +9,30 @@ #define WARPX_PY_H_ #include "WarpXWrappers.H" +#include "Utils/WarpXProfilerWrapper.H" +#include <map> +#include <string> -extern "C" { +/** + * Declare global map to hold python callback functions. + * + * The keys of the map describe at what point in the simulation the python + * functions will be called. Currently supported keys (callback points) are + * afterinit, beforeEsolve, poissonsolver, afterEsolve, beforedeposition, + * afterdeposition, particlescraper, particleloader, beforestep, afterstep, + * afterrestart, particleinjection and appliedfields. +*/ +extern std::map< std::string, WARPX_CALLBACK_PY_FUNC_0 > warpx_callback_py_map; - extern WARPX_CALLBACK_PY_FUNC_0 warpx_py_afterinit; - extern WARPX_CALLBACK_PY_FUNC_0 warpx_py_beforeEsolve; - extern WARPX_CALLBACK_PY_FUNC_0 warpx_py_poissonsolver; - extern WARPX_CALLBACK_PY_FUNC_0 warpx_py_afterEsolve; - extern WARPX_CALLBACK_PY_FUNC_0 warpx_py_beforedeposition; - extern WARPX_CALLBACK_PY_FUNC_0 warpx_py_afterdeposition; - extern WARPX_CALLBACK_PY_FUNC_0 warpx_py_particlescraper; - extern WARPX_CALLBACK_PY_FUNC_0 warpx_py_particleloader; - extern WARPX_CALLBACK_PY_FUNC_0 warpx_py_beforestep; - extern WARPX_CALLBACK_PY_FUNC_0 warpx_py_afterstep; - extern WARPX_CALLBACK_PY_FUNC_0 warpx_py_afterrestart; - extern WARPX_CALLBACK_PY_FUNC_0 warpx_py_particleinjection; - extern WARPX_CALLBACK_PY_FUNC_0 warpx_py_appliedfields; +/** + * \brief Function to check if the given name is a key in warpx_callback_py_map + */ +bool IsPythonCallBackInstalled ( std::string name ); -} +/** + * \brief Function to look for and execute Python callbacks + */ +void ExecutePythonCallback ( std::string name ); #endif |