Fluid Simulation#

This example shows how to load a fluid simulation, explore the model and its available zones, species, and phases, as well as how to extract a result.

Note

This example requires DPF 7.0 (2024.1.pre0) or above. For more information, see Compatibility.

Perform required imports#

from ansys.dpf import post
from ansys.dpf.post import examples

Load the fluid analysis result#

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)
Fluid Simulation.


Data Sources
------------------------------
DPF  DataSources:
  Result files:
     result key: cas and path: /opt/hostedtoolcache/Python/3.10.15/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.15/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.15/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.15/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.15/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.15/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: SI: 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
     -  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

Explore the available metadata#

Check the available cell and face zones

print(simulation.cell_zones)
print(simulation.face_zones)
{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'}

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

print(simulation.mesh_info)
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]}

Check the available species

print(simulation.species)
0 species available
{}

Check the available phases

print(simulation.phases)
1 phases available
{Phase<name: 'phase-1', id=1>, }
Extract a result
print(simulation.result_info)
Static analysis
Unit system: SI: 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
     -  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)

Print a specific one to get more information on available qualifiers (zones, phases and so on)

print(simulation.result_info["enthalpy"])
# Or use an index
# print(simulation.result_info[0])
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}

Extract this available result as a Dataframe

enthalpy = simulation.enthalpy()
print(enthalpy)
# Not specifying any qualifier returns a unique column of data
 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
     ...        ...

Plot the Dataframe

enthalpy.plot()
05 fluid simulation

Available qualifiers for this result can be used in the extraction request to filter/separate data. Here we want a different column for each available zone for this result

print(simulation.enthalpy(zone_ids=[13, 28]))
# Here only the data for the fluid-stator zone is extracted
print(simulation.enthalpy(zone_ids=[28]))
# The same logic can be applied to any available qualifier found in the ``AvailableResult``
# description under 'Available qualifier labels'.
 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
     ...               ...

The result extraction request can also contain selection arguments The enthalpy result being defined on cells, you can request data for specific cells using their IDs:

print(simulation.enthalpy(cell_ids=[1, 2]))
 results H_S (J/kg)
 set_ids          1
cell_ids
       1 2.7790e+05
       2 2.7781e+05

For selection and manipulation of the Dataframe, please refer to example “Create and manipulate a DPF Dataframe”

Total running time of the script: (0 minutes 4.371 seconds)

Gallery generated by Sphinx-Gallery