CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Using input parameters (velocity inlet) in UDFs - bad UDF? (https://www.cfd-online.com/Forums/fluent-udf/206802-using-input-parameters-velocity-inlet-udfs-bad-udf.html)

student_1994 September 13, 2018 18:17

Using input parameters (velocity inlet) in UDFs - bad UDF?
 
Hi, I am running simulations in volume averaged porous media simulations for various inlet speeds (0.01, 0.02, 0.03...0.15, 0.2 m/s). I am interpreting a UDF with two parts - the first part is for the interfacial heat transfer coefficient (which I have gotten to work without any problems). In the second part of the UDF, I am trying to modify fluid thermal conductivity based on inlet velocity. I made it a parameter for UDFs (went to user-defined tab, parameters, more, use in UDF, select input parameter, clicked the parameter "inlet_vel", define, print (which gives id-to-be-used-in-udf as "real-1"). Then, I go to the same user-defined tab, go to functions, interpreted UDFs, and interpret my UDF. It interprets without any issue. Then, I go to the materials and change fluid thermal conductivity to user-defined "thermal_conductivity_w_dispersion." I run the initialization, which is sometimes where the error arises (at other times, initialization works, but the exact same thing happens). The error causes fluent to crash. The error it gives is (from a screen cap):

"Error at node 2: chip: internal error: invalid builtin -4: pc = 26
Error at node 3: chip: internal error: invalid builtin -4: pc = 26
Error at node 7: chip: internal error: invalid builtin -4: pc = 26
MRI application rank 0 exited before MPI-Finalize() with status 2"

In the code, when I comment in "inlet_vel = 0.1;" instead of "in_vel = RP_Get_Input_Parameter("real-1");" The code when using it equal to 0.1 instead of calling the input parameter works without crashing fluent, so I'm pretty confident that this line is wrong.

Here is my code in its entirety:

#include "udf.h"

DEFINE_PROPERTY(thermal_conductivity_w_dispersion, c, t)
{
real in_vel, inlet_vel, dens, visc, cp, k_with_dispersion, cond_f, rho, permeability, k_fluid;
in_vel = RP_Get_Input_Parameter("real-1");
/*inlet_vel = 0.1; */
permeability = 8.3670e-8; /*Permeability imputted manually*/
cond_f = 0.6; /*Conductivity fluid*/
dens = 1000; /*Density of fluid*/
visc = 0.00001; /*Viscosity fluid*/
cp = 4182; /*Specific heat fluid*/

/*k_with_dispersion = 1.3;*/
k_with_dispersion = cond_f+1*dens*cp*pow(permeability, 0.5)*in_vel;
return k_with_dispersion;
}

DEFINE_PROFILE(h_sf_5PPI_1,t,i)
{
cell_t c;
real vel;

begin_c_loop(c,t)
{
vel = ND_MAG(C_U(c,t),C_V(c,t),C_W(c,t));
F_PROFILE(c, t, i) = 56985.2*pow(vel, 0.67);
}
end_c_loop(c,t)
}

Any suggestions would be appreciated.

blackmask September 13, 2018 20:06

Try this one instead.
Code:

#include "udf.h"

real in_vel = 1.0;

DEFINE_EXECUTE_AT_END(execute_at_end)
{
#if !RP_NODE
    in_vel = RP_Get_Input_Parameter("real-1");
#endif
    host_to_node_real_1(in_vel);
}

DEFINE_PROPERTY(thermal_conductivity_w_dispersion, c, t)
{
    real inlet_vel, dens, visc, cp, k_with_dispersion, cond_f, rho, permeability, k_fluid;

    /*inlet_vel = 0.1; */
    permeability = 8.3670e-8; /*Permeability imputted manually*/
    cond_f = 0.6; /*Conductivity fluid*/
    dens = 1000; /*Density of fluid*/
    visc = 0.00001; /*Viscosity fluid*/
    cp = 4182; /*Specific heat fluid*/

    /*k_with_dispersion = 1.3;*/
    k_with_dispersion = cond_f+1*dens*cp*pow(permeability, 0.5)*in_vel;
    return k_with_dispersion;
}

DEFINE_PROFILE(h_sf_5PPI_1,t,i)
{
    cell_t c;
    real vel;

    begin_c_loop(c,t)
    {
        vel = ND_MAG(C_U(c,t),C_V(c,t),C_W(c,t));
        F_PROFILE(c, t, i) = 56985.2*pow(vel, 0.67);
    }
    end_c_loop(c,t)
}


student_1994 September 14, 2018 00:08

Blackmask,

Thanks for the feedback. It is not crashing and exiting anymore, which is definitely an improvement. I did as you said and now it is returning an error "line 14: mphost_to_node_double_1: no function prototype" (referencing the line that goes "host_to_node_real_1(in_vel);"

I've seen some threads suggesting missing semicolons and compiling instead of interpreting. But I don't think either of these would help in this case.

Do you have any further suggestions?

Thanks,
Justin

AlexanderZ September 14, 2018 00:22

you may try this code

Code:

#include "udf.h"

DEFINE_PROPERTY(thermal_conductivity_w_dispersion, c, t)
{
    real in_vel, inlet_vel, dens, visc, cp, k_with_dispersion, cond_f, rho, permeability, k_fluid;
#if !RP_NODE
    in_vel = RP_Get_Input_Parameter("real-1");
#endif
    host_to_node_real_1(in_vel);
#if !RP_HOST
    /*inlet_vel = 0.1; */
    permeability = 8.3670e-8; /*Permeability imputted manually*/
    cond_f = 0.6; /*Conductivity fluid*/
    dens = 1000; /*Density of fluid*/
    visc = 0.00001; /*Viscosity fluid*/
    cp = 4182; /*Specific heat fluid*/

    /*k_with_dispersion = 1.3;*/
    k_with_dispersion = cond_f+1*dens*cp*pow(permeability, 0.5)*in_vel;
    return k_with_dispersion;
#endif
}

DEFINE_PROFILE(h_sf_5PPI_1,t,i)
{
    cell_t c;
    real vel;

    begin_c_loop(c,t)
    {
        vel = ND_MAG(C_U(c,t),C_V(c,t),C_W(c,t));
        F_PROFILE(c, t, i) = 56985.2*pow(vel, 0.67);
    }
    end_c_loop(c,t)
}

best regards

blackmask September 14, 2018 00:26

My bad. I have updated my solution. You need to hook the execute-at-end function. Does the variable "real-1" change frequently?

student_1994 September 14, 2018 17:35

Blackmask and AlexanderZ:

Both of these modifications have made the code work. Thanks to both you! And Blackmask- regarding your question about how often real-1 changes- I have not seen it change ever, but I am pretty new to this and I have only been using the one variable in a UDF.

blackmask September 14, 2018 20:31

Since [DEFINE_PROPERTY] is invoked for each cell, it is quite inefficient to read scheme variable in the host node (RP_Get_Input_Parameter) and broadcast it to all compute nodes (host_to_node_type_num). You should do it outside of the cell loop.


All times are GMT -4. The time now is 22:28.