1.7. Data Types in Ansys Fluent

In addition to standard C and C++ language data types such as real, int, and so on that you can use to define data in your UDF, there are Ansys Fluent-specific data types that are associated with solver data. These data types represent the computational units for a mesh (Figure 1.1: Mesh Components). Variables that are defined using these data types are typically supplied as arguments to DEFINE macros, as well as to other special functions that access Ansys Fluent solver data.

Some of the more commonly used Ansys Fluent data types are:

Node

A structure data type that stores data associated with a mesh point.

face_t

An integer data type that identifies a particular face within a face thread.

cell_t

An integer data type that identifies a particular cell within a cell thread.

Thread

A structure data type that stores data that is common to the group of cells or faces that it represents. In the Thread data type there is an array (storage) of pointers that each point to an array of cell or face values of a particular field variable (such as pressure, velocity, or gradients). Within that array of pointers, the index by which to identify a pointer to the array of (cell or face values of) a particular field variable is of the type Svar. For multiphase applications, there is a thread structure for each phase, as well as for the mixture. See Multiphase-specific Data Types for details.

Svar

An index used to identify a pointer in the Thread storage. All possible values for this index variable are given in the enumeration of that type in the file src/storage/storage.h. Note that some values are generated using macros like SV_[COUPLED_]SOLUTION_VAR[_WITH_FC](...), SV_UDS_I(...) or SV_UDSI_G(...) and are therefore not found explicitly in the enumeration. If a pointer in the storage array of pointers still has the value NULL, memory for the corresponding field variable has not been allocated yet. A call to the function Alloc_Storage_Vars(domain, SV_..., ..., SV_NULL); can be used to change that allocation. The expression if (NULLP(THREAD_STORAGE(t, SV_...))) can be used to test whether the memory for a particular field variable has already been allocated on a given Thread or not.

Domain

A structure data type that stores data associated with a collection of node, face, and cell threads in a mesh. For single-phase applications, there is only a single domain structure. For multiphase applications, there are domain structures for each phase, the interaction between phases, as well as for the mixture. The mixture-level domain is the highest-level structure for a multiphase model. See Multiphase-specific Data Types for details.


Important:  All Ansys Fluent data types are case-sensitive.


When you use a UDF in Ansys Fluent, your function can access solution variables at individual cells or cell faces in the fluid and boundary zones. UDFs need to be passed appropriate arguments such as a thread reference (that is, a pointer to a particular thread) and the cell or face ID in order to enable individual cells or faces to be accessed. Note that a face ID or cell ID by itself does not uniquely identify the face or cell. A thread pointer is always required along with the ID to identify the thread to which the face (or cell) belongs.

Some UDFs are passed the cell index variable (c) as an argument (such as in DEFINE_PROPERTY(my_function,c,t)), or the face index variable (f) (such as in DEFINE_UDS_FLUX(my_function,f,t,i)). If the cell or face index variable (for example, cell_t c, face_t f) is not passed as an argument and is needed in the UDF, the variable is always available to be used by the function after it has been declared locally. See DEFINE_UDS_FLUX for an example.

The data structures that are passed to your UDF (as pointers) depend on the DEFINE macro you are using and the property or term you are trying to modify. For example, DEFINE_ADJUST UDFs are general-purpose functions that are passed a domain pointer (d) (such as in DEFINE_ADJUST(my_function, d)). DEFINE_PROFILE UDFs are passed a thread pointer (t) to the boundary zone to which the function is hooked, such as in DEFINE_PROFILE(my_function, thread, i).

Some UDFs (such as DEFINE_ON_DEMAND functions) are not passed any pointers to data structures, while others are not passed the pointer the UDF needs. If your UDF needs to access a thread or domain pointer that is not directly passed by the solver through an argument, then you will need to use a special Ansys Fluent-supplied macro to obtain the pointer in your UDF. For example, DEFINE_ADJUST is passed only the domain pointer, so if your UDF needs a thread pointer, it will have to declare the variable locally and then obtain it using the special macro Lookup_Thread. An exception to this is if your UDF needs a thread pointer to loop over all of the cell threads or all the face threads in a domain (using thread_loop_c(c,t) or thread_loop_f(f,t), respectively) and it is not passed to the DEFINE macro. Since the UDF will be looping over all threads in the domain, you will not need to use Lookup_Thread to get the thread pointer to pass it to the looping macro; you will just need to declare the thread pointer (and cell or face ID) locally before calling the loop. See DEFINE_ADJUST for an example.

As another example, if you are using DEFINE_ON_DEMAND (which is not passed any pointer argument) to execute an asynchronous UDF and your UDF needs a domain pointer, then the function will need to declare the domain variable locally and obtain it using Get_Domain. See DEFINE_ON_DEMAND for an example. Refer to Special Macros for details.