diff --git a/src/finiteVolume/cfdTools/general/coupling/externalFileCoupler.C b/src/finiteVolume/cfdTools/general/coupling/externalFileCoupler.C index bb17b4cf8a9e5b4eb8f11e0abac6c0e8bdebbe72..5ac87200e71c6d4051ee8616784c77fa2187fb69 100644 --- a/src/finiteVolume/cfdTools/general/coupling/externalFileCoupler.C +++ b/src/finiteVolume/cfdTools/general/coupling/externalFileCoupler.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2015-2017 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -93,7 +93,8 @@ static enum Time::stopAtControls getStopAction(const std::string& filename) Foam::externalFileCoupler::externalFileCoupler() : runState_(NONE), - commsDir_("$FOAM_CASE/comms"), + commsDir_("<case>/comms"), + statusEnd_("done"), waitInterval_(1u), timeOut_(100u), slaveFirst_(false), @@ -108,6 +109,7 @@ Foam::externalFileCoupler::externalFileCoupler(const fileName& commsDir) : runState_(NONE), commsDir_(commsDir), + statusEnd_("done"), waitInterval_(1u), timeOut_(100u), slaveFirst_(false), @@ -155,6 +157,7 @@ bool Foam::externalFileCoupler::readDict(const dictionary& dict) dict.readEntry("commsDir", commsDir_); commsDir_.expand(); commsDir_.clean(); + statusEnd_ = dict.lookupOrDefault<word>("shutdown", "done"); slaveFirst_ = dict.lookupOrDefault("initByExternal", false); Info<< type() << ": initialize" << nl @@ -188,7 +191,7 @@ Foam::externalFileCoupler::useMaster(const bool wait) const if (!wasInit) { // First time - Foam::mkDir(commsDir_); + mkDir(commsDir_); } const fileName lck(lockFile()); @@ -196,7 +199,8 @@ Foam::externalFileCoupler::useMaster(const bool wait) const // Create lock file - only if it doesn't already exist if (!Foam::isFile(lck)) { - Log << type() << ": creating lock file" << endl; + Log << type() + << ": creating lock file with status=openfoam" << endl; std::ofstream os(lck); os << "status=openfoam\n"; @@ -223,7 +227,7 @@ Foam::externalFileCoupler::useSlave(const bool wait) const if (!wasInit) { // First time - Foam::mkDir(commsDir_); + mkDir(commsDir_); } Log << type() << ": removing lock file" << endl; @@ -356,10 +360,10 @@ void Foam::externalFileCoupler::shutdown() const { if (Pstream::master() && runState_ == MASTER && Foam::isDir(commsDir_)) { - Log << type() << ": lock file status=done" << endl; + Log << type() << ": lock file status=" << statusEnd_ << endl; std::ofstream os(lockFile()); - os << "status=done\n"; + os << "status=" << statusEnd_ << nl; } runState_ = DONE; // Avoid re-triggering in destructor diff --git a/src/finiteVolume/cfdTools/general/coupling/externalFileCoupler.H b/src/finiteVolume/cfdTools/general/coupling/externalFileCoupler.H index b0aab9c3474502dd714f3e7080b0767a05e67e91..a242cdb9531e7b29eb9c7c3b15d396b5be25e34d 100644 --- a/src/finiteVolume/cfdTools/general/coupling/externalFileCoupler.H +++ b/src/finiteVolume/cfdTools/general/coupling/externalFileCoupler.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2015-2017 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -54,6 +54,7 @@ Description waitInterval 1; timeOut 100; initByExternal no; + shutdown done; } \endverbatim @@ -106,7 +107,7 @@ class externalFileCoupler { public: - // Public data types + // Public Data Types //- The run state (ie, who is currently in charge) enum runState @@ -117,10 +118,9 @@ public: DONE //!< Finished }; - private: - // Private data + // Private Data //- The current run (and initialization) state mutable runState runState_; @@ -128,6 +128,9 @@ private: //- Local path to communications directory fileName commsDir_; + //- Value for "status=..." on termination + word statusEnd_; + //- Interval time between checking for return data [s] unsigned waitInterval_; diff --git a/src/functionObjects/field/externalCoupled/externalCoupled.H b/src/functionObjects/field/externalCoupled/externalCoupled.H index 331a9f0795eb2a81da4daf9f70a3a001bab18eea..98d4d0ef58943ba5e61f4fe0c1c34b246230fa87 100644 --- a/src/functionObjects/field/externalCoupled/externalCoupled.H +++ b/src/functionObjects/field/externalCoupled/externalCoupled.H @@ -88,7 +88,7 @@ Usage log yes; commsDir "<case>/comms"; initByExternal yes; - stateEnd remove; // (remove | done) + shutdown done; // Any arbitrary status=... value regions { @@ -104,7 +104,6 @@ Usage } \endverbatim - This reads/writes (on the master processor) the directory: \verbatim comms/region0_region1/TPatchGroup/ @@ -125,18 +124,17 @@ Usage The entries comprise: \table - Property | Description | Required | Default value - type | type name: externalCoupled | yes | - commsDir | communication directory | yes | - waitInterval | wait interval in (s) | no | 1 - timeOut | timeout in (s) | no | 100*waitInterval - stateEnd | Lockfile treatment on termination | no | done - initByExternal | initialization values supplied by external app | yes - calcFrequency | calculation frequency | no | 1 - regions | the regions to couple | yes + Property | Description | Required | Default + type | Type name: externalCoupled | yes | + commsDir | Communication directory | yes | + waitInterval | wait interval in (s) | no | 1 + timeOut | timeout in (s) | no | 100*waitInterval + shutdown | Lockfile status=... on termination | no | done + initByExternal | Initialization values supplied by external app | yes + calcFrequency | Calculation frequency | no | 1 + regions | The regions to couple | yes | \endtable - SourceFiles externalCoupled.C externalCoupledTemplates.C @@ -151,8 +149,6 @@ SourceFiles #include "DynamicList.H" #include "wordReList.H" #include "scalarField.H" -#include "Enum.H" -#include "Switch.H" #include "UPtrList.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -176,22 +172,6 @@ class externalCoupled public functionObjects::timeFunctionObject, public externalFileCoupler { -public: - - // Public data types - - //- Lockfile state on termination - enum stateEnd - { - REMOVE, //!< Remove lock file on end - DONE, //!< Lock file contains status=done on end - IGNORE //!< Internal use only (for handling cleanup). - }; - -private: - - //- State end names (NB, only selectable values itemized) - static const Enum<stateEnd> stateEndNames_; // Private Member Data