解决1D Navier Stokes具有可压缩质量保护(液压阻尼器)的问题

发布于 2025-01-28 11:29:55 字数 2282 浏览 2 评论 0原文

我想在圆柱施加的管(笛卡尔山脉)上求解一个1D Navier方程。

沿y方向的流动为p1,右腔室最初都在8e5 pa处。圆柱壁是固定的,宽度'L'的活塞正在用A移动位移x = asin(omega t)给定u = a omega cos(omega t)的速度,我怀疑会给我一个错误。

沿间隙的速度轮廓为U1,在X空间中离散。沿Y沿Y的压力变化假定PF的线性DP/DY =(P1-P2+PF)/L是由于间隙上的摩擦而导致的压力损失。

from gekko import GEKKO
import numpy as np
import matplotlib.pyplot as plt
import scipy.integrate

amp=10e-3
freq=10
tf = 2/freq
omega=2*np.pi*freq
npt = 101
time = np.linspace(0.25/freq,tf,npt)

xglob=amp*np.sin(omega*time)
uglob=amp*omega*np.cos(omega*time)

delta=0.007
npx=101
dx=np.float32(delta/(npx-1))

r1=0.01
r2=0.004
xpos = np.float32(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()

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(0) for i in range(npx)]
p1=m.Var(800000)
p2=m.Var(800000)

# mu.value[:]=(630 * (1+(0.05*(dudx[:]))**2)**(-0.23))
# mu=m.Intermediate(630 * (1+(0.05*(dudx))**2)**(-0.23))

Qgap=m.Var(value=0)

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(Qgap==scipy.integrate.trapz(2*np.pi*xpos*np.array(u1)))

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)

但是我没有得到理想的结果。速度U1收敛良好。 QGAP具有方便的值。压力P1和P2没有必要的。

从物理意义上讲,P1应从8E5增加到一定值,然后降低到8e5以下,导致P2进行相反的情况。 但是,在运行代码并将P1和P2绘制时,它表明它们都有正弦变化,但P2> p1。

请帮我。

I would like to solve a 1D Navier equation on a cylindrical imposed tubes(cartesian cordinates).
A simple Hydraulic Damper

The flow is along y direction, with right chamber having pressure p1 and left chamber pressure p2 both initially at 8e5 Pa. The Cylindrical wall is stationary, and the piston of width 'l' is moving with a displacement x=asin(omegat) given a velocity of u=aomegacos(omegat) which I doubt to give me an error.

The velocity profile along the gap is u1, discretised in x space. Pressure variation along y is assumed linear dp/dy=(p1-p2+pf)/l with pf is pressure loss due to friction on the gap.

from gekko import GEKKO
import numpy as np
import matplotlib.pyplot as plt
import scipy.integrate

amp=10e-3
freq=10
tf = 2/freq
omega=2*np.pi*freq
npt = 101
time = np.linspace(0.25/freq,tf,npt)

xglob=amp*np.sin(omega*time)
uglob=amp*omega*np.cos(omega*time)

delta=0.007
npx=101
dx=np.float32(delta/(npx-1))

r1=0.01
r2=0.004
xpos = np.float32(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()

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(0) for i in range(npx)]
p1=m.Var(800000)
p2=m.Var(800000)

# mu.value[:]=(630 * (1+(0.05*(dudx[:]))**2)**(-0.23))
# mu=m.Intermediate(630 * (1+(0.05*(dudx))**2)**(-0.23))

Qgap=m.Var(value=0)

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(Qgap==scipy.integrate.trapz(2*np.pi*xpos*np.array(u1)))

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)

But I don't get the desired results. The velocity u1 converges quite well. Qgap has convenient values. The pressures p1 and p2 are not as desired.

In a physical sense, p1 should increase from 8e5 to a certain value, then decrease below 8e5 resulting to p2 to do the opposite.
But when running the code and plotting p1 and p2 together, it shows they both have got sinusoidal variation but p2>p1.

Please help me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

朱染 2025-02-04 11:29:55

如果结果不是您的期望,而是方程式是正确的,那么集成精度可能是数值问题。我建议尝试此潜在解决方案的顺序:

  1. 增加时间点的数量。
