examples.diffusion.steadyState.mesh20x20.modifiedMeshInputΒΆ

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")
Last updated on Jun 26, 2024. Created using Sphinx 7.1.2.