Split a mesh#
MAPDL LSDYNA Fluent CFX
This tutorial shows how to split a mesh on a given property.
There are two approaches to accomplish this goal:
Use the split_mesh operator to split a already existing MeshedRegion;
Split the mesh scoping and create the split MeshedRegion objects.
Download tutorial as Python script
Download tutorial as Jupyter notebook
Define the mesh#
The mesh object in DPF is a |MeshedRegion|. You can obtain a |MeshedRegion| by creating your own from scratch or by getting it from a result file. For more information check the Create a mesh from scratch and Get a mesh from a result file tutorials.
For this tutorial, we get a |MeshedRegion| from a result file. You can use one available in the |Examples| module. For more information see the Get a mesh from a result file tutorial.
# Import the ``ansys.dpf.core`` module
from ansys.dpf import core as dpf
# Import the examples module
from ansys.dpf.core import examples
# Import the operators module
from ansys.dpf.core import operators as ops
# Define the result file path
result_file_path_1 = examples.find_multishells_rst()
# Create the model
model_1 = dpf.Model(data_sources=result_file_path_1)
# Get the mesh
meshed_region_1 = model_1.metadata.meshed_region
# Import the ``ansys.dpf.core`` module
from ansys.dpf import core as dpf
# Import the examples module
from ansys.dpf.core import examples
# Import the operators module
from ansys.dpf.core import operators as ops
# Define the result file path
result_file_path_2 = examples.download_d3plot_beam()
# Create the DataSources object
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")
# Create the model
model_2 = dpf.Model(data_sources=ds_2)
# Get the mesh
meshed_region_2 = model_2.metadata.meshed_region
# Import the ``ansys.dpf.core`` module
from ansys.dpf import core as dpf
# Import the examples module
from ansys.dpf.core import examples
# Import the operators module
from ansys.dpf.core import operators as ops
# Define the result file path
result_file_path_3 = examples.download_fluent_axial_comp()["flprj"]
# Create the model
model_3 = dpf.Model(data_sources=result_file_path_3)
# Get the mesh
meshed_region_3 = model_3.metadata.meshed_region
# Import the ``ansys.dpf.core`` module
from ansys.dpf import core as dpf
# Import the examples module
from ansys.dpf.core import examples
# Import the operators module
from ansys.dpf.core import operators as ops
# Define the result file path
result_file_path_4 = examples.download_cfx_mixing_elbow()
# Create the model
model_4 = dpf.Model(data_sources=result_file_path_4)
# Get the mesh
meshed_region_4 = model_4.metadata.meshed_region
First approach#
This approach consists in splitting an already existing |MeshedRegion| based on a given property. To accomplish
that end, you must use the split_mesh operator. Currently you can split a mesh by material or eltype.
The split mesh parts are stored in the DPF collection called |MeshesContainer|, where they are ordered by labels.
When you use the split_mesh operator, each split mesh part has two different labels:
A “body” label
A label with the property used to split the mesh
Here, we split the |MeshedRegion| by material.
# Split the mesh by material
meshes_11 = ops.mesh.split_mesh(mesh=meshed_region_1, property="mat").eval()
# Print the meshes
print(meshes_11)
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 the mesh by material
meshes_21 = ops.mesh.split_mesh(mesh=meshed_region_2, property="mat").eval()
# Print the meshes
print(meshes_21)
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 the mesh by material
meshes_31 = ops.mesh.split_mesh(mesh=meshed_region_3, property="mat").eval()
# Print the meshes
print(meshes_31)
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 the mesh by material
meshes_41 = ops.mesh.split_mesh(mesh=meshed_region_4, property="mat").eval()
# Print the meshes
print(meshes_41)
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.
Second approach#
This approach consists in splitting the |Scoping| of a given |MeshedRegion| based on a given property and then creating a new |MeshedRegion| for each split |Scoping|.
To accomplish this goal you must follow these steps:
- Use the
split_on_property_typeoperator to split the mesh |Scoping|. This operator splits a |Scoping| on a given property (elshape and/or material, since 2025R1 it supports any scalar property field name contained in the mesh property fields). The split |Scoping| is stored in the DPF collection called |ScopingsContainer|, where they are ordered by labels. In this case, you get labels with the property used to split the |Scoping|.
- Use the
- Create the split |MeshedRegion| objects using the
from_scopingsoperator for the |Scoping| of interest. The split parts are stored in the DPF collection called |MeshesContainer| where they are also ordered by labels. These labels are corresponding to the “mat” labels gotten with the
split_on_property_typeoperator.
- Create the split |MeshedRegion| objects using the
Here, we split the mesh scoping by material and create a |MeshedRegion| for all the split |Scoping| in the |ScopingsContainer|.
# Define the scoping split by material
split_scoping_1 = ops.scoping.split_on_property_type(mesh=meshed_region_1, label1="mat").eval()
# Get the split meshes
meshes_12 = ops.mesh.from_scopings(scopings_container=split_scoping_1, mesh=meshed_region_1).eval()
# Print the meshes
print(meshes_12)
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.
# Define the scoping split by material
split_scoping_2 = ops.scoping.split_on_property_type(mesh=meshed_region_2, label1="mat").eval()
# Get the split meshes
meshes_22 = ops.mesh.from_scopings(scopings_container=split_scoping_2, mesh=meshed_region_2).eval()
# Print the meshes
print(meshes_22)
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.
# Define the scoping split by material
split_scoping_3 = ops.scoping.split_on_property_type(mesh=meshed_region_3, label1="mat").eval()
# Get the split meshes
meshes_32 = ops.mesh.from_scopings(scopings_container=split_scoping_3, mesh=meshed_region_3).eval()
# Print the meshes
print(meshes_32)
DPF Meshes Container
with 1 mesh(es)
defined on labels: mat
with:
- mesh 0 {mat: -1, } with 16660 nodes and 13856 elements.
# Define the scoping split by material
split_scoping_4 = ops.scoping.split_on_property_type(mesh=meshed_region_4, label1="mat").eval()
# Get the split meshes
meshes_42 = ops.mesh.from_scopings(scopings_container=split_scoping_4, mesh=meshed_region_4).eval()
# Print the meshes
print(meshes_42)
DPF Meshes Container
with 1 mesh(es)
defined on labels: mat
with:
- mesh 0 {mat: -1, } with 6219 nodes and 15695 elements.