I am trying to define arrays as GEKKO params, that will be used with comparison operators such as >, <, >=, != and even within other functions outside the ones shown in the code below. How can I handle such without the TypeError: object of type 'int' has no len() error?. Running the code as shown below, throws the TypeError: object of type 'int' has no len error. Any guidance will be hugely appreciated.
import numpy as np
from scipy import interpolate
from gekko import GEKKO
def check_p_u(u_hub_next):
m = GEKKO(remote=True)
u_hub_next = m.Param(value = u_hub_next)
if 0 <= u_hub_next < 3:
p_u = 0
return p_u
elif 3 <= u_hub_next < 3.5:
p_u = 8
return p_u
elif 3.5 <= u_hub_next < 4.5:
p_u = 10.5
return p_u
else:
return 0.1
def intpolatn(u_hub_next):
m = GEKKO(remote=True)
u_hub_next = m.Param(value = u_hub_next)
windvel = m.Param(np.array([0, 3, 4, 5, 6, 7, 8, 9, 10, 11]))
thrust_coeff = m.Param(np.array([0, 0.88, 0.88, 0.87, 0.87, 0.86, 0.84, 0.79, 0.71, 0.6]))
f = interpolate.interp1d(windvel, thrust_coeff, kind = 'cubic')
if windvel[0] <= u_hub_next < windvel[1]:
m = 0
c_t = 0
axial = 0
p_u = check_p_u(u_hub_next)
u_hub_next = 0
return [u_hub_next, c_t, axial, p_u]
elif windvel[1] <= u_hub_next < windvel[2]:
c_t = f(u_hub_next)
axial = 0.5 * (1 - np.sqrt(1 - c_t))
p_u = check_p_u(u_hub_next)
return [u_hub_next, c_t, axial, p_u]
elif windvel[2] <= u_hub_next < windvel[3]:
c_t = f(u_hub_next)
axial = 0.5 * (1 - np.sqrt(1 - c_t))
p_u = check_p_u(u_hub_next)
return [u_hub_next, c_t, axial, p_u]
elif windvel[3] <= u_hub_next < windvel[4]:
c_t = f(u_hub_next)
axial = 0.5 * (1 - np.sqrt(1 - c_t))
p_u = check_p_u(u_hub_next)
return [u_hub_next, c_t, axial, p_u]
y = intpolatn(3.2)
print(y)
