55 Log <<
" Reading/initialising field " << meanFieldName <<
endl;
61 Log <<
" Cannot allocate average field " << meanFieldName
62 <<
" since an object with that name already exists."
63 <<
" Disabling averaging for field." <<
endl;
69 const Type& baseField = *fieldPtr;
102 fieldAverageItem& item
106 typedef typename VolFieldType::Internal VolFieldInternalType;
116 addMeanFieldType<VolFieldType>(item)
117 || addMeanFieldType<VolFieldInternalType>(item)
118 || addMeanFieldType<SurfaceFieldType>(item)
119 || addMeanFieldType<SurfFieldType>(item)
130 const fieldAverageItem& item
133 if (restartOnOutput_)
138 const word& fieldName = item.fieldName();
140 const Type* fieldPtr = findObject<Type>(fieldName);
147 const FIFOStack<word>& fieldNames = item.windowFieldNames();
151 const word&
name = fieldIter();
163 if (
io.typeHeaderOk<Type>(
true))
166 obr().store(
new Type(
io, fieldPtr->mesh()));
171 <<
"Unable to read window " << Type::typeName <<
" " <<
name
172 <<
". Averaging restart behaviour may be compromised"
184 const fieldAverageItem& item
188 typedef typename VolFieldType::Internal VolFieldInternalType;
192 if (item.window() > 0)
196 restoreWindowFieldsType<VolFieldType>(item)
197 || restoreWindowFieldsType<VolFieldInternalType>(item)
198 || restoreWindowFieldsType<SurfaceFieldType>(item)
205template<
class Type1,
class Type2>
208 fieldAverageItem& item
211 const auto* baseFieldPtr = findObject<Type1>(item.fieldName());
218 const word& meanFieldName = item.meanFieldName();
219 const word& prime2MeanFieldName = item.prime2MeanFieldName();
221 Log <<
" Reading/initialising field " << prime2MeanFieldName <<
nl;
223 if (foundObject<Type2>(prime2MeanFieldName))
225 else if (obr().
found(prime2MeanFieldName))
227 Log <<
" Cannot allocate average field " << prime2MeanFieldName
228 <<
" since an object with that name already exists."
229 <<
" Disabling averaging for field." <<
endl;
231 item.prime2Mean() =
false;
235 const auto& baseField = *baseFieldPtr;
236 const Type1& meanField = lookupObject<Type1>(meanFieldName);
253 sqr(baseField) -
sqr(meanField)
264template<
class Type1,
class Type2>
267 fieldAverageItem& item
271 typedef typename VolFieldType1::Internal VolFieldInternalType1;
276 typedef typename VolFieldType2::Internal VolFieldInternalType2;
282 if (item.prime2Mean())
287 <<
"To calculate the prime-squared average, the "
288 <<
"mean average must also be selected for field "
293 addPrime2MeanFieldType<VolFieldType1, VolFieldType2>(item)
294 || addPrime2MeanFieldType<VolFieldInternalType1, VolFieldInternalType2>
298 || addPrime2MeanFieldType<SurfaceFieldType1, SurfaceFieldType2>(item)
299 || addPrime2MeanFieldType<SurfFieldType1, SurfFieldType2>(item);
309 fieldAverageItem& item
312 const auto* fPtr = findObject<Type>(item.fieldName());
319 const Type& baseField = *fPtr;
321 const word windowFieldName = item.windowFieldName(this->
name());
342 DebugInfo <<
"Create and store: " << windowFieldName <<
endl;
344 item.addToWindow(windowFieldName,
obr().
time().deltaTValue());
354 typedef typename VolFieldType::Internal VolFieldInternalType;
360 if (item.storeWindowFields())
364 storeWindowFieldType<VolFieldType>(item)
365 || storeWindowFieldType<VolFieldInternalType>(item)
366 || storeWindowFieldType<SurfaceFieldType>(item)
367 || storeWindowFieldType<SurfFieldType>(item)
377 typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
378 typedef typename VolFieldType::Internal VolFieldInternalType;
379 typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
380 typedef DimensionedField<Type, polySurfaceGeoMesh> SurfFieldType;
382 const auto& obr = this->obr();
384 for (
const fieldAverageItem& item : faItems_)
388 item.calculateMeanField<VolFieldType>(obr)
389 || item.calculateMeanField<VolFieldInternalType>(obr)
390 || item.calculateMeanField<SurfaceFieldType>(obr)
391 || item.calculateMeanField<SurfFieldType>(
obr)
397template<
class Type1,
class Type2>
401 typedef typename VolFieldType1::Internal VolFieldInternalType1;
406 typedef typename VolFieldType2::Internal VolFieldInternalType2;
410 const auto& obr = this->obr();
412 for (
const fieldAverageItem& item : faItems_)
416 item.calculatePrime2MeanField<VolFieldType1, VolFieldType2>(obr)
417 || item.calculatePrime2MeanField
418 <VolFieldInternalType1, VolFieldInternalType2>(obr)
419 || item.calculatePrime2MeanField
420 <SurfaceFieldType1, SurfaceFieldType2>(obr)
421 || item.calculatePrime2MeanField<SurfFieldType1, SurfFieldType2>(
obr)
427template<
class Type1,
class Type2>
430 const fieldAverageItem& item
433 if (!foundObject<Type1>(item.fieldName()))
438 const Type1& meanField = lookupObject<Type1>(item.meanFieldName());
440 Type2& prime2MeanField = lookupObjectRef<Type2>(item.prime2MeanFieldName());
442 prime2MeanField +=
sqr(meanField);
448template<
class Type1,
class Type2>
452 typedef typename VolFieldType1::Internal VolFieldInternalType1;
457 typedef typename VolFieldType2::Internal VolFieldInternalType2;
463 if (item.prime2Mean())
467 addMeanSqrToPrime2MeanType<VolFieldType1, VolFieldType2>(item)
468 || addMeanSqrToPrime2MeanType
469 <VolFieldInternalType1, VolFieldInternalType2>(item)
470 || addMeanSqrToPrime2MeanType
471 <SurfaceFieldType1, SurfaceFieldType2>(item)
472 || addMeanSqrToPrime2MeanType
473 <SurfFieldType1, SurfFieldType2>(item)
483 const word& fieldName
486 const auto* fPtr = findObject<Type>(fieldName);
490 DebugInfo<<
"writing " << Type::typeName <<
": " << fieldName <<
endl;
491 return fPtr->
write();
502 typedef typename VolFieldType::Internal VolFieldInternalType;
506 for (
const fieldAverageItem& item : faItems_)
510 const word& fieldName = item.meanFieldName();
514 writeFieldType<VolFieldType>(fieldName)
515 || writeFieldType<VolFieldInternalType>(fieldName)
516 || writeFieldType<SurfaceFieldType>(fieldName)
517 || writeFieldType<SurfFieldType>(fieldName)
521 if (item.prime2Mean())
523 const word& fieldName = item.prime2MeanFieldName();
527 writeFieldType<VolFieldType>(fieldName)
528 || writeFieldType<VolFieldInternalType>(fieldName)
529 || writeFieldType<SurfaceFieldType>(fieldName)
530 || writeFieldType<SurfFieldType>(fieldName)
534 if (item.writeWindowFields())
536 FIFOStack<word> fieldNames = item.windowFieldNames();
539 const word& fieldName = fieldNameIter();
543 writeFieldType<VolFieldType>(fieldName)
544 || writeFieldType<VolFieldInternalType>(fieldName)
545 || writeFieldType<SurfaceFieldType>(fieldName)
546 || writeFieldType<SurfFieldType>(fieldName)
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
A FIFO stack based on a singly-linked list.
Generic GeometricField class.
@ REGISTER
Request registration (bool: true).
@ NO_READ
Nothing to be read.
@ READ_IF_PRESENT
Reading is optional [identical to LAZY_READ].
@ MUST_READ
Reading required.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
Helper class to describe what form of averaging to apply. A set will be applied to each base field in...
const FIFOStack< word > & windowFieldNames() const
Return the list of window field names (windowType = EXACT).
const word & fieldName() const
Return const access to the field name.
bool mean() const
Return const access to the mean flag.
void addToWindow(const word &fieldName, const scalar deltaT)
Add field to window.
scalar window() const
Return the window length (iterations or seconds).
word windowFieldName(const word &prefix) const
Helper function to construct a window field name.
bool prime2Mean() const
Return const access to the prime-squared mean flag.
const word & prime2MeanFieldName() const
Return const access to the prime-squared mean field name.
bool active() const
Return const access to the active flag.
const word & meanFieldName() const
Return const access to the mean field name.
bool writeFieldType(const word &fieldName) const
Write fields.
Switch restartOnOutput_
Restart the averaging process on output.
void writeFields() const
Write fields.
bool addMeanField(fieldAverageItem &item)
Add mean average field to database.
void calculatePrime2MeanFields() const
Calculate prime-squared average fields.
List< fieldAverageItem > faItems_
List of field average items, describing what averages to be calculated and output.
bool addPrime2MeanField(fieldAverageItem &item)
Add prime-squared average field to database.
bool addPrime2MeanFieldType(fieldAverageItem &item)
Add prime-squared average field to database.
bool restoreWindowFieldsType(const fieldAverageItem &item)
bool addMeanFieldType(fieldAverageItem &item)
Add mean average field to database.
bool addMeanSqrToPrime2MeanType(const fieldAverageItem &item) const
Add mean-squared field value to prime-squared mean field.
bool storeWindowFieldType(fieldAverageItem &item)
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.
const ObjectType & lookupObject(const word &fieldName) const
Lookup and return object (eg, a field) from the (sub) objectRegistry.
bool foundObject(const word &fieldName) const
Find object (eg, a field) in the (sub) objectRegistry.
virtual const objectRegistry & obr() const
The region or sub-region registry being used.
const ObjectType * findObject(const word &fieldName) const
Return const pointer to the object (eg, a field) in the (sub) objectRegistry.
ObjectType & lookupObjectRef(const word &fieldName) const
Lookup and return object (eg, a field) from the (sub) objectRegistry.
const Time & time() const
Return time database.
bool store()
Register object with its registry and transfer ownership to the registry.
A class for handling words, derived from Foam::string.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define DebugInfo
Report an information message using Foam::Info.
#define WarningInFunction
Report a warning using Foam::Warning.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Ostream & endl(Ostream &os)
Add newline and flush stream.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a).
Fields (face and point) for polySurface.
#define forAllConstIters(container, iter)
Iterate across all elements of the container object with const access.