47 namespace fileOperations
53 masterUncollatedFileOperation,
59 masterUncollatedFileOperation,
69 "maxMasterFileBufferSize",
77 fileOperationInitialise,
78 fileOperationInitialise_unthreaded,
91 const bool checkGlobal,
94 const dirIndexList& pDirs,
102 newInstancePath.clear();
104 if (
io.instance().isAbsolute())
131 if (
io.time().processorCase())
133 for (
const dirIndex& dirIdx : pDirs)
135 const fileName& pDir = dirIdx.first();
141 searchType = dirIdx.second().first();
149 fileName localPath =
io.objectPath();
153 localPath != writePath
168 &&
io.time().processorCase()
170 io.instance() ==
io.time().system()
171 ||
io.instance() ==
io.time().constant()
175 fileName parentPath =
177 io.rootPath()/
io.globalCaseName()
178 /
io.instance()/
io.db().dbDir()/
io.local()/
io.name()
190 const auto pathFnd =
times_.cfind(
io.time().path());
192 if (
search && pathFnd.good())
198 instant(
io.instance())
201 if (newInstancePath.size() && newInstancePath !=
io.instance())
204 for (
const dirIndex& dirIdx : pDirs)
206 const fileName& pDir = dirIdx.first();
215 switch (dirIdx.second().first())
245 io.rootPath()/
io.caseName()
246 /newInstancePath/
io.db().dbDir()/
io.local()/
io.name()
267 const pathType& searchType,
269 const word& instancePath
278 return io.instance()/
io.name();
284 return io.path()/
io.name();
290 return objectPath(
io,
io.headerClassName());
320 processorsPath(
io,
io.instance(), procDir)
329 processorsPath(
io,
io.instance(), processorsDir(
io))
337 io.rootPath()/
io.globalCaseName()
338 /
io.instance()/
io.db().dbDir()/
io.local()/
io.name();
345 io.rootPath()/
io.caseName()
346 /instancePath/
io.db().dbDir()/
io.local()/
io.name();
377 processorsPath(
io, instancePath, procDir)
386 processorsPath(
io, instancePath, processorsDir(
io))
408 const fileName& filePath,
410 PstreamBuffers& pBufs
413 if (recvProcs.empty())
return;
420 <<
"Cannot open file " << filePath
429 Info<<
"masterUncollatedFileOperation::readAndSend :" 431 <<
" (compressed:" << bool(ifs.compression())
432 <<
") : " <<
" bytes" <<
endl;
435 for (
const label proci : recvProcs)
437 UOPstream
os(proci, pBufs);
438 os.write(buf.cdata_bytes(), buf.size_bytes());
463 if (filePaths[0].empty())
466 <<
"Cannot find file " <<
io.objectPath()
467 <<
" fileHandler : comm:" << comm
475 if (readOnProcs[proci])
485 Pout<<
"masterUncollatedFileOperation::readStream :" 486 <<
" For uniform file " << filePaths[0]
487 <<
" sending to " << recvProcs
488 <<
" in comm:" << comm <<
endl;
490 readAndSend(filePaths[0], recvProcs, pBufs);
497 if (filePaths[0].empty())
500 <<
"Cannot find file " <<
io.objectPath()
501 <<
" fileHandler : comm:" << comm
507 isPtr.
reset(
new IFstream(filePaths[0]));
510 if (!
io.readHeader(*isPtr))
513 <<
"problem while reading header for object " 515 <<
" fileHandler : comm:" << comm
526 Pout<<
"masterUncollatedFileOperation::readStream :" 527 <<
" For processor " << proci
528 <<
" opening " << filePaths[proci] <<
endl;
531 const fileName& fPath = filePaths[proci];
533 if (readOnProcs[proci] && !fPath.empty())
537 readAndSend(fPath,
labelList(one{}, proci), pBufs);
559 is.read(buf.data(), buf.size());
564 Pout<<
"masterUncollatedFileOperation::readStream :" 565 <<
" Done reading " << buf.size() <<
" bytes" <<
endl;
572 isPtr.
reset(
new ICharStream(std::move(buf)));
577 if (!
io.readHeader(*isPtr))
580 <<
"problem while reading header for object " 582 <<
" fileHandler : comm:" << comm
589 isPtr.
reset(
new dummyISstream());
622 return commAndIORanks;
630 void Foam::fileOperations::masterUncollatedFileOperation::init(
bool verbose)
637 <<
"I/O : " << typeName
638 <<
" (maxMasterFileBufferSize " << maxMasterFileBufferSize <<
')' 647 <<
"Resetting fileModificationChecking to timeStamp" <<
endl;
656 <<
"Resetting fileModificationChecking to inotify" 674 managedComm_(getManagedComm(comm_))
701 const bool distributedRoots,
732 managedComm_ = getManagedComm(comm_);
753 return masterOp<bool>
769 return masterOp<bool>
782 const bool followLink
785 return masterOp<mode_t>
798 const bool followLink
817 const bool checkGzip,
818 const bool followLink
821 return masterOp<bool>
824 existsOp(checkGzip, followLink),
834 const bool followLink
837 return masterOp<bool>
850 const bool checkGzip,
851 const bool followLink
854 return masterOp<bool>
857 isFileOp(checkGzip, followLink),
867 const bool followLink
878 fileSizeOp(followLink),
889 const bool followLink
895 if constexpr (std::is_integral_v<time_t>)
904 lastModifiedOp(followLink),
912 return masterOp<time_t>
915 lastModifiedOp(followLink),
926 const bool followLink
929 return masterOp<double>
932 highResLastModifiedOp(followLink),
942 const std::string& ext
945 return masterOp<bool>
960 return masterOp<bool>
977 return masterOp<bool>
980 rmDirOp(silent, emptyOnly),
992 const bool followLink
995 return masterOp<fileNameList>
998 readDirOp(
type, filtergz, followLink),
1009 const bool followLink
1012 return masterOp<bool>
1029 return masterOp<bool>
1044 const bool followLink
1047 return masterOp<bool>
1062 const bool checkGlobal,
1064 const word& typeName,
1070 Pout<<
"masterUncollatedFileOperation::filePath :" 1071 <<
" objectPath:" <<
io.objectPath()
1072 <<
" checkGlobal:" << checkGlobal
1082 if (cacheLevel() > 0)
1084 (void)findTimes(
io.time().path(),
io.time().constant());
1090 pathType searchType = NOTFOUND;
1092 word newInstancePath;
1115 const_cast<masterUncollatedFileOperation&
>(*this).nProcs(oldNProcs);
1121 Pout<<
"masterUncollatedFileOperation::filePath :" 1122 <<
" master objPath:" << objPath
1124 <<
" procsDir:" << procsDir <<
" instance:" << newInstancePath
1135 int masterType(searchType);
1137 searchType = pathType(masterType);
1146 ||
io.local() ==
"uniform" 1178 objPath = localObjectPath
1194 objPath = masterOp<fileName>
1208 Pout<<
"masterUncollatedFileOperation::filePath :" 1209 <<
" Returning from file searching using type " 1211 <<
" objectPath:" <<
io.objectPath() <<
endl 1220 const bool checkGlobal,
1227 Pout<<
"masterUncollatedFileOperation::dirPath :" 1228 <<
" objectPath:" <<
io.objectPath()
1229 <<
" checkGlobal:" << checkGlobal
1236 const refPtr<dirIndexList> pDirs(lookupProcessorsPath(
io.objectPath()));
1239 if (cacheLevel() > 0)
1241 (void)findTimes(
io.time().path(),
io.time().constant());
1247 pathType searchType = NOTFOUND;
1249 word newInstancePath;
1258 objPath = filePathInfo
1270 const_cast<masterUncollatedFileOperation&
>(*this).nProcs(oldNProcs);
1276 Pout<<
"masterUncollatedFileOperation::dirPath :" 1277 <<
" master objPath:" << objPath
1279 <<
" procsDir:" << procsDir <<
" instance:" << newInstancePath
1291 int masterType(searchType);
1293 searchType = pathType(masterType);
1303 ||
io.local() ==
"uniform" 1336 objPath = localObjectPath
1352 objPath = masterOp<fileName>
1355 fileOrNullOp(
false),
1366 Pout<<
"masterUncollatedFileOperation::dirPath :" 1367 <<
" Returning from directory searching using type " 1369 <<
" objectPath:" <<
io.objectPath() <<
endl 1378 const dirIndexList& pDirs,
1385 const bool isFile = !
io.name().empty();
1391 if (isFileOrDir(
isFile, writePath))
1397 if (
io.time().processorCase())
1399 for (
const dirIndex& dirIdx : pDirs)
1401 const fileName& pDir = dirIdx.first();
1403 processorsPath(
io,
io.instance(), pDir)
1405 if (procPath != writePath && isFileOrDir(
isFile, procPath))
1413 fileName localPath =
io.objectPath();
1415 if (localPath != writePath && isFileOrDir(
isFile, localPath))
1428 const scalar startValue,
1429 const word& stopInstance,
1430 const bool constant_fallback
1435 Pout<<
"masterUncollatedFileOperation::findInstance :" 1436 <<
" Starting searching for name:" << startIO.
name()
1437 <<
" local:" << startIO.
local()
1438 <<
" from instance:" << startIO.
instance()
1465 foundInstance =
io.instance();
1467 const_cast<masterUncollatedFileOperation&
>(*this).nProcs(oldNProcs);
1476 if (!foundInstance.empty())
1478 io.instance() = foundInstance;
1481 Pout<<
"masterUncollatedFileOperation::findInstance :" 1482 <<
" for name:" <<
io.name() <<
" local:" <<
io.local()
1483 <<
" found starting instance:" <<
io.instance() <<
endl;
1492 enum failureCodes { FAILED_STOPINST = 1, FAILED_CONSTINST = 2 };
1504 label instIndex = ts.size()-1;
1507 for (; instIndex >= 0; --instIndex)
1509 if (ts[instIndex].value() <= startValue)
1516 for (; instIndex >= 0; --instIndex)
1525 io.instance() = ts[instIndex].name();
1528 foundInstance =
io.instance();
1531 Pout<<
"masterUncollatedFileOperation::findInstance :" 1532 <<
" for name:" <<
io.name() <<
" local:" <<
io.local()
1533 <<
" found at:" <<
io.instance()
1540 if (
io.instance() == stopInstance)
1544 Pout<<
"masterUncollatedFileOperation::findInstance :" 1545 <<
" name:" <<
io.name()
1546 <<
" local:" <<
io.local()
1547 <<
" at stop-instance:" <<
io.instance() <<
endl;
1552 failed = failureCodes::FAILED_STOPINST;
1557 foundInstance =
io.instance();
1578 !failed && foundInstance.empty()
1579 && (ts.empty() || ts[0].name() != time.
constant() || startValue < 0)
1593 Pout<<
"masterUncollatedFileOperation::findInstance :" 1594 <<
" name:" <<
io.name()
1595 <<
" local:" <<
io.local()
1596 <<
" at:" <<
io.instance() <<
endl;
1598 foundInstance =
io.instance();
1602 if (!failed && foundInstance.empty())
1606 failed = failureCodes::FAILED_CONSTINST;
1608 else if (constant_fallback)
1614 foundInstance.clear();
1618 const_cast<masterUncollatedFileOperation&
>(*this).nProcs(oldNProcs);
1625 io.instance() = foundInstance;
1634 if (!
io.name().empty())
1637 <<
" file \"" <<
io.name() <<
"\" in";
1642 <<
io.local() <<
" in times " 1643 << startIO.
instance() <<
" down to ";
1645 if (failed == failureCodes::FAILED_STOPINST)
1658 Pout<<
"masterUncollatedFileOperation::findInstance :" 1659 <<
" name:" <<
io.name() <<
" local:" <<
io.local()
1660 <<
" returning instance:" <<
io.instance() <<
endl;
1677 Pout<<
"masterUncollatedFileOperation::readObjects :" 1679 <<
" local:" <<
local <<
" instance:" << instance <<
endl;
1683 newInstance.clear();
1705 if (newInstance.empty())
1725 if (!foundInst.empty())
1737 const_cast<masterUncollatedFileOperation&
>(*this).nProcs(oldNProcs);
1746 Pout<<
"masterUncollatedFileOperation::readObjects :" 1747 <<
" newInstance:" << newInstance
1748 <<
" objectNames:" << objectNames <<
endl;
1759 const word& typeName
1766 Pout<<
"masterUncollatedFileOperation::readHeader :" <<
endl 1767 <<
" objectPath:" <<
io.objectPath() <<
endl 1768 <<
" filePath :" << fName <<
endl;
1809 io.headerClassName(),
1833 result.resize(np,
false);
1834 headerClassName.resize(np);
1839 if (!filePaths[proci].empty())
1841 if (proci > 0 && filePaths[proci] == filePaths[proci-1])
1843 result[proci] = result[proci-1];
1844 headerClassName[proci] = headerClassName[proci-1];
1845 note[proci] = note[proci-1];
1849 IFstream is(filePaths[proci]);
1855 headerClassName[proci] =
io.headerClassName();
1856 note[proci] =
io.note();
1864 PstreamBuffers pBufs(comm_);
1869 io.headerClassName() = headerClassName[0];
1870 io.note() = note[0];
1873 for (
const int proci : pBufs.
subProcs())
1875 UOPstream
os(proci, pBufs);
1876 os << result[proci] << headerClassName[proci] << note[proci];
1885 is >> ok >>
io.headerClassName() >>
io.note();
1891 Pout<<
"masterUncollatedFileOperation::readHeader :" <<
" ok:" << ok
1892 <<
" class:" <<
io.headerClassName()
1893 <<
" for file:" << fName <<
endl;
1904 const word& typeName,
1905 const bool readOnProc
1910 Pout<<
"masterUncollatedFileOperation::readStream :" 1911 <<
" object : " <<
io.name()
1912 <<
" global : " <<
io.global()
1913 <<
" globalObject : " <<
io.globalObject()
1914 <<
" fName : " << fName <<
" readOnProc:" << readOnProc <<
endl;
1921 bool isCollated =
false;
1941 headerIO.readHeader(*isPtr);
1951 Pout<<
"masterUncollatedFileOperation::readStream :" 1952 <<
" For object : " <<
io.name()
1953 <<
" doing straight IFstream input from " 1958 io.IOobject::operator=(headerIO);
1977 Pout<<
"masterUncollatedFileOperation::readStream :" 1978 <<
" For object : " <<
io.name()
1979 <<
" starting collating input from " << fName <<
endl;
1988 procRangeType
group;
1997 label proci = detectProcessorPath(
io.objectPath());
2002 <<
"Could not detect processor number" 2003 <<
" from objectPath:" <<
io.objectPath()
2004 <<
" fileHandler : comm:" << comm_
2012 proci = proci -
group.start();
2017 Pout<<
"masterUncollatedFileOperation::readStream :" 2018 <<
" For object : " <<
io.name()
2019 <<
" starting input from block " << proci
2020 <<
" of " << isPtr->name() <<
endl;
2029 label readComm = -1;
2037 isPtr.
reset(
new IFstream(fName));
2042 IOobject headerIO(
io);
2043 headerIO.readHeader(*isPtr);
2054 bool bigSize =
false;
2062 > off_t(maxMasterFileBufferSize)
2091 Pout<<
"masterUncollatedFileOperation::readStream :" 2092 <<
" For object : " <<
io.name()
2093 <<
" starting separated input from " << fName <<
endl;
2096 if (
io.global() ||
io.globalObject())
2111 UPstream::listGatherValues<bool>
2138 UPstream::listGatherValues<bool>
2151 return read(
io, comm_, uniform, filePaths, readOnProcs);
2160 const bool masterOnly,
2162 const word& typeName
2167 if (
io.global() ||
io.globalObject())
2171 Pout<<
"masterUncollatedFileOperation::read :" 2172 <<
" Reading global object " <<
io.name()
2174 <<
" Pstream::myProcNo:" 2187 auto& is =
io.readStream(typeName);
2188 ok =
io.readData(is);
2191 const_cast<masterUncollatedFileOperation&
>(*this).nProcs(oldNProcs);
2203 os <<
io.headerClassName() <<
io.note();
2204 bool okWrite =
io.writeData(
os);
2211 is >>
io.headerClassName() >>
io.note();
2212 ok =
io.readData(is);
2220 Pout<<
"masterUncollatedFileOperation::read :" 2221 <<
" Reading local object " <<
io.name() <<
endl;
2224 ok =
io.readData(
io.readStream(typeName));
2230 Pout<<
"masterUncollatedFileOperation::read :" 2231 <<
" Read object:" <<
io.name()
2232 <<
" isGlobal:" << (
io.global() ||
io.globalObject())
2233 <<
" status:" << ok <<
endl;
2244 const bool writeOnProc
2251 Pout<<
"masterUncollatedFileOperation::writeObject :" 2252 <<
" io:" << pathName <<
" writeOnProc:" << writeOnProc <<
endl;
2269 &&
io.writeHeader(
os)
2285 const word& constantName
2288 const auto iter = times_.cfind(directory);
2293 Pout<<
"masterUncollatedFileOperation::findTimes :" 2294 <<
" Found " << iter.val()->size() <<
" cached times" <<
nl 2295 <<
" for directory:" << directory <<
endl;
2297 return *(iter.val());
2311 const_cast<masterUncollatedFileOperation&
>(*this).nProcs(oldNProcs);
2320 Pout<<
"masterUncollatedFileOperation::findTimes :" 2322 <<
" for directory:" << directory <<
endl;
2328 if (cacheLevel() > 0)
2330 auto* tPtr =
new DynamicList<instant>(std::move(times));
2331 times_.set(directory, tPtr);
2355 auto iter = times_.find(tm.
path());
2359 DynamicList<instant>& times = *(iter.val());
2364 const label startIdx =
2366 (times.empty() || times[0].name() != tm.
constant())
2375 if (times.size() <= startIdx || times.last() < timeNow)
2383 SubList<instant>(times, times.size()-startIdx, startIdx),
2390 Pout<<
"masterUncollatedFileOperation::setTime :" 2391 <<
" Caching time " << tm.
timeName()
2392 <<
" for case:" << tm.
path() <<
endl;
2395 times.append(timeNow);
2397 SubList<instant> realTimes
2399 times, times.size()-startIdx, startIdx
2437 Pout<<
"masterUncollatedFileOperation::NewIFstream :" 2438 <<
" Opening global file " << filePath <<
endl;
2454 Pout<<
"masterUncollatedFileOperation::NewIFstream :" 2455 <<
" Opening local file " << filePath
2456 <<
" for rank " << proci <<
endl;
2481 Pout<<
"masterUncollatedFileOperation::NewIFstream :" 2482 <<
" Reading " << filePath
2491 is.
read(buf.data(), buf.size());
2496 Pout<<
"masterUncollatedFileOperation::NewIFstream :" 2497 <<
" Done reading " << buf.size() <<
" bytes" <<
endl;
2507 isPtr->name() = filePath;
2525 const bool writeOnProc
2548 const bool writeOnProc
2577 Pout<<
"masterUncollatedFileOperation::sync :" 2578 <<
" syncing information across processors" <<
endl;
2589 timeNames.
resize(times_.size());
2590 instants.
resize(times_.size());
2596 timeNames[i] = iter.key();
2597 instants[i] = std::move(*(iter.val()));
2607 fileName dir(timeNames[i]);
2608 auto ptr = autoPtr<DynamicList<instant>>
::New(std::move(instants[i]));
2616 procRangeType
group;
2618 const label proci = splitProcessorPath
2637 if (proci != -1 && proci != myProci)
2643 times_.insert(dir, ptr);
2656 watchFd = monitor().addWatch(fName);
2666 const label watchIndex
2672 ok = monitor().removeWatch(watchIndex);
2692 if (monitor().getFile(watchIndices[i]) == fName)
2728 const label index = findWatch(watchIndices,
f);
2737 newWatchIndices.
push_back(watchIndices[index]);
2738 removedWatches.
erase(index);
2743 for (
const label index : removedWatches)
2745 removeWatch(watchIndices[index]);
2760 const label watchIndex
2766 fName = monitor().getFile(watchIndex);
2776 const bool masterOnly,
2782 monitor().updateStates(
true,
false);
2796 state = monitor().getState(watchFd);
2811 monitor().setUnmodified(watchFd);
virtual void storeComm() const
Transfer ownership of communicator to this fileOperation. Use with caution.
virtual mode_t mode(const fileName &, const bool followLink=true) const
Return the file mode.
fileName localObjectPath(const IOobject &, const pathType &searchType, const word &processorsDir, const word &instancePath) const
Construct filePath.
virtual bool isFile(const fileName &, const bool checkGzip=true, const bool followLink=true) const
Does the name exist as a FILE in the file system?
virtual fileMonitor::fileState getState(const label) const
Get current state of file (using handle)
static const Enum< pathType > pathTypeNames_
Generic output stream using a standard (STL) stream.
virtual bool cp(const fileName &src, const fileName &dst, const bool followLink=true) const
Copy, recursively if necessary, the source to the destination.
const Type & value() const noexcept
Return const reference to value.
virtual bool chMod(const fileName &, const mode_t) const
Set the file mode.
virtual bool mv(const fileName &src, const fileName &dst, const bool followLink=false) const
Rename src to dst.
fileName path() const
Return path = rootPath/caseName. Same as TimePaths::path()
virtual fileNameList readDir(const fileName &, const fileName::Type=fileName::FILE, const bool filtergz=true, const bool followLink=true) const
Read a directory and return the entries as a string list.
Input/output streams with (internal or external) character storage.
A class for handling file names.
off_t fileSize(const fileName &name, const bool followLink=true)
Return size of file or -1 on failure (normally follows symbolic links).
virtual time_t lastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
errorManipArg< error, int > exit(error &err, const int errNo=1)
virtual label addWatch(const fileName &) const
Add watching of a file. Returns handle.
as PROCUNCOLLATED but with instance
HashPtrTable< DynamicList< instant > > times_
Cached times for a given directory.
masterUncollatedFileOperation(bool verbose=false)
Default construct.
void resize(const label len)
Adjust allocated size of list.
commsTypes
Communications types.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
static void broadcasts(const int communicator, Type &value, Args &&... values)
Broadcast multiple items to all communicator ranks. Does nothing in non-parallel. ...
void finishedScatters(const bool wait=true)
Mark all sends to sub-procs as done.
#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.
void append(const T &val)
Append an element at the end of the list.
static autoPtr< ISstream > read(IOobject &io, const label comm, const bool uniform, const fileNameList &filePaths, const boolUList &readOnProcs)
Read files on comms master.
const word & name() const noexcept
Return the object name.
virtual autoPtr< ISstream > NewIFstream(const fileName &) const
Generate an ISstream that reads a file.
fileName processorsPath(const IOobject &io, const word &instance, const word &procDir) const
Generate path (like io.path) with provided instance and any.
static autoPtr< ISstream > readBlock(const label blocki, ISstream &is, IOobject &headerIO)
Read selected block (non-seeking) + header information.
static void freeCommunicator(const label communicator, const bool withComponents=true)
Free a previously allocated communicator.
fileState
Enumeration defining the file state.
static rangeType allProcs(const label communicator=worldComm)
Range of process indices for all processes.
int infoDetailLevel
Global for selective suppression of Info output.
virtual double highResLastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
constexpr char nl
The newline '\n' character (0x0a)
virtual bool readHeader(IOobject &, const fileName &, const word &typeName) const
Read object header from supplied file.
static label newCommunicator(const label parent, const labelRange &subRanks, const bool withComponents=true)
Create new communicator with sub-ranks on the parent communicator.
virtual bool isDir(const fileName &, const bool followLink=true) const
Does the name exist as a DIRECTORY in the file system?
label findSortedIndex(const ListType &input, typename ListType::const_reference val, const label start=0)
Binary search to find the index of the last element in a sorted list that is less than value...
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.
virtual bool rmDir(const fileName &dir, const bool silent=false, const bool emptyOnly=false) const
Remove a directory and its contents.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
void clear() noexcept
Same as reset(nullptr)
runTimeSource setTime(sourceTimes[sourceTimeIndex], sourceTimeIndex)
file found in time directory
virtual autoPtr< ISstream > readStream(regIOobject &, const fileName &, const word &typeName, const bool readOnProc=true) const
Reads header for regIOobject and returns an ISstream to read the contents.
void stableSort(UList< T > &list)
Stable sort the list.
static bool readBlocks(const label comm, autoPtr< ISstream > &isPtr, List< char > &contentChars, const UPstream::commsTypes commsType)
Read data into *this. ISstream is only valid on master.
static int & msgType() noexcept
Message tag of standard messages.
label subCycling() const noexcept
Zero (tests as false) if time is not being sub-cycled, otherwise the current sub-cycle index or the t...
A simple container for options an IOstream can normally have.
virtual bool ln(const fileName &src, const fileName &dst) const
Create a softlink. dst should not exist. Returns true if.
static std::streamsize read(const UPstream::commsTypes commsType, const int fromProcNo, Type *buffer, std::streamsize count, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm, UPstream::Request *req=nullptr)
Receive buffer contents (contiguous types) from given processor.
static void broadcast(Type &value, const int communicator=UPstream::worldComm)
Broadcast content (contiguous or non-contiguous) to all communicator ranks. Does nothing in non-paral...
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Negative if the process is not a...
static label worldComm
Communicator for all ranks. May differ from commGlobal() if local worlds are in use.
List< string > stringList
List of string.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
A class for managing references or pointers (no reference counting)
bool exists(const dirIndexList &, IOobject &io) const
Helper: check IO for local existence. Like filePathInfo but.
An encapsulation of filesystem-related operations.
fileName objectPath() const
The complete path + object name.
Macros for easy insertion into run-time selection tables.
as PROCOBJECT but with instance
static bool isReadRequired(readOption opt) noexcept
True if (MUST_READ | READ_MODIFIED) bits are set.
UList< label > labelUList
A UList of labels.
static void gatherList(UList< T > &values, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Gather data, but keep individual values separate.
bool read(const char *buf, int32_t &val)
Same as readInt32.
#define forAll(list, i)
Loop across all elements in list.
constexpr const char *const group
Group name for atomic constants.
virtual fileName filePath(const bool checkGlobal, const IOobject &io, const word &typeName, const bool search) const
Search for an object. checkGlobal : also check undecomposed case.
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
addToRunTimeSelectionTable(fileOperation, collatedFileOperation, word)
virtual bool writeObject(const regIOobject &io, IOstreamOption streamOpt=IOstreamOption(), const bool writeOnProc=true) const
Writes a regIOobject (so header, contents and divider).
Tuple2< fileName, Tuple2< pathType, int > > dirIndex
Augment fileName with pathType and local offset.
Input inter-processor communications stream using MPI send/recv etc. - operating on external buffer...
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
atomicType
Atomic operations (output)
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run. ...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
instance is absolute directory
"scheduled" (MPI standard) : (MPI_Send, MPI_Recv)
bool good() const noexcept
True if the managed pointer is non-null.
objectPath exists in 'processorsNN'
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i), works like std::iota() but returning a...
static float maxMasterFileBufferSize
Max size of parallel communications. Switches from non-blocking.
A class for handling words, derived from Foam::string.
const Time & time() const noexcept
Return time registry.
Master-only drop-in replacement for OFstream.
objectPath exists in 'processorN'
virtual fileName dirPath(const bool checkGlobal, const IOobject &io, const bool search) const
Search for a directory. checkGlobal : also check undecomposed.
virtual instantList findTimes(const fileName &, const word &) const
Get sorted list of times.
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.
static constexpr int masterNo() noexcept
Relative rank for the master process - is always 0.
void finishedSends(const bool wait=true)
Mark the send phase as being finished.
virtual void addWatches(regIOobject &, const fileNameList &) const
Helper: add watches for list of regIOobjects.
static const word null
An empty word.
addNamedToRunTimeSelectionTable(fileOperationInitialise, fileOperationInitialise_collated, word, collated)
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?
as PROCBASEOBJECT but with instance
objectPath exists in 'processorsNN_first-last'
static bool isCollatedType(const word &objectType)
True if object type is a known collated type.
virtual bool removeWatch(const label) const
Remove watch on a file (using handle)
static word findInstancePath(const UList< instant > &timeDirs, const instant &t)
Search instantList for matching time value, return the instance name or word::null if nothing is equa...
no append (truncates existing)
static void readAndSend(const fileName &filePath, const labelUList &recvProcs, PstreamBuffers &pBufs)
Read file contents and send to processors.
virtual void updateStates(const bool masterOnly, const bool syncPar) const
Update state of all files.
static bool readHeader(IOobject &io, Istream &is)
Read header as per IOobject with additional handling of decomposedBlockData.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
const Time & time() const noexcept
Return Time associated with the objectRegistry.
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
UPstream::rangeType subProcs() const noexcept
Range of sub-processes indices associated with PstreamBuffers.
const labelList & watchIndices() const noexcept
Read access to file-monitoring handles.
virtual bool mvBak(const fileName &, const std::string &ext="bak") const
Rename to a corresponding backup file.
virtual void sync()
Forcibly parallel sync.
static int cacheLevel() noexcept
Return cache level.
static word timeName(const scalar t, const int precision=precision_)
Return a time name for the given scalar time value formatted with the given precision.
const word & constant() const noexcept
Return constant name.
label recvDataCount(const label proci) const
Number of unconsumed receive bytes for the specified processor. Must call finishedSends() or other fi...
int debug
Static debugging option.
OBJstream os(runTime.globalPath()/outputName)
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
static fileCheckTypes fileModificationChecking
Type of file modification checking.
Input from file stream as an ISstream, normally using std::ifstream for the actual input...
static Tuple2< label, labelList > getCommPattern()
Buffers for inter-processor communications streams (UOPstream, UIPstream).
void push_back(const T &val)
Copy append an element to the end of this list.
static bool uniformFile(const fileNameList &names)
True if the file names are identical. False on an empty list.
static labelRange subRanks(const labelUList &mainIOranks)
Get (contiguous) range/bounds of ranks addressed within the given main io-ranks.
const fileName & instance() const noexcept
Read access to instance path component.
virtual ~masterUncollatedFileOperation()
Destructor.
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
virtual bool mkDir(const fileName &, mode_t=0777) const
Make directory.
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)
word format(conversionProperties.get< word >("format"))
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
List< word > wordList
List of word.
virtual instantList findTimes(const fileName &, const word &) const
Get sorted list of times.
virtual bool rm(const fileName &) const
Remove a file, returning true if successful otherwise false.
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
virtual void sync()
Forcibly parallel sync.
virtual fileName filePathInfo(const bool checkGlobal, const bool isFile, const IOobject &io, const dirIndexList &pDirs, const bool search, pathType &searchType, word &processorsDir, word &instance) const
Search (locally!) for object; return info on how it was found.
instantList times() const
Search the case for valid time directories.
float floatOptimisationSwitch(const char *name, const float deflt=0)
Lookup optimisation switch or add default value.
virtual void setTime(const Time &) const
Callback for time change.
#define WarningInFunction
Report a warning using Foam::Warning.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
virtual void setUnmodified(const label) const
Set current state of file (using handle) to unmodified.
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.
static DynamicList< char > readContents(const fileName &pathname)
Get file contents from specified file (compressed/uncompressed). Returns an empty list if the file ca...
An ISstream with internal List storage. Always UNCOMPRESSED.
registerOptSwitch("maxThreadFileBufferSize", float, collatedFileOperation::maxThreadFileBufferSize)
streamFormat
Data format (ascii | binary)
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
"nonBlocking" (immediate) : (MPI_Isend, MPI_Irecv)
virtual autoPtr< OSstream > NewOFstream(const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), const bool writeOnProc=true) const
Generate an OSstream that writes a file.
messageStream Info
Information stream (stdout output on master, null elsewhere)
static List< int > & procID(int communicator)
The list of ranks within a given communicator.
virtual fileName::Type type(const fileName &, const bool followLink=true) const
Return the file type: DIRECTORY, FILE or SYMLINK.
virtual fileName getFile(const label) const
Get name of file being watched (using handle)
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
virtual off_t fileSize(const fileName &, const bool followLink=true) const
Return size of file.
virtual label findWatch(const labelList &watchIndices, const fileName &) const
Find index (or -1) of file in list of handles.
static labelList getGlobalIORanks()
Get list of global IO ranks from FOAM_IORANKS env variable. If set, these correspond to the IO master...
defineTypeNameAndDebug(collatedFileOperation, 0)
List< label > labelList
A List of labels.
static rangeType subProcs(const label communicator=worldComm)
Range of process indices for sub-processes.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
virtual fileNameList readObjects(const objectRegistry &db, const fileName &instance, const fileName &local, word &newInstance) const
Search directory for objects. Used in IOobjectList.
List< instant > instantList
List of instants.
Registry of regIOobjects.
const T1 & first() const noexcept
Access the first element.
virtual void setTime(const Time &) const
Callback for time change.
const fileName & local() const noexcept
Read access to local path component.
List< fileName > fileNameList
List of fileName.
fileOperations that performs all file operations on the master processor. Requires the calls to be pa...
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
static void reduceOr(bool &value, const int communicator=worldComm)
Logical (or) reduction (MPI_AllReduce)
Defines the attributes of an object for which implicit objectRegistry management is supported...
mode_t mode(const fileName &name, const bool followLink=true)
Return the file mode, normally following symbolic links.
virtual fileName objectPath(const IOobject &io, const word &typeName) const
Generate disk file name for object. Opposite of filePath.
List< bool > boolList
A List of bools.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Type
Enumerations to handle directory entry types.
Extract type (as a word) from an object, typically using its type() method.
label comm_
Communicator to use.
forAllConstIters(mixture.phases(), phase)
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...