|
[Sponsors] |
May 15, 2019, 03:51 |
How to lock the fvSolution file ?
|
#1 |
New Member
Aaron Pumnul
Join Date: May 2019
Posts: 9
Rep Power: 7 |
Hello,
I'm very new to OpenFoam but at this time I work with an older version of it (2.3), I'm sure though it won't affect my question. I would like to lock the fvSolution file because I have another process (created in python) which is writing to it causing it to be modified and then reread by OpenFoam again.(their access is not synchronized and I want to synchronize it) my ugly solution is to check explicitly when fvSolution is read: In regIOobjectRead.C to override Code:
bool Foam::regIOobject::read() void Foam::regIOobject::close() Code:
bool Foam::regIOobject::read() { if objPath == "fvSolution" { // lock the file to prevent it from being opened by other processes flock(fvSolution, LOCK_EX); ... } } void Foam::regIOobject::close() { ... flock(fvSolution, LOCK_UN); //unlock } fvSolution.H also inherits from regIOobject.C so I could override Code:
bool Foam::regIOobject::read() {//put lock and then call regIOobject::read()} void Foam::regIOobject::close() {//release lock} I received no output from these 2 methods. (is fvSolution.H used at all ?) So how can I prevent an external process from writing to fvSolution when it's being read ? I don't understand why changing fvSolution.H produces no output. Last edited by aaron99; May 16, 2019 at 07:07. |
|
May 15, 2019, 09:25 |
|
#2 |
Senior Member
|
Hi,
It is not quite clear what you want to achieve. - Prohibit modification of fvSolution file? - Ignore modifications of fvSolution file made by another process? |
|
May 15, 2019, 11:46 |
|
#3 |
New Member
Aaron Pumnul
Join Date: May 2019
Posts: 9
Rep Power: 7 |
Hello Alexey,
when fvSolution file is being read by OpenFoam(call it p1), I want to put a lock on it, such that other external process (call it p2) can't open the file (nor to read or write to it), that is p2 must wait for p1 to finish its job(aka close the stream) and only then p2 will proceed to do with fvSolution whatever p2 intends to. With other words I want to give p1 exclusive rights to the file, so other processes will wait on p1 to finish its reading/writing and only then will other processes proceed to the fvSolution file. Thank you! |
|
May 16, 2019, 11:43 |
|
#4 |
Senior Member
|
Hi,
Could you elaborate on how you have overridden read method in fvSolution class? For example, I have done the following: 1. Added to fvSolution.H Code:
virtual bool read(); 2. Created fvSolution.C with the following code: Code:
#include "fvSolution.H" bool Foam::fvSolution::read() { Info << "Enter fvSolution::read()" << endl; solution::read(); Info << "Exit fvSolution::read()" << endl; return true; } 4. Recompiled OpenFOAM. Started simulation, modified fvSolution file and saw: Code:
... DILUPBiCGStab: Solving for k, Initial residual = 4.31815290661e-05, Final residual = 1.53001780603e-13, No Iterations 1 ExecutionTime = 58.26 s ClockTime = 59 s regIOobject::readIfModified() : Re-reading object fvSolution from file ".../system/fvSolution" Enter fvSolution::read() Exit fvSolution::read() fieldAverage averages write: Calculating averages Courant Number mean: 0.00120237595803 max: 0.00120238118572 deltaT = 1.72796544044e-06 Time = 4.36792704089e-06 PIMPLE: Iteration 1 DILUPBiCGStab: Solving for Ux, Initial residual = 0.00128745430922, Final residual = 6.81778088848e-12, No Iterations 1 ... Though, I tested it on OpenFOAM-6 (compilation of 2.3.x with gcc-8 is rather unpleasant experience). Last edited by alexeym; May 16, 2019 at 11:44. Reason: Forgotten step |
|
May 17, 2019, 08:33 |
|
#5 |
New Member
Aaron Pumnul
Join Date: May 2019
Posts: 9
Rep Power: 7 |
Thanks for the repply.
the code you provided works fine but only in the case if fvSolution was modified, this triggers the Foam::fvSolution::read() method which you overrode. (it is fine for the purpose) But I thought that Foam::fvSolution::read() would be called also for the first time when fvSolution is read, but it's not. So I would prefer to put a lock as well when fvSolution file is being read for the first time, can I achieve that without checking explicitly in regIOobjectRead.C ? |
|
May 17, 2019, 11:44 |
|
#6 |
Senior Member
|
Hi,
During construction of fvSolution class solution::read method is called (from solution constructor). So, you can either modify constructor of solution class (so it locks file), or you can try to modify fvSolution. In case of solution class modification, you can add bool parameter to constructor with default false value. In fvSolution constructor you set this parameter to true. Locking/unlocking should be added to solution's read method. In case of fvSolution modification, it is a little bit more complicated. Currently fvSolution is a child of the above mentioned solution, make it a child of fileLocker and solution. fileLocker is a class, which locks a file. To the fileLocker constructor you pass objectRegistry and file name, object constructs full path and lock the file. unlock method of fileLocker releases lock, created during construction. So, after the modification, constructor of fvSolution will look like: Code:
fvSolution(const objectRegistry& obr) : fileLocker(obr, "fvSolution"), solution(obr, "fvSolution") { unlock(); } Last edited by alexeym; May 17, 2019 at 11:45. Reason: Typo |
|
Tags |
solution control |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
how to calculate mass flow rate on patches and summation of that during the run? | immortality | OpenFOAM Post-Processing | 104 | February 16, 2021 08:46 |
OpenFoam "Permission denied" and "command not found" problems. | iyidaniel@yahoo.co.uk | OpenFOAM Running, Solving & CFD | 11 | January 2, 2018 06:47 |
[foam-extend.org] problem when installing foam-extend-1.6 | Thomas pan | OpenFOAM Installation | 7 | September 9, 2015 21:53 |
"parabolicVelocity" in OpenFoam 2.1.0 ? | sawyer86 | OpenFOAM Running, Solving & CFD | 21 | February 7, 2012 11:44 |
ParaView Compilation | jakaranda | OpenFOAM Installation | 3 | October 27, 2008 11:46 |