![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
The macros listed in this section are special macros that are used often in UDFs.
Thread Pointer for Zone ID (
Lookup_Thread)
You can use Lookup_Thread when you want to retrieve the pointer t to the thread that is associated with a given integer zone ID number for a boundary zone. The zone_ID that is passed to the macro is the zone number that ANSYS FLUENT assigns to the boundary and displays in the boundary condition dialog box (e.g., Fluid). Note that this macro does the inverse of THREAD_ID (see below).
There are two arguments to Lookup_Thread. domain is passed by ANSYS FLUENT and is the pointer to the domain structure. You supply the integer value of zone_ID.
For example, the code
int zone_ID = 2; Thread *thread_name = Lookup_Thread(domain,zone_ID); |
passes a zone ID of
to
Lookup_Thread. A zone ID of
may, for example, correspond to a wall zone in your case.
Now suppose that your UDF needs to operate on a particular thread in a domain (instead of looping over all threads), and the DEFINE macro you are using to define your UDF doesn't have the thread pointer passed to it from the solver (e.g., DEFINE_ADJUST). You can use Lookup_Thread in your UDF to get the desired thread pointer. This is a two-step process.
First, you will need to get the integer ID of the zone by visiting the boundary condition dialog box (e.g., Fluid) and noting the zone ID. You can also obtain the value of the Zone ID from the solver using RP_Get_Integer. Note that in order to use RP_Get_Integer, you will have had to define the zone ID variable first, either in another UDF using RP_Set_Integer, or on the Scheme side using rp-var-define (see Section 3.6 for details.)
Next, you supply the zone_ID as an argument to Lookup_Thread either as a hard-coded integer (e.g., 1, 2) or as the variable assigned from RP_Get_Integer. Lookup_Thread returns the pointer to the thread that is associated with the given zone ID. You can then assign the thread pointer to a thread_name and use it in your UDF.
|
Note that when
Lookup_Thread is utilized in a multiphase flow problem, the domain pointer that is passed to the function depends on the UDF that it is contained within. For example, if
Lookup_Thread is used in an adjust function (
DEFINE_ADJUST) then the mixture domain is passed and the thread pointer returned is the mixture-level thread.
|
Example
Below is a UDF that uses Lookup_Thread. In this example, the pointer to the thread for a given zone_ID is retrieved by Lookup_Thread and is assigned to thread. The thread pointer is then used in begin_f_loop to loop over all faces in the given thread, and in F_CENTROID to get the face centroid value.
/*******************************************************************/ Example of an adjust UDF that uses Lookup_Thread. Note that if this UDF is applied to a multiphase flow problem, the thread that is returned is the mixture-level thread ********************************************************************/ #include "udf.h" /* domain passed to Adjust function is mixture domain for multiphase*/ DEFINE_ADJUST(print_f_centroids, domain) { real FC[2]; face_t f; int ID = 1; /* Zone ID for wall-1 zone from Boundary Conditions task page */ Thread *thread = Lookup_Thread(domain, ID); begin_f_loop(f, thread) { F_CENTROID(FC,f,thread); printf("x-coord = %f y-coord = %f", FC[0], FC[1]); } end_f_loop(f,thread) } |
Zone ID (
THREAD_ID)
You can use THREAD_ID when you want to retrieve the integer zone ID number (displayed in a boundary conditions dialog box such as Fluid) that is associated with a given thread pointer t. Note that this macro does the inverse of Lookup_Thread (see above).
int zone_ID = THREAD_ID(t); |
Domain Pointer (
Get_Domain)
You can use the Get_Domain macro to retrieve a domain pointer when it is not explicitly passed as an argument to your UDF. This is commonly used in ON_DEMAND functions since DEFINE_ON_DEMAND is not passed any arguments from the ANSYS FLUENT solver. It is also used in initialization and adjust functions for multiphase applications where a phase domain pointer is needed but only a mixture pointer is passed.
Get_Domain(domain_id); |
domain_id is an
integer whose value is
1 for the mixture domain, but the values for the phase domains can be any integer greater than
. The
ID for a particular phase can be found be selecting it in the
Phases task page in
ANSYS FLUENT.
Phases
Single-Phase Flows
In the case of single-phase flows, domain_id is 1 and Get_Domain(1) will return the fluid domain pointer.
DEFINE_ON_DEMAND(my_udf) { Domain *domain; /* domain is declared as a variable */ domain = Get_Domain(1); /* returns fluid domain pointer */ ... } |
Multiphase Flows
In the case of multiphase flows , the value returned by Get_Domain is either the mixture-level, a phase-level, or an interaction phase-level domain pointer. The value of domain_id is always 1 for the mixture domain. You can obtain the domain_id using the ANSYS FLUENT graphical user interface much in the same way that you can determine the zone ID from the Boundary Conditions task page. Simply go to the Phases task page in ANSYS FLUENT and select the desired phase. The domain_id will then be displayed. You will need to hard code this integer ID as an argument to the macro as shown below.
DEFINE_ON_DEMAND(my_udf) { Domain *mixture_domain; mixture_domain = Get_Domain(1); /* returns mixture domain pointer */ /* and assigns to variable */ Domain *subdomain; subdomain = Get_Domain(2); /* returns phase with ID=2 domain pointer*/ /* and assigns to variable */ ... } |
Example
The following example is a UDF named get_coords that prints the thread face centroids for two specified thread IDs. The function implements the Get_Domain utility for a single-phase application. In this example, the function Print_Thread_Face_Centroids uses the Lookup_Thread function to determine the pointer to a thread, and then writes the face centroids of all the faces in a specified thread to a file. The Get_Domain(1) function call returns the pointer to the domain (or mixture domain, in the case of a multiphase application). This argument is not passed to DEFINE_ON_DEMAND.
/***************************************************************** Example of UDF for single phase that uses Get_Domain utility ******************************************************************/ #include "udf.h" FILE *fout; void Print_Thread_Face_Centroids(Domain *domain, int id) { real FC[2]; face_t f; Thread *t = Lookup_Thread(domain, id); fprintf(fout,"thread id %d\n", id); begin_f_loop(f,t) { F_CENTROID(FC,f,t); fprintf(fout, "f%d %g %g %g\n", f, FC[0], FC[1], FC[2]); } end_f_loop(f,t) fprintf(fout, "\n"); } DEFINE_ON_DEMAND(get_coords) { Domain *domain; domain = Get_Domain(1); fout = fopen("faces.out", "w"); Print_Thread_Face_Centroids(domain, 2); Print_Thread_Face_Centroids(domain, 4); fclose(fout); } |
Note that Get_Domain(1) replaces the extern Domain *domain expression used in previous releases of FLUENT 6.
Set Boundary Condition Value (
F_PROFILE)
F_PROFILE is typically used in a DEFINE_PROFILE UDF to set a boundary condition value in memory for a given face and thread. The index i that is an argument to F_PROFILE is also an argument to DEFINE_PROFILE and identifies the particular boundary variable (e.g., pressure, temperature, velocity) that is to be set. F_PROFILE is defined in mem.h.
Macro: | F_PROFILE( f, t, i) |
Argument types: | face_t f |
Thread *t | |
int i | |
Function returns: | void |
The arguments of F_PROFILE are f, the index of the face face_t; t, a pointer to the face's thread t; and i, an integer index to the particular face variable that is to be set. i is defined by ANSYS FLUENT when you hook a DEFINE_PROFILE UDF to a particular variable (e.g., pressure, temperature, velocity) in a boundary condition dialog box. This index is passed to your UDF by the ANSYS FLUENT solver so that the function knows which variable to operate on.
Suppose you want to define a custom inlet boundary pressure profile for your ANSYS FLUENT case defined by the following equation:
You can set the pressure profile using a
DEFINE_PROFILE UDF. Since a profile is an array of data, your UDF will need to create the pressure array by looping over all faces in the boundary zone, and for each face, set the pressure value using
F_PROFILE. In the sample UDF source code shown below, the
coordinate of the centroid is obtained using
F_CENTROID, and this value is used in the pressure calculation that is stored for each face. The solver passes the UDF the right index to the pressure variable because the UDF is hooked to
Gauge Total Pressure in the
Pressure Inlet boundary condition dialog box. See Section
2.3.15 for more information on
DEFINE_PROFILE UDFs.
/*********************************************************************** UDF for specifying a parabolic pressure profile boundary profile ************************************************************************/ #include "udf.h" DEFINE_PROFILE(pressure_profile,t,i) { real x[ND_ND]; /* this will hold the position vector */ real y; face_t f; begin_f_loop(f,t) { F_CENTROID(x,f,t); y = x[1]; F_PROFILE(f,t,i) = 1.1e5 - y*y/(.0745*.0745)*0.1e5; } end_f_loop(f,t) } |
THREAD_SHADOW(t)
THREAD_SHADOW returns the face thread that is the shadow of Thread *t if it is one of a face/face-shadow pair that comprise a thin wall. It returns NULL if the boundary is not part of a thin wall and is often used in an if statement such as:
if (!NULLP(ts = THREAD_SHADOW(t))) { /* Do things here using the shadow wall thread (ts) */ } |