How to access the local residuals through UDF
Valérie Gelbgras
Member, Employee Posts: 157
✭✭✭✭
Answers
-
In the TUI of Fluent, type:
solve/set/expert
and answer 'yes' to 'Save cell residuals for post-processing?'You can now access the residuals in the post-processing.
It is also possible to access the residual values in a UDF. An example is provided below.
In this example, a first DEFINE_ON_DEMAND stores the residual values of Pressure (= Mass Imbalance) X,Y and Z velocity, and the temperature in 5 UDMs.
A second DEFINE_ON_DEMAND use a general way to access any post processing variable with C_POST_VAR. In this second macro, "temperature-residual" can be replaced by the name you would enter in the TUI if you were to use TUI commands to produce e.g. a contour plot...
#include "udf.h" DEFINE_ON_DEMAND(report_residuals) { cell_t c; Thread *ct; Domain *d=Get_Domain(ROOT_DOMAIN_ID); if(RP_Get_Boolean("save-cell-residuals?")) { Message("\nSaving Residuals in UDMs...\n"); thread_loop_c(ct,d) { begin_c_loop(c,ct) { C_UDMI(c,ct,0) = C_STORAGE_R(c,ct, SV_P_R); C_UDMI(c,ct,1) = C_STORAGE_R(c, ct, SV_U_R); C_UDMI(c,ct,2) = C_STORAGE_R(c, ct, SV_V_R); C_UDMI(c,ct,3) = C_STORAGE_R(c, ct, SV_W_R); C_UDMI(c,ct,4) = C_STORAGE_R(c, ct, SV_T_R); } end_c_loop(c,ct) } } else { Message("\nResiduals are not set to be saved.\n"); } } DEFINE_ON_DEMAND(alternative) { Domain *domain = Get_Domain(1); #if !RP_HOST Thread *t; cell_t c; #endif Cell_Function_Values(domain, "temperature-residual"); #if !RP_HOST if (RP_Get_Boolean("save-cell-residuals?")) { Message0("\nSaving Residuals in UDMs...\n"); thread_loop_c(t, domain) { begin_c_loop(c, t) { C_UDMI(c, t, 4) = C_POST_VAR(c, t); } end_c_loop(c, t) } } else { Message0("\nResiduals are not set to be saved.\n"); } #endif }
0