-
Notifications
You must be signed in to change notification settings - Fork 12
Remove usage of _result_properties dictionary #918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
657d2f7
0afb202
67aa9f8
19eafb1
7f5f4b6
68a8b53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |||||
| from typing import Optional, Protocol | ||||||
|
|
||||||
| from ansys.dpf.core import Operator, Workflow | ||||||
| from ansys.dpf.core.available_result import AvailableResult | ||||||
|
|
||||||
| from ansys.dpf.post.selection import _WfNames | ||||||
|
|
||||||
|
|
@@ -122,3 +123,28 @@ def _append_workflow(new_wf: Optional[Workflow], last_wf: Workflow): | |||||
| output_input_names={_WfNames.output_data: _WfNames.input_data}, | ||||||
| ) | ||||||
| return new_wf | ||||||
|
|
||||||
|
|
||||||
| 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) | ||||||
|
|
||||||
| # special case for beam results, which are extracted from SMISC | ||||||
| if res is None and base_name in [ | ||||||
| "B_N", | ||||||
| "B_M1", | ||||||
| "B_M2", | ||||||
| "B_MT", | ||||||
| "B_SN", | ||||||
| "B_EL", | ||||||
| "B_T1", | ||||||
| "B_T2", | ||||||
| ]: | ||||||
| res = next((r for r in available_results if r.operator_name == "SMISC"), None) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @FedericoNegri so all There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, that's my understanding |
||||||
|
|
||||||
| if res is not None: | ||||||
| return res.native_location | ||||||
|
|
||||||
| raise ValueError(f"Result with base name '{base_name}' not found.") | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either we make this check explicit here, or we move the check for existing result with base name somewhere above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I disagree, the function throws if it can't find the result, which is a prerequisite for querying its location.
I've been thinking about this and considered having a function def _get_available_result(
available_results: list[AvailableResult], base_name: str
) -> AvailableResult:
res = next((r for r in available_results if r.operator_name == base_name), None)
# special case for beam results, which are extracted from SMISC
if res is None and base_name in [
"B_N",
"B_M1",
"B_M2",
"B_MT",
"B_SN",
"B_EL",
"B_T1",
"B_T2",
]:
res = next((r for r in available_results if r.operator_name == "SMISC"), None)
if res is None:
raise ValueError(f"Result with base name '{base_name}' is not available.")
return resbut I think it would just be misleading. You come in with The proper fix is to have those beam results be listed as available results (that was discussed internally). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree on the proper fix. |
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2203,36 +2203,10 @@ def test_kinetic_energy(self, transient_simulation): | |||||
| assert np.allclose(field.data, field_ref.data) | ||||||
|
|
||||||
| def test_structural_temperature(self, transient_simulation): | ||||||
| result = transient_simulation.structural_temperature(set_ids=[2]) | ||||||
| assert len(result._fc) == 1 | ||||||
| assert result._fc.get_time_scoping().ids == [2] | ||||||
| field = result._fc[0] | ||||||
| op = transient_simulation._model.operator("BFE") | ||||||
| field_ref = op.eval()[0] | ||||||
| assert field.component_count == 1 | ||||||
| assert np.allclose(field.data, field_ref.data) | ||||||
|
|
||||||
| def test_structural_temperature_nodal(self, transient_simulation): | ||||||
| result = transient_simulation.structural_temperature_nodal(set_ids=[2]) | ||||||
| assert len(result._fc) == 1 | ||||||
| assert result._fc.get_time_scoping().ids == [2] | ||||||
| field = result._fc[0] | ||||||
| op = transient_simulation._model.operator("BFE") | ||||||
| op.connect(9, post.locations.nodal) | ||||||
| field_ref = op.eval()[0] | ||||||
| assert field.component_count == 1 | ||||||
| assert np.allclose(field.data, field_ref.data) | ||||||
|
|
||||||
| def test_structural_temperature_elemental(self, transient_simulation): | ||||||
| result = transient_simulation.structural_temperature_elemental(set_ids=[2]) | ||||||
| assert len(result._fc) == 1 | ||||||
| assert result._fc.get_time_scoping().ids == [2] | ||||||
| field = result._fc[0] | ||||||
| op = transient_simulation._model.operator("BFE") | ||||||
| op.connect(9, post.locations.elemental) | ||||||
| field_ref = op.eval()[0] | ||||||
| assert field.component_count == 1 | ||||||
| assert np.allclose(field.data, field_ref.data) | ||||||
| # the model does not contain structural temperature results | ||||||
| with pytest.raises(ValueError) as excinfo: | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @FedericoNegri so this test used to silently fail at finding the native location, and returned something wrong? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case the test was comparing trivial arrays, there's an internal bug report for that operator. But in general the logic before was resorting to some defaults in case of missing location. That resulted in hidden errors for results that weren't registered in the |
||||||
| _ = transient_simulation.structural_temperature(set_ids=[1]) | ||||||
| assert "not found" in str(excinfo.value) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| # @pytest.mark.skipif( | ||||||
| # not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_5_0, | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could also have a function here which redirects from
B_Nand whatnot toSMISCas you did, but does not handle getting the native location.This way the handling of the native location remains the same, and you have a clear function which checks for availability of results and throws a precise error when it fails.