meshes Package

meshes Package

fipy.meshes.Grid3D(dx=1.0, dy=1.0, dz=1.0, nx=None, ny=None, nz=None, Lx=None, Ly=None, Lz=None, overlap=2, communicator=ParallelCommWrapper())

Factory function to select between UniformGrid3D and NonUniformGrid3D. If Lx is specified the length of the domain is always Lx regardless of dx.

Parameters :
  • dx: grid spacing in the horizontal direction
  • dy: grid spacing in the vertical direction
  • dz: grid spacing in the z-direction
  • nx: number of cells in the horizontal direction
  • ny: number of cells in the vertical direction
  • nz: number of cells in the z-direction
  • Lx: the domain length in the horizontal direction
  • Ly: the domain length in the vertical direction
  • Lz: the domain length in the z-direction
  • overlap: the number of overlapping cells for parallel simulations. Generally 2 is adequate. Higher order equations or discretizations require more.
  • communicator: either fipy.tools.parallelComm or fipy.tools.serialComm. Select fipy.tools.serialComm to create a serial mesh when running in parallel. Mostly used for test purposes.
fipy.meshes.Grid2D(dx=1.0, dy=1.0, nx=None, ny=None, Lx=None, Ly=None, overlap=2, communicator=ParallelCommWrapper())

Factory function to select between UniformGrid2D and NonUniformGrid2D. If Lx is specified the length of the domain is always Lx regardless of dx.

Parameters :
  • dx: grid spacing in the horizontal direction
  • dy: grid spacing in the vertical direction
  • nx: number of cells in the horizontal direction
  • ny: number of cells in the vertical direction
  • Lx: the domain length in the horizontal direction
  • Ly: the domain length in the vertical direction
  • overlap: the number of overlapping cells for parallel simulations. Generally 2 is adequate. Higher order equations or discretizations require more.
  • communicator: either fipy.tools.parallelComm or fipy.tools.serialComm. Select fipy.tools.serialComm to create a serial mesh when running in parallel. Mostly used for test purposes.
>>> print Grid2D(Lx=3., nx=2).dx
1.5
fipy.meshes.Grid1D(dx=1.0, nx=None, Lx=None, overlap=2, communicator=ParallelCommWrapper())

Factory function to select between UniformGrid1D and NonUniformGrid1D. If Lx is specified the length of the domain is always Lx regardless of dx.

Parameters :
  • dx: grid spacing in the horizonal direction
  • nx: number of cells in the horizonal direction
  • Lx: the domain length in the horizonal direction
  • overlap: the number of overlapping cells for parallel simulations. Generally 2 is adequate. Higher order equations or discretizations require more.
  • communicator: either fipy.tools.parallelComm or fipy.tools.serialComm. Select fipy.tools.serialComm to create a serial mesh when running in parallel. Mostly used for test purposes.
fipy.meshes.CylindricalGrid2D(dr=None, dz=None, nr=None, nz=None, Lr=None, Lz=None, dx=1.0, dy=1.0, nx=None, ny=None, Lx=None, Ly=None, origin=((0, ), (0, )), overlap=2, communicator=ParallelCommWrapper())

Factory function to select between CylindricalUniformGrid2D and CylindricalNonUniformGrid2D. If Lx is specified the length of the domain is always Lx regardless of dx.

Parameters :
  • dr or dx: grid spacing in the radial direction
  • dz or dy: grid spacing in the vertical direction
  • nr or nx: number of cells in the radial direction
  • nz or ny: number of cells in the vertical direction
  • Lr or Lx: the domain length in the radial direction
  • Lz or Ly: the domain length in the vertical direction
  • origin : position of the mesh’s origin in the form ((x,),(y,))
  • overlap: the number of overlapping cells for parallel simulations. Generally 2 is adequate. Higher order equations or discretizations require more.
  • communicator: either fipy.tools.parallelComm or fipy.tools.serialComm. Select fipy.tools.serialComm to create a serial mesh when running in parallel. Mostly used for test purposes.
fipy.meshes.CylindricalGrid1D(dr=None, nr=None, Lr=None, dx=1.0, nx=None, Lx=None, origin=(0, ), overlap=2, communicator=ParallelCommWrapper())

