def interpolation(self, n=2, plot=True): from fealpy.pde.poisson_2d import CosCosData from fealpy.functionspace import ConformingVirtualElementSpace2d pde = CosCosData() node = np.array([(0, 0), (1, 0), (1, 1), (0, 1)], dtype=np.float64) cell = np.array([(0, 1, 2, 3)], dtype=np.int_) mesh = QuadrangleMesh(node, cell) #mesh = PolygonMesh.from_mesh(mesh) mesh = HalfEdgeMesh2d.from_mesh(mesh) mesh.uniform_refine(n=n) #mesh.print() space = ConformingVirtualElementSpace2d(mesh, p=1) uI = space.interpolation(pde.solution) up = space.project_to_smspace(uI) error = space.integralalg.L2_error(pde.solution, up) print(error) if plot: fig = plt.figure() axes = fig.gca() #mesh.add_halfedge_plot(axes, showindex=True) mesh.add_plot(axes) mesh.find_node(axes, showindex=True) mesh.find_edge(axes, showindex=True) mesh.find_cell(axes, showindex=True) plt.show()
def Lshapetest(self, plot=True): node = np.array([ (-1.0, -1.0), (0.0, -1.0), (1.0, -1.0), (1.0, 0.0), (0.0, 0.0), (0.0, 1.0), (-1.0, 1.0), (-1.0,0.0)], dtype=np.float) cell = np.array([[0, 1, 4, 7],[1,2,3,4],[7,4,5,6]], dtype=np.int) mesh = QuadrangleMesh(node, cell) mesh.uniform_refine(n=2) #mesh.node = mesh.node[np.lexsort(mesh.node[:,::-1].T)] ''' l = len(mesh.node) node1 = np.zeros((l,2)) node1[:9,:] = mesh.node[mesh.node[:,1] = -1] node1[9:18,:] = mesh.node[mesh.node[:,1] = -1] ''' if plot: fig = plt.figure() axes = fig.gca() mesh.add_plot(axes) mesh.node = mesh.node[np.lexsort(mesh.node[:,::-1].T)] mesh.find_node(axes,showindex = True) #mesh.find_edge(axes) #mesh.print() plt.show()
def refine_RB_test(self, plot=True): node = np.array([ (0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)], dtype=np.float) cell = np.array([[0, 1, 2, 3]], dtype=np.int) mesh = QuadrangleMesh(node, cell) mesh.uniform_refine() markedCell = np.array([3], dtype=np.int) mesh.refine_RB(markedCell) if plot: fig = plt.figure() axes = fig.gca() mesh.add_plot(axes) mesh.find_node(axes, showindex=True) mesh.find_edge(axes, showindex=True) mesh.find_cell(axes, showindex=True) mesh.print() plt.show()
def halfedgemesh(n=4, h=4): """ 半边数据结构的网格 """ node = np.array([(0, 0), (h, 0), (h, h), (0, h)], dtype=np.float64) cell = np.array([(0, 1, 2, 3)], dtype=np.int_) mesh = QuadrangleMesh(node, cell) mesh = HalfEdgeMesh2d.from_mesh(mesh) mesh.uniform_refine(n) return mesh
def test_quadrangle_mesh(): from fealpy.mesh import QuadrangleMesh node = np.array( [ (0.0, 0.0), # 0 号点 (0.0, 1.0), # 1 号点 (0.0, 2.0), # 2 号点 (1.0, 0.0), # 3 号点 (1.0, 1.0), # 4 号点 (1.0, 2.0), # 5 号点 (2.0, 0.0), # 6 号点 (2.0, 1.0), # 7 号点 (2.0, 2.0), # 8 号点 ], dtype=np.float64) cell = np.array( [ (0, 3, 4, 1), # 0 号单元 (1, 4, 5, 3), # 1 号单元 (3, 6, 7, 4), # 2 号单元 (4, 7, 8, 5), # 3 号单元 ], dtype=np.int_) mesh = QuadrangleMesh(node, cell) cell2node = mesh.ds.cell_to_node() cell2edge = mesh.ds.cell_to_edge() cell2cell = mesh.ds.cell_to_cell() edge2node = mesh.ds.edge_to_node() edge2edge = mesh.ds.edge_to_edge() edge2cell = mesh.ds.edge_to_cell() node2node = mesh.ds.node_to_node() node2edge = mesh.ds.node_to_edge() node2cell = mesh.ds.node_to_cell() # 加密测试 mesh.uniform_refine()
scale=1) axes.quiver(space.ccenter[:, 0], space.ccenter[:, 1], A0[:, 0], A0[:, 1], angles='xy', scale_units='xy', scale=1) plt.show() node = np.array([(0, 0), (1, 0), (1, 1), (0, 1), (0.5, 0), (1, 0.4), (0.3, 1), (0, 0.6), (0.5, 0.45)], dtype=np.float) cell = np.array([(0, 4, 8, 7), (4, 1, 5, 8), (7, 8, 6, 3), (8, 5, 2, 6)], dtype=np.int) pde = CosCosData() mesh = QuadrangleMesh(node, cell) mesh.uniform_refine(7) space = QuadBilinearFiniteElementSpace(mesh) uI = space.interpolation(pde.solution) L2 = space.integralalg.L2_error(pde.solution, uI.value) print("L2:", L2) H1 = space.integralalg.L2_error(pde.gradient, uI.grad_value) print("H1:", H1)