Skip to content

Commit 78e159c

Browse files
Merge branch 'feat/enhanced_beam_implementation' of https://github.com/ansys/pyansys-geometry into feat/enhanced_beam_implementation
2 parents d1ddcc7 + 95cf1b1 commit 78e159c

File tree

7 files changed

+63
-41
lines changed

7 files changed

+63
-41
lines changed

doc/changelog.d/1828.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
enhanced beam implementation

src/ansys/geometry/core/designer/beam.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class BeamType(Enum):
4848
CABLE = 3
4949
PIPE = 4
5050
THERMALFLUID = 5
51-
UNKNOWN = 6
51+
UNKNOWN = 6
5252

5353

5454
class SectionAnchorType(Enum):
@@ -93,6 +93,7 @@ def name(self) -> str:
9393
"""Name of the beam profile."""
9494
return self._name
9595

96+
9697
class BeamCircularProfile(BeamProfile):
9798
"""Represents a single circular beam profile.
9899
@@ -179,7 +180,7 @@ class BeamCrossSectionInfo:
179180
section_anchor : SectionAnchorType
180181
Specifies how the beam section is anchored to the beam path.
181182
section_angle : float
182-
The rotation angle of the cross section clockwise from the default perpendicular of the
183+
The rotation angle of the cross section clockwise from the default perpendicular of the
183184
beam path.
184185
section_frame : Frame
185186
The section frame at the start of the beam.
@@ -227,12 +228,15 @@ def __repr__(self) -> str:
227228
lines.append(f" Section Anchor : {self.section_anchor.name}")
228229
lines.append(f" Section Angle : {self.section_angle}")
229230
lines.append(f" Section Frame : {self.section_frame}")
230-
lines.extend(["\n", " Section Profile info", " -------------------", str(self.section_profile)])
231+
lines.extend(
232+
["\n", " Section Profile info", " -------------------", str(self.section_profile)]
233+
)
231234
return "\n".join(lines)
232235

236+
233237
class BeamProperties:
234238
"""Represents the properties of a beam.
235-
239+
236240
Parameters
237241
----------
238242
area : float
@@ -323,6 +327,7 @@ def torsion_constant(self) -> float:
323327
"""The torsion constant of the beam."""
324328
return self._torsion_constant
325329

