CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (http://www.cfd-online.com/Forums/fluent-udf/)
-   -   FLUENT UDFs (http://www.cfd-online.com/Forums/fluent-udf/105383-fluent-udfs.html)

saisanthoshm88 July 29, 2012 13:59

FLUENT UDFs
 
Could some one please let me know how to write a UDF to assign a volume averaged temperature in a domain as the temperature at an outlet.

I think that the face loops in Fluent are meant to assign boundary conditions on a surface boundary and the cell loops are meant to access (or) set volumetric quantities.

Please correct me if Im wrong

Amir July 30, 2012 10:25

Quote:

Originally Posted by saisanthoshm88 (Post 374221)
Could some one please let me know how to write a UDF to assign a volume averaged temperature in a domain as the temperature at an outlet.

I think that the face loops in Fluent are meant to assign boundary conditions on a surface boundary and the cell loops are meant to access (or) set volumetric quantities.

Please correct me if Im wrong

Exactly; so you need to use a loop over cells to find average value and then use another loop over faces to assign the BC in appropriate macro.

Bests,

saisanthoshm88 July 31, 2012 15:12

1 Attachment(s)
Thanks for the reply Amir. Could you please look into the attached .c file of udf and let me know if it is fine to go on with.

I've two outlets so I used the macro Lookup_Thread(domain,zone_id) to reference them and then assigned the volume averaged temperature using two begin_f_loop(f,t) loops

I've interpreted it and found no errors.

On a conceptual basis please correct me if I'm wrong and also suggest if there is any better way of doing this.

As a newbie to the UDF programming in Fluent I'd certainly appreciate your help

Amir August 1, 2012 03:11

Dear Santhosh,

I don't think you're really a newbie in UDF, because it's handled well. :)
But just a point; As you noticed, it's stated in the manual that we can also use DEFINE_ADJUST macro for BC manipulation but honestly I did it with DEFINE_PROFILE so far because I'm not sure that the values in BC override the DEFINE_ADJUST values or not. So if I wanted to write such UDF, I used 1 DEFINE_ADJUST and 2 DEFINE_PROFILE macros in a file with global variables. So check the BC certainly to see whether they're affected in this way or not. (just for checking!)

Bests,

saisanthoshm88 August 1, 2012 04:47

1 Attachment(s)
Hi Amir,

Thanks for the suggestions. In case you experienced that the DEFINE_PROFILE macro is more reliable then i'd like to go with it.

Please find attached the modified UDF i've interpreted it and it has no errors but just to crosscheck please have a look into it and let me know if everything is fine there.

Thanking you for the help !

Amir August 1, 2012 06:14

Quote:

Originally Posted by saisanthoshm88 (Post 374762)
Please find attached the modified UDF i've interpreted it and it has no errors but just to crosscheck please have a look into it and let me know if everything is fine there.

Hi,

Unfortunately it's not correct. The procedure for DEFINE_PROFILE is not the same as DEFINE_ADJUST; i.e., you'll need F_PROFILE(...) statements in order to assign values to boundaries. Take a look over one of the examples of manual and it would be clear.
Another point; it's better to use initialization for accumulative variables in programming; you did it for tavg but didn't for vol_tot.
If you want to use DEFINE_PROFILE, you need global variables; something like this:
Code:

#include ....
real tavg, vol_tot; // global variables accessible via all macros
DEFINE_ADJUST(.....)
{
  .... //compute tavg
}
DEFINE_PROFILE(...)
{
  .... // for face 1
}
DEFINE_PROFILE(...)
{
  .... // for face 2
}

All in one file to be interpretable.

If everything is the same for assigning values to 2 faces, you can use just one DEFINE_PROFILE and use it for both faces.



Bests,

saisanthoshm88 August 1, 2012 07:57

Yaa I got your point Amir but now when I've prepared a udf following these suggestions, Fluent throws an error when I use the same udf name in both the macros viz.., DEFINE_ADJUST and DEFINE_PROFILE.

However the interpretation is successful with no errors only when different udf names were used in the DEFINE_ADJUST and DEFINE_PROFILE macros.

So while defining the backflow temperature at the outlet is it enough to just hook up the udf of the DEFINE_PROFILE macro

Amir August 1, 2012 08:22

Quote:

Originally Posted by saisanthoshm88 (Post 374807)
Yaa I got your point Amir but now when I've prepared a udf following these suggestions, Fluent throws an error when I use the same udf name in both the macros viz.., DEFINE_ADJUST and DEFINE_PROFILE.
However the interpretation is successful with no errors only when different udf names were used in the DEFINE_ADJUST and DEFINE_PROFILE macros.

Obviously you have to select different names for different macros. you can see these names while hooking in FLUENT GUI.
Quote:

Originally Posted by saisanthoshm88 (Post 374807)
So while defining the backflow temperature at the outlet is it enough to just hook up the udf of the DEFINE_PROFILE macro

Yes, this macro can access global variable; tavg.

Bests,

saisanthoshm88 August 1, 2012 08:26

Many thanks for your help Amir. Your suggestions were really valuable.

saisanthoshm88 August 1, 2012 11:28

I'm sorry for raising this again Amir but if the udf referenced in the macro DEFINE_PROFILE is hooked to the outlet boundary then does Fluent execute the macro DEFINE_ADJUST .

I wonder about this because the udf associated with the DEFINE_ADJUST macro is not hooked there.

My worry is that in case Fluent doesn't execute the DEFINE_ADJUST macro then a value of 0 will be assigned to the outlet temperature as the global variable tavg is initialized to zero in the begining

Amir August 1, 2012 11:48

No, just the UDFs that are hooked, are executed. Note that each UDF should be hooked in its proper panel; you have to hook DEFINE_ADJUST in it's panel and DEFINE_PROFILE in BC panel.
But a point I forgot is that because you're using accumulative variables you have to set initialization in DEFINE_ADJUST macro too. (it's more conservative even if you've used static variables)

Bests,

zainab August 8, 2012 05:21

Hi Amir
I am working on modeling 3D gas-liquid slug flow in horizontal pipe, and I cannot get the true slug phase distribution can you help me to write UDF for volume fraction where I wont the lower half of the cylindrical pipe being always filled with the secondary phase while the upper half taking its value from iterations.
thank you.

landa August 13, 2012 03:59

a question about under relaxation factor
 
I have a question about setting under relaxation factor.
is changing the relaxation factor supposed to change the final answer?!
when i changed it in a problem, the final solution that i was expected wasn't gained and when i decreased it again, the final solution changed again.

Amir August 13, 2012 06:17

Quote:

Originally Posted by landa (Post 376755)
I have a question about setting under relaxation factor.
is changing the relaxation factor supposed to change the final answer?!
when i changed it in a problem, the final solution that i was expected wasn't gained and when i decreased it again, the final solution changed again.

Hi,

It's a numerical setting tool. In some cases, with high relaxation factors few unstability may occur but in more stable cases, increasing these factors increases the rate of convergency. In these cases, if you provide enough iterations the same results will obtain. (The rate of convergency is changed)

Bests,

syavash August 13, 2012 17:39

Dear Saisanthoshm

Could you get it work by implementing define_profile for assigning boundary temperature?
I have a similar problem regarding with assigning specific temperatures into wall boundaries.

If so,would you please send me your UDF?!
My email is syavash_azna@yahoo.com
Thank you very much

Kanarya January 16, 2013 11:51

F_PROFILE(f,t,i) = C_UDMI(c0,t0,2);
 
Hi,
I have problem to read the C_UDMI now it is saving but if I use it in F_profile it is always Zero :(
I am simulating gas-solid flow. So I want to save velocity and volume fraction in outlet and then to use it in inlet so I managed to save it with C_UDMI but in inlet everything is zero it seems it doesnt work. here is my inlet profile:
DEFINE_PROFILE(abs_vel,t,i)
{
Domain *d;
cell_t c, c0;
face_t f;
Thread *ct,*t0;

begin_f_loop(f,t)
{

c0 = F_C0(f, t);
t0 = THREAD_T0(t);
if (C_UDMI(c0,t0,2) =0)
F_PROFILE(f,t,i)=0.001;
else
F_PROFILE(f,t,i) = C_UDMI(c0,t0,2);
}
end_f_loop(f,t)
}
thanks for your help!!!

Amir January 16, 2013 12:02

Quote:

Originally Posted by Kanarya (Post 402242)
Hi,
I have problem to read the C_UDMI now it is saving but if I use it in F_profile it is always Zero :(
I am simulating gas-solid flow. So I want to save velocity and volume fraction in outlet and then to use it in inlet so I managed to save it with C_UDMI but in inlet everything is zero it seems it doesnt work. here is my inlet profile:
DEFINE_PROFILE(abs_vel,t,i)
{
Domain *d;
cell_t c, c0;
face_t f;
Thread *ct,*t0;

begin_f_loop(f,t)
{

c0 = F_C0(f, t);
t0 = THREAD_T0(t);
if (C_UDMI(c0,t0,2) =0)
F_PROFILE(f,t,i)=0.001;
else
F_PROFILE(f,t,i) = C_UDMI(c0,t0,2);
}
end_f_loop(f,t)
}
thanks for your help!!!

Try F_UDMI(f,t,i) instead and check whether it works or not. (refer to UDF manual to see examples)

Bests,

Kanarya January 16, 2013 12:06

Quote:

Originally Posted by Amir (Post 402245)
Try F_UDMI(f,t,i) instead and check whether it works or not. (refer to UDF manual to see examples)

Bests,

thanks Amir!
DEFINE_PROFILE(abs_vel,t,i)
{

Domain *d;
Thread *ct,*t0;
cell_t c, c0;
face_t f;
//d = Get_Domain(1);
//t0= Lookup_Thread(d, 10014);

begin_f_loop(f,t)
{


c0 = F_C0(f, t);
t0 = THREAD_T0(t);
//if (C_UDMI(c0,t0,2) =0)
//F_PROFILE(c0,t0,i)=0.001;
//else
C_UDMI(c0,t0,2)=F_UDMI(f,t,2);
F_PROFILE(f,t,i)=F_UDMI(f,t,2) ;/*C_UDMI(c0,t0,2);*/
}
end_f_loop(f,t)

}
I tried this one bu doesnt work as well
thanks again for your help!

Amir January 16, 2013 12:22

Quote:

Originally Posted by Kanarya (Post 402248)
thanks Amir!
DEFINE_PROFILE(abs_vel,t,i)
{

Domain *d;
Thread *ct,*t0;
cell_t c, c0;
face_t f;
//d = Get_Domain(1);
//t0= Lookup_Thread(d, 10014);

begin_f_loop(f,t)
{


c0 = F_C0(f, t);
t0 = THREAD_T0(t);
//if (C_UDMI(c0,t0,2) =0)
//F_PROFILE(c0,t0,i)=0.001;
//else
C_UDMI(c0,t0,2)=F_UDMI(f,t,2);
F_PROFILE(f,t,i)=F_UDMI(f,t,2) ;/*C_UDMI(c0,t0,2);*/
}
end_f_loop(f,t)

}
I tried this one bu doesnt work as well
thanks again for your help!

#include "udf.h"
DEFINE_PROFILE(abs_vel,t,i)
{

face_t f;
begin_f_loop(f,t)
{

F_PROFILE(f,t,i)=F_UDMI(f,t,0) ;
}
end_f_loop(f,t)

}

Kanarya January 16, 2013 12:28

[QUOTE=Amir;402252]#include "udf.h"


All times are GMT -4. The time now is 11:49.