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