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

How to understand the BasicTurbulenceModel class in OpenFOAM

Register Blogs Community New Posts Updated Threads Search

Like Tree5Likes
  • 1 Post By wyldckat
  • 1 Post By wyldckat
  • 3 Post By dzsmoglai

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 2, 2019, 09:47
Smile How to understand the BasicTurbulenceModel class in OpenFOAM
  #1
New Member
 
Zongshi
Join Date: May 2019
Location: Zurich, Switzerland
Posts: 4
Rep Power: 7
dzsmoglai is on a distinguished road
Recently I was doing model modification of OF. The question that I really encounted very often was what the BasicTurbulentModel class was in OF. Can someone tell me where I can find the .H or .C file or it?
Thanks very much
dzsmoglai is offline   Reply With Quote

Old   August 4, 2019, 07:26
Default
  #2
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Quick answer: Look at the source code documentation for the version you are using, e.g.: https://cpp.openfoam.org/v7/

Oh... now I understand, the problem is that "BasicTurbulentModel" is a template class name designation of sorts... a placeholder if you will, it's not a specific class. The actual class is constructed by:

You can use Github search feature at the top of the page to look for names... I looked for "makeTurbulenceModelTypes" and found that file.
__________________
wyldckat is offline   Reply With Quote

Old   August 4, 2019, 10:32
Default
  #3
Senior Member
 
Santiago Lopez Castano
Join Date: Nov 2012
Posts: 354
Rep Power: 16
Santiago is on a distinguished road
everything was easier for us mortals (non CS majors) before version 4, where turbulence models were handled via autoPointers...

I have never understood this paradigm switch (really, not being sarcastic). I dont see any speed gains from it.
Santiago is offline   Reply With Quote

Old   August 4, 2019, 12:40
Default
  #4
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Quick answers:
Quote:
Originally Posted by Santiago View Post
everything was easier for us mortals (non CS majors) before version 4, where turbulence models were handled via autoPointers...
They are still handled with auto-pointers...

Quote:
Originally Posted by Santiago View Post
I have never understood this paradigm switch (really, not being sarcastic). I dont see any speed gains from it.
This was explained in one of the release notes... It's explained in detail here: https://openfoam.org/release/2-3-0/m...se/#turbulence - section "Multiphase Turbulence".

In a nutshell: For example, k-epsilon turbulence models are nearly identical for all single and multiphase solvers. The only things that usually change is the presence of density and phase fraction. But the way the code was written in the past was to have copy-paste-adapt each and every turbulence class for each type of fluid flow modelling.

With these template classes, you only need to write each turbulence model once and deploy for all types and phases of fluid flow.


edit: The question on the first post was also asked some 4 months ago here: BasicTurbulenceModel class declaration in OpenFOAM 6
anon_q likes this.

Last edited by wyldckat; August 4, 2019 at 12:41. Reason: see "edit:"
wyldckat is offline   Reply With Quote

Old   August 4, 2019, 16:07
Default
  #5
Senior Member
 
Santiago Lopez Castano
Join Date: Nov 2012
Posts: 354
Rep Power: 16
Santiago is on a distinguished road
then this requires to implement a turbulence model that works somehow for density based/compressible/incompressible models, am I right?
Santiago is offline   Reply With Quote

Old   August 4, 2019, 16:41
Default
  #6
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Quote:
Originally Posted by Santiago View Post
then this requires to implement a turbulence model that works somehow for density based/compressible/incompressible models, am I right?
Yes, but it's usually fairly straight forward, it's just a matter of following the other turbulence modelling examples.

Or you could simply ignore the "alpha" and "rho" input arguments if you want to not care about them... in other words, to keep using the old equation formulation.
wyldckat is offline   Reply With Quote

Old   August 4, 2019, 16:53
Default
  #7
Senior Member
 
Santiago Lopez Castano
Join Date: Nov 2012
Posts: 354
Rep Power: 16
Santiago is on a distinguished road
Quote:
Originally Posted by wyldckat View Post
Yes, but it's usually fairly straight forward, it's just a matter of following the other turbulence modelling examples.

Or you could simply ignore the "alpha" and "rho" input arguments if you want to not care about them... in other words, to keep using the old equation formulation.
For Smagorinsky LES, for instance, I find this new framework to be rather useless and, at the user level may lead to the impression that the models available actually work for density/velocity bases solvers.

I guess that in the RANS realm it might be more useful, given the empiricism inhetent in most of the models...

Has someone testes whether this templating is indeed faster than just "repeating" code? Asking for a friend...
Santiago is offline   Reply With Quote

