|
[Sponsors] |
Need help understanding where deltaCoeffs function is defined |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
June 21, 2019, 16:20 |
Need help understanding where deltaCoeffs function is defined
|
#1 |
Senior Member
Lee Strobel
Join Date: Jun 2016
Posts: 133
Rep Power: 10 |
Hi, I am reading through the OF source code for the function gaussLaplacianScheme<Type, GType>::fvmLaplacian. The following is a snippet of the function code that I am curious about:
Code:
tmp<fvMatrix<Type>> tfvm = fvmLaplacianUncorrected ( SfGammaSn, this->tsnGradScheme_().deltaCoeffs(vf), vf ); I'm a bit confused ... |
|
June 22, 2019, 06:12 |
|
#2 |
Member
Join Date: Dec 2018
Location: Darmstadt, Germany
Posts: 87
Rep Power: 7 |
Hey there,
the quick answer: Just checked the child classes, they all seem to have an implementation of that function (for instance faceCorrectedSnGrad - https://cpp.openfoam.org/v6/classFoa...tedSnGrad.html). a general note: I am also sometimes strugling to get an overview due to that heavy dynamic polymorphism usage within OF. I don't think they had the keywords override and final at the time OF was written but these would definitely help to better understand (and improve) the code (maybe we should add an issue in the OF-dev repository). Can any active OF-developer comment on that? Cheers RP |
|
June 22, 2019, 06:51 |
|
#3 |
Senior Member
Lee Strobel
Join Date: Jun 2016
Posts: 133
Rep Power: 10 |
Hi raumpolizei,
Thanks for your reply and for checking those child classes. However, as far as I can see, The tsnGradSceme_ object isn't based on a child class of snGradScheme, it seems to be a direct instantiation of snGradScheme (although referenced in a tmp object). So, unless I'm missing something (which I must be), I still don't see where tsnGradScheme_().deltaCoeffs() can be defined. Regarding your other comments, I'm not sure about override and final, as I'm still not so familiar with c++ (but learning more). I do think though that many of the header files could really do with better comment introductions, to more clearly explain what the classes and functions are doing and what all the variables are, which would greatly help learners like myself. Btw, I am currently trying to learn this by reading this book by F. Moukalled. It's a really good book and seems to explain most of the concepts very well, but still the OF codebase seems very complex and there are some things that I'm finding a bit hard to follow, with so much polymorphism and template use, as you say. |
|
June 22, 2019, 12:58 |
|
#4 |
Member
Join Date: Dec 2018
Location: Darmstadt, Germany
Posts: 87
Rep Power: 7 |
Hey Lee,
the class template Foam::tmp seems to be the openfoam equivalent to the shared_ptr type in the c++ standard, if you take a look at the implementation of tmp, you will see that it holds a pointer to an object (of type T, it is a class template), thus allowing runtime polymorphism. The () operator returns a reference to that object. So basically what you have is a reference to an snGradScheme type object, and this can be any of the snGradScheme childs but no (as you well stated, pure virtual = interface class = no instantiation possible) concrete snGradScheme object.If you are new to C++, I recommend you to read a bit about dynamic and static polymorphism and the differences between both (helped me a lot). OF strongly relies on both techniques (and combines them). Cheers RP PS: I forgot smart pointers! To understand Foam::autoPtr and Foam::tmp |
|
June 23, 2019, 07:43 |
|
#5 |
Senior Member
Lee Strobel
Join Date: Jun 2016
Posts: 133
Rep Power: 10 |
Ah, ok. I had missed that the snGradScheme object in the tmp object could be any of the child classes of snGradScheme. That makes a lot more sense now. By default, laplacianScheme seems to use correctedSnGrad, which for deltaCoeffs() seems to return mesh().nonOrthDeltaCoeffs().
Yes, I think I need to read up some more about c++ polymorphism, as it seems this stuff can get very complicated. Thanks very much for your help! |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
using METIS functions in fortran | dokeun | Main CFD Forum | 7 | January 29, 2013 04:06 |
Compilation errors in ThirdPartymallochoard | feng_w | OpenFOAM Installation | 1 | January 25, 2009 06:59 |
Problem with compile the setParabolicInlet | ivanyao | OpenFOAM Running, Solving & CFD | 6 | September 5, 2008 20:50 |
Problem with rhoSimpleFoam | matteo_gautero | OpenFOAM Running, Solving & CFD | 0 | February 28, 2008 06:51 |
Droplet Evaporation | Christian | Main CFD Forum | 2 | February 27, 2007 06:27 |