examples.convection.exponential1DSource package

Submodules

examples.convection.exponential1DSource.mesh1D module

Solve the steady-state convection-diffusion equation with a constant source.

Like examples.convection.exponential1D.mesh1D this example solves a steady-state convection-diffusion equation, but adds a constant source, S_0 = 1, such that

\nabla \cdot \left(D \nabla \phi + \vec{u} \phi \right) + S_0 = 0.

>>> diffCoeff = 1.
>>> convCoeff = (10.,)
>>> sourceCoeff = 1.

We define a 1D mesh

>>> from fipy import CellVariable, Grid1D, DiffusionTerm, ExponentialConvectionTerm, DefaultAsymmetricSolver, Viewer
>>> from fipy.tools import numerix
>>> nx = 1000
>>> L = 10.
>>> mesh = Grid1D(dx=L / 1000, nx=nx)
>>> valueLeft = 0.
>>> valueRight = 1.

The solution variable is initialized to valueLeft:

>>> var = CellVariable(name="variable", mesh=mesh)

and impose the boundary conditions

\phi = \begin{cases}
0& \text{at $x = 0$,} \\
1& \text{at $x = L$,}
\end{cases}

with

>>> var.constrain(valueLeft, mesh.facesLeft)
>>> var.constrain(valueRight, mesh.facesRight)

We define the convection-diffusion equation with source

>>> eq = (DiffusionTerm(coeff=diffCoeff)
...       + ExponentialConvectionTerm(coeff=convCoeff)
...       + sourceCoeff)
>>> eq.solve(var=var,
...          solver=DefaultAsymmetricSolver(tolerance=1.e-15, iterations=10000))

and test the solution against the analytical result:

\phi = -\frac{S_0 x}{u_x}
+ \left(1 + \frac{S_0 x}{u_x}\right)\frac{1 - \exp(-u_x x / D)}{1 - \exp(-u_x L / D)}

or

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

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

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

examples.convection.exponential1DSource.tri2D module

This example solves the steady-state convection-diffusion equation as described in examples.diffusion.convection.exponential1D.mesh1D but uses a constant source value such that,

S_c = 1.

Here the axes are reversed (nx = 1, ny = 1000) and

\vec{u} = (0, 10)

>>> from fipy import CellVariable, Tri2D, DiffusionTerm, ExponentialConvectionTerm, DefaultAsymmetricSolver, Viewer
>>> from fipy.tools import numerix
>>> L = 10.
>>> nx = 1
>>> ny = 1000
>>> mesh = Tri2D(dx = L / ny, dy = L / ny, nx = nx, ny = ny)
>>> valueBottom = 0.
>>> valueTop = 1.
>>> var = CellVariable(name = "concentration",
...                    mesh = mesh,
...                    value = valueBottom)
>>> var.constrain(valueBottom, mesh.facesBottom)
>>> var.constrain(valueTop, mesh.facesTop)
>>> diffCoeff = 1.
>>> convCoeff = (0., 10.)
>>> sourceCoeff = 1.
>>> eq = (-sourceCoeff - DiffusionTerm(coeff = diffCoeff)
...       - ExponentialConvectionTerm(coeff = convCoeff))
>>> eq.solve(var=var,
...          solver=DefaultAsymmetricSolver(tolerance=1.e-15, iterations=10000))

The analytical solution test for this problem is given by:

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