FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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::fieldAverage
26 
27 Description
28  Calculates the field averages given list of fieldAverageItems, e.g.
29 
30  @verbatim
31  fieldAverage1
32  {
33  // Type of functionObject
34  type fieldAverage;
35 
36  // Where to load it from (if not already in solver)
37  functionObjectLibs ("libfieldAverage.so");
38 
39  // Whether to perform a clean restart, or start from previous
40  // averaging info if available
41  cleanRestart true;
42 
43  // Whether to reset the averaged fields after they have been written.
44  // Used to average over only the preceding write interval for transient
45  // cases.
46  resetOnOutput true;
47 
48  // Fields to be averaged. runTime modifiable!
49  fields
50  (
51  U
52  {
53  mean on;
54  prime2Mean on;
55  base time;
56  }
57  p
58  {
59  mean on;
60  prime2Mean on;
61  base time;
62  }
63  );
64  @endverbatim
65 
66  Member function calcAverages() calculates the averages.
67 
68  Member function fieldAverage::write() calls calcAverages(). Average
69  field names are constructed by concatenating the base field with the
70  averaging type, e.g.
71  - base field, U
72  - arithmetic mean field, UMean
73  - prime-squared field, UPrime2Mean
74 
75  Information regarding the number of averaging steps, and total averaging
76  time are written on a (base) per-field basis to the
77  fieldAveragingProperties dictionary, located in <time>/uniform
78 
79 SourceFiles
80  fieldAverage.C
81  fieldAverageTemplates.C
82 
83 \*---------------------------------------------------------------------------*/
84 
85 #ifndef fieldAverage_H
86 #define fieldAverage_H
87 
89 #include <OpenFOAM/pointFieldFwd.H>
90 #include <OpenFOAM/Switch.H>
91 
92 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
93 
94 namespace Foam
95 {
96 
97 // Forward declaration of classes
98 class objectRegistry;
99 class dictionary;
100 class fieldAverageItem;
101 class OFstream;
102 template<class Type>
103 class List;
104 class mapPolyMesh;
105 
106 /*---------------------------------------------------------------------------*\
107  Class fieldAverage Declaration
108 \*---------------------------------------------------------------------------*/
109 
111 {
112 protected:
113 
114  // File and field name extensions
115 
116  //- Mean average
117  static const word EXT_MEAN;
118 
119  //- Prime-squared average
120  static const word EXT_PRIME2MEAN;
121 
122  // Private data
123 
124  //- Name of this set of field averages.
126 
127  //- Database this class is registered to
129 
130  //- On/off switch
131  bool active_;
132 
133  //- Time at last call, prevents repeated averaging
135 
136  //- Clean restart flag
138 
139  //- resetOnOutput flag
141 
142  //- List of field average items, describing what averages to be
143  // calculated and output
145 
146  // Lists of averages
147 
148  // Arithmetic mean fields
154 
155  // Prime-squared fields
156  // Only applicable to volScalarFields / volVectorFields
159 
160 
161  // Counters
162 
163  //- Iteration steps counter
165 
166  //- Total time counter
168 
169 
170  // Private Member Functions
171 
172  // Initialisation routines
173 
174  //- Checkout fields (causes deletion) from the database
175  // and reset lists
176  void resetFields(wordList&);
177 
178  //- Reset lists (clear existing values) and initialize averaging.
179  // Check requested field averages are valid, populate field lists
180  void initialize();
181 
182  //- Add mean average field to list
183  template<class Type>
184  void addMeanField(const label, wordList&) const;
185 
186  //- Add prime-squared average field to list
187  template<class Type1, class Type2>
188  void addPrime2MeanField
189  (
190  const label,
191  const wordList&,
192  wordList&
193  ) const;
194 
195 
196  // Calculation functions
197 
198  //- Main calculation routine
199  virtual void calcAverages();
200 
201  //- Calculate mean average fields
202  template<class Type>
203  void calculateMeanFields(const wordList&) const;
204 
205  //- Add mean-squared field value to prime-squared mean field
206  template<class Type1, class Type2>
208  (
209  const wordList&,
210  const wordList&
211  ) const;
212 
213  //- Calculate prime-squared average fields
214  template<class Type1, class Type2>
216  (
217  const wordList&,
218  const wordList&
219  ) const;
220 
221 
222  // IO
223 
224  //- Write averages
225  virtual void writeAverages() const;
226 
227  //- Write fields
228  template<class Type>
229  void writeFieldList(const wordList&) const;
230 
231  //- Write averaging properties - steps and time
232  void writeAveragingProperties() const;
233 
234  //- Read averaging properties - steps and time
236 
237 
238  // Functions to be over-ridden from IOoutputFilter class
239 
240  //- Update mesh
241  virtual void updateMesh(const mapPolyMesh&);
242 
243  //- Move points
244  virtual void movePoints(const Field<point>&);
245 
246 
247  //- Disallow default bitwise copy construct
248  fieldAverage(const fieldAverage&);
249 
250  //- Disallow default bitwise assignment
251  void operator=(const fieldAverage&);
252 
253 
254 public:
255 
256  //- Runtime type information
257  TypeName("fieldAverage");
258 
259 
260  // Constructors
261 
262  //- Construct for given objectRegistry and dictionary.
263  // Allow the possibility to load fields from files
265  (
266  const word& name,
267  const objectRegistry&,
268  const dictionary&,
269  const bool loadFromFiles = false
270  );
271 
272 
273  //- Destructor
274 
275  virtual ~fieldAverage();
276 
277 
278  // Member Functions
279 
280  //- Return name of the set of field averages
281  virtual const word& name() const
282  {
283  return name_;
284  }
285 
286  //- Read the field average data
287  virtual void read(const dictionary&);
288 
289  //- Execute the averaging
290  virtual void execute();
291 
292  //- Execute the averaging at the final time-loop, currently does nothing
293  virtual void end();
294 
295  //- Calculate the field average data and write
296  virtual void write();
297 };
298 
299 
300 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
301 
302 } // End namespace Foam
303 
304 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
305 
306 #ifdef NoRepository
307 # include "fieldAverageTemplates.C"
308 #endif
309 
310 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
311 
312 #endif
313 
314 // ************************ vim: set sw=4 sts=4 et: ************************ //