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

Extract a member function from a class by using autoPtr

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   October 10, 2018, 13:34
Default Extract a member function from a class by using autoPtr
  #1
New Member
 
Mary
Join Date: Jul 2017
Posts: 17
Rep Power: 3
mkhm is on a distinguished road
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.
mkhm is offline   Reply With Quote

Old   October 12, 2018, 11:37
Default
  #2
New Member
 
Mary
Join Date: Jul 2017
Posts: 17
Rep Power: 3
mkhm is on a distinguished road
No one can help me ?
mkhm is offline   Reply With Quote

Old   October 13, 2018, 06:39
Default
  #3
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,381
Blog Entries: 41
Rep Power: 114
wyldckat is a glorious beacon of lightwyldckat is a glorious beacon of lightwyldckat is a glorious beacon of lightwyldckat is a glorious beacon of lightwyldckat is a glorious beacon of lightwyldckat is a glorious beacon of light
Greetings mkhm,
  1. I've moved your thread to the sub-forum for Programming: https://www.cfd-online.com/Forums/op...ng-development - given that your question is mostly regarding programming
  2. If you notice that you've posted a new post or thread in the wrong place, please contact the forum moderators, as indicated in the forum rules page, and I quote:
    Quote:
    If you have posted your question in the wrong place please contact a Forum Moderator to have it moved.
    (Sorry for nitpicking, but since you posted that no one was helping you, I felt compelled to point out why possibly you were not getting any answers... )
  3. It would be useful to have more details on what you want to do exactly, because it's possible that you are trying to get things to work with the wrong approach.
    • What I mean is that it depends if you are trying to do new reaction calculations or if you are trying to load existing results and process them accordingly, because each strategy requires different approaches.
  4. Knowing which solver you've used to simulate the case also helps, given that each solver can use a different mechanism for creating transport and reaction structures.
  5. And the last question is if this is something that you only want to calculate after the simulation is complete or if it's something you want to do while the simulation is running.
Best regards,
Bruno
__________________
wyldckat is offline   Reply With Quote

Old   October 15, 2018, 02:52
Default
  #4
New Member
 
Mary
Join Date: Jul 2017
Posts: 17
Rep Power: 3
mkhm is on a distinguished road
Quote:
Originally Posted by wyldckat View Post
Greetings mkhm,
  1. I've moved your thread to the sub-forum for Programming: https://www.cfd-online.com/Forums/op...ng-development - given that your question is mostly regarding programming
  2. If you notice that you've posted a new post or thread in the wrong place, please contact the forum moderators, as indicated in the forum rules page, and I quote:

    (Sorry for nitpicking, but since you posted that no one was helping you, I felt compelled to point out why possibly you were not getting any answers... )
  3. It would be useful to have more details on what you want to do exactly, because it's possible that you are trying to get things to work with the wrong approach.
    • What I mean is that it depends if you are trying to do new reaction calculations or if you are trying to load existing results and process them accordingly, because each strategy requires different approaches.
  4. Knowing which solver you've used to simulate the case also helps, given that each solver can use a different mechanism for creating transport and reaction structures.
  5. And the last question is if this is something that you only want to calculate after the simulation is complete or if it's something you want to do while the simulation is running.
Best regards,
Bruno
Hi Bruno

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;
I'll write something like:

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

    );
In fisrt case, I have the following error:


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
mkhm is offline   Reply With Quote

Reply

Tags
autoptr, openfoam, postprocessing, utility, virtual

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
refineWallLayer Error Yuby OpenFOAM Meshing & Mesh Conversion 1 May 19, 2017 10:13
non-orthogonal faces and incorrect orientation? nennbs OpenFOAM Native Meshers: blockMesh 7 April 17, 2013 05:42
is internalField(U) equivalent to zeroGradient? immortality OpenFOAM Running, Solving & CFD 7 March 29, 2013 01:27
Droplet Evaporation Christian Main CFD Forum 2 February 27, 2007 06:27
Accessing a member function in a class fabianpk OpenFOAM 2 June 14, 2006 09:20


All times are GMT -4. The time now is 17:43.