Go to the documentation of this file.
65 { fileOperation::NOTFOUND,
"notFound" },
66 { fileOperation::ABSOLUTE,
"absolute" },
67 { fileOperation::OBJECT,
"objectPath" },
68 { fileOperation::WRITEOBJECT,
"writeObject" },
69 { fileOperation::PROCUNCOLLATED,
"uncollatedProc" },
70 { fileOperation::PROCBASEOBJECT,
"globalProc" },
71 { fileOperation::PROCOBJECT,
"localProc" },
72 { fileOperation::PARENTOBJECT,
"parentObjectPath" },
73 { fileOperation::FINDINSTANCE,
"findInstance" },
74 { fileOperation::PROCUNCOLLATEDINSTANCE,
"uncollatedProcInstance" },
75 { fileOperation::PROCBASEINSTANCE,
"globalProcInstance" },
76 { fileOperation::PROCINSTANCE,
"localProcInstance" }
110 static bool parseProcsNumRange
112 const std::string str,
117 const char * nptr = str.c_str();
118 char *endptr =
nullptr;
122 intmax_t parsed = std::strtoimax(nptr, &endptr, 10);
123 if (errno || nptr == endptr)
return false;
125 const int nProcs = int(parsed);
135 if (*endptr !=
'_')
return false;
141 parsed = std::strtoimax(nptr, &endptr, 10);
142 if (errno || nptr == endptr)
return false;
144 const int firstProc = int(parsed);
147 if (*endptr !=
'-')
return false;
153 parsed = std::strtoimax(nptr, &endptr, 10);
154 if (errno || nptr == endptr)
return false;
156 const int lastProc = int(parsed);
166 && (nProcs >= 0 && firstProc >= 0 && firstProc <= lastProc)
172 group.reset(firstProc, lastProc-firstProc+1);
240 const word& constantName
244 bool haveConstant =
false;
246 if (!constantName.empty())
248 for (
const fileName& dirName : dirEntries)
250 if (dirName == constantName)
263 times[nTimes].value() = 0;
264 times[nTimes].name() = constantName;
269 for (
const fileName& dirName : dirEntries)
271 if (readScalar(dirName, times[nTimes].value()))
273 times[nTimes].name() = dirName;
318 const word& constantName,
322 if (extraTimes.size())
324 const bool haveConstant =
327 && times[0].name() == constantName
330 const bool haveExtraConstant =
333 && extraTimes[0].name() == constantName
337 instantList combinedTimes(times.size()+extraTimes.size());
340 if (haveExtraConstant)
345 combinedTimes[sz++] = extraTimes[0];
350 combinedTimes[sz++] = times[i];
352 for (; extrai < extraTimes.size(); extrai++)
354 combinedTimes[sz++] = extraTimes[extrai];
360 if (times.size() > 1)
363 if (times[0].
name() == constantName)
370 label newi = starti+1;
371 for (label i = newi; i < times.size(); i++)
373 if (times[i].value() != times[i-1].value())
377 times[newi] = times[i];
410 splitProcessorPath(fName,
path, pDir, local,
group, numProcs);
416 const auto iter = procsDirs_.cfind(procPath);
432 const bool readDirMasterOnly
445 if (readDirMasterOnly)
455 <<
"readDir on master: send " << dirEntries.size()
456 <<
" names to sub-processes" <<
endl;
468 Pout<<
"readDir without special master/send treatment"
472 dirEntries =
readDir(
path, fileName::Type::DIRECTORY);
480 for (
const fileName& dirN : dirEntries)
485 const label readProci =
486 splitProcessorPath(dirN,
rp, rd, rl,
group, rNum);
488 nProcs =
max(nProcs, readProci+1);
492 if (proci == readProci)
495 pathTypeIdx.
first() = pathType::PROCUNCOLLATED;
500 nProcs =
max(nProcs, rNum);
511 pathTypeIdx.
first() = pathType::PROCBASEOBJECT;
512 pathTypeIdx.
second() = proci;
515 else if (
group.found(proci))
520 pathTypeIdx.
first() = pathType::PROCOBJECT;
525 if (pathTypeIdx.
first() != pathType::NOTFOUND)
537 unsigned procDirsStatus = (procDirs.empty() ? 1u : 2u);
541 Pout<<
"fileOperation::lookupProcessorsPath " << procPath
542 <<
" detected:" << procDirs <<
endl;
549 if (procDirsStatus == 3u)
560 int flavour(pathType::PROCUNCOLLATED);
561 for (
const dirIndex& pDir : procDirs)
563 flavour =
max(flavour,
int(pDir.second().first()));
569 if (procDirs.empty())
575 pathTypeIdx.
first() == pathType::PROCBASEOBJECT
579 pathTypeIdx.
second() = proci;
608 Pout<<
"fileOperation::lookupProcessorsPath "
610 <<
" synthetic:" << procDirs <<
endl;
627 if (procDirsStatus & 2u)
629 procsDirs_.insert(procPath, procDirs);
632 return procsDirs_[procPath];
644 return lookupAndCacheProcessorsPath(fName,
true);
655 if (io.
name().empty())
671 if (originalPath != objPath)
674 if (io.
name().empty())
676 ok =
isDir(originalPath);
696 const bool distributedRoots
700 distributed_(distributedRoots)
707 const word& handlerType,
712 <<
"Constructing fileHandler" <<
endl;
714 auto* ctorPtr = wordConstructorTable(handlerType);
722 *wordConstructorTablePtr_
734 bool old(distributed_);
761 mkDir(pathName.path());
799 Pout<<
"fileOperation::filePath :" <<
" fName:" << fName <<
endl;
806 splitProcessorPath(fName,
path, pDir, local,
group, numProcs);
818 for (
const dirIndex& dirIdx : procDirs())
820 const fileName& procDir = dirIdx.first();
827 Pout<<
"fileOperation::filePath : " << collatedName <<
endl;
838 Pout<<
"fileOperation::filePath : " << fName <<
endl;
845 Pout<<
"fileOperation::filePath : Not found" <<
endl;
853 return monitor().addWatch(fName);
859 return monitor().removeWatch(watchIndex);
871 if (getFile(watchIndices[i]) == fName)
893 const label index = findWatch(watchIndices,
f);
897 newWatchIndices.
append(addWatch(
f));
902 newWatchIndices.
append(watchIndices[index]);
903 removedWatches.erase(index);
908 for (
const label index : removedWatches)
910 removeWatch(watchIndices[index]);
919 return monitor().getFile(watchIndex);
925 const bool masterOnly,
938 return monitor().getState(watchFd);
944 monitor().setUnmodified(watchFd);
951 const word& constantName
956 Pout<<
"fileOperation::findTimes : Finding times in directory "
957 << directory <<
endl;
965 instantList times = sortTimes(dirEntries, constantName);
970 for (
const dirIndex& dirIdx : procDirs())
972 const fileName& procDir = dirIdx.first();
973 fileName collDir(processorsPath(directory, procDir));
974 if (!collDir.empty() && collDir != directory)
986 sortTimes(extraEntries, constantName),
995 Pout<<
"fileOperation::findTimes : Found times:" << times <<
endl;
1004 const scalar startValue,
1005 const word& stopInstance
1021 <<
"Found exact match for \"" << io.
name()
1032 label instanceI = ts.size()-1;
1034 for (; instanceI >= 0; --instanceI)
1036 if (ts[instanceI].value() <= startValue)
1043 for (; instanceI >= 0; --instanceI)
1045 io.
instance() = ts[instanceI].name();
1060 <<
"Found exact match for \"" << io.
name()
1071 <<
"Hit stopInstance " << stopInstance <<
endl;
1079 if (io.
name().empty())
1082 <<
"Cannot find directory "
1084 <<
" down to " << stopInstance
1090 <<
"Cannot find file \"" << io.
name()
1091 <<
"\" in directory " << io.
local()
1092 <<
" in times " << startIO.
instance()
1093 <<
" down to " << stopInstance
1114 || ts.first().name() != time.
constant()
1122 <<
"Found constant match for \"" << io.
name()
1138 <<
"Cannot find file \"" << io.
name() <<
"\" in directory "
1158 Pout<<
"fileOperation::readObjects :"
1160 <<
" instance:" << instance <<
endl;
1170 newInstance = instance;
1178 if (!procsPath.empty())
1180 newInstance = instance;
1205 for (
const fileName& dirN : dirNames)
1211 const label readProci =
1212 splitProcessorPath(dirN,
rp, rd, rl,
group, rNum);
1214 maxProc =
max(maxProc, readProci);
1224 if (nProcs == 0 &&
Foam::isDir(dir/processorsBaseDir))
1227 <<
"Defunct collated naming: " << processorsBaseDir <<
nl
1228 <<
"Manually rename with the decomposition number. Eg," <<
nl <<
nl
1229 <<
" mv processors processors16" <<
nl <<
nl
1230 <<
"...returning 1" <<
endl;
1244 Pout<<
"fileOperation::flush : clearing processor directories cache"
1254 const word& procsDir
1264 const word& instance,
1265 const word& procsDir
1269 processorsCasePath(io, procsDir)
1279 const word& procsDir
1285 if (caseName.starts_with(
"processor"))
1289 if (!std::isdigit(caseName[9]))
1292 <<
" does not end in old-style processorDDD" <<
endl;
1295 return dir.
path()/procsDir;
1314 label returnProci = -1;
1334 size_t slashLocal = string::npos;
1346 (
pos = objPath.find(
"processor",
pos)) != string::npos;
1350 if (
pos > 0 && objPath[
pos-1] !=
'/')
1357 size_t firstp =
pos + 9;
1362 const bool plural = (objPath[firstp] ==
's');
1368 else if (!std::isdigit(objPath[firstp]))
1375 slashLocal = objPath.find(
'/', firstp);
1378 const size_t lastp =
1379 (slashLocal == string::npos ? objPath.length() : slashLocal);
1381 if (!std::isdigit(objPath[lastp-1]))
1405 objPath.substr(firstp, lastp-firstp),
1412 nProcs = nProcsRead;
1425 Foam::read(objPath.substr(firstp, lastp-firstp), proci)
1430 returnProci = proci;
1437 if (
pos != string::npos)
1444 path = objPath.substr(0,
pos-1);
1448 if (slashLocal != string::npos)
1450 procDir = objPath.substr(
pos, slashLocal-
pos);
1451 local = objPath.substr(slashLocal+1);
1455 procDir = objPath.substr(
pos);
1468 return splitProcessorPath(fName,
path, pDir, local,
group, nProcs);
1491 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...
regionProperties rp(runTime)
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.
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.
constexpr const char *const group
Group name for atomic constants.
void resize(const label len)
Adjust allocated size of list.
iterator end() noexcept
Return an iterator to end traversing the UList.
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.
Specialized string sorting.
const fileName & instance() const noexcept
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
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 autoPtr< fileOperation > NewUncollated()
Static construct the commonly used uncollatedFileOperation.
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.
const Time & time() const
Return Time associated with the objectRegistry.
virtual void updateStates(const bool masterOnly, const bool syncPar) const
Update state of all files.
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.
bool good() const noexcept
True if next operation might succeed.
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.
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.
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
iterator begin() noexcept
Return an iterator to begin traversing the UList.
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
An input stream of tokens.
#define DebugInFunction
Report an information message using Foam::Info.
const fileName & local() const noexcept
void setSize(const label n)
Alias for resize()
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.
#define FatalErrorInLookup(lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
static word defaultFileHandler
Name of the default fileHandler.
static int compare(const std::string &s1, const std::string &s2)
Natural compare for std::string.
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)
readOption readOpt() const noexcept
The read option.
refPtr< dirIndexList > lookupAndCacheProcessorsPath(const fileName &objectPath, const bool syncPar) const
Lookup name of processorsDDD using cache.
virtual void setUnmodified(const label) const
Set current state of file (using handle) to unmodified.
const word & name() const noexcept
Return name.
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.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
static int & msgType() noexcept
Message tag of standard messages.
#define DebugInfo
Report an information message using Foam::Info.
fileOperation that assumes file operations are local.
bool exists(IOobject &io) const
static bool & parRun() noexcept
Test if this a parallel run.
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.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
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.
static labelList ioRanks()
Retrieve list of IO ranks from FOAM_IORANKS env variable.
const T2 & second() const noexcept
Return second.
virtual label findWatch(const labelList &watchIndices, const fileName &) const
Find index (or -1) of file in list of handles.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
virtual refPtr< dirIndexList > lookupProcessorsPath(const fileName &objectPath) const
Lookup name of processorsDDD using cache.
bool writeHeader(Ostream &os) const
Write header with current type()
static word processorsBaseDir
Return the processors directory name (usually "processors")
void size(const label n)
Older name for setAddressableSize.
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
fileName objectPath() const
The complete path + object name.
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'.
const T1 & first() const noexcept
Return first.
#define WarningInFunction
Report a warning using Foam::Warning.
pathType
Enumeration for the location of an IOobject.
bool distributed() const noexcept
Distributed roots (parallel run)
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)
const objectRegistry & db() const noexcept
Return the local objectRegistry.
dimensionedScalar pos(const dimensionedScalar &ds)