Go to the documentation of this file.
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" }
104 const word& constantName
112 bool haveConstant =
false;
113 for (
const fileName& dirName : dirEntries)
115 if (dirName == constantName)
118 times[nTimes].value() = 0;
119 times[nTimes].name() = constantName;
126 for (
const fileName& dirName : dirEntries)
129 if (readScalar(dirName, timeValue))
131 times[nTimes].value() = timeValue;
132 times[nTimes].name() = dirName;
159 const word& constantName,
163 if (extraTimes.size())
165 const bool haveConstant =
168 && times[0].name() == constantName
171 const bool haveExtraConstant =
174 && extraTimes[0].name() == constantName
178 instantList combinedTimes(times.size()+extraTimes.size());
181 if (haveExtraConstant)
186 combinedTimes[sz++] = extraTimes[0];
191 combinedTimes[sz++] = times[i];
193 for (; extrai < extraTimes.size(); extrai++)
195 combinedTimes[sz++] = extraTimes[extrai];
201 if (times.size() > 1)
204 if (times[0].
name() == constantName)
211 label newi = starti+1;
212 for (
label i = newi; i < times.size(); i++)
214 if (times[i].value() != times[i-1].value())
218 times[newi] = times[i];
254 splitProcessorPath(fName,
path, pDir, local, gStart, gSz, numProcs);
260 const auto iter = procsDirs_.cfind(procPath);
287 label rStart, rSize, rNum;
289 splitProcessorPath(dirN,
rp, rd, rl, rStart, rSize, rNum);
290 maxProc =
max(maxProc, readProci);
292 if (proci == readProci)
304 else if (proci >= rStart && proci < rStart+rSize)
349 || (!syncPar && procDirs.size())
352 procsDirs_.insert(procPath, procDirs);
356 Pout<<
"fileOperation::lookupProcessorsPath : For:" << procPath
357 <<
" detected:" << procDirs <<
endl;
361 return procsDirs_[procPath];
372 return lookupAndCacheProcessorsPath(fName,
true);
383 if (io.
name().empty())
399 if (originalPath != objPath)
402 if (io.
name().empty())
404 ok =
isDir(originalPath);
429 const word& handlerType,
434 <<
"Constructing fileHandler" <<
endl;
436 auto cstrIter = wordConstructorTablePtr_->cfind(handlerType);
438 if (!cstrIter.found())
444 *wordConstructorTablePtr_
477 mkDir(pathName.path());
524 Pout<<
"fileOperation::filePath :" <<
" fName:" << fName <<
endl;
534 splitProcessorPath(fName,
path, pDir, local, gStart, gSz, numProcs);
548 const fileName& procDir = procDirs()[i].first();
555 Pout<<
"fileOperation::filePath : " << collatedName <<
endl;
566 Pout<<
"fileOperation::filePath : " << fName <<
endl;
573 Pout<<
"fileOperation::filePath : Not found" <<
endl;
581 return monitor().addWatch(fName);
587 return monitor().removeWatch(watchIndex);
599 if (getFile(watchIndices[i]) == fName)
621 const label index = findWatch(watchIndices,
f);
625 newWatchIndices.
append(addWatch(
f));
630 newWatchIndices.
append(watchIndices[index]);
631 removedWatches.
erase(index);
636 for (
const label index : removedWatches)
638 removeWatch(watchIndices[index]);
647 return monitor().getFile(watchIndex);
653 const bool masterOnly,
666 return monitor().getState(watchFd);
672 monitor().setUnmodified(watchFd);
679 const word& constantName
684 Pout<<
"fileOperation::findTimes : Finding times in directory "
685 << directory <<
endl;
698 instantList times = sortTimes(dirEntries, constantName);
705 const fileName& procDir = procDirs()[i].first();
706 fileName collDir(processorsPath(directory, procDir));
707 if (!collDir.empty() && collDir != directory)
719 sortTimes(extraEntries, constantName),
728 Pout<<
"fileOperation::findTimes : Found times:" << times <<
endl;
737 const scalar startValue,
738 const word& stopInstance
754 <<
"Found exact match for \"" << io.
name()
765 label instanceI = ts.size()-1;
767 for (; instanceI >= 0; --instanceI)
769 if (ts[instanceI].value() <= startValue)
776 for (; instanceI >= 0; --instanceI)
778 io.
instance() = ts[instanceI].name();
793 <<
"Found exact match for \"" << io.
name()
804 <<
"Hit stopInstance " << stopInstance <<
endl;
812 if (io.
name().empty())
815 <<
"Cannot find directory "
817 <<
" down to " << stopInstance
823 <<
"Cannot find file \"" << io.
name()
824 <<
"\" in directory " << io.
local()
825 <<
" in times " << startIO.
instance()
826 <<
" down to " << stopInstance
847 || ts.first().name() != time.
constant()
855 <<
"Found constant match for \"" << io.
name()
871 <<
"Cannot find file \"" << io.
name() <<
"\" in directory "
891 Pout<<
"fileOperation::readObjects :"
893 <<
" instance:" << instance <<
endl;
903 newInstance = instance;
911 if (!procsPath.empty())
913 newInstance = instance;
947 splitProcessorPath(dirN,
path, pDir, local,
start, size,
n)
959 if (nProcs == 0 &&
Foam::isDir(dir/processorsBaseDir))
978 <<
" to determine the number of decompositions."
979 <<
" Returning 1" <<
endl;
992 Pout<<
"fileOperation::flush : clearing processor directories cache"
1002 const word& procsDir
1012 const word& instance,
1013 const word& procsDir
1017 processorsCasePath(io, procsDir)
1027 const word& procsDir
1036 if (caseName.size() <= 9 || caseName[9] ==
's')
1039 <<
" does not end in old-style processorDDD" <<
endl;
1042 return dir.
path()/procsDir;
1075 if (
pos == string::npos)
1085 if (
pos > 0 && objectPath[
pos-1] !=
'/')
1091 procDir = objectPath;
1096 path = objectPath.substr(0,
pos-1);
1097 procDir = objectPath.substr(
pos);
1101 pos = procDir.find(
'/');
1102 if (
pos != string::npos)
1104 local = procDir.substr(
pos+1);
1105 procDir = procDir.substr(0,
pos);
1117 if (
f.size() &&
f[0] ==
's')
1127 if (fromStart != string::npos && toStart != string::npos)
1129 string nProcsName(
f.substr(0, fromStart));
1130 string fromName(
f.substr(fromStart+1, toStart-(fromStart+1)));
1131 string toName(
f.substr(toStart+1));
1133 label groupEnd = -1;
1141 groupSize = groupEnd-groupStart+1;
1175 return splitProcessorPath(fName,
path, pDir, local,
start, size, nProcs);
1187 if (handler.empty())
1212 if (newHandler.
valid())
int debug
Static debugging option.
virtual fileName::Type type(const fileName &, const bool followLink=true) const =0
Return the file type: DIRECTORY, FILE or LINK.
const fileName & globalCaseName() const
Return global case name.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
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?
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
const word & name() const
Return name.
A class for handling words, derived from Foam::string.
static void mergeTimes(const instantList &extraTimes, const word &constantName, instantList ×)
Merge two times.
An encapsulation of filesystem-related operations.
A class for handling file names.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
fileName processorsPath(const IOobject &, const word &instance, const word &procDir) const
Generate path (like io.path) with provided instance and any.
virtual void addWatches(regIOobject &, const fileNameList &) const
Helper: add watches for list of regIOobjects.
static std::string path(const std::string &str)
Return directory path name (part before last /)
const labelList & watchIndices() const
Return file-monitoring handles.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
static bool less(const vector &x, const vector &y)
To compare normals.
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.
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
virtual bool writeData(Ostream &) const =0
Pure virtual writeData function.
const fileName & rootPath() const
const fileName & instance() const
static std::string name(const std::string &str)
Return basename (part beyond last /), including its extension.
bool read(const char *buf, int32_t &val)
Same as readInt32.
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
static bool & parRun()
Is this a parallel run?
static const Enum< pathType > pathTypeNames_
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
static fileCheckTypes fileModificationChecking
Type of file modification checking.
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.
static label splitProcessorPath(const fileName &, fileName &path, fileName &procDir, fileName &local, label &groupStart, label &groupSize, label &nProcs)
Split fileName into part before 'processor' and part after.
static void scatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Distribute without modification. Reverse of gather.
fileState
Enumeration defining the file state.
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 fileOperation & fileHandler()
Get current file handler.
bool valid() const noexcept
True if the managed pointer is non-null.
Ostream & endl(Ostream &os)
Add newline and flush stream.
static bool isFileOrDir(const bool isFile, const fileName &)
Helper: check for file (isFile) or directory (!isFile)
virtual void setNProcs(const label nProcs)
Set number of processor directories/results. Only used in.
prefixOSstream Pout
An Ostream wrapper for parallel output to std::cout.
const Time & time() const
Return time.
virtual void updateStates(const bool masterOnly, const bool syncPar) const
Update state of all files.
string getEnv(const std::string &envName)
Get environment value for given envName.
virtual instantList findTimes(const fileName &, const word &) const
Get sorted list of times.
#define forAll(list, i)
Loop across all elements in list.
virtual fileName getFile(const label) const
Get name of file being watched (using handle)
virtual IOobject findInstance(const IOobject &io, const scalar startValue, const word &stopInstance) const
Find instance where IOobject is. Fails if cannot be found.
const objectRegistry & db() const
Return the local objectRegistry.
Registry of regIOobjects.
static autoPtr< fileOperation > New(const word &handlerType, bool verbose=false)
Select fileHandler-type.
virtual const fileName & dbDir() const
Local directory path of this objectRegistry relative to the time.
const fileName & local() const
virtual tmpNrc< dirIndexList > lookupProcessorsPath(const fileName &) const
Lookup name of processorsDDD using cache. Return empty fileName.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Representation of a major/minor version number.
static instantList sortTimes(const fileNameList &, const word &)
Sort directory entries according to time value.
fileOperation(const label comm)
Construct from communicator.
bool erase(const iterator &iter)
Erase an entry specified by given iterator.
#define DebugInFunction
Report an information message using Foam::Info.
A class for managing temporary objects without reference counting.
word name(const complex &c)
Return string representation of complex.
DynamicList< T, SizeMin > & append(const T &val)
Append an element to the end of this list.
virtual label nProcs(const fileName &dir, const fileName &local="") const
Get number of processor directories/results. Used for e.g.
void transfer(List< T > &list)
Checking for changes to files.
instantList times() const
Search the case for valid time directories.
virtual fileMonitor::fileState getState(const label) const
Get current state of file (using handle)
graph_traits< Graph >::vertices_size_type size_type
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
streamFormat
Data format (ascii | binary)
#define FatalErrorInLookup(lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalError.
autoPtr< fileMonitor > monitorPtr_
file-change monitor for all registered files
static word defaultFileHandler
Default fileHandler.
errorManip< error > abort(error &err)
virtual fileName objectPath(const IOobject &io, const word &typeName) const
Generate disk file name for object. Opposite of filePath.
static const fileName null
An empty fileName.
virtual label addWatch(const fileName &) const
Add watching of a file. Returns handle.
errorManipArg< error, int > exit(error &err, const int errNo=1)
virtual bool removeWatch(const label) const
Remove watch on a file (using handle)
static bool master(const label communicator=0)
Am I the master process.
virtual void setUnmodified(const label) const
Set current state of file (using handle) to unmodified.
fileMonitor & monitor() const
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
static int & msgType()
Message tag of standard messages.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
bool exists(IOobject &io) const
Does ioobject exist. Is either a directory (empty name()) or.
readOption readOpt() const
The read option.
label ListType::const_reference const label start
virtual fileNameList readObjects(const objectRegistry &db, const fileName &instance, const fileName &local, word &newInstance) const
Search directory for objects. Used in IOobjectList.
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
static label detectProcessorPath(const fileName &)
Detect processor number from '/aa/bb/processorDDD/cc'.
static const word null
An empty word.
virtual label findWatch(const labelList &watchIndices, const fileName &) const
Find index (or -1) of file in list of handles.
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED)
static autoPtr< fileOperation > fileHandlerPtr_
Static fileOperation.
bool writeHeader(Ostream &os) const
Write header.
static word processorsBaseDir
Return the processors directory name (usually "processors")
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
tmpNrc< dirIndexList > lookupAndCacheProcessorsPath(const fileName &, const bool syncPar) const
Lookup name of processorsDDD using cache. Return empty fileName.
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
regionProperties rp(runTime)
bool good() const
Return true if next operation might succeed.
fileName objectPath() const
The complete path + object name.
void setSize(const label newSize)
Alias for resize(const label)
const word & constant() const
Return constant name.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
fileName path() const
The complete path.
dictionary & optimisationSwitches()
The OptimisationSwitches sub-dictionary in the central controlDict(s).
virtual bool writeObject(const regIOobject &, IOstream::streamFormat format=IOstream::ASCII, IOstream::versionNumber version=IOstream::currentVersion, IOstream::compressionType compression=IOstream::UNCOMPRESSED, const bool valid=true) const
Writes a regIOobject (so header, contents and divider).
fileName processorsCasePath(const IOobject &, const word &procDir) const
Generate path (like io.path) from root+casename with any.
fileNameList readDir(const fileName &directory, const fileName::Type type=fileName::FILE, const bool filtergz=true, const bool followLink=true)
Read a directory and return the entries as a fileName List.
defineTypeNameAndDebug(combustionModel, 0)
#define WarningInFunction
Report a warning using Foam::Warning.
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
static label numBlocks(const fileName &)
Detect number of blocks in a file.
dimensionedScalar pos(const dimensionedScalar &ds)