Skip to content

Commit 26c2158

Browse files
unskipped design tests
adding more beams support
1 parent 5f92630 commit 26c2158

File tree

3 files changed

+253
-36
lines changed

3 files changed

+253
-36
lines changed

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

Lines changed: 203 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# SOFTWARE.
2222
"""Provides for creating and managing a beam."""
2323

24+
from enum import Enum
2425
from typing import TYPE_CHECKING
2526

2627
from ansys.geometry.core.math.point import Point3D
@@ -30,6 +31,31 @@
3031

3132
if TYPE_CHECKING: # pragma: no cover
3233
from ansys.geometry.core.designer.component import Component
34+
from ansys.geometry.core.designer.part import Part
35+
from ansys.geometry.core.materials.material import Material
36+
from ansys.geometry.core.math.frame import Frame
37+
from ansys.geometry.core.shapes.curves.trimmed_curve import TrimmedCurve
38+
from ansys.geometry.core.shapes.parameterization import ParamUV
39+
40+
41+
class BeamType(Enum):
42+
"""Provides values for the beam types supported."""
43+
44+
BEAM = 0
45+
SPRING = 1
46+
LINK_TRUSS = 2
47+
CABLE = 3
48+
PIPE = 4
49+
THERMALFLUID = 5
50+
UNKNOWN = 6
51+
52+
53+
class SectionAnchorType(Enum):
54+
"""Provides values for the section anchor types supported."""
55+
56+
CENTROID = 0
57+
SHEAR_CENTER = 1
58+
ANCHOR_LOCATION = 2
3359

3460

3561
class BeamProfile:
@@ -66,7 +92,6 @@ def name(self) -> str:
6692
"""Name of the beam profile."""
6793
return self._name
6894

