def generateCubeMesh(): mesh_info = MeshInfo() mesh_info.set_points([ (0, 0, 0), (1, 0, 0), (1, 1, 0), (0, 1, 0), (0, 0, 1), (1, 0, 1), (1, 1, 1), (0, 1, 1), ]) mesh_info.set_facets([ [0, 1, 2, 3], [4, 5, 6, 7], [0, 4, 5, 1], [1, 5, 6, 2], [2, 6, 7, 3], [3, 7, 4, 0], ]) mesh = build(mesh_info) cellList = [] vertexList = [] mupifMesh = Mesh.UnstructuredMesh() print("Mesh Points:") for i, p in enumerate(mesh.points): print(i, p) vertexList.extend([Vertex.Vertex(i, i, p)]) print("Point numbers in tetrahedra:") for i, t in enumerate(mesh.elements): print(i, t) cellList.extend([Cell.Tetrahedron_3d_lin(mupifMesh, i, i, t)]) mupifMesh.setup(vertexList, cellList) return(mupifMesh)
def getMesh(self, cellFilter): """ Reads a mesh from Ensight file. :param tuple cellFilter: A tuple containing a list of eligible cell types (according to CellGeometryType)?? :return: mesh :rtype: Mesh """ mesh = Mesh.UnstructuredMesh() vertices = [] coords = np.zeros((3), dtype='f') for i in range(0, self.getNumberOfVertices()): coords = self.getCoords(i, coords) tuple = (coords) vertices.append(Vertex.Vertex(i, i + 1, tuple)) cells = [] for i in range(0, self.getNumberOfCells()): if (self.giveCellType(i) == 12 and self.giveCellType(i) in cellFilter): cells.append( Cell.Brick_3d_lin( mesh, i, i, (int(self.giveVertex(i, 0)), int(self.giveVertex( i, 1)), int(self.giveVertex(i, 2)), int(self.giveVertex(i, 3)), int(self.giveVertex( i, 4)), int(self.giveVertex( i, 5)), int(self.giveVertex( i, 6)), int(self.giveVertex(i, 7))))) elif (self.giveCellType(i) == 9 and self.giveCellType(i) in cellFilter): cells.append( Cell.Quad_2d_lin( mesh, i, i, (int(self.giveVertex(i, 0)), int(self.giveVertex( i, 1)), int(self.giveVertex( i, 2)), int(self.giveVertex(i, 3))))) mesh.setup(vertices, cells) return mesh
def meshgen(origin, size, nx, ny, tria=False): """ Generates a simple mesh on rectangular domain Params: origin(tuple): x,y coordinates of origin (lower left corner) size(tuple): tuple containing size in x and y directions nx(int): number of elements in x direction ny(int): number of elements in y direction tria(bool): when True, triangular mesh generated, quad otherwise """ dx = size[0] / nx dy = size[1] / ny num = 0 vertexlist = [] celllist = [] mesh = Mesh.UnstructuredMesh() # generate vertices for ix in range(nx + 1): for iy in range(ny + 1): if (debug): print("Adding vertex %d: %f %f %f " % (num, ix * dx, iy * dy, 0.0)) vertexlist.append( Vertex.Vertex(num, num, coords=(origin[0] + 1.0 * ix * dx, origin[1] + 1.0 * iy * dy, 0.0))) num = num + 1 # generate cells num = 1 for ix in range(nx): for iy in range(ny): si = iy + ix * (ny + 1) # index of lower left node if (not tria): if (debug): print("Adding quad %d: %d %d %d %d" % (num, si, si + ny + 1, si + ny + 2, si + 1)) celllist.append( Cell.Quad_2d_lin(mesh, num, num, vertices=(si, si + ny + 1, si + ny + 2, si + 1))) num = num + 1 else: if (debug): print("Adding tria %d: %d %d %d" % (num, si, si + ny + 1, si + ny + 2)) celllist.append( Cell.Triangle_2d_lin(mesh, num, num, vertices=(si, si + ny + 1, si + ny + 2))) num = num + 1 if (debug): print("Adding tria %d: %d %d %d" % (num, si, si + ny + 2, si + 1)) celllist.append( Cell.Triangle_2d_lin(mesh, num, num, vertices=(si, si + ny + 2, si + 1))) num = num + 1 mesh.setup(vertexlist, celllist) return mesh
def generateConeMesh(plot=True): x0 = 0 y0 = 0 z0 = 1 h = 1 r_bottom = 1.3 r_top = 1.5 r_scale = r_top / r_bottom rz = [(0, z0), (1, z0), (r_scale, z0 + h), (0, z0 + h)] base = [] # Create circle for theta in np.linspace(0, 2 * np.pi, 40): x = r_bottom * np.sin(theta) y = r_bottom * np.cos(theta) base.extend([(x, y)]) (points, facets, facet_holestarts, markers) = generate_extrusion(rz_points=rz, base_shape=base) if plot: p_array = np.array(points) xs = p_array[:, 0] + x0 ys = p_array[:, 1] + y0 zs = p_array[:, 2] fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter(xs, ys, zs) for f in facets: plt.plot(xs[list(f[0])], ys[list(f[0])], zs[list(f[0])]) if True: axLim = ax.get_w_lims() MAX = np.max(axLim) for direction in (-1, 1): for point in np.diag(direction * MAX * np.array([1, 1, 1])): ax.plot([point[0]], [point[1]], [np.abs(point[2])], 'w') x = [0, 0] y = [0, 0] z = [1, 1 + 0.2] plt.plot(x, y, z) plt.show() mesh_info = MeshInfo() mesh_info.set_points(points) mesh_info.set_facets_ex(facets) mesh = build(mesh_info) # print(mesh.elements) cellList = [] vertexList = [] mupifMesh = Mesh.UnstructuredMesh() for i, p in enumerate(mesh.points): p = (p[0] + x0, p[1] + y0, p[2]) vertexList.extend([Vertex.Vertex(i, i, p)]) for i, t in enumerate(mesh.elements): cellList.extend([Cell.Tetrahedron_3d_lin(mupifMesh, i, i, t)]) mupifMesh.setup(vertexList, cellList) return (mupifMesh)