.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials\mesh\split_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_split_mesh.py: .. _ref_tutorials_split_mesh: Split a mesh ============ :bdg-mapdl:`MAPDL` :bdg-lsdyna:`LSDYNA` :bdg-fluent:`Fluent` :bdg-cfx:`CFX` This tutorial shows how to split a mesh on a given property. There are two approaches: - :ref:`Use the split_mesh operator ` to split an already existing :class:`MeshedRegion`. - :ref:`Split the mesh scoping ` and create the split ``MeshedRegion`` objects. .. GENERATED FROM PYTHON SOURCE LINES 42-44 Import the necessary modules ----------------------------- .. GENERATED FROM PYTHON SOURCE LINES 44-48 .. code-block:: Python from ansys.dpf import core as dpf from ansys.dpf.core import examples, operators as ops .. GENERATED FROM PYTHON SOURCE LINES 49-57 Define the mesh ---------------- For this tutorial, we get a ``MeshedRegion`` from a result file for each solver. For more information see the :ref:`ref_tutorials_get_mesh_from_result_file` tutorial. MAPDL — use a multi-shell result file. .. GENERATED FROM PYTHON SOURCE LINES 57-62 .. code-block:: Python result_file_path_1 = examples.find_multishells_rst() model_1 = dpf.Model(data_sources=result_file_path_1) meshed_region_1 = model_1.metadata.meshed_region .. GENERATED FROM PYTHON SOURCE LINES 63-64 LS-DYNA .. GENERATED FROM PYTHON SOURCE LINES 64-72 .. 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 73-74 Fluent .. GENERATED FROM PYTHON SOURCE LINES 74-79 .. 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 80-81 CFX .. GENERATED FROM PYTHON SOURCE LINES 81-86 .. 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 87-105 .. _ref_first_approach_split_mesh: First approach — use the ``split_mesh`` operator ------------------------------------------------- Use the :class:`split_mesh` operator to split an already existing ``MeshedRegion`` based on a given property. Currently you can split a mesh by material (``"mat"``) or element type (``"eltype"``). The split mesh parts are stored in a :class:`MeshesContainer`, ordered by ``labels``. When using the ``split_mesh`` operator, each split mesh part has two labels: a ``"body"`` label and a label for the property used to split the mesh. Here, we split the ``MeshedRegion`` by material. .. GENERATED FROM PYTHON SOURCE LINES 105-118 .. code-block:: Python meshes_11 = ops.mesh.split_mesh(mesh=meshed_region_1, property="mat").eval() print("Split mesh MAPDL:", meshes_11) meshes_21 = ops.mesh.split_mesh(mesh=meshed_region_2, property="mat").eval() print("Split mesh LSDYNA:", meshes_21) meshes_31 = ops.mesh.split_mesh(mesh=meshed_region_3, property="mat").eval() print("Split mesh Fluent:", meshes_31) meshes_41 = ops.mesh.split_mesh(mesh=meshed_region_4, property="mat").eval() print("Split mesh CFX:", meshes_41) .. rst-class:: sphx-glr-script-out .. code-block:: none Split mesh MAPDL: DPF Meshes Container with 12 mesh(es) defined on labels: body mat with: - mesh 0 {mat: 2, body: 1, } with 5072 nodes and 3086 elements. - mesh 1 {mat: 3, body: 2, } with 135 nodes and 112 elements. - mesh 2 {mat: 5, body: 3, } with 104 nodes and 34 elements. - mesh 3 {mat: 7, body: 4, } with 218 nodes and 105 elements. - mesh 4 {mat: 11, body: 5, } with 71 nodes and 22 elements. - mesh 5 {mat: 4, body: 6, } with 90 nodes and 70 elements. - mesh 6 {mat: 6, body: 7, } with 104 nodes and 34 elements. - mesh 7 {mat: 8, body: 8, } with 218 nodes and 105 elements. - mesh 8 {mat: 12, body: 9, } with 71 nodes and 22 elements. - mesh 9 {mat: 9, body: 10, } with 327 nodes and 165 elements. - mesh 10 {mat: 1, body: 11, } with 1782 nodes and 300 elements. - mesh 11 {mat: 10, body: 12, } with 327 nodes and 165 elements. Split mesh LSDYNA: DPF Meshes Container with 2 mesh(es) defined on labels: body mat with: - mesh 0 {mat: 2, body: 1, } with 1651 nodes and 1512 elements. - mesh 1 {mat: 1, body: 2, } with 289 nodes and 544 elements. Split mesh Fluent: DPF Meshes Container with 1 mesh(es) defined on labels: body mat with: - mesh 0 {mat: -1, body: 1, } with 16660 nodes and 13856 elements. Split mesh CFX: DPF Meshes Container with 1 mesh(es) defined on labels: body mat with: - mesh 0 {mat: -1, body: 1, } with 6219 nodes and 15695 elements. .. GENERATED FROM PYTHON SOURCE LINES 119-141 .. _ref_second_approach_split_mesh: Second approach — split the scoping then build meshes ------------------------------------------------------ This approach: 1. Uses the :class:`split_on_property_type` operator to split the mesh :class:`Scoping` on a given property. The split scoping is stored in a :class:`ScopingsContainer`, ordered by labels for the split property. 2. Creates the split ``MeshedRegion`` objects using the :class:`from_scopings` operator for each ``Scoping`` of interest. The split parts are stored in a ``MeshesContainer``. Here, we split the mesh scoping by material and create a ``MeshedRegion`` for all split ``Scoping`` objects in the ``ScopingsContainer``. .. GENERATED FROM PYTHON SOURCE LINES 141-157 .. code-block:: Python split_scoping_1 = ops.scoping.split_on_property_type(mesh=meshed_region_1, label1="mat").eval() meshes_12 = ops.mesh.from_scopings(scopings_container=split_scoping_1, mesh=meshed_region_1).eval() print("Split via scoping MAPDL:", meshes_12) split_scoping_2 = ops.scoping.split_on_property_type(mesh=meshed_region_2, label1="mat").eval() meshes_22 = ops.mesh.from_scopings(scopings_container=split_scoping_2, mesh=meshed_region_2).eval() print("Split via scoping LSDYNA:", meshes_22) split_scoping_3 = ops.scoping.split_on_property_type(mesh=meshed_region_3, label1="mat").eval() meshes_32 = ops.mesh.from_scopings(scopings_container=split_scoping_3, mesh=meshed_region_3).eval() print("Split via scoping Fluent:", meshes_32) split_scoping_4 = ops.scoping.split_on_property_type(mesh=meshed_region_4, label1="mat").eval() meshes_42 = ops.mesh.from_scopings(scopings_container=split_scoping_4, mesh=meshed_region_4).eval() print("Split via scoping CFX:", meshes_42) .. rst-class:: sphx-glr-script-out .. code-block:: none Split via scoping MAPDL: DPF Meshes Container with 12 mesh(es) defined on labels: mat with: - mesh 0 {mat: 2, } with 5072 nodes and 3086 elements. - mesh 1 {mat: 3, } with 135 nodes and 112 elements. - mesh 2 {mat: 5, } with 104 nodes and 34 elements. - mesh 3 {mat: 7, } with 218 nodes and 105 elements. - mesh 4 {mat: 11, } with 71 nodes and 22 elements. - mesh 5 {mat: 4, } with 90 nodes and 70 elements. - mesh 6 {mat: 6, } with 104 nodes and 34 elements. - mesh 7 {mat: 8, } with 218 nodes and 105 elements. - mesh 8 {mat: 12, } with 71 nodes and 22 elements. - mesh 9 {mat: 9, } with 327 nodes and 165 elements. - mesh 10 {mat: 1, } with 1782 nodes and 300 elements. - mesh 11 {mat: 10, } with 327 nodes and 165 elements. Split via scoping LSDYNA: DPF Meshes Container with 2 mesh(es) defined on labels: mat with: - mesh 0 {mat: 2, } with 1651 nodes and 1512 elements. - mesh 1 {mat: 1, } with 289 nodes and 544 elements. Split via scoping Fluent: DPF Meshes Container with 1 mesh(es) defined on labels: mat with: - mesh 0 {mat: -1, } with 16660 nodes and 13856 elements. Split via scoping CFX: DPF Meshes Container with 1 mesh(es) defined on labels: mat with: - mesh 0 {mat: -1, } with 6219 nodes and 15695 elements. .. rst-class:: sphx-glr-timing **Total running time of the script:** (1 minutes 3.883 seconds) .. _sphx_glr_download_tutorials_mesh_split_mesh.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: split_mesh.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: split_mesh.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: split_mesh.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_