fieldAverageItem.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2017-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::functionObjects::fieldAverageItem
29 
30 Description
31  Helper class to describe what form of averaging to apply. A set will be
32  applied to each base field in Foam::fieldAverage, of the following form.
33 
34 Usage
35  \verbatim
36  <field1>
37  {
38  mean on;
39  prime2Mean on;
40  base time; // iteration
41  window 200; // optional averaging window
42  windowName w1; // optional window name (default = "")
43  windowType approximate; // window type
44 
45  allowRestart yes; // optional, used for windowType 'exact'
46  }
47  \endverbatim
48 
49  where the entries mean:
50  \table
51  Property | Description | Type | Req'd | Dflt
52  mean | Flag to calculate average | bool | yes | -
53  prime2Mean | Flag to calculate prime-square average | bool | yes | -
54  base | Type of averaging interval | word | yes | -
55  window | Averaging window | scalar | no |
56  windowName | Name of the averaging window | word | no | ""
57  windowType | Type of averaging window | word | no |
58  allowRestart | Flag to allow restart for windowType=exact | bool | no |
59  \endtable
60 
61  Options for the \c base entry:
62  \verbatim
63  time | Averaging interval is based on time
64  iter | Averaging interval is based on iterations
65  \endverbatim
66 
67  Options for the \c windowType entry:
68  \verbatim
69  none | no windowing
70  exact | allow additional files will be stored and written
71  approximate | disallow additional files will be stored and written
72  \endverbatim
73 
74 Note
75  To employ the \c prime2Mean option, the \c mean option must be enabled.
76 
77 SourceFiles
78  fieldAverageItem.C
79  fieldAverageItemIO.C
80 
81 \*---------------------------------------------------------------------------*/
82 
83 #ifndef fieldAverageItem_H
84 #define fieldAverageItem_H
85 
86 #include "Enum.H"
87 #include "Switch.H"
88 #include "FIFOStack.H"
89 
90 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
91 
92 namespace Foam
93 {
94 
95 // Forward Declarations
96 class objectRegistry;
97 
98 namespace functionObjects
99 {
100 
101 // Forward Declarations
102 class fieldAverageItem;
103 Istream& operator>>(Istream&, fieldAverageItem&);
104 Ostream& operator<<(Ostream&, const fieldAverageItem&);
105 
106 /*---------------------------------------------------------------------------*\
107  Class fieldAverageItem Declaration
108 \*---------------------------------------------------------------------------*/
109 
110 class fieldAverageItem
111 {
112 public:
113 
114  // Public Data
115 
116  // File and field name extensions
117 
118  //- Mean average
119  static const word EXT_MEAN;
120 
121  //- Prime-squared average
122  static const word EXT_PRIME2MEAN;
123 
124 
125  //- Enumeration defining the averaging base type
126  enum class baseType
127  {
128  ITER,
129  TIME
130  };
131 
132  //- Enumeration defining the averaging window type
133  enum class windowType
134  {
135  NONE,
136  APPROXIMATE,
137  EXACT
138  };
139 
140 
141 private:
142 
143  // Private Data
144 
145  //- Active flag
146  bool active_;
147 
148  //- Field name
149  word fieldName_;
150 
151  //- Compute mean flag
152  bool mean_;
154  //- Name of mean field
155  word meanFieldName_;
156 
157  //- Compute prime-squared mean flag
158  bool prime2Mean_;
159 
160  //- Name of prime-squared mean field
161  word prime2MeanFieldName_;
162 
163  //- Averaging base type names
164  static const Enum<baseType> baseTypeNames_;
165 
166  //- Averaging base type
167  baseType base_;
168 
169  //- Total number of iterations item has been evolved
170  label totalIter_;
171 
172  //- Total time item has been evolved
173  scalar totalTime_;
174 
175  //- Averaging window - defaults to -1 for 'all iters/time'
176  scalar window_;
177 
178  //- Averaging window name - defaults to 'window'
179  word windowName_;
180 
181  //- Averaging window type
182  windowType windowType_;
183 
184  //- Averaging window type names
185  static const Enum<windowType> windowTypeNames_;
186 
187  //- List of window times (windowType = EXACT)
188  FIFOStack<scalar> windowTimes_;
189 
190  //- List of window field names (windowType = EXACT)
191  FIFOStack<word> windowFieldNames_;
192 
193  //- Switch to write all necessary files for clean restart
194  bool allowRestart_;
195 
196 
197 public:
198 
199  // Constructors
200 
201  //- Construct null
203 
204  //- Construct from Istream
206 
207  //- Construct as copy
209 
210 
211  //- Destructor
213 
214 
215  // Member Functions
216 
217  // Access
218 
219  //- Return const access to the active flag
220  inline bool active() const;
221 
222  //- Return non-const access to the active flag
223  inline bool& active();
224 
225  //- Return const access to the field name
226  inline const word& fieldName() const;
227 
228  //- Return const access to the mean flag
229  inline bool mean() const;
230 
231  //- Return non-const access to the mean flag
232  inline bool& mean();
233 
234  //- Return const access to the mean field name
235  inline const word& meanFieldName() const;
236 
237  //- Set the mean field name
238  inline void setMeanFieldName(const word& name);
239 
240  //- Return const access to the prime-squared mean flag
241  inline bool prime2Mean() const;
242 
243  //- Return non-const access to the prime-squared mean flag
244  inline bool& prime2Mean();
245 
246  //- Return const access to the prime-squared mean field name
247  inline const word& prime2MeanFieldName() const;
248 
249  //- Set the prime-squared mean field name
250  inline void setPrime2MeanFieldName(const word& name);
251 
252  //- Return averaging base type name
253  inline const word& base() const;
254 
255  //- Return the total number of iterations item has been evolved
256  inline label totalIter() const;
257 
258  //- Return the total time item has been evolved
259  inline scalar totalTime() const;
260 
261  //- Return the window length (iterations or seconds)
262  inline scalar window() const;
263 
264  //- Return the (optional) window name
265  inline const word& windowName() const;
266 
267  //- Return the list of window times (windowType = EXACT)
268  inline const FIFOStack<scalar>& windowTimes() const;
269 
270  //- Return the list of window field names (windowType = EXACT)
271  inline const FIFOStack<word>& windowFieldNames() const;
272 
273  //- Return the allow restart flag
274  inline bool allowRestart() const;
275 
276  //- Return the current time interval
277  inline scalar dt(const scalar deltaT) const;
278 
279  //- Return the total time interval
280  inline scalar Dt() const;
281 
282  //- Helper function to construct a window field name
283  inline word windowFieldName(const word& prefix) const;
284 
285  //- Return true if time is inside window (including boundaries)
286  inline bool inWindow(const scalar t) const;
287 
288  //- Return true if we wish to store window fields
289  inline bool storeWindowFields() const;
290 
291  //- Return true if we wish to write window fields
292  inline bool writeWindowFields() const;
293 
294  //- Add field to window
295  void addToWindow(const word& fieldName, const scalar deltaT);
296 
297  //- Evolve and update
298  void evolve(const objectRegistry& obr);
299 
300  //- Clear out all mean fields and (optionally) supporting data
301  void clear(const objectRegistry& obr, const bool fullClean);
302 
303  //- Read state and re-initialise values
304  bool readState(const dictionary& dict);
305 
306  //- Write state for restart
307  void writeState(dictionary& dict) const;
308 
309  //- Calculate the mean field value
310  template<class Type>
311  bool calculateMeanField(const objectRegistry& obr) const;
312 
313  //- Calculate prime-squared average fields
314  template<class Type1, class Type2>
315  bool calculatePrime2MeanField(const objectRegistry& obr) const;
316 
317 
318  // Member Operators
319 
320  void operator=(const fieldAverageItem&);
321 
322 
323  // Friend Operators
324 
325  friend bool operator==
326  (
327  const fieldAverageItem& a,
328  const fieldAverageItem& b
329  )
330  {
331  return
332  a.active_ == b.active_
333  && a.fieldName_ == b.fieldName_
334  && a.mean_ == b.mean_
335  && a.meanFieldName_ == b.meanFieldName_
336  && a.prime2Mean_ == b.prime2Mean_
337  && a.prime2MeanFieldName_ == b.prime2MeanFieldName_
338  && a.base_ == b.base_
339  && a.totalIter_ == b.totalIter_
340  && a.totalTime_ == b.totalTime_
341  && a.window_ == b.window_
342  && a.windowName_ == b.windowName_
343  && a.windowType_ == b.windowType_
344  && a.allowRestart_ == b.allowRestart_;
345  }
346 
347  friend bool operator!=
348  (
349  const fieldAverageItem& a,
350  const fieldAverageItem& b
351  )
352  {
353  return !(a == b);
354  }
355 
356 
357  // IOstream Operators
358 
360  friend Ostream& operator<<(Ostream&, const fieldAverageItem&);
361 };
362 
363 
364 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
365 
366 } // End namespace functionObjects
367 } // End namespace Foam
368 
369 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
370 
371 #include "fieldAverageItemI.H"
372 
373 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
374 
375 #ifdef NoRepository
376  #include "fieldAverageItemTemplates.C"
377 #endif
378 
379 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
380 
381 #endif
382 
383 // ************************************************************************* //
dictionary dict
const word & meanFieldName() const
Return const access to the mean field name.
friend Istream & operator>>(Istream &, fieldAverageItem &)
friend Ostream & operator<<(Ostream &, const fieldAverageItem &)
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
void setMeanFieldName(const word &name)
Set the mean field name.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
baseType
Enumeration defining the averaging base type.
bool mean() const
Return const access to the mean flag.
scalar totalTime() const
Return the total time item has been evolved.
bool allowRestart() const
Return the allow restart flag.
word windowFieldName(const word &prefix) const
Helper function to construct a window field name.
const word & windowName() const
Return the (optional) window name.
scalar window() const
Return the window length (iterations or seconds)
const word & base() const
Return averaging base type name.
scalar dt(const scalar deltaT) const
Return the current time interval.
bool active() const
Return const access to the active flag.
bool readState(const dictionary &dict)
Read state and re-initialise values.
scalar Dt() const
Return the total time interval.
static const word EXT_PRIME2MEAN
Prime-squared average.
const word & fieldName() const
Return const access to the field name.
void operator=(const fieldAverageItem &)
void addToWindow(const word &fieldName, const scalar deltaT)
Add field to window.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
void writeState(dictionary &dict) const
Write state for restart.
Ostream & operator<<(Ostream &, const fieldInfo &)
Definition: fieldInfo.H:158
bool inWindow(const scalar t) const
Return true if time is inside window (including boundaries)
Istream & operator>>(Istream &, fieldInfo &)
Definition: fieldInfo.H:153
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
A class for handling words, derived from Foam::string.
Definition: word.H:63
const FIFOStack< scalar > & windowTimes() const
Return the list of window times (windowType = EXACT)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const FIFOStack< word > & windowFieldNames() const
Return the list of window field names (windowType = EXACT)
void evolve(const objectRegistry &obr)
Evolve and update.
const word & prime2MeanFieldName() const
Return const access to the prime-squared mean field name.
void setPrime2MeanFieldName(const word &name)
Set the prime-squared mean field name.
bool storeWindowFields() const
Return true if we wish to store window fields.
Helper class to describe what form of averaging to apply. A set will be applied to each base field in...
void clear(const objectRegistry &obr, const bool fullClean)
Clear out all mean fields and (optionally) supporting data.
Registry of regIOobjects.
label totalIter() const
Return the total number of iterations item has been evolved.
windowType
Enumeration defining the averaging window type.
bool prime2Mean() const
Return const access to the prime-squared mean flag.
bool calculatePrime2MeanField(const objectRegistry &obr) const
Calculate prime-squared average fields.
bool writeWindowFields() const
Return true if we wish to write window fields.
static const word EXT_MEAN
Mean average.
Namespace for OpenFOAM.
bool calculateMeanField(const objectRegistry &obr) const
Calculate the mean field value.