option to restart averaging on output
[OpenFOAM-1.5.x.git] / src / postProcessing / fieldAverage / fieldAverage / fieldAverage.H
bloba83381cfbcc455e8faf8ff7d588a4a937c3c7749
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::fieldAverage
28 Description
29     Calculates the field averages given list of fieldAverageItems, e.g.
31     @verbatim
32     fieldAverage1
33     {
34         // Type of functionObject
35         type fieldAverage;
37         // Where to load it from (if not already in solver)
38         functionObjectLibs ("libfieldAverage.so");
40         // Fields to be probed. runTime modifiable!
41         fields
42         (
43             U
44             {
45                 mean            on;
46                 prime2Mean      on;
47                 base            time;
48             }
49             p
50             {
51                 mean            on;
52                 prime2Mean      on;
53                 base            time;
54             }
55         );
56     @endverbatim
58     Member function calcAverages() calculates the averages.
60     Member function fieldAverage::write() calls calcAverages(). Average
61     field names are constructed by concatenating the base field with the
62     averaging type, e.g.
63     - base field, U
64     - arithmetic mean field, UMean
65     - prime-squared field, UPrime2Mean
67     Information regarding the number of averaging steps, and total averaging
68     time are written on a (base) per-field basis to the
69     fieldAveragingProperties dictionary, located in \<time\>/uniform
71 SourceFiles
72     fieldAverage.C
73     fieldAverageTemplates.C
75 \*---------------------------------------------------------------------------*/
77 #ifndef fieldAverage_H
78 #define fieldAverage_H
80 #include "volFieldsFwd.H"
81 #include "pointFieldFwd.H"
82 #include "Switch.H"
84 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
86 namespace Foam
89 // Forward declaration of classes
90 class objectRegistry;
91 class dictionary;
92 class fieldAverageItem;
93 class OFstream;
94 template<class Type>
95 class List;
96 class mapPolyMesh;
98 /*---------------------------------------------------------------------------*\
99                          Class fieldAverage Declaration
100 \*---------------------------------------------------------------------------*/
102 class fieldAverage
104 protected:
106     // Private data
108         //- Name of this set of field averages.
109         word name_;
111         //- Database this class is registered to
112         const objectRegistry& obr_;
114         //- On/off switch
115         bool active_;
117         //- Time at last call, prevents repeated averaging
118         label prevTimeIndex_;
120         //- resetOnOutput flag
121         Switch resetOnOutput_;
123         //- List of field average items, describing what averages to be
124         //  calculated and output
125         List<fieldAverageItem> faItems_;
127         // File and field name extensions
129             //- Mean average
130             static const word EXT_MEAN;
132             //- Prime-squared average
133             static const word EXT_PRIME2MEAN;
136         // Lists of averages
138             // Arithmetic mean fields
139             wordList meanScalarFields_;
140             wordList meanVectorFields_;
141             wordList meanSphericalTensorFields_;
142             wordList meanSymmTensorFields_;
143             wordList meanTensorFields_;
145             // Prime-squared fields - applicable to volVectorFields only
146             wordList prime2MeanScalarFields_;
147             wordList prime2MeanSymmTensorFields_;
150         // Counters
152             //- Iteration steps counter
153             List<label> totalIter_;
155             //- Total time counter
156             List<scalar> totalTime_;
159     // Private Member Functions
161         // Initialisation routines
163             //- Checkout fields (causes deletion) from the database
164             void checkoutFields(const wordList&) const;
166             //- Reset size of lists (clear existing values)
167             void resetLists(const label nItems);
169             //- Intitialise averaging. Check requested field averages are
170             //  valid, and populate field lists
171             void initialise();
173             //- Add mean average field to PtrList
174             template<class Type>
175             void addMeanField(const label, wordList&) const;
177             //- Add prime-squared average field to PtrList
178             template<class Type1, class Type2>
179             void addPrime2MeanField
180             (
181                 const label,
182                 const wordList&,
183                 wordList&
184             ) const;
187         // Calculation functions
189             //- Main calculation routine
190             virtual void calcAverages();
192             //- Calculate mean average fields
193             template<class Type>
194             void calculateMeanFields(const wordList&) const;
196             //- Add mean-squared field value to prime-squared mean field
197             template<class Type1, class Type2>
198             void addMeanSqrToPrime2Mean
199             (
200                 const wordList&,
201                 const wordList&
202             ) const;
204             //- Calculate prime-squared average fields
205             template<class Type1, class Type2>
206             void calculatePrime2MeanFields
207             (
208                 const wordList&,
209                 const wordList&
210             ) const;
213         // I-O
215             //- Write averages
216             virtual void writeAverages() const;
218             //- Write fields
219             template<class Type>
220             void writeFieldList(const wordList&) const;
222             //- Write averaging properties - steps and time
223             void writeAveragingProperties() const;
225             //- Read averaging properties - steps and time
226             void readAveragingProperties();
229         // Functions to be over-ridden from IOoutputFilter class
231             //- Update mesh
232             virtual void updateMesh(const mapPolyMesh&);
234             //- Move points
235             virtual void movePoints(const Field<point>&);
238         //- Disallow default bitwise copy construct
239         fieldAverage(const fieldAverage&);
241         //- Disallow default bitwise assignment
242         void operator=(const fieldAverage&);
245 public:
247     //- Runtime type information
248     TypeName("fieldAverage");
251     // Constructors
253         //- Construct for given objectRegistry and dictionary.
254         //  Allow the possibility to load fields from files
255         fieldAverage
256         (
257             const word& name,
258             const objectRegistry&,
259             const dictionary&,
260             const bool loadFromFiles = false
261         );
264     //- Destructor
266         virtual ~fieldAverage();
269     // Member Functions
271         //- Return name of the set of field averages
272         virtual const word& name() const
273         {
274             return name_;
275         }
277         //- Read the field average data
278         virtual void read(const dictionary&);
280         //- Calculate the field average data and write
281         virtual void write();
285 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
287 } // End namespace Foam
289 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
291 #ifdef NoRepository
292 #   include "fieldAverageTemplates.C"
293 #endif
295 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
297 #endif
299 // ************************************************************************* //