|
[Sponsors] |
June 18, 2014, 13:50 |
Edit controlDict at runtime
|
#1 |
New Member
Join Date: Sep 2013
Posts: 9
Rep Power: 13 |
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! |
|
June 18, 2014, 14:04 |
RE:
|
#2 |
New Member
Join Date: Sep 2013
Posts: 9
Rep Power: 13 |
Actually this does work..seems like there was some issue in decomposePar but the code works!
|
|
July 15, 2014, 20:55 |
Trouble with editing controldict in parallel run
|
#3 |
New Member
Join Date: Sep 2013
Posts: 9
Rep Power: 13 |
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! |
|
July 16, 2014, 05:14 |
|
#4 |
Senior Member
|
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. |
|
February 15, 2021, 05:23 |
|
#5 |
Member
Tom Lauriks
Join Date: Apr 2020
Posts: 34
Rep Power: 6 |
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); } |
|
|
|
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 |