在 FiPy 中求解总体平衡 PDE 时遇到问题
我是使用FIPY以及通常使用有限体积方法的初学者。因此,如果我的问题很幼稚,请原谅我
,我试图解决形式的人口平衡方程 pde 边界条件如下 边界条件
x范围为0.5e-6到1000e-6的值,我想使用均匀的网眼。
这是我当前拥有的代码,并且无法正常工作。在代码中,我认为术语g和b_0是时间不变,可以使问题更容易。有人可以指导我如何定义上述问题中的术语以获取工作解决方案吗?
from fipy import *
import scipy
b0 = 11.78*10**7
g0 = 2.549e-7
#Define Mesh
nx = 1000
dx = 10e-7
mesh = Grid1D(nx = nx, dx = dx)
x = mesh.cellCenters[0]
#Define coefficients
G = FaceVariable(mesh=mesh, value = g0)
#Defining the solution Variable
phi = CellVariable(name = 'Solution Variable', mesh = mesh,
hasOld = True)
#Set initial condition
g = (scipy.stats.norm(loc = x[500], scale = 5e-6).pdf(x))*b0
phi.setValue(g)
#Set Boundary Condition
(phi*G).constrain(b0, where = mesh.facesLeft)
(phi*G).constrain(0, where = mesh.facesRight)
#Define the convective coefficient
conv_coefficient = G
#Define the Equation
eqn = TransientTerm() == -ConvectionTerm(coeff = conv_coefficient)
steps = 1
for step in range(steps):
dt = 10
eqn.solve(var = phi, dt = dt)
plt.plot(phi.value)
I am a beginner in using FiPy and also in working with Finite Volume Methods in general. So please forgive me if my questions are naïve
I am trying to solve a population balance equation of the form
PDE
with the boundary conditions as follows
Boundary Conditions
The value of x ranges from 0.5e-6 to 1000e-6 and I want to use a uniform mesh.
This is the code that I currently have and it is not working. In the code I have assumed that the terms G and b_0 are time invariant to make the problem easier. Can someone please guide me about how I should define the terms in the above problem to get a working solution?
from fipy import *
import scipy
b0 = 11.78*10**7
g0 = 2.549e-7
#Define Mesh
nx = 1000
dx = 10e-7
mesh = Grid1D(nx = nx, dx = dx)
x = mesh.cellCenters[0]
#Define coefficients
G = FaceVariable(mesh=mesh, value = g0)
#Defining the solution Variable
phi = CellVariable(name = 'Solution Variable', mesh = mesh,
hasOld = True)
#Set initial condition
g = (scipy.stats.norm(loc = x[500], scale = 5e-6).pdf(x))*b0
phi.setValue(g)
#Set Boundary Condition
(phi*G).constrain(b0, where = mesh.facesLeft)
(phi*G).constrain(0, where = mesh.facesRight)
#Define the convective coefficient
conv_coefficient = G
#Define the Equation
eqn = TransientTerm() == -ConvectionTerm(coeff = conv_coefficient)
steps = 1
for step in range(steps):
dt = 10
eqn.solve(var = phi, dt = dt)
plt.plot(phi.value)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的脚本有几个问题:
您必须在使用它们之前导入特定的Scipy模块,例如
导入scipy.stats
。Phi
在单元中心定义。g
在单元格之间的面上定义。 Fipy不知道如何在两个不同的位置繁殖变量。如书面,您的第一个边界条件可以重新排列到dirichlet条件
=“ https://i.sstatic.net/uihij.png” rel =“ nofollow noreferrer”>
,或
coeff
对对流
必须是向量(rank-1),但是cons_coeff = g
是等级 - 0。您可以制作g
rank-1(可能应该),但是您的边界条件没有意义,因为,而
完整的代码
仍然存在疑问,因为您的表达方式不一致关于标量和矢量数量。我强烈建议您尝试解决1D表达的PDE。几乎总是误导。您需要知道什么是标量,什么是向量,这很难在1D中跟踪。
Your script has several problems:
You must import specific scipy modules before using them, e.g.,
import scipy.stats
.phi
is defined at cell centers.G
is defined at the faces between cells. FiPy doesn't know how to multiply variables in two different locations.As written, your first boundary condition can be rearranged to the Dirichlet condition
, or
Your second boundary condition can be rearranged to the Dirichlet condition
, or
The
expresses "vector * scalar = scalar". Since
and
are only functions of time, you can make this work by changing the definitions to
coeff
argument toConvectionTerm
must be a vector (rank-1), butconv_coeff = G
is rank-0. You can makeG
rank-1 (and probably should), but then your boundary condition doesn't make sense, asand
The full code is
I still have doubts as your expressions aren't consistent about scalar and vector quantities. I strongly recommend against trying to solve PDEs expressed in 1D. It's almost always misleading. You need to know what is scalar and what is vector and this is hard to keep track of in 1D.