ENH: make external file coupling status= configurable (#1243)

This commit is contained in:
Mark Olesen
2019-03-21 17:26:16 +01:00
committed by Andrew Heather
parent a48dc227d4
commit ac646d48b7
3 changed files with 28 additions and 41 deletions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015-2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -93,7 +93,8 @@ static enum Time::stopAtControls getStopAction(const std::string& filename)
Foam::externalFileCoupler::externalFileCoupler() Foam::externalFileCoupler::externalFileCoupler()
: :
runState_(NONE), runState_(NONE),
commsDir_("$FOAM_CASE/comms"), commsDir_("<case>/comms"),
statusEnd_("done"),
waitInterval_(1u), waitInterval_(1u),
timeOut_(100u), timeOut_(100u),
slaveFirst_(false), slaveFirst_(false),
@ -108,6 +109,7 @@ Foam::externalFileCoupler::externalFileCoupler(const fileName& commsDir)
: :
runState_(NONE), runState_(NONE),
commsDir_(commsDir), commsDir_(commsDir),
statusEnd_("done"),
waitInterval_(1u), waitInterval_(1u),
timeOut_(100u), timeOut_(100u),
slaveFirst_(false), slaveFirst_(false),
@ -155,6 +157,7 @@ bool Foam::externalFileCoupler::readDict(const dictionary& dict)
dict.readEntry("commsDir", commsDir_); dict.readEntry("commsDir", commsDir_);
commsDir_.expand(); commsDir_.expand();
commsDir_.clean(); commsDir_.clean();
statusEnd_ = dict.lookupOrDefault<word>("shutdown", "done");
slaveFirst_ = dict.lookupOrDefault("initByExternal", false); slaveFirst_ = dict.lookupOrDefault("initByExternal", false);
Info<< type() << ": initialize" << nl Info<< type() << ": initialize" << nl
@ -188,7 +191,7 @@ Foam::externalFileCoupler::useMaster(const bool wait) const
if (!wasInit) if (!wasInit)
{ {
// First time // First time
Foam::mkDir(commsDir_); mkDir(commsDir_);
} }
const fileName lck(lockFile()); 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 // Create lock file - only if it doesn't already exist
if (!Foam::isFile(lck)) if (!Foam::isFile(lck))
{ {
Log << type() << ": creating lock file" << endl; Log << type()
<< ": creating lock file with status=openfoam" << endl;
std::ofstream os(lck); std::ofstream os(lck);
os << "status=openfoam\n"; os << "status=openfoam\n";
@ -223,7 +227,7 @@ Foam::externalFileCoupler::useSlave(const bool wait) const
if (!wasInit) if (!wasInit)
{ {
// First time // First time
Foam::mkDir(commsDir_); mkDir(commsDir_);
} }
Log << type() << ": removing lock file" << endl; Log << type() << ": removing lock file" << endl;
@ -356,10 +360,10 @@ void Foam::externalFileCoupler::shutdown() const
{ {
if (Pstream::master() && runState_ == MASTER && Foam::isDir(commsDir_)) 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()); std::ofstream os(lockFile());
os << "status=done\n"; os << "status=" << statusEnd_ << nl;
} }
runState_ = DONE; // Avoid re-triggering in destructor runState_ = DONE; // Avoid re-triggering in destructor

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015-2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -54,6 +54,7 @@ Description
waitInterval 1; waitInterval 1;
timeOut 100; timeOut 100;
initByExternal no; initByExternal no;
shutdown done;
} }
\endverbatim \endverbatim
@ -106,7 +107,7 @@ class externalFileCoupler
{ {
public: public:
// Public data types // Public Data Types
//- The run state (ie, who is currently in charge) //- The run state (ie, who is currently in charge)
enum runState enum runState
@ -117,10 +118,9 @@ public:
DONE //!< Finished DONE //!< Finished
}; };
private: private:
// Private data // Private Data
//- The current run (and initialization) state //- The current run (and initialization) state
mutable runState runState_; mutable runState runState_;
@ -128,6 +128,9 @@ private:
//- Local path to communications directory //- Local path to communications directory
fileName commsDir_; fileName commsDir_;
//- Value for "status=..." on termination
word statusEnd_;
//- Interval time between checking for return data [s] //- Interval time between checking for return data [s]
unsigned waitInterval_; unsigned waitInterval_;

View File

@ -88,7 +88,7 @@ Usage
log yes; log yes;
commsDir "<case>/comms"; commsDir "<case>/comms";
initByExternal yes; initByExternal yes;
stateEnd remove; // (remove | done) shutdown done; // Any arbitrary status=... value
regions regions
{ {
@ -104,7 +104,6 @@ Usage
} }
\endverbatim \endverbatim
This reads/writes (on the master processor) the directory: This reads/writes (on the master processor) the directory:
\verbatim \verbatim
comms/region0_region1/TPatchGroup/ comms/region0_region1/TPatchGroup/
@ -125,18 +124,17 @@ Usage
The entries comprise: The entries comprise:
\table \table
Property | Description | Required | Default value Property | Description | Required | Default
type | type name: externalCoupled | yes | type | Type name: externalCoupled | yes |
commsDir | communication directory | yes | commsDir | Communication directory | yes |
waitInterval | wait interval in (s) | no | 1 waitInterval | wait interval in (s) | no | 1
timeOut | timeout in (s) | no | 100*waitInterval timeOut | timeout in (s) | no | 100*waitInterval
stateEnd | Lockfile treatment on termination | no | done shutdown | Lockfile status=... on termination | no | done
initByExternal | initialization values supplied by external app | yes initByExternal | Initialization values supplied by external app | yes
calcFrequency | calculation frequency | no | 1 calcFrequency | Calculation frequency | no | 1
regions | the regions to couple | yes regions | The regions to couple | yes |
\endtable \endtable
SourceFiles SourceFiles
externalCoupled.C externalCoupled.C
externalCoupledTemplates.C externalCoupledTemplates.C
@ -151,8 +149,6 @@ SourceFiles
#include "DynamicList.H" #include "DynamicList.H"
#include "wordReList.H" #include "wordReList.H"
#include "scalarField.H" #include "scalarField.H"
#include "Enum.H"
#include "Switch.H"
#include "UPtrList.H" #include "UPtrList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -176,22 +172,6 @@ class externalCoupled
public functionObjects::timeFunctionObject, public functionObjects::timeFunctionObject,
public externalFileCoupler 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 // Private Member Data