.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials\mesh\explore_mesh.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_tutorials_mesh_explore_mesh.py: .. _ref_tutorials_explore_mesh: Explore a mesh ============== :bdg-mapdl:`MAPDL` :bdg-lsdyna:`LSDYNA` :bdg-fluent:`Fluent` :bdg-cfx:`CFX` This tutorial explains how to access a mesh data and metadata so it can be manipulated. The mesh object in DPF is a :class:`MeshedRegion`. You can obtain a ``MeshedRegion`` by creating your own from scratch or by getting it from a result file. For more information, see the :ref:`ref_tutorials_create_a_mesh_from_scratch` and :ref:`ref_tutorials_get_mesh_from_result_file` tutorials. .. GENERATED FROM PYTHON SOURCE LINES 43-45 Import the necessary modules ----------------------------- .. GENERATED FROM PYTHON SOURCE LINES 45-49 .. code-block:: Python from ansys.dpf import core as dpf from ansys.dpf.core import examples, operators as ops .. GENERATED FROM PYTHON SOURCE LINES 50-57 Define the mesh --------------- For this tutorial, we get a :class:`MeshedRegion` from a result file. For more information see the :ref:`ref_tutorials_get_mesh_from_result_file` tutorial. .. GENERATED FROM PYTHON SOURCE LINES 59-60 MAPDL .. GENERATED FROM PYTHON SOURCE LINES 60-64 .. code-block:: Python result_file_path_1 = examples.find_static_rst() model_1 = dpf.Model(data_sources=result_file_path_1) meshed_region_1 = model_1.metadata.meshed_region .. GENERATED FROM PYTHON SOURCE LINES 65-66 LS-DYNA .. GENERATED FROM PYTHON SOURCE LINES 66-74 .. code-block:: Python result_file_path_2 = examples.download_d3plot_beam() ds_2 = dpf.DataSources() ds_2.set_result_file_path(filepath=result_file_path_2[0], key="d3plot") ds_2.add_file_path(filepath=result_file_path_2[3], key="actunits") model_2 = dpf.Model(data_sources=ds_2) meshed_region_2 = model_2.metadata.meshed_region .. GENERATED FROM PYTHON SOURCE LINES 75-76 Fluent .. GENERATED FROM PYTHON SOURCE LINES 76-81 .. code-block:: Python result_file_path_3 = examples.download_fluent_axial_comp()["flprj"] model_3 = dpf.Model(data_sources=result_file_path_3) meshed_region_3 = model_3.metadata.meshed_region .. GENERATED FROM PYTHON SOURCE LINES 82-83 CFX .. GENERATED FROM PYTHON SOURCE LINES 83-88 .. code-block:: Python result_file_path_4 = examples.download_cfx_mixing_elbow() model_4 = dpf.Model(data_sources=result_file_path_4) meshed_region_4 = model_4.metadata.meshed_region .. GENERATED FROM PYTHON SOURCE LINES 89-110 Explore the mesh data ---------------------- Access the mesh data by manipulating the ``MeshedRegion`` object methods. The mesh data includes: - Unit - Nodes, elements, and faces - Named selections The :attr:`MeshedRegion.nodes`, :attr:`MeshedRegion.elements`, :attr:`MeshedRegion.faces`, and :attr:`MeshedRegion.named_selections` properties return corresponding DPF objects: :class:`Nodes`, :class:`Elements`, :class:`Faces`, and :class:`Scoping`. Here, we explore the data about the mesh nodes for each solver. .. GENERATED FROM PYTHON SOURCE LINES 110-115 .. code-block:: Python nodes_1 = meshed_region_1.nodes print("Object type: ", type(nodes_1), "\n") print("Nodes (MAPDL): ", nodes_1) .. rst-class:: sphx-glr-script-out .. code-block:: none Object type: Nodes (MAPDL): DPF Node collection with 81 nodes .. GENERATED FROM PYTHON SOURCE LINES 116-120 .. code-block:: Python nodes_2 = meshed_region_2.nodes print("Nodes (LSDYNA): ", nodes_2) .. rst-class:: sphx-glr-script-out .. code-block:: none Nodes (LSDYNA): DPF Node collection with 1940 nodes .. GENERATED FROM PYTHON SOURCE LINES 121-125 .. code-block:: Python nodes_3 = meshed_region_3.nodes print("Nodes (Fluent): ", nodes_3) .. rst-class:: sphx-glr-script-out .. code-block:: none Nodes (Fluent): DPF Node collection with 16660 nodes .. GENERATED FROM PYTHON SOURCE LINES 126-130 .. code-block:: Python nodes_4 = meshed_region_4.nodes print("Nodes (CFX): ", nodes_4) .. rst-class:: sphx-glr-script-out .. code-block:: none Nodes (CFX): DPF Node collection with 6219 nodes .. GENERATED FROM PYTHON SOURCE LINES 131-139 Get the mesh bounding box -------------------------- Use the :attr:`MeshedRegion.bounding_box` property to get the bounding box. It is a 6D :class:`Field` with 1 entity containing the bounding box data in the format ``[x_min, y_min, z_min, x_max, y_max, z_max]``. .. GENERATED FROM PYTHON SOURCE LINES 139-152 .. code-block:: Python bbox_1 = meshed_region_1.bounding_box print("Bounding box (MAPDL): ", bbox_1) bbox_2 = meshed_region_2.bounding_box print("Bounding box (LSDYNA): ", bbox_2) bbox_3 = meshed_region_3.bounding_box print("Bounding box (Fluent): ", bbox_3) bbox_4 = meshed_region_4.bounding_box print("Bounding box (CFX): ", bbox_4) .. rst-class:: sphx-glr-script-out .. code-block:: none Bounding box (MAPDL): DPF bounding_box Field Location: overall Unit: m 1 entities Data: 6 components and 1 elementary data IDs data(m) ------------ ---------- 0 0.000000e+00 3.000000e-02 0.000000e+00 3.000000e-02 6.000000e-02 3.000000e-02 Bounding box (LSDYNA): DPF bounding_box Field Location: overall Unit: mm 1 entities Data: 6 components and 1 elementary data IDs data(mm) ------------ ---------- 0 -1.500000e+02 -1.500000e+02 0.000000e+00 1.500000e+02 1.500000e+02 1.010000e+02 Bounding box (Fluent): DPF bounding_box Field Location: overall Unit: m 1 entities Data: 6 components and 1 elementary data IDs data(m) ------------ ---------- 0 -5.146646e-02 -1.041350e-01 -6.350001e-02 2.717609e-02 -5.315754e-02 1.847001e-02 Bounding box (CFX): DPF bounding_box Field Location: overall Unit: m 1 entities Data: 6 components and 1 elementary data IDs data(m) ------------ ---------- 0 -5.000000e-01 -1.000000e+00 0.000000e+00 5.000000e-01 6.000000e+00 6.500000e+00 .. GENERATED FROM PYTHON SOURCE LINES 153-158 Explore the mesh metadata -------------------------- Access the mesh metadata by manipulating the ``MeshedRegion`` object properties. Check which metadata properties are available for each result file. .. GENERATED FROM PYTHON SOURCE LINES 158-171 .. code-block:: Python available_props_1 = meshed_region_1.available_property_fields print("Available properties (MAPDL): ", available_props_1) available_props_2 = meshed_region_2.available_property_fields print("Available properties (LSDYNA): ", available_props_2) available_props_3 = meshed_region_3.available_property_fields print("Available properties (Fluent): ", available_props_3) available_props_4 = meshed_region_4.available_property_fields print("Available properties (CFX): ", available_props_4) .. rst-class:: sphx-glr-script-out .. code-block:: none Available properties (MAPDL): ['connectivity', 'elprops', 'eltype', 'apdl_element_type', 'section', 'mat'] Available properties (LSDYNA): ['connectivity', 'eltype', 'mat'] Available properties (Fluent): ['connectivity', 'eltype', 'faces_type', 'faces_nodes_connectivity', 'elements_faces_connectivity', 'elements_faces_reversed'] Available properties (CFX): ['connectivity', 'eltype'] .. GENERATED FROM PYTHON SOURCE LINES 172-177 Extract a specific property — the element types for each mesh. The element type is given as a number. See :class:`element_types` for the corresponding element names. .. GENERATED FROM PYTHON SOURCE LINES 177-189 .. code-block:: Python el_types_1 = meshed_region_1.elements.element_types_field print("Element types (MAPDL): ", el_types_1) el_types_2 = meshed_region_2.property_field(property_name="eltype") print("Element types (LSDYNA): ", el_types_2) el_types_3 = meshed_region_3.property_field(property_name="eltype") print("Element types (Fluent): ", el_types_3) el_types_4 = meshed_region_4.property_field(property_name="eltype") print("Element types (CFX): ", el_types_4) .. rst-class:: sphx-glr-script-out .. code-block:: none Element types (MAPDL): DPF Property Field 8 entities Data: 1 components and 8 elementary data Elemental IDs data ------------ ---------- 5 1 6 1 1 1 ... Element types (LSDYNA): DPF Property Field 2056 entities Data: 1 components and 2056 elementary data Elemental IDs data ------------ ---------- 257 11 258 11 259 11 ... Element types (Fluent): DPF Property Field 13856 entities Data: 1 components and 13856 elementary data Elemental IDs data ------------ ---------- 1 11 2 11 3 11 ... Element types (CFX): DPF Property Field 15695 entities Data: 1 components and 15695 elementary data Elemental IDs data ------------ ---------- 1 10 2 10 3 10 ... .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 6.997 seconds) .. _sphx_glr_download_tutorials_mesh_explore_mesh.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: explore_mesh.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: explore_mesh.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: explore_mesh.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_