examples.convection.powerLaw1D package

Submodules

examples.convection.powerLaw1D.mesh1D module

This example solves the steady-state convection-diffusion equation as described in examples.diffusion.convection.exponential1D.mesh1D but uses the PowerLawConvectionTerm rather than the ExponentialConvectionTerm.

>>> from fipy import CellVariable, Grid1D, DiffusionTerm, PowerLawConvectionTerm, Viewer
>>> from fipy.tools import numerix
>>> L = 10.
>>> nx = 1000
>>> mesh = Grid1D(dx = L / nx, nx = nx)
>>> valueLeft = 0.
>>> valueRight = 1.
>>> var = CellVariable(name = "concentration",
...                    mesh = mesh,
...                    value = valueLeft)
>>> var.constrain(valueLeft, mesh.facesLeft)
>>> var.constrain(valueRight, mesh.facesRight)
>>> diffCoeff = 1.
>>> convCoeff = (10.,)
>>> eq = (DiffusionTerm(coeff=diffCoeff)
...       + PowerLawConvectionTerm(coeff=convCoeff))
>>> eq.solve(var = var)

We test the solution against the analytical result:

>>> axis = 0
>>> x = mesh.cellCenters[axis]
>>> CC = 1. - numerix.exp(-convCoeff[axis] * x / diffCoeff)
>>> DD = 1. - numerix.exp(-convCoeff[axis] * L / diffCoeff)
>>> analyticalArray = CC / DD
>>> print(var.allclose(analyticalArray, rtol = 1e-2, atol = 1e-2))
1

If the problem is run interactively, we can view the result:

>>> if __name__ == '__main__':
...     viewer = Viewer(vars = var)
...     viewer.plot()

examples.convection.powerLaw1D.tri2D module

This example solves the steady-state convection-diffusion equation as described in mod:examples.diffusion.convection.exponential1D.mesh1D but uses the PowerLawConvectionTerm rather than the ExponentialConvectionTerm instantiator.

>>> from fipy import CellVariable, Grid2D, DiffusionTerm, PowerLawConvectionTerm, DefaultAsymmetricSolver, Viewer
>>> from fipy.tools import numerix
>>> L = 10.
>>> nx = 1000
>>> mesh = Grid2D(dx = L / nx, nx = nx)
>>> valueLeft = 0.
>>> valueRight = 1.
>>> var = CellVariable(name = "concentration",
...                    mesh = mesh,
...                    value = valueLeft)
>>> var.constrain(valueLeft, mesh.facesLeft)
>>> var.constrain(valueRight, mesh.facesRight)
>>> diffCoeff = 1.
>>> convCoeff = (10., 0.)
>>> eq = (DiffusionTerm(coeff=diffCoeff)
...       + PowerLawConvectionTerm(coeff=convCoeff))
>>> eq.solve(var=var,
...          solver=DefaultAsymmetricSolver(tolerance=1.e-15, iterations=2000))

The analytical solution test for this problem is given by:

>>> axis = 0
>>> x = mesh.cellCenters[axis]
>>> CC = 1. - numerix.exp(-convCoeff[axis] * x / diffCoeff)
>>> DD = 1. - numerix.exp(-convCoeff[axis] * L / diffCoeff)
>>> analyticalArray = CC / DD
>>> print(var.allclose(analyticalArray, rtol = 1e-2, atol = 1e-2))
1
>>> if __name__ == '__main__':
...     viewer = Viewer(vars = var)
...     viewer.plot()
Last updated on Jun 27, 2023. Created using Sphinx 6.2.1.