|
[Sponsors] |
Construct and return a clone - trying to understand this |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
October 27, 2020, 16:53 |
Construct and return a clone - trying to understand this
|
#1 |
Member
Stanley John
Join Date: Sep 2018
Posts: 79
Rep Power: 7 |
Hi,
I am trying to understand openfoam coding and I have come across this piece of code to often. What does this do? It located in /src/lagrangian/parcel/submodels/Momentum/ParticleForces/Gravity/GravityForce.H PHP Code:
In /src/lagrangian/parcel/submodels/ForceTypes/ParticleForceList/ParticleForceList.C I do see a piece of code PHP Code:
|
|
October 29, 2020, 16:15 |
|
#2 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,684
Rep Power: 40 |
Too many questions all at once. Which is your first one?
|
|
October 29, 2020, 20:34 |
|
#3 |
Member
Stanley John
Join Date: Sep 2018
Posts: 79
Rep Power: 7 |
Thanks Mark, lets go top top bottom as I understand the flow goes from:
1) ParticleForceList 2) ParticleForce 3) Individual particle forces for eg: gravity As I understand in ParticleForceList.C it reads user defined input for particles forces and based on user input it invokes PHP Code:
Ques2) In object particleForce object and also individual particle forces (eg gravity) there is base constructor and a clone of it. Also below it there is PHP Code:
Really appreciate your help! |
|
October 30, 2020, 18:34 |
|
#4 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,684
Rep Power: 40 |
Quote:
To understand the benefit of the clone() method, consider not having it - what would that look like for the following task? Make a copy of an item. If we know the type is "ABaseClass", we can write that, but what about "BDerivedClass" and "CDerivedClass" ? How would you create a copy of each list item, which derived from "A"? Enter the clone() method. Since it is virtual, it "knows" it's own type. Call it, and you get the copy you were looking for without knowing the type. |
||
November 3, 2020, 01:29 |
|
#5 |
Member
Stanley John
Join Date: Sep 2018
Posts: 79
Rep Power: 7 |
Thank you the explanation, as wannabe openFoam programmer, can you recommend any examples/keywords/lookups videos that can help one understand this, with out the additional baggage of dealling with 100's of differnet files? Anything that you used to self learn and climb the ladder up?
Thanks once again |
|
November 3, 2020, 15:20 |
|
#6 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,684
Rep Power: 40 |
Most of this is stuff that a regular user/programmer using OpenFOAM doesn't really need to know. Just find existing code patterns that mostly resemble what you need and go from there. And don't be overly smart and try to do something totally different if you don't understand why the original code was written that way.
Like any natural language, it takes time and practice to become reasonably fluent. |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
No matching function error: Phase change source term added to interMixingFoam | wavefunction | OpenFOAM Programming & Development | 2 | February 4, 2022 07:46 |
undefined reference to a C++'s class member function | linyanx | OpenFOAM Programming & Development | 5 | May 12, 2017 12:44 |
error adding void fraction into the solver & Error when chemistry is on | cmigueis | OpenFOAM Programming & Development | 23 | August 14, 2016 14:53 |
Add Temperature to multiphaseInterFoam | nthiers | OpenFOAM Programming & Development | 6 | February 17, 2016 08:42 |
Compiled custom wall function unknown by solver | juhuettn | OpenFOAM Programming & Development | 22 | October 22, 2014 09:56 |