Solve a convection problem with a source.
This example solves the equation
with at . The boundary condition at is an outflow boundary condition requiring the use of an artificial constraint to be set on the right hand side faces. Exterior faces without constraints are considered to have zero outflow. An ImplicitSourceTerm object will be used to represent this term. The derivative of can be represented by a ConvectionTerm with a constant unitary velocity field from left to right. The following is an example code that includes a test against the analytical result.
>>> from fipy import *
>>> L = 10. >>> nx = 5000 >>> dx = L / nx >>> mesh = Grid1D(dx=dx, nx=nx) >>> phi0 = 1.0 >>> alpha = 1.0 >>> phi = CellVariable(name=r"$\phi$", mesh=mesh, value=phi0) >>> solution = CellVariable(name=r"solution", mesh=mesh, value=phi0 * numerix.exp(-alpha * mesh.cellCenters))
>>> if __name__ == "__main__": ... viewer = Viewer(vars=(phi, solution)) ... viewer.plot() ... raw_input("press key to continue")
>>> phi.constrain(phi0, mesh.facesLeft) >>> ## fake outflow condition >>> phi.faceGrad.constrain(, mesh.facesRight)
>>> eq = PowerLawConvectionTerm((1,)) + ImplicitSourceTerm(alpha) >>> eq.solve(phi) >>> print numerix.allclose(phi, phi0 * numerix.exp(-alpha * mesh.cellCenters), atol=1e-3) True
>>> if __name__ == "__main__": ... viewer = Viewer(vars=(phi, solution)) ... viewer.plot() ... raw_input("finished")