ENH: respond to externalCoupled lock file contents

- waitForSlave now return a Time::stopAtControls enumeration:

    unknown:     when lockfile has no specially recognized content.
    endTime:     when lockfile contains "status=done"
    writeNow:    when lockfile contains "action=writeNow"
    nextWrite:   when lockfile contains "action=nextWrite"
    noWriteNow:  when lockfile contains "action=noWriteNow"

These values can be used by the caller to terminate the master
(OpenFOAM) as desired in response to information placed there by the
slave process.
This commit is contained in:
Mark Olesen
2017-11-28 12:02:18 +01:00
parent 402e605391
commit bb0fa65122
5 changed files with 185 additions and 92 deletions

View File

@ -460,6 +460,42 @@ void Foam::functionObjects::externalCoupled::initCoupling()
}
void Foam::functionObjects::externalCoupled::performCoupling()
{
// Ensure coupling has been initialised
initCoupling();
// Write data for external source
writeDataMaster();
// Signal external source to execute (by removing lock file)
// - Wait for slave to provide data
useSlave();
// Wait for response - and catch any abort information sent from slave
const auto action = waitForSlave();
// Remove old data files from OpenFOAM
removeDataMaster();
// Read data passed back from external source
readDataMaster();
// Signal external source to wait (by creating the lock file)
useMaster();
// Process any abort information sent from slave
if
(
action != time_.stopAt()
&& action != Time::stopAtControls::saUnknown
)
{
time_.stopAt(action);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::externalCoupled::externalCoupled
@ -483,46 +519,16 @@ Foam::functionObjects::externalCoupled::externalCoupled
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::externalCoupled::~externalCoupled()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::externalCoupled::execute()
{
if (!initialisedCoupling_ || time_.timeIndex() % calcFrequency_ == 0)
{
// Initialise the coupling
initCoupling();
// Write data for external source
writeDataMaster();
// Signal external source to execute (by removing lock file)
// - Wait for slave to provide data
useSlave();
// Wait for response
waitForSlave();
// Remove old data files from OpenFOAM
removeDataMaster();
// Read data passed back from external source
readDataMaster();
// Signal external source to wait (by creating the lock file)
useMaster();
return true;
}
else
{
return false;
performCoupling();
}
return false;
}

View File

@ -282,6 +282,9 @@ private:
static void checkOrder(const wordList& regionNames);
//- Perform the coupling with necessary initialization etc.
void performCoupling();
//- Disallow default bitwise copy constructor
externalCoupled(const externalCoupled&) = delete;
@ -313,7 +316,7 @@ public:
//- Destructor
virtual ~externalCoupled();
virtual ~externalCoupled() = default;
// Member Functions