Creating a DPF custom operator's library
Last update: 10.07.2023
Creating a DPF custom operator's library
The Data Processing Framework (DPF) provides numerical simulation users/engineers with a toolbox for accessing and transforming simulation data. It is used to handle complex pre- or post-processing of simulation data within a simulation workflow.
In DPF, Operators are the main object used to create, transform and stream the data. An operator is composed of a “core” that handles the calculation. It receives the data using input pins, applies a transformation and makes the data available through the output pins (think of an integrated circuit in electronics). See the Concepts and Terminology to learn more.
In Ansys 2022 R2 and later, you can create custom operator's libraries in C++. It enables to access custom capabilities in any project that is using DPF.
This guide explains how to create and compile an operator's library C++ project, and how to consume it in another C++ project.
Pre-requisites
In order to use DPF in a C++ project, it is required to have access to the following files of the AWP_ROOT232/dpf/include folder (AWP_ROOT232 being an environment variable defining the root of the Ansys Inc or DPF Server product):
- dpf_api.h
- dpf_api_i.cpp
DPF_HGP_ROOT environment variable must be set to define the location of those files and must be set to follow this tutorial.
Here is the command for Windows: set DPF_HGP_ROOT=%AWP_ROOT232%/dpf/include
It can also be set by editing the environment variables in Windows settings.
Here is the command for Linux: export DPF_HGP_ROOT=${AWP_ROOT232}/dpf/include
Moreover it is needed to have compilation tools. Both CMake and Visual Studio are supported for project management and compilation. Examples using both are provided in the following sections.
Create a DPF_Custom_Operators folder. The following sections of this tutorial are performed from this folder.
Create a C++ Custom operator's library
This section details the C++ code to create a custom basic operator's library.
In the DPF_Custom_Operators folder previously created, create a MyCustomOperator.h file with the following content:
The staticData structure allows to use the DPF capabilities and must be incorporated only once per project. The CustomMessage structure contains all the implementation related to the custom operator. It always contains:
- a name method (unique identifier)
- a specification method which defines and describes the operator inputs, outputs and data computation
- a run method which contains the data computation code
In the DPF_Custom_Operators folder, create a MyCustomOperator.cpp file with the following content:
It is now required to compile the code.
Compile the C++ Custom operator's library
This sections details the compilation process of the C++ code.
Using Visual Studio (Windows only)
In the DPF_Custom_Operators folder previously created, create a CustomOperators.vcxproj file with the following content:
Then, open the MyCustomOperator.vcxproj project in Visual Studio and compile it.
Using CMake (Windows and Linux)
In the DPF_Custom_Operators folder previously created, create a CMakeLists.txt file with the following content:
Then, run the following commands in a command line opened from the DPF_Custom_Operators folder.
On Windows, it creates a build/Release folder which contains the "CustomOperators.dll". On Linux, it creates the "libCustomOperators.so" file into the build folder.
Create an application that consumes the C++ Custom operator's library
The following shows how to consume the CustomOperators binary into another C++ project. The consumption is done by loading the binary in the new C++ project at runtime.
Create the testing files
Set a DPF_Custom_Operators environment variable to the DPF_Custom_Operators folder.
In the DPF_Custom_Operators folder previously created, create a DPF_application folder.
In the DPF_application folder, create a CustomOperatorsTest.cpp with the following content:
Compile the test application
With CMake (Windows and Linux)
In the DPF_application folder, create a CMakeLists.txt file with the following content:
Run the following commands in a command line opened from the DPF_application folder.
With Visual Studio (Windows only)
In the DPF_application folder, create a CustomOperatorsTest.vcxproj file with the following content:
Run the test application
With CMake
Run the following command in a command line opened from the DPF_application folder.
On Windows, use the following:
Setting the PATH is required to find DPF entry point (DataProcessingCore.dll).
On Linux, use the following:
Setting the LD_LIBRARY_PATH is required to find DPF entry point (libDataProcessingCore.so).
If you face licensing issues, the ANSYSLMD_LICENSE_FILE might must be set. Refer to the License terms section to learn how to set it.
With Visual Studio
Edit your environment variables and update the PATH value inserting a "%AWP_ROOT232%/aisol/bin/winx64" field. It is needed that the application can find DPF entry point (DataProcessingCore.dll) while running. Edit your environment variables and create a DPF_Custom_Operators variable that targets the DPF_Custom_Operators folder location. Open the CustomOperatorsTest.vcxproj project in Visual Studio. Compile it. Press F5 to run the code.
Result
The following message should appear: