Skip to content

Commit 3da9747

Browse files
beams imported from existing designs and existing named selections
1 parent ff07f5a commit 3da9747

File tree

3 files changed

+61
-20
lines changed

3 files changed

+61
-20
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def section_frame(self) -> Frame:
217217
return self._section_frame
218218

219219
@property
220-
def section_profile(self) -> BeamProfile:
220+
def section_profile(self) -> list[list[TrimmedCurve]] | None:
221221
"""The section profile in the XY plane."""
222222
return self._section_profile
223223

@@ -349,7 +349,9 @@ def __init__(
349349
id: str,
350350
start: Point3D,
351351
end: Point3D,
352-
profile: BeamProfile,
352+
profile: BeamProfile | None,
353+
# TODO: Beams need BeamProfiles imported from existing design
354+
# https://github.com/ansys/pyansys-geometry/issues/1825
353355
parent_component: "Component",
354356
name: str = None,
355357
is_deleted: bool = False,
@@ -359,7 +361,7 @@ def __init__(
359361
cross_section: BeamCrossSectionInfo = None,
360362
properties: BeamProperties = None,
361363
shape: TrimmedCurve = None,
362-
type: BeamType = None,
364+
beam_type: BeamType = None,
363365

364366
):
365367
"""Initialize ``Beam`` class."""
@@ -368,7 +370,7 @@ def __init__(
368370
check_type(id, str)
369371
check_type(start, Point3D)
370372
check_type(end, Point3D)
371-
check_type(profile, BeamProfile)
373+
check_type(profile, (type(None), BeamProfile))
372374
check_type(parent_component, Component)
373375

374376
self._id = id
@@ -378,15 +380,14 @@ def __init__(
378380
self._parent_component = parent_component
379381
self._is_alive = True
380382
self._name = name
381-
self._id = id
382383
self._is_deleted = is_deleted
383384
self._is_reversed = is_reversed
384385
self._is_rigid = is_rigid
385386
self._material = material
386387
self._cross_section = cross_section
387388
self._properties = properties
388389
self._shape = shape
389-
self._type = type
390+
self._type = beam_type
390391

391392
@property
392393
def id(self) -> str:

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,6 @@ def __create_beams(
12461246

12471247
beams = []
12481248
for beam in response.created_beams:
1249-
print(beam.cross_section.section_profile)
12501249
cross_section = BeamCrossSectionInfo(
12511250
SectionAnchorType(beam.cross_section.section_anchor),
12521251
beam.cross_section.section_angle,
@@ -1259,7 +1258,7 @@ def __create_beams(
12591258
Interval(curve.interval_start, curve.interval_end),
12601259
curve.length) for curve in curve_list]
12611260
for curve_list in beam.cross_section.section_profile],
1262-
)
1261+
)
12631262
properties = BeamProperties(
12641263
beam.properties.area,
12651264
ParamUV(beam.properties.centroid_x, beam.properties.centroid_y),

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

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
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
2830
from beartype import beartype as check_input_types
2931
from google.protobuf.empty_pb2 import Empty
3032
import numpy as np
@@ -57,13 +59,15 @@
5759
from ansys.api.geometry.v0.parts_pb2_grpc import PartsStub
5860
from ansys.geometry.core.connection.backend import BackendType
5961
from ansys.geometry.core.connection.conversions import (
62+
grpc_curve_to_curve,
6063
grpc_frame_to_frame,
64+
grpc_material_to_material,
6165
grpc_matrix_to_matrix,
6266
grpc_point_to_point3d,
6367
plane_to_grpc_plane,
6468
point3d_to_grpc_point,
6569
)
66-
from ansys.geometry.core.designer.beam import Beam, BeamCircularProfile, BeamProfile
70+
from ansys.geometry.core.designer.beam import Beam, BeamCircularProfile, BeamCrossSectionInfo, BeamProfile, BeamProperties, SectionAnchorType
6771
from ansys.geometry.core.designer.body import Body, MasterBody, MidSurfaceOffsetType
6872
from ansys.geometry.core.designer.component import Component, SharedTopologyType
6973
from ansys.geometry.core.designer.coordinate_system import CoordinateSystem
@@ -1138,6 +1142,53 @@ def __read_existing_design(self) -> None:
11381142
m = Material(material.name, density, properties)
11391143
self.materials.append(m)
11401144

1145+
# Create Beams
1146+
for beam in response.beams:
1147+
cross_section = BeamCrossSectionInfo(
1148+
SectionAnchorType(beam.cross_section.section_anchor),
1149+
beam.cross_section.section_angle,
1150+
grpc_frame_to_frame(beam.cross_section.section_frame),
1151+
[
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+
)
1160+
properties = BeamProperties(
1161+
beam.properties.area,
1162+
ParamUV(beam.properties.centroid_x, beam.properties.centroid_y),
1163+
beam.properties.warping_constant,
1164+
beam.properties.ixx,
1165+
beam.properties.ixy,
1166+
beam.properties.iyy,
1167+
ParamUV(beam.properties.shear_center_x, beam.properties.shear_center_y),
1168+
beam.properties.torsional_constant,
1169+
)
1170+
1171+
new_beam = Beam(
1172+
beam.id.id,
1173+
grpc_point_to_point3d(beam.shape.start),
1174+
grpc_point_to_point3d(beam.shape.end),
1175+
None,
1176+
# TODO: Beams need BeamProfiles imported from existing design
1177+
# https://github.com/ansys/pyansys-geometry/issues/1825
1178+
self,
1179+
beam.name,
1180+
beam.is_deleted,
1181+
beam.is_reversed,
1182+
beam.is_rigid,
1183+
grpc_material_to_material(beam.material),
1184+
cross_section,
1185+
properties,
1186+
beam.shape,
1187+
beam.type,
1188+
)
1189+
1190+
self._beams.append(new_beam)
1191+
11411192
# Create NamedSelections
11421193
for ns in response.named_selections:
11431194
result = self._named_selections_stub.Get(EntityIdentifier(id=ns.id))
@@ -1146,8 +1197,7 @@ def __read_existing_design(self) -> None:
11461197
bodies = get_bodies_from_ids(self, [body.id for body in result.bodies])
11471198
faces = get_faces_from_ids(self, [face.id for face in result.faces])
11481199
edges = get_edges_from_ids(self, [edge.id for edge in result.edges])
1149-
beams = get_beams_from_ids(self, [beam.id for beam in result.beams])
1150-
print(result.beams)
1200+
beams = get_beams_from_ids(self, [beam.id.id for beam in result.beams])
11511201

11521202
design_points = []
11531203
for dp in result.design_points:
@@ -1167,15 +1217,6 @@ def __read_existing_design(self) -> None:
11671217
)
11681218
self._named_selections[new_ns.name] = new_ns
11691219

1170-
# Create Beams
1171-
# for beam in response.beams:
1172-
# new_beam = Beam(
1173-
# beam.id,
1174-
1175-
# )
1176-
1177-
# self._beams.append(new_beam)
1178-
11791220
# Create CoordinateSystems
11801221
num_created_coord_systems = 0
11811222
for component_id, coordinate_systems in response.component_coord_systems.items():

0 commit comments

Comments
 (0)