Old   August 4, 2019, 17:25
Default
  #8
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Somewhat quick answers:
Quote:
Originally Posted by Santiago View Post
For Smagorinsky LES, for instance, I find this new framework to be rather useless and, at the user level may lead to the impression that the models available actually work for density/velocity bases solvers.
?? I'm not familiar with the LES implementation in OpenFOAM, but ... after looking at the code, see my answer(s) on the next paragraph...


Quote:
Originally Posted by Santiago View Post
Has someone testes whether this templating is indeed faster than just "repeating" code? Asking for a friend...
I really don't know where you are getting the information or idea that this change in OpenFOAM was to make the code run faster... the primary objective was to reduce the maintenance effort down to a minimum.

Whenever there was a bug in a turbulence model, the same bug had to be fixed 4 or 5 different classes, which were implementing the same turbulence model. That was a massive hazard and would easily result in bugs staying not fixed for some flow types, because developers would/could forget to update one or two classes for the same model... it was almost insane that it was ever implemented that way, from a development/sustainability perspective.
It was easier to look at the code and re-adapt it, but it was not to the ones doing the maintenance of the code.

.... Right, back to your question: in practice, the CPU performance should be (nearly) identical, since the compiler will reinterpret the code to each fluid flow model, namely will do the copy-paste-adapt for us. This way a bug is fixed once, but in fact fixes for all 4-5 instantiated models, as well as any new fluid flow models people can come up with.
wyldckat is offline   Reply With Quote

Old   August 5, 2019, 06:41
Default
  #9
New Member
 
