CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

access to member function variable

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 28, 2016, 09:35
Default access to member function variable
  #1
New Member
 
Rahand
Join Date: Mar 2016
Posts: 10
Rep Power: 7
Rahand is on a distinguished road
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;
}
Rahand is offline   Reply With Quote

Old   March 29, 2016, 13:00
Default
  #2
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 19
marupio is on a distinguished road
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?
__________________
~~~
Follow me on twitter @DavidGaden
marupio is offline   Reply With Quote

Old   March 29, 2016, 15:37
Talking
  #3
New Member
 
Rahand
Join Date: Mar 2016
Posts: 10
Rep Power: 7
Rahand is on a distinguished road
Quote:
Originally Posted by marupio View Post
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 -.-
Rahand is offline   Reply With Quote

Old   March 29, 2016, 15:46
Default
  #4
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 19
marupio is on a distinguished road
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!
__________________
~~~
Follow me on twitter @DavidGaden
marupio is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Virtual inheritance problem while adding public member function to LES SGS Model konneym OpenFOAM Programming & Development 4 November 4, 2013 11:37
latest OpenFOAM-1.6.x from git failed to compile phsieh2005 OpenFOAM Bugs 25 February 9, 2010 04:37
Can anybody help me to solve the list errors while compiling Openfoam 15 on Opensuse 103 32bit coompressor OpenFOAM Installation 0 November 12, 2008 19:53
[blockMesh] Axisymmetrical mesh Rasmus Gjesing (Gjesing) OpenFOAM Meshing & Mesh Conversion 10 April 2, 2007 14:00
[OpenFOAM] Could you please help me liugx212 ParaView 4 December 22, 2005 16:55


All times are GMT -4. The time now is 18:28.