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

UDF to record FLUENT Solver variables...

Register Blogs Community New Posts Updated Threads Search

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 29, 2010, 06:09
Exclamation UDF to record FLUENT Solver variables...
  #1
Member
 
Join Date: Jan 2010
Posts: 54
Rep Power: 16
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, 13:00
Default
  #2
Senior Member
 
Join Date: Nov 2009
Posts: 411
Rep Power: 19
DoHander is on a distinguished road
Maybe this will help you:

http://www.cfd-online.com/Forums/flu...ome-nodes.html

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, 05:46
Default
  #3
Member
 
Join Date: Jan 2010
Posts: 54
Rep Power: 16
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, 13:02
Default
  #4
Senior Member
 
Join Date: Nov 2009
Posts: 411
Rep Power: 19
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 and athalia like this.
DoHander is offline   Reply With Quote

Old   February 1, 2010, 11:30
Default
  #5
Member
 
Join Date: Jan 2010
Posts: 54
Rep Power: 16
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, 13:37
Default Monitors
  #6
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20
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, 12:54
Default
  #7
Member
 
Join Date: Jan 2010
Posts: 54
Rep Power: 16
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, 06:06
Default
  #8
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20
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 and athalia like this.
dmoroian is offline   Reply With Quote

Old   February 9, 2010, 06:39
Default
  #9
Senior Member
 
sbaffini's Avatar
 
Paolo Lampitella
Join Date: Mar 2009
Location: Italy
Posts: 2,152
Blog Entries: 29
Rep Power: 39
sbaffini will become famous soon enoughsbaffini will become famous soon enough
Send a message via Skype™ to sbaffini
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, 12:25
Default
  #10
Member
 
Join Date: Jan 2010
Posts: 54
Rep Power: 16
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

Old   September 23, 2019, 14:34
Default
  #11
New Member
 
Athalia
Join Date: Sep 2019
Posts: 2
Rep Power: 0
athalia is on a distinguished road
Quote:
Originally Posted by dmoroian View Post
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!

Hello @dmoroian,

it's been over 9 years! But I hope you could answer two questions about your code.

1. I believe in

Code:
C_CENTROID(x,c,t);
            NV_V(x,-=,pos);
            d2 = NV_MAG2(x);
            if(d2 < d20)
            {
               d20 = d2;
               t0 = t;
               c0 = c;
            }
you calculate the square of the magnitude of vector "x - pos". In order to find the cell with given coordinates "pos", why do you compare the square of the magnitude to a million?! Is is a typo and you meant 1e-9?

2. I want to use your code to print out the UDF output in a particular cell. How can I adapt the following line it your code? If there isn't a macro defined for the value, I want to store (like C_U(c0, t0) ), how can I store if to a text data?

Code:
DEFINE_EXCHANGE_PROPERTY(drag, cell, mix_thread, s_col, f_col) 
{
/*calculate drag coefficient drag_coeff*/
		return drag_coeff;
}

DEFINE_ON_DEMAND(bubu)
{
/*[...]
*/
	fprintf(pf, "%e\t%e\n", CURRENT_TIME, C_U(c0, t0));
/*[...]
*/
}
athalia is offline   Reply With Quote

Old   September 24, 2019, 00:07
Default
  #12
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
write to file
https://www.programiz.com/c-programm...e-input-output

best regards
AlexanderZ is offline   Reply With Quote

Reply

Tags
les, macros, udf, velocity fluctuations


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
UDF in Fluent Andrew Fluent UDF and Scheme Programming 5 March 7, 2016 03:38
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 10:19
UDF problem caused by various version of Fluent Yurong FLUENT 3 January 15, 2006 10: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 02:31.