aboutsummaryrefslogtreecommitdiff
path: root/Python/pywarpx/callbacks.py
diff options
context:
space:
mode:
authorGravatar Roelof Groenewald <40245517+roelof-groenewald@users.noreply.github.com> 2021-08-26 13:03:40 -0700
committerGravatar GitHub <noreply@github.com> 2021-08-26 13:03:40 -0700
commit71fbd848580b1d249a4c6dc7f3bb1b253d631b87 (patch)
tree778fd6ff5c033b833a0e0100abaa11347405cf05 /Python/pywarpx/callbacks.py
parentdf4504de42360074b9cfdcef8c03d248459c047e (diff)
downloadWarpX-71fbd848580b1d249a4c6dc7f3bb1b253d631b87.tar.gz
WarpX-71fbd848580b1d249a4c6dc7f3bb1b253d631b87.tar.zst
WarpX-71fbd848580b1d249a4c6dc7f3bb1b253d631b87.zip
Improvement in electrostic field solve when using EB & a small refactoring of the Electrostatic solver (#2143)
* refactored parts of the electrostatic solver to allow an outside Poisson solver to be installed * added callback to install a Poisson solver that can be used instead of the MLMG solver * added call to the poissonsolver callback if one is installed and updated ElectrostaticSolver.cpp to calculate the electric field directly in amrex if EBs are used * fixed issue causing ElectrostaticSphereEB test to crash * fixed the logic for when to call computeE * added function to allow charge density to be deposited in rho_fp from outside WarpX * fixed inconsistency between labframe and relativistic electrostatic simulation setup * fixed typo * fixed issue that caused ElectrostaticSphere test to fail and removed unnecessary call to multiply E_y by -1 when doing a 2d simulation * revert edit to error handling string * changes requested during PR review * additional change requested during PR review * fixed typo * revert unnecessary changes
Diffstat (limited to 'Python/pywarpx/callbacks.py')
-rw-r--r--Python/pywarpx/callbacks.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/Python/pywarpx/callbacks.py b/Python/pywarpx/callbacks.py
index 4ccaa479d..70cece8a8 100644
--- a/Python/pywarpx/callbacks.py
+++ b/Python/pywarpx/callbacks.py
@@ -23,6 +23,7 @@ The install can be done using a decorator, which has the prefix "callfrom". See
Functions can be called at the following times:
- afterinit <installafterinit>: immediately after the init is complete
- beforeEsolve <installbeforeEsolve>: before the solve for E fields
+ - poissonsolver <installpoissonsolver>: In place of the computePhi call but only in an electrostatic simulation
- afterEsolve <installafterEsolve>: after the solve for E fields
- beforedeposition <installbeforedeposition>: before the particle deposition (for charge and/or current)
- afterdeposition <installafterdeposition>: after particle deposition (for charge and/or current)
@@ -228,6 +229,7 @@ class CallbackFunctions(object):
# --- Now create the actual instances.
_afterinit = CallbackFunctions('afterinit')
_beforeEsolve = CallbackFunctions('beforeEsolve')
+_poissonsolver = CallbackFunctions('poissonsolver')
_afterEsolve = CallbackFunctions('afterEsolve')
_beforedeposition = CallbackFunctions('beforedeposition')
_afterdeposition = CallbackFunctions('afterdeposition')
@@ -246,6 +248,7 @@ _c_afterinit = _CALLBACK_FUNC_0(_afterinit)
libwarpx.warpx_set_callback_py_afterinit(_c_afterinit)
_c_beforeEsolve = _CALLBACK_FUNC_0(_beforeEsolve)
libwarpx.warpx_set_callback_py_beforeEsolve(_c_beforeEsolve)
+_c_poissonsolver = _CALLBACK_FUNC_0(_poissonsolver)
_c_afterEsolve = _CALLBACK_FUNC_0(_afterEsolve)
libwarpx.warpx_set_callback_py_afterEsolve(_c_afterEsolve)
_c_beforedeposition = _CALLBACK_FUNC_0(_beforedeposition)
@@ -275,7 +278,7 @@ def printcallbacktimers(tmin=1.,lminmax=False,ff=None):
- ff=None: If given, timings will be written to the file object instead of stdout
"""
if ff is None: ff = sys.stdout
- for c in [_afterinit,_beforeEsolve,_afterEsolve,
+ for c in [_afterinit,_beforeEsolve,_poissonsolver,_afterEsolve,
_beforedeposition,_afterdeposition,
_particlescraper,
_particleloader,
@@ -331,6 +334,24 @@ def isinstalledbeforeEsolve(f):
return _beforeEsolve.isinstalledfuncinlist(f)
# ----------------------------------------------------------------------------
+def callfrompoissonsolver(f):
+ installpoissonsolver(f)
+ return f
+def installpoissonsolver(f):
+ """Adds a function to solve Poisson's equation. Note that the C++ object
+ warpx_py_poissonsolver is declared as a nullptr but once the call to set it
+ to _c_poissonsolver below is executed it is no longer a nullptr, and therefore
+ if (warpx_py_poissonsolver) evaluates to True. For this reason a poissonsolver
+ cannot be uninstalled with the uninstallfuncinlist functionality at present."""
+ if _poissonsolver.hasfuncsinstalled():
+ raise RuntimeError('Only one field solver can be installed.')
+ libwarpx.warpx_set_callback_py_poissonsolver(_c_poissonsolver)
+ _poissonsolver.installfuncinlist(f)
+def isinstalledpoissonsolver(f):
+ """Checks if the function is called for a field solve"""
+ return _poissonsolver.isinstalledfuncinlist(f)
+
+# ----------------------------------------------------------------------------
def callfromafterEsolve(f):
installafterEsolve(f)
return f