我正在试图找出使重力排水水箱保持在所需液位的入口流量的值.在使用Imode3找到解决方案后,我想使用Imode4在一段时间内模拟处于这种状态的系统.以下是我正在使用的代码:
from gekko import GEKKO
import numpy as np
m = GEKKO(remote = False)
F_in = m.MV(value = 1, name= 'F_in')
level = m.CV(value = 1, name = 'level')
F_out = m.Var(value = 1, name = 'F_out')
level.STATUS = 1
level.SPHI = 6
level.SPLO = 4
m.Equation(level.dt() == (F_in - F_out)/5)
m.Equation(F_out == 2*(level)**0.5)
# Find the steady state.
F_in.STATUS = 1
m.options.IMODE = 3
m.options.SOLVER = 3
m.solve(disp = False)
print(F_in.value)
# Run at steady state for 5 time units.
F_in.STATUS = 0 # Turn STATUS off for 0 DOF.
m.time = np.linspace(0,5,10)
m.options.IMODE = 4
m.solve(disp = False)
print(level.value)
但是,代码会产生错误,指出Imode4需要0个自由度.将F_in状态更改为0是否不会导致0 DOF?以下是完整的错误消息:
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
Cell In[4], line 27
25 m.time = np.linspace(0,5,10)
26 m.options.IMODE = 4
---> 27 m.solve(disp = False)
28 print(level.value)
File ~\VRMEng\VRMEng\Lib\site-packages\gekko\gekko.py:2140, in GEKKO.solve(self, disp, debug, GUI, **kwargs)
2138 print("Error:", errs)
2139 if (debug >= 1) and record_error:
-> 2140 raise Exception(apm_error)
2142 else: #solve on APM server
2143 def send_if_exists(extension):
Exception: @error: Degrees of Freedom
* Error: DOF must be zero for this mode
STOPPING...
任何帮助我们都将不胜感激!