简体   繁体   English

用 Gekko 求解偏微分方程的问题 Python

[英]Problem on solving Partial Differential Equations with Gekko Python

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 2 pi r*v(r)*dr.在我的代码中,我想通过积分 2 pi r*v(r)*dr 来计算随时间变化的体积流量。 I have used scipy.integrate.trapz to solve this inside the code m.GEKKO().我在代码 m.GEKKO() 中使用 scipy.integrate.trapz 来解决这个问题。

I want to have a graph of Qgap vs time.我想要一张 Qgap 与时间的关系图。 When I execute the code, I get a single Qgap value in the solution.当我执行代码时,我在解决方案中获得了一个 Qgap 值。

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.所有的细节都可以通过 Sujuan Jiao 等人的这篇文章<<用剪切稀化流体对液压阻尼器进行建模以进行阻尼机制分析>> 轻松找到。

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.速度分布由 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)

Although the problem solves successfully:虽然问题成功解决:

 Iter    Objective  Convergence
   50  6.52927E-21  1.43369E-03
 Successful solution
 
 ---------------------------------------------------
 Solver         :  APOPT (v1.0)
 Solution time  :    36.8693000000021      sec
 Objective      :   0.000000000000000E+000
 Successful solution
 ---------------------------------------------------

It is not using the scipy.integrate.trapz() function inside the Gekko model. Gekko builds a symbolic model. See gk0_model.apm in m.path or use m.open_folder() to open the run folder.它没有使用 Gekko model 内部的scipy.integrate.trapz() function。Gekko 构建了一个符号 model。请参阅gk0_model.apm中的m.path或使用m.open_folder()打开运行文件夹。

There is an m.integral() function in gekko, but this integrates with respect to time.在 gekko 中有一个m.integral() function,但它是在时间上积分的。 You likely need to write out the collocation equations or the integral in Gekko equation form.您可能需要以 Gekko 方程形式写出 配置方程或积分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM