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
19 changes: 17 additions & 2 deletions src/ansys/dpf/post/result_workflows/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,20 @@ def _append_workflow(new_wf: Optional[Workflow], last_wf: Workflow):
return new_wf


def _find_available_result(
available_results: list[AvailableResult], operator_name: str
) -> Optional[AvailableResult]:
"""Find an available result by operator name."""
return next(
(r for r in available_results if r.operator_name == operator_name), None
)


def _get_native_location(
available_results: list[AvailableResult], base_name: str
) -> str:
"""Get the native location of a result from its base name."""
res = next((r for r in available_results if r.operator_name == base_name), None)
res = _find_available_result(available_results, base_name)

# special case for beam results, which are extracted from SMISC
if res is None and base_name in [
Expand All @@ -142,7 +151,13 @@ def _get_native_location(
"B_T1",
"B_T2",
]:
res = next((r for r in available_results if r.operator_name == "SMISC"), None)
res = _find_available_result(available_results, "SMISC")

# special case for nodal averaged results from MAPDL rst files
if res is None and base_name.startswith("mapdl::rst::"):
res = _find_available_result(
available_results, base_name.replace("mapdl::rst::", "")
)

if res is not None:
return res.native_location
Expand Down
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ def beam_example():
)


@pytest.fixture()
def nar_example():
return _download_file(
"result_files/nodal-averaged-results", "static_nar.rst", True, None, False
)


@dataclasses.dataclass
class ReferenceCsvFilesNodal:
# reference result with all bodies combined
Expand Down
15 changes: 15 additions & 0 deletions tests/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
from ansys.dpf.post.result_workflows._utils import (
AveragingConfig,
_CreateOperatorCallable,
_find_available_result,
_get_native_location,
)
from ansys.dpf.post.selection import _WfNames
from ansys.dpf.post.simulation import MechanicalSimulation, Simulation
Expand Down Expand Up @@ -4711,3 +4713,16 @@ def test_nodal_averaging_on_elemental_scoping(average_per_body_two_cubes):
assert field.size == 8
assert np.allclose(field.min().data[0], 1.724714e-5)
assert np.allclose(field.max().data[0], 6.407787e-5)


def test_nar_results_location(nar_example):
simulation: StaticMechanicalSimulation = post.load_simulation(
data_sources=nar_example,
simulation_type=AvailableSimulationTypes.static_mechanical,
)

assert _find_available_result(simulation.results, "NS") is not None
assert _find_available_result(simulation.results, "mapdl::rst::NS") is None

assert _get_native_location(simulation.results, "NS") == locations.nodal
assert _get_native_location(simulation.results, "mapdl::rst::NS") == locations.nodal