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()
import sys import numpy as np import matplotlib.pyplot as plt from fealpy.mesh.TriangleMesh import TriangleMesh point = 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(point, cell) fig = plt.figure() axes = fig.gca() tmesh.add_plot(axes) tmesh.find_point(axes, showindex=True) tmesh.find_edge(axes, showindex=True) tmesh.find_cell(axes, showindex=True) plt.show()
mesh_info = MeshInfo() mesh_info.set_points([(0, 0), (1, 0), (1, 1), (0, 1)]) mesh_info.set_facets([[0, 1], [1, 2], [2, 3], [3, 0]]) h = 0.05 mesh = build(mesh_info, max_volume=h**2) node = np.array(mesh.points, dtype=np.float) cell = np.array(mesh.elements, dtype=np.int) NC = cell.shape[0] n = NC // size r = NC % size elmdist = np.zeros(size + 1, dtype=np.int) elmdist[1:] = n elmdist[1:r + 1] += 1 elmdist = np.add.accumulate(elmdist) eptr = np.arange(0, 3 * (elmdist[rank + 1] - elmdist[rank] + 1), 3) eind = cell[elmdist[rank]:elmdist[rank + 1]].flatten() edgecuts, part = pyparmetis.part_mesh(5, elmdist, eptr, eind, comm) tmesh = TriangleMesh(node, cell) tmesh.celldata['cell_process_id'] = part fig = plt.figure() axes = fig.gca() tmesh.add_plot(axes, cellcolor='w', markersize=200) tmesh.find_cell(axes, color=tmesh.celldata['cell_process_id']) plt.show()