diff --git a/src/postProcessing/functionObjects/jobControl/externalCoupled/externalCoupledFunctionObject.C b/src/postProcessing/functionObjects/jobControl/externalCoupled/externalCoupledFunctionObject.C index 66f11a9038..fcfc0bd855 100644 --- a/src/postProcessing/functionObjects/jobControl/externalCoupled/externalCoupledFunctionObject.C +++ b/src/postProcessing/functionObjects/jobControl/externalCoupled/externalCoupledFunctionObject.C @@ -49,7 +49,54 @@ namespace Foam Foam::word Foam::externalCoupledFunctionObject::lockName = "OpenFOAM"; -Foam::string Foam::externalCoupledFunctionObject::patchKey = "# Patch: "; +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_; + + +namespace Foam +{ +//! \cond fileScope +//- Write list content with size, bracket, content, bracket one-per-line. +// This makes for consistent for parsing, regardless of the list length. +template +static void writeList(Ostream& os, const string& header, const UList& L) +{ + // Header string + os << header.c_str() << nl; + + // Write size and start delimiter + os << L.size() << nl + << token::BEGIN_LIST; + + // Write contents + forAll(L, i) + { + os << nl << L[i]; + } + + // Write end delimiter + os << nl << token::END_LIST << nl << endl; +} +//! \endcond + +} +// namespace Foam // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -88,7 +135,7 @@ Foam::fileName Foam::externalCoupledFunctionObject::lockFile() const } -void Foam::externalCoupledFunctionObject::createLockFile() const +void Foam::externalCoupledFunctionObject::useMaster() const { if (!Pstream::master()) { @@ -104,13 +151,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 +166,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 +264,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 +306,7 @@ void Foam::externalCoupledFunctionObject::wait() const } // prevent other procs from racing ahead - reduce(found, sumOp