examples.convection.exponential2D.cylindricalMesh2DNonUniformΒΆ

This example solves the steady-state cylindrical convection-diffusion equation given by:

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

with coefficients \(D = 1\) and \(\vec{u} = (10,)\), or

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

We define a 2D cylindrical mesh representing an annulus. The mesh is a pseudo-1D mesh, but is a good test case for the CylindricalGrid2D() mesh. The mesh has a non-constant cell spacing.

>>> from fipy import CellVariable, CylindricalGrid2D, DiffusionTerm, ExponentialConvectionTerm, Viewer
>>> from fipy.tools import numerix
>>> r0 = 1.
>>> r1 = 2.
>>> nr = 100
>>> Rratio = (r1 / r0)**(1 / float(nr))
>>> dr = r0 * (Rratio - 1) * Rratio**numerix.arange(nr)
>>> mesh = CylindricalGrid2D(dr=dr, dz=1., nz=1) + ((r0,), (0.,))

The solution variable is initialized to valueLeft:

>>> valueLeft = 0.
>>> valueRight = 1.
>>> var = CellVariable(mesh=mesh, name = "variable")

and impose the boundary conditions

\[\begin{split}\phi = \begin{cases} 0& \text{at $r = r_0$,} \\ 1& \text{at $r = r_1$,} \end{cases}\end{split}\]

with

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

The equation is created with the DiffusionTerm and ExponentialConvectionTerm.

>>> eq = (DiffusionTerm(coeff=diffCoeff)
...       + ExponentialConvectionTerm(coeff=convCoeff))

More details of the benefits and drawbacks of each type of convection term can be found in Numerical Schemes. Essentially, the ExponentialConvectionTerm and PowerLawConvectionTerm will both handle most types of convection-diffusion cases, with the PowerLawConvectionTerm being more efficient.

We solve the equation

>>> eq.solve(var=var)

and test the solution against the analytical result

\[\phi = \exp{\frac{u}{D} \left(r_1 - r\right)} \left( \frac{ \Ei{\frac{u r_0}{D}} - \Ei{\frac{u r}{D}} }{ \Ei{\frac{u r_0}{D}} - \Ei{\frac{u r_1}{D}} } \right)\]
>>> axis = 0
>>> try:
...     from scipy.special import expi 
...     r = mesh.cellCenters[axis]
...     U = convCoeff[0][0]
...     AA = numerix.exp(U / diffCoeff * (r1 - r))
...     BB = expi(U * r0 / diffCoeff) - expi(U * r / diffCoeff) 
...     CC = expi(U * r0 / diffCoeff) - expi(U * r1 / diffCoeff) 
...     analyticalArray = AA * BB / CC 
... except ImportError:
...     print("The SciPy library is unavailable. It is required for testing purposes.")
>>> print(var.allclose(analyticalArray, atol=1e-3)) 
1

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

>>> if __name__ == '__main__':
...     viewer = Viewer(vars=var)
...     viewer.plot()
Last updated on Jun 26, 2024. Created using Sphinx 7.1.2.