How to stop iteration process from UDF

Sometimes, users want to stop iteration process according to some criteria that are calculated in a UDF. But FLUENT can only stop the iteration process after a fixed number of iterations or when residual is reached.
Solution is to perform in a scheme loop 1 iteration, until some rp-variable is changed.

The scheme-side could look like this:

; make it possible that a UDF stops the iterations

(if (not (rp-var-object 'stop))(rp-var-define 'stop #f 'bool #f))

(define (my-iter max-iter)
(do ((i 0 (+ i 1))
((or (> i max-iter) (%rpgetvar 'stop))
(display i)
(iterate 1)

The UDF side looks like this:

#include "udf.h"

double bc=1.0,dbc=1.0;

face_t f;
dbc *= 0.5;
bc += dbc;
if(dbc<0.0001) RP_Set_Boolean("stop",1);

F_PROFILE(f,ft,eqn) = bc;

You would hook the UDF to some boundary condition, and start the iteration from the TUI with (my-iter 2000)

This solution should also apply to 6.2.16. In this version there is still no other way to stop iterating from a UDF (as far as I know).

Show Form
No comments yet. Be the first to add a comment!