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

UDF to record FLUENT Solver variables...

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree5Likes
  • 1 Post By DoHander
  • 1 Post By dmoroian
  • 2 Post By sbaffini
  • 1 Post By mariachi

Reply
 
LinkBack Thread Tools Display Modes
Old   January 29, 2010, 07:09
Exclamation UDF to record FLUENT Solver variables...
  #1
Member
 
Join Date: Jan 2010
Posts: 53
Rep Power: 7
mariachi is on a distinguished road
dear friends,

Fluent provides macros to access solution variables like velocity etc. These macros are used in writing UDF to access any variable of interest.

I am doing LES, and i want to capture the fluctuations in velocity. If i write a UDF to access the velocity variable provided in these macros, i can observe the fluctuating component of velocity which will offcourse be not observed once the same UDF is linked to URANS case. Is that right? Correct me if i am wrong.

Plz anyone help me in writing the UDF or give me if someone has done some similar work, i dont know how to write the UDF!

Waiting patiently for your quick reply
mariachi is offline   Reply With Quote

Old   January 30, 2010, 14:00
Default
  #2
Senior Member
 
Join Date: Nov 2009
Posts: 411
Rep Power: 10
DoHander is on a distinguished road
Maybe this will help you:

pressure time history of some nodes

it is actually a Scheme macro and not a UDF, but you can use this in Fluent if you want to save some data at every time step.

I suspect you want to record the velocity fluctuations in some particular region and not on your entire mesh (if you have a 3d problem and try to save these at every point at each time step you will end up with some GB of data).

Do
DoHander is offline   Reply With Quote

Old   January 31, 2010, 06:46
Default
  #3
Member
 
Join Date: Jan 2010
Posts: 53
Rep Power: 7
mariachi is on a distinguished road
Hey Do thanks for ur input,

Yeah exactly this is the problem, i want to capture velocity fluctuations at a single cell or face or node, not the entire domain or the entire zone (mesh is 10 mill so hard disk is gonna start crying haha).

I saw ur link, i havent looked into scheme programming before so ill do check it out as well. But i have heard that for my particular problem, i have to write UDF. Nobody mentioned scheme macro, but surely ill see them as well.

I have been studying UDF for the past couple of days, i can use the DEFINE_EXECUTE_AT_END macro which executes the UDF at the end of each time step. Now i am facing 2 problems in the UDF,

1. How to tell Fluent to pick up say x property at y cell? I have used UDF's which do this, but they either do it for the entire domain or the entire zone. I couldnt find any which does the operation on a single cell...

2. After that i want the UDF to write that value to say data.out or data.txt file on the hard disk? I have used UDF's that print the data onto ur Fluent screen after every time step, but i dont want that...

Can u help...
mariachi is offline   Reply With Quote

Old   January 31, 2010, 14:02
Default
  #4
Senior Member
 
Join Date: Nov 2009
Posts: 411
Rep Power: 10
DoHander is on a distinguished road
"2. After that i want the UDF to write that value to say data.out or data.txt file on the hard disk? I have used UDF's that print the data onto ur Fluent screen after every time step, but i dont want that..."

Open a file and use fprintf instead of Message or printf ... This should be basic for any C programmer (this will write an integer to data.txt):

FILE *fp;
fp=fopen("data.txt","w");
fprintf(fp,"%d\n",int_test);
..............

You should probably move the part that opens the file in a EXECUTE_ON_DEMAND and the part that actually writes in EXECUTE_AT_END, and keep *fp as a global variable in your UDF.

Do
maphd likes this.
DoHander is offline   Reply With Quote

Old   February 1, 2010, 12:30
Default
  #5
Member
 
Join Date: Jan 2010
Posts: 53
Rep Power: 7
mariachi is on a distinguished road
Thankyou so much,
Ill check it out and give u the input, hope i dont have to ask any more questions
mariachi is offline   Reply With Quote

Old   February 1, 2010, 14:37
Default Monitors
  #6
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 647
Rep Power: 11
dmoroian is on a distinguished road
Quote:
Originally Posted by mariachi View Post
... i want to capture velocity fluctuations at a single cell or face or node...
Hi Mariachi,
Why don't you use monitors for this purpose? You will avoid writing udf's!