npt = 501
time = np.linspace(0.25/freq,tf,npt)`
  1. 使用m.options.imode = 7用于基于时间的顺序模拟。如果问题大小太大,则可以提高解决方案速度。它产生与m.options.imode = 4的解决方案相同,但可以更快。 SET disp = false避免由于打印求解器输出以进行顺序模拟而避免放缓。
  2. 增加位置点的数量。
delta=0.007
npx=151
dx=np.float32(delta/(npx-1))

使用npx = 201它达到方程式长度限制,其中符号表格为> 15,000字符。除此之外,您还需要使用m.sum()将梯形规则编写为gekko等式,以减少方程式。

  1. 使用m.options.nodes = 4或更多(最多6),以提高准确性。 nodes = 3应该足够,因此这是最后一件事。

求解器报告了成功的解决方案,因此所有方程式都可以满足所需的公差。

 --------- APM Model Size ------------
 Each time step contains
   Objects      :            0
   Constants    :            0
   Variables    :          108
   Intermediates:            0
   Connections  :            0
   Equations    :          104
   Residuals    :          104
 
 Number of state variables:          41700
 Number of total equations: -        41700
 Number of slack variables: -            0
 ---------------------------------------
 Degrees of freedom       :              0
 
 ----------------------------------------------
 Dynamic Simulation with APOPT Solver
 ----------------------------------------------
 
 Iter    Objective  Convergence
    0  3.36523E-08  1.26261E+04
    1  2.02851E-08  4.39248E+03

   40  4.41072E-24  3.38415E-06
 Successful solution
 
 ---------------------------------------------------
 Solver         :  APOPT (v1.0)
 Solution time  :    29.1031000000003      sec
 Objective      :   0.000000000000000E+000
 Successful solution
 ---------------------------------------------------

检查模型文件gk0_model.apm(文件在文件夹中)确认方程:

m.Equation(Qgap==scipy.integrate.trapz(2*np.pi*xpos*np.array(u1)))`

