How to access residual levels and iteration count in a UDF

Sometimes the iteration count and/or the residual levels need to be accessed in
a UDF.
For the iteration count, have the following variable defined:

int current_iteration_number = (nres==0)?(1):((int)count2[nres-1]);

Also, here's an example accessing the residuals.

Note that for a particular equation, you might want to check for
an equation name such as "continuity" using:
streq(DOMAIN_EQN_LABEL(domain,nw) , "continuity").

the name must be exactly as it appears in the standard output.

nres is the counter of the current residual storage position.
Note that the iteration number is stored in count2[]

#include "udf.h"

int nw;
real scaled_res;

Message("nResiduals for iteration %g",count2[nres-1]);
for(nw=0; nw<MAX_EQNS; ++nw)
Message("n%s equation:",DOMAIN_EQN_LABEL(domain,nw));


Message(" %g",scaled_res);

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