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) <!--
79 --> |$FOAM_CASE/<time>/<inpField>s
80 output file | - | -
81 output field | {vol,surface}<Type>Field(s) <!--
82 --> | $FOAM_CASE/<time>/<outField>s
83 \endtable
84
85 where \c <Type>=Scalar/Vector/SphericalTensor/SymmTensor/Tensor.
86
87Usage
88 Minimal example by using \c system/controlDict.functions:
89 \verbatim
90 fieldAverage1
91 {
92 // Mandatory entries (unmodifiable)
93 type fieldAverage;
94 libs (fieldFunctionObjects);
95
96 // Mandatory entries (runtime modifiable)
97 fields
98 (
99 <field1>
100 {
101 // Optional (inherited) entries
102 ...
103 }
104
105 ...
106
107 <fieldN>
108 {
109 ...
110 }
111 );
112
113 // Optional entries (runtime modifiable)
114 restartOnRestart false;
115 restartOnOutput false;
116 periodicRestart false;
117 restartPeriod 0.002;
118
119 // Optional (inherited) entries
120 ...
121 }
122 \endverbatim
123
124 where the entries mean:
125 \table
126 Property | Description | Type | Req'd | Dflt
127 type | Type name: fieldAverage | word | yes | -
128 libs | Library name: fieldFunctionObjects | word | yes | -
129 fields | Names of the operand fields and averaging options <!--
130 --> | dict | yes | -
131 restartOnRestart| Restart the averaging on restart | bool | no | false
132 restartOnOutput | Restart the averaging on output | bool | no | false
133 periodicRestart | Periodically restart the averaging | bool | no | false
134 restartPeriod | Periodic restart period | scalar | conditional | -
135 restartTime | One-shot reset of the averaging | scalar | no | GREAT
136 subRegion | Name for alternative objectRegistry | word | no | ""
137 \endtable
138
139 The inherited entries are elaborated in:
140 - \link functionObject.H \endlink
141 - \link fieldAverageItem.H \endlink
142
143 Usage by the \c postProcess utility is not available.
144
145See also
146 - Foam::functionObject
147 - Foam::functionObjects::fieldAverageItem
148 - Foam::functionObjects::fvMeshFunctionObject
149 - ExtendedCodeGuide::functionObjects::field::fieldAverage
150
151SourceFiles
152 fieldAverage.C
153 fieldAverageTemplates.C
154 fieldAverageItem.C
155
156\*---------------------------------------------------------------------------*/
157
158#ifndef functionObjects_fieldAverage_H
159#define functionObjects_fieldAverage_H
160
161#include "fvMeshFunctionObject.H"
162#include "FIFOStack.H"
163
164// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
165
166namespace Foam
167{
168namespace functionObjects
169{
170
171// Forward declaration of classes
172class fieldAverageItem;
173
174/*---------------------------------------------------------------------------*\
175 Class fieldAverage Declaration
176\*---------------------------------------------------------------------------*/
177
178class fieldAverage
179:
180 public fvMeshFunctionObject
181{
182protected:
183
184 // Protected Data
185
186 //- Time at last call, prevents repeated averaging
187 label prevTimeIndex_;
188
189 //- Initialised flag
190 bool initialised_;
191
192 //- Restart the averaging process on restart
193 Switch restartOnRestart_;
194
195 //- Restart the averaging process on output
196 Switch restartOnOutput_;
197
198 //- Periodically restart the averaging process
199 Switch periodicRestart_;
200
201 //- Restart period
202 scalar restartPeriod_;
203
204 //- Specific restart time
205 scalar restartTime_;
206
207 //- List of field average items, describing what averages to be
208 // calculated and output
209 List<fieldAverageItem> faItems_;
210
211 // Counters
212
213 //- Iteration steps counter
214 List<label> totalIter_;
215
216 //- Total time counter
217 List<scalar> totalTime_;
218
219 //- Index for periodic restart
220 label periodIndex_;
221
222
223 // Protected Member Functions
224
225 // Initialisation routines
226
227 //- Reset lists (clear existing values) and initialize averaging.
228 // Check requested field averages are valid, populate field lists
229 void initialize();
230
231 //- Restart averaging for restartOnOutput
232 void restart();
233
234 //- Add mean average field to database
235 template<class Type>
236 void addMeanFieldType(fieldAverageItem& item);
237
238 //- Add mean average field to database
239 template<class Type>
240 void addMeanField(fieldAverageItem& item);
241
242 //- Add prime-squared average field to database
243 template<class Type1, class Type2>
244 void addPrime2MeanFieldType(fieldAverageItem& item);
245
246 //- Add prime-squared average field to database
247 template<class Type1, class Type2>
248 void addPrime2MeanField(fieldAverageItem& item);
249
250
251 // Calculation functions
252
253 //- Main calculation routine
254 virtual void calcAverages();
255
256 //- Calculate mean average fields
257 template<class Type>
258 void calculateMeanFields() const;
260 //- Calculate prime-squared average fields
261 template<class Type1, class Type2>
262 void calculatePrime2MeanFields() const;
263
264 //- Add mean-squared field value to prime-squared mean field
265 template<class Type1, class Type2>
266 void addMeanSqrToPrime2MeanType(const fieldAverageItem& item) const;
267
268 //- Add mean-squared field value to prime-squared mean field
269 template<class Type1, class Type2>
270 void addMeanSqrToPrime2Mean() const;
272 template<class Type>
275 template<class Type>
276 void storeWindowFields();
278 template<class Type>
281 template<class Type>
282 void restoreWindowFields(const fieldAverageItem& item);
284 // I-O
285
286 //- Write averages
287 virtual void writeAverages() const;
288
289 //- Write fields
290 template<class Type>
291 void writeFieldType(const word& fieldName) const;
292
293 //- Write fields
294 template<class Type>
295 void writeFields() const;
296
297 //- Write averaging properties - steps and time
299
300 //- Read averaging properties - steps and time
302
303
304public:
305
306 //- Runtime type information
307 TypeName("fieldAverage");
308
309
310 // Constructors
311
312 //- Construct from Time and dictionary
314 (
315 const word& name,
316 const Time& runTime,
317 const dictionary&
318 );
319
320 //- No copy construct
321 fieldAverage(const fieldAverage&) = delete;
322
323 //- No copy assignment
324 void operator=(const fieldAverage&) = delete;
325
326
327 //- Destructor
328 virtual ~fieldAverage() = default;
329
330
331 // Member Functions
332
333 //- Read the field average data
334 virtual bool read(const dictionary&);
335
336 //- Calculate the field averages
337 virtual bool execute();
338
339 //- Write the field averages
340 virtual bool write();
341};
342
343
344// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
345
346} // End namespace functionObjects
347} // End namespace Foam
348
349// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
350
351#ifdef NoRepository
352 #include "fieldAverageTemplates.C"
353#endif
354
355// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
356
357#endif
358
359// ************************************************************************* //
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:78
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
const word & name() const noexcept
Return the name of this functionObject.
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...
Definition: fieldAverage.H:262
Switch periodicRestart_
Periodically restart the averaging process.
Definition: fieldAverage.H:280
TypeName("fieldAverage")
Runtime type information.
label prevTimeIndex_
Time at last call, prevents repeated averaging.
Definition: fieldAverage.H:268
void writeAveragingProperties()
Write averaging properties - steps and time.
Definition: fieldAverage.C:206
void restart()
Restart averaging for restartOnOutput.
Definition: fieldAverage.C:104
void initialize()
Reset lists (clear existing values) and initialize averaging.
Definition: fieldAverage.C:48
Switch restartOnRestart_
Restart the averaging process on restart.
Definition: fieldAverage.H:274
virtual ~fieldAverage()=default
Destructor.
Switch restartOnOutput_
Restart the averaging process on output.
Definition: fieldAverage.H:277
label periodIndex_
Index for periodic restart.
Definition: fieldAverage.H:301
virtual void calcAverages()
Main calculation routine.
Definition: fieldAverage.C:119
void addMeanSqrToPrime2MeanType(const fieldAverageItem &item) const
Add mean-squared field value to prime-squared mean field.
void addMeanFieldType(fieldAverageItem &item)
Add mean average field to database.
scalar restartPeriod_
Restart period.
Definition: fieldAverage.H:283
void addMeanField(fieldAverageItem &item)
Add mean average field to database.
scalar restartTime_
Specific restart time.
Definition: fieldAverage.H:286
bool initialised_
Initialised flag.
Definition: fieldAverage.H:271
void calculatePrime2MeanFields() const
Calculate prime-squared average fields.
List< scalar > totalTime_
Total time counter.
Definition: fieldAverage.H:298
List< fieldAverageItem > faItems_
List of field average items, describing what averages to be.
Definition: fieldAverage.H:290
List< label > totalIter_
Iteration steps counter.
Definition: fieldAverage.H:295
void operator=(const fieldAverage &)=delete
No copy assignment.
fieldAverage(const fieldAverage &)=delete
No copy construct.
void addPrime2MeanFieldType(fieldAverageItem &item)
Add prime-squared average field to database.
void storeWindowFieldType(fieldAverageItem &item)
virtual void writeAverages() const
Write averages.
Definition: fieldAverage.C:192
void readAveragingProperties()
Read averaging properties - steps and time.
Definition: fieldAverage.C:217
void writeFieldType(const word &fieldName) const
Write fields.
virtual bool execute()
Calculate the field averages.
Definition: fieldAverage.C:374
virtual bool write()
Write the field averages.
Definition: fieldAverage.C:382
void calculateMeanFields() const
Calculate mean average fields.
void restoreWindowFields(const fieldAverageItem &item)
void addPrime2MeanField(fieldAverageItem &item)
Add prime-squared average field to database.
virtual bool read(const dictionary &)
Read the field average data.
Definition: fieldAverage.C:294
void addMeanSqrToPrime2Mean() const
Add mean-squared field value to prime-squared mean field.
void restoreWindowFieldsType(const fieldAverageItem &item)
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
A class for handling words, derived from Foam::string.
Definition: word.H:68
engineTime & runTime
Namespace for OpenFOAM.
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73