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)
(newline)
(iterate 1)
)
)

The UDF side looks like this:

#include "udf.h"

double bc=1.0,dbc=1.0;

DEFINE_PROFILE(cathode,ft,eqn)
{
face_t f;
dbc *= 0.5;
bc += dbc;
Message("dbc=%gn",dbc);
if(dbc<0.0001) RP_Set_Boolean("stop",1);

begin_f_loop(f,ft)
{
F_PROFILE(f,ft,eqn) = bc;
}
end_f_loop(f,ft)
}

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
Comments
 
Thanks.
How i can implement this scheme in fluent (my version =15) ?
Mdr, Mon Apr 01, 2019