我试图用fipy来解决python中的对流扩散方程。我想操纵对流系数,使其指向域的中心。
我的代码是
from fipy import *
# Setting mesh and discretising space
nx = 10
dx = 1.
mesh = Grid1D(nx=nx, dx=dx)
x = mesh.cellCenters[0]
# Setting variable of results and adding inicial conditions
phi = CellVariable(name="solution variable", mesh=mesh, value=0.)
phi.setValue(1., where=(4 < x) & (6 > x))
# Plotting inicial conditions
if __name__ == '__main__':
viewer = Viewer(vars=phi, datamin=-0.1, datamax=1.5)
viewer.plot()
# Diffusion and convection coefficients
D = 1.
C = (1.,)
# Setting PDE
eqX = TransientTerm() == DiffusionTerm(coeff=D) - \
ConvectionTerm(coeff=C)
# Solving Transient term
timeStepDuration = 0.1
steps = 15
t = timeStepDuration * steps
for step in range(steps):
eqX.solve(var=phi, dt=timeStepDuration)
# Plotting results
if __name__ == '__main__':
viewer = Viewer(vars=phi, datamin=0., datamax=1.)
viewer.plot()
正如您所看到的,沿着时间,波浪随着对流系数向量建立的方向移动。操纵波的对流系数的代码如何仅向我的域的中心移动?
任何建议都将不胜感激!
答案 0 :(得分:0)
对流系数控制行波的方向。例如,要使波始终朝向域的中心行进,请将对流系数更改为
C = CellVariable(mesh=mesh, rank=1)
C[:] = 1.
C.setValue(-1., where=x > 5.)
如果波在域的前半部分,或者如果它位于域的后半部分,则速度为-1,这将使波速为1。如果初始方波偏离中心,则它将返回中心。