|
[Sponsors] |
May 4, 2024, 18:53 |
Accessing Dictionary Files from src files
|
#1 |
Member
Refik
Join Date: Dec 2014
Location: Turkey
Posts: 56
Rep Power: 11 |
Hello,
I am developing my own chemistry library and need to track reaction rates for certain reactions. For this i copied StandardChemistryModel class and it is my intention to make the class create an dictionary object which i can use to read the index of the reaction to be tracked. In myStandardChemistryModel.H, i added following members: IOdictionary Dict; label tracked; In myStandardChemistryModel.C constructor, i added the following inside the constructor scope (not initilializer list): Dict ( IOobject ( "DictName", this->mesh().time().constant(), this->mesh(), IOobject::NO_READ, IOobject::NO_WRITE ) ); tracked(readLabel(Dict.lookup("reactionTrackLabel" ))); When i try to compile, i get the following error: error: no match for call to '(Foam::IOdictionary) (Foam::IOobject)' This code works well (with runTime) in solver files but now that i am in the "src" part, i wonder why it wouldnt recognize the dictionary object. Can anybody offer some guidance on what to try ? Best Regards. |
|
May 7, 2024, 05:20 |
Why not in the initializer list?
|
#2 |
New Member
Felix Benz
Join Date: Jan 2020
Posts: 3
Rep Power: 6 |
Hello,
is there a reason not to put it in the initializer list? I also had problems initializing IOobjects in the constructor scope. Best regards Felix |
|
May 7, 2024, 12:02 |
|
#3 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,706
Rep Power: 40 |
Quote:
You think you are constructing an IOdictionary within your constructor body, but "Dict" has already been implicitly default constructed before that point. Not sure how that even compiles, since there is no default constructor for that class. Within the body, you aren't actually constructing "Dict", but calling it with its operator()(....) method - which is also not defined. Your issues continue with "tracked" as well - also trying to use an operator()(...) on an integer, which will not go well. |
||
May 22, 2024, 14:41 |
|
#4 | |
Member
Refik
Join Date: Dec 2014
Location: Turkey
Posts: 56
Rep Power: 11 |
Quote:
Thank you for your response, sir. I did it in the initializer list and situation is resolved. So basically when i introduce "Dict" in the class header and tried to fill it within constructor, it does not create it but consider it as a function call which is not defined. Am i correct ? Same goes with "tracked" as well i reckon. Is there really no other way to relate "Dict" member to the dictionary in the case file ? |
||
May 23, 2024, 02:01 |
|
#5 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,706
Rep Power: 40 |
Quote:
There is nothing special (ie, non-C++ conform) about how things are working, and I honestly don't understand your question. Please reformulate it. If you are asking about default constructing members in the initialization and then copy/move assigning them within the body : this will depend on what the particular member classes allow. For all things derived from IOobject and regIOobject, it is not possible to default construct them. In most cases, a subsequent copy assignment will only copy the contained data, not the regIOobject database interface. If you are asking about how to specify non-ambiguous access to the member functions of member classes, it's just standard C++ for that as well. If you are asking about, for example, how to obtain the dictionary part of the class: Code:
// assuming the class inherits from IOdictionary dictionary& dict = *this; // or dictionary& dict = static_cast<dictionary&>(*this); // or dictionary& dict = static_cast<IOdictionary&>(*this); // or ... |
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Accessing boundary patch dictionary within thermodynamic library | Tobi | OpenFOAM Programming & Development | 8 | November 5, 2018 03:50 |
Accessing mesh dictionary from solver | Pascal_doran | OpenFOAM Programming & Development | 6 | October 31, 2017 07:26 |
Results saving in CFD | hawk | Main CFD Forum | 16 | July 21, 2005 20:51 |
[making animations] fclose fails to close files? | Mika | FLUENT | 0 | March 30, 2001 08:19 |
Merging .msh files in TGrid | Raza Mirza | FLUENT | 2 | January 18, 2001 18:09 |