|
[Sponsors] |
How to understand the BasicTurbulenceModel class in OpenFOAM |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
August 2, 2019, 09:47 |
How to understand the BasicTurbulenceModel class in OpenFOAM
|
#1 |
New Member
Zongshi
Join Date: May 2019
Location: Zurich, Switzerland
Posts: 4
Rep Power: 7 |
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 |
|
August 4, 2019, 07:26 |
|
#2 |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
Blog Entries: 45
Rep Power: 128 |
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.
__________________
|
|
August 4, 2019, 10:32 |
|
#3 |
Senior Member
Santiago Lopez Castano
Join Date: Nov 2012
Posts: 354
Rep Power: 16 |
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. |
|
August 4, 2019, 12:40 |
|
#4 | ||
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
Blog Entries: 45
Rep Power: 128 |
Quick answers:
Quote:
Quote:
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 Last edited by wyldckat; August 4, 2019 at 12:41. Reason: see "edit:" |
|||
August 4, 2019, 16:07 |
|
#5 |
Senior Member
Santiago Lopez Castano
Join Date: Nov 2012
Posts: 354
Rep Power: 16 |
then this requires to implement a turbulence model that works somehow for density based/compressible/incompressible models, am I right?
|
|
August 4, 2019, 16:41 |
|
#6 | |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
Blog Entries: 45
Rep Power: 128 |
Quote:
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. |
||
August 4, 2019, 16:53 |
|
#7 | |
Senior Member
Santiago Lopez Castano
Join Date: Nov 2012
Posts: 354
Rep Power: 16 |
Quote:
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... |
||
August 4, 2019, 17:25 |
|
#8 | ||
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
Blog Entries: 45
Rep Power: 128 |
Somewhat quick answers:
Quote:
Quote:
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. |
|||
August 5, 2019, 06:41 |
|
#9 |
New Member
Zongshi
Join Date: May 2019
Location: Zurich, Switzerland
Posts: 4
Rep Power: 7 |
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() {} 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 |
|
August 5, 2019, 20:38 |
|
#10 | |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
Blog Entries: 45
Rep Power: 128 |
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:
... 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 Last edited by wyldckat; August 11, 2019 at 08:25. Reason: see "edit:" |
||
August 8, 2019, 10:53 |
BasicTurbulenceModel
|
#11 | |
New Member
Zongshi
Join Date: May 2019
Location: Zurich, Switzerland
Posts: 4
Rep Power: 7 |
Quote:
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. Last edited by dzsmoglai; August 10, 2019 at 15:23. |
||
October 29, 2022, 07:16 |
|
#12 |
Senior Member
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16 |
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"); 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 |
|
Tags |
turbulence models |
|
|
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 |