Go to the documentation of this file.
63 std::string fileContent;
65 std::ifstream is(filename);
66 std::getline(is, fileContent,
'\0');
68 if (fileContent.find(
"done") != std::string::npos)
70 return Time::stopAtControls::saEndTime;
73 const auto equals = fileContent.find(
'=');
75 if (equals != std::string::npos)
83 Time::stopAtControls::saUnknown
87 return Time::stopAtControls::saUnknown;
98 commsDir_(
"<case>/comms"),
166 <<
" directory: " << commsDir_ <<
nl
167 <<
" slave-first: " <<
Switch(slaveFirst_) <<
endl;
188 const bool wasInit = initialized();
205 <<
": creating lock file with status=openfoam" <<
endl;
207 std::ofstream os(lck);
208 os <<
"status=openfoam\n";
214 return waitForMaster();
217 return Time::stopAtControls::saUnknown;
224 const bool wasInit = initialized();
242 return waitForSlave();
245 return Time::stopAtControls::saUnknown;
257 auto action = Time::stopAtControls::saUnknown;
270 if (prevTime < modTime)
277 action = Time::stopAtControls::saEndTime;
281 sleep(waitInterval_);
285 label intAction(action);
301 auto action = Time::stopAtControls::saUnknown;
306 unsigned totalTime = 0;
308 Log <<
type() <<
": waiting for lock file to appear " << lck <<
endl;
312 sleep(waitInterval_);
314 if (timeOut_ && (totalTime += waitInterval_) > timeOut_)
317 <<
"Wait time exceeded timeout of " << timeOut_
321 Log <<
type() <<
": wait time = " << totalTime <<
endl;
326 Log <<
type() <<
": found lock file " << lck <<
endl;
329 label intAction(action);
365 Log <<
type() <<
": lock file status=" << statusDone_ <<
endl;
367 std::ofstream os(lockFile());
368 os <<
"status=" << statusDone_ <<
nl;
virtual void writeDataSlave() const
Write data files from slave (external program)
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
A class for handling words, derived from Foam::string.
virtual void removeDataMaster() const
Remove data files written by master (OpenFOAM)
A class for handling file names.
virtual void writeDataMaster() const
Write data files from master (OpenFOAM)
enum Time::stopAtControls useMaster(const bool wait=false) const
Create lock file to indicate that OpenFOAM is in charge.
static word validate(const std::string &s, const bool prefix=false)
Construct validated word (no invalid characters).
static void scatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Distribute without modification. Reverse of gather.
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
Ostream & endl(Ostream &os)
Add newline and flush stream.
enum Time::stopAtControls waitForMaster() const
Wait for master to complete.
virtual void readDataMaster()
Read data files on master (OpenFOAM).
static const Enum< stopAtControls > stopAtControlNames
Names for stopAtControls.
static enum Time::stopAtControls getStopAction(const std::string &filename)
virtual void removeDataSlave() const
Remove data files written by slave (external program)
messageStream Info
Information stream (uses stdout - output is on the master only)
virtual ~externalFileCoupler()
Destructor.
virtual void readDataSlave()
Read data files on slave (external program).
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
double highResLastModified(const fileName &, const bool followLink=true)
Return time of last file modification.
static word lockName
Name of the lock file.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
dimensionedScalar log(const dimensionedScalar &ds)
errorManip< error > abort(error &err)
Inter-processor communication reduction functions.
static bool master(const label communicator=0)
Am I the master process.
enum Time::stopAtControls useSlave(const bool wait=false) const
Remove lock file to indicate that the external program is in charge.
Encapsulates the logic for coordinating between OpenFOAM and an external application.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
string & expand(const bool allowEmpty=false)
enum Time::stopAtControls waitForSlave() const
Wait for slave to complete.
void shutdown() const
Generate status=done in lock (only when run-state = master)
static bool clean(std::string &str)
Cleanup filename.
bool readDict(const dictionary &dict)
Read communication settings from dictionary.
externalFileCoupler()
Construct using standard defaults.
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
defineTypeNameAndDebug(combustionModel, 0)
unsigned int sleep(const unsigned int sec)
Sleep for the specified number of seconds.
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?