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-2013 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
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::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 fieldAveragingProperties dictionary, located in <time>/uniform
56 
57  When restarting form a previous calculation, the averaging is continuous.
58  However, the averaging process can be restarted using the \c resetOnRestart
59  option.
60 
61  To restart the averaging process after each calculation output time, use
62  the \c resetOnOutput option.
63 
64  Example of function object specification:
65  \verbatim
66  fieldAverage1
67  {
68  type fieldAverage;
69  functionObjectLibs ("libfieldFunctionObjects.so");
70  ...
71  resetOnRestart true;
72  resetOnOutput false;
73  fields
74  (
75  U
76  {
77  mean on;
78  prime2Mean on;
79  base time;
80  window 10.0;
81  windowName w1;
82  }
83  p
84  {
85  mean on;
86  prime2Mean on;
87  base time;
88  }
89  );
90  }
91  \endverbatim
92 
93  \heading Function object usage
94  \table
95  Property | Description | Required | Default value
96  type | type name: fieldAverage | yes |
97  resetOnRestart | flag to reset the averaging on restart | yes |
98  resetOnOutput| flag to reset the averaging on output | yes |
99  fields | list of fields and averaging options | yes |
100  log | Log to standard output | no | yes
101  \endtable
102 
103 
104 Note
105  To employ the \c prime2Mean option, the \c mean option must be selecetd.
106 
107 SeeAlso
108  Foam::functionObject
109  Foam::OutputFilterFunctionObject
110 
111 SourceFiles
112  fieldAverage.C
113  fieldAverageTemplates.C
114  fieldAverageItem.C
115 
116 \*---------------------------------------------------------------------------*/
117 
118 #ifndef fieldAverage_H
119 #define fieldAverage_H
120 
121 #include "functionObjectState.H"
122 #include "volFieldsFwd.H"
123 #include "Switch.H"
124 
125 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
126 
127 namespace Foam
128 {
129 
130 // Forward declaration of classes
131 class objectRegistry;
132 class dictionary;
133 class fieldAverageItem;
134 template<class Type>
135 class List;
136 class polyMesh;
137 class mapPolyMesh;
138 
139 /*---------------------------------------------------------------------------*\
140  Class fieldAverage Declaration
141 \*---------------------------------------------------------------------------*/
142 
143 class fieldAverage
144 :
145  public functionObjectState
146 {
147 protected:
148 
149  // Protected data
150 
151  //- Reference to the database
152  const objectRegistry& obr_;
153 
154  //- Time at last call, prevents repeated averaging
156 
157  //- Reset the averaging process on restart flag
158  Switch resetOnRestart_;
159 
160  //- Reset the averaging process on output flag
161  Switch resetOnOutput_;
162 
163  //- Switch to send output to Info as well as to file
164  Switch log_;
165 
166  //- Initialised flag
167  bool initialised_;
168 
169  //- List of field average items, describing what averages to be
170  // calculated and output
172 
173  // Counters
174 
175  //- Iteration steps counter
177 
178  //- Total time counter
180 
181 
182  // Private Member Functions
183 
184  // Initialisation routines
185 
186  //- Checkout fields (causes deletion) from the database
187  // and reset lists
188  void resetFields();
189 
190  //- Reset lists (clear existing values) and initialize averaging.
191  // Check requested field averages are valid, populate field lists
192  void initialize();
193 
194  //- Add mean average field to database
195  template<class Type>
196  void addMeanFieldType(const label fieldI);
197 
198  //- Add mean average field to database
199  template<class Type>
200  void addMeanField(const label fieldI);
201 
202  //- Add prime-squared average field to database
203  template<class Type1, class Type2>
204  void addPrime2MeanFieldType(const label fieldI);
205 
206  //- Add prime-squared average field to database
207  template<class Type1, class Type2>
208  void addPrime2MeanField(const label fieldI);
209 
210 
211  // Calculation functions
212 
213  //- Main calculation routine
214  virtual void calcAverages();
215 
216  //- Calculate mean average fields
217  template<class Type>
218  void calculateMeanFieldType(const label fieldI) const;
219 
220  //- Calculate mean average fields
221  template<class Type>
222  void calculateMeanFields() const;
223 
224  //- Calculate prime-squared average fields
225  template<class Type1, class Type2>
226  void calculatePrime2MeanFieldType(const label fieldI) const;
227 
228  //- Calculate prime-squared average fields
229  template<class Type1, class Type2>
230  void calculatePrime2MeanFields() const;
231 
232  //- Add mean-squared field value to prime-squared mean field
233  template<class Type1, class Type2>
234  void addMeanSqrToPrime2MeanType(const label fieldI) const;
235 
236  //- Add mean-squared field value to prime-squared mean field
237  template<class Type1, class Type2>
238  void addMeanSqrToPrime2Mean() const;
239 
240 
241  // I-O
242 
243  //- Write averages
244  virtual void writeAverages() const;
245 
246  //- Write fields
247  template<class Type>
248  void writeFieldType(const word& fieldName) const;
249 
250  //- Write fields
251  template<class Type>
252  void writeFields() const;
253 
254  //- Write averaging properties - steps and time
256 
257  //- Read averaging properties - steps and time
259 
260 
261  //- Disallow default bitwise copy construct
262  fieldAverage(const fieldAverage&);
263 
264  //- Disallow default bitwise assignment
265  void operator=(const fieldAverage&);
266 
267 
268 public:
269 
270  //- Runtime type information
271  TypeName("fieldAverage");
272 
273 
274  // Constructors
275 
276  //- Construct for given objectRegistry and dictionary.
277  // Allow the possibility to load fields from files
279  (
280  const word& name,
281  const objectRegistry&,
282  const dictionary&,
283  const bool loadFromFiles = false
284  );
285 
286 
287  //- Destructor
288  virtual ~fieldAverage();
289 
290 
291  // Member Functions
292 
293  //- Return name of the set of field averages
294  virtual const word& name() const
295  {
296  return name_;
297  }
298 
299  //- Read the field average data
300  virtual void read(const dictionary&);
301 
302  //- Execute the averaging
303  virtual void execute();
304 
305  //- Execute the averaging at the final time-loop, currently does nothing
306  virtual void end();
307 
308  //- Called when time was set at the end of the Time::operator++
309  virtual void timeSet();
310 
311  //- Calculate the field average data and write
312  virtual void write();
313 
314  //- Update mesh
315  virtual void updateMesh(const mapPolyMesh&);
316 
317  //- Move points
318  virtual void movePoints(const polyMesh&);
319 };
320 
321 
322 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
323 
324 } // End namespace Foam
325 
326 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
327 
328 #ifdef NoRepository
329 # include "fieldAverageTemplates.C"
330 #endif
331 
332 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
333 
334 #endif
335 
336 // ************************************************************************* //
Foam::fieldAverage::writeAverages
virtual void writeAverages() const
Write averages.
Definition: fieldAverage.C:151
volFieldsFwd.H
Foam::fieldAverage::movePoints
virtual void movePoints(const polyMesh &)
Move points.
Definition: fieldAverage.C:331
Foam::Switch
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:60
Foam::fieldAverage::faItems_
List< fieldAverageItem > faItems_
List of field average items, describing what averages to be.
Definition: fieldAverage.H:200
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::functionObjectState
Base class for function objects, adding functionality to read/write state information (data required ...
Definition: functionObjectState.H:54
Foam::fieldAverage::calculatePrime2MeanFields
void calculatePrime2MeanFields() const
Calculate prime-squared average fields.
Definition: fieldAverageTemplates.C:294
Foam::fieldAverage::totalIter_
List< label > totalIter_
Iteration steps counter.
Definition: fieldAverage.H:205
Foam::fieldAverage::writeAveragingProperties
void writeAveragingProperties()
Write averaging properties - steps and time.
Definition: fieldAverage.C:163
Foam::fieldAverage::name
virtual const word & name() const
Return name of the set of field averages.
Definition: fieldAverage.H:323
functionObjectState.H
Foam::fieldAverage::totalTime_
List< scalar > totalTime_
Total time counter.
Definition: fieldAverage.H:208
Foam::fieldAverage::timeSet
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Definition: fieldAverage.C:294
Foam::fieldAverage::readAveragingProperties
void readAveragingProperties()
Read averaging properties - steps and time.
Definition: fieldAverage.C:177
Foam::fieldAverage::updateMesh
virtual void updateMesh(const mapPolyMesh &)
Update mesh.
Definition: fieldAverage.C:325
Foam::fieldAverage::log_
Switch log_
Switch to send output to Info as well as to file.
Definition: fieldAverage.H:193
Foam::fieldAverage::writeFieldType
void writeFieldType(const word &fieldName) const
Write fields.
Definition: fieldAverageTemplates.C:354
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::fieldAverage::addPrime2MeanField
void addPrime2MeanField(const label fieldI)
Add prime-squared average field to database.
Definition: fieldAverageTemplates.C:155
Foam::fieldAverage::fieldAverage
fieldAverage(const fieldAverage &)
Disallow default bitwise copy construct.
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::fieldAverage
This function object calculates average quantities for a user-specified selection of volumetric and s...
Definition: fieldAverage.H:172
Foam::label
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
Foam::fieldAverage::end
virtual void end()
Execute the averaging at the final time-loop, currently does nothing.
Definition: fieldAverage.C:290
Foam::fieldAverage::execute
virtual void execute()
Execute the averaging.
Definition: fieldAverage.C:280
Foam::fieldAverage::writeFields
void writeFields() const
Write fields.
Definition: fieldAverageTemplates.C:365
Foam::fieldAverage::addMeanField
void addMeanField(const label fieldI)
Add mean average field to database.
Definition: fieldAverageTemplates.C:83
Switch.H
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::fieldAverage::calcAverages
virtual void calcAverages()
Main calculation routine.
Definition: fieldAverage.C:108
Foam::fieldAverage::addMeanSqrToPrime2MeanType
void addMeanSqrToPrime2MeanType(const label fieldI) const
Add mean-squared field value to prime-squared mean field.
Definition: fieldAverageTemplates.C:314
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::fieldAverage::obr_
const objectRegistry & obr_
Reference to the database.
Definition: fieldAverage.H:181
Foam::fieldAverage::addMeanSqrToPrime2Mean
void addMeanSqrToPrime2Mean() const
Add mean-squared field value to prime-squared mean field.
Definition: fieldAverageTemplates.C:334
Foam::fieldAverage::addMeanFieldType
void addMeanFieldType(const label fieldI)
Add mean average field to database.
Definition: fieldAverageTemplates.C:34
Foam::fieldAverage::read
virtual void read(const dictionary &)
Read the field average data.
Definition: fieldAverage.C:259
Foam::functionObjectState::name_
const word name_
Name of model.
Definition: functionObjectState.H:72
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::fieldAverage::addPrime2MeanFieldType
void addPrime2MeanFieldType(const label fieldI)
Add prime-squared average field to database.
Definition: fieldAverageTemplates.C:105
Foam::fieldAverage::TypeName
TypeName("fieldAverage")
Runtime type information.
Foam::fieldAverage::calculateMeanFields
void calculateMeanFields() const
Calculate mean average fields.
Definition: fieldAverageTemplates.C:230
fieldAverageTemplates.C
Foam::fieldAverage::~fieldAverage
virtual ~fieldAverage()
Destructor.
Definition: fieldAverage.C:253
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
Foam::fieldAverage::calculatePrime2MeanFieldType
void calculatePrime2MeanFieldType(const label fieldI) const
Calculate prime-squared average fields.
Definition: fieldAverageTemplates.C:247
List
Definition: Test.C:19
Foam::fieldAverage::initialised_
bool initialised_
Initialised flag.
Definition: fieldAverage.H:196
Foam::fieldAverage::prevTimeIndex_
label prevTimeIndex_
Time at last call, prevents repeated averaging.
Definition: fieldAverage.H:184
Foam::fieldAverage::write
virtual void write()
Calculate the field average data and write.
Definition: fieldAverage.C:298
Foam::fieldAverage::calculateMeanFieldType
void calculateMeanFieldType(const label fieldI) const
Calculate mean average fields.
Definition: fieldAverageTemplates.C:188
Foam::fieldAverage::resetOnOutput_
Switch resetOnOutput_
Reset the averaging process on output flag.
Definition: fieldAverage.H:190
Foam::fieldAverage::resetOnRestart_
Switch resetOnRestart_
Reset the averaging process on restart flag.
Definition: fieldAverage.H:187
Foam::fieldAverage::initialize
void initialize()
Reset lists (clear existing values) and initialize averaging.
Definition: fieldAverage.C:65
Foam::fieldAverage::resetFields
void resetFields()
Checkout fields (causes deletion) from the database.
Definition: fieldAverage.C:42
Foam::fieldAverage::operator=
void operator=(const fieldAverage &)
Disallow default bitwise assignment.