mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: make external file coupling status= configurable (#1243)
This commit is contained in:
committed by
Andrew Heather
parent
a48dc227d4
commit
ac646d48b7
@ -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
|
||||
|
||||
@ -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_;
|
||||
|
||||
|
||||
@ -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 |
|
||||
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
|
||||
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
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user