.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/01-advanced-pyansys-examples/using_meshobject_with_field_data.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_01-advanced-pyansys-examples_using_meshobject_with_field_data.py: .. _ref_postprocess_using_meshobjects: ==================================================================== 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. This example shows how to use the ``MeshObjectPlot`` class to plot your custom objects with scalar data on mesh. .. GENERATED FROM PYTHON SOURCE LINES 38-40 Necessary imports ================= .. GENERATED FROM PYTHON SOURCE LINES 40-48 .. code-block:: Python 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, Plotter .. GENERATED FROM PYTHON SOURCE LINES 49-54 Download the VTK file ===================== A VTK dataset can be produced utilizing `PyDPF `_ for Ansys Flagship products simulations results file format. .. GENERATED FROM PYTHON SOURCE LINES 54-57 .. code-block:: Python mixing_elbow_file_src = examples.download_file("mixing_elbow.vtk", "result_files/fluent-mixing_elbow_steady-state") .. GENERATED FROM PYTHON SOURCE LINES 58-63 Define a custom object class ============================ Note that the ``CustomObject`` class must have a way to get the mesh and a name or ID. .. GENERATED FROM PYTHON SOURCE LINES 63-83 .. code-block:: Python 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() .. GENERATED FROM PYTHON SOURCE LINES 84-86 Create a ``MeshObjectPlot`` instance ==================================== .. GENERATED FROM PYTHON SOURCE LINES 86-96 .. code-block:: Python 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), ) .. GENERATED FROM PYTHON SOURCE LINES 97-99 Get the available field data arrays ==================================== .. GENERATED FROM PYTHON SOURCE LINES 99-103 .. code-block:: Python field_data_arrays = custom_vtk.get_field_array_info() print(f"Field data arrays: {field_data_arrays}") .. rst-class:: sphx-glr-script-out .. code-block:: none Field data arrays: ["Velocity {'time': 1, 'zone': 87}", "Temperature {'time': 1, 'zone': 87}"] .. GENERATED FROM PYTHON SOURCE LINES 104-106 Plot the ``MeshObjectPlot`` instance with mesh object & field data (0) ====================================================================== .. GENERATED FROM PYTHON SOURCE LINES 106-119 .. code-block:: Python 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() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/01-advanced-pyansys-examples/images/sphx_glr_using_meshobject_with_field_data_001.png :alt: using meshobject with field data :srcset: /examples/01-advanced-pyansys-examples/images/sphx_glr_using_meshobject_with_field_data_001.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/ansys-tools-visualization-interface/ansys-tools-visualization-interface/doc/source/examples/01-advanced-pyansys-examples/images/sphx_glr_using_meshobject_with_field_data_001.vtksz .. GENERATED FROM PYTHON SOURCE LINES 120-122 Plot the ``MeshObjectPlot`` instance with mesh object & other field data (1) ============================================================================ .. GENERATED FROM PYTHON SOURCE LINES 122-133 .. code-block:: Python 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() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/01-advanced-pyansys-examples/images/sphx_glr_using_meshobject_with_field_data_002.png :alt: using meshobject with field data :srcset: /examples/01-advanced-pyansys-examples/images/sphx_glr_using_meshobject_with_field_data_002.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/ansys-tools-visualization-interface/ansys-tools-visualization-interface/doc/source/examples/01-advanced-pyansys-examples/images/sphx_glr_using_meshobject_with_field_data_002.vtksz .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 6.318 seconds) .. _sphx_glr_download_examples_01-advanced-pyansys-examples_using_meshobject_with_field_data.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: using_meshobject_with_field_data.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: using_meshobject_with_field_data.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: using_meshobject_with_field_data.zip `