Пример #1
0
def discretise_mesh(mesh, layer, target, min_angle=15, factor=1):
    """ Discretise a mesh from an input triangulated coarse mesh into small denser meshes.

    Parameters
    ----------
    mesh : guid
        The guid of the Rhino input mesh.
    layer : str
        Layer name to draw results.
    target : float
        Target length of each triangle.
    min_angle : float
        Minimum internal angle of triangles.
    factor : float
        Factor on the maximum area of each triangle.

    Returns
    -------
    None

    """

    rhinomesh = RhinoMesh(mesh)
    vertices = rhinomesh.get_vertex_coordinates()
    faces = [face[:3] for face in rhinomesh.get_face_vertices()]

    try:

        points, tris = meshing.discretise_faces(vertices=vertices,
                                                faces=faces,
                                                target=target,
                                                min_angle=min_angle,
                                                factor=factor)

        rs.CurrentLayer(rs.AddLayer(layer))
        rs.DeleteObjects(rs.ObjectsByLayer(layer))
        rs.EnableRedraw(False)

        for pts, tri in zip(points, tris):
            mesh_faces = []

            for i in tri:
                face_ = i + [i[-1]]
                mesh_faces.append(face_)
            rs.AddMesh(pts, mesh_faces)

        rs.EnableRedraw(True)

    except:

        print('***** Error using MeshPy (Triangle) or drawing faces *****')
Пример #2
0
def add_tets_from_mesh(structure,
                       name,
                       mesh,
                       draw_tets=False,
                       volume=None,
                       layer='Default',
                       acoustic=False,
                       thermal=False):
    """ Adds tetrahedron elements from a Rhino mesh to the Structure object.

    Parameters
    ----------
    structure : obj
        Structure object to update.
    name : str
        Name for the element set of tetrahedrons.
    mesh : obj
        The Rhino mesh representing the outer surface.
    draw_tets : bool
        Draw the generated tetrahedrons.
    volume : float
        Maximum volume for each tet.
    layer : str
        Layer to draw tetrahedrons if draw_tets=True.
    acoustic : bool
        Acoustic properties on or off.
    thermal : bool
        Thermal properties on or off.

    Returns
    -------
    None
        Nodes and elements are updated in the Structure object.

    """

    rhinomesh = RhinoMesh(mesh)
    vertices = rhinomesh.get_vertex_coordinates()
    faces = [face[:3] for face in rhinomesh.get_face_vertices()]

    basedir = utilities.__file__.split('__init__.py')[0]
    xfunc = XFunc('tets', basedir=basedir, tmpdir=structure.path)
    xfunc.funcname = 'functions.tets_from_vertices_faces'

    try:
        tets_points, tets_elements = xfunc(vertices=vertices,
                                           faces=faces,
                                           volume=volume)

        for point in tets_points:
            structure.add_node(point)

        ekeys = []
        for element in tets_elements:
            nodes = [
                structure.check_node_exists(tets_points[i]) for i in element
            ]
            ekey = structure.add_element(nodes=nodes,
                                         type='TetrahedronElement',
                                         acoustic=acoustic,
                                         thermal=thermal)
            ekeys.append(ekey)
        structure.add_set(name=name, type='element', selection=ekeys)

        if draw_tets:
            rs.EnableRedraw(False)
            rs.DeleteObjects(rs.ObjectsByLayer(layer))
            rs.CurrentLayer(layer)
            tet_faces = [[0, 2, 1, 1], [1, 2, 3, 3], [1, 3, 0, 0],
                         [0, 3, 2, 2]]
            for i, points in enumerate(tets_elements):
                xyz = [tets_points[j] for j in points]
                rs.AddMesh(vertices=xyz, face_vertices=tet_faces)
        rs.EnableRedraw(True)

    except:
        print('***** Error using MeshPy or drawing Tets *****')
Пример #3
0
def add_tets_from_mesh(structure,
                       name,
                       mesh,
                       draw_tets=False,
                       volume=None,
                       thermal=False):
    """ Adds tetrahedron elements from a mesh in Rhino to the Structure object.

    Parameters
    ----------
    structure : obj
        Structure object to update.
    name : str
        Name for the element set of tetrahedrons.
    mesh : guid
        The mesh in Rhino representing the outer surface.
    draw_tets : str
        Layer to draw tetrahedrons on.
    volume : float
        Maximum volume for each tet.
    thermal : bool
        Thermal properties on or off.

    Returns
    -------
    None

    """

    rhinomesh = RhinoMesh(mesh)
    vertices = rhinomesh.get_vertex_coordinates()
    faces = [face[:3] for face in rhinomesh.get_face_vertices()]

    try:
        tets_points, tets_elements = meshing.tets_from_vertices_faces(
            vertices=vertices, faces=faces, volume=volume)

        for point in tets_points:
            structure.add_node(point)

        ekeys = []

        for element in tets_elements:

            nodes = [
                structure.check_node_exists(tets_points[i]) for i in element
            ]
            ekey = structure.add_element(nodes=nodes,
                                         type='TetrahedronElement',
                                         thermal=thermal)
            ekeys.append(ekey)

        structure.add_set(name=name, type='element', selection=ekeys)

        if draw_tets:

            rs.EnableRedraw(False)
            rs.DeleteObjects(rs.ObjectsByLayer(draw_tets))
            rs.CurrentLayer(draw_tets)

            tet_faces = [[0, 2, 1, 1], [1, 2, 3, 3], [1, 3, 0, 0],
                         [0, 3, 2, 2]]

            for i, points in enumerate(tets_elements):

                xyz = [tets_points[j] for j in points]
                rs.AddMesh(vertices=xyz, face_vertices=tet_faces)

            rs.EnableRedraw(True)

        print('***** MeshPy (TetGen) successfull *****')

    except:

        print('***** Error using MeshPy (TetGen) or drawing Tets *****')