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"),
124 void Foam::functionObjectList::createOutputRegistry()
const 126 objectsRegistryPtr_.reset
132 "functionObjectObjects",
150 autoPtr<functionObject> oldptr;
152 auto iter = indices_.find(
key);
159 oldptr = this->release(oldIndex);
160 indices_.erase(iter);
171 void Foam::functionObjectList::listDir
189 listDir(dir/d, available);
200 listDir(d, available);
204 <<
"Available configured functionObjects:" 221 for (
const fileName& d :
findEtcDirs(functionObjectDictPath))
223 dictFile =
search(funcName, d);
224 if (!dictFile.empty())
236 const string& funcNameArgs,
254 const auto argsBeg = funcNameArgs.find(
'(');
255 if (argsBeg == std::string::npos)
265 const auto argsEnd = funcNameArgs.rfind(
')');
273 (argsEnd != std::string::npos && argsBeg < argsEnd)
274 ? (argsEnd - argsBeg - 1)
291 <<
"Cannot find functionObject file " << funcName <<
endl;
297 ISstream& fileStream = *fileStreamPtr;
301 dictionary& funcDict = (funcDictPtr ? *funcDictPtr : funcsDict);
309 funcDict.
set(
"field",
args[0]);
318 else if (funcDict.
found(
"field"))
322 else if (funcDict.
found(
"fields"))
332 namedArg.first() +
' ' + namedArg.second() +
';' 341 funcDict.
set(
"region", region);
347 functionsDict.
merge(funcArgsDict);
353 Foam::functionObjectList::errorHandlingType
354 Foam::functionObjectList::getOrDefaultErrorHandling
358 const errorHandlingType deflt
368 <<
"The sub-dictionary '" <<
key 369 <<
"' masks error handling for functions" <<
endl;
373 const word enumName(eptr->
get<word>());
375 if (!errorHandlingNames_.found(enumName))
379 << enumName <<
" is not in enumeration: " 380 << errorHandlingNames_ <<
nl 384 return errorHandlingNames_.get(enumName);
394 Foam::functionObjectList::functionObjectList
404 Foam::functionObjectList::functionObjectList
417 parentDict_(parentDict),
418 propsDictPtr_(nullptr),
419 objectsRegistryPtr_(nullptr),
420 execution_(execution),
444 bool modifiedControlDict =
false;
448 modifiedControlDict =
true;
468 modifiedControlDict =
true;
481 modifiedControlDict =
true;
498 if (modifiedControlDict)
507 functionsPtr->
start();
524 propsDictPtr_.reset(
nullptr);
525 createPropertiesDict();
533 createPropertiesDict();
536 return *propsDictPtr_;
545 createPropertiesDict();
548 return *propsDictPtr_;
554 if (!objectsRegistryPtr_)
556 createOutputRegistry();
559 return *objectsRegistryPtr_;
565 if (!objectsRegistryPtr_)
567 createOutputRegistry();
570 return *objectsRegistryPtr_;
577 errorHandling_.clear();
591 if (funcObj.name() == objName)
612 updated_ = execution_ =
false;
639 auto errIter = errorHandling_.cbegin();
643 const errorHandlingType errorHandling = *errIter;
646 const word& objName = funcObj.name();
650 errorHandling == errorHandlingType::WARN
651 || errorHandling == errorHandlingType::IGNORE
659 bool hadError =
false;
667 "functionObject::" + objName +
"::execute" 670 ok = funcObj.execute() && ok;
680 errorHandling != errorHandlingType::IGNORE
681 && (nWarnings = ++warnings_(objName)) <=
maxWarnings 687 <<
"--> execute() function object '" 692 Info<<
nl <<
"... silencing further warnings";
713 "functionObject::" + objName +
":write" 716 ok = funcObj.write() && ok;
725 errorHandling != errorHandlingType::IGNORE
726 && (nWarnings = ++warnings_(objName)) <=
maxWarnings 732 <<
"--> write() function object '" 737 Info<<
nl <<
"... silencing further warnings";
757 "functionObject::" + objName +
"::execute" 760 ok = funcObj.execute() && ok;
768 "functionObject::" + objName +
":write" 771 ok = funcObj.write() && ok;
778 if (time_.writeTime())
783 propsDictPtr_->writeObject
798 bool ok = execution_;
806 ok = funcObj.execute(subIndex) && ok;
820 bool ok = execution_;
822 if (ok && functionNames.
size())
830 ok = funcObj.execute(subIndex) && ok;
850 auto errIter = errorHandling_.cbegin();
854 const errorHandlingType errorHandling = *errIter;
857 const word& objName = funcObj.name();
867 addProfiling(fo,
"functionObject::" + objName +
"::end");
868 ok = funcObj.end() && ok;
877 errorHandling != errorHandlingType::IGNORE
878 && (nWarnings = ++warnings_(objName)) <=
maxWarnings 884 <<
"--> end() function object '" 889 Info<<
nl <<
"... silencing further warnings";
919 const word& objName = funcObj.name();
926 "functionObject::" + objName +
"::adjustTimeStep" 929 ok = funcObj.adjustTimeStep() && ok;
941 createPropertiesDict();
944 updated_ = execution_;
953 const entry* entryPtr =
962 errorHandling_.clear();
967 else if (!entryPtr->isDict())
972 <<
"'functions' entry is not a dictionary" 977 const dictionary& functionsDict = entryPtr->dict();
979 PtrList<functionObject> newPtrs(functionsDict.size());
980 List<SHA1Digest> newDigs(functionsDict.size());
982 errorHandling_.resize
984 functionsDict.size(),
985 errorHandlingType::DEFAULT
988 HashTable<label> newIndices;
997 functionObject::dictionaryConstructorTablePtr_
1001 const errorHandlingType errorHandlingFallback =
1002 getOrDefaultErrorHandling
1006 errorHandlingType::DEFAULT
1011 for (
const entry& dEntry : functionsDict)
1013 const word&
key = dEntry.keyword();
1015 if (!dEntry.isDict())
1019 if (
key ==
"useNamePrefix")
1021 Switch sw(dEntry.stream().front());
1029 <<
"Entry '" <<
key <<
"' is not a valid switch" 1033 else if (
key !=
"errors" &&
key !=
"libs")
1036 <<
"Entry '" <<
key <<
"' is not a dictionary" 1043 const dictionary&
dict = dEntry.dict();
1048 const errorHandlingType errorHandling =
1049 getOrDefaultErrorHandling
1053 errorHandlingFallback
1056 errorHandling_[nFunc] = errorHandling;
1060 label oldIndex = -1;
1061 autoPtr<functionObject> objPtr =
remove(
key, oldIndex);
1063 const bool needsTimeControl =
1072 if (enabled && newDigs[nFunc] != digests_[oldIndex])
1074 const bool wasTimeControl =
1075 isA<functionObjects::timeControl>(*objPtr);
1077 if (needsTimeControl != wasTimeControl)
1082 objPtr.reset(
nullptr);
1091 "functionObject::" + objPtr->name() +
"::read" 1094 enabled = objPtr->read(
dict);
1101 objPtr.reset(
nullptr);
1106 if (enabled && !objPtr)
1118 "functionObject::" +
key +
"::new" 1120 if (needsTimeControl)
1124 new functionObjects::timeControl(
key, time_,
dict)
1134 objPtr.reset(
nullptr);
1136 switch (errorHandling)
1138 case errorHandlingType::IGNORE:
1141 case errorHandlingType::STRICT:
1147 case errorHandlingType::DEFAULT:
1149 if (isA<Foam::IOerror>(err))
1160 case errorHandlingType::WARN:
1165 <<
"--> loading function object '" 1180 objPtr.reset(
nullptr);
1188 newPtrs.set(nFunc, std::move(objPtr));
1189 newIndices.insert(
key, nFunc);
1194 newPtrs.resize(nFunc);
1195 newDigs.resize(nFunc);
1196 errorHandling_.resize(nFunc);
1201 digests_.transfer(newDigs);
1202 indices_.transfer(newIndices);
1217 bool changed = funcObj.filesModified();
1231 funcObj.updateMesh(mpm);
1243 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 List 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.
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::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.
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...
virtual void write(Ostream &os, const bool withTitle=true) const
Print error message.
Reading is optional [identical to LAZY_READ].
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.
static void printStack(Ostream &os, int size=-1)
Helper function to print a stack, with optional upper limit.
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...
Request registration (bool: true)
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 ...