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

How to make a dictionary run-time modifiable?

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

Reply
 
LinkBack Thread Tools Display Modes
Old   April 8, 2011, 07:46
Default How to make a dictionary run-time modifiable?
  #1
New Member
 
Kedar Jathar
Join Date: Jan 2010
Posts: 7
Rep Power: 7
kedarj14 is on a distinguished road
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 14:37. Reason: merged thread "how to make my variable run time modifiable" with this one
kedarj14 is offline   Reply With Quote

Old   September 21, 2014, 13:10
Default How to make a dictionary run-time modifiable?
  #2
New Member
 
Gennaro
Join Date: May 2014
Posts: 23
Rep Power: 3
Gennaro is on a distinguished road
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"))
        );
How can I make it run-time modifiable?

Thanks in advance

Gennaro
Gennaro is offline   Reply With Quote

Old   September 25, 2014, 09:35
Default
  #3
New Member
 
Gennaro
Join Date: May 2014
Posts: 23
Rep Power: 3
Gennaro is on a distinguished road
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.
Gennaro is offline   Reply With Quote

Old   October 12, 2014, 12:56
Default
  #4
Senior Member
 
Join Date: Jan 2013
Posts: 196
Rep Power: 4
openfoammaofnepo is on a distinguished road
Dear Gennaro,

I have the same concern, did you solve this problem now? Thank you very much.
OFFO


Quote:
Originally Posted by Gennaro View Post
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.
openfoammaofnepo is offline   Reply With Quote

Old   October 12, 2014, 15:17
Default
  #5
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,251
Blog Entries: 34
Rep Power: 84
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
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
instead of:
Code:
IOobject::MUST_READ
But this only ensures that the dictionary variable is updated. In Gennaro's example, the variable "equationConstants" is automatically updated at the beginning of the "runTime"/"simpleControl"/"pimpleControl" loop.
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:
  1. Create a new class that derives from "IOdictionary" and place inside it the code that handles the population of the variables "*lambda". I'll call it "LambdaManager" for example.
  2. In the "createFields.H" file, replace all of your presented code with something like this:
    Code:
    //definition for replacing all of the lists you've got with just one
    PtrList<LambdaManager> equationConstants(numRegions);
    
    //... then use this instead
    
            equationConstants.set
            (
              i,
              new LambdaManager(
                IOobject(
                (
                    "equationConstants",
                    runTime.constant(),
                    fluidRegions[i],
                    IOobject::MUST_READ_IF_MODIFIED,
                    IOobject::NO_WRITE
                )
              )
            );
  3. Now, the final step for this trick (assuming you can create the new class on your own), is to replace the calls to the variables from this:
    Code:
    Alambdas(i)()
    To this:
    Code:
    equationConstants(i)().Alambda()


A simplified version of this big example would be something like this:
  1. Have a look at the solver "laplacianFoam": https://github.com/OpenFOAM/OpenFOAM.../laplacianFoam
  2. Move this piece of code from "createFields.H":
    Code:
        Info<< "Reading diffusivity DT\n" << endl;
    
        dimensionedScalar DT
        (
            transportProperties.lookup("DT")
        );
    to "laplacianFoam.C", after this part of the code:
    Code:
        while (simple.loop())
        {
            Info<< "Time = " << runTime.timeName() << nl << endl;
  3. In other words, it becomes something like this:
    Code:
        while (simple.loop())
        {
            Info<< "Time = " << runTime.timeName() << nl << endl;
    
            Info<< "Updating diffusivity DT\n" << endl;
    
            dimensionedScalar DT
            (
                transportProperties.lookup("DT")
            );
  4. It's not the prettiest solution, but I'm not in the mood to test this myself and to improve this solution
    I'm not 100% certain, but I think that this might work:
    Code:
        while (simple.loop())
        {
            Info<< "Time = " << runTime.timeName() << nl << endl;
    
            if(transportProperties.modified())
            {
                Info<< "Updating diffusivity DT\n" << endl;
    
                DT = dimensionedScalar(transportProperties.lookup("DT"));
            }
    Of course this implies that in this case, you should not make any changes to the file "createFields.H"
Best regards,
Bruno
wyldckat is offline   Reply With Quote

Reply

Tags
runtime modifiable

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
simpleFoam error - "Floating point exception" mbcx4jc2 OpenFOAM Running, Solving & CFD 11 June 25, 2015 13:53
Sudden jump in Courant number NJG OpenFOAM Running, Solving & CFD 7 May 15, 2014 13:52
How to export time series of variables for one point? mary mor OpenFOAM Post-Processing 7 February 19, 2014 16:56
AMI interDyMFoam for mixer nu problem danny123 OpenFOAM Programming & Development 8 September 6, 2013 02:34
Transient simulation not converging skabilan OpenFOAM Running, Solving & CFD 12 September 17, 2007 17:48


All times are GMT -4. The time now is 16:42.