本文介绍了Gekko和CoolProp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用GEKKO和CoolProp进行热系统仿真.尝试在模型方程式中使用CoolProp的函数时(如下图所示,等熵展开),我收到有关变量类型的错误消息:"必须是实数,而不是GKVariable ".有人可以帮我解决这个问题吗?
I'm using GEKKO and CoolProp for thermal systems simulation. When trying to use CoolProp's functions inside the model equations (as shown below for an isentropic expansion) I'm getting an error message regarding the variable type:"must be real number, not GKVariable".Could someone please help me with this issue?
from gekko import GEKKO
import CoolProp.CoolProp as CP
#
p1 = 2e5
T1 = 300.0 + 273.15
p2 = 1e5
eta = 0.80
fluid = 'H2O'
#
h1 = CP.PropsSI('H','T',T1,'P',p1,fluid)
s1 = CP.PropsSI('S','T',T1,'P',p1,fluid)
#
m = GEKKO()
h2 = m.Var()
h2s = m.Var()
T2 = m.Var()
#
m.Equation(eta * (h1 - h2) - (h1 - h2s) == 0)
m.Equation(h2s - CP.PropsSI('H','S',s1,'P',p2,fluid) == 0)
m.Equation(h2 - CP.PropsSI('H','T',T2,'P',p2,fluid) == 0)
#
m.options.IMODE = 1 #Steady state
m.options.SOLVER = 3 # solver (IPOPT)
m.solve(disp=False)
#
print(T2.value[0])
谢谢.
推荐答案
Gekko需要具有CoolProp方程来执行自动微分.如果没有方程式,则可以使用cspline
(三次样条文档).
Gekko needs to have the CoolProp equations to perform automatic differentiation. If it doesn't have the equation then you could use a cspline
(cubic spline documentation).
from gekko import GEKKO
import CoolProp.CoolProp as CP
import numpy as np
#
p1 = 2e5
T1 = 300.0 + 273.15
p2 = 1e5
eta = 0.80
fluid = 'H2O'
# constants
h1 = CP.PropsSI('H','T',T1,'P',p1,fluid)
s1 = CP.PropsSI('S','T',T1,'P',p1,fluid)
c2 = CP.PropsSI('H','S',s1,'P',p2,fluid)
# gekko model
m = GEKKO(remote=False)
h2 = m.Var()
h2s = m.Var()
T2 = m.Var()
# build cubic spline
n = 100
T = np.linspace(373,1000,100)
h = [CP.PropsSI('H','T',Ti,'P',p1,fluid) for Ti in T]
m.cspline(T2,h2,T,h)
#
m.Equation(eta * (h1 - h2) - (h1 - h2s) == 0)
m.Equation(h2s - c2 == 0)
#
m.options.IMODE = 1 #Steady state
m.options.SOLVER = 3 # solver (IPOPT)
m.solve(disp=False)
#
print(T2.value[0])
这将产生解决方案:
T2 = 468.52459939
这篇关于Gekko和CoolProp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!