From 19b5952c35989e8bde15dba643f231ddbb233149 Mon Sep 17 00:00:00 2001 From: mark Date: Tue, 25 Oct 2016 15:43:27 +0200 Subject: [PATCH] ENH: enable 'status=done' when finishing an externalCoupled FO - This provides a mechanism for the external code to detect when OpenFOAM is done. - Adjust tutorial to use the mechanism. Also test in parallel. --- .../externalCoupledFunctionObject.C | 104 ++++++++++++++---- .../externalCoupledFunctionObject.H | 40 ++++++- .../externalCoupledMultiRegionHeater/Allrun | 6 + .../Allrun.pre | 2 +- .../externalSolver | 38 +++++-- .../system/controlDict | 38 +------ .../system/externalCoupled | 43 ++++++++ 7 files changed, 195 insertions(+), 76 deletions(-) create mode 100644 tutorials/heatTransfer/chtMultiRegionFoam/externalCoupledMultiRegionHeater/system/externalCoupled 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