Factory function to select between CylindricalUniformGrid1D and CylindricalNonUniformGrid1D. If Lx is specified the length of the domain is always Lx regardless of dx.

Parameters :
  • dr or dx: grid spacing in the radial direction
  • nr or nx: number of cells in the radial direction
  • Lr or Lx: the domain length in the radial direction
  • origin : position of the mesh’s origin in the form (x,)
  • overlap: the number of overlapping cells for parallel simulations. Generally 2 is adequate. Higher order equations or discretizations require more.
  • communicator: either fipy.tools.parallelComm or fipy.tools.serialComm. Select fipy.tools.serialComm to create a serial mesh when running in parallel. Mostly used for test purposes.
class fipy.meshes.PeriodicGrid1D(dx=1.0, nx=None, overlap=2, *args, **kwargs)

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
cellCenters

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).

class fipy.meshes.PeriodicGrid2D(dx=1.0, dy=1.0, nx=None, ny=None, overlap=2, communicator=ParallelCommWrapper(), *args, **kwargs)

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
class fipy.meshes.PeriodicGrid2DLeftRight(dx=1.0, dy=1.0, nx=None, ny=None, overlap=2, communicator=ParallelCommWrapper(), *args, **kwargs)

Bases: fipy.meshes.periodicGrid2D._BasePeriodicGrid2D

class fipy.meshes.PeriodicGrid2DTopBottom(dx=1.0, dy=1.0, nx=None, ny=None, overlap=2, communicator=ParallelCommWrapper(), *args, **kwargs)

Bases: fipy.meshes.periodicGrid2D._BasePeriodicGrid2D

class fipy.meshes.SkewedGrid2D(dx=1.0, dy=1.0, nx=None, ny=1, rand=0, *args, **kwargs)

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.

physicalShape

Return physical dimensions of Grid2D.

shape
class fipy.meshes.Tri2D(dx=1.0, dy=1.0, nx=1, ny=1, _RepresentationClass=<class 'fipy.meshes.representations.gridRepresentation._Grid2DRepresentation'>, _TopologyClass=<class 'fipy.meshes.topologies.meshTopology._Mesh2DTopology'>)

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 :
  • dx, dy: The X and Y dimensions of each ‘box’. If dx <> dy, the line segments connecting the cell centers will not be orthogonal to the faces.
  • nx, ny: The number of boxes in the X direction and the Y direction. The total number of boxes will be equal to nx * ny, and the total number of cells will be equal to 4 * nx * ny.
physicalShape

Return physical dimensions of Grid2D.

shape
fipy.meshes.openMSHFile(name, dimensions=None, coordDimensions=None, communicator=ParallelCommWrapper(), order=1, mode='r', background=None)

Open a Gmsh MSH file

Parameters :
  • filename: a string indicating gmsh output file
  • dimensions: an integer indicating dimension of mesh
  • coordDimensions: an integer indicating dimension of shapes
  • order: ???
  • mode: a string beginning with ‘r’ for reading and ‘w’ for writing. The file will be created if it doesn’t exist when opened for writing; it will be truncated when opened for writing. Add a ‘b’ to the mode for binary files.
  • background: a CellVariable that specifies the desired characteristic lengths of the mesh cells
fipy.meshes.openPOSFile(name, communicator=ParallelCommWrapper(), mode='w')

Open a Gmsh POS post-processing file

class fipy.meshes.Gmsh2D(arg, coordDimensions=2, communicator=ParallelCommWrapper(), order=1, background=None)

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 :
  • arg: a string giving (i) the path to an MSH file, (ii) a path to a

    Gmsh geometry (”.geo”) file, or (iii) a Gmsh geometry script

  • coordDimensions: an integer indicating dimension of shapes

  • order: ???

  • background: a CellVariable that specifies the desired characteristic lengths of the mesh cells

class fipy.meshes.Gmsh2DIn3DSpace(arg, communicator=ParallelCommWrapper(), order=1, background=None)

Bases: fipy.meshes.gmshMesh.Gmsh2D

