import sys import numpy as np import matplotlib.pyplot as plt from fealpy.mesh.TriangleMesh import TriangleMesh, TriangleMeshDataStructure node = np.array([(0, 0), (1, 0), (1, 1), (0, 1)], dtype=np.float) cell = np.array([(1, 2, 0), (3, 0, 2)], dtype=np.int) tmesh = TriangleMesh(node, cell) tmesh.uniform_refine(1) node = tmesh.node cell = tmesh.entity('cell') print(tmesh.ds.node_to_cell()) N = node.shape[0] tmeshstrcture = TriangleMeshDataStructure(N, cell) fig = plt.figure() axes = fig.gca() tmesh.add_plot(axes) tmesh.find_node(axes, showindex=True) tmesh.find_edge(axes, showindex=True) tmesh.find_cell(axes, showindex=True) plt.show()
[1,1], [0,1]], dtype=np.float) cell = np.array([[1, 2, 0], [3, 0, 2]], dtype=np.int) mesh = TriangleMesh(point, cell) V = LagrangeFiniteElementSpace(mesh, degree) bc = np.array([(0.1, 0.2, 0.7), (0.3, 0.4, 0.3)]) for b in bc: print(V.basis(b)) #print(V.basis_einsum(bc)) ipoints = V.interpolation_points() cell2dof = V.cell_to_dof() fig, axes = plt.subplots(1, 3) mesh.add_plot(axes[0]) mesh.find_node(axes[0], node=ipoints, showindex=True) for ax in axes.reshape(-1)[1:]: ax.axis('tight') ax.axis('off') axes[1].table(cellText=cell, rowLabels=['0:', '1:'], loc='center', fontsize=100) axes[1].set_title('cell', y=0.7) axes[2].table(cellText=cell2dof, rowLabels=['0:', '1:'], loc='center', fontsize=100) axes[2].set_title('cell2dof', y=0.6) plt.tight_layout(pad=1, w_pad=1, h_pad=1.0) plt.show()
cell[:NC,2] = sign[0:-1,0:-1].flatten() cell[NC:,0] = sign[1:,0:-1].flatten()#每个小正方形上面的小三角形 cell[NC:,1] = sign[0:-1,0:-1].flatten() cell[NC:,2] = sign[1:,1:].flatten() print(node) print(cell) # In[5]: from fealpy.mesh.TriangleMesh import TriangleMesh import matplotlib.pyplot as plt get_ipython().run_line_magic('matplotlib', 'inline') tmesh = TriangleMesh(node, cell) fig, axes = plt.subplots(1, 3,figsize=(15,15)) tmesh.add_plot(axes[0]) tmesh.find_node(axes[0], showindex=True, markersize=20, fontsize=20) tmesh.find_cell(axes[0], showindex=True, markersize=15, fontsize=15) axes[0].set_title('mesh') for ax in axes.reshape(-1)[1:]: ax.axis('tight') ax.axis('off') axes[1].table(cellText=node, rowLabels=np.arange(NN), loc='center') axes[1].set_title('node', y=0.2) axes[2].table(cellText=cell, rowLabels=np.arange(2*NC), loc='center') axes[2].set_title('cell', y=0.9) plt.tight_layout(pad=0.4, w_pad=1, h_pad=1.0) plt.show()
tmesh = TriangleMesh(point, cell) # Partition the mesh cells into n parts edgecuts, parts = metis.part_mesh(tmesh, nparts=n, entity='cell', contig=True) 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 } sio.matlab.savemat('test' + str(n) + 'parts' + str(h) + '.mat', data) fig = plt.figure() axes = fig.gca() tmesh.add_plot(axes, cellcolor='w') tmesh.find_node(axes, color=parts, markersize=20) fig.savefig('test.pdf') plt.show()