CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   reRead Dict after changed (http://www.cfd-online.com/Forums/openfoam-programming-development/101695-reread-dict-after-changed.html)

wernsen May 11, 2012 03:23

[solved] reRead Dict after changed
 
Hello coders,

this is my first thread in the coding forum since I've just started to get used to the "OF language". The code I wrote works quite good so far.

I was wondering how I can tell my code to reread my new created dict if its changed during the run. I tried to change somthing but OF does not recocnize it.

Code:

       
IOdictionary postProperties
        (
            IOobject
            (
                    "myDict",        // Name
                    runTime.constant(),    // liegt im "constant" Ordner
                    mesh,                  // registry for the dict
                    IOobject::MUST_READ,    // muss vorhanden sein, sonst fehler
                    IOobject::NO_WRITE      // nur lesen, nicht schreiben
            )
        );

What do I have to change in order to get the same behaviour e.g. controlDict. If I change this Dict OF notice it during the run and acts on this.

chears
MARTIN

niklas May 11, 2012 03:44

IOobject::MUST_READ_IF_MODIFIED

wernsen May 11, 2012 04:28

Thank you!

I think we should change than http://openfoamwiki.net/index.php/In...IOobject_class

niklas May 11, 2012 04:43

The MUST_READ_IF_MODIFIED was added after the wiki was written.
But that is the advantage of wiki's. You can make your own addition and correct mistakes
if you want to.

wernsen May 11, 2012 05:00

yes thats right.

One question remains. I tried to change the dict and it is noticed by OF, but the variables remained the same. I think I have to add my script some how a function which is triggered by the dict change to refresh my variables with the new chaned dict.

How could I do it or is there maybe a code where I can have a look how this will be done?

niklas May 11, 2012 06:19

Im going to assume that you have written your program in such a way that it is assumed that
your variable will never change, i.e. your readScalar statement is placed right after the dictionary.

scalar value(readScalar(Dict.lookup("value")));

Once this is read, value is set. It doesnt matter if you changed it in the dictionary.
The only thing that will happen is that your dictionary changed, but you never read it again.

If you instead place the readScalar-statement where you are using it, i.e. in the loop (probably), it will work.

This only makes sense if you have used the MUST_READ_IF_MODIFIED option,
if you used MUST_READ, it made sense to place the readScalar statement right after the dictionary,
cause the dictionary was only read once (even if changed), so reading(lookup) it over and over is pointless.

Ralph M November 17, 2012 08:08

Hello guys,

This was just the topic that I was looking for. I tried to reposition the read-statement directly in the loop but with no effect. Are there other options to work around this problem?

Thanks!

Ralph

niklas November 19, 2012 02:48

Quote:

Originally Posted by Ralph M (Post 392681)
Hello guys,
This was just the topic that I was looking for. I tried to reposition the read-statement directly in the loop but with no effect. Are there other options to work around this problem?

What does it say in system/controlDict for this

runTimeModifiable no;

it should read yes.

Ralph M November 19, 2012 06:07

Dear Niklas,
I already checked that option in the controlDict; it was on yes indeed but didn't yielded the desired result.

I worked around by defining extra input parameters directly in the solver. Works fine for the moment, altough rereading the dictionairy would be more elegant!
Cheers,
Ralph

niklas November 19, 2012 07:04

can you post the code

Ralph M November 19, 2012 07:37

Not from this computer but I'm reading two variables from the dictionairy and then use an if-statement in the solver to chose one of the two variables.


All times are GMT -4. The time now is 05:32.