From b523f002c4758c7cd9b16b97060a2aa7570f8a81 Mon Sep 17 00:00:00 2001 From: Paul Profizi <100710998+PProfizi@users.noreply.github.com> Date: Mon, 16 Sep 2024 10:18:03 +0200 Subject: [PATCH 1/6] Fix coordinate system example retro-compatibility --- .../13-nodes_in_local_coordinate_system.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/10-mesh_operations/13-nodes_in_local_coordinate_system.py b/examples/10-mesh_operations/13-nodes_in_local_coordinate_system.py index 5fa3479535..1e8b7666ba 100644 --- a/examples/10-mesh_operations/13-nodes_in_local_coordinate_system.py +++ b/examples/10-mesh_operations/13-nodes_in_local_coordinate_system.py @@ -55,7 +55,12 @@ ############################################################################### # Get the rotation matrix of the LCS ID 12. # The first 9 values in the ``cs`` output is the rotation matrix. -cs = dpf.operators.result.coordinate_system() +try: + # Starting with DPF 2025.1.pre1 + cs = dpf.operators.result.coordinate_system() +except KeyError: + # For previous DPF versions + cs = model.operator(r"mapdl::rst::CS") cs.inputs.data_sources.connect(model) cs.inputs.cs_id.connect(12) cs_rot_mat = cs.outputs.field.get_data().data.T[0:9] From 0f0bab235cf06ca3f2e6931c9c6489f7953c0b42 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Mon, 16 Sep 2024 10:38:20 +0200 Subject: [PATCH 2/6] Add a proper test Signed-off-by: paul.profizi --- tests/operators/test_coordinate_system.py | 53 +++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/operators/test_coordinate_system.py diff --git a/tests/operators/test_coordinate_system.py b/tests/operators/test_coordinate_system.py new file mode 100644 index 0000000000..0d700512fd --- /dev/null +++ b/tests/operators/test_coordinate_system.py @@ -0,0 +1,53 @@ +# Copyright (C) 2020 - 2024 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +# Tests the result.coordinate_system operator +import ansys.dpf.core as dpf +from ansys.dpf.core import examples +import numpy as np + + +def test_operator_coordinate_system_rst(server_type): + model = dpf.Model(examples.download_hemisphere(server=server_type), server=server_type) + cs = dpf.operators.result.coordinate_system(server=server_type) + cs.inputs.data_sources.connect(model) + cs.inputs.cs_id.connect(12) + cs_rot_mat = cs.outputs.field().data + ref = np.array( + [ + [ + -0.18966565, + 0.91517569, + 0.35564083, + -0.91517569, + -0.03358143, + -0.40165376, + -0.35564083, + -0.40165376, + 0.84391579, + 4.74164122, + 22.87939222, + 8.89102077, + ] + ] + ) + assert np.allclose(cs_rot_mat.data, ref) From 077a451fecab250d1115936d92c333daffa345e7 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Mon, 16 Sep 2024 10:46:12 +0200 Subject: [PATCH 3/6] Fix code style Signed-off-by: paul.profizi --- .../13-nodes_in_local_coordinate_system.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/10-mesh_operations/13-nodes_in_local_coordinate_system.py b/examples/10-mesh_operations/13-nodes_in_local_coordinate_system.py index 1e8b7666ba..36778b0d8b 100644 --- a/examples/10-mesh_operations/13-nodes_in_local_coordinate_system.py +++ b/examples/10-mesh_operations/13-nodes_in_local_coordinate_system.py @@ -56,12 +56,13 @@ # Get the rotation matrix of the LCS ID 12. # The first 9 values in the ``cs`` output is the rotation matrix. try: - # Starting with DPF 2025.1.pre1 - cs = dpf.operators.result.coordinate_system() + # Starting with DPF 2025.1.pre1 + cs = dpf.operators.result.coordinate_system() + cs.inputs.data_sources.connect(model) except KeyError: - # For previous DPF versions - cs = model.operator(r"mapdl::rst::CS") -cs.inputs.data_sources.connect(model) + # For previous DPF versions + cs = model.operator(r"mapdl::rst::CS") + cs.inputs.cs_id.connect(12) cs_rot_mat = cs.outputs.field.get_data().data.T[0:9] From f5d45c5c5493a454672b1d684f3d314458d43513 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Mon, 16 Sep 2024 16:15:18 +0200 Subject: [PATCH 4/6] Make the test retro-compatible Signed-off-by: paul.profizi --- tests/operators/test_coordinate_system.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/operators/test_coordinate_system.py b/tests/operators/test_coordinate_system.py index 0d700512fd..497db0a0c2 100644 --- a/tests/operators/test_coordinate_system.py +++ b/tests/operators/test_coordinate_system.py @@ -28,8 +28,13 @@ def test_operator_coordinate_system_rst(server_type): model = dpf.Model(examples.download_hemisphere(server=server_type), server=server_type) - cs = dpf.operators.result.coordinate_system(server=server_type) - cs.inputs.data_sources.connect(model) + try: + # Starting with DPF 2025.1.pre1 + cs = dpf.operators.result.coordinate_system(server=server_type) + cs.inputs.data_sources.connect(model) + except KeyError: + # For previous DPF versions + cs = model.operator(r"mapdl::rst::CS") cs.inputs.cs_id.connect(12) cs_rot_mat = cs.outputs.field().data ref = np.array( From 2b38babebd16cc42fc1d62fa67e3fd3bc8b5bfc7 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Mon, 16 Sep 2024 17:02:58 +0200 Subject: [PATCH 5/6] Make the test retro-compatible Signed-off-by: paul.profizi --- tests/operators/test_coordinate_system.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/operators/test_coordinate_system.py b/tests/operators/test_coordinate_system.py index 497db0a0c2..a9d93e9b8e 100644 --- a/tests/operators/test_coordinate_system.py +++ b/tests/operators/test_coordinate_system.py @@ -23,16 +23,17 @@ # Tests the result.coordinate_system operator import ansys.dpf.core as dpf from ansys.dpf.core import examples +import conftest import numpy as np def test_operator_coordinate_system_rst(server_type): model = dpf.Model(examples.download_hemisphere(server=server_type), server=server_type) - try: + if conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_9_0: # Starting with DPF 2025.1.pre1 cs = dpf.operators.result.coordinate_system(server=server_type) cs.inputs.data_sources.connect(model) - except KeyError: + else: # For previous DPF versions cs = model.operator(r"mapdl::rst::CS") cs.inputs.cs_id.connect(12) From 10b634f048811b7e139126711a9541bede12520d Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Mon, 16 Sep 2024 17:21:33 +0200 Subject: [PATCH 6/6] Make the test retro-compatible Signed-off-by: paul.profizi --- tests/operators/test_coordinate_system.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/operators/test_coordinate_system.py b/tests/operators/test_coordinate_system.py index a9d93e9b8e..720c2f0f9f 100644 --- a/tests/operators/test_coordinate_system.py +++ b/tests/operators/test_coordinate_system.py @@ -29,7 +29,7 @@ def test_operator_coordinate_system_rst(server_type): model = dpf.Model(examples.download_hemisphere(server=server_type), server=server_type) - if conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_9_0: + if conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_9_1: # Starting with DPF 2025.1.pre1 cs = dpf.operators.result.coordinate_system(server=server_type) cs.inputs.data_sources.connect(model)