python - FiPy 方程组发散。建议?
问题描述
在这个新集合中,p 和 m 是我的变量,其中所有其他值都是常数。fc²m|m|/2DA²p 中的 m 和 p 值被视为每个单元格的平均值。此外,我想固定入口质量流量 (m(0, t)) 和出口压力 (p(L,t)),因此我将其定义为约束。
我有两个问题:我的代码似乎发散了,对于每个时间步,它要么给我一个非常高的 m 在管道中的值,而下一个给我一个非常负的值,依此类推。此外,似乎简单地定义入口质量流量和出口压力给出了一个不真实的解决方案。
有什么想法和建议吗?再次感谢您,亲爱的社区。
下面的代码:
import fipy as fi
import matplotlib.pyplot as plt
import numpy as np
import scipy as sci
from matplotlib import animation
from fipy.variables.cellVariable import CellVariable
#1. Domain
L = 101
dx = .1
mesh = fi.Grid1D(nx = L, dx=dx)
#2. Parameters values (Arbitrary)
Lambda = 0.0001 # Friction factor
D = .4 # Pipe diameter
T = 350 # Gas Temperature
c = 380
A = 3.14 * (D **2) / 4
#3. Variables
## Pressure and mass flow
p = fi.CellVariable(name="pressure",
hasOld=True,
mesh=mesh,
value=0.)
p.setValue(10000000.) # This is the initial condition
m = fi.CellVariable(name="mass flow",
hasOld=True,
mesh=mesh,
value=0.)
m.setValue(300.) # This is the initial condition
#4. Boundary conditions
p.constrain (2000000., where = mesh.facesRight)
p.constrain (15., where = mesh.facesLeft)
m.constrain (500., where = mesh.facesLeft)
m.constrain (500., where = mesh.facesRight)
#5. PDE
eq1 = fi.TransientTerm(var=p) == fi.ConvectionTerm(coeff = [-(c**2) / A], var=m)
eq2 = fi.TransientTerm(var=m) == fi.ConvectionTerm(coeff = [-A], var=p) - (Lambda*(c**2)*m.cellVolumeAverage*abs(m.cellVolumeAverage)/(2*D*A*p.cellVolumeAverage))
eqn = (eq1 & eq2)
timeStepDuration = .001
steps = 50
#This make a chart of the results
for step in range(steps):
plt.plot(np.linspace(0, L, nx), m.value)
#plt.xlim(0,1.1)
#plt.ylim(0, 20)
plt.show()
eqn.sweep(dt=timeStepDuration)
p.updateOld()
m.updateOld()
解决方案
推荐阅读
- asp.net - 如何将数据从 clickOnce 应用程序传回给调用者
- machine-learning - 有条件抽样
- apache-spark - 获取数组中项目的索引,该数组是 Spark 数据框中的一列
- html - 导航文章和侧边宽度总和为 100%,但侧边换行
- vb.net - WebForms 标签文本未从 OnInit() 更新
- android - 正确使用反射获取Class方法
- amazon-web-services - 当 lambda 死亡时会发生什么?
- typescript - 指定参数必须具有 keyof 属性
- listview - 切换切换时隐藏数据单元格中的行
- java - 只有创建视图层次结构的原始线程才能在 asynctask 中触及其视图错误