用Gekko Python求解部分微分方程的问题
我在尝试求解下面附加的部分微分方程时得到了收敛的解决方案。
在我的代码中,我想通过集成2 pi r*v(r)*DR来计算量流量。我已经使用scipy.integrate.trapz在Code M.Gekko()中解决此问题。
我想拥有QGAP与时间的图。执行代码时,我会在解决方案中获得一个QGAP值。
请帮我。
所有细节都可以通过本文轻松找到,与剪切稀释流体进行液压阻尼器的建模,用于阻尼机理分析>>> Sujuan Jiao等人作者。
速度曲线由R1和R1+Delta之间的100点离散,而BC在R1 = U(活塞速度)和壁时为0。
from gekko import GEKKO
import numpy as np
import matplotlib.pyplot as plt
import scipy.integrate
amp=10e-2
freq=10
tf = 2/freq
omega=2*np.pi*freq
npt = 101
time = np.linspace(0,tf,npt)
xglob=amp*np.sin(omega*time)
uglob=amp*omega*np.cos(omega*time)
delta=0.007
npx=100
dx=np.float32(delta/npx)
r1=0.01
r2=0.004
xpos = np.linspace(r1,r1+delta,npx)
Ap=np.pi*(r1**2-r2**2)
rho=850
beta=5e8
L=0.06
l=0.01
pressf=12*amp*0.707*uglob\
*np.cos(2*np.pi*freq*time)/(delta**2)\
*630*(1+(0.05*(0.707*uglob/delta)**2))**(-0.23)
m = GEKKO()
def Q(r,v):
Q=(2*np.pi*r*np.transpose(np.array(v)))
return scipy.integrate.trapz(Q,r)
m.time = time
t=m.Param(m.time)
x=m.MV(ub=amp+1)
x.value=np.ones(npt)*xglob
u=m.MV(ub=10)
u.value=np.ones(npt)*uglob
pf=m.MV(lb=20)
pf.value=np.ones(npt)*pressf
u1=[m.Var(1) for i in range(npx)]
p1=m.Var(800000)
p2=m.Var(800000)
Qgap=Q(xpos,u1)
m.Equation(u1[0].dt()==-1*(p1-p2+pf)/l \
+ ((630 * (1+(0.05*((u-u1[0])/dx))**2)**(-0.23))/rho)\
*((u-2*u1[0]+u1[1])/(dx*dx)))
m.Equations([(u1[i].dt()==-1*(p1-p2+pf)/l \
+ ((630 * (1+(0.05*((u1[i+1]-u1[i-1])/(2*dx)))**2)**(-0.23))/rho)\
*((u1[i+1]-2*u1[i]+u1[i-1])/(dx*dx))) for i in range(1,npx-1)])
m.Equation(u1[-1].dt()==-1*(p1-p2+pf)/l \
+ (((630 * (1+(0.05*((u1[-1]-0)/dx))**2)**(-0.23)))/rho)\
*((u1[-2]-2*u1[-1]+0)/(dx*dx)))
m.Equation(p1.dt()==(beta/(Ap*(L-x)))*(-Qgap+Ap*u))
m.Equation(p2.dt()==(beta/(Ap*(L+x)))*(Qgap-Ap*u))
# simulation
m.options.IMODE = 4
m.options.solver=1
m.options.nodes=3
m.solve(disp=True)
I get a converging solution while trying to solve a Partial Differential Equation attached below.
In my code, I want to calculate a volume flow rate over time by integrating 2pir*v(r)*dr . I have used scipy.integrate.trapz to solve this inside the code m.GEKKO().
I want to have a graph of Qgap vs time. When I execute the code, I get a single Qgap value in the solution.
Please help me.
All the details can be easily found through this article <<Modeling of a hydraulic damper with shear thinning fluid for damping mechanism analysis>> by Sujuan Jiao et al.
The velocity profile is discretised by 100 points in space between r1 and r1+delta with BC at r1=u (piston velocity) and 0 at the wall.
from gekko import GEKKO
import numpy as np
import matplotlib.pyplot as plt
import scipy.integrate
amp=10e-2
freq=10
tf = 2/freq
omega=2*np.pi*freq
npt = 101
time = np.linspace(0,tf,npt)
xglob=amp*np.sin(omega*time)
uglob=amp*omega*np.cos(omega*time)
delta=0.007
npx=100
dx=np.float32(delta/npx)
r1=0.01
r2=0.004
xpos = np.linspace(r1,r1+delta,npx)
Ap=np.pi*(r1**2-r2**2)
rho=850
beta=5e8
L=0.06
l=0.01
pressf=12*amp*0.707*uglob\
*np.cos(2*np.pi*freq*time)/(delta**2)\
*630*(1+(0.05*(0.707*uglob/delta)**2))**(-0.23)
m = GEKKO()
def Q(r,v):
Q=(2*np.pi*r*np.transpose(np.array(v)))
return scipy.integrate.trapz(Q,r)
m.time = time
t=m.Param(m.time)
x=m.MV(ub=amp+1)
x.value=np.ones(npt)*xglob
u=m.MV(ub=10)
u.value=np.ones(npt)*uglob
pf=m.MV(lb=20)
pf.value=np.ones(npt)*pressf
u1=[m.Var(1) for i in range(npx)]
p1=m.Var(800000)
p2=m.Var(800000)
Qgap=Q(xpos,u1)
m.Equation(u1[0].dt()==-1*(p1-p2+pf)/l \
+ ((630 * (1+(0.05*((u-u1[0])/dx))**2)**(-0.23))/rho)\
*((u-2*u1[0]+u1[1])/(dx*dx)))
m.Equations([(u1[i].dt()==-1*(p1-p2+pf)/l \
+ ((630 * (1+(0.05*((u1[i+1]-u1[i-1])/(2*dx)))**2)**(-0.23))/rho)\
*((u1[i+1]-2*u1[i]+u1[i-1])/(dx*dx))) for i in range(1,npx-1)])
m.Equation(u1[-1].dt()==-1*(p1-p2+pf)/l \
+ (((630 * (1+(0.05*((u1[-1]-0)/dx))**2)**(-0.23)))/rho)\
*((u1[-2]-2*u1[-1]+0)/(dx*dx)))
m.Equation(p1.dt()==(beta/(Ap*(L-x)))*(-Qgap+Ap*u))
m.Equation(p2.dt()==(beta/(Ap*(L+x)))*(Qgap-Ap*u))
# simulation
m.options.IMODE = 4
m.options.solver=1
m.options.nodes=3
m.solve(disp=True)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尽管该问题成功地解决了:
它没有使用
scipy.integrate.trapz()
函数在Gekko模型中。 Gekko构建了符号模型。请参阅gk0_model.apm
在M.Path
中或使用m.open_folder()
打开运行文件夹。Gekko中有一个
M.Integral()
函数,但这与时间集成在一起。您可能需要写出“ noreferrer”> colotaration equacations 或Gekko方程式中不可或缺。Although the problem solves successfully:
It is not using the
scipy.integrate.trapz()
function inside the Gekko model. Gekko builds a symbolic model. Seegk0_model.apm
inm.path
or usem.open_folder()
to open the run folder.There is an
m.integral()
function in gekko, but this integrates with respect to time. You likely need to write out the collocation equations or the integral in Gekko equation form.