How to understand the BasicTurbulenceModel class in OpenFOAM
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 |
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. |
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. |
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: https://www.cfd-online.com/Forums/op...nfoam-6-a.html |
then this requires to implement a turbulence model that works somehow for density based/compressible/incompressible models, am I right?
|
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. |
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... |
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. |
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> 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 |
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 https://www.cfd-online.com/Forums/op...tml#post730795 - 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 ;) |
BasicTurbulenceModel
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.:) |
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:
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 |
All times are GMT -4. The time now is 10:28. |