Create a topologically 2D Mesh in 3D coordinates using Gmsh

Parameters :
  • arg: a string giving (i) the path to an MSH file, (ii) a path to a

    Gmsh geometry (”.geo”) file, or (iii) a Gmsh geometry script

  • coordDimensions: an integer indicating dimension of shapes

  • order: ???

  • background: a CellVariable that specifies the desired characteristic lengths of the mesh cells

class fipy.meshes.Gmsh3D(arg, communicator=ParallelCommWrapper(), order=1, background=None)

Bases: fipy.meshes.mesh.Mesh

Create a 3D Mesh using Gmsh

Parameters :
  • arg: a string giving (i) the path to an MSH file, (ii) a path to a

    Gmsh geometry (”.geo”) file, or (iii) a Gmsh geometry script

  • order: ???

  • background: a CellVariable that specifies the desired characteristic lengths of the mesh cells

class fipy.meshes.GmshGrid2D(dx=1.0, dy=1.0, nx=1, ny=None, coordDimensions=2, communicator=ParallelCommWrapper(), order=1)

Bases: fipy.meshes.gmshMesh.Gmsh2D

Should serve as a drop-in replacement for Grid2D.

class fipy.meshes.GmshGrid3D(dx=1.0, dy=1.0, dz=1.0, nx=1, ny=None, nz=None, communicator=ParallelCommWrapper(), order=1)

Bases: fipy.meshes.gmshMesh.Gmsh3D

Should serve as a drop-in replacement for Grid3D.

class fipy.meshes.GmshImporter2D(arg, coordDimensions=2)

Bases: fipy.meshes.gmshMesh.Gmsh2D

class fipy.meshes.GmshImporter2DIn3DSpace(arg)

Bases: fipy.meshes.gmshMesh.Gmsh2DIn3DSpace

class fipy.meshes.GmshImporter3D(arg)

Bases: fipy.meshes.gmshMesh.Gmsh3D

abstractMesh Module

class fipy.meshes.abstractMesh.AbstractMesh(communicator, _RepresentationClass=<class 'fipy.meshes.representations.abstractRepresentation._AbstractRepresentation'>, _TopologyClass=<class 'fipy.meshes.topologies.abstractTopology._AbstractTopology'>)

Bases: object

A class encapsulating all commonalities among meshes in FiPy.

VTKCellDataSet

Returns a TVTK DataSet representing the cells of this mesh

VTKFaceDataSet

Returns a TVTK DataSet representing the face centers of this mesh

aspect2D

The physical y:x aspect ratio of a 2D mesh

cellCenters
cellDistanceVectors
cellFaceIDs

Topology properties

cellToFaceDistanceVectors
cellVolumes
exteriorFaces
faceCenters
facesBack

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
facesBottom

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
facesDown

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
facesFront

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
facesLeft

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
facesRight

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
facesTop

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
facesUp

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
getCellCenters(*args, **kwds)

Deprecated since version 3.0: use the cellCenters property instead

getCellVolumes(*args, **kwds)

Deprecated since version 3.0: use the cellVolumes property instead

getDim(*args, **kwds)

Deprecated since version 3.0: use the dim property instead

getExteriorFaces(*args, **kwds)

Deprecated since version 3.0: use the exteriorFaces property instead

Return only the faces that have one neighboring cell.

getFaceCellIDs(*args, **kwds)

Deprecated since version 3.0: use the faceCellIDs property instead

getFaceCenters(*args, **kwds)

Deprecated since version 3.0: use the faceCenters property instead

getFacesBack(*args, **kwds)

Deprecated since version 3.0: use the facesBack property instead

getFacesBottom(*args, **kwds)

Deprecated since version 3.0: use the facesBottom property instead

getFacesDown(*args, **kwds)

Deprecated since version 3.0: use the facesBottom property instead

getFacesFront(*args, **kwds)

Deprecated since version 3.0: use the facesFront property instead

getFacesLeft(*args, **kwds)

Deprecated since version 3.0: use the facesLeft property instead

getFacesRight(*args, **kwds)

Deprecated since version 3.0: use the facesRight property instead

getFacesTop(*args, **kwds)

