CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   access to member function variable (https://www.cfd-online.com/Forums/openfoam-programming-development/168735-access-member-function-variable.html)

Rahand March 28, 2016 09:35

access to member function variable
 
Hello everyone,

I'm using the lagrangian evaporation methods of OF2.4.0 and trying to change one to the Abramzon&Sirignano model. Since my C++ knowledge isone beginners level, I'm stuck with the following problem.

In short: in the 1.function 'calculate' there's a value Bt which is calculated. This values should be passed to the 2.function 'dh'. Two different scopes. I guess a direct passing is not possible.
Is there an alternative way to get access to this variable? Declare it globally or introduce it as a function? Or how?

For the evaporation part I found a very helpful work of the Chalmers University. But for this issue everything I tried leads to errors!

I'll appreciate any help. Thanks!

Code:

template<class CloudType>
void Foam::NewLiquidEvaporation<CloudType>::calculate
(
    const scalar dt,
    const label cellI,
    const scalar Re,
    const scalar Pr,
    const scalar d,
    const scalar nu,
    const scalar T,       
    const scalar Ts,       
    const scalar pc,       
    const scalar Tc,       
    const scalarField& Yl,
    scalarField& dMassPC

   
) const
{

    // calculate mass transfer of each specie in liquid
    forAll(activeLiquids_, i)
    {

        const scalar Bm = (Y_FS - Yc)/max(SMALL, 1.0 - Y_FS); // mass transfer number
        scalar Nu = Nu0;
        scalar Sh = Sh0;
        scalar Bt = 0.0;
       
        //iteration for Bt
        if (Bm > 0)
        {
        const scalar Fm = pow((1 + Bm), 0.7)/Bm*log(1 + Bm);
        Sh = 2 + (Sh0-2)/Fm;
        scalar Ft = 0.0;
        Nu = 0.0;
        scalar psiB = 0.0;
        scalar eps = 1.0;   
        scalar Btiter = Bm;                       

        for (label iter = 0; iter < 10; iter++)
        {
        if (eps > 5e-2)
        {
        Ft = pow((1 + Btiter), 0.7)/Btiter*log(1 + Btiter);

        Nu = 2 + (Nu0-2)/Ft;

        psiB = (Cp_Fref/Cp_mix)*(Sh/Nu)*(1/Le_mix);
        eps = std::abs((pow((1 + Bm), psiB)-1)/Btiter-1);
        Btiter = (pow((1 + Bm), psiB)-1);
        }
        }
        Bt = Btiter;
        }

        if (Xc*pc > pSat0)
        {
        // saturated vapour - no phase change
        }
        else
        {
        dMassPC[lid] = pi*d*Sh*rho_mix*Dab_Fref*log(1.0 + Bm)*dt;
        }

    }
}

template<class CloudType>
Foam::scalar Foam::NewLiquidEvaporation<CloudType>::dh
(
    const label idc,
    const label idl,
    const scalar p,
    const scalar T
) const
{
    scalar dh = 0;

    typedef PhaseChangeModel<CloudType> parent;
    switch (parent::enthalpyTransfer_)
    {
        case (parent::etLatentHeat):
        {
            dh = liquids_.properties()[idl].hl(p, T);
            break;
        }
        case (parent::etEnthalpyDifference):
        {
            scalar hc = this->owner().composition().carrier().Ha(idc, p, T);
            scalar hp = liquids_.properties()[idl].h(p, T);

            dh = hc - hp;
                       
            break;
        }

        case (parent::etAbraSiri):
        {
            scalar hl = liquids_.properties()[idl].hl(p, T);

            dh = Cp_Fref*(Tc-T)/Bt + hl;
 
            break;
        }

        default:
        {
            FatalErrorIn
            (
                "Foam::scalar Foam::NewLiquidEvaporation<CloudType>::dh"
                "("
                    "const label, "
                    "const label, "
                    "const scalar, "
                    "const scalar"
                ") const"
            )  << "Unknown enthalpyTransfer type" << abort(FatalError);
        }
    }

    return dh;
}


marupio March 29, 2016 13:00

These are in the same object? You could store it as a member variable. But in the first instance above, Bt is calculated within a forAll(activeLiquids_), and in the second, Bt is just used. So which activeLiquid applies to the second scope?

Rahand March 29, 2016 15:37

Quote:

Originally Posted by marupio (Post 592224)
These are in the same object? You could store it as a member variable. But in the first instance above, Bt is calculated within a forAll(activeLiquids_), and in the second, Bt is just used. So which activeLiquid applies to the second scope?


Thank you for your response.

Yes, everything is (unfortunatelly) in one object. If I store it as a member variable (= member function?) then I still have to pass the values from one function to another or everything property has to be again calculated in the second variable or am I wrong?

The function 'dh' is called from another class for each liquid. So that's why I thing every Bt (each cellId and activeLiquid) should be applied to the second scope. I didn't pay attention while writing it here, sorry.
But here I'm still confused with the subscripts.

Or how would the call for Bt look like and what type (scalarField/volScalarfield) would it have if defined as a member variable to be be sure that every cell and liquid is correctly designated?

From ReactingParcel.C:

Code:

    forAll(dMassPC, i)
    {
        const label idc = composition.localToGlobalCarrierId(idPhase, i);
        const label idl = composition.globalIds(idPhase)[i];

        const scalar dh = phaseChange.dh(idc, idl, pc_, T);
   
        Sh -= dMassPC[i]*dh/dt;
    }

Thanks again and sorry for all the questions, but I am a bit overstrained for the moment -.-

marupio March 29, 2016 15:46

No, a member variable is not the same as a member function. Use a scalarList for Bt and index it by activeLiquid index. I hope one of the dh function parameters is the activeLiquid index, otherwise you will have to add that.

There's lots of examples of using a scalarList throughout the code base. Best of luck!


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