    

 ## On this page

  

 

 # Ansys Common Fluids Factory API 

 Last update: 16.07.2025 

# <a class="anchor" id="FactoryAPIIntro"></a>Introduction

Before reading or writing to a [Common Fluids Restart](index.xhtml#Files) or [Common Fluids Post](index.xhtml#Files) 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:

- [read a CFF File](_factory_a_p_i.xhtml#FactoryAPIRead)
- [write a CFF File](_factory_a_p_i.xhtml#FactoryAPIWrite)

# <a class="anchor" id="FactoryAPIRead"></a>Obtaining an Object to Read a CFF File

To read a CFF file, you must first create an instance of the [ansys::CffProvider](classansys_1_1_cff_provider.xhtml "Class that provides functions to access data stored within a CFF database. The database may be stored...") API.

A factory method exists to perform this action:

[ansys::getDataProvider](namespaceansys.xhtml#a2f23564ea3eec12f9b204a64356e88c1 "A function that provides that obtains an instance of an ansys::CffFileProvider that can be used to re...") should be used to obtain an [ansys::CffFileProvider](classansys_1_1_cff_file_provider.xhtml "Class that provides functions to access data stored within a CFF file.") object.

This object is a subclass of [ansys::CffProvider](classansys_1_1_cff_provider.xhtml "Class that provides functions to access data stored within a CFF database. The database may be stored..."), specifically handling files.

[ansys::CffFileProvider](classansys_1_1_cff_file_provider.xhtml)* provider = [ansys::getDataProvider](namespaceansys.xhtml#a2f23564ea3eec12f9b204a64356e88c1)(fileName);

[ansys::CffFileProvider](classansys_1_1_cff_file_provider.xhtml)

Class that provides functions to access data stored within a CFF file.

**Definition:** CffFileProvider.hpp:18



[ansys::getDataProvider](namespaceansys.xhtml#a2f23564ea3eec12f9b204a64356e88c1)

ANSYS_FLUIDS_FACTORY_DLL CffFileProvider * getDataProvider(const std::string &amp;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).

## <a class="anchor" id="FactoryCasFromDat"></a>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](_project_a_p_i.xhtml).

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"; 

[ansys::CffFileProvider](classansys_1_1_cff_file_provider.xhtml)* provider = [ansys::getDataProvider](namespaceansys.xhtml#a2f23564ea3eec12f9b204a64356e88c1)(datFileName); 

if (provider || !provider-&gt;[startReading](classansys_1_1_cff_file_provider.xhtml#a80f6009e97e3a51b718be37582aefd3d)(datFileName, [ansys::DataClass::CFF\_RESULTS](group__enums.xhtml#ggab852cc24891eb831942fb8da764d8ddbaacfdbe512195015b6446480e80caf4a4))) {

 std::cerr &lt;&lt; "Unable to read dat file" &lt;&lt; std::endl;

 exit(1);

}

std::string casFileName;

provider-&gt;[getSettingString](classansys_1_1_cff_provider.xhtml#ac334920f8d33bbdae03b282f9e02c43a)([ansys::DataClass::CFF\_RESULTS](group__enums.xhtml#ggab852cc24891eb831942fb8da764d8ddbaacfdbe512195015b6446480e80caf4a4), "Case File", casFileName);

[ansys::CffFileProvider::startReading](classansys_1_1_cff_file_provider.xhtml#a80f6009e97e3a51b718be37582aefd3d)

bool startReading(const std::string &amp;file, DataClass dataClass)

Start reading data of the class specified from the file passed in.

**Definition:** CffFileProviderMethods.cpp:38



[ansys::CffProvider::getSettingString](classansys_1_1_cff_provider.xhtml#ac334920f8d33bbdae03b282f9e02c43a)

virtual void getSettingString(DataClass dataClass, const std::string &amp;datasetName, std::string &amp;contents, const std::string &amp;path="") const

Read settings from a data set as text.

**Definition:** CffProviderMethods.cpp:345



[CFF\_RESULTS](group__enums.xhtml#ggab852cc24891eb831942fb8da764d8ddbaacfdbe512195015b6446480e80caf4a4)

@ 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](_c_f_f_a_p_i.xhtml#OpenCaseAndDataForRead).

# <a class="anchor" id="FactoryAPIWrite"></a>Obtaining an Object to Write a CFF File

To write a file using the CFF API you must first obtain a [ansys::CffFileConsumer](classansys_1_1_cff_file_consumer.xhtml "Class that provides functions to access data stored within a CFF file.") object.

[ansys::CffFileConsumer](classansys_1_1_cff_file_consumer.xhtml)* consumer = ansys::getDataConsumer([CFF\_HDF](group__enums.xhtml#gga9d98ab88553e163862440763fc91c76aa07723f3ffb199eb4f791d1f74b5ac567)));

if (!consumer) {

 std::cerr &lt;&lt; "Unable to obtain an interface to write a CFF file." &lt;&lt; std::endl;

 exit(1);

}

[ansys::CffFileConsumer](classansys_1_1_cff_file_consumer.xhtml)

Class that provides functions to access data stored within a CFF file.

**Definition:** CffFileConsumer.hpp:18



[CFF\_HDF](group__enums.xhtml#gga9d98ab88553e163862440763fc91c76aa07723f3ffb199eb4f791d1f74b5ac567)

@ CFF_HDF

**Definition:** CffTypes.h:648





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

consumer-&gt;[setDataPrecision](classansys_1_1_cff_consumer.xhtml#ad74e63316298fa4468f604c380dbd6cf)([CFF\_PRECISION\_DOUBLE](group__enums.xhtml#gga2ecbf04cb65f31fde87a9c60a5bab3d6a583d6d67a6ee03f067b1dc6b717de7e6));

consumer-&gt;setCompression(1);

 

// Indicate the application name writing the data

consumer-&gt;[setSolverType](classansys_1_1_cff_base.xhtml#a30ca8450d5f621a2decc2dde0ff9207f)("name");

 

// Prepare to write mesh the first mesh

consumer-&gt;[setMeshId](classansys_1_1_cff_base.xhtml#a7a12ef6589a193f80be541291b0cec4b)(1);

[ansys::CffBase::setSolverType](classansys_1_1_cff_base.xhtml#a30ca8450d5f621a2decc2dde0ff9207f)

virtual void setSolverType(SolverType solverType)

Set the name of the application that is supplying the data.

**Definition:** CffBaseMethods.cpp:1713



[ansys::CffBase::setMeshId](classansys_1_1_cff_base.xhtml#a7a12ef6589a193f80be541291b0cec4b)

void setMeshId(const MeshIdType meshId)

Set the Identifier for active mesh being read or written.

**Definition:** CffBaseMethods.cpp:362



[ansys::CffConsumer::setDataPrecision](classansys_1_1_cff_consumer.xhtml#ad74e63316298fa4468f604c380dbd6cf)

void setDataPrecision(DataPrecisionType ptype)

Sets the precision for solution data.

**Definition:** CffConsumerMethods.cpp:4436



[CFF\_PRECISION\_DOUBLE](group__enums.xhtml#gga2ecbf04cb65f31fde87a9c60a5bab3d6a583d6d67a6ee03f067b1dc6b717de7e6)

@ CFF_PRECISION_DOUBLE

**Definition:** CffTypes.h:436





The file can then be opened:

// Start writing the data

bool ok = consumer-&gt;[startWriting](classansys_1_1_cff_file_consumer.xhtml#aff7fae604a6a9ccb6318096c895ec851)("elbow.cas.h5", [ansys::DataClass::CFF\_CASE](group__enums.xhtml#ggab852cc24891eb831942fb8da764d8ddba6c8b8209348df38321689fb67cd4b331));

if(!ok) {

 std::cerr &lt;&lt; "Error writing to case file" &lt;&lt; std::endl;

 delete consumer;

 return 1;

}

...

[ansys::CffFileConsumer::startWriting](classansys_1_1_cff_file_consumer.xhtml#aff7fae604a6a9ccb6318096c895ec851)

bool startWriting(const std::string &amp;file, DataClass dataClass)

Start writing data of the specified class to the file passed as an argument.

**Definition:** CffFileConsumerMethods.cpp:29



[CFF\_CASE](group__enums.xhtml#ggab852cc24891eb831942fb8da764d8ddba6c8b8209348df38321689fb67cd4b331)

@ CFF_CASE

**Definition:** CffTypes.h:419





The functions in the [ansys::CffConsumer](classansys_1_1_cff_consumer.xhtml "Class that provides functions to write data within a CFF database. The database may be stored within ...") class can then be used to write your data.