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/)
-   -   Implementation of runTime-updated scalar (http://www.cfd-online.com/Forums/openfoam-programming-development/83822-implementation-runtime-updated-scalar.html)

sebonator January 12, 2011 07:56

Implementation of runTime-updated scalar
 
Hi there!

I am writing a modified solver and had to add a new entry "steadyIterationSteps" to my controlDict. This constant should be updated every time step for my transient solver. The aim is, that the constant can be modified during runtime, like for example the value of "stopAt" in the controlDict.

I read the constant every time step (=> The "read"-command is located inside the "while (runTime.run())"-loop), but the value with which the solver works isn't updated! If I change the value before starting the solver, then it reads the value as I want it to, but a modification during runtime still is not possible! So my problem is, that the controlDict is read for the first time step, but not for the following time steps!

Maybe the operation of reading is not the problem, but at least the variable "iterationSteps" in my solver does not receive the new value properly!

I tried both of the following commands to read in the value:

Code:

scalar iterationSteps = runTime.controlDict().lookupOrDefault<scalar>("steadyIterationSteps", 500);
Code:

scalar iterationSteps(readScalar(runTime.controlDict().lookup("steadyIterationSteps")));
but no one of them is able to update the value of "iterationSteps" every time-step.

Could you give me a hint what is missing in my code or what I do wrong? I also tried to find out how the other entries in the controlDict are read in, but I didn't understand the codes and classes as they seem to be extremely nested at this point!

Thanks for every reply!
Greetings Sebastian

l_r_mcglashan January 12, 2011 08:18

Just a guess, but if you put "runTime.read();" above those lines does it work?

sebonator January 12, 2011 09:49

Problem solved!!!
 
Thanks Laurence!

Your idea solved the problem!

I did not know, that the whole controlDict is saved inside this "runTime"-variable. I thought the "runTime.controlDict()" just directs the commands I showed in my first post to find the controlDict inside the system-directory.

Well, this "runTime.read()" command was in fact missing in the solver I based my modified solver on, too! I am trying to modify the chtMultiRegionFoam-solver and copied my style to read in "iterationSteps"-variable from the original way to read in the maximum allowed diffusion number in chtMultiRegionFoam. After a test, I realized that a runtime-modification of that value is not possible in the original chtMultiRegionFoam, either.

But: maybe this has a physical reason which I don't know, so I don't want to blame the author of the original chtMultiregionFoam-solver.

Well, thanks to Lawrence again!
Greetings Sebastian

l_r_mcglashan January 12, 2011 10:13

runTime.readModifiedObjects() might be better.
Have a look at Foam::Time in doxygen:
http://foam.sourceforge.net/docs/cpp...am_1_1Time.php

If you think there's a bug then post it on the openfoam site.

sebonator January 12, 2011 17:29

Hi Lawrence,

thanks again for the post! At the moment I don't know if the "runTime.readModifiedObjects()" is better, because I can't really see from doxygen what it does. But "runTime.read()" works fine for me, thank you!

Can you really get information about what you need from doxygen? The only thing I can use it for is to look up unknown functions and hope that the description-text is detailed enough for me to understand! If there is no description text the only possibility that's left to me is to guess what the function does from it's input and output arguments.

I never got any information from looking at the method-definitions in the source code, because OpenFoam (and maybe other object-oriented programs, too) is coded in such a nested way that it is really hard to understand!

How do you search functions you need or look up what a function does, Lawrence?

Thanks in advance!
Greetings Sebastian

l_r_mcglashan January 13, 2011 06:02

I empathise with you a little. :). The Class references are very useful though! I found this on the OFwiki: How to use Doxygen with OF. A few points of mine would be:

Have a look at Foam::Time, which is the type of runTime. The inheritance diagram shows us that Time inherits (publically) from various other classes, objectRegistry being one. If you want to see what readModifiedObjects() does, click on the function name and it takes you down to the description. It tells you that it's been reimplemented from objectRegistry. You can click on line 192 and it takes you to the part of the source code that contains the implementation of readModifiedObjects(). Ignore the parallel bit for now and compare it to read(). You'll see that it calls objectRegistry::readModifiedObjects().

List of all members is also a useful link if you want to quickly see what ALL the functions that are available to the class are.

sebonator January 13, 2011 06:47

Hi Lawrence!

Thanks again for your explanations! The WIKI-page really describes the basics, this is very good for all beginners out there!

What helped me is especially your hint to the "List of all members"! I did not see that link all the time, because I was working in Doxygen when entered from www.openfoam.com and that page is not really nice to view as the typical openfoam.com header always limits your view.

I think I can use doxygen better from now on. Thanks a lot Lawrence! If you've still got other tips for ambitious OpenFOAM programmers ;-) then I would appreciate if you share them with me (our us ;-) )

Thanks a lot!
Greetings Sebastian


All times are GMT -4. The time now is 07:14.