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/)
-   -   How to calculate tke? (https://www.cfd-online.com/Forums/openfoam-programming-development/153123-how-calculate-tke.html)

lourencosm May 18, 2015 08:49

How to calculate tke?
 
Hello,

I'm trying to calculate the tke in interfoam but I can't call k.
This file goes next to the Courant calculation in the solver structure.
Can anybody help me to call k? Thank you.

This is the code:
Code:

scalar TkeSum = 0.0;

if (mesh.nInternalFaces())
{
    scalarField Tke (rho*mesh.V().field()*k);
    TkeSum = gSum(Tke);
}

Info<< "All phases tke: " << TkeSum << endl;
Info<< "tke units: kg*m^2/s^2" << endl;
Info<< "  " << endl;


I get this error:
Code:

allTke.H: In function ‘int main(int, char**)’:
allTke.H:39:43: error: ‘k’ was not declared in this scope
    scalarField Tke (rho*mesh.V().field()*k);
                                          ^
allTke.H:39:43: note: suggested alternative:
In file included from /opt/OpenFOAM/OpenFOAM-2.2.2/src/OpenFOAM/lnInclude/constants.H:46:0,
                from /opt/OpenFOAM/OpenFOAM-2.2.2/src/finiteVolume/lnInclude/fvCFD.H:17,
                from ihFoamLSM.C:69:
/opt/OpenFOAM/OpenFOAM-2.2.2/src/OpenFOAM/lnInclude/fundamentalConstants.H:79:36: note:  ‘Foam::constant::physicoChemical::k’
    extern const dimensionedScalar k;
                                    ^


T.D. May 18, 2015 09:44

Hi lourencosm,

You should do: scalarField Tke (rho*mesh.V().field()*k.value());


Best Regards,

GoodLuck !

T.D.

Quote:

Originally Posted by lourencosm (Post 546704)
Hello,

I'm trying to calculate the tke in interfoam but I can't call k.
This file goes next to the Courant calculation in the solver structure.
Can anybody help me to call k? Thank you.

This is the code:
Code:

scalar TkeSum = 0.0;

if (mesh.nInternalFaces())
{
    scalarField Tke (rho*mesh.V().field()*k);
    TkeSum = gSum(Tke);
}

Info<< "All phases tke: " << TkeSum << endl;
Info<< "tke units: kg*m^2/s^2" << endl;
Info<< "  " << endl;

I get this error:
Code:

allTke.H: In function ‘int main(int, char**)’:
allTke.H:39:43: error: ‘k’ was not declared in this scope
    scalarField Tke (rho*mesh.V().field()*k);
                                          ^
allTke.H:39:43: note: suggested alternative:
In file included from /opt/OpenFOAM/OpenFOAM-2.2.2/src/OpenFOAM/lnInclude/constants.H:46:0,
                from /opt/OpenFOAM/OpenFOAM-2.2.2/src/finiteVolume/lnInclude/fvCFD.H:17,
                from ihFoamLSM.C:69:
/opt/OpenFOAM/OpenFOAM-2.2.2/src/OpenFOAM/lnInclude/fundamentalConstants.H:79:36: note:  ‘Foam::constant::physicoChemical::k’
    extern const dimensionedScalar k;
                                    ^



lourencosm May 18, 2015 10:06

Thank you T.B. but it still no working.

(k is meant to be from the k-epsilon turbulent model)
Now I get this error:
Code:

allTke.H: In function ‘int main(int, char**)’:
allTke.H:40:43: error: ‘k’ was not declared in this scope
    scalarField Tke (rho*mesh.V().field()*k.value());
                                          ^
allTke.H:40:43: note: suggested alternative:
In file included from /opt/OpenFOAM/OpenFOAM-2.2.2/src/OpenFOAM/lnInclude/constants.H:46:0,
                from /opt/OpenFOAM/OpenFOAM-2.2.2/src/finiteVolume/lnInclude/fvCFD.H:17,
                from ihFoamLSM.C:69:
/opt/OpenFOAM/OpenFOAM-2.2.2/src/OpenFOAM/lnInclude/fundamentalConstants.H:79:36: note:  ‘Foam::constant::physicoChemical::k’
    extern const dimensionedScalar k;
                                    ^

Thank you.

alexeym May 18, 2015 10:45

Hi,

@lourencosm

Where do you try to add this code? Inside the solver, inside the turbulence model, somewhere else?

Compiler tried to do its best to guess what you are trying to say, but was not successful as he suggested you Boltzmann constant instead of kinetic turbulent energy.

lourencosm May 18, 2015 10:56

In the interfoam.C file, therefore the solver main file.

Code:

int main(int argc, char *argv[])
{
    #include "setRootCase.H"
    #include "createTime.H"
    #include "createMesh.H"

    pimpleControl pimple(mesh);

    #include "initContinuityErrs.H"
    #include "createFields.H"
    #include "readTimeControls.H"
    #include "correctPhi.H"
    #include "CourantNo.H"
    #include "setInitialDeltaT.H"


    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

    Info<< "\nStarting time loop\n" << endl;

    while (runTime.run())
    {
        #include "readTimeControls.H"
        #include "CourantNo.H"
        #include "alphaCourantNo.H"
        #include "allTke.H"                            //-------------------here!!
        #include "setDeltaT.H"

        runTime++;

        Info<< "Time = " << runTime.timeName() << nl << endl;


alexeym May 18, 2015 11:12

Hi,

In this case you have turbulence variable of type autoPtr<incompressible::turbulenceModel> turbulence, which is created in createFields.H file. incompressible::turbulenceModel class has k method which returns TKE.

So finally your code should be something like:

Code:

dimensionedScalar totalTKE(fvc::domainIntegrate(rho*turbulence->k()));

lourencosm May 18, 2015 11:49

Thank you very much alexeym!

I was driving nuts!
I had already tried RASModel->k() and turbulenceModel->k() with no result. Thank you.

I ended up by using this function because I need the air, water and interface values as well:
Code:

scalar waterTkeSum = 0.0;
scalar airTkeSum = 0.0;
scalar interfaceTkeSum = 0.0;
scalar TkeSum = 0.0;

if (mesh.nInternalFaces())
{
    scalarField Tke(rho*turbulence->k());

    scalarField water (neg(0.99 - alpha1));
    scalarField waterTke(water*Tke);

    scalarField air (neg(alpha1 - 0.01));
    scalarField airTke (air*Tke);

    scalarField interface (pos(alpha1 - 0.01)*pos(0.99 - alpha1));
    scalarField interfaceTke (interface*Tke);

    waterTkeSum = gSum(waterTke);
    airTkeSum = gSum(airTke);
    interfaceTkeSum = gSum(interfaceTke);
    TkeSum = gSum(Tke);
}

Info<< "All phases tke: " << TkeSum << endl;
Info<< "Water tke : " << waterTkeSum << endl;
Info<< "Air tke : " << airTkeSum << endl;
Info<< "Interface tke : " << interfaceTkeSum << endl;
Info<< "tke units: kg*m^2/s^2" << endl;
Info<< "  " << endl;



All times are GMT -4. The time now is 21:55.