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 | Copyright (C) 2011-2017 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::functionObjects::fieldAverage
26 
27 Group
28  grpFieldFunctionObjects
29 
30 Description
31  Calculates average quantities for a user-specified selection of volumetric
32  and surface fields.
33 
34  Fields are entered as a list of sub-dictionaries, which indicate the type of
35  averages to perform, and can be updated during the calculation. The current
36  options include:
37  - \c mean: arithmetic mean
38  - \c prime2Mean: prime-squared mean
39  - \c base: average over 'time', or 'iteration'
40  - \c window: optional averaging window, specified in 'base' units
41 
42  Average field names are constructed by concatenating the base field with
43  the averaging type, e.g. when averaging field 'U', the resultant fields
44  are:
45  - arithmetic mean field, \c UMean
46  - prime-squared field, \c UPrime2Mean
47 
48  Information regarding the number of averaging steps, and total averaging
49  time are written on a per-field basis to the \c "<functionObject
50  name>Properties" dictionary, located in <time>/uniform
51 
52  When restarting form a previous calculation, the averaging is continuous or
53  may be restarted using the \c restartOnRestart option.
54 
55  The averaging process may be restarted after each calculation output time
56  using the \c restartOnOutput option or restarted periodically using the \c
57  periodicRestart option and setting \c restartPeriod to the required
58  averaging period.
59 
60  Example of function object specification:
61  \verbatim
62  fieldAverage1
63  {
64  type fieldAverage;
65  libs ("libfieldFunctionObjects.so");
66 
67  writeControl writeTime;
68 
69  restartOnRestart false;
70  restartOnOutput false;
71  periodicRestart false;
72  restartPeriod 0.002;
73 
74  fields
75  (
76  U
77  {
78  mean on;
79  prime2Mean on;
80  base time;
81  window 10.0;
82  windowName w1;
83  }
84  p
85  {
86  mean on;
87  prime2Mean on;
88  base time;
89  }
90  );
91  }
92  \endverbatim
93 
94 Usage
95  \table
96  Property | Description | Required | Default
97  type | type name: fieldAverage | yes |
98  restartOnRestart | Restart the averaging on restart | no | no
99  restartOnOutput | Restart the averaging on output | no | no
100  periodicRestart | Periodically restart the averaging | no | no
101  restartPeriod | Periodic restart period | conditional |
102  fields | list of fields and averaging options | yes |
103  \endtable
104 
105 
106 Note
107  To employ the \c prime2Mean option, the \c mean option must be selecetd.
108 
109 See also
110  Foam::functionObjects::fvMeshFunctionObject
111  Foam::functionObject
112 
113 SourceFiles
114  fieldAverage.C
115  fieldAverageTemplates.C
116  fieldAverageItem.C
117 
118 \*---------------------------------------------------------------------------*/
119 
120 #ifndef functionObjects_fieldAverage_H
121 #define functionObjects_fieldAverage_H
122 
123 #include "fvMeshFunctionObject.H"
124 
125 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
126 
127 namespace Foam
128 {
129 namespace functionObjects
130 {
131 
132 // Forward declaration of classes
133 class fieldAverageItem;
134 
135 /*---------------------------------------------------------------------------*\
136  Class fieldAverage Declaration
137 \*---------------------------------------------------------------------------*/
138 
139 class fieldAverage
140 :
141  public fvMeshFunctionObject
142 {
143 protected:
144 
145  // Protected data
146 
147  //- Time at last call, prevents repeated averaging
149 
150  //- Restart the averaging process on restart
151  Switch restartOnRestart_;
152 
153  //- Restart the averaging process on output
154  Switch restartOnOutput_;
155 
156  //- Periodically restart the averaging process
157  Switch periodicRestart_;
158 
159  //- Restart period
160  scalar restartPeriod_;
161 
162  //- Initialised flag
163  bool initialised_;
164 
165  //- List of field average items, describing what averages to be
166  // calculated and output
167  List<fieldAverageItem> faItems_;
168 
169  // Counters
170 
171  //- Iteration steps counter
172  List<label> totalIter_;
174  //- Total time counter
176 
177  //- Index for periodic restart
179 
180 
181  // Protected Member Functions
183  // Initialisation routines
184 
185  //- Checkout fields (causes deletion) from the database
186  // and reset lists
187  void resetFields();
189  //- Reset lists (clear existing values) and initialize averaging.
190  // Check requested field averages are valid, populate field lists
191  void initialize();
192 
193  //- Restart averaging for restartOnOutput
194  void restart();
195 
196  //- Add mean average field to database
197  template<class Type>
198  void addMeanFieldType(const label fieldi);
199 
200  //- Add mean average field to database
201  template<class Type>
202  void addMeanField(const label fieldi);
203 
204  //- Add prime-squared average field to database
205  template<class Type1, class Type2>
206  void addPrime2MeanFieldType(const label fieldi);
207 
208  //- Add prime-squared average field to database
209  template<class Type1, class Type2>
210  void addPrime2MeanField(const label fieldi);
211 
213  // Calculation functions
214 
215  //- Main calculation routine
216  virtual void calcAverages();
217 
218  //- Calculate mean average fields
219  template<class Type>
220  void calculateMeanFieldType(const label fieldi) const;
221 
222  //- Calculate mean average fields
223  template<class Type>
224  void calculateMeanFields() const;
225 
226  //- Calculate prime-squared average fields
227  template<class Type1, class Type2>
228  void calculatePrime2MeanFieldType(const label fieldi) const;
229 
230  //- Calculate prime-squared average fields
231  template<class Type1, class Type2>
232  void calculatePrime2MeanFields() const;
233 
234  //- Add mean-squared field value to prime-squared mean field
235  template<class Type1, class Type2>
236  void addMeanSqrToPrime2MeanType(const label fieldi) const;
237 
238  //- Add mean-squared field value to prime-squared mean field
239  template<class Type1, class Type2>
240  void addMeanSqrToPrime2Mean() const;
241 
242 
243  // I-O
244 
245  //- Write averages
246  virtual void writeAverages() const;
247 
248  //- Write fields
249  template<class Type>
250  void writeFieldType(const word& fieldName) const;
251 
252  //- Write fields
253  template<class Type>
254  void writeFields() const;
255 
256  //- Write averaging properties - steps and time
257  void writeAveragingProperties() const;
258 
259  //- Read averaging properties - steps and time
261 
262 
263  //- Disallow default bitwise copy construct
264  fieldAverage(const fieldAverage&);
265 
266  //- Disallow default bitwise assignment
267  void operator=(const fieldAverage&);
268 
269 
270 public:
271 
272  //- Runtime type information
273  TypeName("fieldAverage");
274 
275 
276  // Constructors
277 
278  //- Construct from Time and dictionary
280  (
281  const word& name,
282  const Time& runTime,
283  const dictionary&
284  );
285 
286 
287  //- Destructor
288  virtual ~fieldAverage();
289 
290 
291  // Member Functions
292 
293  //- Read the field average data
294  virtual bool read(const dictionary&);
295 
296  //- Calculate the field averages
297  virtual bool execute();
298 
299  //- Write the field averages
300  virtual bool write();
301 };
302 
303 
304 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
305 
306 } // End namespace functionObjects
307 } // End namespace Foam
308 
309 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
310 
311 #ifdef NoRepository
312  #include "fieldAverageTemplates.C"
313 #endif
314 
315 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
316 
317 #endif
318 
319 // ************************************************************************* //
void writeAveragingProperties() const
Write averaging properties - steps and time.
Definition: fieldAverage.C:193
void addPrime2MeanFieldType(const label fieldi)
Add prime-squared average field to database.
void addMeanField(const label fieldi)
Add mean average field to database.
void addMeanSqrToPrime2MeanType(const label fieldi) const
Add mean-squared field value to prime-squared mean field.
virtual bool read(const dictionary &)
Read the field average data.
Definition: fieldAverage.C:313
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
fieldAverage(const fieldAverage &)
Disallow default bitwise copy construct.
const word & name() const
Return the name of this functionObject.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
virtual bool write()
Write the field averages.
Definition: fieldAverage.C:347
void operator=(const fieldAverage &)
Disallow default bitwise assignment.
List< scalar > totalTime_
Total time counter.
Definition: fieldAverage.H:209
Switch periodicRestart_
Periodically restart the averaging process.
Definition: fieldAverage.H:191
scalar restartPeriod_
Restart period.
Definition: fieldAverage.H:194
void calculatePrime2MeanFieldType(const label fieldi) const
Calculate prime-squared average fields.
void addMeanFieldType(const label fieldi)
Add mean average field to database.
virtual bool execute()
Calculate the field averages.
Definition: fieldAverage.C:339
void calculateMeanFieldType(const label fieldi) const
Calculate mean average fields.
void calculatePrime2MeanFields() const
Calculate prime-squared average fields.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
label prevTimeIndex_
Time at last call, prevents repeated averaging.
Definition: fieldAverage.H:182
void writeFields() const
Write fields.
Switch restartOnOutput_
Restart the averaging process on output.
Definition: fieldAverage.H:188
List< label > totalIter_
Iteration steps counter.
Definition: fieldAverage.H:206
void writeFieldType(const word &fieldName) const
Write fields.
void readAveragingProperties()
Read averaging properties - steps and time.
Definition: fieldAverage.C:223
A class for handling words, derived from string.
Definition: word.H:59
Calculates average quantities for a user-specified selection of volumetric and surface fields...
Definition: fieldAverage.H:173
List< fieldAverageItem > faItems_
List of field average items, describing what averages to be.
Definition: fieldAverage.H:201
virtual void calcAverages()
Main calculation routine.
Definition: fieldAverage.C:129
void calculateMeanFields() const
Calculate mean average fields.
void initialize()
Reset lists (clear existing values) and initialize averaging.
Definition: fieldAverage.C:68
Switch restartOnRestart_
Restart the averaging process on restart.
Definition: fieldAverage.H:185
void addPrime2MeanField(const label fieldi)
Add prime-squared average field to database.
void resetFields()
Checkout fields (causes deletion) from the database.
Definition: fieldAverage.C:45
label periodIndex_
Index for periodic restart.
Definition: fieldAverage.H:212
void restart()
Restart averaging for restartOnOutput.
Definition: fieldAverage.C:117
TypeName("fieldAverage")
Runtime type information.
void addMeanSqrToPrime2Mean() const
Add mean-squared field value to prime-squared mean field.
virtual ~fieldAverage()
Destructor.
Definition: fieldAverage.C:307
bool initialised_
Initialised flag.
Definition: fieldAverage.H:197
virtual void writeAverages() const
Write averages.
Definition: fieldAverage.C:179
Namespace for OpenFOAM.