Skip to main content

Common Fluids Format 2023 R2

Ansys Common Fluids Factory API

Last update: 16.07.2025

Introduction

Before reading or writing to a Common Fluids Restart or Common Fluids Post file it is necessary to obtain an instance of the API. Two factory methods exist to obtain an instance of the API for obtaining an object to:

Obtaining an Object to Read a CFF File

To read a CFF file, you must first create an instance of the ansys::CffProvider API.

A factory method exists to perform this action:

ansys::getDataProvider should be used to obtain an ansys::CffFileProvider object.

This object is a subclass of ansys::CffProvider, specifically handling files.

Class that provides functions to access data stored within a CFF file.
Definition: CffFileProvider.hpp:18
ANSYS_FLUIDS_FACTORY_DLL CffFileProvider * getDataProvider(const std::string &sourceFile)
A function that provides that obtains an instance of an ansys::CffFileProvider that can be used to re...
Definition: providers.cpp:105

Although you are specifying a file name to the factory when requesting a new provider, the object isn't aware of the filename you have used to create the object at this stage.

The reason for this is that the provider created is unaware as to whether the filename you provided is expected to contain mesh, topology and settings information (in other words, a cas file) or is expected to contain solution data (in other words, a dat file).

How to determine which cas file goes with which dat file?

For some simulations you may find that there are multiple cas and dat files available.

If these are referenced from within a CFFProject file to access the CFFRestart or CFFPost files the association between a dat file and a specific cas file can be explictly found within the Project data. See Project API.

If you don't have a CFFProject file, you cannot always assume that the cas file associated with the dat file will always have the same name. In fact in the case of a transient sequence it is likely that each dat file may be different from the cas files. In this case you should always determine the cas file to use from the information found within the dat file.

This can be done by opening the dat file first and requesting a specific setting using the function below:

std::string datFileName = "elbow.dat.h5";
if (provider || !provider->startReading(datFileName, ansys::DataClass::CFF_RESULTS)) {
std::cerr << "Unable to read dat file" << std::endl;
exit(1);
}
std::string casFileName;
provider->getSettingString(ansys::DataClass::CFF_RESULTS, "Case File", casFileName);
bool startReading(const std::string &file, DataClass dataClass)
Start reading data of the class specified from the file passed in.
Definition: CffFileProviderMethods.cpp:38
virtual void getSettingString(DataClass dataClass, const std::string &datasetName, std::string &contents, const std::string &path="") const
Read settings from a data set as text.
Definition: CffProviderMethods.cpp:345
@ CFF_RESULTS
Definition: CffTypes.h:421

After finding out the name of the cas file it is preferable to destroy the instance of the provider just created and create a new one, as is shown below.

You can now specify the files to the new instance of the ansys::CfFileProvider by follwing the instructions here.

Obtaining an Object to Write a CFF File

To write a file using the CFF API you must first obtain a ansys::CffFileConsumer object.

ansys::CffFileConsumer* consumer = ansys::getDataConsumer(CFF_HDF));
if (!consumer) {
std::cerr << "Unable to obtain an interface to write a CFF file." << std::endl;
exit(1);
}
Class that provides functions to access data stored within a CFF file.
Definition: CffFileConsumer.hpp:18
@ CFF_HDF
Definition: CffTypes.h:648

You should then set the file attributes you require. For example:

consumer->setCompression(1);
// Indicate the application name writing the data
consumer->setSolverType("name");
// Prepare to write mesh the first mesh
consumer->setMeshId(1);
virtual void setSolverType(SolverType solverType)
Set the name of the application that is supplying the data.
Definition: CffBaseMethods.cpp:1713
void setMeshId(const MeshIdType meshId)
Set the Identifier for active mesh being read or written.
Definition: CffBaseMethods.cpp:362
void setDataPrecision(DataPrecisionType ptype)
Sets the precision for solution data.
Definition: CffConsumerMethods.cpp:4436
@ CFF_PRECISION_DOUBLE
Definition: CffTypes.h:436

The file can then be opened:

// Start writing the data
bool ok = consumer->startWriting("elbow.cas.h5", ansys::DataClass::CFF_CASE);
if(!ok) {
std::cerr << "Error writing to case file" << std::endl;
delete consumer;
return 1;
}
...
bool startWriting(const std::string &file, DataClass dataClass)
Start writing data of the specified class to the file passed as an argument.
Definition: CffFileConsumerMethods.cpp:29
@ CFF_CASE
Definition: CffTypes.h:419

The functions in the ansys::CffConsumer class can then be used to write your data.

Connect with Ansys