.. 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: Fluid Simulation Result Extraction ================================== This example shows how to load a fluid simulation (here a heating coil simulated with CFX), explore the metadata available, and use the result extraction capabilities. .. note:: This example requires DPF 7.0 (2024.1.pre0) or above. For more information, see :ref:`compatibility`. .. GENERATED FROM PYTHON SOURCE LINES 15-17 Perform required imports ------------------------ .. GENERATED FROM PYTHON SOURCE LINES 17-20 .. code-block:: Python from ansys.dpf import post from ansys.dpf.post import examples .. GENERATED FROM PYTHON SOURCE LINES 21-23 Load the fluid analysis result ------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 23-31 .. code-block:: Python fluid_example_files = examples.download_cfx_heating_coil() 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.14/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.14/x64/lib/python3.10/site-packages/ansys/dpf/core/examples/result_files/cfx-heating_coil/def.dat.cff DPF Model ------------------------------ Static analysis Unit system: SI: m, kg, N, s, V, A, K Physics Type: Fluid Available results: - specific_heat: Nodal Specific Heat - epsilon: Nodal Epsilon - 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 32-35 Explore the available metadata ------------------------------ Check the available cell and face zones .. GENERATED FROM PYTHON SOURCE LINES 35-38 .. 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 39-42 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 42-44 .. 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 45-46 Check the available species .. GENERATED FROM PYTHON SOURCE LINES 46-48 .. code-block:: Python print(simulation.species) .. rst-class:: sphx-glr-script-out .. code-block:: none 0 species available {} .. GENERATED FROM PYTHON SOURCE LINES 49-50 Check the available phases .. GENERATED FROM PYTHON SOURCE LINES 50-53 .. 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 54-58 Extract a result ---------------- ############################################################################## Check the metadata on available results .. GENERATED FROM PYTHON SOURCE LINES 58-60 .. code-block:: Python print(simulation.result_info) .. rst-class:: sphx-glr-script-out .. code-block:: none Static analysis Unit system: SI: m, kg, N, s, V, A, K Physics Type: Fluid Available results: - specific_heat: Nodal Specific Heat - epsilon: Nodal Epsilon - 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 61-62 Print information about a specific available result .. GENERATED FROM PYTHON SOURCE LINES 62-66 .. code-block:: Python print(simulation.result_info["temperature"]) # Or use 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} .. GENERATED FROM PYTHON SOURCE LINES 67-69 Extract the temperature data ---------------------------- .. GENERATED FROM PYTHON SOURCE LINES 69-74 .. code-block:: Python temperature = simulation.temperature() print(temperature) # # The dataframe obtained 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 75-76 Select data for phase 2 only (Water) .. GENERATED FROM PYTHON SOURCE LINES 76-78 .. 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 79-86 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 identifiers, 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 86-92 .. code-block:: Python water_temperature = simulation.temperature(phases=["Water at 25 C"]) # equivalent to # water_temperature = simulation.temperature(phases=[2]) print(water_temperature) # # The dataframe obtained 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 93-96 To extract a result on given zones use the 'zone_ids' argument or the 'qualifiers' dictionary argument with key 'zone' Here we request and plot the temperature on all face zones .. GENERATED FROM PYTHON SOURCE LINES 96-98 .. 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-timing **Total running time of the script:** (0 minutes 3.457 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>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_