Skip to content

Commit bd7bf01

Browse files
Revathyvenugopal162RobPasMueMaxJPRey
authored
Add design points and modify named selection (#219)
Co-authored-by: Roberto Pastor Muela <roberto.pastormuela@ansys.com> Co-authored-by: Maxime Rey <87315832+MaxJPRey@users.noreply.github.com> Co-authored-by: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com>
1 parent 044b6a6 commit bd7bf01

File tree

6 files changed

+244
-3
lines changed

6 files changed

+244
-3
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from ansys.geometry.core.designer.body import Body, MidSurfaceOffsetType, TemplateBody
44
from ansys.geometry.core.designer.component import Component, SharedTopologyType
55
from ansys.geometry.core.designer.design import Design, DesignFileFormat
6+
from ansys.geometry.core.designer.designpoint import DesignPoint
67
from ansys.geometry.core.designer.edge import CurveType, Edge
78
from ansys.geometry.core.designer.face import Face, SurfaceType
89
from ansys.geometry.core.designer.part import Part, TransformedPart

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

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
TranslateRequest,
1313
)
1414
from ansys.api.geometry.v0.bodies_pb2_grpc import BodiesStub
15-
from ansys.api.geometry.v0.commands_pb2 import CreateBeamSegmentsRequest
15+
from ansys.api.geometry.v0.commands_pb2 import CreateBeamSegmentsRequest, CreateDesignPointsRequest
1616
from ansys.api.geometry.v0.commands_pb2_grpc import CommandsStub
1717
from ansys.api.geometry.v0.components_pb2 import (
1818
CreateRequest,
@@ -37,6 +37,7 @@
3737
from ansys.geometry.core.designer.beam import Beam, BeamProfile
3838
from ansys.geometry.core.designer.body import Body, TemplateBody
3939
from ansys.geometry.core.designer.coordinate_system import CoordinateSystem
40+
from ansys.geometry.core.designer.designpoint import DesignPoint
4041
from ansys.geometry.core.designer.face import Face
4142
from ansys.geometry.core.designer.part import Part, TransformedPart
4243
from ansys.geometry.core.errors import protect_grpc
@@ -96,6 +97,7 @@ class Component:
9697
_components: List["Component"]
9798
_beams: List[Beam]
9899
_coordinate_systems: List[CoordinateSystem]
100+
_design_points: List[DesignPoint]
99101

100102
@protect_grpc
101103
@check_input_types
@@ -132,6 +134,7 @@ def __init__(
132134
self._components = []
133135
self._beams = []
134136
self._coordinate_systems = []
137+
self._design_points = []
135138
self._parent_component = parent_component
136139
self._is_alive = True
137140
self._shared_topology = None
@@ -192,6 +195,11 @@ def beams(self) -> List[Beam]:
192195
"""``Beam`` objects inside of the component."""
193196
return self._beams
194197

198+
@property
199+
def design_points(self) -> List[DesignPoint]:
200+
"""``DesignPoint`` objects inside of the component."""
201+
return self._design_points
202+
195203
@property
196204
def coordinate_systems(self) -> List[CoordinateSystem]:
197205
"""``CoordinateSystem`` objects inside of the component."""
@@ -730,6 +738,57 @@ def delete_body(self, body: Union[Body, str]) -> None:
730738
)
731739
pass
732740

741+
def add_design_point(
742+
self,
743+
name: str,
744+
point: Point3D,
745+
) -> DesignPoint:
746+
"""Creates a single design point.
747+
748+
Parameters
749+
----------
750+
name : str
751+
User-defined label for the design points.
752+
points : Point3D
753+
3D point constituting the design point.
754+
"""
755+
return self.add_design_points(name, [point])[0]
756+
757+
@protect_grpc
758+
@check_input_types
759+
def add_design_points(
760+
self,
761+
name: str,
762+
points: List[Point3D],
763+
) -> List[DesignPoint]:
764+
"""Creates a list of design points.
765+
766+
Parameters
767+
----------
768+
name : str
769+
User-defined label for the design points.
770+
points : List[Point3D]
771+
List of 3D points constituting the design points.
772+
"""
773+
# Create DesignPoint objects server-side
774+
self._grpc_client.log.debug(f"Creating design points on {self.id}...")
775+
response = self._commands_stub.CreateDesignPoints(
776+
CreateDesignPointsRequest(
777+
points=[point3d_to_grpc_point(point) for point in points], parent=self.id
778+
)
779+
)
780+
self._grpc_client.log.debug("Design points successfully created.")
781+
782+
# Once created on the server, create them client side
783+
new_design_points = []
784+
n_design_points = len(response.ids)
785+
for index in range(n_design_points):
786+
new_design_points.append((DesignPoint(response.ids[index], name, points[index], self)))
787+
self._design_points.extend(new_design_points)
788+
789+
# Finally return the list of created DesignPoint objects
790+
return self._design_points[-n_design_points:]
791+
733792
@protect_grpc
734793
@check_input_types
735794
def delete_beam(self, beam: Union[Beam, str]) -> None:
@@ -1048,5 +1107,6 @@ def __repr__(self) -> str:
10481107
lines.append(f" N Bodies : {sum(alive_bodies)}")
10491108
lines.append(f" N Beams : {sum(alive_beams)}")
10501109
lines.append(f" N Coordinate Systems : {sum(alive_coords)}")
1110+
lines.append(f" N Design Points : {len(self.design_points)}")
10511111
lines.append(f" N Components : {sum(alive_comps)}")
10521112
return "\n".join(lines)

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424
from pint import Quantity
2525

2626
from ansys.geometry.core.connection import GrpcClient, plane_to_grpc_plane, point3d_to_grpc_point
27-
from ansys.geometry.core.designer.beam import BeamCircularProfile, BeamProfile
27+
from ansys.geometry.core.designer.beam import Beam, BeamCircularProfile, BeamProfile
2828
from ansys.geometry.core.designer.body import Body, MidSurfaceOffsetType
2929
from ansys.geometry.core.designer.component import Component, SharedTopologyType
30+
from ansys.geometry.core.designer.designpoint import DesignPoint
3031
from ansys.geometry.core.designer.edge import Edge
3132
from ansys.geometry.core.designer.face import Face
3233
from ansys.geometry.core.designer.selection import NamedSelection
@@ -213,6 +214,8 @@ def create_named_selection(
213214
bodies: Optional[List[Body]] = None,
214215
faces: Optional[List[Face]] = None,
215216
edges: Optional[List[Edge]] = None,
217+
beams: Optional[List[Beam]] = None,
218+
design_points: Optional[List[DesignPoint]] = None,
216219
) -> NamedSelection:
217220
"""Create a named selection on the active Geometry server instance.
218221
@@ -226,14 +229,24 @@ def create_named_selection(
226229
All faces to include in the named selection.
227230
edges : List[Edge], default: None
228231
All edges to include in the named selection.
232+
beams : List[Beam], default: None
233+
All beams to include in the named selection.
234+
design_points : List[DesignPoints], default: None
235+
All design points to include in the named selection.
229236
230237
Returns
231238
-------
232239
NamedSelection
233240
Newly created named selection maintaining references to all target entities.
234241
"""
235242
named_selection = NamedSelection(
236-
name, self._grpc_client, bodies=bodies, faces=faces, edges=edges
243+
name,
244+
self._grpc_client,
245+
bodies=bodies,
246+
faces=faces,
247+
edges=edges,
248+
beams=beams,
249+
design_points=design_points,
237250
)
238251
self._named_selections[named_selection.name] = named_selection
239252

@@ -479,4 +492,5 @@ def __repr__(self):
479492
lines.append(f" N Named Selections : {len(self.named_selections)}")
480493
lines.append(f" N Materials : {len(self.materials)}")
481494
lines.append(f" N Beam Profiles : {len(self.beam_profiles)}")
495+
lines.append(f" N Design Points : {len(self.design_points)}")
482496
return "\n".join(lines)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"""``DesignPoint`` class module."""
2+
3+
from beartype.typing import TYPE_CHECKING, Union
4+
5+
from ansys.geometry.core.math import Point3D
6+
from ansys.geometry.core.misc import check_type
7+
8+
if TYPE_CHECKING: # pragma: no cover
9+
from ansys.geometry.core.designer.component import Component
10+
11+
12+
class DesignPoint:
13+
"""
14+
Provides the ``DesignPoint`` class for creating design points in components.
15+
16+
Parameters
17+
----------
18+
id : str
19+
Server-defined ID for the design points.
20+
name : str
21+
User-defined label for the design points.
22+
points : Point3D
23+
3D point constituting the design points.
24+
parent_component : Component
25+
Parent component to nest the new design point under within the design assembly.
26+
"""
27+
28+
def __init__(self, id: str, name: str, point: Point3D, parent_component: "Component"):
29+
"""Constructor method for the ``DesignPoints`` class."""
30+
from ansys.geometry.core.designer.component import Component
31+
32+
check_type(id, str)
33+
check_type(name, str)
34+
check_type(point, Point3D)
35+
check_type(parent_component, Component)
36+
37+
self._id = id
38+
self._name = name
39+
self._value = point
40+
self._parent_component = parent_component
41+
42+
@property
43+
def id(self) -> str:
44+
"""ID of the design point."""
45+
return self._id
46+
47+
@property
48+
def name(self) -> str:
49+
"""Name of the design point."""
50+
return self._name
51+
52+
@property
53+
def value(self) -> Point3D:
54+
"""Design point value."""
55+
return self._value
56+
57+
@property
58+
def parent_component(self) -> Union["Component", None]:
59+
"""Component node that the design point is under."""
60+
return self._parent_component
61+
62+
def __repr__(self) -> str:
63+
"""String representation of the design points."""
64+
lines = [f"ansys.geometry.core.designer.DesignPoints {hex(id(self))}"]
65+
lines.append(f" Name : {self.name}")
66+
lines.append(f" Design Point : {self.value}")
67+
return "\n".join(lines)

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
from beartype.typing import List, Optional
77

88
from ansys.geometry.core.connection import GrpcClient
9+
from ansys.geometry.core.designer.beam import Beam
910
from ansys.geometry.core.designer.body import Body
11+
from ansys.geometry.core.designer.designpoint import DesignPoint
1012
from ansys.geometry.core.designer.edge import Edge
1113
from ansys.geometry.core.designer.face import Face
1214
from ansys.geometry.core.errors import protect_grpc
@@ -33,6 +35,10 @@ class NamedSelection:
3335
All faces to include in the named selection.
3436
edges : List[Edge], default: None
3537
All edges to include in the named selection.
38+
beams : List[Beam], default: None
39+
All beams to include in the named selection.
40+
design_points : List[DesignPoints], default: None
41+
All design_points to include in the named selection.
3642
"""
3743

3844
@protect_grpc
@@ -44,6 +50,8 @@ def __init__(
4450
bodies: Optional[List[Body]] = None,
4551
faces: Optional[List[Face]] = None,
4652
edges: Optional[List[Edge]] = None,
53+
beams: Optional[List[Beam]] = None,
54+
design_points: Optional[List[DesignPoint]] = None,
4755
):
4856
"""Constructor method for the ``NamedSelection`` class."""
4957

@@ -53,6 +61,10 @@ def __init__(
5361
faces = []
5462
if edges is None:
5563
edges = []
64+
if beams is None:
65+
beams = []
66+
if design_points is None:
67+
design_points = []
5668

5769
self._grpc_client = grpc_client
5870
self._named_selections_stub = NamedSelectionsStub(grpc_client.channel)
@@ -64,6 +76,8 @@ def __init__(
6476
[ids.add(body.id) for body in bodies]
6577
[ids.add(face.id) for face in faces]
6678
[ids.add(edge.id) for edge in edges]
79+
[ids.add(beam.id) for beam in beams]
80+
[ids.add(dp.id) for dp in design_points]
6781

6882
named_selection_request = CreateRequest(name=name, members=ids)
6983
self._grpc_client.log.debug("Requesting creation of named selection.")

tests/integration/test_design.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ def test_delete_body_component(modeler: Modeler):
656656
assert "N Named Selections : 0" in design_str
657657
assert "N Materials : 0" in design_str
658658
assert "N Beam Profiles : 0" in design_str
659+
assert "N Design Points : 0" in design_str
659660

660661
comp_1_str = str(comp_1)
661662
assert "ansys.geometry.core.designer.Component" in comp_1_str
@@ -665,6 +666,7 @@ def test_delete_body_component(modeler: Modeler):
665666
assert "N Bodies : 0" in comp_1_str
666667
assert "N Beams : 0" in comp_1_str
667668
assert "N Components : 0" in comp_1_str
669+
assert "N Design Points : 0" in comp_1_str
668670
assert "N Coordinate Systems : 0" in comp_1_str
669671

670672
body_1_str = str(body_1)
@@ -1178,6 +1180,89 @@ def test_midsurface_properties(modeler: Modeler):
11781180
assert "Surface offset : MidSurfaceOffsetType.BOTTOM" in surf_repr
11791181

11801182

1183+
def test_design_points(modeler: Modeler):
1184+
"""Test for verifying the ``DesignPoints``"""
1185+
1186+
# Create your design on the server side
1187+
design = modeler.create_design("DesignPoints")
1188+
point = Point3D([6, 66, 666], UNITS.mm)
1189+
design_points_1 = design.add_design_point("FirstPointSet", point)
1190+
1191+
# Check the design points
1192+
assert len(design.design_points) == 1
1193+
assert design_points_1.id is not None
1194+
assert design_points_1.name == "FirstPointSet"
1195+
assert design_points_1.value == point
1196+
1197+
# Create another set of design points
1198+
point_set_2 = [Point3D([10, 10, 10], UNITS.m), Point3D([20, 20, 20], UNITS.m)]
1199+
design_points_2 = design.add_design_points("SecondPointSet", point_set_2)
1200+
1201+
assert len(design.design_points) == 3
1202+
1203+
nested_component = design.add_component("NestedComponent")
1204+
design_point_3 = nested_component.add_design_point("Nested", Point3D([7, 77, 777], UNITS.mm))
1205+
1206+
assert design_point_3.id is not None
1207+
assert design_point_3.value == Point3D([7, 77, 777], UNITS.mm)
1208+
assert design_point_3.parent_component.id == nested_component.id
1209+
assert len(nested_component.design_points) == 1
1210+
assert nested_component.design_points[0] == design_point_3
1211+
1212+
design_point_1_str = str(design_points_1)
1213+
assert "ansys.geometry.core.designer.DesignPoint" in design_point_1_str
1214+
assert " Name : FirstPointSet" in design_point_1_str
1215+
assert " Design Point : [0.006 0.066 0.666]" in design_point_1_str
1216+
1217+
design_point_2_str = str(design_points_2)
1218+
assert "ansys.geometry.core.designer.DesignPoint" in design_point_2_str
1219+
assert " Name : SecondPointSet" in design_point_2_str
1220+
assert " Design Point : [10. 10. 10.]" in design_point_2_str
1221+
assert "ansys.geometry.core.designer.DesignPoint" in design_point_2_str
1222+
assert " Name : SecondPointSet" in design_point_2_str
1223+
assert " Design Point : [20. 20. 20.]" in design_point_2_str
1224+
1225+
1226+
def test_named_selections_beams(modeler: Modeler, skip_not_on_linux_service):
1227+
"""Test for verifying the correct creation of ``NamedSelection`` with beams."""
1228+
1229+
# Create your design on the server side
1230+
design = modeler.create_design("NamedSelectionBeams_Test")
1231+
1232+
# Test creating a named selection out of beams
1233+
circle_profile_1 = design.add_beam_circular_profile(
1234+
"CircleProfile1", Quantity(10, UNITS.mm), Point3D([0, 0, 0]), UNITVECTOR3D_X, UNITVECTOR3D_Y
1235+
)
1236+
beam_1 = design.create_beam(
1237+
Point3D([9, 99, 999], UNITS.mm), Point3D([8, 88, 888], UNITS.mm), circle_profile_1
1238+
)
1239+
ns_beams = design.create_named_selection("CircleProfile", beams=[beam_1])
1240+
assert len(design.named_selections) == 1
1241+
assert design.named_selections[0].name == "CircleProfile"
1242+
1243+
# Try deleting this named selection
1244+
design.delete_named_selection(ns_beams)
1245+
assert len(design.named_selections) == 0
1246+
1247+
1248+
def test_named_selections_design_points(modeler: Modeler):
1249+
"""Test for verifying the correct creation of ``NamedSelection`` with design points."""
1250+
1251+
# Create your design on the server side
1252+
design = modeler.create_design("NamedSelectionBeams_Test")
1253+
1254+
# Test creating a named selection out of design_points
1255+
point_set_1 = Point3D([10, 10, 0], UNITS.m)
1256+
design_points_1 = design.add_design_point("FirstPointSet", point_set_1)
1257+
ns_despoint = design.create_named_selection("FirstPointSet", design_points=[design_points_1])
1258+
assert len(design.named_selections) == 1
1259+
assert design.named_selections[0].name == "FirstPointSet"
1260+
1261+
# Try deleting this named selection
1262+
design.delete_named_selection(ns_despoint)
1263+
assert len(design.named_selections) == 0
1264+
1265+
11811266
def test_component_instances(modeler: Modeler, skip_not_on_linux_service):
11821267
"""Test creation of ``Component`` instances and the effects this has."""
11831268

0 commit comments

Comments
 (0)