|
[Sponsors] |
May 20, 2019, 11:26 |
Follow the code when runTimeSelection
|
#1 |
Member
Fabien Robaux
Join Date: Oct 2016
Posts: 51
Rep Power: 10 |
Hi everyone,
I am currently trying to understand the code (precisely the overset library) and follow it up to its roots. I'm stuck on a runTimeSelection that, even if I read this page, I do not completely get. The code in cellCellStencil.C (function ::New) Code:
auto cstrIter = meshConstructorTablePtr_->cfind(stencilType); I didnt completly understand what meshConstructor table is but i think this there is a link somewhere to the derived class of cellCellStencil.C. Then Code:
return autoPtr<cellCellStencil>(cstrIter()(mesh, dict, true)) What constructor of this class does he use? Is there a way to print stuffs. When I do Code:
Info << cstrIter() Thanks for your clues! =) Have a good day |
|
May 20, 2019, 12:56 |
|
#2 |
Member
Join Date: Dec 2018
Location: Darmstadt, Germany
Posts: 87
Rep Power: 7 |
The function New is basically a base class factory function returning a pointer to an object of the base class, therefore enabling dynamic polymorphism at runtime (so that you can use different type of "baseclass" at runtime without recompiling the code). Most of it is hidden to the user and managed via macros. In OpenFOAM in a class enabling runtime polymorphism, you will find macros as declareRunTimeSelectionTable and defineRunTimeSelectionTable. If you take a look at the definitions of these macros, for instance in OF1812 https://www.openfoam.com/documentati...ce.html#l00273 you will find out that the meshConstructorTable you are referring to is of type HashTable:
Code:
typedef HashTable<argNames##ConstructorPtr, word, string::hash> \ argNames##ConstructorTable; // here argNames is "mesh" Code:
return autoPtr<cellCellStencil>(cstrIter()(mesh, dict, true)); //calls constructor, pass mesh dict and true as arguments. |
|
May 21, 2019, 04:47 |
|
#3 |
Member
Fabien Robaux
Join Date: Oct 2016
Posts: 51
Rep Power: 10 |
Hello,
Thanks for your quick response, it seems more clear now. If I want to print something to understand, does cstrIter() have an attribute that I can send to Info to help me? I going to read that article! |
|
May 21, 2019, 05:34 |
|
#4 |
Member
Join Date: Dec 2018
Location: Darmstadt, Germany
Posts: 87
Rep Power: 7 |
Well, what you could do is:
Code:
Info << "Selecting cellCellStencil Type " << stencilType << nl; Good luck! |
|
May 21, 2019, 05:51 |
|
#5 |
Member
Fabien Robaux
Join Date: Oct 2016
Posts: 51
Rep Power: 10 |
Ok,
For the new library that's exactly what I've done, I have created my own library copied from the original to do that kind of small tests. For the Info on stencilType I have already done this. I also test the type of AutoPtr created. Ps. The ressource you linked me is really insteresting! Thanks again! |
|
Tags |
iterator, runtimeselection |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
The FOAM Documentation Project - SHUT-DOWN | holger_marschall | OpenFOAM | 242 | March 7, 2013 13:30 |
How to make code run in parallel? | cwang5 | OpenFOAM Programming & Development | 1 | May 30, 2011 05:47 |
Open Source Vs Commercial Software | MechE | OpenFOAM | 28 | May 16, 2011 12:02 |
Error in CFX Solver | Leuchte | CFX | 5 | November 6, 2010 07:12 |
Small 3-D code | Zdravko Stojanovic | Main CFD Forum | 2 | July 19, 2010 11:11 |