50 for (fieldAverageItem& item :
faItems_)
53 item.clear(
obr(),
false);
59 for (fieldAverageItem& item :
faItems_)
69 for (fieldAverageItem& item :
faItems_)
76 for (
const fieldAverageItem& item :
faItems_)
86 for (
const fieldAverageItem& item :
faItems_)
91 <<
"Field " << item.fieldName()
92 <<
" not found in database for averaging";
106 Log <<
" Restarting averaging at time "
107 << obr().time().timeOutputValue()
126 const label currentTimeIndex = obr().time().timeIndex();
127 const scalar currentTime = obr().time().value();
129 if (prevTimeIndex_ == currentTimeIndex)
135 prevTimeIndex_ = currentTimeIndex;
138 bool doRestart =
false;
139 if (periodicRestart_)
141 const scalar deltaT = obr().time().deltaTValue();
142 const scalar nextTime = restartPeriod_*periodIndex_ + 0.5*deltaT;
144 if (currentTime > nextTime)
151 if (currentTime >= restartTime_)
154 restartTime_ = GREAT;
163 <<
" Calculating averages" <<
nl;
167 faItems_[fieldi].evolve(obr());
170 storeWindowFields<scalar>();
171 storeWindowFields<vector>();
172 storeWindowFields<sphericalTensor>();
173 storeWindowFields<symmTensor>();
174 storeWindowFields<tensor>();
176 addMeanSqrToPrime2Mean<scalar, scalar>();
177 addMeanSqrToPrime2Mean<vector, symmTensor>();
179 calculateMeanFields<scalar>();
180 calculateMeanFields<vector>();
181 calculateMeanFields<sphericalTensor>();
182 calculateMeanFields<symmTensor>();
183 calculateMeanFields<tensor>();
194 Log <<
" Writing average fields" <<
endl;
219 if (restartOnRestart_ || restartOnOutput_)
221 Info<<
" Starting averaging at time "
222 << obr().time().timeOutputValue()
227 Info<<
" Restarting averaging for fields:" <<
nl;
230 for (fieldAverageItem& item : faItems_)
232 const word& fieldName = item.fieldName();
233 if (foundProperty(fieldName))
236 getDict(fieldName, fieldDict);
237 item.readState(fieldDict);
239 if (item.allowRestart())
241 scalar userTotalTime =
242 obr().time().timeToUserTime(item.totalTime());
244 Info<<
" " << fieldName
245 <<
": iters = " << item.totalIter()
246 <<
" time = " << userTotalTime <<
nl;
250 item.clear(obr(),
true);
252 Info<<
" " << fieldName
253 <<
": starting averaging at time "
254 << obr().time().timeOutputValue() <<
endl;
259 Info<<
" " << fieldName
260 <<
": starting averaging at time "
261 << obr().time().timeOutputValue() <<
endl;
280 restartOnRestart_(false),
281 restartOnOutput_(false),
282 periodicRestart_(false),
283 restartPeriod_(GREAT),
300 restartOnRestart_ =
false;
301 restartOnOutput_ =
false;
302 periodicRestart_ =
false;
303 restartPeriod_ = GREAT;
304 restartTime_ = GREAT;
308 dict.readIfPresent(
"restartOnRestart", restartOnRestart_);
309 dict.readIfPresent(
"restartOnOutput", restartOnOutput_);
310 dict.readIfPresent(
"periodicRestart", periodicRestart_);
313 dict.readEntry(
"fields", faItems0);
318 for (
auto& item : faItems0)
320 if (
names.insert(item.fieldName()))
322 item.setMeanFieldName(scopedName(item.meanFieldName()));
323 item.setPrime2MeanFieldName(scopedName(item.prime2MeanFieldName()));
324 faItems.push_back(item);
329 <<
"Duplicate entry found: " << item.fieldName()
330 <<
" (ignored)" <<
endl;
334 faItems_.transfer(faItems);
336 const scalar currentTime = obr().time().value();
338 if (periodicRestart_)
340 scalar userRestartPeriod =
dict.get<scalar>(
"restartPeriod");
341 restartPeriod_ = obr().time().userTimeToTime(userRestartPeriod);
343 if (restartPeriod_ > 0)
347 while (currentTime > restartPeriod_*periodIndex_)
352 Info<<
" Restart period " << userRestartPeriod
353 <<
" - next restart at " << (userRestartPeriod*periodIndex_)
358 periodicRestart_ =
false;
360 Info<<
" Restart period " << userRestartPeriod
366 scalar userRestartTime = 0;
367 if (
dict.readIfPresent(
"restartTime", userRestartTime))
369 restartTime_ = obr().time().userTimeToTime(userRestartTime);
371 if (currentTime > restartTime_)
374 restartTime_ = GREAT;
378 Info<<
" Restart scheduled at time " << userRestartTime
383 readAveragingProperties();
402 writeAveragingProperties();
404 if (restartOnOutput_)
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
IOdictionary propsDict(dictIO)
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
void push_back(const T &val)
Copy append an element to the end of this list.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
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,...
Abstract base-class for Time/database function objects.
const word & name() const noexcept
Return the name of this functionObject.
virtual bool read(const dictionary &dict)
Read and set the function object if its data have changed.
word scopedName(const word &name) const
Return a scoped (prefixed) name.
virtual const word & type() const =0
Runtime type information.
Helper class to describe what form of averaging to apply. A set will be applied to each base field in...
Computes ensemble- and/or time-based field averages, with optional windowing, for a user-specified se...
Switch periodicRestart_
Periodically restart the averaging process.
label prevTimeIndex_
Time at last call, prevents repeated averaging.
void writeAveragingProperties()
Write averaging properties - steps and time.
void restart()
Restart averaging for restartOnOutput.
void initialize()
Reset lists (clear existing values) and initialize averaging.
Switch restartOnRestart_
Restart the averaging process on restart.
Switch restartOnOutput_
Restart the averaging process on output.
label periodIndex_
Index for periodic restart.
virtual void calcAverages()
Main calculation routine.
scalar restartPeriod_
Restart period.
bool addMeanField(fieldAverageItem &item)
Add mean average field to database.
scalar restartTime_
Specific restart time.
bool initialised_
Initialised flag.
void calculatePrime2MeanFields() const
Calculate prime-squared average fields.
List< fieldAverageItem > faItems_
List of field average items, describing what averages to be calculated and output.
virtual bool read(const dictionary &dict)
Read the function-object dictionary.
bool addPrime2MeanField(fieldAverageItem &item)
Add prime-squared average field to database.
virtual void writeAverages() const
Write averages.
void readAveragingProperties()
Read averaging properties - steps and time.
virtual bool execute()
Execute the function-object operations.
virtual bool write()
Write the function-object results.
fieldAverage(const word &name, const Time &runTime, const dictionary &)
Construct from name, Time and dictionary.
void calculateMeanFields() const
Calculate mean average fields.
void restoreWindowFields(const fieldAverageItem &item)
void addMeanSqrToPrime2Mean() const
Add mean-squared field value to prime-squared mean field.
fvMeshFunctionObject(const fvMeshFunctionObject &)=delete
No copy construct.
virtual const objectRegistry & obr() const
The region or sub-region registry being used.
bool getDict(const word &entryName, dictionary &dict) const
Set dictionary, return true if set.
bool foundProperty(const word &entryName) const
Return true if the property exists.
void setProperty(const word &entryName, const Type &value)
Add generic property.
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define WarningInFunction
Report a warning using Foam::Warning.
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
bool read(const char *buf, int32_t &val)
Same as readInt32.
messageStream Info
Information stream (stdout output on master, null elsewhere).
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Ostream & endl(Ostream &os)
Add newline and flush stream.
void writeFields(const fvMesh &mesh, const wordHashSet &selectedFields, const bool writeFaceFields)
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).
static bool initialised_(false)
#define forAll(list, i)
Loop across all elements in list.