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

Read a dictionary inside the intermediate library

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

Reply
 
LinkBack Thread Tools Display Modes
Old   June 23, 2016, 09:23
Default Read a dictionary inside the intermediate library
  #1
Member
 
Sören Sander
Join Date: Sep 2012
Location: Germany
Posts: 42
Rep Power: 6
Sören Sander is on a distinguished road
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
    )
);
Adding this line into intermediate/parcels/Templates/KinematicParcel/KinematicParcel.C
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
        )
    );
gives the error

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,
             ^
In the main solver " #include "createTime.H" " creates runTime, if I am not mistaken. However, I need to access a variable amount of aPriori defined values inside the kinematic parcel.
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
    {
...
However, I was not able to add a variable here.

Any ideas are welcome,
Best regards,
Sören
Sören Sander is offline   Reply With Quote

Old   June 24, 2016, 06:11
Default
  #2
Senior Member
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Leoben (Austria)
Posts: 1,501
Blog Entries: 6
Rep Power: 25
Tobi will become famous soon enoughTobi will become famous soon enough
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
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
You are trying to build a IOobject that can be done like that:
Code:
 IOobject (const word &name, const fileName &instance, const objectRegistry &registry, readOption r=NO_READ, writeOption w=NO_WRITE, bool registerObject=true)
As you see, the the second argument is a file name and the third one an objectRegistry. Now the question is how to get these. In the header file there is nothing related to these object. So if it is possible you can have access to already available registry fields with ->db() or you can extract anything from the TrackData field. A short look into doxygen shows that trackData is only a List<>. So not related to any registryObject file.

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.
__________________
Best regards,
Tobias Holzmann

Some interesting OpenFOAM tutorials and videos on www.Holzmann-cfd.de

Last edited by Tobi; June 24, 2016 at 08:19.
Tobi is offline   Reply With Quote

Old   July 1, 2016, 03:03
Default
  #3
Member
 
Sören Sander
Join Date: Sep 2012
Location: Germany
Posts: 42
Rep Power: 6
Sören Sander is on a distinguished road
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
Sören Sander is offline   Reply With Quote

Old   July 1, 2016, 03:36
Default
  #4
Senior Member
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Leoben (Austria)
Posts: 1,501
Blog Entries: 6
Rep Power: 25
Tobi will become famous soon enoughTobi will become famous soon enough
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
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.
__________________
Best regards,
Tobias Holzmann

Some interesting OpenFOAM tutorials and videos on www.Holzmann-cfd.de
Tobi is offline   Reply With Quote

Old   July 1, 2016, 08:16
Default
  #5
Member
 
Sören Sander
Join Date: Sep 2012
Location: Germany
Posts: 42
Rep Power: 6
Sören Sander is on a distinguished road
Fields are read as an argument of the constructor, e.g.

Code:
    Info<< "Constructing kinematicCloud " << kinematicCloudName << endl;
    basicKinematicCollidingCloud kinematicCloud
    (
        kinematicCloudName,
        rhoInf,
        U,
        ...
which means, I need to construct them at the main solver first and then pass them towards the particle library. Using db() functionality, I could also access the values inside the calculator function (which would result in re-reading the values quite too often, as you already pointed out).
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_;
This way the constructor does not need the dictionary as an input argument. I guess one would need to add a new dictionary somewhere there? What I tried:

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");
Which works inside the "calc" routine. But adding it to the constructor lead to an error as "td" is unknown (not defined there). I guess I miss how to access the fields inside the constructor.
Sören Sander is offline   Reply With Quote

Reply

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
using fieldAverage library to average postprocessing eelcovv OpenFOAM Programming & Development 28 August 8, 2016 04:53
Read properties per component from an input file dictionary Cyp OpenFOAM Programming & Development 29 November 1, 2015 22:41
How to read a list from a dictionary? ivan_cozza OpenFOAM Programming & Development 6 November 7, 2014 09: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 15:37


All times are GMT -4. The time now is 08:00.