Error when multiplying with an interpolant

Hi,

I posted a previous question on a similar (but not identical) topic. However the problem here is much more refined, so I may delete the previous one.

I am getting an error when I take the product of an interpolant function with something. But I don’t see any logical reason why this should be a problem. When I do an addition, it works fine. I have provided a MWE below, and the error is:

ValueError: cannot reshape array of size 1 into shape (17,1)

import pybamm
import numpy as np

model = pybamm.BaseModel()

x_p = pybamm.SpatialVariable("x_p", domain="positive electrode", coord_sys="cartesian")
c = pybamm.Variable("c", domain="positive electrode")

L_p = 50e-6 
t_max = 100

x_data = np.linspace(0, L_p, 50)
t_data = np.linspace(0, t_max, 100)

y_data = np.ones((len(x_data), len(t_data))) # arbitrary data to be interpolated

interp_func = pybamm.Interpolant((x_data, t_data), y_data, (x_p, pybamm.t)) # 2d interpolation function, with x and t as inputs

a = c + interp_func # no problem with addition

b = c * interp_func # product throws error

Thanks in advance for your help!

Hey I am facing a similar issue. were you able to solve it?

Hi, no unfortunately I have not solved it yet.

1 Like