Go to the documentation of this file.
64 { fileOperation::NOTFOUND,
"notFound" },
65 { fileOperation::ABSOLUTE,
"absolute" },
66 { fileOperation::OBJECT,
"objectPath" },
67 { fileOperation::WRITEOBJECT,
"writeObject" },
68 { fileOperation::PROCUNCOLLATED,
"uncollatedProc" },
69 { fileOperation::PROCBASEOBJECT,
"globalProc" },
70 { fileOperation::PROCOBJECT,
"localProc" },
71 { fileOperation::PARENTOBJECT,
"parentObjectPath" },
72 { fileOperation::FINDINSTANCE,
"findInstance" },
73 { fileOperation::PROCUNCOLLATEDINSTANCE,
"uncollatedProcInstance" },
74 { fileOperation::PROCBASEINSTANCE,
"globalProcInstance" },
75 { fileOperation::PROCINSTANCE,
"localProcInstance" }
109 static bool parseProcsNumRange
111 const std::string str,
116 const char * nptr = str.c_str();
117 char *endptr =
nullptr;
121 intmax_t parsed = std::strtoimax(nptr, &endptr, 10);
122 if (errno || nptr == endptr)
return false;
124 const int nProcs = int(parsed);
134 if (*endptr !=
'_')
return false;
140 parsed = std::strtoimax(nptr, &endptr, 10);
141 if (errno || nptr == endptr)
return false;
143 const int firstProc = int(parsed);
146 if (*endptr !=
'-')
return false;
152 parsed = std::strtoimax(nptr, &endptr, 10);
153 if (errno || nptr == endptr)
return false;
155 const int lastProc = int(parsed);
165 && (nProcs >= 0 && firstProc >= 0 && firstProc <= lastProc)
171 group.reset(firstProc, lastProc-firstProc+1);
188 const word& constantName
192 bool haveConstant =
false;
194 if (!constantName.empty())
196 for (
const fileName& dirName : dirEntries)
198 if (dirName == constantName)
211 times[nTimes].value() = 0;
212 times[nTimes].name() = constantName;
217 for (
const fileName& dirName : dirEntries)
219 if (readScalar(dirName, times[nTimes].value()))
221 times[nTimes].name() = dirName;
266 const word& constantName,
270 if (extraTimes.size())
272 const bool haveConstant =
275 && times[0].name() == constantName
278 const bool haveExtraConstant =
281 && extraTimes[0].name() == constantName
285 instantList combinedTimes(times.size()+extraTimes.size());
288 if (haveExtraConstant)
293 combinedTimes[sz++] = extraTimes[0];
298 combinedTimes[sz++] = times[i];
300 for (; extrai < extraTimes.size(); extrai++)
302 combinedTimes[sz++] = extraTimes[extrai];
308 if (times.size() > 1)
311 if (times[0].
name() == constantName)
318 label newi = starti+1;
319 for (label i = newi; i < times.size(); i++)
321 if (times[i].value() != times[i-1].value())
325 times[newi] = times[i];
358 splitProcessorPath(fName,
path, pDir, local,
group, numProcs);
364 const auto iter = procsDirs_.cfind(procPath);
380 const bool readDirMasterOnly
400 <<
"readDir on master: send " << dirEntries.size()
401 <<
" names to sub-processes" <<
endl;
413 Pout<<
"readDir without special master/send treatment"
417 dirEntries =
readDir(
path, fileName::Type::DIRECTORY);
426 for (
const fileName& dirN : dirEntries)
431 const label readProci =
432 splitProcessorPath(dirN,
rp, rd, rl,
group, rNum);
434 maxProc =
max(maxProc, readProci);
436 if (proci == readProci)
448 else if (
group.found(proci))
452 const label localProci = proci -
group.start();
494 || (!syncPar && procDirs.size())
497 procsDirs_.insert(procPath, procDirs);
501 Pout<<
"fileOperation::lookupProcessorsPath : For:" << procPath
502 <<
" detected:" << procDirs <<
endl;
506 return procsDirs_[procPath];
518 return lookupAndCacheProcessorsPath(fName,
true);
529 if (io.
name().empty())
545 if (originalPath != objPath)
548 if (io.
name().empty())
550 ok =
isDir(originalPath);
570 const bool distributedRoots
574 distributed_(distributedRoots)
581 const word& handlerType,
586 <<
"Constructing fileHandler" <<
endl;
588 auto cstrIter = wordConstructorTablePtr_->cfind(handlerType);
590 if (!cstrIter.found())
596 *wordConstructorTablePtr_
627 mkDir(pathName.path());
665 Pout<<
"fileOperation::filePath :" <<
" fName:" << fName <<
endl;
672 splitProcessorPath(fName,
path, pDir, local,
group, numProcs);
684 for (
const dirIndex& dirIdx : procDirs())
686 const fileName& procDir = dirIdx.first();
693 Pout<<
"fileOperation::filePath : " << collatedName <<
endl;
704 Pout<<
"fileOperation::filePath : " << fName <<
endl;
711 Pout<<
"fileOperation::filePath : Not found" <<
endl;
719 return monitor().addWatch(fName);
725 return monitor().removeWatch(watchIndex);
737 if (getFile(watchIndices[i]) == fName)
759 const label index = findWatch(watchIndices,
f);
763 newWatchIndices.
append(addWatch(
f));
768 newWatchIndices.
append(watchIndices[index]);
769 removedWatches.
erase(index);
774 for (
const label index : removedWatches)
776 removeWatch(watchIndices[index]);
785 return monitor().getFile(watchIndex);
791 const bool masterOnly,
804 return monitor().getState(watchFd);
810 monitor().setUnmodified(watchFd);
817 const word& constantName
822 Pout<<
"fileOperation::findTimes : Finding times in directory "
823 << directory <<
endl;
831 instantList times = sortTimes(dirEntries, constantName);
836 for (
const dirIndex& dirIdx : procDirs())
838 const fileName& procDir = dirIdx.first();
839 fileName collDir(processorsPath(directory, procDir));
840 if (!collDir.empty() && collDir != directory)
852 sortTimes(extraEntries, constantName),
861 Pout<<
"fileOperation::findTimes : Found times:" << times <<
endl;
870 const scalar startValue,
871 const word& stopInstance
887 <<
"Found exact match for \"" << io.
name()
898 label instanceI = ts.size()-1;
900 for (; instanceI >= 0; --instanceI)
902 if (ts[instanceI].value() <= startValue)
909 for (; instanceI >= 0; --instanceI)
911 io.
instance() = ts[instanceI].name();
926 <<
"Found exact match for \"" << io.
name()
937 <<
"Hit stopInstance " << stopInstance <<
endl;
945 if (io.
name().empty())
948 <<
"Cannot find directory "
950 <<
" down to " << stopInstance
956 <<
"Cannot find file \"" << io.
name()
957 <<
"\" in directory " << io.
local()
958 <<
" in times " << startIO.
instance()
959 <<
" down to " << stopInstance
980 || ts.first().name() != time.
constant()
988 <<
"Found constant match for \"" << io.
name()
1004 <<
"Cannot find file \"" << io.
name() <<
"\" in directory "
1024 Pout<<
"fileOperation::readObjects :"
1026 <<
" instance:" << instance <<
endl;
1036 newInstance = instance;
1044 if (!procsPath.empty())
1046 newInstance = instance;
1071 for (
const fileName& dirN : dirNames)
1077 const label readProci =
1078 splitProcessorPath(dirN,
rp, rd, rl,
group, rNum);
1080 maxProc =
max(maxProc, readProci);
1091 if (nProcs == 0 &&
Foam::isDir(dir/processorsBaseDir))
1110 <<
" to determine the number of decompositions."
1111 <<
" Returning 1" <<
endl;
1124 Pout<<
"fileOperation::flush : clearing processor directories cache"
1134 const word& procsDir
1144 const word& instance,
1145 const word& procsDir
1149 processorsCasePath(io, procsDir)
1159 const word& procsDir
1165 if (caseName.starts_with(
"processor"))
1169 if (!std::isdigit(caseName[9]))
1172 <<
" does not end in old-style processorDDD" <<
endl;
1175 return dir.
path()/procsDir;
1194 label returnProci = -1;
1214 size_t slashLocal = string::npos;
1226 (
pos = objPath.find(
"processor",
pos)) != string::npos;
1230 if (
pos > 0 && objPath[
pos-1] !=
'/')
1237 size_t firstp =
pos + 9;
1242 const bool plural = (objPath[firstp] ==
's');
1248 else if (!std::isdigit(objPath[firstp]))
1255 slashLocal = objPath.find(
'/', firstp);
1258 const size_t lastp =
1259 (slashLocal == string::npos ? objPath.length() : slashLocal);
1261 if (!std::isdigit(objPath[lastp-1]))
1285 objPath.substr(firstp, lastp-firstp),
1292 nProcs = nProcsRead;
1305 Foam::read(objPath.substr(firstp, lastp-firstp), proci)
1310 returnProci = proci;
1317 if (
pos != string::npos)
1324 path = objPath.substr(0,
pos-1);
1328 if (slashLocal != string::npos)
1330 procDir = objPath.substr(
pos, slashLocal-
pos);
1331 local = objPath.substr(slashLocal+1);
1335 procDir = objPath.substr(
pos);
1348 return splitProcessorPath(fName,
path, pDir, local,
group, nProcs);
1360 if (handler.empty())
int debug
Static debugging option.
static refPtr< T > New(Args &&... args)
Construct refPtr of T with forwarding arguments.
const fileName & globalCaseName() const
Return global case name.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
bool exists(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist (as DIRECTORY or FILE) in the file system?
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
const word & name() const
Return name.
A class for handling words, derived from Foam::string.
static void mergeTimes(const instantList &extraTimes, const word &constantName, instantList ×)
Merge two times.
An encapsulation of filesystem-related operations.
A class for handling file names.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
constexpr const char *const group
Group name for atomic constants.
fileName processorsPath(const IOobject &, const word &instance, const word &procDir) const
Generate path (like io.path) with provided instance and any.
static autoPtr< fileOperation > fileHandlerPtr_
Static fileOperation.
virtual void addWatches(regIOobject &, const fileNameList &) const
Helper: add watches for list of regIOobjects.
static std::string path(const std::string &str)
Return directory path name (part before last /)
const labelList & watchIndices() const
Return file-monitoring handles.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
An interval of (signed) integers defined by a start and a size.
static bool less(const vector &x, const vector &y)
To compare normals.
bool typeHeaderOk(const bool checkType=true, const bool search=true, const bool verbose=true)
Read header (uses typeFilePath to find file) and check its info.
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
virtual bool writeData(Ostream &) const =0
Pure virtual writeData function.
const fileName & rootPath() const
const fileName & instance() const
static std::string name(const std::string &str)
Return basename (part beyond last /), including its extension.
bool read(const char *buf, int32_t &val)
Same as readInt32.
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
static bool & parRun()
Test if this a parallel run, or allow modify access.
static const Enum< pathType > pathTypeNames_
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
static fileCheckTypes fileModificationChecking
Type of file modification checking.
virtual fileName filePath(const bool checkGlobal, const IOobject &, const word &typeName, const bool search=true) const =0
Search for an object. checkGlobal : also check undecomposed case.
static bool master(const label communicator=worldComm)
Am I the master process.
static void scatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Distribute without modification. Reverse of gather.
fileState
Enumeration defining the file state.
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
const fileOperation & fileHandler()
Get current file handler.
Ostream & endl(Ostream &os)
Add newline and flush stream.
static bool isFileOrDir(const bool isFile, const fileName &)
Helper: check for file (isFile) or directory (!isFile)
virtual void setNProcs(const label nProcs)
Set number of processor directories/results. Only used in.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
static label numBlocks(const fileName &fName)
Detect number of blocks in a file.
const Time & time() const
Return time.
virtual void updateStates(const bool masterOnly, const bool syncPar) const
Update state of all files.
refPtr< dirIndexList > lookupAndCacheProcessorsPath(const fileName &, const bool syncPar) const
Lookup name of processorsDDD using cache.
string getEnv(const std::string &envName)
Get environment value for given envName.
virtual instantList findTimes(const fileName &, const word &) const
Get sorted list of times.
static instantList sortTimes(const fileNameList &dirEntries, const word &constantName="constant")
Sort directory entries according to time value,.
#define forAll(list, i)
Loop across all elements in list.
virtual fileName getFile(const label) const
Get name of file being watched (using handle)
virtual IOobject findInstance(const IOobject &io, const scalar startValue, const word &stopInstance) const
Find instance where IOobject is. Fails if cannot be found.
const objectRegistry & db() const
Return the local objectRegistry.
Registry of regIOobjects.
static autoPtr< fileOperation > New(const word &handlerType, bool verbose=false)
Select fileHandler-type.
virtual const fileName & dbDir() const
Local directory path of this objectRegistry relative to the time.
const fileName & local() const
bool erase(const iterator &iter)
Erase an entry specified by given iterator.
#define DebugInFunction
Report an information message using Foam::Info.
word name(const complex &c)
Return string representation of complex.
DynamicList< T, SizeMin > & append(const T &val)
Append an element to the end of this list.
virtual label nProcs(const fileName &dir, const fileName &local="") const
Get number of processor directories/results. Used for e.g.
void transfer(List< T > &list)
Checking for changes to files.
instantList times() const
Search the case for valid time directories.
The IOstreamOption is a simple container for options an IOstream can normally have.
virtual bool writeObject(const regIOobject &io, IOstreamOption streamOpt=IOstreamOption(), const bool valid=true) const
Writes a regIOobject (so header, contents and divider).
virtual fileMonitor::fileState getState(const label) const
Get current state of file (using handle)
Generic output stream using a standard (STL) stream.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
void resize(const label newSize)
Adjust allocated size of list.
#define FatalErrorInLookup(lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalError.
autoPtr< fileMonitor > monitorPtr_
File-change monitor for all registered files.
static word defaultFileHandler
Name of the default fileHandler.
errorManip< error > abort(error &err)
virtual fileName objectPath(const IOobject &io, const word &typeName) const
Generate disk file name for object. Opposite of filePath.
static const fileName null
An empty fileName.
virtual label addWatch(const fileName &) const
Add watching of a file. Returns handle.
errorManipArg< error, int > exit(error &err, const int errNo=1)
virtual bool removeWatch(const label) const
Remove watch on a file (using handle)
virtual void setUnmodified(const label) const
Set current state of file (using handle) to unmodified.
fileMonitor & monitor() const
Get or create fileMonitor singleton.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
fileOperation(const label comm, const bool distributedRoots=false)
Construct from communicator, optionally with distributed roots.
static int & msgType()
Message tag of standard messages.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define DebugInfo
Report an information message using Foam::Info.
bool exists(IOobject &io) const
Does ioobject exist. Is either a directory (empty name()) or.
readOption readOpt() const
The read option.
static label splitProcessorPath(const fileName &objectPath, fileName &path, fileName &procDir, fileName &local, procRangeType &group, label &nProcs)
Split objectPath into part before 'processor' and part after.
virtual fileNameList readObjects(const objectRegistry &db, const fileName &instance, const fileName &local, word &newInstance) const
Search directory for objects. Used in IOobjectList.
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
static const word null
An empty word.
virtual label findWatch(const labelList &watchIndices, const fileName &) const
Find index (or -1) of file in list of handles.
virtual refPtr< dirIndexList > lookupProcessorsPath(const fileName &objectPath) const
Lookup name of processorsDDD using cache.
bool writeHeader(Ostream &os) const
Write header.
static word processorsBaseDir
Return the processors directory name (usually "processors")
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
regionProperties rp(runTime)
bool good() const
Return true if next operation might succeed.
fileName objectPath() const
The complete path + object name.
void setSize(const label newSize)
Alias for resize(const label)
const word & constant() const
Return constant name.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
fileName path() const
The complete path.
dictionary & optimisationSwitches()
The OptimisationSwitches sub-dictionary in the central controlDict(s).
fileName processorsCasePath(const IOobject &, const word &procDir) const
Generate path (like io.path) from root+casename with any.
fileNameList readDir(const fileName &directory, const fileName::Type type=fileName::FILE, const bool filtergz=true, const bool followLink=true)
Read a directory and return the entries as a fileName List.
defineTypeNameAndDebug(combustionModel, 0)
static label detectProcessorPath(const fileName &objPath)
Detect processor number from '/aa/bb/processorDDD/cc'.
#define WarningInFunction
Report a warning using Foam::Warning.
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
A class for managing references or pointers (no reference counting)
dimensionedScalar pos(const dimensionedScalar &ds)