CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   FLUENT (http://www.cfd-online.com/Forums/fluent/)
-   -   Seek help in writing UDF (http://www.cfd-online.com/Forums/fluent/45007-seek-help-writing-udf.html)

Jack Martinez June 12, 2007 09:05

Seek help in writing UDF
 
Hello everybody

I seek urgent help in writting a UDF.

I need to write a UDF that can extract temperature at the boundary wall face and an adjacent cell centroid in interior. The difference of these temperature is used with heat flux data (that has also to be extracted) at the boundary wall to calculate the heat transfer coefficient (HTC) over one particular face.

This heat transfer coefficient (HTC) will then be exported to a C++ program for further calculations.

OR

If there is some alternate way (using GUI or other) by which we can calculate the heat transfer coefficient (calculated with-in FLUENT) over a boundary face and can export it in a C++ program without using any TEXT USER INTERFACE (EXCEL; WORD; NOTEPAD file), this procedure then has to be repeated to calculate HTC over all the faces on the boundary..

Can someone please extend some help in writing this UDF.

Thanks in advance.

Jack.

Tomasz Bednarz June 12, 2007 19:29

Re: Seek help in writing UDF
 
This should help, kindest regards, Tomasz

d = Get_Domain(1);

tf = Lookup_Thread(d,Face_Id); tc = Lookup_Thread(d,Cell_Id);

c0=F_C0(f,tf);

begin_f_loop(f,tf) { face_wall_value = F_T(f,tf); neubouring_cell_value = C_T(c0,tc); } end_f_loop(f,tf)


Jack Martinez June 13, 2007 03:16

Re: Seek help in writing UDF
 
Hello Mr. Berdnarz

Thank you very much for your prompt reply.

Regarding your solution posted, kindly clarify my few queries:-

1. To my understanding, You have included separate Lookup_Thread for extracting thread pointer for wall face and the adjacent cell but the zone_id which, we need to define for using this Macro, is available only for wall faces (= zone_id at the particular boundary) how can we get the zone_id for adjacent cells.

2. Kindly suggest me some Macro to extract the wall heat flux at the same boundary face (Face_Id).

3. Do you have idea about script using which we can transfer the computed results, using this UDF, in the solver directly to a C++ program.

please give some input on:-

if we define a UDS for HTC and store it in UDM... will there be a possibity of accessing this HTC in other program while the solver is still running.

Tomasz Bednarz June 13, 2007 03:49

Re: Seek help in writing UDF
 
Sorry, it should be:

d = Get_Domain(1); tf = Lookup_Thread(d,Face_Id); tc = Lookup_Thread(d,Cell_Id); begin_f_loop(f,tf) { c0=F_C0(f,tf); face_wall_value = F_T(f,tf); neubouring_cell_value = C_T(c0,tc); } end_f_loop(f,tf)

Your queries: 1. face_id is id of your wall, cell_id is your interior region 2. you could estimate your heat flux by defining udf on the same matter, however Fluent has build-in functions for getting heat flux on the walls - please refer to the manual (also you can read on getting gradients in Fluent - http://warlock.amnesty.scene.pl) 3. surely - download Visual C/C++ from M$ website which is free of charge. then run Fluent having paths correctly defined for the compiler. then do your UDF in compiled version and you will be able to use any kind of C++ magic from your UDF... you can define time-points when your UDF function will be called - you can do it even for every inner iteration - again refer to the manual - all is there...

Hope it helps you a bit, kindest regards, Tomash


Jack Martinez June 13, 2007 04:55

Re: Seek help in writing UDF
 
hello.

In your proposed solution,

1. Does the face_ID & cell_ID hold different values? In that case how can we get the zone_ID for the cells.

2. If same, then then what is the advantage of using two Lookup_Thread. Can the below mentioned one be an alternative solution:-

d = Get_Domain(1);

t = Lookup_Thread(d,zone_ID);

begin_f_loop(f,t)

{

c0 = F_C0(f,t);

t0 = F_C0_THREAD(f,t);

temp_wall = F_T(f,t);

enthalpy_wall = F_H(f,t); \* for calculating the wall heat flux*\

if(FLUID_THREAD_P(t0))

return;

temp_adj = C_T(c0,t0);

}

end_f_loop(f,t)

Please give some more input on "run Fluent having paths correctly defined for the compiler. then do your UDF in compiled version and you will be able to use any kind of C++ magic from your UDF". I have not much experienced with C++...especially this stuff like exporting/importing data dynamically...

I need to transfer HTC values calculated on the face values after every iteration/time step to the C++ compiler.

Best Regrads Jack

Tomasz Bednarz June 13, 2007 10:30

Re: Seek help in writing UDF
 
Hi Jack,

> 1. Does the face_ID & cell_ID hold different values?
: In that case how can we get the zone_ID for the cells. '

Of course they are not the same... You can check ID in Fluent when defining BC for instance...

> 2. If same, then then what is the advantage of using two

no, they are not the same...

> Please give some more input on "run Fluent having paths correctly defined for the compiler. then do your UDF in

install visual studio, and there you have batch file which runs all env variables... from command prompt run fluent and you are there :)

> I need to transfer HTC values calculated on the face values after every iteration/time step to the C++ compiler.

shoudn't be a problem... please refer to the manual - you have examples and almost ready solutions there,

regards, Tomash


Nitesh Goyal June 13, 2007 11:51

Re: Seek help in writing UDF
 
Hi

Ok, if the zone id for cell is different then that of face at boundary, which one you would suggest to assign to the cell adjacent to the wall, the zone id of fluid or zone_id of interior. I checked in BC panel, they hold different ids.

I have to run my case in LINUX system. So I would be really thankful if you may please suggest me how to specify the path in FLUENT for GNU compiler to compile my UDF and also whether a dynamic library is neccesary or optional to link it with LINUX.

Regarding Exporting the HTC values, which example are you refering to. I checked the UDF manual 6.3 but couldn't find the appropriate manual in which they have mentioned any details about computing the HTC values or exporting values from solver to other compiler for post-processing.

Thanks in advance

Regards

Jack Martinez.

Jack Martinez June 13, 2007 11:56

Re: Seek help in writing UDF
 
Oh, I used my Friends computer so the message appeared with his name.

Tomasz Bednarz June 13, 2007 21:42

Re: Seek help in writing UDF
 
again: id_face should be your wall's zone id id_cell should be your fluid's zone id

Linux: under Linux you don't need to care about setting env variables as it is under XP. only be sure, that gcc/gc++ compiler is in your path... The procedure of compiling in fluent is then the same...

There are many examples of getting face values... writing them to the file then is not a big deal... for instance to save x location and the temperature:

begin_f_loop(f,t) {

F_CENTROID(xc,f,t);

fprintf(fout, "%.8f\t%.8f\t", xc[0], F_T(f,t)); ...

Hope it helps,


Jack Martinez June 14, 2007 10:24

Re: Seek help in writing UDF
 
Below mentioned is the UDF I hace conceptualised but due to problem in compiler I couldn't check it yet. Please give some input on it...

d=Get_Domain(1); t = Lookup_Thread(d,Face_Id); begin_f_loop(f,t) {

c0 = F_C0(f,t);

t0 = F_C0_THREAD(f,t);

temp_wall = F_T(f,t);

temp_grad = C_T_G(c0,t0)[1]*C_VOLUME(c0,t0);

heat_flux = k_cond*temp_grad;

if(!FLUID_THREAD_P(t0))

return;

temp_adj = C_T(c0,t0);

h = heat_flux/(temp_wall " temp_adj); /*printf("Temp_Wall: %g\n Temp_Cell_Centroid: %g \n HTC: %g",temp_wall, temp_adj, htc);*/ } end_f_loop(f,t) }

Looking forward for ur comment..

Also please let me know do u have experience with running Fluent in Batch Mode. I have some basic queries in that

Regards Jack Martinez...


All times are GMT -4. The time now is 01:45.