Factory function to select between UniformGrid3D and NonUniformGrid3D. If Lx is specified the length of the domain is always Lx regardless of dx.
| Parameters : |
|
|---|
Factory function to select between UniformGrid2D and NonUniformGrid2D. If Lx is specified the length of the domain is always Lx regardless of dx.
| Parameters : |
|
|---|
>>> print Grid2D(Lx=3., nx=2).dx
1.5
Factory function to select between UniformGrid1D and NonUniformGrid1D. If Lx is specified the length of the domain is always Lx regardless of dx.
| Parameters : |
|
|---|
Factory function to select between CylindricalUniformGrid2D and CylindricalNonUniformGrid2D. If Lx is specified the length of the domain is always Lx regardless of dx.
| Parameters : |
|
|---|
Factory function to select between CylindricalUniformGrid1D and CylindricalNonUniformGrid1D. If Lx is specified the length of the domain is always Lx regardless of dx.
| Parameters : |
|
|---|
Bases: fipy.meshes.nonUniformGrid1D.NonUniformGrid1D
Creates a Periodic grid mesh.
>>> mesh = PeriodicGrid1D(dx = (1, 2, 3))
>>> print numerix.allclose(numerix.nonzero(mesh.exteriorFaces)[0],
... [3])
True
>>> print numerix.allclose(mesh.faceCellIDs.filled(-999),
... [[2, 0, 1, 2],
... [0, 1, 2, -999]])
True
>>> print numerix.allclose(mesh._cellDistances,
... [ 2., 1.5, 2.5, 1.5])
True
>>> print numerix.allclose(mesh._cellToCellDistances,
... [[ 2., 1.5, 2.5],
... [ 1.5, 2.5, 2. ]])
True
>>> print numerix.allclose(mesh._faceNormals,
... [[ 1., 1., 1., 1.]])
True
>>> print numerix.allclose(mesh._cellVertexIDs,
... [[1, 2, 2],
... [0, 1, 0]])
True
Defined outside of a geometry class since we need the CellVariable version of cellCenters; that is, the cellCenters defined in fipy.meshes.mesh and not in any geometry (since a CellVariable requires a reference to a mesh).
Bases: fipy.meshes.periodicGrid2D._BasePeriodicGrid2D
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
>>> mesh = PeriodicGrid2D(dx = 1., dy = 0.5, nx = 2, ny = 2)
>>> print numerix.allclose(numerix.nonzero(mesh.exteriorFaces)[0],
... [ 4, 5, 8, 11])
True
>>> print numerix.allclose(mesh.faceCellIDs.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 numerix.allclose(mesh._cellDistances,
... [ 0.5, 0.5, 0.5, 0.5, 0.25, 0.25, 1., 1., 0.5, 1., 1., 0.5])
True
>>> print numerix.allclose(mesh.cellFaceIDs,
... [[0, 1, 2, 3],
... [7, 6, 10, 9],
... [2, 3, 0, 1],
... [6, 7, 9, 10]])
True
>>> print numerix.allclose(mesh._cellToCellDistances,
... [[ 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 numerix.allclose(mesh._faceNormals, normals)
True
>>> print numerix.allclose(mesh._cellVertexIDs,
... [[4, 5, 7, 8],
... [3, 4, 6, 7],
... [1, 2, 4, 5],
... [0, 1, 3, 4]])
True
Bases: fipy.meshes.periodicGrid2D._BasePeriodicGrid2D
Bases: fipy.meshes.periodicGrid2D._BasePeriodicGrid2D
Bases: fipy.meshes.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.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.
Open a Gmsh MSH file
| Parameters : |
|
|---|
Open a Gmsh POS post-processing file
Bases: fipy.meshes.mesh2D.Mesh2D
Construct a 2D Mesh using Gmsh
>>> radius = 5.
>>> side = 4.
>>> squaredCircle = Gmsh2D('''
... // A mesh consisting of a square inside a circle inside a circle
...
... // define the basic dimensions of the mesh
...
... cellSize = 1;
... radius = %(radius)g;
... side = %(side)g;
...
... // define the compass points of the inner circle
...
... Point(1) = {0, 0, 0, cellSize};
... Point(2) = {-radius, 0, 0, cellSize};
... Point(3) = {0, radius, 0, cellSize};
... Point(4) = {radius, 0, 0, cellSize};
... Point(5) = {0, -radius, 0, cellSize};
...
... // define the compass points of the outer circle
...
... Point(6) = {-2*radius, 0, 0, cellSize};
... Point(7) = {0, 2*radius, 0, cellSize};
... Point(8) = {2*radius, 0, 0, cellSize};
... Point(9) = {0, -2*radius, 0, cellSize};
...
... // define the corners of the square
...
... Point(10) = {side/2, side/2, 0, cellSize/2};
... Point(11) = {-side/2, side/2, 0, cellSize/2};
... Point(12) = {-side/2, -side/2, 0, cellSize/2};
... Point(13) = {side/2, -side/2, 0, cellSize/2};
...
... // define the inner circle
...
... Circle(1) = {2, 1, 3};
... Circle(2) = {3, 1, 4};
... Circle(3) = {4, 1, 5};
... Circle(4) = {5, 1, 2};
...
... // define the outer circle
...
... Circle(5) = {6, 1, 7};
... Circle(6) = {7, 1, 8};
... Circle(7) = {8, 1, 9};
... Circle(8) = {9, 1, 6};
...
... // define the square
...
... Line(9) = {10, 13};
... Line(10) = {13, 12};
... Line(11) = {12, 11};
... Line(12) = {11, 10};
...
... // define the three boundaries
...
... Line Loop(1) = {1, 2, 3, 4};
... Line Loop(2) = {5, 6, 7, 8};
... Line Loop(3) = {9, 10, 11, 12};
...
... // define the three domains
...
... Plane Surface(1) = {2, 1};
... Plane Surface(2) = {1, 3};
... Plane Surface(3) = {3};
...
... // label the three domains
...
... // attention: if you use any "Physical" labels, you *must* label
... // all elements that correspond to FiPy Cells (Physical Surace in 2D
... // and Physical Volume in 3D) or Gmsh will not include them and FiPy
... // will not be able to include them in the Mesh.
...
... // note: if you do not use any labels, all Cells will be included.
...
... Physical Surface("Outer") = {1};
... Physical Surface("Middle") = {2};
... Physical Surface("Inner") = {3};
...
... // label the "north-west" part of the exterior boundary
...
... // note: you only need to label the Face elements
... // (Physical Line in 2D and Physical Surface in 3D) that correspond
... // to boundaries you are interested in. FiPy does not need them to
... // construct the Mesh.
...
... Physical Line("NW") = {5};
... ''' % locals())
It can be easier to specify certain domains and boundaries within Gmsh than it is to define the same domains and boundaries with FiPy expressions.
Here we compare obtaining the same Cells and Faces using FiPy’s parametric descriptions and Gmsh’s labels.
>>> x, y = squaredCircle.cellCenters
>>> middle = ((x**2 + y**2 <= radius**2)
... & ~((x > -side/2) & (x < side/2)
... & (y > -side/2) & (y < side/2)))
>>> print (middle == squaredCircle.physicalCells["Middle"]).all()
True
>>> X, Y = squaredCircle.faceCenters
>>> NW = ((X**2 + Y**2 > (1.99*radius)**2)
... & (X**2 + Y**2 < (2.01*radius)**2)
... & (X <= 0) & (Y >= 0))
>>> print (NW == squaredCircle.physicalFaces["NW"]).all()
True
It is possible to direct Gmsh to give the mesh different densities in different locations
>>> geo = '''
... // A mesh consisting of a square
...
... // define the corners of the square
...
... Point(1) = {1, 1, 0, 1};
... Point(2) = {0, 1, 0, 1};
... Point(3) = {0, 0, 0, 1};
... Point(4) = {1, 0, 0, 1};
...
... // define the square
...
... Line(1) = {1, 2};
... Line(2) = {2, 3};
... Line(3) = {3, 4};
... Line(4) = {4, 1};
...
... // define the boundary
...
... Line Loop(1) = {1, 2, 3, 4};
...
... // define the domain
...
... Plane Surface(1) = {1};
... '''
>>> from fipy import CellVariable, numerix
>>> std = []
>>> bkg = None
>>> for refine in range(4):
... square = Gmsh2D(geo, background=bkg)
... x, y = square.cellCenters
... bkg = CellVariable(mesh=square, value=abs(x / 4) + 0.01)
... std.append(numerix.std(numerix.sqrt(2 * square.cellVolumes) / bkg))
Check that the mesh is monotonically approaching the desired density
>>> print numerix.greater(std[:-1], std[1:]).all()
True
and that the final density is close enough to the desired density
>>> print std[-1] < 0.2
True
The initial mesh doesn’t have to be from Gmsh
>>> from fipy import Tri2D
>>> trisquare = Tri2D(nx=1, ny=1)
>>> x, y = trisquare.cellCenters
>>> bkg = CellVariable(mesh=trisquare, value=abs(x / 4) + 0.01)
>>> std1 = numerix.std(numerix.sqrt(2 * trisquare.cellVolumes) / bkg)
>>> square = Gmsh2D(geo, background=bkg)
>>> x, y = square.cellCenters
>>> bkg = CellVariable(mesh=square, value=abs(x / 4) + 0.01)
>>> std2 = numerix.std(numerix.sqrt(2 * square.cellVolumes) / bkg)
>>> print std1 > std2
True
| Parameters : |
|
|---|
Bases: fipy.meshes.gmshMesh.Gmsh2D
Create a topologically 2D Mesh in 3D coordinates using Gmsh
| Parameters : |
|
|---|
Bases: fipy.meshes.mesh.Mesh
Create a 3D Mesh using Gmsh
| Parameters : |
|
|---|
Bases: fipy.meshes.gmshMesh.Gmsh2D
Should serve as a drop-in replacement for Grid2D.
Bases: fipy.meshes.gmshMesh.Gmsh3D
Should serve as a drop-in replacement for Grid3D.
Bases: fipy.meshes.gmshMesh.Gmsh2D
Bases: fipy.meshes.gmshMesh.Gmsh3D
Bases: object
A class encapsulating all commonalities among meshes in FiPy.
Returns a TVTK DataSet representing the cells of this mesh
Returns a TVTK DataSet representing the face centers of this mesh
The physical y:x aspect ratio of a 2D mesh
Topology properties
Return list of faces on back boundary of Grid3D with the z-axis running from front to back.
>>> from fipy import Grid3D, numerix
>>> mesh = Grid3D(nx = 3, ny = 2, nz = 1, dx = 0.5, dy = 2., dz = 4.)
>>> print numerix.allequal((6, 7, 8, 9, 10, 11),
... numerix.nonzero(mesh.facesBack)[0])
True
Return list of faces on bottom boundary of Grid3D with the y-axis running from bottom to top.
>>> from fipy import Grid2D, Grid3D, numerix
>>> mesh = Grid3D(nx = 3, ny = 2, nz = 1, dx = 0.5, dy = 2., dz = 4.)
>>> print numerix.allequal((12, 13, 14),
... numerix.nonzero(mesh.facesBottom)[0])
1
>>> x, y, z = mesh.faceCenters
>>> print numerix.allequal((12, 13),
... numerix.nonzero(mesh.facesBottom & (x < 1))[0])
1
Return list of faces on bottom boundary of Grid3D with the y-axis running from bottom to top.
>>> from fipy import Grid2D, Grid3D, numerix
>>> mesh = Grid3D(nx = 3, ny = 2, nz = 1, dx = 0.5, dy = 2., dz = 4.)
>>> print numerix.allequal((12, 13, 14),
... numerix.nonzero(mesh.facesBottom)[0])
1
>>> x, y, z = mesh.faceCenters
>>> print numerix.allequal((12, 13),
... numerix.nonzero(mesh.facesBottom & (x < 1))[0])
1
Return list of faces on front boundary of Grid3D with the z-axis running from front to back.
>>> from fipy import Grid3D, numerix
>>> mesh = Grid3D(nx = 3, ny = 2, nz = 1, dx = 0.5, dy = 2., dz = 4.)
>>> print numerix.allequal((0, 1, 2, 3, 4, 5),
... numerix.nonzero(mesh.facesFront)[0])
True
Return face on left boundary of Grid1D as list with the x-axis running from left to right.
>>> from fipy import Grid2D, Grid3D
>>> mesh = Grid3D(nx = 3, ny = 2, nz = 1, dx = 0.5, dy = 2., dz = 4.)
>>> print numerix.allequal((21, 25),
... numerix.nonzero(mesh.facesLeft)[0])
True
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print numerix.allequal((9, 13),
... numerix.nonzero(mesh.facesLeft)[0])
True
Return list of faces on right boundary of Grid3D with the x-axis running from left to right.
>>> from fipy import Grid2D, Grid3D, numerix
>>> mesh = Grid3D(nx = 3, ny = 2, nz = 1, dx = 0.5, dy = 2., dz = 4.)
>>> print numerix.allequal((24, 28),
... numerix.nonzero(mesh.facesRight)[0])
True
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print numerix.allequal((12, 16),
... numerix.nonzero(mesh.facesRight)[0])
True
Return list of faces on top boundary of Grid3D with the y-axis running from bottom to top.
>>> from fipy import Grid2D, Grid3D, numerix
>>> mesh = Grid3D(nx = 3, ny = 2, nz = 1, dx = 0.5, dy = 2., dz = 4.)
>>> print numerix.allequal((18, 19, 20),
... numerix.nonzero(mesh.facesTop)[0])
True
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print numerix.allequal((6, 7, 8),
... numerix.nonzero(mesh.facesTop)[0])
True
Return list of faces on top boundary of Grid3D with the y-axis running from bottom to top.
>>> from fipy import Grid2D, Grid3D, numerix
>>> mesh = Grid3D(nx = 3, ny = 2, nz = 1, dx = 0.5, dy = 2., dz = 4.)
>>> print numerix.allequal((18, 19, 20),
... numerix.nonzero(mesh.facesTop)[0])
True
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print numerix.allequal((6, 7, 8),
... numerix.nonzero(mesh.facesTop)[0])
True
Deprecated since version 3.0: use the cellCenters property instead
Deprecated since version 3.0: use the cellVolumes property instead
Deprecated since version 3.0: use the dim property instead
Deprecated since version 3.0: use the exteriorFaces property instead
Return only the faces that have one neighboring cell.
Deprecated since version 3.0: use the faceCellIDs property instead
Deprecated since version 3.0: use the faceCenters property instead
Deprecated since version 3.0: use the facesBottom property instead
Deprecated since version 3.0: use the facesBottom property instead
Deprecated since version 3.0: use the facesFront property instead
Deprecated since version 3.0: use the facesRight property instead
Deprecated since version 3.0: use the interiorFaceCellIDs property instead
Deprecated since version 3.0: use the interiorFaceIDs property instead
Deprecated since version 3.0: use the interiorFaces property instead
Return only the faces that have two neighboring cells.
Deprecated since version 3.0: use the numberOfCells property instead
Deprecated since version 3.0: use the physicalShape property instead
Deprecated since version 3.0: use the shape property instead
Deprecated since version 3.0: use the vertexCoords property instead
Equivalent to using cellCenters[0].
>>> from fipy import *
>>> print Grid1D(nx=2).x
[ 0.5 1.5]
Equivalent to using cellCenters[1].
>>> from fipy import *
>>> print Grid2D(nx=2, ny=2).y
[ 0.5 0.5 1.5 1.5]
>>> print Grid1D(nx=2).y
Traceback (most recent call last):
...
AttributeError: 1D meshes do not have a "y" attribute.
Equivalent to using cellCenters[2].
>>> from fipy import *
>>> print Grid3D(nx=2, ny=2, nz=2).z
[ 0.5 0.5 0.5 0.5 1.5 1.5 1.5 1.5]
>>> print Grid2D(nx=2, ny=2).z
Traceback (most recent call last):
...
AttributeError: 1D and 2D meshes do not have a "z" attribute.
1D Mesh
Bases: fipy.meshes.nonUniformGrid1D.NonUniformGrid1D
Creates a 1D cylindrical grid mesh.
>>> mesh = CylindricalNonUniformGrid1D(nx = 3)
>>> print mesh.cellCenters
[[ 0.5 1.5 2.5]]
>>> mesh = CylindricalNonUniformGrid1D(dx = (1, 2, 3))
>>> print mesh.cellCenters
[[ 0.5 2. 4.5]]
>>> print numerix.allclose(mesh.cellVolumes, (0.5, 4., 13.5))
True
>>> mesh = CylindricalNonUniformGrid1D(nx = 2, dx = (1, 2, 3))
Traceback (most recent call last):
...
IndexError: nx != len(dx)
>>> mesh = CylindricalNonUniformGrid1D(nx=2, dx=(1., 2.)) + ((1.,),)
>>> print mesh.cellCenters
[[ 1.5 3. ]]
>>> print numerix.allclose(mesh.cellVolumes, (1.5, 6))
True
2D rectangular Mesh
Bases: fipy.meshes.nonUniformGrid2D.NonUniformGrid2D
Creates a 2D cylindrical grid mesh with horizontal faces numbered first and then vertical faces.
1D Mesh
Bases: fipy.meshes.uniformGrid1D.UniformGrid1D
Creates a 1D cylindrical grid mesh.
>>> mesh = CylindricalUniformGrid1D(nx = 3)
>>> print mesh.cellCenters
[[ 0.5 1.5 2.5]]
2D cylindrical rectangular Mesh with constant spacing in x and constant spacing in y
Bases: fipy.meshes.uniformGrid2D.UniformGrid2D
Creates a 2D cylindrical grid in the radial and axial directions, appropriate for axial symmetry.
Factory function to select between UniformGrid3D and NonUniformGrid3D. If Lx is specified the length of the domain is always Lx regardless of dx.
| Parameters : |
|
|---|
Factory function to select between UniformGrid2D and NonUniformGrid2D. If Lx is specified the length of the domain is always Lx regardless of dx.
| Parameters : |
|
|---|
>>> print Grid2D(Lx=3., nx=2).dx
1.5
Factory function to select between UniformGrid1D and NonUniformGrid1D. If Lx is specified the length of the domain is always Lx regardless of dx.
| Parameters : |
|
|---|
Factory function to select between CylindricalUniformGrid2D and CylindricalNonUniformGrid2D. If Lx is specified the length of the domain is always Lx regardless of dx.
| Parameters : |
|
|---|
Factory function to select between CylindricalUniformGrid1D and CylindricalNonUniformGrid1D. If Lx is specified the length of the domain is always Lx regardless of dx.
| Parameters : |
|
|---|
Open a Gmsh MSH file
| Parameters : |
|
|---|
Open a Gmsh POS post-processing file
Bases: fipy.meshes.mesh2D.Mesh2D
Construct a 2D Mesh using Gmsh
>>> radius = 5.
>>> side = 4.
>>> squaredCircle = Gmsh2D('''
... // A mesh consisting of a square inside a circle inside a circle
...
... // define the basic dimensions of the mesh
...
... cellSize = 1;
... radius = %(radius)g;
... side = %(side)g;
...
... // define the compass points of the inner circle
...
... Point(1) = {0, 0, 0, cellSize};
... Point(2) = {-radius, 0, 0, cellSize};
... Point(3) = {0, radius, 0, cellSize};
... Point(4) = {radius, 0, 0, cellSize};
... Point(5) = {0, -radius, 0, cellSize};
...
... // define the compass points of the outer circle
...
... Point(6) = {-2*radius, 0, 0, cellSize};
... Point(7) = {0, 2*radius, 0, cellSize};
... Point(8) = {2*radius, 0, 0, cellSize};
... Point(9) = {0, -2*radius, 0, cellSize};
...
... // define the corners of the square
...
... Point(10) = {side/2, side/2, 0, cellSize/2};
... Point(11) = {-side/2, side/2, 0, cellSize/2};
... Point(12) = {-side/2, -side/2, 0, cellSize/2};
... Point(13) = {side/2, -side/2, 0, cellSize/2};
...
... // define the inner circle
...
... Circle(1) = {2, 1, 3};
... Circle(2) = {3, 1, 4};
... Circle(3) = {4, 1, 5};
... Circle(4) = {5, 1, 2};
...
... // define the outer circle
...
... Circle(5) = {6, 1, 7};
... Circle(6) = {7, 1, 8};
... Circle(7) = {8, 1, 9};
... Circle(8) = {9, 1, 6};
...
... // define the square
...
... Line(9) = {10, 13};
... Line(10) = {13, 12};
... Line(11) = {12, 11};
... Line(12) = {11, 10};
...
... // define the three boundaries
...
... Line Loop(1) = {1, 2, 3, 4};
... Line Loop(2) = {5, 6, 7, 8};
... Line Loop(3) = {9, 10, 11, 12};
...
... // define the three domains
...
... Plane Surface(1) = {2, 1};
... Plane Surface(2) = {1, 3};
... Plane Surface(3) = {3};
...
... // label the three domains
...
... // attention: if you use any "Physical" labels, you *must* label
... // all elements that correspond to FiPy Cells (Physical Surace in 2D
... // and Physical Volume in 3D) or Gmsh will not include them and FiPy
... // will not be able to include them in the Mesh.
...
... // note: if you do not use any labels, all Cells will be included.
...
... Physical Surface("Outer") = {1};
... Physical Surface("Middle") = {2};
... Physical Surface("Inner") = {3};
...
... // label the "north-west" part of the exterior boundary
...
... // note: you only need to label the Face elements
... // (Physical Line in 2D and Physical Surface in 3D) that correspond
... // to boundaries you are interested in. FiPy does not need them to
... // construct the Mesh.
...
... Physical Line("NW") = {5};
... ''' % locals())
It can be easier to specify certain domains and boundaries within Gmsh than it is to define the same domains and boundaries with FiPy expressions.
Here we compare obtaining the same Cells and Faces using FiPy’s parametric descriptions and Gmsh’s labels.
>>> x, y = squaredCircle.cellCenters
>>> middle = ((x**2 + y**2 <= radius**2)
... & ~((x > -side/2) & (x < side/2)
... & (y > -side/2) & (y < side/2)))
>>> print (middle == squaredCircle.physicalCells["Middle"]).all()
True
>>> X, Y = squaredCircle.faceCenters
>>> NW = ((X**2 + Y**2 > (1.99*radius)**2)
... & (X**2 + Y**2 < (2.01*radius)**2)
... & (X <= 0) & (Y >= 0))
>>> print (NW == squaredCircle.physicalFaces["NW"]).all()
True
It is possible to direct Gmsh to give the mesh different densities in different locations
>>> geo = '''
... // A mesh consisting of a square
...
... // define the corners of the square
...
... Point(1) = {1, 1, 0, 1};
... Point(2) = {0, 1, 0, 1};
... Point(3) = {0, 0, 0, 1};
... Point(4) = {1, 0, 0, 1};
...
... // define the square
...
... Line(1) = {1, 2};
... Line(2) = {2, 3};
... Line(3) = {3, 4};
... Line(4) = {4, 1};
...
... // define the boundary
...
... Line Loop(1) = {1, 2, 3, 4};
...
... // define the domain
...
... Plane Surface(1) = {1};
... '''
>>> from fipy import CellVariable, numerix
>>> std = []
>>> bkg = None
>>> for refine in range(4):
... square = Gmsh2D(geo, background=bkg)
... x, y = square.cellCenters
... bkg = CellVariable(mesh=square, value=abs(x / 4) + 0.01)
... std.append(numerix.std(numerix.sqrt(2 * square.cellVolumes) / bkg))
Check that the mesh is monotonically approaching the desired density
>>> print numerix.greater(std[:-1], std[1:]).all()
True
and that the final density is close enough to the desired density
>>> print std[-1] < 0.2
True
The initial mesh doesn’t have to be from Gmsh
>>> from fipy import Tri2D
>>> trisquare = Tri2D(nx=1, ny=1)
>>> x, y = trisquare.cellCenters
>>> bkg = CellVariable(mesh=trisquare, value=abs(x / 4) + 0.01)
>>> std1 = numerix.std(numerix.sqrt(2 * trisquare.cellVolumes) / bkg)
>>> square = Gmsh2D(geo, background=bkg)
>>> x, y = square.cellCenters
>>> bkg = CellVariable(mesh=square, value=abs(x / 4) + 0.01)
>>> std2 = numerix.std(numerix.sqrt(2 * square.cellVolumes) / bkg)
>>> print std1 > std2
True
| Parameters : |
|
|---|
Bases: fipy.meshes.gmshMesh.Gmsh2D
Create a topologically 2D Mesh in 3D coordinates using Gmsh
| Parameters : |
|
|---|
Bases: fipy.meshes.mesh.Mesh
Create a 3D Mesh using Gmsh
| Parameters : |
|
|---|
Bases: fipy.meshes.gmshMesh.Gmsh2D
Should serve as a drop-in replacement for Grid2D.
Bases: fipy.meshes.gmshMesh.Gmsh3D
Should serve as a drop-in replacement for Grid3D.
Bases: fipy.meshes.gmshMesh.Gmsh2D
Bases: fipy.meshes.gmshMesh.Gmsh3D
Bases: exceptions.Exception
Bases: fipy.meshes.abstractMesh.AbstractMesh
Generic mesh class using numerix to do the calculations
Meshes contain cells, faces, and vertices.
This is built for a non-mixed element 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.
Bases: fipy.meshes.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.
Bases: fipy.meshes.mesh.Mesh
This function returns a new 3D mesh. The 2D mesh is extruded using the extrudeFunc and the number of layers.
| Parameters : |
|
|---|
>>> from fipy.meshes.nonUniformGrid2D import NonUniformGrid2D
>>> print NonUniformGrid2D(nx=2,ny=2).extrude(layers=2).cellCenters
[[ 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).cellCenters
[[ 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 ]]
1D Mesh
Bases: fipy.meshes.mesh1D.Mesh1D
Creates a 1D grid mesh.
>>> mesh = NonUniformGrid1D(nx = 3)
>>> print mesh.cellCenters
[[ 0.5 1.5 2.5]]
>>> mesh = NonUniformGrid1D(dx = (1, 2, 3))
>>> print mesh.cellCenters
[[ 0.5 2. 4.5]]
>>> mesh = NonUniformGrid1D(nx = 2, dx = (1, 2, 3))
Traceback (most recent call last):
...
IndexError: nx != len(dx)
2D rectangular Mesh
Bases: fipy.meshes.mesh2D.Mesh2D
Creates a 2D grid mesh with horizontal faces numbered first and then vertical faces.
Bases: fipy.meshes.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.
Peridoic 1D Mesh
Bases: fipy.meshes.nonUniformGrid1D.NonUniformGrid1D
Creates a Periodic grid mesh.
>>> mesh = PeriodicGrid1D(dx = (1, 2, 3))
>>> print numerix.allclose(numerix.nonzero(mesh.exteriorFaces)[0],
... [3])
True
>>> print numerix.allclose(mesh.faceCellIDs.filled(-999),
... [[2, 0, 1, 2],
... [0, 1, 2, -999]])
True
>>> print numerix.allclose(mesh._cellDistances,
... [ 2., 1.5, 2.5, 1.5])
True
>>> print numerix.allclose(mesh._cellToCellDistances,
... [[ 2., 1.5, 2.5],
... [ 1.5, 2.5, 2. ]])
True
>>> print numerix.allclose(mesh._faceNormals,
... [[ 1., 1., 1., 1.]])
True
>>> print numerix.allclose(mesh._cellVertexIDs,
... [[1, 2, 2],
... [0, 1, 0]])
True
Defined outside of a geometry class since we need the CellVariable version of cellCenters; that is, the cellCenters defined in fipy.meshes.mesh and not in any geometry (since a CellVariable requires a reference to a mesh).
2D periodic rectangular Mesh
Bases: fipy.meshes.periodicGrid2D._BasePeriodicGrid2D
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
>>> mesh = PeriodicGrid2D(dx = 1., dy = 0.5, nx = 2, ny = 2)
>>> print numerix.allclose(numerix.nonzero(mesh.exteriorFaces)[0],
... [ 4, 5, 8, 11])
True
>>> print numerix.allclose(mesh.faceCellIDs.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 numerix.allclose(mesh._cellDistances,
... [ 0.5, 0.5, 0.5, 0.5, 0.25, 0.25, 1., 1., 0.5, 1., 1., 0.5])
True
>>> print numerix.allclose(mesh.cellFaceIDs,
... [[0, 1, 2, 3],
... [7, 6, 10, 9],
... [2, 3, 0, 1],
... [6, 7, 9, 10]])
True
>>> print numerix.allclose(mesh._cellToCellDistances,
... [[ 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 numerix.allclose(mesh._faceNormals, normals)
True
>>> print numerix.allclose(mesh._cellVertexIDs,
... [[4, 5, 7, 8],
... [3, 4, 6, 7],
... [1, 2, 4, 5],
... [0, 1, 3, 4]])
True
Bases: fipy.meshes.periodicGrid2D._BasePeriodicGrid2D
Bases: fipy.meshes.periodicGrid2D._BasePeriodicGrid2D
Bases: fipy.meshes.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.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.
Bases: fipy.meshes.abstractMesh.AbstractMesh
Wrapped scaled geometry properties
1D Mesh
Bases: fipy.meshes.uniformGrid.UniformGrid
Creates a 1D grid mesh.
>>> mesh = UniformGrid1D(nx = 3)
>>> print mesh.cellCenters
[[ 0.5 1.5 2.5]]
Geometry set and calc
2D rectangular Mesh with constant spacing in x and constant spacing in y
Bases: fipy.meshes.uniformGrid.UniformGrid
Creates a 2D grid mesh with horizontal faces numbered first and then vertical faces.
Bases: fipy.meshes.uniformGrid.UniformGrid
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.