Skip to content

Commit

Permalink
fix adding sections issue with tapered beams
Browse files Browse the repository at this point in the history
  • Loading branch information
Krande committed Dec 20, 2024
1 parent 493e3c9 commit 32d83f4
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# SCM syntax highlighting
pixi.lock linguist-language=YAML linguist-generated=true
17 changes: 13 additions & 4 deletions src/ada/api/beams/base_bm.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,12 +503,21 @@ def solid_geom(self) -> Geometry:
geo = geo_conv.straight_tapered_beam_to_geom(self)
if self.taper_type == TaperTypes.CENTERED:
return geo

if self.up.is_equal(ada.Direction(0, 0, 1)):
off_dir = -1
elif self.up.is_equal(ada.Direction(0, 0, -1)):
off_dir = 1
else:
logger.warning("Tapered beam is not aligned with global z-axis")
off_dir = 0

if self.taper_type == TaperTypes.FLUSH_TOP:
offset_dir_1 = ada.Direction(0, -self.section.h / 2)
offset_dir_2 = ada.Direction(0, -self.taper.h / 2)
offset_dir_1 = ada.Direction(0, off_dir*self.section.h / 2)
offset_dir_2 = ada.Direction(0, off_dir*self.taper.h / 2)
elif self.taper_type == TaperTypes.FLUSH_BOTTOM:
offset_dir_1 = ada.Direction(0, self.section.h / 2)
offset_dir_2 = ada.Direction(0, self.taper.h / 2)
offset_dir_1 = ada.Direction(0, -off_dir*self.section.h / 2)
offset_dir_2 = ada.Direction(0, -off_dir*self.taper.h / 2)
else:
raise ValueError(f"Unknown taper type {self.taper_type}")

Expand Down
10 changes: 9 additions & 1 deletion src/ada/api/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,8 @@ def name_map(self) -> dict[str, Section]:
return self._name_map

def add(self, section: Section) -> Section:
from ada import BeamTapered

if section.name is None:
raise Exception("Name is not allowed to be None.")

Expand All @@ -722,7 +724,13 @@ def add(self, section: Section) -> Section:
index = self._sections.index(section)
existing_section = self._sections[index]
for elem in section.refs:
elem.section = existing_section
if isinstance(elem, BeamTapered):
if existing_section == elem.section:
elem.section = existing_section
else:
elem.taper = existing_section
else:
elem.section = existing_section
if elem not in existing_section.refs:
existing_section.refs.append(elem)
return existing_section
Expand Down
2 changes: 1 addition & 1 deletion src/ada/api/spatial/part.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __init__(
self._presentation_layers = PresentationLayers()
self.fem = FEM(name + "-1", parent=self) if fem is None else fem

def add_beam(self, beam: Beam, add_to_layer: str = None) -> Beam:
def add_beam(self, beam: Beam, add_to_layer: str = None) -> Beam | BeamTapered:
if beam.units != self.units:
beam.units = self.units
beam.parent = self
Expand Down
17 changes: 17 additions & 0 deletions tests/core/sections/test_sections_properties.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ada
from ada import Section
from ada.core.utils import roundoff

Expand Down Expand Up @@ -197,3 +198,19 @@ def test_circular():
]

eval_assertions(sec, assertions)

def test_tapered_section():
sec, tap = ada.Section.from_str("TG600/300x300x10x20")
p = ada.Part("MyBeams")
for i in range(0, 5):
bm = p.add_beam(ada.BeamTapered(f"bm{i}", (0, 0, i), (10, 0, i), sec, tap))
assert isinstance(bm, ada.BeamTapered)
assert bm.section == sec
assert bm.taper == tap

beams = list(p.get_all_physical_objects(by_type=ada.BeamTapered))
assert len(beams) == 5

beam0 = beams[0]
assert beam0.section == sec
assert beam0.taper == tap

0 comments on commit 32d83f4

Please sign in to comment.