Example #1
0
 def __setstate__(self, dict):
     self.epsilon = dict['epsilon']
     self.actualDomainHeight = dict['actualDomainHeight']
     self.actualFineRegionHeight = dict['actualFineRegionHeight']
     self.cellSize = dict['cellSize']
     self.fineMesh = dict['fineMesh']
     Mesh2D.__init__(self, dict['vertexCoords'], dict['faceVertexIDs'], dict['cellFaceIDs'])
Example #2
0
    def __init__(self, cellSize = None, desiredDomainWidth = None, desiredDomainHeight = None, desiredFineRegionHeight = None, transitionRegionHeight = None):

        """

        Arguments:

        `cellSize` - The cell size in the fine grid around the trench.

        `desiredDomainWidth` - The desired domain width.

        `desiredDomainHeight` - The total desired height of the
        domain.

        `desiredFineRegionHeight` - The desired height of the in the
        fine region around the trench.

        `transitionRegionHeight` - The height of the transition
        region.

        """
        self.cellSize = cellSize
        ## Calculate the fine region cell counts.
        nx = int(desiredDomainWidth / self.cellSize)
        ny = int(desiredFineRegionHeight / self.cellSize)

        ## Calculate the actual mesh dimensions
        self.actualFineRegionHeight = ny * self.cellSize
        actualDomainWidth = nx * self.cellSize
        numberOfBoundaryLayerCells = int((desiredDomainHeight - self.actualFineRegionHeight - transitionRegionHeight) / actualDomainWidth)
        self.epsilon = self.cellSize * 1e-10
        self.actualDomainHeight = self.actualFineRegionHeight + transitionRegionHeight + numberOfBoundaryLayerCells * actualDomainWidth
        
        ## Build the fine region mesh.
        from fipy.tools import serial
        self.fineMesh = Grid2D(nx = nx, ny = ny, dx = cellSize, dy = cellSize, parallelModule=serial)

        ## Build the transition mesh and displace.
        transitionMesh = self.buildTransitionMesh(nx, transitionRegionHeight, cellSize) + ((0,), (self.actualFineRegionHeight,))

        ## Build the boundary layer mesh.

        from fipy.tools import serial
        boundaryLayerMesh = Grid2D(dx = actualDomainWidth,
                                   dy = actualDomainWidth,
                                   nx = 1,
                                   ny = numberOfBoundaryLayerCells,
                                   parallelModule=serial) + ((0,), (self.actualFineRegionHeight + transitionRegionHeight,),)

        ## Add the meshes together.
        mesh = self.fineMesh._concatenate(transitionMesh, self.epsilon)

        mesh = mesh._concatenate(boundaryLayerMesh, self.epsilon)

        ## Initialize the mesh.
        dict = mesh.__getstate__()
        Mesh2D.__init__(self,dict['vertexCoords'], dict['faceVertexIDs'], dict['cellFaceIDs'])
Example #3
0
 def __getstate__(self):
     dict = Mesh2D.__getstate__(self)
     dict['epsilon'] = self.epsilon
     dict['actualDomainHeight'] = self.actualDomainHeight
     dict['actualFineRegionHeight'] = self.actualFineRegionHeight
     dict['cellSize'] = self.cellSize
     dict['fineMesh'] = self.fineMesh
     dict['faceVertexIDs'] = self.faceVertexIDs.filled()
     return dict
Example #4
0
 def __init__(self, dx = 1., dy = 1., nx = 1, ny = 1):
     """
     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.nx = nx
     self.ny = ny
     
     self.dx = PhysicalField(value = dx)
     scale = PhysicalField(value = 1, unit = self.dx.getUnit())
     self.dx /= scale
     
     self.dy = PhysicalField(value = dy)
     if self.dy.getUnit().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
     
     vertices = self._createVertices()
     faces = self._createFaces()
     cells = self._createCells()
     cells = numerix.sort(cells, axis=0)
     Mesh2D.__init__(self, vertices, faces, cells)
     self.setScale(value = scale)
Example #5
0
    def __init__(self, dx = 1., dy = 1., nx = None, ny = 1, rand = 0):
        self.nx = nx
        self.ny = ny
        
        self.dx = PhysicalField(value = dx)
        scale = PhysicalField(value = 1, unit = self.dx.getUnit())
        self.dx /= scale
        
        self.dy = PhysicalField(value = dy)
        if self.dy.getUnit().isDimensionless():
            self.dy = dy
        else:
            self.dy /= scale

        from fipy import Grid2D
        self.grid = Grid2D(nx=nx, ny=ny, dx=dx, dy=dy)

        self.numberOfVertices = self.grid._getNumberOfVertices()
        
        vertices = self.grid.getVertexCoords()

        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._getFaceVertexIDs()
        
        cells = self.grid._getCellFaceIDs()

        Mesh2D.__init__(self, changedVertices, faces, cells)
        
        self.setScale(value = scale)
Example #6
0
File: grid2D.py Project: regmi/fipy
    def __init__(self, dx=1., dy=1., nx=None, ny=None, overlap=2, parallelModule=parallel):
        
        self.args = {
            'dx': dx, 
            'dy': dy, 
            'nx': nx, 
            'ny': ny, 
            'overlap': overlap,
            'parallelModule': parallelModule
        }

        self.dx = PhysicalField(value = dx)
        scale = PhysicalField(value=1, unit=self.dx.getUnit())
        self.dx /= scale
        
        nx = self._calcNumPts(d=self.dx, n=nx, axis="x")
        
        self.dy = PhysicalField(value = dy)
        if self.dy.getUnit().isDimensionless():
            self.dy = dy
        else:
            self.dy /= scale
            
        ny = self._calcNumPts(d=self.dy, n=ny, axis="y")
        
        (self.nx,
         self.ny,
         self.overlap,
         self.offset) = self._calcParallelGridInfo(nx, ny, overlap, parallelModule)

        if numerix.getShape(self.dx) is not ():
            Xoffset = numerix.sum(self.dx[0:self.offset[0]])
            self.dx = self.dx[self.offset[0]:self.offset[0] + self.nx]
        else:
            Xoffset = 0

        if numerix.getShape(self.dy) is not ():
            Yoffset =  numerix.sum(self.dy[0:self.offset[1]])
            self.dy = self.dy[self.offset[1]:self.offset[1] + self.ny]
        else:
            Yoffset = 0
            
        if self.nx == 0:
            self.ny = 0
        if self.ny == 0:
            self.nx = 0
        if self.nx == 0 or self.ny == 0:
            self.numberOfHorizontalRows = 0
            self.numberOfVerticalColumns = 0
        else:
            self.numberOfHorizontalRows = (self.ny + 1)
            self.numberOfVerticalColumns = (self.nx + 1)

        self.numberOfVertices = self.numberOfHorizontalRows * self.numberOfVerticalColumns

        vertices = self._createVertices() + ((Xoffset,), (Yoffset,))
        faces = self._createFaces()
        self.numberOfFaces = len(faces[0])
        cells = self._createCells()
        Mesh2D.__init__(self, vertices, faces, cells)
        
        self.setScale(value = scale)
Example #7
0
 def _getFaceAreas(self):
     return Mesh2D._getFaceAreas(self) * self.getFaceCenters()[0]
Example #8
0
 def __init__(self, mesh):
     Mesh2D.__init__(self,
                     mesh.getVertexCoords(),
                     mesh.faceVertexIDs,
                     mesh.cellFaceIDs)
Example #9
0
 def getCellVolumes(self):
     return Mesh2D.getCellVolumes(self) * self.getCellCenters()[0]