35 namespace functionObjects
49 if (faItems_[i].mean())
51 if (obr_.found(faItems_[i].meanFieldName()))
53 obr_.checkOut(*obr_[faItems_[i].meanFieldName()]);
57 if (faItems_[i].prime2Mean())
59 if (obr_.found(faItems_[i].prime2MeanFieldName()))
61 obr_.checkOut(*obr_[faItems_[i].prime2MeanFieldName()]);
70 if (!totalIter_.size())
72 totalIter_.setSize(faItems_.size(), 1);
75 if (!totalTime_.size())
77 totalTime_.setSize(faItems_.size(), obr_.time().deltaTValue());
84 if (totalTime_[fieldi] < 0)
86 totalTime_[fieldi] = obr_.time().deltaTValue();
96 addMeanField<scalar>(fieldi);
97 addMeanField<vector>(fieldi);
98 addMeanField<sphericalTensor>(fieldi);
99 addMeanField<symmTensor>(fieldi);
100 addMeanField<tensor>(fieldi);
106 addPrime2MeanField<scalar, scalar>(fieldi);
107 addPrime2MeanField<vector, symmTensor>(fieldi);
119 Log <<
" Restarting averaging at time " << obr_.time().timeName()
136 const label currentTimeIndex = obr_.time().timeIndex();
137 const scalar currentTime = obr_.time().value();
139 if (prevTimeIndex_ == currentTimeIndex)
145 prevTimeIndex_ = currentTimeIndex;
148 if (periodicRestart_ && currentTime > restartPeriod_*periodIndex_)
155 <<
" Calculating averages" <<
nl;
157 addMeanSqrToPrime2Mean<scalar, scalar>();
158 addMeanSqrToPrime2Mean<vector, symmTensor>();
160 calculateMeanFields<scalar>();
161 calculateMeanFields<vector>();
162 calculateMeanFields<sphericalTensor>();
163 calculateMeanFields<symmTensor>();
164 calculateMeanFields<tensor>();
166 calculatePrime2MeanFields<scalar, scalar>();
167 calculatePrime2MeanFields<vector, symmTensor>();
171 totalIter_[fieldi]++;
172 totalTime_[fieldi] += obr_.time().deltaTValue();
181 Log <<
" Writing average fields" <<
endl;
183 writeFields<scalar>();
184 writeFields<vector>();
185 writeFields<sphericalTensor>();
186 writeFields<symmTensor>();
187 writeFields<tensor>();
199 name() +
"Properties",
200 obr_.time().timeName(),
211 const word& fieldName = faItems_[fieldi].fieldName();
213 propsDict.
subDict(fieldName).
add(
"totalIter", totalIter_[fieldi]);
214 propsDict.
subDict(fieldName).
add(
"totalTime", totalTime_[fieldi]);
217 propsDict.regIOobject::write();
225 if ((restartOnRestart_ || restartOnOutput_) &&
log)
227 Info<<
" Starting averaging at time " << obr_.time().timeName()
234 name() +
"Properties",
235 obr_.time().timeName(obr_.time().startTime().value()),
245 Log <<
" Starting averaging at time " 246 << obr_.time().timeName() <<
nl;
253 Log <<
" Restarting averaging for fields:" <<
nl;
255 totalIter_.setSize(faItems_.size(), 1);
259 totalTime_.setSize(faItems_.size(), -1);
263 const word& fieldName = faItems_[fieldi].fieldName();
264 if (propsDict.
found(fieldName))
268 totalIter_[fieldi] =
readLabel(fieldDict.lookup(
"totalIter"));
269 totalTime_[fieldi] =
readScalar(fieldDict.lookup(
"totalTime"));
271 Log <<
" " << fieldName
272 <<
" iters = " << totalIter_[fieldi]
273 <<
" time = " << totalTime_[fieldi] <<
nl;
291 restartOnRestart_(
false),
292 restartOnOutput_(
false),
293 periodicRestart_(
false),
294 restartPeriod_(great),
317 initialised_ =
false;
324 dict.
lookup(
"fields") >> faItems_;
326 if (periodicRestart_)
328 dict.
lookup(
"restartPeriod") >> restartPeriod_;
331 readAveragingProperties();
350 writeAveragingProperties();
352 if (restartOnOutput_)
void writeAveragingProperties() const
Write averaging properties - steps and time.
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
virtual bool read(const dictionary &)
Read the field average data.
#define forAll(list, i)
Loop across all elements in list.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
bool typeHeaderOk(const bool checkType=true)
Read header (uses typeFilePath to find file) and check header.
fieldAverage(const fieldAverage &)
Disallow default bitwise copy construct.
dimensionedScalar log(const dimensionedScalar &ds)
A list of keyword definitions, which are a keyword followed by any number of values (e...
virtual bool write()
Write the field averages.
Ostream & endl(Ostream &os)
Add newline and flush stream.
virtual bool execute()
Calculate the field averages.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
IOdictionary propsDict(IOobject("particleTrackProperties", runTime.constant(), mesh, IOobject::MUST_READ_IF_MODIFIED))
Macros for easy insertion into run-time selection tables.
bool add(entry *, bool mergeEntry=false)
Add a new entry.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
virtual bool read(const dictionary &)
Read optional controls.
bool read(const char *, int32_t &)
void readAveragingProperties()
Read averaging properties - steps and time.
A class for handling words, derived from string.
virtual void calcAverages()
Main calculation routine.
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
label readLabel(Istream &is)
word name(const complex &)
Return a string representation of a complex.
fileName::Type type(const fileName &, const bool followLink=true)
Return the file type: DIRECTORY or FILE.
void initialize()
Reset lists (clear existing values) and initialize averaging.
void resetFields()
Checkout fields (causes deletion) from the database.
void restart()
Restart averaging for restartOnOutput.
#define Log
Report write to Foam::Info if the local log switch is true.
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
virtual ~fieldAverage()
Destructor.
virtual void writeAverages() const
Write averages.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
addToRunTimeSelectionTable(functionObject, add, dictionary)
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.