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 init_mesh(self, n=0, p=None): t = self.CircleCurve.radius c = np.sqrt(3.0) / 2.0 node = np.array( [[0.0, 0.0], [t, 0.0], [t / 2.0, c * t], [-t / 2.0, c * t], [-t, 0.0], [-t / 2.0, -c * t], [t / 2.0, -c * t]], dtype=np.float64) cell = np.array( [[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 6], [0, 6, 1]], dtype=np.int_) mesh = TriangleMesh(node, cell) for i in range(n): NN = mesh.number_of_nodes() mesh.uniform_refine() node = mesh.entity('node') self.CircleCurve.project(node[NN:]) node = mesh.entity('node') cell = mesh.entity('cell') mesh = LagrangeTriangleMesh(node, cell, p=p) isBdNode = mesh.ds.boundary_node_flag() node = mesh.entity('node') bdnode = node[isBdNode] self.CircleCurve.project(bdnode) node[isBdNode] = bdnode return mesh