# Stop steady state iteration process from UDF

I am running a steady state simulation and my aim is to send the journal file with a large number of iterations and no convergence criteria to the cluster. I would like the FLUENT solver to stop the calculation once a certain value inside my UDF is met.

How can I achieve that? (Note that this value is a variable that exists only inside the UDF)

I saw online some methods that use "scheme variables" and/or creating a command inside "Execute commands" but they do not seem to work in my case.

Maybe I'm implementing them in the wrong way, also because I have no idea how the syntax for "Execute commands" work nor where to look for learning it.

Could you help me?

## Comments

Hi

Define a global variable like

`int my_convergence_variable=0;`

Then write a function to report this variable

`DEFINE_REPORT_DEFINITION_FN(my_convergence_function)`

`{`

`return my_convergence_variable;`

`}`

Then when you need to stop inside any function

`if (condition){`

`my_convergence_variable=1;`

`}`

Then. before you start simulations go to Residuals,>Convergence criteria ... Now you should find your variable in the list ... put the condition ...

You might need to add this variable in the report definition before you find it in the convergence criteria

Thank you @YasserSelima

You have been very helpful on many posts.

Appreciate it.

Regards,

Keyur

How to access Ansys Online Help Document

How to show full resolution image

Guidelines on the Student Community

How to use Google to search within Ansys Student Community

My pleasure

@YasserSelima thank you for you answer, but unfortunately when I tested your solution I see in the console "Solution for report definition report-convergence has converged" but the iterations go on. I would like them to stop when the report has converged.

Do you may know how I can do that?

Have the rest of the equations converged?

@Rob does it matter? I would like the calculation to stop when I ask for it, as if I was pressing the "stop button" in FLUENT.

So, in the test, the other equations did not converge but since I tried with "none" in the Convergence Criterion, I expected the calculation to stop only when the report definition converged.

*edit: setting "absolute" in the Convergence Criterion and unselecting all the "check convergence ticks" works.

Thanks again for the help @YasserSelima :)

You must set the criteria as only one condition converges ... this is a check box in the residuals tab

@mardott yes as the check in Fluent is on residuals and the report, thanks @YasserSelima for the fix.

Actually I am still have issues. Maybe it depends on what I set in the "Convergence Conditions" box?

yes, it depends. In the same panel of residuals, uncheck the boxes under check convergence.

Then in the convergence conditions panel when you selected your variable, make sure to check at the bottom only one condition is met.

So, I discovered what the problem was.

The "stop criterion" stands for something different based on the FLUENT version one uses.

In your version (and so the one in the file in "knowledge resources: solutions" of Ansys Portal) I put in "stop criterion" the value at which my variable has to stop. E.g. for the solution you suggested it should be 1

Unfortunately. in the version I am using (FLUENT 19 R2), the "stop criterion" stands for the residuals for the function, calculated as

So, with your solution, if I put 1, my solution converges when the residuals of my function is <= 1, i.e. after 2 iterations.

I solved it by:

(as global variable) int conv;

inside a function eg. DEFINE_EXECUTE_AT_END(...):

{conv = N_ITER;

if(convergence condition meet)

conv = N_ITER -1;}

DEFINE_REPORT_DEFINITION_FN(...)

{return conv;}

Glad it works and nice idea .. I did not know that this is the residual value .. thanks for sharing the idea