63 std::string fileContent;
65 std::ifstream is(filename);
66 std::getline(is, fileContent,
'\0');
68 if (fileContent.find(
"done") != std::string::npos)
73 const auto equals = fileContent.find(
'=');
75 if (equals != std::string::npos)
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();
224 const bool wasInit = initialized();
242 return waitForSlave();
270 if (prevTime < modTime)
281 sleep(waitInterval_);
285 label intAction(action);
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;
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Inter-processor communication reduction functions.
EnumType lookup(const word &enumName, const EnumType deflt) const
The enumeration corresponding to the given name.
static void scatter(const List< commsStruct > &comms, T &value, const int tag, const label comm)
Broadcast data: Distribute without modification.
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.
@ saUnknown
Dummy no-op. Do not change current value.
@ saEndTime
Stop when Time reaches prescribed endTime.
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
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
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.
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.
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.
A class for handling file names.
static bool clean(std::string &str)
virtual void validate()
Validate the turbulence fields after construction.
splitCell * master() const
string & expand(const bool allowEmpty=false)
A class for handling words, derived from Foam::string.
#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?
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)