Exemplo n.º 1
0
    def __init__(
            self,
            name,
            guid=None,
            metadata=None,
            units="m",
            parent=None,
            colour=None,
            ifc_elem=None,
            placement=Placement(),
            ifc_ref: IfcRef = None,
            opacity=1.0,
    ):
        super().__init__(name,
                         guid,
                         metadata,
                         units,
                         parent,
                         ifc_elem=ifc_elem,
                         ifc_ref=ifc_ref)
        from ada.visualize.new_render_api import Visualize

        self._penetrations = []
        self._placement = placement
        placement.parent = self
        self.colour = colour
        self.opacity = opacity
        self._elem_refs = []
        self._viz = Visualize(self)
Exemplo n.º 2
0
    def add_geom(self, geom, obj, geom_repr=None):
        from ada.concepts.transforms import Placement
        from ada.core.vector_utils import vector_length

        from .utils import transform_shape

        name = obj.name if obj.name is not None else next(shp_names)
        Interface_Static_SetCVal("write.step.product.name", name)

        # Transform geometry
        res = obj.placement.absolute_placement()
        if vector_length(res - Placement().origin) > 0:
            geom = transform_shape(geom, transform=tuple(res))
        try:
            if geom_repr == ElemType.SHELL:
                stat = self.writer.Transfer(
                    geom, STEPControl_ShellBasedSurfaceModel)
            else:
                stat = self.writer.Transfer(geom, STEPControl_AsIs)
        except BaseException as e:
            logging.info(f"Passing {obj} due to {e}")
            return None

        if int(stat) > int(IFSelect_RetError):
            raise Exception("Some Error occurred")

        item = stepconstruct_FindEntity(self.fp, geom)
        if not item:
            logging.debug("STEP item not found for FindEntity")
        else:
            item.SetName(TCollection_HAsciiString(name))
Exemplo n.º 3
0
def simple_stru():
    return SimpleStru(
        "SimpleStructure",
        w=10,
        l=10,
        h=3,
        gsec="BG200x100x10x20",
        csec="BG200x200x20x20",
        placement=Placement(origin=(200, 100, 500)),
    )
Exemplo n.º 4
0
    def __init__(
        self,
        name,
        points,
        height,
        thickness,
        placement=Placement(),
        offset=TYPES_JUSL.CENTER,
        metadata=None,
        colour=None,
        ifc_elem=None,
        units="m",
        guid=None,
        opacity=1.0,
    ):
        super().__init__(
            name, guid=guid, metadata=metadata, units=units, ifc_elem=ifc_elem, colour=colour, opacity=opacity
        )

        self._name = name
        self.placement = placement
        self.colour = colour
        new_points = []
        for p in points:
            np_ = [float(c) for c in p]
            if len(np_) == 2:
                np_ += [0.0]
            new_points.append(tuple(np_))
        self._points = new_points
        self._segments = list(zip(self._points[:-1], self.points[1:]))
        self._height = height
        self._thickness = thickness
        self._openings = []
        self._doors = []
        self._inserts = []
        if type(offset) is str:
            if offset not in Wall.TYPES_JUSL.all:
                raise ValueError(f'Unknown string input "{offset}" for offset')
            if offset == Wall.TYPES_JUSL.CENTER:
                self._offset = 0.0
            elif offset == Wall.TYPES_JUSL.LEFT:
                self._offset = -self._thickness / 2
            else:  # offset = RIGHT
                self._offset = self._thickness / 2
        else:
            if type(offset) not in (float, int):
                raise ValueError("Offset can only be string or float, int")
            self._offset = offset
Exemplo n.º 5
0
    def __init__(
        self,
        name,
        colour=None,
        placement=Placement(),
        fem: FEM = None,
        settings: Settings = Settings(),
        metadata=None,
        parent=None,
        units="m",
        ifc_elem=None,
        guid=None,
        ifc_ref: IfcRef = None,
    ):
        super().__init__(name,
                         guid=guid,
                         metadata=metadata,
                         units=units,
                         parent=parent,
                         ifc_elem=ifc_elem,
                         ifc_ref=ifc_ref)
        self._nodes = Nodes(parent=self)
        self._beams = Beams(parent=self)
        self._plates = Plates(parent=self)
        self._pipes = list()
        self._walls = list()
        self._connections = Connections(parent=self)
        self._materials = Materials(parent=self)
        self._sections = Sections(parent=self)
        self._colour = colour
        self._placement = placement
        self._instances: Dict[Any, Instance] = dict()
        self._shapes = []
        self._parts = dict()
        self._groups: Dict[str, Group] = dict()

        if ifc_elem is not None:
            self.metadata["ifctype"] = self._import_part_from_ifc(ifc_elem)
        else:
            if self.metadata.get("ifctype") is None:
                self.metadata["ifctype"] = "site" if type(
                    self) is Assembly else "storey"

        self._props = settings
        if fem is not None:
            fem.parent = self

        self.fem = FEM(name + "-1", parent=self) if fem is None else fem
