    

 ## On this page

  

 

 # OperatorsApis

 Last update: 16.07.2025 

Examples showing how to use the DPF operators to compute the data.

//

// COPYRIGHT ANSYS. ALL RIGHTS RESERVED.

//

\#include "dpf\_api.h"

\#include &lt;limits&gt;

\#pragma warning (disable : 4189) //local variable is initialized but not referenced

\#ifdef EXAMPLE

\#include "Example.h"

\#else

\#include &lt;gtest/gtest.h&gt;

\#endif

 

TEST(Operator, ImportAndReadData)

{

 // Those operators allow to read data from solver files or from standard file types. 

 // Different solver format are handled by DPF like rst/mode/rfrq/rdsp.. for MAPDL, d3plot 

 // for LsDyna, cas.h5/dat.h5/res/flprj for CFX and Fluent, odb for Abaqus... To read those, 

 // different readers have been implemented in plugins. Plugins can be loaded on demand in 

 // any dpf's scripting language with the "load library" methods. File readers can be used 

 // generically thanks to dpf's result providers, which means that the same operators can 

 // be used for any file types. For example, reading a displacement or a stress for any files 

 // will be done with the following code.

 

 // set the result file path to the right path

 std::string fileName("../../../testfiles/mapdl\_files/TwoSolids.rst");

 <a id="_a0" name="_a0"></a>[ansys::dpf::DataSources](classansys_1_1dpf_1_1DataSources.xhtml) my_data_sources;

 my_data_sources.<a id="a1" name="a1"></a>[addResultFile](classansys_1_1dpf_1_1DataSources.xhtml#ad2a5bb6f24ca621ffaaee9e7a47cdc20)(fileName);

 

 //displacement for any solver file

 <a id="_a2" name="_a2"></a>[ansys::dpf::Operator](classansys_1_1dpf_1_1Operator.xhtml) u_op("U");

 u_op.<a id="a3" name="a3"></a>connect(<a id="a4" name="a4"></a>[ansys::dpf::eDataSourcesPin](namespaceansys_1_1dpf.xhtml#aa4a44a04a0aafb8fe0645f019bbd94d1a5b6613f802062fde4faea4b553db7fbc), my_data_sources);

 <a id="_a5" name="_a5"></a>[ansys::dpf::FieldsContainer](classansys_1_1dpf_1_1FieldsContainer.xhtml) my_u = u_op.<a id="a6" name="a6"></a>[getOutputFieldsContainer](classansys_1_1dpf_1_1Operator.xhtml#a9994ffe0f23c4a5de614099abb95286c)(0);

 

 

 //stress for any solver file

 [ansys::dpf::Operator](classansys_1_1dpf_1_1Operator.xhtml) s_op("S");

 s_op.connect([ansys::dpf::eDataSourcesPin](namespaceansys_1_1dpf.xhtml#aa4a44a04a0aafb8fe0645f019bbd94d1a5b6613f802062fde4faea4b553db7fbc), my_data_sources);

 [ansys::dpf::FieldsContainer](classansys_1_1dpf_1_1FieldsContainer.xhtml) my_s = s_op.[getOutputFieldsContainer](classansys_1_1dpf_1_1Operator.xhtml#a9994ffe0f23c4a5de614099abb95286c)(0);

}

 

TEST(Operator, ImportAndReadDataCustom)

{

 // Result providers can be customized to read a specific time frequency or to provide 

 // results on a subset of the mesh.

 

 // set the result file path to the right path

 std::string fileName("../../../testfiles/mapdl\_files/TwoSolids.rst");

 [ansys::dpf::DataSources](classansys_1_1dpf_1_1DataSources.xhtml) my_data_sources;

 my_data_sources.[addResultFile](classansys_1_1dpf_1_1DataSources.xhtml#ad2a5bb6f24ca621ffaaee9e7a47cdc20)(fileName);

 

 //displacement for any solver file

 [ansys::dpf::Operator](classansys_1_1dpf_1_1Operator.xhtml) u_op("U");

 u_op.connect([ansys::dpf::eDataSourcesPin](namespaceansys_1_1dpf.xhtml#aa4a44a04a0aafb8fe0645f019bbd94d1a5b6613f802062fde4faea4b553db7fbc), my_data_sources);

 

 // Different ways to set the time scoping

 // Select one time/frequency

 u_op.connect(<a id="a7" name="a7"></a>[ansys::dpf::eTimeScopPin](namespaceansys_1_1dpf.xhtml#aa4a44a04a0aafb8fe0645f019bbd94d1ac390a52dd8c4f1e8ff81a162cdc04d4f), 2); // Int : Select second time/freq set in the time freq support

 u_op.connect([ansys::dpf::eTimeScopPin](namespaceansys_1_1dpf.xhtml#aa4a44a04a0aafb8fe0645f019bbd94d1ac390a52dd8c4f1e8ff81a162cdc04d4f), 0.002); // Double : Gives a field interpolated at the given time/freq value

 

 // Select multiple times/frequencies 

 std::vector&lt;int&gt; time_sets = { 1,2,3 };

 u_op.connect([ansys::dpf::eTimeScopPin](namespaceansys_1_1dpf.xhtml#aa4a44a04a0aafb8fe0645f019bbd94d1ac390a52dd8c4f1e8ff81a162cdc04d4f), time_sets); // Vec Int: Select time/freq sets in the time freq support

 std::vector&lt;double&gt; times = { 0.002, 0.003 };

 u_op.connect([ansys::dpf::eTimeScopPin](namespaceansys_1_1dpf.xhtml#aa4a44a04a0aafb8fe0645f019bbd94d1ac390a52dd8c4f1e8ff81a162cdc04d4f), times); // Vec Double : Gives fields interpolated at the given time/freq values

 

 // Select all the time/frequencies of a load step

 <a id="_a8" name="_a8"></a>[ansys::dpf::Scoping](classansys_1_1dpf_1_1Scoping.xhtml) load_step({ 2 }, <a id="a9" name="a9"></a>[ansys::dpf::locations::time\_step](structansys_1_1dpf_1_1locations.xhtml#abc48364ef6b184ddf696099c9a2993cd));

 u_op.connect([ansys::dpf::eTimeScopPin](namespaceansys_1_1dpf.xhtml#aa4a44a04a0aafb8fe0645f019bbd94d1ac390a52dd8c4f1e8ff81a162cdc04d4f), load_step);

 

 [ansys::dpf::Scoping](classansys_1_1dpf_1_1Scoping.xhtml) node_scoping({ 1,2,3 }, <a id="a10" name="a10"></a>[ansys::dpf::locations::nodal](structansys_1_1dpf_1_1locations.xhtml#aa4e1967b0838d8597200c606c8564d29));

 u_op.connect(<a id="a11" name="a11"></a>[ansys::dpf::eMeshScopPin](namespaceansys_1_1dpf.xhtml#aa4a44a04a0aafb8fe0645f019bbd94d1a79a70f074b2f79ccaff75ae8e4ec9ec9), node_scoping);

 

 [ansys::dpf::Scoping](classansys_1_1dpf_1_1Scoping.xhtml) element_scoping({ 1,2,3 }, <a id="a12" name="a12"></a>[ansys::dpf::locations::elemental](structansys_1_1dpf_1_1locations.xhtml#a3f66169a86ab935fb398b3fdde98bb04));

 u_op.connect([ansys::dpf::eMeshScopPin](namespaceansys_1_1dpf.xhtml#aa4a44a04a0aafb8fe0645f019bbd94d1a79a70f074b2f79ccaff75ae8e4ec9ec9), element_scoping);

 

 // uncomment this line to compute the fields container.

 // this requires a license.

 // ansys::dpf::FieldsContainer my\_u = u\_op.getOutputFieldsContainer(0);;

}

 

TEST(Operator, ReadExportedData)

{

 // Standards file formats reader are also supported to import custom data. 

 // Fields can be imported from csv, vtk or hdf5 files

 

 std::string my_path = "c:/temp/file.csv";

 [ansys::dpf::DataSources](classansys_1_1dpf_1_1DataSources.xhtml) my_data_sources;

 my_data_sources.[addResultFile](classansys_1_1dpf_1_1DataSources.xhtml#ad2a5bb6f24ca621ffaaee9e7a47cdc20)(my_path);

 

 [ansys::dpf::Operator](classansys_1_1dpf_1_1Operator.xhtml) csv("csv\_to\_field");

 csv.connect([ansys::dpf::eDataSourcesPin](namespaceansys_1_1dpf.xhtml#aa4a44a04a0aafb8fe0645f019bbd94d1a5b6613f802062fde4faea4b553db7fbc), my_data_sources);

 // uncomment this line to compute the fields container.

 // this requires a license.

 // ansys::dpf::FieldsContainer my\_fields = csv.getOutputFieldsContainer(0);

}

 

TEST(Operator, TransformingExistingData)

{

 // The field being the main data container in DPF, most of the operator transforming the data 

 // take a field or fields container as input and return a transformed field or fields container 

 // in output. Analytic, averaging or filtering operations can be performed on the simulation data

 

 <a id="_a13" name="_a13"></a>[ansys::dpf::Field](classansys_1_1dpf_1_1Field.xhtml) field1(3, { 3 }, [ansys::dpf::locations::nodal](structansys_1_1dpf_1_1locations.xhtml#aa4e1967b0838d8597200c606c8564d29));

 field1.<a id="a14" name="a14"></a>[setData](classansys_1_1dpf_1_1Field.xhtml#a9f7828d92496843cc5f15ee9e32f6c4a)({ 1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0 });

 field1.scoping().setIds({ 1,2,3 });

 

 // using analytic operator: scale operator

 [ansys::dpf::Operator](classansys_1_1dpf_1_1Operator.xhtml) op1("scale");

 op1.connect(0, field1);

 op1.connect(1, 2.0);

 [ansys::dpf::Field](classansys_1_1dpf_1_1Field.xhtml) out = op1.getOutputField(0);

 int size = 0;

 [ansys::dpf::dp\_double](namespaceansys_1_1dpf.xhtml#acb480013bfed185b5e34a0bdcb0e3790)* const data = out.<a id="a15" name="a15"></a>[data](classansys_1_1dpf_1_1Field.xhtml#a0967a8c6cee105a679dd1151a5d41004)(size);

 // returns:

 // { 2., 4., 6., 8., 10., 12., 14., 16., 18.}

}

 

TEST(Operator, ExportingData)

{

 // After transforming or reading simulation data with DPF, the user might want to export the 

 // results in a given format to use it in another environment or to save it for future use with 

 // dpf. Vtk, h5, csv and txt (serializer operator) are examples of supported exports. Export 

 // operators often match with import operators allowing user to reuse their data. The 

 // "serialization" operators menu lists the available import/export operators.

 

 // set the result file path to the right path

 std::string fileName("../../../testfiles/mapdl\_files/TwoSolids.rst");

 [ansys::dpf::DataSources](classansys_1_1dpf_1_1DataSources.xhtml) my_data_sources;

 my_data_sources.[addResultFile](classansys_1_1dpf_1_1DataSources.xhtml#ad2a5bb6f24ca621ffaaee9e7a47cdc20)(fileName);

 

 //displacement for any solver file

 [ansys::dpf::Operator](classansys_1_1dpf_1_1Operator.xhtml) u_op("U");

 u_op.connect([ansys::dpf::eDataSourcesPin](namespaceansys_1_1dpf.xhtml#aa4a44a04a0aafb8fe0645f019bbd94d1a5b6613f802062fde4faea4b553db7fbc), my_data_sources);

 [ansys::dpf::FieldsContainer](classansys_1_1dpf_1_1FieldsContainer.xhtml) my_fields = u_op.getOutputFieldsContainer(0);

 

 //scale it by 2.0

 [ansys::dpf::Operator](classansys_1_1dpf_1_1Operator.xhtml) my_scale_op("scale\_fc");

 my_scale_op.connect(0, my_fields);

 my_scale_op.connect(1, 2.0);

 

 //get the mesh

 [ansys::dpf::Operator](classansys_1_1dpf_1_1Operator.xhtml) my_mesh_op("MeshProvider");

 my_mesh_op.connect([ansys::dpf::eDataSourcesPin](namespaceansys_1_1dpf.xhtml#aa4a44a04a0aafb8fe0645f019bbd94d1a5b6613f802062fde4faea4b553db7fbc), my_data_sources);

 

 // export the result in vtk

 // uncomment the following code to enable the export operations

 // this requires a license.

 //ansys::dpf::Operator my\_export("vtk\_export");

 //my\_export.connect(0, std::string("C:/temp/fileNew.vtk"));

 //my\_export.connect(1, my\_mesh\_op, 0);

 //my\_export.connect(2, my\_scale\_op, 0);

 // my\_export.run();

}

 

TEST(Operator, ChainingOperators)

{

 // To create more complex operations and customizable results, operators can be 

 // chained together to create workflows. This way a result can be read from a solver 

 // result file and directly transformed in a single workflow. Examples can be found 

 // in APIs/Workflow examples menu. 2 syntaxes can be used to create and connect 

 // operators together.

 

 // set the result file path to the right path

 std::string fileName("../../../testfiles/mapdl\_files/TwoSolids.rst");

 [ansys::dpf::DataSources](classansys_1_1dpf_1_1DataSources.xhtml) my_data_sources;

 my_data_sources.[addResultFile](classansys_1_1dpf_1_1DataSources.xhtml#ad2a5bb6f24ca621ffaaee9e7a47cdc20)(fileName);

 

 [ansys::dpf::Operator](classansys_1_1dpf_1_1Operator.xhtml) u_op("U");

 u_op.connect([ansys::dpf::eDataSourcesPin](namespaceansys_1_1dpf.xhtml#aa4a44a04a0aafb8fe0645f019bbd94d1a5b6613f802062fde4faea4b553db7fbc), my_data_sources);

 

 [ansys::dpf::Operator](classansys_1_1dpf_1_1Operator.xhtml) norm_op("norm\_fc");

 norm_op.connect(0, u_op, 0); //connect norm\_op input pin 0 to u\_op output pin 0

 

 [ansys::dpf::FieldsContainer](classansys_1_1dpf_1_1FieldsContainer.xhtml) my_u_norm = norm_op.getOutputFieldsContainer(0);

}

 

TEST(Operator, UsingConfigurations)

{

 // Advanced user might want to configurate an operator's behavior during its running phase. 

 // This can be done through the "config". This option allows to choose if an operator can 

 // directly modify the input data container instead of creating a new one with the "inplace" 

 // configuration, to choose if an operation between to fields should use their indices or mesh 

 // ids with the "work\_by\_index" configuration... Each operator's description explains which 

 // configuration are supported.

 

 [ansys::dpf::Field](classansys_1_1dpf_1_1Field.xhtml) field1(3, { 3 }, [ansys::dpf::locations::nodal](structansys_1_1dpf_1_1locations.xhtml#aa4e1967b0838d8597200c606c8564d29));

 field1.[setData](classansys_1_1dpf_1_1Field.xhtml#a9f7828d92496843cc5f15ee9e32f6c4a)({ 1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0 });

 field1.scoping().setIds({ 1,2,3 });

 

 [ansys::dpf::Field](classansys_1_1dpf_1_1Field.xhtml) field2(3, { 3 }, [ansys::dpf::locations::nodal](structansys_1_1dpf_1_1locations.xhtml#aa4e1967b0838d8597200c606c8564d29));

 field2.[setData](classansys_1_1dpf_1_1Field.xhtml#a9f7828d92496843cc5f15ee9e32f6c4a)({ 1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0 });

 field2.scoping().setIds({ 3,4,5 });

 

 <a id="_a16" name="_a16"></a>[ansys::dpf::OperatorConfig](classansys_1_1dpf_1_1OperatorConfig.xhtml) config = <a id="a17" name="a17"></a>[ansys::dpf::core::defaultOperatorConfig](classansys_1_1dpf_1_1core.xhtml#a20f37512490ec6131335f52be7f2f28d)("add");

 

 bool current_value = config.<a id="a18" name="a18"></a>[getBoolValue](classansys_1_1dpf_1_1OperatorConfig.xhtml#a3948249196192234ee24269ba8e994b7)("work\_by\_index");//returns current values of configuration

 

 //modify work\_by\_index config (default is false)

 config.<a id="a19" name="a19"></a>[set](classansys_1_1dpf_1_1OperatorConfig.xhtml#a13fa51659fa378a6f67b344bbb9ea1be)("work\_by\_index", true);

 

 //instantiate the operator with the config

 [ansys::dpf::Operator](classansys_1_1dpf_1_1Operator.xhtml) op1("add", config);

 op1.connect(0, field1);

 op1.connect(1, field2);

 [ansys::dpf::Field](classansys_1_1dpf_1_1Field.xhtml) out = op1.getOutputField(0);

 int size = 0;

 [ansys::dpf::dp\_double](namespaceansys_1_1dpf.xhtml#acb480013bfed185b5e34a0bdcb0e3790)* const data = out.[data](classansys_1_1dpf_1_1Field.xhtml#a0967a8c6cee105a679dd1151a5d41004)(size);

 // returns:

 // { 2., 4., 6., 8., 10., 12., 14., 16., 18.}

 

 //use default config value

 config.[set](classansys_1_1dpf_1_1OperatorConfig.xhtml#a13fa51659fa378a6f67b344bbb9ea1be)("work\_by\_index", false);

 op1 = [ansys::dpf::Operator](classansys_1_1dpf_1_1Operator.xhtml)("add", config);

 op1.connect(0, field1);

 op1.connect(1, field2);

 out = op1.getOutputField(0);

 [ansys::dpf::dp\_double](namespaceansys_1_1dpf.xhtml#acb480013bfed185b5e34a0bdcb0e3790)* const data2 = out.[data](classansys_1_1dpf_1_1Field.xhtml#a0967a8c6cee105a679dd1151a5d41004)(size);

 // returns:

 // { 1., 2., 3., 4., 5., 6., 8., 10., 12., 4., 5., 6., 7., 8., 9.}

 

 // changing the "permissive" config could allow to add fields of different homogeneities

 // changing the "binary\_operation" config could allow to keep only the intersection between fields ids and not the union

 //...

}

[ansys::dpf::DataSources](classansys_1_1dpf_1_1DataSources.xhtml)

**Definition:** dpf_api.h:2371



[ansys::dpf::DataSources::addResultFile](classansys_1_1dpf_1_1DataSources.xhtml#ad2a5bb6f24ca621ffaaee9e7a47cdc20)

void addResultFile(std::string const &amp;file_path, std::string const &amp;key)



[ansys::dpf::Field](classansys_1_1dpf_1_1Field.xhtml)

Data for an entity.

**Definition:** dpf_api.h:991



[ansys::dpf::Field::data](classansys_1_1dpf_1_1Field.xhtml#a0967a8c6cee105a679dd1151a5d41004)

dp_double *const data(int &amp;size) const



[ansys::dpf::Field::setData](classansys_1_1dpf_1_1Field.xhtml#a9f7828d92496843cc5f15ee9e32f6c4a)

void setData(std::vector&lt; double &gt; const &amp;data)



[ansys::dpf::FieldsContainer](classansys_1_1dpf_1_1FieldsContainer.xhtml)

Contains a group of fields.

**Definition:** dpf_api.h:1889



[ansys::dpf::OperatorConfig](classansys_1_1dpf_1_1OperatorConfig.xhtml)

**Definition:** dpf_api.h:4119



[ansys::dpf::OperatorConfig::set](classansys_1_1dpf_1_1OperatorConfig.xhtml#a13fa51659fa378a6f67b344bbb9ea1be)

void set(std::string const &amp;option, dp_int value)



[ansys::dpf::OperatorConfig::getBoolValue](classansys_1_1dpf_1_1OperatorConfig.xhtml#a3948249196192234ee24269ba8e994b7)

bool getBoolValue(std::string const &amp;option) const



[ansys::dpf::Operator](classansys_1_1dpf_1_1Operator.xhtml)

Wrap an elementary operation.

**Definition:** dpf_api.h:2651



[ansys::dpf::Operator::getOutputFieldsContainer](classansys_1_1dpf_1_1Operator.xhtml#a9994ffe0f23c4a5de614099abb95286c)

FieldsContainer getOutputFieldsContainer(dp_index pin_index)



[ansys::dpf::Scoping](classansys_1_1dpf_1_1Scoping.xhtml)

Define a set of entities by ids.

**Definition:** dpf_api.h:838



[ansys::dpf::core::defaultOperatorConfig](classansys_1_1dpf_1_1core.xhtml#a20f37512490ec6131335f52be7f2f28d)

static OperatorConfig defaultOperatorConfig(std::string const &amp;op_identifier, Client const *const client=nullptr)



[ansys::dpf::eDataSourcesPin](namespaceansys_1_1dpf.xhtml#aa4a44a04a0aafb8fe0645f019bbd94d1a5b6613f802062fde4faea4b553db7fbc)

@ eDataSourcesPin

**Definition:** dpf_api.h:2583



[ansys::dpf::eMeshScopPin](namespaceansys_1_1dpf.xhtml#aa4a44a04a0aafb8fe0645f019bbd94d1a79a70f074b2f79ccaff75ae8e4ec9ec9)

@ eMeshScopPin

**Definition:** dpf_api.h:2577



[ansys::dpf::eTimeScopPin](namespaceansys_1_1dpf.xhtml#aa4a44a04a0aafb8fe0645f019bbd94d1ac390a52dd8c4f1e8ff81a162cdc04d4f)

@ eTimeScopPin

**Definition:** dpf_api.h:2575



[ansys::dpf::dp\_double](namespaceansys_1_1dpf.xhtml#acb480013bfed185b5e34a0bdcb0e3790)

double dp_double

**Definition:** dpf_api_base.h:57



[ansys::dpf::locations::elemental](structansys_1_1dpf_1_1locations.xhtml#a3f66169a86ab935fb398b3fdde98bb04)

static const Location elemental

**Definition:** dpf_api_base.h:178



[ansys::dpf::locations::nodal](structansys_1_1dpf_1_1locations.xhtml#aa4e1967b0838d8597200c606c8564d29)

static const Location nodal

**Definition:** dpf_api_base.h:176



[ansys::dpf::locations::time\_step](structansys_1_1dpf_1_1locations.xhtml#abc48364ef6b184ddf696099c9a2993cd)

static const Location time_step

**Definition:** dpf_api_base.h:202