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 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 mpl_toolkits.mplot3d as a3 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]
node[flag, 2] *= 20 mesh = LagrangeHexahedronMesh(node, cell, p=1) edge = mesh.entity('edge') face = mesh.entity('face') mesh.ds.NF = len(face) mesh = reader.to_tetmesh(mesh) node = np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 0, 20], [1, 0, 20], [1, 1, 20], [0, 1, 20]], dtype=np.float) """ node = np.array([ [0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 0, 1], [1, 0, 1], [1, 1, 1], [0, 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_bisect(2) mesh.to_vtk(fname='112ew.vtu')
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()