Skip to content

Add more coverage for MeshInfo and rev. comments from previous PR #1057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions examples/12-fluids/00-fluids_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
Explore Fluids models
------------------------------------------------------

This example shows how to explore Ansys Fluent and Ansys CFX models employing
This example demonstrates how to explore Ansys Fluent and Ansys CFX models employing
the ``MeshInfo`` and ``ResultInfo``.
"""

###############################################################################
# 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
# model. Import the result file and create a model.

import ansys.dpf.core as dpf
from ansys.dpf.core import examples
Expand All @@ -28,7 +28,7 @@
# 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``
# the available information in the ``MeshInfo`` .

minfo = model.metadata.mesh_info
print(minfo)
Expand All @@ -53,12 +53,12 @@
# 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
# each body is limited by several face zones.

print(minfo.get_property("body_face_topology"))

###############################################################################
# The cell and face zone ids shown in the previous PropertyFields can be mapped
# 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.
Expand All @@ -68,13 +68,13 @@

###############################################################################
# All zone names (regardless of them being cell or face zones) are exported to
# the "zone_names" ``StringField``
# the "zone_names" ``StringField`` .

print(minfo.get_property("zone_names"))

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

print(minfo.get_property("body_scoping"))
print(minfo.get_property("cell_zone_scoping"))
Expand Down Expand Up @@ -111,7 +111,7 @@
# 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
# Import the result file and create a model.

path = examples.download_cfx_heating_coil()
ds = dpf.DataSources()
Expand All @@ -123,7 +123,7 @@
# Exploring the mesh
# ~~~~~~~~~~~~~~~~~~
# If once again we explore the MeshInfo, we can see that the same information is
# readily available
# readily available.

minfo = model.metadata.mesh_info
print(minfo)
Expand All @@ -141,12 +141,12 @@
print(minfo.get_property("body_cell_topology"))

###############################################################################
# You can also explore the face zone IDs in each body
# You can also explore the face zone IDs in each body.

print(minfo.get_property("body_face_topology"))

###############################################################################
# The cell and face zone names are readily available
# The cell and face zone names are readily available.

print(minfo.get_property("cell_zone_names"))
print(minfo.get_property("face_zone_names"))
Expand All @@ -155,7 +155,7 @@
# Exploring the results
# ~~~~~~~~~~~~~~~~~~~~~
# By exploring the ResultInfo we can see that all CFX variables are exported to
# the Nodes
# the Nodes.

rinfo = model.metadata.result_info
print(rinfo)
Expand Down
11 changes: 6 additions & 5 deletions examples/12-fluids/02-fluids_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# Exploring Ansys Fluent results
# ------------------------------
# This example demonstrates how you can explore Ansys Fluent results. Import
# the result file and explore the available results with the ``ResultInfo``
# the result file and explore the available results with the ``ResultInfo`` .

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

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


def displace_mesh(original_mesh: dpf.MeshInfo, disp: list) -> dpf.MeshedRegion:
def displace_mesh(original_mesh: dpf.MeshedRegion, disp: list) -> dpf.MeshedRegion:
new_mesh = original_mesh.deep_copy()
overall_field = dpf.fields_factory.create_3d_vector_field(1, dpf.locations.overall)
overall_field.append(disp, 1)
Expand Down Expand Up @@ -138,7 +138,8 @@ def displace_mesh(original_mesh: dpf.MeshInfo, disp: list) -> dpf.MeshedRegion:
# inlets and outlets of the model. Face results defined on individual zones need
# the connection of the mesh pin to retrieve their right mesh_support. In particular,
# the connected entity should be a ``MeshesContainer`` labelled on zone. This is the
# output from the meshes_provider operator, as seen in :ref:`ref_fluids_mesh`
# output from the meshes_provider operator, as seen in :ref:`ref_fluids_mesh` .

in_sco = dpf.Scoping(ids=[3], location=dpf.locations.zone)
in_meshes = dpf.operators.mesh.meshes_provider(
streams_container=streams, region_scoping=in_sco
Expand Down Expand Up @@ -189,7 +190,7 @@ def displace_mesh(original_mesh: dpf.MeshInfo, disp: list) -> dpf.MeshedRegion:
# and exported to an Elemental ``Field`` (thus, the behavior for Elemental results
# is replicated). ElementalAndFaces results do not bring their ``MeshSupport`` by
# default, and thus the mesh input can be employed to connect the MeshedRegion
# and display the result
# and display the result.

print(rinfo.available_results[11])
v = dpf.operators.result.velocity(streams_container=streams, mesh=whole_mesh).eval()
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/dpf/core/dpf_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def connect(self, pin, inpt, pin_out=0):
Number of the input pin.

inpt : str, int, double, bool, list[int], list[float], Field, FieldsContainer, Scoping,
ScopingsContainer, MeshedRegion, MeshesContainer, DataSources, CyclicSupport, Outputs
ScopingsContainer, MeshedRegion, MeshesContainer, DataSources, CyclicSupport, dict, Outputs
Operator, os.PathLike Object to connect to.

pin_out : int, optional
Expand Down
13 changes: 13 additions & 0 deletions src/ansys/dpf/core/mesh_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ def number_nodes(self):

return self.generic_data_container.get_property("num_nodes")

@property
def number_faces(self):
"""
Returns
-------
number_faces : int
Number of faces of the mesh.
"""
if "num_faces" in self._generic_data_container.get_property_description():
return self.generic_data_container.get_property("num_faces")
else:
return 0

@property
def number_elements(self):
"""
Expand Down
42 changes: 20 additions & 22 deletions tests/test_mesh_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,29 +161,32 @@ def test_output_mesh_info_provider_fluent(server_clayer):

