fipy.meshes.mesh¶
Classes
|
Generic mesh class using numerix to do the calculations |
Exceptions
- class fipy.meshes.mesh.Mesh(vertexCoords, faceVertexIDs, cellFaceIDs, communicator=DummyComm(), _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
- __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¶
Coordinates of geometric centers of cells
- property cellFaceIDs¶
- 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
- 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.
- exception fipy.meshes.mesh.MeshAdditionError¶
Bases:
Exception
- __cause__¶
exception cause
- __context__¶
exception context
- __delattr__(name, /)¶
Implement delattr(self, name).
- __getattribute__(name, /)¶
Return getattr(self, name).
- __reduce__()¶
Helper for pickle.
- __repr__()¶
Return repr(self).
- __setattr__(name, value, /)¶
Implement setattr(self, name, value).
- __str__()¶
Return str(self).
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.