.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/04-Fluid-Examples/00-explore-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_04-Fluid-Examples_00-explore-fluid-simulation.py: .. _ref_fluid_example_extractions: Exctarct fluid simulation results ================================= This example shows how to load a fluid simulation for a heating coil that has been simulated with Ansys CFX, explore the metadata available, and use the result extraction capabilities. .. note:: This example requires DPF 7.0 (2024.1.pre0) or later. For more information, see :ref:`compatibility`. .. GENERATED FROM PYTHON SOURCE LINES 37-41 Perform required imports ------------------------ Perform required imports. This example uses a supplied file that you can get using the ``examples`` module. .. GENERATED FROM PYTHON SOURCE LINES 41-44 .. code-block:: Python from ansys.dpf import post from ansys.dpf.post import examples .. GENERATED FROM PYTHON SOURCE LINES 45-47 Load fluid analysis result -------------------------- .. GENERATED FROM PYTHON SOURCE LINES 47-55 .. code-block:: Python fluid_example_files = examples.download_cfx_heating_coil() simulation = post.FluidSimulation( cas=fluid_example_files["cas"], dat=fluid_example_files["dat"] ) # Print the simulation TO see 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/cfx-heating_coil/def.cas.cff Secondary files: path: /opt/hostedtoolcache/Python/3.10.18/x64/lib/python3.10/site-packages/ansys/dpf/core/examples/result_files/cfx-heating_coil/def.dat.cff DPF Model ------------------------------ Static analysis Unit system: Custom: m, kg, N, s, V, A, K Physics Type: Fluid Available results: - specific_heat: Nodal Specific Heat - epsilon: Nodal Epsilon - aspect_ratio: Nodal Aspect Ratio - static_enthalpy_beta: Nodal Static Enthalpy Beta - velocity_u_beta: Nodal Velocity U Beta - velocity_v_beta: Nodal Velocity V Beta - velocity_w_beta: Nodal Velocity W Beta - courant_number: Nodal Courant Number - volume_of_finite_volumes: Nodal Volume Of Finite Volumes - volume_porosity: Nodal Volume Porosity - static_enthalpy_gradient: Nodal Static Enthalpy Gradient - pressure_gradient: Nodal Pressure Gradient - velocity_u_gradient: Nodal Velocity U Gradient - velocity_v_gradient: Nodal Velocity V Gradient - velocity_w_gradient: Nodal Velocity W Gradient - mesh_expansion_factor: Nodal Mesh Expansion Factor - orthogonality_angle: Nodal Orthogonality Angle - absolute_pressure: Nodal Absolute Pressure - specific_heat_capacity_at_constant_volume: Nodal Specific Heat Capacity At Constant Volume - specific_volume: Nodal Specific Volume - shear_strain_rate: Nodal Shear Strain Rate - turbulence_eddy_frequency: Nodal Turbulence Eddy Frequency - enthalpy: Nodal Enthalpy - turbulent_kinetic_energy: Nodal Turbulent Kinetic Energy - thermal_conductivity: Nodal Thermal Conductivity - dynamic_viscosity: Nodal Dynamic Viscosity - turbulent_viscosity: Nodal Turbulent Viscosity - static_pressure: Nodal Static Pressure - total_pressure: Nodal Total Pressure - density: Nodal Density - entropy: Nodal Entropy - temperature: Nodal Temperature - total_temperature: Nodal Total Temperature - velocity: Nodal Velocity Available qualifier labels: - phase: (1), Water at 25 C (2), Copper (3) - zone: outflow (9), Default (10), inflow (11), Solid 2.8 1 (12), Solid 2.7 1 (13), Solid 2.6 1 (14), Solid 2.5 1 (15), Solid 2.4 1 (16), Solid 2.3 1 (17), Default 1 (1), Default (18), Solid 2.3 (19), Solid 2.4 (20), Solid 2.5 (21), Solid 2.6 (22), Solid 2.7 (23), Solid 2.8 (24), heater (2) ------------------------------ DPF Meshed Region: 25456 nodes 74882 elements 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 56-59 Explore available metadata -------------------------- Check the available cell and face zones. .. GENERATED FROM PYTHON SOURCE LINES 59-62 .. code-block:: Python print(simulation.cell_zones) print(simulation.face_zones) .. rst-class:: sphx-glr-script-out .. code-block:: none {1: 'Default 1', 2: 'heater'} {9: 'outflow', 10: 'Default', 11: 'inflow', 12: 'Solid 2.8 1', 13: 'Solid 2.7 1', 14: 'Solid 2.6 1', 15: 'Solid 2.5 1', 16: 'Solid 2.4 1', 17: 'Solid 2.3 1', 18: 'Default', 19: 'Solid 2.3', 20: 'Solid 2.4', 21: 'Solid 2.5', 22: 'Solid 2.6', 23: 'Solid 2.7', 24: 'Solid 2.8'} .. GENERATED FROM PYTHON SOURCE LINES 63-66 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 66-68 .. code-block:: Python print(simulation.mesh_info) .. rst-class:: sphx-glr-script-out .. code-block:: none Fluid mesh metadata ------------------- Number of nodes: 25456 Number of faces: 11780 Number of cells: 74882 Cell zones: {1: 'Default 1', 2: 'heater'} Face zones: {9: 'outflow', 10: 'Default', 11: 'inflow', 12: 'Solid 2.8 1', 13: 'Solid 2.7 1', 14: 'Solid 2.6 1', 15: 'Solid 2.5 1', 16: 'Solid 2.4 1', 17: 'Solid 2.3 1', 18: 'Default', 19: 'Solid 2.3', 20: 'Solid 2.4', 21: 'Solid 2.5', 22: 'Solid 2.6', 23: 'Solid 2.7', 24: 'Solid 2.8'} Cell to face zones: {1: [9, 10, 11, 12, 13, 14, 15, 16, 17], 2: [18, 19, 20, 21, 22, 23, 24]} .. GENERATED FROM PYTHON SOURCE LINES 69-70 Check available species. .. GENERATED FROM PYTHON SOURCE LINES 70-72 .. code-block:: Python print(simulation.species) .. rst-class:: sphx-glr-script-out .. code-block:: none 0 species available {} .. GENERATED FROM PYTHON SOURCE LINES 73-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 3 phases available {Phase', id=1>, Phase, Phase, } .. GENERATED FROM PYTHON SOURCE LINES 77-78 Check the metadata on available results .. GENERATED FROM PYTHON SOURCE LINES 78-80 .. 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: - specific_heat: Nodal Specific Heat - epsilon: Nodal Epsilon - aspect_ratio: Nodal Aspect Ratio - static_enthalpy_beta: Nodal Static Enthalpy Beta - velocity_u_beta: Nodal Velocity U Beta - velocity_v_beta: Nodal Velocity V Beta - velocity_w_beta: Nodal Velocity W Beta - courant_number: Nodal Courant Number - volume_of_finite_volumes: Nodal Volume Of Finite Volumes - volume_porosity: Nodal Volume Porosity - static_enthalpy_gradient: Nodal Static Enthalpy Gradient - pressure_gradient: Nodal Pressure Gradient - velocity_u_gradient: Nodal Velocity U Gradient - velocity_v_gradient: Nodal Velocity V Gradient - velocity_w_gradient: Nodal Velocity W Gradient - mesh_expansion_factor: Nodal Mesh Expansion Factor - orthogonality_angle: Nodal Orthogonality Angle - absolute_pressure: Nodal Absolute Pressure - specific_heat_capacity_at_constant_volume: Nodal Specific Heat Capacity At Constant Volume - specific_volume: Nodal Specific Volume - shear_strain_rate: Nodal Shear Strain Rate - turbulence_eddy_frequency: Nodal Turbulence Eddy Frequency - enthalpy: Nodal Enthalpy - turbulent_kinetic_energy: Nodal Turbulent Kinetic Energy - thermal_conductivity: Nodal Thermal Conductivity - dynamic_viscosity: Nodal Dynamic Viscosity - turbulent_viscosity: Nodal Turbulent Viscosity - static_pressure: Nodal Static Pressure - total_pressure: Nodal Total Pressure - density: Nodal Density - entropy: Nodal Entropy - temperature: Nodal Temperature - total_temperature: Nodal Total Temperature - velocity: Nodal Velocity Available qualifier labels: - phase: (1), Water at 25 C (2), Copper (3) - zone: outflow (9), Default (10), inflow (11), Solid 2.8 1 (12), Solid 2.7 1 (13), Solid 2.6 1 (14), Solid 2.5 1 (15), Solid 2.4 1 (16), Solid 2.3 1 (17), Default 1 (1), Default (18), Solid 2.3 (19), Solid 2.4 (20), Solid 2.5 (21), Solid 2.6 (22), Solid 2.7 (23), Solid 2.8 (24), heater (2) .. GENERATED FROM PYTHON SOURCE LINES 81-84 Extract a result ---------------- Print information about a specific available result. .. GENERATED FROM PYTHON SOURCE LINES 84-89 .. code-block:: Python print(simulation.result_info["temperature"]) # Printing information using an index. print(simulation.result_info[12]) .. rst-class:: sphx-glr-script-out .. code-block:: none DPF Result ---------- temperature Operator name: "TEMP" Number of components: 1 Dimensionality: scalar Homogeneity: temperature Units: K Location: Nodal Available qualifier labels: - zone: Default 1 (1), outflow (9), Default (10), inflow (11), Solid 2.8 1 (12), Solid 2.7 1 (13), Solid 2.6 1 (14), Solid 2.5 1 (15), Solid 2.4 1 (16), Solid 2.3 1 (17), heater (2), Default (18), Solid 2.3 (19), Solid 2.4 (20), Solid 2.5 (21), Solid 2.6 (22), Solid 2.7 (23), Solid 2.8 (24) - phase: Water at 25 C (2), Copper (3) Available qualifier combinations: {'zone': 1, 'phase': 2} {'zone': 9, 'phase': 2} {'zone': 10, 'phase': 2} {'zone': 11, 'phase': 2} {'zone': 12, 'phase': 2} {'zone': 13, 'phase': 2} {'zone': 14, 'phase': 2} {'zone': 15, 'phase': 2} {'zone': 16, 'phase': 2} {'zone': 17, 'phase': 2} {'zone': 2, 'phase': 3} {'zone': 18, 'phase': 3} {'zone': 19, 'phase': 3} {'zone': 20, 'phase': 3} {'zone': 21, 'phase': 3} {'zone': 22, 'phase': 3} {'zone': 23, 'phase': 3} {'zone': 24, 'phase': 3} DPF Result ---------- velocity_u_gradient Operator name: "G_GRADIENT_VEL_1" Number of components: 3 Dimensionality: vector Homogeneity: frequency Units: Hz Location: Nodal Available qualifier labels: - zone: Default 1 (1), outflow (9), Default (10), inflow (11), Solid 2.8 1 (12), Solid 2.7 1 (13), Solid 2.6 1 (14), Solid 2.5 1 (15), Solid 2.4 1 (16), Solid 2.3 1 (17) - phase: Water at 25 C (2) Available qualifier combinations: {'zone': 1, 'phase': 2} {'zone': 9, 'phase': 2} {'zone': 10, 'phase': 2} {'zone': 11, 'phase': 2} {'zone': 12, 'phase': 2} {'zone': 13, 'phase': 2} {'zone': 14, 'phase': 2} {'zone': 15, 'phase': 2} {'zone': 16, 'phase': 2} {'zone': 17, 'phase': 2} .. GENERATED FROM PYTHON SOURCE LINES 90-92 Extract temperature data ------------------------- .. GENERATED FROM PYTHON SOURCE LINES 92-97 .. code-block:: Python temperature = simulation.temperature() print(temperature) # The resulting dataframe shows data for two different phases. .. rst-class:: sphx-glr-script-out .. code-block:: none results TEMP (K) set_ids 1 phase Water at 25 C (2) Copper (3) node_ids 1 3.0533e+02 2 3.0389e+02 3 3.0155e+02 4 3.0201e+02 5 3.0340e+02 6 3.0487e+02 ... ... ... .. GENERATED FROM PYTHON SOURCE LINES 98-99 Select data for phase 2 (Water) only .. GENERATED FROM PYTHON SOURCE LINES 99-101 .. code-block:: Python print(temperature.select(phase=[2])) .. rst-class:: sphx-glr-script-out .. code-block:: none results TEMP (K) set_ids 1 phase Water at 25 C (2) node_ids 1 3.0533e+02 2 3.0389e+02 3 3.0155e+02 4 3.0201e+02 5 3.0340e+02 6 3.0487e+02 ... ... .. GENERATED FROM PYTHON SOURCE LINES 102-108 To directly extract the temperature data for a given phase, pass the ``temperature()`` method a ``phases`` argument. This argument must be given a list of phase unique IDs, which appear in the dataframe in the phase label column between parentheses, or as listed under the ``Available qualifier labels`` section of the metadata on the result. You can also directly use the phase name. .. GENERATED FROM PYTHON SOURCE LINES 108-114 .. code-block:: Python water_temperature = simulation.temperature(phases=["Water at 25 C"]) # equivalent to # water_temperature = simulation.temperature(phases=[2]) print(water_temperature) # # The resulting dataframe now only stores data for the Water phase. .. rst-class:: sphx-glr-script-out .. code-block:: none results TEMP (K) ... set_ids 1 ... phase Water at 25 C (2) ... zone Default 1 (1) outflow (9) Default (10) inflow (11) Solid 2.8 1 (12) Solid 2.7 1 (13) ... node_ids ... 1 3.0533e+02 3.0533e+02 ... 2 3.0389e+02 3.0389e+02 ... 3 3.0155e+02 3.0155e+02 ... 4 3.0201e+02 3.0201e+02 ... 5 3.0340e+02 3.0340e+02 ... 6 3.0487e+02 3.0487e+02 ... ... ... ... ... ... ... ... ... .. GENERATED FROM PYTHON SOURCE LINES 115-118 To extract a result on given zones use the ``zone_ids`` argument or the ``qualifiers`` dictionary argument with the ``zone`` key. This code gets and plots the temperature on all face zones. .. GENERATED FROM PYTHON SOURCE LINES 118-120 .. code-block:: Python face_temperature = simulation.temperature(zone_ids=list(simulation.face_zones.keys())) face_temperature.plot() .. image-sg:: /examples/04-Fluid-Examples/images/sphx_glr_00-explore-fluid-simulation_001.png :alt: 00 explore fluid simulation :srcset: /examples/04-Fluid-Examples/images/sphx_glr_00-explore-fluid-simulation_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none (None, ) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 3.342 seconds) .. _sphx_glr_download_examples_04-Fluid-Examples_00-explore-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: 00-explore-fluid-simulation.ipynb <00-explore-fluid-simulation.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 00-explore-fluid-simulation.py <00-explore-fluid-simulation.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 00-explore-fluid-simulation.zip <00-explore-fluid-simulation.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_