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

Improved error messages for bindings #9

Merged
merged 11 commits into from
Apr 6, 2021
25 changes: 13 additions & 12 deletions cyprecice/cyprecice.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ cdef class Interface:

if len(position) > 0:
dimensions = len(position)
assert(dimensions == self.get_dimensions())
assert dimensions == self.get_dimensions(), "Dimensions of vertex coordinate in set_mesh_vertex does not match with dimensions in problem definition. Provided dimensions: {}, expected dimensions: {}".format(dimensions, self.get_dimensions())
elif len(position) == 0:
dimensions = self.get_dimensions()

Expand Down Expand Up @@ -530,7 +530,7 @@ cdef class Interface:

if len(positions) > 0:
size, dimensions = positions.shape
assert(dimensions == self.get_dimensions())
assert dimensions == self.get_dimensions(), "Dimensions of vertex coordinates in set_mesh_vertices does not match with dimensions in problem definition. Provided dimensions: {}, expected dimensions: {}".format(dimensions, self.get_dimensions())
elif len(positions) == 0:
size = positions.shape[0]
dimensions = self.get_dimensions()
Expand Down Expand Up @@ -640,7 +640,7 @@ cdef class Interface:

if len(positions) > 0:
size, dimensions = positions.shape
assert(dimensions == self.get_dimensions())
assert dimensions == self.get_dimensions(), "Dimensions of position coordinates in get_mesh_vertex_ids_from_positions does not match with dimensions in problem definition. Provided dimensions: {}, expected dimensions: {}".format(dimensions, self.get_dimensions())
elif len(positions) == 0:
size = positions.shape[0]
dimensions = self.get_dimensions()
Expand Down Expand Up @@ -892,15 +892,15 @@ cdef class Interface:

if len(values) > 0:
size, dimensions = values.shape
assert(dimensions == self.get_dimensions())
assert dimensions == self.get_dimensions(), "Dimensions of vector data in write_block_vector_data does not match with dimensions in problem definition. Provided dimensions: {}, expected dimensions: {}".format(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(_values.size == size * self.get_dimensions())
assert(_vertex_ids.size == size)
assert _values.size == size * self.get_dimensions(), "Vector data is not provided for all vertices in write_block_vector_data. Check length of input data provided. Provided size: {}, expected size: {}".format(_values.size, size * self.get_dimensions())
assert _vertex_ids.size == size, "Vertex IDs are of incorrect length in write_block_vector_data. Check length of vertex ids input. Provided size: {}, expected size: {}".format(_vertex_ids.size, size)

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

Expand Down Expand Up @@ -941,11 +941,14 @@ cdef class Interface:
>>> interface.write_vector_data(data_id, vertex_id, value)
"""
check_array_like(value, "value", "write_vector_data")
assert len(value) > 0, "Input vector data is empty in write_vector_data"

assert(len(value) > 0)
dimensions = len(value)
assert(dimensions == self.get_dimensions())

assert dimensions == self.get_dimensions(), "Dimensions of vector data in write_vector_data does not match with dimensions in problem definition. Provided dimensions: {}, expected dimensions: {}".format(dimensions, self.get_dimensions())

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)

def write_block_scalar_data (self, data_id, vertex_ids, values):
Expand Down Expand Up @@ -985,13 +988,11 @@ cdef class Interface:
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, dtype=np.double)

assert(_values.size == size)
assert(_vertex_ids.size == size)

assert _values.size == size, "Scalar data is not provided for all vertices in write_block_scalar_data. Check size of input data provided. Provided size: {}, expected size: {}".format(_values.size, size)
assert _vertex_ids.size == size, "Vertex IDs are of incorrect length in write_block_scalar_data. Check size of vertex ids input. Provided size: {}, expected size: {}".format(_vertex_ids.size, size)
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