csdms / bmi-example-python

An example of wrapping a model written in Python with a BMI
https://bmi.csdms.io
MIT License
13 stars 22 forks source link

The set_value function should redimensionalize flattened input array #16

Closed mdpiper closed 3 years ago

mdpiper commented 3 years ago

In this example, the current set_value implementation is:

https://github.com/csdms/bmi-example-python/blob/e6b1e9105daef44fe1f0adba5b857cde1bbd032a/heat/bmi_heat.py#L239-L250

A problem arises when the model variable referenced by get_value_ptr is dimensional--the input src argument is flattened, by definition, while the val variable is dimensional. This raises an exception with a message like

ValueError: could not broadcast input array from shape (48,) into shape (8,6)
mdpiper commented 3 years ago

A solution is to dimensionalize the input argument, so

val[:] = src

becomes

val[:] = src.reshape(val.shape)