def init_mesh(self, n=9, 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) for i in range(n): mesh.bisect() NN = mesh.number_of_nodes() node = mesh.entity('node') cell = mesh.entity('cell') bc = mesh.entity_barycenter('cell') isDelCell = ((bc[:, 0] > 0) & (bc[:, 1] < 0)) cell = cell[~isDelCell] isValidNode = np.zeros(NN, dtype=np.bool) isValidNode[cell] = True node = node[isValidNode] idxMap = np.zeros(NN, dtype=mesh.itype) idxMap[isValidNode] = range(isValidNode.sum()) cell = idxMap[cell] mesh = TetrahedronMesh(node, cell) 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()
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) data = {'node': trimesh.node, 'elem': trimesh.ds.cell + 1}