0

I am attempting to solve the convection diffusion equation in FiPy. For the moment, all I am trying to achieve is a Neumann boundary condition, so that the wave reflects back at the right-hand boundary rather than travelling out of the domain.

I have added the following line:

phi.faceGrad.constrain(0, mesh.exteriorFaces)

But this doesn't seem to change anything.

Am I imposing the wrong boundary condition? Am I imposing it incorrectly? I have searched for this, but can't seem to find an example which has the simple property of a wave reflecting off a boundary! My code is below. Thanks so much.

from fipy import *

nx = 100
L = 1.
dx = L/nx
steps = 160
dt = 0.1
t = dt * steps

mesh = Grid1D(nx=nx, dx=dx)
x = mesh.cellCenters[0]

phi = CellVariable(name="solution variable", mesh=mesh, value=0.)
phi.setValue(1., where=(x>0.03) & (x<0.09))

# Diffusion and convection coefficients
D = FaceVariable(name='diffusion coefficient',mesh=mesh,value=1.*10**(-4.))
C = (0.1,)

# Boundary conditions
phi.faceGrad.constrain(0, mesh.exteriorFaces)

eq = TransientTerm() == DiffusionTerm(coeff=D) - ConvectionTerm(coeff=C)

for step in range(steps):
    eq.solve(var=phi, dt=dt)
    if step%20==0:
        viewer = Viewer(vars=phi, datamin=0., datamax=1.)
        viewer.plot()
freitreppe
  • 11
  • 1

0 Answers0