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:" 219 for (
const fileName& d :
findEtcDirs(functionObjectDictPath))
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" 973 const dictionary& functionsDict = entryPtr->dict();
975 PtrList<functionObject> newPtrs(functionsDict.size());
976 List<SHA1Digest> newDigs(functionsDict.size());
978 errorHandling_.resize
980 functionsDict.size(),
981 errorHandlingType::DEFAULT
984 HashTable<label> newIndices;
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().front());
1025 <<
"Entry '" <<
key <<
"' is not a valid switch" 1029 else if (
key !=
"errors" &&
key !=
"libs")
1032 <<
"Entry '" <<
key <<
"' is not a dictionary" 1039 const dictionary&
dict = dEntry.dict();
1044 const errorHandlingType errorHandling =
1045 getOrDefaultErrorHandling
1049 errorHandlingFallback
1052 errorHandling_[nFunc] = errorHandling;
1056 label oldIndex = -1;
1057 autoPtr<functionObject> objPtr =
remove(
key, oldIndex);
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" 1090 enabled = objPtr->read(
dict);
1097 objPtr.reset(
nullptr);
1102 if (enabled && !objPtr)
1114 "functionObject::" +
key +
"::new" 1116 if (needsTimeControl)
1120 new functionObjects::timeControl(
key, time_,
dict)
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);
1185 newIndices.insert(
key, nFunc);
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);
bool read()
Read and set the function objects if their data have changed.
static word validate(const std::string &s, const bool prefix=false)
Construct validated word (no invalid characters).
bool match(const UList< wordRe > &patterns, const std::string &text)
Return true if text matches one of the regular expressions.
prefixOSstream Perr
OSstream wrapped stderr (std::cerr) with parallel prefix.
label splitFunctionArgs(const std::string &str, wordRes &args, List< Tuple2< word, string >> &namedArgs)
Split out arguments (named or unnamed) from an input string.
void size(const label n)
Older name for setAddressableSize.
#define addProfiling(name, descr)
Define profiling trigger with specified name and description string.
static constexpr const uint32_t maxWarnings
Max number of warnings (per functionObject)
A class for handling file names.
bool filesModified() const
Did any file get changed during execution?
SHA1Digest digest() const
Return the SHA1 digest of the dictionary contents.
errorManipArg< error, int > exit(error &err, const int errNo=1)
void off()
Switch the function objects off.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Storage for function object properties, derived from IOdictionary. Provides functionality to read/wri...
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
static bool entriesPresent(const dictionary &dict)
Helper function to identify if a timeControl object is present.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
label findObjectID(const word &objName) const
Find the ID of a given function object by name, -1 if not found.
static void list()
Print a list of functionObject configuration files in the directories located using Foam::findEtcDirs...
constexpr char nl
The newline '\n' character (0x0a)
bool throwing() const noexcept
Return the current exception throwing state (on or off)
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
static const fileName null
An empty fileName.
Ostream & endl(Ostream &os)
Add newline and flush stream.
List< T > getList(const label index) const
Get a List of values from the argument at index.
static bool & parRun() noexcept
Test if this a parallel run.
functionObjects::properties & propsDict()
Write access to the properties dictionary ("functionObjectProperties") registered on Time...
void on()
Switch the function objects on.
autoPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler.
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
bool adjustTimeStep()
Called at the end of Time::adjustDeltaT() if adjustTime is true.
Ignore writing from objectRegistry::writeObject()
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T. FatalIOError if not found, or if the number of tokens is incorrect.
T getOrDefault(const word &optName, const T &deflt) const
Get a value from the named option if present, or return default.
Abstract base-class for Time/database function objects.
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
A keyword and a list of tokens is a 'dictionaryEntry'.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
bool start()
Called at the start of the time-loop.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
IOdictionary propsDict(dictIO)
bool read(const char *buf, int32_t &val)
Same as readInt32.
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Class to handle errors and exceptions in a simple, consistent stream-based manner.
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
static autoPtr< functionObjectList > New(const argList &args, const Time &runTime, dictionary &controlDict, HashSet< wordRe > &requiredFields)
Construct and return a functionObjectList for an application.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
bool merge(const dictionary &dict)
Merge entries from the given dictionary.
Foam::word regionName(Foam::polyMesh::defaultRegion)
bool execute()
Called at each ++ or += of the time-loop.
void resetPropertiesDict()
Reset/read properties dictionary for current time.
bool returnReduceAnd(const bool value, const label comm=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
static void exit(int errNo=1)
Shutdown (finalize) MPI as required and exit program with errNo.
static bool useAbort()
True if FOAM_ABORT is on.
A class for handling words, derived from Foam::string.
Functions to search 'etc' directories for configuration files etc.
Reading required, file watched for runTime modification.
Extract command arguments and options from the supplied argc and argv parameters. ...
static fileName findDict(const word &funcName)
Find a functionObject dictionary file in the case <system> directory or any directory located using F...
static void printStack(Ostream &os)
Helper function to print a stack.
virtual void write(Ostream &os, const bool withTitle=true) const
Print error message.
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
label size() const noexcept
The number of arguments.
A List of wordRe with additional matching capabilities.
T get() const
Get a T from the stream, FatalIOError if the number of tokens is incorrect.
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
List of function objects with start(), execute() and end() functions that is called for each object...
static void exitNow(const error &err)
Mimic exit handling of the error class.
runTime controlDict().readEntry("adjustTimeStep"
The central control dictionary, the contents of which are either taken directly from the FOAM_CONTROL...
errorManip< error > abort(error &err)
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings...
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
static bool readFunctionObject(const string &funcNameArgs0, dictionary &functionsDict, HashSet< wordRe > &requiredFields, const word ®ion=word::null)
Read the specified functionObject configuration dictionary parsing the optional arguments included in...
static word timeName(const scalar t, const int precision=precision_)
Return time name of given scalar time formatted with the given precision.
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
messageStream Warning
Warning stream (stdout output on master, null elsewhere), with additional 'FOAM Warning' header text...
void clear()
Clear the list of function objects.
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
bool status() const
Return the execution status (on/off) of the function objects.
static unsigned int precision_
Default precision.
Generic input stream using a standard (STL) stream.
#define WarningInFunction
Report a warning using Foam::Warning.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Input from string buffer, using a ISstream. Always UNCOMPRESSED.
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
static bool defaultUseNamePrefix
Global default for useNamePrefix.
const entry * findEntry(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
void clear()
Clear the PtrList. Delete allocated entries and set size to zero.
messageStream Info
Information stream (stdout output on master, null elsewhere)
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.
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
void transfer(PtrList< T > &list)
Transfer into this list and annul the argument list.
objectRegistry & storedObjects()
Write access to the output objects ("functionObjectObjects") registered on Time.
Mesh consisting of general polyhedral cells.
entry * set(entry *entryPtr)
Assign a new entry, overwriting any existing entry.
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
static autoPtr< functionObject > New(const word &name, const Time &runTime, const dictionary &dict)
Select from dictionary, based on its "type" entry.
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.
void updateMesh(const mapPolyMesh &mpm)
Update for changes of mesh.
Registry of regIOobjects.
label triggerIndex() const
Return the current trigger index (read from the propsDict)
fileNameList readDir(const fileName &directory, const fileName::Type type=fileName::Type::FILE, const bool filtergz=true, const bool followLink=true)
Read a directory and return the entries as a fileName List.
Foam::argList args(argc, argv)
void movePoints(const polyMesh &mesh)
Update for changes of mesh.
Defines the attributes of an object for which implicit objectRegistry management is supported...
static fileName functionObjectDictPath
Default relative path ("caseDicts/postProcessing") to the directory structure containing functionObje...
bool end()
Called when Time::run() determines that the time-loop exits.
bool found(const word &optName) const
Return true if the named option is found.
A keyword and a list of tokens is an 'entry'.
const dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary pointer if present (and a sub-dictionary) otherwise return nullptr...
string expand(const std::string &s, const HashTable< string > &mapping, const char sigil='$')
Expand occurrences of variables according to the mapping and return the expanded string.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...