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/)
-   -   UDF problem for Population balance model (https://www.cfd-online.com/Forums/fluent-udf/206140-udf-problem-population-balance-model.html)

Amir.11 August 30, 2018 08:37

UDF problem for Population balance model
 
Hi everyone,

I have some difficulties using Fluent UDF and would like to share them with you, hopefully someone can help me out.

I picked one of the Fluent UDF examples to define particle growth rate in a solid/liquid system where discrete population balance model is considered.

Constant growth rate was already tested without any problem but an error message appears when I try to run a simulation with “Growth rate UDF” which is:


================================================== ============================

Node x: Process xxxx: Received signal SIGSEGV.

================================================== ============================
The fl process could not be started.



My understanding is that something could be wrong between a macro in the UDF and some models in fluent.
The Eulerian multiphase model with mass transfer and granular solid is applied.
The energy equation is on and the memory location is also declared.


Is there any need to turn the species transfer on?


There could be also a parallelizing problem.
I am confused here, and could not figure out how Fluent UDF actually process in parallel.





The UDF is:

/************************************************** **********************
UDF that computes the particle growth rate
************************************************** ***********************/

#include "udf.h"
#include "sg_pb.h"
#include "sg_mphase.h"

DEFINE_PB_GROWTH_RATE(growth_rate, cell, thread,d_1)
{
/* d_1 can be used if size-dependent growth is needed */
/* When using SMM, only size-independent or linear growth is allowed */

real SS;
real G;
real Kg = 2.8e-8; /* growth constant */
real Ng = 1.; /* growth law power index */
real T,solute_mass_frac,solvent_mass_frac, solute_mol_frac,solubility;
real solute_mol_wt, solvent_mol_wt;

Thread *tc = THREAD_SUPER_THREAD(thread); /*obtain mixture thread */
Thread **pt = THREAD_SUB_THREADS(tc); /* pointer to sub_threads */
Thread *tp = pt[P_PHASE]; /* primary phase thread */

solute_mol_wt = 74.55; /* molecular weight of potassium chloride */
solvent_mol_wt = 18.; /* molecular weight of water */
solute_mass_frac = C_YI(cell,tp,0);
/* mass fraction of solute in primary phase (solvent) */

solvent_mass_frac = 1.0 - solute_mass_frac;
solute_mol_frac = (solute_mass_frac/solute_mol_wt)/
((solute_mass_frac/solute_mol_wt)+(solvent_mass_frac/solvent_mol_wt));

T = C_T(cell,tp); /* Temperature of primary phase in Kelvin */

solubility = 0.0005*T-0.0794;
/* Solubility Law relating equilibrium solute mole fraction to Temperature*/

SS = solute_mol_frac/solubility; /* Definition of Supersaturation */

if (SS <= 1.)
{
G = 0.;
}
else
{
G = Kg*pow((SS-1),Ng);
}
return G;
}




Any suggestion or comment is welcome and will be greatly appreciated.

Amir

blackmask August 31, 2018 06:07

The code is modified to handle the situation where a null pointer is encountered. You could use it to pinpoint the unexpected behavior.
Code:

#include "udf.h"
#include "sg_pb.h"
#include "sg_mphase.h"

DEFINE_PB_GROWTH_RATE(growth_rate, cell, thread,d_1)
{
    /* d_1 can be used if size-dependent growth is needed */
    /* When using SMM, only size-independent or linear growth is allowed */

    real SS;
    real G;
    real Kg = 2.8e-8; /* growth constant */
    real Ng = 1.; /* growth law power index */
    real T,solute_mass_frac,solvent_mass_frac, solute_mol_frac,solubility;
    real solute_mol_wt, solvent_mol_wt;



    solute_mol_wt = 74.55; /* molecular weight of potassium chloride */
    solvent_mol_wt = 18.; /* molecular weight of water */

    solute_mass_frac = 0.0; /* in case */
    T = 300.0; /* in case */

    Thread *tc = NULL, **pt = NULL, *tp =NULL;

    tc = THREAD_SUPER_THREAD(thread); /*obtain mixture thread */
    if (NULLP(tc))
    {
        Message("processor [%d]: NULL mixture thread\n");
        goto CALC;
    }
    pt = THREAD_SUB_THREADS(tc); /* pointer to sub_threads */
    if (NULLP(pt))
    {
        Message("processor [%d]: NULL sub_threads\n");
        goto CALC;
    }
    tp = pt[P_PHASE]; /* primary phase thread */
    if (NULLP(tp))
    {
        Message("processor [%d]: NULL primary phase thread\n");
        goto CALC;
    }

    if (NULLP(THREAD_STORAGE(tp, SV_Y)))
    {
        Message("processor [%d]: NULL YI\n");
        goto CALC;
    }
    solute_mass_frac = C_YI(cell,tp,0);
    if (NULLP(THREAD_STORAGE(tp, SV_T)))
    {
        Message("processor [%d]: NULL T\n");
        goto CALC;
    }
    T = C_T(cell,tp); /* Temperature of primary phase in Kelvin */
    /* mass fraction of solute in primary phase (solvent) */

    CALC:solvent_mass_frac = 1.0 - solute_mass_frac;
    solute_mol_frac = (solute_mass_frac/solute_mol_wt)/
            ((solute_mass_frac/solute_mol_wt)+(solvent_mass_frac/solvent_mol_wt));

    solubility = 0.0005*T-0.0794;
    /* Solubility Law relating equilibrium solute mole fraction to Temperature*/

    SS = solute_mol_frac/solubility; /* Definition of Supersaturation */

    if (SS <= 1.)
    {
        G = 0.;
    }
    else
    {
        G = Kg*pow((SS-1),Ng);
    }
    return G;
}


Amir.11 August 31, 2018 08:55

Thanks for your reply,

Now am pretty sure that is a parallelizing problem.

First I tried to run it in a serial solver and got this warning during compilation:

************************************************** **************************
** WARNING: Automatically switched to run in parallel -t1 mode. **
** Detected non-parallelized UDF usage, enabling parallel usage. **
** If you encounter any issues, please re-run with -t0 flag. **
************************************************** **************************

Then a MPI error appeared when starting the calculation.

================================================== ============================

Node 0: Process 7744: Received signal SIGSEGV.

================================================== ============================
MPI Application rank 0 exited before MPI_Finalize() with status 2
The fl process could not be started.



Seeing this, I tried to configure a parallelizing simulation.
I shared both the main fluent folder (located at: C:\Program Files\AnsysInc\v182\fluent) and my working directory folder. Then use a mapped drive letter to the shared folder.


I Launched Fluent and Set my working directory to the shared and changed the Fluent root path to be UNC.
By clicking ok to launch the program, the launcher disappears and cannot open.


Any comment is appreciated.
Many thanks in advance,
Amir

blackmask August 31, 2018 21:34

Did you use the modified code and still get SIGSEGV?

Amir.11 September 3, 2018 09:21

Quote:

Originally Posted by blackmask (Post 704908)
Did you use the modified code and still get SIGSEGV?



Hello and sorry for this late reply,

Actually I didn't get SIGSEGV by the modified code but couldn't use it either:

The below error message was appeared when interpreting:

Error: C:/Users/ADMINI~1/AppData/Local/Temp/GR.c.5276.7.c: line 25: parse error.
Error: C:/Users/ADMINI~1/AppData/Local/Temp/GR.c.5276.7.c: line 27: tc: undeclared variable


However I was able to compile it but the simulation couldn't get started.

Best,
Amir

Amir.11 September 5, 2018 11:06

I think I know where the problem comes from:

This UDF example (#1) takes ''solute_mass_fraction'' via ''C_YI'' macro.
The thing is, in population balance model and multiphase simulation, Mass fraction isn't declared anywhere, so its value is unknown for the code.

what I think should be used here is rather volume fraction. Because in the boundary conditions for PBM and the multiphase model, the code uses volume fraction and not mass fraction.

Once the volume fraction is defined, mass fraction could be calculated from solute and mixture density.

With this change the simulation could be started but there is also a thing which may cause an error:

The growth rate UDF couldn't be used with Eulerian multiphase model. So you may apply either Mixture or VOF method.

This is the code adding volume fraction:



/************************************************** **********************
UDF that computes the particle growth rate
************************************************** ***********************/

#include "udf.h"
#include "sg_pb.h"
#include "sg_mphase.h"

DEFINE_PB_GROWTH_RATE(growth_rate, cell, thread, d_1)
{
/* d_1 can be used if size-dependent growth is needed */
/* When using SMM, only size-independent or linear growth is allowed */

real SS;
real G;
real Kg = 2.8e-8; /* growth constant */
real Ng = 1.; /* growth law power index */
real T,solute_vol_frac,solvent_vol_frac,solute_mass_fra c,solvent_mass_frac, solute_mol_frac,solubility;
real solute_mol_wt, solvent_mol_wt;

Thread *tc = THREAD_SUPER_THREAD(thread); /*obtain mixture thread */
Thread **st = THREAD_SUB_THREADS(tc); /* pointer to sub_threads */
Thread *ts = st[S_PHASE]; /* secondary phase thread */

solute_mol_wt = 28.086; /* molecular weight of Silicon */
solvent_mol_wt = 18.; /* molecular weight of water */

solute_vol_frac = C_VOF(cell,ts); /* volume fraction of solute */
solvent_vol_frac = 1.0 - solute_vol_frac;

solute_mass_frac = solute_vol_frac*C_R(cell,ts)/C_R(cell,tc);
solvent_mass_frac = 1.0 - solute_mass_frac;

solute_mol_frac = (solute_mass_frac/solute_mol_wt)/
((solute_mass_frac/solute_mol_wt)+(solvent_mass_frac/solvent_mol_wt));

T = C_T(cell,tc); /* Temperature of primary phase in Kelvin */

solubility = 0.0005*T-0.0794;
/* Solubility Law relating equilibrium solute mole fraction to Temperature*/

SS = solute_mol_frac/solubility; /* Definition of Supersaturation */

if (SS <= 1.)
{
G = 0.;
}
else
{
G = Kg*pow((SS-1),Ng);
}
return G;

}


Best,
Amir

Mohammadhossein May 30, 2022 04:36

UDF of growth rate in population balance
 
Hi dears
I encounter some problems in growth rate udf and I share them.
I hope someone help me out.
I have a growth rate in population balance which depends on the diameter:
G(L)=(Rp*L0*L0*L0)/(3*ro*di*di*di)
Which L0 is initial diameter and di is next diameter due the growth.
I set initial diameter, but next step time initial diameter will change and I don't know how udf can recognize new diameter. Moreover, how I can set di?

bests
Mohammadhossein


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