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/)
-   -   Error: Segmentation Fault - Fluent (https://www.cfd-online.com/Forums/fluent-udf/173152-error-segmentation-fault-fluent.html)

uzziel01 June 14, 2016 13:13

Error: Segmentation Fault - Fluent
 
1 Attachment(s)
Hello!!

I'm trying to simulate Natural Convection inside a refrigerator. I have a polynomial to enviromental temperature and I've made a UDF to calculate the temperature inside the refrigerator and to calculate the "h" coefficient for convection using the correlation of Churchill y Chu.

Fluent interprets the UDF correctly, but when I'm going to initialize the solution a message appears.

:confused::confused::confused::confused:

Could anyone help me, please?


This is the code of de UDF.

Code:

DEFINE_PROFILE(h_constant, thread, position)
{
real tsuma=0;   
real tavg;
real temp;
face_t f;
int contador=0;

real p,t_env;
real r,Cp,k,mu,vis;
real Pr;

real g=9.81, beta,L=0.43,Ts,Gr;
real Ra,Nu,h;

        cell_t c; /* Se declara una variable de celda */
        Thread *t_c;
        Domain *y;
        int refri_id=1;       
        y=Get_Domain(refri_id);  /*    Indica el ID de la zona de la pared    */
       


   
                    /* Calculo de la temperatura promedio del dominio */   

            thread_loop_c(t_c,y)
            {

                begin_c_loop(c,t_c)
                {
                    temp = C_T(c,t_c);
                    contador++;
                    tsuma += temp;
                }
                end_c_loop(c,t_c)

                tavg = tsuma/contador;
            }


                            /* Temperatura ambiente */

              p=CURRENT_TIME;
       
           
              if (p<=9000)
                t_env=298.1+0.001334*p-0.0000001681*(pow(p,2))+0.000000000006433*(pow(p,3));
              else if (p>9000 && p<=69900)
                t_env=302.1-0.00003154*p-0.0000000006091*(pow(p,2));
              else if (p>69900 && p<=106800)
                t_env=-231.3+0.022*p-0.0000003451*(pow(p,2))+0.000000000002433*(pow(p,3))-0.000000000000000006474*(pow(p,4));
              else if (p>106800 && p<=158400)
                t_env=311.9-0.00006337*p-0.0000000001965*(pow(p,2));
              else if (p>158400 && p<=198900)
                t_env=40.92+0.00281*p-0.000000007524*(pow(p,2));
              else if (p>198900 && p<=241500)
                t_env=287.7+0.0002514*p-0.0000000009*(pow(p,2));
           



            /* ****************************************************************** */
                      /*    Correlación para h    */
            /* ****************************************************************** */



                /* Cálculo para propiedades del aire a T=tenv */
       

        r=3.68909-0.0128308*t_env+0.0000148526*(pow(t_env,2));
        Cp=1017.11-0.131603*(t_env)+0.000300914*(pow(t_env,2));
        k=0.00318413+0.0000748721*t_env;
        mu=0.00000429617+0.0000000475835*t_env;

        vis=mu/r;

                        /* Prandtl */

       
        Pr=(Cp*mu)/k;

                        /* Grashof */

        /* L=43.5 cm */
       

        Ts=(tavg+t_env)/2.;
        beta=1./Ts;

        Gr=(g*beta*(tavg-t_env)*(pow(L,3)))/(pow(vis,2));

                        /* Rayleigh */
       
        Ra=Gr*Pr;

                /* Correlación de Churchill y Chu para Nusselt */
       

        Nu=0.68+((0.670*(pow(Ra,0.25))))/pow(1+(0.492/(pow(Pr,9/16))),4/9);

        h=(Nu*k)/L;


        begin_f_loop(f,thread)
            {
                F_PROFILE(f,thread,position)=h;
            }
        end_f_loop(f,thread)

        printf("Valor de h: %g\n", h);

}


`e` June 14, 2016 17:42

This segmentation error occurs when you're trying to access a variable which isn't available. You'll need to identify the line of code which is causing this error. First, try replacing C_T(c,t_c) with 1. to check if the cell temperature is available across all cells. If the segmentation error disappears, then it's possible the cell temperature isn't available on the first time step for the DEFINE_PROFILE macro (apply a conditional statement in this case).

Note: if you're running this macro with the parallel solver then these looping macros only access the cells within the compute node's partition. Therefore, the average temperature calculated would not cover the entire domain. See the UDF manual for examples on communicating between compute nodes (message passing).

uzziel01 June 14, 2016 18:35

Thanks
 
Quote:

Originally Posted by `e` (Post 604898)
This segmentation error occurs when you're trying to access a variable which isn't available. You'll need to identify the line of code which is causing this error. First, try replacing C_T(c,t_c) with 1. to check if the cell temperature is available across all cells. If the segmentation error disappears, then it's possible the cell temperature isn't available on the first time step for the DEFINE_PROFILE macro (apply a conditional statement in this case).

Note: if you're running this macro with the parallel solver then these looping macros only access the cells within the compute node's partition. Therefore, the average temperature calculated would not cover the entire domain. See the UDF manual for examples on communicating between compute nodes (message passing).

Thanks `e`

I've changed the value that you suggues me, but I have the same error yet.

I've change the value in F_PROFILE, to, but it's the same error.

Could you suggues me another thing to change?

Thanks `e`

`e` June 15, 2016 07:25

Quote:

Originally Posted by `e` (Post 604898)
You'll need to identify the line of code which is causing this error.

Either remove lines of code until you find the cause of the error or add messages using the Message() function to help with debugging.

alinik December 9, 2016 16:39

Braulio,

I am having the same error.
Apparently this line is creating the problem:

thread_loop_c (t,domain)

Did you find a solution to your problem?



Quote:

Originally Posted by uzziel01 (Post 604871)
Hello!!

I'm trying to simulate Natural Convection inside a refrigerator. I have a polynomial to enviromental temperature and I've made a UDF to calculate the temperature inside the refrigerator and to calculate the "h" coefficient for convection using the correlation of Churchill y Chu.

Fluent interprets the UDF correctly, but when I'm going to initialize the solution a message appears.

:confused::confused::confused::confused:

Could anyone help me, please?


This is the code of de UDF.

Code:

DEFINE_PROFILE(h_constant, thread, position)
{
real tsuma=0;   
real tavg;
real temp;
face_t f;
int contador=0;

real p,t_env;
real r,Cp,k,mu,vis;
real Pr;

real g=9.81, beta,L=0.43,Ts,Gr;
real Ra,Nu,h;

        cell_t c; /* Se declara una variable de celda */
        Thread *t_c;
        Domain *y;
        int refri_id=1;       
        y=Get_Domain(refri_id);  /*    Indica el ID de la zona de la pared    */
       


   
                    /* Calculo de la temperatura promedio del dominio */   

            thread_loop_c(t_c,y)
            {

                begin_c_loop(c,t_c)
                {
                    temp = C_T(c,t_c);
                    contador++;
                    tsuma += temp;
                }
                end_c_loop(c,t_c)

                tavg = tsuma/contador;
            }


                            /* Temperatura ambiente */

              p=CURRENT_TIME;
       
           
              if (p<=9000)
                t_env=298.1+0.001334*p-0.0000001681*(pow(p,2))+0.000000000006433*(pow(p,3));
              else if (p>9000 && p<=69900)
                t_env=302.1-0.00003154*p-0.0000000006091*(pow(p,2));
              else if (p>69900 && p<=106800)
                t_env=-231.3+0.022*p-0.0000003451*(pow(p,2))+0.000000000002433*(pow(p,3))-0.000000000000000006474*(pow(p,4));
              else if (p>106800 && p<=158400)
                t_env=311.9-0.00006337*p-0.0000000001965*(pow(p,2));
              else if (p>158400 && p<=198900)
                t_env=40.92+0.00281*p-0.000000007524*(pow(p,2));
              else if (p>198900 && p<=241500)
                t_env=287.7+0.0002514*p-0.0000000009*(pow(p,2));
           



            /* ****************************************************************** */
                      /*    Correlación para h    */
            /* ****************************************************************** */



                /* Cálculo para propiedades del aire a T=tenv */
       

        r=3.68909-0.0128308*t_env+0.0000148526*(pow(t_env,2));
        Cp=1017.11-0.131603*(t_env)+0.000300914*(pow(t_env,2));
        k=0.00318413+0.0000748721*t_env;
        mu=0.00000429617+0.0000000475835*t_env;

        vis=mu/r;

                        /* Prandtl */

       
        Pr=(Cp*mu)/k;

                        /* Grashof */

        /* L=43.5 cm */
       

        Ts=(tavg+t_env)/2.;
        beta=1./Ts;

        Gr=(g*beta*(tavg-t_env)*(pow(L,3)))/(pow(vis,2));

                        /* Rayleigh */
       
        Ra=Gr*Pr;

                /* Correlación de Churchill y Chu para Nusselt */
       

        Nu=0.68+((0.670*(pow(Ra,0.25))))/pow(1+(0.492/(pow(Pr,9/16))),4/9);

        h=(Nu*k)/L;


        begin_f_loop(f,thread)
            {
                F_PROFILE(f,thread,position)=h;
            }
        end_f_loop(f,thread)

        printf("Valor de h: %g\n", h);

}




All times are GMT -4. The time now is 12:15.