Deprecated since version 3.0: use the facesTop property instead

getFacesUp(*args, **kwds)

Deprecated since version 3.0: use the facesTop property instead

getInteriorFaceCellIDs(*args, **kwds)

Deprecated since version 3.0: use the interiorFaceCellIDs property instead

getInteriorFaceIDs(*args, **kwds)

Deprecated since version 3.0: use the interiorFaceIDs property instead

getInteriorFaces(*args, **kwds)

Deprecated since version 3.0: use the interiorFaces property instead

Return only the faces that have two neighboring cells.

getNearestCell(point)
getNumberOfCells(*args, **kwds)

Deprecated since version 3.0: use the numberOfCells property instead

getPhysicalShape(*args, **kwds)

Deprecated since version 3.0: use the physicalShape property instead

getScale(*args, **kwds)

Deprecated since version 3.0: use the scale property instead

getShape(*args, **kwds)

Deprecated since version 3.0: use the shape property instead

getVertexCoords(*args, **kwds)

Deprecated since version 3.0: use the vertexCoords property instead

interiorFaceCellIDs
interiorFaceIDs
interiorFaces
scale
scaledCellDistances
scaledCellToCellDistances
scaledCellVolumes
scaledFaceAreas
scaledFaceToCellDistances
setScale(*args, **kwds)

Deprecated since version 3.0: use the scale property instead

x

Equivalent to using cellCenters[0].

>>> from fipy import *
>>> print Grid1D(nx=2).x
[ 0.5  1.5]
y

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.
z

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.

cylindricalGrid1D Module

cylindricalGrid2D Module

cylindricalNonUniformGrid1D Module

1D Mesh

class fipy.meshes.cylindricalNonUniformGrid1D.CylindricalNonUniformGrid1D(dx=1.0, nx=None, origin=(0, ), overlap=2, communicator=ParallelCommWrapper(), *args, **kwargs)

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

cylindricalNonUniformGrid2D Module

2D rectangular Mesh

class fipy.meshes.cylindricalNonUniformGrid2D.CylindricalNonUniformGrid2D(dx=1.0, dy=1.0, nx=None, ny=None, origin=((0.0, ), (0.0, )), overlap=2, communicator=ParallelCommWrapper(), *args, **kwargs)

Bases: fipy.meshes.nonUniformGrid2D.NonUniformGrid2D

Creates a 2D cylindrical grid mesh with horizontal faces numbered first and then vertical faces.

cellCenters
cellVolumes
faceCenters

cylindricalUniformGrid1D Module

1D Mesh

class fipy.meshes.cylindricalUniformGrid1D.CylindricalUniformGrid1D(dx=1.0, nx=1, origin=(0, ), overlap=2, communicator=ParallelCommWrapper(), *args, **kwargs)

Bases: fipy.meshes.uniformGrid1D.UniformGrid1D

Creates a 1D cylindrical grid mesh.

>>> mesh = CylindricalUniformGrid1D(nx = 3)
>>> print mesh.cellCenters
[[ 0.5  1.5  2.5]]
cellVolumes

cylindricalUniformGrid2D Module

2D cylindrical rectangular Mesh with constant spacing in x and constant spacing in y

class fipy.meshes.cylindricalUniformGrid2D.CylindricalUniformGrid2D(dx=1.0, dy=1.0, nx=1, ny=1, origin=((0, ), (0, )), overlap=2, communicator=ParallelCommWrapper(), *args, **kwargs)

Bases: fipy.meshes.uniformGrid2D.UniformGrid2D

Creates a 2D cylindrical grid in the radial and axial directions, appropriate for axial symmetry.

cellVolumes

factoryMeshes Module

fipy.meshes.factoryMeshes.Grid3D(dx=1.0, dy=1.0, dz=1.0, nx=None, ny=None, nz=None, Lx=None, Ly=None, Lz=None, overlap=2, communicator=ParallelCommWrapper())

Factory function to select between UniformGrid3D and NonUniformGrid3D. If Lx is specified the length of the domain is always Lx regardless of dx.

