示例#1
0
    def __init__(self, smesh):
        Mesh.__init__(self)
        if isinstance(smesh, SMesh.Mesh):
            self.smesh = smesh
        else:
            raise TypeError('smesh must be of type simphony mesh class')



        # establish mappig between integer numbering and uuids
        self._vertexUUIDMap = {}
        self._cellUUIDMap = {}
        i = 1
        for point in self.smesh._iter_points():
            self._vertexUUIDMap[i] = point.uid
            i = i+1
        # process cells (edges, faces, cells):
        i = 1
        for edge in self.smesh._iter_edges():
            self._cellUUIDMap[i] = edge.uid
            i = i+1
        for face in self.smesh._iter_faces():
            self._cellUUIDMap[i] = face.uid
            i = i+1
        for cell in self.smesh._iter_cells():
            self._cellUUIDMap[i] = cell.uid
            i = i+1            
示例#2
0
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)
示例#3
0
    def _getMesh(self):
        '''Return mesh object from the model. Called internally from makeField, and the result will be re-used for multiple fields.

        :return: Mesh
        :rtype: mupif.Mesh.UnstructuredMesh
        '''
        if self.mesh: return self.mesh

        dom = self.domain
        self.mesh = Mesh.UnstructuredMesh()
        verts, cells = [], []

        # vertices
        for dn in range(1, dom.giveNumberOfDofManagers() + 1):
            dof = dom.giveDofManager(dn)
            cc = dof.giveCoordinates()
            assert len(cc) in (1, 2, 3)  # 1D, 2D, 3D
            verts.append(tuple([cc[i] for i in range(len(cc))]))
            # note: seems that the previous line should read
            # verts.append(Vertex.Vertex(dn-1, dof.giveLabel(), tuple([cc[i] for i in range(len(cc))])))
        # cells
        for en in range(1, dom.giveNumberOfElements() + 1):
            elt = dom.giveElement(en)
            gt = elt.giveGeometryType()
            eltType = elementTypeMap.get(
                gt)  # mupif class which will be instantiated
            if not eltType:
                raise ValueError(
                    'Element type %s not mapped to any mupif cell type.' %
                    (str(gt)))
            # convert to 0-based indices
            vv = tuple([
                elt.giveDofManager(n) - 1
                for n in range(1, elt.numberOfDofManagers + 1)
            ])
            cells.append(
                eltType(mesh=self.mesh,
                        number=en - 1,
                        label=en - 1,
                        vertices=vv))
        # build mesh, cache it and return
        self.mesh.setup(verts, cells)
        return self.mesh
示例#4
0
    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
示例#5
0
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
示例#6
0
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)