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, cellSize=None, desiredDomainWidth=None, desiredDomainHeight=None, desiredFineRegionHeight=None, transitionRegionHeight=None, communicator=parallelComm): """ 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. """ # Calculate the fine region cell counts. nx = int(desiredDomainWidth / cellSize) ny = int(desiredFineRegionHeight / cellSize) # Calculate the actual mesh dimensions actualFineRegionHeight = ny * cellSize actualDomainWidth = nx * cellSize boundaryLayerHeight = desiredDomainHeight - actualFineRegionHeight - transitionRegionHeight numberOfBoundaryLayerCells = int(boundaryLayerHeight / actualDomainWidth) # Build the fine region mesh. self.fineMesh = Grid2D(nx=nx, ny=ny, dx=cellSize, dy=cellSize, communicator=serialComm) eps = cellSize / nx / 10 super(GapFillMesh, self).__init__(""" ny = %(ny)g; cellSize = %(cellSize)g - %(eps)g; height = %(actualFineRegionHeight)g; width = %(actualDomainWidth)g; boundaryLayerHeight = %(boundaryLayerHeight)g; transitionRegionHeight = %(transitionRegionHeight)g; numberOfBoundaryLayerCells = %(numberOfBoundaryLayerCells)g; Point(1) = {0, 0, 0, cellSize}; Point(2) = {width, 0, 0, cellSize}; Line(3) = {1, 2}; Point(10) = {0, height, 0, cellSize}; Point(11) = {width, height, 0, cellSize}; Point(12) = {0, height + transitionRegionHeight, 0, width}; Point(13) = {width, height + transitionRegionHeight, 0, width}; Line(14) = {10,11}; Line(15) = {11,13}; Line(16) = {13,12}; Line(17) = {12,10}; Line Loop(18) = {14, 15, 16, 17}; Plane Surface(19) = {18}; Extrude{0, height, 0} { Line{3}; Layers{ ny }; Recombine;} Line(100) = {12, 13}; Extrude{0, boundaryLayerHeight, 0} { Line{100}; Layers{ numberOfBoundaryLayerCells }; Recombine;} """ % locals(), communicator=communicator)
# gr = c.grad(c.center(), pN) ax.arrow(b.center()[0], b.center()[1], gr[0], gr[1], color='red') for b in grid.boundaries(): gr = boundGrad2[b.id()] # gr = c.grad(c.center(), pN) ax.arrow(b.center()[0], b.center()[1], gr[0], gr[1], color='green') ax.set_xlim([-0.5, 3.5]) ax.set_ylim([-0.5, 3.1]) # F = grid.grad(pot) # print(F) print("div:", divergence(grid, boundGrad)) sys.path.append('/home/carsten/src/fipy') mesh = Grid2D(nx=3, ny=2) val = np.arange(3 * 2.) var = CellVariable(mesh=mesh, value=val) print(var.faceGrad._calcValueNoInline()) print('-____________') # print(var.faceGrad) print(var.faceGrad.divergence) # print(var.__pos__) # [ 4. 3. 2. -2. -3. -4.] ax, cbar = show(grid, np.array(var)) show(grid, axes=ax) X, Y = mesh.getCellCenters() gr = var.grad.numericValue m = 1