67 { fileOperation::NOTFOUND,
"notFound" },
68 { fileOperation::ABSOLUTE,
"absolute" },
69 { fileOperation::OBJECT,
"objectPath" },
70 { fileOperation::WRITEOBJECT,
"writeObject" },
71 { fileOperation::PROCUNCOLLATED,
"uncollatedProc" },
72 { fileOperation::PROCBASEOBJECT,
"globalProc" },
73 { fileOperation::PROCOBJECT,
"localProc" },
74 { fileOperation::PARENTOBJECT,
"parentObjectPath" },
75 { fileOperation::FINDINSTANCE,
"findInstance" },
76 { fileOperation::PROCUNCOLLATEDINSTANCE,
"uncollatedProcInstance" },
77 { fileOperation::PROCBASEINSTANCE,
"globalProcInstance" },
78 { fileOperation::PROCINSTANCE,
"localProcInstance" }
112 static bool parseProcsNumRange
114 const std::string str,
119 const char * nptr = str.c_str();
120 char *endptr =
nullptr;
124 intmax_t parsed = std::strtoimax(nptr, &endptr, 10);
125 if (errno || nptr == endptr)
return false;
127 const int nProcs = int(parsed);
137 if (*endptr !=
'_')
return false;
143 parsed = std::strtoimax(nptr, &endptr, 10);
144 if (errno || nptr == endptr)
return false;
146 const int firstProc = int(parsed);
149 if (*endptr !=
'-')
return false;
155 parsed = std::strtoimax(nptr, &endptr, 10);
156 if (errno || nptr == endptr)
return false;
158 const int lastProc = int(parsed);
168 && (nProcs >= 0 && firstProc >= 0 && firstProc <= lastProc)
174 group.reset(firstProc, lastProc-firstProc+1);
242 const word& constantName
246 bool haveConstant =
false;
248 if (!constantName.empty())
250 for (
const fileName& dirName : dirEntries)
252 if (dirName == constantName)
265 times[nTimes].value() = 0;
266 times[nTimes].name() = constantName;
271 for (
const fileName& dirName : dirEntries)
273 if (readScalar(dirName, times[nTimes].value()))
275 times[nTimes].name() = dirName;
305 const auto& object0 =
names[0];
309 if (object0 !=
names[i])
326 fileName masterName(
name);
356 const word& constantName,
360 if (extraTimes.size())
362 const bool haveConstant =
365 && times[0].name() == constantName
368 const bool haveExtraConstant =
371 && extraTimes[0].name() == constantName
375 instantList combinedTimes(times.size()+extraTimes.size());
378 if (haveExtraConstant)
383 combinedTimes[sz++] = extraTimes[0];
388 combinedTimes[sz++] = times[i];
390 for (; extrai < extraTimes.size(); extrai++)
392 combinedTimes[sz++] = extraTimes[extrai];
394 combinedTimes.setSize(sz);
395 times.transfer(combinedTimes);
398 if (times.size() > 1)
401 if (times[0].
name() == constantName)
408 label newi = starti+1;
409 for (label i = newi; i < times.size(); i++)
411 if (times[i].value() != times[i-1].value())
415 times[newi] = times[i];
454 const auto iter = procsDirs_.cfind(procPath);
461 DynamicList<dirIndex> procDirs;
470 const bool readDirMasterOnly
483 if (readDirMasterOnly)
493 <<
"readDir on master: send " << dirEntries.size()
494 <<
" names to sub-processes" <<
endl;
506 Pout<<
"readDir without special master/send treatment" 510 dirEntries =
readDir(
path, fileName::Type::DIRECTORY);
518 for (
const fileName& dirN : dirEntries)
523 const label readProci =
524 splitProcessorPath(dirN,
rp, rd, rl,
group, rNum);
526 nProcs =
max(nProcs, readProci+1);
528 Tuple2<pathType, int> pathTypeIdx(pathType::NOTFOUND, 0);
530 if (proci == readProci)
533 pathTypeIdx.first() = pathType::PROCUNCOLLATED;
538 nProcs =
max(nProcs, rNum);
549 pathTypeIdx.first() = pathType::PROCBASEOBJECT;
550 pathTypeIdx.second() = proci;
553 else if (
group.found(proci))
558 pathTypeIdx.first() = pathType::PROCOBJECT;
559 pathTypeIdx.second() = (proci -
group.start());
563 if (pathTypeIdx.first() != pathType::NOTFOUND)
565 procDirs.append(dirIndex(dirN, pathTypeIdx));
575 unsigned procDirsStatus = (procDirs.empty() ? 1u : 2u);
579 Pout<<
"fileOperation::lookupProcessorsPath " << procPath
580 <<
" detected:" << procDirs <<
endl;
585 reduce(procDirsStatus, bitOrOp<unsigned>());
587 if (procDirsStatus == 3u)
598 int flavour(pathType::PROCUNCOLLATED);
599 for (
const dirIndex& pDir : procDirs)
601 flavour =
max(flavour,
int(pDir.second().first()));
604 reduce(nProcs, maxOp<label>());
605 reduce(flavour, maxOp<int>());
607 if (procDirs.empty())
609 Tuple2<pathType, int> pathTypeIdx(pathType(flavour), 0);
613 pathTypeIdx.first() == pathType::PROCBASEOBJECT
617 pathTypeIdx.second() = proci;
646 Pout<<
"fileOperation::lookupProcessorsPath " 648 <<
" synthetic:" << procDirs <<
endl;
658 const_cast<fileOperation&
>(*this).setNProcs(nProcs);
665 if (procDirsStatus & 2u)
667 procsDirs_.insert(procPath, procDirs);
670 return procsDirs_[procPath];
682 return lookupAndCacheProcessorsPath(fName,
true);
709 if (originalPath != objPath)
714 ok =
isDir(originalPath);
734 const bool distributedRoots
738 distributed_(distributedRoots)
745 const word& handlerType,
749 if (handlerType.empty())
754 <<
"defaultFileHandler name is undefined" <<
nl 762 <<
"Constructing fileHandler" <<
endl;
764 auto* ctorPtr = wordConstructorTable(handlerType);
772 *wordConstructorTablePtr_
784 bool old(distributed_);
811 mkDir(pathName.path());
820 OSstream&
os = *osPtr;
823 const_cast<regIOobject&
>(
io).updateMetaData();
847 const fileName& fName,
848 const bool checkGzip,
849 const bool followLink
854 Pout<<
"fileOperation::filePath :" <<
" fName:" << fName <<
endl;
872 refPtr<dirIndexList> procDirs(lookupProcessorsPath(fName));
873 for (
const dirIndex& dirIdx : procDirs())
875 const fileName& procDir = dirIdx.first();
877 fileName collatedName(
path/procDir/
local);
878 if (
exists(collatedName, checkGzip, followLink))
882 Pout<<
"fileOperation::filePath : " << collatedName <<
endl;
889 if (
exists(fName, checkGzip, followLink))
893 Pout<<
"fileOperation::filePath : " << fName <<
endl;
900 Pout<<
"fileOperation::filePath : Not found" <<
endl;
909 return monitor().addWatch(fName);
915 return monitor().removeWatch(watchIndex);
927 if (getFile(watchIndices[i]) == fName)
942 const labelList& watchIndices = rio.watchIndices();
944 DynamicList<label> newWatchIndices;
947 for (
const fileName&
f : files)
949 const label index = findWatch(watchIndices,
f);
953 newWatchIndices.append(addWatch(
f));
958 newWatchIndices.append(watchIndices[index]);
959 removedWatches.erase(index);
964 for (
const label index : removedWatches)
966 removeWatch(watchIndices[index]);
969 rio.watchIndices() = newWatchIndices;
975 return monitor().getFile(watchIndex);
981 const bool masterOnly,
994 return monitor().getState(watchFd);
1000 monitor().setUnmodified(watchFd);
1007 const word& constantName
1012 Pout<<
"fileOperation::findTimes : Finding times in directory " 1013 << directory <<
endl;
1021 instantList times = sortTimes(dirEntries, constantName);
1025 refPtr<dirIndexList> procDirs(lookupProcessorsPath(directory));
1026 for (
const dirIndex& dirIdx : procDirs())
1028 const fileName& procDir = dirIdx.first();
1029 fileName collDir(processorsPath(directory, procDir));
1030 if (!collDir.empty() && collDir != directory)
1042 sortTimes(extraEntries, constantName),
1051 Pout<<
"fileOperation::findTimes : Found times:" <<
flatOutput(times)
1060 const IOobject& startIO,
1061 const scalar startValue,
1062 const word& stopInstance
1065 const Time& time = startIO.
time();
1066 IOobject
io(startIO);
1077 <<
"Found exact match for \"" <<
io.
name()
1087 enum failureCodes { FAILED_STOPINST = 1, FAILED_CONSTINST = 2 };
1093 label instIndex = ts.
size()-1;
1096 for (; instIndex >= 0; --instIndex)
1098 if (ts[instIndex].value() <= startValue)
1105 for (; instIndex >= 0; --instIndex)
1123 <<
"Found exact match for \"" <<
io.
name()
1134 <<
"Hit stopInstance " << stopInstance <<
endl;
1138 failed = failureCodes::FAILED_STOPINST;
1164 && (ts.empty() || ts[0].name() != time.constant() || startValue < 0)
1172 <<
"Found constant match for \"" <<
io.
name()
1182 if (!failed && exitIfMissing)
1184 failed = failureCodes::FAILED_CONSTINST;
1197 <<
" file \"" <<
io.
name() <<
"\" in";
1203 << startIO.instance() <<
" down to ";
1205 if (failed == failureCodes::FAILED_STOPINST)
1222 const objectRegistry& db,
1223 const fileName& instance,
1224 const fileName&
local,
1230 Pout<<
"fileOperation::readObjects :" 1231 <<
" db:" << db.objectPath()
1232 <<
" instance:" << instance <<
endl;
1235 fileName
path(db.path(instance, db.dbDir()/
local));
1237 newInstance.clear();
1242 newInstance = instance;
1248 fileName procsPath(filePath(
path));
1250 if (!procsPath.empty())
1252 newInstance = instance;
1277 for (
const fileName& dirN : dirNames)
1280 procRangeType
group;
1283 const label readProci =
1284 splitProcessorPath(dirN,
rp, rd, rl,
group, rNum);
1286 maxProc =
max(maxProc, readProci);
1296 if (nProcs == 0 &&
Foam::isDir(dir/processorsBaseDir))
1299 <<
"Defunct collated naming: " << processorsBaseDir <<
nl 1300 <<
"Manually rename with the decomposition number. Eg," 1302 <<
" mv processors processors16" <<
nl <<
nl 1303 <<
"...returning 1" <<
endl;
1317 Pout<<
"fileOperation::flush : clearing processor directories cache" 1327 const word& procsDir
1337 const word& instance,
1338 const word& procsDir
1342 processorsCasePath(
io, procsDir)
1352 const word& procsDir
1358 if (caseName.starts_with(
"processor"))
1362 if (!std::isdigit(caseName[9]))
1365 <<
" does not end in old-style processorDDD" <<
endl;
1368 return dir.
path()/procsDir;
1377 const fileName& objPath,
1382 procRangeType&
group,
1387 label returnProci = -1;
1407 size_t slashLocal = string::npos;
1419 (
pos = objPath.find(
"processor",
pos)) != string::npos;
1423 if (
pos > 0 && objPath[
pos-1] !=
'/')
1430 size_t firstp =
pos + 9;
1435 const bool plural = (objPath[firstp] ==
's');
1441 else if (!std::isdigit(objPath[firstp]))
1448 slashLocal = objPath.find(
'/', firstp);
1451 const size_t lastp =
1452 (slashLocal == string::npos ? objPath.length() : slashLocal);
1454 if (!std::isdigit(objPath[lastp-1]))
1478 objPath.substr(firstp, lastp-firstp),
1485 nProcs = nProcsRead;
1498 Foam::read(objPath.substr(firstp, lastp-firstp), proci)
1503 returnProci = proci;
1510 if (
pos != string::npos)
1517 path = objPath.substr(0,
pos-1);
1521 if (slashLocal != string::npos)
1523 procDir = objPath.substr(
pos, slashLocal-
pos);
1524 local = objPath.substr(slashLocal+1);
1528 procDir = objPath.substr(
pos);
1539 procRangeType
group;
1541 return splitProcessorPath(fName,
path, pDir,
local,
group, nProcs);
1564 if (handlerType.empty())
1600 autoPtr<fileOperation> old;
1604 newHandler.get() !=
nullptr 1608 old.reset(newHandler.release());
static const Enum< pathType > pathTypeNames_
static label detectProcessorPath(const fileName &objPath)
Detect processor number from '/aa/bb/processorDDD/cc'.
virtual refPtr< dirIndexList > lookupProcessorsPath(const fileName &objectPath) const
Lookup name of processorsDDD using cache.
List< instant > instantList
List of instants.
fileOperation(const label comm, const bool distributedRoots=false)
Construct from communicator, optionally with distributed roots.
void size(const label n)
Older name for setAddressableSize.
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
List of names generated by calling name() for each list item and filtered for matches.
A class for handling file names.
Specialized string sorting.
virtual fileMonitor::fileState getState(const label) const
Get current state of file (using handle)
errorManipArg< error, int > exit(error &err, const int errNo=1)
void resize(const label len)
Adjust allocated size of list.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
Checking for changes to files.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
const word & name() const noexcept
Return the object name.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
static refPtr< T > New(Args &&... args)
Construct refPtr with forwarding arguments.
An interval of (signed) integers defined by a start and a size.
fileState
Enumeration defining the file state.
constexpr char nl
The newline '\n' character (0x0a)
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
virtual void setUnmodified(const label) const
Set current state of file (using handle) to unmodified.
bool exists(IOobject &io) const
Does IOObject exist. Is either a directory (empty name()) or a file.
virtual fileNameList readObjects(const objectRegistry &db, const fileName &instance, const fileName &local, word &newInstance) const
Search directory for objects. Used in IOobjectList.
Ostream & endl(Ostream &os)
Add newline and flush stream.
static bool & parRun() noexcept
Test if this a parallel run.
autoPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler.
A simple container for options an IOstream can normally have.
static std::string path(const std::string &str)
Return directory path name (part before last /)
string getEnv(const std::string &envName)
Get environment value for given envName.
#define FatalErrorInLookup(lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalError.
static word processorsBaseDir
Return the processors directory name (usually "processors")
fileName processorsPath(const IOobject &, const word &instance, const word &procDir) const
Generate path (like io.path) with provided instance and any.
static bool less(const vector &x, const vector &y)
To compare normals.
bool writeHeader(Ostream &os) const
Write header with current type()
A class for managing references or pointers (no reference counting)
An encapsulation of filesystem-related operations.
fileName objectPath() const
The complete path + object name.
static bool isReadRequired(readOption opt) noexcept
True if (MUST_READ | MUST_READ_IF_MODIFIED) bits are set.
static void broadcast(Type &value, const label comm=UPstream::worldComm)
Broadcast content (contiguous or non-contiguous) to all processes in communicator.
bool read(const char *buf, int32_t &val)
Same as readInt32.
refPtr< dirIndexList > lookupAndCacheProcessorsPath(const fileName &objectPath, const bool syncPar) const
Lookup name of processorsDDD using cache.
fileOperation that assumes file operations are local.
#define forAll(list, i)
Loop across all elements in list.
constexpr const char *const group
Group name for atomic constants.
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
virtual void updateStates(const bool masterOnly, const bool syncPar) const
Update state of all files.
dimensionedScalar pos(const dimensionedScalar &ds)
bool returnReduceAnd(const bool value, const label comm=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
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.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
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.
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
A class for handling words, derived from Foam::string.
virtual fileName getFile(const label) const
Get name of file being watched (using handle)
#define DebugInFunction
Report an information message using Foam::Info.
virtual IOobject findInstance(const IOobject &io, const scalar startValue, const word &stopInstance) const
Find instance where IOobject is.
virtual instantList findTimes(const fileName &, const word &) const
Get sorted list of times.
void sort(UList< T > &list)
Sort the list.
regionProperties rp(runTime)
const objectRegistry & db() const noexcept
Return the local objectRegistry.
static const word null
An empty word.
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?
virtual void addWatches(regIOobject &, const fileNameList &) const
Helper: add watches for list of regIOobjects.
static int compare(const std::string &s1, const std::string &s2)
Natural compare for std::string.
static instantList sortTimes(const fileNameList &dirEntries, const word &constantName="constant")
Sort directory entries according to time value,.
virtual label addWatch(const fileName &) const
Add watching of a file. Returns handle.
virtual bool writeObject(const regIOobject &io, IOstreamOption streamOpt=IOstreamOption(), const bool valid=true) const
Writes a regIOobject (so header, contents and divider).
errorManip< error > abort(error &err)
iterator begin() noexcept
Return an iterator to begin traversing the UList.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
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.
#define DebugInfo
Report an information message using Foam::Info.
static void mergeTimes(const instantList &extraTimes, const word &constantName, instantList ×)
Merge two times.
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
static std::string name(const std::string &str)
Return basename (part beyond last /), including its extension.
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
int debug
Static debugging option.
fileName processorsCasePath(const IOobject &, const word &procDir) const
Generate path (like io.path) from root+casename with any.
OBJstream os(runTime.globalPath()/outputName)
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
defineTypeNameAndDebug(combustionModel, 0)
static fileCheckTypes fileModificationChecking
Type of file modification checking.
fileMonitor & monitor() const
Get or create fileMonitor singleton.
static autoPtr< fileOperation > fileHandlerPtr_
Static fileOperation.
static autoPtr< fileOperation > New(const word &handlerType, bool verbose=false)
Select fileHandler-type. Uses defaultFileHandler if the handlerType is empty.
static bool uniformFile(const fileNameList &names)
True if the file names are identical. False on an empty list.
const fileName & instance() const noexcept
Read access to instance path component.
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
static bool isFileOrDir(const bool isFile, const fileName &)
Helper: check for file (isFile) or directory (!isFile)
const fileName & rootPath() const
Return the Time::rootPath()
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
virtual label nProcs(const fileName &dir, const fileName &local="") const
Get number of processor directories/results. Used for e.g.
static word defaultFileHandler
Name of the default fileHandler.
#define WarningInFunction
Report a warning using Foam::Warning.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
const fileName & globalCaseName() const noexcept
Return global case name.
const Time & time() const
Return Time associated with the objectRegistry.
bool good() const noexcept
True if next operation might succeed.
static bool master(const label communicator=worldComm)
Am I the master rank.
bool distributed() const noexcept
Distributed roots (parallel run)
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
Reduce inplace (cf. MPI Allreduce) using specified communication schedule.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
virtual const fileName & dbDir() const
Local directory path of this objectRegistry relative to the time.
dictionary & optimisationSwitches()
The OptimisationSwitches sub-dictionary in the central controlDict(s).
iterator end() noexcept
Return an iterator to end traversing the UList.
List< label > labelList
A List of labels.
static labelList ioRanks()
Retrieve list of IO ranks from FOAM_IORANKS env variable.
const T1 & first() const noexcept
Access the first element.
const fileName & local() const noexcept
Read access to local path component.
virtual label findWatch(const labelList &watchIndices, const fileName &) const
Find index (or -1) of file in list of handles.
fileNameList readDir(const fileName &directory, const fileName::Type type=fileName::Type::FILE, const bool filtergz=true, const bool followLink=true)
Read a directory and return the entries as a fileName List.
List< fileName > fileNameList
A List of fileNames.
Defines the attributes of an object for which implicit objectRegistry management is supported...
virtual fileName objectPath(const IOobject &io, const word &typeName) const
Generate disk file name for object. Opposite of filePath.
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.
virtual bool removeWatch(const label) const
Remove watch on a file (using handle)
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
static autoPtr< fileOperation > NewUncollated()
Static construct the commonly used uncollatedFileOperation.