Exemplo n.º 6
0
    def __init__(
            self,
            name,
            w=5,
            l=5,
            h=3,
            gsec="IPE200",
            csec="HEB200",
            pl_thick=10e-3,
            placement=Placement(),
    ):
        super(SimpleStru, self).__init__(name, placement=placement)
        self.Params.w = w
        self.Params.h = h
        self.Params.l = l

        # Define the 5 corner points of each storey
        c1, c2, c3, c4 = self.c1, self.c2, self.c3, self.c4

        # Define the relationship of corners that make up the 4 support beams
        beams = [(c1, c2), (c2, c3), (c3, c4), (c4, c1)]

        z0 = 0
        z1 = h
        sec = Section(gsec, from_str=gsec, parent=self)
        self._elevations = [z0, z1]
        for elev in self._elevations:
            for p1, p2 in beams:
                self.add_beam(
                    Beam(next(bm_name),
                         n1=p1(elev),
                         n2=p2(elev),
                         sec=sec,
                         jusl=Beam.JUSL_TYPES.TOS))
            points = [c1(elev), c2(elev), c3(elev), c4(elev)]
            p = self.add_part(
                ReinforcedFloor(next(floor_name), points, pl_thick))
            self.add_set("floors", [p])

        # Columns
        columns = [(c1(z0), c1(h)), (c2(z0), c2(h)), (c3(z0), c3(h)),
                   (c4(z0), c4(h))]
        for p1, p2 in columns:
            bm = self.add_beam(Beam(next(bm_name), n1=p1, n2=p2, sec=csec))
            self.add_set("columns", [bm])
Exemplo n.º 7
0
def assembly() -> Assembly:
    bm1 = Beam("bm1", (0, 0, 1), (1, 0, 1), "IPE300")
    bm2 = Beam("bm2", (1.1, 0, 1), (2, 0, 1), "IPE300")
    bm3 = Beam("bm3", (2.1, 0, 1), (3, 0, 1), "IPE300")

    placement = Placement(origin=(1, 1, 1), xdir=(1, 0, 0), zdir=(0, 0, 1))
    pl_points = [(0, 0), (1, 0), (1, 1), (0, 1)]
    pl1 = Plate("pl1", pl_points, 10e-3, placement=placement)

    pipe = Pipe("pipe", [(0, 0.5, 0), (1, 0.5, 0), (1.2, 0.7, 0.2),
                         (1.5, 0.7, 0.2)], "OD120x6")

    p1, p2 = (1, -2, 0), (2, -1, 1)
    shp1 = PrimBox("MyBox", p1, p2)
    shp1.add_penetration(PrimSphere("MyCutout", p1, 0.5))

    return Assembly() / (Part("MyFemObjects") /
                         [bm1, bm2, bm3, pl1, shp1, pipe])
