How to access the local residuals through UDF

Member, Employee Posts: 157
50 Answers 100 Likes 10 Comments Name Dropper
✭✭✭✭
edited June 2023 in Fluids

How to access the local residuals through UDF

Tagged:

Answers

  • Member, Employee Posts: 157
    50 Answers 100 Likes 10 Comments Name Dropper
    ✭✭✭✭
    Answer ✓

    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...

    1. #include "udf.h"
    2. DEFINE_ON_DEMAND(report_residuals)
    3. {
    4. cell_t c;
    5. Thread *ct;
    6. Domain *d=Get_Domain(ROOT_DOMAIN_ID);
    7. if(RP_Get_Boolean("save-cell-residuals?"))
    8. {
    9. Message("\nSaving Residuals in UDMs...\n");
    10. thread_loop_c(ct,d)
    11. {
    12. begin_c_loop(c,ct)
    13. {
    14. C_UDMI(c,ct,0) = C_STORAGE_R(c,ct, SV_P_R);
    15. C_UDMI(c,ct,1) = C_STORAGE_R(c, ct, SV_U_R);
    16. C_UDMI(c,ct,2) = C_STORAGE_R(c, ct, SV_V_R);
    17. C_UDMI(c,ct,3) = C_STORAGE_R(c, ct, SV_W_R);
    18. C_UDMI(c,ct,4) = C_STORAGE_R(c, ct, SV_T_R);
    19. }
    20. end_c_loop(c,ct)
    21. }
    22. }
    23. else
    24. {
    25. Message("\nResiduals are not set to be saved.\n");
    26. }
    27. }
    28. DEFINE_ON_DEMAND(alternative)
    29. {
    30. Domain *domain = Get_Domain(1);
    31. #if !RP_HOST
    32. Thread *t;
    33. cell_t c;
    34. #endif
    35. Cell_Function_Values(domain, "temperature-residual");
    36. #if !RP_HOST
    37. if (RP_Get_Boolean("save-cell-residuals?"))
    38. {
    39. Message0("\nSaving Residuals in UDMs...\n");
    40. thread_loop_c(t, domain)
    41. {
    42. begin_c_loop(c, t)
    43. {
    44. C_UDMI(c, t, 4) = C_POST_VAR(c, t);
    45. }
    46. end_c_loop(c, t)
    47. }
    48. }
    49. else
    50. {
    51. Message0("\nResiduals are not set to be saved.\n");
    52. }
    53. #endif
    54. }

Welcome!

It looks like you're new here. Sign in or register to get started.