How to make a dictionary run-time modifiable?
Hello All:
I have a bool type of variable which is read from the transport properties file. The true/false value gets read for the first time. However if I change that value in the transport properties file at runtime then the change is not communicated to the solver. The solver registers that the transport properties file has changed but it doesn't update the value of my variable. Controldict runtime modifiable is yes. Is there something more I need to do to make the solver understand it has to read the updated value ? Thanks, Kedar |
How to make a dictionary run-time modifiable?
Hi all,
I created the following dictionary in createFields.H: Code:
IOdictionary equationConstants Thanks in advance Gennaro |
any ideas? The problem is that not currently being run-time modifiable, if I change values in the dictionary file while a simulation is running, the new values are not read.
|
Dear Gennaro,
I have the same concern, did you solve this problem now? Thank you very much. OFFO Quote:
|
Greetings to all!
I've moved the very first post from an old thread to this thread, since it's all in the same topic. And I have to say that this is a bit of a tricky topic. First of all, the core magic happens if you use this option: Code:
IOobject::MUST_READ_IF_MODIFIED Code:
IOobject::MUST_READ Therefore, the variables "*lambdas" can only be updated if "equationConstants" is called once again. Usually what's done is that this kind of auto-updatable code is placed inside a class that handles the data maintenance and storage. For example, if you look at the class "motionSolver": https://github.com/OpenFOAM/OpenFOAM...r/motionSolver - you'll see how this class derives from "IOdictionary", where the method "read()" is a virtual method that when reimplemented in "motionSolver", will automatically update the variables within "motionSolver" based on the data read from the assigned dictionary file. This method "read()" is called automatically by the mechanism "IOdictionary" inherits from other classes - for more information, read this wiki page and the ones referenced in it: http://openfoamwiki.net/index.php/Op...IOobject_class Therefore, the solution should be to do the following steps, in Gennaro's example:
A simplified version of this big example would be something like this:
Bruno |
Dear Bruno,
This is an old problem, but it seems I have not solved it yet. I add the following in the createField.H to build a dictionary: Code:
IOdictionary additionalControlsDict Code:
dimensionedScalar relax(additionalControlsDict.lookup("relax")); Also, in the last thread, you mentioned that: Code:
Therefore, the variables "*lambdas" can only be updated if "equationConstants" is called once again. Thank you. |
Hi OFFO,
Many thanks for asking about this, because as I had mentioned in the previous post, I wasn't certain if it would work, since I didn't test it myself. Nonetheless, I've tested this now with icoFoam and apparently the "modified()" method can only be used by the auto-reading mechanism. What we should simply do is the same that the file "readPISOControls.H" does (see in folder "src/finiteVolume/cfdTools/general/include/" in OpenFOAM 2.1.1): Code:
const dictionary& pisoDict = mesh.solutionDict().subDict("PISO"); Code:
while (runTime.loop()) Code:
while (runTime.loop()) Bruno |
All times are GMT -4. The time now is 04:11. |