From 2734aaaa3481af2b9e4f11247455f0a209f38a95 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Mon, 10 Jul 2023 16:00:48 +0200 Subject: [PATCH 01/22] Fix wrong input name for solid_to_skin operator --- src/ansys/dpf/post/simulation.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ansys/dpf/post/simulation.py b/src/ansys/dpf/post/simulation.py index 5c31c2a0c..7137e2a72 100644 --- a/src/ansys/dpf/post/simulation.py +++ b/src/ansys/dpf/post/simulation.py @@ -895,9 +895,7 @@ def _create_averaging_operator( forward = self._model.operator(name="forward_fc") forward.connect(0, first_average_op, 0) average_wf = dpf.Workflow(server=self._model._server) - average_wf.set_input_name( - _WfNames.skin, first_average_op.inputs.mesh_scoping - ) + average_wf.set_input_name(_WfNames.skin, first_average_op.inputs.mesh) average_wf.connect_with( selection.spatial_selection._selection, output_input_names={_WfNames.skin: _WfNames.skin}, From cd4746baf9d13f514827d7c4061e8ae1d6b27d41 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Mon, 10 Jul 2023 16:09:23 +0200 Subject: [PATCH 02/22] Fix retro --- src/ansys/dpf/post/simulation.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ansys/dpf/post/simulation.py b/src/ansys/dpf/post/simulation.py index 7137e2a72..1c277b50b 100644 --- a/src/ansys/dpf/post/simulation.py +++ b/src/ansys/dpf/post/simulation.py @@ -895,7 +895,13 @@ def _create_averaging_operator( forward = self._model.operator(name="forward_fc") forward.connect(0, first_average_op, 0) average_wf = dpf.Workflow(server=self._model._server) - average_wf.set_input_name(_WfNames.skin, first_average_op.inputs.mesh) + if hasattr(first_average_op.inputs, "mesh_scoping"): + inpt = ( + first_average_op.inputs.mesh_scoping + ) # To keep for retro-compatibility + else: + inpt = first_average_op.inputs.mesh + average_wf.set_input_name(_WfNames.skin, inpt) average_wf.connect_with( selection.spatial_selection._selection, output_input_names={_WfNames.skin: _WfNames.skin}, From dab0442c76ffb0fd9643bc9596278d2f296e1d91 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Fri, 27 Oct 2023 15:56:38 +0200 Subject: [PATCH 03/22] Working modif, let's try to add mesh_by_scop back for performance --- src/ansys/dpf/post/selection.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/ansys/dpf/post/selection.py b/src/ansys/dpf/post/selection.py index e2cad3f45..153c84a99 100644 --- a/src/ansys/dpf/post/selection.py +++ b/src/ansys/dpf/post/selection.py @@ -443,11 +443,21 @@ def select_skin( elements = Scoping( server=self._server, ids=elements, location=locations.elemental ) - mesh_by_scop_op = operators.mesh.from_scoping( - scoping=elements, server=self._server + # mesh_by_scop_op = operators.mesh.from_scoping( + # scoping=elements, server=self._server + # ) + # mesh_input = mesh_by_scop_op.inputs.mesh + # op.inputs.mesh.connect(mesh_by_scop_op) + forward_op = operators.utility.forward() + mesh_input = forward_op.inputs.any + nodal_scoping = operators.scoping.transpose( + mesh_scoping=elements, server=self._server + ) + nodal_scoping.connect(1, forward_op) + op.connect(0, forward_op) + op.inputs.mesh_scoping.connect( + nodal_scoping.outputs.mesh_scoping_as_scoping ) - mesh_input = mesh_by_scop_op.inputs.mesh - op.inputs.mesh.connect(mesh_by_scop_op) if mesh_input is not None: self._selection.set_input_name(_WfNames.initial_mesh, mesh_input) From fe7a25e3ef72cdba3b47bad4e5bd2c314add9b41 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Fri, 27 Oct 2023 16:14:14 +0200 Subject: [PATCH 04/22] Cannot add mesh_by_scop back as it is actually the source of the problem --- src/ansys/dpf/post/selection.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/ansys/dpf/post/selection.py b/src/ansys/dpf/post/selection.py index 153c84a99..a1c8d95f8 100644 --- a/src/ansys/dpf/post/selection.py +++ b/src/ansys/dpf/post/selection.py @@ -443,11 +443,6 @@ def select_skin( elements = Scoping( server=self._server, ids=elements, location=locations.elemental ) - # mesh_by_scop_op = operators.mesh.from_scoping( - # scoping=elements, server=self._server - # ) - # mesh_input = mesh_by_scop_op.inputs.mesh - # op.inputs.mesh.connect(mesh_by_scop_op) forward_op = operators.utility.forward() mesh_input = forward_op.inputs.any nodal_scoping = operators.scoping.transpose( From 552b032a4c7baee31f86f00b1ac9b020282f26d7 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Fri, 27 Oct 2023 16:50:10 +0200 Subject: [PATCH 05/22] Add testing --- tests/test_selection.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/test_selection.py b/tests/test_selection.py index a9eaa1c62..09676050f 100644 --- a/tests/test_selection.py +++ b/tests/test_selection.py @@ -5,7 +5,7 @@ from ansys.dpf import core as dpf from ansys.dpf import post from ansys.dpf.post import examples -from ansys.dpf.post.selection import SpatialSelection +from ansys.dpf.post.selection import SpatialSelection, _WfNames from conftest import SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0 @@ -50,6 +50,32 @@ def test_spatial_selection_select_named_selection(allkindofcomplexity): assert 14826 in ids +def test_spatial_selection_select_skin(static_rst): + simulation = post.StaticMechanicalSimulation(static_rst) + selection = SpatialSelection() + selection._selection.progress_bar = False + selection.select_skin( + location=post.locations.elemental_nodal, + result_native_location=post.locations.elemental_nodal, + elements=[1, 2, 3], + ) + mesh_wf = dpf.Workflow() + mesh_wf.set_output_name( + _WfNames.initial_mesh, simulation._model.metadata.mesh_provider + ) + selection._selection.connect_with( + mesh_wf, + output_input_names={_WfNames.initial_mesh: _WfNames.initial_mesh}, + ) + # This returns a scoping on the initial mesh (logic to change?) + scoping_ids = selection.apply_to(simulation) + assert len(scoping_ids) == 8 + + # This gives the skin mesh with its 9 shell elements + skin = selection._selection.get_output(_WfNames.skin, dpf.MeshedRegion) + assert len(skin.elements.scoping.ids) == 9 + + @pytest.mark.skipif( not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0, reason="Faces added with ansys-dpf-server 2024.1.pre0.", From b040a22d63ef20672695437fed392650eb227b3e Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Fri, 27 Oct 2023 17:39:26 +0200 Subject: [PATCH 06/22] Start fixing refs of tests --- tests/test_simulation.py | 46 +++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/tests/test_simulation.py b/tests/test_simulation.py index 701f62662..6220d673f 100644 --- a/tests/test_simulation.py +++ b/tests/test_simulation.py @@ -657,31 +657,27 @@ def test_skin_layer(self, static_simulation: post.StaticMechanicalSimulation): def test_skin_layer2(self, static_simulation: post.StaticMechanicalSimulation): result = static_simulation.displacement(set_ids=[1], skin=[1, 2, 3]) - assert len(result.index.mesh_index) == 44 + assert len(result.index.mesh_index) == 38 + static_simulation.plot() + result.plot() def test_skin_layer3(self, static_simulation: post.StaticMechanicalSimulation): result = static_simulation.elastic_strain_eqv_von_mises_elemental( skin=[1, 2, 3] ) - if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1: - assert len(result.index.mesh_index) == 14 - else: - assert len(result.index.mesh_index) == 18 + assert len(result.index.mesh_index) == 9 def test_skin_layer4(self, static_simulation: post.StaticMechanicalSimulation): result = static_simulation.stress_principal_nodal(skin=[1, 2, 3]) - assert len(result.index.mesh_index) == 44 + assert len(result.index.mesh_index) == 38 def test_skin_layer5(self, static_simulation: post.StaticMechanicalSimulation): result = static_simulation.elastic_strain_eqv_von_mises_nodal(skin=[1, 2, 3]) - assert len(result.index.mesh_index) == 44 + assert len(result.index.mesh_index) == 38 def test_skin_layer6(self, static_simulation: post.StaticMechanicalSimulation): result = static_simulation.stress_principal_elemental(skin=[1, 2, 3]) - if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1: - assert len(result.index.mesh_index) == 14 - else: - assert len(result.index.mesh_index) == 18 + assert len(result.index.mesh_index) == 9 class TestTransientMechanicalSimulation: @@ -1324,7 +1320,7 @@ def test_skin_layer2( self, transient_simulation: post.TransientMechanicalSimulation ): result = transient_simulation.displacement(set_ids=[1], skin=[1, 2, 3]) - assert len(result.index.mesh_index) == 44 + assert len(result.index.mesh_index) == 42 def test_skin_layer3( self, transient_simulation: post.TransientMechanicalSimulation @@ -1996,7 +1992,10 @@ def test_disp_skin(self, frame_modal_simulation: post.ModalMechanicalSimulation) result.max(axis="node_ids").array, [0.05656421, 9.59989137, 1.08656671] ) result = frame_modal_simulation.displacement(set_ids=[1], skin=[1, 2, 3]) - assert len(result.index.mesh_index) == 21 + if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1: + assert len(result.index.mesh_index) == 21 + else: + assert len(result.index.mesh_index) == 14 assert np.allclose( result.max(axis="node_ids").array, [-0.77876072, 7.08211902, 0.05292333] ) @@ -2796,24 +2795,31 @@ def test_strain_skin(self, harmonic_simulation: post.HarmonicMechanicalSimulatio else: assert len(result.index.mesh_index) == 3942 assert len(result.columns.set_ids) == 1 + outer_nodes = harmonic_simulation.mesh.named_selections[ + "OUTER_FACE" + ]._scoping + outer_elements = dpf.operators.scoping.transpose( + mesh_scoping=outer_nodes, + meshed_region=harmonic_simulation.mesh._meshed_region, + ).eval() result = harmonic_simulation.stress_principal_elemental( - set_ids=[1], skin=list(range(1, 100)) + set_ids=[1], skin=outer_elements.ids ) if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1: - assert len(result.index.mesh_index) == 122 + assert len(result.index.mesh_index) == 240 else: assert len(result.index.mesh_index) == 192 assert len(result.columns.set_ids) == 1 result = harmonic_simulation.elastic_strain_eqv_von_mises_nodal( - set_ids=[1], skin=list(range(1, 100)) + set_ids=[1], skin=outer_elements.ids ) if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1: - assert len(result.index.mesh_index) == 520 + assert len(result.index.mesh_index) == 880 else: assert len(result.index.mesh_index) == 530 assert len(result.columns.set_ids) == 1 assert np.allclose( - result.select(complex=0).max(axis="node_ids").array, [1.34699501e-06] + result.select(complex=0).max(axis="node_ids").array, [1.22784309e-06] ) result = harmonic_simulation.elastic_strain_eqv_von_mises_nodal( set_ids=[1], skin=True @@ -2824,10 +2830,10 @@ def test_strain_skin(self, harmonic_simulation: post.HarmonicMechanicalSimulatio assert len(result.index.mesh_index) == 4802 assert len(result.columns.set_ids) == 1 result = harmonic_simulation.elastic_strain_principal_nodal( - set_ids=[1], skin=list(range(1, 100)) + set_ids=[1], skin=outer_elements.ids ) if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1: - assert len(result.index.mesh_index) == 520 + assert len(result.index.mesh_index) == 880 else: assert len(result.index.mesh_index) == 530 assert len(result.columns.set_ids) == 1 From 15308a27b2aa24759650ff38eb06f5b8ab002fa2 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Fri, 27 Oct 2023 17:42:12 +0200 Subject: [PATCH 07/22] Fix refs of tests for current server --- tests/test_simulation.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/test_simulation.py b/tests/test_simulation.py index 6220d673f..4fd20c999 100644 --- a/tests/test_simulation.py +++ b/tests/test_simulation.py @@ -2750,7 +2750,7 @@ def test_disp_skin(self, harmonic_simulation: post.HarmonicMechanicalSimulation) [2.76941713e-09, 2.76940199e-09, 4.10914311e-10], ) result = harmonic_simulation.displacement(set_ids=[1], skin=[1, 2, 3]) - assert len(result.index.mesh_index) == 44 + assert len(result.index.mesh_index) == 40 def test_stress_skin(self, harmonic_simulation: post.HarmonicMechanicalSimulation): if harmonic_simulation._model._server.meet_version("6.2"): @@ -2760,19 +2760,26 @@ def test_stress_skin(self, harmonic_simulation: post.HarmonicMechanicalSimulatio else: assert len(result.index.mesh_index) == 3942 assert len(result.columns.set_ids) == 1 + outer_nodes = harmonic_simulation.mesh.named_selections[ + "OUTER_FACE" + ]._scoping + outer_elements = dpf.operators.scoping.transpose( + mesh_scoping=outer_nodes, + meshed_region=harmonic_simulation.mesh._meshed_region, + ).eval() result = harmonic_simulation.stress_elemental( - set_ids=[1], skin=list(range(1, 100)) + set_ids=[1], skin=outer_elements.ids ) if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1: - assert len(result.index.mesh_index) == 122 + assert len(result.index.mesh_index) == 240 else: assert len(result.index.mesh_index) == 192 assert len(result.columns.set_ids) == 1 result = harmonic_simulation.stress_eqv_von_mises_nodal( - set_ids=[1], skin=list(range(1, 100)) + set_ids=[1], skin=outer_elements.ids ) if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1: - assert len(result.index.mesh_index) == 520 + assert len(result.index.mesh_index) == 880 else: assert len(result.index.mesh_index) == 530 assert len(result.columns.set_ids) == 1 From 3bc8779a4b842c7772fbdf07fd98ee8ddf979bad Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Fri, 27 Oct 2023 18:07:20 +0200 Subject: [PATCH 08/22] Fix refs of tests --- tests/test_simulation.py | 68 ++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/tests/test_simulation.py b/tests/test_simulation.py index 4fd20c999..da5a19b42 100644 --- a/tests/test_simulation.py +++ b/tests/test_simulation.py @@ -1320,7 +1320,10 @@ def test_skin_layer2( self, transient_simulation: post.TransientMechanicalSimulation ): result = transient_simulation.displacement(set_ids=[1], skin=[1, 2, 3]) - assert len(result.index.mesh_index) == 42 + if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1: + assert len(result.index.mesh_index) == 42 + else: + assert len(result.index.mesh_index) == 44 def test_skin_layer3( self, transient_simulation: post.TransientMechanicalSimulation @@ -1991,13 +1994,21 @@ def test_disp_skin(self, frame_modal_simulation: post.ModalMechanicalSimulation) assert np.allclose( result.max(axis="node_ids").array, [0.05656421, 9.59989137, 1.08656671] ) - result = frame_modal_simulation.displacement(set_ids=[1], skin=[1, 2, 3]) + + fixed_nodes = frame_modal_simulation.mesh.named_selections["_FIXEDSU"]._scoping + fixed_elements = dpf.operators.scoping.transpose( + mesh_scoping=fixed_nodes, + meshed_region=frame_modal_simulation.mesh._meshed_region, + ).eval() + result = frame_modal_simulation.displacement( + set_ids=[1], skin=fixed_elements.ids + ) if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1: - assert len(result.index.mesh_index) == 21 + assert len(result.index.mesh_index) == 335 else: - assert len(result.index.mesh_index) == 14 + assert len(result.index.mesh_index) == 455 assert np.allclose( - result.max(axis="node_ids").array, [-0.77876072, 7.08211902, 0.05292333] + result.max(axis="node_ids").array, [0.05594125, 0.23687614, 0.21415196] ) def test_stress_skin(self, frame_modal_simulation: post.ModalMechanicalSimulation): @@ -2014,32 +2025,32 @@ def test_stress_skin(self, frame_modal_simulation: post.ModalMechanicalSimulatio ) assert len(result.columns.set_ids) == 1 if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1: - assert len(result.index.mesh_index) == 36 + assert len(result.index.mesh_index) == 72 assert np.allclose( result.max(axis="element_ids").array, [ [ - 36.52192259, - 58.73246002, - 371.72294617, - 12.80614456, - 134.60557556, - 38.0447108, + 88.09000492, + 426.21118164, + 747.8219401, + 30.50066868, + 412.80891927, + 109.25983429, ] ], ) else: - assert len(result.index.mesh_index) == 110 + assert len(result.index.mesh_index) == 497 assert np.allclose( result.max(axis="element_ids").array, [ [ - 36.52192259, - 58.73246002, - 371.72294617, - 25.97949378, - 139.83338165, - 69.25232569, + 145.15428162, + 426.21118164, + 840.23429362, + 34.79916509, + 415.22954305, + 109.25983429, ] ], ) @@ -2089,9 +2100,9 @@ def test_strain_skin(self, frame_modal_simulation: post.ModalMechanicalSimulatio set_ids=[1], skin=list(range(1, 100)) ) if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1: - assert len(result.index.mesh_index) == 36 + assert len(result.index.mesh_index) == 72 else: - assert len(result.index.mesh_index) == 110 + assert len(result.index.mesh_index) == 497 assert len(result.columns.set_ids) == 1 def test_strain_skin2(self, frame_modal_simulation: post.ModalMechanicalSimulation): @@ -2750,7 +2761,10 @@ def test_disp_skin(self, harmonic_simulation: post.HarmonicMechanicalSimulation) [2.76941713e-09, 2.76940199e-09, 4.10914311e-10], ) result = harmonic_simulation.displacement(set_ids=[1], skin=[1, 2, 3]) - assert len(result.index.mesh_index) == 40 + if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1: + assert len(result.index.mesh_index) == 40 + else: + assert len(result.index.mesh_index) == 44 def test_stress_skin(self, harmonic_simulation: post.HarmonicMechanicalSimulation): if harmonic_simulation._model._server.meet_version("6.2"): @@ -2773,7 +2787,7 @@ def test_stress_skin(self, harmonic_simulation: post.HarmonicMechanicalSimulatio if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1: assert len(result.index.mesh_index) == 240 else: - assert len(result.index.mesh_index) == 192 + assert len(result.index.mesh_index) == 560 assert len(result.columns.set_ids) == 1 result = harmonic_simulation.stress_eqv_von_mises_nodal( set_ids=[1], skin=outer_elements.ids @@ -2781,7 +2795,7 @@ def test_stress_skin(self, harmonic_simulation: post.HarmonicMechanicalSimulatio if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1: assert len(result.index.mesh_index) == 880 else: - assert len(result.index.mesh_index) == 530 + assert len(result.index.mesh_index) == 960 assert len(result.columns.set_ids) == 1 result = harmonic_simulation.stress_eqv_von_mises_nodal( set_ids=[1], skin=True @@ -2815,7 +2829,7 @@ def test_strain_skin(self, harmonic_simulation: post.HarmonicMechanicalSimulatio if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1: assert len(result.index.mesh_index) == 240 else: - assert len(result.index.mesh_index) == 192 + assert len(result.index.mesh_index) == 560 assert len(result.columns.set_ids) == 1 result = harmonic_simulation.elastic_strain_eqv_von_mises_nodal( set_ids=[1], skin=outer_elements.ids @@ -2823,7 +2837,7 @@ def test_strain_skin(self, harmonic_simulation: post.HarmonicMechanicalSimulatio if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1: assert len(result.index.mesh_index) == 880 else: - assert len(result.index.mesh_index) == 530 + assert len(result.index.mesh_index) == 960 assert len(result.columns.set_ids) == 1 assert np.allclose( result.select(complex=0).max(axis="node_ids").array, [1.22784309e-06] @@ -2842,7 +2856,7 @@ def test_strain_skin(self, harmonic_simulation: post.HarmonicMechanicalSimulatio if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1: assert len(result.index.mesh_index) == 880 else: - assert len(result.index.mesh_index) == 530 + assert len(result.index.mesh_index) == 960 assert len(result.columns.set_ids) == 1 result = harmonic_simulation.elastic_strain_eqv_von_mises_elemental( set_ids=[1], skin=True From e3393a0551dd97449ec38b8f48b7d787320c26a9 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Mon, 30 Oct 2023 12:23:16 +0100 Subject: [PATCH 09/22] Fix refs of tests --- tests/test_simulation.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/test_simulation.py b/tests/test_simulation.py index da5a19b42..f5f70e240 100644 --- a/tests/test_simulation.py +++ b/tests/test_simulation.py @@ -1328,8 +1328,9 @@ def test_skin_layer2( def test_skin_layer3( self, transient_simulation: post.TransientMechanicalSimulation ): + print(transient_simulation.mesh.named_selections) result = transient_simulation.stress_principal_elemental( - skin=list(range(1, 100)) + skin=transient_simulation.mesh.element_ids ) if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1: assert len(result.index.mesh_index) == 124 @@ -1340,7 +1341,7 @@ def test_skin_layer4( self, transient_simulation: post.TransientMechanicalSimulation ): result = transient_simulation.elastic_strain_eqv_von_mises_elemental( - skin=list(range(1, 100)) + skin=transient_simulation.mesh.element_ids ) if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1: assert len(result.index.mesh_index) == 124 @@ -1350,7 +1351,9 @@ def test_skin_layer4( def test_skin_layer5( self, transient_simulation: post.TransientMechanicalSimulation ): - result = transient_simulation.stress_principal_nodal(skin=list(range(1, 100))) + result = transient_simulation.stress_principal_nodal( + skin=transient_simulation.mesh.element_ids + ) if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1: assert len(result.index.mesh_index) == 374 else: @@ -1360,7 +1363,7 @@ def test_skin_layer6( self, transient_simulation: post.TransientMechanicalSimulation ): result = transient_simulation.elastic_strain_eqv_von_mises_nodal( - skin=list(range(1, 100)) + skin=transient_simulation.mesh.element_ids ) if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1: assert len(result.index.mesh_index) == 374 From 8f81e3d4c2a11a9a82c78b150298b7a7436f14e8 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Fri, 3 Nov 2023 10:14:09 +0100 Subject: [PATCH 10/22] Fix typo --- src/ansys/dpf/post/post_utility.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ansys/dpf/post/post_utility.py b/src/ansys/dpf/post/post_utility.py index 292c73b17..0d8d9d281 100644 --- a/src/ansys/dpf/post/post_utility.py +++ b/src/ansys/dpf/post/post_utility.py @@ -223,10 +223,10 @@ def load_simulation( simulation_type = AvailableSimulationTypes.unsteady_fluid else: raise ValueError( - f"Unknown analysis type '{analysis_type}' for {physics_type}." + f"Unknown analysis type '{analysis_type}' for '{physics_type}'." ) else: - raise ValueError(f"Unknown physics type '{physics_type}.") + raise ValueError(f"Unknown physics type '{physics_type}'.") if simulation_type in [ getattr(AvailableSimulationTypes, x) for x in vars(AvailableSimulationTypes) From 29926b858c48e2dbc7b09fbb9cca68b8c026613c Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Tue, 7 Nov 2023 16:54:18 +0100 Subject: [PATCH 11/22] WIP --- src/ansys/dpf/post/selection.py | 61 +++++++++++++++++-- src/ansys/dpf/post/simulation.py | 25 +++++++- .../dpf/post/static_mechanical_simulation.py | 50 +++++++++++---- 3 files changed, 118 insertions(+), 18 deletions(-) diff --git a/src/ansys/dpf/post/selection.py b/src/ansys/dpf/post/selection.py index a1c8d95f8..44e14d9bc 100644 --- a/src/ansys/dpf/post/selection.py +++ b/src/ansys/dpf/post/selection.py @@ -219,10 +219,32 @@ def __init__( """ self._server = get_or_create_server(server) self._selection = Workflow(server=self._server) - + self._current_initial_mesh_output = None if scoping is not None: self.select_with_scoping(scoping) + def reduce_mesh(self, element_ids: Union[Scoping, List[int]]): + """Reduce the mesh under consideration to the given list of elements. + + Parameters + ---------- + element_ids: + Scoping or list of IDs of elements to reduce the mesh to. + """ + if not isinstance(element_ids, Scoping): + element_ids = Scoping( + ids=element_ids, location=locations.elemental, server=self._server + ) + op = operators.mesh.from_scoping(element_ids, server=self._server) + self._selection.add_operator(op) + # If the workflow already has an initial_mesh output, connect this after + if self._current_initial_mesh_output: + op.inputs.mesh.connect(self._current_initial_mesh_output) + else: + self._selection.set_input_name(_WfNames.initial_mesh, op.inputs.mesh) + self._selection.set_output_name(_WfNames.initial_mesh, op.outputs.mesh) + self._current_initial_mesh_output = op.outputs.mesh + def select_named_selection( self, named_selection: Union[str, List[str]], @@ -393,7 +415,7 @@ def select_skin( Native (as found in the file) location of the output result. Used to pick the location of the scoping. elements: - List of elements to use to compute the external layer, + List of elements to use to compute the skin, default is all the elements of the model. Getting the skin on a selection of elements for cyclic symmetry is not supported. is_model_cyclic: @@ -455,7 +477,18 @@ def select_skin( ) if mesh_input is not None: - self._selection.set_input_name(_WfNames.initial_mesh, mesh_input) + # If the workflow already has an initial_mesh output, connect this after + if self._current_initial_mesh_output: + mesh_input.connect(self._current_initial_mesh_output) + else: + self._selection.set_input_name(_WfNames.initial_mesh, mesh_input) + # self._selection.set_output_name(_WfNames.initial_mesh, op.outputs.mesh) + # self._current_initial_mesh_output = op.outputs.mesh + + # pass + # else: + # # otherwise, set this as the initial_mesh input + # self._selection.set_input_name(_WfNames.initial_mesh, mesh_input) if location == result_native_location: self._selection.set_output_name(_WfNames.mesh, op.outputs.mesh) self._selection.set_output_name(_WfNames.skin, op.outputs.mesh) @@ -726,9 +759,14 @@ def requires_mesh(self) -> bool: """Whether the selection workflow requires a ``mesh`` as an input or not.""" return _WfNames.initial_mesh in self._selection.input_names + @property + def reduces_mesh(self) -> bool: + """Whether the selection workflow gives a reduced ``mesh`` as an output or not.""" + return _WfNames.initial_mesh in self._selection.output_names + @property def outputs_mesh(self) -> bool: - """Whether the selection workflow as an output named ``mesh``.""" + """Whether the selection workflow has an output named ``mesh``.""" return _WfNames.mesh in self._selection.output_names def requires_manual_averaging( @@ -803,6 +841,16 @@ def spatial_selection(self) -> SpatialSelection: def spatial_selection(self, value: SpatialSelection): self._spatial_selection = value + def reduce_mesh(self, element_ids: Union[List[int]]): + """Reduce the mesh under consideration to the given list of elements. + + Parameters + ---------- + element_ids: + List of IDs of elements to reduce the mesh to. + """ + self._spatial_selection.reduce_mesh(element_ids) + def select_time_freq_indices(self, time_freq_indices: List[int]) -> None: """Select time frequency sets by their indices (zero-based indexing). @@ -1021,6 +1069,11 @@ def requires_mesh(self) -> bool: """Whether the selection workflow requires a ``initial_mesh`` as an input or not.""" return self._spatial_selection.requires_mesh + @property + def reduces_mesh(self) -> bool: + """Whether the selection workflow gives a reduced ``mesh`` as an output or not.""" + return self._spatial_selection.reduces_mesh + @property def outputs_mesh(self) -> bool: """Whether the selection workflow as an output named ``mesh``.""" diff --git a/src/ansys/dpf/post/simulation.py b/src/ansys/dpf/post/simulation.py index 02536a8e6..f4b706f27 100644 --- a/src/ansys/dpf/post/simulation.py +++ b/src/ansys/dpf/post/simulation.py @@ -536,12 +536,12 @@ def _build_result_workflow( force_elemental_nodal: bool, ) -> (dpf.Workflow, dpf.Operator): op = self._model.operator(name=name) - op.connect(7, self.mesh._meshed_region) if force_elemental_nodal: op.connect(9, "ElementalNodal") elif location: op.connect(9, location) wf = Workflow(server=self._model._server) + wf.set_input_name(_WfNames.initial_mesh, op, 7) wf.set_input_name(_WfNames.read_cyclic, op, 14) wf.set_input_name(_WfNames.cyclic_sectors_to_expand, op, 18) wf.set_input_name(_WfNames.cyclic_phase, op, 19) @@ -816,6 +816,7 @@ def _build_selection( external_layer: bool = False, skin: Union[bool, List[int]] = False, expand_cyclic: Union[bool, List[Union[int, List[int]]]] = True, + reduce_mesh: Union[bool, List[int]] = False, ) -> Selection: tot = ( (node_ids is not None) @@ -841,6 +842,28 @@ def _build_selection( selection = Selection(server=self._model._server) # Create the SpatialSelection + # Reduce mesh if necessary + if reduce_mesh is not False: + extract_scoping = None + if not isinstance(reduce_mesh, bool): + select_mesh = Selection() + select_mesh.select_elements(reduce_mesh) + extract_scoping = select_mesh.spatial_selection.apply_to(self) + elif not isinstance(skin, bool): + select_mesh = Selection() + select_mesh.select_elements(skin) + extract_scoping = select_mesh.spatial_selection.apply_to(self) + elif element_ids is not None: + select_mesh = Selection() + select_mesh.select_elements(element_ids) + extract_scoping = select_mesh.spatial_selection.apply_to(self) + elif named_selections: + select_mesh = Selection() + select_mesh.select_named_selection(named_selections) + extract_scoping = select_mesh.spatial_selection.apply_to(self) + if extract_scoping is not None: + selection.reduce_mesh(extract_scoping) + # First: the skin and the external layer to be able to have both a mesh scoping and # the skin/external layer if (skin is not None and skin is not False) or ( diff --git a/src/ansys/dpf/post/static_mechanical_simulation.py b/src/ansys/dpf/post/static_mechanical_simulation.py index 2a254c61b..d956108b4 100644 --- a/src/ansys/dpf/post/static_mechanical_simulation.py +++ b/src/ansys/dpf/post/static_mechanical_simulation.py @@ -37,6 +37,7 @@ def _get_result( phase_angle_cyclic: Union[float, None] = None, external_layer: Union[bool, List[int]] = False, skin: Union[bool, List[int]] = False, + reduce_mesh: Union[bool, List[int]] = False, ) -> DataFrame: """Extract results from the simulation. @@ -104,6 +105,11 @@ def _get_result( is computed over list of elements (not supported for cyclic symmetry). Getting the skin on more than one result (several time freq sets, split data...) is only supported starting with Ansys 2023R2. + reduce_mesh: + Perform a reduction of the mesh under consideration based on, by order of priority: + - the list of element IDs given to this parameter + - parameter skin if reduce_mesh=True + - parameter element_ids if reduce_mesh=True and skin=None Returns ------- @@ -138,6 +144,7 @@ def _get_result( location=location, external_layer=external_layer, skin=skin, + reduce_mesh=reduce_mesh, ) comp, to_extract, columns = self._create_components( @@ -181,10 +188,20 @@ def _get_result( output_input_names={_WfNames.initial_mesh: _WfNames.initial_mesh}, ) - wf.connect_with( - selection.spatial_selection._selection, - output_input_names={"scoping": "mesh_scoping"}, - ) + if selection.reduces_mesh: + wf.connect_with( + selection.spatial_selection._selection, + output_input_names={ + "scoping": "mesh_scoping", + "initial_mesh": "initial_mesh", + }, + ) + else: + result_op.connect(7, self.mesh._meshed_region) + wf.connect_with( + selection.spatial_selection._selection, + output_input_names={"scoping": "mesh_scoping"}, + ) # Treat cyclic cases wf = self._treat_cyclic(expand_cyclic, phase_angle_cyclic, wf) @@ -1099,6 +1116,7 @@ def stress_eqv_von_mises_elemental( phase_angle_cyclic: Union[float, None] = None, external_layer: Union[bool, List[int]] = False, skin: Union[bool, List[int]] = False, + reduce_mesh: Union[bool, List[int]] = False, ) -> DataFrame: """Extract elemental equivalent von Mises stress results from the simulation. @@ -1137,17 +1155,22 @@ def stress_eqv_von_mises_elemental( If the problem is multi-stage, can take a list of lists of sector numbers, ordered by stage. phase_angle_cyclic: - For cyclic problems, phase angle to apply (in degrees). + For cyclic problems, phase angle to apply (in degrees). external_layer: - Select the external layer (last layer of solid elements under the skin) - of the mesh for plotting and data extraction. If a list is passed, the external - layer is computed over list of elements. + Select the external layer (last layer of solid elements under the skin) + of the mesh for plotting and data extraction. If a list is passed, the external + layer is computed over list of elements. skin: - Select the skin (creates new 2D elements connecting the external nodes) - of the mesh for plotting and data extraction. If a list is passed, the skin - is computed over list of elements (not supported for cyclic symmetry). Getting the - skin on more than one result (several time freq sets, split data...) is only - supported starting with Ansys 2023R2. + Select the skin (creates new 2D elements connecting the external nodes) + of the mesh for plotting and data extraction. If a list is passed, the skin + is computed over list of elements (not supported for cyclic symmetry). Getting the + skin on more than one result (several time freq sets, split data...) is only + supported starting with Ansys 2023R2. + reduce_mesh: + Perform a reduction of the mesh under consideration based on, by order of priority: + - the list of element IDs given to this parameter + - parameter skin if reduce_mesh=True + - parameter element_ids if reduce_mesh=True and skin=None Returns ------- @@ -1171,6 +1194,7 @@ def stress_eqv_von_mises_elemental( phase_angle_cyclic=phase_angle_cyclic, external_layer=external_layer, skin=skin, + reduce_mesh=reduce_mesh, ) def stress_eqv_von_mises_nodal( From f6161a42190e6f24f32772745d8058be0cc217df Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Tue, 7 Nov 2023 17:35:34 +0100 Subject: [PATCH 12/22] Use "initial_mesh_wf_out" name --- src/ansys/dpf/post/static_mechanical_simulation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ansys/dpf/post/static_mechanical_simulation.py b/src/ansys/dpf/post/static_mechanical_simulation.py index d956108b4..6123a0347 100644 --- a/src/ansys/dpf/post/static_mechanical_simulation.py +++ b/src/ansys/dpf/post/static_mechanical_simulation.py @@ -181,11 +181,11 @@ def _get_result( if selection.requires_mesh: mesh_wf = core.Workflow(server=self._model._server) mesh_wf.set_output_name( - _WfNames.initial_mesh, self._model.metadata.mesh_provider + "initial_mesh_wf_out", self._model.metadata.mesh_provider ) selection.spatial_selection._selection.connect_with( mesh_wf, - output_input_names={_WfNames.initial_mesh: _WfNames.initial_mesh}, + output_input_names={"initial_mesh_wf_out": _WfNames.initial_mesh}, ) if selection.reduces_mesh: From a43d2fbdbf52fa1190c2f2f9ffdf3d19a7fcbc41 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Tue, 7 Nov 2023 17:37:03 +0100 Subject: [PATCH 13/22] Use "result_mesh" name --- src/ansys/dpf/post/selection.py | 1 + src/ansys/dpf/post/simulation.py | 2 +- src/ansys/dpf/post/static_mechanical_simulation.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ansys/dpf/post/selection.py b/src/ansys/dpf/post/selection.py index 44e14d9bc..c0a95f233 100644 --- a/src/ansys/dpf/post/selection.py +++ b/src/ansys/dpf/post/selection.py @@ -45,6 +45,7 @@ class _WfNames: cyclic_sectors_to_expand = "cyclic_sectors_to_expand" cyclic_phase = "cyclic_phase" result = "result" + result_mesh = "result_mesh" def _is_model_cyclic(is_cyclic: str): diff --git a/src/ansys/dpf/post/simulation.py b/src/ansys/dpf/post/simulation.py index f4b706f27..1764b3924 100644 --- a/src/ansys/dpf/post/simulation.py +++ b/src/ansys/dpf/post/simulation.py @@ -541,7 +541,7 @@ def _build_result_workflow( elif location: op.connect(9, location) wf = Workflow(server=self._model._server) - wf.set_input_name(_WfNames.initial_mesh, op, 7) + wf.set_input_name(_WfNames.result_mesh, op, 7) wf.set_input_name(_WfNames.read_cyclic, op, 14) wf.set_input_name(_WfNames.cyclic_sectors_to_expand, op, 18) wf.set_input_name(_WfNames.cyclic_phase, op, 19) diff --git a/src/ansys/dpf/post/static_mechanical_simulation.py b/src/ansys/dpf/post/static_mechanical_simulation.py index 6123a0347..d72191de4 100644 --- a/src/ansys/dpf/post/static_mechanical_simulation.py +++ b/src/ansys/dpf/post/static_mechanical_simulation.py @@ -193,7 +193,7 @@ def _get_result( selection.spatial_selection._selection, output_input_names={ "scoping": "mesh_scoping", - "initial_mesh": "initial_mesh", + "initial_mesh": _WfNames.result_mesh, }, ) else: From c34562a766913ce7f3bf6982fa33f00703bf491e Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Tue, 7 Nov 2023 17:37:37 +0100 Subject: [PATCH 14/22] WIP --- src/ansys/dpf/post/simulation.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/ansys/dpf/post/simulation.py b/src/ansys/dpf/post/simulation.py index 1764b3924..3359f72cb 100644 --- a/src/ansys/dpf/post/simulation.py +++ b/src/ansys/dpf/post/simulation.py @@ -845,22 +845,28 @@ def _build_selection( # Reduce mesh if necessary if reduce_mesh is not False: extract_scoping = None + # Reduce on the list of reduced if not isinstance(reduce_mesh, bool): + # reduce_mesh=list select_mesh = Selection() select_mesh.select_elements(reduce_mesh) extract_scoping = select_mesh.spatial_selection.apply_to(self) - elif not isinstance(skin, bool): - select_mesh = Selection() - select_mesh.select_elements(skin) - extract_scoping = select_mesh.spatial_selection.apply_to(self) - elif element_ids is not None: - select_mesh = Selection() - select_mesh.select_elements(element_ids) - extract_scoping = select_mesh.spatial_selection.apply_to(self) - elif named_selections: - select_mesh = Selection() - select_mesh.select_named_selection(named_selections) - extract_scoping = select_mesh.spatial_selection.apply_to(self) + else: + # reduce_mesh=True + if not isinstance(skin, bool): + select_mesh = Selection() + select_mesh.select_elements(skin) + extract_scoping = select_mesh.spatial_selection.apply_to(self) + else: + # reduce_mesh=True, skin=True|False + if element_ids is not None: + select_mesh = Selection() + select_mesh.select_elements(element_ids) + extract_scoping = select_mesh.spatial_selection.apply_to(self) + elif named_selections: + select_mesh = Selection() + select_mesh.select_named_selection(named_selections) + extract_scoping = select_mesh.spatial_selection.apply_to(self) if extract_scoping is not None: selection.reduce_mesh(extract_scoping) From d7f1189a8f3f40d28d531b0306e95f518766b01d Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Wed, 8 Nov 2023 19:40:16 +0100 Subject: [PATCH 15/22] Fix mesh connection --- src/ansys/dpf/post/static_mechanical_simulation.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ansys/dpf/post/static_mechanical_simulation.py b/src/ansys/dpf/post/static_mechanical_simulation.py index d72191de4..3637d2653 100644 --- a/src/ansys/dpf/post/static_mechanical_simulation.py +++ b/src/ansys/dpf/post/static_mechanical_simulation.py @@ -187,6 +187,8 @@ def _get_result( mesh_wf, output_input_names={"initial_mesh_wf_out": _WfNames.initial_mesh}, ) + else: + result_op.connect(7, self.mesh._meshed_region) if selection.reduces_mesh: wf.connect_with( @@ -197,7 +199,6 @@ def _get_result( }, ) else: - result_op.connect(7, self.mesh._meshed_region) wf.connect_with( selection.spatial_selection._selection, output_input_names={"scoping": "mesh_scoping"}, From fa8aa84d70d4bfe4fccbb15ca96f439108ff9a7c Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Mon, 13 Nov 2023 16:51:23 +0100 Subject: [PATCH 16/22] Update 02-mesh-skin.py example with titles to plots --- examples/02-Performance-Improvements/02-mesh-skin.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/02-Performance-Improvements/02-mesh-skin.py b/examples/02-Performance-Improvements/02-mesh-skin.py index ac93eebef..5922a3459 100644 --- a/examples/02-Performance-Improvements/02-mesh-skin.py +++ b/examples/02-Performance-Improvements/02-mesh-skin.py @@ -50,7 +50,7 @@ # Extract displacement data on the skin. displacement_skin = simulation.displacement(skin=True) -displacement_skin.plot() +displacement_skin.plot(text="U with skin=True") print(f"number of nodes with skin=True: {len(displacement_skin.index.mesh_index)}") print(f"number of nodes with skin=False: {len(simulation.mesh.node_ids)}") @@ -62,7 +62,7 @@ # Averaging, and invariants computation are done through a solid to skin connectivity mapping. elemental_stress_skin = simulation.stress_principal_elemental(components=[1], skin=True) -elemental_stress_skin.plot() +elemental_stress_skin.plot(text="S1 with skin=True") print( f"number of elements with skin=True: {len(elemental_stress_skin.index.mesh_index)}" @@ -71,15 +71,15 @@ elastic_strain_eqv_skin = simulation.elastic_strain_eqv_von_mises_nodal(skin=True) -elastic_strain_eqv_skin.plot() +elastic_strain_eqv_skin.plot(text="EE with skin=True") ############################################################################### -# Extract the external layer on a selection of elements -# ----------------------------------------------------- +# Extract on the skin of a selection of elements +# ---------------------------------------------- all_elements = simulation.mesh.element_ids elements = [] for i in range(0, int(all_elements.size / 2)): elements.append(all_elements[i]) elemental_stress_skin = simulation.stress_principal_elemental(skin=elements) -elemental_stress_skin.plot() +elemental_stress_skin.plot(text="S1 with skin=elements") From adc8a46e01be7b7f7dc37918ad4a5aca353873a6 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Mon, 13 Nov 2023 16:52:00 +0100 Subject: [PATCH 17/22] Remove progress bar from selection workflows --- src/ansys/dpf/post/selection.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ansys/dpf/post/selection.py b/src/ansys/dpf/post/selection.py index c0a95f233..fb3afa37f 100644 --- a/src/ansys/dpf/post/selection.py +++ b/src/ansys/dpf/post/selection.py @@ -69,6 +69,7 @@ def __init__(self, server: Union[BaseServer, None] = None): """ self._server = get_or_create_server(server) self._selection = Workflow(server=self._server) + self._selection.progress_bar = False def select_time_freq_indices(self, time_freq_indices: List[int]) -> None: """Select time frequency sets by their indices (zero-based indexing). @@ -220,6 +221,7 @@ def __init__( """ self._server = get_or_create_server(server) self._selection = Workflow(server=self._server) + self._selection.progress_bar = False self._current_initial_mesh_output = None if scoping is not None: self.select_with_scoping(scoping) From e24b07a94cfc307ee2bb4233d5b52663355fda17 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Mon, 13 Nov 2023 16:52:40 +0100 Subject: [PATCH 18/22] Remove progress bar from initial mesh workflow --- src/ansys/dpf/post/static_mechanical_simulation.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ansys/dpf/post/static_mechanical_simulation.py b/src/ansys/dpf/post/static_mechanical_simulation.py index 3637d2653..1cbb19949 100644 --- a/src/ansys/dpf/post/static_mechanical_simulation.py +++ b/src/ansys/dpf/post/static_mechanical_simulation.py @@ -180,6 +180,7 @@ def _get_result( ) if selection.requires_mesh: mesh_wf = core.Workflow(server=self._model._server) + mesh_wf.progress_bar = False mesh_wf.set_output_name( "initial_mesh_wf_out", self._model.metadata.mesh_provider ) From 72c1d14886b50557c5dbf8e98eebd72fb2d9649c Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Mon, 13 Nov 2023 16:56:03 +0100 Subject: [PATCH 19/22] Temporary hack to remove mesh cached in model's streams --- src/ansys/dpf/post/static_mechanical_simulation.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ansys/dpf/post/static_mechanical_simulation.py b/src/ansys/dpf/post/static_mechanical_simulation.py index 1cbb19949..817a14eed 100644 --- a/src/ansys/dpf/post/static_mechanical_simulation.py +++ b/src/ansys/dpf/post/static_mechanical_simulation.py @@ -179,6 +179,7 @@ def _get_result( output_input_names=("scoping", "time_scoping"), ) if selection.requires_mesh: + self._model._metadata = None mesh_wf = core.Workflow(server=self._model._server) mesh_wf.progress_bar = False mesh_wf.set_output_name( From f15e96c1ae509f4f01dd22b0488f601666992a2e Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Tue, 21 Nov 2023 14:41:16 +0100 Subject: [PATCH 20/22] Add tests WIP --- tests/test_simulation.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_simulation.py b/tests/test_simulation.py index f5f70e240..04133760a 100644 --- a/tests/test_simulation.py +++ b/tests/test_simulation.py @@ -679,6 +679,17 @@ def test_skin_layer6(self, static_simulation: post.StaticMechanicalSimulation): result = static_simulation.stress_principal_elemental(skin=[1, 2, 3]) assert len(result.index.mesh_index) == 9 + def test_reduced_mesh(self, static_simulation: post.StaticMechanicalSimulation): + result = static_simulation.stress_eqv_von_mises_elemental(reduce_mesh=True) + print(result) + assert len(result.mesh_index) == static_simulation.mesh.num_elements + result = static_simulation.stress_eqv_von_mises_elemental( + reduce_mesh=static_simulation.mesh.element_ids[:-2] + ) + print(static_simulation.mesh.element_ids[:-2]) + print(result) + assert len(result.mesh_index) == static_simulation.mesh.num_elements - 2 + class TestTransientMechanicalSimulation: @fixture From 2d37b7615a040a7426e573adbba31405b4c2d097 Mon Sep 17 00:00:00 2001 From: Paul Profizi <100710998+PProfizi@users.noreply.github.com> Date: Thu, 23 Nov 2023 14:46:03 +0100 Subject: [PATCH 21/22] Apply suggestions from code review Co-authored-by: JennaPaikowsky <98607744+JennaPaikowsky@users.noreply.github.com> --- src/ansys/dpf/post/selection.py | 4 ++-- .../dpf/post/static_mechanical_simulation.py | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/ansys/dpf/post/selection.py b/src/ansys/dpf/post/selection.py index fb3afa37f..ed65e8421 100644 --- a/src/ansys/dpf/post/selection.py +++ b/src/ansys/dpf/post/selection.py @@ -227,7 +227,7 @@ def __init__( self.select_with_scoping(scoping) def reduce_mesh(self, element_ids: Union[Scoping, List[int]]): - """Reduce the mesh under consideration to the given list of elements. + """Reduce the mesh with consideration to the given list of elements. Parameters ---------- @@ -845,7 +845,7 @@ def spatial_selection(self, value: SpatialSelection): self._spatial_selection = value def reduce_mesh(self, element_ids: Union[List[int]]): - """Reduce the mesh under consideration to the given list of elements. + """Reduce the mesh with consideration to the given list of elements. Parameters ---------- diff --git a/src/ansys/dpf/post/static_mechanical_simulation.py b/src/ansys/dpf/post/static_mechanical_simulation.py index 817a14eed..7c13dea5e 100644 --- a/src/ansys/dpf/post/static_mechanical_simulation.py +++ b/src/ansys/dpf/post/static_mechanical_simulation.py @@ -106,10 +106,10 @@ def _get_result( skin on more than one result (several time freq sets, split data...) is only supported starting with Ansys 2023R2. reduce_mesh: - Perform a reduction of the mesh under consideration based on, by order of priority: - - the list of element IDs given to this parameter - - parameter skin if reduce_mesh=True - - parameter element_ids if reduce_mesh=True and skin=None + Perform a reduction of the mesh based on, by order of priority: + - The list of element IDs given to this parameter + - Parameter skin if reduce_mesh=True + - Parameter element_ids if reduce_mesh=True and skin=None Returns ------- @@ -1168,12 +1168,12 @@ def stress_eqv_von_mises_elemental( of the mesh for plotting and data extraction. If a list is passed, the skin is computed over list of elements (not supported for cyclic symmetry). Getting the skin on more than one result (several time freq sets, split data...) is only - supported starting with Ansys 2023R2. + supported starting with Ansys 2023 R2. reduce_mesh: - Perform a reduction of the mesh under consideration based on, by order of priority: - - the list of element IDs given to this parameter - - parameter skin if reduce_mesh=True - - parameter element_ids if reduce_mesh=True and skin=None + Perform a reduction of the mesh based on, by order of priority: + - The list of element IDs given to this parameter + - Parameter skin if reduce_mesh=True + - Parameter element_ids if reduce_mesh=True and skin=None Returns ------- From e5abaadf19826c975e9b59f16126fed408899fa2 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Wed, 20 Dec 2023 10:38:16 +0100 Subject: [PATCH 22/22] Remove dirty trick to reset model.metadata now a fix has been made --- src/ansys/dpf/post/static_mechanical_simulation.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ansys/dpf/post/static_mechanical_simulation.py b/src/ansys/dpf/post/static_mechanical_simulation.py index 7c13dea5e..4d1bb4bb9 100644 --- a/src/ansys/dpf/post/static_mechanical_simulation.py +++ b/src/ansys/dpf/post/static_mechanical_simulation.py @@ -179,7 +179,6 @@ def _get_result( output_input_names=("scoping", "time_scoping"), ) if selection.requires_mesh: - self._model._metadata = None mesh_wf = core.Workflow(server=self._model._server) mesh_wf.progress_bar = False mesh_wf.set_output_name(