|
[Sponsors] |
How to make a dictionary run-time modifiable? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
April 8, 2011, 08:46 |
How to make a dictionary run-time modifiable?
|
#1 |
New Member
Kedar Jathar
Join Date: Jan 2010
Posts: 7
Rep Power: 16 |
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 Last edited by wyldckat; October 12, 2014 at 15:37. Reason: merged thread "how to make my variable run time modifiable" with this one |
|
September 21, 2014, 14:10 |
How to make a dictionary run-time modifiable?
|
#2 |
New Member
Gennaro
Join Date: May 2014
Posts: 23
Rep Power: 12 |
Hi all,
I created the following dictionary in createFields.H: Code:
IOdictionary equationConstants ( IOobject ( "equationConstants", runTime.constant(), fluidRegions[i], IOobject::MUST_READ, IOobject::NO_WRITE ) ); Info<< " Reading Alambda\n" << endl; Alambdas.set ( i, new dimensionedScalar(equationConstants.lookup("Alambda")) ); Info<< " Reading Slambda\n" << endl; Slambdas.set ( i, new dimensionedScalar(equationConstants.lookup("Slambda")) ); Info<< " Reading Tlambda\n" << endl; Tlambdas.set ( i, new dimensionedScalar(equationConstants.lookup("Tlambda")) ); Info<< " Reading SMALL\n" << endl; SMALLs.set ( i, new dimensionedScalar(equationConstants.lookup("SMALL")) ); Info<< " Reading Sigma\n" << endl; Sigmas.set ( i, new dimensionedScalar(equationConstants.lookup("Sigma")) ); Info<< " Reading Lref\n" << endl; Lrefs.set ( i, new dimensionedScalar(equationConstants.lookup("Lref")) ); Thanks in advance Gennaro |
|
September 25, 2014, 10:35 |
|
#3 |
New Member
Gennaro
Join Date: May 2014
Posts: 23
Rep Power: 12 |
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.
|
|
October 12, 2014, 13:56 |
|
#4 |
Senior Member
Join Date: Jan 2013
Posts: 372
Rep Power: 14 |
Dear Gennaro,
I have the same concern, did you solve this problem now? Thank you very much. OFFO |
|
October 12, 2014, 16:17 |
|
#5 |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128 |
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
__________________
Last edited by wyldckat; November 29, 2015 at 12:24. Reason: see "edit 1 year later" |
|
November 3, 2015, 13:02 |
|
#6 |
Senior Member
Join Date: Jan 2013
Posts: 372
Rep Power: 14 |
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 ( IOobject ( "additionalControls", runTime.constant(), mesh, IOobject::MUST_READ_IF_MODIFIED, IOobject::NO_WRITE ) ); Code:
dimensionedScalar relax(additionalControlsDict.lookup("relax")); Info<<"relax="<< relax <<endl; 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. |
|
November 29, 2015, 12:27 |
|
#7 |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128 |
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"); const int nOuterCorr = pisoDict.lookupOrDefault<int>("nOuterCorrectors", 1); const int nCorr = pisoDict.lookupOrDefault<int>("nCorrectors", 1); const int nNonOrthCorr = pisoDict.lookupOrDefault<int>("nNonOrthogonalCorrectors", 0); const bool momentumPredictor = pisoDict.lookupOrDefault("momentumPredictor", true); const bool transonic = pisoDict.lookupOrDefault("transonic", false); Code:
while (runTime.loop()) { Info<< "Time = " << runTime.timeName() << nl << endl; #include "readPISOControls.H" #include "CourantNo.H" fvVectorMatrix UEqn ( fvm::ddt(U) + fvm::div(phi, U) - fvm::laplacian(nu, U) ); Code:
while (runTime.loop()) { Info<< "Time = " << runTime.timeName() << nl << endl; #include "readPISOControls.H" #include "CourantNo.H" nu = transportProperties.lookup("nu"); fvVectorMatrix UEqn ( fvm::ddt(U) + fvm::div(phi, U) - fvm::laplacian(nu, U) ); Bruno
__________________
|
|
Tags |
runtime modifiable |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Transient simulation not converging | skabilan | OpenFOAM Running, Solving & CFD | 14 | December 17, 2019 00:12 |
How to export time series of variables for one point? | mary mor | OpenFOAM Post-Processing | 8 | July 19, 2017 11:54 |
simpleFoam error - "Floating point exception" | mbcx4jc2 | OpenFOAM Running, Solving & CFD | 12 | August 4, 2015 03:20 |
Sudden jump in Courant number | NJG | OpenFOAM Running, Solving & CFD | 7 | May 15, 2014 14:52 |
AMI interDyMFoam for mixer nu problem | danny123 | OpenFOAM Programming & Development | 8 | September 6, 2013 03:34 |