示例#1
0
def get_part_from_bulk_str(name,
                           bulk_str,
                           parent,
                           instance_name=None,
                           metadata=None):
    from ada import Part

    metadata = dict(move=None, rotate=None) if metadata is None else metadata
    instance_name = name if instance_name is None else instance_name
    if instance_name is None:
        instance_name = "Temp"
    fem = FEM(name=instance_name, metadata=metadata)
    part = Part(name, fem=fem, parent=parent)
    fem._nodes = get_nodes_from_inp(bulk_str, fem)
    fem.nodes.move(move=fem.metadata["move"], rotate=fem.metadata["rotate"])
    fem._elements = get_elem_from_inp(bulk_str, fem)
    fem.elements.build_sets()
    bulk_sets = get_sets_from_bulk(bulk_str, fem)
    fem._sets = fem.sets + bulk_sets
    fem._sections = get_sections_from_inp(bulk_str, fem)
    fem._bcs += get_bcs_from_bulk(bulk_str, fem)
    fem._masses = get_mass_from_bulk(bulk_str, fem)
    fem.surfaces.update(get_surfaces_from_bulk(bulk_str, fem))
    fem._lcsys = get_lcsys_from_bulk(bulk_str, fem)
    fem._constraints = get_constraints_from_inp(bulk_str, fem)

    return part
示例#2
0
def get_fem_from_cache(cache_fem):
    node_groups = cache_fem["NODES"]
    fem = FEM(cache_fem.attrs["NAME"])
    fem._nodes = get_nodes_from_cache(node_groups, fem)
    elements = []
    for eltype, mesh in cache_fem["MESH"].items():
        el_ids = mesh["ELEMENTS"][()]
        elements += [
            Elem(el_id[0], [fem.nodes.from_id(eli)
                            for eli in el_id[1:]], eltype) for el_id in el_ids
        ]
    fem._elements = FemElements(elements, fem)

    return fem
示例#3
0
def get_nodes_and_elements(gmsh, fem=None, fem_set_name="all_elements"):
    """

    :param gmsh:
    :type gmsh: gmsh
    :param fem:
    :type fem: ada.fem.FEM
    :param fem_set_name:
    :type fem_set_name: str
    """
    from ada.fem import FEM

    fem = FEM("AdaFEM") if fem is None else fem

    nodes = list(gmsh.model.mesh.getNodes(-1, -1))
    # Get nodes
    fem._nodes = Nodes(
        [
            Node(
                [roundoff(x) for x in gmsh.model.mesh.getNode(n)[0]],
                n,
                parent=fem,
            ) for n in nodes[0]
        ],
        parent=fem,
    )

    # Get elements
    elemTypes, elemTags, elemNodeTags = gmsh.model.mesh.getElements(2, -1)
    elements = []
    for k, element_list in enumerate(elemTags):
        face, dim, morder, numv, parv, _ = gmsh.model.mesh.getElementProperties(
            elemTypes[k])
        elem_type = gmsh_map[face]
        for j, eltag in enumerate(element_list):
            nodes = []
            for i in range(numv):
                idtag = numv * j + i
                p1 = elemNodeTags[k][idtag]
                nodes.append(fem.nodes.from_id(p1))

            el = Elem(eltag, nodes, elem_type, parent=fem)
            elements.append(el)
    fem._elements = FemElements(elements, fem_obj=fem)
    femset = FemSet(fem_set_name, elements, "elset")
    fem.sets.add(femset)
示例#4
0
文件: reader.py 项目: Caladeux/adapy
def meshio_read_fem(assembly, fem_file, fem_name=None):
    """
    Import a FEM file using the meshio package.


    :param assembly: Assembly object
    :param fem_file: Path to fem file
    :param fem_name: Name of FEM model
    :type assembly: ada.Assembly
    """
    from ada import Node, Part

    from . import meshio_to_ada_type

    mesh = meshio.read(fem_file)
    name = fem_name if fem_name is not None else "Part-1"
    fem = FEM(name)

    def to_node(data):
        return Node(data[1], data[0])

    point_ids = mesh.points_id if "points_id" in mesh.__dict__.keys() else [
        i + 1 for i, x in enumerate(mesh.points)
    ]
    elem_counter = Counter(0)

    cell_ids = (mesh.cells_id if "cells_id" in mesh.__dict__.keys() else
                [[next(elem_counter) for cell in cellblock.data]
                 for cellblock in mesh.cells])
    fem._nodes = Nodes([to_node(p) for p in zip(point_ids, mesh.points)])

    cell_block_counter = Counter(-1)

    def to_elem(cellblock):
        block_id = next(cell_block_counter)
        return [
            Elem(
                cell_ids[block_id][i],
                [fem.nodes.from_id(point_ids[c]) for c in cell],
                meshio_to_ada_type[cellblock.type],
            ) for i, cell in enumerate(cellblock.data)
        ]

    fem._elements = FemElements(chain.from_iterable(map(to_elem, mesh.cells)))
    assembly.add_part(Part(name, fem=fem))
