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

Implementation of runTime-updated scalar

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

Like Tree2Likes
  • 2 Post By sebonator

Reply
 
LinkBack Thread Tools Display Modes
Old   January 12, 2011, 07:56
Default Implementation of runTime-updated scalar
  #1
Member
 
Sebastian Lang
Join Date: Aug 2009
Posts: 46
Rep Power: 7
sebonator is on a distinguished road
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
HakikiCanakkaleli and codder like this.
sebonator is offline   Reply With Quote

Old   January 12, 2011, 08:18
Default
  #2
Senior Member
 
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 14
l_r_mcglashan will become famous soon enough
Just a guess, but if you put "runTime.read();" above those lines does it work?
__________________
Laurence R. McGlashan :: Website
l_r_mcglashan is offline   Reply With Quote

Old   January 12, 2011, 09:49
Talking Problem solved!!!
  #3
Member
 
Sebastian Lang
Join Date: Aug 2009
Posts: 46
Rep Power: 7
sebonator is on a distinguished road
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
sebonator is offline   Reply With Quote

Old   January 12, 2011, 10:13
Default
  #4
Senior Member
 
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 14
l_r_mcglashan will become famous soon enough
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.
__________________
Laurence R. McGlashan :: Website
l_r_mcglashan is offline   Reply With Quote

Old   January 12, 2011, 17:29
Default
  #5
Member
 
Sebastian Lang
Join Date: Aug 2009
Posts: 46
Rep Power: 7
sebonator is on a distinguished road
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
sebonator is offline   Reply With Quote

Old   January 13, 2011, 06:02
Default
  #6
Senior Member
 
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 14
l_r_mcglashan will become famous soon enough
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.
__________________
Laurence R. McGlashan :: Website
l_r_mcglashan is offline   Reply With Quote

Old   January 13, 2011, 06:47
Default
  #7
Member
 
Sebastian Lang
Join Date: Aug 2009
Posts: 46
Rep Power: 7
sebonator is on a distinguished road
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
sebonator is offline   Reply With Quote

Reply

Tags
controldict, read from file, runtime, update

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
dieselFoam problem!! trying to introduce a new heat transfer model vivek070176 OpenFOAM Programming & Development 10 December 24, 2014 00:48
Solving for an additional species CO in coalChemistryFoam N. A. OpenFOAM Programming & Development 2 November 13, 2014 09:43
Specifying nonuniform boundary condition maka OpenFOAM Running, Solving & CFD 59 October 22, 2014 14:52
CFX12 rif errors romance CFX 4 October 26, 2009 14:41
solving passive scalar by user function in AVLFIRE huyp Main CFD Forum 0 September 4, 2008 10:21


All times are GMT -4. The time now is 01:00.