aboutsummaryrefslogtreecommitdiff
path: root/Python/pywarpx
diff options
context:
space:
mode:
authorGravatar Lorenzo Giacomel <47607756+lgiacome@users.noreply.github.com> 2021-12-14 08:52:09 +0100
committerGravatar GitHub <noreply@github.com> 2021-12-13 23:52:09 -0800
commit6c00c243f986467f3a80ab6a1a5177e7577e7680 (patch)
treeacbe063b4cc4d7a98a185e1a953298af037fab4c /Python/pywarpx
parent6844ef6ad95ce748f9e7f69144fec4e3e4041e72 (diff)
downloadWarpX-6c00c243f986467f3a80ab6a1a5177e7577e7680.tar.gz
WarpX-6c00c243f986467f3a80ab6a1a5177e7577e7680.tar.zst
WarpX-6c00c243f986467f3a80ab6a1a5177e7577e7680.zip
Adding EB multifabs to the Python interface (#2647)
* Adding edge_lengths and face_areas to the Python interface * Added wrappers for the two new arrays of data * Adding a CI test * Fixed test name * Added customRunCmd * Added mpi in test
Diffstat (limited to 'Python/pywarpx')
-rwxr-xr-xPython/pywarpx/_libwarpx.py145
-rw-r--r--Python/pywarpx/fields.py42
2 files changed, 187 insertions, 0 deletions
diff --git a/Python/pywarpx/_libwarpx.py b/Python/pywarpx/_libwarpx.py
index e32dc239d..6850e1b28 100755
--- a/Python/pywarpx/_libwarpx.py
+++ b/Python/pywarpx/_libwarpx.py
@@ -214,6 +214,10 @@ libwarpx.warpx_getGfieldCP_PML.restype = _LP_LP_c_real
libwarpx.warpx_getGfieldCPLoVects_PML.restype = _LP_c_int
libwarpx.warpx_getGfieldFP_PML.restype = _LP_LP_c_real
libwarpx.warpx_getGfieldFPLoVects_PML.restype = _LP_c_int
+libwarpx.warpx_getEdgeLengths.restype = _LP_LP_c_real
+libwarpx.warpx_getEdgeLengthsLoVects.restype = _LP_c_int
+libwarpx.warpx_getFaceAreas.restype = _LP_LP_c_real
+libwarpx.warpx_getFaceAreasLoVects.restype = _LP_c_int
libwarpx.warpx_getParticleBoundaryBufferSize.restype = ctypes.c_int
libwarpx.warpx_getParticleBoundaryBufferStructs.restype = _LP_LP_c_particlereal
libwarpx.warpx_getParticleBoundaryBuffer.restype = _LP_LP_c_particlereal
@@ -234,6 +238,12 @@ libwarpx.warpx_getF_nodal_flag.restype = _LP_c_int
libwarpx.warpx_getG_nodal_flag.restype = _LP_c_int
libwarpx.warpx_getF_pml_nodal_flag.restype = _LP_c_int
libwarpx.warpx_getG_pml_nodal_flag.restype = _LP_c_int
+libwarpx.warpx_get_edge_lengths_x_nodal_flag.restype = _LP_c_int
+libwarpx.warpx_get_edge_lengths_y_nodal_flag.restype = _LP_c_int
+libwarpx.warpx_get_edge_lengths_z_nodal_flag.restype = _LP_c_int
+libwarpx.warpx_get_face_areas_x_nodal_flag.restype = _LP_c_int
+libwarpx.warpx_get_face_areas_y_nodal_flag.restype = _LP_c_int
+libwarpx.warpx_get_face_areas_z_nodal_flag.restype = _LP_c_int
#libwarpx.warpx_getPMLSigma.restype = _LP_c_real
#libwarpx.warpx_getPMLSigmaStar.restype = _LP_c_real
@@ -1753,6 +1763,60 @@ def get_mesh_G_fp_pml(level, include_ghosts=True):
raise Exception('PML not initialized')
+def get_mesh_edge_lengths(level, direction, include_ghosts=True):
+ '''
+
+ This returns a list of numpy arrays containing the mesh edge lengths
+ data on each grid for this process. This version returns the density 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
+ direction : the component of the data you want
+ include_ghosts : whether to include ghost zones or not
+
+ Returns
+ -------
+
+ A List of numpy arrays.
+
+ '''
+
+ return _get_mesh_field_list(libwarpx.warpx_getEdgeLengths, level, direction, include_ghosts)
+
+
+def get_mesh_face_areas(level, direction, include_ghosts=True):
+ '''
+
+ This returns a list of numpy arrays containing the mesh face areas
+ data on each grid for this process. This version returns the density 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
+ direction : the component of the data you want
+ include_ghosts : whether to include ghost zones or not
+
+ Returns
+ -------
+
+ A List of numpy arrays.
+
+ '''
+
+ return _get_mesh_field_list(libwarpx.warpx_getFaceAreas, level, direction, include_ghosts)
+
+
def _get_mesh_array_lovects(level, direction, include_ghosts=True, getlovectsfunc=None):
assert(0 <= level and level <= libwarpx.warpx_finestLevel())
@@ -2378,6 +2442,51 @@ def get_mesh_G_fp_lovects_pml(level, include_ghosts=True):
except ValueError:
raise Exception('PML not initialized')
+
+def get_mesh_edge_lengths_lovects(level, direction, include_ghosts=True):
+ '''
+
+ This returns a list of the lo vectors of the arrays containing the mesh edge lengths
+ data on each grid for this process.
+
+ Parameters
+ ----------
+
+ level : the AMR level to get the data for
+ direction : the component of the data you want
+ 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, direction, include_ghosts, libwarpx.warpx_getEdgeLengthsLoVects)
+
+
+def get_mesh_face_areas_lovects(level, direction, include_ghosts=True):
+ '''
+
+ This returns a list of the lo vectors of the arrays containing the mesh face areas
+ data on each grid for this process.
+
+ Parameters
+ ----------
+
+ level : the AMR level to get the data for
+ direction : the component of the data you want
+ 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, direction, include_ghosts, libwarpx.warpx_getFaceAreasLoVects)
+
+
def _get_nodal_flag(getdatafunc):
data = getdatafunc()
if not data:
@@ -2480,6 +2589,42 @@ def get_G_nodal_flag():
'''
return _get_nodal_flag(libwarpx.warpx_getG_nodal_flag)
+def get_edge_lengths_x_nodal_flag():
+ '''
+ This returns a 1d array of the nodal flags for the x edge lengths along each direction. A 1 means node centered, and 0 cell centered.
+ '''
+ return _get_nodal_flag(libwarpx.warpx_get_edge_lengths_x_nodal_flag)
+
+def get_edge_lengths_y_nodal_flag():
+ '''
+ This returns a 1d array of the nodal flags for the y edge lengths along each direction. A 1 means node centered, and 0 cell centered.
+ '''
+ return _get_nodal_flag(libwarpx.warpx_get_edge_lengths_y_nodal_flag)
+
+def get_edge_lengths_z_nodal_flag():
+ '''
+ This returns a 1d array of the nodal flags for the z edge lengths along each direction. A 1 means node centered, and 0 cell centered.
+ '''
+ return _get_nodal_flag(libwarpx.warpx_get_edge_lengths_z_nodal_flag)
+
+def get_face_areas_x_nodal_flag():
+ '''
+ This returns a 1d array of the nodal flags for the x face areas along each direction. A 1 means node centered, and 0 cell centered.
+ '''
+ return _get_nodal_flag(libwarpx.warpx_get_face_areas_x_nodal_flag)
+
+def get_face_areas_y_nodal_flag():
+ '''
+ This returns a 1d array of the nodal flags for the y face areas along each direction. A 1 means node centered, and 0 cell centered.
+ '''
+ return _get_nodal_flag(libwarpx.warpx_get_face_areas_y_nodal_flag)
+
+def get_face_areas_z_nodal_flag():
+ '''
+ This returns a 1d array of the nodal flags for the z face areas along each direction. A 1 means node centered, and 0 cell centered.
+ '''
+ return _get_nodal_flag(libwarpx.warpx_get_face_areas_z_nodal_flag)
+
def get_F_pml_nodal_flag():
'''
This returns a 1d array of the nodal flags for F in the PML along each direction. A 1 means node centered, and 0 cell centered.
diff --git a/Python/pywarpx/fields.py b/Python/pywarpx/fields.py
index 612ea32c0..cb63a8af4 100644
--- a/Python/pywarpx/fields.py
+++ b/Python/pywarpx/fields.py
@@ -682,6 +682,48 @@ def GFPWrapper(level=0, include_ghosts=False):
get_nodal_flag=_libwarpx.get_G_nodal_flag,
level=level, include_ghosts=include_ghosts)
+def EdgeLengthsxWrapper(level=0, include_ghosts=False):
+ return _MultiFABWrapper(direction=0,
+ get_lovects=_libwarpx.get_mesh_edge_lengths_lovects,
+ get_fabs=_libwarpx.get_mesh_edge_lengths,
+ get_nodal_flag=_libwarpx.get_edge_lengths_x_nodal_flag,
+ level=level, include_ghosts=include_ghosts)
+
+def EdgeLengthsyWrapper(level=0, include_ghosts=False):
+ return _MultiFABWrapper(direction=1,
+ get_lovects=_libwarpx.get_mesh_edge_lengths_lovects,
+ get_fabs=_libwarpx.get_mesh_edge_lengths,
+ get_nodal_flag=_libwarpx.get_edge_lengths_y_nodal_flag,
+ level=level, include_ghosts=include_ghosts)
+
+def EdgeLengthszWrapper(level=0, include_ghosts=False):
+ return _MultiFABWrapper(direction=2,
+ get_lovects=_libwarpx.get_mesh_edge_lengths_lovects,
+ get_fabs=_libwarpx.get_mesh_edge_lengths,
+ get_nodal_flag=_libwarpx.get_edge_lengths_z_nodal_flag,
+ level=level, include_ghosts=include_ghosts)
+
+def FaceAreasxWrapper(level=0, include_ghosts=False):
+ return _MultiFABWrapper(direction=0,
+ get_lovects=_libwarpx.get_mesh_face_areas_lovects,
+ get_fabs=_libwarpx.get_mesh_face_areas,
+ get_nodal_flag=_libwarpx.get_face_areas_x_nodal_flag,
+ level=level, include_ghosts=include_ghosts)
+
+def FaceAreasyWrapper(level=0, include_ghosts=False):
+ return _MultiFABWrapper(direction=1,
+ get_lovects=_libwarpx.get_mesh_face_areas_lovects,
+ get_fabs=_libwarpx.get_mesh_face_areas,
+ get_nodal_flag=_libwarpx.get_face_areas_y_nodal_flag,
+ level=level, include_ghosts=include_ghosts)
+
+def FaceAreaszWrapper(level=0, include_ghosts=False):
+ return _MultiFABWrapper(direction=2,
+ get_lovects=_libwarpx.get_mesh_face_areas_lovects,
+ get_fabs=_libwarpx.get_mesh_face_areas,
+ get_nodal_flag=_libwarpx.get_face_areas_z_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,