Skip to content

Commit d3cd835

Browse files
authored
Create classes for enums (#125)
1 parent 7ef8d80 commit d3cd835

File tree

12 files changed

+344
-466
lines changed

12 files changed

+344
-466
lines changed

src/ansys/sherlock/core/analysis.py

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def run_analysis(
8383
- elements: list
8484
List of tuples (``type``, ``event``)
8585
86-
- analysis_type : RunAnalysisRequest.Analysis.AnalysisType
86+
- analysis_type : RunAnalysisRequestAnalysisType
8787
Type of analysis to run.
8888
8989
- event : list
@@ -116,7 +116,7 @@ def run_analysis(
116116
"Test",
117117
"Card",
118118
[
119-
(SherlockAnalysisService_pb2.RunAnalysisRequest.Analysis.AnalysisType.NaturalFreq,
119+
(RunAnalysisRequestAnalysisType.NATURAL_FREQ,
120120
[
121121
("Phase 1", ["Harmonic Event"])
122122
]
@@ -280,10 +280,6 @@ def update_harmonic_vibe_props(
280280
)
281281
282282
"""
283-
if self.FREQ_UNIT_LIST is None:
284-
self._init_freq_units()
285-
if self.TEMP_UNIT_LIST is None:
286-
self._init_temp_units()
287283
try:
288284
if project == "":
289285
raise SherlockUpdateHarmonicVibePropsError(message="Project name is invalid.")
@@ -355,15 +351,6 @@ def update_harmonic_vibe_props(
355351

356352
if "analysis_temp_units" in harmonic_vibe_props.keys():
357353
analysis_temp_units = harmonic_vibe_props["analysis_temp_units"]
358-
if (
359-
(self.TEMP_UNIT_LIST is not None)
360-
and (analysis_temp_units is not None)
361-
and (analysis_temp_units not in self.TEMP_UNIT_LIST)
362-
):
363-
raise SherlockUpdateHarmonicVibePropsError(
364-
message=f"Analysis temperature units are invalid for "
365-
f"harmonic vibe properties {i}: " + analysis_temp_units
366-
)
367354
else:
368355
analysis_temp_units = None
369356

@@ -384,15 +371,6 @@ def update_harmonic_vibe_props(
384371

385372
if "natural_freq_min_units" in harmonic_vibe_props.keys():
386373
natural_freq_min_units = harmonic_vibe_props["natural_freq_min_units"]
387-
if (
388-
(self.FREQ_UNIT_LIST is not None)
389-
and (natural_freq_min_units is not None)
390-
and (natural_freq_min_units not in self.FREQ_UNIT_LIST)
391-
):
392-
raise SherlockUpdateHarmonicVibePropsError(
393-
message=f"Minimum natural frequency units are invalid for "
394-
f"harmonic vibe properties {i}: " + natural_freq_min_units
395-
)
396374
else:
397375
natural_freq_min_units = None
398376

@@ -403,15 +381,6 @@ def update_harmonic_vibe_props(
403381

404382
if "natural_freq_max_units" in harmonic_vibe_props.keys():
405383
natural_freq_max_units = harmonic_vibe_props["natural_freq_max_units"]
406-
if (
407-
(self.FREQ_UNIT_LIST is not None)
408-
and (natural_freq_max_units is not None)
409-
and (natural_freq_max_units not in self.FREQ_UNIT_LIST)
410-
):
411-
raise SherlockUpdateHarmonicVibePropsError(
412-
message=f"Maximum natural frequency units are invalid for "
413-
f"harmonic vibe properties {i}: " + natural_freq_max_units
414-
)
415384
else:
416385
natural_freq_max_units = None
417386

@@ -512,7 +481,7 @@ def get_random_vibe_input_fields(self, model_source=None):
512481
cca_name="Card",
513482
)
514483
>>> sherlock.analysis.get_random_vibe_input_fields(
515-
model_source=SherlockAnalysisService_pb2.ModelSource.STRAIN_MAP
484+
model_source=ModelSource.STRAIN_MAP
516485
)
517486
"""
518487
if not self._is_connection_up():
@@ -629,7 +598,7 @@ def update_random_vibe_props(
629598
random_vibe_damping="0.01, 0.05",
630599
analysis_temp=20,
631600
analysis_temp_units="C",
632-
model_source=SherlockAnalysisService_pb2.ModelSource.STRAIN_MAP,
601+
model_source=ModelSource.STRAIN_MAP,
633602
)
634603
635604
"""
@@ -1004,13 +973,13 @@ def update_pcb_modeling_props(self, project, cca_names, analyses):
1004973
analyses : list
1005974
List of elements consisting of the following properties:
1006975
1007-
- analysis_type : UpdatePcbModelingPropsRequest.Analysis.AnalysisType
976+
- analysis_type : UpdatePcbModelingPropsRequestAnalysisType
1008977
Type of analysis applied.
1009-
- pcb_model_type : UpdatePcbModelingPropsRequest.Analysis.PcbModelType
978+
- pcb_model_type : UpdatePcbModelingPropsRequestPcbModelType
1010979
The PCB modeling mesh type.
1011980
- modeling_region_enabled : bool
1012981
Indicates if modeling regions are enabled.
1013-
- pcb_material_model : UpdatePcbModelingPropsRequest.Analysis.PcbMaterialModel
982+
- pcb_material_model : UpdatePcbModelingPropsRequestPcbMaterialModel
1014983
The PCB modeling PCB model type.
1015984
- pcb_max_materials : int
1016985
The number of PCB materials for Uniform Elements and Layered Elements PCB model
@@ -1044,11 +1013,11 @@ def update_pcb_modeling_props(self, project, cca_names, analyses):
10441013
["Main Board"],
10451014
[
10461015
(
1047-
update_request.Analysis.AnalysisType.NaturalFreq,
1048-
update_request.Analysis.PcbModelType.Bonded,
1016+
UpdatePcbModelingPropsRequestAnalysisType.HARMONIC_VIBE,
1017+
UpdatePcbModelingPropsRequestPcbModelType.BONDED,
10491018
True,
1050-
update_request.Analysis.PcbMaterialModel.Uniform,
1051-
SherlockAnalysisService_pb2.ElementOrder.SolidShell,
1019+
UpdatePcbModelingPropsRequestPcbMaterialModel.UNIFORM,
1020+
ElementOrder.SOLID_SHELL,
10521021
6,
10531022
"mm",
10541023
3,

src/ansys/sherlock/core/common.py

Lines changed: 7 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Common(GrpcStub):
1818

1919
def __init__(self, channel):
2020
"""Initialize a gRPC stub for the Sherlock Common service."""
21-
self.channel = channel
21+
super().__init__(channel)
2222
self.stub = SherlockCommonService_pb2_grpc.SherlockCommonServiceStub(channel)
2323

2424
def check(self):
@@ -73,99 +73,16 @@ def list_units(self, unitType):
7373
7474
Parameters
7575
----------
76-
unitType : string
77-
Unit type. Options are:
78-
79-
- ``"ACCEL_DENSITY"``
80-
- ``"ACCELERATION"``
81-
- ``"AREA"``
82-
- ``""BANDWIDTH"``
83-
- ``"CAPACITANCE"``
84-
- ``"CTE"``
85-
- ``"CURRENT"``
86-
- ``"DENSITY"``
87-
- ``"DISP_DENSITY"``
88-
- ``"FORCE"``
89-
- ``"FREQUENCY"``
90-
- ``"INDUCTANCE"``
91-
- ``"LENGTH"``
92-
- ``"POWER"``
93-
- ``"RESISTANCE"``
94-
- ``"SIZE"``
95-
- ``"SPECIFIC_HEAT"``
96-
- ``"STRAIN"``
97-
- ``"STRESS"``
98-
- ``"TEMPERATURE"``
99-
- ``"THERMAL_CONDUCTIVITY"``
100-
- ``"THERMAL_RESISTANCE"``
101-
- ``"TIME"``
102-
- ``"VELOCITY"``
103-
- ``"VELOCITY_DENSITY"``
104-
- ``"VOLTAGE"``
105-
- ``"VOLUME"``
106-
- ``"WEIGHT"``
76+
unitType : ListUnitsRequestUnitType
77+
Unit type.
10778
79+
Returns
80+
-------
81+
str
82+
Units for the unit type.
10883
"""
10984
if unitType == "":
11085
raise SherlockCommonServiceError(message="Unit type is missing.")
111-
elif unitType == "ACCEL_DENSITY":
112-
unitType = SherlockCommonService_pb2.ListUnitsRequest.ACCEL_DENSITY
113-
elif unitType == "ACCELERATION":
114-
unitType = SherlockCommonService_pb2.ListUnitsRequest.ACCELERATION
115-
elif unitType == "AREA":
116-
unitType = SherlockCommonService_pb2.ListUnitsRequest.AREA
117-
elif unitType == "BANDWIDTH":
118-
unitType = SherlockCommonService_pb2.ListUnitsRequest.BANDWIDTH
119-
elif unitType == "CAPACITANCE":
120-
unitType = SherlockCommonService_pb2.ListUnitsRequest.CAPACITANCE
121-
elif unitType == "CTE":
122-
unitType = SherlockCommonService_pb2.ListUnitsRequest.CTE
123-
elif unitType == "CURRENT":
124-
unitType = SherlockCommonService_pb2.ListUnitsRequest.CURRENT
125-
elif unitType == "DENSITY":
126-
unitType = SherlockCommonService_pb2.ListUnitsRequest.DENSITY
127-
elif unitType == "DISP_DENSITY":
128-
unitType = SherlockCommonService_pb2.ListUnitsRequest.DISP_DENSITY
129-
elif unitType == "FORCE":
130-
unitType = SherlockCommonService_pb2.ListUnitsRequest.FORCE
131-
elif unitType == "FREQUENCY":
132-
unitType = SherlockCommonService_pb2.ListUnitsRequest.FREQUENCY
133-
elif unitType == "INDUCTANCE":
134-
unitType = SherlockCommonService_pb2.ListUnitsRequest.INDUCTANCE
135-
elif unitType == "LENGTH":
136-
unitType = SherlockCommonService_pb2.ListUnitsRequest.LENGTH
137-
elif unitType == "POWER":
138-
unitType = SherlockCommonService_pb2.ListUnitsRequest.POWER
139-
elif unitType == "RESISTANCE":
140-
unitType = SherlockCommonService_pb2.ListUnitsRequest.RESISTANCE
141-
elif unitType == "SIZE":
142-
unitType = SherlockCommonService_pb2.ListUnitsRequest.SIZE
143-
elif unitType == "SPECIFIC_HEAT":
144-
unitType = SherlockCommonService_pb2.ListUnitsRequest.SPECIFIC_HEAT
145-
elif unitType == "STRAIN":
146-
unitType = SherlockCommonService_pb2.ListUnitsRequest.STRAIN
147-
elif unitType == "STRESS":
148-
unitType = SherlockCommonService_pb2.ListUnitsRequest.STRESS
149-
elif unitType == "TEMPERATURE":
150-
unitType = SherlockCommonService_pb2.ListUnitsRequest.TEMPERATURE
151-
elif unitType == "THERMAL_CONDUCTIVITY":
152-
unitType = SherlockCommonService_pb2.ListUnitsRequest.THERMAL_CONDUCTIVITY
153-
elif unitType == "THERMAL_RESISTANCE":
154-
unitType = SherlockCommonService_pb2.ListUnitsRequest.THERMAL_RESISTANCE
155-
elif unitType == "TIME":
156-
unitType = SherlockCommonService_pb2.ListUnitsRequest.TIME
157-
elif unitType == "VELOCITY":
158-
unitType = SherlockCommonService_pb2.ListUnitsRequest.VELOCITY
159-
elif unitType == "VELOCITY_DENSITY":
160-
unitType = SherlockCommonService_pb2.ListUnitsRequest.VELOCITY_DENSITY
161-
elif unitType == "VOLTAGE":
162-
unitType = SherlockCommonService_pb2.ListUnitsRequest.VOLTAGE
163-
elif unitType == "VOLUME":
164-
unitType = SherlockCommonService_pb2.ListUnitsRequest.VOLUME
165-
elif unitType == "WEIGHT":
166-
unitType = SherlockCommonService_pb2.ListUnitsRequest.WEIGHT
167-
else:
168-
raise SherlockCommonServiceError(message=f"Unit type '{unitType}' is invalid.")
16986

17087
if not self._is_connection_up():
17188
LOG.error("Not connected to a gRPC service.")
@@ -175,18 +92,10 @@ def list_units(self, unitType):
17592

17693
try:
17794
response = self.stub.listUnits(request)
178-
17995
return_code = response.returnCode
180-
18196
if return_code.value == -1:
182-
if return_code.message == "":
183-
raise SherlockCommonServiceError(error_array=response.errors)
184-
18597
raise SherlockCommonServiceError(message=return_code.message)
186-
18798
except SherlockCommonServiceError as e:
188-
for error in e.str_itr():
189-
LOG.error(error)
19099
raise e
191100

192101
return response.units

src/ansys/sherlock/core/model.py

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -289,62 +289,3 @@ def generate_trace_model(
289289
except Exception as e:
290290
LOG.error(str(e))
291291
raise
292-
293-
294-
# def set_trace_parameter(
295-
# trace_param=None,
296-
# trace_param_diameter_threshold_val=2,
297-
# trace_param_diameter_threshold_unit="mm",
298-
# trace_param_min_hole_diameter_val=0.25,
299-
# trace_param_min_hole_diameter_unit="mm",
300-
# ):
301-
# """Set the Trace Properties for the Export Trace Reinforcement Model operation."""
302-
# if trace_param is None:
303-
# trace_param = SherlockModelService_pb2.ExportTraceReinforcementModelRequest().TraceParam()
304-
# else:
305-
# if not isinstance(
306-
# trace_param, SherlockModelService_pb2.ExportTraceReinforcementModelRequest.TraceParam
307-
# ):
308-
# raise SherlockModelServiceError(
309-
# "trace_param object is not of type "
310-
# "SherlockModelService_pb2.ExportTraceReinforcementModelRequest.TraceParam."
311-
# )
312-
313-
# trace_param.diameterThreshold.value = trace_param_diameter_threshold_val
314-
# trace_param.diameterThreshold.unit = trace_param_diameter_threshold_unit
315-
# trace_param.minHoleDiameterForShellOrBeam.value = trace_param_min_hole_diameter_val
316-
# trace_param.minHoleDiameterForShellOrBeam.unit = trace_param_min_hole_diameter_unit
317-
318-
# return trace_param
319-
320-
321-
# def set_trace_drill_hole_parameter(
322-
# trace_drill_hole_param=None,
323-
# trace_drill_hole_modeling="DISABLED",
324-
# trace_drill_hole_min_diameter_val=2,
325-
# trace_drill_hole_min_diameter_unit="mm",
326-
# trace_drill_hole_max_edge_val=1,
327-
# trace_drill_hole_max_edge_unit="mm",
328-
# ):
329-
# """Set the drill hole properties for exporting the trace reinforcement model."""
330-
# if trace_drill_hole_param is None:
331-
# trace_drill_hole_param = (
332-
# SherlockModelService_pb2.ExportTraceReinforcementModelRequest().TraceDrillHoleParam()
333-
# )
334-
# else:
335-
# if not isinstance(
336-
# trace_drill_hole_param,
337-
# SherlockModelService_pb2.ExportTraceReinforcementModelRequest.TraceDrillHoleParam,
338-
# ):
339-
# raise SherlockModelServiceError(
340-
# "trace_drill_hole_param object is not of type "
341-
# "SherlockModelService_pb2.ExportTraceReinforcementModelRequest.TraceDrillHoleParam."
342-
# )
343-
344-
# trace_drill_hole_param.drillHoleModeling = trace_drill_hole_modeling
345-
# trace_drill_hole_param.minHoleDiameter.value = trace_drill_hole_min_diameter_val
346-
# trace_drill_hole_param.minHoleDiameter.unit = trace_drill_hole_min_diameter_unit
347-
# trace_drill_hole_param.maxEdgeLength.value = trace_drill_hole_max_edge_val
348-
# trace_drill_hole_param.maxEdgeLength.unit = trace_drill_hole_max_edge_unit
349-
350-
# return trace_drill_hole_param

src/ansys/sherlock/core/parts.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def _init_location_units(self):
142142
self.PART_LOCATION_UNITS = part_location_response.units
143143

144144
def _init_board_sides(self):
145-
"""Initialize boad sides."""
145+
"""Initialize board sides."""
146146
if self._is_connection_up():
147147
board_sides_request = SherlockPartsService_pb2.GetBoardSidesRequest()
148148
board_sides_response = self.stub.getBoardSides(board_sides_request)
@@ -167,11 +167,10 @@ def update_parts_list(
167167
Name of the CCA.
168168
part_library : str
169169
Name of the parts library.
170-
matching : str
171-
Matching mode for updates. Options are ``"Both"`` and ``"Part"``.
172-
duplication : str
170+
matching : UpdatesPartsListRequestMatchingMode
171+
Matching mode for updates.
172+
duplication : UpdatesPartsListRequestDuplicationMode
173173
How to handle duplication during the update.
174-
Options are ``"First"``, ``"Error"``, and ``"Ignore"``.
175174
176175
Examples
177176
--------
@@ -190,8 +189,8 @@ def update_parts_list(
190189
"Test",
191190
"Card",
192191
"Sherlock Part Library",
193-
"Both",
194-
"Error",
192+
UpdatesPartsListRequestMatchingMode.BOTH,
193+
UpdatesPartsListRequestDuplicationMode.ERROR,
195194
)
196195
"""
197196
try:
@@ -201,10 +200,6 @@ def update_parts_list(
201200
raise SherlockUpdatePartsListError(message="CCA name is invalid.")
202201
if part_library == "":
203202
raise SherlockUpdatePartsListError(message="Parts library is invalid.")
204-
if matching not in self.MATCHING_ARGS:
205-
raise SherlockUpdatePartsListError(message="Matching argument is invalid.")
206-
if duplication not in self.DUPLICATION_ARGS:
207-
raise SherlockUpdatePartsListError(message="Duplication argument is invalid.")
208203
except SherlockUpdatePartsListError as e:
209204
for error in e.str_itr():
210205
LOG.error(error)
@@ -226,9 +221,6 @@ def update_parts_list(
226221

227222
try:
228223
if return_code.value == -1:
229-
if return_code.message == "":
230-
raise SherlockUpdatePartsListError(error_array=response.updateError)
231-
232224
raise SherlockUpdatePartsListError(message=return_code.message)
233225
else:
234226
LOG.info(return_code.message)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Copyright (c) 2023 ANSYS, Inc. and/or its affiliates.
2+
3+
"""PySherlock client library constants for enumerated types."""

0 commit comments

Comments
 (0)