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/)
-   -   Eulerian-Eulerian Source Term (https://www.cfd-online.com/Forums/fluent-udf/173587-eulerian-eulerian-source-term.html)

camilo_costa June 22, 2016 21:00

Eulerian-Eulerian Source Term
 
1 Attachment(s)
Hi!!!

I am trying to simulate a 2D, transient and Eulerian-Eulerian problem. I want to create a source term in x-mon and y-mon directions for both gas and liquid phases.
The equation of source term is showed in the figure. My code for create the source term in gas for x-direction is:

Code:

DEFINE_SOURCE(intforcexg, c, tm, dS, eqn)
{
        real dotprot_CUG_CVOF_gas;
        real dotprot_CUG_CVOF_liq;
        real C_T = 1;
        real source;
        real A_i;
        real diam = 1e-5;

        Thread *t = THREAD_SUPER_THREAD(tm);
        Thread *tg = THREAD_SUB_THREAD(t, gas_zone);
        Thread *tl = THREAD_SUB_THREAD(t, liq_zone);

        if ((NULL != THREAD_STORAGE(tg, SV_VOF_G)) && (NULL != THREAD_STORAGE(tg,
                SV_U_G)) && (NULL != THREAD_STORAGE(tl, SV_VOF_G)) &&
                (NULL != THREAD_STORAGE(tl, SV_U_G))) {

                dotprot_CUG_CVOF_gas = NV_DOT(C_U_G(c, tg), C_VOF_G(c, tg));
                dotprot_CUG_CVOF_liq = NV_DOT(C_U_G(c, tl), C_VOF_G(c, tl));
               
                A_i = 6. * C_VOF(c, tg) * C_VOF(c, tl) / diam;

                source = (-C_T * C_VOF(c, tg) * C_MU_EFF(c, tg) * dotprot_CUG_CVOF_gas -
                        C_T * C_VOF(c, tl) * C_MU_EFF(c, tl) * dotprot_CUG_CVOF_liq) * A_i;
                       
                //C_UDMI(c, t, 0) = source;
                return source;
        }

        else {
                return 0;
        }
}

I able to store the gradients in memory like described in udf manual.
When I try to run with x-source force appears this msg:
Error: received a fatal signal (Segmentation fault).
Error Object: #f

I am lost, anyone could help me? ;););)

Best Regards!!!

RAJ KIRAN June 23, 2016 10:05

You are missing dS[eqn] in your UDF.

camilo_costa June 23, 2016 17:19

Thank you RAJ KIRAN.
But is really necessary declare
Code:

dS[eqn] = 0;
for all define_source problems?

Recentelly I discover that the fluent not disponibilize the C_VOF_G, and is necessary compute him. I find two ways for resolve this problem.
First:
Code:

DEFINE_ADJUST(adjust_gradient_g, gas_dom)
{
        Thread *t;
        cell_t c;
        face_t f;
        gas_dom = Get_Domain(gas_id);

        /* Fill UDS with the variable. */
        thread_loop_c(t, gas_dom) {
                begin_c_loop(c, t) {
                        C_UDSI(c, t, 0) = C_VOF(c, t);
                }
                end_c_loop(c, t)
        }

        thread_loop_f(t, gas_dom) {
                if (THREAD_STORAGE(t, SV_UDS_I(0)) != NULL)
                        begin_f_loop(f, t) {
                        F_UDSI(f, t, 0) = F_VOF(f, t);
                        }
                end_f_loop(f, t)
        }
}

DEFINE_ADJUST(adjust_gradient_l, liq_dom)
{
        Thread *t;
        cell_t c;
        face_t f;
        liq_dom = Get_Domain(liq_id);

        /* Fill UDS with the variable. */
        thread_loop_c(t, liq_dom) {
                begin_c_loop(c, t) {
                        C_UDSI(c, t, 1) = C_VOF(c, t);
                }
                end_c_loop(c, t)
        }

        thread_loop_f(t, liq_dom) {
                if (THREAD_STORAGE(t, SV_UDS_I(1)) != NULL)
                        begin_f_loop(f, t) {
                        F_UDSI(f, t, 1) = F_VOF(f, t);
                        }
                end_f_loop(f, t)
        }
}

Second:
Code:

DEFINE_ADJUST(store_gradient_g, domain)
{
        Thread *t;
        Thread **pt;
        cell_t c;
        int phase_domain_index = 0.;
        Domain *pDomain = DOMAIN_SUB_DOMAIN(domain, phase_domain_index);
        {
                Alloc_Storage_Vars(pDomain, SV_VOF_RG, SV_VOF_G, SV_NULL);
                Scalar_Reconstruction(pDomain, SV_VOF, -1, SV_VOF_RG, NULL);
                Scalar_Derivatives(pDomain, SV_VOF, -1, SV_VOF_G, SV_VOF_RG,
                        Vof_Deriv_Accumulate);
        }

        mp_thread_loop_c(t, domain, pt)
        if (FLUID_THREAD_P(t)) {
                Thread *ppt = pt[phase_domain_index];

                begin_c_loop(c, t) {
                        C_UDMI(c, t, 0) = C_VOF_G(c, ppt)[0];
                        C_UDMI(c, t, 1) = C_VOF_G(c, ppt)[1];
                        C_UDMI(c, t, 2) = C_VOF_G(c, ppt)[2];
                }
                end_c_loop(c, t)
        }
        Free_Storage_Vars(pDomain, SV_VOF_RG, SV_VOF_G, SV_NULL);
}

