Note
Go to the end to download the full example code.
Split a mesh#
MAPDL LSDYNA Fluent CFX
This tutorial shows how to split a mesh on a given property.
There are two approaches:
Use the split_mesh operator to split an already existing
MeshedRegion.Split the mesh scoping and create the split
MeshedRegionobjects.
Import the necessary modules#
from ansys.dpf import core as dpf
from ansys.dpf.core import examples, operators as ops
Define the mesh#
For this tutorial, we get a MeshedRegion from a result file for each solver.
For more information see the Get a mesh from a result file
tutorial.
MAPDL — use a multi-shell result file.
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
LS-DYNA
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
Fluent
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
CFX
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
First approach — use the split_mesh operator#
Use the
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
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.
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)
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.
Second approach — split the scoping then build meshes#
This approach:
Uses the
split_on_property_typeoperator to split the meshScopingon a given property. The split scoping is stored in aScopingsContainer, ordered by labels for the split property.Creates the split
MeshedRegionobjects using thefrom_scopingsoperator for eachScopingof interest. The split parts are stored in aMeshesContainer.
Here, we split the mesh scoping by material and create a MeshedRegion for all
split Scoping objects in the ScopingsContainer.
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)
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.
Total running time of the script: (1 minutes 2.014 seconds)