Zongshi
Join Date: May 2019
Location: Zurich, Switzerland
Posts: 4
Rep Power: 7
dzsmoglai is on a distinguished road
Dear Santos, Thanks for your quick answer. I am really happy that my first post could be answered by other Foamers so quickly. However, I am still kinds of confused about the BasciTurbulenceModel. I clearly know sometimes it is just a placeholder of a template. But just as mentioned 4 months ago here in linearViscousStress.H:
Code:
template<class BasicTurbulenceModel>
class linearViscousStress
:
    public BasicTurbulenceModel
{

public:

    typedef typename BasicTurbulenceModel::alphaField alphaField;
    typedef typename BasicTurbulenceModel::rhoField rhoField;
    typedef typename BasicTurbulenceModel::transportModel transportModel;


    // Constructors

        //- Construct from components
        linearViscousStress
        (
            const word& modelName,
            const alphaField& alpha,
            const rhoField& rho,
            const volVectorField& U,
            const surfaceScalarField& alphaRhoPhi,
            const surfaceScalarField& phi,
            const transportModel& transport,
            const word& propertiesName
        );


    //- Destructor
    virtual ~linearViscousStress()
    {}
If I am right, the KEpsilon class inherits from eddyViscosity, which inherits from linearViscousStress. And in the code above, LinearViscousStress class has no own member variables, all of its member variables are from "parrent class" BasicTurbulenceModel. So What I am really eager to know is:
1. What member variables class BasicTurbulenceModel has;
2. What member functions class BasicTurbulenceModel has;
Which also means where I can find the declaration of it.

Thank you very much again.
Zongshi

Last edited by wyldckat; August 5, 2019 at 20:19. Reason: Added [CODE][/CODE] markers
dzsmoglai is offline   Reply With Quote

Old   August 5, 2019, 20:38
Default
  #10
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Quick answer: https://cpp.openfoam.org/v7/classFoa...ousStress.html

There is a connection graph right at the start... it gives an overview of what classes are used by this template class "linearViscousStress".
If you look at this class implementation: https://github.com/OpenFOAM/OpenFOAM...iscousStress.C - what it adds a few more methods that will take advantage of the base turbulence model.

For example, this template class "linearViscousStress" provides the method "divDevRhoReff" that the solvers are looking for. This method is common to all turbulence models, hence the reason why "linearViscousStress" exists: it's sort of a wrapper for all turbulence models.


Quote:
Originally Posted by dzsmoglai View Post
So What I am really eager to know is:
1. What member variables class BasicTurbulenceModel has;
2. What member functions class BasicTurbulenceModel has;
Which also means where I can find the declaration of it.
It has whichever methods the used turbulence model has got. For example, if "RASModel" is used, then it has these methods: https://cpp.openfoam.org/v7/classFoam_1_1RASModel.html
  • Which in turn depends on which sub-model you want to use... for example.... oh, now I see what you mean...
So the simpler way to figure out which methods exist, is by going into the turbulence model you are looking for, e.g. kEpsilon: https://cpp.openfoam.org/v7/classFoa...1kEpsilon.html


... sigh... it's not easy to point to a specific location and say how it is... but the diagram shown in BasicTurbulenceModel class declaration in OpenFOAM 6 - post #3, does give a good topological view of the methods to expect...


I don't have time right now to try and draw a diagram of how the turbulence models are constructed and which methods are made available at a specific point... I'll try to look into this later this week, if someone else doesn't beat me to it before then...


edit: OK, no need for me to look into this further... the mentioned blog post below is fortunately enough for people to figure it out
Linmunn likes this.

Last edited by wyldckat; August 11, 2019 at 08:25. Reason: see "edit:"
wyldckat is offline   Reply With Quote

Old   August 8, 2019, 10:53
Default BasicTurbulenceModel
  #11
New Member
 
Zongshi
Join Date: May 2019
Location: Zurich, Switzerland
Posts: 4
Rep Power: 7
dzsmoglai is on a distinguished road
Quote:
Originally Posted by dzsmoglai View Post
So What I am really eager to know is:
1. What member variables class BasicTurbulenceModel has;
2. What member functions class BasicTurbulenceModel has;
Which also means where I can find the declaration of it.

Thank you very much again.
Zongshi
Hey, guys!
After reading some blogs and posts online and the source codes of OpenFoam as well, I think now I know what BasicTurbulenceModel is:

Actually, it is a template parameter which indicates the compressibility of the flow. As far as I know so far, it can be either incompressibleTurbulenceModel or compressibleTurbulenceModel, which are also two classed based on the class turbulenceModel.

one can easily find the definition of turbulenceModel as below in
//$FOAM_SRC/TurbulenceModels/turbulenceModels/turbulenceModel.H(.C as well)

#ifndef turbulenceModel_H
#define turbulenceModel_H

#include "IOdictionary.H"
..............
............

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

namespace Foam
{

// Forward declarations
class fvMesh;

/*---------------------------------------------------------------------------*\
Class turbulenceModel Declaration
\*---------------------------------------------------------------------------*/

class turbulenceModel
:
public IOdictionary
{
protected:

// Protected data

const Time& runTime_;
const fvMesh& mesh_;

..................
.....................
}

So everytime you see it, it could be either incompressibleTurbulenceModel or compressibleTurbulenceModel.


Moreover, to better understand the turbulenceModel structure in OpenFOAM, one can see this blog (in Chinese unfortunately)
https://marinecfd.xyz/post/openfoam-...mework-part-1/

Thanks again for dear Foamers who answered my question.
Uyan, Nico994396 and Teresa Sun like this.

Last edited by dzsmoglai; August 10, 2019 at 15:23.
dzsmoglai is offline   Reply With Quote

Old   October 29, 2022, 07:16
Default
  #12
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
I wanted to access a specific turbulence model in a coded function object(a compressible Spalart Allmaras model).



I achieve it by this line of code



Code:

const auto& turbulence =  

        mesh().lookupObject<Foam::RASModels::SpalartAllmaras<
CompressibleTurbulenceModel<
compressibleTransportModel>>>("turbulenceProperties");
in order to get the object with template function lookupOpject i need to specify the correct type of the object I wanted to get.



Since the SpalartAllmaras model takes the template argument SpalartAllmaras<BasicTurbulenceModel> I had to specify a specific type of BasicTurbulenceModel. I wanted to have a compressible turbulence model.


The BasicTurbulenceModel is also a template class with an argument transportModel BasicTurbulenceModel<transportModel>. For this reason i needed a specific type of transport model. Finally the specific transport model was a compressibleTransportModel. This class is no template class and finally the compilation worked.


I did the whole exercise in order to have access to the Stilda() function of the Spalart Allmaras model. But then I realized it is a protected function and cannot be accessed outside the class hierarchy



But at the end I understood how the turbulence models are build


Or does anyone know how to access a protected member function from outside the class hierarchy?


Best


Michael
mAlletto is offline   Reply With Quote

Reply

Tags
turbulence models


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
OpenFOAM Training Jan-Apr 2017, Virtual, London, Houston, Berlin cfd.direct OpenFOAM Announcements from Other Sources 0 September 21, 2016 12:50
OpenFOAM : domain motion implementation with sixDoFRigidBodyMotionSolver class doctorWho OpenFOAM Programming & Development 0 September 16, 2016 10:16
[OpenFOAM.org] A Mac OS X of23x Development Environment Using Docker rt08 OpenFOAM Installation 1 February 28, 2016 20:00
OpenFOAM v3.0.1 Training, London, Houston, Berlin, Jan-Mar 2016 cfd.direct OpenFOAM Announcements from Other Sources 0 January 5, 2016 04:18
Cross-compiling OpenFOAM 1.7.0 on Linux for Windows 32 and 64bits with Mingw-w64 wyldckat OpenFOAM Announcements from Other Sources 3 September 8, 2010 07:25


All times are GMT -4. The time now is 23:27.