def __init__(self, dx = 1., dy = 1., nx = 1, ny = 1, _RepresentationClass=_Grid2DRepresentation, _TopologyClass=_Mesh2DTopology): """ Creates a 2D triangular mesh with horizontal faces numbered first then vertical faces, then diagonal faces. Vertices are numbered starting with the vertices at the corners of boxes and then the vertices at the centers of boxes. Cells on the right of boxes are numbered first, then cells on the top of boxes, then cells on the left of boxes, then cells on the bottom of boxes. Within each of the 'sub-categories' in the above, the vertices, cells and faces are numbered in the usual way. :Parameters: - `dx, dy`: The X and Y dimensions of each 'box'. If `dx` <> `dy`, the line segments connecting the cell centers will not be orthogonal to the faces. - `nx, ny`: The number of boxes in the X direction and the Y direction. The total number of boxes will be equal to `nx * ny`, and the total number of cells will be equal to `4 * nx * ny`. """ self.args = { 'dx': dx, 'dy': dy, 'nx': nx, 'ny': ny } self.nx = nx self.ny = ny self.numberOfHorizontalFaces = self.nx * (self.ny + 1) self.numberOfVerticalFaces = self.ny * (self.nx + 1) self.numberOfEachDiagonalFaces = self.nx * self.ny self.dx = PhysicalField(value = dx) scale = PhysicalField(value = 1, unit = self.dx.unit) self.dx /= scale self.dy = PhysicalField(value = dy) if self.dy.unit.isDimensionless(): self.dy = dy else: self.dy /= scale self.numberOfCornerVertices = (self.nx + 1) * (self. ny + 1) self.numberOfCenterVertices = self.nx * self.ny self.numberOfTotalVertices = self.numberOfCornerVertices + self.numberOfCenterVertices self.offset = (0, 0) vertices = self._createVertices() faces = self._createFaces() cells = self._createCells() cells = numerix.sort(cells, axis=0) Mesh2D.__init__(self, vertices, faces, cells, _RepresentationClass=_RepresentationClass, _TopologyClass=_TopologyClass) self.scale = scale
def _translate(self, vector): """ Test for ticket:298. >>> from fipy import * >>> m = PeriodicGrid2DLeftRight(nx=2, ny=2) + [[-1], [0]] >>> orderedCellVertexIDs = [[1, 2, 4, 5], ... [4, 5, 7, 8], ... [3, 4, 6, 7], ... [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.mesh2D import Mesh2D Mesh2D.__init__(newmesh, newCoords, self.faceVertexIDs, self._nonPeriodicCellFaceIDs, communicator=self.communicator) newmesh._makePeriodic() return newmesh
def __init__(self, dx=1., dy=1., nx=None, ny=1, rand=0, *args, **kwargs): self.args = {'dx': dx, 'dy': dy, 'nx': nx, 'ny': ny, 'rand': rand} self.nx = nx self.ny = ny self.dx = PhysicalField(value=dx) scale = PhysicalField(value=1, unit=self.dx.unit) self.dx /= scale self.dy = PhysicalField(value=dy) if self.dy.unit.isDimensionless(): self.dy = dy else: self.dy /= scale self.grid = Grid2D(nx=nx, ny=ny, dx=dx, dy=dy, communicator=serialComm) self.numberOfVertices = self.grid._numberOfVertices vertices = self.grid.vertexCoords changedVertices = numerix.zeros(vertices.shape, 'd') for i in range(len(vertices[0])): if ((i % (nx + 1)) != 0 and (i % (nx + 1)) != nx and (i // nx + 1) != 0 and (i // nx + 1) != ny): changedVertices[0, i] = vertices[0, i] + (rand * ( (random.random() * 2) - 1)) changedVertices[1, i] = vertices[1, i] + (rand * ( (random.random() * 2) - 1)) else: changedVertices[0, i] = vertices[0, i] changedVertices[1, i] = vertices[1, i] faces = self.grid.faceVertexIDs cells = self.grid.cellFaceIDs Mesh2D.__init__(self, changedVertices, faces, cells, communicator=serialComm, *args, **kwargs) self.scale = scale
def __init__(self, dx = 1., dy = 1., nx = None, ny = 1, rand = 0, *args, **kwargs): self.args = { 'dx': dx, 'dy': dy, 'nx': nx, 'ny': ny, 'rand': rand } self.nx = nx self.ny = ny self.dx = PhysicalField(value = dx) scale = PhysicalField(value = 1, unit = self.dx.unit) self.dx /= scale self.dy = PhysicalField(value = dy) if self.dy.unit.isDimensionless(): self.dy = dy else: self.dy /= scale self.grid = Grid2D(nx=nx, ny=ny, dx=dx, dy=dy) self.numberOfVertices = self.grid._numberOfVertices vertices = self.grid.vertexCoords changedVertices = numerix.zeros(vertices.shape, 'd') for i in range(len(vertices[0])): if((i % (nx+1)) != 0 and (i % (nx+1)) != nx and (i / nx+1) != 0 and (i / nx+1) != ny): changedVertices[0, i] = vertices[0, i] + (rand * ((random.random() * 2) - 1)) changedVertices[1, i] = vertices[1, i] + (rand * ((random.random() * 2) - 1)) else: changedVertices[0, i] = vertices[0, i] changedVertices[1, i] = vertices[1, i] faces = self.grid.faceVertexIDs cells = self.grid.cellFaceIDs Mesh2D.__init__(self, changedVertices, faces, cells, *args, **kwargs) self.scale = scale
def __init__(self, dx=1., dy=1., nx=None, ny=None, overlap=2, communicator=parallelComm, _RepresentationClass=_Grid2DRepresentation, _TopologyClass=_Grid2DTopology): builder = _NonuniformGrid2DBuilder() self.args = { 'dx': dx, 'dy': dy, 'nx': nx, 'ny': ny, 'overlap': overlap, 'communicator': communicator } builder.buildGridData([dx, dy], [nx, ny], overlap, communicator) ([self.dx, self.dy], [self.nx, self.ny], self.dim, scale, self.globalNumberOfCells, self.globalNumberOfFaces, self.overlap, self.offset, self.numberOfVertices, self.numberOfFaces, self.numberOfCells, self.shape, self.physicalShape, self._meshSpacing, self.numberOfHorizontalRows, self.numberOfVerticalColumns, self.numberOfHorizontalFaces, vertices, faces, cells, [self.Xoffset, self.Yoffset]) = builder.gridData Mesh2D.__init__(self, vertices, faces, cells, communicator=communicator, _RepresentationClass=_RepresentationClass, _TopologyClass=_TopologyClass) self.scale = scale
def _translate(self, vector): """ Test for ticket:298. >>> from fipy import * >>> m = PeriodicGrid2DLeftRight(nx=2, ny=2) + [[-1], [0]] >>> orderedCellVertexIDs = [[1, 2, 4, 5], ... [4, 5, 7, 8], ... [3, 4, 6, 7], ... [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.mesh2D import Mesh2D Mesh2D.__init__(newmesh, newCoords, self.faceVertexIDs, self._nonPeriodicCellFaceIDs, communicator=self.communicator) newmesh._makePeriodic() return newmesh