Skip to content

Commit

Permalink
fix section consolidation 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 32d83f4 commit 5933daa
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 14 deletions.
13 changes: 9 additions & 4 deletions src/ada/api/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,14 +737,19 @@ def add(self, section: Section) -> Section:

if section.name in self._name_map.keys():
logger.info(f'Section with same name "{section.name}" already exists. Will use that section instead')
existing_section = self._name_map[section.name]
existing_section: Section = self._name_map[section.name]
for elem in section.refs:
if section == elem.section:
elem.section = existing_section
if isinstance(elem, BeamTapered):
if existing_section.equal_props(elem.section):
elem.section = existing_section
elif existing_section.equal_props(elem.taper):
elem.taper = existing_section
else:
elem.taper = existing_section
if existing_section.equal_props(elem.section):
elem.section = existing_section
if elem not in existing_section.refs:
existing_section.refs.append(elem)

return existing_section

if section.id is None:
Expand Down
9 changes: 7 additions & 2 deletions src/ada/api/spatial/part.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,9 +545,14 @@ def consolidate_sections(self, include_self=True):
if elem not in res.refs:
res.refs.append(elem)
if isinstance(elem, (Beam, FemSection)):
if isinstance(elem, BeamTapered) and sec.guid == elem.taper.guid:
if isinstance(elem, BeamTapered) and res.guid == elem.taper.guid:
if not res.equal_props(elem.taper):
raise ValueError(f"Section {res} and {elem.taper} have different properties")
elem.taper = res
elem.section = res
else:
if not res.equal_props(elem.section):
raise ValueError(f"Section {res} and {elem.section} have different properties")
elem.section = res
else:
raise NotImplementedError(f"Not yet support section {type(elem)=}")

Expand Down
4 changes: 2 additions & 2 deletions src/ada/sections/concept.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ada.sections.categories import BaseTypes, SectionCat

if TYPE_CHECKING:
from ada import Beam, CurvePoly2d, Pipe, PipeSegElbow, PipeSegStraight
from ada import Beam, BeamTapered, CurvePoly2d, Pipe, PipeSegElbow, PipeSegStraight
from ada.fem import FemSection
from ada.sections.profiles import SectionProfile

Expand Down Expand Up @@ -270,7 +270,7 @@ def _repr_html_(self):
JUPYTER_SECTION_RENDERER(self)

@property
def refs(self) -> list[Beam | FemSection | Pipe | PipeSegStraight | PipeSegElbow]:
def refs(self) -> list[Beam | BeamTapered | FemSection | Pipe | PipeSegStraight | PipeSegElbow]:
return self._refs

def __hash__(self):
Expand Down
36 changes: 30 additions & 6 deletions tests/core/sections/test_sections_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,42 @@ 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
assert bm.section.equal_props(sec)
assert bm.taper.equal_props(tap)

sec1, tap1 = ada.Section.from_str("TG600/300x300x10x20")
for i in range(6, 10):
bm = p.add_beam(ada.BeamTapered(f"bm{i}", (0, 0, i), (10, 0, i), sec1, tap1))
assert isinstance(bm, ada.BeamTapered)
assert bm.section.equal_props(sec1)
assert bm.taper.equal_props(tap1)

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

for beam0 in beams:
assert beam0.section.equal_props(sec)
assert beam0.taper.equal_props(tap)

p2 = ada.Part("MyBeams2")
for i in range(11, 17):
bm = p2.add_beam(ada.BeamTapered(f"bm{i}", (0, 0, i), (10, 0, i), sec1, tap1))
assert isinstance(bm, ada.BeamTapered)
assert bm.section.equal_props(sec1)
assert bm.taper.equal_props(tap1)

a = ada.Assembly() / [p, p2]
a.consolidate_sections()

beam0 = beams[0]
assert beam0.section == sec
assert beam0.taper == tap
for beam in a.get_all_physical_objects(by_type=ada.BeamTapered):
assert beam.section.equal_props(sec1)
assert beam.taper.equal_props(tap1)

0 comments on commit 5933daa

Please sign in to comment.