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

Accessing Dictionary Files from src files

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 4, 2024, 18:53
Default Accessing Dictionary Files from src files
  #1
Member
 
Refik
Join Date: Dec 2014
Location: Turkey
Posts: 56
Rep Power: 11
rewol is on a distinguished road
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.
rewol is offline   Reply With Quote

Old   May 7, 2024, 05:20
Default Why not in the initializer list?
  #2
New Member
 
Felix Benz
Join Date: Jan 2020
Posts: 3
Rep Power: 6
FBenz is on a distinguished road
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
FBenz is offline   Reply With Quote

Old   May 7, 2024, 12:02
Default
  #3
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,706
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by rewol View Post
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.



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

Old   May 22, 2024, 14:41
Default
  #4
Member
 
Refik
Join Date: Dec 2014
Location: Turkey
Posts: 56
Rep Power: 11
rewol is on a distinguished road
Quote:
Originally Posted by olesen View Post
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.

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

Old   May 23, 2024, 02:01
Default
  #5
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,706
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by rewol View Post
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 ?

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

Reply


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


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


All times are GMT -4. The time now is 21:53.