69-
7095
class BeamCircularProfile(BeamProfile):
7196
"""Represents a single circular beam profile.
7297
@@ -145,6 +170,162 @@ def __repr__(self) -> str:
145170
return "\n".join(lines)
146171

147172

173+
class BeamCrossSectionInfo:
174+
"""Represents the cross-section information for a beam.
175+
176+
Parameters
177+
----------
178+
section_anchor : SectionAnchorType
179+
Specifies how the beam section is anchored to the beam path.
180+
section_angle : float
181+
The rotation angle of the cross section clockwise from the default perpendicular of the
182+
beam path.
183+
section_frame : Frame
184+
The section frame at the start of the beam.
185+
section_profile : BeamProfile
186+
The section profile in the XY plane.
187+
"""
188+
189+
def __init__(
190+
self,
191+
section_anchor: SectionAnchorType,
192+
section_angle: float,
193+
section_frame: Frame,
194+
section_profile: BeamProfile,
195+
):
196+
"""Initialize ``BeamCrossSectionInfo`` class."""
197+
check_type(section_anchor, SectionAnchorType)
198+
check_type(section_angle, float)
199+
check_type(section_frame, Frame)
200+
check_type(section_profile, BeamProfile)
201+
202+
self._section_anchor = section_anchor
203+
self._section_angle = section_angle
204+
self._section_frame = section_frame
205+
self._section_profile = section_profile
206+
207+
@property
208+
def section_anchor(self) -> SectionAnchorType:
209+
"""Specifies how the beam section is anchored to the beam path."""
210+
return self._section_anchor
211+
212+
@property
213+
def section_angle(self) -> float:
214+
"""The rotation angle of the cross section clockwise from the default perpendicular of the beam path."""
215+
return self._section_angle
216+
217+
@property
218+
def section_frame(self) -> Frame:
219+
"""The section frame at the start of the beam."""
220+
return self._section_frame
221+
222+
@property
223+
def section_profile(self) -> BeamProfile:
224+
"""The section profile in the XY plane."""
225+
return self._section_profile
226+
227+
def __repr__(self) -> str:
228+
"""Represent the ``BeamCrossSectionInfo`` as a string."""
229+
lines = [f"ansys.geometry.core.designer.BeamCrossSectionInfo {hex(id(self))}"]
230+
lines.append(f" Section Anchor : {self.section_anchor.name}")
231+
lines.append(f" Section Angle : {self.section_angle}")
232+
lines.append(f" Section Frame : {self.section_frame}")
233+
lines.extend(["\n", " Section Profile info", " -------------------", str(self.section_profile)])
234+
return "\n".join(lines)
235+
236+
class BeamProperties:
237+
"""Represents the properties of a beam.
238+
239+
Parameters
240+
----------
241+
area : float
242+
The cross-sectional area of the beam.
243+
centroid : ParamUV
244+
The centroid of the beam section.
245+
warping_constant : float
246+
The warping constant of the beam.
247+
ixx : float
248+
The moment of inertia about the x-axis.
249+
ixy : float
250+
The product of inertia.
251+
iyy : float
252+
The moment of inertia about the y-axis.
253+
shear_center : ParamUV
254+
The shear center of the beam.
255+
torsion_constant : float
256+
The torsion constant of the beam.
257+
"""
258+
259+
def __init__(
260+
self,
261+
area: float,
262+
centroid: ParamUV,
263+
warping_constant: float,
264+
ixx: float,
265+
ixy: float,
266+
iyy: float,
267+
shear_center: ParamUV,
268+
torsion_constant: float,
269+
):
270+
"""Initialize ``BeamProperties`` class."""
271+
check_type(area, float)
272+
check_type(centroid, ParamUV)
273+
check_type(warping_constant, float)
274+
check_type(ixx, float)
275+
check_type(ixy, float)
276+
check_type(iyy, float)
277+
check_type(shear_center, ParamUV)
278+
check_type(torsion_constant, float)
279+
280+
self._area = area
281+
self._centroid = centroid
282+
self._warping_constant = warping_constant
283+
self._ixx = ixx
284+
self._ixy = ixy
285+
self._iyy = iyy
286+
self._shear_center = shear_center
287+
self._torsion_constant = torsion_constant
288+
289+
@property
290+
def area(self) -> float:
291+
"""The cross-sectional area of the beam."""
292+
return self._area
293+
294+
@property
295+
def centroid(self) -> ParamUV:
296+
"""The centroid of the beam section."""
297+
return self._centroid
298+
299+
@property
300+
def warping_constant(self) -> float:
301+
"""The warping constant of the beam."""
302+
return self._warping_constant
303+
304+
@property
305+
def ixx(self) -> float:
306+
"""The moment of inertia about the x-axis."""
307+
return self._ixx
308+
309+
@property
310+
def ixy(self) -> float:
311+
"""The product of inertia."""
312+
return self._ixy
313+
314+
@property
315+
def iyy(self) -> float:
316+
"""The moment of inertia about the y-axis."""
317+
return self._iyy
318+
319+
@property
320+
def shear_center(self) -> ParamUV:
321+
"""The shear center of the beam."""
322+
return self._shear_center
323+
324+
@property
325+
def torsion_constant(self) -> float:
326+
"""The torsion constant of the beam."""
327+
return self._torsion_constant
328+
148329
class Beam:
149330
"""Represents a simplified solid body with an assigned 2D cross-section.
150331
@@ -172,7 +353,17 @@ def __init__(
172353
start: Point3D,
173354
end: Point3D,
174355
profile: BeamProfile,
175-
parent_component: "Component",
356+
parent_component: Component,
357+
name: str = None,
358+
is_deleted: bool = False,
359+
is_reversed: bool = False,
360+
is_rigid: bool = False,
361+
material: Material = None,
362+
cross_section: BeamCrossSectionInfo = None,
363+
properties: BeamProperties = None,
364+
shape: TrimmedCurve = None,
365+
type: BeamType = None,
366+
176367
):
177368
"""Initialize ``Beam`` class."""
178369
from ansys.geometry.core.designer.component import Component
@@ -189,6 +380,16 @@ def __init__(
189380
self._profile = profile
190381
self._parent_component = parent_component
191382
self._is_alive = True
383+
self._name = name
384+
self._id = id
385+
self._is_deleted = is_deleted
386+
self._is_reversed = is_reversed
387+
self._is_rigid = is_rigid
388+
self._material = material
389+
self._cross_section = cross_section
390+
self._properties = properties
391+
self._shape = shape
392+
self._type = type
192393

193394
@property
194395
def id(self) -> str:

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

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
from ansys.api.geometry.v0.models_pb2 import Direction, Line, TrimmedCurveList
6060
from ansys.geometry.core.connection.client import GrpcClient
6161
from ansys.geometry.core.connection.conversions import (
62+
grpc_beam_to_beam,
63+
grpc_material_to_material,
6264
grpc_matrix_to_matrix,
6365
plane_to_grpc_plane,
6466
point3d_to_grpc_point,
@@ -89,6 +91,7 @@
8991
from ansys.geometry.core.shapes.curves.trimmed_curve import TrimmedCurve
9092
from ansys.geometry.core.shapes.parameterization import Interval
9193
from ansys.geometry.core.shapes.surfaces import TrimmedSurface
94+
from ansys.geometry.core.sketch.arc import Arc
9295
from ansys.geometry.core.sketch.sketch import Sketch
9396
from ansys.geometry.core.typing import Real
9497

@@ -1121,7 +1124,11 @@ def translate_bodies(
11211124
@check_input_types
11221125
@ensure_design_is_active
11231126
def create_beams(
1124-
self, segments: list[tuple[Point3D, Point3D]], profile: BeamProfile
1127+
self,
1128+
segments: list[tuple[Point3D, Point3D]],
1129+
profile: BeamProfile,
1130+
arcs: list[Arc] = None,
1131+
circles: list[Circle] = None,
11251132
) -> list[Beam]:
11261133
"""Create beams under the component.
11271134
@@ -1131,6 +1138,10 @@ def create_beams(
11311138
list of start and end pairs, each specifying a single line segment.
11321139
profile : BeamProfile
11331140
Beam profile to use to create the beams.
1141+
arcs : list[Curve], default: None
1142+
list of arcs to create beams from.
1143+
circles : list[Curve], default: None
1144+
list of circles to create beams from.
11341145
11351146
Returns
11361147
-------
@@ -1145,7 +1156,7 @@ def create_beams(
11451156
if self._grpc_client.backend_version < (25, 2, 0):
11461157
return self.__create_beams_legacy(segments, profile)
11471158
else:
1148-
return self.__create_beams(segments, profile)
1159+
return self.__create_beams(segments, profile, arcs, circles)
11491160

11501161
def __create_beams_legacy(self, segments: list[tuple[Point3D, Point3D]], profile: BeamProfile
11511162
) -> list[Beam]:
@@ -1191,8 +1202,12 @@ def __create_beams_legacy(self, segments: list[tuple[Point3D, Point3D]], profile
11911202
self._beams.extend(new_beams)
11921203
return self._beams[-n_beams:]
11931204

1194-
beams = []
1195-
def __create_beams(self, segments: list[tuple[Point3D, Point3D]], profile: BeamProfile
1205+
def __create_beams(
1206+
self,
1207+
segments: list[tuple[Point3D, Point3D]],
1208+
profile: BeamProfile,
1209+
arcs: list[Arc] = None,
1210+
circles: list[Circle] = None,
11961211
) -> list[Beam]:
11971212
"""Create beams under the component.
11981213
@@ -1208,31 +1223,39 @@ def __create_beams(self, segments: list[tuple[Point3D, Point3D]], profile: BeamP
12081223
list[Beam]
12091224
A list of the created Beams.
12101225
"""
1226+
request = CreateBeamSegmentRequest(
1227+
profile=profile.id,
1228+
parent=self.id,
1229+
)
1230+
12111231
for segment in segments:
1212-
request = CreateBeamSegmentRequest(
1213-
profile=profile.id,
1214-
parent=self.id,
1232+
request.lines.append(
1233+
Line(start=point3d_to_grpc_point(segment[0]), end=point3d_to_grpc_point(segment[1]))
12151234
)
12161235

1217-
for segment in segments:
1218-
request.lines.append(
1219-
Line(start=point3d_to_grpc_point(segment[0]), end=point3d_to_grpc_point(segment[1]))
1220-
)
1236+
self._grpc_client.log.debug(f"Creating beams on {self.id}...")
1237+
response = self._commands_stub.CreateDescriptiveBeamSegments(request)
1238+
self._grpc_client.log.debug("Beams successfully created.")
12211239

1222-
self._grpc_client.log.debug(f"Creating beams on {self.id}...")
1223-
response = self._commands_stub.CreateBeamSegments(request)
1224-
self._grpc_client.log.debug("Beams successfully created.")
1225-
1226-
for beam in response.created_beams:
1227-
beams.append(
1228-
Beam(
1229-
id = beam.id,
1230-
start = ,
1231-
end = ,
1232-
profile=profile,
1233-
parent_component=self,
1234-
)
1240+
beams = []
1241+
for beam in response.created_beams:
1242+
beams.append(
1243+
Beam(
1244+
beam.name,
1245+
beam.can_suppress,
1246+
beam.is_deleted,
1247+
beam.is_reversed,
1248+
beam.is_rigid,
1249+
grpc_material_to_material(beam.material),
1250+
beam.id,
1251+
self,
1252+
grpc_cross_section_to_cross_section(beam.cross_section),
1253+
grpc_beam_properties_to_beam_properties(beam.properties),
1254+
beam.shape,
1255+
beam.type,
1256+
beams.append(grpc_beam_to_beam(beam))
12351257
)
1258+
)
12361259

12371260
return beams
12381261

0 commit comments

Comments
 (0)