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_
475 mkDir(pathName.path());
513 Pout<<
"fileOperation::filePath :" <<
" fName:" << fName <<
endl;
523 splitProcessorPath(fName,
path, pDir, local, gStart, gSz, numProcs);
537 const fileName& procDir = procDirs()[i].first();
544 Pout<<
"fileOperation::filePath : " << collatedName <<
endl;
555 Pout<<
"fileOperation::filePath : " << fName <<
endl;
562 Pout<<
"fileOperation::filePath : Not found" <<
endl;
570 return monitor().addWatch(fName);
576 return monitor().removeWatch(watchIndex);
588 if (getFile(watchIndices[i]) == fName)
610 const label index = findWatch(watchIndices,
f);
614 newWatchIndices.
append(addWatch(
f));
619 newWatchIndices.
append(watchIndices[index]);
620 removedWatches.
erase(index);
625 for (
const label index : removedWatches)
627 removeWatch(watchIndices[index]);
636 return monitor().getFile(watchIndex);
642 const bool masterOnly,
655 return monitor().getState(watchFd);
661 monitor().setUnmodified(watchFd);
668 const word& constantName
673 Pout<<
"fileOperation::findTimes : Finding times in directory "
674 << directory <<
endl;
687 instantList times = sortTimes(dirEntries, constantName);
694 const fileName& procDir = procDirs()[i].first();
695 fileName collDir(processorsPath(directory, procDir));
696 if (!collDir.empty() && collDir != directory)
708 sortTimes(extraEntries, constantName),
717 Pout<<
"fileOperation::findTimes : Found times:" << times <<
endl;
726 const scalar startValue,
727 const word& stopInstance
743 <<
"Found exact match for \"" << io.
name()
754 label instanceI = ts.size()-1;
756 for (; instanceI >= 0; --instanceI)
758 if (ts[instanceI].value() <= startValue)
765 for (; instanceI >= 0; --instanceI)
767 io.
instance() = ts[instanceI].name();
782 <<
"Found exact match for \"" << io.
name()
793 <<
"Hit stopInstance " << stopInstance <<
endl;
801 if (io.
name().empty())
804 <<
"Cannot find directory "
806 <<
" down to " << stopInstance
812 <<
"Cannot find file \"" << io.
name()
813 <<
"\" in directory " << io.
local()
814 <<
" in times " << startIO.
instance()
815 <<
" down to " << stopInstance
836 || ts.first().name() != time.
constant()
844 <<
"Found constant match for \"" << io.
name()
860 <<
"Cannot find file \"" << io.
name() <<
"\" in directory "
880 Pout<<
"fileOperation::readObjects :"
882 <<
" instance:" << instance <<
endl;
892 newInstance = instance;
900 if (!procsPath.empty())
902 newInstance = instance;
932 label start, size,
n;
936 splitProcessorPath(dirN,
path, pDir, local, start, size,
n)
948 if (nProcs == 0 &&
Foam::isDir(dir/processorsBaseDir))
967 <<
" to determine the number of decompositions."
968 <<
" Returning 1" <<
endl;
981 Pout<<
"fileOperation::flush : clearing processor directories cache"
1001 const word& instance,
1002 const word& procsDir
1006 processorsCasePath(io, procsDir)
1016 const word& procsDir
1025 if (caseName.size() <= 9 || caseName[9] ==
's')
1028 <<
" does not end in old-style processorDDD" <<
endl;
1031 return dir.
path()/procsDir;
1064 if (
pos == string::npos)
1074 if (
pos > 0 && objectPath[
pos-1] !=
'/')
1080 procDir = objectPath;
1085 path = objectPath.substr(0,
pos-1);
1086 procDir = objectPath.substr(
pos);
1090 pos = procDir.find(
'/');
1091 if (
pos != string::npos)
1093 local = procDir.substr(
pos+1);
1094 procDir = procDir.substr(0,
pos);
1106 if (
f.size() &&
f[0] ==
's')
1116 if (fromStart != string::npos && toStart != string::npos)
1118 string nProcsName(
f.substr(0, fromStart));
1119 string fromName(
f.substr(fromStart+1, toStart-(fromStart+1)));
1120 string toName(
f.substr(toStart+1));
1122 label groupEnd = -1;
1130 groupSize = groupEnd-groupStart+1;
1163 label start, size, nProcs;
1164 return splitProcessorPath(fName,
path, pDir, local, start, size, nProcs);
1176 if (handler.empty())
int debug
Static debugging option.
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.
static autoPtr< fileOperation > fileHandlerPtr_
Static fileOperation.
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.
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.
static label numBlocks(const fileName &fName)
Detect number of blocks in a file.
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.
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.
The IOstreamOption is a simple container for options an IOstream can normally have.
virtual bool writeObject(const regIOobject &io, IOstreamOption streamOpt=IOstreamOption(), const bool valid=true) const
Writes a regIOobject (so header, contents and divider).
virtual fileMonitor::fileState getState(const label) const
Get current state of file (using handle)
Generic output stream using a standard (STL) stream.
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.
#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.
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.
bool writeHeader(Ostream &os) const
Write header.
static word processorsBaseDir
Return the processors directory name (usually "processors")
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).
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?
dimensionedScalar pos(const dimensionedScalar &ds)