OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

fieldAverage.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     Foam::fieldAverage
00027 
00028 Description
00029     Calculates the field averages given list of fieldAverageItems, e.g.
00030 
00031     @verbatim
00032     fieldAverage1
00033     {
00034         // Type of functionObject
00035         type fieldAverage;
00036 
00037         // Where to load it from (if not already in solver)
00038         functionObjectLibs ("libfieldAverage.so");
00039 
00040         // Whether to perform a clean restart, or start from previous
00041         // averaging info if available
00042         cleanRestart true;
00043 
00044         // Whether to reset the averaged fields after they have been written.
00045         // Used to average over only the preceding write interval for transient
00046         // cases.
00047         resetOnOutput true;
00048 
00049         // Fields to be averaged. runTime modifiable!
00050         fields
00051         (
00052             U
00053             {
00054                 mean            on;
00055                 prime2Mean      on;
00056                 base            time;
00057             }
00058             p
00059             {
00060                 mean            on;
00061                 prime2Mean      on;
00062                 base            time;
00063             }
00064         );
00065     @endverbatim
00066 
00067     Member function calcAverages() calculates the averages.
00068 
00069     Member function fieldAverage::write() calls calcAverages(). Average
00070     field names are constructed by concatenating the base field with the
00071     averaging type, e.g.
00072     - base field, U
00073     - arithmetic mean field, UMean
00074     - prime-squared field, UPrime2Mean
00075 
00076     Information regarding the number of averaging steps, and total averaging
00077     time are written on a (base) per-field basis to the
00078     fieldAveragingProperties dictionary, located in <time>/uniform
00079 
00080 SourceFiles
00081     fieldAverage.C
00082     fieldAverageTemplates.C
00083 
00084 \*---------------------------------------------------------------------------*/
00085 
00086 #ifndef fieldAverage_H
00087 #define fieldAverage_H
00088 
00089 #include "volFieldsFwd.H"
00090 #include "pointFieldFwd.H"
00091 #include "Switch.H"
00092 
00093 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00094 
00095 namespace Foam
00096 {
00097 
00098 // Forward declaration of classes
00099 class objectRegistry;
00100 class dictionary;
00101 class fieldAverageItem;
00102 class OFstream;
00103 template<class Type>
00104 class List;
00105 class mapPolyMesh;
00106 
00107 /*---------------------------------------------------------------------------*\
00108                          Class fieldAverage Declaration
00109 \*---------------------------------------------------------------------------*/
00110 
00111 class fieldAverage
00112 {
00113 protected:
00114 
00115     // File and field name extensions
00116 
00117         //- Mean average
00118         static const word EXT_MEAN;
00119 
00120         //- Prime-squared average
00121         static const word EXT_PRIME2MEAN;
00122 
00123     // Private data
00124 
00125         //- Name of this set of field averages.
00126         word name_;
00127 
00128         //- Database this class is registered to
00129         const objectRegistry& obr_;
00130 
00131         //- On/off switch
00132         bool active_;
00133 
00134         //- Time at last call, prevents repeated averaging
00135         label prevTimeIndex_;
00136 
00137         //- Clean restart flag
00138         Switch cleanRestart_;
00139 
00140         //- resetOnOutput flag
00141         Switch resetOnOutput_;
00142 
00143         //- List of field average items, describing what averages to be
00144         //  calculated and output
00145         List<fieldAverageItem> faItems_;
00146 
00147         // Lists of averages
00148 
00149             // Arithmetic mean fields
00150             wordList meanScalarFields_;
00151             wordList meanVectorFields_;
00152             wordList meanSphericalTensorFields_;
00153             wordList meanSymmTensorFields_;
00154             wordList meanTensorFields_;
00155 
00156             // Prime-squared fields
00157             // Only applicable to volScalarFields / volVectorFields
00158             wordList prime2MeanScalarFields_;
00159             wordList prime2MeanSymmTensorFields_;
00160 
00161 
00162         // Counters
00163 
00164             //- Iteration steps counter
00165             List<label> totalIter_;
00166 
00167             //- Total time counter
00168             List<scalar> totalTime_;
00169 
00170 
00171     // Private Member Functions
00172 
00173         // Initialisation routines
00174 
00175             //- Checkout fields (causes deletion) from the database
00176             //  and reset lists
00177             void resetFields(wordList&);
00178 
00179             //- Reset lists (clear existing values) and initialize averaging.
00180             //  Check requested field averages are valid, populate field lists
00181             void initialize();
00182 
00183             //- Add mean average field to list
00184             template<class Type>
00185             void addMeanField(const label, wordList&) const;
00186 
00187             //- Add prime-squared average field to list
00188             template<class Type1, class Type2>
00189             void addPrime2MeanField
00190             (
00191                 const label,
00192                 const wordList&,
00193                 wordList&
00194             ) const;
00195 
00196 
00197         // Calculation functions
00198 
00199             //- Main calculation routine
00200             virtual void calcAverages();
00201 
00202             //- Calculate mean average fields
00203             template<class Type>
00204             void calculateMeanFields(const wordList&) const;
00205 
00206             //- Add mean-squared field value to prime-squared mean field
00207             template<class Type1, class Type2>
00208             void addMeanSqrToPrime2Mean
00209             (
00210                 const wordList&,
00211                 const wordList&
00212             ) const;
00213 
00214             //- Calculate prime-squared average fields
00215             template<class Type1, class Type2>
00216             void calculatePrime2MeanFields
00217             (
00218                 const wordList&,
00219                 const wordList&
00220             ) const;
00221 
00222 
00223         // IO
00224 
00225             //- Write averages
00226             virtual void writeAverages() const;
00227 
00228             //- Write fields
00229             template<class Type>
00230             void writeFieldList(const wordList&) const;
00231 
00232             //- Write averaging properties - steps and time
00233             void writeAveragingProperties() const;
00234 
00235             //- Read averaging properties - steps and time
00236             void readAveragingProperties();
00237 
00238 
00239         // Functions to be over-ridden from IOoutputFilter class
00240 
00241             //- Update mesh
00242             virtual void updateMesh(const mapPolyMesh&);
00243 
00244             //- Move points
00245             virtual void movePoints(const Field<point>&);
00246 
00247 
00248         //- Disallow default bitwise copy construct
00249         fieldAverage(const fieldAverage&);
00250 
00251         //- Disallow default bitwise assignment
00252         void operator=(const fieldAverage&);
00253 
00254 
00255 public:
00256 
00257     //- Runtime type information
00258     TypeName("fieldAverage");
00259 
00260 
00261     // Constructors
00262 
00263         //- Construct for given objectRegistry and dictionary.
00264         //  Allow the possibility to load fields from files
00265         fieldAverage
00266         (
00267             const word& name,
00268             const objectRegistry&,
00269             const dictionary&,
00270             const bool loadFromFiles = false
00271         );
00272 
00273 
00274     //- Destructor
00275 
00276         virtual ~fieldAverage();
00277 
00278 
00279     // Member Functions
00280 
00281         //- Return name of the set of field averages
00282         virtual const word& name() const
00283         {
00284             return name_;
00285         }
00286 
00287         //- Read the field average data
00288         virtual void read(const dictionary&);
00289 
00290         //- Execute the averaging
00291         virtual void execute();
00292 
00293         //- Execute the averaging at the final time-loop, currently does nothing
00294         virtual void end();
00295 
00296         //- Calculate the field average data and write
00297         virtual void write();
00298 };
00299 
00300 
00301 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00302 
00303 } // End namespace Foam
00304 
00305 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00306 
00307 #ifdef NoRepository
00308 #   include "fieldAverageTemplates.C"
00309 #endif
00310 
00311 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00312 
00313 #endif
00314 
00315 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd