51 "caseDicts/postProcessing"
65 <<
"\nFOAM aborting (FOAM_ABORT set)\n" <<
endl;
72 <<
"\nFOAM parallel run exiting\n" <<
endl;
78 <<
"\nFOAM exiting\n" <<
endl;
88void Foam::functionObjectList::createPropertiesDict()
const
94 new functionObjects::properties
98 "functionObjectProperties",
100 "uniform"/word(
"functionObjects"),
111void Foam::functionObjectList::createOutputRegistry()
const
113 objectsRegistryPtr_.reset
119 "functionObjectObjects",
131Foam::autoPtr<Foam::functionObject> Foam::functionObjectList::remove
139 auto iter = indices_.find(key);
146 oldptr = this->release(oldIndex);
147 indices_.erase(iter);
158void Foam::functionObjectList::listDir
176 listDir(dir/d, available);
187 listDir(d, available);
191 <<
"Available configured functionObjects:"
208 for (
const fileName& d :
findEtcDirs(functionObjectDictPath))
210 dictFile =
search(funcName, d);
211 if (!dictFile.empty())
223 const string& funcNameArgs,
241 const auto argsBeg = funcNameArgs.find(
'(');
242 if (argsBeg == std::string::npos)
252 const auto argsEnd = funcNameArgs.rfind(
')');
260 (argsEnd != std::string::npos && argsBeg < argsEnd)
261 ? (argsEnd - argsBeg - 1)
278 <<
"Cannot find functionObject file " << funcName <<
endl;
284 ISstream& fileStream = *fileStreamPtr;
288 dictionary& funcDict = (funcDictPtr ? *funcDictPtr : funcsDict);
296 funcDict.set(
"field",
args[0]);
297 funcDict.set(
"fields",
args);
302 funcDict.set(
"fields",
args);
305 else if (funcDict.found(
"field"))
309 else if (funcDict.found(
"fields"))
319 namedArg.first() +
' ' + namedArg.second() +
';'
328 funcDict.set(
"region", region);
334 functionsDict.
merge(funcArgsDict);
341Foam::functionObjectList::getOrDefaultErrorHandling
355 <<
"The sub-dictionary '" <<
key
356 <<
"' masks error handling for functions" <<
endl;
360 const word enumName(eptr->get<
word>());
366 << enumName <<
" is not in enumeration: "
381Foam::functionObjectList::functionObjectList
391Foam::functionObjectList::functionObjectList
404 parentDict_(parentDict),
405 propsDictPtr_(nullptr),
406 objectsRegistryPtr_(nullptr),
407 execution_(execution),
431 bool modifiedControlDict =
false;
433 if (
args.found(
"dict"))
435 modifiedControlDict =
true;
453 if (
args.found(
"func"))
455 modifiedControlDict =
true;
468 modifiedControlDict =
true;
485 if (modifiedControlDict)
494 functionsPtr->start();
511 propsDictPtr_.reset(
nullptr);
512 createPropertiesDict();
520 createPropertiesDict();
523 return *propsDictPtr_;
532 createPropertiesDict();
535 return *propsDictPtr_;
541 if (!objectsRegistryPtr_)
543 createOutputRegistry();
546 return *objectsRegistryPtr_;
552 if (!objectsRegistryPtr_)
554 createOutputRegistry();
557 return *objectsRegistryPtr_;
564 errorHandling_.clear();
578 if (funcObj.name() == objName)
599 updated_ = execution_ =
false;
626 auto errIter = errorHandling_.cbegin();
630 const auto errorHandling = *errIter;
633 const word& objName = funcObj.name();
643 const bool oldThrowingError =
FatalError.throwing(
true);
644 const bool oldThrowingIOerr =
FatalIOError.throwing(
true);
646 bool hadError =
false;
654 "functionObject::", objName,
"::execute"
657 ok = funcObj.execute() && ok;
668 && (nWarnings = ++warnings_(objName)) <=
maxWarnings
674 <<
"--> execute() function object '"
679 Info<<
nl <<
"... silencing further warnings";
700 "functionObject::", objName,
":write"
703 ok = funcObj.write() && ok;
714 && (nWarnings = ++warnings_(objName)) <=
maxWarnings
720 <<
"--> write() function object '"
725 Info<<
nl <<
"... silencing further warnings";
741 && !hadError && !warnings_.empty()
744 warnings_.erase(objName);
756 "functionObject::", objName,
"::execute"
759 ok = funcObj.execute() && ok;
767 "functionObject::", objName,
":write"
770 ok = funcObj.write() && ok;
777 if (time_.writeTime() && writeProperties)
782 propsDictPtr_->writeObject
797 bool ok = execution_;
805 ok = funcObj.execute(subIndex) && ok;
819 bool ok = execution_;
821 if (ok && functionNames.
size())
829 ok = funcObj.execute(subIndex) && ok;
849 auto errIter = errorHandling_.cbegin();
853 const auto errorHandling = *errIter;
856 const word& objName = funcObj.name();
861 const bool oldThrowingError =
FatalError.throwing(
true);
862 const bool oldThrowingIOerr =
FatalIOError.throwing(
true);
867 ok = funcObj.end() && ok;
882 <<
"--> end() function object '"
896 && !warnings_.empty()
899 warnings_.erase(objName);
921 const word& objName = funcObj.name();
928 "functionObject::", objName,
"::adjustTimeStep"
931 ok = funcObj.adjustTimeStep() && ok;
943 createPropertiesDict();
946 updated_ = execution_;
955 const entry* entryPtr =
964 errorHandling_.clear();
969 else if (!entryPtr->isDict())
974 <<
"'functions' entry is not a dictionary"
979 const dictionary& functionsDict = entryPtr->dict();
984 errorHandling_.resize
986 functionsDict.size(),
999 functionObject::dictionaryConstructorTablePtr_
1004 getOrDefaultErrorHandling
1013 for (
const entry& dEntry : functionsDict)
1015 const word&
key = dEntry.keyword();
1017 if (!dEntry.isDict())
1021 if (key ==
"useNamePrefix")
1023 Switch sw(dEntry.stream().front());
1031 <<
"Entry '" <<
key <<
"' is not a valid switch"
1035 else if (key !=
"errors" && key !=
"libs")
1038 <<
"Entry '" <<
key <<
"' is not a dictionary"
1051 getOrDefaultErrorHandling
1055 errorHandlingFallback
1058 errorHandling_[nFunc] = errorHandling;
1062 label oldIndex = -1;
1065 const bool needsTimeControl =
1074 if (enabled && newDigs[nFunc] != digests_[oldIndex])
1076 const bool wasTimeControl =
1079 if (needsTimeControl != wasTimeControl)
1084 objPtr.reset(
nullptr);
1093 "functionObject::", objPtr->name(),
"::read"
1096 enabled = objPtr->read(
dict);
1103 objPtr.reset(
nullptr);
1108 if (enabled && !objPtr)
1111 const bool oldThrowingError =
FatalError.throwing(
true);
1112 const bool oldThrowingIOerr =
FatalIOError.throwing(
true);
1120 "functionObject::", key,
"::new"
1122 if (needsTimeControl)
1134 catch (
const Foam::error& err)
1136 objPtr.reset(
nullptr);
1138 switch (errorHandling)
1167 <<
"--> loading function object '"
1182 objPtr.reset(
nullptr);
1190 newPtrs.set(nFunc, std::move(objPtr));
1191 newIndices.insert(key, nFunc);
1196 newPtrs.resize(nFunc);
1197 newDigs.resize(nFunc);
1198 errorHandling_.resize(nFunc);
1203 digests_.transfer(newDigs);
1204 indices_.transfer(newIndices);
1219 bool changed = funcObj.filesModified();
1233 funcObj.updateMesh(mpm);
1245 funcObj.movePoints(
mesh);
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
IOdictionary propsDict(dictIO)
label size() const noexcept
The number of elements in list.
A HashTable with keys but without contents that is similar to std::unordered_set.
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
A HashTable similar to std::unordered_map.
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
@ REGISTER
Request registration (bool: true).
@ NO_READ
Nothing to be read.
@ READ_IF_PRESENT
Reading is optional [identical to LAZY_READ].
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
A simple container for options an IOstream can normally have.
@ ASCII
"ascii" (normal default)
static unsigned int precision_
Default precision.
Generic input stream using a standard (STL) stream.
Input from string buffer, using a ISstream. Always UNCOMPRESSED.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void resize(const label len)
Adjust allocated size of list.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
void transfer(PtrList< T > &list)
Transfer into this list and annul the argument list.
const T * set(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie,...
void clear()
Clear the PtrList. Delete allocated entries and set size to zero.
constexpr PtrList() noexcept
void resize(const label newLen)
Adjust size of PtrList.
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
bool good() const noexcept
True if the Switch represents a valid enumeration.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
static word timeName(const scalar t, const int precision=precision_)
Return a time name for the given scalar time value formatted with the given precision.
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
bool empty() const noexcept
True if List is empty (ie, size() is zero).
void size(const label n)
Older name for setAddressableSize.
static bool parRun(const bool on) noexcept
Set as parallel run on/off.
static void exit(int errNo=1)
Shutdown (finalize) MPI as required and exit program with errNo.
Extract command arguments and options from the supplied argc and argv parameters.
label size() const noexcept
The number of arguments.
bool found(const word &optName) const
Return true if the named option is found.
List< T > getList(const label index) const
Get a List of values from the argument at index.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
A keyword and a list of tokens is a 'dictionaryEntry'.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
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.
const dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary pointer if present (and it is a dictionary) otherwise return nullptr...
bool merge(const dictionary &dict)
Merge entries from the given dictionary.
const entry * findEntry(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
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...
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
entry * set(entry *entryPtr)
Assign a new entry, overwriting any existing entry.
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
SHA1Digest digest() const
Return the SHA1 digest of the dictionary contents.
A keyword and a list of tokens is an 'entry'.
virtual bool isDict() const noexcept
True if this entry is a dictionary.
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.
virtual const dictionary & dict() const =0
Return dictionary, if entry is a dictionary, otherwise Fatal.
T get() const
Get a T from the stream, FatalIOError if the number of tokens is incorrect.
Class to handle errors and exceptions in a simple, consistent stream-based manner.
handlerTypes
Handling of errors. The exact handling depends on the local context.
@ WARN
Warn on errors/problems.
@ STRICT
Fatal on errors/problems.
@ DEFAULT
Default behaviour (local meaning).
@ IGNORE
Ignore on errors/problems.
virtual void write(Ostream &os, const bool withTitle=true) const
Print error message.
static bool useAbort()
True if FOAM_ABORT is on.
static void printStack(Ostream &os, int size=-1)
Helper function to print a stack, with optional upper limit.
static const Enum< handlerTypes > handlerNames
Names of the error handler types.
A class for handling file names.
static const fileName null
An empty fileName.
List of function objects with start(), execute() and end() functions that is called for each object.
static fileName findDict(const word &funcName)
Find a functionObject dictionary file in the case <system> directory or any directory located using F...
void off()
Switch the function objects off.
static autoPtr< functionObjectList > New(const argList &args, const Time &runTime, dictionary &controlDict, HashSet< wordRe > &requiredFields)
Construct and return a functionObjectList for an application.
objectRegistry & storedObjects()
Write access to the output objects ("functionObjectObjects") registered on Time.
bool filesModified() const
Did any file get changed during execution?
void movePoints(const polyMesh &mesh)
Update for changes of mesh.
label findObjectID(const word &objName) const
Find the ID of a given function object by name, -1 if not found.
bool adjustTimeStep()
Called at the end of Time::adjustDeltaT() if adjustTime is true.
void updateMesh(const mapPolyMesh &mpm)
Update for changes of mesh.
static void list()
Print a list of functionObject configuration files in the directories located using Foam::findEtcDirs...
bool start()
Called at the start of the time-loop.
bool execute(bool writeProperties=true)
Called at each ++ or += of the time-loop.
void clear()
Clear the list of function objects.
void resetPropertiesDict()
Reset/read properties dictionary for current time.
functionObjects::properties & propsDict()
Write access to the properties dictionary ("functionObjectProperties") registered on Time.
bool status() const
Return the execution status (on/off) of the function objects.
label triggerIndex() const
Return the current trigger index (read from the propsDict).
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 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.
void on()
Switch the function objects on.
bool read()
Read and set the function objects if their data have changed.
Abstract base-class for Time/database function objects.
static bool defaultUseNamePrefix
Global default for useNamePrefix.
static autoPtr< functionObject > New(const word &name, const Time &runTime, const dictionary &dict)
Select from dictionary, based on its "type" entry.
Storage for function object properties, derived from IOdictionary. Provides functionality to read/wri...
Wrapper around functionObjects to add time control.
static bool entriesPresent(const dictionary &dict)
Helper function to identify if a timeControl object is present.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Registry of regIOobjects.
Mesh consisting of general polyhedral cells.
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
A List of wordRe with additional matching capabilities.
static bool match(const UList< wordRe > &selectors, const std::string &text, bool literal=false)
Test for a match of any selectors against the text.
A class for handling words, derived from Foam::string.
static word validate(const std::string &s, const bool prefix=false)
Construct validated word (no invalid characters).
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
runTime controlDict().readEntry("adjustTimeStep"
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Functions to search 'etc' directories for configuration files etc.
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
#define WarningInFunction
Report a warning using Foam::Warning.
constexpr auto key(const Type &t) noexcept
Helper function to return the enum value.
label splitFunctionArgs(const std::string &str, wordRes &args, List< Tuple2< word, string > > &namedArgs)
Split out arguments (named or unnamed) from an input string.
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.
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
bool read(const char *buf, int32_t &val)
Same as readInt32.
prefixOSstream Perr
OSstream wrapped stderr (std::cerr) with parallel prefix.
static void exitNow(const error &err)
Mimic exit handling of the error class.
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler().
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
const Type * isA(const U &obj)
Attempt dynamic_cast to Type.
bool returnReduceAnd(const bool value, const int communicator=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
fileNameList findEtcDirs(const fileName &name, unsigned short location=0777, const bool findFirst=false)
Search for directories from user/group/other etc locations.
errorManipArg< error, int > exit(error &err, const int errNo=1)
messageStream Warning
Warning stream (stdout output on master, null elsewhere), with additional 'FOAM Warning' header text.
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
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.
constexpr char nl
The newline '\n' character (0x0a).
#define addProfiling(Name,...)
Define profiling trigger with specified name and description string. The description is generated by ...
Foam::argList args(argc, argv)
static constexpr const unsigned maxWarnings