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" }
110static 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);
207 Foam::stringOps::natural_sort::compare
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
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"
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;
521 pathTypeIdx.
second() = (proci - group.start());
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);
671 if (originalPath != objPath)
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_);
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
1020 <<
"Found exact match for \"" <<
io.
name()
1028 const bool exitIfMissing
1034 enum failureCodes { FAILED_STOPINST = 1, FAILED_CONSTINST = 2 };
1040 label instIndex = ts.
size()-1;
1043 for (; instIndex >= 0; --instIndex)
1045 if (ts[instIndex].value() <= startValue)
1052 for (; instIndex >= 0; --instIndex)
1070 <<
"Found exact match for \"" <<
io.
name()
1081 <<
"Hit stopInstance " << stopInstance <<
endl;
1085 failed = failureCodes::FAILED_STOPINST;
1111 && (ts.
empty() || ts[0].name() != time.
constant() || startValue < 0)
1119 <<
"Found constant match for \"" <<
io.
name()
1129 if (!failed && exitIfMissing)
1131 failed = failureCodes::FAILED_CONSTINST;
1144 <<
" file \"" <<
io.
name() <<
"\" in";
1150 << startIO.
instance() <<
" down to ";
1152 if (failed == failureCodes::FAILED_STOPINST)
1177 Pout<<
"fileOperation::readObjects :"
1179 <<
" instance:" << instance <<
endl;
1189 newInstance = instance;
1197 if (!procsPath.empty())
1199 newInstance = instance;
1224 for (
const fileName& dirN : dirNames)
1230 const label readProci =
1231 splitProcessorPath(dirN,
rp, rd, rl, group, rNum);
1233 maxProc =
max(maxProc, readProci);
1243 if (nProcs == 0 &&
Foam::isDir(dir/processorsBaseDir))
1246 <<
"Defunct collated naming: " << processorsBaseDir <<
nl
1247 <<
"Manually rename with the decomposition number. Eg,"
1249 <<
" mv processors processors16" <<
nl <<
nl
1250 <<
"...returning 1" <<
endl;
1264 Pout<<
"fileOperation::flush : clearing processor directories cache"
1274 const word& procsDir
1284 const word& instance,
1285 const word& procsDir
1289 processorsCasePath(
io, procsDir)
1299 const word& procsDir
1309 if (!std::isdigit(caseName[9]))
1312 <<
" does not end in old-style processorDDD" <<
endl;
1315 return dir.
path()/procsDir;
1334 label returnProci = -1;
1370 if (
pos > 0 && objPath[
pos-1] !=
'/')
1377 size_t firstp =
pos + 9;
1382 const bool plural = (objPath[firstp] ==
's');
1388 else if (!std::isdigit(objPath[firstp]))
1395 slashLocal = objPath.find(
'/', firstp);
1398 const size_t lastp =
1399 (slashLocal ==
string::npos ? objPath.length() : slashLocal);
1401 if (!std::isdigit(objPath[lastp-1]))
1425 objPath.substr(firstp, lastp-firstp),
1432 nProcs = nProcsRead;
1445 Foam::read(objPath.substr(firstp, lastp-firstp), proci)
1450 returnProci = proci;
1464 path = objPath.substr(0,
pos-1);
1470 procDir = objPath.substr(
pos, slashLocal-
pos);
1471 local = objPath.substr(slashLocal+1);
1475 procDir = objPath.substr(
pos);
1488 return splitProcessorPath(fName,
path, pDir, local, group, nProcs);
1511 if (handler.empty())
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
void append(const T &val)
Copy append an element to the end of this list.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
bool erase(const iterator &iter)
Erase an entry specified by given iterator.
A List of objects of type <T> with automated input and output.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
const word & name() const noexcept
Return the object name.
const Time & time() const
Return Time associated with the objectRegistry.
readOption readOpt() const noexcept
The read option.
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.
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
const objectRegistry & db() const noexcept
Return the local objectRegistry.
const fileName & local() const noexcept
Read access to local path component.
const fileName & instance() const noexcept
Read access to instance path component.
static fileCheckTypes fileModificationChecking
Type of file modification checking.
fileName path() const
The complete path.
const fileName & rootPath() const
Return the Time::rootPath()
fileName objectPath() const
The complete path + object name.
bool writeHeader(Ostream &os) const
Write header with current type()
The IOstreamOption is a simple container for options an IOstream can normally have.
bool good() const noexcept
True if next operation might succeed.
An input stream of tokens.
An interval of (signed) integers defined by a start and a size.
void transfer(List< T > &list)
void setSize(const label n)
Alias for resize()
void resize(const label len)
Adjust allocated size of list.
Generic output stream using a standard (STL) stream.
label nProcs() const noexcept
Number of ranks associated with PstreamBuffers.
static void broadcast(Type &value, const label comm=UPstream::worldComm)
instantList times() const
Search the case for valid time directories.
const fileName & globalCaseName() const
Return global case name.
const word & constant() const
Return constant name.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
const T1 & first() const noexcept
Return first.
const T2 & second() const noexcept
Return second.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
iterator begin() noexcept
Return an iterator to begin traversing the UList.
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
iterator end() noexcept
Return an iterator to end traversing the UList.
void size(const label n)
Older name for setAddressableSize.
static bool & parRun() noexcept
Test if this a parallel run.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Checking for changes to files.
fileState
Enumeration defining the file state.
A class for handling file names.
static const fileName null
An empty fileName.
static std::string path(const std::string &str)
Return directory path name (part before last /)
static std::string name(const std::string &str)
Return basename (part beyond last /), including its extension.
An encapsulation of filesystem-related operations.
virtual void addWatches(regIOobject &, const fileNameList &) const
Helper: add watches for list of regIOobjects.
static bool isFileOrDir(const bool isFile, const fileName &)
Helper: check for file (isFile) or directory (!isFile)
bool distributed() const noexcept
Distributed roots (parallel run)
virtual void setNProcs(const label nProcs)
Set number of processor directories/results. Only used in.
refPtr< dirIndexList > lookupAndCacheProcessorsPath(const fileName &objectPath, const bool syncPar) const
Lookup name of processorsDDD using cache.
static instantList sortTimes(const fileNameList &dirEntries, const word &constantName="constant")
Sort directory entries according to time value,.
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
virtual bool removeWatch(const label) const
Remove watch on a file (using handle)
virtual fileNameList readObjects(const objectRegistry &db, const fileName &instance, const fileName &local, word &newInstance) const
Search directory for objects. Used in IOobjectList.
static word defaultFileHandler
Name of the default fileHandler.
virtual label findWatch(const labelList &watchIndices, const fileName &) const
Find index (or -1) of file in list of handles.
fileName processorsCasePath(const IOobject &, const word &procDir) const
Generate path (like io.path) from root+casename with any.
virtual refPtr< dirIndexList > lookupProcessorsPath(const fileName &objectPath) const
Lookup name of processorsDDD using cache.
virtual IOobject findInstance(const IOobject &io, const scalar startValue, const word &stopInstance) const
Find instance where IOobject is.
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.
static autoPtr< fileOperation > NewUncollated()
Static construct the commonly used uncollatedFileOperation.
static label detectProcessorPath(const fileName &objPath)
Detect processor number from '/aa/bb/processorDDD/cc'.
pathType
Enumeration for the location of an IOobject.
static labelList ioRanks()
Retrieve list of IO ranks from FOAM_IORANKS env variable.
virtual fileMonitor::fileState getState(const label) const
Get current state of file (using handle)
virtual void setUnmodified(const label) const
Set current state of file (using handle) to unmodified.
virtual void updateStates(const bool masterOnly, const bool syncPar) const
Update state of all files.
static const Enum< pathType > pathTypeNames_
fileMonitor & monitor() const
Get or create fileMonitor singleton.
static autoPtr< fileOperation > fileHandlerPtr_
Static fileOperation.
fileName processorsPath(const IOobject &, const word &instance, const word &procDir) const
Generate path (like io.path) with provided instance and any.
virtual instantList findTimes(const fileName &, const word &) const
Get sorted list of times.
static word processorsBaseDir
Return the processors directory name (usually "processors")
virtual bool writeObject(const regIOobject &io, IOstreamOption streamOpt=IOstreamOption(), const bool valid=true) const
Writes a regIOobject (so header, contents and divider).
virtual fileName getFile(const label) const
Get name of file being watched (using handle)
static void mergeTimes(const instantList &extraTimes, const word &constantName, instantList ×)
Merge two times.
fileOperation that assumes file operations are local.
Registry of regIOobjects.
virtual const fileName & dbDir() const
Local directory path of this objectRegistry relative to the time.
virtual fileName filePath() const
Return complete path + object name if the file exists.
A class for managing references or pointers (no reference counting)
bool exists() const noexcept
True if expression is non-empty.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
const labelList & watchIndices() const noexcept
Read access to file-monitoring handles.
splitCell * master() const
bool starts_with(const std::string &s) const
True if string starts with the given prefix (cf. C++20)
virtual void addWatch()
Add file watch on object (READ_IF_MODIFIED)
A class for handling words, derived from Foam::string.
static const word null
An empty word.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
regionProperties rp(runTime)
#define FatalErrorInLookup(lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
#define DebugInfo
Report an information message using Foam::Info.
#define WarningInFunction
Report a warning using Foam::Warning.
#define DebugInFunction
Report an information message using Foam::Info.
constexpr const char *const group
Group name for atomic constants.
dictionary & optimisationSwitches()
The OptimisationSwitches sub-dictionary in the central controlDict(s).
const fileOperation & fileHandler()
Get current file handler.
dimensionedScalar pos(const dimensionedScalar &ds)
string getEnv(const std::string &envName)
Get environment value for given envName.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
bool read(const char *buf, int32_t &val)
Same as readInt32.
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?
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
Ostream & endl(Ostream &os)
Add newline and flush stream.
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
errorManip< error > abort(error &err)
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.
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
errorManipArg< error, int > exit(error &err, const int errNo=1)
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)
#define defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.
#define forAll(list, i)
Loop across all elements in list.
Specialized string sorting.
A list compare binary predicate for normal sort.