CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Access to turbulence values in my own solver (http://www.cfd-online.com/Forums/openfoam-programming-development/114617-access-turbulence-values-my-own-solver.html)

sfigato March 14, 2013 05:19

Access to turbulence values in my own solver
 
Dear Foamers,

I am building my own OpenFOAM solver by modifing the interPhaseChangeFoam. I want to add a new model. I want to get acces to the value of turbulence kinetic energy inside that model. In order to fix this issue, I have tried to follow many threads as:

http://www.cfd-online.com/Forums/ope...k-epsilon.html

http://www.cfd-online.com/Forums/ope...-low-re-3.html


Nevertheless, noone of them helped me to fix it!
I would like to have access to the actual values of for instance k-omega SST variables, but I would like to understand how do I generally find out where certain variables are computed and how to access them?

Can anyone explain me this issue?

Regards

Marco

Bernhard March 14, 2013 05:49

This link may be helpful:
http://openfoamwiki.net/index.php/Op...objectRegistry

Also, I think this post covers your basic needs:
http://www.cfd-online.com/Forums/ope...tml#post254591

sfigato March 14, 2013 06:08

2 Attachment(s)
Dear Bernhard,

I have already read these links! Since I am quite new with OpenFoam programming I could not fix my problem!

I try to explain it in deepen it :

I would like to use the value of turbulence kinetic energy in my model SchnerrSauer.C (interPhaseChangeFoam)..so I have tried to add to SchnerrSauer.C the following lines:

Quote:

...
Foam::tmp<Foam::volScalarField>
Foam::PhaseChangeTwoPhaseMixtures::SchnerrSauer::p Coeff
(
const volScalarField& p
)
const
{
volScalarField limitedAlpha1(min(max(alpha1_, scalar(0)), scalar(1)));
volScalarField rho
(
limitedAlpha1*rho1() + (scalar(1) - limitedAlpha1)*rho2()
);

return

const volScalarFieldField& turbulence->k() = db().lookupObject<volScalarField>("turbulence->k()");

(3*rho1()*rho2())*sqrt(2/(3*rho1()))
*rRb(limitedAlpha1)/(rho*sqrt(mag(p - pSat()) + 0.01*pSat()));
}
....

and I got this error message:

Quote:

...
SOURCE=phaseChangeTwoPhaseMixtures/SchnerrSauer/SchnerrSauer.C ; g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3 -DNoRepository -ftemplate-depth-100 -I/opt/OpenFOAM/OpenFOAM-2.1.x/src/transportModels -I/opt/OpenFOAM/OpenFOAM-2.1.x/src/transportModels/incompressible/lnInclude -I/opt/OpenFOAM/OpenFOAM-2.1.x/src/transportModels/interfaceProperties/lnInclude -I/opt/OpenFOAM/OpenFOAM-2.1.x/src/turbulenceModels/incompressible/turbulenceModel -IphaseChangeTwoPhaseMixtures/phaseChangeTwoPhaseMixture -I/opt/OpenFOAM/OpenFOAM-2.1.x/src/finiteVolume/lnInclude -IlnInclude -I. -I/opt/OpenFOAM/OpenFOAM-2.1.x/src/OpenFOAM/lnInclude -I/opt/OpenFOAM/OpenFOAM-2.1.x/src/OSspecific/POSIX/lnInclude -fPIC -c $SOURCE -o Make/linux64GccDPOpt/SchnerrSauer.o
phaseChangeTwoPhaseMixtures/SchnerrSauer/SchnerrSauer.C: In member function ‘Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> > Foam::phaseChangeTwoPhaseMixtures::SchnerrSauer::p Coeff(const volScalarField&) const’:
phaseChangeTwoPhaseMixtures/SchnerrSauer/SchnerrSauer.C:110:5: error: expected primary-expression before ‘const’
phaseChangeTwoPhaseMixtures/SchnerrSauer/SchnerrSauer.C:110:5: error: expected ‘;’ before ‘const’
phaseChangeTwoPhaseMixtures/SchnerrSauer/SchnerrSauer.C:110:11: error: ‘volScalarFieldField’ does not name a type
phaseChangeTwoPhaseMixtures/SchnerrSauer/SchnerrSauer.C:114:1: warning: control reaches end of non-void function [-Wreturn-type]
make: *** [Make/linux64GccDPOpt/SchnerrSauer.o] Fehler 1

Hera are the two files of the model

Thanks in advance
Regards
Marco

Bernhard March 14, 2013 06:15

First you get an error because of the return above the bold line.

Following the second link, I would guess that you can access k by:
Code:

const volScalarFieldField& k = db().lookupObject<volScalarField>("k");
turbulence->k() is only how it is called inside the solver, because you construct a turbulence model with a reference to k.

sfigato March 14, 2013 06:22

Thanks for the quick reply!

I add the line in this way:

Quote:

...
Foam::tmp<Foam::volScalarField>
Foam::phaseChangeTwoPhaseMixtures::SchnerrSauer::p Coeff
(
const volScalarField& p
)
const
{
volScalarField limitedAlpha1(min(max(alpha1_, scalar(0)), scalar(1)));
volScalarField rho
(
limitedAlpha1*rho1() + (scalar(1) - limitedAlpha1)*rho2()
);
const volScalarField& k = db().lookupObject<volScalarField>("k");

return

(3*rho1()*rho2())*sqrt(2/(3*rho1()))
*rRb(limitedAlpha1)/(rho*sqrt(mag(p - pSat()) + 0.01*pSat()));
}
...
ana I got this error:

Quote:

SOURCE=phaseChangeTwoPhaseMixtures/SchnerrSauer/SchnerrSauer.C ; g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3 -DNoRepository -ftemplate-depth-100 -I/opt/OpenFOAM/OpenFOAM-2.1.x/src/transportModels -I/opt/OpenFOAM/OpenFOAM-2.1.x/src/transportModels/incompressible/lnInclude -I/opt/OpenFOAM/OpenFOAM-2.1.x/src/transportModels/interfaceProperties/lnInclude -I/opt/OpenFOAM/OpenFOAM-2.1.x/src/turbulenceModels/incompressible/turbulenceModel -IphaseChangeTwoPhaseMixtures/phaseChangeTwoPhaseMixture -I/opt/OpenFOAM/OpenFOAM-2.1.x/src/finiteVolume/lnInclude -IlnInclude -I. -I/opt/OpenFOAM/OpenFOAM-2.1.x/src/OpenFOAM/lnInclude -I/opt/OpenFOAM/OpenFOAM-2.1.x/src/OSspecific/POSIX/lnInclude -fPIC -c $SOURCE -o Make/linux64GccDPOpt/SchnerrSauer.o
phaseChangeTwoPhaseMixtures/SchnerrSauer/SchnerrSauer.C: In member function ‘Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> > Foam::phaseChangeTwoPhaseMixtures::SchnerrSauer::p Coeff(const volScalarField&) const’:
phaseChangeTwoPhaseMixtures/SchnerrSauer/SchnerrSauer.C:107:11: error: ‘volScalarField’ does not name a type
make: *** [Make/linux64GccDPOpt/SchnerrSauer.o] Fehler 1

Maybe, I did not understand where I must add this line..in order to get acces to k value for all the model files!

Regards
Marco

Bernhard March 14, 2013 06:27

Probably you need to include a few files in the header of your files. I am not exactly sure which, but maybe you can find it in a few examples?

sfigato March 14, 2013 06:32

Dear Bernhard,

sorry but I had a type mistake. It is working in your way!

How can I be sure that this 'k' is the turbulence kinetic energy?
The code compiles for another variable name too (for example if I reply 'k' with 'm')

Regards
Marco

Bernhard March 14, 2013 06:36

Try to run it with both variables names. Also, you can copy the contents to a new volScalarField and write it to disk, then compare.

sfigato March 14, 2013 07:36

I am pretty sure that turbulence kinetic energy is named by turbulence->k()...the question is How can I use it inside my model (which is used to get the source term in a n equation inside the solver)!

I obviously include #include "turbulenceModel.H".
I am sorry again if i do not understand but I do not know so well C++!

Greets
Marco

Bernhard March 14, 2013 07:58

Quote:

Originally Posted by sfigato (Post 413960)
I am pretty sure that turbulence kinetic energy is named by turbulence->k()...

This is actually not true. If you look in the source code of, for example, the kEpsilon model, you will find

Code:

95    k_                                                                                           
 96    (                                                                                             
 97        IOobject                                                                                 
 98        (                                                                                         
 99            "k",                                                                                 
100            runTime_.timeName(),                                                                 
101            mesh_,                                                                               
102            IOobject::NO_READ,                                                                   
103            IOobject::AUTO_WRITE                                                                 
104        ),                                                                                       
105        autoCreateK("k", mesh_)
106    ),

This is no different then the volScalarFields that are created in the createFields.H of your solver.

turbulence->k() is just to call the member function k() of your object turbulence (which via an intelligent way is of the class kEpsilon). It does not do a lot more than returning this volScalarField.
Code:

137        //- Return the turbulence kinetic energy
138        virtual tmp<volScalarField> k() const
139        {
140            return k_;
141        }

Also, if you open your 0/k file, you will probably see something like
Code:

FoamFile
{
    version    2.0;
    format      ascii;
    class      volScalarField;
    location    "0";
    object      k;
}

Thus, the name is k, and turbulence->k() is just a way to call it.

This all is by the way relatively straightforward C++. I encourage you to learn the C++ (until you understand classes and pointers)

sfigato March 14, 2013 08:18

Dear Bernhard,

First of all, thanks for the reply. If I understand from your post the name 'k' refers to the turbulence kinetic energy. Moreover, the only way tu use it in my model is what you have adviced to me:

Quote:

const volScalarFieldField& k = db().lookupObject<volScalarField>("k");
I am following your hint to learn more about C++ (but it si not a easy task for me)!
The last question and I promis that I do not disturb you anymore..

It is enough the line that I added to use the turbulence kinetic energy or I must modify somelse in side the ScnerrSauer.H file or inside the model itself?

For example to use pressure value inside the model*1..it is by default:

Quote:

(
const volScalarField& p
)

I thank you for you kindness.

Greets
Marco

*1 Maybe it si not true!

Bernhard March 14, 2013 08:21

Yes, that is the only. You do not have an object turbulence inside the model. This is only constructed in the solver.

In the other case, a pointer to the pressurefield is passed to the model via constructor functions. If you want to change that, you also have to change the way that the constructor is called. In general, this is not what you want to do.


All times are GMT -4. The time now is 11:57.