![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
There are three types of cell looping macros that are available for parallel coding; one that loops over interior cells only, exterior cells only, and both interior and exterior cells.
Looping Over Cells
A partitioned mesh in parallel ANSYS FLUENT is made up of interior cells and exterior cells (see Figure 7.2.1). There is a set of cell-looping macros you can use to loop over interior cells only, exterior cells only, or both interior and exterior cells.
Interior Cell Looping Macro
The macro begin,end_c_loop_int loops over interior cells in a partitioned mesh (Figure 7.5.1) and is identified by the suffix int. This macro pair can also be used by the serial version of ANSYS FLUENT to loop over all cells in the given thread. It contains a begin and end statement, and between these statements, operations can be performed on each of the thread's interior cells in turn. The macro is passed a cell index c and a cell thread pointer tc.
begin_c_loop_int(c, tc) { } end_c_loop_int(c, tc) |
![]() |
Example
real total_volume = 0.0; begin_c_loop_int(c,tc) { /* C_VOLUME gets the cell volume and accumulates it. The end result will be the total volume of each compute node's respective mesh */ total_volume += C_VOLUME(c,tc); } end_c_loop_int(c,tc) |
Exterior Cell Looping Macro
The macro begin,end_c_loop_ext loops over exterior cells in a partitioned mesh (Figure 7.5.2) and is identified by the suffix ext. It contains a begin and end statement, and between these statements, operations can be performed on each of the thread's exterior cells in turn. The macro is passed a cell index c and cell thread pointer tc. In most situations, there is no need to use the exterior cell loop macros. They are only provided for convenience if you come across a special need in your UDF.
begin_c_loop_ext(c, tc) { } end_c_loop_ext(c,tc) |
![]() |
Interior and Exterior Cell Looping Macro
The macro begin,end_c_loop can be used in a serial or parallel UDF. In parallel, the macro will loop over all interior and exterior cells in a mesh partition (Figure 7.5.3). Note that in serial, this pair of macros is equivalent to the begin,end_c_loop_int macros. It contains a begin and end statement, and between these statements, operations can be performed on each of the thread's interior and exterior cells in turn. The macro is passed a cell index c and a cell thread pointer tc.
begin_c_loop(c, tc) { } end_c_loop(c ,tc) |
![]() |
Example
real temp; begin_c_loop(c,tc) { /* get cell temperature, compute temperature function and store result in user-defined memory, location index 0. */ temp = C_T(c,tc); C_UDMI(c,tc,0) = (temp - tmin) / (tmax - tmin); /* assumes a valid tmax and tmin has already been computed */ } end_c_loop(c,tc) |
Looping Over Faces
For the purpose of discussing parallel ANSYS FLUENT, faces can be categorized into two types: interior faces and boundary zone faces (Figure 7.2.2). Partition boundary faces are interior faces that lie on the partition boundary of a compute node's mesh.
begin,end_f_loop is a face looping macro available in parallel ANSYS FLUENT that loops over all interior and boundary zone faces in a compute node. The macro begin,end_f_loop contains a begin and end statement, and between these statements, operations can be performed on each of the faces of the thread. The macro is passed a face index f and face thread pointer tf.
begin_f_loop(f, tf) { } end_f_loop(f,tf) |
|
begin_f_loop_int and
begin_f_loop_ext are looping macros that loop around interior and exterior faces in a compute node, respectively. The
_int form is equivalent to
begin_f_loop_int. Although these macros exist, they do not have a practical application in UDFs and should not be used.
|
Recall that partition boundary faces lie on the boundary between two adjacent compute nodes and are represented on both nodes. Therefore, there are some computations (e.g., summations) when a partition boundary face will get counted twice in a face loop. This can be corrected by testing whether the current node is a face's principal compute node inside your face looping macro, using PRINCIPAL_FACE_P . This is shown in the example below. See Section 7.2 for details.
Example
begin_f_loop(f,tf) /* each compute node checks whether or not it is the principal compute node with respect to the given face and thread */ if PRINCIPAL_FACE_P(f,tf) /* face is on the principal compute node, so get the area and pressure vectors, and compute the total area and pressure for the thread from the magnitudes */ { F_AREA(area,f,tf); total_area += NV_MAG(area); total_pres_a += NV_MAG(area)*F_P(f,tf); } end_f_loop(f,tf) total_area = PRF_GRSUM1(total_area); total_pres_a = PRF_GRSUM1(total_pres_a); |