38namespace functionObjects
53 item.clear(
obr(),
false);
61 addMeanField<scalar>(item);
62 addMeanField<vector>(item);
63 addMeanField<sphericalTensor>(item);
64 addMeanField<symmTensor>(item);
65 addMeanField<tensor>(item);
71 addPrime2MeanField<scalar, scalar>(item);
72 addPrime2MeanField<vector, symmTensor>(item);
78 restoreWindowFields<scalar>(item);
79 restoreWindowFields<vector>(item);
80 restoreWindowFields<sphericalTensor>(item);
81 restoreWindowFields<symmTensor>(item);
82 restoreWindowFields<tensor>(item);
91 <<
"Field " << item.fieldName()
92 <<
" not found in database for averaging";
106 Log <<
" Restarting averaging at time "
107 << obr().time().timeOutputValue()
112 item.clear(obr(),
true);
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>();
185 calculatePrime2MeanFields<scalar, scalar>();
186 calculatePrime2MeanFields<vector, symmTensor>();
194 Log <<
" Writing average fields" <<
endl;
196 writeFields<scalar>();
197 writeFields<vector>();
198 writeFields<sphericalTensor>();
199 writeFields<symmTensor>();
200 writeFields<tensor>();
212 setProperty(item.fieldName(),
propsDict);
219 if (restartOnRestart_ || restartOnOutput_)
221 Info<<
" Starting averaging at time "
222 << obr().time().timeOutputValue()
227 Info<<
" Restarting averaging for fields:" <<
nl;
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),
299 initialised_ =
false;
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_);
311 dict.readEntry(
"fields", faItems_);
313 for (
auto& item : faItems_)
315 item.setMeanFieldName(scopedName(item.meanFieldName()));
316 item.setPrime2MeanFieldName(scopedName(item.prime2MeanFieldName()));
319 const scalar currentTime = obr().time().value();
321 if (periodicRestart_)
323 scalar userRestartPeriod =
dict.get<scalar>(
"restartPeriod");
324 restartPeriod_ = obr().time().userTimeToTime(userRestartPeriod);
326 if (restartPeriod_ > 0)
330 while (currentTime > restartPeriod_*periodIndex_)
335 Info<<
" Restart period " << userRestartPeriod
336 <<
" - next restart at " << (userRestartPeriod*periodIndex_)
341 periodicRestart_ =
false;
343 Info<<
" Restart period " << userRestartPeriod
349 scalar userRestartTime = 0;
350 if (
dict.readIfPresent(
"restartTime", userRestartTime))
352 restartTime_ = obr().time().userTimeToTime(userRestartTime);
354 if (currentTime > restartTime_)
357 restartTime_ = GREAT;
361 Info<<
" Restart scheduled at time " << userRestartTime
366 readAveragingProperties();
385 writeAveragingProperties();
387 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.
virtual bool read()
Re-read model coefficients if they have changed.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
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 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...
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.
virtual void calcAverages()
Main calculation routine.
bool initialised_
Initialised flag.
List< fieldAverageItem > faItems_
List of field average items, describing what averages to be.
virtual void writeAverages() const
Write averages.
void readAveragingProperties()
Read averaging properties - steps and time.
virtual bool execute()
Calculate the field averages.
virtual bool write()
Write the field averages.
virtual bool read(const dictionary &)
Read the field average data.
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
virtual const objectRegistry & obr() const
The region or sub-region registry being used.
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.
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.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
constexpr char nl
The newline '\n' character (0x0a)
#define forAll(list, i)
Loop across all elements in list.
IOdictionary propsDict(dictIO)