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/)
-   -   C_UDMI function causing SIGSEGV error (https://www.cfd-online.com/Forums/fluent-udf/231895-c_udmi-function-causing-sigsegv-error.html)

Hosea_Chan November 22, 2020 21:17

C_UDMI function causing SIGSEGV error
 
Dear forum users,

I am working on a DEFINE_ADJUST function to compute the average velocity at the inlet of the cell zone and store the average velocity in the cells with C_UDMI function, which will be used to compute the momentum source term later. The code is as follows:
Code:


DEFINE_ADJUST(update,d)
{

        int id_a[cell_zones] = {17,21}; /* get zone id of channel-in later, need input */
        int id_v[cell_zones] = {6,7}; /* get zone id of channel volume later, need input */

        int i;
        for (i=0;i<2;i++) {
               
                #if !RP_HOST
                        real A[ND_ND];
                        real tfa = 0.0;
                        real tfi = 0.0;
                        real Ux = 0.0;
                        face_t f;
                        cell_t c;


                        Thread* t1=Lookup_Thread(d,id_a[i]);
                        Thread* t2 = Lookup_Thread(d,id_v[i]);


                        begin_f_loop(f, t1)
                        {
                                if PRINCIPAL_FACE_P(f,t1)
                                {                               
                                        F_AREA(A,f,t1);
                                        tfa += NV_MAG(A);
                                        /* summing the x-velocity of face */
                                        tfi += F_U(f,t1)*NV_MAG(A);
                                }
                        }
                        end_f_loop(f, t1)

                        tfi=PRF_GRSUM1(tfi);
                        tfa=PRF_GRSUM1(tfa);
                        Ux = tfi / tfa;
                        Message0("Average zone %d U:%12.4e\n",i, Ux);
                        Message0("Begin store c loop %d.\n",i);
                        begin_c_loop(c,t2)
                        {
                                if (FLUID_THREAD_P(t2) && NNULLP(THREAD_STORAGE(t2, SV_UDM_I)))
                                {
                                        C_UDMI(c,t2,1) = Ux;
                                }
                        }
                        end_c_loop(c,t2)
                        Message0("End store c loop %d.\n",i);
                #endif               
        }
}

However, I get a SIGSEGV error when I run the code. After isolating the code part by part, it seems that the line "C_UDMI(c,t2,1) = Ux;" is causing the problem as the code runs fine if I commented the line. I have reserved UDM slots in the Fluent GUI. I also used C_UDMI(c,t2,0) for storing the total volume in the DEFINE_INIT code earlier:

Code:

DEFINE_INIT(initialize,d)


{
        #if !RP_HOST
                real total_volume[cell_zones];
                //Domain* d;
               
                int i;
                d = Get_Domain(1);
       
                for (i=0; i<2 ; i++)
                {
                        cell_t c;
                        Thread* t2 = Lookup_Thread(d,id_v[i]);
                        begin_c_loop(c, t2)
                        Message0("Begin volume c loop %d\n",i);
                        {
                                total_volume[i] += C_VOLUME(c,t2);
                        }
                        end_c_loop(c, t2)
                        #if RP_NODE
                                total_volume[i] = PRF_GRSUM1(total_volume[i]);
                               
                        #endif
                       
                        Message0("Begin store c loop %d\n",i);
                        begin_c_loop(c,t2)
                        {
                                if (FLUID_THREAD_P(t2) && NNULLP(THREAD_STORAGE(t2, SV_UDM_I)))
                                {
                                        C_UDMI(c,t2,0) = total_volume[i];
                                }
                        }
                        end_c_loop(c,t2)
                       
                        Message0("total_volume of zone %d: %12.4e\n", i,total_volume[i]);
                       
                }

               
        #endif /* !RP_HOST */
       
}

It used to cause SIGSEGV as well, but with reference to another post with similar issue, the line "if (FLUID_THREAD_P(t2) && NNULLP(THREAD_STORAGE(t2, SV_UDM_I)))" seem to have solved the problem in the DEFINE_INIT code but not the DEFINE_ADJUST code. A link to the refered post is here: https://www.cfd-online.com/Forums/fl...emory-udf.html

Thank you for your help in advance!

Best regards,
Hosea

djendara December 13, 2020 18:22

usefully you have to lunch the computation without hook the function for one iteration and after hook your udf and try it !


All times are GMT -4. The time now is 17:44.