Exemplo n.º 8
0
    def add_insert(self, insert: "WallInsert", wall_segment: int, off_x, off_z):
        """

        :param insert:
        :param wall_segment:
        :param off_x:
        :param off_z:
        :return:
        """
        from OCC.Extend.ShapeFactory import get_oriented_boundingbox

        xvec, yvec, zvec = self.get_segment_props(wall_segment)
        p1, p2 = self._segments[wall_segment]

        start = p1 + yvec * (self._thickness / 2 + self.offset) + xvec * off_x + zvec * off_z
        insert._depth = self._thickness
        insert.placement = Placement(origin=start, xdir=xvec, ydir=zvec, zdir=yvec)

        frame = insert.shapes[0]
        center, dim, oobb_shp = get_oriented_boundingbox(frame.geom)
        x, y, z = center.X(), center.Y(), center.Z()
        dx, dy, dz = dim[0], dim[1], dim[2]

        x0 = x - abs(dx / 2)
        y0 = y - abs(dy / 2)
        z0 = z - abs(dz / 2)

        x1 = x + abs(dx / 2)
        y1 = y + abs(dy / 2)
        z1 = z + abs(dz / 2)

        self._inserts.append(insert)
        self._openings.append([wall_segment, insert, (x0, y0, z0), (x1, y1, z1)])

        tol = 0.4
        wi = insert

        p1 = wi.placement.origin - yvec * (wi.depth / 2 + tol)
        p2 = wi.placement.origin + yvec * (wi.depth / 2 + tol) + xvec * wi.width + zvec * wi.height

        self._penetrations.append(PrimBox("my_pen", p1, p2))
Exemplo n.º 9
0
def get_sh_sections_for_beam_obj(model: gmsh.model, beam: Beam,
                                 gmsh_data: GmshData, fem: FEM):
    from ada.sections.bm_sh_ident import eval_thick_normal_from_cog_of_beam_plate

    pl1 = Placement(beam.n1.p, beam.yvec, beam.up, beam.xvec)
    for _, ent in gmsh_data.entities:
        _, _, param = model.mesh.getNodes(2, ent, True)
        normal = np.array([
            0.0 if abs(x) == 0.0 else x
            for x in model.getNormal(ent, param)[:3]
        ])
        cog = model.occ.getCenterOfMass(2, ent)
        pc = eval_thick_normal_from_cog_of_beam_plate(beam.section, cog,
                                                      normal, pl1)

        _, tags, _ = model.mesh.getElements(2, ent)
        elements = [fem.elements.from_id(x) for x in chain.from_iterable(tags)]
        set_name = make_name_fem_ready(f"el{beam.name}_e{ent}_{pc.type}_sh")
        fem_sec_name = make_name_fem_ready(f"d{beam.name}_e{ent}_{pc.type}_sh")

        add_shell_section(set_name, fem_sec_name, normal, pc.thick, elements,
                          beam, fem)
Exemplo n.º 10
0
def create_beam_geom(beam: Beam, solid=True):
    from ada.concepts.transforms import Placement
    from ada.sections.categories import SectionCat

    from .section_utils import cross_sec_face

    xdir, ydir, zdir = beam.ori
    ydir_neg = tuple_minus(
        ydir) if beam.section.type not in SectionCat.angular else tuple(ydir)

    section_profile = beam.section.get_section_profile(solid)
    taper_profile = beam.taper.get_section_profile(solid)

    placement_1 = Placement(origin=beam.n1.p, xdir=ydir_neg, zdir=xdir)
    placement_2 = Placement(origin=beam.n2.p, xdir=ydir_neg, zdir=xdir)

    sec = cross_sec_face(section_profile, placement_1, solid)
    tap = cross_sec_face(taper_profile, placement_2, solid)

    if type(sec) != list and (sec.IsNull() or tap.IsNull()):
        raise UnableToCreateSolidOCCGeom(
            f"Unable to create solid OCC geometry from Beam '{beam.name}'")

    def through_section(sec_a, sec_b, solid_):
        generator_sec = BRepOffsetAPI_ThruSections(solid_, False)
        generator_sec.AddWire(sec_a)
        generator_sec.AddWire(sec_b)
        generator_sec.Build()
        return generator_sec.Shape()

    if type(sec) is TopoDS_Face:
        sec_result = face_to_wires(sec)
        tap_result = face_to_wires(tap)
    elif type(sec) is TopoDS_Wire:
        sec_result = [sec]
        tap_result = [tap]
    else:
        try:
            assert isinstance(sec, list)
        except AssertionError as e:
            logging.error(e)
        sec_result = sec
        tap_result = tap

    shapes = list()
    for s_, t_ in zip(sec_result, tap_result):
        shapes.append(through_section(s_, t_, solid))

    if beam.section.type in SectionCat.box + SectionCat.tubular + SectionCat.rhs + SectionCat.shs and solid is True:
        cut_shape = BRepAlgoAPI_Cut(shapes[0], shapes[1]).Shape()
        shape_upgrade = ShapeUpgrade_UnifySameDomain(cut_shape, False, True,
                                                     False)
        shape_upgrade.Build()
        return shape_upgrade.Shape()

    if len(shapes) == 1:
        return shapes[0]
    else:
        result = shapes[0]
        for s in shapes[1:]:
            result = BRepAlgoAPI_Fuse(result, s).Shape()
        return result