Parameters :
  • dx: grid spacing in the horizontal direction
  • dy: grid spacing in the vertical direction
  • dz: grid spacing in the z-direction
  • nx: number of cells in the horizontal direction
  • ny: number of cells in the vertical direction
  • nz: number of cells in the z-direction
  • Lx: the domain length in the horizontal direction
  • Ly: the domain length in the vertical direction
  • Lz: the domain length in the z-direction
  • overlap: the number of overlapping cells for parallel simulations. Generally 2 is adequate. Higher order equations or discretizations require more.
  • communicator: either fipy.tools.parallelComm or fipy.tools.serialComm. Select fipy.tools.serialComm to create a serial mesh when running in parallel. Mostly used for test purposes.
fipy.meshes.factoryMeshes.Grid2D(dx=1.0, dy=1.0, nx=None, ny=None, Lx=None, Ly=None, overlap=2, communicator=ParallelCommWrapper())

Factory function to select between UniformGrid2D and NonUniformGrid2D. If Lx is specified the length of the domain is always Lx regardless of dx.

Parameters :
  • dx: grid spacing in the horizontal direction
  • dy: grid spacing in the vertical direction
  • nx: number of cells in the horizontal direction
  • ny: number of cells in the vertical direction
  • Lx: the domain length in the horizontal direction
  • Ly: the domain length in the vertical direction
  • overlap: the number of overlapping cells for parallel simulations. Generally 2 is adequate. Higher order equations or discretizations require more.
  • communicator: either fipy.tools.parallelComm or fipy.tools.serialComm. Select fipy.tools.serialComm to create a serial mesh when running in parallel. Mostly used for test purposes.
>>> print Grid2D(Lx=3., nx=2).dx
1.5
fipy.meshes.factoryMeshes.Grid1D(dx=1.0, nx=None, Lx=None, overlap=2, communicator=ParallelCommWrapper())

Factory function to select between UniformGrid1D and NonUniformGrid1D. If Lx is specified the length of the domain is always Lx regardless of dx.

Parameters :
  • dx: grid spacing in the horizonal direction
  • nx: number of cells in the horizonal direction
  • Lx: the domain length in the horizonal direction
  • overlap: the number of overlapping cells for parallel simulations. Generally 2 is adequate. Higher order equations or discretizations require more.
  • communicator: either fipy.tools.parallelComm or fipy.tools.serialComm. Select fipy.tools.serialComm to create a serial mesh when running in parallel. Mostly used for test purposes.
fipy.meshes.factoryMeshes.CylindricalGrid2D(dr=None, dz=None, nr=None, nz=None, Lr=None, Lz=None, dx=1.0, dy=1.0, nx=None, ny=None, Lx=None, Ly=None, origin=((0, ), (0, )), overlap=2, communicator=ParallelCommWrapper())

Factory function to select between CylindricalUniformGrid2D and CylindricalNonUniformGrid2D. If Lx is specified the length of the domain is always Lx regardless of dx.

Parameters :
  • dr or dx: grid spacing in the radial direction
  • dz or dy: grid spacing in the vertical direction
  • nr or nx: number of cells in the radial direction
  • nz or ny: number of cells in the vertical direction
  • Lr or Lx: the domain length in the radial direction
  • Lz or Ly: the domain length in the vertical direction
  • origin : position of the mesh’s origin in the form ((x,),(y,))
  • overlap: the number of overlapping cells for parallel simulations. Generally 2 is adequate. Higher order equations or discretizations require more.
  • communicator: either fipy.tools.parallelComm or fipy.tools.serialComm. Select fipy.tools.serialComm to create a serial mesh when running in parallel. Mostly used for test purposes.
fipy.meshes.factoryMeshes.CylindricalGrid1D(dr=None, nr=None, Lr=None, dx=1.0, nx=None, Lx=None, origin=(0, ), overlap=2, communicator=ParallelCommWrapper())

Factory function to select between CylindricalUniformGrid1D and CylindricalNonUniformGrid1D. If Lx is specified the length of the domain is always Lx regardless of dx.

