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" }
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);
226 const word& constantName
230 bool haveConstant =
false;
232 if (!constantName.empty())
234 for (
const fileName& dirName : dirEntries)
236 if (dirName == constantName)
249 times[nTimes].value() = 0;
250 times[nTimes].name() = constantName;
255 for (
const fileName& dirName : dirEntries)
257 if (readScalar(dirName, times[nTimes].value()))
259 times[nTimes].name() = dirName;
289 const auto& object0 =
names[0];
293 if (object0 !=
names[i])
310 fileName masterName(
name);
340 const word& constantName,
344 if (extraTimes.
size())
346 const bool haveConstant =
349 && times[0].name() == constantName
352 const bool haveExtraConstant =
355 && extraTimes[0].name() == constantName
362 if (haveExtraConstant)
367 combinedTimes[sz++] = extraTimes[0];
372 combinedTimes[sz++] = times[i];
374 for (; extrai < extraTimes.
size(); extrai++)
376 combinedTimes[sz++] = extraTimes[extrai];
382 if (times.
size() > 1)
385 if (times[0].
name() == constantName)
392 label newi = starti+1;
393 for (label i = newi; i < times.
size(); i++)
395 if (times[i].value() != times[i-1].value())
399 times[newi] = times[i];
445 if (cacheLevel() > 0)
447 const auto iter = procsDirs_.cfind(procPath);
464 const bool readDirMasterOnly
477 if (readDirMasterOnly)
487 <<
"readDir on master: send " << dirEntries.
size()
488 <<
" names to sub-processes" <<
endl;
500 Pout<<
"readDir without special master/send treatment" 504 dirEntries =
readDir(
path, fileName::Type::DIRECTORY);
512 for (
const fileName& dirN : dirEntries)
517 const label readProci =
518 splitProcessorPath(dirN,
rp, rd, rl,
group, rNum);
520 nProcs =
max(nProcs, readProci+1);
524 if (proci == readProci)
527 pathTypeIdx.
first() = pathType::PROCUNCOLLATED;
532 nProcs =
max(nProcs, rNum);
543 pathTypeIdx.
first() = pathType::PROCBASEOBJECT;
544 pathTypeIdx.
second() = proci;
547 else if (
group.contains(proci))
552 pathTypeIdx.
first() = pathType::PROCOBJECT;
557 if (pathTypeIdx.
first() != pathType::NOTFOUND)
559 procDirs.
append(dirIndex(dirN, pathTypeIdx));
569 unsigned procDirsStatus = (procDirs.
empty() ? 1u : 2u);
573 Pout<<
"fileOperation::lookupProcessorsPath " << procPath
574 <<
" detected:" << procDirs <<
endl;
581 if (procDirsStatus == 3u)
592 int flavour(pathType::PROCUNCOLLATED);
593 for (
const dirIndex& pDir : procDirs)
595 flavour =
max(flavour,
int(pDir.second().first()));
601 if (procDirs.empty())
607 pathTypeIdx.
first() == pathType::PROCBASEOBJECT
612 pathTypeIdx.
second() = proci;
641 Pout<<
"fileOperation::lookupProcessorsPath " 643 <<
" synthetic:" << procDirs <<
endl;
660 if (procDirsStatus & 2u)
662 if (cacheLevel() > 0)
664 procsDirs_.insert(procPath, procDirs);
667 return procsDirs_[procPath];
684 return lookupAndCacheProcessorsPath(fName,
true);
714 if (originalPath != objPath)
719 ok =
isDir(originalPath);
742 const bool distributedRoots
745 comm_(commAndIORanks.first()),
747 distributed_(distributedRoots),
748 ioRanks_(commAndIORanks.second())
756 const bool distributedRoots
761 distributed_(distributedRoots),
782 const bool writeOnProc
789 mkDir(pathName.path());
826 const bool checkGzip,
827 const bool followLink
832 Pout<<
"fileOperation::filePath :" <<
" fName:" << fName <<
endl;
850 refPtr<dirIndexList> procDirs(lookupProcessorsPath(fName));
851 for (
const dirIndex& dirIdx : procDirs())
853 const fileName& procDir = dirIdx.first();
855 fileName collatedName(
path/procDir/
local);
856 if (
exists(collatedName, checkGzip, followLink))
860 Pout<<
"fileOperation::filePath : " << collatedName <<
endl;
867 if (
exists(fName, checkGzip, followLink))
871 Pout<<
"fileOperation::filePath : " << fName <<
endl;
878 Pout<<
"fileOperation::filePath : Not found" <<
endl;
887 return monitor().addWatch(fName);
893 return monitor().removeWatch(watchIndex);
905 if (getFile(watchIndices[i]) == fName)
927 const label index = findWatch(watchIndices,
f);
931 newWatchIndices.
append(addWatch(
f));
936 newWatchIndices.
append(watchIndices[index]);
937 removedWatches.
erase(index);
942 for (
const label index : removedWatches)
944 removeWatch(watchIndices[index]);
953 return monitor().getFile(watchIndex);
959 const bool masterOnly,
972 return monitor().getState(watchFd);
978 monitor().setUnmodified(watchFd);
985 const word& constantName
990 Pout<<
"fileOperation::findTimes : Finding times in directory " 991 << directory <<
endl;
999 instantList times = sortTimes(dirEntries, constantName);
1003 refPtr<dirIndexList> procDirs(lookupProcessorsPath(directory));
1004 for (
const dirIndex& dirIdx : procDirs())
1006 const fileName& procDir = dirIdx.first();
1007 fileName collDir(processorsPath(directory, procDir));
1008 if (!collDir.empty() && collDir != directory)
1020 sortTimes(extraEntries, constantName),
1029 Pout<<
"fileOperation::findTimes : Found times:" <<
flatOutput(times)
1039 const scalar startValue,
1040 const word& stopInstance
1055 <<
"Found exact match for \"" <<
io.
name()
1065 enum failureCodes { FAILED_STOPINST = 1, FAILED_CONSTINST = 2 };
1071 label instIndex = ts.
size()-1;
1074 for (; instIndex >= 0; --instIndex)
1076 if (ts[instIndex].value() <= startValue)
1083 for (; instIndex >= 0; --instIndex)
1101 <<
"Found exact match for \"" <<
io.
name()
1112 <<
"Hit stopInstance " << stopInstance <<
endl;
1116 failed = failureCodes::FAILED_STOPINST;
1142 && (ts.empty() || ts[0].name() != time.
constant() || startValue < 0)
1150 <<
"Found constant match for \"" <<
io.
name()
1160 if (!failed && exitIfMissing)
1162 failed = failureCodes::FAILED_CONSTINST;
1175 <<
" file \"" <<
io.
name() <<
"\" in";
1181 << startIO.
instance() <<
" down to ";
1183 if (failed == failureCodes::FAILED_STOPINST)
1208 Pout<<
"fileOperation::readObjects :" 1210 <<
" instance:" << instance <<
endl;
1215 newInstance.clear();
1220 newInstance = instance;
1226 fileName procsPath(filePath(
path));
1228 if (!procsPath.empty())
1230 newInstance = instance;
1251 for (
const fileName& dirN : dirNames)
1254 procRangeType
group;
1257 const label readProci =
1258 splitProcessorPath(dirN,
rp, rd, rl,
group, rNum);
1260 maxProc =
max(maxProc, readProci);
1270 if (nProcs == 0 &&
Foam::isDir(dir/processorsBaseDir))
1273 <<
"Defunct collated naming: " << processorsBaseDir <<
nl 1274 <<
"Manually rename with the decomposition number. Eg," 1276 <<
" mv processors processors16" <<
nl <<
nl 1277 <<
"...returning 1" <<
endl;
1291 Pout<<
"fileOperation::flush : clearing processor directories cache" 1302 Pout<<
"fileOperation::sync : parallel synchronisation" 1318 const word& procsDir
1328 const word& instance,
1329 const word& procsDir
1333 processorsCasePath(
io, procsDir)
1343 const word& procsDir
1349 if (caseName.starts_with(
"processor"))
1353 if (!std::isdigit(caseName[9]))
1356 <<
" does not end in old-style processorDDD" <<
endl;
1359 return dir.
path()/procsDir;
1373 procRangeType&
group,
1378 label returnProci = -1;
1398 size_t slashLocal = string::npos;
1410 (
pos = objPath.find(
"processor",
pos)) != string::npos;
1414 if (
pos > 0 && objPath[
pos-1] !=
'/')
1421 size_t firstp =
pos + 9;
1426 const bool plural = (objPath[firstp] ==
's');
1432 else if (!std::isdigit(objPath[firstp]))
1439 slashLocal = objPath.find(
'/', firstp);
1442 const size_t lastp =
1443 (slashLocal == string::npos ? objPath.length() : slashLocal);
1445 if (!std::isdigit(objPath[lastp-1]))
1469 objPath.substr(firstp, lastp-firstp),
1476 nProcs = nProcsRead;
1489 Foam::read(objPath.substr(firstp, lastp-firstp), proci)
1494 returnProci = proci;
1501 if (
pos != string::npos)
1508 path = objPath.substr(0,
pos-1);
1512 if (slashLocal != string::npos)
1514 procDir = objPath.substr(
pos, slashLocal-
pos);
1515 local = objPath.substr(slashLocal+1);
1519 procDir = objPath.substr(
pos);
1530 procRangeType
group;
1532 return splitProcessorPath(fName,
path, pDir,
local,
group, nProcs);
1544 const auto& fp = *iproxy;
1546 os <<
"fileHandler:" << fp.type()
1547 <<
" nProcs:" << fp.nProcs()
1548 <<
" comm:" << fp.comm()
1549 <<
" 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.
List< instant > instantList
List of instants.
Generic output stream using a standard (STL) stream.
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.
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.
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)
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 processes in communicator.
fileName path() const
The complete path.
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)
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 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 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.
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,.
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 (uses typeFilePath to find file) 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 processes in communicator.
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)
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?
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.
#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.
static List< int > & procID(const label communicator)
The list of ranks within a given communicator.
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.
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.
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)
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.
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.