def init_mesh(self, n=1, meshtype='tet'): node = np.array([[-1, -1, -1], [1, -1, -1], [1, 1, -1], [-1, 1, -1], [-1, -1, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1]], dtype=np.float) cell = np.array([[0, 1, 2, 6], [0, 5, 1, 6], [0, 4, 5, 6], [0, 7, 4, 6], [0, 3, 7, 6], [0, 2, 3, 6]], dtype=np.int) mesh = TetrahedronMesh(node, cell) mesh.uniform_refine(n) return mesh
def test_tetrahedron_mesh(): from fealpy.mesh import TetrahedronMesh node = np.array( [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]], dtype=np.float64) cell = np.array([[0, 1, 2, 3]], dtype=np.int_) mesh = TetrahedronMesh(node, cell) # 获取测试 assert id(node) == id(mesh.entity('node')) assert id(cell) == id(mesh.entity('cell')) isBdNode = mesh.ds.boundary_node_flag() assert np.all(isBdNode) isBdEdge = mesh.ds.boundary_edge_flag() assert np.all(isBdEdge) isBdFace = mesh.ds.boundary_face_flag() assert np.all(isBdFace) cell2node = mesh.ds.cell_to_node() cell2edge = mesh.ds.cell_to_edge() cell2face = mesh.ds.cell_to_face() cell2cell = mesh.ds.cell_to_cell() edge2node = mesh.ds.edge_to_node() edge2edge = mesh.ds.edge_to_edge() edge2face = mesh.ds.edge_to_face() edge2cell = mesh.ds.edge_to_cell() face2node = mesh.ds.face_to_node() face2edge = mesh.ds.face_to_edge() face2face = mesh.ds.face_to_face() face2cell = mesh.ds.face_to_cell() node2node = mesh.ds.node_to_node() node2edge = mesh.ds.node_to_edge() node2face = mesh.ds.node_to_face() node2cell = mesh.ds.node_to_cell() mesh.uniform_refine()
import matplotlib.colors as colors import pylab as pl from fealpy.mesh import TetrahedronMesh from fealpy.mesh import TriangleMesh point = np.array([[-1, -1, -1], [1, -1, -1], [1, 1, -1], [-1, 1, -1], [-1, -1, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1]], dtype=np.float) cell = np.array([[0, 1, 2, 6], [0, 5, 1, 6], [0, 4, 5, 6], [0, 7, 4, 6], [0, 3, 7, 6], [0, 2, 3, 6]], dtype=np.int) mesh = TetrahedronMesh(point, cell) mesh.uniform_refine(3) face = mesh.entity('face') isBdFace = mesh.ds.boundary_face_flag() cell = face[isBdFace] node = mesh.entity('node') NN = mesh.number_of_nodes() isBDNode = mesh.ds.boundary_node_flag() NB = np.sum(isBDNode) idxmap = np.zeros(NN, dtype=np.int32) idxmap[isBDNode] = range(NB) cell = idxmap[cell] node = node[isBDNode] trimesh = TriangleMesh(node, cell)
from fealpy.mesh import TetrahedronMesh from fealpy.mesh.simple_mesh_generator import boxmesh3d node = np.array([ [-1,-1,-1], [ 1,-1,-1], [ 1, 1,-1], [-1, 1,-1], [-1,-1, 1], [ 1,-1, 1], [ 1, 1, 1], [-1, 1, 1]], dtype=np.float) cell = np.array([ [0,1,2,6], [0,5,1,6], [0,4,5,6], [0,7,4,6], [0,3,7,6], [0,2,3,6]], dtype=np.int) mesh = TetrahedronMesh(node, cell) mesh.uniform_refine(2) mesh.print() fig = pl.figure() axes = a3.Axes3D(fig) mesh.add_plot(axes) mesh.find_node(axes, showindex=True) pl.show()