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  //- Set the mean field name
240  inline void setMeanFieldName(const word& name);
241 
242  //- Return const access to the prime-squared mean flag
243  inline bool prime2Mean() const;
244 
245  //- Return non-const access to the prime-squared mean flag
246  inline bool& prime2Mean();
247 
248  //- Return const access to the prime-squared mean field name
249  inline const word& prime2MeanFieldName() const;
250 
251  //- Set the prime-squared mean field name
252  inline void setPrime2MeanFieldName(const word& name);
253 
254  //- Return averaging base type name
255  inline const word& base() const;
256 
257  //- Return the total number of iterations item has been evolved
258  inline label totalIter() const;
259 
260  //- Return the total time item has been evolved
261  inline scalar totalTime() const;
262 
263  //- Return the window length (iterations or seconds)
264  inline scalar window() const;
265 
266  //- Return the (optional) window name
267  inline const word& windowName() const;
268 
269  //- Return the list of window times (windowType = EXACT)
270  inline const FIFOStack<scalar>& windowTimes() const;
271 
272  //- Return the list of window field names (windowType = EXACT)
273  inline const FIFOStack<word>& windowFieldNames() const;
274 
275  //- Return the allow restart flag
276  inline bool allowRestart() const;
277 
278  //- Return the current time interval
279  inline scalar dt(const scalar deltaT) const;
280 
281  //- Return the total time interval
282  inline scalar Dt() const;
283 
284  //- Helper function to construct a window field name
285  inline word windowFieldName(const word& prefix) const;
286 
287  //- Return true if time is inside window (including boundaries)
288  inline bool inWindow(const scalar t) const;
289 
290  //- Return true if we wish to store window fields
291  inline bool storeWindowFields() const;
292 
293  //- Return true if we wish to write window fields
294  inline bool writeWindowFields() const;
295 
296  //- Add field to window
297  void addToWindow(const word& fieldName, const scalar deltaT);
298 
299  //- Evolve and update
300  void evolve(const objectRegistry& obr);
301 
302  //- Clear out all mean fields and (optionally) supporting data
303  void clear(const objectRegistry& obr, const bool fullClean);
304 
305  //- Read state and re-initialise values
306  bool readState(const dictionary& dict);
307 
308  //- Write state for restart
309  void writeState(dictionary& dict) const;
310 
311  //- Calculate the mean field value
312  template<class Type>
313  bool calculateMeanField(const objectRegistry& obr) const;
314 
315  //- Calculate prime-squared average fields
316  template<class Type1, class Type2>
317  bool calculatePrime2MeanField(const objectRegistry& obr) const;
318 
319 
320  // Member Operators
321 
322  void operator=(const fieldAverageItem&);
323 
324 
325  // Friend Operators
326 
327  friend bool operator==
328  (
329  const fieldAverageItem& a,
330  const fieldAverageItem& b
331  )
332  {
333  return
334  a.active_ == b.active_
335  && a.fieldName_ == b.fieldName_
336  && a.mean_ == b.mean_
337  && a.meanFieldName_ == b.meanFieldName_
338  && a.prime2Mean_ == b.prime2Mean_
339  && a.prime2MeanFieldName_ == b.prime2MeanFieldName_
340  && a.base_ == b.base_
341  && a.totalIter_ == b.totalIter_
342  && a.totalTime_ == b.totalTime_
343  && a.window_ == b.window_
344  && a.windowName_ == b.windowName_
345  && a.windowType_ == b.windowType_
346  && a.allowRestart_ == b.allowRestart_;
347  }
348 
349  friend bool operator!=
350  (
351  const fieldAverageItem& a,
352  const fieldAverageItem& b
353  )
354  {
355  return !(a == b);
356  }
357 
358 
359  // IOstream Operators
360 
362  friend Ostream& operator<<(Ostream&, const fieldAverageItem&);
363 };
364 
365 
366 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
367 
368 } // End namespace functionObjects
369 } // End namespace Foam
370 
371 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
372 
373 #include "fieldAverageItemI.H"
374 
375 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
376 
377 #ifdef NoRepository
378  #include "fieldAverageItemTemplates.C"
379 #endif
380 
381 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
382 
383 #endif
384 
385 // ************************************************************************* //
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:135
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::functionObjects::fieldAverageItem::windowType::NONE
Foam::functionObjects::fieldAverageItem::setPrime2MeanFieldName
void setPrime2MeanFieldName(const word &name)
Set the prime-squared mean field name.
Definition: fieldAverageItemI.H:96
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:245
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:143
Foam::functionObjects::fieldAverageItem::dt
scalar dt(const scalar deltaT) const
Return the current time interval.
Definition: fieldAverageItemI.H:155
Foam::functionObjects::operator>>
Istream & operator>>(Istream &, fieldInfo &)
Definition: fieldInfo.H:138
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:148
Foam::functionObjects::fieldAverageItem::storeWindowFields
bool storeWindowFields() const
Return true if we wish to store window fields.
Definition: fieldAverageItemI.H:239
Foam::functionObjects::fieldAverageItem::totalIter
label totalIter() const
Return the total number of iterations item has been evolved.
Definition: fieldAverageItemI.H:110
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:214
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:123
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:128
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::setMeanFieldName
void setMeanFieldName(const word &name)
Set the mean field name.
Definition: fieldAverageItemI.H:68
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:76
Foam::functionObjects::fieldAverageItem::totalTime
scalar totalTime() const
Return the total time item has been evolved.
Definition: fieldAverageItemI.H:116
Foam::functionObjects::fieldAverageItem::window
scalar window() const
Return the window length (iterations or seconds)
Definition: fieldAverageItemI.H:122
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:181
Foam::functionObjects::fieldAverageItem::prime2MeanFieldName
const word & prime2MeanFieldName() const
Return const access to the prime-squared mean field name.
Definition: fieldAverageItemI.H:89
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
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:142
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:206
Foam::functionObjects::fieldAverageItem::base
const word & base() const
Return averaging base type name.
Definition: fieldAverageItemI.H:104
Enum.H