CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   DEFINE_EXECUTE_AT_END --> loop on boundary with the use of Lookup_Thread ??? (https://www.cfd-online.com/Forums/fluent-udf/121870-define_execute_at_end-loop-boundary-use-lookup_thread.html)

macfly August 7, 2013 01:33

DEFINE_EXECUTE_AT_END --> loop on boundary with the use of Lookup_Thread ???
 
Hi,

Here is a simple UDF that calculates and prints the volume integral of temperature at the end of each time step:

Code:

#include "udf.h"
DEFINE_EXECUTE_AT_END(execute_at_end)
{
Domain *d;
Thread *t;
real sum_T=0.;
cell_t c;
d = Get_Domain(1);
thread_loop_c(t,d)
        begin_c_loop(c,t)
                sum_T += C_T(c,t) * C_VOLUME(c,t);  /* Integrate temperature */
        end_c_loop(c,t)
printf("Volume integral of temperature = %g K*m^3\n", sum_T);
}

Now, I would like to do a similar operation but on a boundary, with the use of the Lookup_Thread function. The UDF manual only has an example for the calculation of something in a domain (Get_Domain), not on a boundary (Lookup_Thread). I tried to modify my code with no success. I can make it work with DEFINE_ADJUST at each iteration, but it's not what I want: I want to perform some calculation on a boundary at each time step, not at each iteration.

Any idea how I can tell DEFINE_EXECUTE_AT_END to loop on a boundary?

blackmask August 7, 2013 03:12

As you mentioned, use "Look_Thread" to find the specific thread.

Code:

#include "udf.h" DEFINE_EXECUTE_AT_END(execute_at_end) { Domain *d; Thread *t; real sum_T=0.; cell_t c;
real A_vec[ND_ND], A_scl;
d = Get_Domain(1); t = Lookup_Thread(12, d); /*change "12" to the actual id of your b.c. */        begin_c_loop(c,t)
F_AREA(A_vec, c, t);
A_scl = NV_MAG(A_vec);
sum_T += C_T(c,t) * A_scl;  /* Integrate temperature */        end_c_loop(c,t) printf("Surface integral of temperature = %g K\n", sum_T); }


macfly August 7, 2013 13:20

Thanks blackmask, I got it. Your example had little errors: it loops over cells instead of faces, and you inverted d and 12 in Lookup_Thread(d, 12). I guess you wrote it quick.

Here is my code for calculating area averaged T on outlet at the end of each time step:
Code:

DEFINE_EXECUTE_AT_END(execute_at_end)
{
Domain *domain;
Thread *thread;
face_t face;
real area[ND_ND];
real total_area = 0.0;
real total_area_ave_temp = 0.0;
int ID = 18; /* outlet ID displayed in Fluent boundary conditions panel */
domain = Get_Domain(1);
thread = Lookup_Thread(domain, ID);
        begin_f_loop(face, thread)
                F_AREA(area, face, thread);
                total_area += NV_MAG(area);
                total_area_ave_temp += NV_MAG(area)*F_T(face, thread);
        end_f_loop(face, thread)
T_mean = total_area_ave_temp/total_area;
printf("Area averaged T on boundary %d = %f K\n", ID, T_mean);
}

The code for averaging is inspired by the example in the UDF Manual 14.5 entitled Global Summation of Pressure on a Face Zone and its Area Average Computation.

blackmask August 7, 2013 20:12

You are right, I misplaced the domain pointer and thread id. However "begin_c_loop" and "begin_f_loop" are equivalent macros. I clicked "reply", copied your original code, added several lines and manually adjust the indentation. For some reason the format of the code is mangled.


All times are GMT -4. The time now is 08:32.