.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\12-fluids\00-fluids_model.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_12-fluids_00-fluids_model.py: .. _ref_fluids_model: 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 :ref:`ref_compatibility`. .. GENERATED FROM PYTHON SOURCE LINES 17-21 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. .. GENERATED FROM PYTHON SOURCE LINES 21-30 .. code-block:: Python 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) .. GENERATED FROM PYTHON SOURCE LINES 31-37 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`` . .. GENERATED FROM PYTHON SOURCE LINES 37-41 .. code-block:: Python minfo = model.metadata.mesh_info print(minfo) .. rst-class:: sphx-glr-script-out .. code-block:: none 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_scoping Scoping face_zone_names StringField cell_zone_elements PropertyField face_zone_elements PropertyField face_zone_scoping Scoping zone_names StringField num_elem_zone PropertyField zone_scoping Scoping splittable_by StringField .. GENERATED FROM PYTHON SOURCE LINES 42-45 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. .. GENERATED FROM PYTHON SOURCE LINES 45-48 .. code-block:: Python print(minfo.get_property("body_names")) .. rst-class:: sphx-glr-script-out .. code-block:: none DPF String Field 2 Body entities Data:2 elementary data Body IDs data ------------ ---------- 13 fluid-rotor 28 fluid-stator .. GENERATED FROM PYTHON SOURCE LINES 49-53 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. .. GENERATED FROM PYTHON SOURCE LINES 53-56 .. code-block:: Python print(minfo.get_property("body_cell_topology")) .. rst-class:: sphx-glr-script-out .. code-block:: none DPF Property Field 2 entities Data: 1 components and 2 elementary data Body IDs data ------------ ---------- 13 13 28 28 .. GENERATED FROM PYTHON SOURCE LINES 57-62 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. .. GENERATED FROM PYTHON SOURCE LINES 62-65 .. code-block:: Python print(minfo.get_property("body_face_topology")) .. rst-class:: sphx-glr-script-out .. code-block:: none DPF Property Field 2 entities Data: 1 components and 24 elementary data Body IDs data ------------ ---------- 13 2 3 4 ... 28 15 16 17 ... .. GENERATED FROM PYTHON SOURCE LINES 66-70 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. .. GENERATED FROM PYTHON SOURCE LINES 70-74 .. code-block:: Python print(minfo.get_property("cell_zone_names")) print(minfo.get_property("face_zone_names")) .. rst-class:: sphx-glr-script-out .. code-block:: none 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 ... .. GENERATED FROM PYTHON SOURCE LINES 75-77 All zone names (regardless of them being cell or face zones) are exported to the "zone_names" ``StringField`` . .. GENERATED FROM PYTHON SOURCE LINES 77-80 .. code-block:: Python print(minfo.get_property("zone_names")) .. rst-class:: sphx-glr-script-out .. code-block:: none DPF String Field 26 zone entities Data:26 elementary data zone IDs data ------------ ---------- 13 fluid-rotor 2 default-interior:0 3 rotor-hub ... .. GENERATED FROM PYTHON SOURCE LINES 81-82 Helpers are provided to quickly get a map of zone ID to zone name. .. GENERATED FROM PYTHON SOURCE LINES 82-86 .. code-block:: Python print(minfo.zones) print(minfo.cell_zones) print(minfo.face_zones) .. rst-class:: sphx-glr-script-out .. code-block:: none {'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'} .. GENERATED FROM PYTHON SOURCE LINES 87-89 To facilitate the extraction of results, the body, cell and face zone ``Scoping`` are extracted. They can be used to scope results. .. GENERATED FROM PYTHON SOURCE LINES 89-94 .. code-block:: Python print(minfo.get_property("body_scoping")) print(minfo.get_property("cell_zone_scoping")) print(minfo.get_property("face_zone_scoping")) .. rst-class:: sphx-glr-script-out .. code-block:: none DPF Scoping: with Body location and 2 entities DPF Scoping: with zone location and 2 entities DPF Scoping: with zone location and 24 entities .. GENERATED FROM PYTHON SOURCE LINES 95-101 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). .. GENERATED FROM PYTHON SOURCE LINES 101-105 .. code-block:: Python rinfo = model.metadata.result_info print(rinfo) .. rst-class:: sphx-glr-script-out .. code-block:: none 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) .. GENERATED FROM PYTHON SOURCE LINES 106-110 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". .. GENERATED FROM PYTHON SOURCE LINES 110-113 .. code-block:: Python print(rinfo.available_results[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: - phase: phase-1 (1) - zone: fluid-rotor (13), fluid-stator (28) Available qualifier combinations: {'phase': 1, 'zone': 13} {'phase': 1, 'zone': 28} .. GENERATED FROM PYTHON SOURCE LINES 114-117 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. .. GENERATED FROM PYTHON SOURCE LINES 117-121 .. code-block:: Python print(rinfo.available_results[2]) .. rst-class:: sphx-glr-script-out .. code-block:: none 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} .. GENERATED FROM PYTHON SOURCE LINES 122-126 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. .. GENERATED FROM PYTHON SOURCE LINES 126-133 .. code-block:: Python 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) .. GENERATED FROM PYTHON SOURCE LINES 134-138 Exploring the mesh ~~~~~~~~~~~~~~~~~~ If once again we explore the MeshInfo, we can see that the same information is readily available. .. GENERATED FROM PYTHON SOURCE LINES 138-142 .. code-block:: Python minfo = model.metadata.mesh_info print(minfo) .. rst-class:: sphx-glr-script-out .. code-block:: none 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 face_zone_names StringField cell_zone_scoping Scoping cell_zone_elements PropertyField face_zone_elements PropertyField face_zone_scoping Scoping zone_names StringField num_elem_zone PropertyField zone_scoping Scoping splittable_by StringField .. GENERATED FROM PYTHON SOURCE LINES 143-144 In this CFX model there are also two bodies. .. GENERATED FROM PYTHON SOURCE LINES 144-147 .. code-block:: Python print(minfo.get_property("body_names")) .. rst-class:: sphx-glr-script-out .. code-block:: none DPF String Field 2 Body entities Data:2 elementary data Body IDs data ------------ ---------- 1 Default 1 2 heater .. GENERATED FROM PYTHON SOURCE LINES 148-151 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. .. GENERATED FROM PYTHON SOURCE LINES 151-154 .. code-block:: Python print(minfo.get_property("body_cell_topology")) .. rst-class:: sphx-glr-script-out .. code-block:: none DPF Property Field 2 entities Data: 1 components and 6 elementary data Body IDs data ------------ ---------- 1 3 4 5 2 6 7 8 .. GENERATED FROM PYTHON SOURCE LINES 155-156 You can also explore the face zone IDs in each body. .. GENERATED FROM PYTHON SOURCE LINES 156-159 .. code-block:: Python print(minfo.get_property("body_face_topology")) .. rst-class:: sphx-glr-script-out .. code-block:: none DPF Property Field 2 entities Data: 1 components and 16 elementary data Body IDs data ------------ ---------- 1 9 10 11 ... 2 18 19 20 ... .. GENERATED FROM PYTHON SOURCE LINES 160-161 The cell and face zone names are readily available. .. GENERATED FROM PYTHON SOURCE LINES 161-165 .. code-block:: Python print(minfo.get_property("cell_zone_names")) print(minfo.get_property("face_zone_names")) .. rst-class:: sphx-glr-script-out .. code-block:: none 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 ... .. GENERATED FROM PYTHON SOURCE LINES 166-170 Exploring the results ~~~~~~~~~~~~~~~~~~~~~ By exploring the ResultInfo we can see that all CFX variables are exported to the Nodes. .. GENERATED FROM PYTHON SOURCE LINES 170-174 .. code-block:: Python rinfo = model.metadata.result_info print(rinfo) .. 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: - 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: (1), Water at 25 C (2), Copper (3) .. GENERATED FROM PYTHON SOURCE LINES 175-179 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. .. GENERATED FROM PYTHON SOURCE LINES 179-185 .. code-block:: Python labels = rinfo.available_qualifier_labels print(labels) phase_names = rinfo.qualifier_label_support(labels[1]).string_field_support_by_property("names") print(phase_names) .. rst-class:: sphx-glr-script-out .. code-block:: none ['zone', 'phase'] DPF String Field 3 entities Data:3 elementary data IDs data ------------ ---------- 1 2 Water at 25 C 3 Copper .. GENERATED FROM PYTHON SOURCE LINES 186-189 Each result holds more detailed information while explored individually. Static Pressure is only available for phase 1 (""), and several cell and face zones. .. GENERATED FROM PYTHON SOURCE LINES 189-192 .. code-block:: Python print(rinfo.available_results[7]) .. rst-class:: sphx-glr-script-out .. code-block:: none DPF Result ---------- static_pressure Operator name: "P_S" Number of components: 1 Dimensionality: scalar Homogeneity: pressure Units: Pa Location: Nodal Available qualifier labels: - phase: (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} .. GENERATED FROM PYTHON SOURCE LINES 193-195 Thermal conductivity, however, exists for phases 2 and 3 ("Copper" and "Water at 25 C", respectively), and several face and cell zones. .. GENERATED FROM PYTHON SOURCE LINES 195-197 .. code-block:: Python print(rinfo.available_results[4]) .. rst-class:: sphx-glr-script-out .. code-block:: none 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} .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 8.336 seconds) .. _sphx_glr_download_examples_12-fluids_00-fluids_model.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 00-fluids_model.ipynb <00-fluids_model.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 00-fluids_model.py <00-fluids_model.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_