gekko兼容。它产生与梯形规则的符号形式。

    v104=((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
(((((((((((((((((((((((((((((((((((((((((((((1.0)*((((0.06327167898416519)*
(v2))+((0.06283185631036758)*(v1))))))/(2.0))+((((1.0)*
((((0.0637115016579628)*(v3))+((0.06327167898416519)*(v2))))))/(2.0)))+
((((1.0)*((((0.0641513243317604)*(v4))+((0.0637115016579628)*
(v3))))))/(2.0)))+((((1.0)*((((0.06459114700555801)*(v5))+
...
+((((1.0)*((((0.10681416094303131)*(v101))+((0.1063743382692337)*
(v100))))))/(2.0)))

这是在17.8 sec中求解的最终形式,并以更准确的速度返回了成功的解决方案。

from gekko import GEKKO
import numpy as np
import matplotlib.pyplot as plt
import scipy.integrate

amp=10e-3
freq=10
tf = 2/freq
omega=2*np.pi*freq
npt = 501
time = np.linspace(0.25/freq,tf,npt)

xglob=amp*np.sin(omega*time)
uglob=amp*omega*np.cos(omega*time)

delta=0.007
npx=151
dx=np.float32(delta/(npx-1))

r1=0.01
r2=0.004
xpos = np.float32(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(remote=False)

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(0) for i in range(npx)]
p1=m.Var(800000)
p2=m.Var(800000)

# mu.value[:]=(630 * (1+(0.05*(dudx[:]))**2)**(-0.23))
# mu=m.Intermediate(630 * (1+(0.05*(dudx))**2)**(-0.23))

Qgap=m.Var(value=0)

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))

m.Equation(Qgap==scipy.integrate.trapz(2*np.pi*xpos*np.array(u1)))

# simulation
m.options.IMODE = 7
m.options.solver=1
m.options.nodes=3

#m.open_folder()
m.solve(disp=False)

print(m.options.SOLVETIME)
print(m.options.APPSTATUS)

If the results are not what you expect but the equations are correct, then it could be numerical issues with the integration accuracy. I recommend trying this order of potential solutions:

  1. Increase the number of time points.
npt = 501
time = np.linspace(0.25/freq,tf,npt)`
  1. Use m.options.IMODE=7 for time-based sequential simulation. This can improve the solution speed if the problem size is too large. It produces the same solution as m.options.IMODE=4 but can be faster. Set disp=False to avoid a slowdown due to printing the solver output for sequential simulation.
  2. Increase the number of position points.
delta=0.007
npx=151
dx=np.float32(delta/(npx-1))

With npx=201 it reaches an equation length limit where the symbolic form is >15,000 characters. Beyond this, you would need to write the trapezoidal rule as a gekko equation, using m.sum() to reduce the equation size.

  1. Use m.options.NODES=4 or more (up to 6) for more accuracy. NODES=3 should be sufficient so this is a last thing to try.

The solver reports a successful solution so all of the equations are satisfied to the required tolerance.

 --------- APM Model Size ------------
 Each time step contains
   Objects      :            0
   Constants    :            0
   Variables    :          108
   Intermediates:            0
   Connections  :            0
   Equations    :          104
   Residuals    :          104
 
 Number of state variables:          41700
 Number of total equations: -        41700
 Number of slack variables: -            0
 ---------------------------------------
 Degrees of freedom       :              0
 
 ----------------------------------------------
 Dynamic Simulation with APOPT Solver
 ----------------------------------------------
 
 Iter    Objective  Convergence
    0  3.36523E-08  1.26261E+04
    1  2.02851E-08  4.39248E+03

   40  4.41072E-24  3.38415E-06
 Successful solution
 
 ---------------------------------------------------
 Solver         :  APOPT (v1.0)
 Solution time  :    29.1031000000003      sec
 Objective      :   0.000000000000000E+000
 Successful solution
 ---------------------------------------------------

Checking the model file gk0_model.apm (file is in folder print(m.path) or m.open_folder() to open the run folder) confirms that the equation:

m.Equation(Qgap==scipy.integrate.trapz(2*np.pi*xpos*np.array(u1)))`

is compatible with gekko. It produces a symbolic form of integration with the trapezoidal rule.

    v104=((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
(((((((((((((((((((((((((((((((((((((((((((((1.0)*((((0.06327167898416519)*
(v2))+((0.06283185631036758)*(v1))))))/(2.0))+((((1.0)*
((((0.0637115016579628)*(v3))+((0.06327167898416519)*(v2))))))/(2.0)))+
((((1.0)*((((0.0641513243317604)*(v4))+((0.0637115016579628)*
(v3))))))/(2.0)))+((((1.0)*((((0.06459114700555801)*(v5))+
...
+((((1.0)*((((0.10681416094303131)*(v101))+((0.1063743382692337)*
(v100))))))/(2.0)))

Here is a final form that solves in 17.8 sec and returns a successful solution with more accuracy.

from gekko import GEKKO
import numpy as np
import matplotlib.pyplot as plt
import scipy.integrate

amp=10e-3
freq=10
tf = 2/freq
omega=2*np.pi*freq
npt = 501
time = np.linspace(0.25/freq,tf,npt)

xglob=amp*np.sin(omega*time)
uglob=amp*omega*np.cos(omega*time)

delta=0.007
npx=151
dx=np.float32(delta/(npx-1))

r1=0.01
r2=0.004
xpos = np.float32(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(remote=False)

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(0) for i in range(npx)]
p1=m.Var(800000)
p2=m.Var(800000)

# mu.value[:]=(630 * (1+(0.05*(dudx[:]))**2)**(-0.23))
# mu=m.Intermediate(630 * (1+(0.05*(dudx))**2)**(-0.23))

Qgap=m.Var(value=0)

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))

m.Equation(Qgap==scipy.integrate.trapz(2*np.pi*xpos*np.array(u1)))

# simulation
m.options.IMODE = 7
m.options.solver=1
m.options.nodes=3

#m.open_folder()
m.solve(disp=False)

print(m.options.SOLVETIME)
print(m.options.APPSTATUS)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文