From 1f0c4becb95546c1abec09318ab54128e1ac1b83 Mon Sep 17 00:00:00 2001 From: achitwar Date: Fri, 26 Jul 2024 21:03:09 +0530 Subject: [PATCH 01/10] Added postprocessing visualization example. --- .../01-advanced-pyansys-examples/README.txt | 4 + .../using_meshobject_with_field_data.py | 132 ++++++++++++++++++ pyproject.toml | 1 + 3 files changed, 137 insertions(+) create mode 100644 examples/01-advanced-pyansys-examples/README.txt create mode 100644 examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py diff --git a/examples/01-advanced-pyansys-examples/README.txt b/examples/01-advanced-pyansys-examples/README.txt new file mode 100644 index 00000000..b0ef1ca5 --- /dev/null +++ b/examples/01-advanced-pyansys-examples/README.txt @@ -0,0 +1,4 @@ +Advanced usage examples +======================= + +These examples show how to use the Visualization Interface Tool to postprocess simulation data. \ No newline at end of file diff --git a/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py b/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py new file mode 100644 index 00000000..1289b2f9 --- /dev/null +++ b/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py @@ -0,0 +1,132 @@ +# Copyright (C) 2023 - 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. + +""" +.. _ref_postprocess_using_meshobjects: + +====================================================================== +Use the ``MeshObjectPlot`` class to postprocess Simulation Results +====================================================================== + +The Visualization Interface Tool provides the ``MeshObject`` helper class to relate a custom object. +With a custom object, you can take advantage of the full potential of the Visualization Interface Tool. + +This example shows how to use the ``MeshObjectPlot`` class to plot your custom objects with scalar data on mesh. + +""" + +################################################### +# Necessary imports +# ================================================= + + +import pyvista as pv +from ansys.tools.visualization_interface.backends.pyvista import PyVistaBackend +from ansys.tools.visualization_interface import MeshObjectPlot +from ansys.tools.visualization_interface import Plotter +from ansys.fluent.core import examples + +################################################### +# Download the VTK file +# ================================================= + +# A VTK dataset can be produced utilizing the `pydpf `_ +# for Ansys Flagship products simulations results file format. + +mixing_elbow_file_src = examples.download_file("mixing_elbow.vtk", "result_files/fluent-mixing_elbow_steady-state") + +################################################### +# Define a custom object class +# ================================================= + +# Note that the ``CustomObject`` class must have a way to get the mesh +# and a name or ID. + + +class CustomObject: + def __init__(self): + self.name = "CustomObject" + self.mesh = pv.read(mixing_elbow_file_src) + + def get_mesh(self): + return self.mesh + + def get_field_array_info(self): + return self.mesh.array_names + + def name(self): + return self.name + + +# Create a custom object +custom_vtk = CustomObject() + +###################################### +# Create a ``MeshObjectPlot`` instance +# ==================================== + +mesh_object = MeshObjectPlot(custom_vtk, custom_vtk.get_mesh()) + +# Define the camera position +cpos = ( + (-0.3331763564757694, 0.08802797061044923, -1.055269197114142), + (0.08813476356878325, -0.03975174212669032, -0.012819952697089087), + (0.045604530283921085, 0.9935979348314435, 0.10336039239608838), +) + +###################################### +# Get the available field data arrays +# ==================================== + +field_data_arrays = custom_vtk.get_field_array_info() +print(f"Field data arrays: {field_data_arrays}") + +#################################################################### +# Plot the ``MeshObjectPlot`` instance with mesh object & field data +# ================================================================== + +pv_backend = PyVistaBackend() +pl = Plotter(backend=pv_backend) +pl.plot( + mesh_object, + scalars=field_data_arrays[0], + show_edges=True, + show_scalar_bar=True, +) +pl._backend.pv_interface.scene.camera_position = cpos +pl.show() + + +########################################################################## +# Plot the ``MeshObjectPlot`` instance with mesh object & other field data +# ======================================================================== + +pv_backend = PyVistaBackend() +pl = Plotter(backend=pv_backend) +pl.plot( + mesh_object, + scalars=field_data_arrays[1], + show_edges=True, + show_scalar_bar=True, +) +pl._backend.pv_interface.scene.camera_position = cpos +pl.show() diff --git a/pyproject.toml b/pyproject.toml index 104897de..397a5af8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,6 +45,7 @@ doc = [ "sphinx_design==0.6.0", "sphinx-gallery==0.17.0", "sphinx-jinja==2.0.2", + "ansys-fluent-core==0.22.0", ] [project.urls] From 1592d004be2cab5541ae0d3c2f9ee088550b362e Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Fri, 26 Jul 2024 15:35:42 +0000 Subject: [PATCH 02/10] chore: adding changelog file 112.changed.md --- doc/changelog.d/112.changed.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changelog.d/112.changed.md diff --git a/doc/changelog.d/112.changed.md b/doc/changelog.d/112.changed.md new file mode 100644 index 00000000..23bff419 --- /dev/null +++ b/doc/changelog.d/112.changed.md @@ -0,0 +1 @@ +Added postprocessing visualization example. \ No newline at end of file From 5a23e605040a80f44a105d2395d9e97159c9eba0 Mon Sep 17 00:00:00 2001 From: Abhishek Chitwar <99339845+abhishekchitwar@users.noreply.github.com> Date: Mon, 29 Jul 2024 12:11:01 +0530 Subject: [PATCH 03/10] Update examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py Co-authored-by: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> --- .../using_meshobject_with_field_data.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py b/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py index 1289b2f9..32f0653e 100644 --- a/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py +++ b/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py @@ -23,9 +23,9 @@ """ .. _ref_postprocess_using_meshobjects: -====================================================================== -Use the ``MeshObjectPlot`` class to postprocess Simulation Results -====================================================================== +==================================================================== +Postprocessing simulation results using the ``MeshObjectPlot`` class +==================================================================== The Visualization Interface Tool provides the ``MeshObject`` helper class to relate a custom object. With a custom object, you can take advantage of the full potential of the Visualization Interface Tool. From 9c2ebc1b2d26d656694e73e806b3315f13a4f970 Mon Sep 17 00:00:00 2001 From: Abhishek Chitwar <99339845+abhishekchitwar@users.noreply.github.com> Date: Mon, 29 Jul 2024 12:11:14 +0530 Subject: [PATCH 04/10] Update examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py Co-authored-by: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> --- .../using_meshobject_with_field_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py b/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py index 32f0653e..223a24cd 100644 --- a/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py +++ b/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py @@ -36,7 +36,7 @@ ################################################### # Necessary imports -# ================================================= +# ================= import pyvista as pv From c14858464c14ccfab147f2636af40e8cafc5c5db Mon Sep 17 00:00:00 2001 From: Abhishek Chitwar <99339845+abhishekchitwar@users.noreply.github.com> Date: Mon, 29 Jul 2024 12:12:03 +0530 Subject: [PATCH 05/10] Update examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py Co-authored-by: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> --- .../using_meshobject_with_field_data.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py b/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py index 223a24cd..c869e194 100644 --- a/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py +++ b/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py @@ -39,11 +39,11 @@ # ================= +from ansys.fluent.core import examples import pyvista as pv + from ansys.tools.visualization_interface.backends.pyvista import PyVistaBackend -from ansys.tools.visualization_interface import MeshObjectPlot -from ansys.tools.visualization_interface import Plotter -from ansys.fluent.core import examples +from ansys.tools.visualization_interface import MeshObjectPlot, Plotter ################################################### # Download the VTK file From dc61dd5c2a89bf0e88d0904320a610f7e8874146 Mon Sep 17 00:00:00 2001 From: Abhishek Chitwar <99339845+abhishekchitwar@users.noreply.github.com> Date: Mon, 29 Jul 2024 12:12:14 +0530 Subject: [PATCH 06/10] Update examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py Co-authored-by: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> --- .../using_meshobject_with_field_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py b/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py index c869e194..0324c543 100644 --- a/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py +++ b/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py @@ -47,7 +47,7 @@ ################################################### # Download the VTK file -# ================================================= +# ===================== # A VTK dataset can be produced utilizing the `pydpf `_ # for Ansys Flagship products simulations results file format. From d167ca87180d1308a48c8f4a1f8d8047ac7ddddf Mon Sep 17 00:00:00 2001 From: Abhishek Chitwar <99339845+abhishekchitwar@users.noreply.github.com> Date: Mon, 29 Jul 2024 12:12:27 +0530 Subject: [PATCH 07/10] Update examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py Co-authored-by: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> --- .../using_meshobject_with_field_data.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py b/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py index 0324c543..45c93085 100644 --- a/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py +++ b/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py @@ -48,8 +48,8 @@ ################################################### # Download the VTK file # ===================== - -# A VTK dataset can be produced utilizing the `pydpf `_ +# +# A VTK dataset can be produced utilizing `PyDPF `_ # for Ansys Flagship products simulations results file format. mixing_elbow_file_src = examples.download_file("mixing_elbow.vtk", "result_files/fluent-mixing_elbow_steady-state") From 1b737631226c1c96f48b6f23ebaeb364c1462412 Mon Sep 17 00:00:00 2001 From: Abhishek Chitwar <99339845+abhishekchitwar@users.noreply.github.com> Date: Mon, 29 Jul 2024 12:12:46 +0530 Subject: [PATCH 08/10] Update examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py Co-authored-by: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> --- .../using_meshobject_with_field_data.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py b/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py index 45c93085..ae358d3c 100644 --- a/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py +++ b/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py @@ -56,8 +56,8 @@ ################################################### # Define a custom object class -# ================================================= - +# ============================ +# # Note that the ``CustomObject`` class must have a way to get the mesh # and a name or ID. From 3192fd7ed6a89f11a3e7d869f967c0439eb46afa Mon Sep 17 00:00:00 2001 From: Abhishek Chitwar <99339845+abhishekchitwar@users.noreply.github.com> Date: Mon, 29 Jul 2024 12:13:01 +0530 Subject: [PATCH 09/10] Update examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py Co-authored-by: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> --- .../using_meshobject_with_field_data.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py b/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py index ae358d3c..efce606e 100644 --- a/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py +++ b/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py @@ -100,9 +100,9 @@ def name(self): field_data_arrays = custom_vtk.get_field_array_info() print(f"Field data arrays: {field_data_arrays}") -#################################################################### -# Plot the ``MeshObjectPlot`` instance with mesh object & field data -# ================================================================== +######################################################################## +# Plot the ``MeshObjectPlot`` instance with mesh object & field data (0) +# ====================================================================== pv_backend = PyVistaBackend() pl = Plotter(backend=pv_backend) From 74d652dd531185a31dc67db5c0601b88333c8210 Mon Sep 17 00:00:00 2001 From: Abhishek Chitwar <99339845+abhishekchitwar@users.noreply.github.com> Date: Mon, 29 Jul 2024 12:13:13 +0530 Subject: [PATCH 10/10] Update examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py Co-authored-by: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> --- .../using_meshobject_with_field_data.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py b/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py index efce606e..b507b6bc 100644 --- a/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py +++ b/examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py @@ -116,9 +116,9 @@ def name(self): pl.show() -########################################################################## -# Plot the ``MeshObjectPlot`` instance with mesh object & other field data -# ======================================================================== +############################################################################## +# Plot the ``MeshObjectPlot`` instance with mesh object & other field data (1) +# ============================================================================ pv_backend = PyVistaBackend() pl = Plotter(backend=pv_backend)