examples.diffusion.steadyState.mesh20x20 package

Submodules

examples.diffusion.steadyState.mesh20x20.gmshinput module

This input file again solves a 1D diffusion problem as in ./examples/diffusion/steadyState/mesh1D/input.py. In order to test the non-orthogonality error, this uses a SkewedGrid2D, which is a Grid2D with each interior vertex moved in a random direction.

examples.diffusion.steadyState.mesh20x20.isotropy module

This input file solves a steady-state 1D diffusion problem as in ./examples/diffusion/mesh1D.py. The difference being that it uses a tensor for the diffusion coefficient, even though the coefficient is isotropic.

>>> from fipy import Grid2D, CellVariable, DiffusionTerm, Viewer
>>> Lx = 20
>>> mesh = Grid2D(nx=20, ny=20)
>>> x, y = mesh.cellCenters
>>> valueLeft = 0.
>>> valueRight = 1.
>>> var = CellVariable(name = "solution variable",
...                    mesh = mesh,
...                    value = valueLeft)
>>> var.constrain(valueLeft, mesh.facesLeft)
>>> var.constrain(valueRight, mesh.facesRight)
>>> DiffusionTerm(coeff=(((1., 0.),
...                       (0., 1.)),)).solve(var)
>>> if __name__ == '__main__':
...     viewer = Viewer(vars=var).plot()
>>> analyticalArray = valueLeft + (valueRight - valueLeft) * x / Lx
>>> print(var.allclose(analyticalArray, atol = 0.025))
1

examples.diffusion.steadyState.mesh20x20.modifiedMeshInput module

This input file again solves a 1D diffusion problem as in ./examples/diffusion/steadyState/mesh1D/input.py. The difference being that it uses a triangular mesh loaded in using the Gmsh2D object.

The result is again tested in the same way:

>>> from fipy import Gmsh2D, CellVariable, DiffusionTerm, Viewer
>>> from fipy.tools import numerix
>>> valueLeft = 0.
>>> valueRight = 1.
>>> Lx = 20
>>> mesh = Gmsh2D('''
...     cellSize = 0.5;
...     Point(2) = {0, 0, 0, cellSize};
...     Point(3) = {%(Lx)g, 0, 0, cellSize};
...     Point(4) = {%(Lx)g, %(Lx)g, 0, cellSize};
...     Point(5) = {0, %(Lx)g, 0, cellSize};
...
...     Line(6) = {2, 3};
...     Line(7) = {3, 4};
...     Line(8) = {4, 5};
...     Line(9) = {5, 2};
...
...     Line Loop(10) = {6, 7, 8, 9};
...
...     Plane Surface(11) = {10};
...     ''' % locals()) 
>>> var = CellVariable(name = "solution variable",
...               mesh = mesh,
...               value = valueLeft) 
>>> var.constrain(valueLeft, mesh.facesLeft) 
>>> var.constrain(valueRight, mesh.facesRight) 
>>> DiffusionTerm().solve(var) 
>>> from fipy import input
>>> x = mesh.cellCenters[0] 
>>> analyticalArray = valueLeft + (valueRight - valueLeft) * x / Lx 
>>> print(var.allclose(analyticalArray, atol=0.025)) 
True
>>> errorVar = abs(var - analyticalArray) 
>>> errorVar.name = "absolute error" 
>>> NonOrthoVar = CellVariable(name="non-orthogonality",
...                            mesh=mesh,
...                            value=mesh._nonOrthogonality) 
>>> print(max(NonOrthoVar) < 0.51) 
True
>>> if __name__ == '__main__':
...     viewer = Viewer(vars=var)
...     viewer.plot()
...
...     errorViewer = Viewer(vars=errorVar)
...     errorViewer.plot()
...
...     NOViewer = Viewer(vars=NonOrthoVar)
...     NOViewer.plot()
...
...     input("finished")

examples.diffusion.steadyState.mesh20x20.orthoerror module

This test file generates lots of different SkewedGrid2D meshes, each with a different non-orthogonality, and runs a 1D diffusion problem on them all. It computes the RMS non-orthogonality and the RMS error for each mesh and displays them in a graph, allowing the relationship of error to non-orthogonality to be investigated.

examples.diffusion.steadyState.mesh20x20.tri2Dinput module

This input file again solves a 2D diffusion problem on a triangular mesh.

>>> DiffusionTerm().solve(var)

The result is again tested in the same way:

>>> Lx = nx * dx
>>> x = mesh.cellCenters[0]
>>> analyticalArray = valueLeft + (valueRight - valueLeft) * x / Lx
>>> print(var.allclose(analyticalArray, rtol = 1e-8))
1
Last updated on Jun 27, 2023. Created using Sphinx 6.2.1.