fipy.meshes package

Subpackages

Submodules

fipy.meshes.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.

property VTKCellDataSet

Returns a TVTK DataSet representing the cells of this mesh

property VTKFaceDataSet

Returns a TVTK DataSet representing the face centers of this mesh

__add__(other)

Either translate a Mesh or concatenate two Mesh objects.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

If a vector is added to a Mesh, a translated Mesh is returned

>>> translatedMesh = baseMesh + ((5,), (10,))
>>> print(translatedMesh.cellCenters)
[[  5.5   6.5   5.5   6.5]
 [ 10.5  10.5  11.5  11.5]]

If a Mesh is added to a Mesh, a concatenation of the two Mesh objects is returned

>>> addedMesh = baseMesh + (baseMesh + ((2,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

The two Mesh objects need not be properly aligned in order to concatenate them but the resulting mesh may not have the intended connectivity

>>> addedMesh = baseMesh + (baseMesh + ((3,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  3.5  4.5  3.5  4.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]
>>> addedMesh = baseMesh + (baseMesh + ((2,), (2,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  2.5  2.5  3.5  3.5]]

No provision is made to avoid or consolidate overlapping Mesh objects

>>> addedMesh = baseMesh + (baseMesh + ((1,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  1.5  2.5  1.5  2.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

Different Mesh classes can be concatenated

>>> from fipy.meshes import Tri2D
>>> triMesh = Tri2D(dx = 1.0, dy = 1.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[0.5, 1.5, 0.5, 1.5, 2.83333333,  3.83333333,
...                 2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [0.5, 0.5, 1.5, 1.5, 0.5, 0.5, 0.83333333, 0.83333333,
...                 0.5, 0.5, 0.16666667, 0.16666667]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

again, their faces need not align, but the mesh may not have the desired connectivity

>>> triMesh = Tri2D(dx = 1.0, dy = 2.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[ 0.5, 1.5, 0.5, 1.5, 2.83333333, 3.83333333,
...                  2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [ 0.5, 0.5, 1.5, 1.5, 1., 1.,
...                  1.66666667, 1.66666667, 1., 1., 0.33333333, 0.33333333]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

Mesh concatenation is not limited to 2D meshes

>>> from fipy.meshes import Grid3D
>>> threeDBaseMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                         nx = 2, ny = 2, nz = 2)
>>> threeDSecondMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                           nx = 1, ny = 1, nz = 1)
>>> threeDAddedMesh = threeDBaseMesh + (threeDSecondMesh + ((2,), (0,), (0,)))
>>> print(threeDAddedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  0.5  1.5  0.5  1.5  2.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  0.5  1.5  1.5  1.5  1.5  0.5]]

but the different Mesh objects must, of course, have the same dimensionality.

>>> InvalidMesh = threeDBaseMesh + baseMesh 
Traceback (most recent call last):
...
MeshAdditionError: Dimensions do not match
__div__(other)

Tests. >>> from fipy import * >>> print((Grid1D(nx=1) / 2.).cellCenters) [[ 0.25]] >>> AbstractMesh(communicator=None) / 2. Traceback (most recent call last): … NotImplementedError

__getstate__()

Helper for pickle.

__mul__(other)
__radd__(other)

Either translate a Mesh or concatenate two Mesh objects.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

If a vector is added to a Mesh, a translated Mesh is returned

>>> translatedMesh = baseMesh + ((5,), (10,))
>>> print(translatedMesh.cellCenters)
[[  5.5   6.5   5.5   6.5]
 [ 10.5  10.5  11.5  11.5]]

If a Mesh is added to a Mesh, a concatenation of the two Mesh objects is returned

>>> addedMesh = baseMesh + (baseMesh + ((2,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

The two Mesh objects need not be properly aligned in order to concatenate them but the resulting mesh may not have the intended connectivity

>>> addedMesh = baseMesh + (baseMesh + ((3,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  3.5  4.5  3.5  4.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]
>>> addedMesh = baseMesh + (baseMesh + ((2,), (2,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  2.5  2.5  3.5  3.5]]

No provision is made to avoid or consolidate overlapping Mesh objects

>>> addedMesh = baseMesh + (baseMesh + ((1,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  1.5  2.5  1.5  2.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

Different Mesh classes can be concatenated

>>> from fipy.meshes import Tri2D
>>> triMesh = Tri2D(dx = 1.0, dy = 1.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[0.5, 1.5, 0.5, 1.5, 2.83333333,  3.83333333,
...                 2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [0.5, 0.5, 1.5, 1.5, 0.5, 0.5, 0.83333333, 0.83333333,
...                 0.5, 0.5, 0.16666667, 0.16666667]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

again, their faces need not align, but the mesh may not have the desired connectivity

>>> triMesh = Tri2D(dx = 1.0, dy = 2.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[ 0.5, 1.5, 0.5, 1.5, 2.83333333, 3.83333333,
...                  2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [ 0.5, 0.5, 1.5, 1.5, 1., 1.,
...                  1.66666667, 1.66666667, 1., 1., 0.33333333, 0.33333333]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

Mesh concatenation is not limited to 2D meshes

>>> from fipy.meshes import Grid3D
>>> threeDBaseMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                         nx = 2, ny = 2, nz = 2)
>>> threeDSecondMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                           nx = 1, ny = 1, nz = 1)
>>> threeDAddedMesh = threeDBaseMesh + (threeDSecondMesh + ((2,), (0,), (0,)))
>>> print(threeDAddedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  0.5  1.5  0.5  1.5  2.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  0.5  1.5  1.5  1.5  1.5  0.5]]

but the different Mesh objects must, of course, have the same dimensionality.

>>> InvalidMesh = threeDBaseMesh + baseMesh 
Traceback (most recent call last):
...
MeshAdditionError: Dimensions do not match
__repr__()

Return repr(self).

__rmul__(other)
__setstate__(state)
__sub__(other)

Tests. >>> from fipy import * >>> m = Grid1D() >>> print((m - ((1,))).cellCenters) [[-0.5]] >>> ((1,)) - m Traceback (most recent call last): … TypeError: unsupported operand type(s) for -: ‘tuple’ and ‘UniformGrid1D’

__truediv__(other)

Tests. >>> from fipy import * >>> print((Grid1D(nx=1) / 2.).cellCenters) [[ 0.25]] >>> AbstractMesh(communicator=None) / 2. Traceback (most recent call last): … NotImplementedError

property aspect2D

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

property cellCenters
property cellDistanceVectors
property cellFaceIDs

Topology properties

property cellToFaceDistanceVectors
property cellVolumes
property extents
property exteriorFaces
property faceCenters
property facesBack

Return list of faces on back boundary of 3D Mesh 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
>>> ignore = mesh.facesBack.value 
property facesBottom

Return list of faces on bottom boundary of 2D or 3D Mesh 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])) 
True
>>> ignore = mesh.facesBottom.value 
>>> x, y, z = mesh.faceCenters
>>> print(numerix.allequal((12, 13),
...                        numerix.nonzero(mesh.facesBottom & (x < 1))[0])) 
True
>>> ignore = mesh.facesBottom.value 
property facesDown

Return list of faces on bottom boundary of 2D or 3D Mesh 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])) 
True
>>> ignore = mesh.facesBottom.value 
>>> x, y, z = mesh.faceCenters
>>> print(numerix.allequal((12, 13),
...                        numerix.nonzero(mesh.facesBottom & (x < 1))[0])) 
True
>>> ignore = mesh.facesBottom.value 
property facesFront

Return list of faces on front boundary of 3D Mesh 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
>>> ignore = mesh.facesFront.value 
property facesLeft

Return face on left boundary of Mesh 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
>>> ignore = mesh.facesLeft.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((9, 13),
...                        numerix.nonzero(mesh.facesLeft)[0])) 
True
>>> ignore = mesh.facesLeft.value 
property facesRight

Return list of faces on right boundary of Mesh 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
>>> ignore = mesh.facesRight.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((12, 16),
...                        numerix.nonzero(mesh.facesRight)[0])) 
True
>>> ignore = mesh.facesRight.value 
property facesTop

Return list of faces on top boundary of 2D or 3D Mesh 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
>>> ignore = mesh.facesTop.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((6, 7, 8),
...                        numerix.nonzero(mesh.facesTop)[0])) 
True
>>> ignore = mesh.facesTop.value 
property facesUp

Return list of faces on top boundary of 2D or 3D Mesh 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
>>> ignore = mesh.facesTop.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((6, 7, 8),
...                        numerix.nonzero(mesh.facesTop)[0])) 
True
>>> ignore = mesh.facesTop.value 
getNearestCell(point)
property interiorFaceCellIDs
property interiorFaceIDs
property interiorFaces
property scale
property scaledCellDistances
property scaledCellToCellDistances
property scaledCellVolumes
property scaledFaceAreas
property scaledFaceToCellDistances
property x

Equivalent to using cellCenters[0].

>>> from fipy import *
>>> print(Grid1D(nx=2).x)
[ 0.5  1.5]
property 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.
property 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.

fipy.meshes.cylindricalGrid1D module

fipy.meshes.cylindricalGrid2D module

fipy.meshes.cylindricalNonUniformGrid1D module

1D Mesh

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

Bases: 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
property VTKCellDataSet

Returns a TVTK DataSet representing the cells of this mesh

property VTKFaceDataSet

Returns a TVTK DataSet representing the face centers of this mesh

__add__(other)

Either translate a Mesh or concatenate two Mesh objects.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

If a vector is added to a Mesh, a translated Mesh is returned

>>> translatedMesh = baseMesh + ((5,), (10,))
>>> print(translatedMesh.cellCenters)
[[  5.5   6.5   5.5   6.5]
 [ 10.5  10.5  11.5  11.5]]

If a Mesh is added to a Mesh, a concatenation of the two Mesh objects is returned

>>> addedMesh = baseMesh + (baseMesh + ((2,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

The two Mesh objects need not be properly aligned in order to concatenate them but the resulting mesh may not have the intended connectivity

>>> addedMesh = baseMesh + (baseMesh + ((3,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  3.5  4.5  3.5  4.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]
>>> addedMesh = baseMesh + (baseMesh + ((2,), (2,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  2.5  2.5  3.5  3.5]]

No provision is made to avoid or consolidate overlapping Mesh objects

>>> addedMesh = baseMesh + (baseMesh + ((1,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  1.5  2.5  1.5  2.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

Different Mesh classes can be concatenated

>>> from fipy.meshes import Tri2D
>>> triMesh = Tri2D(dx = 1.0, dy = 1.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[0.5, 1.5, 0.5, 1.5, 2.83333333,  3.83333333,
...                 2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [0.5, 0.5, 1.5, 1.5, 0.5, 0.5, 0.83333333, 0.83333333,
...                 0.5, 0.5, 0.16666667, 0.16666667]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

again, their faces need not align, but the mesh may not have the desired connectivity

>>> triMesh = Tri2D(dx = 1.0, dy = 2.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[ 0.5, 1.5, 0.5, 1.5, 2.83333333, 3.83333333,
...                  2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [ 0.5, 0.5, 1.5, 1.5, 1., 1.,
...                  1.66666667, 1.66666667, 1., 1., 0.33333333, 0.33333333]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

Mesh concatenation is not limited to 2D meshes

>>> from fipy.meshes import Grid3D
>>> threeDBaseMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                         nx = 2, ny = 2, nz = 2)
>>> threeDSecondMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                           nx = 1, ny = 1, nz = 1)
>>> threeDAddedMesh = threeDBaseMesh + (threeDSecondMesh + ((2,), (0,), (0,)))
>>> print(threeDAddedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  0.5  1.5  0.5  1.5  2.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  0.5  1.5  1.5  1.5  1.5  0.5]]

but the different Mesh objects must, of course, have the same dimensionality.

>>> InvalidMesh = threeDBaseMesh + baseMesh 
Traceback (most recent call last):
...
MeshAdditionError: Dimensions do not match
__div__(other)

Tests. >>> from fipy import * >>> print((Grid1D(nx=1) / 2.).cellCenters) [[ 0.25]] >>> AbstractMesh(communicator=None) / 2. Traceback (most recent call last): … NotImplementedError

__getstate__()

Helper for pickle.

__mul__(factor)

Dilate a Mesh by factor.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

The factor can be a scalar

>>> dilatedMesh = baseMesh * 3
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.5  1.5  4.5  4.5]]

or a vector

>>> dilatedMesh = baseMesh * ((3,), (2,))
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.   1.   3.   3. ]]

but the vector must have the same dimensionality as the Mesh

>>> dilatedMesh = baseMesh * ((3,), (2,), (1,)) 
Traceback (most recent call last):
...
ValueError: shape mismatch: objects cannot be broadcast to a single shape
__radd__(other)

Either translate a Mesh or concatenate two Mesh objects.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

If a vector is added to a Mesh, a translated Mesh is returned

>>> translatedMesh = baseMesh + ((5,), (10,))
>>> print(translatedMesh.cellCenters)
[[  5.5   6.5   5.5   6.5]
 [ 10.5  10.5  11.5  11.5]]

If a Mesh is added to a Mesh, a concatenation of the two Mesh objects is returned

>>> addedMesh = baseMesh + (baseMesh + ((2,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

The two Mesh objects need not be properly aligned in order to concatenate them but the resulting mesh may not have the intended connectivity

>>> addedMesh = baseMesh + (baseMesh + ((3,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  3.5  4.5  3.5  4.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]
>>> addedMesh = baseMesh + (baseMesh + ((2,), (2,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  2.5  2.5  3.5  3.5]]

No provision is made to avoid or consolidate overlapping Mesh objects

>>> addedMesh = baseMesh + (baseMesh + ((1,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  1.5  2.5  1.5  2.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

Different Mesh classes can be concatenated

>>> from fipy.meshes import Tri2D
>>> triMesh = Tri2D(dx = 1.0, dy = 1.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[0.5, 1.5, 0.5, 1.5, 2.83333333,  3.83333333,
...                 2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [0.5, 0.5, 1.5, 1.5, 0.5, 0.5, 0.83333333, 0.83333333,
...                 0.5, 0.5, 0.16666667, 0.16666667]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

again, their faces need not align, but the mesh may not have the desired connectivity

>>> triMesh = Tri2D(dx = 1.0, dy = 2.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[ 0.5, 1.5, 0.5, 1.5, 2.83333333, 3.83333333,
...                  2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [ 0.5, 0.5, 1.5, 1.5, 1., 1.,
...                  1.66666667, 1.66666667, 1., 1., 0.33333333, 0.33333333]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

Mesh concatenation is not limited to 2D meshes

>>> from fipy.meshes import Grid3D
>>> threeDBaseMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                         nx = 2, ny = 2, nz = 2)
>>> threeDSecondMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                           nx = 1, ny = 1, nz = 1)
>>> threeDAddedMesh = threeDBaseMesh + (threeDSecondMesh + ((2,), (0,), (0,)))
>>> print(threeDAddedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  0.5  1.5  0.5  1.5  2.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  0.5  1.5  1.5  1.5  1.5  0.5]]

but the different Mesh objects must, of course, have the same dimensionality.

>>> InvalidMesh = threeDBaseMesh + baseMesh 
Traceback (most recent call last):
...
MeshAdditionError: Dimensions do not match
__repr__()

Return repr(self).

__rmul__(factor)

Dilate a Mesh by factor.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

The factor can be a scalar

>>> dilatedMesh = baseMesh * 3
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.5  1.5  4.5  4.5]]

or a vector

>>> dilatedMesh = baseMesh * ((3,), (2,))
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.   1.   3.   3. ]]

but the vector must have the same dimensionality as the Mesh

>>> dilatedMesh = baseMesh * ((3,), (2,), (1,)) 
Traceback (most recent call last):
...
ValueError: shape mismatch: objects cannot be broadcast to a single shape
__setstate__(state)
__sub__(other)

Tests. >>> from fipy import * >>> m = Grid1D() >>> print((m - ((1,))).cellCenters) [[-0.5]] >>> ((1,)) - m Traceback (most recent call last): … TypeError: unsupported operand type(s) for -: ‘tuple’ and ‘UniformGrid1D’

__truediv__(other)

Tests. >>> from fipy import * >>> print((Grid1D(nx=1) / 2.).cellCenters) [[ 0.25]] >>> AbstractMesh(communicator=None) / 2. Traceback (most recent call last): … NotImplementedError

property aspect2D

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

property cellCenters
property cellDistanceVectors
property cellFaceIDs
property cellToFaceDistanceVectors
property cellVolumes
property extents
property exteriorFaces
property faceCenters
property facesBack

Return list of faces on back boundary of 3D Mesh 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
>>> ignore = mesh.facesBack.value 
property facesBottom

Return list of faces on bottom boundary of 2D or 3D Mesh 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])) 
True
>>> ignore = mesh.facesBottom.value 
>>> x, y, z = mesh.faceCenters
>>> print(numerix.allequal((12, 13),
...                        numerix.nonzero(mesh.facesBottom & (x < 1))[0])) 
True
>>> ignore = mesh.facesBottom.value 
property facesDown

Return list of faces on bottom boundary of 2D or 3D Mesh 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])) 
True
>>> ignore = mesh.facesBottom.value 
>>> x, y, z = mesh.faceCenters
>>> print(numerix.allequal((12, 13),
...                        numerix.nonzero(mesh.facesBottom & (x < 1))[0])) 
True
>>> ignore = mesh.facesBottom.value 
property facesFront

Return list of faces on front boundary of 3D Mesh 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
>>> ignore = mesh.facesFront.value 
property facesLeft

Return face on left boundary of Mesh 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
>>> ignore = mesh.facesLeft.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((9, 13),
...                        numerix.nonzero(mesh.facesLeft)[0])) 
True
>>> ignore = mesh.facesLeft.value 
property facesRight

Return list of faces on right boundary of Mesh 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
>>> ignore = mesh.facesRight.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((12, 16),
...                        numerix.nonzero(mesh.facesRight)[0])) 
True
>>> ignore = mesh.facesRight.value 
property facesTop

Return list of faces on top boundary of 2D or 3D Mesh 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
>>> ignore = mesh.facesTop.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((6, 7, 8),
...                        numerix.nonzero(mesh.facesTop)[0])) 
True
>>> ignore = mesh.facesTop.value 
property facesUp

Return list of faces on top boundary of 2D or 3D Mesh 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
>>> ignore = mesh.facesTop.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((6, 7, 8),
...                        numerix.nonzero(mesh.facesTop)[0])) 
True
>>> ignore = mesh.facesTop.value 
getNearestCell(point)
property interiorFaceCellIDs
property interiorFaceIDs
property interiorFaces
property scale
property scaledCellDistances
property scaledCellToCellDistances
property scaledCellVolumes
property scaledFaceAreas
property scaledFaceToCellDistances
property x

Equivalent to using cellCenters[0].

>>> from fipy import *
>>> print(Grid1D(nx=2).x)
[ 0.5  1.5]
property 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.
property 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.

fipy.meshes.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=SerialPETScCommWrapper(), *args, **kwargs)

Bases: NonUniformGrid2D

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

property VTKCellDataSet

Returns a TVTK DataSet representing the cells of this mesh

property VTKFaceDataSet

Returns a TVTK DataSet representing the face centers of this mesh

__add__(other)

Either translate a Mesh or concatenate two Mesh objects.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

If a vector is added to a Mesh, a translated Mesh is returned

>>> translatedMesh = baseMesh + ((5,), (10,))
>>> print(translatedMesh.cellCenters)
[[  5.5   6.5   5.5   6.5]
 [ 10.5  10.5  11.5  11.5]]

If a Mesh is added to a Mesh, a concatenation of the two Mesh objects is returned

>>> addedMesh = baseMesh + (baseMesh + ((2,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

The two Mesh objects need not be properly aligned in order to concatenate them but the resulting mesh may not have the intended connectivity

>>> addedMesh = baseMesh + (baseMesh + ((3,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  3.5  4.5  3.5  4.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]
>>> addedMesh = baseMesh + (baseMesh + ((2,), (2,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  2.5  2.5  3.5  3.5]]

No provision is made to avoid or consolidate overlapping Mesh objects

>>> addedMesh = baseMesh + (baseMesh + ((1,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  1.5  2.5  1.5  2.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

Different Mesh classes can be concatenated

>>> from fipy.meshes import Tri2D
>>> triMesh = Tri2D(dx = 1.0, dy = 1.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[0.5, 1.5, 0.5, 1.5, 2.83333333,  3.83333333,
...                 2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [0.5, 0.5, 1.5, 1.5, 0.5, 0.5, 0.83333333, 0.83333333,
...                 0.5, 0.5, 0.16666667, 0.16666667]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

again, their faces need not align, but the mesh may not have the desired connectivity

>>> triMesh = Tri2D(dx = 1.0, dy = 2.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[ 0.5, 1.5, 0.5, 1.5, 2.83333333, 3.83333333,
...                  2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [ 0.5, 0.5, 1.5, 1.5, 1., 1.,
...                  1.66666667, 1.66666667, 1., 1., 0.33333333, 0.33333333]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

Mesh concatenation is not limited to 2D meshes

>>> from fipy.meshes import Grid3D
>>> threeDBaseMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                         nx = 2, ny = 2, nz = 2)
>>> threeDSecondMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                           nx = 1, ny = 1, nz = 1)
>>> threeDAddedMesh = threeDBaseMesh + (threeDSecondMesh + ((2,), (0,), (0,)))
>>> print(threeDAddedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  0.5  1.5  0.5  1.5  2.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  0.5  1.5  1.5  1.5  1.5  0.5]]

but the different Mesh objects must, of course, have the same dimensionality.

>>> InvalidMesh = threeDBaseMesh + baseMesh 
Traceback (most recent call last):
...
MeshAdditionError: Dimensions do not match
__div__(other)

Tests. >>> from fipy import * >>> print((Grid1D(nx=1) / 2.).cellCenters) [[ 0.25]] >>> AbstractMesh(communicator=None) / 2. Traceback (most recent call last): … NotImplementedError

__getstate__()

Helper for pickle.

__mul__(factor)

Dilate a Mesh by factor.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

The factor can be a scalar

>>> dilatedMesh = baseMesh * 3
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.5  1.5  4.5  4.5]]

or a vector

>>> dilatedMesh = baseMesh * ((3,), (2,))
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.   1.   3.   3. ]]

but the vector must have the same dimensionality as the Mesh

>>> dilatedMesh = baseMesh * ((3,), (2,), (1,)) 
Traceback (most recent call last):
...
ValueError: shape mismatch: objects cannot be broadcast to a single shape
__radd__(other)

Either translate a Mesh or concatenate two Mesh objects.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

If a vector is added to a Mesh, a translated Mesh is returned

>>> translatedMesh = baseMesh + ((5,), (10,))
>>> print(translatedMesh.cellCenters)
[[  5.5   6.5   5.5   6.5]
 [ 10.5  10.5  11.5  11.5]]

If a Mesh is added to a Mesh, a concatenation of the two Mesh objects is returned

>>> addedMesh = baseMesh + (baseMesh + ((2,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

The two Mesh objects need not be properly aligned in order to concatenate them but the resulting mesh may not have the intended connectivity

>>> addedMesh = baseMesh + (baseMesh + ((3,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  3.5  4.5  3.5  4.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]
>>> addedMesh = baseMesh + (baseMesh + ((2,), (2,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  2.5  2.5  3.5  3.5]]

No provision is made to avoid or consolidate overlapping Mesh objects

>>> addedMesh = baseMesh + (baseMesh + ((1,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  1.5  2.5  1.5  2.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

Different Mesh classes can be concatenated

>>> from fipy.meshes import Tri2D
>>> triMesh = Tri2D(dx = 1.0, dy = 1.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[0.5, 1.5, 0.5, 1.5, 2.83333333,  3.83333333,
...                 2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [0.5, 0.5, 1.5, 1.5, 0.5, 0.5, 0.83333333, 0.83333333,
...                 0.5, 0.5, 0.16666667, 0.16666667]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

again, their faces need not align, but the mesh may not have the desired connectivity

>>> triMesh = Tri2D(dx = 1.0, dy = 2.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[ 0.5, 1.5, 0.5, 1.5, 2.83333333, 3.83333333,
...                  2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [ 0.5, 0.5, 1.5, 1.5, 1., 1.,
...                  1.66666667, 1.66666667, 1., 1., 0.33333333, 0.33333333]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

Mesh concatenation is not limited to 2D meshes

>>> from fipy.meshes import Grid3D
>>> threeDBaseMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                         nx = 2, ny = 2, nz = 2)
>>> threeDSecondMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                           nx = 1, ny = 1, nz = 1)
>>> threeDAddedMesh = threeDBaseMesh + (threeDSecondMesh + ((2,), (0,), (0,)))
>>> print(threeDAddedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  0.5  1.5  0.5  1.5  2.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  0.5  1.5  1.5  1.5  1.5  0.5]]

but the different Mesh objects must, of course, have the same dimensionality.

>>> InvalidMesh = threeDBaseMesh + baseMesh 
Traceback (most recent call last):
...
MeshAdditionError: Dimensions do not match
__repr__()

Return repr(self).

__rmul__(factor)

Dilate a Mesh by factor.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

The factor can be a scalar

>>> dilatedMesh = baseMesh * 3
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.5  1.5  4.5  4.5]]

or a vector

>>> dilatedMesh = baseMesh * ((3,), (2,))
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.   1.   3.   3. ]]

but the vector must have the same dimensionality as the Mesh

>>> dilatedMesh = baseMesh * ((3,), (2,), (1,)) 
Traceback (most recent call last):
...
ValueError: shape mismatch: objects cannot be broadcast to a single shape
__setstate__(state)
__sub__(other)

Tests. >>> from fipy import * >>> m = Grid1D() >>> print((m - ((1,))).cellCenters) [[-0.5]] >>> ((1,)) - m Traceback (most recent call last): … TypeError: unsupported operand type(s) for -: ‘tuple’ and ‘UniformGrid1D’

__truediv__(other)

Tests. >>> from fipy import * >>> print((Grid1D(nx=1) / 2.).cellCenters) [[ 0.25]] >>> AbstractMesh(communicator=None) / 2. Traceback (most recent call last): … NotImplementedError

property aspect2D

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

property cellCenters
property cellDistanceVectors
property cellFaceIDs
property cellToFaceDistanceVectors
property cellVolumes
property extents
property exteriorFaces
extrude(extrudeFunc=<function Mesh2D.<lambda>>, layers=1)

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

>>> 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.allclose([[ 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       ]]))
True
Parameters:
  • extrudeFunc (function) – Takes the vertex coordinates and returns the displaced values

  • layers (int) – Number of layers in the extruded mesh (number of times extrudeFunc will be called)

property faceCenters
property facesBack

Return list of faces on back boundary of 3D Mesh 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
>>> ignore = mesh.facesBack.value 
property facesBottom

Return list of faces on bottom boundary of 2D or 3D Mesh 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])) 
True
>>> ignore = mesh.facesBottom.value 
>>> x, y, z = mesh.faceCenters
>>> print(numerix.allequal((12, 13),
...                        numerix.nonzero(mesh.facesBottom & (x < 1))[0])) 
True
>>> ignore = mesh.facesBottom.value 
property facesDown

Return list of faces on bottom boundary of 2D or 3D Mesh 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])) 
True
>>> ignore = mesh.facesBottom.value 
>>> x, y, z = mesh.faceCenters
>>> print(numerix.allequal((12, 13),
...                        numerix.nonzero(mesh.facesBottom & (x < 1))[0])) 
True
>>> ignore = mesh.facesBottom.value 
property facesFront

Return list of faces on front boundary of 3D Mesh 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
>>> ignore = mesh.facesFront.value 
property facesLeft

Return face on left boundary of Mesh 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
>>> ignore = mesh.facesLeft.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((9, 13),
...                        numerix.nonzero(mesh.facesLeft)[0])) 
True
>>> ignore = mesh.facesLeft.value 
property facesRight

Return list of faces on right boundary of Mesh 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
>>> ignore = mesh.facesRight.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((12, 16),
...                        numerix.nonzero(mesh.facesRight)[0])) 
True
>>> ignore = mesh.facesRight.value 
property facesTop

Return list of faces on top boundary of 2D or 3D Mesh 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
>>> ignore = mesh.facesTop.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((6, 7, 8),
...                        numerix.nonzero(mesh.facesTop)[0])) 
True
>>> ignore = mesh.facesTop.value 
property facesUp

Return list of faces on top boundary of 2D or 3D Mesh 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
>>> ignore = mesh.facesTop.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((6, 7, 8),
...                        numerix.nonzero(mesh.facesTop)[0])) 
True
>>> ignore = mesh.facesTop.value 
getNearestCell(point)
property interiorFaceCellIDs
property interiorFaceIDs
property interiorFaces
property scale
property scaledCellDistances
property scaledCellToCellDistances
property scaledCellVolumes
property scaledFaceAreas
property scaledFaceToCellDistances
property x

Equivalent to using cellCenters[0].

>>> from fipy import *
>>> print(Grid1D(nx=2).x)
[ 0.5  1.5]
property 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.
property 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.

fipy.meshes.cylindricalUniformGrid1D module

1D Mesh

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

Bases: UniformGrid1D

Creates a 1D cylindrical grid mesh.

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

Returns a TVTK DataSet representing the cells of this mesh

property VTKFaceDataSet

Returns a TVTK DataSet representing the face centers of this mesh

__add__(other)

Either translate a Mesh or concatenate two Mesh objects.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

If a vector is added to a Mesh, a translated Mesh is returned

>>> translatedMesh = baseMesh + ((5,), (10,))
>>> print(translatedMesh.cellCenters)
[[  5.5   6.5   5.5   6.5]
 [ 10.5  10.5  11.5  11.5]]

If a Mesh is added to a Mesh, a concatenation of the two Mesh objects is returned

>>> addedMesh = baseMesh + (baseMesh + ((2,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

The two Mesh objects need not be properly aligned in order to concatenate them but the resulting mesh may not have the intended connectivity

>>> addedMesh = baseMesh + (baseMesh + ((3,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  3.5  4.5  3.5  4.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]
>>> addedMesh = baseMesh + (baseMesh + ((2,), (2,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  2.5  2.5  3.5  3.5]]

No provision is made to avoid or consolidate overlapping Mesh objects

>>> addedMesh = baseMesh + (baseMesh + ((1,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  1.5  2.5  1.5  2.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

Different Mesh classes can be concatenated

>>> from fipy.meshes import Tri2D
>>> triMesh = Tri2D(dx = 1.0, dy = 1.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[0.5, 1.5, 0.5, 1.5, 2.83333333,  3.83333333,
...                 2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [0.5, 0.5, 1.5, 1.5, 0.5, 0.5, 0.83333333, 0.83333333,
...                 0.5, 0.5, 0.16666667, 0.16666667]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

again, their faces need not align, but the mesh may not have the desired connectivity

>>> triMesh = Tri2D(dx = 1.0, dy = 2.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[ 0.5, 1.5, 0.5, 1.5, 2.83333333, 3.83333333,
...                  2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [ 0.5, 0.5, 1.5, 1.5, 1., 1.,
...                  1.66666667, 1.66666667, 1., 1., 0.33333333, 0.33333333]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

Mesh concatenation is not limited to 2D meshes

>>> from fipy.meshes import Grid3D
>>> threeDBaseMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                         nx = 2, ny = 2, nz = 2)
>>> threeDSecondMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                           nx = 1, ny = 1, nz = 1)
>>> threeDAddedMesh = threeDBaseMesh + (threeDSecondMesh + ((2,), (0,), (0,)))
>>> print(threeDAddedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  0.5  1.5  0.5  1.5  2.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  0.5  1.5  1.5  1.5  1.5  0.5]]

but the different Mesh objects must, of course, have the same dimensionality.

>>> InvalidMesh = threeDBaseMesh + baseMesh 
Traceback (most recent call last):
...
MeshAdditionError: Dimensions do not match
__div__(other)

Tests. >>> from fipy import * >>> print((Grid1D(nx=1) / 2.).cellCenters) [[ 0.25]] >>> AbstractMesh(communicator=None) / 2. Traceback (most recent call last): … NotImplementedError

__getstate__()

Helper for pickle.

__mul__(factor)
__radd__(other)

Either translate a Mesh or concatenate two Mesh objects.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

If a vector is added to a Mesh, a translated Mesh is returned

>>> translatedMesh = baseMesh + ((5,), (10,))
>>> print(translatedMesh.cellCenters)
[[  5.5   6.5   5.5   6.5]
 [ 10.5  10.5  11.5  11.5]]

If a Mesh is added to a Mesh, a concatenation of the two Mesh objects is returned

>>> addedMesh = baseMesh + (baseMesh + ((2,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

The two Mesh objects need not be properly aligned in order to concatenate them but the resulting mesh may not have the intended connectivity

>>> addedMesh = baseMesh + (baseMesh + ((3,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  3.5  4.5  3.5  4.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]
>>> addedMesh = baseMesh + (baseMesh + ((2,), (2,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  2.5  2.5  3.5  3.5]]

No provision is made to avoid or consolidate overlapping Mesh objects

>>> addedMesh = baseMesh + (baseMesh + ((1,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  1.5  2.5  1.5  2.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

Different Mesh classes can be concatenated

>>> from fipy.meshes import Tri2D
>>> triMesh = Tri2D(dx = 1.0, dy = 1.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[0.5, 1.5, 0.5, 1.5, 2.83333333,  3.83333333,
...                 2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [0.5, 0.5, 1.5, 1.5, 0.5, 0.5, 0.83333333, 0.83333333,
...                 0.5, 0.5, 0.16666667, 0.16666667]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

again, their faces need not align, but the mesh may not have the desired connectivity

>>> triMesh = Tri2D(dx = 1.0, dy = 2.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[ 0.5, 1.5, 0.5, 1.5, 2.83333333, 3.83333333,
...                  2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [ 0.5, 0.5, 1.5, 1.5, 1., 1.,
...                  1.66666667, 1.66666667, 1., 1., 0.33333333, 0.33333333]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

Mesh concatenation is not limited to 2D meshes

>>> from fipy.meshes import Grid3D
>>> threeDBaseMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                         nx = 2, ny = 2, nz = 2)
>>> threeDSecondMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                           nx = 1, ny = 1, nz = 1)
>>> threeDAddedMesh = threeDBaseMesh + (threeDSecondMesh + ((2,), (0,), (0,)))
>>> print(threeDAddedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  0.5  1.5  0.5  1.5  2.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  0.5  1.5  1.5  1.5  1.5  0.5]]

but the different Mesh objects must, of course, have the same dimensionality.

>>> InvalidMesh = threeDBaseMesh + baseMesh 
Traceback (most recent call last):
...
MeshAdditionError: Dimensions do not match
__repr__()

Return repr(self).

__rmul__(other)
__setstate__(state)
__sub__(other)

Tests. >>> from fipy import * >>> m = Grid1D() >>> print((m - ((1,))).cellCenters) [[-0.5]] >>> ((1,)) - m Traceback (most recent call last): … TypeError: unsupported operand type(s) for -: ‘tuple’ and ‘UniformGrid1D’

__truediv__(other)

Tests. >>> from fipy import * >>> print((Grid1D(nx=1) / 2.).cellCenters) [[ 0.25]] >>> AbstractMesh(communicator=None) / 2. Traceback (most recent call last): … NotImplementedError

property aspect2D

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

property cellCenters
property cellDistanceVectors
property cellFaceIDs
property cellToFaceDistanceVectors
property cellVolumes
property extents
property exteriorFaces
property faceCellIDs
property faceCenters
property faceNormals
property facesBack

Return list of faces on back boundary of 3D Mesh 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
>>> ignore = mesh.facesBack.value 
property facesBottom

Return list of faces on bottom boundary of 2D or 3D Mesh 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])) 
True
>>> ignore = mesh.facesBottom.value 
>>> x, y, z = mesh.faceCenters
>>> print(numerix.allequal((12, 13),
...                        numerix.nonzero(mesh.facesBottom & (x < 1))[0])) 
True
>>> ignore = mesh.facesBottom.value 
property facesDown

Return list of faces on bottom boundary of 2D or 3D Mesh 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])) 
True
>>> ignore = mesh.facesBottom.value 
>>> x, y, z = mesh.faceCenters
>>> print(numerix.allequal((12, 13),
...                        numerix.nonzero(mesh.facesBottom & (x < 1))[0])) 
True
>>> ignore = mesh.facesBottom.value 
property facesFront

Return list of faces on front boundary of 3D Mesh 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
>>> ignore = mesh.facesFront.value 
property facesLeft

Return face on left boundary of Mesh 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
>>> ignore = mesh.facesLeft.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((9, 13),
...                        numerix.nonzero(mesh.facesLeft)[0])) 
True
>>> ignore = mesh.facesLeft.value 
property facesRight

Return list of faces on right boundary of Mesh 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
>>> ignore = mesh.facesRight.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((12, 16),
...                        numerix.nonzero(mesh.facesRight)[0])) 
True
>>> ignore = mesh.facesRight.value 
property facesTop

Return list of faces on top boundary of 2D or 3D Mesh 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
>>> ignore = mesh.facesTop.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((6, 7, 8),
...                        numerix.nonzero(mesh.facesTop)[0])) 
True
>>> ignore = mesh.facesTop.value 
property facesUp

Return list of faces on top boundary of 2D or 3D Mesh 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
>>> ignore = mesh.facesTop.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((6, 7, 8),
...                        numerix.nonzero(mesh.facesTop)[0])) 
True
>>> ignore = mesh.facesTop.value 
getNearestCell(point)
property interiorFaceCellIDs
property interiorFaceIDs
property interiorFaces
property scale
property scaledCellDistances
property scaledCellToCellDistances
property scaledCellVolumes
property scaledFaceAreas
property scaledFaceToCellDistances
property vertexCoords
property x

Equivalent to using cellCenters[0].

>>> from fipy import *
>>> print(Grid1D(nx=2).x)
[ 0.5  1.5]
property 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.
property 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.

fipy.meshes.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=SerialPETScCommWrapper(), *args, **kwargs)

Bases: UniformGrid2D

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

property VTKCellDataSet

Returns a TVTK DataSet representing the cells of this mesh

property VTKFaceDataSet

Returns a TVTK DataSet representing the face centers of this mesh

__add__(other)

Either translate a Mesh or concatenate two Mesh objects.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

If a vector is added to a Mesh, a translated Mesh is returned

>>> translatedMesh = baseMesh + ((5,), (10,))
>>> print(translatedMesh.cellCenters)
[[  5.5   6.5   5.5   6.5]
 [ 10.5  10.5  11.5  11.5]]

If a Mesh is added to a Mesh, a concatenation of the two Mesh objects is returned

>>> addedMesh = baseMesh + (baseMesh + ((2,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

The two Mesh objects need not be properly aligned in order to concatenate them but the resulting mesh may not have the intended connectivity

>>> addedMesh = baseMesh + (baseMesh + ((3,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  3.5  4.5  3.5  4.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]
>>> addedMesh = baseMesh + (baseMesh + ((2,), (2,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  2.5  2.5  3.5  3.5]]

No provision is made to avoid or consolidate overlapping Mesh objects

>>> addedMesh = baseMesh + (baseMesh + ((1,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  1.5  2.5  1.5  2.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

Different Mesh classes can be concatenated

>>> from fipy.meshes import Tri2D
>>> triMesh = Tri2D(dx = 1.0, dy = 1.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[0.5, 1.5, 0.5, 1.5, 2.83333333,  3.83333333,
...                 2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [0.5, 0.5, 1.5, 1.5, 0.5, 0.5, 0.83333333, 0.83333333,
...                 0.5, 0.5, 0.16666667, 0.16666667]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

again, their faces need not align, but the mesh may not have the desired connectivity

>>> triMesh = Tri2D(dx = 1.0, dy = 2.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[ 0.5, 1.5, 0.5, 1.5, 2.83333333, 3.83333333,
...                  2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [ 0.5, 0.5, 1.5, 1.5, 1., 1.,
...                  1.66666667, 1.66666667, 1., 1., 0.33333333, 0.33333333]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

Mesh concatenation is not limited to 2D meshes

>>> from fipy.meshes import Grid3D
>>> threeDBaseMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                         nx = 2, ny = 2, nz = 2)
>>> threeDSecondMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                           nx = 1, ny = 1, nz = 1)
>>> threeDAddedMesh = threeDBaseMesh + (threeDSecondMesh + ((2,), (0,), (0,)))
>>> print(threeDAddedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  0.5  1.5  0.5  1.5  2.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  0.5  1.5  1.5  1.5  1.5  0.5]]

but the different Mesh objects must, of course, have the same dimensionality.

>>> InvalidMesh = threeDBaseMesh + baseMesh 
Traceback (most recent call last):
...
MeshAdditionError: Dimensions do not match
__div__(other)

Tests. >>> from fipy import * >>> print((Grid1D(nx=1) / 2.).cellCenters) [[ 0.25]] >>> AbstractMesh(communicator=None) / 2. Traceback (most recent call last): … NotImplementedError

__getstate__()

Helper for pickle.

__mul__(factor)
__radd__(other)

Either translate a Mesh or concatenate two Mesh objects.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

If a vector is added to a Mesh, a translated Mesh is returned

>>> translatedMesh = baseMesh + ((5,), (10,))
>>> print(translatedMesh.cellCenters)
[[  5.5   6.5   5.5   6.5]
 [ 10.5  10.5  11.5  11.5]]

If a Mesh is added to a Mesh, a concatenation of the two Mesh objects is returned

>>> addedMesh = baseMesh + (baseMesh + ((2,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

The two Mesh objects need not be properly aligned in order to concatenate them but the resulting mesh may not have the intended connectivity

>>> addedMesh = baseMesh + (baseMesh + ((3,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  3.5  4.5  3.5  4.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]
>>> addedMesh = baseMesh + (baseMesh + ((2,), (2,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  2.5  2.5  3.5  3.5]]

No provision is made to avoid or consolidate overlapping Mesh objects

>>> addedMesh = baseMesh + (baseMesh + ((1,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  1.5  2.5  1.5  2.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

Different Mesh classes can be concatenated

>>> from fipy.meshes import Tri2D
>>> triMesh = Tri2D(dx = 1.0, dy = 1.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[0.5, 1.5, 0.5, 1.5, 2.83333333,  3.83333333,
...                 2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [0.5, 0.5, 1.5, 1.5, 0.5, 0.5, 0.83333333, 0.83333333,
...                 0.5, 0.5, 0.16666667, 0.16666667]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

again, their faces need not align, but the mesh may not have the desired connectivity

>>> triMesh = Tri2D(dx = 1.0, dy = 2.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[ 0.5, 1.5, 0.5, 1.5, 2.83333333, 3.83333333,
...                  2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [ 0.5, 0.5, 1.5, 1.5, 1., 1.,
...                  1.66666667, 1.66666667, 1., 1., 0.33333333, 0.33333333]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

Mesh concatenation is not limited to 2D meshes

>>> from fipy.meshes import Grid3D
>>> threeDBaseMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                         nx = 2, ny = 2, nz = 2)
>>> threeDSecondMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                           nx = 1, ny = 1, nz = 1)
>>> threeDAddedMesh = threeDBaseMesh + (threeDSecondMesh + ((2,), (0,), (0,)))
>>> print(threeDAddedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  0.5  1.5  0.5  1.5  2.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  0.5  1.5  1.5  1.5  1.5  0.5]]

but the different Mesh objects must, of course, have the same dimensionality.

>>> InvalidMesh = threeDBaseMesh + baseMesh 
Traceback (most recent call last):
...
MeshAdditionError: Dimensions do not match
__repr__()

Return repr(self).

__rmul__(other)
__setstate__(state)
__sub__(other)

Tests. >>> from fipy import * >>> m = Grid1D() >>> print((m - ((1,))).cellCenters) [[-0.5]] >>> ((1,)) - m Traceback (most recent call last): … TypeError: unsupported operand type(s) for -: ‘tuple’ and ‘UniformGrid1D’

__truediv__(other)

Tests. >>> from fipy import * >>> print((Grid1D(nx=1) / 2.).cellCenters) [[ 0.25]] >>> AbstractMesh(communicator=None) / 2. Traceback (most recent call last): … NotImplementedError

property aspect2D

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

property cellCenters
property cellDistanceVectors
property cellFaceIDs
property cellToFaceDistanceVectors
property cellVolumes
property extents
property exteriorFaces
property faceCellIDs
property faceCenters
property faceNormals
property faceVertexIDs
property facesBack

Return list of faces on back boundary of 3D Mesh 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
>>> ignore = mesh.facesBack.value 
property facesBottom

Return list of faces on bottom boundary of 2D or 3D Mesh 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])) 
True
>>> ignore = mesh.facesBottom.value 
>>> x, y, z = mesh.faceCenters
>>> print(numerix.allequal((12, 13),
...                        numerix.nonzero(mesh.facesBottom & (x < 1))[0])) 
True
>>> ignore = mesh.facesBottom.value 
property facesDown

Return list of faces on bottom boundary of 2D or 3D Mesh 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])) 
True
>>> ignore = mesh.facesBottom.value 
>>> x, y, z = mesh.faceCenters
>>> print(numerix.allequal((12, 13),
...                        numerix.nonzero(mesh.facesBottom & (x < 1))[0])) 
True
>>> ignore = mesh.facesBottom.value 
property facesFront

Return list of faces on front boundary of 3D Mesh 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
>>> ignore = mesh.facesFront.value 
property facesLeft

Return face on left boundary of Mesh 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
>>> ignore = mesh.facesLeft.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((9, 13),
...                        numerix.nonzero(mesh.facesLeft)[0])) 
True
>>> ignore = mesh.facesLeft.value 
property facesRight

Return list of faces on right boundary of Mesh 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
>>> ignore = mesh.facesRight.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((12, 16),
...                        numerix.nonzero(mesh.facesRight)[0])) 
True
>>> ignore = mesh.facesRight.value 
property facesTop

Return list of faces on top boundary of 2D or 3D Mesh 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
>>> ignore = mesh.facesTop.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((6, 7, 8),
...                        numerix.nonzero(mesh.facesTop)[0])) 
True
>>> ignore = mesh.facesTop.value 
property facesUp

Return list of faces on top boundary of 2D or 3D Mesh 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
>>> ignore = mesh.facesTop.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((6, 7, 8),
...                        numerix.nonzero(mesh.facesTop)[0])) 
True
>>> ignore = mesh.facesTop.value 
getNearestCell(point)
property interiorFaceCellIDs
property interiorFaceIDs
property interiorFaces
property scale
property scaledCellDistances
property scaledCellToCellDistances
property scaledCellVolumes
property scaledFaceAreas
property scaledFaceToCellDistances
property vertexCoords
property x

Equivalent to using cellCenters[0].

>>> from fipy import *
>>> print(Grid1D(nx=2).x)
[ 0.5  1.5]
property 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.
property 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.

fipy.meshes.factoryMeshes module

fipy.meshes.factoryMeshes.CylindricalGrid1D(dr=None, nr=None, Lr=None, dx=1.0, nx=None, Lx=None, origin=(0,), overlap=2, communicator=SerialPETScCommWrapper())

Create a 2D cylindrical mesh

Factory function to select between CylindricalUniformGrid1D and CylindricalNonUniformGrid1D. If Lr is specified the length of the domain is always Lr regardless of dr, unless dr is a list of spacings, in which case Lr will be the sum of dr.

Parameters:
  • dr (float) – Grid spacing in the radial direction. Alternative: dx.

  • nr (int) – Number of cells in the radial direction. Alternative: nx.

  • Lr (float) – Domain length in the radial direction. Alternative: Lx.

  • overlap (int) – the number of overlapping cells for parallel simulations. Generally 2 is adequate. Higher order equations or discretizations require more.

  • communicator (CommWrapper) – MPI communicator to use. Select serialComm to create a serial mesh when running in parallel; mostly used for test purposes. (default: parallelComm).

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=SerialPETScCommWrapper())

Create a 2D cylindrical mesh

Factory function to select between CylindricalUniformGrid2D and CylindricalNonUniformGrid2D. If Lr is specified the length of the domain is always Lr regardless of dr, unless dr is a list of spacings, in which case Lr will be the sum of dr.

Parameters:
  • dr (float) – Grid spacing in the radial direction. Alternative: dx.

  • dz (float) – grid spacing in the vertical direction. Alternative: dy.

  • nr (int) – Number of cells in the radial direction. Alternative: nx.

  • nz (int) – Number of cells in the vertical direction. Alternative: ny.

  • Lr (float) – Domain length in the radial direction. Alternative: Lx.

  • Lz (float) – Domain length in the vertical direction. Alternative: Ly.

  • overlap (int) – the number of overlapping cells for parallel simulations. Generally 2 is adequate. Higher order equations or discretizations require more.

  • communicator (CommWrapper) – MPI communicator to use. Select serialComm to create a serial mesh when running in parallel; mostly used for test purposes. (default: parallelComm).

fipy.meshes.factoryMeshes.Grid1D(dx=1.0, nx=None, Lx=None, overlap=2, communicator=SerialPETScCommWrapper())

Create a 1D Cartesian mesh

Factory function to select between UniformGrid1D and NonUniformGrid1D. If Lx is specified the length of the domain is always Lx regardless of dx, unless dx is a list of spacings, in which case Lx will be the sum of dx and nx will be the count of dx.

Parameters:
  • dx (float) – Grid spacing in the horizontal direction

  • nx (int) – Number of cells in the horizontal direction

  • Lx (float) – Domain length in the horizontal direction

  • overlap (int) – Number of overlapping cells for parallel simulations. Generally 2 is adequate. Higher order equations or discretizations require more.

  • communicator (CommWrapper) – MPI communicator to use. Select serialComm to create a serial mesh when running in parallel; mostly used for test purposes. (default: parallelComm).

fipy.meshes.factoryMeshes.Grid2D(dx=1.0, dy=1.0, nx=None, ny=None, Lx=None, Ly=None, overlap=2, communicator=SerialPETScCommWrapper())

Create a 2D Cartesian mesh

Factory function to select between UniformGrid2D and NonUniformGrid2D. If L{x,y} is specified, the length of the domain is always L{x,y} regardless of d{x,y}, unless d{x,y} is a list of spacings, in which case L{x,y} will be the sum of d{x,y} and n{x,y} will be the count of d{x,y}.

>>> print(Grid2D(Lx=3., nx=2).dx)
1.5
Parameters:
  • dx (float) – Grid spacing in the horizontal direction

  • dy (float) – Grid spacing in the vertical direction

  • nx (int) – Number of cells in the horizontal direction

  • ny (int) – Number of cells in the vertical direction

  • Lx (float) – Domain length in the horizontal direction

  • Ly (float) – Domain length in the vertical direction

  • overlap (int) – Number of overlapping cells for parallel simulations. Generally 2 is adequate. Higher order equations or discretizations require more.

  • communicator (CommWrapper) – MPI communicator to use. Select serialComm to create a serial mesh when running in parallel; mostly used for test purposes. (default: parallelComm).

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=SerialPETScCommWrapper())

Create a 3D Cartesian mesh

Factory function to select between UniformGrid3D and NonUniformGrid3D. If L{x,y,z} is specified, the length of the domain is always L{x,y,z} regardless of d{x,y,z}, unless d{x,y,z} is a list of spacings, in which case L{x,y,z} will be the sum of d{x,y,z} and n{x,y,z} will be the count of d{x,y,z}.

Parameters:
  • dx (float) – Grid spacing in the horizontal direction

  • dy (float) – Grid spacing in the vertical direction

  • dz (float) – Grid spacing in the depth direction

  • nx (int) – Number of cells in the horizontal direction

  • ny (int) – Number of cells in the vertical direction

  • nz (int) – Number of cells in the depth direction

  • Lx (float) – Domain length in the horizontal direction

  • Ly (float) – Domain length in the vertical direction

  • Lz (float) – Domain length in the depth direction

  • overlap (int) – Number of overlapping cells for parallel simulations. Generally 2 is adequate. Higher order equations or discretizations require more.

  • communicator (CommWrapper) – MPI communicator to use. Select serialComm to create a serial mesh when running in parallel; mostly used for test purposes. (default: parallelComm).

fipy.meshes.factoryMeshes.SphericalGrid1D(dr=None, nr=None, Lr=None, dx=1.0, nx=None, Lx=None, origin=(0,), overlap=2, communicator=SerialPETScCommWrapper())

Create a 1D spherical mesh

Factory function to select between SphericalUniformGrid1D and SphericalNonUniformGrid1D. If Lr is specified the length of the domain is always Lr regardless of dr, unless dr is a list of spacings, in which case Lr will be the sum of dr.

Parameters:
  • dr (float) – Grid spacing in the radial direction. Alternative: dx.

  • nr (int) – Number of cells in the radial direction. Alternative: nx.

  • Lr (float) – Domain length in the radial direction. Alternative: Lx.

  • overlap (int) – the number of overlapping cells for parallel simulations. Generally 2 is adequate. Higher order equations or discretizations require more.

  • communicator (CommWrapper) – MPI communicator to use. Select serialComm to create a serial mesh when running in parallel; mostly used for test purposes. (default: parallelComm).

fipy.meshes.gmshMesh module

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

Bases: Mesh2D

Construct a 2D Mesh using Gmsh

If called in parallel, the mesh will be partitioned based on the value of parallelComm.Nproc. If an MSH file is supplied, it must have been previously partitioned with the number of partitions matching parallelComm.Nproc.

>>> 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 Surface 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
>>> error = []
>>> bkg = None
>>> from builtins import range
>>> for refine in range(4):
...     square = Gmsh2D(geo, background=bkg) 
...     x, y = square.cellCenters 
...     bkg = CellVariable(mesh=square, value=abs(x / 4) + 0.01) 
...     error.append(((2 * numerix.sqrt(square.cellVolumes) / bkg - 1)**2).cellVolumeAverage) 

Check that the mesh is (semi)monotonically approaching the desired density (the first step may increase, depending on the number of partitions)

>>> print(numerix.greater(error[:-1], error[1:]).all()) 
True

and that the final density is close enough to the desired density

>>> print(error[-1] < 0.02) 
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.sqrt(2 * trisquare.cellVolumes) / bkg).std()
>>> square = Gmsh2D(geo, background=bkg) 
>>> x, y = square.cellCenters 
>>> bkg = CellVariable(mesh=square, value=abs(x / 4) + 0.01) 
>>> std2 = (numerix.sqrt(2 * square.cellVolumes) / bkg).std() 
>>> print(std1 > std2) 
True
Parameters:
  • arg (str) – (i) the path to an MSH file, (ii) a path to a Gmsh geometry (.geo) file, or (iii) a Gmsh geometry script

  • coordDimensions (int) – Dimension of shapes

  • overlap (int) – The number of overlapping cells for parallel simulations. Generally 1 is adequate. Higher order equations or discretizations require more. If overlap is greater than one, communication reverts to serial, as Gmsh only provides one layer of ghost cells.

  • background (CellVariable) – Specifies the desired characteristic lengths of the mesh cells

property VTKCellDataSet

Returns a TVTK DataSet representing the cells of this mesh

property VTKFaceDataSet

Returns a TVTK DataSet representing the face centers of this mesh

__add__(other)

Either translate a Mesh or concatenate two Mesh objects.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

If a vector is added to a Mesh, a translated Mesh is returned

>>> translatedMesh = baseMesh + ((5,), (10,))
>>> print(translatedMesh.cellCenters)
[[  5.5   6.5   5.5   6.5]
 [ 10.5  10.5  11.5  11.5]]

If a Mesh is added to a Mesh, a concatenation of the two Mesh objects is returned

>>> addedMesh = baseMesh + (baseMesh + ((2,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

The two Mesh objects need not be properly aligned in order to concatenate them but the resulting mesh may not have the intended connectivity

>>> addedMesh = baseMesh + (baseMesh + ((3,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  3.5  4.5  3.5  4.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]
>>> addedMesh = baseMesh + (baseMesh + ((2,), (2,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  2.5  2.5  3.5  3.5]]

No provision is made to avoid or consolidate overlapping Mesh objects

>>> addedMesh = baseMesh + (baseMesh + ((1,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  1.5  2.5  1.5  2.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

Different Mesh classes can be concatenated

>>> from fipy.meshes import Tri2D
>>> triMesh = Tri2D(dx = 1.0, dy = 1.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[0.5, 1.5, 0.5, 1.5, 2.83333333,  3.83333333,
...                 2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [0.5, 0.5, 1.5, 1.5, 0.5, 0.5, 0.83333333, 0.83333333,
...                 0.5, 0.5, 0.16666667, 0.16666667]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

again, their faces need not align, but the mesh may not have the desired connectivity

>>> triMesh = Tri2D(dx = 1.0, dy = 2.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[ 0.5, 1.5, 0.5, 1.5, 2.83333333, 3.83333333,
...                  2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [ 0.5, 0.5, 1.5, 1.5, 1., 1.,
...                  1.66666667, 1.66666667, 1., 1., 0.33333333, 0.33333333]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

Mesh concatenation is not limited to 2D meshes

>>> from fipy.meshes import Grid3D
>>> threeDBaseMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                         nx = 2, ny = 2, nz = 2)
>>> threeDSecondMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                           nx = 1, ny = 1, nz = 1)
>>> threeDAddedMesh = threeDBaseMesh + (threeDSecondMesh + ((2,), (0,), (0,)))
>>> print(threeDAddedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  0.5  1.5  0.5  1.5  2.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  0.5  1.5  1.5  1.5  1.5  0.5]]

but the different Mesh objects must, of course, have the same dimensionality.

>>> InvalidMesh = threeDBaseMesh + baseMesh 
Traceback (most recent call last):
...
MeshAdditionError: Dimensions do not match
__div__(other)

Tests. >>> from fipy import * >>> print((Grid1D(nx=1) / 2.).cellCenters) [[ 0.25]] >>> AbstractMesh(communicator=None) / 2. Traceback (most recent call last): … NotImplementedError

__getstate__()

Helper for pickle.

__mul__(factor)

Dilate a Mesh by factor.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

The factor can be a scalar

>>> dilatedMesh = baseMesh * 3
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.5  1.5  4.5  4.5]]

or a vector

>>> dilatedMesh = baseMesh * ((3,), (2,))
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.   1.   3.   3. ]]

but the vector must have the same dimensionality as the Mesh

>>> dilatedMesh = baseMesh * ((3,), (2,), (1,)) 
Traceback (most recent call last):
...
ValueError: shape mismatch: objects cannot be broadcast to a single shape
__radd__(other)

Either translate a Mesh or concatenate two Mesh objects.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

If a vector is added to a Mesh, a translated Mesh is returned

>>> translatedMesh = baseMesh + ((5,), (10,))
>>> print(translatedMesh.cellCenters)
[[  5.5   6.5   5.5   6.5]
 [ 10.5  10.5  11.5  11.5]]

If a Mesh is added to a Mesh, a concatenation of the two Mesh objects is returned

>>> addedMesh = baseMesh + (baseMesh + ((2,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

The two Mesh objects need not be properly aligned in order to concatenate them but the resulting mesh may not have the intended connectivity

>>> addedMesh = baseMesh + (baseMesh + ((3,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  3.5  4.5  3.5  4.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]
>>> addedMesh = baseMesh + (baseMesh + ((2,), (2,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  2.5  2.5  3.5  3.5]]

No provision is made to avoid or consolidate overlapping Mesh objects

>>> addedMesh = baseMesh + (baseMesh + ((1,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  1.5  2.5  1.5  2.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

Different Mesh classes can be concatenated

>>> from fipy.meshes import Tri2D
>>> triMesh = Tri2D(dx = 1.0, dy = 1.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[0.5, 1.5, 0.5, 1.5, 2.83333333,  3.83333333,
...                 2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [0.5, 0.5, 1.5, 1.5, 0.5, 0.5, 0.83333333, 0.83333333,
...                 0.5, 0.5, 0.16666667, 0.16666667]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

again, their faces need not align, but the mesh may not have the desired connectivity

>>> triMesh = Tri2D(dx = 1.0, dy = 2.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[ 0.5, 1.5, 0.5, 1.5, 2.83333333, 3.83333333,
...                  2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [ 0.5, 0.5, 1.5, 1.5, 1., 1.,
...                  1.66666667, 1.66666667, 1., 1., 0.33333333, 0.33333333]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

Mesh concatenation is not limited to 2D meshes

>>> from fipy.meshes import Grid3D
>>> threeDBaseMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                         nx = 2, ny = 2, nz = 2)
>>> threeDSecondMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                           nx = 1, ny = 1, nz = 1)
>>> threeDAddedMesh = threeDBaseMesh + (threeDSecondMesh + ((2,), (0,), (0,)))
>>> print(threeDAddedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  0.5  1.5  0.5  1.5  2.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  0.5  1.5  1.5  1.5  1.5  0.5]]

but the different Mesh objects must, of course, have the same dimensionality.

>>> InvalidMesh = threeDBaseMesh + baseMesh 
Traceback (most recent call last):
...
MeshAdditionError: Dimensions do not match
__repr__()

Return repr(self).

__rmul__(factor)

Dilate a Mesh by factor.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

The factor can be a scalar

>>> dilatedMesh = baseMesh * 3
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.5  1.5  4.5  4.5]]

or a vector

>>> dilatedMesh = baseMesh * ((3,), (2,))
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.   1.   3.   3. ]]

but the vector must have the same dimensionality as the Mesh

>>> dilatedMesh = baseMesh * ((3,), (2,), (1,)) 
Traceback (most recent call last):
...
ValueError: shape mismatch: objects cannot be broadcast to a single shape
__setstate__(state)
__sub__(other)

Tests. >>> from fipy import * >>> m = Grid1D() >>> print((m - ((1,))).cellCenters) [[-0.5]] >>> ((1,)) - m Traceback (most recent call last): … TypeError: unsupported operand type(s) for -: ‘tuple’ and ‘UniformGrid1D’

__truediv__(other)

Tests. >>> from fipy import * >>> print((Grid1D(nx=1) / 2.).cellCenters) [[ 0.25]] >>> AbstractMesh(communicator=None) / 2. Traceback (most recent call last): … NotImplementedError

property aspect2D

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

property cellCenters
property cellDistanceVectors
property cellFaceIDs
property cellToFaceDistanceVectors
property cellVolumes
property extents
property exteriorFaces
extrude(extrudeFunc=<function Mesh2D.<lambda>>, layers=1)

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

>>> 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.allclose([[ 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       ]]))
True
Parameters:
  • extrudeFunc (function) – Takes the vertex coordinates and returns the displaced values

  • layers (int) – Number of layers in the extruded mesh (number of times extrudeFunc will be called)

property faceCenters
property facesBack

Return list of faces on back boundary of 3D Mesh 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
>>> ignore = mesh.facesBack.value 
property facesBottom

Return list of faces on bottom boundary of 2D or 3D Mesh 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])) 
True
>>> ignore = mesh.facesBottom.value 
>>> x, y, z = mesh.faceCenters
>>> print(numerix.allequal((12, 13),
...                        numerix.nonzero(mesh.facesBottom & (x < 1))[0])) 
True
>>> ignore = mesh.facesBottom.value 
property facesDown

Return list of faces on bottom boundary of 2D or 3D Mesh 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])) 
True
>>> ignore = mesh.facesBottom.value 
>>> x, y, z = mesh.faceCenters
>>> print(numerix.allequal((12, 13),
...                        numerix.nonzero(mesh.facesBottom & (x < 1))[0])) 
True
>>> ignore = mesh.facesBottom.value 
property facesFront

Return list of faces on front boundary of 3D Mesh 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
>>> ignore = mesh.facesFront.value 
property facesLeft

Return face on left boundary of Mesh 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
>>> ignore = mesh.facesLeft.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((9, 13),
...                        numerix.nonzero(mesh.facesLeft)[0])) 
True
>>> ignore = mesh.facesLeft.value 
property facesRight

Return list of faces on right boundary of Mesh 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
>>> ignore = mesh.facesRight.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((12, 16),
...                        numerix.nonzero(mesh.facesRight)[0])) 
True
>>> ignore = mesh.facesRight.value 
property facesTop

Return list of faces on top boundary of 2D or 3D Mesh 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
>>> ignore = mesh.facesTop.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((6, 7, 8),
...                        numerix.nonzero(mesh.facesTop)[0])) 
True
>>> ignore = mesh.facesTop.value 
property facesUp

Return list of faces on top boundary of 2D or 3D Mesh 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
>>> ignore = mesh.facesTop.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((6, 7, 8),
...                        numerix.nonzero(mesh.facesTop)[0])) 
True
>>> ignore = mesh.facesTop.value 
getNearestCell(point)
property interiorFaceCellIDs
property interiorFaceIDs
property interiorFaces
property scale
property scaledCellDistances
property scaledCellToCellDistances
property scaledCellVolumes
property scaledFaceAreas
property scaledFaceToCellDistances
property x

Equivalent to using cellCenters[0].

>>> from fipy import *
>>> print(Grid1D(nx=2).x)
[ 0.5  1.5]
property 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.
property 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.
class fipy.meshes.gmshMesh.Gmsh2DIn3DSpace(arg, communicator=SerialPETScCommWrapper(), overlap=1, background=None)

Bases: Gmsh2D

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

If called in parallel, the mesh will be partitioned based on the value of parallelComm.Nproc. If an MSH file is supplied, it must have been previously partitioned with the number of partitions matching parallelComm.Nproc.

Parameters:
  • arg (str) – (i) the path to an MSH file, (ii) a path to a Gmsh geometry (.geo) file, or (iii) a Gmsh geometry script

  • coordDimensions (int) – Dimension of shapes

  • overlap (int) – The number of overlapping cells for parallel simulations. Generally 1 is adequate. Higher order equations or discretizations require more. If overlap is greater than one, communication reverts to serial, as Gmsh only provides one layer of ghost cells.

  • background (CellVariable) – Specifies the desired characteristic lengths of the mesh cells

property VTKCellDataSet

Returns a TVTK DataSet representing the cells of this mesh

property VTKFaceDataSet

Returns a TVTK DataSet representing the face centers of this mesh

__add__(other)

Either translate a Mesh or concatenate two Mesh objects.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

If a vector is added to a Mesh, a translated Mesh is returned

>>> translatedMesh = baseMesh + ((5,), (10,))
>>> print(translatedMesh.cellCenters)
[[  5.5   6.5   5.5   6.5]
 [ 10.5  10.5  11.5  11.5]]

If a Mesh is added to a Mesh, a concatenation of the two Mesh objects is returned

>>> addedMesh = baseMesh + (baseMesh + ((2,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

The two Mesh objects need not be properly aligned in order to concatenate them but the resulting mesh may not have the intended connectivity

>>> addedMesh = baseMesh + (baseMesh + ((3,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  3.5  4.5  3.5  4.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]
>>> addedMesh = baseMesh + (baseMesh + ((2,), (2,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  2.5  2.5  3.5  3.5]]

No provision is made to avoid or consolidate overlapping Mesh objects

>>> addedMesh = baseMesh + (baseMesh + ((1,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  1.5  2.5  1.5  2.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

Different Mesh classes can be concatenated

>>> from fipy.meshes import Tri2D
>>> triMesh = Tri2D(dx = 1.0, dy = 1.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[0.5, 1.5, 0.5, 1.5, 2.83333333,  3.83333333,
...                 2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [0.5, 0.5, 1.5, 1.5, 0.5, 0.5, 0.83333333, 0.83333333,
...                 0.5, 0.5, 0.16666667, 0.16666667]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

again, their faces need not align, but the mesh may not have the desired connectivity

>>> triMesh = Tri2D(dx = 1.0, dy = 2.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[ 0.5, 1.5, 0.5, 1.5, 2.83333333, 3.83333333,
...                  2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [ 0.5, 0.5, 1.5, 1.5, 1., 1.,
...                  1.66666667, 1.66666667, 1., 1., 0.33333333, 0.33333333]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

Mesh concatenation is not limited to 2D meshes

>>> from fipy.meshes import Grid3D
>>> threeDBaseMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                         nx = 2, ny = 2, nz = 2)
>>> threeDSecondMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                           nx = 1, ny = 1, nz = 1)
>>> threeDAddedMesh = threeDBaseMesh + (threeDSecondMesh + ((2,), (0,), (0,)))
>>> print(threeDAddedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  0.5  1.5  0.5  1.5  2.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  0.5  1.5  1.5  1.5  1.5  0.5]]

but the different Mesh objects must, of course, have the same dimensionality.

>>> InvalidMesh = threeDBaseMesh + baseMesh 
Traceback (most recent call last):
...
MeshAdditionError: Dimensions do not match
__div__(other)

Tests. >>> from fipy import * >>> print((Grid1D(nx=1) / 2.).cellCenters) [[ 0.25]] >>> AbstractMesh(communicator=None) / 2. Traceback (most recent call last): … NotImplementedError

__getstate__()

Helper for pickle.

__mul__(factor)

Dilate a Mesh by factor.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

The factor can be a scalar

>>> dilatedMesh = baseMesh * 3
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.5  1.5  4.5  4.5]]

or a vector

>>> dilatedMesh = baseMesh * ((3,), (2,))
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.   1.   3.   3. ]]

but the vector must have the same dimensionality as the Mesh

>>> dilatedMesh = baseMesh * ((3,), (2,), (1,)) 
Traceback (most recent call last):
...
ValueError: shape mismatch: objects cannot be broadcast to a single shape
__radd__(other)

Either translate a Mesh or concatenate two Mesh objects.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

If a vector is added to a Mesh, a translated Mesh is returned

>>> translatedMesh = baseMesh + ((5,), (10,))
>>> print(translatedMesh.cellCenters)
[[  5.5   6.5   5.5   6.5]
 [ 10.5  10.5  11.5  11.5]]

If a Mesh is added to a Mesh, a concatenation of the two Mesh objects is returned

>>> addedMesh = baseMesh + (baseMesh + ((2,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

The two Mesh objects need not be properly aligned in order to concatenate them but the resulting mesh may not have the intended connectivity

>>> addedMesh = baseMesh + (baseMesh + ((3,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  3.5  4.5  3.5  4.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]
>>> addedMesh = baseMesh + (baseMesh + ((2,), (2,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  2.5  2.5  3.5  3.5]]

No provision is made to avoid or consolidate overlapping Mesh objects

>>> addedMesh = baseMesh + (baseMesh + ((1,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  1.5  2.5  1.5  2.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

Different Mesh classes can be concatenated

>>> from fipy.meshes import Tri2D
>>> triMesh = Tri2D(dx = 1.0, dy = 1.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[0.5, 1.5, 0.5, 1.5, 2.83333333,  3.83333333,
...                 2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [0.5, 0.5, 1.5, 1.5, 0.5, 0.5, 0.83333333, 0.83333333,
...                 0.5, 0.5, 0.16666667, 0.16666667]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

again, their faces need not align, but the mesh may not have the desired connectivity

>>> triMesh = Tri2D(dx = 1.0, dy = 2.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[ 0.5, 1.5, 0.5, 1.5, 2.83333333, 3.83333333,
...                  2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [ 0.5, 0.5, 1.5, 1.5, 1., 1.,
...                  1.66666667, 1.66666667, 1., 1., 0.33333333, 0.33333333]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

Mesh concatenation is not limited to 2D meshes

>>> from fipy.meshes import Grid3D
>>> threeDBaseMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                         nx = 2, ny = 2, nz = 2)
>>> threeDSecondMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                           nx = 1, ny = 1, nz = 1)
>>> threeDAddedMesh = threeDBaseMesh + (threeDSecondMesh + ((2,), (0,), (0,)))
>>> print(threeDAddedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  0.5  1.5  0.5  1.5  2.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  0.5  1.5  1.5  1.5  1.5  0.5]]

but the different Mesh objects must, of course, have the same dimensionality.

>>> InvalidMesh = threeDBaseMesh + baseMesh 
Traceback (most recent call last):
...
MeshAdditionError: Dimensions do not match
__repr__()

Return repr(self).

__rmul__(factor)

Dilate a Mesh by factor.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

The factor can be a scalar

>>> dilatedMesh = baseMesh * 3
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.5  1.5  4.5  4.5]]

or a vector

>>> dilatedMesh = baseMesh * ((3,), (2,))
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.   1.   3.   3. ]]

but the vector must have the same dimensionality as the Mesh

>>> dilatedMesh = baseMesh * ((3,), (2,), (1,)) 
Traceback (most recent call last):
...
ValueError: shape mismatch: objects cannot be broadcast to a single shape
__setstate__(state)
__sub__(other)

Tests. >>> from fipy import * >>> m = Grid1D() >>> print((m - ((1,))).cellCenters) [[-0.5]] >>> ((1,)) - m Traceback (most recent call last): … TypeError: unsupported operand type(s) for -: ‘tuple’ and ‘UniformGrid1D’

__truediv__(other)

Tests. >>> from fipy import * >>> print((Grid1D(nx=1) / 2.).cellCenters) [[ 0.25]] >>> AbstractMesh(communicator=None) / 2. Traceback (most recent call last): … NotImplementedError

property aspect2D

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

property cellCenters
property cellDistanceVectors
property cellFaceIDs
property cellToFaceDistanceVectors
property cellVolumes
property extents
property exteriorFaces
extrude(extrudeFunc=<function Mesh2D.<lambda>>, layers=1)

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

>>> 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.allclose([[ 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       ]]))
True
Parameters:
  • extrudeFunc (function) – Takes the vertex coordinates and returns the displaced values

  • layers (int) – Number of layers in the extruded mesh (number of times extrudeFunc will be called)

property faceCenters
property facesBack

Return list of faces on back boundary of 3D Mesh 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
>>> ignore = mesh.facesBack.value 
property facesBottom

Return list of faces on bottom boundary of 2D or 3D Mesh 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])) 
True
>>> ignore = mesh.facesBottom.value 
>>> x, y, z = mesh.faceCenters
>>> print(numerix.allequal((12, 13),
...                        numerix.nonzero(mesh.facesBottom & (x < 1))[0])) 
True
>>> ignore = mesh.facesBottom.value 
property facesDown

Return list of faces on bottom boundary of 2D or 3D Mesh 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])) 
True
>>> ignore = mesh.facesBottom.value 
>>> x, y, z = mesh.faceCenters
>>> print(numerix.allequal((12, 13),
...                        numerix.nonzero(mesh.facesBottom & (x < 1))[0])) 
True
>>> ignore = mesh.facesBottom.value 
property facesFront

Return list of faces on front boundary of 3D Mesh 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
>>> ignore = mesh.facesFront.value 
property facesLeft

Return face on left boundary of Mesh 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
>>> ignore = mesh.facesLeft.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((9, 13),
...                        numerix.nonzero(mesh.facesLeft)[0])) 
True
>>> ignore = mesh.facesLeft.value 
property facesRight

Return list of faces on right boundary of Mesh 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
>>> ignore = mesh.facesRight.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((12, 16),
...                        numerix.nonzero(mesh.facesRight)[0])) 
True
>>> ignore = mesh.facesRight.value 
property facesTop

Return list of faces on top boundary of 2D or 3D Mesh 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
>>> ignore = mesh.facesTop.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((6, 7, 8),
...                        numerix.nonzero(mesh.facesTop)[0])) 
True
>>> ignore = mesh.facesTop.value 
property facesUp

Return list of faces on top boundary of 2D or 3D Mesh 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
>>> ignore = mesh.facesTop.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((6, 7, 8),
...                        numerix.nonzero(mesh.facesTop)[0])) 
True
>>> ignore = mesh.facesTop.value 
getNearestCell(point)
property interiorFaceCellIDs
property interiorFaceIDs
property interiorFaces
property scale
property scaledCellDistances
property scaledCellToCellDistances
property scaledCellVolumes
property scaledFaceAreas
property scaledFaceToCellDistances
property x

Equivalent to using cellCenters[0].

>>> from fipy import *
>>> print(Grid1D(nx=2).x)
[ 0.5  1.5]
property 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.
property 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.
class fipy.meshes.gmshMesh.Gmsh3D(arg, communicator=SerialPETScCommWrapper(), overlap=1, background=None)

Bases: Mesh

Create a 3D Mesh using Gmsh

If called in parallel, the mesh will be partitioned based on the value of parallelComm.Nproc. If an MSH file is supplied, it must have been previously partitioned with the number of partitions matching parallelComm.Nproc.

Parameters:
  • arg (str) – (i) the path to an MSH file, (ii) a path to a Gmsh geometry (.geo) file, or (iii) a Gmsh geometry script

  • overlap (int) – The number of overlapping cells for parallel simulations. Generally 1 is adequate. Higher order equations or discretizations require more. If overlap is greater than one, communication reverts to serial, as Gmsh only provides one layer of ghost cells.

  • background (CellVariable) – Specifies the desired characteristic lengths of the mesh cells

property VTKCellDataSet

Returns a TVTK DataSet representing the cells of this mesh

property VTKFaceDataSet

Returns a TVTK DataSet representing the face centers of this mesh

__add__(other)

Either translate a Mesh or concatenate two Mesh objects.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

If a vector is added to a Mesh, a translated Mesh is returned

>>> translatedMesh = baseMesh + ((5,), (10,))
>>> print(translatedMesh.cellCenters)
[[  5.5   6.5   5.5   6.5]
 [ 10.5  10.5  11.5  11.5]]

If a Mesh is added to a Mesh, a concatenation of the two Mesh objects is returned

>>> addedMesh = baseMesh + (baseMesh + ((2,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

The two Mesh objects need not be properly aligned in order to concatenate them but the resulting mesh may not have the intended connectivity

>>> addedMesh = baseMesh + (baseMesh + ((3,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  3.5  4.5  3.5  4.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]
>>> addedMesh = baseMesh + (baseMesh + ((2,), (2,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  2.5  2.5  3.5  3.5]]

No provision is made to avoid or consolidate overlapping Mesh objects

>>> addedMesh = baseMesh + (baseMesh + ((1,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  1.5  2.5  1.5  2.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

Different Mesh classes can be concatenated

>>> from fipy.meshes import Tri2D
>>> triMesh = Tri2D(dx = 1.0, dy = 1.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[0.5, 1.5, 0.5, 1.5, 2.83333333,  3.83333333,
...                 2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [0.5, 0.5, 1.5, 1.5, 0.5, 0.5, 0.83333333, 0.83333333,
...                 0.5, 0.5, 0.16666667, 0.16666667]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

again, their faces need not align, but the mesh may not have the desired connectivity

>>> triMesh = Tri2D(dx = 1.0, dy = 2.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[ 0.5, 1.5, 0.5, 1.5, 2.83333333, 3.83333333,
...                  2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [ 0.5, 0.5, 1.5, 1.5, 1., 1.,
...                  1.66666667, 1.66666667, 1., 1., 0.33333333, 0.33333333]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

Mesh concatenation is not limited to 2D meshes

>>> from fipy.meshes import Grid3D
>>> threeDBaseMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                         nx = 2, ny = 2, nz = 2)
>>> threeDSecondMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                           nx = 1, ny = 1, nz = 1)
>>> threeDAddedMesh = threeDBaseMesh + (threeDSecondMesh + ((2,), (0,), (0,)))
>>> print(threeDAddedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  0.5  1.5  0.5  1.5  2.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  0.5  1.5  1.5  1.5  1.5  0.5]]

but the different Mesh objects must, of course, have the same dimensionality.

>>> InvalidMesh = threeDBaseMesh + baseMesh 
Traceback (most recent call last):
...
MeshAdditionError: Dimensions do not match
__div__(other)

Tests. >>> from fipy import * >>> print((Grid1D(nx=1) / 2.).cellCenters) [[ 0.25]] >>> AbstractMesh(communicator=None) / 2. Traceback (most recent call last): … NotImplementedError

__getstate__()

Helper for pickle.

__mul__(factor)

Dilate a Mesh by factor.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

The factor can be a scalar

>>> dilatedMesh = baseMesh * 3
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.5  1.5  4.5  4.5]]

or a vector

>>> dilatedMesh = baseMesh * ((3,), (2,))
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.   1.   3.   3. ]]

but the vector must have the same dimensionality as the Mesh

>>> dilatedMesh = baseMesh * ((3,), (2,), (1,)) 
Traceback (most recent call last):
...
ValueError: shape mismatch: objects cannot be broadcast to a single shape
__radd__(other)

Either translate a Mesh or concatenate two Mesh objects.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

If a vector is added to a Mesh, a translated Mesh is returned

>>> translatedMesh = baseMesh + ((5,), (10,))
>>> print(translatedMesh.cellCenters)
[[  5.5   6.5   5.5   6.5]
 [ 10.5  10.5  11.5  11.5]]

If a Mesh is added to a Mesh, a concatenation of the two Mesh objects is returned

>>> addedMesh = baseMesh + (baseMesh + ((2,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

The two Mesh objects need not be properly aligned in order to concatenate them but the resulting mesh may not have the intended connectivity

>>> addedMesh = baseMesh + (baseMesh + ((3,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  3.5  4.5  3.5  4.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]
>>> addedMesh = baseMesh + (baseMesh + ((2,), (2,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  2.5  2.5  3.5  3.5]]

No provision is made to avoid or consolidate overlapping Mesh objects

>>> addedMesh = baseMesh + (baseMesh + ((1,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  1.5  2.5  1.5  2.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

Different Mesh classes can be concatenated

>>> from fipy.meshes import Tri2D
>>> triMesh = Tri2D(dx = 1.0, dy = 1.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[0.5, 1.5, 0.5, 1.5, 2.83333333,  3.83333333,
...                 2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [0.5, 0.5, 1.5, 1.5, 0.5, 0.5, 0.83333333, 0.83333333,
...                 0.5, 0.5, 0.16666667, 0.16666667]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

again, their faces need not align, but the mesh may not have the desired connectivity

>>> triMesh = Tri2D(dx = 1.0, dy = 2.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[ 0.5, 1.5, 0.5, 1.5, 2.83333333, 3.83333333,
...                  2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [ 0.5, 0.5, 1.5, 1.5, 1., 1.,
...                  1.66666667, 1.66666667, 1., 1., 0.33333333, 0.33333333]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

Mesh concatenation is not limited to 2D meshes

>>> from fipy.meshes import Grid3D
>>> threeDBaseMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                         nx = 2, ny = 2, nz = 2)
>>> threeDSecondMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                           nx = 1, ny = 1, nz = 1)
>>> threeDAddedMesh = threeDBaseMesh + (threeDSecondMesh + ((2,), (0,), (0,)))
>>> print(threeDAddedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  0.5  1.5  0.5  1.5  2.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  0.5  1.5  1.5  1.5  1.5  0.5]]

but the different Mesh objects must, of course, have the same dimensionality.

>>> InvalidMesh = threeDBaseMesh + baseMesh 
Traceback (most recent call last):
...
MeshAdditionError: Dimensions do not match
__repr__()

Return repr(self).

__rmul__(factor)

Dilate a Mesh by factor.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

The factor can be a scalar

>>> dilatedMesh = baseMesh * 3
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.5  1.5  4.5  4.5]]

or a vector

>>> dilatedMesh = baseMesh * ((3,), (2,))
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.   1.   3.   3. ]]

but the vector must have the same dimensionality as the Mesh

>>> dilatedMesh = baseMesh * ((3,), (2,), (1,)) 
Traceback (most recent call last):
...
ValueError: shape mismatch: objects cannot be broadcast to a single shape
__setstate__(state)
__sub__(other)

Tests. >>> from fipy import * >>> m = Grid1D() >>> print((m - ((1,))).cellCenters) [[-0.5]] >>> ((1,)) - m Traceback (most recent call last): … TypeError: unsupported operand type(s) for -: ‘tuple’ and ‘UniformGrid1D’

__truediv__(other)

Tests. >>> from fipy import * >>> print((Grid1D(nx=1) / 2.).cellCenters) [[ 0.25]] >>> AbstractMesh(communicator=None) / 2. Traceback (most recent call last): … NotImplementedError

property aspect2D

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

property cellCenters
property cellDistanceVectors
property cellFaceIDs
property cellToFaceDistanceVectors
property cellVolumes
property extents
property exteriorFaces
property faceCenters
property facesBack

Return list of faces on back boundary of 3D Mesh 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
>>> ignore = mesh.facesBack.value 
property facesBottom

Return list of faces on bottom boundary of 2D or 3D Mesh 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])) 
True
>>> ignore = mesh.facesBottom.value 
>>> x, y, z = mesh.faceCenters
>>> print(numerix.allequal((12, 13),
...                        numerix.nonzero(mesh.facesBottom & (x < 1))[0])) 
True
>>> ignore = mesh.facesBottom.value 
property facesDown

Return list of faces on bottom boundary of 2D or 3D Mesh 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])) 
True
>>> ignore = mesh.facesBottom.value 
>>> x, y, z = mesh.faceCenters
>>> print(numerix.allequal((12, 13),
...                        numerix.nonzero(mesh.facesBottom & (x < 1))[0])) 
True
>>> ignore = mesh.facesBottom.value 
property facesFront

Return list of faces on front boundary of 3D Mesh 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
>>> ignore = mesh.facesFront.value 
property facesLeft

Return face on left boundary of Mesh 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
>>> ignore = mesh.facesLeft.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((9, 13),
...                        numerix.nonzero(mesh.facesLeft)[0])) 
True
>>> ignore = mesh.facesLeft.value 
property facesRight

Return list of faces on right boundary of Mesh 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
>>> ignore = mesh.facesRight.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((12, 16),
...                        numerix.nonzero(mesh.facesRight)[0])) 
True
>>> ignore = mesh.facesRight.value 
property facesTop

Return list of faces on top boundary of 2D or 3D Mesh 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
>>> ignore = mesh.facesTop.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((6, 7, 8),
...                        numerix.nonzero(mesh.facesTop)[0])) 
True
>>> ignore = mesh.facesTop.value 
property facesUp

Return list of faces on top boundary of 2D or 3D Mesh 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
>>> ignore = mesh.facesTop.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((6, 7, 8),
...                        numerix.nonzero(mesh.facesTop)[0])) 
True
>>> ignore = mesh.facesTop.value 
getNearestCell(point)
property interiorFaceCellIDs
property interiorFaceIDs
property interiorFaces
property scale
property scaledCellDistances
property scaledCellToCellDistances
property scaledCellVolumes
property scaledFaceAreas
property scaledFaceToCellDistances
property x

Equivalent to using cellCenters[0].

>>> from fipy import *
>>> print(Grid1D(nx=2).x)
[ 0.5  1.5]
property 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.
property 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.
class fipy.meshes.gmshMesh.GmshGrid2D(dx=1.0, dy=1.0, nx=1, ny=None, coordDimensions=2, communicator=SerialPETScCommWrapper(), overlap=1)

Bases: Gmsh2D

Should serve as a drop-in replacement for Grid2D

property VTKCellDataSet

Returns a TVTK DataSet representing the cells of this mesh

property VTKFaceDataSet

Returns a TVTK DataSet representing the face centers of this mesh

__add__(other)

Either translate a Mesh or concatenate two Mesh objects.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

If a vector is added to a Mesh, a translated Mesh is returned

>>> translatedMesh = baseMesh + ((5,), (10,))
>>> print(translatedMesh.cellCenters)
[[  5.5   6.5   5.5   6.5]
 [ 10.5  10.5  11.5  11.5]]

If a Mesh is added to a Mesh, a concatenation of the two Mesh objects is returned

>>> addedMesh = baseMesh + (baseMesh + ((2,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

The two Mesh objects need not be properly aligned in order to concatenate them but the resulting mesh may not have the intended connectivity

>>> addedMesh = baseMesh + (baseMesh + ((3,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  3.5  4.5  3.5  4.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]
>>> addedMesh = baseMesh + (baseMesh + ((2,), (2,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  2.5  2.5  3.5  3.5]]

No provision is made to avoid or consolidate overlapping Mesh objects

>>> addedMesh = baseMesh + (baseMesh + ((1,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  1.5  2.5  1.5  2.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

Different Mesh classes can be concatenated

>>> from fipy.meshes import Tri2D
>>> triMesh = Tri2D(dx = 1.0, dy = 1.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[0.5, 1.5, 0.5, 1.5, 2.83333333,  3.83333333,
...                 2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [0.5, 0.5, 1.5, 1.5, 0.5, 0.5, 0.83333333, 0.83333333,
...                 0.5, 0.5, 0.16666667, 0.16666667]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

again, their faces need not align, but the mesh may not have the desired connectivity

>>> triMesh = Tri2D(dx = 1.0, dy = 2.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[ 0.5, 1.5, 0.5, 1.5, 2.83333333, 3.83333333,
...                  2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [ 0.5, 0.5, 1.5, 1.5, 1., 1.,
...                  1.66666667, 1.66666667, 1., 1., 0.33333333, 0.33333333]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

Mesh concatenation is not limited to 2D meshes

>>> from fipy.meshes import Grid3D
>>> threeDBaseMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                         nx = 2, ny = 2, nz = 2)
>>> threeDSecondMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                           nx = 1, ny = 1, nz = 1)
>>> threeDAddedMesh = threeDBaseMesh + (threeDSecondMesh + ((2,), (0,), (0,)))
>>> print(threeDAddedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  0.5  1.5  0.5  1.5  2.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  0.5  1.5  1.5  1.5  1.5  0.5]]

but the different Mesh objects must, of course, have the same dimensionality.

>>> InvalidMesh = threeDBaseMesh + baseMesh 
Traceback (most recent call last):
...
MeshAdditionError: Dimensions do not match
__div__(other)

Tests. >>> from fipy import * >>> print((Grid1D(nx=1) / 2.).cellCenters) [[ 0.25]] >>> AbstractMesh(communicator=None) / 2. Traceback (most recent call last): … NotImplementedError

__getstate__()

Helper for pickle.

__mul__(factor)

Dilate a Mesh by factor.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

The factor can be a scalar

>>> dilatedMesh = baseMesh * 3
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.5  1.5  4.5  4.5]]

or a vector

>>> dilatedMesh = baseMesh * ((3,), (2,))
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.   1.   3.   3. ]]

but the vector must have the same dimensionality as the Mesh

>>> dilatedMesh = baseMesh * ((3,), (2,), (1,)) 
Traceback (most recent call last):
...
ValueError: shape mismatch: objects cannot be broadcast to a single shape
__radd__(other)

Either translate a Mesh or concatenate two Mesh objects.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

If a vector is added to a Mesh, a translated Mesh is returned

>>> translatedMesh = baseMesh + ((5,), (10,))
>>> print(translatedMesh.cellCenters)
[[  5.5   6.5   5.5   6.5]
 [ 10.5  10.5  11.5  11.5]]

If a Mesh is added to a Mesh, a concatenation of the two Mesh objects is returned

>>> addedMesh = baseMesh + (baseMesh + ((2,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

The two Mesh objects need not be properly aligned in order to concatenate them but the resulting mesh may not have the intended connectivity

>>> addedMesh = baseMesh + (baseMesh + ((3,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  3.5  4.5  3.5  4.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]
>>> addedMesh = baseMesh + (baseMesh + ((2,), (2,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  2.5  2.5  3.5  3.5]]

No provision is made to avoid or consolidate overlapping Mesh objects

>>> addedMesh = baseMesh + (baseMesh + ((1,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  1.5  2.5  1.5  2.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

Different Mesh classes can be concatenated

>>> from fipy.meshes import Tri2D
>>> triMesh = Tri2D(dx = 1.0, dy = 1.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[0.5, 1.5, 0.5, 1.5, 2.83333333,  3.83333333,
...                 2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [0.5, 0.5, 1.5, 1.5, 0.5, 0.5, 0.83333333, 0.83333333,
...                 0.5, 0.5, 0.16666667, 0.16666667]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

again, their faces need not align, but the mesh may not have the desired connectivity

>>> triMesh = Tri2D(dx = 1.0, dy = 2.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[ 0.5, 1.5, 0.5, 1.5, 2.83333333, 3.83333333,
...                  2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [ 0.5, 0.5, 1.5, 1.5, 1., 1.,
...                  1.66666667, 1.66666667, 1., 1., 0.33333333, 0.33333333]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

Mesh concatenation is not limited to 2D meshes

>>> from fipy.meshes import Grid3D
>>> threeDBaseMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                         nx = 2, ny = 2, nz = 2)
>>> threeDSecondMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                           nx = 1, ny = 1, nz = 1)
>>> threeDAddedMesh = threeDBaseMesh + (threeDSecondMesh + ((2,), (0,), (0,)))
>>> print(threeDAddedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  0.5  1.5  0.5  1.5  2.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  0.5  1.5  1.5  1.5  1.5  0.5]]

but the different Mesh objects must, of course, have the same dimensionality.

>>> InvalidMesh = threeDBaseMesh + baseMesh 
Traceback (most recent call last):
...
MeshAdditionError: Dimensions do not match
__repr__()

Return repr(self).

__rmul__(factor)

Dilate a Mesh by factor.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

The factor can be a scalar

>>> dilatedMesh = baseMesh * 3
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.5  1.5  4.5  4.5]]

or a vector

>>> dilatedMesh = baseMesh * ((3,), (2,))
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.   1.   3.   3. ]]

but the vector must have the same dimensionality as the Mesh

>>> dilatedMesh = baseMesh * ((3,), (2,), (1,)) 
Traceback (most recent call last):
...
ValueError: shape mismatch: objects cannot be broadcast to a single shape
__setstate__(state)
__sub__(other)

Tests. >>> from fipy import * >>> m = Grid1D() >>> print((m - ((1,))).cellCenters) [[-0.5]] >>> ((1,)) - m Traceback (most recent call last): … TypeError: unsupported operand type(s) for -: ‘tuple’ and ‘UniformGrid1D’

__truediv__(other)

Tests. >>> from fipy import * >>> print((Grid1D(nx=1) / 2.).cellCenters) [[ 0.25]] >>> AbstractMesh(communicator=None) / 2. Traceback (most recent call last): … NotImplementedError

property aspect2D

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

property cellCenters
property cellDistanceVectors
property cellFaceIDs
property cellToFaceDistanceVectors
property cellVolumes
property extents
property exteriorFaces
extrude(extrudeFunc=<function Mesh2D.<lambda>>, layers=1)

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

>>> 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.allclose([[ 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       ]]))
True
Parameters:
  • extrudeFunc (function) – Takes the vertex coordinates and returns the displaced values

  • layers (int) – Number of layers in the extruded mesh (number of times extrudeFunc will be called)

property faceCenters
property facesBack

Return list of faces on back boundary of 3D Mesh 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
>>> ignore = mesh.facesBack.value 
property facesBottom

Return list of faces on bottom boundary of 2D or 3D Mesh 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])) 
True
>>> ignore = mesh.facesBottom.value 
>>> x, y, z = mesh.faceCenters
>>> print(numerix.allequal((12, 13),
...                        numerix.nonzero(mesh.facesBottom & (x < 1))[0])) 
True
>>> ignore = mesh.facesBottom.value 
property facesDown

Return list of faces on bottom boundary of 2D or 3D Mesh 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])) 
True
>>> ignore = mesh.facesBottom.value 
>>> x, y, z = mesh.faceCenters
>>> print(numerix.allequal((12, 13),
...                        numerix.nonzero(mesh.facesBottom & (x < 1))[0])) 
True
>>> ignore = mesh.facesBottom.value 
property facesFront

Return list of faces on front boundary of 3D Mesh 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
>>> ignore = mesh.facesFront.value 
property facesLeft

Return face on left boundary of Mesh 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
>>> ignore = mesh.facesLeft.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((9, 13),
...                        numerix.nonzero(mesh.facesLeft)[0])) 
True
>>> ignore = mesh.facesLeft.value 
property facesRight

Return list of faces on right boundary of Mesh 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
>>> ignore = mesh.facesRight.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((12, 16),
...                        numerix.nonzero(mesh.facesRight)[0])) 
True
>>> ignore = mesh.facesRight.value 
property facesTop

Return list of faces on top boundary of 2D or 3D Mesh 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
>>> ignore = mesh.facesTop.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((6, 7, 8),
...                        numerix.nonzero(mesh.facesTop)[0])) 
True
>>> ignore = mesh.facesTop.value 
property facesUp

Return list of faces on top boundary of 2D or 3D Mesh 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
>>> ignore = mesh.facesTop.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((6, 7, 8),
...                        numerix.nonzero(mesh.facesTop)[0])) 
True
>>> ignore = mesh.facesTop.value 
getNearestCell(point)
property interiorFaceCellIDs
property interiorFaceIDs
property interiorFaces
property scale
property scaledCellDistances
property scaledCellToCellDistances
property scaledCellVolumes
property scaledFaceAreas
property scaledFaceToCellDistances
property x

Equivalent to using cellCenters[0].

>>> from fipy import *
>>> print(Grid1D(nx=2).x)
[ 0.5  1.5]
property 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.
property 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.
class fipy.meshes.gmshMesh.GmshGrid3D(dx=1.0, dy=1.0, dz=1.0, nx=1, ny=None, nz=None, communicator=SerialPETScCommWrapper(), overlap=1)

Bases: Gmsh3D

Should serve as a drop-in replacement for Grid3D

property VTKCellDataSet

Returns a TVTK DataSet representing the cells of this mesh

property VTKFaceDataSet

Returns a TVTK DataSet representing the face centers of this mesh

__add__(other)

Either translate a Mesh or concatenate two Mesh objects.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

If a vector is added to a Mesh, a translated Mesh is returned

>>> translatedMesh = baseMesh + ((5,), (10,))
>>> print(translatedMesh.cellCenters)
[[  5.5   6.5   5.5   6.5]
 [ 10.5  10.5  11.5  11.5]]

If a Mesh is added to a Mesh, a concatenation of the two Mesh objects is returned

>>> addedMesh = baseMesh + (baseMesh + ((2,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

The two Mesh objects need not be properly aligned in order to concatenate them but the resulting mesh may not have the intended connectivity

>>> addedMesh = baseMesh + (baseMesh + ((3,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  3.5  4.5  3.5  4.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]
>>> addedMesh = baseMesh + (baseMesh + ((2,), (2,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  2.5  2.5  3.5  3.5]]

No provision is made to avoid or consolidate overlapping Mesh objects

>>> addedMesh = baseMesh + (baseMesh + ((1,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  1.5  2.5  1.5  2.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

Different Mesh classes can be concatenated

>>> from fipy.meshes import Tri2D
>>> triMesh = Tri2D(dx = 1.0, dy = 1.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[0.5, 1.5, 0.5, 1.5, 2.83333333,  3.83333333,
...                 2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [0.5, 0.5, 1.5, 1.5, 0.5, 0.5, 0.83333333, 0.83333333,
...                 0.5, 0.5, 0.16666667, 0.16666667]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

again, their faces need not align, but the mesh may not have the desired connectivity

>>> triMesh = Tri2D(dx = 1.0, dy = 2.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[ 0.5, 1.5, 0.5, 1.5, 2.83333333, 3.83333333,
...                  2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [ 0.5, 0.5, 1.5, 1.5, 1., 1.,
...                  1.66666667, 1.66666667, 1., 1., 0.33333333, 0.33333333]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

Mesh concatenation is not limited to 2D meshes

>>> from fipy.meshes import Grid3D
>>> threeDBaseMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                         nx = 2, ny = 2, nz = 2)
>>> threeDSecondMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                           nx = 1, ny = 1, nz = 1)
>>> threeDAddedMesh = threeDBaseMesh + (threeDSecondMesh + ((2,), (0,), (0,)))
>>> print(threeDAddedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  0.5  1.5  0.5  1.5  2.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  0.5  1.5  1.5  1.5  1.5  0.5]]

but the different Mesh objects must, of course, have the same dimensionality.

>>> InvalidMesh = threeDBaseMesh + baseMesh 
Traceback (most recent call last):
...
MeshAdditionError: Dimensions do not match
__div__(other)

Tests. >>> from fipy import * >>> print((Grid1D(nx=1) / 2.).cellCenters) [[ 0.25]] >>> AbstractMesh(communicator=None) / 2. Traceback (most recent call last): … NotImplementedError

__getstate__()

Helper for pickle.

__mul__(factor)

Dilate a Mesh by factor.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

The factor can be a scalar

>>> dilatedMesh = baseMesh * 3
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.5  1.5  4.5  4.5]]

or a vector

>>> dilatedMesh = baseMesh * ((3,), (2,))
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.   1.   3.   3. ]]

but the vector must have the same dimensionality as the Mesh

>>> dilatedMesh = baseMesh * ((3,), (2,), (1,)) 
Traceback (most recent call last):
...
ValueError: shape mismatch: objects cannot be broadcast to a single shape
__radd__(other)

Either translate a Mesh or concatenate two Mesh objects.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

If a vector is added to a Mesh, a translated Mesh is returned

>>> translatedMesh = baseMesh + ((5,), (10,))
>>> print(translatedMesh.cellCenters)
[[  5.5   6.5   5.5   6.5]
 [ 10.5  10.5  11.5  11.5]]

If a Mesh is added to a Mesh, a concatenation of the two Mesh objects is returned

>>> addedMesh = baseMesh + (baseMesh + ((2,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

The two Mesh objects need not be properly aligned in order to concatenate them but the resulting mesh may not have the intended connectivity

>>> addedMesh = baseMesh + (baseMesh + ((3,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  3.5  4.5  3.5  4.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]
>>> addedMesh = baseMesh + (baseMesh + ((2,), (2,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  2.5  2.5  3.5  3.5]]

No provision is made to avoid or consolidate overlapping Mesh objects

>>> addedMesh = baseMesh + (baseMesh + ((1,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  1.5  2.5  1.5  2.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

Different Mesh classes can be concatenated

>>> from fipy.meshes import Tri2D
>>> triMesh = Tri2D(dx = 1.0, dy = 1.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[0.5, 1.5, 0.5, 1.5, 2.83333333,  3.83333333,
...                 2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [0.5, 0.5, 1.5, 1.5, 0.5, 0.5, 0.83333333, 0.83333333,
...                 0.5, 0.5, 0.16666667, 0.16666667]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

again, their faces need not align, but the mesh may not have the desired connectivity

>>> triMesh = Tri2D(dx = 1.0, dy = 2.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[ 0.5, 1.5, 0.5, 1.5, 2.83333333, 3.83333333,
...                  2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [ 0.5, 0.5, 1.5, 1.5, 1., 1.,
...                  1.66666667, 1.66666667, 1., 1., 0.33333333, 0.33333333]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

Mesh concatenation is not limited to 2D meshes

>>> from fipy.meshes import Grid3D
>>> threeDBaseMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                         nx = 2, ny = 2, nz = 2)
>>> threeDSecondMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                           nx = 1, ny = 1, nz = 1)
>>> threeDAddedMesh = threeDBaseMesh + (threeDSecondMesh + ((2,), (0,), (0,)))
>>> print(threeDAddedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  0.5  1.5  0.5  1.5  2.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  0.5  1.5  1.5  1.5  1.5  0.5]]

but the different Mesh objects must, of course, have the same dimensionality.

>>> InvalidMesh = threeDBaseMesh + baseMesh 
Traceback (most recent call last):
...
MeshAdditionError: Dimensions do not match
__repr__()

Return repr(self).

__rmul__(factor)

Dilate a Mesh by factor.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

The factor can be a scalar

>>> dilatedMesh = baseMesh * 3
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.5  1.5  4.5  4.5]]

or a vector

>>> dilatedMesh = baseMesh * ((3,), (2,))
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.   1.   3.   3. ]]

but the vector must have the same dimensionality as the Mesh

>>> dilatedMesh = baseMesh * ((3,), (2,), (1,)) 
Traceback (most recent call last):
...
ValueError: shape mismatch: objects cannot be broadcast to a single shape
__setstate__(state)
__sub__(other)

Tests. >>> from fipy import * >>> m = Grid1D() >>> print((m - ((1,))).cellCenters) [[-0.5]] >>> ((1,)) - m Traceback (most recent call last): … TypeError: unsupported operand type(s) for -: ‘tuple’ and ‘UniformGrid1D’

__truediv__(other)

Tests. >>> from fipy import * >>> print((Grid1D(nx=1) / 2.).cellCenters) [[ 0.25]] >>> AbstractMesh(communicator=None) / 2. Traceback (most recent call last): … NotImplementedError

property aspect2D

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

property cellCenters
property cellDistanceVectors
property cellFaceIDs
property cellToFaceDistanceVectors
property cellVolumes
property extents
property exteriorFaces
property faceCenters
property facesBack

Return list of faces on back boundary of 3D Mesh 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
>>> ignore = mesh.facesBack.value 
property facesBottom

Return list of faces on bottom boundary of 2D or 3D Mesh 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])) 
True
>>> ignore = mesh.facesBottom.value 
>>> x, y, z = mesh.faceCenters
>>> print(numerix.allequal((12, 13),
...                        numerix.nonzero(mesh.facesBottom & (x < 1))[0])) 
True
>>> ignore = mesh.facesBottom.value 
property facesDown

Return list of faces on bottom boundary of 2D or 3D Mesh 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])) 
True
>>> ignore = mesh.facesBottom.value 
>>> x, y, z = mesh.faceCenters
>>> print(numerix.allequal((12, 13),
...                        numerix.nonzero(mesh.facesBottom & (x < 1))[0])) 
True
>>> ignore = mesh.facesBottom.value 
property facesFront

Return list of faces on front boundary of 3D Mesh 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
>>> ignore = mesh.facesFront.value 
property facesLeft

Return face on left boundary of Mesh 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
>>> ignore = mesh.facesLeft.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((9, 13),
...                        numerix.nonzero(mesh.facesLeft)[0])) 
True
>>> ignore = mesh.facesLeft.value 
property facesRight

Return list of faces on right boundary of Mesh 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
>>> ignore = mesh.facesRight.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((12, 16),
...                        numerix.nonzero(mesh.facesRight)[0])) 
True
>>> ignore = mesh.facesRight.value 
property facesTop

Return list of faces on top boundary of 2D or 3D Mesh 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
>>> ignore = mesh.facesTop.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((6, 7, 8),
...                        numerix.nonzero(mesh.facesTop)[0])) 
True
>>> ignore = mesh.facesTop.value 
property facesUp

Return list of faces on top boundary of 2D or 3D Mesh 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
>>> ignore = mesh.facesTop.value 
>>> mesh = Grid2D(nx = 3, ny = 2, dx = 0.5, dy = 2.)
>>> print(numerix.allequal((6, 7, 8),
...                        numerix.nonzero(mesh.facesTop)[0])) 
True
>>> ignore = mesh.facesTop.value 
getNearestCell(point)
property interiorFaceCellIDs
property interiorFaceIDs
property interiorFaces
property scale
property scaledCellDistances
property scaledCellToCellDistances
property scaledCellVolumes
property scaledFaceAreas
property scaledFaceToCellDistances
property x

Equivalent to using cellCenters[0].

>>> from fipy import *
>>> print(Grid1D(nx=2).x)
[ 0.5  1.5]
property 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.
property 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.
fipy.meshes.gmshMesh.openMSHFile(name, dimensions=None, coordDimensions=None, communicator=SerialPETScCommWrapper(), overlap=1, mode='r', background=None)

Open a Gmsh MSH file

Parameters:
  • filename (str) – Gmsh output file

  • dimensions (int) – Dimension of mesh

  • coordDimensions (int) – Dimension of shapes

  • overlap (int) – The number of overlapping cells for parallel simulations. Generally 1 is adequate. Higher order equations or discretizations require more. If overlap is greater than one, communication reverts to serial, as Gmsh only provides one layer of ghost cells.

  • mode (str) – 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 (CellVariable) – Specifies the desired characteristic lengths of the mesh cells

fipy.meshes.gmshMesh.openPOSFile(name, communicator=SerialPETScCommWrapper(), mode='w')

Open a Gmsh POS post-processing file

fipy.meshes.grid1D module

fipy.meshes.grid2D module

fipy.meshes.grid3D module

fipy.meshes.mesh module

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

Bases: 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.

property VTKCellDataSet

Returns a TVTK DataSet representing the cells of this mesh

property VTKFaceDataSet

Returns a TVTK DataSet representing the face centers of this mesh

__add__(other)

Either translate a Mesh or concatenate two Mesh objects.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

If a vector is added to a Mesh, a translated Mesh is returned

>>> translatedMesh = baseMesh + ((5,), (10,))
>>> print(translatedMesh.cellCenters)
[[  5.5   6.5   5.5   6.5]
 [ 10.5  10.5  11.5  11.5]]

If a Mesh is added to a Mesh, a concatenation of the two Mesh objects is returned

>>> addedMesh = baseMesh + (baseMesh + ((2,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

The two Mesh objects need not be properly aligned in order to concatenate them but the resulting mesh may not have the intended connectivity

>>> addedMesh = baseMesh + (baseMesh + ((3,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  3.5  4.5  3.5  4.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]
>>> addedMesh = baseMesh + (baseMesh + ((2,), (2,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  2.5  2.5  3.5  3.5]]

No provision is made to avoid or consolidate overlapping Mesh objects

>>> addedMesh = baseMesh + (baseMesh + ((1,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  1.5  2.5  1.5  2.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

Different Mesh classes can be concatenated

>>> from fipy.meshes import Tri2D
>>> triMesh = Tri2D(dx = 1.0, dy = 1.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[0.5, 1.5, 0.5, 1.5, 2.83333333,  3.83333333,
...                 2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [0.5, 0.5, 1.5, 1.5, 0.5, 0.5, 0.83333333, 0.83333333,
...                 0.5, 0.5, 0.16666667, 0.16666667]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

again, their faces need not align, but the mesh may not have the desired connectivity

>>> triMesh = Tri2D(dx = 1.0, dy = 2.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[ 0.5, 1.5, 0.5, 1.5, 2.83333333, 3.83333333,
...                  2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [ 0.5, 0.5, 1.5, 1.5, 1., 1.,
...                  1.66666667, 1.66666667, 1., 1., 0.33333333, 0.33333333]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

Mesh concatenation is not limited to 2D meshes

>>> from fipy.meshes import Grid3D
>>> threeDBaseMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                         nx = 2, ny = 2, nz = 2)
>>> threeDSecondMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                           nx = 1, ny = 1, nz = 1)
>>> threeDAddedMesh = threeDBaseMesh + (threeDSecondMesh + ((2,), (0,), (0,)))
>>> print(threeDAddedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  0.5  1.5  0.5  1.5  2.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  0.5  1.5  1.5  1.5  1.5  0.5]]

but the different Mesh objects must, of course, have the same dimensionality.

>>> InvalidMesh = threeDBaseMesh + baseMesh 
Traceback (most recent call last):
...
MeshAdditionError: Dimensions do not match
__div__(other)

Tests. >>> from fipy import * >>> print((Grid1D(nx=1) / 2.).cellCenters) [[ 0.25]] >>> AbstractMesh(communicator=None) / 2. Traceback (most recent call last): … NotImplementedError

__getstate__()

Helper for pickle.

__mul__(factor)

Dilate a Mesh by factor.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

The factor can be a scalar

>>> dilatedMesh = baseMesh * 3
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.5  1.5  4.5  4.5]]

or a vector

>>> dilatedMesh = baseMesh * ((3,), (2,))
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.   1.   3.   3. ]]

but the vector must have the same dimensionality as the Mesh

>>> dilatedMesh = baseMesh * ((3,), (2,), (1,)) 
Traceback (most recent call last):
...
ValueError: shape mismatch: objects cannot be broadcast to a single shape
__radd__(other)

Either translate a Mesh or concatenate two Mesh objects.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

If a vector is added to a Mesh, a translated Mesh is returned

>>> translatedMesh = baseMesh + ((5,), (10,))
>>> print(translatedMesh.cellCenters)
[[  5.5   6.5   5.5   6.5]
 [ 10.5  10.5  11.5  11.5]]

If a Mesh is added to a Mesh, a concatenation of the two Mesh objects is returned

>>> addedMesh = baseMesh + (baseMesh + ((2,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

The two Mesh objects need not be properly aligned in order to concatenate them but the resulting mesh may not have the intended connectivity

>>> addedMesh = baseMesh + (baseMesh + ((3,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  3.5  4.5  3.5  4.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]
>>> addedMesh = baseMesh + (baseMesh + ((2,), (2,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  2.5  3.5  2.5  3.5]
 [ 0.5  0.5  1.5  1.5  2.5  2.5  3.5  3.5]]

No provision is made to avoid or consolidate overlapping Mesh objects

>>> addedMesh = baseMesh + (baseMesh + ((1,), (0,)))
>>> print(addedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  1.5  2.5  1.5  2.5]
 [ 0.5  0.5  1.5  1.5  0.5  0.5  1.5  1.5]]

Different Mesh classes can be concatenated

>>> from fipy.meshes import Tri2D
>>> triMesh = Tri2D(dx = 1.0, dy = 1.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[0.5, 1.5, 0.5, 1.5, 2.83333333,  3.83333333,
...                 2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [0.5, 0.5, 1.5, 1.5, 0.5, 0.5, 0.83333333, 0.83333333,
...                 0.5, 0.5, 0.16666667, 0.16666667]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

again, their faces need not align, but the mesh may not have the desired connectivity

>>> triMesh = Tri2D(dx = 1.0, dy = 2.0, nx = 2, ny = 1)
>>> triMesh = triMesh + ((2,), (0,))
>>> triAddedMesh = baseMesh + triMesh
>>> cellCenters = [[ 0.5, 1.5, 0.5, 1.5, 2.83333333, 3.83333333,
...                  2.5, 3.5, 2.16666667, 3.16666667, 2.5, 3.5],
...                [ 0.5, 0.5, 1.5, 1.5, 1., 1.,
...                  1.66666667, 1.66666667, 1., 1., 0.33333333, 0.33333333]]
>>> print(numerix.allclose(triAddedMesh.cellCenters,
...                        cellCenters))
True

Mesh concatenation is not limited to 2D meshes

>>> from fipy.meshes import Grid3D
>>> threeDBaseMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                         nx = 2, ny = 2, nz = 2)
>>> threeDSecondMesh = Grid3D(dx = 1.0, dy = 1.0, dz = 1.0,
...                           nx = 1, ny = 1, nz = 1)
>>> threeDAddedMesh = threeDBaseMesh + (threeDSecondMesh + ((2,), (0,), (0,)))
>>> print(threeDAddedMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5  0.5  1.5  0.5  1.5  2.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  0.5  1.5  1.5  1.5  1.5  0.5]]

but the different Mesh objects must, of course, have the same dimensionality.

>>> InvalidMesh = threeDBaseMesh + baseMesh 
Traceback (most recent call last):
...
MeshAdditionError: Dimensions do not match
__repr__()

Return repr(self).

__rmul__(factor)

Dilate a Mesh by factor.

>>> from fipy.meshes import Grid2D
>>> baseMesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
>>> print(baseMesh.cellCenters)
[[ 0.5  1.5  0.5  1.5]
 [ 0.5  0.5  1.5  1.5]]

The factor can be a scalar

>>> dilatedMesh = baseMesh * 3
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.5  1.5  4.5  4.5]]

or a vector

>>> dilatedMesh = baseMesh * ((3,), (2,))
>>> print(dilatedMesh.cellCenters)
[[ 1.5  4.5  1.5  4.5]
 [ 1.   1.   3.   3. ]]

but the vector must have the same dimensionality as the Mesh

>>> dilatedMesh = baseMesh * ((3,), (2,), (1,)) 
Traceback (most recent call last):
...
ValueError: shape mismatch: objects cannot be broadcast to a single shape
__setstate__(state)
__sub__(other)

Tests. >>> from fipy import * >>> m = Grid1D() >>> print((m - ((1,))).cellCenters) [[-0.5]] >>> ((1,)) - m Traceback (most recent call last): … TypeError: unsupported operand type(s) for -: ‘tuple’ and ‘UniformGrid1D’

__truediv__(other)

Tests. >>> from fipy import * >>> print((Grid1D(nx=1) / 2.).cellCenters) [[ 0.25]] >>> AbstractMesh(communicator=None) / 2. Traceback (most recent call last): … NotImplementedError

property aspect2D

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

property cellCenters
property cellDistanceVectors
property cellFaceIDs
property cellToFaceDistanceVectors
property cellVolumes
property extents
property exteriorFaces
property faceCenters
property facesBack

Return list of faces on back boundary of 3D Mesh 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
>>> ignore = mesh.facesBack.value 
property facesBottom

Return list of faces on bottom boundary of 2D or 3D Mesh 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])) 
True
>>> ignore = mesh.facesBottom.value 
>>> x, y, z = mesh.faceCenters
>>> print(numerix.allequal((12, 13),
...                        numerix.nonzero(mesh.facesBottom & (x < 1))[0])) 
True
>>> ignore = mesh.facesBottom.value 
property facesDown

Return list of faces on bottom boundary of 2D or 3D Mesh with the y-axis running from bottom to top.

>>> from fipy import