示例#5
0
def read_fem(assembly, fem_file, fem_name=None):
    """

    :param assembly:
    :param fem_file:
    :param fem_name:
    :return:
    """
    from ada import Node, Part

    f = h5py.File(fem_file, "r")

    # Mesh ensemble
    mesh_ensemble = f["ENS_MAA"]
    meshes = mesh_ensemble.keys()
    if len(meshes) != 1:
        raise ValueError("Must only contain exactly 1 mesh, found {}.".format(len(meshes)))
    mesh_name = list(meshes)[0]
    mesh = mesh_ensemble[mesh_name]

    dim = mesh.attrs["ESP"]

    fem_name = fem_name if fem_name is not None else mesh_name

    # Initialize FEM object
    fem = FEM(mesh_name)

    # Possible time-stepping
    if "NOE" not in mesh:
        # One needs NOE (node) and MAI (French maillage, meshing) data. If they
        # are not available in the mesh, check for time-steppings.
        time_step = mesh.keys()
        if len(time_step) != 1:
            raise ValueError(f"Must only contain exactly 1 time-step, found {len(time_step)}.")
        mesh = mesh[list(time_step)[0]]

    # Points
    pts_dataset = mesh["NOE"]["COO"]
    n_points = pts_dataset.attrs["NBR"]
    points = pts_dataset[()].reshape((n_points, dim), order="F")

    if "NUM" in mesh["NOE"]:
        point_num = list(mesh["NOE"]["NUM"])
    else:
        logging.warning("No node information is found on MED file")
        point_num = np.arange(1, len(points) + 1)

    fem._nodes = Nodes([Node(p, point_num[i]) for i, p in enumerate(points)], parent=fem)

    # Point tags
    tags = None
    if "FAM" in mesh["NOE"]:
        tags = mesh["NOE"]["FAM"][()]

    # Information for point tags
    point_tags = {}
    fas = mesh["FAS"] if "FAS" in mesh else f["FAS"][mesh_name]
    if "NOEUD" in fas:
        point_tags = _read_families(fas["NOEUD"])

    point_sets = _point_tags_to_sets(tags, point_tags, fem) if tags is not None else []

    # Information for cell tags
    cell_tags = {}
    if "ELEME" in fas:
        cell_tags = _read_families(fas["ELEME"])

    # CellBlock
    cell_types = []
    med_cells = mesh["MAI"]

    elements = []
    element_sets = dict()
    for med_cell_type, med_cell_type_group in med_cells.items():
        if med_cell_type == "PO1":
            logging.warning("Point elements are still not supported")
            continue

        cell_type = med_to_abaqus_type(med_cell_type)
        cell_types.append(cell_type)

        nod = med_cell_type_group["NOD"]
        n_cells = nod.attrs["NBR"]
        nodes_in = nod[()].reshape(n_cells, -1, order="F")

        if "NUM" in med_cell_type_group.keys():
            num = list(med_cell_type_group["NUM"])
        else:
            num = np.arange(0, len(nodes_in))

        element_block = [
            Elem(num[i], [fem.nodes.from_id(e) for e in c], cell_type, parent=fem) for i, c in enumerate(nodes_in)
        ]
        elements += element_block
        # Cell tags
        if "FAM" in med_cell_type_group:
            cell_data = med_cell_type_group["FAM"][()]
            cell_type_sets = _cell_tag_to_set(cell_data, cell_tags)
            for key, val in cell_type_sets.items():
                if key not in element_sets.keys():
                    element_sets[key] = []
                element_sets[key] += [element_block[i] for i in val]

    fem._elements = FemElements(elements, fem)

    elsets = []
    for name, values in element_sets.items():
        elsets.append(FemSet(name, values, "elset", parent=fem))

    fem._sets = FemSets(elsets + point_sets, fem_obj=fem)

    assembly.add_part(Part(fem_name, fem=fem))
    return