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()
tmesh = TriangleMesh(point, cell) # Partition the mesh cells into n parts edgecuts, parts = metis.part_mesh(tmesh, nparts=n, entity='point') point = tmesh.point edge = tmesh.ds.edge cell = tmesh.ds.cell cell2edge = tmesh.ds.cell_to_edge() edge2cell = tmesh.ds.edge_to_cell() isBdPoint = tmesh.ds.boundary_point_flag() data = { 'Point': point, 'Face': edge + 1, 'Elem': cell + 1, 'Edge2Elem': edge2cell + 1, 'isBdPoint': isBdPoint, '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_point(axes, color=parts, markersize=20) fig.savefig('test.pdf') plt.show()
from fealpy.functionspace.tools import function_space from fealpy.mesh.TriangleMesh import TriangleMesh degree = int(sys.argv[1]) 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) mesh = TriangleMesh(point, cell) V = function_space(mesh, 'Lagrange', degree) ipoints = V.interpolation_points() cell2dof = V.cell_to_dof() fig, axes = plt.subplots(1, 3) mesh.add_plot(axes[0]) mesh.find_point(axes[0], point=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)
from fealpy.functionspace import LagrangeFiniteElementSpace from fealpy.mesh.TriangleMesh import TriangleMesh degree = 4 point = np.array([[0, 0], [1, 0], [1 / 2, np.sqrt(3) / 2]], dtype=np.float) cell = np.array([[0, 1, 2]], dtype=np.int) mesh = TriangleMesh(point, cell) fig = plt.figure() axes = fig.gca() axes.set_aspect('equal') axes.set_axis_off() mesh.add_plot(axes, cellcolor='w', linewidths=2) mesh.find_point(axes, showindex=True, color='k', fontsize=20, markersize=25) V = LagrangeFiniteElementSpace(mesh, degree) ldof = V.number_of_local_dofs() ipoints = V.interpolation_points() cell2dof = V.dof.cell2dof[0] ipoints = ipoints[cell2dof] d = Delaunay(ipoints) mesh2 = TriangleMesh(ipoints, d.simplices) fig = plt.figure() axes = fig.gca() axes.set_aspect('equal') axes.set_axis_off() edge = mesh2.ds.edge