65 std::ifstream is(filename);
66 std::getline(is, fileContent,
'\0');
73 const auto equals = fileContent.find(
'=');
75 if (equals != std::string::npos)
98 commsDir_(
"<case>/comms"),
132 externalFileCoupler()
159 dict.readEntry(
"commsDir", commsDir_);
162 statusDone_ =
dict.getOrDefault<
word>(
"statusDone",
"done");
163 slaveFirst_ =
dict.getOrDefault(
"initByExternal",
false);
166 <<
" directory: " << commsDir_ <<
nl
167 <<
" slave-first: " <<
Switch(slaveFirst_) <<
endl;
170 waitInterval_ =
dict.getOrDefault(
"waitInterval", 1u);
179 log =
dict.getOrDefault(
"log",
false);
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();
224 const bool wasInit = initialized();
242 return waitForSlave();
270 if (prevTime < modTime)
281 sleep(waitInterval_);
286 int intAction(action);
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;
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Inter-processor communication reduction functions.
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
static const Enum< stopAtControls > stopAtControlNames
Names for stopAtControls.
stopAtControls
Stop-run control options, which are primarily used when altering the stopAt condition.
@ saUnknown
Dummy no-op. Do not change current value.
@ saEndTime
Stop when Time reaches prescribed endTime.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
@ broadcast
broadcast [MPI]
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
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...
Encapsulates the logic for coordinating between OpenFOAM and an external application.
enum Time::stopAtControls useSlave(const bool wait=false) const
Remove lock file to indicate that the external program is in charge.
@ SLAVE
The slave (external program) is in charge.
@ MASTER
The master (OpenFOAM) is in charge.
virtual void writeDataMaster() const
Write data files from master (OpenFOAM).
virtual void removeDataSlave() const
Remove data files written by slave (external program).
enum Time::stopAtControls useMaster(const bool wait=false) const
Create lock file to indicate that OpenFOAM is in charge.
virtual ~externalFileCoupler()
Destructor.
fileName lockFile() const
Return the file path to the lock file.
bool readDict(const dictionary &dict)
Read communication settings from dictionary.
static word lockName
Name of the lock file.
virtual void readDataSlave()
Read data files on slave (external program).
enum Time::stopAtControls waitForMaster() const
Wait for master to complete.
virtual void writeDataSlave() const
Write data files from slave (external program).
virtual void readDataMaster()
Read data files on master (OpenFOAM).
virtual void removeDataMaster() const
Remove data files written by master (OpenFOAM).
enum Time::stopAtControls waitForSlave() const
Wait for slave to complete.
void shutdown() const
Generate status=done in lock (only when run-state = master).
externalFileCoupler()
Construct using standard defaults.
bool initialized() const
True if state has been initialized.
A class for handling file names.
static bool clean(std::string &str)
Cleanup filename string, possibly applies other transformations such as changing the path separator e...
bool contains(char c) const noexcept
True if string contains given character (cf. C++23).
string & expand(const bool allowEmpty=false)
Inplace expand initial tags, tildes, and all occurrences of environment variables as per stringOps::e...
A class for handling words, derived from Foam::string.
static word validate(const std::string &s, const bool prefix=false)
Construct validated word (no invalid characters).
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
static enum Time::stopAtControls getStopAction(const std::string &filename)
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
messageStream Info
Information stream (stdout output on master, null elsewhere).
unsigned int sleep(const unsigned int sec)
Sleep for the specified number of seconds.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
dimensionedScalar log(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
errorManip< error > abort(error &err)
double highResLastModified(const fileName &, const bool followLink=true)
Return time of last file modification.
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
constexpr char nl
The newline '\n' character (0x0a).