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 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) 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
import numpy as np import mpl_toolkits.mplot3d as a3 import pylab as pl from fealpy.mesh.TetrahedronMesh import TetrahedronMesh 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()
import pylab as pl from fealpy.mesh.TetrahedronMesh import TetrahedronMesh #point = np.array([ # [0, 0, 0], # [1, 0, 0], # [0, 1, 0], # [0, 0, 1]], dtype=np.float) # #cell = np.array([ # [0, 1, 2, 3]], dtype=np.int) 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) for i in range(3): angle = mesh.dihedral_angle() print("max:", np.max(angle)) print("min:", np.min(angle)) mesh.uniform_refine() ax0 = a3.Axes3D(pl.figure()) mesh.add_plot(ax0) pl.show()