330+
326331
class Beam:
327332
"""Represents a simplified solid body with an assigned 2D cross-section.
328333
@@ -362,7 +367,6 @@ def __init__(
362367
properties: BeamProperties = None,
363368
shape: TrimmedCurve = None,
364369
beam_type: BeamType = None,
365-
366370
):
367371
"""Initialize ``Beam`` class."""
368372
from ansys.geometry.core.designer.component import Component

src/ansys/geometry/core/designer/component.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,8 +1164,9 @@ def create_beams(
11641164
return self.__create_beams_legacy(segments, profile)
11651165
else:
11661166
return self.__create_beams(segments, profile, arcs, circles)
1167-
1168-
def __create_beams_legacy(self, segments: list[tuple[Point3D, Point3D]], profile: BeamProfile
1167+
1168+
def __create_beams_legacy(
1169+
self, segments: list[tuple[Point3D, Point3D]], profile: BeamProfile
11691170
) -> list[Beam]:
11701171
"""Create beams under the component.
11711172
@@ -1183,7 +1184,7 @@ def __create_beams_legacy(self, segments: list[tuple[Point3D, Point3D]], profile
11831184
Returns
11841185
-------
11851186
list[Beam]
1186-
A list of the created Beams.
1187+
A list of the created Beams.
11871188
"""
11881189
request = CreateBeamSegmentsRequest(parent=self.id, profile=profile.id)
11891190

@@ -1208,13 +1209,13 @@ def __create_beams_legacy(self, segments: list[tuple[Point3D, Point3D]], profile
12081209

12091210
self._beams.extend(new_beams)
12101211
return self._beams[-n_beams:]
1211-
1212+
12121213
def __create_beams(
1213-
self,
1214-
segments: list[tuple[Point3D, Point3D]],
1215-
profile: BeamProfile,
1216-
arcs: list[Arc] = None,
1217-
circles: list[Circle] = None,
1214+
self,
1215+
segments: list[tuple[Point3D, Point3D]],
1216+
profile: BeamProfile,
1217+
arcs: list[Arc] = None,
1218+
circles: list[Circle] = None,
12181219
) -> list[Beam]:
12191220
"""Create beams under the component.
12201221
@@ -1228,7 +1229,7 @@ def __create_beams(
12281229
Returns
12291230
-------
12301231
list[Beam]
1231-
A list of the created Beams.
1232+
A list of the created Beams.
12321233
"""
12331234
request = CreateBeamSegmentsRequest(
12341235
profile=profile.id,
@@ -1251,14 +1252,19 @@ def __create_beams(
12511252
beam.cross_section.section_angle,
12521253
grpc_frame_to_frame(beam.cross_section.section_frame),
12531254
[
1254-
[TrimmedCurve(
1255-
grpc_curve_to_curve(curve.geometry),
1256-
grpc_point_to_point3d(curve.start),
1257-
grpc_point_to_point3d(curve.end),
1258-
Interval(curve.interval_start, curve.interval_end),
1259-
curve.length) for curve in curve_list]
1260-
for curve_list in beam.cross_section.section_profile],
1261-
)
1255+
[
1256+
TrimmedCurve(
1257+
grpc_curve_to_curve(curve.geometry),
1258+
grpc_point_to_point3d(curve.start),
1259+
grpc_point_to_point3d(curve.end),
1260+
Interval(curve.interval_start, curve.interval_end),
1261+
curve.length,
1262+
)
1263+
for curve in curve_list
1264+
]
1265+
for curve_list in beam.cross_section.section_profile
1266+
],
1267+
)
12621268
properties = BeamProperties(
12631269
beam.properties.area,
12641270
ParamUV(beam.properties.centroid_x, beam.properties.centroid_y),
@@ -1270,7 +1276,7 @@ def __create_beams(
12701276
beam.properties.torsional_constant,
12711277
)
12721278

1273-
beams.append(
1279+
beams.append(
12741280
Beam(
12751281
beam.id.id,
12761282
grpc_point_to_point3d(beam.shape.start),
@@ -1288,7 +1294,7 @@ def __create_beams(
12881294
beam.type,
12891295
)
12901296
)
1291-
1297+
12921298
self._beams.extend(beams)
12931299
return beams
12941300

src/ansys/geometry/core/designer/design.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
from pathlib import Path
2626
from typing import Union
2727

28-
from ansys.geometry.core.shapes.curves.trimmed_curve import TrimmedCurve
29-
from ansys.geometry.core.shapes.parameterization import Interval, ParamUV
3028
from beartype import beartype as check_input_types
3129
from google.protobuf.empty_pb2 import Empty
3230
import numpy as np
@@ -67,7 +65,14 @@
6765
plane_to_grpc_plane,
6866
point3d_to_grpc_point,
6967
)
70-
from ansys.geometry.core.designer.beam import Beam, BeamCircularProfile, BeamCrossSectionInfo, BeamProfile, BeamProperties, SectionAnchorType
68+
from ansys.geometry.core.designer.beam import (
69+
Beam,
70+
BeamCircularProfile,
71+
BeamCrossSectionInfo,
72+
BeamProfile,
73+
BeamProperties,
74+
SectionAnchorType,
75+
)
7176
from ansys.geometry.core.designer.body import Body, MasterBody, MidSurfaceOffsetType
7277
from ansys.geometry.core.designer.component import Component, SharedTopologyType
7378
from ansys.geometry.core.designer.coordinate_system import CoordinateSystem
@@ -94,6 +99,8 @@
9499
from ansys.geometry.core.misc.options import ImportOptions
95100
from ansys.geometry.core.modeler import Modeler
96101
from ansys.geometry.core.parameters.parameter import Parameter, ParameterUpdateStatus
102+
from ansys.geometry.core.shapes.curves.trimmed_curve import TrimmedCurve
103+
from ansys.geometry.core.shapes.parameterization import Interval, ParamUV
97104
from ansys.geometry.core.typing import RealSequence
98105

99106

@@ -1149,14 +1156,19 @@ def __read_existing_design(self) -> None:
11491156
beam.cross_section.section_angle,
11501157
grpc_frame_to_frame(beam.cross_section.section_frame),
11511158
[
1152-
[TrimmedCurve(
1153-
grpc_curve_to_curve(curve.curve),
1154-
grpc_point_to_point3d(curve.start),
1155-
grpc_point_to_point3d(curve.end),
1156-
Interval(curve.interval_start, curve.interval_end),
1157-
curve.length) for curve in curve_list.curves]
1158-
for curve_list in beam.cross_section.section_profile],
1159-
)
1159+
[
1160+
TrimmedCurve(
1161+
grpc_curve_to_curve(curve.curve),
1162+
grpc_point_to_point3d(curve.start),
1163+
grpc_point_to_point3d(curve.end),
1164+
Interval(curve.interval_start, curve.interval_end),
1165+
curve.length,
1166+
)
1167+
for curve in curve_list.curves
1168+
]
1169+
for curve_list in beam.cross_section.section_profile
1170+
],
1171+
)
11601172
properties = BeamProperties(
11611173
beam.properties.area,
11621174
ParamUV(beam.properties.centroid_x, beam.properties.centroid_y),

src/ansys/geometry/core/misc/auxiliary.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,7 @@ def get_beams_from_ids(design: "Design", beam_ids: list[str]) -> list["Beam"]:
257257
-----
258258
This method takes a design and beam ids, and gets their corresponding ``Beam`` objects.
259259
"""
260-
return [
261-
beam for beam in design.beams if beam.id in beam_ids
262-
] # noqa: E501
260+
return [beam for beam in design.beams if beam.id in beam_ids] # noqa: E501
263261

264262

265263
def convert_color_to_hex(

tests/integration/test_design.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2665,6 +2665,7 @@ def test_revolve_sketch_fail_invalid_path(modeler: Modeler):
26652665

26662666
def test_component_tree_print(modeler: Modeler):
26672667
"""Test for verifying the tree print for ``Component`` objects."""
2668+
26682669
def check_list_equality(lines, expected_lines):
26692670
# By doing "a in b" rather than "a == b", we can check for substrings
26702671
# which, in the case of beam ids, is necessary since they are unique

tests/integration/test_design_import.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,6 @@ def test_design_import_with_named_selections(modeler: Modeler):
383383
beam1 = design._named_selections["Beam1"]
384384
assert len(beam1.bodies) == 0
385385
assert len(beam1.beams) == 1
386-
386+
387387
beam = beam1.beams[0]
388-
assert beam._name == "B1"
388+
assert beam._name == "B1"

0 commit comments

Comments
 (0)