Parameters :
  • dr or dx: grid spacing in the radial direction
  • nr or nx: number of cells in the radial direction
  • Lr or Lx: the domain length in the radial direction
  • origin : position of the mesh’s origin in the form (x,)
  • overlap: the number of overlapping cells for parallel simulations. Generally 2 is adequate. Higher order equations or discretizations require more.
  • communicator: either fipy.tools.parallelComm or fipy.tools.serialComm. Select fipy.tools.serialComm to create a serial mesh when running in parallel. Mostly used for test purposes.

gmshMesh Module

fipy.meshes.gmshMesh.openMSHFile(name, dimensions=None, coordDimensions=None, communicator=ParallelCommWrapper(), order=1, mode='r', background=None)

Open a Gmsh MSH file

Parameters :
  • filename: a string indicating gmsh output file
  • dimensions: an integer indicating dimension of mesh
  • coordDimensions: an integer indicating dimension of shapes
  • order: ???
  • mode: a string beginning with ‘r’ for reading and ‘w’ for writing. The file will be created if it doesn’t exist when opened for writing; it will be truncated when opened for writing. Add a ‘b’ to the mode for binary files.
  • background: a CellVariable that specifies the desired characteristic lengths of the mesh cells
fipy.meshes.gmshMesh.openPOSFile(name, communicator=ParallelCommWrapper(), mode='w')

Open a Gmsh POS post-processing file

class fipy.meshes.gmshMesh.Gmsh2D(arg, coordDimensions=2, communicator=ParallelCommWrapper(), order=1, background=None)

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 :
  • arg: a string giving (i) the path to an MSH file, (ii) a path to a

    Gmsh geometry (”.geo”) file, or (iii) a Gmsh geometry script

  • coordDimensions: an integer indicating dimension of shapes

  • order: ???

  • background: a CellVariable that specifies the desired characteristic lengths of the mesh cells

class fipy.meshes.gmshMesh.Gmsh2DIn3DSpace(arg, communicator=ParallelCommWrapper(), order=1, background=None)

Bases: fipy.meshes.gmshMesh.Gmsh2D

Create a topologically 2D Mesh in 3D coordinates using Gmsh

Parameters :
  • arg: a string giving (i) the path to an MSH file, (ii) a path to a

    Gmsh geometry (”.geo”) file, or (iii) a Gmsh geometry script

  • coordDimensions: an integer indicating dimension of shapes

  • order: ???

  • background: a CellVariable that specifies the desired characteristic lengths of the mesh cells

class fipy.meshes.gmshMesh.Gmsh3D(arg, communicator=ParallelCommWrapper(), order=1, background=None)

Bases: fipy.meshes.mesh.Mesh

Create a 3D Mesh using Gmsh

Parameters :
  • arg: a string giving (i) the path to an MSH file, (ii) a path to a

    Gmsh geometry (”.geo”) file, or (iii) a Gmsh geometry script

  • order: ???

  • background: a CellVariable that specifies the desired characteristic lengths of the mesh cells

class fipy.meshes.gmshMesh.GmshGrid2D(dx=1.0, dy=1.0, nx=1, ny=None, coordDimensions=2, communicator=ParallelCommWrapper(), order=1)

Bases: fipy.meshes.gmshMesh.Gmsh2D

Should serve as a drop-in replacement for Grid2D.

class fipy.meshes.gmshMesh.GmshGrid3D(dx=1.0, dy=1.0, dz=1.0, nx=1, ny=None, nz=None, communicator=ParallelCommWrapper(), order=1)

Bases: fipy.meshes.gmshMesh.Gmsh3D

Should serve as a drop-in replacement for Grid3D.

class fipy.meshes.gmshMesh.GmshImporter2D(arg, coordDimensions=2)

Bases: fipy.meshes.gmshMesh.Gmsh2D

class fipy.meshes.gmshMesh.GmshImporter2DIn3DSpace(arg)

Bases: fipy.meshes.gmshMesh.Gmsh2DIn3DSpace

class fipy.meshes.gmshMesh.GmshImporter3D(arg)

Bases: fipy.meshes.gmshMesh.Gmsh3D

grid1D Module

grid2D Module

grid3D Module

mesh Module

exception fipy.meshes.mesh.MeshAdditionError

Bases: exceptions.Exception

