我试图用Matlab函数Pdepe(https://www.mathworks.com/help/matlab/ref/pdepe.html)求解对流扩散反应问题的一维耦合偏微分方程。这个函数在我的高平流项和扩散项的情况下不能正常工作。 因此,我搜索并找到了这个使用Python库FiPy来解决PDEs系统的选项。 我的初始条件是4*L/10的u1=1
我的耦合方程如下:
du1/dt=d/dx(D1*du1/dx)+g*x*du1/dx-mu1*u1/(K+u1)*u2
du2/dt=d/dx(D2*du2/dx)+g*x*du2/dx+mu2*u1/(K+u1)*u2
我试着结合一些小例子来写这篇文章(examples.conversion.exponential1DSource.mesh1D,examples.levelSet.advision.mesh1D,examples.cahnHilliard.mesh2DCoupled). 在
以下几行不是一个有效的示例,而是我第一次尝试编写代码。这是我第一次使用FiPy(在文档的测试和示例之外),所以对于普通用户来说,这似乎完全没有抓住要点。在
from fipy import *
g = 0.66
L = 10.
nx = 1000
mu1 = 1.
mu2 = 1.
K = 1.
D1 = 1.
D2 = 1.
mesh = Grid1D(dx=L / 1000, nx=nx)
x = mesh.cellCenters[0]
convCoeff = g*(x-L/2)
u10 = 4*L/10 < x < 6*L/10
u20 = 1.
u1 = CellVariable(name="u1", mesh=mesh, value=u10)
u2 = CellVariable(name="u2", mesh=mesh, value=u20)
## Neumann boundary conditions
u1.faceGrad.constrain(0., where=mesh.facesLeft)
u1.faceGrad.constrain(0., where=mesh.facesRight)
u2.faceGrad.constrain(0., where=mesh.facesLeft)
u2.faceGrad.constrain(0., where=mesh.facesRight)
sourceCoeff1 = -1*mu1*u1/(K+u1)*u2
sourceCoeff2 = 1*mu2*u1/(K+u1)*u2
eq11 = (TransientTerm(var=u1) == DiffusionTerm(coeff=D1, var=u1) + ConvectionTerm(coeff=convCoeff))
eq21 = (TransientTerm(var=u2) == DiffusionTerm(coeff=D2, var=u2) + ConvectionTerm(coeff=convCoeff))
eq12 = ImplicitSourceTerm(coeff=sourceCoeff1, var=u1)
eq22 = ImplicitSourceTerm(coeff=sourceCoeff2, var=u2)
eq1 = eq11 & eq12
eq2 = eq21 & eq22
eqn = eq1 & eq2
vi = Viewer((u1, u2))
for t in range(100):
u1.updateOld()
u2.updateOld()
eqn.solve(dt=1.e-3)
vi.plot()
谢谢您的任何建议或更正。 如果您碰巧知道这类问题的好教程,我很乐意阅读,因为我没有找到比FiPy文档中的示例更好的东西。在
几个问题:
u10
成为一个布尔字段,这会混淆FiPy,因此 写 ^{pr2}$ 或者,更好的是,写信ConvectionTerm
取向量系数。一种方法是 它表示1D rank-1变量Variable
aTerm
适用于哪一个,则必须对所有Term
进行声明,因此请写下,例如。,ConvectionTerm(coeff=g*x, var=u1)
不代表g*x*du1/dx。它表示d(g*x*u1)/dx。所以,我相信你会想要ImplicitSourceTerm(coeff=sourceCoeff1, var=u1
不代表-1*mu1*u1/(K+u1)*u2
,而是表示-1*mu1*u1/(K+u1)*u2*u1
。所以,为了得到方程之间的最佳耦合,写下正如@wd15在评论中指出的,您声明了两个未知的四个方程。
&
并不意味着“把两个方程加在一起”(这可以用+
来完成),而是意味着“同时求解这两个方程”。写,所以CellVariable
,必须用hasOld=True
声明updateOld()
,因此似乎可以工作的完整代码是here
相关问题 更多 >
编程相关推荐