examples.meshing package

Submodules

examples.meshing.gmshRefinement module

examples.meshing.inputGrid2D module

To run this example from the base FiPy directory, type:

$ python examples/meshing/inputGrid2D.py --numberOfElements=X

This example demonstrates how to build a 1D mesh and obtain basic mesh information. The command line argument, X, controls the number of elements on the mesh. Firstly parse the command line argument for numberOfElements, with the default set at 100.

>>> from fipy.tools.parser import parse
>>> numberOfElements = parse('--numberOfElements', action = 'store', type = 'int', default = 100)

A Grid2D object is invoked in the following way,

>>> from fipy import Grid2D, CellVariable, Viewer
>>> from fipy.tools import numerix
>>> nx = int(numerix.sqrt(numberOfElements))
>>> ny = nx
>>> dx = 1.
>>> dy = 1.
>>> mesh = Grid2D(nx = nx, ny = nx, dx = dx, dy = dy)

Once the mesh has been built information about the mesh can be obtained. For example the mesh volumes can be obtained with the getCellVolumes() method.

>>> vols = mesh.cellVolumes
>>> numerix.allclose(dx * dy * numerix.ones(nx * ny), vols)
1

Obtain the number of cells in the mesh

>>> N = mesh.numberOfCells
>>> numerix.allclose(N, numberOfElements)
1

Obtain all the left exterior faces, this is equal to ny.

>>> faces = mesh.facesLeft
>>> len(faces) == ny
1

One can view the mesh with the following code,

>>> if __name__ == '__main__':
...     viewer = Viewer(CellVariable(value = 0, mesh = mesh))
...     viewer.plot()

examples.meshing.sphere module

An interesting problem is to solve an equation on a 2D geometry that is embedded in 3D space, such as diffusion on the surface of a sphere (with nothing either inside or outside the sphere). This example demonstrates how to create the required mesh.

>>> from fipy import Gmsh2DIn3DSpace, CellVariable, MayaviClient
>>> from fipy.tools import numerix
>>> mesh = Gmsh2DIn3DSpace('''
...     radius = 5.0;
...     cellSize = 0.3;
...
...     // create inner 1/8 shell
...     Point(1) = {0, 0, 0, cellSize};
...     Point(2) = {-radius, 0, 0, cellSize};
...     Point(3) = {0, radius, 0, cellSize};
...     Point(4) = {0, 0, radius, cellSize};
...     Circle(1) = {2, 1, 3};
...     Circle(2) = {4, 1, 2};
...     Circle(3) = {4, 1, 3};
...     Line Loop(1) = {1, -3, 2} ;
...     Ruled Surface(1) = {1};
...
...     // create remaining 7/8 inner shells
...     t1[] = Rotate {{0,0,1},{0,0,0},Pi/2} {Duplicata{Surface{1};}};
...     t2[] = Rotate {{0,0,1},{0,0,0},Pi} {Duplicata{Surface{1};}};
...     t3[] = Rotate {{0,0,1},{0,0,0},Pi*3/2} {Duplicata{Surface{1};}};
...     t4[] = Rotate {{0,1,0},{0,0,0},-Pi/2} {Duplicata{Surface{1};}};
...     t5[] = Rotate {{0,0,1},{0,0,0},Pi/2} {Duplicata{Surface{t4[0]};}};
...     t6[] = Rotate {{0,0,1},{0,0,0},Pi} {Duplicata{Surface{t4[0]};}};
...     t7[] = Rotate {{0,0,1},{0,0,0},Pi*3/2} {Duplicata{Surface{t4[0]};}};
...
...     // create entire inner and outer shell
...     Surface Loop(100)={1,t1[0],t2[0],t3[0],t7[0],t4[0],t5[0],t6[0]};
... ''').extrude(extrudeFunc=lambda r: 1.1 * r) 
>>> x, y, z = mesh.cellCenters 
>>> var = CellVariable(mesh=mesh, value=x * y * z, name="x*y*z") 
>>> if __name__ == '__main__':
...     viewer = MayaviClient(vars=var)
...     viewer.plot()
>>> max(numerix.sqrt(x**2 + y**2 + z**2)) < 5.3 
True
>>> min(numerix.sqrt(x**2 + y**2 + z**2)) > 5.2 
True

examples.meshing.test module

Run all the test cases in examples/meshing/

Last updated on Jun 27, 2023. Created using Sphinx 6.2.1.