initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / postProcessing / fieldAverage / fieldAverage / fieldAverage.H
blob7d7b22af8294bdcc2c366632e55b3062342a2548
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
74     IOfieldAverage.H
76 \*---------------------------------------------------------------------------*/
78 #ifndef fieldAverage_H
79 #define fieldAverage_H
81 #include "volFieldsFwd.H"
82 #include "pointFieldFwd.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         //- List of field average items, describing waht averages to be
118         //  calculated and output
119         List<fieldAverageItem> faItems_;
121         // File and field name extensions
123             //- Mean average
124             static const word EXT_MEAN;
126             //- Prime-squared average
127             static const word EXT_PRIME2MEAN;
130         // Lists of averages
132             // Arithmetic mean fields
133             PtrList<volScalarField> meanScalarFields_;
134             PtrList<volVectorField> meanVectorFields_;
135             PtrList<volSphericalTensorField> meanSphericalTensorFields_;
136             PtrList<volSymmTensorField> meanSymmTensorFields_;
137             PtrList<volTensorField> meanTensorFields_;
139             // Prime-squared fields - applicable to volVectorFields only
140             PtrList<volScalarField> prime2MeanScalarFields_;
141             PtrList<volSymmTensorField> prime2MeanSymmTensorFields_;
144         // Counters
146             //- Iteration steps counter
147             List<label> totalIter_;
149             //- Total time counter
150             List<scalar> totalTime_;
153     // Private Member Functions
155         // Initialisation routines
157             //- Reset size of lists (clear existing values)
158             void resetLists(const label nItems);
160             //- Intitialise averaging. Check requested field averages are
161             //  valid, and populate field lists
162             void initialise();
164             //- Add mean average field to PtrList
165             template<class Type>
166             void addMeanField
167             (
168                 const label,
169                 PtrList<GeometricField<Type, fvPatchField, volMesh> >&
170             );
172             //- Add prime-squared average field to PtrList
173             template<class Type1, class Type2>
174             void addPrime2MeanField
175             (
176                 const label,
177                 PtrList<GeometricField<Type1, fvPatchField, volMesh> >&,
178                 PtrList<GeometricField<Type2, fvPatchField, volMesh> >&
179             );
182         // Calculation functions
184             //- Main calculation routine
185             virtual void calcAverages();
187             //- Calculate mean average fields
188             template<class Type>
189             void calculateMeanFields
190             (
191                 PtrList<GeometricField<Type, fvPatchField, volMesh> >&
192             );
194             //- Add mean-squared field value to prime-squared mean field
195             template<class Type1, class Type2>
196             void addMeanSqrToPrime2Mean
197             (
198                 PtrList<GeometricField<Type1, fvPatchField, volMesh> >&,
199                 PtrList<GeometricField<Type2, fvPatchField, volMesh> >&
200             );
202             //- Calculate prime-squared average fields
203             template<class Type1, class Type2>
204             void calculatePrime2MeanFields
205             (
206                 PtrList<GeometricField<Type1, fvPatchField, volMesh> >&,
207                 PtrList<GeometricField<Type2, fvPatchField, volMesh> >&
208             );
211         // I-O
213             //- Write averages
214             virtual void writeAverages() const;
216             //- Write fields
217             template<class Type>
218             void writeFieldList
219             (
220                 const PtrList<GeometricField<Type, fvPatchField, volMesh> >&
221                     fieldList
222             ) const;
224             //- Write averaging properties - steps and time
225             void writeAveragingProperties() const;
227             //- Read averaging properties - steps and time
228             void readAveragingProperties();
231         // Functions to be over-ridden from IOoutputFilter class
233             //- Update mesh
234             virtual void updateMesh(const mapPolyMesh&);
236             //- Move points
237             virtual void movePoints(const Field<point>&);
240         //- Disallow default bitwise copy construct
241         fieldAverage(const fieldAverage&);
243         //- Disallow default bitwise assignment
244         void operator=(const fieldAverage&);
247 public:
249     //- Runtime type information
250     TypeName("fieldAverage");
253     // Constructors
255         //- Construct for given objectRegistry and dictionary.
256         //  Allow the possibility to load fields from files
257         fieldAverage
258         (
259             const word& name,
260             const objectRegistry&,
261             const dictionary&,
262             const bool loadFromFiles = false
263         );
266     //- Destructor
268         virtual ~fieldAverage();
271     // Member Functions
273         //- Return name of the set of field averages
274         virtual const word& name() const
275         {
276             return name_;
277         }
279         //- Read the field average data
280         virtual void read(const dictionary&);
282         //- Calculate the field average data and write
283         virtual void write();
287 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
289 } // End namespace Foam
291 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
293 #ifdef NoRepository
294 #   include "fieldAverageTemplates.C"
295 #endif
297 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
299 #endif
301 // ************************************************************************* //