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
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