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

Edit controlDict at runtime

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 18, 2014, 13:50
Default Edit controlDict at runtime
  #1
New Member
 
Join Date: Sep 2013
Posts: 9
Rep Power: 12
menonshyam is on a distinguished road
Hello all,

I am trying to edit fields in the controlDict file during the course of my simulation. The code below works just fine if i run my application on a single core but if i use multiple cores through mpirun, I am unable to get the field to update. Any ideas on this!?

IOdictionary controlDict(IOobject("controlDict", runTime.system(),mesh,IOobject::MUST_READ,IOobject ::AUTO_WRITE));
controlDict.set("endTime",50);
controlDict.Foam::regIOobject::write();

Thanks!
menonshyam is offline   Reply With Quote

Old   June 18, 2014, 14:04
Default RE:
  #2
New Member
 
Join Date: Sep 2013
Posts: 9
Rep Power: 12
menonshyam is on a distinguished road
Actually this does work..seems like there was some issue in decomposePar but the code works!
menonshyam is offline   Reply With Quote

Old   July 15, 2014, 20:55
Default Trouble with editing controldict in parallel run
  #3
New Member
 
Join Date: Sep 2013
Posts: 9
Rep Power: 12
menonshyam is on a distinguished road
Hello,

So i am still having trouble getting a parallel run to stop based on a condition in the code by editing the control dict file. This is what i have right now:

If condition {
controlDict.set("stopAt","noWriteNow");
controlDict.Foam::regIOobject::write();
}

However when i decompose and run this code on multiple processors, in the processors where this condition is satisfied, a new 'system' folder is created with the updated controlDict as per the code. But the remaining processors and the job itself still appear to keep on running. How do i fix this so that the job ends on all the processors!?

Thanks!
menonshyam is offline   Reply With Quote

Old   July 16, 2014, 05:14
Default
  #4
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

it depends.

If you need to stop simulation when criterion is satisfied on every processor, then you can use reduce operation (http://foam.sourceforge.net/docs/cpp/a07342.html) with 'and' binary operation. So criterion is true only when it is true on every processor.

If you need to stop simulation when criterion is satisfied on any processor, then you can use scatter operation (http://foam.sourceforge.net/docs/cpp/a01997.html) to notify every processor that it's time to stop.
alexeym is offline   Reply With Quote

Old   February 15, 2021, 05:23
Default
  #5
Member
 
Tom Lauriks
Join Date: Apr 2020
Posts: 34
Rep Power: 5
Tom Lauriks is on a distinguished road
Hello, this is an old post, but I ran into the same issue (openfoam v6).

I've read another post on the forum on the same topic, where someone said that in parallel runs, it would be very complicated to update the controlDict from within openfoam. This is probably right, because I tried this and at a certain point, I'm pretty sure I got an error message stating that I was trying to modify the registry object controlDict, which is in fact declared as constant.

However, the controlDict can manually be modified during a parallel run without problems. So what I did was fall back on the basic c++ functionalities, and changed purgeWrite 3 to purgeWrite 0 directly in the file without going through OF functionalities, which indeed delivered the desired result.

I'm just starting with coding in c++, so this might not be the best way to do this, but below I will paste the code that achieved this:
Code:
if (currentTime > 20.0 && currentTime < 21.0)
    {
        Info << type() << name() << ": " 
                << "switch time detected" << nl << endl;

        string controlDict(obr_.time().rootPath()/obr_.time().globalCaseName() + "/system/controlDict"); 
    system("sed -i 's/purgeWrite 3/purgeWrite 0/g' " + controlDict);

     }
This if statement was placed in my function object, in the execute function. To my understanding, the system command allows you to execute bash commands from within a c++ program. Since it is very easy to paste strings together, as demonstrated in the construction of the string containing the path to the controldict and the sed command passed onto the linux bash, I presume this method can be quite versatile.
Tom Lauriks is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Probes/Sensors in runtime gabitinho OpenFOAM Post-Processing 9 August 14, 2015 13:55
Problem in3D model processing mebinitap OpenFOAM 2 December 12, 2014 05:40
Laptop for CFD - recommendation Far Hardware 20 May 31, 2012 18:01
writing controlDict as otherfields ubaid OpenFOAM 5 September 29, 2010 08:28
ParaView Compilation jakaranda OpenFOAM Installation 3 October 27, 2008 12:46


All times are GMT -4. The time now is 08:43.