class fipy.meshes.mesh.Mesh(vertexCoords, faceVertexIDs, cellFaceIDs, communicator=SerialCommWrapper(), _RepresentationClass=<class 'fipy.meshes.representations.meshRepresentation._MeshRepresentation'>, _TopologyClass=<class 'fipy.meshes.topologies.meshTopology._MeshTopology'>)

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.

mesh1D Module

Generic mesh class using numerix to do the calculations

Meshes contain cells, faces, and vertices.

This is built for a non-mixed element mesh.

class fipy.meshes.mesh1D.Mesh1D(vertexCoords, faceVertexIDs, cellFaceIDs, communicator=SerialCommWrapper(), _RepresentationClass=<class 'fipy.meshes.representations.meshRepresentation._MeshRepresentation'>, _TopologyClass=<class 'fipy.meshes.topologies.meshTopology._Mesh1DTopology'>)

Bases: fipy.meshes.mesh.Mesh

mesh2D Module

Generic mesh class using numerix to do the calculations

Meshes contain cells, faces, and vertices.

This is built for a non-mixed element mesh.

class fipy.meshes.mesh2D.Mesh2D(vertexCoords, faceVertexIDs, cellFaceIDs, communicator=SerialCommWrapper(), _RepresentationClass=<class 'fipy.meshes.representations.meshRepresentation._MeshRepresentation'>, _TopologyClass=<class 'fipy.meshes.topologies.meshTopology._Mesh2DTopology'>)

Bases: fipy.meshes.mesh.Mesh

extrude(extrudeFunc=<function <lambda> at 0x107c3a5f0>, layers=1)

This function returns a new 3D mesh. The 2D mesh is extruded using the extrudeFunc and the number of layers.

Parameters :
  • extrudeFunc: function that takes the vertex coordinates and returns the displaced values
  • layers: the number of layers in the extruded mesh (number of times extrudeFunc will be called)
>>> 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       ]]

nonUniformGrid1D Module

1D Mesh

class fipy.meshes.nonUniformGrid1D.NonUniformGrid1D(dx=1.0, nx=None, overlap=2, communicator=ParallelCommWrapper(), _BuilderClass=<class 'fipy.meshes.builders.grid1DBuilder._NonuniformGrid1DBuilder'>, _RepresentationClass=<class 'fipy.meshes.representations.gridRepresentation._Grid1DRepresentation'>, _TopologyClass=<class 'fipy.meshes.topologies.gridTopology._Grid1DTopology'>)

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)

nonUniformGrid2D Module

2D rectangular Mesh

class fipy.meshes.nonUniformGrid2D.NonUniformGrid2D(dx=1.0, dy=1.0, nx=None, ny=None, overlap=2, communicator=ParallelCommWrapper(), _RepresentationClass=<class 'fipy.meshes.representations.gridRepresentation._Grid2DRepresentation'>, _TopologyClass=<class 'fipy.meshes.topologies.gridTopology._Grid2DTopology'>)

Bases: fipy.meshes.mesh2D.Mesh2D

Creates a 2D grid mesh with horizontal faces numbered first and then vertical faces.

nonUniformGrid3D Module

class fipy.meshes.nonUniformGrid3D.NonUniformGrid3D(dx=1.0, dy=1.0, dz=1.0, nx=None, ny=None, nz=None, overlap=2, communicator=ParallelCommWrapper(), _RepresentationClass=<class 'fipy.meshes.representations.gridRepresentation._Grid3DRepresentation'>, _TopologyClass=<class 'fipy.meshes.topologies.gridTopology._Grid3DTopology'>)

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.

periodicGrid1D Module

Peridoic 1D Mesh

class fipy.meshes.periodicGrid1D.PeriodicGrid1D(dx=1.0, nx=None, overlap=2, *args, **kwargs)

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
cellCenters

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).

periodicGrid2D Module

2D periodic rectangular Mesh

class fipy.meshes.periodicGrid2D.PeriodicGrid2D(dx=1.0, dy=1.0, nx=None, ny=None, overlap=2, communicator=ParallelCommWrapper(), *args, **kwargs)

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
class fipy.meshes.periodicGrid2D.PeriodicGrid2DLeftRight(dx=1.0, dy=1.0, nx=None, ny=None, overlap=2, communicator=ParallelCommWrapper(), *args, **kwargs)

