def convexity(self): node = np.array([[0, 0], [2, 0], [2, 1], [1, 1], [1, 2], [1, 3], [1, 4], [2, 4], [2, 5], [0, 5], [0, 2]], dtype=np.float) cell = np.array([0, 1, 2, 3, 4, 10, 5, 6, 7, 8, 9, 10, 4], dtype=np.int_) cellLocation = np.array([0, 6, 13], dtype=np.int) mesh = PolygonMesh(node, cell, cellLocation) mesh = HalfEdgeMesh2d.from_mesh(mesh) mesh.init_level_info() mesh.convexity() mesh.print() fig = plt.figure() axes = fig.gca() mesh.add_plot(axes) mesh.find_node(axes, showindex=True) mesh.find_cell(axes, showindex=True) mesh.add_halfedge_plot(axes, showindex=True) plt.show()
def refine_poly_test(self, plot=True): node = np.array([(0.0, 0.0), (0.0, 1.0), (0.0, 2.0), (1.0, 0.0), (1.0, 1.0), (1.0, 2.0), (2.0, 0.0), (2.0, 1.0), (2.0, 2.0)], dtype=np.float) cell = np.array([0, 3, 4, 4, 1, 0, 1, 4, 5, 2, 3, 6, 7, 4, 4, 7, 8, 5], dtype=np.int) cellLocation = np.array([0, 3, 6, 10, 14, 18], dtype=np.int) mesh = PolygonMesh(node, cell, cellLocation) mesh = HalfEdgeMesh.from_mesh(mesh) fig = plt.figure() axes = fig.gca() mesh.add_plot(axes) mesh.find_node(axes, showindex=True) mesh.find_cell(axes, showindex=True) clevel = mesh.celldata['level'] print(clevel) NE = mesh.number_of_edges() NC = mesh.number_of_cells() if True: isMarkedCell = mesh.mark_helper([2]) mesh.refine_poly(isMarkedCell, dflag=False) if False: isMarkedCell = mesh.mark_helper([6]) mesh.refine_poly(isMarkedCell, dflag=False) if False: isMarkedCell = mesh.mark_helper([3]) mesh.refine_poly(isMarkedCell, dflag=False) if 1: isMarkedCell = mesh.mark_helper([1, 5]) mesh.refine_poly(isMarkedCell, dflag=False) if False: isMarkedCell = mesh.mark_helper([1, 12]) mesh.refine_poly(isMarkedCell, dflag=False) if False: isMarkedCell = mesh.mark_helper([0, 21]) mesh.refine_poly(isMarkedCell, dflag=False) clevel = mesh.celldata['level'] print(clevel) #print("halfedge level:\n") #for i, val in enumerate(mesh.halfedgedata['level']): # print(i, ':', val, mesh.ds.halfedge[i, 0:2]) #print("cell level:\n") #for i, val in enumerate(mesh.celldata['level']): # print(i, ':', val) if plot: fig = plt.figure() axes = fig.gca() mesh.add_plot(axes) mesh.find_node(axes, showindex=True) mesh.find_cell(axes, showindex=True) NAC = mesh.number_of_all_cells() # 包括外部区域和洞 cindex = range(mesh.ds.cellstart, NAC) fig = plt.figure() axes = fig.gca() mesh.add_plot(axes) mesh.find_node(axes, showindex=True) mesh.add_halfedge_plot(axes, showindex=True) mesh.find_cell(axes, showindex=True, multiindex=cindex) NN = mesh.number_of_nodes() nindex = np.zeros(NN, dtype=np.int) halfedge = mesh.ds.halfedge nindex[halfedge[:, 0]] = mesh.get_data('halfedge', 'level') cindex = mesh.get_data('cell', 'level') fig = plt.figure() axes = fig.gca() mesh.add_plot(axes) mesh.find_node(axes, showindex=True, multiindex=nindex) mesh.find_cell(axes, showindex=True, multiindex=cindex) plt.show() else: return mesh
def adaptive_poly(self, plot=True): """" initial mesh """ node = np.array([(0.0, 0.0), (0.0, 1.0), (0.0, 2.0), (1.0, 0.0), (1.0, 1.0), (1.0, 2.0), (2.0, 0.0), (2.0, 1.0), (2.0, 2.0)], dtype=np.float) cell = np.array([0, 3, 4, 4, 1, 0, 1, 4, 5, 2, 3, 6, 7, 4, 4, 7, 8, 5], dtype=np.int) cellLocation = np.array([0, 3, 6, 10, 14, 18], dtype=np.int) mesh = PolygonMesh(node, cell, cellLocation) mesh = HalfEdgeMesh2d.from_mesh(mesh) #fig = plt.figure() #axes = fig.gca() #mesh.add_plot(axes) #mesh.find_node(axes, showindex=True) #mesh.find_cell(axes, showindex=True) NE = mesh.number_of_edges() nC = mesh.number_of_cells() """ refined mesh """ aopts = mesh.adaptive_options(method='numrefine', maxcoarsen=3, HB=True) eta = [0, 0, 1, 1, 1] mesh.adaptive(eta, aopts) print('r', aopts['HB']) #fig = plt.figure() #axes = fig.gca() #mesh.add_plot(axes) #mesh.find_node(axes, showindex=True) #mesh.find_cell(axes, showindex=True) #plt.show() mesh.from_mesh(mesh) """ coarsened mesh """ eta = [0, 0, 0, 0, 0, 0, 0, -1, 0, -1, 0, -1, 0, -1] #eta = [0,0,0,0,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2] mesh.adaptive(eta, aopts) print('c', aopts['HB']) print(mesh.ds.hcell) #fig = plt.figure() #axes = fig.gca() #mesh.add_plot(axes) #mesh.find_node(axes, showindex=True) #mesh.find_cell(axes, showindex=True) #plt.show() if plot: fig = plt.figure() axes = fig.gca() mesh.add_plot(axes) mesh.add_halfedge_plot(axes, showindex=True) mesh.find_node(axes, showindex=True) #mesh.find_cell(axes, showindex=True) plt.show() if 0: NAC = mesh.number_of_all_cells() # 包括外部区域和洞 cindex = range(mesh.ds.cellstart, NAC) fig = plt.figure() axes = fig.gca() mesh.add_plot(axes) mesh.find_node(axes, showindex=True) mesh.find_cell(axes, showindex=True, multiindex=cindex) NN = mesh.number_of_nodes() nindex = np.zeros(NN, dtype=np.int) halfedge = mesh.ds.halfedge nindex[halfedge[:, 0]] = mesh.get_data('halfedge', 'level') cindex = mesh.get_data('cell', 'level') fig = plt.figure() axes = fig.gca() mesh.add_plot(axes) mesh.find_node(axes, showindex=True, multiindex=nindex) mesh.find_cell(axes, showindex=True, multiindex=cindex) plt.show() else: return mesh
def refine_poly(self, plot=True): node = np.array([(0.0, 0.0), (0.0, 1.0), (0.0, 2.0), (1.0, 0.0), (1.0, 1.0), (1.0, 2.0), (2.0, 0.0), (2.0, 1.0), (2.0, 2.0)], dtype=np.float) cell = np.array([0, 3, 4, 4, 1, 0, 1, 4, 5, 2, 3, 6, 7, 4, 4, 7, 8, 5], dtype=np.int) cellLocation = np.array([0, 3, 6, 10, 14, 18], dtype=np.int) mesh = PolygonMesh(node, cell, cellLocation) mesh = HalfEdgeMesh2d.from_mesh(mesh) mesh.uniform_refine(n=2) print(mesh.number_of_nodes()) #fig = plt.figure() #axes = fig.gca() #mesh.add_plot(axes) #mesh.find_node(axes, showindex=True) #mesh.find_cell(axes, showindex=True) NE = mesh.number_of_edges() NC = mesh.number_of_cells() if True: isMarkedCell = mesh.mark_helper([2]) mesh.refine_poly(isMarkedCell) if False: isMarkedCell = mesh.mark_helper([6]) mesh.refine_poly(isMarkedCell, dflag=False) if False: isMarkedCell = mesh.mark_helper([3]) mesh.refine_poly(isMarkedCell, dflag=False) if False: isMarkedCell = mesh.mark_helper([1, 5]) mesh.refine_poly(isMarkedCell) if False: isMarkedCell = mesh.mark_helper([1, 12]) mesh.refine_poly(isMarkedCell, dflag=False) if False: isMarkedCell = mesh.mark_helper([0, 21]) mesh.refine_poly(isMarkedCell, dflag=False) if plot: fig = plt.figure() axes = fig.gca() mesh.add_plot(axes) mesh.find_node(axes, showindex=True) mesh.add_halfedge_plot(axes, showindex=True) mesh.find_cell(axes, showindex=True) plt.show() if 0: NAC = mesh.number_of_all_cells() # 包括外部区域和洞 cindex = range(mesh.ds.cellstart, NAC) fig = plt.figure() axes = fig.gca() #mesh.add_plot(axes) mesh.add_halfedge_plot(axes, showindex=True) mesh.find_node(axes, showindex=True) mesh.find_cell(axes, showindex=True, multiindex=cindex) NN = mesh.number_of_nodes() nindex = np.zeros(NN, dtype=np.int) halfedge = mesh.ds.halfedge nindex[halfedge[:, 0]] = mesh.get_data('halfedge', 'level') cindex = mesh.get_data('cell', 'level') fig = plt.figure() axes = fig.gca() #mesh.add_plot(axes) mesh.find_node(axes, showindex=True, multiindex=nindex) #mesh.find_cell(axes, showindex=True, multiindex=cindex) plt.show() else: return mesh