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

Iteration Number in Fluent 5

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By Alfonso Ferrandez

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 6, 2000, 12:43
Default Iteration Number in Fluent 5
  #1
Alfonso Ferrandez
Guest
 
Posts: n/a
Dear all,

is there an easy way to determine what iteration number the solver is at within a timestep? I'm writing a UDF that relies on executing ONLY for the first iteration of each time-step, and although I've played with the value of "UDF Profile Update Interval", Fluent always seems to execute the UDF for EVERY iteration!

If there is a simpler way of solving this "minuscule" problem? If so, I would certainly like to hear from any of you. It's so simple it's driving me mad!

Thanks! AL
  Reply With Quote

Old   March 6, 2000, 17:57
Default Re: Iteration Number in Fluent 5
  #2
Kai Kang
Guest
 
Posts: n/a
I have never tried before, just an idea:

For transient simulation you can obtain the simulation time, RP_Get_REAL("flow_time"), you can declare a variable in your UDF as static to save the flow_time, each time the UDF is called, compared the newer time with whatever save in this variable and if the same, then return, otherwise execute the rest part of the UDF and update that variable.

Or write out to a file and save the time there.

  Reply With Quote

Old   March 6, 2000, 18:23
Default Re: Iteration Number in Fluent 5
  #3
Alfonso Ferrandez
Guest
 
Posts: n/a
Unfortunately, this UDF is a DEFINE_SOURCE type, which means it's called many times (loops across all cells in internal fluid) and therefore I can't tell whether the UDF has been executed again because of a cell in the domain, or because it's a different iteration.

And, to use the write to file approach, I have the same dilemma... what do I write if I don't know iteration number, or cell being set...

And also, I was trying to avoid read/write files because it's a very time consuming algorithm we're talking about...

Thanks anyway! Any more ideas? Cheerio! AL
  Reply With Quote

Old   March 6, 2000, 22:22
Default Re: Iteration Number in Fluent 5
  #4
Greg Perkins
Guest
 
Posts: n/a
There's a couple of things you might like to try.

Recently Nelson Carter (ndc@fluent.com) sent me this code to determine the current iteration number:-

int current_iter = (nres == 0) ? (0) : ((int) count2[nres - 1]);

This works fine. For your transient case you'll probably need to check something else with the timestep, flowtime etc.

To check whether you're UDF is called again at the same iteration or at a new iteration use a static variable. Here is some code I'm using to do something every 25 iterations (current_iter as defined above):-

static int disp = FALSE;

if ((current_iter % 25) == 0)

{

if (disp == FALSE)

{

/* --- do what ever you like */

disp = TRUE;

}

}

else disp = FALSE;

You can change the number 25 to whatever you like...

Hope it helps!
  Reply With Quote

Old   March 7, 2000, 06:23
Default Re: Iteration Number in Fluent 5
  #5
Alfonso Ferrandez
Guest
 
Posts: n/a
Thanks Greg!

With your help and a little modification I managed to make it work! And now, for all of those who might need to do this again, here's a snippet of code that will make it much easier for you. As an example a use a SOURCE UDF... this code does nothing else than showing you the basic structure, the actual agorithm is up to you

/*********** Code Snippet ****************/

static int control_t = 0; static int first_iter;

DEFINE_SOURCE(xmom_source_dynamic, cell, thread, dS, eqn) {

int time_step, iter, current_iter;

time_step = RP_Get_Integer("time-step");

current_iter = (nres == 0) ? (0) : ((int) count2[nres - 1]);

if (control_t != time_step) first_iter = current_iter;

if (first_iter == current_iter) /* Execute for first iteration of each timestep ONLY*/

{

/* do things...*/

control_t = time_step; /* Note change in timestep */

}

else

{

cxprintf(stdout,"Internal iteration %d\n", current_iter); /* Or simply do nothing! */

}

return f; }

/**************** END OF CODE SNIPPET *****************/

I hope this goes towards helping the "UDF Sharing" spirit that is going around the forum lately

Cheerio! AL
brenohc likes this.
  Reply With Quote

Old   March 7, 2000, 07:29
Default Re: Iteration Number in Fluent 5
  #6
Jonas Larsson
Guest
 
Posts: n/a
Thanks for sharing this! Why don't you also upload it to ftp.cfd-online.com/incoming - I've opened an FTP area there for sharing UDFs etc. If people use it I will design a more user-friendly web-interface to it.
  Reply With Quote

Old   March 7, 2000, 10:12
Default Re: Iteration Number in Fluent 5
  #7
Alfonso Ferrandez
Guest
 
Posts: n/a
Hi Jonas!

I've done as you indicated. I put a few more comments, and a "description header" I made up, since I don't think anybody has agreed on a standard yet...

Enjoy! AL
  Reply With Quote

Old   March 7, 2000, 10:55
Default Re: Iteration Number in Fluent 5
  #8
Jonas Larsson
Guest
 
Posts: n/a
Many thanks! I've moved it to the public "fluent" directory at ftp.cfd-online.com where anyone can download it.

Here is a link to it: ftp://ftp.cfd-online.com/fluent/iter_number.c

I like your header! It is short but still gives the essentials.
  Reply With Quote

Old   October 4, 2017, 12:27
Default
  #9
New Member
 
sina sadighi
Join Date: Jul 2017
Posts: 5
Rep Power: 9
sinasadighi is on a distinguished road
Quote:
Originally Posted by Greg Perkins
;93889
There's a couple of things you might like to try.

Recently Nelson Carter (ndc@fluent.com) sent me this code to determine the current iteration number:-

int current_iter = (nres == 0) ? (0) : ((int) count2[nres - 1]);

This works fine. For your transient case you'll probably need to check something else with the timestep, flowtime etc.

To check whether you're UDF is called again at the same iteration or at a new iteration use a static variable. Here is some code I'm using to do something every 25 iterations (current_iter as defined above):-

static int disp = FALSE;

if ((current_iter % 25) == 0)

{

if (disp == FALSE)

{

/* --- do what ever you like */

disp = TRUE;

}

}

else disp = FALSE;

You can change the number 25 to whatever you like...

Hope it helps!
hi
i need Ur help ,
i want a code that put outlet temperatrue average in 5 iteration into inlet in a channel.
it's steady .
how could i write it .
sinasadighi 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
[snappyHexMesh] SnappyHexMesh for internal Flow vishwa OpenFOAM Meshing & Mesh Conversion 24 June 27, 2016 09:54
Obtaining Reynolds Number in FLUENT Emmanuel FLUENT 2 April 7, 2016 02:46
Problem with decomposePar tool vinz OpenFOAM Pre-Processing 18 January 26, 2011 03:17
Use the number of iteration AdN FLUENT 0 April 27, 2006 12:10
[Commercial meshers] Trimmed cell and embedded refinement mesh conversion issues michele OpenFOAM Meshing & Mesh Conversion 2 July 15, 2005 05:15


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