![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
This section contains a description of looping macros that are to be used for multiphase UDFs only. They enable your function to loop over all cells and faces for given threads or domains. Refer to Section 1.10.1 and, in particular, Figure 1.10.1 for a discussion on hierarchy of structures within ANSYS FLUENT.
Looping Over Phase Domains in Mixture (
sub_domain_loop)
The sub_domain_loop macro loops over all phase domains (subdomains) within the mixture domain. The macro steps through and provides each phase domain pointer defined in the mixture domain as well as the corresponding phase_domain_index. As discussed in Section 1.10.1, the domain pointer is needed, in part, to gain access to data within each phase. Note that sub_domain_loop is similar in implementation to the sub_thread_loop macro described below.
int phase_domain_index; /* index of subdomain pointers */ Domain *mixture_domain; Domain *subdomain; sub_domain_loop(subdomain, mixture_domain, phase_domain_index) |
The variable arguments to sub_domain_loop are subdomain, mixture_domain, and phase_domain_index. subdomain is a pointer to the phase-level domain, and mixture_domain is a pointer to the mixture-level domain. The mixture_domain is automatically passed to your UDF by the ANSYS FLUENT solver when you use a DEFINE macro that contains a domain variable argument (e.g., DEFINE_ADJUST) and your UDF is hooked to the mixture. If mixture_domain is not explicitly passed to your UDF, you will need to use another utility macro to retrieve it (e.g., Get_Domain(1)) before calling sub_domain_loop (see Section 3.2.6). phase_domain_index is an index of subdomain pointers. phase_domain_index is 0 for the primary phase, and is incremented by one for each secondary phase in the mixture. Note that subdomain and phase_domain_index are set within the sub_domain_loop macro.
The following interpreted UDF patches an initial volume fraction for a particular phase in a solution. It is executed once at the beginning of the solution process. The function sets up a spherical volume centered at 0.5, 0.5, 0.5 with a radius of 0.25. A secondary-phase volume fraction of 1 is then patched to the cells within the spherical volume, while the volume fraction for the secondary phase in all other cells is set to 0.
/***************************************************************** UDF for initializing phase volume fraction ******************************************************************/ #include "udf.h" /* domain pointer that is passed by INIT function is mixture domain */ DEFINE_INIT(my_init_function, mixture_domain) { int phase_domain_index; cell_t cell; Thread *cell_thread; Domain *subdomain; real xc[ND_ND]; /* loop over all subdomains (phases) in the superdomain (mixture) */ sub_domain_loop(subdomain, mixture_domain, phase_domain_index) { /* loop if secondary phase */ if (DOMAIN_ID(subdomain) == 3) /* loop over all cell threads in the secondary phase domain */ thread_loop_c (cell_thread,subdomain) { /* loop over all cells in secondary phase cell threads */ begin_c_loop_all (cell,cell_thread) { C_CENTROID(xc,cell,cell_thread); if (sqrt(ND_SUM(pow(xc[0] - 0.5,2.), pow(xc[1] - 0.5,2.), pow(xc[2] - 0.5,2.))) < 0.25) /* set volume fraction to 1 for centroid */ C_VOF(cell,cell_thread) = 1.; else /* otherwise initialize to zero */ C_VOF(cell,cell_thread) = 0.; } end_c_loop_all (cell,cell_thread) } } } |
Looping Over Phase Threads in Mixture (
sub_thread_loop)
The sub_thread_loop macro loops over all phase-level threads (subthreads) associated with a mixture-level thread. The macro steps through and returns the pointer to each subthread as well as the corresponding phase_domain_index. As discussed in Section 1.10.1, if the subthread pointer is associated with an inlet zone, then the macro will provide the pointers to the face threads associated with the inlet for each of the phases.
int phase_domain_index; Thread *subthread; Thread *mixture_thread; sub_thread_loop(subthread, mixture_thread, phase_domain_index) |
The variable arguments to sub_thread_loop are subthread, mixture_thread, and phase_domain_index. subthread is a pointer to the phase thread, and mixture_thread is a pointer to the mixture-level thread. The mixture_thread is automatically passed to your UDF by the ANSYS FLUENT solver when you use a DEFINE macro that contains a thread variable argument (e.g., DEFINE_PROFILE) and your UDF is hooked to the mixture. If the mixture_thread is not explicitly passed to your UDF, you will need to use a utility macro to retrieve it before calling sub_thread_loop. phase_domain_index is an index of subdomain pointers that can be retrieved using the PHASE_DOMAIN_INDEX macro. (See Section 3.3.2 for details.) The index begins at 0 for the primary phase, and is incremented by one for each secondary phase in the mixture. Note that subthread and phase_domain_index are initialized within the sub_thread_loop macro definition.
Looping Over Phase Cell Threads in Mixture (
mp_thread_loop_c)
The
mp_thread_loop_c macro loops through all cell threads (at the mixture level) within the mixture domain and provides the pointers of the phase-level (cell) threads associated with each mixture-level thread. This is nearly identical to the
thread_loop_c macro (Section
3.3) when applied to the mixture domain. The difference is that, in addition to stepping through each cell thread, the macro also returns a pointer array
(
pt) that identifies the corresponding phase-level threads. The pointer to the cell thread for the
th phase is
pt[i], where
i is the
phase_domain_index.
pt[i] can be used as an argument to macros requiring the phase-level thread pointer.
phase_domain_index can be retrieved using the
PHASE_DOMAIN_INDEX macro. (See Section
3.3.2 for details.)
Thread **pt; Thread *cell_threads; Domain *mixture_domain; mp_thread_loop_c(cell_threads, mixture_domain, pt) |
The variable arguments to mp_thread_loop_c are cell_threads, mixture_domain, and pt. cell_threads is a pointer to the cell threads, and mixture_domain is a pointer to the mixture-level domain. pt is an array pointer whose elements contain pointers to phase-level threads.
mixture_domain is automatically passed to your UDF by the ANSYS FLUENT solver when you use a DEFINE macro that contains a domain variable argument (e.g., DEFINE_ADJUST) and your UDF is hooked to the mixture. If mixture_domain is not explicitly passed to your UDF, you will need to use another utility macro to retrieve it (e.g., Get_Domain(1), described in Section 3.2.6). Note that the values for pt and cell_threads are set within the looping function.
mp_thread_loop_c is typically used along with begin_c_loop. begin_c_loop loops over cells in a cell thread. When begin_c_loop is nested within mp_thread_loop_c, you can loop over all cells in all phase cell threads within a mixture.
Looping Over Phase Face Threads in Mixture (
mp_thread_loop_f)
The
mp_thread_loop_f macro loops through all face threads (at the mixture level) within the mixture domain and provides the pointers of the phase-level (face) threads associated with each mixture-level thread. This is nearly identical to the
thread_loop_f macro when applied to the mixture domain. The difference is that, in addition to stepping through each face thread, the macro also returns a pointer array (
pt) that identifies the corresponding phase-level threads. The pointer to the face thread for the
th phase is
pt[i], where
i is the
phase_domain_index.
pt[i] can be used as an argument to macros requiring the phase-level thread pointer. The
phase_domain_index can be retrieved using the
PHASE_DOMAIN_INDEX macro.
(See Section
3.3.2 for details.)
Thread **pt; Thread *face_threads; Domain *mixture_domain; mp_thread_loop_f(face_threads, mixture_domain, pt) |
The variable arguments to mp_thread_loop_f are face_threads, mixture_domain, and pt. face_threads is a pointer to the face threads, and mixture_domain is a pointer to the mixture-level domain. pt is an array pointer whose elements contain pointers to phase-level threads.
mixture_domain is automatically passed to your UDF by the ANSYS FLUENT solver if you are using a DEFINE macro that contains a domain variable argument (e.g., DEFINE_ADJUST) and your UDF is hooked to the mixture. If mixture_domain is not explicitly passed to your UDF, you may use another utility macro to retrieve it (e.g., Get_Domain(1), described in Section 3.2.6). Note that the values for pt and face_threads are set within the looping function.
mp_thread_loop_f is typically used along with begin_f_loop. begin_f_loop loops over faces in a face thread. When begin_f_loop is nested within mp_thread_loop_f, you can loop over all faces in all phase face threads within a mixture.