63 { fileOperation::NOTFOUND,
"notFound" },
64 { fileOperation::ABSOLUTE,
"absolute" },
65 { fileOperation::OBJECT,
"objectPath" },
66 { fileOperation::WRITEOBJECT,
"writeObject" },
67 { fileOperation::PROCUNCOLLATED,
"uncollatedProc" },
68 { fileOperation::PROCBASEOBJECT,
"globalProc" },
69 { fileOperation::PROCOBJECT,
"localProc" },
70 { fileOperation::PARENTOBJECT,
"parentObjectPath" },
71 { fileOperation::FINDINSTANCE,
"findInstance" },
72 { fileOperation::PROCUNCOLLATEDINSTANCE,
"uncollatedProcInstance" },
73 { fileOperation::PROCBASEINSTANCE,
"globalProcInstance" },
74 { fileOperation::PROCINSTANCE,
"localProcInstance" }
83 int Foam::fileOperation::nProcsFilter_(-1);
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);
224 const word& constantName
228 bool haveConstant =
false;
230 if (!constantName.empty())
232 for (
const fileName& dirName : dirEntries)
234 if (dirName == constantName)
247 times[nTimes].value() = 0;
248 times[nTimes].name() = constantName;
253 for (
const fileName& dirName : dirEntries)
255 if (readScalar(dirName, times[nTimes].value()))
257 times[nTimes].name() = dirName;
287 const auto& object0 =
names[0];
291 if (object0 !=
names[i])
308 fileName masterName(
name);
338 const word& constantName,
342 if (extraTimes.
size())
344 const bool haveConstant =
347 && times[0].name() == constantName
350 const bool haveExtraConstant =
353 && extraTimes[0].name() == constantName
360 if (haveExtraConstant)
365 combinedTimes[sz++] = extraTimes[0];
370 combinedTimes[sz++] = times[i];
372 for (; extrai < extraTimes.
size(); extrai++)
374 combinedTimes[sz++] = extraTimes[extrai];
380 if (times.
size() > 1)
383 if (times[0].
name() == constantName)
390 label newi = starti+1;
391 for (label i = newi; i < times.
size(); i++)
393 if (times[i].value() != times[i-1].value())
397 times[newi] = times[i];
440 const label targetNProcs
458 if (cacheLevel() > 0)
460 const auto iter = procsDirs_.cfind(procPath);
477 const bool readDirMasterOnly
490 if (readDirMasterOnly)
500 <<
"readDir on master: send " << dirEntries.
size()
501 <<
" names to sub-processes" <<
endl;
513 Pout<<
"readDir without special master/send treatment" 517 dirEntries =
readDir(
path, fileName::Type::DIRECTORY);
525 for (
const fileName& dirN : dirEntries)
530 const label readProci =
531 splitProcessorPath(dirN,
rp, rd, rl,
group, rNum);
533 nProcs =
max(nProcs, readProci+1);
537 if (proci == readProci)
540 pathTypeIdx.
first() = pathType::PROCUNCOLLATED;
544 if (targetNProcs > 1 && (targetNProcs != rNum))
558 nProcs =
max(nProcs, rNum);
564 if (proci < rNum || (nProcsFilter_ == 0))
569 pathTypeIdx.
first() = pathType::PROCBASEOBJECT;
570 pathTypeIdx.
second() = proci;
573 else if (
group.contains(proci) || (nProcsFilter_ == 0))
578 pathTypeIdx.
first() = pathType::PROCOBJECT;
583 if (pathTypeIdx.
first() != pathType::NOTFOUND)
585 procDirs.
append(dirIndex(dirN, pathTypeIdx));
590 sortProcessorDirs(procDirs);
599 unsigned int procDirsStatus = (procDirs.
empty() ? 1u : 2u);
603 Pout<<
"fileOperation::lookupProcessorsPath " << procPath
611 if (procDirsStatus == 3u)
622 int flavour(pathType::PROCUNCOLLATED);
623 for (
const dirIndex& pDir : procDirs)
625 flavour =
max(flavour,
int(pDir.second().first()));
631 if (procDirs.empty())
637 pathTypeIdx.
first() == pathType::PROCBASEOBJECT
642 pathTypeIdx.
second() = proci;
671 Pout<<
"fileOperation::lookupProcessorsPath " 673 <<
" synthetic:" << procDirs <<
endl;
687 if (procDirsStatus & 2u)
689 if (cacheLevel() > 0)
691 procsDirs_.insert(procPath, procDirs);
694 return procsDirs_[procPath];
710 return lookupAndCacheProcessorsPath(fName,
true);
740 if (originalPath != objPath)
745 ok =
isDir(originalPath);
768 const bool distributedRoots
771 comm_(commAndIORanks.first()),
773 distributed_(distributedRoots),
774 ioRanks_(commAndIORanks.second())
782 const bool distributedRoots
787 distributed_(distributedRoots),
808 const bool writeOnProc
815 mkDir(pathName.path());
852 const bool checkGzip,
853 const bool followLink
858 Pout<<
"fileOperation::filePath :" <<
" fName:" << fName <<
endl;
877 refPtr<dirIndexList> procDirs(lookupProcessorsPath(fName));
878 for (
const dirIndex& dirIdx : procDirs())
880 const fileName& procDir = dirIdx.first();
882 fileName collatedName(
path/procDir/
local);
883 if (
exists(collatedName, checkGzip, followLink))
887 Pout<<
"fileOperation::filePath : " << collatedName <<
endl;
889 foundName = collatedName;
895 if (foundName.empty())
899 if (
exists(fName, checkGzip, followLink))
901 if (foundName.empty())
908 if (!foundName.empty())
912 Pout<<
"fileOperation::filePath : " << foundName <<
endl;
919 Pout<<
"fileOperation::filePath : Not found" <<
endl;
928 return monitor().addWatch(fName);
934 return monitor().removeWatch(watchIndex);
946 if (getFile(watchIndices[i]) == fName)
968 const label index = findWatch(watchIndices,
f);
972 newWatchIndices.
append(addWatch(
f));
977 newWatchIndices.
append(watchIndices[index]);
978 removedWatches.
erase(index);
983 for (
const label index : removedWatches)
985 removeWatch(watchIndices[index]);
994 return monitor().getFile(watchIndex);
1000 const bool masterOnly,
1013 return monitor().getState(watchFd);
1019 monitor().setUnmodified(watchFd);
1026 const word& constantName
1031 Pout<<
"fileOperation::findTimes : Finding times in directory " 1032 << directory <<
endl;
1040 instantList times = sortTimes(dirEntries, constantName);
1044 refPtr<dirIndexList> procDirs(lookupProcessorsPath(directory));
1045 for (
const dirIndex& dirIdx : procDirs())
1047 const fileName& procDir = dirIdx.first();
1048 fileName collDir(processorsPath(directory, procDir));
1049 if (!collDir.empty() && collDir != directory)
1061 sortTimes(extraEntries, constantName),
1070 Pout<<
"fileOperation::findTimes : Found times:" <<
flatOutput(times)
1080 const scalar startValue,
1081 const word& stopInstance,
1082 const bool constant_fallback
1097 <<
"Found exact match for \"" <<
io.
name()
1107 enum failureCodes { FAILED_STOPINST = 1, FAILED_CONSTINST = 2 };
1113 label instIndex = ts.
size()-1;
1116 for (; instIndex >= 0; --instIndex)
1118 if (ts[instIndex].value() <= startValue)
1125 for (; instIndex >= 0; --instIndex)
1143 <<
"Found exact match for \"" <<
io.
name()
1154 <<
"Hit stopInstance " << stopInstance <<
endl;
1158 failed = failureCodes::FAILED_STOPINST;
1185 && (ts.empty() || ts[0].name() != time.
constant() || startValue < 0)
1193 <<
"Found constant match for \"" <<
io.
name()
1207 failed = failureCodes::FAILED_CONSTINST;
1209 else if (constant_fallback)
1230 <<
" file \"" <<
io.
name() <<
"\" in";
1236 << startIO.
instance() <<
" down to ";
1238 if (failed == failureCodes::FAILED_STOPINST)
1263 Pout<<
"fileOperation::readObjects :" 1265 <<
" instance" << instance
1281 newInstance.clear();
1286 newInstance = instance;
1292 fileName procsPath(filePath(
path));
1294 if (!procsPath.empty())
1296 newInstance = instance;
1297 objectNames =
Foam::readDir(procsPath, fileName::Type::FILE);
1332 foundDirs.
resize(wanted);
1337 for (
const fileName& dirN : dirNames)
1340 procRangeType
group;
1343 const label readProci =
1344 splitProcessorPath(dirN,
rp, rd, rl,
group, rNum);
1346 maxProc =
max(maxProc, readProci);
1351 maxProc =
max(maxProc, rNum-1);
1363 else if (readProci >= 0)
1366 foundDirs.
set(readProci);
1376 nProcs = gapIndex-1;
1379 if (nProcs == 0 &&
Foam::isDir(dir/processorsBaseDir))
1382 <<
"Defunct collated naming: " << processorsBaseDir <<
nl 1383 <<
"Manually rename with the decomposition number. Eg," 1385 <<
" mv processors processors16" <<
nl <<
nl 1386 <<
"...returning 1" <<
endl;
1400 Pout<<
"fileOperation::flush : clearing processor directories cache" 1411 Pout<<
"fileOperation::sync : parallel synchronisation" 1427 const word& procsDir
1437 const word& instance,
1438 const word& procsDir
1442 processorsCasePath(
io, procsDir)
1452 const word& procsDir
1458 if (caseName.starts_with(
"processor"))
1462 if (!std::isdigit(caseName[9]))
1465 <<
" does not end in old-style processorDDD" <<
endl;
1468 return dir.
path()/procsDir;
1487 label returnProci = -1;
1507 size_t slashLocal = string::npos;
1519 (
pos = objPath.find(
"processor",
pos)) != string::npos;
1523 if (
pos > 0 && objPath[
pos-1] !=
'/')
1530 size_t firstp =
pos + 9;
1535 const bool plural = (objPath[firstp] ==
's');
1541 else if (!std::isdigit(objPath[firstp]))
1548 slashLocal = objPath.find(
'/', firstp);
1551 const size_t lastp =
1552 (slashLocal == string::npos ? objPath.
length() : slashLocal);
1554 if (!std::isdigit(objPath[lastp-1]))
1578 objPath.substr(firstp, lastp-firstp),
1585 nProcs = nProcsRead;
1598 Foam::read(objPath.substr(firstp, lastp-firstp), proci)
1603 returnProci = proci;
1610 if (
pos != string::npos)
1617 path = objPath.substr(0,
pos-1);
1621 if (slashLocal != string::npos)
1623 procDir = objPath.substr(
pos, slashLocal-
pos);
1624 local = objPath.substr(slashLocal+1);
1628 procDir = objPath.substr(
pos);
1641 return splitProcessorPath(fName,
path, pDir,
local,
group, nProcs);
1653 const auto& fp = *iproxy;
1655 os <<
"fileHandler:" << fp.type()
1656 <<
" nProcs:" << fp.nProcs()
1657 <<
" comm:" << fp.comm()
1658 <<
" distributed:" << fp.distributed()
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.
Generic output stream using a standard (STL) stream.
void size(const label n)
Older name for setAddressableSize.
static std::string::size_type length(const char *s)
Length of the character sequence (with nullptr protection)
void set(const bitSet &bitset)
Set specified bits from another bitset.
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.
virtual IOobject findInstance(const IOobject &io, const scalar startValue, const word &stopInstance, const bool constant_fallback=true) const
Find time instance where IOobject is located. The name of the IOobject can be empty, in which case only the IOobject::local() is checked. Does not search beyond stopInstance (if set) or constant.
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.
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument 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...
label nProcs() const noexcept
Overall number of processors, from UPstream::nProcs() or detected from directories/results.
const word & name() const noexcept
Return the object name.
fileName processorsPath(const IOobject &io, const word &instance, const word &procDir) const
Generate path (like io.path) with provided instance and any.
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.
A range or interval of labels defined by a start and a size.
constexpr char nl
The newline '\n' character (0x0a)
bool empty() const noexcept
True if List 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.
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 /)
static label worldComm
Communicator for all ranks. May differ from commGlobal() if local worlds are in use.
static word processorsBaseDir
Return the processors directory name (usually "processors")
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
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)
label find_first_not() const
Locate the first bit that is unset.
An encapsulation of filesystem-related operations.
fileName objectPath() const
The complete path + object name.
static bool isReadRequired(readOption opt) noexcept
True if (MUST_READ | READ_MODIFIED) bits are set.
static void broadcast(Type &value, const label comm=UPstream::worldComm)
Broadcast content (contiguous or non-contiguous) to all communicator ranks. Does nothing in non-paral...
fileName path() const
The complete path for the object (with instance, local,...).
void resize(const label numElem, const unsigned int val=0u)
Reset addressable list size, does not shrink the allocated size.
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.
#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?
virtual void updateStates(const bool masterOnly, const bool syncPar) const
Update state of all files.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
dimensionedScalar pos(const dimensionedScalar &ds)
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run. ...
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.
IOList< label > labelIOList
IO for a List of label.
void setSize(const label n)
Alias for resize()
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 expressions::valueTypeCode::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.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
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 instantList findTimes(const fileName &, const word &) const
Get sorted list of times.
void sort(UList< T > &list)
Sort the list.
virtual bool writeObject(const regIOobject &io, IOstreamOption streamOpt=IOstreamOption(), const bool writeOnProc=true) const
Writes a regIOobject (so header, contents and divider).
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,.
const fileName & globalCaseName() const noexcept
Return the Time::globalCaseName()
virtual label addWatch(const fileName &) const
Add watching of a file. Returns handle.
void append(const T &val)
Copy append an element to the end of this list.
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 (respects is_globalIOobject trait) and check its info.
#define DebugInfo
Report an information message using Foam::Info.
const Time & time() const noexcept
Return Time associated with the objectRegistry.
static void mergeTimes(const instantList &extraTimes, const word &constantName, instantList ×)
Merge two times.
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
const labelList & watchIndices() const noexcept
Read access to file-monitoring handles.
virtual void sync()
Forcibly parallel sync.
static std::string name(const std::string &str)
Return basename (part beyond last /), including its extension.
const word & constant() const noexcept
Return constant name.
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
int debug
Static debugging option.
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.
fileName processorsCasePath(const IOobject &io, const word &procDir) const
Generate path (like io.path) from root+casename with any.
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 void broadcasts(const label comm, Type &arg1, Args &&... args)
Broadcast multiple items to all communicator ranks. Does nothing in non-parallel. ...
bool erase(const iterator &iter)
Erase an entry specified by given iterator.
static bool isFileOrDir(const bool isFile, const fileName &)
Helper: check for file (isFile) or directory (!isFile)
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 fileName & rootPath() const noexcept
Return the Time::rootPath()
A helper class for outputting values to Ostream.
instantList times() const
Search the case for valid time directories.
static word defaultFileHandler
Name of the default fileHandler.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
#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...
static List< int > & procID(const label communicator)
The list of ranks within a given communicator.
const objectRegistry & parent() const noexcept
Return the parent objectRegistry.
bool good() const noexcept
True if next operation might succeed.
static int cacheLevel_
Cache level (eg, for caching time directories). Default: 1.
const T2 & second() const noexcept
Access the second element.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
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.
fileOperation(const label comm, const labelUList &ioRanks=labelUList::null(), const bool distributedRoots=false)
Construct from communicator, optionally with specified io-ranks and/or distributed roots...
dictionary & optimisationSwitches()
The OptimisationSwitches sub-dictionary in the central controlDict(s).
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
iterator end() noexcept
Return an iterator to end traversing the UList.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
List< instant > instantList
List of instants.
Registry of regIOobjects.
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.
List< fileName > fileNameList
List of fileName.
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.
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.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Inter-processor communications stream.
void reduce(T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce) using linear/tree communication schedule.
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.