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