def par_mesh(h, n): mesh_info = MeshInfo() # Set the vertices of the domain [0, 1]^2 mesh_info.set_points([ (0,0), (1,0), (1,1), (0,1)]) # Set the facets of the domain [0, 1]^2 mesh_info.set_facets([ [0,1], [1,2], [2,3], [3,0] ]) # Generate the tet mesh mesh = build(mesh_info, max_volume=(h)**2) node = np.array(mesh.points, dtype=np.float) cell = np.array(mesh.elements, dtype=np.int) tmesh = TriangleMesh(node, cell) # Partition the mesh cells into n parts if n > 1: edgecuts, parts = metis.part_mesh(tmesh, nparts=n, entity='node') else: NN = tmesh.number_of_nodes() parts = np.zeros(NN, dtype=np.int) tmesh.nodedata['partition'] = parts return tmesh
def load_scft_data(f): data = sio.loadmat(f) point = np.array(data['cmp_mesh']['node'][0, 0], dtype=np.float) cell = np.array(data['cmp_mesh']['elem'][0, 0] - 1, dtype=np.int) rho = np.array(data['scft']['rho'][0, 0], dtype=np.float) tri = TriangleMesh(point, cell) tri.pointData['rhoA'] = rho[1, :] return tri
def space_mesh(self, n=4): point = np.array([(0, 0), (2, 0), (4, 0), (0, 2), (2, 2), (4, 2)], dtype=np.float) cell = np.array([(3, 0, 4), (1, 4, 0), (2, 5, 1), (4, 1, 5)], dtype=np.int) mesh = TriangleMesh(point, cell) mesh.uniform_refine(n) return mesh
def lshape_mesh(r=1): point = np.array([(-1, -1), (0, -1), (-1, 0), (0, 0), (1, 0), (-1, 1), (0, 1), (1, 1)], dtype=np.float) cell = np.array([(0, 1, 3, 2), (2, 3, 6, 5), (3, 4, 7, 6)], dtype=np.int) tmesh = TriangleMesh(point, cell) if r > 0: tmesh.uniform_refine(r) return tmesh
def init_mesh(self, n=0, p=None): t = self.CircleCurve.radius c = np.sqrt(3.0) / 2.0 node = np.array( [[0.0, 0.0], [t, 0.0], [t / 2.0, c * t], [-t / 2.0, c * t], [-t, 0.0], [-t / 2.0, -c * t], [t / 2.0, -c * t]], dtype=np.float64) cell = np.array( [[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 6], [0, 6, 1]], dtype=np.int_) mesh = TriangleMesh(node, cell) for i in range(n): NN = mesh.number_of_nodes() mesh.uniform_refine() node = mesh.entity('node') self.CircleCurve.project(node[NN:]) node = mesh.entity('node') cell = mesh.entity('cell') mesh = LagrangeTriangleMesh(node, cell, p=p) isBdNode = mesh.ds.boundary_node_flag() node = mesh.entity('node') bdnode = node[isBdNode] self.CircleCurve.project(bdnode) node[isBdNode] = bdnode return mesh
def init_mesh(self, n=4, meshtype='tri', h=0.1): """ generate the initial mesh """ from meshpy.triangle import build domain = self.domain(domaintype='meshpy') mesh = build(domain, max_volume=h**2) node = np.array(mesh.points, dtype=np.float64) cell = np.array(mesh.elements, dtype=np.int_) if meshtype == 'tri': return TriangleMesh(node, cell) elif meshtype == 'polygon': mesh = TriangleMeshWithInfinityNode(TriangleMesh(node, cell)) pnode, pcell, pcellLocation = mesh.to_polygonmesh() return PolygonMesh(pnode, pcell, pcellLocation)
def uncross_mesh(self, box, n=10, r="1"): qmesh = rectangledomainmesh(box, nx=n, ny=n, meshtype='quad') node = qmesh.entity('node') cell = qmesh.entity('cell') NN = qmesh.number_of_nodes() NC = qmesh.number_of_cells() bc = qmesh.barycenter('cell') if r == "1": bc1 = np.sqrt(np.sum((bc - node[cell[:, 0], :])**2, axis=1))[0] newNode = np.r_['0', node, bc - bc1 * 0.3] elif r == "2": ll = node[cell[:, 0]] - node[cell[:, 2]] bc = qmesh.barycenter('cell') + ll / 4 newNode = np.r_['0', node, bc] newCell = np.zeros((4 * NC, 3), dtype=np.int) newCell[0:NC, 0] = range(NN, NN + NC) newCell[0:NC, 1:3] = cell[:, 0:2] newCell[NC:2 * NC, 0] = range(NN, NN + NC) newCell[NC:2 * NC, 1:3] = cell[:, 1:3] newCell[2 * NC:3 * NC, 0] = range(NN, NN + NC) newCell[2 * NC:3 * NC, 1:3] = cell[:, 2:4] newCell[3 * NC:4 * NC, 0] = range(NN, NN + NC) newCell[3 * NC:4 * NC, 1:3] = cell[:, [3, 0]] return TriangleMesh(newNode, newCell)
def nonuniform_mesh(self, box, n=10): nx = 4 * n ny = 4 * n n1 = 2 * n + 1 N = n1**2 NC = 4 * n * n node = np.zeros((N, 2)) x = np.zeros(n1, dtype=np.float) x[0::2] = range(0, nx + 1, 4) x[1::2] = range(3, nx + 1, 4) y = np.zeros(n1, dtype=np.float) y[0::2] = range(0, nx + 1, 4) y[1::2] = range(1, nx + 1, 4) node[:, 0] = x.repeat(n1) / nx node[:, 1] = np.tile(y, n1) / ny idx = np.arange(N).reshape(n1, n1) cell = np.zeros((2 * NC, 3), dtype=np.int) cell[:NC, 0] = idx[1:, 0:-1].flatten(order='F') cell[:NC, 1] = idx[1:, 1:].flatten(order='F') cell[:NC, 2] = idx[0:-1, 0:-1].flatten(order='F') cell[NC:, 0] = idx[0:-1, 1:].flatten(order='F') cell[NC:, 1] = idx[0:-1, 0:-1].flatten(order='F') cell[NC:, 2] = idx[1:, 1:].flatten(order='F') return TriangleMesh(node, cell)
def init_mesh(self, n=4, meshtype='tri', h=0.1): """ generate the initial mesh """ node = np.array([(0, 0), (1, 0), (1, 1), (0, 1)], dtype=np.float) if meshtype is 'quadtree': cell = np.array([(0, 1, 2, 3)], dtype=np.int) mesh = Quadtree(node, cell) mesh.uniform_refine(n) return mesh if meshtype is 'quad': node = np.array([(0, 0), (1, 0), (1, 1), (0, 1), (0.5, 0), (1, 0.4), (0.3, 1), (0, 0.6), (0.5, 0.45)], dtype=np.float) cell = np.array([(0, 4, 8, 7), (4, 1, 5, 8), (7, 8, 6, 3), (8, 5, 2, 6)], dtype=np.int) mesh = QuadrangleMesh(node, cell) mesh.uniform_refine(n) return mesh elif meshtype is 'tri': cell = np.array([(1, 2, 0), (3, 0, 2)], dtype=np.int) mesh = TriangleMesh(node, cell) mesh.uniform_refine(n) return mesh elif meshtype is 'stri': mesh = StructureQuadMesh([0, 1, 0, 1], h) return mesh else: raise ValueError("".format)
def init_mesh(self, n=1, meshtype='tri'): node = np.array([(0, 0), (1, 0), (1, 1), (0, 1)], dtype=np.float) if meshtype is 'tri': cell = np.array([(1, 2, 0), (3, 0, 2)], dtype=np.int) mesh = TriangleMesh(node, cell) mesh.uniform_refine(n) return mesh elif meshtype is 'quadtree': cell = np.array([(0, 1, 2, 3)], dtype=np.int) mesh = Quadtree(node, cell) mesh.uniform_refine(n) return mesh elif meshtype is 'tritree': cell = np.array([(1, 2, 0), (3, 0, 2)], dtype=np.int) mesh = Tritree(node, cell) mesh.uniform_refine(n) return mesh else: raise ValueError("I don't know the meshtype %s".format(meshtype))
def init_mesh(self, n=4, meshtype='tri', h=0.1): """ generate the initial mesh """ node = np.array([(0, -1), (1, -1), (1, 1), (0, 1)], dtype=np.float64) if meshtype == 'quadtree': cell = np.array([(0, 1, 2, 3)], dtype=np.int_) mesh = Quadtree(node, cell) mesh.uniform_refine(n) return mesh if meshtype == 'quad': node = np.array([(0, 0), (1, 0), (1, 1), (0, 1), (0.5, 0), (1, 0.4), (0.3, 1), (0, 0.6), (0.5, 0.45)], dtype=np.float64) cell = np.array([(0, 4, 8, 7), (4, 1, 5, 8), (7, 8, 6, 3), (8, 5, 2, 6)], dtype=np.int_) mesh = QuadrangleMesh(node, cell) mesh.uniform_refine(n) return mesh elif meshtype == 'tri': cell = np.array([(1, 2, 0), (3, 0, 2)], dtype=np.int_) mesh = TriangleMesh(node, cell) mesh.uniform_refine(n) # |--- to test box = [0, 1, -1, 1] mesh = MF.boxmesh2d(box, nx=10, ny=20, meshtype='tri') # |--- return mesh elif meshtype == 'halfedge': cell = np.array([(1, 2, 0), (3, 0, 2)], dtype=np.int_) mesh = TriangleMesh(node, cell) mesh = HalfEdgeMesh2d.from_mesh(mesh) mesh.uniform_refine(n) return mesh elif meshtype == 'squad': mesh = StructureQuadMesh([0, 1, 0, 1], h) return mesh else: raise ValueError("".format)
def customized_mesh(self): # node = np.load('WaveMeshNode1.npy') # cell = np.load('WaveMeshCell1.npy') print('\n') print( '# --------------------- in CapillaryWaveData code --------------------- #' ) nodename = 'WaveMeshNode1.npy' cellname = 'WaveMeshCell1.npy' # nodename = 'WaveMeshNode_mat2.npy' # cellname = 'WaveMeshCell_mat2.npy' node = np.load('./CapillaryWaveMesh/' + nodename) # WaveMeshNode_mat1 是新构造的网格 cell = np.load('./CapillaryWaveMesh/' + cellname) mesh = TriangleMesh(node, cell) print('Mesh-cell-name = %s, || Number-of-mesh-cells = %d' % (cellname, mesh.number_of_cells())) print( '# --------------------------------------------------------------------- #' ) return mesh
def local_mesh(tmesh, rank): NN = tmesh.number_of_nodes() parts = tmesh.nodedata['partition'] cell = tmesh.entity('cell') node = tmesh.entity('node') flag = np.sum(parts[cell] == rank, axis=1) > 0 cell0 = cell[flag] isLocalNode = np.zeros(NN, dtype=np.bool) isLocalNode[cell0] = True node0 = node[isLocalNode] gid, = np.nonzero(isLocalNode) # build the idx map from global to local NN0 = np.sum(isLocalNode) idxMap = np.zeros(NN, dtype=np.int) idxMap[isLocalNode] = range(NN0) cell0 = idxMap[cell0] lmesh = TriangleMesh(node0, cell0) lmesh.nodedata['partition'] = parts[isLocalNode] lmesh.nodedata['global_id'] = gid lmesh.global2local = idxMap lmesh.neighbor = set(parts[isLocalNode]) - {rank} return lmesh
def fishbone(self, box, n=10): qmesh = rectangledomainmesh(box, nx=n, ny=n, meshtype='quad') node = qmesh.entity('node') cell = qmesh.entity('cell') NC = qmesh.number_of_cells() isLeftCell = np.zeros((n, n), dtype=np.bool) isLeftCell[0::2, :] = True isLeftCell = isLeftCell.reshape(-1) lcell = cell[isLeftCell] rcell = cell[~isLeftCell] newCell = np.r_['0', lcell[:, [1, 2, 0]], lcell[:, [3, 0, 2]], rcell[:, [0, 1, 3]], rcell[:, [2, 3, 1]]] return TriangleMesh(node, newCell)
def init_mesh(self, n=4, meshtype='tri'): if meshtype == 'tri': node = np.array([(0, -1), (-1, 0), (0, 0), (1, 0), (1, 0), (0, 1)], dtype=np.float64) cell = np.array([(2, 1, 0), (2, 0, 3), (2, 5, 1), (2, 4, 5)], dtype=np.int_) mesh = TriangleMesh(node, cell) mesh.uniform_refine(n) return mesh elif meshtype == 'quadtree': r = 1 - 2**(1 / 2) / 2 a = 1 / 2 - 2**(1 / 2) / 2 rr = 1 / 2 node = np.array([(0, -1), (-rr, -rr), (rr, -rr), (-r, -r), (0, -r), (r, -r), (-1, 0), (-r, 0), (0, 0), (r, 0), (1, 0), (r, 0), (-r, r), (0, r), (r, r), (-rr, rr), (rr, rr), (0, 1)], dtype=np.float64) cell = np.array([(0, 4, 3, 1), (2, 5, 4, 0), (1, 3, 7, 6), (3, 4, 8, 7), (4, 5, 9, 8), (5, 2, 10, 9), (6, 7, 12, 15), (7, 8, 13, 12), (8, 11, 14, 13), (11, 10, 16, 14), (12, 13, 17, 15), (13, 14, 16, 17)], dtype=np.int_) mesh = Quadtree(node, cell) mesh.uniform_refine(n) return mesh elif meshtype == 'tritree': node = np.array([(0, -1), (-1, 0), (0, 0), (1, 0), (1, 0), (0, 1)], dtype=np.float64) cell = np.array([(2, 1, 0), (2, 0, 3), (2, 5, 1), (2, 4, 5)], dtype=np.int_) mesh = Tritree(node, cell) mesh.uniform_refine(n) return mesh else: raise ValueError("I don't know the meshtype %s".format(meshtype))
def init_mesh(self, n=4, meshtype='quadtree', h=0.1, nx=10, ny=10): point = np.array([(-1, -1), (1, -1), (1, 1), (-1, 1)], dtype=np.float64) if meshtype == 'quadtree': cell = np.array([(0, 1, 2, 3)], dtype=np.int_) mesh = Quadtree(point, cell) mesh.uniform_refine(n) return mesh elif meshtype == 'tri': cell = np.array([(1, 2, 0), (3, 0, 2)], dtype=np.int_) mesh = TriangleMesh(point, cell) mesh.uniform_refine(n) return mesh elif meshtype == 'stri': mesh = StructureQuadMesh([0, 1, 0, 1], nx, ny) return mesh else: raise ValueError("".format)
def init_mesh(self, n=4, meshtype='tri', h=0.1): """ generate the initial mesh """ node = np.array([(0, 0), (1, 0), (1, 1), (0, 1)], dtype=np.float64) if meshtype == 'quadtree': cell = np.array([(0, 1, 2, 3)], dtype=np.int_) mesh = Quadtree(node, cell) mesh.uniform_refine(n) return mesh elif meshtype == 'tri': cell = np.array([(1, 2, 0), (3, 0, 2)], dtype=np.int_) mesh = TriangleMesh(node, cell) mesh.uniform_refine(n) return mesh elif meshtype == 'stri': mesh = StructureQuadMesh([0, 1, 0, 1], h) return mesh else: raise ValueError("".format)
def init_mesh(self, n=4, meshtype='tri'): node = np.array([(-1, -1), (0, -1), (1, -1), (-1, 0), (0, 0), (1, 0), (-1, 1), (0, 1), (1, 1)], dtype=np.float) if meshtype is 'tri': cell = np.array([(1, 4, 0), (3, 0, 4), (4, 1, 5), (2, 5, 1), (4, 7, 3), (6, 3, 7), (7, 4, 8), (5, 8, 4)], dtype=np.int) mesh = TriangleMesh(node, cell) mesh.uniform_refine(n) elif meshtype is 'quadtree': cell = np.array([(0, 1, 4, 3), (1, 2, 5, 4), (3, 4, 7, 6), (4, 5, 8, 7)], dtype=np.int) mesh = Quadtree(node, cell) mesh.uniform_refine(n) else: raise ValueError("".format) return mesh
def cross_mesh(self, box, n=10): qmesh = rectangledomainmesh(box, nx=n, ny=n, meshtype='quad') node = qmesh.entity('node') cell = qmesh.entity('cell') NN = qmesh.number_of_nodes() NC = qmesh.number_of_cells() bc = qmesh.barycenter('cell') newNode = np.r_['0', node, bc] newCell = np.zeros((4 * NC, 3), dtype=np.int) newCell[0:NC, 0] = range(NN, NN + NC) newCell[0:NC, 1:3] = cell[:, 0:2] newCell[NC:2 * NC, 0] = range(NN, NN + NC) newCell[NC:2 * NC, 1:3] = cell[:, 1:3] newCell[2 * NC:3 * NC, 0] = range(NN, NN + NC) newCell[2 * NC:3 * NC, 1:3] = cell[:, 2:4] newCell[3 * NC:4 * NC, 0] = range(NN, NN + NC) newCell[3 * NC:4 * NC, 1:3] = cell[:, [3, 0]] return TriangleMesh(newNode, newCell)
def mesh2dpy(mesh_info, h, n): mesh = build(mesh_info, max_volume=(h)**2) point = np.array(mesh.points, dtype=np.float) cell = np.array(mesh.elements, dtype=np.int) tmesh = TriangleMesh(point, cell) edgecuts, parts = metis.part_mesh(tmesh, nparts=n, entity='cell') 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, 'Edge': edge + 1, 'Elem': cell + 1, 'Edge2Elem': edge2cell + 1, 'isBdPoint': isBdPoint, 'Partitions': parts + 1 } result = sio.matlab.savemat('test' + str(n) + 'parts' + str(h) + '.mat', data) return result
import sys import numpy as np import matplotlib.pyplot as plt from fealpy.mesh.TriangleMesh import TriangleMesh, TriangleMeshDataStructure node = 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(node, cell) tmesh.uniform_refine(1) node = tmesh.node cell = tmesh.entity('cell') print(tmesh.ds.node_to_cell()) N = node.shape[0] tmeshstrcture = TriangleMeshDataStructure(N, cell) fig = plt.figure() axes = fig.gca() tmesh.add_plot(axes) tmesh.find_node(axes, showindex=True) tmesh.find_edge(axes, showindex=True) tmesh.find_cell(axes, showindex=True) plt.show()
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()
def customized_mesh(self): # box = self.box # mesh = MF.boxmesh2d(box, nx=10, ny=20, meshtype='tri') # mesh = HalfEdgeMesh2d.from_mesh(mesh, NV=3) # 三角形网格的单边数据结构 cell = np.array( [[0, 1, 3], [4, 3, 1], [4, 1, 5], [2, 5, 1], [6, 3, 7], [4, 7, 3], [4, 5, 7], [8, 7, 5], [6, 7, 9], [10, 9, 7], [10, 7, 11], [8, 11, 7], [12, 9, 13], [10, 13, 9], [10, 11, 13], [14, 13, 11]], dtype=np.int) node = np.array([[0, -1], [0.5, -1], [1, -1], [0, -0.5], [0.5, -0.5], [1, -0.5], [0, 0], [0.5, 0], [1, 0], [0, 0.5], [0.5, 0.5], [1, 0.5], [0, 1], [0.5, 1], [1, 1]], dtype=np.float) mesh = TriangleMesh(node, cell) mesh = HalfEdgeMesh2d.from_mesh(mesh, NV=3) mesh.uniform_refine(2) cm = 1. tt = 0.2 while cm > 0.01 / 2: bc = mesh.cell_barycenter() NC = mesh.number_of_cells() cellstart = mesh.ds.cellstart isMarkedCell = np.zeros(NC + cellstart, dtype=np.bool_) isMarkedCell[cellstart:] = abs(bc[:, 1] - 0.) < tt mesh.refine_triangle_rg(isMarkedCell) cm = np.sqrt(np.min(mesh.entity_measure('cell'))) if tt > 0.025: tt = tt / 2. # |--- 下面做一下网格结构的转换, 因为目前 HalfEdgeMesh2d 对 p>1 时有 bug mesh = TriangleMesh(mesh.node, mesh.entity('cell')) return mesh
import sys import numpy as np import matplotlib.pyplot as plt 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)
from scipy.spatial import Delaunay pde = CosCosData() maxit = 5 h = 0.2 box = [0, 1, 0, 1] pfix = np.array([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]], dtype=np.float) fd = lambda p: drectangle(p, box) pmesh = distmesh2d(fd, h, box, pfix, meshtype='polygon') area = pmesh.entity_measure('cell') node = pmesh.entity('node') t = Delaunay(node) tmesh = TriangleMesh(node, t.simplices.copy()) area = tmesh.entity_measure('cell') tmesh.delete_cell(area < 1e-8) area = tmesh.entity_measure('cell') print(len(tmesh.node)) pmesh = PolygonMesh.from_mesh(tmesh) print(pmesh.ds.cell) fig = plt.figure() axes = fig.gca() pmesh.add_plot(axes) #mesh.find_node(axes, showindex=True) plt.show() Ndof = np.zeros((maxit, ), dtype=np.int) errorType = [
from fealpy.mesh.TriangleMesh import TriangleMesh from fealpy.mesh.Tritree import Tritree node = 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(node, cell) mesh.uniform_refine(1) node = mesh.entity('node') cell = mesh.entity('cell') tmesh = Tritree(node, cell) isLeafCell = tmesh.is_leaf_cell() flag = (np.sum(cell == 0, axis=1) == 5) & isLeafCell idx, = np.where(flag) for i in range(2): tmesh.refine(idx) tmesh.coarsen(idx) fig = plt.figure() axes = fig.gca() tmesh.add_plot(axes) #tmesh.find_node(axes, showindex=True) #tmesh.find_edge(axes, showindex=True)
aa = np.arange(0, 1, measure) - measure / 2. current_cell = [] for k in range(len(aa) - 1): aa_m = aa[k + 1] flag = (abs(cb_x - aa_m) < 1.e-8) & outflag current_cell_temp, = np.nonzero(flag) current_cell.append(current_cell_temp) the_cell = np.array(current_cell) return the_cell.flatten() print(os.getcwd()) mfile = loadmat('./CapillaryWaveMesh_4.mat') node = mfile['node'] cell = mfile['elem'] mesh = TriangleMesh(node, cell) mesh = HalfEdgeMesh2d.from_mesh(mesh, NV=3) # cell = np.array([[0, 1, 3], [4, 3, 1], [4, 1, 5], [2, 5, 1], # [6, 3, 7], [4, 7, 3], [4, 5, 7], [8, 7, 5], # [6, 7, 9], [10, 9, 7], [10, 7, 11], [8, 11, 7], # [12, 9, 13], [10, 13, 9], [10, 11, 13], [14, 13, 11]], dtype=np.int) # node = np.array([[0, -1], [0.5, -1], [1, -1], # [0, -0.5], [0.5, -0.5], [1, -0.5], # [0, 0], [0.5, 0], [1, 0], # [0, 0.5], [0.5, 0.5], [1, 0.5], # [0, 1], [0.5, 1], [1, 1]], dtype=np.float) # mesh = TriangleMesh(node, cell) # mesh = HalfEdgeMesh2d.from_mesh(mesh, NV=3) # # fig = plt.figure() # # axes = fig.gca()
verts2, segs2, m2 = corner(x2, y2, 3) verts3 = np.array([ [0.004, 0.025], [0.004, 0.035] ]) segs3 = np.array([[0, 1]], dtype=np.int32) m3= np.array([[4]]) verts = np.concatenate([verts0, verts1, verts2, verts3], axis=0) segs = np.concatenate([segs0, segs1+4, segs2+8, segs3+12], axis=0) marker = np.concatenate([m0, m1, m2, m3], axis=0) plsg = {'segments':segs, 'vertices':verts, 'segment_markers':marker} t = triangle.triangulate(plsg, 'pq30a0.000004') tmesh = TriangleMesh(t['vertices'], t['triangles']) tmesh.uniform_refine() data = { 'node':tmesh.point, 'elem':tmesh.ds.cell + 1, 'node_marker': t['vertex_markers'] } sio.matlab.savemat('trimesh', data) #plot.plot(plt.axes(), **t) #plt.show() fig = plt.figure() axes = fig.gca()
def mesh_2dpy(mesh_info, h): mesh = build(mesh_info, max_volume=(h)**2) point = np.array(mesh.points, dtype=np.float) cell = np.array(mesh.elements, dtype=np.int) tmesh = TriangleMesh(point, cell) return tmesh
def refine_marker(self, tmesh): cell = tmesh.entity('cell') isLeafCell = tmesh.is_leaf_cell() flag = (np.sum(cell == 0, axis=1) == 1) & isLeafCell idx, = np.where(flag) return idx def coarsen_marker(self, qtmesh): pass node = np.array([(0, 0.5), (0.865, 0), (1.73, 0.5), (0.865, 1)], dtype=np.float) cell = np.array([(1, 2, 3), (3, 0, 1)], dtype=np.int) tmesh = TriangleMesh(node, cell) tmesh.uniform_refine(0) node = tmesh.entity('node') cell = tmesh.entity('cell') tritree = Tritree(node, cell, irule=1) marker = AdaptiveMarker() for i in range(1): tritree.refine(marker) a = np.array([2, 4], dtype=np.int) fig = plt.figure() axes = fig.gca() tritree.add_plot(axes) #tritree.find_node(axes, showindex=True)