.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/00-Different-analysis-types/05-fluid-simulation.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-Different-analysis-types_05-fluid-simulation.py: .. _ref_fluid_example: Postprocess a fluid simulation ============================== This example shows how to load a fluid simulation, explore the model and its available zones, species, and phases, and then extract a result. .. note:: This example requires DPF 7.0 (2024.1.pre0) or later. For more information, see :ref:`compatibility`. .. GENERATED FROM PYTHON SOURCE LINES 37-39 Perform required imports ------------------------ .. GENERATED FROM PYTHON SOURCE LINES 39-42 .. code-block:: Python from ansys.dpf import post from ansys.dpf.post import examples .. GENERATED FROM PYTHON SOURCE LINES 43-45 Load the fluid analysis result ------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 45-53 .. code-block:: Python fluid_example_files = examples.download_fluent_axial_comp() simulation = post.FluidSimulation( cas=fluid_example_files["cas"], dat=fluid_example_files["dat"] ) # Printing the simulation will show most of the available metadata print(simulation) .. rst-class:: sphx-glr-script-out .. code-block:: none Fluid Simulation. Data Sources ------------------------------ DPF DataSources: Result files: result key: cas and path: /opt/hostedtoolcache/Python/3.10.18/x64/lib/python3.10/site-packages/ansys/dpf/core/examples/result_files/fluent-axial_comp/axial_comp-1-01438.cas.h5 result key: cas and path: /opt/hostedtoolcache/Python/3.10.18/x64/lib/python3.10/site-packages/ansys/dpf/core/examples/result_files/fluent-axial_comp/axial_comp-1-01439.cas.h5 result key: cas and path: /opt/hostedtoolcache/Python/3.10.18/x64/lib/python3.10/site-packages/ansys/dpf/core/examples/result_files/fluent-axial_comp/axial_comp-1-01440.cas.h5 Secondary files: path: /opt/hostedtoolcache/Python/3.10.18/x64/lib/python3.10/site-packages/ansys/dpf/core/examples/result_files/fluent-axial_comp/axial_comp-1-01438.dat.h5 path: /opt/hostedtoolcache/Python/3.10.18/x64/lib/python3.10/site-packages/ansys/dpf/core/examples/result_files/fluent-axial_comp/axial_comp-1-01439.dat.h5 path: /opt/hostedtoolcache/Python/3.10.18/x64/lib/python3.10/site-packages/ansys/dpf/core/examples/result_files/fluent-axial_comp/axial_comp-1-01440.dat.h5 DPF Model ------------------------------ Static analysis Unit system: Custom: m, kg, N, s, V, A, K Physics Type: Fluid Available results: - enthalpy: Elemental Enthalpy - mass_flow_rate: Faces Mass Flow Rate - static_pressure: ElementalAndFaces Static Pressure - mean_static_pressure: Elemental Mean Static Pressure - rms_static_pressure: Elemental Rms Static Pressure - surface_heat_rate: Faces Surface Heat Rate - density: ElementalAndFaces Density - face_artificial_wall_flag: Faces Face Artificial Wall Flag - body_force: Elemental Body Force - density_t_1: Elemental Density T 1 - pressure_discontinuity_sensor: Elemental Pressure Discontinuity Sensor - dpm_partition: Elemental Dpm Partition - nucleation_rate_of_water_droplet: Faces Nucleation Rate Of Water Droplet - energy_m1: Elemental Energy M1 - mass_flux_m1: Faces Mass Flux M1 - pressure_m1: Elemental Pressure M1 - radiation_heat_flow_rate: Faces Radiation Heat Flow Rate - temperature_m1: ElementalAndFaces Temperature M1 - temperature_m2: Faces Temperature M2 - x_velocity_m1: ElementalAndFaces X Velocity M1 - y_velocity_m1: ElementalAndFaces Y Velocity M1 - wall_velocity: Faces Wall Velocity - original_wall_velocity: Faces Original Wall Velocity - z_velocity_m1: ElementalAndFaces Z Velocity M1 - wall_shear_stress: Faces Wall Shear Stress - temperature: ElementalAndFaces Temperature - mean_temperature: ElementalAndFaces Mean Temperature - rms_temperature: Elemental Rms Temperature - velocity: ElementalAndFaces Velocity - mean_velocity: Elemental Mean Velocity - rms_velocity: Elemental Rms Velocity Available qualifier labels: - phase: phase-1 (1) - zone: default-interior:0 (2), rotor-hub (3), rotor-shroud (4), rotor-inlet (5), rotor-interface (6), rotor-blade-1 (7), rotor-blade-2 (8), rotor-per-1-shadow (9), rotor-per-1 (10), rotor-per-2-shadow (11), rotor-per-2 (12), fluid-rotor (13), default-interior (15), stator-hub (16), stator-shroud (17), stator-interface (18), stator-outlet (19), stator-blade-1 (20), stator-blade-2 (21), stator-blade-3 (22), stator-blade-4 (23), stator-per-2 (24), stator-per-2-shadow (25), stator-per-1 (26), stator-per-1-shadow (27), fluid-stator (28) ------------------------------ DPF Meshed Region: 16660 nodes 13856 elements 44242 faces Unit: m With solid (3D) elements ------------------------------ DPF Time/Freq Support: Number of sets: 1 Cumulative Frequency () LoadStep Substep 1 0.000000 1 1 .. GENERATED FROM PYTHON SOURCE LINES 54-57 Explore available metadata -------------------------- Check the available cell and face zones. .. GENERATED FROM PYTHON SOURCE LINES 57-60 .. code-block:: Python print(simulation.cell_zones) print(simulation.face_zones) .. rst-class:: sphx-glr-script-out .. code-block:: none {13: 'fluid-rotor', 28: 'fluid-stator'} {2: 'default-interior:0', 3: 'rotor-hub', 4: 'rotor-shroud', 5: 'rotor-inlet', 6: 'rotor-interface', 7: 'rotor-blade-1', 8: 'rotor-blade-2', 9: 'rotor-per-1-shadow', 10: 'rotor-per-1', 11: 'rotor-per-2-shadow', 12: 'rotor-per-2', 15: 'default-interior', 16: 'stator-hub', 17: 'stator-shroud', 18: 'stator-interface', 19: 'stator-outlet', 20: 'stator-blade-1', 21: 'stator-blade-2', 22: 'stator-blade-3', 23: 'stator-blade-4', 24: 'stator-per-2', 25: 'stator-per-2-shadow', 26: 'stator-per-1', 27: 'stator-per-1-shadow'} .. GENERATED FROM PYTHON SOURCE LINES 61-64 The mesh metadata is available separately from the mesh as accessing the mesh means loading it. Use the ``mesh_info`` property to explore the mesh structure to define queries. .. GENERATED FROM PYTHON SOURCE LINES 64-66 .. code-block:: Python print(simulation.mesh_info) .. rst-class:: sphx-glr-script-out .. code-block:: none Fluid mesh metadata ------------------- Number of nodes: 16660 Number of faces: 45391 Number of cells: 13856 Cell zones: {13: 'fluid-rotor', 28: 'fluid-stator'} Face zones: {2: 'default-interior:0', 3: 'rotor-hub', 4: 'rotor-shroud', 5: 'rotor-inlet', 6: 'rotor-interface', 7: 'rotor-blade-1', 8: 'rotor-blade-2', 9: 'rotor-per-1-shadow', 10: 'rotor-per-1', 11: 'rotor-per-2-shadow', 12: 'rotor-per-2', 15: 'default-interior', 16: 'stator-hub', 17: 'stator-shroud', 18: 'stator-interface', 19: 'stator-outlet', 20: 'stator-blade-1', 21: 'stator-blade-2', 22: 'stator-blade-3', 23: 'stator-blade-4', 24: 'stator-per-2', 25: 'stator-per-2-shadow', 26: 'stator-per-1', 27: 'stator-per-1-shadow'} Cell to face zones: {13: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], 28: [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27]} .. GENERATED FROM PYTHON SOURCE LINES 67-69 Check available species ~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 69-71 .. code-block:: Python print(simulation.species) .. rst-class:: sphx-glr-script-out .. code-block:: none 0 species available {} .. GENERATED FROM PYTHON SOURCE LINES 72-74 Check available phases ~~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 74-76 .. code-block:: Python print(simulation.phases) .. rst-class:: sphx-glr-script-out .. code-block:: none 1 phases available {Phase, } .. GENERATED FROM PYTHON SOURCE LINES 77-79 Check metadata on available results ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 79-81 .. code-block:: Python print(simulation.result_info) .. rst-class:: sphx-glr-script-out .. code-block:: none Static analysis Unit system: Custom: m, kg, N, s, V, A, K Physics Type: Fluid Available results: - enthalpy: Elemental Enthalpy - mass_flow_rate: Faces Mass Flow Rate - static_pressure: ElementalAndFaces Static Pressure - mean_static_pressure: Elemental Mean Static Pressure - rms_static_pressure: Elemental Rms Static Pressure - surface_heat_rate: Faces Surface Heat Rate - density: ElementalAndFaces Density - face_artificial_wall_flag: Faces Face Artificial Wall Flag - body_force: Elemental Body Force - density_t_1: Elemental Density T 1 - pressure_discontinuity_sensor: Elemental Pressure Discontinuity Sensor - dpm_partition: Elemental Dpm Partition - nucleation_rate_of_water_droplet: Faces Nucleation Rate Of Water Droplet - energy_m1: Elemental Energy M1 - mass_flux_m1: Faces Mass Flux M1 - pressure_m1: Elemental Pressure M1 - radiation_heat_flow_rate: Faces Radiation Heat Flow Rate - temperature_m1: ElementalAndFaces Temperature M1 - temperature_m2: Faces Temperature M2 - x_velocity_m1: ElementalAndFaces X Velocity M1 - y_velocity_m1: ElementalAndFaces Y Velocity M1 - wall_velocity: Faces Wall Velocity - original_wall_velocity: Faces Original Wall Velocity - z_velocity_m1: ElementalAndFaces Z Velocity M1 - wall_shear_stress: Faces Wall Shear Stress - temperature: ElementalAndFaces Temperature - mean_temperature: ElementalAndFaces Mean Temperature - rms_temperature: Elemental Rms Temperature - velocity: ElementalAndFaces Velocity - mean_velocity: Elemental Mean Velocity - rms_velocity: Elemental Rms Velocity Available qualifier labels: - phase: phase-1 (1) - zone: default-interior:0 (2), rotor-hub (3), rotor-shroud (4), rotor-inlet (5), rotor-interface (6), rotor-blade-1 (7), rotor-blade-2 (8), rotor-per-1-shadow (9), rotor-per-1 (10), rotor-per-2-shadow (11), rotor-per-2 (12), fluid-rotor (13), default-interior (15), stator-hub (16), stator-shroud (17), stator-interface (18), stator-outlet (19), stator-blade-1 (20), stator-blade-2 (21), stator-blade-3 (22), stator-blade-4 (23), stator-per-2 (24), stator-per-2-shadow (25), stator-per-1 (26), stator-per-1-shadow (27), fluid-stator (28) .. GENERATED FROM PYTHON SOURCE LINES 82-86 Extract a result ---------------- Print a specific result to get more information on available qualifiers (such as zones and phases). .. GENERATED FROM PYTHON SOURCE LINES 86-90 .. code-block:: Python print(simulation.result_info["enthalpy"]) # Or use an index # print(simulation.result_info[0]) .. rst-class:: sphx-glr-script-out .. code-block:: none DPF Result ---------- enthalpy Operator name: "H_S" Number of components: 1 Dimensionality: scalar Homogeneity: specific_energy Units: J/kg Location: Elemental Available qualifier labels: - zone: fluid-rotor (13), fluid-stator (28) - phase: phase-1 (1) Available qualifier combinations: {'zone': 13, 'phase': 1} {'zone': 28, 'phase': 1} .. GENERATED FROM PYTHON SOURCE LINES 91-93 Extract this result as a dataframe ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 93-97 .. code-block:: Python enthalpy = simulation.enthalpy() print(enthalpy) # Not specifying any qualifier returns a unique column of data .. rst-class:: sphx-glr-script-out .. code-block:: none results H_S (J/kg) set_ids 1 cell_ids 1 2.7790e+05 2 2.7781e+05 3 2.7795e+05 4 2.7712e+05 5 2.7720e+05 6 2.7769e+05 ... ... .. GENERATED FROM PYTHON SOURCE LINES 98-100 Plot dataframe ~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 100-102 .. code-block:: Python enthalpy.plot() .. image-sg:: /examples/00-Different-analysis-types/images/sphx_glr_05-fluid-simulation_001.png :alt: 05 fluid simulation :srcset: /examples/00-Different-analysis-types/images/sphx_glr_05-fluid-simulation_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none (None, ) .. GENERATED FROM PYTHON SOURCE LINES 103-109 Use qualifiers for result to filter or separate data ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can use available qualifiers for the result in the extraction request to filter or separate data. This code outputs a different column for each available zone for the result. .. GENERATED FROM PYTHON SOURCE LINES 109-117 .. code-block:: Python print(simulation.enthalpy(zone_ids=[13, 28])) # # This code extracts only the data for the fluid-stator zone. print(simulation.enthalpy(zone_ids=[28])) # # You can apply the same logic to any available qualifier found in the ``AvailableResult`` # description under 'Available qualifier labels'. .. rst-class:: sphx-glr-script-out .. code-block:: none results H_S (J/kg) set_ids 1 zone fluid-rotor (13) fluid-stator (28) cell_ids 1 2.7790e+05 2 2.7781e+05 3 2.7795e+05 4 2.7712e+05 5 2.7720e+05 6 2.7769e+05 ... ... ... results H_S (J/kg) set_ids 1 zone fluid-stator (28) cell_ids 6081 3.0593e+05 6082 3.0567e+05 6083 3.0510e+05 6084 3.0407e+05 6085 3.0543e+05 6086 3.0252e+05 ... ... .. GENERATED FROM PYTHON SOURCE LINES 118-121 The result extraction request can also contain selection arguments. Because the enthalpy result is being defined on cells, you can request data for specific cells using their IDs: .. GENERATED FROM PYTHON SOURCE LINES 121-123 .. code-block:: Python print(simulation.enthalpy(cell_ids=[1, 2])) .. rst-class:: sphx-glr-script-out .. code-block:: none results H_S (J/kg) set_ids 1 cell_ids 1 2.7790e+05 2 2.7781e+05 .. GENERATED FROM PYTHON SOURCE LINES 124-126 For an example showing how to create and manipulate a DPF dataframe, see :ref:`ref_dataframe_example`. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 3.281 seconds) .. _sphx_glr_download_examples_00-Different-analysis-types_05-fluid-simulation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 05-fluid-simulation.ipynb <05-fluid-simulation.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 05-fluid-simulation.py <05-fluid-simulation.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 05-fluid-simulation.zip <05-fluid-simulation.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_