diff --git a/src/postProcessing/functionObjects/jobControl/externalCoupled/externalCoupledFunctionObject.C b/src/postProcessing/functionObjects/jobControl/externalCoupled/externalCoupledFunctionObject.C index 66f11a9038..392502b034 100644 --- a/src/postProcessing/functionObjects/jobControl/externalCoupled/externalCoupledFunctionObject.C +++ b/src/postProcessing/functionObjects/jobControl/externalCoupled/externalCoupledFunctionObject.C @@ -51,6 +51,23 @@ Foam::word Foam::externalCoupledFunctionObject::lockName = "OpenFOAM"; Foam::string Foam::externalCoupledFunctionObject::patchKey = "# Patch: "; +template<> +const char* Foam::NamedEnum +< + Foam::externalCoupledFunctionObject::stateEnd, + 2 +>::names[] = +{ + "remove", + "done" +}; + +const Foam::NamedEnum +< + Foam::externalCoupledFunctionObject::stateEnd, + 2 +> Foam::externalCoupledFunctionObject::stateEndNames_; + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -88,7 +105,7 @@ Foam::fileName Foam::externalCoupledFunctionObject::lockFile() const } -void Foam::externalCoupledFunctionObject::createLockFile() const +void Foam::externalCoupledFunctionObject::useMaster() const { if (!Pstream::master()) { @@ -104,13 +121,13 @@ void Foam::externalCoupledFunctionObject::createLockFile() const if (log_) Info<< type() << ": creating lock file" << endl; OFstream os(fName); - os << "lock file"; + os << "status=openfoam\n"; os.flush(); } } -void Foam::externalCoupledFunctionObject::removeLockFile() const +void Foam::externalCoupledFunctionObject::useSlave() const { if (!Pstream::master()) { @@ -119,7 +136,35 @@ void Foam::externalCoupledFunctionObject::removeLockFile() const if (log_) Info<< type() << ": removing lock file" << endl; - rm(lockFile()); + Foam::rm(lockFile()); +} + + +void Foam::externalCoupledFunctionObject::cleanup() const +{ + if (!Pstream::master()) + { + return; + } + + const fileName lck(lockFile()); + switch (stateEnd_) + { + case REMOVE: + { + if (log_) Info<< type() << ": removing lock file" << endl; + Foam::rm(lck); + } + break; + case DONE: + { + if (log_) Info<< type() << ": lock file status=done" << endl; + OFstream os(lck); + os << "status=done\n"; + os.flush(); + } + break; + } } @@ -189,30 +234,29 @@ void Foam::externalCoupledFunctionObject::removeWriteFiles() const } -void Foam::externalCoupledFunctionObject::wait() const +void Foam::externalCoupledFunctionObject::waitForSlave() const { const fileName fName(lockFile()); - label found = 0; label totalTime = 0; + bool found = false; if (log_) Info<< type() << ": beginning wait for lock file " << fName << nl; - while (found == 0) + while (!found) { if (Pstream::master()) { if (totalTime > timeOut_) { FatalErrorInFunction - << "Wait time exceeded time out time of " << timeOut_ + << "Wait time exceeded timeout of " << timeOut_ << " s" << abort(FatalError); } IFstream is(fName); - if (is.good()) { - found++; + found = true; if (log_) { @@ -232,7 +276,7 @@ void Foam::externalCoupledFunctionObject::wait() const } // prevent other procs from racing ahead - reduce(found, sumOp