|
| 1 | +.. _ref_tutorials_read_mesh_metadata: |
| 2 | + |
| 3 | +====================== |
| 4 | +Read the mesh metadata |
| 5 | +====================== |
| 6 | + |
| 7 | +.. |MeshedRegion| replace:: :class:`MeshedRegion <ansys.dpf.core.meshed_region.MeshedRegion>` |
| 8 | +.. |Model| replace:: :class:`Model <ansys.dpf.core.model.Model>` |
| 9 | +.. |DataSources| replace:: :class:`Model <ansys.dpf.core.data_sources.DataSources>` |
| 10 | +.. |MeshInfo| replace:: :class:`MeshInfo <ansys.dpf.core.mesh_info.MeshInfo>` |
| 11 | + |
| 12 | +This tutorial explains how to read a mesh metadata (data about the elements, nodes, faces, region, zone ...) |
| 13 | +for LSDYNA, Fluent or CFX result files. |
| 14 | + |
| 15 | +The mesh object in DPF is a |MeshedRegion|. You can obtain a |MeshedRegion| by creating your |
| 16 | +own by scratch or by getting it from a result file. For more information check the |
| 17 | +:ref:`tutorials_create_a_mesh_from_scratch` and :ref:`tutorials_get_mesh_from_result_file` tutorials. |
| 18 | + |
| 19 | +We have the |MeshInfo| object to read metadata information before extracting the |MeshedRegion|. |
| 20 | +You can obtain this object by creating a |Model| with a result file. |
| 21 | + |
| 22 | +Define the |Model| |
| 23 | +------------------ |
| 24 | + |
| 25 | +Here we we will download result files available in our `Examples` package. |
| 26 | +For more information about how to import your result file in DPF check |
| 27 | +the :ref:`ref_tutorials_import_data` tutorial section. |
| 28 | + |
| 29 | +.. tab-set:: |
| 30 | + |
| 31 | + .. tab-item:: LSDYNA |
| 32 | + |
| 33 | + .. code-block:: python |
| 34 | +
|
| 35 | + # Import the ``ansys.dpf.core`` module, including examples files and the operators subpackage |
| 36 | + from ansys.dpf import core as dpf |
| 37 | + from ansys.dpf.core import examples |
| 38 | + from ansys.dpf.core import operators as ops |
| 39 | + # Define the result file |
| 40 | + result_file_path_2 = examples.download_d3plot_beam() |
| 41 | + # Create the DataSources object |
| 42 | + my_data_sources_2 = dpf.DataSources() |
| 43 | + my_data_sources_2.set_result_file_path(filepath=result_file_path_2[0], key="d3plot") |
| 44 | + my_data_sources_2.add_file_path(filepath=result_file_path_2[3], key="actunits") |
| 45 | + # Create the model |
| 46 | + my_model_2 = dpf.Model(data_sources=my_data_sources_2) |
| 47 | + # Get the mesh |
| 48 | + my_meshed_region_2 = my_model_2.metadata.meshed_region |
| 49 | +
|
| 50 | + .. tab-item:: Fluent |
| 51 | + |
| 52 | + .. code-block:: python |
| 53 | +
|
| 54 | + # Import the ``ansys.dpf.core`` module, including examples files and the operators subpackage |
| 55 | + from ansys.dpf import core as dpf |
| 56 | + from ansys.dpf.core import examples |
| 57 | + from ansys.dpf.core import operators as ops |
| 58 | + # Define the result file |
| 59 | + result_file_path_3 = examples.download_fluent_axial_comp()["flprj"] |
| 60 | + # Create the model |
| 61 | + my_model_3 = dpf.Model(data_sources=result_file_path_3) |
| 62 | + # Get the mesh |
| 63 | + my_meshed_region_3 = my_model_3.metadata.meshed_region |
| 64 | +
|
| 65 | + .. tab-item:: CFX |
| 66 | + |
| 67 | + .. code-block:: python |
| 68 | +
|
| 69 | + # Import the ``ansys.dpf.core`` module, including examples files and the operators subpackage |
| 70 | + from ansys.dpf import core as dpf |
| 71 | + from ansys.dpf.core import examples |
| 72 | + from ansys.dpf.core import operators as ops |
| 73 | + # Define the result file |
| 74 | + result_file_path_4 = examples.download_cfx_mixing_elbow() |
| 75 | + # Create the model |
| 76 | + my_model_4 = dpf.Model(data_sources=result_file_path_4) |
| 77 | + # Get the mesh |
| 78 | + my_meshed_region_4 = my_model_4.metadata.meshed_region |
| 79 | +
|
| 80 | +Read the mesh metadata |
| 81 | +---------------------- |
| 82 | + |
| 83 | +The |Model| is a helper designed to give shortcuts to access the analysis results |
| 84 | +metadata, by opening a DataSources or a Streams, and to instanciate results provider |
| 85 | +for it. |
| 86 | + |
| 87 | +From the |Model| you can access the |MeshedRegion| metadata information with the |MeshInfo| object. |
| 88 | +The mesh metadata information includes : |
| 89 | + |
| 90 | +- Properties; |
| 91 | +- Parts; |
| 92 | +- Faces; |
| 93 | +- Bodies; |
| 94 | +- Zones; |
| 95 | +- Number of nodes and elements; |
| 96 | +- Elements types. |
| 97 | + |
| 98 | +Get the the mesh metadata information and print the available ones: |
| 99 | + |
| 100 | +.. tab-set:: |
| 101 | + |
| 102 | + .. tab-item:: LSDYNA |
| 103 | + |
| 104 | + .. code-block:: python |
| 105 | +
|
| 106 | + # Get the mesh metadata information |
| 107 | + my_mesh_info_2 = my_model_2.metadata.mesh_info |
| 108 | + # Print the mesh metadata information |
| 109 | + print(my_mesh_info_2) |
| 110 | +
|
| 111 | + .. rst-class:: sphx-glr-script-out |
| 112 | + |
| 113 | + .. jupyter-execute:: |
| 114 | + :hide-code: |
| 115 | + |
| 116 | + # Import the ``ansys.dpf.core`` module, including examples files and the operators subpackage |
| 117 | + from ansys.dpf import core as dpf |
| 118 | + from ansys.dpf.core import examples |
| 119 | + from ansys.dpf.core import operators as ops |
| 120 | + # Define the result file |
| 121 | + result_file_path_2 = examples.download_d3plot_beam() |
| 122 | + # Create the DataSources object |
| 123 | + my_data_sources_2 = dpf.DataSources() |
| 124 | + my_data_sources_2.set_result_file_path(filepath=result_file_path_2[0], key="d3plot") |
| 125 | + my_data_sources_2.add_file_path(filepath=result_file_path_2[3], key="actunits") |
| 126 | + # Create the model |
| 127 | + my_model_2 = dpf.Model(data_sources=my_data_sources_2) |
| 128 | + # Get the mesh |
| 129 | + my_meshed_region_2 = my_model_2.metadata.meshed_region |
| 130 | + # Get the mesh metadata information |
| 131 | + my_mesh_info_2 = my_model_2.metadata.mesh_info |
| 132 | + # Print the mesh metadata information |
| 133 | + print(my_mesh_info_2) |
| 134 | + |
| 135 | + .. tab-item:: Fluent |
| 136 | + |
| 137 | + .. code-block:: python |
| 138 | +
|
| 139 | + # Get the mesh metadata information |
| 140 | + my_mesh_info_3 = my_model_3.metadata.mesh_info |
| 141 | + # Print the mesh metadata information |
| 142 | + print(my_mesh_info_3) |
| 143 | +
|
| 144 | + .. rst-class:: sphx-glr-script-out |
| 145 | + |
| 146 | + .. jupyter-execute:: |
| 147 | + :hide-code: |
| 148 | + |
| 149 | + # Define the result file |
| 150 | + result_file_path_3 = examples.download_fluent_axial_comp()["flprj"] |
| 151 | + # Create the model |
| 152 | + my_model_3 = dpf.Model(data_sources=result_file_path_3) |
| 153 | + # Get the mesh |
| 154 | + my_meshed_region_3 = my_model_3.metadata.meshed_region |
| 155 | + # Get the mesh metadata information |
| 156 | + my_mesh_info_3 = my_model_3.metadata.mesh_info |
| 157 | + # Print the mesh metadata information |
| 158 | + print(my_mesh_info_3) |
| 159 | + |
| 160 | + .. tab-item:: CFX |
| 161 | + |
| 162 | + .. code-block:: python |
| 163 | +
|
| 164 | + # Get the mesh metadata information |
| 165 | + my_mesh_info_4 = my_model_4.metadata.mesh_info |
| 166 | + # Print the mesh metadata information |
| 167 | + print(my_mesh_info_4) |
| 168 | +
|
| 169 | + .. rst-class:: sphx-glr-script-out |
| 170 | + |
| 171 | + .. jupyter-execute:: |
| 172 | + :hide-code: |
| 173 | + |
| 174 | + # Define the result file |
| 175 | + result_file_path_4 = examples.download_cfx_mixing_elbow() |
| 176 | + # Create the model |
| 177 | + my_model_4 = dpf.Model(data_sources=result_file_path_4) |
| 178 | + # Get the mesh |
| 179 | + my_meshed_region_4 = my_model_4.metadata.meshed_region |
| 180 | + # Get the mesh metadata information |
| 181 | + my_mesh_info_4 = my_model_4.metadata.mesh_info |
| 182 | + # Print the mesh metadata information |
| 183 | + print(my_mesh_info_4) |
| 184 | + |
| 185 | +You can extract each of those mesh information by manipulating the |MeshInfo| object properties. |
| 186 | +For example we can check the part names (for the LSDYNA result file) or the cell zone names |
| 187 | +(for the Fluent or CFX result files): |
| 188 | + |
| 189 | +.. tab-set:: |
| 190 | + |
| 191 | + .. tab-item:: LSDYNA |
| 192 | + |
| 193 | + .. code-block:: python |
| 194 | +
|
| 195 | + # Get the part names |
| 196 | + my_cell_zones_2 = my_mesh_info_2.get_property("part_names") |
| 197 | + print(my_cell_zones_2) |
| 198 | +
|
| 199 | + .. rst-class:: sphx-glr-script-out |
| 200 | + |
| 201 | + .. jupyter-execute:: |
| 202 | + :hide-code: |
| 203 | + |
| 204 | + # Get the part names |
| 205 | + my_cell_zones_2 = my_mesh_info_2.get_property("part_names") |
| 206 | + print(my_cell_zones_2) |
| 207 | + |
| 208 | + .. tab-item:: Fluent |
| 209 | + |
| 210 | + .. code-block:: python |
| 211 | +
|
| 212 | + # Get the cell zone names |
| 213 | + my_cell_zones_3 = my_mesh_info_3.get_property("cell_zone_names") |
| 214 | + print(my_cell_zones_3) |
| 215 | +
|
| 216 | + .. rst-class:: sphx-glr-script-out |
| 217 | + |
| 218 | + .. jupyter-execute:: |
| 219 | + :hide-code: |
| 220 | + |
| 221 | + # Get the cell zone names |
| 222 | + my_cell_zones_3 = my_mesh_info_3.get_property("cell_zone_names") |
| 223 | + print(my_cell_zones_3) |
| 224 | + |
| 225 | + .. tab-item:: CFX |
| 226 | + |
| 227 | + .. code-block:: python |
| 228 | +
|
| 229 | + # Get the cell zone names |
| 230 | + my_cell_zones_4 = my_mesh_info_4.get_property("cell_zone_names") |
| 231 | + print(my_cell_zones_4) |
| 232 | +
|
| 233 | + .. rst-class:: sphx-glr-script-out |
| 234 | + |
| 235 | + .. jupyter-execute:: |
| 236 | + :hide-code: |
| 237 | + |
| 238 | + # Get the cell zone names |
| 239 | + my_cell_zones_4 = my_mesh_info_4.get_property("cell_zone_names") |
| 240 | + print(my_cell_zones_4) |
| 241 | + |
| 242 | +For more information on reading a mesh from a LSDYNA, Fluent or CFX file check the examples sections: |
| 243 | +:ref:`examples_lsdyna`, :ref:`fluids_examples` and :ref:`examples_cfx`. |
0 commit comments