Bases: fipy.meshes.periodicGrid2D._BasePeriodicGrid2D

class fipy.meshes.periodicGrid2D.PeriodicGrid2DTopBottom(dx=1.0, dy=1.0, nx=None, ny=None, overlap=2, communicator=ParallelCommWrapper(), *args, **kwargs)

Bases: fipy.meshes.periodicGrid2D._BasePeriodicGrid2D

skewedGrid2D Module

class fipy.meshes.skewedGrid2D.SkewedGrid2D(dx=1.0, dy=1.0, nx=None, ny=1, rand=0, *args, **kwargs)

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.

physicalShape

Return physical dimensions of Grid2D.

shape

test Module

Test implementation of the mesh

tri2D Module

class fipy.meshes.tri2D.Tri2D(dx=1.0, dy=1.0, nx=1, ny=1, _RepresentationClass=<class 'fipy.meshes.representations.gridRepresentation._Grid2DRepresentation'>, _TopologyClass=<class 'fipy.meshes.topologies.meshTopology._Mesh2DTopology'>)

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 :
  • dx, dy: The X and Y dimensions of each ‘box’. If dx <> dy, the line segments connecting the cell centers will not be orthogonal to the faces.
  • nx, ny: The number of boxes in the X direction and the Y direction. The total number of boxes will be equal to nx * ny, and the total number of cells will be equal to 4 * nx * ny.
physicalShape

Return physical dimensions of Grid2D.

shape

uniformGrid Module

class fipy.meshes.uniformGrid.UniformGrid(communicator, _RepresentationClass=<class 'fipy.meshes.representations.abstractRepresentation._AbstractRepresentation'>, _TopologyClass=<class 'fipy.meshes.topologies.abstractTopology._AbstractTopology'>)

Bases: fipy.meshes.abstractMesh.AbstractMesh

Wrapped scaled geometry properties

uniformGrid1D Module

1D Mesh

class fipy.meshes.uniformGrid1D.UniformGrid1D(dx=1.0, nx=1, origin=(0, ), overlap=2, communicator=ParallelCommWrapper(), _RepresentationClass=<class 'fipy.meshes.representations.gridRepresentation._Grid1DRepresentation'>, _TopologyClass=<class 'fipy.meshes.topologies.gridTopology._Grid1DTopology'>)

Bases: fipy.meshes.uniformGrid.UniformGrid

Creates a 1D grid mesh.

>>> mesh = UniformGrid1D(nx = 3)
>>> print mesh.cellCenters
[[ 0.5  1.5  2.5]]
exteriorFaces

Geometry set and calc

faceCellIDs
vertexCoords

uniformGrid2D Module

2D rectangular Mesh with constant spacing in x and constant spacing in y

class fipy.meshes.uniformGrid2D.UniformGrid2D(dx=1.0, dy=1.0, nx=1, ny=1, origin=((0, ), (0, )), overlap=2, communicator=ParallelCommWrapper(), _RepresentationClass=<class 'fipy.meshes.representations.gridRepresentation._Grid2DRepresentation'>, _TopologyClass=<class 'fipy.meshes.topologies.gridTopology._Grid2DTopology'>)

Bases: fipy.meshes.uniformGrid.UniformGrid

Creates a 2D grid mesh with horizontal faces numbered first and then vertical faces.

faceCellIDs
faceVertexIDs
vertexCoords

uniformGrid3D Module

class fipy.meshes.uniformGrid3D.UniformGrid3D(dx=1.0, dy=1.0, dz=1.0, nx=1, ny=1, nz=1, origin=[[0], [0], [0]], overlap=2, communicator=ParallelCommWrapper(), _RepresentationClass=<class 'fipy.meshes.representations.gridRepresentation._Grid3DRepresentation'>, _TopologyClass=<class 'fipy.meshes.topologies.gridTopology._Grid3DTopology'>)

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.

faceCellIDs
faceVertexIDs
vertexCoords