【发布时间】:2021-09-17 11:12:39
【问题描述】:
我尝试为 apmonitor 网站上动态优化课程的建模 (https://apmonitor.com/do/index.php/Main/ModelFormulation) 部分提供油藏模拟的动态模拟进行编码。代码如下:
from gekko import GEKKO
import numpy as np
import matplotlib.pyplot as plt
m = GEKKO()
#time variable initialization
m.time = np.linspace(0,1,13)
Vf_in= [0, 0, 0, 0]
#define constants
#Area of Reservoir / Lake (km2)
areas =np.array([13.4, 12.0, 384.5, 4400])
#Initial Volume of Reservoir / Lake (km3)
volumes = np.array([0.26, 0.18, 0.68, 22.0])
#flow coefficient
c_out = np.array([0.03, 0.015, 0.06, 0])
h0 = 1000*(volumes/areas)
Vout0 = c_out*np.sqrt(h0)
print("Vout0", Vout0)
#rate of consumption
Vuse = [0.03, 0.05, 0.02,0.00]
#inlet flow rate
Vfi_1 = [0.13, 0.13, 0.13, 0.21, 0.21, 0.21, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13]
#parameter
Vf_in[0] = m.Param(value = V_fi1)
A = [m.Param(value =i) for i in areas]
c_ev = [m.Param(value = 1e-5) for i in range(4)]
c_ev[3] = 0.5e-5
print("C_ev", c_ev)
c_f = [m.Param (value = i) for i in c_out]
#variables
h = [m.Var(value = i) for i in h0]
V = [m.Var(value = i) for i in volumes]
Vout = [m.Var(value = i) for i in Vout0]
print("volumes", V)
print("Heights", h)
#intermediates
Vf_in[1:4] = [m.Intermediate(Vout[i]) for i in range(3)]
V_ev = [m.Intermediate(c_ev[i]*A[i]) for i in range(4)]
#equations
m.Equation([V[i].dt() == Vf_in[i] - Vout[i] - V_ev[i] - Vuse[i] for i in range(4)])
m.Equation([h[i] == 1000*(V[i]/A[i]) for i in range(4)])
m.Equation(Vout[i]**2 == c_f[i]**2 *h[i] for i in range(4))
m.options.IMODE = 4
m.solve(disp = False)
time = [x*12 for x in m.time]
plt.figure()
plt.plot(time, h1.value, label = 'h1')
plt.plot(time, h2.value, label = 'h2')
plt.plot(time, h3.value, label = 'h3')
plt.plot(time, h4.value, label = 'h4')
plt.xlabel('time (in months)')
plt.ylabel('height in metres')
plt.legend(loc = 'best')
plt.show()
我遇到了下面给出的错误:
Exception: @error: Inequality Definition
invalid inequalities: z > x < y
<generatorobject<genexpr>at0x000001655c7ad900>
STOPPING . . .
任何帮助将不胜感激。谢谢!
【问题讨论】: