Skip to content

Commit 71d3606

Browse files
smereupyansys-ci-botjacobrkerstetterpre-commit-ci[bot]
authored
chore: v1 implementation of beam stub (#2444)
Co-authored-by: PyAnsys CI Bot <[email protected]> Co-authored-by: Jacob Kerstetter <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 6a12650 commit 71d3606

File tree

3 files changed

+247
-7
lines changed

3 files changed

+247
-7
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Chore: v1 implementation of beam stub

src/ansys/geometry/core/_grpc/_services/v1/beams.py

Lines changed: 198 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,22 @@
2424
import grpc
2525

2626
from ansys.geometry.core.errors import protect_grpc
27+
from ansys.geometry.core.misc.measurements import DEFAULT_UNITS
2728

2829
from ..base.beams import GRPCBeamsService
30+
from ..base.conversions import to_distance
31+
from .conversions import (
32+
build_grpc_id,
33+
from_grpc_angle_to_angle,
34+
from_grpc_curve_to_curve,
35+
from_grpc_frame_to_frame,
36+
from_grpc_material_to_material,
37+
from_grpc_point_to_point3d,
38+
from_grpc_quantity_to_distance,
39+
from_grpc_quantity_to_float,
40+
from_plane_to_grpc_plane,
41+
from_point3d_to_grpc_point,
42+
)
2943

3044

3145
class GRPCBeamsServiceV1(GRPCBeamsService):
@@ -43,26 +57,203 @@ class GRPCBeamsServiceV1(GRPCBeamsService):
4357

4458
@protect_grpc
4559
def __init__(self, channel: grpc.Channel): # noqa: D102
46-
from ansys.api.discovery.v1.assignments.beams import BeamsStub
60+
from ansys.api.discovery.v1.design.extensions.beam_pb2_grpc import (
61+
BeamStub,
62+
)
63+
from ansys.api.discovery.v1.engineeringdata.beamprofiledata_pb2_grpc import (
64+
BeamProfileDataStub,
65+
)
4766

48-
self.stub = BeamsStub(channel)
67+
self.beam_profile_commands_stub = BeamProfileDataStub(channel)
68+
self.beam_commands_stub = BeamStub(channel)
4969

5070
@protect_grpc
5171
def create_beam_segments(self, **kwargs) -> dict: # noqa: D102
52-
raise NotImplementedError
72+
from ansys.api.discovery.v1.commonmessages_pb2 import Line
73+
from ansys.api.discovery.v1.engineeringdata.beamprofiledata_pb2 import (
74+
CreateBeamProfileSegmentsRequest,
75+
CreateBeamProfileSegmentsRequestData,
76+
)
77+
78+
# Create the gRPC Line objects
79+
lines = []
80+
for segment in kwargs["segments"]:
81+
lines.append(
82+
Line(
83+
start=from_point3d_to_grpc_point(segment[0]),
84+
end=from_point3d_to_grpc_point(segment[1]),
85+
)
86+
)
87+
88+
# Create the request - assumes all inputs are valid and of the proper type
89+
request = CreateBeamProfileSegmentsRequest(
90+
request_data=[
91+
CreateBeamProfileSegmentsRequestData(
92+
profile_id=build_grpc_id(kwargs["profile_id"]),
93+
parent_id=build_grpc_id(kwargs["parent_id"]),
94+
lines=lines,
95+
)
96+
]
97+
)
98+
99+
# Call the gRPC service
100+
response = self.beam_profile_commands_stub.CreateSegments(request)
101+
102+
# Return the response - formatted as a dictionary
103+
return {
104+
"beam_ids": [
105+
[beam.id for beam in response_data.beams_ids]
106+
for response_data in response.response_data
107+
]
108+
}
53109

54110
@protect_grpc
55111
def create_descriptive_beam_segments(self, **kwargs) -> dict: # noqa: D102
56-
raise NotImplementedError
112+
from ansys.api.discovery.v1.commonmessages_pb2 import Line
113+
from ansys.api.discovery.v1.engineeringdata.beamprofiledata_pb2 import (
114+
CreateBeamProfileSegmentsRequest,
115+
CreateBeamProfileSegmentsRequestData,
116+
)
117+
118+
from ansys.geometry.core.shapes.parameterization import Interval, ParamUV
119+
120+
# Create the gRPC Line objects
121+
lines = []
122+
for segment in kwargs["segments"]:
123+
lines.append(
124+
Line(
125+
start=from_point3d_to_grpc_point(segment[0]),
126+
end=from_point3d_to_grpc_point(segment[1]),
127+
)
128+
)
129+
130+
# Create the request - assumes all inputs are valid and of the proper type
131+
request = CreateBeamProfileSegmentsRequest(
132+
request_data=[
133+
CreateBeamProfileSegmentsRequestData(
134+
profile_id=build_grpc_id(kwargs["profile_id"]),
135+
parent_id=build_grpc_id(kwargs["parent_id"]),
136+
lines=lines,
137+
)
138+
]
139+
)
140+
141+
# Call the gRPC service
142+
response = self.beam_profile_commands_stub.CreateDescriptiveSegments(request)
143+
144+
# Return the response - formatted as a dictionary
145+
return {
146+
"created_beams": [
147+
{
148+
"cross_section": {
149+
"section_anchor": beam.cross_section.section_anchor,
150+
"section_angle": (
151+
from_grpc_angle_to_angle(beam.cross_section.section_angle)
152+
).m_as(DEFAULT_UNITS.SERVER_ANGLE),
153+
"section_frame": from_grpc_frame_to_frame(beam.cross_section.section_frame),
154+
"section_profile": [
155+
[
156+
{
157+
"geometry": from_grpc_curve_to_curve(curve.curve),
158+
"start": from_grpc_point_to_point3d(curve.start),
159+
"end": from_grpc_point_to_point3d(curve.end),
160+
"interval": Interval(curve.interval_start, curve.interval_end),
161+
"length": to_distance(curve.length).value,
162+
}
163+
for curve in curve_list.curves
164+
]
165+
for curve_list in beam.cross_section.section_profile
166+
],
167+
},
168+
"properties": {
169+
"area": from_grpc_quantity_to_float(beam.properties.area),
170+
"centroid": ParamUV(beam.properties.centroid_x, beam.properties.centroid_y),
171+
"warping_constant": from_grpc_quantity_to_float(
172+
beam.properties.warping_constant
173+
),
174+
"ixx": from_grpc_quantity_to_float(beam.properties.ixx),
175+
"ixy": from_grpc_quantity_to_float(beam.properties.ixy),
176+
"iyy": from_grpc_quantity_to_float(beam.properties.iyy),
177+
"shear_center": ParamUV(
178+
beam.properties.shear_center_x, beam.properties.shear_center_y
179+
),
180+
"torsional_constant": from_grpc_quantity_to_float(
181+
beam.properties.torsional_constant
182+
),
183+
},
184+
"id": beam.id.id,
185+
"start": from_grpc_point_to_point3d(beam.shape.start),
186+
"end": from_grpc_point_to_point3d(beam.shape.end),
187+
"name": beam.name,
188+
"is_deleted": beam.is_deleted,
189+
"is_reversed": beam.is_reversed,
190+
"is_rigid": beam.is_rigid,
191+
"material": from_grpc_material_to_material(beam.material),
192+
"shape": {
193+
"geometry": from_grpc_curve_to_curve(beam.shape.curve),
194+
"start": from_grpc_point_to_point3d(beam.shape.start),
195+
"end": from_grpc_point_to_point3d(beam.shape.end),
196+
"interval": Interval(beam.shape.interval_start, beam.shape.interval_end),
197+
"length": from_grpc_quantity_to_distance(beam.shape.length),
198+
},
199+
"beam_type": beam.type,
200+
}
201+
for response_data in response.response_data
202+
for beam in response_data.beams
203+
],
204+
}
57205

58206
@protect_grpc
59207
def delete_beam(self, **kwargs) -> dict: # noqa: D102
60-
raise NotImplementedError
208+
from ansys.api.discovery.v1.commonmessages_pb2 import MultipleEntitiesRequest
209+
210+
# Create the request - assumes all inputs are valid and of the proper type
211+
request = MultipleEntitiesRequest(ids=[build_grpc_id(kwargs["beam_id"])])
212+
213+
# Call the gRPC service
214+
_ = self.beam_commands_stub.Delete(request)
215+
216+
# Return the response - formatted as a dictionary
217+
return {}
61218

62219
@protect_grpc
63220
def delete_beam_profile(self, **kwargs) -> dict: # noqa: D102
64-
raise NotImplementedError
221+
from ansys.api.discovery.v1.commonmessages_pb2 import MultipleEntitiesRequest
222+
223+
# Create the request - assumes all inputs are valid and of the proper type
224+
request = MultipleEntitiesRequest(ids=[build_grpc_id(kwargs["id"])])
225+
226+
# Call the gRPC service
227+
_ = self.beam_profile_commands_stub.Delete(request)
228+
229+
# Return the response - formatted as a dictionary
230+
return {}
65231

66232
@protect_grpc
67233
def create_beam_circular_profile(self, **kwargs) -> dict: # noqa: D102
68-
raise NotImplementedError
234+
from ansys.api.discovery.v1.engineeringdata.beamprofiledata_pb2 import (
235+
CreateBeamProfileCircularRequest,
236+
CreateBeamProfileCircularRequestData,
237+
)
238+
239+
from .conversions import from_length_to_grpc_quantity
240+
241+
# Create the request - assumes all inputs are valid and of the proper type
242+
request = CreateBeamProfileCircularRequest(
243+
request_data=[
244+
CreateBeamProfileCircularRequestData(
245+
origin=from_point3d_to_grpc_point(kwargs["center"]),
246+
radius=from_length_to_grpc_quantity(kwargs["radius"]),
247+
plane=from_plane_to_grpc_plane(kwargs["plane"]),
248+
name=kwargs["name"],
249+
)
250+
]
251+
)
252+
253+
# Call the gRPC service
254+
response = self.beam_profile_commands_stub.CreateCircular(request)
255+
256+
# Return the response - formatted as a dictionary
257+
# Note: response.ids is a repeated field, we return the first one
258+
created_beam_entity = response.ids[0]
259+
return {"id": created_beam_entity.id}

src/ansys/geometry/core/_grpc/_services/v1/conversions.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,22 @@ def from_length_to_grpc_quantity(input: "Distance") -> GRPCQuantity:
14281428
return GRPCQuantity(value_in_geometry_units=input.value.m_as(DEFAULT_UNITS.SERVER_LENGTH))
14291429

14301430

1431+
def from_grpc_quantity_to_distance(input: "GRPCQuantity") -> Distance:
1432+
"""Convert a gRPC quantity to ``Distance`` containing a length.
1433+
1434+
Parameters
1435+
----------
1436+
input : GRPCQuantity
1437+
Source measurement data.
1438+
1439+
Returns
1440+
-------
1441+
Distance
1442+
Converted Distance quantity.
1443+
"""
1444+
return Distance(input.value_in_geometry_units, DEFAULT_UNITS.SERVER_LENGTH)
1445+
1446+
14311447
def from_angle_to_grpc_quantity(input: "Measurement") -> GRPCQuantity:
14321448
"""Convert a ``Measurement`` containing an angle to a gRPC quantity.
14331449
@@ -1444,6 +1460,22 @@ def from_angle_to_grpc_quantity(input: "Measurement") -> GRPCQuantity:
14441460
return GRPCQuantity(value_in_geometry_units=input.value.m_as(DEFAULT_UNITS.SERVER_ANGLE))
14451461

14461462

1463+
def from_grpc_angle_to_angle(grpc_quantity: GRPCQuantity) -> "pint.Quantity":
1464+
"""Convert a gRPC quantity representing an angle to a pint Quantity.
1465+
1466+
Parameters
1467+
----------
1468+
grpc_quantity : GRPCQuantity
1469+
Source gRPC quantity data.
1470+
1471+
Returns
1472+
-------
1473+
Measurement
1474+
Converted angle quantity with server angle units.
1475+
"""
1476+
return pint.Quantity(grpc_quantity.value_in_geometry_units, DEFAULT_UNITS.SERVER_ANGLE)
1477+
1478+
14471479
def from_area_to_grpc_quantity(input: "Measurement") -> GRPCQuantity:
14481480
"""Convert a ``Measurement`` containing an area to a gRPC quantity.
14491481
@@ -1492,6 +1524,22 @@ def from_grpc_volume_to_volume(grpc_quantity: GRPCQuantity) -> "pint.Quantity":
14921524
return pint.Quantity(grpc_quantity.value_in_geometry_units, DEFAULT_UNITS.SERVER_VOLUME)
14931525

14941526

1527+
def from_grpc_quantity_to_float(grpc_quantity: GRPCQuantity) -> float:
1528+
"""Convert a gRPC quantity to a float.
1529+
1530+
Parameters
1531+
----------
1532+
grpc_quantity : GRPCQuantity
1533+
Source gRPC quantity data.
1534+
1535+
Returns
1536+
-------
1537+
float
1538+
The float value contained in the quantity.
1539+
"""
1540+
return grpc_quantity.value_in_geometry_units
1541+
1542+
14951543
def from_parameter_to_grpc_quantity(value: float) -> GRPCQuantity:
14961544
"""Convert a dimensionless parameter to a gRPC quantity.
14971545

0 commit comments

Comments
 (0)