CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   UDF problem (https://www.cfd-online.com/Forums/fluent/45076-udf-problem.html)

Dimitris Fidaros June 18, 2007 17:23

UDF problem
 
I have recently started to use UDF and so I am new with it. I want to calculate the average value of user defined scalar on specific face of a 3d domain and to write this value on an ASCII file at the end of time step (transient simulation) but I couldn't manage to compute it. I would appreciate any help on this. Here is the listing I have done.

/************************************************** **********************/ * UDF that calculates the average chlorine concentration at outlet face*/ /* and it prints it at external ASCII file and on GUI */ /************************************************** **********************/

#include "udf.h" DEFINE_EXECUTE_AT_END(chlorine_out_average) { static int last_ts=-1; int cur_ts = N_TIME; real time = CURRENT_TIME; real fa real fi; real tfa; real tfi; real mfi; int n; int id = 4; /* Change id number in order to corespond to right boundary*/ face_t f;

Domain *d = Get_Domain(1); Thread *t = Lookup_Thread(d, id); cell_t c; FILE *fp = fopen("usds_story.txt", "w");

begin_f_loop(f, t) { fa = C_AREA(f,t); fi = C_UDSI(c,t,1); tfa += fa; tfi += fi*fa; } end_f_loop(f, t);

mfi = tfi / tfa;

if (last_ts != curr_ts) { last_ts = curr_ts; fprintf(fp,"Time_Step Time UDS") } fprintf(fp, "%d\ %g\t %g\t14.8E\n", cur_ts, time, mfi); printf("Time Step:%d Time:%g\t UDS:%g\t14.8E\n", cur_ts, time, mfi); }

Thanks in advance


Bogdan June 19, 2007 03:11

Re: UDF problem
 
as it tells the name, the macro DEFINE_EXECUTE_AT_END is executed at the end of the time step (in case of an unsteady simulation), or et the and of iteration (in case of a steady state simulation), so you don't need to check if you are at the first iteration within the timestep. I assume that in the variable fa you want to store the face area. the correct macro is F_AREA(f,t) and not C_AREA(f,t). Another thing, to print messages to the console, use the macro Message instead of printf.

Diego June 19, 2007 04:16

Re: UDF problem
 
Moreover, the correct way to write the Area macro is: F_AREA(A,f,t) , being A the name of the variable. The output A is a vector, not a scalar.

If you want to access to C_UDSI(c,t,1) you must say who is "c". You cannot start a loop over faces, so you will be in a face "f" and call for the UDS in the cell "c". Maybe you are trying to call F_UDSI(f,t,i) ?

For many variables exists two versions, one for the cell values (macros starting with C_XXX) and another for the interpolated values in faces (macros starting with F_XXX)

Greetings, Diego

Dimitris Fidaros June 20, 2007 20:59

Re: UDF problem
 
Thanks a lot. I fix my problem but i would to help me with the parallel version of this code



All times are GMT -4. The time now is 10:39.