def _translate(self, vector): """ Test for ticket:298. >>> from fipy import * >>> m = PeriodicGrid3DLeftRight(nx=2, ny=2, nz=1) + [[-1], [0], [0]] >>> orderedCellVertexIDs = [[13, 14, 16, 17], ... [12, 13, 15, 16], ... [10, 11, 13, 14], ... [9, 10, 12, 13], ... [4, 5, 7, 8], ... [3, 4, 6, 7], ... [1, 2, 4, 5], ... [0, 1, 3, 4]] >>> print(numerix.allclose(m._orderedCellVertexIDs, orderedCellVertexIDs)) # doctest: +PROCESSOR_0 True >>> print(CellVariable(mesh=m, value=m.cellCenters[0])) [-0.5 0.5 -0.5 0.5] """ newCoords = self.vertexCoords + vector newmesh = self.__class__(**self.args) from fipy.meshes.mesh import Mesh Mesh.__init__(newmesh, newCoords, self.faceVertexIDs, self._nonPeriodicCellFaceIDs, communicator=self.communicator) newmesh._makePeriodic() return newmesh
def __init__(self, dx = 1., dy = 1., dz = 1., nx = None, ny = None, nz = None, overlap=2, communicator=parallelComm, _RepresentationClass=_Grid3DRepresentation, _TopologyClass=_Grid3DTopology): builder = _NonuniformGrid3DBuilder() self.args = { 'dx': dx, 'dy': dy, 'dz' :dz, 'nx': nx, 'ny': ny, 'nz': nz, 'overlap': overlap, 'communicator': communicator } builder.buildGridData([dx, dy, dz], [nx, ny, nz], overlap, communicator) ([self.dx, self.dy, self.dz], [self.nx, self.ny, self.nz], self.dim, scale, self.globalNumberOfCells, self.globalNumberOfFaces, self.overlap, self.offset, self.numberOfVertices, self.numberOfFaces, self.numberOfCells, self.shape, self.physicalShape, self._meshSpacing, self.numberOfXYFaces, self.numberOfXZFaces, self.numberOfYZFaces, self.numberOfHorizontalRows, self.numberOfVerticalColumns, self.numberOfLayersDeep, vertices, faces, cells, self.Xoffset, self.Yoffset, self.Zoffset) = builder.gridData Mesh.__init__(self, vertices, faces, cells, communicator=communicator, _RepresentationClass=_RepresentationClass, _TopologyClass=_TopologyClass) self._setScale(scaleLength = scale)
def __init__(self, dx = 1., dy = 1., dz = 1., nx = None, ny = None, nz = None, overlap=2, communicator=parallelComm, _RepresentationClass=_Grid3DRepresentation, _TopologyClass=_Grid3DTopology): builder = _NonuniformGrid3DBuilder() self.args = { 'dx': dx, 'dy': dy, 'dz': dz, 'nx': nx, 'ny': ny, 'nz': nz, 'overlap': overlap, } builder.buildGridData([dx, dy, dz], [nx, ny, nz], overlap, communicator) ([self.dx, self.dy, self.dz], [self.nx, self.ny, self.nz], self.dim, scale, self.globalNumberOfCells, self.globalNumberOfFaces, self.overlap, self.offset, self.numberOfVertices, self.numberOfFaces, self.numberOfCells, self.shape, self.physicalShape, self._meshSpacing, self.numberOfXYFaces, self.numberOfXZFaces, self.numberOfYZFaces, self.numberOfHorizontalRows, self.numberOfVerticalColumns, self.numberOfLayersDeep, vertices, faces, cells, self.Xoffset, self.Yoffset, self.Zoffset) = builder.gridData Mesh.__init__(self, vertices, faces, cells, communicator=communicator, _RepresentationClass=_RepresentationClass, _TopologyClass=_TopologyClass) self._setScale(scaleLength = scale)
def setstate(mesh, state): """Populate a new `Mesh` from ``pickled`` persistent storage. """ from fipy.meshes.mesh import Mesh Mesh.__init__(mesh, **state)
def _extrude(self, mesh, extrudeFunc, layers): ## should extrude self rather than creating a new mesh? ## the following allows the 2D mesh to be in 3D space, this can be the case for a ## Gmsh2DIn3DSpace which would then be extruded. oldVertices = mesh.vertexCoords if oldVertices.shape[0] == 2: oldVertices = numerix.resize(oldVertices, (3, len(oldVertices[0]))) oldVertices[2] = 0 NCells = mesh.numberOfCells NFac = mesh.numberOfFaces NFacPerCell = mesh._maxFacesPerCell ## set up the initial data arrays new_shape = (max(NFacPerCell, 4), (1 + layers)*NCells + layers*NFac) faces = numerix.MA.masked_values(-numerix.ones(new_shape, 'l'), value = -1) orderedVertices = mesh._orderedCellVertexIDs faces[:NFacPerCell, :NCells] = orderedVertices vertices = oldVertices vert0 = mesh.faceVertexIDs faceCount = NCells for layer in range(layers): ## need this later initialFaceCount = faceCount ## build the vertices newVertices = extrudeFunc(oldVertices) vertices = numerix.concatenate((vertices, newVertices), axis=1) ## build the faces along the layers faces[:NFacPerCell, faceCount: faceCount + NCells] = orderedVertices + len(oldVertices[0]) * (layer + 1) try: # numpy 1.1 doesn't copy right side before assigning slice # See: http://www.mail-archive.com/[email protected]/msg09843.html faces[:NFacPerCell, faceCount: faceCount + NCells] = faces[:NFacPerCell, faceCount: faceCount + NCells][::-1,:].copy() except: faces[:NFacPerCell, faceCount: faceCount + NCells] = faces[:NFacPerCell, faceCount: faceCount + NCells][::-1,:] faceCount = faceCount + NCells vert1 = (vert0 + len(oldVertices[0]))[::-1,:] ## build the faces between the layers faces[:4, faceCount: faceCount + NFac] = numerix.concatenate((vert0, vert1), axis = 0)[::-1,:] vert0 = vert0 + len(oldVertices[0]) NCells = mesh.numberOfCells ## build the cells, the first layer has slightly different ordering if layer == 0: c0 = numerix.reshape(numerix.arange(NCells), (1, NCells)) cells = numerix.concatenate((c0, c0 + NCells, mesh.cellFaceIDs + 2 * NCells), axis = 0) else: newCells = numerix.concatenate((c0, c0 + initialFaceCount, mesh.cellFaceIDs + faceCount), axis=0) newCells[0] = cells[1, -NCells:] cells = numerix.concatenate((cells, newCells), axis=1) ## keep a count of things for the next layer faceCount = faceCount + NFac oldVertices = newVertices ## return a new mesh, extrude could just as easily act on self return Mesh(vertices, faces, cells, communicator=mesh.communicator)