65 std::ifstream is(filename);
66 std::getline(is, fileContent,
'\0');
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"),
132 externalFileCoupler()
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;
261 const fileName lck(lockFile());
270 if (prevTime < modTime)
277 action = Time::stopAtControls::saEndTime;
281 sleep(waitInterval_);
286 int intAction(action);
301 auto action = Time::stopAtControls::saUnknown;
305 const fileName lck(lockFile());
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;
330 int intAction(action);
365 Log <<
type() <<
": lock file status=" << statusDone_ <<
endl;
367 std::ofstream
os(lockFile());
368 os <<
"status=" << statusDone_ <<
nl;
static word validate(const std::string &s, const bool prefix=false)
Construct validated word (no invalid characters).
enum Time::stopAtControls waitForMaster() const
Wait for master to complete.
virtual ~externalFileCoupler()
Destructor.
enum Time::stopAtControls waitForSlave() const
Wait for slave to complete.
A class for handling file names.
Inter-processor communication reduction functions.
enum Time::stopAtControls useSlave(const bool wait=false) const
Remove lock file to indicate that the external program is in charge.
dimensionedScalar log(const dimensionedScalar &ds)
bool contains(char c) const noexcept
True if string contains given character (cf. C++23)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
constexpr char nl
The newline '\n' character (0x0a)
Ostream & endl(Ostream &os)
Add newline and flush stream.
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, any/none. Also accepts 0/1 as a string and shortcuts t/f, y/n.
static const Enum< stopAtControls > stopAtControlNames
Names for stopAtControls.
virtual void readDataMaster()
Read data files on master (OpenFOAM).
static void broadcast(Type &value, const label comm=UPstream::worldComm)
Broadcast content (contiguous or non-contiguous) to all communicator ranks. Does nothing in non-paral...
void shutdown() const
Generate status=done in lock (only when run-state = master)
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, IOobjectOption::readOption readOpt=IOobjectOption::MUST_READ) const
Find entry and assign to T val. FatalIOError if it is found and the number of tokens is incorrect...
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
virtual void removeDataMaster() const
Remove data files written by master (OpenFOAM)
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
A class for handling words, derived from Foam::string.
enum Time::stopAtControls useMaster(const bool wait=false) const
Create lock file to indicate that OpenFOAM is in charge.
static word lockName
Name of the lock file.
errorManip< error > abort(error &err)
externalFileCoupler()
Construct using standard defaults.
static enum Time::stopAtControls getStopAction(const std::string &filename)
bool readDict(const dictionary &dict)
Read communication settings from dictionary.
unsigned int sleep(const unsigned int sec)
Sleep for the specified number of seconds.
OBJstream os(runTime.globalPath()/outputName)
virtual void writeDataMaster() const
Write data files from master (OpenFOAM)
defineTypeNameAndDebug(combustionModel, 0)
static bool clean(std::string &str)
Cleanup filename string, possibly applies other transformations such as changing the path separator e...
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
string & expand(const bool allowEmpty=false)
Inplace expand initial tags, tildes, and all occurrences of environment variables as per stringOps::e...
virtual void readDataSlave()
Read data files on slave (external program).
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
messageStream Info
Information stream (stdout output on master, null elsewhere)
virtual void removeDataSlave() const
Remove data files written by slave (external program)
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
stopAtControls
Stop-run control options, which are primarily used when altering the stopAt condition.
EnumType lookup(const word &enumName, const EnumType deflt) const
The enumeration corresponding to the given name.
double highResLastModified(const fileName &, const bool followLink=true)
Return time of last file modification.
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
virtual void writeDataSlave() const
Write data files from slave (external program)