[ANSYS, Inc. Logo] return to home search
next up previous contents index

3.1 Introduction

ANSYS FLUENT provides numerous C types, functions, and preprocessor macros to facilitate the programming of UDFs and the use of CFD objects as defined inside ANSYS FLUENT. The previous chapter presented DEFINE macros with which you must define your UDF. This chapter presents predefined functions (implemented as macros in the code) that are supplied by ANSYS FLUENT that you will use to code your UDF. These macros allow you to access data in an ANSYS FLUENT solver such as cell variables (e.g., cell temperature, centroid), face variables (e.g., face temperature, area), or connectivity variables (e.g., adjacent cell thread and index) that your UDF can use in a computation. A special set of macros commonly used in UDFs is provided that return such values as the thread ID pointer (an internal ANSYS FLUENT structure) when passed the Zone ID (the number assigned to a zone in a boundary conditions dialog box). Another special macro ( F_PROFILE) enables your UDF to set a boundary condition value in the solver. Other types of macros are provided that enable your function to loop over nodes, cells, and faces in a thread or domain in order to retrieve and/or set values. Finally, data access macros that are specific to a particular model (e.g., DPM, NOx) are presented, as well as macros that perform vector, time-dependent, Scheme, and I/O operations.

Function definitions for the macros provided in this chapter are contained in header files. Header files are identified by the .h suffix as in mem.h, metric.h, and dpm.h and are stored in the source code folder:

path $\backslash$ ANSYS Inc $\backslash$ v120 $\backslash$ fluent $\backslash$ fluent12.0. $\stackrel{\Downarrow}{x} \backslash$ src $\backslash$ udf.h

where path is the folder in which you have installed ANSYS FLUENT (by default, the path is C: $\backslash$ Program Files), and $x$ is replaced by the appropriate number for the release (e.g., 9 for fluent12.0.9).

The header files, unless explicitly noted, are included in the udf.h file, so your UDF does not need to contain a special #include compiler directive. You must, however, remember to include the #include "udf.h" directive in any UDF that you write.

Access to data from an ANSYS FLUENT solver is accomplished by hooking your UDF C function (after it is compiled or interpreted) to the code through the graphical user interface (GUI). After the UDF is correctly hooked, the solver's data is passed to the function and is available to use whenever it is called. These data are automatically passed by the solver to your UDF as function arguments. Note that all solver data, regardless of whether they are passed to your UDF by the solver or returned to the solver by the UDF, are specified in SI units. Macros in this chapter are listed with their arguments, argument types, returned value(s), if applicable, and header file.

Each function behind a macro either outputs a value to the solver as an argument, or returns a value that is then available for assignment in your UDF. Input arguments belong to the following ANSYS FLUENT data types:


Node *node pointer to a node
cell_t c cell identifier
face_t f face identifier
Thread *t pointer to a thread
Thread **pt pointer to an array of phase threads
   

Below is an example of a UDF that assigns initial temperature, which utilizes two data access macros ( C_T and C_CENTROID) and two looping macros ( begin..end_c_loop_all and thread_loop_c). Two looping macros are used to set the cell temperature of each cell in every thread in the computational domain. begin..end_c_loop_all is used to loop over all the cells in a cell thread to get the cell centroid and set the cell temperature, and thread_loop_c allows this loop to be repeated over all cell threads in the domain.

C_CENTROID has three arguments: xc, c, and t. Cell identifier c and cell thread pointer t are input arguments, and the argument array xc (the cell centroid) is output (as an argument) to the solver and used in the UDF in a conditional test.

C_T is used to set the cell temperature to the value of $400$ or $300$, depending on the outcome of the conditional test. It is passed the cell's ID c and thread pointer t and returns the real value of the cell temperature to the ANSYS FLUENT solver.

Example

/***********************************************************************
   UDF for initializing flow field variables
   Example of C_T and C_CENTROID usage.
************************************************************************/

#include "udf.h"

DEFINE_INIT(my_init_func,d)
{
  cell_t c;
  Thread *t;
  real xc[ND_ND];

  /* loop over all cell threads in the domain  */
  thread_loop_c(t,d)
    {

      /* loop over all cells  */
      begin_c_loop_all(c,t)
        {
          C_CENTROID(xc,c,t);
          if (sqrt(ND_SUM(pow(xc[0] - 0.5,2.),
                          pow(xc[1] - 0.5,2.),
                          pow(xc[2] - 0.5,2.))) < 0.25)
            C_T(c,t) = 400.;
          else
            C_T(c,t) = 300.;
        }
      end_c_loop_all(c,t)
    }
}


next up previous contents index Previous: 3. Additional Macros for
Up: 3. Additional Macros for
Next: 3.2 Data Access Macros
Release 12.0 © ANSYS, Inc. 2009-01-14