|
| 1 | +""" |
| 2 | +.. _ref_fluids_model: |
| 3 | +
|
| 4 | +Explore Fluids models |
| 5 | +------------------------------------------------------ |
| 6 | +
|
| 7 | +This example shows how to explore Ansys Fluent and Ansys CFX models employing |
| 8 | +the ``MeshInfo`` and ``ResultInfo``. |
| 9 | +""" |
| 10 | + |
| 11 | +############################################################################### |
| 12 | +# Exploring an Ansys Fluent model |
| 13 | +# ------------------------------- |
| 14 | +# The first part of the example demonstrates how you can explore an Ansys Fluent |
| 15 | +# model. Import the result file and create a model |
| 16 | + |
| 17 | +import ansys.dpf.core as dpf |
| 18 | +from ansys.dpf.core import examples |
| 19 | + |
| 20 | +path = examples.download_fluent_axial_comp()["flprj"] |
| 21 | +ds = dpf.DataSources(path) |
| 22 | +model = dpf.Model(data_sources=ds) |
| 23 | + |
| 24 | + |
| 25 | +############################################################################### |
| 26 | +# Exploring the mesh |
| 27 | +# ~~~~~~~~~~~~~~~~~~ |
| 28 | +# Explore the mesh through the ``MeshInfo``. The ``MeshInfo`` provides metadata |
| 29 | +# information about the mesh. For fluid models, it is useful to know the cell and |
| 30 | +# face zones, as well as the topological relationships between them. First get all |
| 31 | +# the available information in the ``MeshInfo`` |
| 32 | + |
| 33 | +minfo = model.metadata.mesh_info |
| 34 | +print(minfo) |
| 35 | + |
| 36 | +############################################################################### |
| 37 | +# Then, get the bodies and their names in the model with the "body_names" ``StringField``, |
| 38 | +# which provides a relationship between body IDs and names. In this model there are two |
| 39 | +# bodies. |
| 40 | + |
| 41 | +print(minfo.get_property("body_names")) |
| 42 | + |
| 43 | +############################################################################### |
| 44 | +# Each body is comprised of a set of cell zones. You can investigate the hierarchical |
| 45 | +# relationship between bodies and cell zones through the "body_cell_topology" |
| 46 | +# ``PropertyField``, which provides a relationship between the body IDs and the cell zone |
| 47 | +# IDs. In this case, each body is only comprised of one cell zone. |
| 48 | + |
| 49 | +print(minfo.get_property("body_cell_topology")) |
| 50 | + |
| 51 | +############################################################################### |
| 52 | +# Similarly, each body is limited by a set of face zones (generally representing |
| 53 | +# boundary conditions). You can investigate the hierarchical relationship between |
| 54 | +# bodies and face zones through the "body_face_topology" ``PropertyField``, which |
| 55 | +# provides a relationship between the body IDs and the face zone IDs. In this case, |
| 56 | +# each body is limited by several face zones |
| 57 | + |
| 58 | +print(minfo.get_property("body_face_topology")) |
| 59 | + |
| 60 | +############################################################################### |
| 61 | +# The cell and face zone ids shown in the previous PropertyFields can be mapped |
| 62 | +# to their names through the "body_zone_names" and "face_zone_names" ``PropertyField``. |
| 63 | +# As in this model there is a 1-1 correspondence between bodies and cell zones, |
| 64 | +# they have the same names and IDs. |
| 65 | + |
| 66 | +print(minfo.get_property("cell_zone_names")) |
| 67 | +print(minfo.get_property("face_zone_names")) |
| 68 | + |
| 69 | +############################################################################### |
| 70 | +# All zone names (regardless of them being cell or face zones) are exported to |
| 71 | +# the "zone_names" ``StringField`` |
| 72 | + |
| 73 | +print(minfo.get_property("zone_names")) |
| 74 | + |
| 75 | +############################################################################### |
| 76 | +# To facilitate the extraction of results, the body, cell and face zone ``Scoping`` |
| 77 | +# are extracted. They can be used to scope results |
| 78 | + |
| 79 | +print(minfo.get_property("body_scoping")) |
| 80 | +print(minfo.get_property("cell_zone_scoping")) |
| 81 | +print(minfo.get_property("face_zone_scoping")) |
| 82 | + |
| 83 | +############################################################################### |
| 84 | +# Exploring the results |
| 85 | +# ~~~~~~~~~~~~~~~~~~~~~ |
| 86 | +# Explore the available results in the model through the ResultInfo. This is a Fluent model |
| 87 | +# whose native results are exported to either the centroid of the elements (like |
| 88 | +# Enthalpy or RMS Temperature), the centroid of the faces (like the Mass Flow Rate) |
| 89 | +# or the centroid of both elements and faces (like Static Pressure). |
| 90 | + |
| 91 | +rinfo = model.metadata.result_info |
| 92 | +print(rinfo) |
| 93 | + |
| 94 | +############################################################################### |
| 95 | +# Each result holds more detailed information while explored individually. Enthalpy |
| 96 | +# is a scalar magnitude exported to the centroids of the elements (cells). Thus, it is |
| 97 | +# available for the two cell zones of the model (13 and 28). In addition, the model |
| 98 | +# only has one phase, and therefore the result can only be extracted for "phase-1". |
| 99 | + |
| 100 | +print(rinfo.available_results[0]) |
| 101 | + |
| 102 | +############################################################################### |
| 103 | +# Static Pressure, however, is ElementalAndFaces, which means that it is exported |
| 104 | +# at both the centroids of the cells and the centroids of the faces. Therefore, it is |
| 105 | +# available for all the cell and face zones of the model. |
| 106 | + |
| 107 | +print(rinfo.available_results[2]) |
| 108 | + |
| 109 | + |
| 110 | +############################################################################### |
| 111 | +# Exploring an Ansys CFX model |
| 112 | +# ---------------------------- |
| 113 | +# The second part of the example demonstrates how you can explore an Ansys CFX model. |
| 114 | +# Import the result file and create a model |
| 115 | + |
| 116 | +path = examples.download_cfx_heating_coil() |
| 117 | +ds = dpf.DataSources() |
| 118 | +ds.set_result_file_path(path["cas"], "cas") |
| 119 | +ds.add_file_path(path["dat"], "dat") |
| 120 | +model = dpf.Model(data_sources=ds) |
| 121 | + |
| 122 | +############################################################################### |
| 123 | +# Exploring the mesh |
| 124 | +# ~~~~~~~~~~~~~~~~~~ |
| 125 | +# If once again we explore the MeshInfo, we can see that the same information is |
| 126 | +# readily available |
| 127 | + |
| 128 | +minfo = model.metadata.mesh_info |
| 129 | +print(minfo) |
| 130 | + |
| 131 | +############################################################################### |
| 132 | +# In this CFX model there are also two bodies. |
| 133 | + |
| 134 | +print(minfo.get_property("body_names")) |
| 135 | + |
| 136 | +############################################################################### |
| 137 | +# For this model, each body is conformed by several cell zones. In this general |
| 138 | +# situation, the body ID corresponds to the highest cell zone ID of the one that |
| 139 | +# comprises it. |
| 140 | + |
| 141 | +print(minfo.get_property("body_cell_topology")) |
| 142 | + |
| 143 | +############################################################################### |
| 144 | +# You can also explore the face zone IDs in each body |
| 145 | + |
| 146 | +print(minfo.get_property("body_face_topology")) |
| 147 | + |
| 148 | +############################################################################### |
| 149 | +# The cell and face zone names are readily available |
| 150 | + |
| 151 | +print(minfo.get_property("cell_zone_names")) |
| 152 | +print(minfo.get_property("face_zone_names")) |
| 153 | + |
| 154 | +############################################################################### |
| 155 | +# Exploring the results |
| 156 | +# ~~~~~~~~~~~~~~~~~~~~~ |
| 157 | +# By exploring the ResultInfo we can see that all CFX variables are exported to |
| 158 | +# the Nodes |
| 159 | + |
| 160 | +rinfo = model.metadata.result_info |
| 161 | +print(rinfo) |
| 162 | + |
| 163 | +############################################################################### |
| 164 | +# However, in this model there are two distinct phases. To understand the phases |
| 165 | +# at the model, you can explore the qualifiers of the ResultInfo. Thus, results |
| 166 | +# could potentially be scoped on "zone" and "phase", with the ID and name of each |
| 167 | +# phase shown below. |
| 168 | + |
| 169 | +labels = rinfo.available_qualifier_labels |
| 170 | +print(labels) |
| 171 | +phase_names = rinfo.qualifier_label_support(labels[1]).string_field_support_by_property("names") |
| 172 | +print(phase_names) |
| 173 | + |
| 174 | +############################################################################### |
| 175 | +# Each result holds more detailed information while explored individually. Static |
| 176 | +# Pressure is only available for phase 1 ("<Mixture>"), and several cell and face |
| 177 | +# zones. |
| 178 | + |
| 179 | +print(rinfo.available_results[7]) |
| 180 | + |
| 181 | +############################################################################### |
| 182 | +# Thermal conductivity, however, exists for phases 2 and 3 ("Copper" and "Water at 25 C", |
| 183 | +# respectively), and several face and cell zones. |
| 184 | + |
| 185 | +print(rinfo.available_results[4]) |
0 commit comments