CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   Call udf some Iterations (https://www.cfd-online.com/Forums/fluent/159467-call-udf-some-iterations.html)

edu_aero September 16, 2015 04:37

Call udf some Iterations
 
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

Bruno Machado September 16, 2015 05:43

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.

edu_aero September 16, 2015 07:05

Quote:

Originally Posted by Bruno Machado (Post 564220)
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 =)

Bruno Machado September 16, 2015 07:13

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 September 16, 2015 07:50

Quote:

Originally Posted by Bruno Machado (Post 564233)
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?

Bruno Machado September 16, 2015 07:56

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.

edu_aero September 16, 2015 08:09

Quote:

Originally Posted by Bruno Machado (Post 564238)
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

Kokemoor September 16, 2015 11:18

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

asal September 14, 2017 12:48

Quote:

Originally Posted by Bruno Machado (Post 564233)
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.

Hello!

I have the same issue and want to use this method to call the UDF every certain iteration.
If I understand correctly, this code needs to be compiled rather than interpret.
However, when I interpret, I got "Parse error"

In another try, I have successfully compiled the UDF, but cannot load it due to the following error:

Code:

Error: The UDF library you are trying to load (libudf) is not compiled for
 parallel use on the current platform (win64).
\n\nThe system cannot find the file specified.
\n\nC:\...\libudf\win64\3ddp_host\libudf.dll
Error Object: #f

Any advice to fix this error would much appritiated.
Thanks.


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