def import_ifc_hierarchy(assembly: Assembly, product, ifc_ref: IfcRef): pr_type = product.is_a() pp = get_parent(product) if pp is None: return None, None # "IfcSpace", if pr_type not in ["IfcBuilding", "IfcBuildingStorey", "IfcSpatialZone"]: return None, None props = get_psets(product) name = product.Name if name is None: logging.debug( f'Name was not found for the IFC element "{product}". Will look for ref to name in props' ) name = resolve_name(props, product) new_part = Part( name, metadata=dict(original_name=name, props=props), guid=product.GlobalId, ifc_ref=ifc_ref, units=assembly.units, ) pp_name = pp.Name if pp_name is None: pp_name = resolve_name(get_psets(pp), pp) if pp_name is None: return None, None parent = assembly.get_by_name(pp_name) return parent, new_part
def pfem(): a = Assembly() / (Part("BeamFEM") / Beam( "bm1", n1=[0, 0, 0], n2=[2, 0, 0], sec="IPE220", colour="red")) part = a.get_part("BeamFEM") with GmshSession(silent=True) as gs: gs.add_obj(a.get_by_name("bm1"), geom_repr="line") gs.mesh(0.1) part.fem = gs.get_fem() return part
def import_ifc_beam(ifc_elem, name, ifc_ref: IfcRef, assembly: Assembly = None) -> Beam: from .exceptions import NoIfcAxesAttachedError mat_ref = get_associated_material(ifc_elem) sec = None mat = None if assembly is not None: sec_name = mat_ref.Profile.ProfileName if hasattr( mat_ref, "Profile") else mat_ref.Name mat_name = mat_ref.Material.Name if hasattr( mat_ref, "Material") else mat_ref.Name sec = assembly.get_by_name(sec_name) mat = assembly.get_by_name(mat_name) if sec is None: sec = import_section_from_ifc(mat_ref.Profile, units=assembly.units) if mat is None: mat = read_material(mat_ref, ifc_ref, assembly) axes = [ rep for rep in ifc_elem.Representation.Representations if rep.RepresentationIdentifier == "Axis" ] if len(axes) != 1: raise NoIfcAxesAttachedError( "Number of axis objects attached to IfcBeam is not 1") if len(axes[0].Items) != 1: raise ValueError("Number of items objects attached to axis is not 1") axis = axes[0].Items[0] if axis.is_a("IfcPolyline") and len(axis.Points) != 2: return import_polyline_beam(ifc_elem, axis, name, sec, mat, ifc_ref, assembly) elif axis.is_a("IfcTrimmedCurve"): return import_revolved_beam(ifc_elem, axis, name, sec, mat, ifc_ref, assembly) else: return import_straight_beam(ifc_elem, axis, name, sec, mat, ifc_ref, assembly)
def test_simplestru_fem_cache(self): model_name = "ParamAssembly" start = time.time() a = Assembly(model_name, clear_cache=True, enable_experimental_cache=True) / SimpleStru("ParamModel") pfem = a.get_by_name("ParamModel") pfem.gmsh.mesh() time1 = time.time() - start print(time1) a.update_cache() start = time.time() b = Assembly(model_name, enable_experimental_cache=True) time2 = time.time() - start print(time2) cache_validation(a, b) print( f"Model generation time reduced from {time1:.2f}s to {time2:.2f}s -> {time1 / time2:.2f} x Improvement" )
def import_ifc_plate(ifc_elem, name, ifc_ref: IfcRef, assembly: Assembly) -> Plate: from .exceptions import NoIfcAxesAttachedError logging.info(f"importing {name}") ifc_mat = get_associated_material(ifc_elem) mat = None if assembly is not None: mat = assembly.get_by_name(name) if mat is None: mat = read_material(ifc_mat, ifc_ref, assembly) # TODO: Fix interpretation of IfcIndexedPolyCurve. Should pass origin to get actual 2d coordinates. # Adding Axis information axes = [ rep for rep in ifc_elem.Representation.Representations if rep.RepresentationIdentifier == "Axis" ] if len(axes) != 1: raise NoIfcAxesAttachedError( "IfcPlate does not have an Axis representation Item") axis = axes[0] origin = axis.Items[0].Points[0].Coordinates # Adding Body bodies = [ rep for rep in ifc_elem.Representation.Representations if rep.RepresentationIdentifier == "Body" ] if len(bodies) != 1: raise NotImplementedError( "Geometry with multiple bodies is not currently supported") if len(bodies[0].Items) != 1: raise NotImplementedError( "Body with multiple Items is not currently supported") item = bodies[0].Items[0] t = item.Depth normal = item.ExtrudedDirection.DirectionRatios xdir = item.Position.RefDirection.DirectionRatios outer_curve = item.SweptArea.OuterCurve if outer_curve.is_a("IfcIndexedPolyCurve"): nodes2d = import_indexedpolycurve(outer_curve, normal, xdir, origin) else: nodes2d = import_polycurve(outer_curve, normal, xdir) if nodes2d is None or t is None: raise ValueError("Unable to get plate nodes or thickness") placement = Placement(origin, xdir=xdir, zdir=normal) return Plate(name, nodes2d, t, mat=mat, placement=placement, guid=ifc_elem.GlobalId, ifc_ref=ifc_ref, units=assembly.units)