CFD Online Discussion Forums

CFD Online Discussion Forums (
-   Fluent UDF and Scheme Programming (
-   -   UDF to record FLUENT Solver variables... (

mariachi January 29, 2010 07:09

UDF to record FLUENT Solver variables...
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 :)

DoHander January 30, 2010 14:00

Maybe this will help you:

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).


mariachi January 31, 2010 06:46

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...

DoHander January 31, 2010 14:02

"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;

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.


mariachi February 1, 2010 12:30

Thankyou so much,
Ill check it out and give u the input, hope i dont have to ask any more questions :)

dmoroian February 1, 2010 14:37


Originally Posted by mariachi (Post 244348)
... 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!


mariachi February 2, 2010 13:54

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???


dmoroian February 4, 2010 07:06

I still think that you may use monitors for this, but if you want udf' it comes an example:

#include "udf.h"
  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)
            d2 = NV_MAG2(x);
            if(d2 < d20)
              d20 = d2;
              t0 = t;
              c0 = c;
  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));

Note: I did not try even to compile this, so use it as guidance!

sbaffini February 9, 2010 07:39

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

mariachi February 19, 2010 13:25

Thanks for ur guidance,

I have used point monitors and it seems its working well as i wanted. So far so good :)

All times are GMT -4. The time now is 22:44.