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

Need help understanding where deltaCoeffs function is defined

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By raumpolizei

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 21, 2019, 16:20
Default Need help understanding where deltaCoeffs function is defined
  #1
Senior Member
 
Lee Strobel
Join Date: Jun 2016
Posts: 133
Rep Power: 9
Time4Tea is on a distinguished road
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 am wondering where the function deltaCoeffs(), as used there, is defined? tsnGradScheme_ appears to be an object of type tmp< snGradScheme< Type > >. However, in snGradScheme.H, deltaCoeffs() is defined as a pure virtual function. So, in that case, shouldn't deltaCoeffs() be undefined, as it doesn't seem to be being implemented by a child class of snGradScheme in this case?


I'm a bit confused ...
Time4Tea is offline   Reply With Quote

Old   June 22, 2019, 06:12
Default
  #2
Member
 
Join Date: Dec 2018
Location: Darmstadt, Germany
Posts: 87
Rep Power: 7
raumpolizei is on a distinguished road
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
raumpolizei is offline   Reply With Quote

Old   June 22, 2019, 06:51
Default
  #3
Senior Member
 
Lee Strobel
Join Date: Jun 2016
Posts: 133
Rep Power: 9
Time4Tea is on a distinguished road
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.
Time4Tea is offline   Reply With Quote

Old   June 22, 2019, 12:58
Default
  #4
Member
 
Join Date: Dec 2018
Location: Darmstadt, Germany
Posts: 87
Rep Power: 7
raumpolizei is on a distinguished road
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
Time4Tea likes this.
raumpolizei is offline   Reply With Quote

Old   June 23, 2019, 07:43
Default
  #5
Senior Member
 
Lee Strobel
Join Date: Jun 2016
Posts: 133
Rep Power: 9
Time4Tea is on a distinguished road
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!
Time4Tea is offline   Reply With Quote

Reply


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
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


All times are GMT -4. The time now is 19:02.