Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle writing of empty arrays to preCICE #69

Merged
merged 10 commits into from
Nov 18, 2020
23 changes: 17 additions & 6 deletions precice.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -868,8 +868,12 @@ cdef class Interface:
"""
if not isinstance(values, np.ndarray):
values = np.asarray(values)
size, dimensions = values.shape
assert(dimensions == self.get_dimensions())
if len(values) > 0:
size, dimensions = values.shape
assert(dimensions == self.get_dimensions())
if len(values) == 0:
size = 0

cdef np.ndarray[int, ndim=1] _vertex_ids = np.ascontiguousarray(vertex_ids, dtype=np.int32)
cdef np.ndarray[double, ndim=1] _values = np.ascontiguousarray(values.flatten(), dtype=np.double)
assert(size == _vertex_ids.size)
Expand Down Expand Up @@ -913,8 +917,10 @@ cdef class Interface:
"""
if not isinstance(value, np.ndarray):
value = np.asarray(value)
dimensions = value.size
assert(dimensions == self.get_dimensions())
if len(value) > 0:
dimensions = value.size
assert(dimensions == self.get_dimensions())

IshaanDesai marked this conversation as resolved.
Show resolved Hide resolved
cdef np.ndarray[np.double_t, ndim=1] _value = np.ascontiguousarray(value, dtype=np.double)
self.thisptr.writeVectorData (data_id, vertex_id, <const double*>_value.data)

Expand Down Expand Up @@ -948,8 +954,13 @@ cdef class Interface:
"""
cdef np.ndarray[int, ndim=1] _vertex_ids = np.ascontiguousarray(vertex_ids, dtype=np.int32)
cdef np.ndarray[double, ndim=1] _values = np.ascontiguousarray(values, dtype=np.double)
assert(_values.size == _vertex_ids.size)
size = vertex_ids.size

if len(values) > 0:
assert(_values.size == _vertex_ids.size)
size = vertex_ids.size
if len(values) == 0:
size = 0

self.thisptr.writeBlockScalarData (data_id, size, <const int*>_vertex_ids.data, <const double*>_values.data)

def write_scalar_data (self, data_id, vertex_id, double value):
Expand Down