Dragos
dmoroian is offline   Reply With Quote

Old   February 2, 2010, 13:54
Default
  #7
Member
 
Join Date: Jan 2010
Posts: 53
Rep Power: 7
mariachi is on a distinguished road
Hey Dragos,

If u read my original post, i want to do this to show the difference of how the NS equations are solved for LES and URANS. In URANS equations, although we do take the time derivative, but its the time derivative of mean velocity "u bar". But in LES, time derivative of actual velocity is taken which includes the fluctuating part as well.

So i want to access this velocity variable "u" solved in the equations. for URANS it will show no fluctuations, for LES it will show fluctuations.Since Fluent calculates all values at the centroid of each cell, i want to record this value at a single cell at each time step. No such option is available in the monitors.

Also i have heard from everybody that u have to write a UDF to accomplish this task. Now i dont exactly know that the approach which i am taking, which i described above, is correct because my theoretical knowledge about the background equations which Fluent solves is not so good. Plz tell me if im wrong???

Thanks
mariachi is offline   Reply With Quote

Old   February 4, 2010, 07:06
Default
  #8
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 647
Rep Power: 11
dmoroian is on a distinguished road
I still think that you may use monitors for this, but if you want udf's...here it comes an example:
Code:
#include "udf.h"
DEFINE_ON_DEMAND(bubu)
{
   real pos[ND_ND] = {1,2,3};/*the position of the monitoring point*/
   static cell_t c0 = -1;/*index of the cell containing the monitoring point*/
   cell_t c;
   static Thread *t0 = NULL;/*thread of the cell containing the monitoring point*/
   Thread *t;
   real x[ND_ND], d2 = 1.0e9, d20 = 1.0e9;
   FILE *pf;
   

   Domain *d = Get_Domain(1);
   
   /*find once the thread and index of the cell containing the monitoring point*/
   if(NULL == t0)
      thread_loop_c(t,d)
      {
         begin_c_loop(c,t)
         {
            C_CENTROID(x,c,t);
            NV_V(x,-=,pos);
            d2 = NV_MAG2(x);
            if(d2 < d20)
            {
               d20 = d2;
               t0 = t;
               c0 = c;
            }
         }
         end_c_loop(c,t)
      }
   if(NULL == (pf = fopen("Ux.txt","a")))
      Error("Could not open file!\n");
   fprintf(pf,"%e\t%e\n",CURRENT_TIME, C_U(c0,t0));
   fclose(pf);
}
Note: I did not try even to compile this, so use it as guidance!
maphd likes this.
dmoroian is offline   Reply With Quote

Old   February 9, 2010, 07:39
Default
  #9
Senior Member
 
sbaffini's Avatar
 
Paolo Lampitella
Join Date: Mar 2009
Location: Italy
Posts: 534
Blog Entries: 14
Rep Power: 17
sbaffini will become famous soon enough
As stated by dmoroian, the most obvious way to do this is by defining a monitor point (unless you don't want the velocity in a whole region). There is no difference in the turbulence model you are going to use, you just need to monitor the velocity in a specified point...and of course you have to write the result in a file, instead of printing it on the console
startup0820 and maphd like this.
sbaffini is offline   Reply With Quote

Old   February 19, 2010, 13:25
Default
  #10
Member
 
Join Date: Jan 2010
Posts: 53
Rep Power: 7
mariachi is on a distinguished road
Thanks for ur guidance,

I have used point monitors and it seems its working well as i wanted. So far so good
maphd likes this.
mariachi is offline   Reply With Quote

Reply

Tags
les, macros, udf, velocity fluctuations

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
UDF in Fluent Andrew Fluent UDF and Scheme Programming 4 March 16, 2012 04:35
Using Fluent with a UDF frm a remote m/c aarti FLUENT 2 September 11, 2008 19:53
compiling my UDF Seyed Farid Hosseinizadeh FLUENT 22 February 14, 2006 11:19
UDF problem caused by various version of Fluent Yurong FLUENT 3 January 15, 2006 11:57
UDF variables F1, y / problem with UDF Fabian FLUENT 6 June 2, 2003 10:22


All times are GMT -4. The time now is 00:13.