This page contains the numMesh Package documentation.
1D Mesh
Bases: fipy.meshes.numMesh.grid1D.Grid1D
Creates a 1D cylindrical grid mesh.
>>> mesh = CylindricalGrid1D(nx = 3)
>>> print mesh.getCellCenters()
[[ 0.5 1.5 2.5]]
>>> mesh = CylindricalGrid1D(dx = (1, 2, 3))
>>> print mesh.getCellCenters()
[[ 0.5 2. 4.5]]
>>> mesh = CylindricalGrid1D(nx = 2, dx = (1, 2, 3))
Traceback (most recent call last):
...
IndexError: nx != len(dx)
>>> mesh = CylindricalGrid1D(nx=2, dx=(1., 2.)) + ((1.,),)
>>> print mesh.getCellCenters()
[[ 1.5 3. ]]
>>> from fipy.tools import parallel
>>> print parallel.procID > 0 or numerix.allclose(mesh.getCellVolumes(), (1.5, 6))
True
2D rectangular Mesh
Bases: fipy.meshes.numMesh.grid2D.Grid2D
Creates a 2D cylindrical grid mesh with horizontal faces numbered first and then vertical faces.
1D Mesh
Bases: fipy.meshes.numMesh.uniformGrid1D.UniformGrid1D
Creates a 1D cylindrical grid mesh.
>>> mesh = CylindricalUniformGrid1D(nx = 3)
>>> print mesh.getCellCenters()
[[ 0.5 1.5 2.5]]
2D cylindrical rectangular Mesh with constant spacing in x and constant spacing in y
Bases: fipy.meshes.numMesh.uniformGrid2D.UniformGrid2D
Creates a 2D cylindrical grid in the radial and axial directions, appropriate for axial symmetry.
Face within a Mesh
Face objects are bounded by Vertex objects. Face objects separate Cell objects.
Face is initialized by Mesh
Parameters : |
|
---|
Return the id of the specified Cell on one side of this Face.
Return the coordinates of the Face center.
This module takes a FiPy mesh and creates a mesh file that can be opened in Gmsh.
Bases: exceptions.Exception
This module takes a Gmsh output file (.msh) and converts it into a FiPy mesh. This currently supports triangular and tetrahedral meshes only.
Gmsh generates unstructured meshes, which may contain a significant amount of non-orthogonality and it is very difficult to directly control the amount of non-orthogonality simply by manipulating Gmsh parameters. Therefore, it is necessary to take into account the possibility of errors arising due to the non-orthogonality of the mesh. To test the degree of error, an experiment was conducted using a simple 1D diffusion problem with constant diffusion coefficients and boundary conditions as follows: fixed value of 0 on the left side, fixed value of 1 on the right side, and a fixed flux of 0 on the top and bottom sides. The analytical solution is clearly a uniform gradient going from left to right. this problem was implemented using a Cartesian Grid2D mesh with each interior vertex displaced a short distance in a random direction to create non-orthogonality. Then the root-mean-square error was plotted against the root-mean-square non-orthogonality. The error in each cell was calculated by simply subtracting the analytical solution at each cell center from the calculated value for that cell. The non-orthogonality in each cell is the average, weighted by face area, of the sines of the angles between the face normals and the line segments joining the cells. Thus, the non-orthogonality of a cell can range from 0 (every face is orthogonal to its corresponding cell-to-cell line segment) to 1 (only possible in a degenerate case). This test was run using 500 separate 20x20 meshes and 500 separate 10x10 meshes, each with the interior vertices moved different amounts so as to created different levels of non-orthogonality. The results are shown below.
Results for 20x20 mesh:
Results for 10x10 mesh:
It is clear from the graphs that finer meshes decrease the error due to non-orthogonality, and that even with a reasonably coarse mesh the error is quite low. However, note that this test is only for a simple 1D diffusion problem with a constant diffusion coefficient, and it is unknown whether the results will be significantly different with more complicated problems.
Test cases:
>>> newmesh = GmshImporter3D('fipy/meshes/numMesh/testgmsh.msh')
>>> print newmesh.getVertexCoords()
[[ 0. 0.5 1. 0.5 0.5]
[ 0. 0.5 0. 1. 0.5]
[ 0. 1. 0. 0. 0.5]]
>>> print newmesh._getFaceVertexIDs()
[[2 4 4 4 3 4 4 3 4 3]
[1 1 2 2 1 3 3 2 3 2]
[0 0 0 1 0 0 1 0 2 1]]
>>> print newmesh._getCellFaceIDs()
[[0 4 7 9]
[1 1 2 3]
[2 5 5 6]
[3 6 8 8]]
>>> mesh = GmshImporter2DIn3DSpace('fipy/meshes/numMesh/GmshTest2D.msh')
>>> print mesh.getVertexCoords()
[[ 0. 1. 0.5 0. 1. 0.5 0. 1. ]
[ 0. 0. 0.5 1. 1. 1.5 2. 2. ]
[ 0. 0. 0. 0. 0. 0. 0. 0. ]]
>>> mesh = GmshImporter2D('fipy/meshes/numMesh/GmshTest2D.msh')
>>> print mesh.getVertexCoords()
[[ 0. 1. 0.5 0. 1. 0.5 0. 1. ]
[ 0. 0. 0.5 1. 1. 1.5 2. 2. ]]
>>> print mesh._getFaceVertexIDs()
[[2 0 1 0 3 1 4 4 3 5 3 6 5 7 7]
[0 1 2 3 2 4 2 3 5 4 6 5 7 4 6]]
>>> print (mesh._getCellFaceIDs() == [[0, 0, 2, 7, 7, 8, 12, 14],
... [1, 3, 5, 4, 8, 10, 13, 11],
... [2, 4, 6, 6, 9, 11, 9, 12]]).flatten().all()
True
The following test case is to test the handedness of the mesh to check it does not return negative volumes. Firstly we set up a list with tuples of strings to be read by gmsh. The list provide instuctions to gmsh to form a circular mesh.
>>> cellSize = 0.7
>>> radius = 1.
>>> lines = ['cellSize = ' + str(cellSize) + ';\n',
... 'radius = ' + str(radius) + ';\n',
... 'Point(1) = {0, 0, 0, cellSize};\n',
... 'Point(2) = {-radius, 0, 0, cellSize};\n',
... 'Point(3) = {0, radius, 0, cellSize};\n',
... 'Point(4) = {radius, 0, 0, cellSize};\n',
... 'Point(5) = {0, -radius, 0, cellSize};\n',
... 'Circle(6) = {2, 1, 3};\n',
... 'Circle(7) = {3, 1, 4};\n',
... 'Circle(8) = {4, 1, 5};\n',
... 'Circle(9) = {5, 1, 2};\n',
... 'Line Loop(10) = {6, 7, 8, 9} ;\n',
... 'Plane Surface(11) = {10};\n']
Check that the sign of the mesh volumes is correct
>>> mesh = GmshImporter2D(lines)
>>> print mesh.getCellVolumes()[0] > 0
1
Reverse the handedness of the mesh and check the sign
>>> lines[7:12] = ['Circle(6) = {3, 1, 2};\n',
... 'Circle(7) = {4, 1, 3};\n',
... 'Circle(8) = {5, 1, 4};\n',
... 'Circle(9) = {2, 1, 5};\n',
... 'Line Loop(10) = {9, 8, 7, 6};\n',]
>>> mesh = GmshImporter2D(lines)
>>> print mesh.getCellVolumes()[0] > 0
1
Bases: fipy.meshes.numMesh.mesh2D.Mesh2D
Bases: fipy.meshes.numMesh.mesh.Mesh
>>> mesh = GmshImporter3D('fipy/meshes/numMesh/testgmsh.msh')
Bases: exceptions.Exception
1D Mesh
Bases: fipy.meshes.numMesh.mesh1D.Mesh1D
Creates a 1D grid mesh.
>>> mesh = Grid1D(nx = 3)
>>> print mesh.getCellCenters()
[[ 0.5 1.5 2.5]]
>>> mesh = Grid1D(dx = (1, 2, 3))
>>> print mesh.getCellCenters()
[[ 0.5 2. 4.5]]
>>> mesh = Grid1D(nx = 2, dx = (1, 2, 3))
Traceback (most recent call last):
...
IndexError: nx != len(dx)
Return physical dimensions of Grid1D.
2D rectangular Mesh
Bases: fipy.meshes.numMesh.mesh2D.Mesh2D
Creates a 2D grid mesh with horizontal faces numbered first and then vertical faces.
Return physical dimensions of Grid2D.
Bases: fipy.meshes.numMesh.mesh.Mesh
3D rectangular-prism Mesh
X axis runs from left to right. Y axis runs from bottom to top. Z axis runs from front to back.
Numbering System:
Vertices: Numbered in the usual way. X coordinate changes most quickly, then Y, then Z.
Cells: Same numbering system as vertices.
Faces: XY faces numbered first, then XZ faces, then YZ faces. Within each subcategory, it is numbered in the usual way.
Return physical dimensions of Grid3D.
Bases: fipy.meshes.common.mesh.Mesh
Generic mesh class using numerix to do the calculations
Meshes contain cells, faces, and vertices.
This is built for a non-mixed element mesh.
faceVertexIds and cellFacesIds must be padded with minus ones.
Return only the faces that have one neighboring cell.
Return only the faces that have two neighboring cells.
Returns a TVTK DataSet representing the cells of this mesh
Returns a TVTK DataSet representing the face centers of this mesh
Bases: exceptions.Exception
Generic mesh class using numerix to do the calculations
Meshes contain cells, faces, and vertices.
This is built for a non-mixed element mesh.
Bases: fipy.meshes.numMesh.mesh.Mesh
faceVertexIds and cellFacesIds must be padded with minus ones.
Generic mesh class using numerix to do the calculations
Meshes contain cells, faces, and vertices.
This is built for a non-mixed element mesh.
Bases: fipy.meshes.numMesh.mesh.Mesh
faceVertexIds and cellFacesIds must be padded with minus ones.
This function returns a new 3D mesh. The 2D mesh is extruded using the extrudeFunc and the number of layers.
Parameters : |
|
---|
>>> from fipy.meshes.grid2D import Grid2D
>>> print Grid2D(nx=2,ny=2).extrude(layers=2).getCellCenters()
[[ 0.5 1.5 0.5 1.5 0.5 1.5 0.5 1.5]
[ 0.5 0.5 1.5 1.5 0.5 0.5 1.5 1.5]
[ 0.5 0.5 0.5 0.5 1.5 1.5 1.5 1.5]]
>>> from fipy.meshes.tri2D import Tri2D
>>> print Tri2D().extrude(layers=2).getCellCenters()
[[ 0.83333333 0.5 0.16666667 0.5 0.83333333 0.5
0.16666667 0.5 ]
[ 0.5 0.83333333 0.5 0.16666667 0.5 0.83333333
0.5 0.16666667]
[ 0.5 0.5 0.5 0.5 1.5 1.5 1.5
1.5 ]]
Peridoic 1D Mesh
Bases: fipy.meshes.numMesh.grid1D.Grid1D
>>> from fipy import numerix
>>> from fipy.tools import parallel
Creates a Periodic grid mesh.
>>> mesh = PeriodicGrid1D(dx = (1, 2, 3))
>>> print (parallel.procID > 0
... or numerix.allclose(numerix.nonzero(mesh.getExteriorFaces())[0],
... [3]))
True
>>> print (parallel.procID > 0
... or numerix.allclose(mesh.getFaceCellIDs().filled(-999),
... [[2, 0, 1, 2],
... [0, 1, 2, -999]]))
True
>>> print (parallel.procID > 0
... or numerix.allclose(mesh._getCellDistances(),
... [ 2., 1.5, 2.5, 1.5]))
True
>>> print (parallel.procID > 0
... or numerix.allclose(mesh._getCellToCellDistances(),
... [[ 2., 1.5, 2.5],
... [ 1.5, 2.5, 2. ]]))
True
>>> print (parallel.procID > 0
... or numerix.allclose(mesh._getFaceNormals(),
... [[ 1., 1., 1., 1.]]))
True
>>> print (parallel.procID > 0
... or numerix.allclose(mesh._getCellVertexIDs(),
... [[1, 2, 2],
... [0, 1, 0]]))
True
2D periodic rectangular Mesh
Bases: fipy.meshes.numMesh.grid2D.Grid2D
Creates a periodic2D grid mesh with horizontal faces numbered first and then vertical faces. Vertices and cells are numbered in the usual way.
>>> from fipy import numerix
>>> from fipy.tools import parallel
>>> mesh = PeriodicGrid2D(dx = 1., dy = 0.5, nx = 2, ny = 2)
>>> print (parallel.procID > 0 or
... numerix.allclose(numerix.nonzero(mesh.getExteriorFaces())[0],
... [ 4, 5, 8, 11]))
True
>>> print (parallel.procID > 0 or
... numerix.allclose(mesh.getFaceCellIDs().filled(-1),
... [[2, 3, 0, 1, 2, 3, 1, 0, 1, 3, 2, 3],
... [0, 1, 2, 3, -1, -1, 0, 1, -1, 2, 3, -1]]))
True
>>> print (parallel.procID > 0 or
... numerix.allclose(mesh._getCellDistances(),
... [ 0.5, 0.5, 0.5, 0.5, 0.25, 0.25, 1., 1., 0.5, 1., 1., 0.5]))
True
>>> print (parallel.procID > 0
... or numerix.allclose(mesh._getCellFaceIDs(),
... [[0, 1, 2, 3],
... [7, 6, 10, 9],
... [2, 3, 0, 1],
... [6, 7, 9, 10]]))
True
>>> print (parallel.procID > 0 or
... numerix.allclose(mesh._getCellToCellDistances(),
... [[ 0.5, 0.5, 0.5, 0.5],
... [ 1., 1., 1., 1. ],
... [ 0.5, 0.5, 0.5, 0.5],
... [ 1., 1., 1., 1. ]]))
True
>>> normals = [[0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1],
... [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0]]
>>> print (parallel.procID > 0
... or numerix.allclose(mesh._getFaceNormals(), normals))
True
>>> print (parallel.procID > 0
... or numerix.allclose(mesh._getCellVertexIDs(),
... [[4, 5, 7, 8],
... [3, 4, 6, 7],
... [1, 2, 4, 5],
... [0, 1, 3, 4]]))
True
Bases: fipy.meshes.numMesh.mesh2D.Mesh2D
Creates a 2D grid mesh with horizontal faces numbered first and then vertical faces. The points are skewed by a random amount (between rand and -rand) in the X and Y directions.
Return physical dimensions of Grid2D.
Bases: fipy.meshes.numMesh.mesh2D.Mesh2D
This class creates a mesh made out of triangles. It does this by starting with a standard Cartesian mesh (Grid2D) and dividing each cell in that mesh (hereafter referred to as a ‘box’) into four equal parts with the dividing lines being the diagonals.
Creates a 2D triangular mesh with horizontal faces numbered first then vertical faces, then diagonal faces. Vertices are numbered starting with the vertices at the corners of boxes and then the vertices at the centers of boxes. Cells on the right of boxes are numbered first, then cells on the top of boxes, then cells on the left of boxes, then cells on the bottom of boxes. Within each of the ‘sub-categories’ in the above, the vertices, cells and faces are numbered in the usual way.
Parameters : |
|
---|
Return physical dimensions of Grid2D.
1D Mesh
Bases: fipy.meshes.numMesh.grid1D.Grid1D
Creates a 1D grid mesh.
>>> mesh = UniformGrid1D(nx = 3)
>>> print mesh.getCellCenters()
[[ 0.5 1.5 2.5]]
2D rectangular Mesh with constant spacing in x and constant spacing in y
Bases: fipy.meshes.numMesh.grid2D.Grid2D
Creates a 2D grid mesh with horizontal faces numbered first and then vertical faces.
Return only the faces that have one neighboring cell.
Return only the faces that have two neighboring cells.
Bases: fipy.meshes.numMesh.grid3D.Grid3D
3D rectangular-prism Mesh with uniform grid spacing in each dimension.
X axis runs from left to right. Y axis runs from bottom to top. Z axis runs from front to back.
Numbering System:
Vertices: Numbered in the usual way. X coordinate changes most quickly, then Y, then Z.
* arrays are arranged Z, Y, X because in numerix, the final index is the one that changes the most quickly *
Cells: Same numbering system as vertices.
Faces: XY faces numbered first, then XZ faces, then YZ faces. Within each subcategory, it is numbered in the usual way.
Return only the faces that have one neighboring cell.
Return only the faces that have two neighboring cells