.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/00-postprocessing/updated_exhaust_manifold_example.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_00-postprocessing_updated_exhaust_manifold_example.py: .. _ref_updated_exhaust_manifold_example: Enhanced Postprocessing with PyVista and Matplotlib --------------------------------------------------- This updated example demonstrates postprocessing capabilities in PyFluent using an object-oriented approach, providing a more user-friendly interface and improved flexibility. The 3D model used in this example is an exhaust manifold, where high-temperature turbulent flows are analyzed in a conjugate heat transfer scenario. Key Improvements: Object-Oriented Design: The code has been modularized into classes and methods, enhancing maintainability and reusability. Interactive User Interface: The user interface now allows seamless interaction, enabling users to control and customize postprocessing parameters. Enhanced Plot Interaction: Users have greater freedom to interact with the plots, such as adding and super-imposing multiple plots, and toggling data views, enhancing the visualization experience. This example utilizes PyVista for 3D visualization and Matplotlib for 2D data plotting. The new design provides a streamlined workflow for exploring and analyzing the temperature and flow characteristics in the exhaust manifold. .. GENERATED FROM PYTHON SOURCE LINES 30-33 Perform required imports ~~~~~~~~~~~~~~~~~~~~~~~~ Perform required imports and set the configuration. .. GENERATED FROM PYTHON SOURCE LINES 33-54 .. code-block:: Python import ansys.fluent.core as pyfluent from ansys.fluent.core import examples from ansys.fluent.visualization import ( Contour, GraphicsWindow, Mesh, Monitor, Pathline, PlotterWindow, Surface, Vector, XYPlot, set_config, ) pyfluent.CONTAINER_MOUNT_PATH = pyfluent.EXAMPLES_PATH set_config(blocking=True, set_view_on_display="isometric") .. GENERATED FROM PYTHON SOURCE LINES 55-60 Download files and launch Fluent ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Download the case and data files and launch Fluent as a service in solver mode with double precision and two processors. Read in the case and data files. .. GENERATED FROM PYTHON SOURCE LINES 60-80 .. code-block:: Python import_case = examples.download_file( file_name="exhaust_system.cas.h5", directory="pyfluent/exhaust_system" ) import_data = examples.download_file( file_name="exhaust_system.dat.h5", directory="pyfluent/exhaust_system" ) solver_session = pyfluent.launch_fluent( precision="double", processor_count=2, start_transcript=False, mode="solver", ui_mode="gui", ) solver_session.settings.file.read_case(file_name=import_case) solver_session.settings.file.read_data(file_name=import_data) .. GENERATED FROM PYTHON SOURCE LINES 81-84 Create graphics object for mesh display ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create a graphics object for the mesh display. .. GENERATED FROM PYTHON SOURCE LINES 84-105 .. code-block:: Python mesh_surfaces_list = [ "in1", "in2", "in3", "out1", "solid_up:1", "solid_up:1:830", "solid_up:1:830-shadow", ] mesh1 = Mesh(solver=solver_session, show_edges=True, surfaces=mesh_surfaces_list) p1 = GraphicsWindow(grid=(1, 2)) p1.add_graphics(mesh1, position=(0, 0)) mesh2 = Mesh(solver=solver_session, surfaces=mesh_surfaces_list) mesh2.show_edges = False p1.add_graphics(mesh2, position=(0, 1)) p1.show() .. image-sg:: /examples/00-postprocessing/images/sphx_glr_updated_exhaust_manifold_example_001.png :alt: updated exhaust manifold example :srcset: /examples/00-postprocessing/images/sphx_glr_updated_exhaust_manifold_example_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 106-109 Create plane-surface XY plane ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create a plane-surface XY plane. .. GENERATED FROM PYTHON SOURCE LINES 109-118 .. code-block:: Python surf_xy_plane = Surface(solver=solver_session) surf_xy_plane.definition.type = "plane-surface" surf_xy_plane.definition.plane_surface.creation_method = "xy-plane" plane_surface_xy = surf_xy_plane.definition.plane_surface.xy_plane plane_surface_xy.z = -0.0441921 p2 = GraphicsWindow(grid=(1, 3)) p2.add_graphics(surf_xy_plane, position=(0, 0)) .. GENERATED FROM PYTHON SOURCE LINES 119-122 Create plane-surface YZ plane ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create a plane-surface YZ plane. .. GENERATED FROM PYTHON SOURCE LINES 122-130 .. code-block:: Python surf_yz_plane = Surface(solver=solver_session) surf_yz_plane.definition.type = "plane-surface" surf_yz_plane.definition.plane_surface.creation_method = "yz-plane" plane_surface_yz = surf_yz_plane.definition.plane_surface.yz_plane plane_surface_yz.x = -0.174628 p2.add_graphics(surf_yz_plane, position=(0, 1)) .. GENERATED FROM PYTHON SOURCE LINES 131-134 Create plane-surface ZX plane ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create a plane-surface ZX plane. .. GENERATED FROM PYTHON SOURCE LINES 134-143 .. code-block:: Python surf_zx_plane = Surface(solver=solver_session) surf_zx_plane.definition.type = "plane-surface" surf_zx_plane.definition.plane_surface.creation_method = "zx-plane" plane_surface_zx = surf_zx_plane.definition.plane_surface.zx_plane plane_surface_zx.y = -0.0627297 p2.add_graphics(surf_zx_plane, position=(0, 2)) p2.show() .. image-sg:: /examples/00-postprocessing/images/sphx_glr_updated_exhaust_manifold_example_002.png :alt: updated exhaust manifold example :srcset: /examples/00-postprocessing/images/sphx_glr_updated_exhaust_manifold_example_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 144-147 Create iso-surface on outlet plane ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create an iso-surface on the outlet plane. .. GENERATED FROM PYTHON SOURCE LINES 147-156 .. code-block:: Python surf_outlet_plane = Surface(solver=solver_session) surf_outlet_plane.definition.type = "iso-surface" iso_surf1 = surf_outlet_plane.definition.iso_surface iso_surf1.field = "y-coordinate" iso_surf1.iso_value = -0.125017 p3 = GraphicsWindow(grid=(2, 1)) p3.add_graphics(surf_outlet_plane, position=(0, 0)) .. GENERATED FROM PYTHON SOURCE LINES 157-160 Create iso-surface on mid-plane ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create an iso-surface on the mid-plane. .. GENERATED FROM PYTHON SOURCE LINES 160-169 .. code-block:: Python surf_mid_plane_x = Surface(solver=solver_session) surf_mid_plane_x.definition.type = "iso-surface" iso_surf2 = surf_mid_plane_x.definition.iso_surface iso_surf2.field = "x-coordinate" iso_surf2.iso_value = -0.174 p3.add_graphics(surf_mid_plane_x, position=(1, 0)) p3.show() .. image-sg:: /examples/00-postprocessing/images/sphx_glr_updated_exhaust_manifold_example_003.png :alt: updated exhaust manifold example :srcset: /examples/00-postprocessing/images/sphx_glr_updated_exhaust_manifold_example_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 170-173 Create iso-surface using velocity magnitude ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create an iso-surface using the velocity magnitude. .. GENERATED FROM PYTHON SOURCE LINES 173-183 .. code-block:: Python surf_vel_contour = Surface(solver=solver_session) surf_vel_contour.definition.type = "iso-surface" iso_surf3 = surf_vel_contour.definition.iso_surface iso_surf3.field = "velocity-magnitude" iso_surf3.rendering = "contour" iso_surf3.iso_value = 0.0 p4 = GraphicsWindow(grid=(2, 2)) p4.add_graphics(surf_vel_contour, position=(0, 0)) .. GENERATED FROM PYTHON SOURCE LINES 184-187 Create temperature contour on mid-plane and outlet ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create a temperature contour on the mid-plane and the outlet. .. GENERATED FROM PYTHON SOURCE LINES 187-193 .. code-block:: Python temperature_contour = Contour(solver=solver_session) temperature_contour.field = "temperature" temperature_contour.surfaces = [surf_mid_plane_x.name, surf_outlet_plane.name] p4.add_graphics(temperature_contour, position=(0, 1)) .. GENERATED FROM PYTHON SOURCE LINES 194-197 Create contour plot of temperature on manifold ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create a contour plot of the temperature on the manifold. .. GENERATED FROM PYTHON SOURCE LINES 197-213 .. code-block:: Python cont_surfaces_list = [ "in1", "in2", "in3", "out1", "solid_up:1", "solid_up:1:830", ] temperature_contour_manifold = Contour( solver=solver_session, field="temperature", surfaces=cont_surfaces_list, ) p4.add_graphics(temperature_contour_manifold, position=(1, 0)) .. GENERATED FROM PYTHON SOURCE LINES 214-217 Create vector ~~~~~~~~~~~~~ Create a vector on a predefined surface. .. GENERATED FROM PYTHON SOURCE LINES 217-227 .. code-block:: Python velocity_vector = Vector( solver=solver_session, field="pressure", surfaces=["solid_up:1:830"], scale=2, ) p4.add_graphics(velocity_vector, position=(1, 1)) p4.show() .. image-sg:: /examples/00-postprocessing/images/sphx_glr_updated_exhaust_manifold_example_004.png :alt: updated exhaust manifold example :srcset: /examples/00-postprocessing/images/sphx_glr_updated_exhaust_manifold_example_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 228-231 Create Pathlines ~~~~~~~~~~~~~~~~ Create a pathlines on a predefined surface. .. GENERATED FROM PYTHON SOURCE LINES 231-245 .. code-block:: Python pathlines = Pathline(solver=solver_session) pathlines.field = "velocity-magnitude" pathlines.surfaces = ["inlet", "inlet1", "inlet2"] p5 = GraphicsWindow() p5.add_graphics(pathlines) p5.show() p6 = GraphicsWindow() p6.add_graphics(mesh2, opacity=0.05) p6.add_graphics(velocity_vector) p6.show() .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/00-postprocessing/images/sphx_glr_updated_exhaust_manifold_example_005.png :alt: updated exhaust manifold example :srcset: /examples/00-postprocessing/images/sphx_glr_updated_exhaust_manifold_example_005.png :class: sphx-glr-multi-img * .. image-sg:: /examples/00-postprocessing/images/sphx_glr_updated_exhaust_manifold_example_006.png :alt: updated exhaust manifold example :srcset: /examples/00-postprocessing/images/sphx_glr_updated_exhaust_manifold_example_006.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 246-249 Create XY plot ~~~~~~~~~~~~~~ Create the default XY plot. .. GENERATED FROM PYTHON SOURCE LINES 249-258 .. code-block:: Python xy_plot = XYPlot( solver=solver_session, surfaces=["outlet"], y_axis_function="temperature", ) p7 = PlotterWindow(grid=(2, 2)) p7.add_plots(xy_plot, position=(0, 0)) .. GENERATED FROM PYTHON SOURCE LINES 259-262 Create residual plot ~~~~~~~~~~~~~~~~~~~~~~ Create and display the residual plot. .. GENERATED FROM PYTHON SOURCE LINES 262-267 .. code-block:: Python residual = Monitor(solver=solver_session) residual.monitor_set_name = "residual" p7.add_plots(residual, position=(0, 1)) .. GENERATED FROM PYTHON SOURCE LINES 268-271 Solve and plot solution monitors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Solve and plot solution monitors. .. GENERATED FROM PYTHON SOURCE LINES 271-283 .. code-block:: Python solver_session.solution.initialization.hybrid_initialize() solver_session.solution.run_calculation.iterate(iter_count=50) mass_bal_rplot = Monitor(solver=solver_session) mass_bal_rplot.monitor_set_name = "mass-bal-rplot" p7.add_plots(mass_bal_rplot, position=(1, 0)) point_vel_rplot = Monitor(solver=solver_session, monitor_set_name="point-vel-rplot") p7.add_plots(point_vel_rplot, position=(1, 1)) p7.show() .. image-sg:: /examples/00-postprocessing/images/sphx_glr_updated_exhaust_manifold_example_007.png :alt: XY Plot, residual, mass-bal-rplot, point-vel-rplot :srcset: /examples/00-postprocessing/images/sphx_glr_updated_exhaust_manifold_example_007.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 284-287 Close Fluent ~~~~~~~~~~~~ Close Fluent. .. GENERATED FROM PYTHON SOURCE LINES 287-289 .. code-block:: Python solver_session.exit() .. rst-class:: sphx-glr-timing **Total running time of the script:** (2 minutes 16.303 seconds) .. _sphx_glr_download_examples_00-postprocessing_updated_exhaust_manifold_example.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: updated_exhaust_manifold_example.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: updated_exhaust_manifold_example.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_