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

objectRegistry::lookupObject<scalar>

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

Like Tree6Likes

Reply
 
LinkBack Thread Tools Display Modes
Old   January 18, 2014, 23:45
Default
  #41
Member
 
Fluid Dynamics
Join Date: Mar 2013
Posts: 41
Rep Power: 4
cfd.with.openfoam is on a distinguished road
Quick update -

I think now I can read and write from disk using the IOdictionary method as well. But as you know this is not a good way to go about it.

I will be looking forward to any comments/workarounds on updating a dictionary during runtime from a BC inside the database so that it can be looked up by another BC - on the fly or w/o writing anything to the disk.

Thank you very much
cfd.with.openfoam is offline   Reply With Quote

Old   January 19, 2014, 05:31
Default
  #42
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 397
Rep Power: 12
marupio is on a distinguished road
If you only need read access to objects created by the other BC, then you can pick them up through the objectRegistry. If you need write access you can cheat with a const cast or have your solver give them access from the top level.

If you want to share non-IOobjects, you can use IOlist or you can lookup the custom BC's themselves and put the data access methods in.
__________________
~~~
Follow me on twitter @DavidGaden
marupio is offline   Reply With Quote

Old   January 19, 2014, 12:23
Default
  #43
Member
 
Fluid Dynamics
Join Date: Mar 2013
Posts: 41
Rep Power: 4
cfd.with.openfoam is on a distinguished road
Hi David,

Thank you for your time. Some comments -

"If you only need read access to objects created by the other BC, then you can pick them up through the objectRegistry."

If I create an IOobject inside the updatecoeffs() member function of my Vel. BC then it is destroyed as soon as I go out and the object can't be looked up inside the updatecoeffs() member function of my Temp. BC. Is there any workaround for this? This is my first coding exercise in OpenFOAM so I don't know too much here.

"If you need write access you can cheat with a const cast or have your solver give them access from the top level"
How to do this David? Can you please explain?

"If you want to share non-IOobjects, you can use IOlist or you can lookup the custom BC's themselves and put the data access methods in. "

This is also beyond my current understanding.

Looking forward to your response.
Thank you
cfd.with.openfoam is offline   Reply With Quote

Old   January 19, 2014, 13:31
Default
  #44
Member
 
Fluid Dynamics
Join Date: Mar 2013
Posts: 41
Rep Power: 4
cfd.with.openfoam is on a distinguished road
Hi again David,

Just wanted to mention that (I think) I have read all the posts in this thread carefully.

Also in my messages I have only used words w/o any code. So here is what I have tried based (completely) on your posts in this thread.

// In the solver i.e createFields.H
Code:
IOdictionary compDict
(
    IOobject
    (
        "compDict",
        runTime.system(),
        mesh,
        IOobject::NO_READ,
        IOobject::NO_WRITE
    )
);
But in my Vel. BC I can't use & to look it up so I use the following which just makes a copy inside the Vel. BC, which gets destroyed as soon as I go out of the members function i.e updateCoeffs
Code:
IOdictionary compDict = db().lookupObject<IOdictionary>
(
   "compDict"
);
Then the variable is set in the Vel BC -
Code:
compDict.set("Zimbo",Zimbo);
Finally in the Temp. BC - again I look up the dictionary
Code:
IOdictionary compDict = db().lookupObject<IOdictionary>
(
   "compDict"
);
Then I try to look up the variable which for obvious reasons just doesn't work
Code:
 ZimboD = readScalar(compDict.lookup("Zimbo"));
You can see that I am just following your suggestions but as you can see that whatever I am doing inside my Vel. BC is not gonna work since I don't have a non-constant reference.

Hopefully it will give you a better picture of where I am.

Thank you for your time.
cfd.with.openfoam is offline   Reply With Quote

Old   January 25, 2014, 23:50
Default
  #45
Member
 
Fluid Dynamics
Join Date: Mar 2013
Posts: 41
Rep Power: 4
cfd.with.openfoam is on a distinguished road
Hi Everybody,

I think I managed to get around my issue by using the following
Code:
IOdictionary& compDict = 
const_cast<IOdictionary&>(db().lookupObject<IOdictionary>("compDict"));
instead of this
Code:
IOdictionary compDict = db().lookupObject<IOdictionary>("compDict"));
in the Vel. BC.

Hope it helps somebody
Thanks for your suggestions David.
cfd.with.openfoam is offline   Reply With Quote

Old   June 30, 2015, 03:53
Default
  #46
kcn
New Member
 
Join Date: May 2014
Posts: 29
Rep Power: 3
kcn is on a distinguished road
Quote:
Originally Posted by marupio View Post
May require some changes while debugging, but here's the essence:

Code:
// in createFields.H
IOdictionary scalarDict
(
    IOobject
    (
        "scalarDict",
        runTime.constant(),
        mesh,
        IOobject::NO_READ,
        IOobject::NO_WRITE
    )
);

// In runTime loop:
scalarDict.set("nameOfScalar", valueOfScalar);

// and you're done
I hope that helps!
Hi,

Can you please tell me how to modify this code to update the value of a subdictionary? I did the following but it didn't work.


// in createFields.H IOdictionary transportProperties ( IOobject ( "transportProperties", runTime.constant(), mesh, IOobject::MUST_READ_IF_MODIFIED, IOobject::AUTO_WRITE ) );
// Define subdictionary

dictionary updatedProperties
(
transportProperties.subDict("updatedProperties")
);

// In runTime loop: updatedProperties.set("nameOfScalar", valueOfScalar);
kcn 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



All times are GMT -4. The time now is 22:58.