Skip to content

Commit 64ca882

Browse files
authored
Add more coverage for MeshInfo and rev. comments from previous PR (#1057)
* Add rev comments from previous PR * restore missing coverage in MeshInfo * Increase coverage * cov
1 parent 3ce3a88 commit 64ca882

File tree

5 files changed

+53
-40
lines changed

5 files changed

+53
-40
lines changed

examples/12-fluids/00-fluids_model.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
Explore Fluids models
55
------------------------------------------------------
66
7-
This example shows how to explore Ansys Fluent and Ansys CFX models employing
7+
This example demonstrates how to explore Ansys Fluent and Ansys CFX models employing
88
the ``MeshInfo`` and ``ResultInfo``.
99
"""
1010

1111
###############################################################################
1212
# Exploring an Ansys Fluent model
1313
# -------------------------------
1414
# The first part of the example demonstrates how you can explore an Ansys Fluent
15-
# model. Import the result file and create a model
15+
# model. Import the result file and create a model.
1616

1717
import ansys.dpf.core as dpf
1818
from ansys.dpf.core import examples
@@ -28,7 +28,7 @@
2828
# Explore the mesh through the ``MeshInfo``. The ``MeshInfo`` provides metadata
2929
# information about the mesh. For fluid models, it is useful to know the cell and
3030
# face zones, as well as the topological relationships between them. First get all
31-
# the available information in the ``MeshInfo``
31+
# the available information in the ``MeshInfo`` .
3232

3333
minfo = model.metadata.mesh_info
3434
print(minfo)
@@ -53,12 +53,12 @@
5353
# boundary conditions). You can investigate the hierarchical relationship between
5454
# bodies and face zones through the "body_face_topology" ``PropertyField``, which
5555
# provides a relationship between the body IDs and the face zone IDs. In this case,
56-
# each body is limited by several face zones
56+
# each body is limited by several face zones.
5757

5858
print(minfo.get_property("body_face_topology"))
5959

6060
###############################################################################
61-
# The cell and face zone ids shown in the previous PropertyFields can be mapped
61+
# The cell and face zone IDs shown in the previous PropertyFields can be mapped
6262
# to their names through the "body_zone_names" and "face_zone_names" ``PropertyField``.
6363
# As in this model there is a 1-1 correspondence between bodies and cell zones,
6464
# they have the same names and IDs.
@@ -68,13 +68,13 @@
6868

6969
###############################################################################
7070
# All zone names (regardless of them being cell or face zones) are exported to
71-
# the "zone_names" ``StringField``
71+
# the "zone_names" ``StringField`` .
7272

7373
print(minfo.get_property("zone_names"))
7474

7575
###############################################################################
7676
# To facilitate the extraction of results, the body, cell and face zone ``Scoping``
77-
# are extracted. They can be used to scope results
77+
# are extracted. They can be used to scope results.
7878

7979
print(minfo.get_property("body_scoping"))
8080
print(minfo.get_property("cell_zone_scoping"))
@@ -111,7 +111,7 @@
111111
# Exploring an Ansys CFX model
112112
# ----------------------------
113113
# The second part of the example demonstrates how you can explore an Ansys CFX model.
114-
# Import the result file and create a model
114+
# Import the result file and create a model.
115115

116116
path = examples.download_cfx_heating_coil()
117117
ds = dpf.DataSources()
@@ -123,7 +123,7 @@
123123
# Exploring the mesh
124124
# ~~~~~~~~~~~~~~~~~~
125125
# If once again we explore the MeshInfo, we can see that the same information is
126-
# readily available
126+
# readily available.
127127

128128
minfo = model.metadata.mesh_info
129129
print(minfo)
@@ -141,12 +141,12 @@
141141
print(minfo.get_property("body_cell_topology"))
142142

143143
###############################################################################
144-
# You can also explore the face zone IDs in each body
144+
# You can also explore the face zone IDs in each body.
145145

146146
print(minfo.get_property("body_face_topology"))
147147

148148
###############################################################################
149-
# The cell and face zone names are readily available
149+
# The cell and face zone names are readily available.
150150

151151
print(minfo.get_property("cell_zone_names"))
152152
print(minfo.get_property("face_zone_names"))
@@ -155,7 +155,7 @@
155155
# Exploring the results
156156
# ~~~~~~~~~~~~~~~~~~~~~
157157
# By exploring the ResultInfo we can see that all CFX variables are exported to
158-
# the Nodes
158+
# the Nodes.
159159

160160
rinfo = model.metadata.result_info
161161
print(rinfo)

examples/12-fluids/02-fluids_results.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Exploring Ansys Fluent results
1111
# ------------------------------
1212
# This example demonstrates how you can explore Ansys Fluent results. Import
13-
# the result file and explore the available results with the ``ResultInfo``
13+
# the result file and explore the available results with the ``ResultInfo`` .
1414

1515
import ansys.dpf.core as dpf
1616
from ansys.dpf.core import examples
@@ -34,7 +34,7 @@
3434
# operator, the result is extracted for all cell zones and exported to an
3535
# Elemental ``Field``. Elemental results do not bring their ``MeshSupport`` by
3636
# default, and thus the mesh input can be employed to connect the MeshedRegion
37-
# and display the result
37+
# and display the result.
3838

3939
print(rinfo.available_results[5])
4040
whole_mesh = dpf.operators.mesh.mesh_provider(streams_container=streams).eval()
@@ -60,7 +60,7 @@
6060
# results can be compared.
6161

6262

63-
def displace_mesh(original_mesh: dpf.MeshInfo, disp: list) -> dpf.MeshedRegion:
63+
def displace_mesh(original_mesh: dpf.MeshedRegion, disp: list) -> dpf.MeshedRegion:
6464
new_mesh = original_mesh.deep_copy()
6565
overall_field = dpf.fields_factory.create_3d_vector_field(1, dpf.locations.overall)
6666
overall_field.append(disp, 1)
@@ -138,7 +138,8 @@ def displace_mesh(original_mesh: dpf.MeshInfo, disp: list) -> dpf.MeshedRegion:
138138
# inlets and outlets of the model. Face results defined on individual zones need
139139
# the connection of the mesh pin to retrieve their right mesh_support. In particular,
140140
# the connected entity should be a ``MeshesContainer`` labelled on zone. This is the
141-
# output from the meshes_provider operator, as seen in :ref:`ref_fluids_mesh`
141+
# output from the meshes_provider operator, as seen in :ref:`ref_fluids_mesh` .
142+
142143
in_sco = dpf.Scoping(ids=[3], location=dpf.locations.zone)
143144
in_meshes = dpf.operators.mesh.meshes_provider(
144145
streams_container=streams, region_scoping=in_sco
@@ -189,7 +190,7 @@ def displace_mesh(original_mesh: dpf.MeshInfo, disp: list) -> dpf.MeshedRegion:
189190
# and exported to an Elemental ``Field`` (thus, the behavior for Elemental results
190191
# is replicated). ElementalAndFaces results do not bring their ``MeshSupport`` by
191192
# default, and thus the mesh input can be employed to connect the MeshedRegion
192-
# and display the result
193+
# and display the result.
193194

194195
print(rinfo.available_results[11])
195196
v = dpf.operators.result.velocity(streams_container=streams, mesh=whole_mesh).eval()

src/ansys/dpf/core/dpf_operator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def connect(self, pin, inpt, pin_out=0):
205205
Number of the input pin.
206206
207207
inpt : str, int, double, bool, list[int], list[float], Field, FieldsContainer, Scoping,
208-
ScopingsContainer, MeshedRegion, MeshesContainer, DataSources, CyclicSupport, Outputs
208+
ScopingsContainer, MeshedRegion, MeshesContainer, DataSources, CyclicSupport, dict, Outputs
209209
Operator, os.PathLike Object to connect to.
210210
211211
pin_out : int, optional

src/ansys/dpf/core/mesh_info.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,19 @@ def number_nodes(self):
150150

151151
return self.generic_data_container.get_property("num_nodes")
152152

153+
@property
154+
def number_faces(self):
155+
"""
156+
Returns
157+
-------
158+
number_faces : int
159+
Number of faces of the mesh.
160+
"""
161+
if "num_faces" in self._generic_data_container.get_property_description():
162+
return self.generic_data_container.get_property("num_faces")
163+
else:
164+
return 0
165+
153166
@property
154167
def number_elements(self):
155168
"""

tests/test_mesh_info.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def test_set_get_num_of(server_type):
9090
num_elements = 2
9191
mesh_info.number_elements = 2
9292
assert mesh_info.number_elements == num_elements
93+
assert mesh_info.number_faces == 0
9394

9495

9596
@pytest.mark.skipif(
@@ -161,29 +162,32 @@ def test_output_mesh_info_provider_fluent(server_clayer):
161162

162163
# """************************ NUMBER OF CELLS/FACES/ZONES ************************"""
163164
num_cells = mesh_info_out.get_property("num_cells")
165+
num_cells2 = mesh_info_out.number_elements
164166
num_faces = mesh_info_out.get_property("num_faces")
167+
num_faces2 = mesh_info_out.number_faces
165168
num_nodes = mesh_info_out.get_property("num_nodes")
166169

167170
assert num_cells == 1344
171+
assert num_cells2 == 1344
168172
assert num_faces == 2773
173+
assert num_faces2 == 2773
169174
assert num_nodes == 1430
170175

171176
# """************************ BODIES ************************"""
172-
"""
173177
# ************ Name ************
174-
body_names = mesh_info_out.get_property("body_name")
178+
body_names = mesh_info_out.get_property("body_names")
175179

176180
body_names_value = body_names._get_data()
177181

178182
assert len(body_names_value) == 1
179183
assert body_names_value[0] == "fluid-1"
180-
"""
184+
181185
# """************ Scoping ************"""
182-
body_scoping = mesh_info_out.get_property("body_scoping")
186+
body_scoping = mesh_info_out.body_scoping
183187

184188
assert body_scoping.size == 1
185189
assert body_scoping[0] == 1
186-
"""
190+
187191
# ************ Topology ************
188192
body_cell_topology = mesh_info_out.get_property("body_cell_topology")
189193
body_face_topology = mesh_info_out.get_property("body_face_topology")
@@ -194,16 +198,15 @@ def test_output_mesh_info_provider_fluent(server_clayer):
194198
body_face_topology_value = body_face_topology._get_data()
195199

196200
assert body_cell_topology_scoping.size == 1
197-
assert body_face_topology_scoping.size == 5
201+
assert body_face_topology_scoping.size == 1
198202
assert body_cell_topology_scoping[0] == 1
199203
assert body_face_topology_scoping[0] == 1
200204
assert body_cell_topology_value[0] == 1
201205
assert body_face_topology_value[0] == 3
202-
"""
206+
203207
# """************************ ZONES ************************"""
204-
"""
205208
# ************ Name ************
206-
zone_names = mesh_info_out.get_property("zone_name")
209+
zone_names = mesh_info_out.get_property("zone_names")
207210

208211
zone_names_value = zone_names._get_data()
209212

@@ -213,9 +216,9 @@ def test_output_mesh_info_provider_fluent(server_clayer):
213216
assert zone_names_value[2] == "symmetry-4"
214217
assert zone_names_value[3] == "pressure-outlet-5"
215218
assert zone_names_value[5] == "velocity-inlet-7"
216-
"""
219+
217220
# """************ Scoping ************"""
218-
zone_scoping = mesh_info_out.get_property("zone_scoping")
221+
zone_scoping = mesh_info_out.zone_scoping
219222

220223
assert zone_scoping.size == 6
221224
assert zone_scoping[0] == 1
@@ -237,7 +240,6 @@ def test_output_mesh_info_provider_fluent(server_clayer):
237240
assert number_of_element_in_zone_value[5] == 15
238241

239242
# """************ CELL ZONES ************"""
240-
241243
# """************ Name ************"""
242244
cell_zone_name = mesh_info_out.get_property("cell_zone_names")
243245

@@ -261,7 +263,6 @@ def test_output_mesh_info_provider_fluent(server_clayer):
261263
assert cell_zone_elements_value[0] == 1344
262264

263265
# """************ FACE ZONES ************"""
264-
265266
# """************ Name ************"""
266267
face_zone_names = mesh_info_out.get_property("face_zone_names")
267268

@@ -315,23 +316,22 @@ def test_output_mesh_info_provider_flprj(fluent_axial_comp, server_clayer):
315316
assert num_nodes == 16660
316317

317318
# """************************ BODIES ************************"""
318-
"""
319319
# ************ Name ************
320-
body_names = res.get_property("body_name")
320+
body_names = res.body_names
321321

322322
body_names_value = body_names._get_data()
323323

324324
assert len(body_names_value) == 2
325325
assert body_names_value[0] == "fluid-rotor"
326326
assert body_names_value[1] == "fluid-stator"
327-
"""
327+
328328
# """************ Scoping ************"""
329329
body_scoping = res.get_property("body_scoping")
330330

331331
assert body_scoping.size == 2
332332
assert body_scoping[0] == 13
333333
assert body_scoping[1] == 28
334-
"""
334+
335335
# ************ Topology ************
336336
body_cell_topology = res.get_property("body_cell_topology")
337337
body_face_topology = res.get_property("body_face_topology")
@@ -342,16 +342,15 @@ def test_output_mesh_info_provider_flprj(fluent_axial_comp, server_clayer):
342342
body_face_topology_value = body_face_topology._get_data()
343343

344344
assert body_cell_topology_scoping.size == 2
345-
assert body_face_topology_scoping.size == 24
345+
assert body_face_topology_scoping.size == 2
346346
assert body_cell_topology_scoping[0] == 13
347347
assert body_face_topology_scoping[0] == 13
348348
assert body_cell_topology_value[0] == 13
349349
assert body_face_topology_value[0] == 2
350-
"""
350+
351351
# """************************ ZONES ************************"""
352-
"""
353352
# ************ Name ************
354-
zone_names = res.get_property("zone_name")
353+
zone_names = res.zone_names
355354

356355
zone_names_value = zone_names._get_data()
357356

@@ -364,7 +363,7 @@ def test_output_mesh_info_provider_flprj(fluent_axial_comp, server_clayer):
364363
assert zone_names_value[18] == "stator-blade-1"
365364
assert zone_names_value[22] == "stator-per-2"
366365
assert zone_names_value[25] == "stator-per-1-shadow"
367-
"""
366+
368367
# """************ Scoping ************"""
369368
zone_scoping = res.get_property("zone_scoping")
370369

0 commit comments

Comments
 (0)