Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/api/analysis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ The ``analysis`` module contains all analysis capabilities.
:toctree: _autosummary

ansys.sherlock.core.analysis.Analysis.get_harmonic_vibe_input_fields
ansys.sherlock.core.analysis.Analysis.get_ict_analysis_input_fields
ansys.sherlock.core.analysis.Analysis.get_mechanical_shock_input_fields
ansys.sherlock.core.analysis.Analysis.get_random_vibe_input_fields
ansys.sherlock.core.analysis.Analysis.get_solder_fatigue_input_fields
ansys.sherlock.core.analysis.Analysis.run_analysis
ansys.sherlock.core.analysis.Analysis.run_strain_map_analysis
ansys.sherlock.core.analysis.Analysis.update_harmonic_vibe_props
ansys.sherlock.core.analysis.Analysis.update_ict_analysis_props
ansys.sherlock.core.analysis.Analysis.update_mechanical_shock_props
ansys.sherlock.core.analysis.Analysis.update_natural_frequency_props
ansys.sherlock.core.analysis.Analysis.update_part_modeling_props
Expand Down
184 changes: 183 additions & 1 deletion src/ansys/sherlock/core/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
SherlockRunAnalysisError,
SherlockRunStrainMapAnalysisError,
SherlockUpdateHarmonicVibePropsError,
SherlockUpdateICTAnalysisPropsError,
SherlockUpdateMechanicalShockPropsError,
SherlockUpdateNaturalFrequencyPropsError,
SherlockUpdatePartModelingPropsError,
Expand Down Expand Up @@ -42,6 +43,10 @@ def __init__(self, channel):
"forceModelRebuild": "force_model_rebuild",
"harmonicVibeDamping": "harmonic_vibe_damping",
"harmonicVibeCount": "harmonic_vibe_count",
"ictApplicationTime": "ict_application_time",
"ictApplicationTimeUnits": "ict_application_time_units",
"ictNumberOfEvents": "ict_number_of_events",
"ictResultCount": "ict_result_count",
"modelSource": "model_source",
"naturalFreqCount": "natural_freq_count",
"naturalFreqMin": "natural_freq_min",
Expand Down Expand Up @@ -333,7 +338,7 @@ def update_harmonic_vibe_props(

if "cca_name" not in harmonic_vibe_props.keys():
raise SherlockUpdateHarmonicVibePropsError(
message=f"CCA name is invalid for harmonic vibe properties {i}."
message=f"CCA name is missing for harmonic vibe properties {i}."
)

cca_name = harmonic_vibe_props["cca_name"]
Expand Down Expand Up @@ -483,6 +488,183 @@ def update_harmonic_vibe_props(
LOG.error(str(e))
raise e

def get_ict_analysis_input_fields(self):
"""Get ICT analysis property fields based on the user configuration.

Parameters
----------
None

Returns
-------
list
List of ICT analysis property fields based on the user configuration.

Examples
--------
>>> from ansys.sherlock.core.launcher import launch_sherlock
>>> sherlock = launch_sherlock()
>>> sherlock.analysis.get_ict_analysis_input_fields()
"""
if not self._is_connection_up():
LOG.error("There is no connection to a gRPC service.")
return

message = SherlockAnalysisService_pb2.GetICTAnalysisInputFieldsRequest()
response = self.stub.getICTAnalysisInputFields(message)

fields = self._translate_field_names(response.fieldName)
LOG.info(fields)

return fields

def update_ict_analysis_props(
self,
project,
ict_analysis_properties,
):
"""Update properties for an ICT analysis.

Parameters
----------
project : str
Name of the Sherlock project.
ict_analysis_properties : list
List of ICT analysis properties for a CCA consisting of these properties:

- cca_name : str
Name of the CCA.
- ict_application_time : double
Specifies the amount of time to complete one ICT event.
- ict_application_time_units : str
Application time units.
Options are ``"ms"``, ``"sec"``, ``"min"``, ``"hr"``, ``"day"``, ``"year"``.
- ict_number_of_events: int
Specifies the number of events to apply to the application time when computing
the time to failure for a component.
- part_validation_enabled: bool
Whether to enable part validation. The default is ``None``.
- require_material_assignment_enabled: bool
Whether to require material assignment. The default is ``None``.
- ict_result_count: int
The number of ICT result layers to generate. This parameter is for use with
thermal analysis.

Returns
-------
int
Status code of the response. 0 for success.

Examples
--------
>>> from ansys.sherlock.core.launcher import launch_sherlock
>>> sherlock = launch_sherlock()
>>> sherlock.project.import_odb_archive(
"ODB++ Tutorial.tgz",
True,
True,
True,
True,
project="Test",
cca_name="Card",
)
>>> sherlock.analysis.update_ict_analysis_props(
"Test",
[{
'cca_name': 'Card',
'ict_application_time': 2,
'ict_application_time_units': 'sec',
'ict_number_of_events': 10,
'part_validation_enabled': False,
'require_material_assignment_enabled': False,
},
]
)

"""
try:
if project == "":
raise SherlockUpdateICTAnalysisPropsError(message="Project name is invalid.")

if not isinstance(ict_analysis_properties, list):
raise SherlockUpdateICTAnalysisPropsError(
message="ICT analysis properties argument is invalid."
)

if len(ict_analysis_properties) == 0:
raise SherlockUpdateICTAnalysisPropsError(
message="One or more ICT analysis properties are required."
)

request = SherlockAnalysisService_pb2.UpdateICTAnalysisPropsRequest(project=project)

for i, ict_analysis_props in enumerate(ict_analysis_properties):
if not isinstance(ict_analysis_props, dict):
raise SherlockUpdateICTAnalysisPropsError(
f"ICT analysis props argument is invalid for ICT analysis properties {i}."
)

if "cca_name" not in ict_analysis_props.keys():
raise SherlockUpdateICTAnalysisPropsError(
message=f"CCA name is missing for ICT analysis properties {i}."
)

cca_name = ict_analysis_props["cca_name"]
if cca_name == "":
raise SherlockUpdateICTAnalysisPropsError(
message=f"CCA name is invalid for ICT analysis properties {i}."
)

props_request = request.ictAnalysisProperties.add()
props_request.ccaName = cca_name

if "ict_analysis_count" in ict_analysis_props.keys():
props_request.ictAnalysisCount = ict_analysis_props["ict_analysis_count"]

if "ict_application_time" in ict_analysis_props.keys():
props_request.applicationTime = ict_analysis_props["ict_application_time"]

if "ict_application_time_units" in ict_analysis_props.keys():
props_request.applicationTimeUnits = ict_analysis_props[
"ict_application_time_units"
]

if "ict_number_of_events" in ict_analysis_props.keys():
props_request.numberOfEvents = ict_analysis_props["ict_number_of_events"]

if "part_validation_enabled" in ict_analysis_props.keys():
props_request.partValidationEnabled = ict_analysis_props[
"part_validation_enabled"
]

if "require_material_assignment_enabled" in ict_analysis_props.keys():
props_request.requireMaterialAssignmentEnabled = ict_analysis_props[
"require_material_assignment_enabled"
]

if "force_model_rebuild" in ict_analysis_props.keys():
props_request.forceModelRebuild = ict_analysis_props["force_model_rebuild"]

except SherlockUpdateICTAnalysisPropsError as e:
LOG.error(str(e))
raise e

if not self._is_connection_up():
LOG.error("There is no connection to a gRPC service.")
return

response = self.stub.updateICTAnalysisProps(request)

try:
if response.value == -1:
raise SherlockUpdateICTAnalysisPropsError(response.message)
else:
LOG.info(response.message)
return response.value
except SherlockUpdateICTAnalysisPropsError as e:
LOG.error(str(e))
raise e

def get_mechanical_shock_input_fields(self, model_source=None):
"""Get mechanical shock property fields based on the user configuration.

Expand Down
12 changes: 12 additions & 0 deletions src/ansys/sherlock/core/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,18 @@ def __str__(self):
return f"Update harmonic vibe properties error: {self.message}"


class SherlockUpdateICTAnalysisPropsError(Exception):
"""Contains the error raised when properties for ICT analysis cannot be updated."""

def __init__(self, message):
"""Initialize error message."""
self.message = message

def __str__(self):
"""Format error message."""
return f"Update ICT analysis properties error: {self.message}"


class SherlockUpdateMechanicalShockPropsError(Exception):
"""Contains the error raised when properties for mechanical shock analysis cannot be updated."""

Expand Down
Loading