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[nres1]); 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" DEFINE_ADJUST(res_list,domain) { int nw; real scaled_res; Message("nResiduals for iteration %g",count2[nres1]); for(nw=0; nw<MAX_EQNS; ++nw) { if(strlen(DOMAIN_EQN_LABEL(domain,nw))>0) { Message("n%s equation:",DOMAIN_EQN_LABEL(domain,nw)); scaled_res=DOMAIN_RES(domain,nw)[nres1]/ DOMAIN_RES_SCALE(domain,nw)[nres1]; Message(" %g",scaled_res); } } Message("n"); 

