examples.diffusion.steadyState.mesh1D package

Submodules

examples.diffusion.steadyState.mesh1D.inputPeriodic module

One can then solve the same problem as in examples/diffusion/steadyState/mesh1D/input.py but with a periodic mesh and no boundary conditions. The periodic mesh is used to simulate periodic boundary conditions.

>>> from fipy import PeriodicGrid1D, CellVariable, TransientTerm, DiffusionTerm, Viewer
>>> nx = 50
>>> dx = 1.
>>> mesh = PeriodicGrid1D(nx = nx, dx = dx)

The variable is initially a line varying form valueLeft to valueRight.

>>> valueLeft = 0
>>> valueRight = 1
>>> x = mesh.cellCenters[0]
>>> Lx = nx * dx
>>> initialArray = valueLeft + (valueRight - valueLeft) * x / Lx
>>> var = CellVariable(name = "solution variable", mesh = mesh,
...                                                value = initialArray)
>>> from fipy import input
>>> if __name__ == '__main__':
...     viewer = Viewer(vars=var, datamin=0., datamax=1.)
...     viewer.plot()
...     input("press key to continue")

A TransientTerm is used to provide some fixed point, otherwise the solver has no fixed value and can become unstable.

>>> eq = TransientTerm(coeff=1e-8) - DiffusionTerm()
>>> eq.solve(var=var, dt=1.)
>>> if __name__ == '__main__':
...     viewer.plot()

The result of the calculation will be the average value over the domain.

>>> print(var.allclose((valueLeft + valueRight) / 2., rtol = 1e-5))
1

examples.diffusion.steadyState.mesh1D.tri2Dinput module

To run this example from the base FiPy directory type:

$ python examples/diffusion/steadyState/mesh1D/tri2Dinput.py

at the command line. A contour plot should appear and the word finished in the terminal.

This example is similar to the example found in examples.diffusion.steadyState.mesh1D.input, however, the mesh is a Tri2D object rather than a Grid2D object.

Here, one time step is executed to implicitly find the steady state solution.

>>> DiffusionTerm().solve(var)

To test the solution, the analytical result is required. The x coordinates from the mesh are gathered and the length of the domain, Lx, is calculated. An array, analyticalArray, is calculated to compare with the numerical result,

>>> x = mesh.cellCenters[0]
>>> Lx = nx * dx
>>> analyticalArray = valueLeft + (valueRight - valueLeft) * x / Lx

Finally the analytical and numerical results are compared with a tolerance of 1e-10.

>>> print(var.allclose(analyticalArray))
1
Last updated on Jun 27, 2023. Created using Sphinx 6.2.1.