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

Call udf some Iterations

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

Like Tree1Likes
  • 1 Post By Bruno Machado

Reply
 
LinkBack Thread Tools Display Modes
Old   September 16, 2015, 04:37
Question Call udf some Iterations
  #1
Member
 
Eduardo Tola
Join Date: Aug 2015
Location: Madrid/Haifa
Posts: 50
Rep Power: 3
edu_aero is on a distinguished road
Hello to everyone!!

I would love to know if there is someone who knows how to call a udf every some iterations (compiled udf), for example 5, instead of every iteration.

In order to not waste computer power, I want to call the function every 'X' iterations and no call every iteration and if a condition is reached then run the function.

Thank you very much
__________________
Having fun with CFD =)
edu_aero is offline   Reply With Quote

Old   September 16, 2015, 05:43
Default
  #2
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 262
Rep Power: 5
Bruno Machado is on a distinguished road
what do you want to do? What you can do is add a counter base on the iteration and put it in an if statement.
Bruno Machado is offline   Reply With Quote

Old   September 16, 2015, 07:05
Default
  #3
Member
 
Eduardo Tola
Join Date: Aug 2015
Location: Madrid/Haifa
Posts: 50
Rep Power: 3
edu_aero is on a distinguished road
Quote:
Originally Posted by Bruno Machado View Post
what do you want to do? What you can do is add a counter base on the iteration and put it in an if statement.
I want to do it in order to calculate some variables related with DPM model, so I just want to calculate after every injection. There is no point of calculation more than one time after a ijnection because the values are the same ones.

Thank you =)
__________________
Having fun with CFD =)
edu_aero is offline   Reply With Quote

Old   September 16, 2015, 07:13
Default
  #4
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 262
Rep Power: 5
Bruno Machado is on a distinguished road
so in that case you can add one counter

static int counter = 0.0;

if (counter <5)
{
do nothing for example
counter += 1.0;
}
else if (counter = 5)
{
do whatever you want;
counter = 0.0;
}


You can do something like this in your execute at the end or adjust macro.
edu_aero likes this.
Bruno Machado is offline   Reply With Quote

Old   September 16, 2015, 07:50
Default
  #5
Member
 
Eduardo Tola
Join Date: Aug 2015
Location: Madrid/Haifa
Posts: 50
Rep Power: 3
edu_aero is on a distinguished road
Quote:
Originally Posted by Bruno Machado View Post
so in that case you can add one counter

static int counter = 0.0;

if (counter <5)
{
do nothing for example
counter += 1.0;
}
else if (counter = 5)
{
do whatever you want;
counter = 0.0;
}


You can do something like this in your execute at the end or adjust macro.
But by doing something like this, the variable will get initialized as zero every time that I run the the code in this case with a DEFINE_ADJUST code every iteration, am I not right?
__________________
Having fun with CFD =)
edu_aero is offline   Reply With Quote

Old   September 16, 2015, 07:56
Default
  #6
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 262
Rep Power: 5
Bruno Machado is on a distinguished road
when the variable reaches 5 (for example), it will execute something and the variable returns to 0. from iterations 1 to 4 it wont do anything. I do not know how to code to do this only every X iterations, but you can say to do nothing in intervals. Not sure if I made myself clear.
Bruno Machado is offline   Reply With Quote

Old   September 16, 2015, 08:09
Talking
  #7
Member
 
Eduardo Tola
Join Date: Aug 2015
Location: Madrid/Haifa
Posts: 50
Rep Power: 3
edu_aero is on a distinguished road
Quote:
Originally Posted by Bruno Machado View Post
when the variable reaches 5 (for example), it will execute something and the variable returns to 0. from iterations 1 to 4 it wont do anything. I do not know how to code to do this only every X iterations, but you can say to do nothing in intervals. Not sure if I made myself clear.
Thank you very much, I didn't know about the use of static, what was exactly what I needed
__________________
Having fun with CFD =)
edu_aero is offline   Reply With Quote

Old   September 16, 2015, 11:18
Default
  #8
Senior Member
 
Andrew Kokemoor
Join Date: Aug 2013
Posts: 121
Rep Power: 6
Kokemoor is on a distinguished road
Bruno's answer is probably easier to implement, but I'll put out an alternative option, just in case.

Under Calculation Activities, you can run some scheme code every X iterations or timesteps. If you have an on-demand UDF, you can call it with
Code:
(%udf-on-demand "udfname::libudf")
Kokemoor is offline   Reply With Quote

Reply

Tags
compiled, dpm, fluent, iteration, udf

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
Problem with chtMultiregionFoam radiation boundary condition baran_foam OpenFOAM Running, Solving & CFD 9 September 4, 2015 07:31
Wrong fluctuation of pressure in transient simulation caitao OpenFOAM Running, Solving & CFD 2 March 5, 2015 22:33
Moving mesh Niklas Wikstrom (Wikstrom) OpenFOAM Running, Solving & CFD 122 June 15, 2014 06:20
pisoFoam with k-epsilon turb blows up - Some questions Heroic OpenFOAM Running, Solving & CFD 26 December 17, 2012 04:34
High Courant Number @ icoFoam Artex85 OpenFOAM Running, Solving & CFD 9 January 3, 2012 09:06


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