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.cpp | |
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 '')
-rw-r--r-- | Source/Python/WarpX_py.cpp | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/Source/Python/WarpX_py.cpp b/Source/Python/WarpX_py.cpp index 1d69ea8f3..7e0e491f8 100644 --- a/Source/Python/WarpX_py.cpp +++ b/Source/Python/WarpX_py.cpp @@ -7,16 +7,18 @@ */ #include "WarpX_py.H" -WARPX_CALLBACK_PY_FUNC_0 warpx_py_afterinit = nullptr; -WARPX_CALLBACK_PY_FUNC_0 warpx_py_beforeEsolve = nullptr; -WARPX_CALLBACK_PY_FUNC_0 warpx_py_poissonsolver = nullptr; -WARPX_CALLBACK_PY_FUNC_0 warpx_py_afterEsolve = nullptr; -WARPX_CALLBACK_PY_FUNC_0 warpx_py_beforedeposition = nullptr; -WARPX_CALLBACK_PY_FUNC_0 warpx_py_afterdeposition = nullptr; -WARPX_CALLBACK_PY_FUNC_0 warpx_py_particlescraper = nullptr; -WARPX_CALLBACK_PY_FUNC_0 warpx_py_particleloader = nullptr; -WARPX_CALLBACK_PY_FUNC_0 warpx_py_beforestep = nullptr; -WARPX_CALLBACK_PY_FUNC_0 warpx_py_afterstep = nullptr; -WARPX_CALLBACK_PY_FUNC_0 warpx_py_afterrestart = nullptr; -WARPX_CALLBACK_PY_FUNC_0 warpx_py_particleinjection = nullptr; -WARPX_CALLBACK_PY_FUNC_0 warpx_py_appliedfields = nullptr; +std::map< std::string, WARPX_CALLBACK_PY_FUNC_0 > warpx_callback_py_map; + +bool IsPythonCallBackInstalled ( std::string name ) +{ + return (warpx_callback_py_map.count(name) == 1u); +} + +// Execute Python callbacks of the type given by the input string +void ExecutePythonCallback ( std::string name ) +{ + if ( IsPythonCallBackInstalled(name) ) { + WARPX_PROFILE("warpx_py_"+name); + warpx_callback_py_map[name](); + } +} |