|
[Sponsors] |
January 18, 2014, 23:45 |
|
#41 |
Member
Fluid Dynamics
Join Date: Mar 2013
Posts: 41
Rep Power: 13 |
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 |
|
January 19, 2014, 05:31 |
|
#42 |
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22 |
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 |
|
January 19, 2014, 12:23 |
|
#43 |
Member
Fluid Dynamics
Join Date: Mar 2013
Posts: 41
Rep Power: 13 |
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 |
|
January 19, 2014, 13:31 |
|
#44 |
Member
Fluid Dynamics
Join Date: Mar 2013
Posts: 41
Rep Power: 13 |
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 ) ); Code:
IOdictionary compDict = db().lookupObject<IOdictionary> ( "compDict" ); Code:
compDict.set("Zimbo",Zimbo); Code:
IOdictionary compDict = db().lookupObject<IOdictionary> ( "compDict" ); Code:
ZimboD = readScalar(compDict.lookup("Zimbo")); Hopefully it will give you a better picture of where I am. Thank you for your time. |
|
January 25, 2014, 23:50 |
|
#45 |
Member
Fluid Dynamics
Join Date: Mar 2013
Posts: 41
Rep Power: 13 |
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")); Code:
IOdictionary compDict = db().lookupObject<IOdictionary>("compDict")); Hope it helps somebody Thanks for your suggestions David. |
|
June 30, 2015, 04:53 |
|
#46 | |
Member
Join Date: May 2014
Posts: 31
Rep Power: 12 |
Quote:
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); |
||
June 26, 2017, 11:36 |
|
#47 | |
New Member
Ehimen
Join Date: Jun 2016
Posts: 12
Rep Power: 10 |
Quote:
This will enable the modification of the dictionary at every timestep. To read the value added to the dictionary, use: updatedProperties.lookup("nameOfScalar") >> newvalueOfScalar; Should be good to go. I use OpenFOAM 4 |
||
November 19, 2017, 10:21 |
|
#48 | |
Senior Member
A. Min
Join Date: Mar 2015
Posts: 308
Rep Power: 12 |
Quote:
Hi I'm not a professional in openFaom programing! Could you please explain about some lines of this code:1 1- what is db() ? 2- what's the meaning of this line: lookupObject<IOdictionary> thanks |
||
March 8, 2022, 12:28 |
|
#49 |
Member
UOCFD
Join Date: Oct 2020
Posts: 40
Rep Power: 6 |
I have a similar problem to yours, so in my BC I have included
Code:
IOdictionary copyOpenFraction = db().lookupObject<IOdictionary>("copyOpenFraction"); Moreover, I added to the solver's createFields.H Code:
IOdictionary copyOpenFraction ( IOobject ( "copyOpenFraction", runTime.system(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), 0 ); Code:
IOdictionary& copyOpenFraction = const_cast<IOdictionary&>(db().lookupObject<IOdictionary>("copyOpenFraction")); Code:
lnInclude/myLocalInteraction.C:221:76: error: there are no arguments to ‘db’ that depend on a template parameter, so a declaration of ‘db’ must be available [-fpermissive] 221 | IOdictionary& copyOpenFraction = const_cast<IOdictionary&>(db().lookupObject<IOdictionary>("copyOpenFraction")); | ^~ lnInclude/myLocalInteraction.C:221:76: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated) |
|
March 8, 2022, 15:53 |
|
#50 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40 |
I would hazard a guess that your local interaction model (or the method where your error shows) is templated on some parameter. The usual way to resolve your error is with something like this:
Code:
this->db().lookupObject<whateverOtherType>(name) |
|
|
|