CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

Using input parameters (velocity inlet) in UDFs - bad UDF?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 13, 2018, 19:17
Default Using input parameters (velocity inlet) in UDFs - bad UDF?
  #1
New Member
 
Justin
Join Date: Feb 2017
Posts: 4
Rep Power: 9
student_1994 is on a distinguished road
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.
student_1994 is offline   Reply With Quote

Old   September 13, 2018, 21:06
Default
  #2
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 22
blackmask will become famous soon enough
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)
}

Last edited by blackmask; September 14, 2018 at 01:23.
blackmask is offline   Reply With Quote

Old   September 14, 2018, 01:08
Default
  #3
New Member
 
Justin
Join Date: Feb 2017
Posts: 4
Rep Power: 9
student_1994 is on a distinguished road
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
student_1994 is offline   Reply With Quote

Old   September 14, 2018, 01:22
Default
  #4
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
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
AlexanderZ is offline   Reply With Quote

Old   September 14, 2018, 01:26
Default
  #5
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 22
blackmask will become famous soon enough
My bad. I have updated my solution. You need to hook the execute-at-end function. Does the variable "real-1" change frequently?
blackmask is offline   Reply With Quote

Old   September 14, 2018, 18:35
Default
  #6
New Member
 
Justin
Join Date: Feb 2017
Posts: 4
Rep Power: 9
student_1994 is on a distinguished road
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.
student_1994 is offline   Reply With Quote

Old   September 14, 2018, 21:31
Default
  #7
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 22
blackmask will become famous soon enough
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.
blackmask is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Transient Velocity Inlet (2d synthetic jet) UDF akulagr Fluent UDF and Scheme Programming 4 October 18, 2018 02:31
Problem using UDF for velocity inlet panasonic18 Fluent UDF and Scheme Programming 2 June 13, 2018 03:59
2D UDF for inlet y velocity Keyu Fluent UDF and Scheme Programming 1 April 26, 2016 06:01
UDF to set velocity and pressure in inlet GerardX89 Fluent UDF and Scheme Programming 0 July 16, 2012 11:15
UDF paraboloid velocity inlet Ronak Shah FLUENT 0 June 4, 2003 10:44


All times are GMT -4. The time now is 10:49.