Import a result file in DPF#
MAPDL LS-DYNA FLUENT CFX
This tutorial shows how to import a result file in DPF.
There are two approaches to import a result file in DPF:
Note
The 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.
Download tutorial as Python script
Download tutorial as Jupyter notebook
Define the result file path#
Both approaches need a file path to be defined. For this tutorial, you can use a result file available in
the Examples
module.
# 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 .rst result file path
result_file_path_11 = examples.find_static_rst()
# Define the modal superposition harmonic analysis (.mode, .rfrq and .rst) result files paths
result_file_path_12 = examples.download_msup_files_to_dict()
# Print the result files paths
print("Result file path 11:", "\n",result_file_path_11, "\n")
print("Result files paths 12:", "\n",result_file_path_12, "\n")
Result file path 11:
D:\ANSYSDev\Sandbox\pydpf-core\.tox\doc-html\Lib\site-packages\ansys\dpf\core\examples\result_files\static.rst
Result files paths 12:
{'rfrq': 'D:\\ANSYSDev\\Sandbox\\pydpf-core\\.tox\\doc-html\\Lib\\site-packages\\ansys\\dpf\\core\\examples\\result_files\\msup\\file.rfrq', 'mode': 'D:\\ANSYSDev\\Sandbox\\pydpf-core\\.tox\\doc-html\\Lib\\site-packages\\ansys\\dpf\\core\\examples\\result_files\\msup\\file.mode', 'rst': 'D:\\ANSYSDev\\Sandbox\\pydpf-core\\.tox\\doc-html\\Lib\\site-packages\\ansys\\dpf\\core\\examples\\result_files\\msup\\file.rst'}
# 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 .d3plot result files paths
result_file_path_21 = examples.download_d3plot_beam()
# Define the .binout result file path
result_file_path_22 = examples.download_binout_matsum()
# Print the result files paths
print("Result files paths 21:", "\n",result_file_path_21, "\n")
print("Result file path 22:", "\n",result_file_path_22, "\n")
Result files paths 21:
['D:\\ANSYSDev\\Sandbox\\pydpf-core\\.tox\\doc-html\\Lib\\site-packages\\ansys\\dpf\\core\\examples\\result_files\\d3plot_beam\\d3plot', 'D:\\ANSYSDev\\Sandbox\\pydpf-core\\.tox\\doc-html\\Lib\\site-packages\\ansys\\dpf\\core\\examples\\result_files\\d3plot_beam\\d3plot01', 'D:\\ANSYSDev\\Sandbox\\pydpf-core\\.tox\\doc-html\\Lib\\site-packages\\ansys\\dpf\\core\\examples\\result_files\\d3plot_beam\\d3plot02', 'D:\\ANSYSDev\\Sandbox\\pydpf-core\\.tox\\doc-html\\Lib\\site-packages\\ansys\\dpf\\core\\examples\\result_files\\d3plot_beam\\file.actunits']
Result file path 22:
D:\ANSYSDev\Sandbox\pydpf-core\.tox\doc-html\Lib\site-packages\ansys\dpf\core\examples\result_files\binout\binout_matsum
# 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 project .flprj result file path
result_file_path_31 = examples.download_fluent_axial_comp()["flprj"]
# Define the CFF .cas.h5/.dat.h5 result files paths
result_file_path_32 = examples.download_fluent_axial_comp()
# Print the result files paths
print("Result file path 31:", "\n",result_file_path_31, "\n")
print("Result files paths 32:", "\n",result_file_path_32, "\n")
Result file path 31:
D:\ANSYSDev\Sandbox\pydpf-core\.tox\doc-html\Lib\site-packages\ansys\dpf\core\examples\result_files\fluent-axial_comp\axial_comp_reduced.flprj
Result files paths 32:
{'flprj': 'D:\\ANSYSDev\\Sandbox\\pydpf-core\\.tox\\doc-html\\Lib\\site-packages\\ansys\\dpf\\core\\examples\\result_files\\fluent-axial_comp\\axial_comp_reduced.flprj', 'cas': ['D:\\ANSYSDev\\Sandbox\\pydpf-core\\.tox\\doc-html\\Lib\\site-packages\\ansys\\dpf\\core\\examples\\result_files\\fluent-axial_comp\\axial_comp-1-01438.cas.h5', 'D:\\ANSYSDev\\Sandbox\\pydpf-core\\.tox\\doc-html\\Lib\\site-packages\\ansys\\dpf\\core\\examples\\result_files\\fluent-axial_comp\\axial_comp-1-01439.cas.h5', 'D:\\ANSYSDev\\Sandbox\\pydpf-core\\.tox\\doc-html\\Lib\\site-packages\\ansys\\dpf\\core\\examples\\result_files\\fluent-axial_comp\\axial_comp-1-01440.cas.h5'], 'dat': ['D:\\ANSYSDev\\Sandbox\\pydpf-core\\.tox\\doc-html\\Lib\\site-packages\\ansys\\dpf\\core\\examples\\result_files\\fluent-axial_comp\\axial_comp-1-01438.dat.h5', 'D:\\ANSYSDev\\Sandbox\\pydpf-core\\.tox\\doc-html\\Lib\\site-packages\\ansys\\dpf\\core\\examples\\result_files\\fluent-axial_comp\\axial_comp-1-01439.dat.h5', 'D:\\ANSYSDev\\Sandbox\\pydpf-core\\.tox\\doc-html\\Lib\\site-packages\\ansys\\dpf\\core\\examples\\result_files\\fluent-axial_comp\\axial_comp-1-01440.dat.h5']}
# 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 project .res result file path
result_file_path_41 = examples.download_cfx_mixing_elbow()
# Define the CFF .cas.cff/.dat.cff result files paths
result_file_path_42 = examples.download_cfx_heating_coil()
# Print the result files paths
print("Result file path 41:", "\n",result_file_path_41, "\n")
print("Result files paths 42:", "\n",result_file_path_42, "\n")
Result file path 41:
D:\ANSYSDev\Sandbox\pydpf-core\.tox\doc-html\Lib\site-packages\ansys\dpf\core\examples\result_files\cfx-mixing_elbow\InjectMixer.res
Result files paths 42:
{'cas': 'D:\\ANSYSDev\\Sandbox\\pydpf-core\\.tox\\doc-html\\Lib\\site-packages\\ansys\\dpf\\core\\examples\\result_files\\cfx-heating_coil\\def.cas.cff', 'dat': 'D:\\ANSYSDev\\Sandbox\\pydpf-core\\.tox\\doc-html\\Lib\\site-packages\\ansys\\dpf\\core\\examples\\result_files\\cfx-heating_coil\\def.dat.cff'}
Use a DataSources
#
The DataSources
object manages paths to their files. Use this object to declare data
inputs for PyDPF-Core APIs.
a) `.rst` result file
Create the DataSources
object and give the path to the result file to the ‘result_path’ argument.
# Create the DataSources object
# Use the ``result_path`` argument and give the result file path
ds_11 = dpf.DataSources(result_path=result_file_path_11)
b) `.mode`, `.rfrq` and `.rst` result files
In the modal superposition, modal coefficients are multiplied by mode shapes (of a previous modal analysis) to analyse a structure under given boundary conditions in a range of frequencies. Doing this expansion “on demand” in DPF instead of in the solver reduces the size of the result files.
The expansion is recursive in DPF: first the modal response is read. Then, upstream mode shapes are found in
the DataSources
, where they are read and expanded. Upstream refers to a source that provides data to a
particular process.
To create a recursive workflow add the upstream DataSources
object, that contains the upstream
data files, to the main DataSources
object.
# Create the main DataSources object
ds_12 = dpf.DataSources()
# Define the main result file path
ds_12.set_result_file_path(filepath=result_file_path_12["rfrq"], key='rfrq')
# Create the upstream DataSources object with the main upstream file path
upstream_ds_12 = dpf.DataSources(result_path=result_file_path_12["mode"])
# Add the additional upstream file path to the upstream DataSources object
upstream_ds_12.add_file_path(filepath=result_file_path_12["rst"])
# Add the upstream DataSources to the main DataSources object
ds_12.add_upstream(upstream_data_sources=upstream_ds_12)
a) `.d3plot` result file
The d3plot file does not contain information related to units. In this case, as the
simulation was run through Mechanical, a file.actunits
file is produced. If this
file is supplemented in the DataSources
, the units will be correctly fetched for all
results in the file as well as for the mesh.
Thus, we must use the set_result_file_path()
and the add_file_path()
methods to add the main
and the additional result file to the DataSources
object.
# Create the DataSources object
ds_21 = dpf.DataSources()
# Define the main result file path
ds_21.set_result_file_path(filepath=result_file_path_21[0], key="d3plot")
# Add the additional file path related to the units
ds_21.add_file_path(filepath=result_file_path_21[3], key="actunits")
b) `.binout` result file
The extension key `.binout` is not explicitly specified in the result file. Thus, we use
the set_result_file_path()
method and give the extension key to the ‘key’ argument to correctly
add the result file path to the DataSources
object.
# Create the DataSources object
ds_22 = dpf.DataSources()
# Define the path to the result file
# Use the ``key`` argument and give the file extension key
ds_22.set_result_file_path(filepath=result_file_path_22, key="binout")
a) `.flprj` result file
Create the DataSources
object and give the path to the result file to the ‘result_path’ argument.
# Create the DataSources object
# Use the ``result_path`` argument and give the result file path
ds_31 = dpf.DataSources(result_path=result_file_path_31)
b) `.cas.h5`, `.dat.h5` result files
Here, we have a main and an additional result file with two extensions keys.
Thus, you must use the set_result_file_path()
and the add_file_path()
methods to add the main and
additional result file to the DataSources
object and explicitly give the first extension key to
their ‘key’ argument.
# Create the DataSources object
ds_32 = dpf.DataSources()
# Define the path to the main result file
# Use the ``key`` argument and give the first extension key
ds_32.set_result_file_path(filepath=result_file_path_32['cas'][0], key="cas")
# Add the additional result file path to the DataSources
# Use the ``key`` argument and give the first extension key
ds_32.add_file_path(filepath=result_file_path_32['dat'][0], key="dat")
a) `.res` result file
Create the DataSources
object and give the path to the result file to the ‘result_path’ argument.
# Create the DataSources object
# Use the ``result_path`` argument and give the result file path
ds_41 = dpf.DataSources(result_path=result_file_path_41)
b) `.cas.cff`, `.dat.cff` result files
Here, we have a main and an additional result file with two extensions keys.
Thus, you must use the set_result_file_path()
and the add_file_path()
methods to add the main and
additional result file to the DataSources
object. Also, you must explicitly give the first extension keys to
the ‘key’ argument.
# Create the DataSources object
ds_42 = dpf.DataSources()
# Define the path to the main result file
# Use the ``key`` argument and give the first extension key
ds_42.set_result_file_path(filepath=result_file_path_42["cas"], key="cas")
# Add the additional result file path to the DataSources
# Use the ``key`` argument and give the first extension key
ds_42.add_file_path(filepath=result_file_path_42["dat"], key="dat")
Use a Model
#
The Model
class creates and evaluates common readers for the files it is given,
such as a mesh provider, a result info provider, and a streams provider.
It provides dynamically built methods to extract the results available in the files, as well as many shortcuts
to facilitate exploration of the available data.
To create a Model
you can provide to the ‘data_sources’ argument.:
The result file path, in the case you are working with a single result file that has an explicit extension key;
A
DataSources
object.
a) `.rst` result file
# Create the model with the result file path
model_11 = dpf.Model(data_sources=result_file_path_11)
# Create the model with the DataSources object
model_12 = dpf.Model(data_sources=ds_11)
b) `.mode`, `.rfrq` and `.rst` result files
# Create the model with the DataSources object
model_13 = dpf.Model(data_sources=ds_12)
a) `.d3plot` result file
# Create the model with the DataSources object
model_21 = dpf.Model(data_sources=ds_21)
b) `.binout` result file
# Create the model with the DataSources object
model_22 = dpf.Model(data_sources=ds_22)
a) `.flprj` result file
# Create the model with the result file path
model_31 = dpf.Model(data_sources=result_file_path_31)
# Create the model with the DataSources object
model_32 = dpf.Model(data_sources=ds_31)
b) `.cas.h5`, `.dat.h5` result files
# Create the model with the DataSources object
model_33 = dpf.Model(data_sources=ds_32)
a) `.res` result file
# Create the model with the result file path
model_41 = dpf.Model(data_sources=result_file_path_41)
# Create the model with the DataSources object
model_42 = dpf.Model(data_sources=ds_41)
b) `.cas.cff`, `.dat.cff` result files
# Create the model with the DataSources object
model_43 = dpf.Model(data_sources=ds_42)