aboutsummaryrefslogtreecommitdiff
path: root/Python
diff options
context:
space:
mode:
Diffstat (limited to 'Python')
-rwxr-xr-xPython/pywarpx/_libwarpx.py61
-rw-r--r--Python/pywarpx/fields.py20
2 files changed, 73 insertions, 8 deletions
diff --git a/Python/pywarpx/_libwarpx.py b/Python/pywarpx/_libwarpx.py
index ca87f4f41..eb296478d 100755
--- a/Python/pywarpx/_libwarpx.py
+++ b/Python/pywarpx/_libwarpx.py
@@ -186,6 +186,8 @@ libwarpx.warpx_getChargeDensityCP.restype = _LP_LP_c_real
libwarpx.warpx_getChargeDensityCPLoVects.restype = _LP_c_int
libwarpx.warpx_getChargeDensityFP.restype = _LP_LP_c_real
libwarpx.warpx_getChargeDensityFPLoVects.restype = _LP_c_int
+libwarpx.warpx_getPhiFP.restype = _LP_LP_c_real
+libwarpx.warpx_getPhiFPLoVects.restype = _LP_c_int
libwarpx.warpx_getParticleBoundaryBufferSize.restype = ctypes.c_int
libwarpx.warpx_getParticleBoundaryBuffer.restype = _LP_LP_c_particlereal
libwarpx.warpx_getParticleBoundaryBufferScrapedSteps.restype = _LP_LP_c_int
@@ -200,6 +202,7 @@ libwarpx.warpx_getJx_nodal_flag.restype = _LP_c_int
libwarpx.warpx_getJy_nodal_flag.restype = _LP_c_int
libwarpx.warpx_getJz_nodal_flag.restype = _LP_c_int
libwarpx.warpx_getRho_nodal_flag.restype = _LP_c_int
+libwarpx.warpx_getPhi_nodal_flag.restype = _LP_c_int
#libwarpx.warpx_getPMLSigma.restype = _LP_c_real
#libwarpx.warpx_getPMLSigmaStar.restype = _LP_c_real
@@ -1350,6 +1353,8 @@ def get_mesh_current_density_fp_pml(level, direction, include_ghosts=True):
return _get_mesh_field_list(libwarpx.warpx_getCurrentDensityFP_PML, level, direction, include_ghosts)
except ValueError:
raise Exception('PML not initialized')
+
+
def get_mesh_charge_density_cp(level, include_ghosts=True):
'''
@@ -1402,6 +1407,31 @@ def get_mesh_charge_density_fp(level, include_ghosts=True):
return _get_mesh_field_list(libwarpx.warpx_getChargeDensityFP, level, None, include_ghosts)
+def get_mesh_phi_fp(level, include_ghosts=True):
+ '''
+
+ This returns a list of numpy arrays containing the mesh electrostatic
+ potential data on each grid for this process. This version returns the
+ potential on the fine patch for the given level.
+
+ The data for the numpy arrays are not copied, but share the underlying
+ memory buffer with WarpX. The numpy arrays are fully writeable.
+
+ Parameters
+ ----------
+
+ level : the AMR level to get the data for
+ include_ghosts : whether to include ghost zones or not
+
+ Returns
+ -------
+
+ A List of numpy arrays.
+
+ '''
+ return _get_mesh_field_list(libwarpx.warpx_getPhiFP, level, None, include_ghosts)
+
+
def _get_mesh_array_lovects(level, direction, include_ghosts=True, getlovectsfunc=None):
assert(0 <= level and level <= libwarpx.warpx_finestLevel())
@@ -1806,8 +1836,8 @@ def get_mesh_charge_density_cp_lovects(level, include_ghosts=True):
def get_mesh_charge_density_fp_lovects(level, include_ghosts=True):
'''
- This returns a list of the lo vectors of the arrays containing the mesh electric field
- data on each grid for this process.
+ This returns a list of the lo vectors of the arrays containing the mesh
+ charge density data on each grid for this process.
Parameters
----------
@@ -1824,6 +1854,27 @@ def get_mesh_charge_density_fp_lovects(level, include_ghosts=True):
return _get_mesh_array_lovects(level, None, include_ghosts, libwarpx.warpx_getChargeDensityFPLoVects)
+def get_mesh_phi_fp_lovects(level, include_ghosts=True):
+ '''
+
+ This returns a list of the lo vectors of the arrays containing the mesh
+ electrostatic potential data on each grid for this process.
+
+ Parameters
+ ----------
+
+ level : the AMR level to get the data for
+ include_ghosts : whether to include ghost zones or not
+
+ Returns
+ -------
+
+ A 2d numpy array of the lo vector for each grid with the shape (dims, number of grids)
+
+ '''
+ return _get_mesh_array_lovects(level, None, include_ghosts, libwarpx.warpx_getPhiFPLoVects)
+
+
def _get_nodal_flag(getdatafunc):
data = getdatafunc()
nodal_flag_ref = np.ctypeslib.as_array(data, (dim,))
@@ -1904,3 +1955,9 @@ def get_Rho_nodal_flag():
This returns a 1d array of the nodal flags for Rho along each direction. A 1 means node centered, and 0 cell centered.
'''
return _get_nodal_flag(libwarpx.warpx_getRho_nodal_flag)
+
+def get_Phi_nodal_flag():
+ '''
+ This returns a 1d array of the nodal flags for Phi along each direction. A 1 means node centered, and 0 cell centered.
+ '''
+ return _get_nodal_flag(libwarpx.warpx_getPhi_nodal_flag)
diff --git a/Python/pywarpx/fields.py b/Python/pywarpx/fields.py
index f7131f326..4afd42bf8 100644
--- a/Python/pywarpx/fields.py
+++ b/Python/pywarpx/fields.py
@@ -441,7 +441,7 @@ class _MultiFABWrapper(object):
"""Sets slices of a decomposed 2D array.
"""
ix = index[0]
- iz = index[2]
+ iz = index[1]
lovects, ngrow = self._getlovects()
hivects, ngrow = self._gethivects()
@@ -461,7 +461,7 @@ class _MultiFABWrapper(object):
ic = None
nx = hivects[0,:].max() - ngrow[0]
- nz = hivects[2,:].max() - ngrow[1]
+ nz = hivects[1,:].max() - ngrow[1]
# --- Add extra dimensions so that the input has the same number of
# --- dimensions as array.
@@ -480,7 +480,7 @@ class _MultiFABWrapper(object):
ixstop = ix + 1
if isinstance(iz, slice):
izstart = max(iz.start or -ngrow[1], -ngrow[1])
- izstop = min(iz.stop or nz + 1 + ngrow[1], nz + self.overlaps[2] + ngrow[1])
+ izstop = min(iz.stop or nz + 1 + ngrow[1], nz + self.overlaps[1] + ngrow[1])
else:
izstart = iz
izstop = iz + 1
@@ -490,13 +490,13 @@ class _MultiFABWrapper(object):
# --- The ix1, 2 etc are relative to global indexing
ix1 = max(ixstart, lovects[0,i])
ix2 = min(ixstop, lovects[0,i] + fields[i].shape[0])
- iz1 = max(izstart, lovects[2,i])
- iz2 = min(izstop, lovects[2,i] + fields[i].shape[2])
+ iz1 = max(izstart, lovects[1,i])
+ iz2 = min(izstop, lovects[1,i] + fields[i].shape[1])
if ix1 < ix2 and iz1 < iz2:
sss = (slice(ix1 - lovects[0,i], ix2 - lovects[0,i]),
- slice(iz1 - lovects[2,i], iz2 - lovects[2,i]))
+ slice(iz1 - lovects[1,i], iz2 - lovects[1,i]))
if ic is not None:
sss = tuple(list(sss) + [ic])
@@ -720,6 +720,14 @@ def RhoFPWrapper(level=0, include_ghosts=False):
get_fabs=_libwarpx.get_mesh_charge_density_fp,
get_nodal_flag=_libwarpx.get_Rho_nodal_flag,
level=level, include_ghosts=include_ghosts)
+
+def PhiFPWrapper(level=0, include_ghosts=False):
+ return _MultiFABWrapper(direction=None,
+ get_lovects=_libwarpx.get_mesh_phi_fp_lovects,
+ get_fabs=_libwarpx.get_mesh_phi_fp,
+ get_nodal_flag=_libwarpx.get_Phi_nodal_flag,
+ level=level, include_ghosts=include_ghosts)
+
def ExCPPMLWrapper(level=1, include_ghosts=False):
assert level>0, Exception('Coarse patch only available on levels > 0')
return _MultiFABWrapper(direction=0,