initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / postProcessing / functionObjects / field / fieldAverage / fieldAverage / fieldAverage.H
blob29ac4c2a3b06820004cedd1675bb1f4d2cef3eb3
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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         // Whether to perform a clean restart, or start from previous
41         // averaging info if available
42         cleanRestart true;
44         // Whether to reset the averaged fields after they have been written.
45         // Used to average over only the preceding write interval for transient
46         // cases.
47         resetOnOutput true;
49         // Fields to be averaged. runTime modifiable!
50         fields
51         (
52             U
53             {
54                 mean            on;
55                 prime2Mean      on;
56                 base            time;
57             }
58             p
59             {
60                 mean            on;
61                 prime2Mean      on;
62                 base            time;
63             }
64         );
65     @endverbatim
67     Member function calcAverages() calculates the averages.
69     Member function fieldAverage::write() calls calcAverages(). Average
70     field names are constructed by concatenating the base field with the
71     averaging type, e.g.
72     - base field, U
73     - arithmetic mean field, UMean
74     - prime-squared field, UPrime2Mean
76     Information regarding the number of averaging steps, and total averaging
77     time are written on a (base) per-field basis to the
78     fieldAveragingProperties dictionary, located in \<time\>/uniform
80 SourceFiles
81     fieldAverage.C
82     fieldAverageTemplates.C
84 \*---------------------------------------------------------------------------*/
86 #ifndef fieldAverage_H
87 #define fieldAverage_H
89 #include "volFieldsFwd.H"
90 #include "pointFieldFwd.H"
91 #include "Switch.H"
93 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
95 namespace Foam
98 // Forward declaration of classes
99 class objectRegistry;
100 class dictionary;
101 class fieldAverageItem;
102 class OFstream;
103 template<class Type>
104 class List;
105 class mapPolyMesh;
107 /*---------------------------------------------------------------------------*\
108                          Class fieldAverage Declaration
109 \*---------------------------------------------------------------------------*/
111 class fieldAverage
113 protected:
115     // File and field name extensions
117         //- Mean average
118         static const word EXT_MEAN;
120         //- Prime-squared average
121         static const word EXT_PRIME2MEAN;
123     // Private data
125         //- Name of this set of field averages.
126         word name_;
128         //- Database this class is registered to
129         const objectRegistry& obr_;
131         //- On/off switch
132         bool active_;
134         //- Time at last call, prevents repeated averaging
135         label prevTimeIndex_;
137         //- Clean restart flag
138         Switch cleanRestart_;
140         //- resetOnOutput flag
141         Switch resetOnOutput_;
143         //- List of field average items, describing what averages to be
144         //  calculated and output
145         List<fieldAverageItem> faItems_;
147         // Lists of averages
149             // Arithmetic mean fields
150             wordList meanScalarFields_;
151             wordList meanVectorFields_;
152             wordList meanSphericalTensorFields_;
153             wordList meanSymmTensorFields_;
154             wordList meanTensorFields_;
156             // Prime-squared fields
157             // Only applicable to volScalarFields / volVectorFields
158             wordList prime2MeanScalarFields_;
159             wordList prime2MeanSymmTensorFields_;
162         // Counters
164             //- Iteration steps counter
165             List<label> totalIter_;
167             //- Total time counter
168             List<scalar> totalTime_;
171     // Private Member Functions
173         // Initialisation routines
175             //- Checkout fields (causes deletion) from the database
176             //  and reset lists
177             void resetFields(wordList&);
179             //- Reset lists (clear existing values) and initialize averaging.
180             //  Check requested field averages are valid, populate field lists
181             void initialize();
183             //- Add mean average field to list
184             template<class Type>
185             void addMeanField(const label, wordList&) const;
187             //- Add prime-squared average field to list
188             template<class Type1, class Type2>
189             void addPrime2MeanField
190             (
191                 const label,
192                 const wordList&,
193                 wordList&
194             ) const;
197         // Calculation functions
199             //- Main calculation routine
200             virtual void calcAverages();
202             //- Calculate mean average fields
203             template<class Type>
204             void calculateMeanFields(const wordList&) const;
206             //- Add mean-squared field value to prime-squared mean field
207             template<class Type1, class Type2>
208             void addMeanSqrToPrime2Mean
209             (
210                 const wordList&,
211                 const wordList&
212             ) const;
214             //- Calculate prime-squared average fields
215             template<class Type1, class Type2>
216             void calculatePrime2MeanFields
217             (
218                 const wordList&,
219                 const wordList&
220             ) const;
223         // IO
225             //- Write averages
226             virtual void writeAverages() const;
228             //- Write fields
229             template<class Type>
230             void writeFieldList(const wordList&) const;
232             //- Write averaging properties - steps and time
233             void writeAveragingProperties() const;
235             //- Read averaging properties - steps and time
236             void readAveragingProperties();
239         // Functions to be over-ridden from IOoutputFilter class
241             //- Update mesh
242             virtual void updateMesh(const mapPolyMesh&);
244             //- Move points
245             virtual void movePoints(const Field<point>&);
248         //- Disallow default bitwise copy construct
249         fieldAverage(const fieldAverage&);
251         //- Disallow default bitwise assignment
252         void operator=(const fieldAverage&);
255 public:
257     //- Runtime type information
258     TypeName("fieldAverage");
261     // Constructors
263         //- Construct for given objectRegistry and dictionary.
264         //  Allow the possibility to load fields from files
265         fieldAverage
266         (
267             const word& name,
268             const objectRegistry&,
269             const dictionary&,
270             const bool loadFromFiles = false
271         );
274     //- Destructor
276         virtual ~fieldAverage();
279     // Member Functions
281         //- Return name of the set of field averages
282         virtual const word& name() const
283         {
284             return name_;
285         }
287         //- Read the field average data
288         virtual void read(const dictionary&);
290         //- Execute the averaging
291         virtual void execute();
293         //- Execute the averaging at the final time-loop, currently does nothing
294         virtual void end();
296         //- Calculate the field average data and write
297         virtual void write();
301 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
303 } // End namespace Foam
305 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
307 #ifdef NoRepository
308 #   include "fieldAverageTemplates.C"
309 #endif
311 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
313 #endif
315 // ************************************************************************* //