Encapsulates the logic for coordinating between OpenFOAM and an external application. More...
Public Types | |
enum | runState { NONE, MASTER, SLAVE, DONE } |
Public Member Functions | |
TypeName ("externalFileCoupler") | |
externalFileCoupler () | |
externalFileCoupler (const fileName &commsDir) | |
externalFileCoupler (const dictionary &dict) | |
virtual | ~externalFileCoupler () |
bool | initialized () const |
bool | slaveFirst () const |
const fileName & | commDirectory () const |
fileName | resolveFile (const word &file) const |
fileName | lockFile () const |
bool | readDict (const dictionary &dict) |
enum Time::stopAtControls | useMaster (const bool wait=false) const |
enum Time::stopAtControls | useSlave (const bool wait=false) const |
enum Time::stopAtControls | waitForMaster () const |
enum Time::stopAtControls | waitForSlave () const |
virtual void | readDataMaster () |
virtual void | readDataSlave () |
virtual void | writeDataMaster () const |
virtual void | writeDataSlave () const |
virtual void | removeDataMaster () const |
virtual void | removeDataSlave () const |
void | shutdown () const |
void | removeDirectory () const |
Static Public Attributes | |
static word | lockName = "OpenFOAM" |
Encapsulates the logic for coordinating between OpenFOAM and an external application.
This class provides a simple interface for explicit coupling with an external application using plain text files located in the user-specified communications directory. These files are to be read/written on the master processor only.
The explicit coupling follows a master/slave model in which OpenFOAM is the 'master' and the external application is the 'slave'. The readiness to exchange information in either direction is handled by a lock file (ie, OpenFOAM.lock). If the lock file is present, the slave (external application) should wait for the master (OpenFOAM) to complete.
When the master is finished its tasks and has prepared data for the slave, the lock file is removed, instructing the external source to take control of the program execution.
When the slave has completed its tasks, it will reinstate the lock file.
Example of the communication specification:
communication { commsDir "<case>/comms"; waitInterval 1; timeOut 100; initByExternal no; statusDone done; }
A typical coupling loop would look like this (on the master-side):
initialize - master takes control writeDataMaster() - write data for slave useSlave() waitForSlave() removeDataMaster() - cleanup old data from master [optional?] readDataMaster() - read data from slave useMaster()
On the slave-side:
waitForMaster() readDataSlave() - read data from master writeDataSlave() - write data for master useMaster()
Note that since the waitForSlave() method not only waits for the lock file to be reinstated but also does a simple check of its contents, it can also serve to communicate some control from the slave to the master.
Definition at line 103 of file externalFileCoupler.H.
enum runState |
Enumerator | |
---|---|
NONE | Not initialized. |
MASTER | The master (OpenFOAM) is in charge. |
SLAVE | The slave (external program) is in charge. |
DONE | Finished. |
Definition at line 110 of file externalFileCoupler.H.
Definition at line 88 of file externalFileCoupler.C.
References fileName::clean(), and string::expand().
externalFileCoupler | ( | const fileName & | commsDir | ) |
Definition at line 103 of file externalFileCoupler.C.
References fileName::clean(), string::expand(), UPstream::master(), and Foam::mkDir().
externalFileCoupler | ( | const dictionary & | dict | ) |
Definition at line 123 of file externalFileCoupler.C.
References dict, UPstream::master(), Foam::mkDir(), and externalFileCoupler::readDict().
|
virtual |
Definition at line 138 of file externalFileCoupler.C.
TypeName | ( | "externalFileCoupler" | ) |
|
inline |
Definition at line 23 of file externalFileCouplerI.H.
References externalFileCoupler::NONE.
|
inline |
Definition at line 29 of file externalFileCouplerI.H.
|
inline |
Definition at line 35 of file externalFileCouplerI.H.
|
inline |
Definition at line 42 of file externalFileCouplerI.H.
|
inline |
Definition at line 50 of file externalFileCouplerI.H.
bool readDict | ( | const dictionary & | dict | ) |
Definition at line 146 of file externalFileCoupler.C.
References dict, Foam::endl(), dictionary::getOrDefault(), Foam::Info, Foam::log(), Foam::nl, dictionary::readEntry(), and Foam::type().
Referenced by externalFileCoupler::externalFileCoupler(), and externalCoupled::read().
enum Foam::Time::stopAtControls useMaster | ( | const bool | wait = false | ) | const |
Definition at line 179 of file externalFileCoupler.C.
References Foam::endl(), Foam::isFile(), Log, UPstream::master(), Foam::mkDir(), os(), and Foam::type().
enum Foam::Time::stopAtControls useSlave | ( | const bool | wait = false | ) | const |
Definition at line 215 of file externalFileCoupler.C.
References Foam::endl(), Log, UPstream::master(), Foam::mkDir(), Foam::rm(), and Foam::type().
enum Foam::Time::stopAtControls waitForMaster | ( | ) | const |
Definition at line 243 of file externalFileCoupler.C.
References Foam::getStopAction(), Foam::highResLastModified(), UPstream::master(), Pstream::scatter(), and Foam::sleep().
enum Foam::Time::stopAtControls waitForSlave | ( | ) | const |
Definition at line 287 of file externalFileCoupler.C.
References Foam::abort(), Foam::endl(), Foam::FatalError, FatalErrorInFunction, Foam::getStopAction(), Foam::isFile(), Log, UPstream::master(), Pstream::scatter(), Foam::sleep(), and Foam::type().
|
virtual |
Reimplemented in externalCoupled.
Definition at line 330 of file externalFileCoupler.C.
|
virtual |
Definition at line 334 of file externalFileCoupler.C.
|
virtual |
Reimplemented in externalCoupled.
Definition at line 338 of file externalFileCoupler.C.
|
virtual |
Definition at line 342 of file externalFileCoupler.C.
|
virtual |
Reimplemented in externalCoupled.
Definition at line 346 of file externalFileCoupler.C.
|
virtual |
Reimplemented in externalCoupled.
Definition at line 350 of file externalFileCoupler.C.
void shutdown | ( | ) | const |
Definition at line 354 of file externalFileCoupler.C.
References Foam::endl(), Foam::isDir(), Log, UPstream::master(), Foam::nl, os(), and Foam::type().
void removeDirectory | ( | ) | const |
|
static |
Definition at line 162 of file externalFileCoupler.H.
Copyright © 2011-2018 OpenFOAM | OPENFOAM® is a registered trademark of OpenCFD Ltd.