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 |
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. |
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 |
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 Code:
IOdictionary compDict = db().lookupObject<IOdictionary> Code:
compDict.set("Zimbo",Zimbo); Code:
IOdictionary compDict = db().lookupObject<IOdictionary> Code:
ZimboD = readScalar(compDict.lookup("Zimbo")); Hopefully it will give you a better picture of where I am. Thank you for your time. |
Hi Everybody,
I think I managed to get around my issue by using the following Code:
IOdictionary& compDict = Code:
IOdictionary compDict = db().lookupObject<IOdictionary>("compDict")); Hope it helps somebody Thanks for your suggestions David. |
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); |
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 |
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 |
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 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] |
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) |
All times are GMT -4. The time now is 01:37. |