def complex_mesh(r, filename, n): import meshio mesh = meshio.read(filename) node = mesh.points node = node[:,0:2]*r cell = mesh.cells mesh.node = node mesh.cell = cell cell = cell['triangle'] isUsingNode = np.zeros(node.shape[0], dtype=np.bool) isUsingNode[cell] = True NN = isUsingNode.sum() idxmap = np.zeros(node.shape[0], dtype=np.int32) idxmap[isUsingNode] = range(NN) cell = idxmap[cell] node = node[isUsingNode] #cell = cell[:,::-1] mesh = TriangleMesh(node,cell) nmesh = TriangleMeshWithInfinityNode(mesh) ppoint, pcell, pcellLocation = nmesh.to_polygonmesh() pmesh = PolygonMesh(ppoint, pcell, pcellLocation) hmesh = HalfEdgeMesh2d.from_mesh(pmesh) hmesh.init_level_info() hmesh.convexity() hmesh.uniform_refine(n=n) mesh = PolygonMesh.from_halfedgemesh(hmesh) return mesh
def init_mesh(self, n=1, meshtype='tri'): node = np.array([ (0, 0), (1, 0), (1, 1), (0, 1)], dtype=np.float) if meshtype == 'tri': cell = np.array([ (1, 2, 0), (3, 0, 2)], dtype=np.int) mesh = TriangleMesh(node, cell) mesh.uniform_refine(n) return mesh elif meshtype == 'quad': nx = 4 ny = 4 mesh = StructureQuadMesh(self.box, nx, ny) mesh.uniform_refine(n) return mesh elif meshtype == 'poly': cell = np.array([ (1, 2, 0), (3, 0, 2)], dtype=np.int) mesh = TriangleMesh(node, cell) mesh.uniform_refine(n) nmesh = TriangleMeshWithInfinityNode(mesh) pnode, pcell, pcellLocation = nmesh.to_polygonmesh() pmesh = PolygonMesh(pnode, pcell, pcellLocation) return pmesh
def init_mesh(self, n=1, meshtype='tri'): node = np.array([ (-1, -1), ( 0, -1), ( 1, -1), (-1, 0), ( 0, 0), ( 1, 0), (-1, 1), ( 0, 1)], dtype=np.float) if meshtype == 'tri': cell = np.array([ (3, 0, 4), (1, 4, 0), (4, 1, 5), (2, 5, 1), (6, 3, 7), (4, 7, 3)], dtype=np.int) mesh = TriangleMesh(node, cell) mesh.uniform_refine(n) return mesh elif meshtype == 'poly': cell = np.array([ (3, 0, 4), (1, 4, 0), (4, 1, 5), (2, 5, 1), (6, 3, 7), (4, 7, 3)], dtype=np.int) mesh = TriangleMesh(node, cell) mesh.uniform_refine(n) nmesh = TriangleMeshWithInfinityNode(mesh) pnode, pcell, pcellLocation = nmesh.to_polygonmesh() pmesh = PolygonMesh(pnode, pcell, pcellLocation) return pmesh
def complex_mesh(r, filename): import meshio mesh = meshio.read(filename) node = mesh.points node = node[:, 0:2] * r cell = mesh.cells mesh.node = node mesh.cell = cell cell = cell['triangle'] isUsingNode = np.zeros(node.shape[0], dtype=np.bool) isUsingNode[cell] = True NN = isUsingNode.sum() idxmap = np.zeros(node.shape[0], dtype=np.int32) idxmap[isUsingNode] = range(NN) cell = idxmap[cell] node = node[isUsingNode] #cell = cell[:,::-1] mesh = TriangleMesh(node, cell) nmesh = TriangleMeshWithInfinityNode(mesh) ppoint, pcell, pcellLocation = nmesh.to_polygonmesh() pmesh = PolygonMesh(ppoint, pcell, pcellLocation) return pmesh
from fealpy.mesh import PolygonMesh, HalfEdgePolygonMesh from fealpy.mesh import TriangleMeshWithInfinityNode from fealpy.tools import showmultirate import pickle maxit = int(sys.argv[1]) theta = float(sys.argv[2]) k = int(sys.argv[3]) # prepare the pde model pde = SFCModelData1() # mesh mesh = pde.init_mesh(n=4, meshtype='tri') mesh = TriangleMeshWithInfinityNode(mesh) pnode, pcell, pcellLocation = mesh.to_polygonmesh() mesh = PolygonMesh(pnode, pcell, pcellLocation) mesh = HalfEdgePolygonMesh.from_polygonmesh(mesh) errorType = ['$\eta$', '$\Psi_0$', '$\Psi_1$'] Ndof = np.zeros((maxit, ), dtype=np.int) errorMatrix = np.zeros((len(errorType), maxit), dtype=np.float) data = {} for i in range(maxit): print(i, "-th step") vem = SFCVEMModel2d(pde, mesh, p=1, q=4) if i == 0: vem.solve(rho=0.7, maxit=40000) else:
from fealpy.geometry import dcircle, drectangle, ddiff from fealpy.geometry import DistDomain2d from fealpy.geometry import huniform from fealpy.mesh import DistMesh2d from fealpy.mesh import PolygonMesh from fealpy.mesh import TriangleMeshWithInfinityNode fd = lambda p: drectangle(p, [0.0, 1.0, 0.0, 1.0]) fh = huniform bbox = [-0.2, 1.2, -0.2, 1.2] pfix = np.array([ (0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)], dtype=np.float) h0 = 0.05 domain = DistDomain2d(fd, fh, bbox, pfix) distmesh2d = DistMesh2d(domain, h0) distmesh2d.run() mesh = TriangleMeshWithInfinityNode(distmesh2d.mesh) pnode, pcell, pcellLocation = mesh.to_polygonmesh() pmesh = PolygonMesh(pnode, pcell, pcellLocation) fig = plt.figure() axes = fig.gca() pmesh.add_plot(axes) fig = plt.figure() axes = fig.gca() distmesh2d.mesh.add_plot(axes) plt.show()