Dear Gekko experts,
I'm trying to convert some legacy functions (often liquid properties) to Gekko in order to use them in process simulation/optimization models.
Usually, such old functions contain many helper variables, loops, if..else's etc.
I have tried to convert them to Gekko with as few changes as possible, using Gekko's 'if2' object as a replacement for the normal if..else parts.
I'm unsure if such an approach is really helpful/efficient...
1.) How does Gekko handle all those helper variables that are used inside the function definitions? Do I have to use Gekko intermediate variables (in order not to clutter the actual model with those helper variables)?
2.) Is there an elegant way in Gekko to handle conditional statements (with several expressions in each block) like this:
def my_function(A, B):
if A>B:
aux1 = ....
aux2 = .....
return( some expression involving aux1, aux2 etc. )
else:
aux3 = ....
aux4 = ....
return( some expression involving aux3, aux4 etc. )
3.) Sometimes functions are not obviously translated into Gekko... then Gekko's cspline or bspline objects seem helpful. However, they seem to establish fixed links between variables... Is there a way to wrap these objects in a function which can be easily called several times within a model? Something like:
TempRange = list(range(-15,145,5))
CpRange = [4.29403, 4.25688, 4.23358, 4.21944, 4.20495, 4.19545, 4.1891, 4.1848, 4.1819, 4.18002, 4.17895, 4.17886, 4.17877, 4.17956, 4.18089, 4.18277, 4.18517, 4.1881, 4.19155, 4.19552, 4.20001, 4.20502, 4.21057, 4.21664, 4.22323, 4.23036, 4.23807, 4.24637, 4.25528, 4.26484, 4.27508, 4.28604]
#cp_water_interp = scipy.interpolate.interp1d(TempRange, CpRange)
def heat_capacity_water(T_degC):
m.cspline(T_degC, cp_water, TempRange, CpRange)
return(cp_water)
Thanks for your patience and any hint...
Thomas