CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   Progamming issue: how do i get acces to the actual values of k-epsilon? (http://www.cfd-online.com/Forums/openfoam/77918-progamming-issue-how-do-i-get-acces-actual-values-k-epsilon.html)

sabin.ceuca July 7, 2010 12:18

Progamming issue: how do i get acces to the actual values of k-epsilon?
 
Hi,
after some struggling with the setup of OpenFOAM simulations, I have now started to write my own models. My first difficulties arose when i wanted to get access to the desired variables. What I actualy mean is lets take for example the density or the specific heat capacity which can be called using "twoPhaseProperties.variableName". Now I would like to have access to the actual values of for instance k-epsilon variables, but I would like to understand how do I generally find out where certain variables are computed and how to access them?
Greetings
Sabin

kathrin_kissling July 8, 2010 03:18

Hello Sabin,

could you tell me which solver and which version you're using?
In your solver (interFoam.C) which might be for example rasInterFoam (older version) or now interFoam (actual version) you will find a line

turbulence->correct();
which will actually call the turbulence model.
the object turbulence is assigned in the createFields.H file in

00095 // Construct incompressible turbulence model
00096 autoPtr<incompressible::turbulenceModel> turbulence
00097 (
00098 incompressible::turbulenceModel::New(U, phi, twoPhaseProperties)
00099 );


There you can see where it comes from. It is an incompressible turbulenceModel, so you have to search in src/turbulenceModel/incompressible/turbulenceModel
or
src/turbulenceModel/RAS/incompressible/RASModel, depending on the version you're using.
.
There you will find the files turbulenceModel.C turbulenceModel.H and newTurbulenceModel.C
respectively RASModel.C RASModel.H and newRASModel.C
Here you will find the reading from your turbulence dictionary and the setting of the turbulence model.
From now on it depends which model you are using. If you give me more information I can try to help you figuring it out.

Best

Kathrin

sabin.ceuca July 8, 2010 06:12

Morning Kathrin,
thanks for the answer

Sorry that I forgot to mention which solver I am using (it's interFoam from OF 1.6) . By looking into this http://foam.sourceforge.net/doc/Doxygen/html/incompressible_2turbulenceModel_2turbulenceModel_8 H_source.html I would understand that if I need the turbulence kinetic energy (k) I should be able to call it by volScalarField turbKinEnergy = turbulence.k(); , because the turbulence kinetic energy is defined in the file turbulenceModel.H as:
virtual tmp<volScalarField>k() const = 0; But it's not working.. During the compilation I get the error ‘class Foam::autoPtr<Foam::incompressible::turbulenceMode l>’ has no member named ‘k’
Do you have an idea how I can access this variable?

Greetings
Sabin

r08n July 8, 2010 06:39

Quote:

Originally Posted by sabin.ceuca (Post 266343)
I would understand that if I need the turbulence kinetic energy (k) I should be able to call it by [COLOR=royalblue]volScalarField turbKinEnergy = turbulence.k();

volScalarField turbKinEnergy = turbulence().k();

('turbulence' with parentheses).

sabin.ceuca July 8, 2010 07:00

Thanks r08n and Kathrin for helping me out, within such a short time.

xinyu August 29, 2012 14:41

Could you please explain wht this works?
 
Quote:

Originally Posted by r08n (Post 266346)
volScalarField turbKinEnergy = turbulence().k();

('turbulence' with parentheses).

I recently encountered the same problem and solved using this thread. Could you kindly explain why we need to add parentheses here? Is this something to do with the tmp type defined in the turbulence library?

Thanks a lot,

Xinyu

sfigato March 14, 2013 04:29

Dear Foamers,

I recently encountered the same problem regarding the access to the turbulence kinetic energy! By follwing the advice of this thread

Quote:

volScalarField turbKinEnergy = turbulence().k();

('turbulence' with parentheses).
I added:
Quote:

.....

// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

Foam::phaseChangeTwoPhaseMixtures::SchnerrSauer::S chnerrSauer
(
const volVectorField& U,
const surfaceScalarField& phi,
const volScalarField& turbKinEnergy = turbulence().k(),
const word& alpha1Name
)

....
and I got this compiling error:

Quote:

....
phaseChangeTwoPhaseMixtures/SchnerrSauer/SchnerrSauer.C:54:54: error: ‘turbulence’ was not declared in this scope
phaseChangeTwoPhaseMixtures/SchnerrSauer/SchnerrSauer.C:50:1: error: prototype for ‘Foam::phaseChangeTwoPhaseMixtures::SchnerrSauer:: SchnerrSauer(const volVectorField&, const surfaceScalarField&, const volScalarField&, const Foam::word&)’ does not match any in class ‘Foam::phaseChangeTwoPhaseMixtures::SchnerrSauer’
In file included from phaseChangeTwoPhaseMixtures/SchnerrSauer/SchnerrSauer.C:26:0:
phaseChangeTwoPhaseMixtures/SchnerrSauer/SchnerrSauer.H:61:7: error: candidates are: Foam::phaseChangeTwoPhaseMixtures::SchnerrSauer::S chnerrSauer(const Foam::phaseChangeTwoPhaseMixtures::SchnerrSauer&)
phaseChangeTwoPhaseMixtures/SchnerrSauer/SchnerrSauer.H:101:9: error: Foam::phaseChangeTwoPhaseMixtures::SchnerrSauer::S chnerrSauer(const volVectorField&, const surfaceScalarField&, const Foam::word&)
make: *** [Make/linux64GccDPOpt/SchnerrSauer.o] Fehler 1


Can anyone help me!?

Regards
Marco

chegdan March 20, 2013 21:50

Marco,

This is because you can't define a initialize a parameter in the constructor in the manner you are attempting.

Code:

const volScalarField& turbKinEnergy = turbulence().k(),
wont work. instead try just

Code:

const volScalarField& turbKinEnergy,
and when you initialize your constructor...make sure to pass the right argument i.e. the TKE.

sfigato March 21, 2013 02:18

1 Attachment(s)
Hi Daniel,

First I thanks you for your reply!

I am dealing with another problem! I implement a homogenoeus multiphase problem using pimple loop! I add a new transport scalar equation with variable density and I want to update my density after tha computing of the scalar quantity!

Here is the code :

Quote:

// Solve Mass Fraction Equation for the Vapour
{

//Mass Fraction of Vapour and Air
Info<< "Calculating field fv\n" << endl;
volScalarField fv
(
IOobject
(
"fv",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
rho2*alpha2/rho
);

Info<< "Calculating field fg\n" << endl;
volScalarField fg
(
IOobject
(
"fg",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
rho3*alpha3/rho
);

//Turbulence Saturation Pressure
Info<< "Calculating field pV\n" << endl;
volScalarField pV
(
IOobject
(
"pV",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
(scalar(0.39)*rho1*turbulence->k()) + pSat
);


//Scalar Transport Equation for Mass Fraction
fvScalarMatrix fvEqn
(
fvm::ddt(rho, fv)
+ fvm::div(rhoPhi /*phi*/, fv)
- fvm::laplacian(Gammaf,fv)
==
- fvm::Sp(Ce*rho1*rho2*sqrt(2*(p-pV)/3/rho1)*sqrt(turbulence->k()/sigma),fv)
- fvm::Sp(Cc*rho1*rho1*sqrt(2*(p-pV)/3/rho1)*sqrt(turbulence->k()/sigma),fv)

);

fvEqn.relax();
solve( fvEqn == Ce*rho1*rho2*sqrt(2*(p-pV)/3/rho1)*sqrt(turbulence->k()/sigma)*(1-fg));


//Update of All Phases Coeffcients
rho == scalar(1)/((fv/rho2)+(fg/rho1)+((scalar(1)-fv-fg)/rho1));
alpha2 == fv*(rho/rho3);
alpha3 == fg*(rho/rho2);
alpha1 == (1- alpha2 -alpha3);
//rhoPhi == rho*phi;

}
In order to updatw my volum fraction coeffcients and the density, are the bold lines enough?

Moreover, what about the rhoPhi variable?
Here is the whole solver!

Thanks

Regards
Marco


All times are GMT -4. The time now is 04:22.