How to call thermal conductivity into Fluent UDF?

tpatter15tpatter15 Member Posts: 5

Hi,

I am writing a UDF to be used for solver feedback based on heat flux. As a preliminary step, I am calculating the directional heat flux at the boundaries. In order to do this I need to call the thermal conductivity into the UDF. My simulation setup is laminar, energized narrow channel flow.

I have been using the following macro "K_store = C_K_L(c,t); " with strange results... I have set the thermal conductivity to a constant value of 0.0242 [W/m-K], but plotting the aforementioned UDF variable gives a contour as shown in the below image (essentially 0 [W/m-K] ).

Is there another method to call thermal conductivity into the UDF that will resolve this discrepancy?



Answers

  • DrAmineDrAmine GermanyPosts: 7,890Forum Coordinator

    So if you assign your cell memory the C_K_L(c,t) you get wrong values? Are you setting the laminar conductivity as constant in the GUI?

  • tpatter15tpatter15 Posts: 14Member

    Yes, that's correct . I get the contour plot shown above for thermal conductivity, but I have set the thermal conductivity to a constant as shown in the screenshot below...



  • RobRob UKPosts: 11,730Forum Coordinator

    We're assuming the UDM is picking up a value. Can you post the code?

  • tpatter15tpatter15 Posts: 14Member

    Rob,

    Attached is the UDF code. I try to call conductivity in both the ADJUST and ON_DEMAND portions.

    Any feedback on why the conductivity is not making it into the UDF would be appreciated.


  • RobRob UKPosts: 11,730Forum Coordinator

    Which I'm not permitted to open: please post as you would normal text.

  • tpatter15tpatter15 Posts: 14Member

    Sorry about that, code pasted in below:

     # include "udf.h"


    /* Note: need to allocate at least as many UDS and UMDs as are in code below... can update to check for this before running to prevent crash? auto-allocate in UDF? */ 

    /* Note: Current counts: UDM = 20; UDS = 20 (2-3 spares 2021.11.08)*/ 

    /* Note: for C_T_G use enter this in comand line before solving: "solve/set/expert" > default (press enter to select [no]) x2 > type "yes" in response to "keep temp. mem. from being freed?" */ 

    /* Note: alternate command? Not working... "solve/set/advanced/retain-temporary-solver-mem" */ 


    /* Define which variable names for scalars ??? */

    /* Need to rename UDMs with more verbal descriptions ??? */ 


     enum

     {

    T_ADJ,

    T_STORE, 

    q_flux,

    q_flux_manual

     };


    /* The following code is executed at the END OF EVERY ITERATION */ 


     DEFINE_ADJUST(adjust_gradient, domain)

     {

    Domain *domain;  

    Thread *t;

    cell_t c;

    face_t f;

    real T_ADJ; 

    real K_ADJ;  

    domain=Get_Domain(1);

     

    /* Loop over all cells and store or calculate various parameters */

      thread_loop_c (t,domain)

       {

       begin_c_loop (c,t)

         {


    T_ADJ = C_T(c,t);

    C_UDSI(c,t,0) = T_ADJ;

    C_UDMI(c,t,0) = C_UDSI(c,t,0);


    K_ADJ = C_K_L(c,t);

    C_UDSI(c,t,1) = K_ADJ;

    C_UDMI(c,t,1) = C_UDSI(c,t,1);


         }

       end_c_loop (c,t)

       }


    /* Loop over all faces and store or calculate various parameters */

    thread_loop_f (t,domain)

       {

       if (THREAD_STORAGE(t,SV_UDS_I(0))!=NULL)

        begin_f_loop (f,t)

         {

    F_UDSI(f,t,0) = F_T(f,t);

    F_UDMI(f,t,0) = F_UDSI(f,t,0);

         }

       end_f_loop (f,t)

       }

      }



    /* The following code is executed on command ONLY */

     DEFINE_ON_DEMAND(store_gradient)

     {  

    Domain *domain;

    Thread *t;

    Thread *t0 = NULL; 

    cell_t c; 

    cell_t c0 = -1;

    face_t f; 

    real T_store; 

    real K_store; 

    real K_const = 0.0242;

    real q_flux_1, q_flux_2, q_flux_3, q_flux_4, q_flux_5; 

    real T_grad_1, T_grad_2, T_grad_3, T_grad_4, T_grad_5; 


    real T1, T2; 

    real y1, y2;

    real q_manual; 

    real xc[ND_ND];

    real xf[ND_ND]; 


    domain=Get_Domain(1); 


    /* Loop over all cells and store or calculate various parameters */

      thread_loop_c (t,domain)

       {

       begin_c_loop (c,t)

        {

    T_store = C_T(c,t); 

    K_store = C_K_L(c,t); 


    C_UDSI(c,t,2) = T_store;

    C_UDMI(c,t,2) = C_UDSI(c,t,2);

    C_UDMI(c,t,3) = NV_MAG(C_UDSI_G(c,t,0)); 

    C_UDMI(c,t,4) = NV_MAG(C_UDSI_G(c,t,2));


    C_UDSI(c,t,5) = K_store;

    C_UDMI(c,t,5) = K_store;


    C_UDSI(c,t,6) = K_const;

    C_UDMI(c,t,6) = K_const;


    /* The following code calculates q", q"_x and q"_y using the C_UDSI_G macro */

    /* Note: requires UDS equations must be set to "off" (so that they do not solve) for this code to be fully accurate */ 

    T_grad_1 = NV_MAG(C_UDSI_G(c,t,0)); 

    q_flux_1 = K_const*T_grad_1;

    C_UDSI(c,t,7) = q_flux_1; 

    C_UDMI(c,t,7) = q_flux_1;


    T_grad_2 = C_UDSI_G(c,t,0)[0]; 

    q_flux_2 = K_const*T_grad_2;

    C_UDMI(c,t,8) = q_flux_2;


    T_grad_3 = C_UDSI_G(c,t,0)[1]; 

    q_flux_3 = K_const*T_grad_3;

    C_UDMI(c,t,9) = q_flux_3;


    /* The following code calculates q"_x and q"_y using the C_T_G macro */

    /* Note: requires "solve/set/expert" command per note at top of UDF */ 

    T_grad_4 = C_T_G(c,t)[0]; 

    q_flux_4 = K_const*T_grad_4;

    C_UDMI(c,t,10) = q_flux_4;


    T_grad_5 = C_T_G(c,t)[1]; 

    q_flux_5 = K_const*T_grad_5;

    C_UDMI(c,t,11) = q_flux_5;


        }

       end_c_loop (c,t)

       }


    /* The following code calculates q"_y using the a manual gradient at the faces only */

    /* Section can be improved to loop through boundary faces only... */ 


    /* new stuff start */

    thread_loop_f (t,domain)

       {

    if (THREAD_STORAGE(t,SV_UDS_I(0))!=NULL)

       begin_f_loop (f,t)

         {

    c0 = F_C0(f,t); 

    /* t0 = F_C0_THREAD(f,t); */

    t0 = THREAD_T0(t); 


    T1 = C_T(c0, t0); 

    C_UDSI(c0,t0,13) = T1;

    C_UDMI(c0,t0,13) = T1;


    C_CENTROID(xc, c0, t0); 

    y1 = xc[1]; 

    C_UDSI(c0,t0,14) = y1;

    C_UDMI(c0,t0,14) = y1;


    T2 = F_T(f,t); 

    F_UDSI(f,t,15) = T2;

    F_UDMI(f,t,15) = T2;


    F_CENTROID(xf, f,t);

    y2 = xf[1];

    F_UDSI(f,t,16) = y2;

    F_UDMI(f,t,16) = y2;


    q_manual = K_const*(T1-T2)/(y1-y2);

    F_UDSI(f,t,12) = q_manual;

    F_UDMI(f,t,12) = q_manual; 

    C_UDMI(c0,t0,17) = F_UDMI(f,t,12);


         }

       end_f_loop (f,t)

       }

    /* new stuff end*/


     } 

  • RobRob UKPosts: 11,730Forum Coordinator

    Why are you doing these 3 steps?

    K_ADJ = C_K_L(c,t);

    C_UDSI(c,t,1) = K_ADJ;

    C_UDMI(c,t,1) = C_UDSI(c,t,1);

    Try

    C_UDSI(c,t,1) = C_K_L(c,t);

    I wonder if the first step is losing the cell values.

  • DrAmineDrAmine GermanyPosts: 7,890Forum Coordinator

    If you are solving the UDS's so the value you get in the memory won't always correspond to C_K_L so be careful there.

  • tpatter15tpatter15 Posts: 14Member

    All,

    I will admit the intermediate steps are not necessary, but should not have impeded data storage. I tried modifying the UDF to store the conductivity directly in a UDS (C_UDSI(c,t,1) = C_K_L(c,t);) but the result was unchanged from the errant contour above.

    Also I confirmed that I am not solving the UDS equation for the UDS assigned to conductivity.

    Any other tips to troubleshoot this issue?



    Thanks,

    Tyler

  • DrAmineDrAmine GermanyPosts: 7,890Forum Coordinator

    If you just put the laminar conductivity in Memory and you check the memory: will it show the same value or not. Forget about all other parts in the UDF: just check that part in a couple of lines UDF.

  • tpatter15tpatter15 Posts: 14Member

    Using a simple udf which just stores the conductivity in a scalar or memory produces the same results shown above... approximately zero.


    Thanks,

    Tyler

  • DrAmineDrAmine GermanyPosts: 7,890Forum Coordinator

    Can you post the lines in the simple UDF?

  • tpatter15tpatter15 Posts: 14Member

    Here is the code for the simple conductivity UDF:


     # include "udf.h"

    /* The following code is executed at the END OF EVERY ITERATION */ 

     DEFINE_ADJUST(adjust_data, domain)

     {

    Domain *domain;  

    Thread *t;

    cell_t c;

    face_t f;

    real K_ADJ;  

    domain=Get_Domain(1);

     

    /* Loop over all cells and store or calculate various parameters */

      thread_loop_c (t,domain)

       {

       begin_c_loop (c,t)

         {

    K_ADJ = C_K_L(c,t);

    C_UDSI(c,t,1) = C_K_L(c,t);

    C_UDMI(c,t,1) = C_UDMI(c,t,1);

         }

       end_c_loop (c,t)

       }

      }


     /* The following code is executed on command ONLY */

     DEFINE_ON_DEMAND(store_data)

     {  

    Domain *domain;

    Thread *t;

    cell_t c; 

    face_t f; 

    real T_store; 

    real K_store; 

    real K_const = 0.0242;

    domain=Get_Domain(1); 


    /* Loop over all cells and store or calculate various parameters */

      thread_loop_c (t,domain)

       {

       begin_c_loop (c,t)

        {

    T_store = C_T(c,t); 

    K_store = C_K_L(c,t); 

    C_UDSI(c,t,5) = C_K_L(c,t);

    C_UDMI(c,t,5) = C_K_L(c,t);

    C_UDSI(c,t,6) = K_const;

    C_UDMI(c,t,6) = K_const;

        }

       end_c_loop (c,t)

       }

     } 

  • tpatter15tpatter15 Posts: 14Member

    Note: there was an error in the code above... In the DEFINE_ADJUST portion, "C_UDMI(c,t,1) = C_UDMI(c,t,1);" should be "C_UDMI(c,t,1) = C_K_L(c,t);"


    This update made no difference, still have the conductivity error in my UDF.

  • DrAmineDrAmine GermanyPosts: 7,890Forum Coordinator

    I created a small UDF to verify and I am able to access the thermal conductivity and the value does match the value I am using in Ansys Fluent. In my small UDF I am taking care that the data access should be done on Nodes only (Starting with #if !RP_HOST and ending with #endif).

  • DrAmineDrAmine GermanyPosts: 7,890Forum Coordinator

    Again check everything without any DEFINE_ADJUST in ON_DEMAND.

Sign In or Register to comment.