Loading...
Searching...
No Matches
fieldAverage.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2017 OpenFOAM Foundation
9 Copyright (C) 2015-2020 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::functionObjects::fieldAverage
29
30Group
31 grpFieldFunctionObjects
32
33Description
34 Computes ensemble- and/or time-based field averages, with optional
35 windowing, for a user-specified selection of volumetric and/or surface
36 fields.
37
38 Fields are entered as a list of sub-dictionaries, which indicate the type of
39 averages to perform, and can be updated during the calculation. The current
40 options include:
41 - \c mean: arithmetic mean
42 \f[
43 \overline{x} = \frac{1}{N}\displaystyle\sum\limits_{i=0}^N x_i
44 \f]
45 - \c prime2Mean: prime-squared mean
46 \f[
47 \overline{x'}^2 = \frac{1}{N}\displaystyle\sum\limits_{i=0}^N
48 (x_i - \overline{x})^2
49 \f]
50 - \c base: average over 'time', or 'iteration' (\c N in the above)
51 - \c window: optional averaging window, specified in 'base' units
52
53 Average field names are constructed by concatenating the base field with
54 the averaging type, e.g. when averaging field 'U', the name of resultant
55 fields becomes:
56 - arithmetic mean field, \c UMean
57 - prime-squared field, \c UPrime2Mean
58
59 Information regarding the number of averaging steps, and total averaging
60 time are written on a per-field basis to the
61 \c "<functionObject name>Properties" dictionary,
62 located in \c <time>/uniform.
63
64 When restarting form a previous calculation, the averaging is continuous or
65 may be restarted using the \c restartOnRestart option.
66
67 The averaging process may be restarted after each calculation output time
68 using the \c restartOnOutput option or restarted periodically using the \c
69 periodicRestart option and setting \c restartPeriod to the required
70 averaging period.
71
72 With the \c subRegion option, also supports fields on function object
73 surface output (e.g., \c sampledSurfaces).
74
75 Operands:
76 \table
77 Operand | Type | Location
78 input | {vol,surface}<Type>Field(s) | <time>/inputFields
79 output file | - | -
80 output field | {vol,surface}<Type>Field(s) | <time>/outputFields
81 \endtable
82
83 where \c Type can be one of:
84 \c Scalar, \c Vector, \c SphericalTensor, \c SymmTensor, or \c Tensor.
85Usage
86 Minimal example by using \c system/controlDict.functions:
87 \verbatim
88 fieldAverageFO
89 {
90 // Mandatory entries
91 type fieldAverage;
92 libs (fieldFunctionObjects);
93 fields
94 (
95 <field1>
96 {
97 // Inherited entries
98 ...
99 }
100
101 ...
102
103 <fieldN>
104 {
105 ...
106 }
107 );
108
109 // Optional entries
110 restartOnRestart false;
111 restartOnOutput false;
112 periodicRestart false;
113 restartPeriod 0.002;
114
115 // Inherited entries
116 ...
117 }
118 \endverbatim
119
120 where the entries mean:
121 \table
122 Property | Description | Type | Reqd | Deflt
123 type | Type name: fieldAverage | word | yes | -
124 libs | Library name: fieldFunctionObjects | word | yes | -
125 fields | Names of the operand fields and averaging options <!--
126 --> | dict | yes | -
127 restartOnRestart| Restart the averaging on restart | bool | no | false
128 restartOnOutput | Restart the averaging on output | bool | no | false
129 periodicRestart | Periodically restart the averaging | bool | no | false
130 restartPeriod | Periodic restart period | scalar | conditional | -
131 restartTime | One-shot reset of the averaging | scalar | no | GREAT
132 subRegion | Name for alternative objectRegistry | word | no | ""
133 \endtable
134
135 The inherited entries are elaborated in:
136 - \link functionObject.H \endlink
137 - \link fieldAverageItem.H \endlink
138
139SourceFiles
140 fieldAverage.C
141 fieldAverageTemplates.C
142 fieldAverageItem.C
143
144\*---------------------------------------------------------------------------*/
145
146#ifndef Foam_functionObjects_fieldAverage_H
147#define Foam_functionObjects_fieldAverage_H
148
149#include "fvMeshFunctionObject.H"
150#include "FIFOStack.H"
151
152// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
153
154namespace Foam
155{
156namespace functionObjects
157{
158
159// Forward Declarations
160class fieldAverageItem;
161
162/*---------------------------------------------------------------------------*\
163 Class fieldAverage Declaration
164\*---------------------------------------------------------------------------*/
165
166class fieldAverage
167:
169{
170protected:
171
172 // Protected Data
173
174 //- Time at last call, prevents repeated averaging
175 label prevTimeIndex_;
176
177 //- Initialised flag
178 bool initialised_;
179
180 //- Restart the averaging process on restart
181 Switch restartOnRestart_;
182
183 //- Restart the averaging process on output
184 Switch restartOnOutput_;
185
186 //- Periodically restart the averaging process
187 Switch periodicRestart_;
188
189 //- Restart period
190 scalar restartPeriod_;
191
192 //- Specific restart time
193 scalar restartTime_;
194
195 //- List of field average items, describing what averages to be
196 //- calculated and output
197 List<fieldAverageItem> faItems_;
198
199 // Counters
200
201 //- Iteration steps counter
202 List<label> totalIter_;
203
204 //- Total time counter
205 List<scalar> totalTime_;
206
207 //- Index for periodic restart
208 label periodIndex_;
209
210
211 // Protected Member Functions
212
213 // Initialisation routines
214
215 //- Reset lists (clear existing values) and initialize averaging.
216 // Check requested field averages are valid, populate field lists
217 void initialize();
218
219 //- Restart averaging for restartOnOutput
220 void restart();
221
222 //- Add mean average field to database
223 template<class Type>
224 bool addMeanFieldType(fieldAverageItem& item);
225
226 //- Add mean average field to database
227 template<class Type>
228 bool addMeanField(fieldAverageItem& item);
229
230 //- Add prime-squared average field to database
231 template<class Type1, class Type2>
232 bool addPrime2MeanFieldType(fieldAverageItem& item);
233
234 //- Add prime-squared average field to database
235 template<class Type1, class Type2>
236 bool addPrime2MeanField(fieldAverageItem& item);
237
238
239 // Calculation functions
240
241 //- Main calculation routine
242 virtual void calcAverages();
243
244 //- Calculate mean average fields
245 template<class Type>
246 void calculateMeanFields() const;
247
248 //- Calculate prime-squared average fields
249 template<class Type1, class Type2>
251
252 //- Add mean-squared field value to prime-squared mean field
253 template<class Type1, class Type2>
254 bool addMeanSqrToPrime2MeanType(const fieldAverageItem& item) const;
256 //- Add mean-squared field value to prime-squared mean field
257 template<class Type1, class Type2>
258 void addMeanSqrToPrime2Mean() const;
259
260 template<class Type>
262
263 template<class Type>
264 void storeWindowFields();
266 template<class Type>
268
269 template<class Type>
271
272 // I-O
273
274 //- Write averages
275 virtual void writeAverages() const;
276
277 //- Write fields
278 template<class Type>
279 bool writeFieldType(const word& fieldName) const;
281 //- Write fields
282 template<class Type>
283 void writeFields() const;
284
285 //- Write averaging properties - steps and time
287
288 //- Read averaging properties - steps and time
290
291
292public:
294 //- Runtime type information
295 TypeName("fieldAverage");
296
297
298 // Constructors
299
300 //- Construct from name, Time and dictionary
302 (
303 const word& name,
304 const Time& runTime,
305 const dictionary&
306 );
307
308 //- No copy construct
309 fieldAverage(const fieldAverage&) = delete;
310
311 //- No copy assignment
312 void operator=(const fieldAverage&) = delete;
313
314
315 //- Destructor
316 virtual ~fieldAverage() = default;
317
318
319 // Member Functions
320
321 //- Read the function-object dictionary
322 virtual bool read(const dictionary& dict);
323
324 //- Execute the function-object operations
325 virtual bool execute();
326
327 //- Write the function-object results
328 virtual bool write();
329};
330
331
332// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
333
334} // End namespace functionObjects
335} // End namespace Foam
336
337// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
338
339#ifdef NoRepository
340 #include "fieldAverageTemplates.C"
341#endif
342
343// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
344
345#endif
346
347// ************************************************************************* //
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition Switch.H:81
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
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.
bool writeFieldType(const word &fieldName) const
Write fields.
TypeName("fieldAverage")
Runtime type information.
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.
virtual ~fieldAverage()=default
Destructor.
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< scalar > totalTime_
Total time counter.
List< fieldAverageItem > faItems_
List of field average items, describing what averages to be calculated and output.
List< label > totalIter_
Iteration steps counter.
virtual bool read(const dictionary &dict)
Read the function-object dictionary.
bool addPrime2MeanField(fieldAverageItem &item)
Add prime-squared average field to database.
bool addPrime2MeanFieldType(fieldAverageItem &item)
Add prime-squared average field to database.
void operator=(const fieldAverage &)=delete
No copy assignment.
bool restoreWindowFieldsType(const fieldAverageItem &item)
bool addMeanFieldType(fieldAverageItem &item)
Add mean average field to database.
fieldAverage(const fieldAverage &)=delete
No copy construct.
bool addMeanSqrToPrime2MeanType(const fieldAverageItem &item) const
Add mean-squared field value to prime-squared mean field.
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.
bool storeWindowFieldType(fieldAverageItem &item)
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.
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
fvMeshFunctionObject(const fvMeshFunctionObject &)=delete
No copy construct.
A class for handling words, derived from Foam::string.
Definition word.H:66
engineTime & runTime
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
Namespace for OpenFOAM.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
dictionary dict
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68