Get reduced matrices and make export#

This example shows how to get reduced matrices and export them to HDF5 and CSV files.

Import the dpf-core module and its examples files, and then create a temporary directory.

from ansys.dpf import core as dpf
from ansys.dpf.core import examples
from ansys.dpf.core import operators as ops

Create the operator and connect data sources.

ds = dpf.DataSources(examples.download_sub_file())

matrices_provider = ops.result.cms_matrices_provider()

Get result fields container that contains the reduced matrices.

fields = matrices_provider.outputs.fields_container()


DPFArray([[ 5.53476768e+11, -2.29728435e+10,  2.29728435e+10, ...,
            0.00000000e+00,  0.00000000e+00,  2.91225427e+05]])

Define a temporary folder for outputs

tmpdir = dpf.core.make_tmp_dir_server(dpf.SERVER)

Export the result fields container to an HDF5 file.

h5_op = ops.serialization.serialize_to_hdf5()
h5_op.inputs.file_path.connect(dpf.path_utilities.join(tmpdir, "matrices.h5"))

Export the result fields container to a CSV file.

csv_op = ops.serialization.field_to_csv()
csv_op.inputs.file_path.connect(dpf.path_utilities.join(tmpdir, "matrices.csv"))

Total running time of the script: (0 minutes 4.086 seconds)

Gallery generated by Sphinx-Gallery