Go to the documentation of this file.
51 "caseDicts/postProcessing"
57 Foam::functionObjectList::errorHandlingType
59 Foam::functionObjectList::errorHandlingNames_
61 { errorHandlingType::DEFAULT,
"default" },
62 { errorHandlingType::WARN,
"warn" },
63 { errorHandlingType::IGNORE,
"ignore" },
64 { errorHandlingType::STRICT,
"strict" },
78 <<
"\nFOAM aborting (FOAM_ABORT set)\n" <<
endl;
85 <<
"\nFOAM parallel run exiting\n" <<
endl;
91 <<
"\nFOAM exiting\n" <<
endl;
101 void Foam::functionObjectList::createPropertiesDict()
const
107 new functionObjects::properties
111 "functionObjectProperties",
113 "uniform"/word(
"functionObjects"),
123 void Foam::functionObjectList::createOutputRegistry()
const
125 objectsRegistryPtr_.reset
131 "functionObjectObjects",
148 autoPtr<functionObject> oldptr;
150 auto iter = indices_.find(
key);
157 oldptr = this->release(oldIndex);
158 indices_.erase(iter);
169 void Foam::functionObjectList::listDir
187 listDir(dir/d, available);
198 listDir(d, available);
202 <<
"Available configured functionObjects:"
203 << available.sortedToc()
221 dictFile =
search(funcName, d);
222 if (!dictFile.empty())
234 const string& funcNameArgs,
252 const auto argsBeg = funcNameArgs.find(
'(');
253 if (argsBeg == std::string::npos)
263 const auto argsEnd = funcNameArgs.rfind(
')');
271 (argsEnd != std::string::npos && argsBeg < argsEnd)
272 ? (argsEnd - argsBeg - 1)
289 <<
"Cannot find functionObject file " << funcName <<
endl;
295 ISstream& fileStream = *fileStreamPtr;
299 dictionary& funcDict = (funcDictPtr ? *funcDictPtr : funcsDict);
307 funcDict.
set(
"field",
args[0]);
316 else if (funcDict.
found(
"field"))
320 else if (funcDict.
found(
"fields"))
330 namedArg.first() +
' ' + namedArg.second() +
';'
339 funcDict.
set(
"region", region);
345 functionsDict.
merge(funcArgsDict);
351 Foam::functionObjectList::errorHandlingType
352 Foam::functionObjectList::getOrDefaultErrorHandling
356 const errorHandlingType deflt
366 <<
"The sub-dictionary '" <<
key
367 <<
"' masks error handling for functions" <<
endl;
371 const word enumName(eptr->
get<word>());
373 if (!errorHandlingNames_.found(enumName))
377 << enumName <<
" is not in enumeration: "
378 << errorHandlingNames_ <<
nl
382 return errorHandlingNames_.get(enumName);
392 Foam::functionObjectList::functionObjectList
402 Foam::functionObjectList::functionObjectList
415 parentDict_(parentDict),
416 propsDictPtr_(
nullptr),
417 objectsRegistryPtr_(
nullptr),
418 execution_(execution),
442 bool modifiedControlDict =
false;
446 modifiedControlDict =
true;
464 modifiedControlDict =
true;
477 modifiedControlDict =
true;
494 if (modifiedControlDict)
503 functionsPtr->
start();
520 propsDictPtr_.reset(
nullptr);
521 createPropertiesDict();
529 createPropertiesDict();
532 return *propsDictPtr_;
541 createPropertiesDict();
544 return *propsDictPtr_;
550 if (!objectsRegistryPtr_)
552 createOutputRegistry();
555 return *objectsRegistryPtr_;
561 if (!objectsRegistryPtr_)
563 createOutputRegistry();
566 return *objectsRegistryPtr_;
573 errorHandling_.clear();
587 if (funcObj.name() == objName)
608 updated_ = execution_ =
false;
635 auto errIter = errorHandling_.cbegin();
639 const errorHandlingType errorHandling = *errIter;
642 const word& objName = funcObj.name();
646 errorHandling == errorHandlingType::WARN
647 || errorHandling == errorHandlingType::IGNORE
655 bool hadError =
false;
663 "functionObject::" + objName +
"::execute"
666 ok = funcObj.execute() && ok;
676 errorHandling != errorHandlingType::IGNORE
677 && (nWarnings = ++warnings_(objName)) <=
maxWarnings
683 <<
"--> execute() function object '"
688 Info<<
nl <<
"... silencing further warnings";
709 "functionObject::" + objName +
":write"
712 ok = funcObj.write() && ok;
721 errorHandling != errorHandlingType::IGNORE
722 && (nWarnings = ++warnings_(objName)) <=
maxWarnings
728 <<
"--> write() function object '"
733 Info<<
nl <<
"... silencing further warnings";
753 "functionObject::" + objName +
"::execute"
756 ok = funcObj.execute() && ok;
764 "functionObject::" + objName +
":write"
767 ok = funcObj.write() && ok;
774 if (time_.writeTime())
779 propsDictPtr_->writeObject
794 bool ok = execution_;
802 ok = funcObj.execute(subIndex) && ok;
816 bool ok = execution_;
818 if (ok && functionNames.
size())
826 ok = funcObj.execute(subIndex) && ok;
846 auto errIter = errorHandling_.cbegin();
850 const errorHandlingType errorHandling = *errIter;
853 const word& objName = funcObj.name();
863 addProfiling(fo,
"functionObject::" + objName +
"::end");
864 ok = funcObj.end() && ok;
873 errorHandling != errorHandlingType::IGNORE
874 && (nWarnings = ++warnings_(objName)) <=
maxWarnings
880 <<
"--> end() function object '"
885 Info<<
nl <<
"... silencing further warnings";
915 const word& objName = funcObj.name();
922 "functionObject::" + objName +
"::adjustTimeStep"
925 ok = funcObj.adjustTimeStep() && ok;
937 createPropertiesDict();
940 updated_ = execution_;
949 const entry* entryPtr =
958 errorHandling_.clear();
963 else if (!entryPtr->
isDict())
968 <<
"'functions' entry is not a dictionary"
980 functionsDict.size(),
981 errorHandlingType::DEFAULT
993 functionObject::dictionaryConstructorTablePtr_
997 const errorHandlingType errorHandlingFallback =
998 getOrDefaultErrorHandling
1002 errorHandlingType::DEFAULT
1007 for (
const entry& dEntry : functionsDict)
1009 const word&
key = dEntry.keyword();
1011 if (!dEntry.isDict())
1015 if (
key ==
"useNamePrefix")
1017 Switch sw(dEntry.stream().peekFirst());
1025 <<
"Entry '" <<
key <<
"' is not a valid switch"
1029 else if (
key !=
"errors" &&
key !=
"libs")
1032 <<
"Entry '" <<
key <<
"' is not a dictionary"
1044 const errorHandlingType errorHandling =
1045 getOrDefaultErrorHandling
1049 errorHandlingFallback
1052 errorHandling_[nFunc] = errorHandling;
1056 label oldIndex = -1;
1059 const bool needsTimeControl =
1068 if (enabled && newDigs[nFunc] != digests_[oldIndex])
1070 const bool wasTimeControl =
1071 isA<functionObjects::timeControl>(*objPtr);
1073 if (needsTimeControl != wasTimeControl)
1078 objPtr.
reset(
nullptr);
1087 "functionObject::" + objPtr->
name() +
"::read"
1097 objPtr.
reset(
nullptr);
1102 if (enabled && !objPtr)
1114 "functionObject::" +
key +
"::new"
1116 if (needsTimeControl)
1130 objPtr.
reset(
nullptr);
1132 switch (errorHandling)
1134 case errorHandlingType::IGNORE:
1137 case errorHandlingType::STRICT:
1143 case errorHandlingType::DEFAULT:
1145 if (isA<Foam::IOerror>(err))
1156 case errorHandlingType::WARN:
1161 <<
"--> loading function object '"
1176 objPtr.
reset(
nullptr);
1184 newPtrs.set(nFunc, objPtr);
1190 newPtrs.resize(nFunc);
1191 newDigs.resize(nFunc);
1192 errorHandling_.resize(nFunc);
1197 digests_.transfer(newDigs);
1198 indices_.transfer(newIndices);
1213 bool changed = funcObj.filesModified();
1227 funcObj.updateMesh(mpm);
1239 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 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...
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
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)
void resize(const label len)
Adjust allocated size of list.
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.
virtual bool isDict() const noexcept
Return true if this entry is a dictionary.
fileNameList findEtcDirs(const fileName &name, unsigned short location=0777, const bool findFirst=false)
Search for directories from user/group/other etc locations.
static word timeName(const scalar t, const int precision=precision_)
Wrapper around functionObjects to add time control.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
bool throwing() const noexcept
Return the current exception throwing state (on or off)
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.
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.
bool merge(const dictionary &dict)
Merge entries from the given dictionary.
static bool defaultUseNamePrefix
Global default for useNamePrefix.
void off()
Switch the function objects off.
label triggerIndex() const
Return the current trigger index (read from the propsDict)
messageStream Info
Information stream (stdout output on master, null elsewhere)
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
IOdictionary propsDict(IOobject("particleTrackProperties", runTime.constant(), mesh, IOobject::MUST_READ_IF_MODIFIED))
virtual bool read(const dictionary &dict)
Read and set the function object if its data have changed.
void resetPropertiesDict()
Reset/read properties dictionary for current time.
functionObjects::properties & propsDict()
#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. Always UNCOMPRESSED.
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.
static const fileName null
An empty fileName.
errorManipArg< error, int > exit(error &err, const int errNo=1)
void reset(autoPtr< T > &&other) noexcept
Delete managed object and set to new given pointer.
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 noexcept
Return the name of this functionObject.
Storage for function object properties, derived from IOdictionary. Provides functionality to read/wri...
static bool & parRun() noexcept
Test if this a parallel run.
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.
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
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 size(const label n)
Older name for setAddressableSize.
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.
string expand(const std::string &s, const HashTable< string > &mapping, const char sigil='$')
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Foam::argList args(argc, argv)
virtual void write(Ostream &os, const bool withTitle=true) const
Print error message.
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.
#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.
label splitFunctionArgs(const std::string &str, wordRes &args, List< Tuple2< word, string >> &namedArgs)
Split out arguments (named or unnamed) from an input string.
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.