Extract a member function from a class by using autoPtr
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:
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. |
No one can help me ? :(
|
Greetings mkhm,
Bruno |
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: https://www.cfd-online.com/Forums/op...-properly.html ). 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 Code:
Code:
For me, species_ is an object to work on it. In the second case : Code:
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 |
Quick'ish answer:
Quote:
But if you really use chemFoam to solve your case... mmm... so, here is my train of thought:
|
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’ 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 |
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 |
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 :)
|
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: https://www.cfd-online.com/Forums/op...c-library.html Best regards, Bruno |
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. |
All times are GMT -4. The time now is 12:13. |