Exemplo n.º 11
0
    def __init__(
        self,
        name,
        nodes,
        t,
        mat="S420",
        use3dnodes=False,
        placement=Placement(),
        pl_id=None,
        offset=None,
        colour=None,
        parent=None,
        ifc_geom=None,
        opacity=1.0,
        metadata=None,
        tol=None,
        units="m",
        ifc_elem=None,
        guid=None,
        ifc_ref: "IfcRef" = None,
    ):
        super().__init__(
            name,
            guid=guid,
            metadata=metadata,
            units=units,
            ifc_elem=ifc_elem,
            placement=placement,
            ifc_ref=ifc_ref,
            colour=colour,
            opacity=opacity,
        )

        points2d = None
        points3d = None

        if use3dnodes is True:
            points3d = nodes
        else:
            points2d = nodes

        self._pl_id = pl_id
        self._material = mat if isinstance(mat, Material) else Material(
            mat, mat_model=CarbonSteel(mat), parent=parent)
        self._material.refs.append(self)
        self._t = t

        if tol is None:
            if units == "mm":
                tol = Settings.mmtol
            elif units == "m":
                tol = Settings.mtol
            else:
                raise ValueError(f'Unknown unit "{units}"')

        self._poly = CurvePoly(
            points3d=points3d,
            points2d=points2d,
            normal=self.placement.zdir,
            origin=self.placement.origin,
            xdir=self.placement.xdir,
            tol=tol,
            parent=self,
        )

        self._offset = offset
        self._parent = parent
        self._ifc_geom = ifc_geom
        self._bbox = None
Exemplo n.º 12
0
def get_placement(ifc_position) -> Placement:
    origin = get_point(ifc_position.Location)
    xdir = get_direction(ifc_position.RefDirection)
    zdir = get_direction(ifc_position.Axis)

    return Placement(origin, xdir=xdir, zdir=zdir)
Exemplo n.º 13
0
    def __init__(
            self,
            name,
            n1: Union[Node, Iterable] = None,
            n2: Union[Node, Iterable] = None,
            sec: Union[str, Section] = None,
            mat: Union[str, Material] = None,
            tap: Union[str, Section] = None,
            jusl=JUSL_TYPES.NA,
            up=None,
            angle=0.0,
            curve: Union[CurvePoly, CurveRevolve] = None,
            e1=None,
            e2=None,
            colour=None,
            parent: Part = None,
            metadata=None,
            opacity=1.0,
            units="m",
            ifc_elem=None,
            guid=None,
            placement=Placement(),
            ifc_ref: IfcRef = None,
    ):
        super().__init__(
            name,
            metadata=metadata,
            units=units,
            guid=guid,
            ifc_elem=ifc_elem,
            placement=placement,
            ifc_ref=ifc_ref,
            colour=colour,
            opacity=opacity,
        )
        if curve is not None:
            curve.parent = self
            if type(curve) is CurvePoly:
                n1 = curve.points3d[0]
                n2 = curve.points3d[-1]
            elif type(curve) is CurveRevolve:
                n1 = curve.p1
                n2 = curve.p2
            else:
                raise ValueError(f'Unsupported curve type "{type(curve)}"')

        self._curve = curve
        self._n1 = n1 if type(n1) is Node else Node(n1[:3], units=units)
        self._n2 = n2 if type(n2) is Node else Node(n2[:3], units=units)
        self._jusl = jusl

        self._connected_to = []
        self._connected_end1 = None
        self._connected_end2 = None
        self._tos = None
        self._e1 = e1
        self._e2 = e2
        self._hinge_prop = None

        self._parent = parent
        self._bbox = None

        # Section and Material setup
        self._section, self._taper = get_section(sec)
        self._section.refs.append(self)
        self._taper.refs.append(self)
        self._material = get_material(mat)
        self._material.refs.append(self)

        if tap is not None:
            self._taper, _ = get_section(tap)

        self._section.parent = self
        self._taper.parent = self

        # Define orientations
        self._init_orientation(angle, up)
        self.add_beam_to_node_refs()