aboutsummaryrefslogtreecommitdiff
path: root/Python
diff options
context:
space:
mode:
Diffstat (limited to 'Python')
-rwxr-xr-xPython/pywarpx/_libwarpx.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Python/pywarpx/_libwarpx.py b/Python/pywarpx/_libwarpx.py
index 9ebbd262f..d80a1915f 100755
--- a/Python/pywarpx/_libwarpx.py
+++ b/Python/pywarpx/_libwarpx.py
@@ -136,6 +136,8 @@ _LP_LP_c_char = ctypes.POINTER(_LP_c_char)
# this is a function for converting a ctypes pointer to a numpy array
def _array1d_from_pointer(pointer, dtype, size):
+ if not pointer:
+ raise Exception(f'_array1d_from_pointer: pointer is a nullptr')
if sys.version_info.major >= 3:
# from where do I import these? this might only work for CPython...
#PyBuf_READ = 0x100
@@ -559,6 +561,8 @@ def get_particle_structs(species_name, level):
particle_data = []
for i in range(num_tiles.value):
+ if particles_per_tile[i] == 0:
+ continue
arr = _array1d_from_pointer(data[i], _p_dtype, particles_per_tile[i])
particle_data.append(arr)
@@ -599,6 +603,10 @@ def get_particle_arrays(species_name, comp_name, level):
particle_data = []
for i in range(num_tiles.value):
+ if particles_per_tile[i] == 0:
+ continue
+ if not data[i]:
+ raise Exception(f'get_particle_arrays: data[i] for i={i} was not initialized')
arr = np.ctypeslib.as_array(data[i], (particles_per_tile[i],))
try:
# This fails on some versions of numpy
@@ -896,6 +904,8 @@ def get_particle_boundary_buffer_structs(species_name, boundary, level):
particle_data = []
for i in range(num_tiles.value):
+ if particles_per_tile[i] == 0:
+ continue
arr = _array1d_from_pointer(data[i], _p_dtype, particles_per_tile[i])
particle_data.append(arr)
@@ -949,6 +959,10 @@ def get_particle_boundary_buffer(species_name, boundary, comp_name, level):
particle_data = []
for i in range(num_tiles.value):
+ if particles_per_tile[i] == 0:
+ continue
+ if not data[i]:
+ raise Exception(f'get_particle_arrays: data[i] for i={i} was not initialized')
arr = np.ctypeslib.as_array(data[i], (particles_per_tile[i],))
try:
# This fails on some versions of numpy
@@ -989,6 +1003,10 @@ def _get_mesh_field_list(warpx_func, level, direction, include_ghosts):
for i in range(size.value):
shape = tuple([shapes[shapesize*i + d] for d in range(shapesize)])
# --- The data is stored in Fortran order, hence shape is reversed and a transpose is taken.
+ if shape[::-1] == 0:
+ continue
+ if not data[i]:
+ raise Exception(f'get_particle_arrays: data[i] for i={i} was not initialized')
arr = np.ctypeslib.as_array(data[i], shape[::-1]).T
try:
# This fails on some versions of numpy