Note
Go to the end to download the full example code.
Explore Fluids models#
This example demonstrates how to explore Ansys Fluent and Ansys CFX models employing
the MeshInfo
and ResultInfo
.
Note
This example requires DPF 7.0 (ansys-dpf-server-2024-1-pre0) or above. For more information, see Compatibility.
Exploring an Ansys Fluent model#
The first part of the example demonstrates how you can explore an Ansys Fluent model. Import the result file and create a model.
import ansys.dpf.core as dpf
from ansys.dpf.core import examples
path = examples.download_fluent_axial_comp()["flprj"]
ds = dpf.DataSources(path)
model = dpf.Model(data_sources=ds)
Exploring the mesh#
Explore the mesh through the MeshInfo
. The MeshInfo
provides metadata
information about the mesh. For fluid models, it is useful to know the cell and
face zones, as well as the topological relationships between them. First get all
the available information in the MeshInfo
.
minfo = model.metadata.mesh_info
print(minfo)
DPF MeshInfo
------------------------------
with properties:
num_cells int
num_nodes int
num_faces int
body_names StringField
body_cell_topology PropertyField
body_face_topology PropertyField
body_scoping Scoping
cell_zone_names StringField
cell_zone_elements PropertyField
cell_zone_scoping Scoping
face_zone_names StringField
face_zone_elements PropertyField
face_zone_scoping Scoping
zone_names StringField
num_elem_zone PropertyField
zone_scoping Scoping
splittable_by StringField
Then, get the bodies and their names in the model with the “body_names” StringField
,
which provides a relationship between body IDs and names. In this model there are two
bodies.
print(minfo.get_property("body_names"))
DPF String Field
2 Body entities
Data:2 elementary data
Body
IDs data
------------ ----------
13 fluid-rotor
28 fluid-stator
Each body is comprised of a set of cell zones. You can investigate the hierarchical
relationship between bodies and cell zones through the “body_cell_topology”
PropertyField
, which provides a relationship between the body IDs and the cell zone
IDs. In this case, each body is only comprised of one cell zone.
print(minfo.get_property("body_cell_topology"))
DPF Property Field
2 entities
Data: 1 components and 2 elementary data
Body
IDs data
------------ ----------
13 13
28 28
Similarly, each body is limited by a set of face zones (generally representing
boundary conditions). You can investigate the hierarchical relationship between
bodies and face zones through the “body_face_topology” PropertyField
, which
provides a relationship between the body IDs and the face zone IDs. In this case,
each body is limited by several face zones.
print(minfo.get_property("body_face_topology"))
DPF Property Field
2 entities
Data: 1 components and 24 elementary data
Body
IDs data
------------ ----------
13 2
3
4
...
28 15
16
17
...
The cell and face zone IDs shown in the previous PropertyFields can be mapped
to their names through the “body_zone_names” and “face_zone_names” PropertyField
.
As in this model there is a 1-1 correspondence between bodies and cell zones,
they have the same names and IDs.
print(minfo.get_property("cell_zone_names"))
print(minfo.get_property("face_zone_names"))
DPF String Field
2 zone entities
Data:2 elementary data
zone
IDs data
------------ ----------
13 fluid-rotor
28 fluid-stator
DPF String Field
24 zone entities
Data:24 elementary data
zone
IDs data
------------ ----------
2 default-interior:0
3 rotor-hub
4 rotor-shroud
...
All zone names (regardless of them being cell or face zones) are exported to
the “zone_names” StringField
.
print(minfo.get_property("zone_names"))
DPF String Field
26 zone entities
Data:26 elementary data
zone
IDs data
------------ ----------
13 fluid-rotor
2 default-interior:0
3 rotor-hub
...
Helpers are provided to quickly get a map of zone ID to zone name.
print(minfo.zones)
print(minfo.cell_zones)
print(minfo.face_zones)
{'13': 'fluid-rotor', '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', '28': 'fluid-stator', '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'}
{'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'}
As well as a map of body ID to body name.
print(minfo.bodies)
{'13': 'fluid-rotor', '28': 'fluid-stator'}
To facilitate the extraction of results, the body, cell and face zone Scoping
are extracted. They can be used to scope results.
print(minfo.get_property("body_scoping"))
print(minfo.get_property("cell_zone_scoping"))
print(minfo.get_property("face_zone_scoping"))
DPF Scoping:
with Body location and 2 entities
DPF Scoping:
with zone location and 2 entities
DPF Scoping:
with zone location and 24 entities
Exploring the results#
Explore the available results in the model through the ResultInfo. This is a Fluent model whose native results are exported to either the centroid of the elements (like Enthalpy or RMS Temperature), the centroid of the faces (like the Mass Flow Rate) or the centroid of both elements and faces (like Static Pressure).
rinfo = model.metadata.result_info
print(rinfo)
Transient 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:
- 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)
- phase: phase-1 (1)
Each result holds more detailed information while explored individually. Enthalpy is a scalar magnitude exported to the centroids of the elements (cells). Thus, it is available for the two cell zones of the model (13 and 28). In addition, the model only has one phase, and therefore the result can only be extracted for “phase-1”.
print(rinfo.available_results[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:
- phase: phase-1 (1)
- zone: fluid-rotor (13), fluid-stator (28)
Available qualifier combinations:
{'phase': 1, 'zone': 13}
{'phase': 1, 'zone': 28}
Static Pressure, however, is ElementalAndFaces, which means that it is exported at both the centroids of the cells and the centroids of the faces. Therefore, it is available for all the cell and face zones of the model.
print(rinfo.available_results[2])
DPF Result
----------
static_pressure
Operator name: "P_S"
Number of components: 1
Dimensionality: scalar
Homogeneity: pressure
Units: Pa
Location: ElementalAndFaces
Available qualifier labels:
- phase: phase-1 (1)
- zone: fluid-rotor (13), fluid-stator (28), 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), 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)
Available qualifier combinations:
{'phase': 1, 'zone': 13}
{'phase': 1, 'zone': 28}
{'phase': 1, 'zone': 3}
{'phase': 1, 'zone': 4}
{'phase': 1, 'zone': 5}
{'phase': 1, 'zone': 6}
{'phase': 1, 'zone': 7}
{'phase': 1, 'zone': 8}
{'phase': 1, 'zone': 9}
{'phase': 1, 'zone': 10}
{'phase': 1, 'zone': 11}
{'phase': 1, 'zone': 12}
{'phase': 1, 'zone': 16}
{'phase': 1, 'zone': 17}
{'phase': 1, 'zone': 18}
{'phase': 1, 'zone': 19}
{'phase': 1, 'zone': 20}
{'phase': 1, 'zone': 21}
{'phase': 1, 'zone': 22}
{'phase': 1, 'zone': 23}
{'phase': 1, 'zone': 24}
{'phase': 1, 'zone': 25}
{'phase': 1, 'zone': 26}
{'phase': 1, 'zone': 27}
Exploring an Ansys CFX model#
The second part of the example demonstrates how you can explore an Ansys CFX model. Import the result file and create a model.
path = examples.download_cfx_heating_coil()
ds = dpf.DataSources()
ds.set_result_file_path(path["cas"], "cas")
ds.add_file_path(path["dat"], "dat")
model = dpf.Model(data_sources=ds)
Exploring the mesh#
If once again we explore the MeshInfo, we can see that the same information is readily available.
minfo = model.metadata.mesh_info
print(minfo)
DPF MeshInfo
------------------------------
with properties:
num_nodes int
num_cells int
body_names StringField
body_cell_topology PropertyField
num_faces int
body_face_topology PropertyField
body_scoping Scoping
cell_zone_names StringField
cell_zone_elements PropertyField
face_zone_names StringField
cell_zone_scoping Scoping
face_zone_elements PropertyField
face_zone_scoping Scoping
zone_names StringField
num_elem_zone PropertyField
zone_scoping Scoping
splittable_by StringField
In this CFX model there are also two bodies.
print(minfo.get_property("body_names"))
DPF String Field
2 Body entities
Data:2 elementary data
Body
IDs data
------------ ----------
1 Default 1
2 heater
For this model, each body is conformed by several cell zones. In this general situation, the body ID corresponds to the highest cell zone ID of the one that comprises it.
print(minfo.get_property("body_cell_topology"))
DPF Property Field
2 entities
Data: 1 components and 6 elementary data
Body
IDs data
------------ ----------
1 3
4
5
2 6
7
8
You can also explore the face zone IDs in each body.
print(minfo.get_property("body_face_topology"))
DPF Property Field
2 entities
Data: 1 components and 16 elementary data
Body
IDs data
------------ ----------
1 9
10
11
...
2 18
19
20
...
The cell and face zone names are readily available.
print(minfo.get_property("cell_zone_names"))
print(minfo.get_property("face_zone_names"))
DPF String Field
6 zone entities
Data:6 elementary data
zone
IDs data
------------ ----------
3 ZN1/ES1
4 ZN1/ES2
5 ZN1/ES3
...
DPF String Field
16 zone entities
Data:16 elementary data
zone
IDs data
------------ ----------
9 outflow
10 Default
11 inflow
...
Exploring the results#
By exploring the ResultInfo we can see that all CFX variables are exported to the Nodes.
rinfo = model.metadata.result_info
print(rinfo)
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:
- 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)
- phase: <Mixture> (1), Water at 25 C (2), Copper (3)
However, in this model there are two distinct phases. To understand the phases at the model, you can explore the qualifiers of the ResultInfo. Thus, results could potentially be scoped on “zone” and “phase”, with the ID and name of each phase shown below.
labels = rinfo.available_qualifier_labels
print(labels)
phase_names = rinfo.qualifier_label_support(labels[1]).string_field_support_by_property("names")
print(phase_names)
['zone', 'phase']
DPF String Field
3 entities
Data:3 elementary data
IDs data
------------ ----------
1 <Mixture>
2 Water at 25 C
3 Copper
Each result holds more detailed information while explored individually. Static Pressure is only available for phase 1 (“<Mixture>”), and several cell and face zones.
print(rinfo.available_results[7])
DPF Result
----------
static_pressure
Operator name: "P_S"
Number of components: 1
Dimensionality: scalar
Homogeneity: pressure
Units: Pa
Location: Nodal
Available qualifier labels:
- phase: <Mixture> (1)
- 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)
Available qualifier combinations:
{'phase': 1, 'zone': 1}
{'phase': 1, 'zone': 9}
{'phase': 1, 'zone': 10}
{'phase': 1, 'zone': 11}
{'phase': 1, 'zone': 12}
{'phase': 1, 'zone': 13}
{'phase': 1, 'zone': 14}
{'phase': 1, 'zone': 15}
{'phase': 1, 'zone': 16}
{'phase': 1, 'zone': 17}
Thermal conductivity, however, exists for phases 2 and 3 (“Copper” and “Water at 25 C”, respectively), and several face and cell zones.
print(rinfo.available_results[4])
DPF Result
----------
thermal_conductivity
Operator name: "KT"
Number of components: 1
Dimensionality: scalar
Homogeneity: conductivity
Units: W*m^-1*K^-1
Location: Nodal
Available qualifier labels:
- phase: Water at 25 C (2), Copper (3)
- 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)
Available qualifier combinations:
{'phase': 2, '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': 3, '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}
Total running time of the script: (0 minutes 4.033 seconds)