|
[Sponsors] |
Read a dictionary inside the intermediate library |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
June 23, 2016, 09:23 |
Read a dictionary inside the intermediate library
|
#1 |
Member
Sören Sander
Join Date: Sep 2012
Location: Germany
Posts: 43
Rep Power: 13 |
Hello Foamers,
usually, a dictionary (e.g. the physicalProperties or transportProperties inside the case file) is read by adding Code:
IOdictionary physicalProperties ( IOobject ( "physicalProperties", runTime.constant(), mesh, IOobject::MUST_READ_IF_MODIFIED, IOobject::NO_WRITE ) ); Code:
template<class ParcelType> template<class TrackData> void Foam::KinematicParcel<ParcelType>::calc ( TrackData& td, const scalar dt, const label cellI ) { // Define local properties at beginning of time step // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ IOdictionary myDict_ ( IOobject ( "myProperties", runTime.constant(), mesh, IOobject::MUST_READ_IF_MODIFIED, IOobject::NO_WRITE ) ); Code:
lnInclude/KinematicParcel.C: In member function 'void Foam::KinematicParcel<ParcelType>::calc(TrackData&, Foam::scalar, Foam::label)': lnInclude/KinematicParcel.C:122:13: error: 'runTime' was not declared in this scope runTime.constant(), ^ lnInclude/KinematicParcel.C:123:13: error: 'mesh' was not declared in this scope mesh, ^ How to access this values inside the KinematicParcel class? Can I access runTime inside the KinematicCloud/KinematicParcel class or am I going a wrong way here? I saw that the class definition of KinematicParcel.H has Code:
template<class ParcelType> class KinematicParcel : public ParcelType { public: //- Class to hold kinematic particle constant properties class constantProperties { ... Any ideas are welcome, Best regards, Sören |
|
June 24, 2016, 06:11 |
|
#2 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51 |
Dear Sören,
you have a knot in your mind. The solver is not related to the library therefore it tells you that you have no variable named runTime in the lib that you trying to modify. The first thing, never call of a dict in a calc function. Do it within the constructor and save the dictionary as a member variable (but that is up to you). For example. In the constructor you would have fields like U_ that can be used to get the time. If I am not wrong its like U_.mesh().time(); In your case you only have 3 variables: Code:
TrackData& td, const scalar dt, const label cellI Code:
IOobject (const word &name, const fileName &instance, const objectRegistry ®istry, readOption r=NO_READ, writeOption w=NO_WRITE, bool registerObject=true) Hence I would prefer to do it in the constructor and save this dictionary as a member of your class. Then you have access to it.
__________________
Keep foaming, Tobias Holzmann Last edited by Tobi; June 24, 2016 at 08:19. |
|
July 1, 2016, 03:03 |
|
#3 |
Member
Sören Sander
Join Date: Sep 2012
Location: Germany
Posts: 43
Rep Power: 13 |
Hi Tobi,
thank you very much for "unknoting" me there. Your suggestion works fine, even though I have the vague feeling OpenFOAM handles this slightly different from my solution (I pass the dict like the fields are passed, it seems OF does read the dict inside the constructor, however I had some issues doing the same there). Best regards, Sören |
|
July 1, 2016, 03:36 |
|
#4 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51 |
Hi,
as I am a Bavarian I understand your phrase "unknoting" but I am not sure if we are allowed to translate it directly Anyway... where is the problem? If I understand it correctly, you added a argument to the constructor and read the file there or you want to add the argument to the function? I am happy that I could help you.
__________________
Keep foaming, Tobias Holzmann |
|
July 1, 2016, 08:16 |
|
#5 |
Member
Sören Sander
Join Date: Sep 2012
Location: Germany
Posts: 43
Rep Power: 13 |
Fields are read as an argument of the constructor, e.g.
Code:
Info<< "Constructing kinematicCloud " << kinematicCloudName << endl; basicKinematicCollidingCloud kinematicCloud ( kinematicCloudName, rhoInf, U, ... However, OpenFoam seems to create dictionaries in libraries inside the constructor, without passing them, e.g. Code:
//- Thermo parcel constant properties typename parcelType::constantProperties constProps_; 1. Add it directly to the loop inside the : Code:
//Read from dictionary named "myProperties" IOdictionary myProperties ( IOobject ( "myProperties", td.cloud().U().time().constant(), td.cloud().U().db(), IOobject::MUST_READ_IF_MODIFIED, IOobject::NO_WRITE ) ); Foam::dimensionedScalar myValue = myProperties.lookup("myValue"); |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
using fieldAverage library to average postprocessing | eelcovv | OpenFOAM Programming & Development | 32 | May 17, 2022 09:55 |
Read properties per component from an input file dictionary | Cyp | OpenFOAM Programming & Development | 29 | November 1, 2015 21:41 |
How to read a list from a dictionary? | ivan_cozza | OpenFOAM Programming & Development | 6 | November 7, 2014 08:31 |
Read inside a class | tonyuprm | OpenFOAM | 12 | July 14, 2010 02:35 |
Phase locked average in run time | panara | OpenFOAM | 2 | February 20, 2008 14:37 |