40 { windowType::NONE,
"none" },
42 { windowType::EXACT,
"exact" }
68 forAll(fieldNames_, fieldi)
70 const word& fieldName = fieldNames_[fieldi];
72 if (
dict.found(fieldName))
75 valueDict.readEntry(
"totalTime", totalTime_[fieldi]);
88 forAll(fieldNames_, fieldi)
90 const word& fieldName = fieldNames_[fieldi];
92 if (
dict.found(fieldName))
95 valueDict.add(
"totalTime", totalTime_[fieldi],
true);
101 dict.add(fieldName, valueDict);
109 forAll(fieldNames_, fieldi)
124 stateFunctionObject& state,
125 const bool writeToFile
130 resetOnRestart_(false),
131 windowType_(windowType::NONE),
133 functionObjectName_(
"unknown-functionObject"),
135 tolerance_(
dict.getOrDefault<scalar>(
"tolerance", -1)),
152 resetOnRestart_ =
false;
154 dict.readEntry(
"functionObject", functionObjectName_);
155 dict.readEntry(
"fields", fieldNames_);
156 if (
dict.readIfPresent(
"window", window_))
158 window_ = state_.time().userTimeToTime(window_);
162 windowType_ = windowTypeNames.get(
"windowType",
dict);
166 totalTime_.resize(fieldNames_.size(),
Zero);
168 dict.readIfPresent(
"resetOnRestart", resetOnRestart_);
170 dict.readIfPresent(
"log",
log);
181 scalar dt = state_.time().deltaTValue();
183 Log <<
indent << state_.type() <<
": " << prefix_.c_str()
184 <<
" averages:" <<
nl;
186 file() << state_.time().timeName();
190 bool converged =
true;
192 forAll(fieldNames_, fieldi)
194 totalTime_[fieldi] += dt;
196 const bool processed =
198 calc<label, scalar>(fieldi, converged,
dict)
199 || calc<scalar>(fieldi, converged,
dict)
200 || calc<vector>(fieldi, converged,
dict)
201 || calc<sphericalTensor>(fieldi, converged,
dict)
202 || calc<symmTensor>(fieldi, converged,
dict)
203 || calc<tensor>(fieldi, converged,
dict)
208 unprocessedFields.
append(fieldNames_[fieldi]);
210 file() <<
tab <<
"n/a";
216 if (unprocessedFields.
size())
219 <<
"From function object: " << functionObjectName_ <<
nl
220 <<
"Unprocessed fields:" <<
nl;
222 for (
const word& fieldName : unprocessedFields)
227 if (unprocessedFields.size() == fieldNames_.size())
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
void append(const T &val)
Copy append an element to the end of this list.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
void size(const label n)
Older name for setAddressableSize.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, IOobjectOption::readOption readOpt=IOobjectOption::MUST_READ) const
Find entry and assign to T val. FatalIOError if it is found and the number of tokens is incorrect,...
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Base class for function objects, adding functionality to read/write state information (data required ...
word functionObjectName_
Name of function object to retrieve data from.
windowType
Averaging window types.
@ APPROXIMATE
"approximate"
scalar tolerance_
Optional tolerance to check for converged results.
virtual void readState(dictionary &dict)
Read state from dictionary.
wordList fieldNames_
List of fields on which to operate.
virtual void writeState(dictionary &dict)
Write state to dictionary for restarts.
virtual bool calculate(dictionary &dict)
Calculate the averages.
List< scalar > totalTime_
Average time per field.
virtual bool read(const dictionary &dict)
Read the field value average data.
bool calc(const label fieldi, bool &converged, dictionary &dict)
Templated function to calculate the average.
virtual void writeFileHeader(Ostream &os) const
Output file header information.
scalar window_
Averaging window.
bool resetOnRestart_
Reset the averaging process on restart.
valueAverageBase(const word &name, const objectRegistry &obr, const dictionary &dict, stateFunctionObject &state, const bool writeToFile=true)
Construct from Time and dictionary.
static const Enum< windowType > windowTypeNames
Names for windowType enumeration.
virtual void resetState(dictionary &dict)
Reset state.
stateFunctionObject & state_
Reference to the state functionObject.
windowType windowType_
Window type.
virtual void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
writeFile(const objectRegistry &obr, const fileName &prefix, const word &name="undefined", const bool writeToFile=true, const string &ext=".dat")
Construct from objectRegistry, prefix, fileName.
virtual void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
virtual bool read(const dictionary &dict)
Read.
const fileName prefix_
Prefix.
virtual OFstream & file()
Return access to the file (if only 1).
virtual void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
virtual bool writeToFile() const
Flag to allow writing to file.
Registry of regIOobjects.
A class for handling words, derived from Foam::string.
OBJstream os(runTime.globalPath()/outputName)
#define WarningInFunction
Report a warning using Foam::Warning.
dimensionedScalar log(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Ostream & indent(Ostream &os)
Indent stream.
static constexpr const zero Zero
Global zero (0).
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
constexpr char nl
The newline '\n' character (0x0a).
constexpr char tab
The tab '\t' character(0x09).
#define forAll(list, i)
Loop across all elements in list.