Ansys Common Fluids Examples
Last update: 24.03.2026Introduction
A number of examples are available to help with understanding how to use the CFF API.
C++ examples
- Reading Case and Data Files using C++ API
- Writing Case and Data Files using C++ API
- Reading Settings Using C++ API
- Reading Discrete Phase Model (DPM) Particle Data Using C++ API
C examples
Instructions to Build Examples
- Copy the code and save it as test.cpp or test.c.
- Set the CFF_SDK_PATH environment variable to the path of the CFF-SDK directory.
- On Linux: To build using the gcc/g++ compiler:
- For C++ source code, use the following command: >> g++ -o test.exe -O3 -Wall -Wuninitialized -Wunused -Wconversion -fpermissive -Wl,--export-dynamic -DNDEBUG=1 -D_GLIBCXX_USE_CXX11_ABI=1 -D_linx64 -lstdc++ -ldl -I${CFF_SDK_PATH}/include -I/${CFF_SDK_PATH}/example -L${CFF_SDK_PATH}/lib/linx64 -lansysfluidscffinterface -lansysfluidsfactory test.cpp
- For C source code, use the following command: >> gcc -o test.exe -O3 -Wall -Wuninitialized -Wunused -Wconversion -Wl,--export-dynamic -DNDEBUG=1 -D_GLIBCXX_USE_CXX11_ABI=1 -D_linx64 -lstdc++ -ldl -I${CFF_SDK_PATH}/include -I/${CFF_SDK_PATH}/example -L${CFF_SDK_PATH}/lib/linx64 -lansysfluidscffinterface -lansysfluidsfactory test.c
- For C++ source code, use the following command:
- On Windows: To build using the MSVC compiler:
- For C++ source code, use the following command: >> cl test.cpp /Fo:test.obj /TP /nologo /Za /EHsc /W3 /MD /O2 /DNDEBUG=1 /D_NT=1 /D_WIN64=1 /I. /I%CFF_SDK_PATH%\include /I%CFF_SDK_PATH%\example /link /nologo /OUT:test.exe /LIBPATH:%CFF_SDK_PATH%\lib\winx64 ansysfluidscffinterface.lib ansysfluidsfactory.lib
- For C source code, use the following command: >> cl test.c /Fo:test.obj /TC /nologo /Za /EHsc /W3 /MD /O2 /DNDEBUG=1 /D_NT=1 /D_WIN64=1 /I. /I%CFF_SDK_PATH%\include /I%CFF_SDK_PATH%\example /link /nologo /OUT:test.exe /LIBPATH:%CFF_SDK_PATH%\lib\winx64 ansysfluidscffinterface.lib ansysfluidsfactory.lib
- For C++ source code, use the following command:
- Set the following environment variables to ensure proper loading of dynamically-linked libraries before executing the program:
- On Linux:
LD_LIBRARY_PATH=${CFF_SDK_PATH}/lib/linx64 - On Windows:
PATH=%CFF_SDK_PATH%\lib\winx64;%PATH%
- On Linux:
Reading Case and Data Files using C++ API
This example demonstrates how to use the CFF I/O SDK to read case and results files. To use it, you must provide the CFF case and data files on the command line. The following source code can be built using Instructions to Build Examples.
Run the following command to read the case file using the Zone method:
For more information, display the help menu by running the following command:
read_example.cpp
We recommend using the option to read data by zone. The functions that do this are in the following file:
ReadByZone.hpp (This can be found at example/hdf/Import/ReadByZone.hpp in the CFF-SDK directory.)
Additional files illustrate how to read data by range:
ReadByZoneRange.hpp (This can be found at example/hdf/Import/ReadByZoneRange.hpp in the CFF-SDK directory.)
Read data by element:
ReadByElement.hpp (This can be found at example/hdf/Import/ReadByElement.hpp in the CFF-SDK directory.)
Writing Case and Data Files using C++ API
The following example demonstrates how to use the CFF API to write case and results files. The following source code can be built using Instructions to Build Examples.
Run the following command to write case and data files using the C++ API:
write_example.cpp
The function uses data that is made available from some functions in a separate utility source file.
CasAndDatCreator.hpp (This can be found at example/hdf/Common/CasAndDatCreator.hpp in the CFF-SDK directory.)
Reading Settings Using C++ API
This example demonstrates how to use the CFF API to read settings from a cas.h5 file. The following source code can be built using Instructions to Build Examples.
Run the following command to read settings from the case file:
settings_import.cpp
Reading Discrete Phase Model (DPM) Particle Data Using C++ API
This example demonstrates how to use the CFF API to read discrete phase model (DPM) particle data. To execute this example, you must supply a data file that has DPM particle data in it. Ansys Fluent writes such data files for cases in which an injection is defined, and the files are in a compatible format by default. The following source code can be built using Instructions to Build Examples.
Run the following command to read particle data from the data file:
read_example.cpp
Reading a CFF file Using C API
This example demonstrates how to use the CFF API wrapper in C code to read a CFF file. The following source code can be built using Instructions to Build Examples.
Run the following command to read case file using the C API:
read_example.c
Writing a CFF File Using C API
This example demonstrates how to use the CFF API wrapper in C code to write a CFF file. The following source code can be built using Instructions to Build Examples.
Run the following command to write case and data files using the C API:
write_example.cpp