Skip to content

Commit 83ee36a

Browse files
Remove usage of _result_properties dictionary (#918)
1 parent 5b49c8c commit 83ee36a

File tree

8 files changed

+49
-47
lines changed

8 files changed

+49
-47
lines changed

src/ansys/dpf/post/harmonic_mechanical_simulation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ def _get_result_workflow(
8181
averaging_config: AveragingConfig = AveragingConfig(),
8282
rescoping: Optional[_Rescoping] = None,
8383
shell_layer: Optional[shell_layers] = None,
84-
) -> (dpf.Workflow, Union[str, list[str], None], str):
84+
) -> Tuple[dpf.Workflow, Union[str, list[str], None], str]:
8585
"""Generate (without evaluating) the Workflow to extract results."""
8686
result_workflow_inputs = _create_result_workflow_inputs(
87+
available_results=self.results,
8788
base_name=base_name,
8889
category=category,
8990
components=components,

src/ansys/dpf/post/modal_mechanical_simulation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
-------------------------
2727
2828
"""
29-
from typing import List, Optional, Union
29+
from typing import List, Optional, Tuple, Union
3030

3131
from ansys.dpf.core import shell_layers
3232

@@ -70,9 +70,10 @@ def _get_result_workflow(
7070
averaging_config: AveragingConfig = AveragingConfig(),
7171
rescoping: Optional[_Rescoping] = None,
7272
shell_layer: Optional[shell_layers] = None,
73-
) -> (dpf.Workflow, Union[str, list[str], None], str):
73+
) -> Tuple[dpf.Workflow, Union[str, list[str], None], str]:
7474
"""Generate (without evaluating) the Workflow to extract results."""
7575
result_workflow_inputs = _create_result_workflow_inputs(
76+
available_results=self.results,
7677
base_name=base_name,
7778
category=category,
7879
components=components,

src/ansys/dpf/post/result_workflows/_build_workflow.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from typing import Callable, List, Optional, Union
2525

2626
from ansys.dpf.core import Operator, Workflow, shell_layers
27-
from ansys.dpf.core.available_result import _result_properties
27+
from ansys.dpf.core.available_result import AvailableResult
2828
from ansys.dpf.core.common import locations
2929

3030
from ansys.dpf.post.result_workflows._component_helper import (
@@ -45,6 +45,7 @@
4545
from ansys.dpf.post.result_workflows._utils import (
4646
AveragingConfig,
4747
_CreateOperatorCallable,
48+
_get_native_location,
4849
_Rescoping,
4950
)
5051
from ansys.dpf.post.selection import Selection, _WfNames
@@ -120,6 +121,7 @@ class _CreateWorkflowInputs:
120121

121122

122123
def _requires_manual_averaging(
124+
available_results: list[AvailableResult],
123125
base_name: str,
124126
location: str,
125127
category: ResultCategory,
@@ -128,8 +130,7 @@ def _requires_manual_averaging(
128130
create_operator_callable: Callable[[str], Operator],
129131
average_per_body: bool,
130132
):
131-
res = _result_properties[base_name] if base_name in _result_properties else None
132-
native_location = res["location"] if res is not None else None
133+
native_location = _get_native_location(available_results, base_name)
133134

134135
if average_per_body and (
135136
native_location == locations.elemental
@@ -138,7 +139,7 @@ def _requires_manual_averaging(
138139
return True
139140
if category == ResultCategory.equivalent and base_name[0] == "E": # strain eqv
140141
return True
141-
if res is not None:
142+
if native_location is not None:
142143
is_model_cyclic = create_operator_callable("is_cyclic").eval()
143144
is_model_cyclic = is_model_cyclic in ["single_stage", "multi_stage"]
144145
if has_external_layer and is_model_cyclic and location != native_location:
@@ -265,6 +266,7 @@ def _create_result_workflows(
265266

266267

267268
def _create_result_workflow_inputs(
269+
available_results: list[AvailableResult],
268270
base_name: str,
269271
category: ResultCategory,
270272
components: Union[str, List[str], int, List[int], None],
@@ -284,6 +286,7 @@ def _create_result_workflow_inputs(
284286
)
285287

286288
force_elemental_nodal = _requires_manual_averaging(
289+
available_results=available_results,
287290
base_name=base_name,
288291
location=location,
289292
category=category,

src/ansys/dpf/post/result_workflows/_utils.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from typing import Optional, Protocol
2525

2626
from ansys.dpf.core import Operator, Workflow
27+
from ansys.dpf.core.available_result import AvailableResult
2728

2829
from ansys.dpf.post.selection import _WfNames
2930

@@ -122,3 +123,28 @@ def _append_workflow(new_wf: Optional[Workflow], last_wf: Workflow):
122123
output_input_names={_WfNames.output_data: _WfNames.input_data},
123124
)
124125
return new_wf
126+
127+
128+
def _get_native_location(
129+
available_results: list[AvailableResult], base_name: str
130+
) -> str:
131+
"""Get the native location of a result from its base name."""
132+
res = next((r for r in available_results if r.operator_name == base_name), None)
133+
134+
# special case for beam results, which are extracted from SMISC
135+
if res is None and base_name in [
136+
"B_N",
137+
"B_M1",
138+
"B_M2",
139+
"B_MT",
140+
"B_SN",
141+
"B_EL",
142+
"B_T1",
143+
"B_T2",
144+
]:
145+
res = next((r for r in available_results if r.operator_name == "SMISC"), None)
146+
147+
if res is not None:
148+
return res.native_location
149+
150+
raise ValueError(f"Result with base name '{base_name}' not found.")

src/ansys/dpf/post/simulation.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
from ansys.dpf.post.meshes import Meshes
5454
from ansys.dpf.post.result_workflows._build_workflow import _requires_manual_averaging
5555
from ansys.dpf.post.result_workflows._component_helper import ResultCategory
56-
from ansys.dpf.post.result_workflows._utils import _Rescoping
56+
from ansys.dpf.post.result_workflows._utils import _get_native_location, _Rescoping
5757
from ansys.dpf.post.selection import Selection
5858

5959

@@ -636,6 +636,7 @@ def _build_selection(
636636
has_skin = len(skin) > 0
637637

638638
requires_manual_averaging = _requires_manual_averaging(
639+
available_results=self.results,
639640
base_name=base_name,
640641
location=location,
641642
category=category,
@@ -658,13 +659,7 @@ def _build_selection(
658659
if requires_manual_averaging and location != locations.elemental_nodal:
659660
location = locations.elemental_nodal
660661

661-
available_results = self._model.metadata.result_info.available_results
662-
result_info = next(
663-
(r for r in available_results if r.operator_name == base_name), None
664-
)
665-
result_native_location = None
666-
if result_info is not None:
667-
result_native_location = result_info.native_location
662+
result_native_location = _get_native_location(self.results, base_name)
668663

669664
# Create the SpatialSelection
670665

src/ansys/dpf/post/static_mechanical_simulation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ def _get_result_workflow(
6666
averaging_config: AveragingConfig = AveragingConfig(),
6767
rescoping: Optional[_Rescoping] = None,
6868
shell_layer: Optional[shell_layers] = None,
69-
) -> (core.Workflow, Union[str, list[str], None], str):
69+
) -> Tuple[core.Workflow, Union[str, list[str], None], str]:
7070
"""Generate (without evaluating) the Workflow to extract results."""
7171
result_workflow_inputs = _create_result_workflow_inputs(
72+
available_results=self.results,
7273
base_name=base_name,
7374
category=category,
7475
components=components,

src/ansys/dpf/post/transient_mechanical_simulation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ def _get_result_workflow(
6868
averaging_config: AveragingConfig = AveragingConfig(),
6969
rescoping: Optional[_Rescoping] = None,
7070
shell_layer: Optional[shell_layers] = None,
71-
) -> (dpf.Workflow, Union[str, list[str], None], str):
71+
) -> Tuple[dpf.Workflow, Union[str, list[str], None], str]:
7272
"""Generate (without evaluating) the Workflow to extract results."""
7373
result_workflow_inputs = _create_result_workflow_inputs(
74+
available_results=self.results,
7475
base_name=base_name,
7576
category=category,
7677
components=components,

tests/test_simulation.py

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,36 +2203,10 @@ def test_kinetic_energy(self, transient_simulation):
22032203
assert np.allclose(field.data, field_ref.data)
22042204

22052205
def test_structural_temperature(self, transient_simulation):
2206-
result = transient_simulation.structural_temperature(set_ids=[2])
2207-
assert len(result._fc) == 1
2208-
assert result._fc.get_time_scoping().ids == [2]
2209-
field = result._fc[0]
2210-
op = transient_simulation._model.operator("BFE")
2211-
field_ref = op.eval()[0]
2212-
assert field.component_count == 1
2213-
assert np.allclose(field.data, field_ref.data)
2214-
2215-
def test_structural_temperature_nodal(self, transient_simulation):
2216-
result = transient_simulation.structural_temperature_nodal(set_ids=[2])
2217-
assert len(result._fc) == 1
2218-
assert result._fc.get_time_scoping().ids == [2]
2219-
field = result._fc[0]
2220-
op = transient_simulation._model.operator("BFE")
2221-
op.connect(9, post.locations.nodal)
2222-
field_ref = op.eval()[0]
2223-
assert field.component_count == 1
2224-
assert np.allclose(field.data, field_ref.data)
2225-
2226-
def test_structural_temperature_elemental(self, transient_simulation):
2227-
result = transient_simulation.structural_temperature_elemental(set_ids=[2])
2228-
assert len(result._fc) == 1
2229-
assert result._fc.get_time_scoping().ids == [2]
2230-
field = result._fc[0]
2231-
op = transient_simulation._model.operator("BFE")
2232-
op.connect(9, post.locations.elemental)
2233-
field_ref = op.eval()[0]
2234-
assert field.component_count == 1
2235-
assert np.allclose(field.data, field_ref.data)
2206+
# the model does not contain structural temperature results
2207+
with pytest.raises(ValueError) as excinfo:
2208+
_ = transient_simulation.structural_temperature(set_ids=[1])
2209+
assert "not found" in str(excinfo.value)
22362210

22372211
# @pytest.mark.skipif(
22382212
# not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_5_0,

0 commit comments

Comments
 (0)