![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Many UDF tasks require repeated operations to be performed on nodes, cells, and threads in a computational domain. For your convenience, ANSYS FLUENT has provided you with a set of predefined macros to accomplish.looping tasks. For example, to define a custom boundary profile function you will need to loop over all the faces in a face thread using begin..end_f_loop looping macros. For operations where you want to loop over all the faces or cells in a domain, you will need to nest a begin..end_f_loop or begin..end_c_loop inside a thread_loop_f or thread_loop_c, respectively.
The following general looping macros can be used for UDFs in single-phase or multiphase models in ANSYS FLUENT. Definitions for these macros are contained in the mem.h header file.
|
You should not access a scheme variable using any of the
RP_GET_... functions from inside a cell or face looping macro (c_loop or f_loop). This type of communication between the solver and cortex is very time consuming and therefore should be done outside of loops.
|
Looping Over Cell Threads in a Domain (
thread_loop_c)
You can use
thread_loop_c
when you want to loop over all cell threads in a given domain. It consists of a single statement, followed by the operation(s) to be performed on all cell threads in the domain enclosed within braces
{}
as shown below. Note that
thread_loop_c is similar in implementation to the
thread_loop_f macro described below.
Domain *domain; Thread *c_thread; thread_loop_c(c_thread, domain) /*loops over all cell threads in domain*/ { } |
Looping Over Face Threads in a Domain (
thread_loop_f)
You can use
thread_loop_f when you want to loop over all face threads in a given domain. It consists of a single statement, followed by the operation(s) to be performed on all face threads in the domain enclosed within braces
{}
as shown below. Note that
thread_loop_f is similar in implementation to the
thread_loop_c macro described above.
Thread *f_thread; Domain *domain; thread_loop_f(f_thread, domain)/* loops over all face threads in a domain*/ { } |
Looping Over Cells in a Cell Thread (
begin...end_c_loop)
You can use
begin_c_loop and
end_c_loop when you want to loop over all cells in a given cell thread. It contains a
begin and
end loop statement, and performs operation(s) on each cell in the cell thread as defined between the braces
{}
. This loop is usually nested within
thread_loop_c when you want to loop over all cells in all cell threads in a domain.
cell_t c; Thread *c_thread; begin_c_loop(c, c_thread) /* loops over cells in a cell thread */ { } end_c_loop(c, c_thread) |
Example
/* Loop over cells in a thread to get information stored in cells. */ begin_c_loop(c, c_thread) { /* C_T gets cell temperature. The += will cause all of the cell temperatures to be added together. */ temp += C_T(c, c_thread); } end_c_loop(c, c_thread) } |
Looping Over Faces in a Face Thread (
begin...end_f_loop)
You can use
begin_f_loop and
end_f_loop when you want to loop over all faces in a given face thread. It contains a
begin and
end loop statement, and performs operation(s) on each face in the face thread as defined between the braces
{}
. This loop is usually nested within
thread_loop_f when you want to loop over all faces in all face threads in a domain.
face_t f; Thread *f_thread; begin_f_loop(f, f_thread) /* loops over faces in a face thread */ { } end_f_loop(f, f_thread) |
Example
/* Loop over faces in a face thread to get the information stored on faces. */ begin_f_loop(f, f_thread) { /* F_T gets face temperature. The += will cause all of the face temperatures to be added together. */ temp += F_T(f, f_thread); } end_f_loop(f, f_thread) |
Looping Over Faces of a Cell (
c_face_loop)
The following looping function loops over all faces of a given cell. It consists of a single loop statement, followed by the action to be taken in braces
{}
.
cell_t c; Thread *t; face_t f; Thread *tf; int n; c_face_loop(c, t, n) /* loops over all faces of a cell */ { . . . f = C_FACE(c,t,n); tf = C_FACE_THREAD(c,t,n); . . . } |
The argument n is the local face index number. The local face index number is used in the C_FACE macro to obtain the global face number (e.g., f = C_FACE(c,t,n)).
Another useful macro that is often used in c_face_loop is C_FACE_THREAD . This macro is used to reference the associated face thread (e.g., tf = C_FACE_THREAD(c,t,n)).
Refer to Section 3.8 for other macros that are associated with c_face_loop.
Looping Over Nodes of a Cell (
c_node_loop)
c_node_loop(c,t,n) is a function that loops over all nodes of a given cell. It consists of a single loop statement, followed by the action to be taken in braces
{}
.
Example:
cell_t c; Thread *t; int n; Node *node; c_node_loop(c,t,n) { . . node = C_NODE(c,t,n); . . } |
Here, n is the local node index number . The index number can be used with the C_NODE macro to obtain the global cell node number (e.g., node = C_NODE(c,t,n)).
Looping Over Nodes of a Face (
f_node_loop)
f_node_loop(f,t,n) is a function that loops over all nodes of a given face. It consists of a single loop statement, followed by the action to be taken in braces
{}
.
Example
face_t f; Thread *t; int n; Node *node; f_node_loop(f,t,n) { . . . node = F_NODE(f,t,n); . . . } |
Here, n is the local node index number . The index number can be used with the F_NODE macro to obtain the global face node number (e.g., node = F_NODE(f,t,n)).
See Section 2.6.4 for an example of a UDF that uses f_node_loop.