Skip to content

Commit 2dd4017

Browse files
rafacantonPProfizi
andauthored
Add examples for Fluids models (#1021)
* Add better support for plotting on faces * deep_copy mesh with an operator * use passed server * legacy behavior for legacy server * Improve MeshInfo api. Begin example * Update all get_property calls * fix missing test * remove topology and name tests to avoid TFS pipelines failing * Add simple example * Revert complete mesh_info tests * README for fluids examples * Second fluid example * fix fluid examples * Remove unneded map * Update docs.yml check for success conditional Parse the whole log for robustness, for cases such as this to still be marked as successful despite text being printed to the stdout after doc generation execution. * Implement rev comments * More examples * continue * averaging * Changes to mesh_info halfway-through * Remove type in mesh_info and gdc docstring * fix issue * Cosmetic changes --------- Co-authored-by: Paul Profizi <[email protected]>
1 parent 5b87a8a commit 2dd4017

File tree

13 files changed

+754
-34
lines changed

13 files changed

+754
-34
lines changed

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ jobs:
139139
shell: bash
140140
working-directory: docs
141141
run: |
142-
case `tail -n 5 log.txt | grep -F "build succeeded" >/dev/null; echo $?` in
142+
case `grep -F "build succeeded" log.txt >/dev/null; echo $?` in
143143
0)
144144
echo "Build succeeded!"
145145
exit 0;;
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
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])
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
"""
2+
.. _ref_fluids_mesh:
3+
4+
Explore Fluids mesh
5+
-------------------
6+
7+
"""
8+
9+
###############################################################################
10+
# Exploring an Ansys Fluent mesh
11+
# ------------------------------
12+
# This example demonstrates how you can explore an Ansys Fluent mesh. Import
13+
# the result file
14+
15+
import ansys.dpf.core as dpf
16+
from ansys.dpf.core import examples
17+
18+
path = examples.download_fluent_axial_comp()["flprj"]
19+
ds = dpf.DataSources(path)
20+
streams = dpf.operators.metadata.streams_provider(data_sources=ds)
21+
22+
23+
###############################################################################
24+
# Using the ``mesh_provider``
25+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~
26+
# The ``mesh_provider`` operator can be used to retrieve the whole mesh of the
27+
# model or the `MeshedRegion` restricted to a particular body or face zone. The
28+
# behavior will differ depending on the inputs to the ``region_scoping`` pin.
29+
# If no scoping is connected, the mesh for the whole model is obtained. This
30+
# is the same mesh that is obtained if the ``Model.metadata.meshed_region``
31+
# API is employed.
32+
33+
mesh_whole = dpf.operators.mesh.mesh_provider(streams_container=streams).eval()
34+
print(mesh_whole)
35+
mesh_whole.plot()
36+
37+
###############################################################################
38+
# If the ``region_scoping`` pin is connected, a ``Scoping`` with 1 zone ID is
39+
# expected, or an integer list with one item, or a single integer. The supported
40+
# zone IDs are either face zone IDs or body IDs. The zones of this particular model
41+
# are explored in :ref:`ref_fluids_model`. ID 4 (rotor-shroud) corresponds to a
42+
# face zone, and thus its mesh is only comprised of faces and nodes. ID 13 (fluid-rotor)
43+
# is a body, and thus its mesh has elements (cells), faces and nodes.
44+
45+
mesh_4 = dpf.operators.mesh.mesh_provider(streams_container=streams, region_scoping=4).eval()
46+
print(mesh_4)
47+
mesh_4.plot()
48+
mesh_13 = dpf.operators.mesh.mesh_provider(streams_container=streams, region_scoping=[13]).eval()
49+
print(mesh_13)
50+
mesh_13.plot()
51+
52+
###############################################################################
53+
# Using the ``meshes_provider``
54+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55+
# The ``meshes_provider`` operator can be used to retrieve the mesh for several
56+
# zones and time steps of the model. The behavior will differ depending on the
57+
# inputs to the ``region_scoping`` pin. If no region_scoping is connected, the
58+
# ``MeshedRegion`` for all body and face zones is retrieved in a ``MeshesContainer``.
59+
# If no time_scoping is connected and the simulation is transient, only the meshes
60+
# for the first time step are extracted.
61+
62+
meshes_all = dpf.operators.mesh.meshes_provider(streams_container=streams).eval()
63+
print(meshes_all)
64+
print("\n".join([str(meshes_all.get_label_space(i)) for i in range(len(meshes_all))]))
65+
66+
###############################################################################
67+
# If the ``region_scoping`` pin is connected, the mesh extraction is restricted to
68+
# the zone IDs contained in the input Scoping/list (in this case, a face zone connected
69+
# to body 18 and body 13).
70+
71+
meshes_23_13 = dpf.operators.mesh.meshes_provider(
72+
streams_container=streams, region_scoping=[23, 13], time_scoping=[3]
73+
).eval()
74+
print(meshes_23_13)
75+
meshes_23_13.plot()

0 commit comments

Comments
 (0)