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