fipy.meshes.gmshMesh¶
Functions
|
Determine the version of Gmsh. |
|
Open a Gmsh MSH file |
|
Open a Gmsh POS post-processing file |
Classes
|
Construct a 2D Mesh using Gmsh |
|
Create a topologically 2D Mesh in 3D coordinates using Gmsh |
|
Create a 3D Mesh using Gmsh |
|
Base class for Gmsh mesh storage files. |
|
Should serve as a drop-in replacement for Grid2D |
|
Should serve as a drop-in replacement for Grid3D |
|
Wrapper for Gmsh MSH storage files. |
|
Wrapper for Gmsh POS mesh storage files. |
Exceptions
|
|
|
- class fipy.meshes.gmshMesh.Gmsh2D(arg, coordDimensions=2, communicator=DummyComm(), 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
- __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¶
- 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 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.
- class fipy.meshes.gmshMesh.Gmsh2DIn3DSpace(arg, communicator=DummyComm(), 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
- __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¶
- 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 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.
- class fipy.meshes.gmshMesh.Gmsh3D(arg, communicator=DummyComm(), 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
- __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.gmshMesh.GmshException¶
Bases:
Exception
Exception
raised for Gmsh error conditions.- __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.
- class fipy.meshes.gmshMesh.GmshFile(filename, communicator, mode, fileIsTemporary=False)¶
Bases:
object
Base class for Gmsh mesh storage files.
- class fipy.meshes.gmshMesh.GmshGrid2D(dx=1.0, dy=1.0, nx=1, ny=None, coordDimensions=2, communicator=DummyComm(), 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
- __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¶
- 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 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.
- class fipy.meshes.gmshMesh.GmshGrid3D(dx=1.0, dy=1.0, dz=1.0, nx=1, ny=None, nz=None, communicator=DummyComm(), 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
- __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.
- class fipy.meshes.gmshMesh.MSHFile(filename, dimensions, coordDimensions=None, communicator=DummyComm(), gmshOutput='', mode='r', fileIsTemporary=False)¶
Bases:
GmshFile
Wrapper for Gmsh MSH storage files.
Class responsible for parsing a Gmsh file and then readying its contents for use by a Mesh constructor.
Can handle a partitioned mesh based on parallelComm.Nproc. If partitioning, the .msh file must either be previously partitioned with the number of partitions matching Nproc, or the mesh must be specified with a .geo file or multiline string.
Does not support gmsh versions < 2. If partitioning, gmsh version must be >= 2.5.
TODO: Refactor face extraction functions.
- Parameters:
filename (str) – Gmsh output file
dimensions (int) – Dimension of mesh
coordDimensions (int) – Dimension of shapes
communicator (CommWrapper) – Generally, fipy.tools.serialComm or fipy.tools.parallelComm. Select ~fipy.tools.serialComm to create a serial mesh when running in parallel; mostly used for test purposes.
gmshOutput (str) – Output (if any) from Gmsh run that created .msh file
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.
fileIsTemporary (bool) – If True, filename should be cleaned up on deletion
- makeMapVariables(mesh)¶
Utility function to make MeshVariables that define different domains in the mesh
- read()¶
Build cellsToVertices
Recover needed vertexCoords and mapping from file using cellsToVertices
Build cellsToVertIDs proper from vertexCoords and vertex map
Build faces
Build cellsToFaces
Isolate relevant data into three files, store in self.nodesPath for $Nodes, self.elemsPath for $Elements. self.namesFile for $PhysicalNames.
- Returns vertexCoords, facesToVertexID, cellsToFaceID,
cellGlobalIDMap, ghostCellGlobalIDMap.
- exception fipy.meshes.gmshMesh.MeshExportError¶
Bases:
GmshException
Exception
raised when FiPy mesh cannot be exported to Gmsh.- __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.
- class fipy.meshes.gmshMesh.POSFile(filename, communicator, mode, fileIsTemporary=False)¶
Bases:
GmshFile
Wrapper for Gmsh POS mesh storage files.
- fipy.meshes.gmshMesh.gmshVersion(communicator=DummyComm())¶
Determine the version of Gmsh.
We can’t trust the generated .msh file for the correct version number, so we have to retrieve it from the gmsh binary.
- fipy.meshes.gmshMesh.openMSHFile(name, dimensions=None, coordDimensions=None, communicator=DummyComm(), 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=DummyComm(), mode='w')¶
Open a Gmsh POS post-processing file