Edit controlDict at runtime
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! |
RE:
Actually this does work..seems like there was some issue in decomposePar but the code works!
|
Trouble with editing controldict in parallel run
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! |
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. |
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) |
All times are GMT -4. The time now is 03:34. |