Get a mesh from a result file#
MAPDL LSDYNA Fluent CFX
This tutorial explains how to extract a mesh from a result file.
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.
Download tutorial as Python script
Download tutorial as Jupyter notebook
Import the result file#
First, import a result file. For this tutorial, you can use one available in the Examples
module.
For more information about how to import your own result file in DPF, see the Import Data
tutorials section.
Here, we create a DataSources
object so the data can be directly accessed by different
PyDPF-Core APIs. This object manages paths to their files.
# 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_static_rst()
# Create the DataSources object
ds_1 = dpf.DataSources(result_path=result_file_path_1)
# 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")
# 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 DataSources object
ds_3 = dpf.DataSources(result_path=result_file_path_3)
# 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 DataSources object
ds_4 = dpf.DataSources(result_path=result_file_path_4)
Get the mesh from the result file#
You can get the mesh from a result file by two methods:
Note
A Model
extracts a large amount of information by default (results, mesh and analysis data).
If using this helper takes a long time for processing the code, mind using a DataSources
object
and instantiating operators directly with it.
Using the DPF Model
#
The Model
is a helper designed to give shortcuts to access the analysis results
metadata and to instanciate results providers by opening a DataSources
or a Streams.
Get the MeshedRegion
by instantiating a Model
object and accessing its metadata.
# Create the Model
model_1 = dpf.Model(data_sources=ds_1)
# Get the mesh
meshed_region_11 = model_1.metadata.meshed_region
# Create the Model
model_2 = dpf.Model(data_sources=ds_2)
# Get the mesh
meshed_region_21 = model_2.metadata.meshed_region
# Create the Model
model_3 = dpf.Model(data_sources=ds_3)
# Get the mesh
meshed_region_31 = model_3.metadata.meshed_region
# Create the Model
model_4 = dpf.Model(data_sources=ds_4)
# Get the mesh
meshed_region_41 = model_4.metadata.meshed_region
Printing the MeshedRegion
displays the mesh dimensions:
Number of nodes and elements
Unit
Elements type
# Print the MeshedRegion
print(meshed_region_11)
DPF Meshed Region:
81 nodes
8 elements
Unit: m
With solid (3D) elements
# Print the MeshedRegion
print(meshed_region_21)
DPF Meshed Region:
1940 nodes
2056 elements
Unit: mm
With solid (3D) elements, beam (1D) elements
# Print the MeshedRegion
print(meshed_region_31)
DPF Meshed Region:
16660 nodes
13856 elements
44242 faces
Unit: m
With solid (3D) elements
# Print the MeshedRegion
print(meshed_region_41)
DPF Meshed Region:
6219 nodes
15695 elements
Unit: m
With solid (3D) elements
Using the mesh_provider
operator#
Get the MeshedRegion
by instantiating the mesh_provider
operator with the
DataSources
object as an argument.
# Get the mesh with the mesh_provider operator
meshed_region_12 = ops.mesh.mesh_provider(data_sources=ds_1).eval()
# Get the mesh with the mesh_provider operator
meshed_region_22 = ops.mesh.mesh_provider(data_sources=ds_2).eval()
# Get the mesh with the mesh_provider operator
meshed_region_32 = ops.mesh.mesh_provider(data_sources=ds_3).eval()
# Get the mesh with the mesh_provider operator
meshed_region_42 = ops.mesh.mesh_provider(data_sources=ds_4).eval()
Printing the MeshedRegion
displays the mesh dimensions:
Number of nodes and elements
Unit
Elements type
# Print the MeshedRegion
print(meshed_region_12)
DPF Meshed Region:
81 nodes
8 elements
Unit: m
With solid (3D) elements
# Print the MeshedRegion
print(meshed_region_22)
DPF Meshed Region:
1940 nodes
2056 elements
Unit: mm
With solid (3D) elements, beam (1D) elements
# Print the MeshedRegion
print(meshed_region_32)
DPF Meshed Region:
16660 nodes
13856 elements
44242 faces
Unit: m
With solid (3D) elements
# Print the MeshedRegion
print(meshed_region_42)
DPF Meshed Region:
6219 nodes
15695 elements
Unit: m
With solid (3D) elements