diff --git a/examples/12-fluids/00-fluids_model.py b/examples/12-fluids/00-fluids_model.py index 6ac20ef051..79ce371174 100644 --- a/examples/12-fluids/00-fluids_model.py +++ b/examples/12-fluids/00-fluids_model.py @@ -4,7 +4,7 @@ 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``. """ @@ -12,7 +12,7 @@ # 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 @@ -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) @@ -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. @@ -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")) @@ -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() @@ -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) @@ -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")) @@ -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) diff --git a/examples/12-fluids/02-fluids_results.py b/examples/12-fluids/02-fluids_results.py index a6918fe07f..8bcb42f40b 100644 --- a/examples/12-fluids/02-fluids_results.py +++ b/examples/12-fluids/02-fluids_results.py @@ -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 @@ -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() @@ -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) @@ -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 @@ -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() diff --git a/src/ansys/dpf/core/dpf_operator.py b/src/ansys/dpf/core/dpf_operator.py index 99e4dd8826..d7d6111247 100644 --- a/src/ansys/dpf/core/dpf_operator.py +++ b/src/ansys/dpf/core/dpf_operator.py @@ -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 diff --git a/src/ansys/dpf/core/mesh_info.py b/src/ansys/dpf/core/mesh_info.py index 3ed2685a96..cbb71da4ef 100644 --- a/src/ansys/dpf/core/mesh_info.py +++ b/src/ansys/dpf/core/mesh_info.py @@ -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): """ diff --git a/tests/test_mesh_info.py b/tests/test_mesh_info.py index 2bab6b7bd2..5efe695dfe 100644 --- a/tests/test_mesh_info.py +++ b/tests/test_mesh_info.py @@ -90,6 +90,7 @@ def test_set_get_num_of(server_type): num_elements = 2 mesh_info.number_elements = 2 assert mesh_info.number_elements == num_elements + assert mesh_info.number_faces == 0 @pytest.mark.skipif( @@ -161,29 +162,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") @@ -194,16 +198,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() @@ -213,9 +216,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 @@ -237,7 +240,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") @@ -261,7 +263,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") @@ -315,23 +316,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") @@ -342,16 +342,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() @@ -364,7 +363,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")