#mesh.uniform_refine(n=4) fig = plt.figure() axes = fig.gca() mesh.add_plot(axes) mesh.find_cell(axes, showindex=True) plt.show() c = np.array([0.5,0.5]) r = 0.5 maxit = 6 k=0 while k < maxit: aopts = mesh.adaptive_options(method='numrefine', maxcoarsen=3, HB=True) node = mesh.node h = np.sqrt(mesh.cell_area()) print('NN', mesh.number_of_nodes()) d = np.sqrt((node[:,0]-c[0])**2+(node[:,1]-c[1])**2) ###要加密的点 flag0 = np.abs(d-r) < 0.1 ##要粗化的点 flag1 = np.abs(d-r) > 0.1 ### 找到点对应的单元都是需要标记的单元 node2cell = mesh.ds.node_to_cell() idx0 = np.argwhere(node2cell[flag0,:]>0) idx1 = np.argwhere(node2cell[flag1,:]>0) NC = mesh.number_of_cells() isrefineflag = np.zeros(NC, dtype=np.bool_) isrefineflag[idx0[:,1]] = 1
def refine_quad(self, plot=True): cell = np.array([[0, 1, 2, 3], [1, 4, 5, 2]], dtype=np.int) node = np.array([[0, 0], [1, 0], [1, 1], [0, 1], [2, 0], [2, 1]], dtype=np.float) mesh = QuadrangleMesh(node, cell) #mesh.uniform_refine() mesh = HalfEdgeMesh.from_mesh(mesh) c = np.array([0.8, 0.8]) r = 0.5 h = 1e-2 l = 6 k = 0 NB = 0 while k < l: halfedge = mesh.ds.halfedge halfedge1 = halfedge[:, 3] node = mesh.node flag = node - c flag = flag[:, 0]**2 + flag[:, 1]**2 flag = flag <= r**2 flag1 = flag[halfedge[:, 0]].astype(int) flag2 = flag[halfedge[halfedge1, 0]].astype(int) markedge = flag1 + flag2 == 1 markedcell = halfedge[markedge, 1] markedcell = np.unique(markedcell) cell = np.unique(halfedge[:, 1]) nc = cell.shape[0] markedcell1 = np.zeros(nc) markedcell1[markedcell] = 1 print('makee', markedcell) mesh.refine_quad(markedcell1) k += 1 print('循环', k, '次***************************') if plot: fig = plt.figure() axes = fig.gca() nindex = mesh.nodedata['level'] mesh.add_plot(axes) #mesh.add_halfedge_plot(axes, showindex=True) #mesh.find_node(axes, showindex=True, multiindex=nindex) plt.show() if 0: fig = plt.figure() axes = fig.gca() mesh.add_plot(axes) mesh.find_node(axes, showindex=True) mesh.find_cell(axes, showindex=True) cindex, = np.nonzero(mesh.ds.cflag) 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 = mesh.nodedata['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()