def findStructElemIDs(elefile, structNodeIDs): """find elements that contain nodes in structNodeIDs :param str elefile: element filename :param structNodeIDs: numpy array :returns: (elems, structElemIds) """ from fem.mesh.fem_mesh import load_elems elems = load_elems(elefile) structElemIDs = {} for i in elems: # TODO: optimize this mess of nested loops j = i.tolist() insideStruct = any(x in structNodeIDs for x in j[2:10]) if insideStruct: structElemIDs[i[0]] = True if len(structElemIDs) == 0: from sys import exit exit('ERROR: no structure elements were found') return (elems, structElemIDs)
def findStructElemIDs(elefile, structNodeIDs): """find elements that contain nodes in structNodeIDs Args: elefile (str): element filename structNodeIDs: elefile: structNodeIDs: Returns: (elems, structElemIds) """ from fem.mesh.fem_mesh import load_elems import sys elems = load_elems(elefile) structElemIDs = {} for i in elems: # TODO: optimize this mess of nested loops j = i.tolist() insideStruct = any(x in structNodeIDs for x in j[2:10]) if insideStruct: structElemIDs[i[0]] = True if len(structElemIDs) == 0: logger.warning("No structure elements were found.") sys.exit() return (elems, structElemIDs)
def sorted_elems(nodeIDcoords): """create sorted elements numpy array from nodes.dyn & elems.dyn :returns: sorted_elems """ from fem.mesh.fem_mesh import load_elems from fem.mesh.fem_mesh import SortElems from fem.mesh.fem_mesh import SortNodeIDs elems = load_elems(testPath / "elems.dyn") [snic, axes] = SortNodeIDs(nodeIDcoords, sort=False) sorted_elems = SortElems(elems, axes) return sorted_elems
def apply_pml(pml_elems, face_constraints, edge_constraints, nodefile="nodes.dyn", elefile="elems.dyn", pmlfile="elems_pml.dyn", bcfile="bc.dyn", pml_partID=2): """ driver function to apply PML boundary conditions :param pml_elems: 3x2 array of ints specifying thickness of PML elements (5--10) on each PML layer :param face_constraints: 3x2 array of strings, specifying the BCs on each face (3), min/max (2) :param edge_constraints: 1x6 vector of BCs on each edge :param nodefile: default - 'nodes.dyn' :param elefile: default - 'elems.dyn' :param pmlfile: default - 'elems_pml.dyn' :param bcfile: 'defauly - 'bc.dyn' :param pml_partID: default - 2 :return: """ from fem.mesh import fem_mesh nodeIDcoords = fem_mesh.load_nodeIDs_coords(nodefile) [snic, axes] = fem_mesh.SortNodeIDs(nodeIDcoords) elems = fem_mesh.load_elems(elefile) sorted_elems = fem_mesh.SortElems(elems, axes) sorted_pml_elems = assign_pml_elems(sorted_elems, pml_elems, pml_partID) write_pml_elems(sorted_pml_elems, pmlfile) bcdict = assign_node_constraints(snic, axes, face_constraints) bcdict = constrain_sym_pml_nodes(bcdict, snic, axes, pml_elems, edge_constraints) bcdict = assign_edge_sym_constraints(bcdict, snic, axes, edge_constraints) write_bc(bcdict, bcfile) return 0
def apply_pml(pml_elems, face_constraints, edge_constraints, nodefile="nodes.dyn", elefile="elems.dyn", pmlfile="elems_pml.dyn", bcfile="bc.dyn", pml_partID=2): """driver function to apply PML boundary conditions Args: pml_elems (str): 3x2 array of ints specifying thickness of PML elements (5--10) on each PML layer face_constraints: 3x2 array of strings, specifying the BCs on each face (3), min/max (2) edge_constraints (str): 1x6 vector of BCs on each edge nodefile (str): default - input file for the node definitions elefile (str): default - input file for the element definitions pmlfile (str): output file for the elements w/ PMLs bcfile (str): output file for the boundary conditions pml_partID (int): PID for the PML elements """ import fem.mesh.fem_mesh as fem_mesh nodeIDcoords = fem_mesh.load_nodeIDs_coords(nodefile) [snic, axes] = fem_mesh.SortNodeIDs(nodeIDcoords) elems = fem_mesh.load_elems(elefile) sorted_elems = fem_mesh.SortElems(elems, axes) sorted_pml_elems = assign_pml_elems(sorted_elems, pml_elems, pml_partID) write_pml_elems(sorted_pml_elems, pmlfile) bcdict = assign_node_constraints(snic, axes, face_constraints) bcdict = constrain_sym_pml_nodes(bcdict, snic, axes, pml_elems, edge_constraints) bcdict = assign_edge_sym_constraints(bcdict, snic, axes, edge_constraints) write_bc(bcdict, bcfile)
def findStructElemIDs(elefile: str, structNodeIDs: dict) -> list: """find elements that contain nodes in structNodeIDs Args: elefile (str): element filename structNodeIDs (dict): Returns: (elems, structElemIds) Raises: ValueError: no structural elements found """ from fem.mesh.fem_mesh import load_elems import sys elems = load_elems(elefile) structElemIDs = {} for i in elems: # TODO: optimize this mess of nested loops j = i.tolist() insideStruct = any(x in structNodeIDs for x in j[2:10]) if insideStruct: structElemIDs[i[0]] = True if len(structElemIDs) == 0: logger.warning("No structure elements were found.") raise ValueError("No structure elements were found.") sys.exit() else: logger.info(f"{len(structElemIDs)} structural elements were found.") return (elems, structElemIDs)