Go to the documentation of this file.
50 "caseDicts/postProcessing"
56 Foam::functionObjectList::errorHandlingType
58 Foam::functionObjectList::errorHandlingNames_
60 { errorHandlingType::DEFAULT,
"default" },
61 { errorHandlingType::WARN,
"warn" },
62 { errorHandlingType::IGNORE,
"ignore" },
63 { errorHandlingType::STRICT,
"strict" },
77 <<
"\nFOAM aborting (FOAM_ABORT set)\n" <<
endl;
84 <<
"\nFOAM parallel run exiting\n" <<
endl;
90 <<
"\nFOAM exiting\n" <<
endl;
100 void Foam::functionObjectList::createStateDict()
const
110 "functionObjectProperties",
112 "uniform"/word(
"functionObjects"),
122 void Foam::functionObjectList::createOutputRegistry()
const
124 objectsRegistryPtr_.reset
130 "functionObjectObjects",
147 autoPtr<functionObject> oldptr;
149 auto iter = indices_.find(key);
156 oldptr = this->release(oldIndex);
157 indices_.erase(iter);
168 void Foam::functionObjectList::listDir
186 listDir(dir/d, available);
197 listDir(d, available);
201 <<
"Available configured functionObjects:"
220 dictFile =
search(funcName, d);
221 if (!dictFile.empty())
233 const string& funcNameArgs,
246 word funcName(funcNameArgs);
252 bool hasNamedArg =
false;
260 word::const_iterator iter = funcNameArgs.begin();
261 iter != funcNameArgs.end();
271 funcName = funcNameArgs.substr(start, i - start);
276 else if (
c ==
',' ||
c ==
')')
287 funcNameArgs.substr(start, i - start)
300 funcNameArgs.substr(start, i - start)
321 funcNameArgs.substr(start, i - start)
337 <<
"Cannot find functionObject file " << funcName <<
endl;
343 ISstream& fileStream = *fileStreamPtr;
347 dictionary& funcDict = (funcDictPtr ? *funcDictPtr : funcsDict);
355 funcDict.
set(
"field",
args[0]);
364 else if (funcDict.
found(
"field"))
368 else if (funcDict.
found(
"fields"))
378 namedArg.first() +
' ' + namedArg.second() +
';'
387 funcDict.
set(
"region", region);
393 functionsDict.
merge(funcArgsDict);
399 Foam::functionObjectList::errorHandlingType
400 Foam::functionObjectList::getOrDefaultErrorHandling
404 const errorHandlingType deflt
414 <<
"The sub-dictionary '" << key
415 <<
"' masks error handling for functions" <<
endl;
419 const word enumName(eptr->
get<word>());
421 if (!errorHandlingNames_.found(enumName))
425 << enumName <<
" is not in enumeration: "
426 << errorHandlingNames_ <<
nl
430 return errorHandlingNames_.get(enumName);
440 Foam::functionObjectList::functionObjectList
450 Foam::functionObjectList::functionObjectList
463 parentDict_(parentDict),
464 stateDictPtr_(
nullptr),
465 objectsRegistryPtr_(
nullptr),
466 execution_(execution),
490 bool modifiedControlDict =
false;
494 modifiedControlDict =
true;
512 modifiedControlDict =
true;
525 modifiedControlDict =
true;
542 if (modifiedControlDict)
551 functionsPtr->
start();
561 return stateDict().getOrDefault<label>(
"triggerIndex",
labelMin);
568 stateDictPtr_.reset(
nullptr);
580 return *stateDictPtr_;
591 return *stateDictPtr_;
597 if (!objectsRegistryPtr_)
599 createOutputRegistry();
602 return *objectsRegistryPtr_;
608 if (!objectsRegistryPtr_)
610 createOutputRegistry();
613 return *objectsRegistryPtr_;
620 errorHandling_.clear();
634 if (funcObj.name() == objName)
655 updated_ = execution_ =
false;
682 auto errIter = errorHandling_.cbegin();
686 const errorHandlingType errorHandling = *errIter;
689 const word& objName = funcObj.name();
693 errorHandling == errorHandlingType::WARN
694 || errorHandling == errorHandlingType::IGNORE
702 bool hadError =
false;
710 "functionObject::" + objName +
"::execute"
713 ok = funcObj.execute() && ok;
723 errorHandling != errorHandlingType::IGNORE
724 && (nWarnings = ++warnings_(objName)) <=
maxWarnings
730 <<
"--> execute() function object '"
735 Info<<
nl <<
"... silencing further warnings";
756 "functionObject::" + objName +
":write"
759 ok = funcObj.write() && ok;
768 errorHandling != errorHandlingType::IGNORE
769 && (nWarnings = ++warnings_(objName)) <=
maxWarnings
775 <<
"--> write() function object '"
780 Info<<
nl <<
"... silencing further warnings";
800 "functionObject::" + objName +
"::execute"
803 ok = funcObj.execute() && ok;
811 "functionObject::" + objName +
":write"
814 ok = funcObj.write() && ok;
821 if (time_.writeTime())
826 stateDictPtr_->writeObject
841 bool ok = execution_;
849 ok = funcObj.execute(subIndex) && ok;
863 bool ok = execution_;
865 if (ok && functionNames.
size())
873 ok = funcObj.execute(subIndex) && ok;
893 auto errIter = errorHandling_.cbegin();
897 const errorHandlingType errorHandling = *errIter;
900 const word& objName = funcObj.name();
910 addProfiling(fo,
"functionObject::" + objName +
"::end");
911 ok = funcObj.end() && ok;
920 errorHandling != errorHandlingType::IGNORE
921 && (nWarnings = ++warnings_(objName)) <=
maxWarnings
927 <<
"--> end() function object '"
932 Info<<
nl <<
"... silencing further warnings";
962 const word& objName = funcObj.name();
969 "functionObject::" + objName +
"::adjustTimeStep"
972 ok = funcObj.adjustTimeStep() && ok;
987 updated_ = execution_;
996 const entry* entryPtr =
1005 errorHandling_.clear();
1010 else if (!entryPtr->
isDict())
1015 <<
"'functions' entry is not a dictionary"
1027 functionsDict.size(),
1028 errorHandlingType::DEFAULT
1040 functionObject::dictionaryConstructorTablePtr_
1044 const errorHandlingType errorHandlingFallback =
1045 getOrDefaultErrorHandling
1049 errorHandlingType::DEFAULT
1054 for (
const entry& dEntry : functionsDict)
1056 const word& key = dEntry.keyword();
1058 if (!dEntry.isDict())
1060 if (key !=
"errors" && key !=
"libs")
1063 <<
"Entry " << key <<
" is not a dictionary" <<
endl;
1074 const errorHandlingType errorHandling =
1075 getOrDefaultErrorHandling
1079 errorHandlingFallback
1082 errorHandling_[nFunc] = errorHandling;
1086 label oldIndex = -1;
1089 const bool needsTimeControl =
1098 if (enabled && newDigs[nFunc] != digests_[oldIndex])
1100 const bool wasTimeControl =
1101 isA<functionObjects::timeControl>(*objPtr);
1103 if (needsTimeControl != wasTimeControl)
1108 objPtr.
reset(
nullptr);
1117 "functionObject::" + objPtr->
name() +
"::read"
1127 objPtr.
reset(
nullptr);
1132 if (enabled && !objPtr)
1144 "functionObject::" + key +
"::new"
1146 if (needsTimeControl)
1160 objPtr.
reset(
nullptr);
1162 switch (errorHandling)
1164 case errorHandlingType::IGNORE:
1167 case errorHandlingType::STRICT:
1173 case errorHandlingType::DEFAULT:
1175 if (isA<Foam::IOerror>(err))
1186 case errorHandlingType::WARN:
1191 <<
"--> loading function object '"
1206 objPtr.
reset(
nullptr);
1214 newPtrs.set(nFunc, objPtr);
1215 newIndices.
insert(key, nFunc);
1220 newPtrs.resize(nFunc);
1221 newDigs.resize(nFunc);
1222 errorHandling_.resize(nFunc);
1227 digests_.transfer(newDigs);
1228 indices_.transfer(newIndices);
1243 bool changed = funcObj.filesModified();
1257 funcObj.updateMesh(mpm);
1269 funcObj.movePoints(
mesh);
A keyword and a list of tokens is an 'entry'.
dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX)
Find and return a sub-dictionary pointer if present.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
void movePoints(const polyMesh &mesh)
Update for changes of mesh.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
A keyword and a list of tokens is a 'dictionaryEntry'.
static bool New(dictionary &parentDict, Istream &is, const inputMode inpMode=inputMode::GLOBAL, const int endChar=0)
Construct from an Istream and insert into the dictionary.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
static void printStack(Ostream &os)
Helper function to print a stack.
bool status() const
Return the execution status (on/off) of the function objects.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
bool adjustTimeStep()
Called at the end of Time::adjustDeltaT() if adjustTime is true.
static fileName findDict(const word &funcName)
A class for handling words, derived from Foam::string.
A class for handling file names.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
static autoPtr< functionObject > New(const word &name, const Time &runTime, const dictionary &dict)
Select from dictionary, based on its "type" entry.
T getOrDefault(const word &optName, const T &deflt) const
Get a value from the named option if present, or return default.
void on()
Switch the function objects on.
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
static void exitNow(const error &err)
Mimic exit handling of the error class.
bool read(const char *buf, int32_t &val)
Same as readInt32.
fileNameList findEtcDirs(const fileName &name, unsigned short location=0777, const bool findFirst=false)
Search for directories from user/group/other etc locations.
IOdictionary & stateDict()
static bool & parRun()
Test if this a parallel run, or allow modify access.
static word timeName(const scalar t, const int precision=precision_)
Wrapper around functionObjects to add time control.
Generic input stream using a standard (STL) stream.
void updateMesh(const mapPolyMesh &mpm)
Update for changes of mesh.
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
static word validate(const std::string &s, const bool prefix=false)
Construct validated word (no invalid characters).
Extract command arguments and options from the supplied argc and argv parameters.
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.
void append(const T &val)
Append an element at the end of the list.
Ostream & endl(Ostream &os)
Add newline and flush stream.
static unsigned int precision_
Default precision.
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
entry * set(entry *entryPtr)
Assign a new entry, overwriting any existing entry.
bool execute()
Called at each ++ or += of the time-loop.
List of function objects with start(), execute() and end() functions that is called for each object.
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
bool start()
Called at the start of the time-loop.
Mesh consisting of general polyhedral cells.
Abstract base-class for Time/database function objects.
void clear()
Clear the list of function objects.
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Registry of regIOobjects.
string expand(const std::string &s, const HashTable< string, word, string::hash > &mapping, const char sigil='$')
bool merge(const dictionary &dict)
Merge entries from the given dictionary.
virtual bool isDict() const
Return true if this entry is a dictionary.
void off()
Switch the function objects off.
label triggerIndex() const
Return the current trigger index (read from the stateDict)
messageStream Info
Information stream (uses stdout - output is on the master only)
runTime controlDict().readEntry("adjustTimeStep"
label findObjectID(const word &objName) const
Find the ID of a given function object by name, -1 if not found.
The IOstreamOption is a simple container for options an IOstream can normally have.
static fileName functionObjectDictPath
graph_traits< Graph >::vertices_size_type size_type
virtual bool read(const dictionary &dict)
Read and set the function object if its data have changed.
void resize(const label newSize)
Adjust allocated size of list.
#define addProfiling(name, descr)
Define profiling trigger with specified name and description string.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
const dictionary & controlDict() const
Return read access to the controlDict dictionary.
static autoPtr< functionObjectList > New(const argList &args, const Time &runTime, dictionary &controlDict, HashSet< wordRe > &requiredFields)
Construct and return a functionObjectList for an application.
void clear()
Clear the PtrList. Delete allocated entries and set size to zero.
Input from string buffer, using a ISstream.
static bool useAbort()
True if FOAM_ABORT is on.
errorManip< error > abort(error &err)
virtual const dictionary & dict() const =0
Return dictionary, if entry is a dictionary.
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
static const fileName null
An empty fileName.
errorManipArg< error, int > exit(error &err, const int errNo=1)
prefixOSstream Perr
OSstream wrapped stderr (std::cerr) with parallel prefix.
Functions to search 'etc' directories for configuration files etc.
label size() const noexcept
The number of arguments.
bool match(const UList< wordRe > &patterns, const std::string &text)
Return true if text matches one of the regular expressions.
static constexpr const uint32_t maxWarnings
Max number of warnings (per functionObject)
static bool readFunctionObject(const string &funcNameArgs0, dictionary &functionsDict, HashSet< wordRe > &requiredFields, const word ®ion=word::null)
const word & name() const
Return the name of this functionObject.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
entry * findEntry(const word &keyword, enum keyType::option matchOpt=keyType::REGEX)
Find for an entry (non-const access) with the given keyword.
A List of wordRe with additional matching capabilities.
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
List< T > getList(const label index) const
Get a List of values from the argument at index.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
const dimensionedScalar c
Speed of light in a vacuum.
HashSet< word > wordHashSet
A HashSet with word keys.
void size(const label n) noexcept
Override size to be inconsistent with allocated storage.
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
static bool entriesPresent(const dictionary &dict)
Helper function to identify if a timeControl object is present.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
void write(Ostream &os, const bool includeTitle=true) const
Print error message.
SHA1Digest digest() const
Return the SHA1 digest of the dictionary contents.
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
bool read()
Read and set the function objects if their data have changed.
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
void resetState()
Reset/read state dictionary for current time.
Foam::argList args(argc, argv)
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.
bool throwExceptions(bool doThrow)
Activate/deactivate exception throwing.
#define WarningInFunction
Report a warning using Foam::Warning.
Class to handle errors and exceptions in a simple, consistent stream-based manner.
bool end()
Called when Time::run() determines that the time-loop exits.
objectRegistry & storedObjects()
void transfer(PtrList< T > &list)
Transfer into this list and annul the argument list.
bool found(const word &optName) const
Return true if the named option is found.
bool filesModified() const
Did any file get changed during execution?
static void exit(int errNo=1)
Shutdown (finalize) MPI as required and exit program with errNo.