DEFINE_ADJUST(store_gradient_l, domain)
{
        Thread *t;
        Thread **st;
        cell_t c;
        int phase_domain_index = 1.;
        Domain *sDomain = DOMAIN_SUB_DOMAIN(domain, phase_domain_index); {
                Alloc_Storage_Vars(sDomain, SV_VOF_RG, SV_VOF_G, SV_NULL);
                Scalar_Reconstruction(sDomain, SV_VOF, -1, SV_VOF_RG, NULL);
                Scalar_Derivatives(sDomain, SV_VOF, -1, SV_VOF_G, SV_VOF_RG,
                        Vof_Deriv_Accumulate);
        }

        mp_thread_loop_c(t, domain, st)
        if (FLUID_THREAD_P(t)) {
                Thread *ppt = st[phase_domain_index];

                begin_c_loop(c, t) {
                        C_UDMI(c, t, 1) = C_VOF_G(c, ppt)[0];
                        C_UDMI(c, t, 4) = C_VOF_G(c, ppt)[1];
                        C_UDMI(c, t, 5) = C_VOF_G(c, ppt)[2];
                }
                end_c_loop(c, t)
        }
        Free_Storage_Vars(sDomain, SV_VOF_RG, SV_VOF_G, SV_NULL);
}

Both is good, but the second I think that is possible retrieve the C_UDSI_G direct.
Don't forget is possible to dissable the solution of uds in your flow. Just disable in Controls -> Equations.

RAJ KIRAN June 24, 2016 06:36

Yes, it is necessary to declare dS[eqn]. By setting it to 0 you pass only the the explicit part of the source code. If you want you can also pass the implicit part of the source, this enhances the stability of the solution and will help convergence rates. (According to the manual, you can read more about this in manual)

I used the second code to calculate the volume fraction gradient. It worked without any problems. I think you can also get the same thing done by using UDS, but I did not try this before.

camilo_costa June 24, 2016 08:57

Quote:

Originally Posted by raj kiran (Post 606410)
yes, it is necessary to declare ds[eqn]. By setting it to 0 you pass only the the explicit part of the source code. If you want you can also pass the implicit part of the source, this enhances the stability of the solution and will help convergence rates. (according to the manual, you can read more about this in manual)

i used the second code to calculate the volume fraction gradient. It worked without any problems. I think you can also get the same thing done by using uds, but i did not try this before.

Thx RAJ KIRAN!!!

camilo_costa June 24, 2016 10:03

1 Attachment(s)
Was observed a differences between the tow methods for obtain the gradient of VOF. See the figures!!!
What is the most correctely?

camilo_costa June 28, 2016 12:19

C_mu_eff
 
Hi Guys!!
I resolved the almost problems, but I can't retrieve the value of C_MU_EFF!! What is wrong in the code?

Code:

DEFINE_ADJUST(intforcexg, d)
{
        cell_t c;
        Thread *t;
        Thread **pt = THREAD_SUB_THREADS(t);
        Thread *tg = pt[0];
        Thread *tl = pt[1];

        real source;
        real c_mu_eff_l;
        real C_T = 1;

        mp_thread_loop_c(t, d, tl) {
                if (FLUID_THREAD_P(t)) {
                        begin_c_loop(c, t) {
                                c_mu_eff_l = C_MU_EFF(c, t);
                                C_UDMI(c, t, 5) = c_mu_eff_l;
                        }
                        end_c_loop(c, t)
                }

        }
}


camilo_costa June 28, 2016 14:05

Quote:

Originally Posted by camilo_costa (Post 607043)
Hi Guys!!
I resolved the almost problems, but I can't retrieve the value of C_MU_EFF!! What is wrong in the code?

Code:

DEFINE_ADJUST(intforcexg, d)
{
        cell_t c;
        Thread *t;
        Thread **pt = THREAD_SUB_THREADS(t);
        Thread *tg = pt[0];
        Thread *tl = pt[1];

        real source;
        real c_mu_eff_l;
        real C_T = 1;

        mp_thread_loop_c(t, d, tl) {
                if (FLUID_THREAD_P(t)) {
                        begin_c_loop(c, t) {
                                c_mu_eff_l = C_MU_EFF(c, t);
                                C_UDMI(c, t, 5) = c_mu_eff_l;
                        }
                        end_c_loop(c, t)
                }

        }
}


Resolved!!
Code:

DEFINE_ADJUST(intforcexg, domain)
{
        real mu_eff_g;
        real mu_eff_l;
        Thread *t;
        Thread **pt;
        cell_t c;

        mp_thread_loop_c(t, domain, pt)
        if (FLUID_THREAD_P(t)) {
                Thread *tp = pt[P_PHASE];
                begin_c_loop(c, t) {
                        mu_eff_g = C_MU_EFF(c, tp);
                        C_UDMI(c, t, 5) = mu_eff_g;
                }
                end_c_loop(c, t)
        }
        mp_thread_loop_c(t, domain, pt)
        if (FLUID_THREAD_P(t)) {
                Thread *tp = pt[S_PHASE];
                begin_c_loop(c, t) {
                        mu_eff_l = C_MU_EFF(c, tp);
                        C_UDMI(c, t, 6) = mu_eff_l;
                }
                end_c_loop(c, t)
        }
}



All times are GMT -4. The time now is 04:42.