forked from ECP-WarpX/WarpX
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Callback modernization (ECP-WarpX#4)
* pyAMReX: Build System * refactor callbacks.py * added binding code in `pyWarpX.cpp` to add or remove keys from the callback dictionary * minor PR cleanups * CMake: Undo Unintentional Change Likely from rebase/merge. Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja>
- Loading branch information
1 parent
53d2888
commit e772eeb
Showing
7 changed files
with
137 additions
and
280 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,35 @@ | ||
/* Copyright 2019 David Grote, Maxence Thevenet, Weiqun Zhang | ||
* | ||
/* Copyright 2019-2022 The WarpX Community | ||
* | ||
* This file is part of WarpX. | ||
* | ||
* Authors: David Grote, Maxence Thevenet, Weiqun Zhang, Roelof Groenewald | ||
* | ||
* License: BSD-3-Clause-LBNL | ||
*/ | ||
#include "WarpX_py.H" | ||
|
||
std::map< std::string, WARPX_CALLBACK_PY_FUNC_0 > warpx_callback_py_map; | ||
std::map< std::string, std::function<void()> > warpx_callback_py_map; | ||
|
||
void InstallPythonCallback ( std::string name, std::function<void()> callback ) | ||
{ | ||
warpx_callback_py_map[name] = callback; | ||
} | ||
|
||
bool IsPythonCallBackInstalled ( std::string name ) | ||
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) ) { | ||
if ( IsPythonCallbackInstalled(name) ) { | ||
WARPX_PROFILE("warpx_py_"+name); | ||
warpx_callback_py_map[name](); | ||
} | ||
} | ||
|
||
void ClearPythonCallback ( std::string name ) | ||
{ | ||
warpx_callback_py_map.erase(name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters