def par_mesh(h, n): mesh_info = MeshInfo() # Set the vertices of the domain [0, 1]^2 mesh_info.set_points([ (0,0), (1,0), (1,1), (0,1)]) # Set the facets of the domain [0, 1]^2 mesh_info.set_facets([ [0,1], [1,2], [2,3], [3,0] ]) # Generate the tet mesh mesh = build(mesh_info, max_volume=(h)**2) node = np.array(mesh.points, dtype=np.float) cell = np.array(mesh.elements, dtype=np.int) tmesh = TriangleMesh(node, cell) # Partition the mesh cells into n parts if n > 1: edgecuts, parts = metis.part_mesh(tmesh, nparts=n, entity='node') else: NN = tmesh.number_of_nodes() parts = np.zeros(NN, dtype=np.int) tmesh.nodedata['partition'] = parts return tmesh
def par_regmesh(n): tmesh = squaremesh(0,1,0,1,3) # Partition the mesh cells into n parts if n > 1: edgecuts, parts = metis.part_mesh(tmesh, nparts=n, entity='node') else: NN = tmesh.number_of_nodes() parts = np.zeros(NN, dtype=np.int) tmesh.nodedata['partition'] = parts return tmesh
def mesh2dpy(mesh_info, h, n): mesh = build(mesh_info, max_volume=(h)**2) point = np.array(mesh.points, dtype=np.float) cell = np.array(mesh.elements, dtype=np.int) tmesh = TriangleMesh(point, cell) edgecuts, parts = metis.part_mesh(tmesh, nparts=n, entity='cell') point = tmesh.point edge = tmesh.ds.edge cell = tmesh.ds.cell cell2edge = tmesh.ds.cell_to_edge() edge2cell = tmesh.ds.edge_to_cell() isBdPoint = tmesh.ds.boundary_point_flag() data = { 'Point': point, 'Edge': edge + 1, 'Elem': cell + 1, 'Edge2Elem': edge2cell + 1, 'isBdPoint': isBdPoint, 'Partitions': parts + 1 } result = sio.matlab.savemat('test' + str(n) + 'parts' + str(h) + '.mat', data) return result
from fealpy.graph import metis n = int(sys.argv[1]) m = int(sys.argv[2]) p=1 pde = CosCosData() mesh = pde.init_mesh(n=n) space = LagrangeFiniteElementSpace(mesh, p=p) bc = BoundaryCondition(space, dirichlet=pde.dirichlet) uh = space.function() A = space.stiff_matrix() F = space.source_vector(pde.source) A, F = bc.apply_dirichlet_bc(A, F, uh) uh[:] = spsolve(A, F) error = space.integralalg.L2_error(pde.solution, uh) edgecuts, parts = metis.part_mesh(mesh, nparts=m, entity='cell', contig=True) print(parts) fig = plt.figure() axes = fig.gca() mesh.add_plot(axes) #mesh.find_node(axes, color=parts) mesh.find_cell(axes, color=parts) plt.show()
[0, 4, 5, 1], [1, 5, 6, 2], [2, 6, 7, 3], [3, 7, 4, 0], ]) # Generate the tet mesh mesh = build(mesh_info, max_volume=(h)**3) point = np.array(mesh.points, dtype=np.float) cell = np.array(mesh.elements, dtype=np.int) tmesh = TetrahedronMesh(point, cell) # Partition the mesh cells into n parts edgecuts, parts = metis.part_mesh(tmesh, nparts=n, entity='cell') point = tmesh.point edge = tmesh.ds.edge face = tmesh.ds.face cell = tmesh.ds.cell face2cell = tmesh.ds.face2cell cell2edge = tmesh.ds.cell_to_edge() face2edge = tmesh.ds.face_to_edge() isBdPoint = tmesh.ds.boundary_point_flag() data = { 'Point': point, 'Face': face + 1, 'Elem': cell + 1, 'Face2Elem': face2cell + 1,
# Set the vertices of the domain [0, 1]^2 mesh_info.set_points([(0, 0), (1, 0), (1, 1), (0, 1)]) # Set the facets of the domain [0, 1]^2 mesh_info.set_facets([[0, 1], [1, 2], [2, 3], [3, 0]]) # Generate the tet mesh mesh = build(mesh_info, max_volume=(h)**2) point = np.array(mesh.points, dtype=np.float) cell = np.array(mesh.elements, dtype=np.int) tmesh = TriangleMesh(point, cell) # Partition the mesh cells into n parts edgecuts, parts = metis.part_mesh(tmesh, nparts=n, entity='point') point = tmesh.point edge = tmesh.ds.edge cell = tmesh.ds.cell cell2edge = tmesh.ds.cell_to_edge() edge2cell = tmesh.ds.edge_to_cell() isBdPoint = tmesh.ds.boundary_point_flag() data = { 'Point': point, 'Face': edge + 1, 'Elem': cell + 1, 'Edge2Elem': edge2cell + 1, 'isBdPoint': isBdPoint, 'Partitions': parts + 1
# Set the vertices of the domain [0, 1]^2 mesh_info.set_points([(0, 0), (1, 0), (1, 1), (0, 1)]) # Set the facets of the domain [0, 1]^2 mesh_info.set_facets([[0, 1], [1, 2], [2, 3], [3, 0]]) # Generate the tet mesh mesh = build(mesh_info, max_volume=(h)**2) node = np.array(mesh.points, dtype=np.float) cell = np.array(mesh.elements, dtype=np.int) tmesh = TriangleMesh(node, cell) # Partition the mesh cells into n parts edgecuts, parts = metis.part_mesh(tmesh, nparts=n, entity='node') node = tmesh.node edge = tmesh.ds.edge cell = tmesh.ds.cell cell2edge = tmesh.ds.cell_to_edge() edge2cell = tmesh.ds.edge_to_cell() isBdNode = tmesh.ds.boundary_node_flag() data = { 'Point': node, 'Face': edge + 1, 'Elem': cell + 1, 'Edge2Elem': edge2cell + 1, 'isBdPoint': isBdNode, 'Partitions': parts + 1