CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

FLUENT UDFs

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 29, 2012, 13:59
Default FLUENT UDFs
  #1
Senior Member
 
---------
Join Date: Oct 2010
Posts: 303
Rep Power: 17
saisanthoshm88 is on a distinguished road
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
__________________
Best regards,
Santhosh.
saisanthoshm88 is offline   Reply With Quote

Old   July 30, 2012, 10:25
Default
  #2
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 735
Blog Entries: 1
Rep Power: 22
Amir is on a distinguished road
Quote:
Originally Posted by saisanthoshm88 View Post
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,
__________________
Amir
Amir is offline   Reply With Quote

Old   July 31, 2012, 15:12
Default
  #3
Senior Member
 
---------
Join Date: Oct 2010
Posts: 303
Rep Power: 17
saisanthoshm88 is on a distinguished road
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
Attached Files
File Type: c VolAvgTemp.c (1.6 KB, 101 views)
__________________
Best regards,
Santhosh.

Last edited by saisanthoshm88; July 31, 2012 at 15:29.
saisanthoshm88 is offline   Reply With Quote

Old   August 1, 2012, 03:11
Default
  #4
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 735
Blog Entries: 1
Rep Power: 22
Amir is on a distinguished road
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,
__________________
Amir
Amir is offline   Reply With Quote

Old   August 1, 2012, 04:47
Default
  #5
Senior Member
 
---------
Join Date: Oct 2010
Posts: 303
Rep Power: 17
saisanthoshm88 is on a distinguished road
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 !
Attached Files
File Type: c VolAvgTempprofile.c (1.8 KB, 41 views)
__________________
Best regards,
Santhosh.
saisanthoshm88 is offline   Reply With Quote

Old   August 1, 2012, 06:14
Default
  #6
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 735
Blog Entries: 1
Rep Power: 22
Amir is on a distinguished road
Quote:
Originally Posted by saisanthoshm88 View Post
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,
__________________
Amir
Amir is offline   Reply With Quote

Old   August 1, 2012, 07:57
Default
  #7
Senior Member
 
---------
Join Date: Oct 2010
Posts: 303
Rep Power: 17
saisanthoshm88 is on a distinguished road
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
__________________
Best regards,
Santhosh.
saisanthoshm88 is offline   Reply With Quote

Old   August 1, 2012, 08:22
Default
  #8
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 735
Blog Entries: 1
Rep Power: 22
Amir is on a distinguished road
Quote:
Originally Posted by saisanthoshm88 View Post
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 View Post
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,
__________________
Amir
Amir is offline   Reply With Quote

Old   August 1, 2012, 08:26
Default
  #9
Senior Member
 
---------
Join Date: Oct 2010
Posts: 303
Rep Power: 17
saisanthoshm88 is on a distinguished road
Many thanks for your help Amir. Your suggestions were really valuable.
__________________
Best regards,
Santhosh.
saisanthoshm88 is offline   Reply With Quote

Old   August 1, 2012, 11:28
Default
  #10
Senior Member
 
---------
Join Date: Oct 2010
Posts: 303
Rep Power: 17
saisanthoshm88 is on a distinguished road
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
__________________
Best regards,
Santhosh.
saisanthoshm88 is offline   Reply With Quote

Old   August 1, 2012, 11:48
Default
  #11
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 735
Blog Entries: 1
Rep Power: 22
Amir is on a distinguished road
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,
__________________
Amir
Amir is offline   Reply With Quote

Old   August 8, 2012, 05:21
Default
  #12
New Member
 
zainab
Join Date: Mar 2012
Posts: 17
Rep Power: 14
zainab is on a distinguished road
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.
zainab is offline   Reply With Quote

Old   August 13, 2012, 03:59
Default a question about under relaxation factor
  #13
New Member
 
B Aram
Join Date: Aug 2012
Posts: 9
Rep Power: 13
landa is on a distinguished road
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.
landa is offline   Reply With Quote

Old   August 13, 2012, 06:17
Default
  #14
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 735
Blog Entries: 1
Rep Power: 22
Amir is on a distinguished road
Quote:
Originally Posted by landa View Post
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,
__________________
Amir
Amir is offline   Reply With Quote

Old   August 13, 2012, 17:39
Default
  #15
Senior Member
 
Syavash Asgari
Join Date: Apr 2010
Posts: 473
Rep Power: 18
syavash is on a distinguished road
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
syavash is offline   Reply With Quote

Old   January 16, 2013, 10:51
Default F_PROFILE(f,t,i) = C_UDMI(c0,t0,2);
  #16
Senior Member
 
Join Date: May 2011
Posts: 231
Rep Power: 15
Kanarya is on a distinguished road
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!!!
Kanarya is offline   Reply With Quote

Old   January 16, 2013, 11:02
Default
  #17
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 735
Blog Entries: 1
Rep Power: 22
Amir is on a distinguished road
Quote:
Originally Posted by Kanarya View Post
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,
__________________
Amir
Amir is offline   Reply With Quote

Old   January 16, 2013, 11:06
Default
  #18
Senior Member
 
Join Date: May 2011
Posts: 231
Rep Power: 15
Kanarya is on a distinguished road
Quote:
Originally Posted by Amir View Post
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!
Kanarya is offline   Reply With Quote

Old   January 16, 2013, 11:22
Default
  #19
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 735
Blog Entries: 1
Rep Power: 22
Amir is on a distinguished road
Quote:
Originally Posted by Kanarya View Post
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)

}
__________________
Amir

Last edited by Amir; January 16, 2013 at 11:40.
Amir is offline   Reply With Quote

Old   January 16, 2013, 11:28
Default
  #20
Senior Member
 
Join Date: May 2011
Posts: 231
Rep Power: 15
Kanarya is on a distinguished road
[QUOTE=Amir;402252]#include "udf.h"

Last edited by Kanarya; January 16, 2013 at 12:01.
Kanarya is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Commercial meshers] Fluent3DMeshToFoam simvun OpenFOAM Meshing & Mesh Conversion 50 January 19, 2020 15:33
heat transfer with RANS wall function, over a flat plate (validation with fluent) bruce OpenFOAM Running, Solving & CFD 6 January 20, 2017 06:22
Error in reading Fluent 13 case file in fluent 12 apurv FLUENT 2 July 12, 2013 07:46
solving ocean wave with Fluent or CFX? gholamghar Main CFD Forum 1 March 21, 2009 12:49
how to upload mutiple UDFs in FLUENT. shunahshep FLUENT 8 March 2, 2005 21:56


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