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 declaration of classes
96 class Istream;
97 class Ostream;
98 class objectRegistry;
99 
100 namespace functionObjects
101 {
102 
103 // Forward declaration of friend functions and operators
104 class fieldAverageItem;
105 Istream& operator>>(Istream&, fieldAverageItem&);
106 Ostream& operator<<(Ostream&, const fieldAverageItem&);
107 
108 /*---------------------------------------------------------------------------*\
109  Class fieldAverageItem Declaration
110 \*---------------------------------------------------------------------------*/
111 
112 class fieldAverageItem
113 {
114 public:
115 
116  // Public Data
117 
118  // File and field name extensions
119 
120  //- Mean average
121  static const word EXT_MEAN;
122 
123  //- Prime-squared average
124  static const word EXT_PRIME2MEAN;
125 
126 
127  //- Enumeration defining the averaging base type
128  enum class baseType
129  {
130  ITER,
131  TIME
132  };
133 
134  //- Enumeration defining the averaging window type
135  enum class windowType
136  {
137  NONE,
138  APPROXIMATE,
139  EXACT
140  };
141 
142 
143 private:
144 
145  // Private Data
146 
147  //- Active flag
148  bool active_;
149 
150  //- Field name
151  word fieldName_;
152 
153  //- Compute mean flag
154  bool mean_;
155 
156  //- Name of mean field
157  word meanFieldName_;
158 
159  //- Compute prime-squared mean flag
160  bool prime2Mean_;
161 
162  //- Name of prime-squared mean field
163  word prime2MeanFieldName_;
164 
165  //- Averaging base type names
166  static const Enum<baseType> baseTypeNames_;
167 
168  //- Averaging base type
169  baseType base_;
170 
171  //- Total number of iterations item has been evolved
172  label totalIter_;
173 
174  //- Total time item has been evolved
175  scalar totalTime_;
176 
177  //- Averaging window - defaults to -1 for 'all iters/time'
178  scalar window_;
179 
180  //- Averaging window name - defaults to 'window'
181  word windowName_;
182 
183  //- Averaging window type
184  windowType windowType_;
185 
186  //- Averaging window type names
187  static const Enum<windowType> windowTypeNames_;
188 
189  //- List of window times (windowType = EXACT)
190  FIFOStack<scalar> windowTimes_;
191 
192  //- List of window field names (windowType = EXACT)
193  FIFOStack<word> windowFieldNames_;
194 
195  //- Switch to write all necessary files for clean restart
196  bool allowRestart_;
197 
198 
199 public:
200 
201  // Constructors
202 
203  //- Construct null
205 
206  //- Construct from Istream
208 
209  //- Construct as copy
211 
212 
213  //- Destructor
215 
216 
217  // Member Functions
218 
219  // Access
220 
221  //- Return const access to the active flag
222  inline bool active() const;
223 
224  //- Return non-const access to the active flag
225  inline bool& active();
226 
227  //- Return const access to the field name
228  inline const word& fieldName() const;
229 
230  //- Return const access to the mean flag
231  inline bool mean() const;
232 
233  //- Return non-const access to the mean flag
234  inline bool& mean();
235 
236  //- Return const access to the mean field name
237  inline const word& meanFieldName() const;
238 
239  //- Return const access to the prime-squared mean flag
240  inline bool prime2Mean() const;
241 
242  //- Return non-const access to the prime-squared mean flag
243  inline bool& prime2Mean();
244 
245  //- Return const access to the prime-squared mean field name
246  inline const word& prime2MeanFieldName() const;
247 
248  //- Return averaging base type name
249  inline const word& base() const;
250 
251  //- Return the total number of iterations item has been evolved
252  inline label totalIter() const;
253 
254  //- Return the total time item has been evolved
255  inline scalar totalTime() const;
256 
257  //- Return the window length (iterations or seconds)
258  inline scalar window() const;
259 
260  //- Return the (optional) window name
261  inline const word& windowName() const;
262 
263  //- Return the list of window times (windowType = EXACT)
264  inline const FIFOStack<scalar>& windowTimes() const;
265 
266  //- Return the list of window field names (windowType = EXACT)
267  inline const FIFOStack<word>& windowFieldNames() const;
268 
269  //- Return the allow restart flag
270  inline bool allowRestart() const;
271 
272  //- Return the current time interval
273  inline scalar dt(const scalar deltaT) const;
274 
275  //- Return the total time interval
276  inline scalar Dt() const;
277 
278  //- Helper function to construct a window field name
279  inline word windowFieldName(const word& prefix) const;
280 
281  //- Return true if time is inside window (including boundaries)
282  inline bool inWindow(const scalar t) const;
283 
284  //- Return true if we wish to store window fields
285  inline bool storeWindowFields() const;
286 
287  //- Return true if we wish to write window fields
288  inline bool writeWindowFields() const;
289 
290  //- Add field to window
291  void addToWindow(const word& fieldName, const scalar deltaT);
292 
293  //- Evolve and update
294  void evolve(const objectRegistry& obr);
295 
296  //- Clear out all mean fields and (optionally) supporting data
297  void clear(const objectRegistry& obr, const bool fullClean);
298 
299  //- Read state and re-initialise values
300  bool readState(const dictionary& dict);
301 
302  //- Write state for restart
303  void writeState(dictionary& dict) const;
304 
305  //- Calculate the mean field value
306  template<class Type>
307  bool calculateMeanField(const objectRegistry& obr) const;
308 
309  //- Calculate prime-squared average fields
310  template<class Type1, class Type2>
311  bool calculatePrime2MeanField(const objectRegistry& obr) const;
312 
313 
314  // Member Operators
315 
316  void operator=(const fieldAverageItem&);
317 
318 
319  // Friend Operators
320 
321  friend bool operator==
322  (
323  const fieldAverageItem& a,
324  const fieldAverageItem& b
325  )
326  {
327  return
328  a.active_ == b.active_
329  && a.fieldName_ == b.fieldName_
330  && a.mean_ == b.mean_
331  && a.meanFieldName_ == b.meanFieldName_
332  && a.prime2Mean_ == b.prime2Mean_
333  && a.prime2MeanFieldName_ == b.prime2MeanFieldName_
334  && a.base_ == b.base_
335  && a.totalIter_ == b.totalIter_
336  && a.totalTime_ == b.totalTime_
337  && a.window_ == b.window_
338  && a.windowName_ == b.windowName_
339  && a.windowType_ == b.windowType_
340  && a.allowRestart_ == b.allowRestart_;
341  }
342 
343  friend bool operator!=
344  (
345  const fieldAverageItem& a,
346  const fieldAverageItem& b
347  )
348  {
349  return !(a == b);
350  }
351 
352 
353  // IOstream Operators
354 
356  friend Ostream& operator<<(Ostream&, const fieldAverageItem&);
357 };
358 
359 
360 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
361 
362 } // End namespace functionObjects
363 } // End namespace Foam
364 
365 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
366 
367 #include "fieldAverageItemI.H"
368 
369 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
370 
371 #ifdef NoRepository
372  #include "fieldAverageItemTemplates.C"
373 #endif
374 
375 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
376 
377 #endif
378 
379 // ************************************************************************* //
Foam::functionObjects::fieldAverageItem::operator>>
friend Istream & operator>>(Istream &, fieldAverageItem &)
FIFOStack.H
Foam::functionObjects::fieldAverageItem::calculatePrime2MeanField
bool calculatePrime2MeanField(const objectRegistry &obr) const
Calculate prime-squared average fields.
Definition: fieldAverageItemTemplates.C:168
Foam::Enum< baseType >
Foam::functionObjects::fieldAverageItem::windowTimes
const FIFOStack< scalar > & windowTimes() const
Return the list of window times (windowType = EXACT)
Definition: fieldAverageItemI.H:116
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::functionObjects::fieldAverageItem::windowType::NONE
Foam::functionObjects::fieldAverageItem::writeState
void writeState(dictionary &dict) const
Write state for restart.
Definition: fieldAverageItem.C:209
Foam::functionObjects::fieldAverageItem::~fieldAverageItem
~fieldAverageItem()
Destructor.
Definition: fieldAverageItem.C:117
fieldAverageItemTemplates.C
Foam::functionObjects::fieldAverageItem::writeWindowFields
bool writeWindowFields() const
Return true if we wish to write window fields.
Definition: fieldAverageItemI.H:226
fieldAverageItemI.H
Foam::functionObjects::fieldAverageItem::readState
bool readState(const dictionary &dict)
Read state and re-initialise values.
Definition: fieldAverageItem.C:193
Foam::functionObjects::operator<<
Ostream & operator<<(Ostream &, const fieldInfo &)
Definition: fieldInfo.H:142
Foam::functionObjects::fieldAverageItem::dt
scalar dt(const scalar deltaT) const
Return the current time interval.
Definition: fieldAverageItemI.H:136
Foam::functionObjects::operator>>
Istream & operator>>(Istream &, fieldInfo &)
Definition: fieldInfo.H:137
Foam::functionObjects::fieldAverageItem::operator=
void operator=(const fieldAverageItem &)
Definition: fieldAverageItem.C:227
Foam::functionObjects::fieldAverageItem::fieldName
const word & fieldName() const
Return const access to the field name.
Definition: fieldAverageItemI.H:42
Foam::functionObjects::fieldAverageItem::allowRestart
bool allowRestart() const
Return the allow restart flag.
Definition: fieldAverageItemI.H:129
Foam::functionObjects::fieldAverageItem::storeWindowFields
bool storeWindowFields() const
Return true if we wish to store window fields.
Definition: fieldAverageItemI.H:220
Foam::functionObjects::fieldAverageItem::totalIter
label totalIter() const
Return the total number of iterations item has been evolved.
Definition: fieldAverageItemI.H:91
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::functionObjects::fieldAverageItem::addToWindow
void addToWindow(const word &fieldName, const scalar deltaT)
Add field to window.
Definition: fieldAverageItem.C:124
Foam::functionObjects::fieldAverageItem::meanFieldName
const word & meanFieldName() const
Return const access to the mean field name.
Definition: fieldAverageItemI.H:61
Foam::functionObjects::fieldAverageItem::clear
void clear(const objectRegistry &obr, const bool fullClean)
Clear out all mean fields and (optionally) supporting data.
Definition: fieldAverageItem.C:163
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
Foam::functionObjects::fieldAverageItem::baseType::TIME
Foam::functionObjects::fieldAverageItem::baseType
baseType
Enumeration defining the averaging base type.
Definition: fieldAverageItem.H:175
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::functionObjects::fieldAverageItem::EXT_MEAN
static const word EXT_MEAN
Mean average.
Definition: fieldAverageItem.H:168
Foam::functionObjects::fieldAverageItem::mean
bool mean() const
Return const access to the mean flag.
Definition: fieldAverageItemI.H:48
Switch.H
Foam::functionObjects::fieldAverageItem::inWindow
bool inWindow(const scalar t) const
Return true if time is inside window (including boundaries)
Definition: fieldAverageItemI.H:195
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::functionObjects::fieldAverageItem::windowType::APPROXIMATE
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionObjects::fieldAverageItem::windowName
const word & windowName() const
Return the (optional) window name.
Definition: fieldAverageItemI.H:109
Foam::functionObjects::fieldAverageItem::baseType::ITER
Foam::functionObjects::fieldAverageItem::active
bool active() const
Return const access to the active flag.
Definition: fieldAverageItemI.H:30
Foam::functionObjects::fieldAverageItem
Helper class to describe what form of averaging to apply. A set will be applied to each base field in...
Definition: fieldAverageItem.H:159
Foam::functionObjects::fieldAverageItem::operator<<
friend Ostream & operator<<(Ostream &, const fieldAverageItem &)
Foam::functionObjects::fieldAverageItem::EXT_PRIME2MEAN
static const word EXT_PRIME2MEAN
Prime-squared average.
Definition: fieldAverageItem.H:171
Foam::functionObjects::fieldAverageItem::prime2Mean
bool prime2Mean() const
Return const access to the prime-squared mean flag.
Definition: fieldAverageItemI.H:67
Foam::functionObjects::fieldAverageItem::totalTime
scalar totalTime() const
Return the total time item has been evolved.
Definition: fieldAverageItemI.H:97
Foam::functionObjects::fieldAverageItem::window
scalar window() const
Return the window length (iterations or seconds)
Definition: fieldAverageItemI.H:103
Foam::functionObjects::fieldAverageItem::fieldAverageItem
fieldAverageItem()
Construct null.
Definition: fieldAverageItem.C:70
Foam::functionObjects::fieldAverageItem::Dt
scalar Dt() const
Return the total time interval.
Definition: fieldAverageItemI.H:162
Foam::functionObjects::fieldAverageItem::prime2MeanFieldName
const word & prime2MeanFieldName() const
Return const access to the prime-squared mean field name.
Definition: fieldAverageItemI.H:79
Foam::functionObjects::fieldAverageItem::calculateMeanField
bool calculateMeanField(const objectRegistry &obr) const
Calculate the mean field value.
Definition: fieldAverageItemTemplates.C:33
Foam::functionObjects::fieldAverageItem::windowFieldNames
const FIFOStack< word > & windowFieldNames() const
Return the list of window field names (windowType = EXACT)
Definition: fieldAverageItemI.H:123
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::functionObjects::fieldAverageItem::windowType::EXACT
Foam::FIFOStack< scalar >
Foam::functionObjects::fieldAverageItem::evolve
void evolve(const objectRegistry &obr)
Evolve and update.
Definition: fieldAverageItem.C:134
Foam::functionObjects::fieldAverageItem::windowType
windowType
Enumeration defining the averaging window type.
Definition: fieldAverageItem.H:182
Foam::functionObjects::fieldAverageItem::windowFieldName
word windowFieldName(const word &prefix) const
Helper function to construct a window field name.
Definition: fieldAverageItemI.H:187
Foam::functionObjects::fieldAverageItem::base
const word & base() const
Return averaging base type name.
Definition: fieldAverageItemI.H:85
Enum.H