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

Access to turbulence values in my own solver

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 14, 2013, 05:19
Default Access to turbulence values in my own solver
  #1
Senior Member
 
sfigato's Avatar
 
Marco Longhitano
Join Date: Jan 2013
Location: Aachen
Posts: 103
Rep Power: 13
sfigato is on a distinguished road
Send a message via Skype™ to sfigato
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
sfigato is offline   Reply With Quote

Old   March 14, 2013, 05:49
Default
  #2
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 22
Bernhard is on a distinguished road
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
Bernhard is offline   Reply With Quote

Old   March 14, 2013, 06:08
Default
  #3
Senior Member
 
sfigato's Avatar
 
Marco Longhitano
Join Date: Jan 2013
Location: Aachen
Posts: 103
Rep Power: 13
sfigato is on a distinguished road
Send a message via Skype™ to sfigato
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: 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:haseChangeTwoPhaseMixtures::SchnerrSauer: 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
Attached Files
File Type: c SchnerrSauer.C (4.9 KB, 22 views)
File Type: h SchnerrSauer.H (4.1 KB, 8 views)
sfigato is offline   Reply With Quote

Old   March 14, 2013, 06:15
Default
  #4
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 22
Bernhard is on a distinguished road
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.
Bernhard is offline   Reply With Quote

Old   March 14, 2013, 06:22
Default
  #5
Senior Member
 
sfigato's Avatar
 
Marco Longhitano
Join Date: Jan 2013
Location: Aachen
Posts: 103
Rep Power: 13
sfigato is on a distinguished road
Send a message via Skype™ to sfigato
Thanks for the quick reply!

I add the line in this way:

Quote:
...
Foam::tmp<Foam::volScalarField>
Foam:haseChangeTwoPhaseMixtures::SchnerrSauer: 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:haseChangeTwoPhaseMixtures::SchnerrSauer: 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
sfigato is offline   Reply With Quote

Old   March 14, 2013, 06:27
Default
  #6
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 22
Bernhard is on a distinguished road
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?
Bernhard is offline   Reply With Quote

Old   March 14, 2013, 06:32
Default
  #7
Senior Member
 
sfigato's Avatar
 
Marco Longhitano
Join Date: Jan 2013
Location: Aachen
Posts: 103
Rep Power: 13
sfigato is on a distinguished road
Send a message via Skype™ to sfigato
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
sfigato is offline   Reply With Quote

Old   March 14, 2013, 06:36
Default
  #8
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 22
Bernhard is on a distinguished road
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.
Bernhard is offline   Reply With Quote

Old   March 14, 2013, 07:36
Default
  #9
Senior Member
 
sfigato's Avatar
 
Marco Longhitano
Join Date: Jan 2013
Location: Aachen
Posts: 103
Rep Power: 13
sfigato is on a distinguished road
Send a message via Skype™ to sfigato
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
sfigato is offline   Reply With Quote

Old   March 14, 2013, 07:58
Default
  #10
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 22
Bernhard is on a distinguished road
Quote:
Originally Posted by sfigato View Post
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)
Bernhard is offline   Reply With Quote

Old   March 14, 2013, 08:18
Default
  #11
Senior Member
 
sfigato's Avatar
 
Marco Longhitano
Join Date: Jan 2013
Location: Aachen
Posts: 103
Rep Power: 13
sfigato is on a distinguished road
Send a message via Skype™ to sfigato
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!
sfigato is offline   Reply With Quote

Old   March 14, 2013, 08:21
Default
  #12
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 22
Bernhard is on a distinguished road
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.
Bernhard is offline   Reply With Quote

Reply


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
thobois class engineTopoChangerMesh error Peter_600 OpenFOAM 4 August 2, 2014 10:52
Divergence problem Smaras FLUENT 13 February 21, 2013 06:03
ATTENTION! Reliability problems in CFX 5.7 Joseph CFX 14 April 20, 2010 16:45
CFX solver workspace properties: modify default values zboud CFX 2 March 8, 2010 09:10
Discussion: Reason of Turbulence!! Wen Long Main CFD Forum 3 May 15, 2009 10:52


All times are GMT -4. The time now is 07:41.