|
[Sponsors] |
Extract a member function from a class by using autoPtr |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
October 10, 2018, 14:34 |
Extract a member function from a class by using autoPtr
|
#1 |
Member
K
Join Date: Jul 2017
Posts: 97
Rep Power: 9 |
Dear Foamers,
I would like to write an utility where I could extract the member functions of a known class. For instance, I would like to extract the forward and backward reaction rates. I know that there is a class called ReactionProxy : https://github.com/OpenFOAM/OpenFOAM...eactionProxy.C where these two variables are virtual public member functions of it. So in createFields, I have to use a pointer to this class. But I have difficulties to figure out how I should write this pointer. I tried many variants such as : Code:
autoPtr<ReactionProxy> pReaction(ReactionProxy::New(mesh)); but it did not work. In chemkinReader.C, they use this class like : Code:
case irreversible: 180 { 181 reactions_.append 182 ( 183 new IrreversibleReaction 184 <Reaction, gasHThermoPhysics, ReactionRateType> 185 ( 186 ReactionProxy<gasHThermoPhysics> 187 ( 188 speciesTable_, 189 lhs.shrink(), 190 rhs.shrink(), 191 speciesThermo_ 192 ), 193 rr 194 ) 195 ); I tried to have inspiration from that part of the code, but I had errors. Could someone explain how we can use public members of a class by using pointers ? I would be very grateful of your replies. I should write some postProcessing tools but as I am lacking C++ knowledge, I have lots of difficulty. Thanks in advance for our replies. |
|
October 12, 2018, 12:37 |
|
#2 |
Member
K
Join Date: Jul 2017
Posts: 97
Rep Power: 9 |
No one can help me ?
|
|
October 13, 2018, 07:39 |
|
#3 | |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128 |
Greetings mkhm,
Bruno
__________________
|
||
October 15, 2018, 03:52 |
|
#4 | |
Member
K
Join Date: Jul 2017
Posts: 97
Rep Power: 9 |
Quote:
Thanks for your reply. I am so excited that finally I got an answer to my question. In below, my replies to your questions/hints: 1. Thanks for moving the thread. Indeed, my question is more about C++ programming. But as the context was the openFoam, I thought I might get a reply faster by posting it in post processings forum of OpenFoam. I was indeed wrong. 2. Thanks for mentionning that. It would help me to probably have an answer to my other thereads which did not get any attention. 3. I have to develop some post processing tools. As I am running the steady state simulations, I can as well think to write a tool which would be executed at the final step of my simulations. I tried to take the sensitivity analysis case of openFoam 1806 and compile it for OpenFoam 4.x where I have my modified solvers (My thread about that function object: How to create a function object in OpenFoam that runs properly ? ). However, this seems to be very complicated as this function object depends on many other classes not available in OpenFoam 4.x. So, I started to think to simplify the work and go step by step. For instance, writing an post processing tool where only some useful variables available by virtual functions are extracted. For example: there is this ProxyReaction ( https://github.com/OpenFOAM/OpenFOAM...eactionProxy.C ) or even Reaction (https://cpp.openfoam.org/v6/classFoam_1_1Reaction.html) where the reaction rate coefficients kf (forward) and kr (reverse) could be accessed by a pointer. However, I can not find a right way of writing an autoPointer to these classes to extact data. I explain you my strategy: The constructers of reaction proxy are: Code:
//- Construct and return a clone virtual autoPtr<Reaction<ReactionThermo>> clone() const; //- Construct and return a clone with new speciesTable virtual autoPtr<Reaction<ReactionThermo>> clone ( const speciesTable& species ) const; Code:
autoPtr<ReactionProxy<gasHThermoPhysics > > pReaction ( ReactionProxy<gasHThermoPhysics>::clone(species_) ); and for species_: Info<< "Reading Fake dictionary\n" << endl; IOdictionary Fake_ ( IOobject ( "Fake", runTime.timeName(), mesh, IOobject::MUST_READ, IOobject::NO_WRITE ) ); wordList speciesList = Fake_.lookup("species"); speciesTable species_ = speciesList; OR autoPtr<ReactionProxy<gasHThermoPhysics > > pReaction ( ReactionProxy<gasHThermoPhysics>::clone() ); Code:
cannot call member function ‘Foam::autoPtr<Foam::Reaction<ReactionThermo> > Foam::ReactionProxy<ReactionThermo>::clone(const speciesTable&) const [with ReactionThermo = Foam::sutherlandTransport<Foam::species::thermo<Foam::janafThermo<Foam::perfectGas<Foam::specie> >, Foam::sensibleEnthalpy> >; Foam::speciesTable = Foam::hashedWordList]’ without object ReactionProxy<gasHThermoPhysics>::clone(species_) For me, species_ is an object to work on it. In the second case : Code:
cannot call member function ‘Foam::autoPtr<Foam::Reaction<ReactionThermo> > Foam::ReactionProxy<ReactionThermo>::clone() const [with ReactionThermo = Foam::sutherlandTransport<Foam::species::thermo<Foam::janafThermo<Foam::perfectGas<Foam::specie> >, Foam::sensibleEnthalpy> >]’ without object ReactionProxy<gasHThermoPhysics>::clone() 4. I took chemFoam solver's make folder, its create fields and the Utility_name.C does nothing for the moment. 5. Ideally, I want it to calculate after simulation. However, my purpose now, it is more learning the C++ by writing some simple tools to elaborate them afterwards. Thanks a lot for your time. Don't hesitate to ask me if there is a need to clarify more some points. Best regards, Mary |
||
October 20, 2018, 17:51 |
|
#5 | |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128 |
Quick'ish answer:
Quote:
But if you really use chemFoam to solve your case... mmm... so, here is my train of thought:
|
||
October 21, 2018, 14:49 |
|
#6 |
Member
K
Join Date: Jul 2017
Posts: 97
Rep Power: 9 |
Dear Bruno,
Thanks for your thorough reply. I am using a modified version of rhoCentralFoam. The solver is changed in order to simulate a reactive flow. I tried to implement your idea. I have the following error: Code:
‘class Foam::psiChemistryModel’ has no member named ‘reactions’ const PtrList<Reaction<psiThermo>>& myReactionsAccess = chemistry.reactions(); Code:
inline const PtrList<Reaction<ThermoType>>& reactions() const; In Reaction proxy and TDAC (https://cpp.openfoam.org/v5/classFoa...3d3b916874f5ca) , I realised that they copied somehow parts of the chemistryModel in order to use some parameters like kf. But as my C++ knowledge is limited, I get lost by this whole information. Do you have any ideas how to solve this problem ? Best regards |
|
October 22, 2018, 15:48 |
|
#7 |
Member
Vince
Join Date: Mar 2017
Posts: 45
Rep Power: 9 |
Hi Mary,
If you're willing to modify the source code, you could add a public member function to the chemistryModel class in Code:
src/thermophysicalModels/chemistryModel/chemistryModel/chemistryModel.H For that, you may want to create a list of volScalarField storing kf in that class and update it for each cell and each species when kf is being calculated (Ctrl+f kf in this file). Your new method would return kf for a given cell and a given species. In your solver, I assume that you know how to update the species concentrations, typically: Code:
reaction->correct(); Code:
const scalar kf = reaction->get_kf(speciei, celli); For more details, here's a solver that is also based on rhoCentralFoam and reactingFoam: https://github.com/vincentcasseau/hy...sible/hy2Foam/ You could check the definition of reaction and see how it's used in eqns/YEqn.H. Please let us know if that answers your question. Thanks, Vince |
|
November 4, 2018, 04:29 |
|
#8 |
Member
K
Join Date: Jul 2017
Posts: 97
Rep Power: 9 |
Thanks Vince for your reply. My objective was more to learn how to extract data from existing classes of OpenFoam. Anyway, thanks for proposing this alternative
|
|
November 4, 2018, 09:30 |
|
#9 |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128 |
Greetings to all,
OK... that's what happens when I don't test things myself... alright, continuing with the thought+search process:
Beyond this, yesterday I found another thread discussing accesses to new entries on boundary conditions and dictionaries in general, which might come in handy for you as well for something else: Accessing boundary patch dictionary within thermodynamic library Best regards, Bruno
__________________
|
|
November 13, 2018, 13:05 |
|
#10 |
Member
K
Join Date: Jul 2017
Posts: 97
Rep Power: 9 |
Thanks a lot Bruno.
It works fine for me. Without any crashes Special thanks for sharing your thought+search process. It is a very useful teaching way. I learned a lot. And I am sure that I will read again and again this thread for other implementation processes. Thanks for the time you put for this case. |
|
Tags |
autoptr, openfoam, postprocessing, utility, virtual |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Other] refineWallLayer Error | Yuby | OpenFOAM Meshing & Mesh Conversion | 2 | November 11, 2021 12:04 |
[blockMesh] non-orthogonal faces and incorrect orientation? | nennbs | OpenFOAM Meshing & Mesh Conversion | 7 | April 17, 2013 06:42 |
is internalField(U) equivalent to zeroGradient? | immortality | OpenFOAM Running, Solving & CFD | 7 | March 29, 2013 02:27 |
Droplet Evaporation | Christian | Main CFD Forum | 2 | February 27, 2007 07:27 |
Accessing a member function in a class | fabianpk | OpenFOAM | 2 | June 14, 2006 10:20 |