Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

____________________________________________________________________________________

How to access the heat flux in general purpose


Fluent UDFs?
Problem/Description:
When you are developing your own models or boundary conditions with ANSYS Fluent UDFs (User-
Defined Functions) it can be necessary to get access to the heat flux through a boundary zone. However,
there is no documented macro to get access to the heat flux calculated by Fluent.
You can use the undocumented macro BOUNDARY_HEAT_FLUX(f, t) to get access to the heat transfer
rate through a boundary zone.

Note: This macro is not documented. You can use it on your own risk. ANSYS can decline working on
support requests related to cases that depend on such macros and the macros can change without notice
in future versions of ANSYS Fluent.

Solution:
To access the heat transfer rate on walls and flow openings (e.g. velocity inlet) you can use the following
macro:

BOUNDARY_HEAT_FLUX(face_t, thread)

Although the macro is called "flux" it returns the heat transfer rate. If you need the heat flux you have to
divide it through the area of the face.

The following example code is also attached as C source file to this solution.

01 /*******************************************************************\
02 Start UDF code
03 Example uses undocumented macros
04 ANSYS can decline support for all UDFs that use such macros
05 Example UDF provided without guarantees and support
06 \*******************************************************************/
07
08 #include "udf.h"
09
10 DEFINE_ON_DEMAND(heat_flux_output)
11 {
12 /* Do nothing on the host process, only run serial and on compute
nodes */
13 #if !RP_HOST
14 Domain *d = Get_Domain(1);
15 Thread *t;
16 face_t f;
17 real hf;
18 real thf = 0.0;
19

© 2015 ANSYS, Inc. All rights reserved.


20 /* Abort if case is not initialized */
21 if (!Data_Valid_P())
22 Error("No data available");
23
24 /* Loop over all face threads */
25 thread_loop_f(t, d)
26 {
27 /* Skip current thread if it is not a wall or flow opening */
28 if (!BOUNDARY_FACE_THREAD_P(t) || THREAD_TYPE(t) ==
THREAD_F_JUMP)
29 continue;
30
31 /* Reset heat transfer rate for current thread */
32 hf = 0.0;
33
34 /* Loop over all faces in the current thread */
35 begin_f_loop(f, t)
36 {
37 /* Skip face if it is an external face (parallel only) */
38 if (!PRINCIPAL_FACE_P(f, t))
39 continue;
40
41 /* Get the heat flux of the face */
42 hf += BOUNDARY_HEAT_FLUX(f, t);
43 }
44 end_f_loop(f, t)
45
46 /* Build the sum over all compute nodes */
47 #if RP_NODE
48 hf = PRF_GRSUM1(hf);
49 #endif /* RP_NODE */
50
51 /* Get the total heat flux over all zones */
52 thf += hf;
53
54 /* Output for the current zone */
55 Message0("Total heat transfer rate for zone %d: %9.8e W\n",
THREAD_ID(t), hf);
56 }
57
58 /* Output for all ones */
59 Message0("\nTotal heat transfer rate for all zones: %9.8e W\n",
thf);
60 #endif /* !RP_HOST */
61 }
62
63 /*******************************************************************\
64 End UDF code
65 \*******************************************************************/
66

© 2015 ANSYS, Inc. All rights reserved.


Legend:
 Comment
 C statement
 Fluent macro
 Fluent loop macro
 Variable declaration
 String
 Compiler directive

To use this UDF download the attachment from the ANSYS Customer Portal. It is not recommended to
copy and paste the code from this document to avoid formatting issues.

Also attached is a demonstration case. To use it follow the steps:


1. Extract the contents of the attached ZIP file to a working directory
2. Start Fluent 3d, double precision, serial or parallel from that working directory
3. Load the case file
4. Compile the C source file and load the library
Note that the source file is provided with Windows line breaks.
5. Initialize the solution and run a few iterations
6. Execute the UDF from “Define > User-Defined > Execute on Demand…”

Although it is not required to run this case to convergence to see how this UDF works, just remember that
heat conduction cases should always be calculated using double precision and the residuals
convergence criterion should be lowered to get a reasonably converged solution.

Important: Use the described macro at your own risk. There is no documentation for this macro. ANSYS
can decline working on support requests related to cases that depend on such macros.

Attachments:
1. 2039857-example.zip
Archive contains example case and C source file to demonstrate the application of the macro
BOUNDARY_HEAT_FLUX(f, t)

© 2015 ANSYS, Inc. All rights reserved.

You might also like