# """************************ NUMBER OF CELLS/FACES/ZONES ************************"""
num_cells = mesh_info_out.get_property("num_cells")
num_cells2 = mesh_info_out.number_elements
num_faces = mesh_info_out.get_property("num_faces")
num_faces2 = mesh_info_out.number_faces
num_nodes = mesh_info_out.get_property("num_nodes")

assert num_cells == 1344
assert num_cells2 == 1344
assert num_faces == 2773
assert num_faces2 == 2773
assert num_nodes == 1430

# """************************ BODIES ************************"""
"""
# ************ Name ************
body_names = mesh_info_out.get_property("body_name")
body_names = mesh_info_out.get_property("body_names")

body_names_value = body_names._get_data()

assert len(body_names_value) == 1
assert body_names_value[0] == "fluid-1"
"""

# """************ Scoping ************"""
body_scoping = mesh_info_out.get_property("body_scoping")
body_scoping = mesh_info_out.body_scoping

assert body_scoping.size == 1
assert body_scoping[0] == 1
"""

# ************ Topology ************
body_cell_topology = mesh_info_out.get_property("body_cell_topology")
body_face_topology = mesh_info_out.get_property("body_face_topology")
Expand All @@ -194,16 +197,15 @@ def test_output_mesh_info_provider_fluent(server_clayer):
body_face_topology_value = body_face_topology._get_data()

assert body_cell_topology_scoping.size == 1
assert body_face_topology_scoping.size == 5
assert body_face_topology_scoping.size == 1
assert body_cell_topology_scoping[0] == 1
assert body_face_topology_scoping[0] == 1
assert body_cell_topology_value[0] == 1
assert body_face_topology_value[0] == 3
"""

# """************************ ZONES ************************"""
"""
# ************ Name ************
zone_names = mesh_info_out.get_property("zone_name")
zone_names = mesh_info_out.get_property("zone_names")

zone_names_value = zone_names._get_data()

Expand All @@ -213,9 +215,9 @@ def test_output_mesh_info_provider_fluent(server_clayer):
assert zone_names_value[2] == "symmetry-4"
assert zone_names_value[3] == "pressure-outlet-5"
assert zone_names_value[5] == "velocity-inlet-7"
"""

# """************ Scoping ************"""
zone_scoping = mesh_info_out.get_property("zone_scoping")
zone_scoping = mesh_info_out.zone_scoping

assert zone_scoping.size == 6
assert zone_scoping[0] == 1
Expand All @@ -237,7 +239,6 @@ def test_output_mesh_info_provider_fluent(server_clayer):
assert number_of_element_in_zone_value[5] == 15

# """************ CELL ZONES ************"""

# """************ Name ************"""
cell_zone_name = mesh_info_out.get_property("cell_zone_names")

Expand All @@ -261,7 +262,6 @@ def test_output_mesh_info_provider_fluent(server_clayer):
assert cell_zone_elements_value[0] == 1344

# """************ FACE ZONES ************"""

# """************ Name ************"""
face_zone_names = mesh_info_out.get_property("face_zone_names")

Expand Down Expand Up @@ -315,23 +315,22 @@ def test_output_mesh_info_provider_flprj(fluent_axial_comp, server_clayer):
assert num_nodes == 16660

# """************************ BODIES ************************"""
"""
# ************ Name ************
body_names = res.get_property("body_name")
body_names = res.body_names

body_names_value = body_names._get_data()

assert len(body_names_value) == 2
assert body_names_value[0] == "fluid-rotor"
assert body_names_value[1] == "fluid-stator"
"""

# """************ Scoping ************"""
body_scoping = res.get_property("body_scoping")

assert body_scoping.size == 2
assert body_scoping[0] == 13
assert body_scoping[1] == 28
"""

# ************ Topology ************
body_cell_topology = res.get_property("body_cell_topology")
body_face_topology = res.get_property("body_face_topology")
Expand All @@ -342,16 +341,15 @@ def test_output_mesh_info_provider_flprj(fluent_axial_comp, server_clayer):
body_face_topology_value = body_face_topology._get_data()

assert body_cell_topology_scoping.size == 2
assert body_face_topology_scoping.size == 24
assert body_face_topology_scoping.size == 2
assert body_cell_topology_scoping[0] == 13
assert body_face_topology_scoping[0] == 13
assert body_cell_topology_value[0] == 13
assert body_face_topology_value[0] == 2
"""

# """************************ ZONES ************************"""
"""
# ************ Name ************
zone_names = res.get_property("zone_name")
zone_names = res.zone_names

zone_names_value = zone_names._get_data()

Expand All @@ -364,7 +362,7 @@ def test_output_mesh_info_provider_flprj(fluent_axial_comp, server_clayer):
assert zone_names_value[18] == "stator-blade-1"
assert zone_names_value[22] == "stator-per-2"
assert zone_names_value[25] == "stator-per-1-shadow"
"""

# """************ Scoping ************"""
zone_scoping = res.get_property("zone_scoping")

Expand Down