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-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::functionObjects::fieldAverageItem
29
30Description
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
34Usage
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
74Note
75 To employ the \c prime2Mean option, the \c mean option must be enabled.
76
77SourceFiles
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
92namespace Foam
93{
94
95// Forward declaration of classes
96class Istream;
97class Ostream;
98class objectRegistry;
99
100namespace functionObjects
101{
102
103// Forward declaration of friend functions and operators
104class fieldAverageItem;
105Istream& operator>>(Istream&, fieldAverageItem&);
106Ostream& operator<<(Ostream&, const fieldAverageItem&);
107
108/*---------------------------------------------------------------------------*\
109 Class fieldAverageItem Declaration
110\*---------------------------------------------------------------------------*/
111
112class fieldAverageItem
113{
114public:
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,
139 EXACT
140 };
141
142
143private:
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_;
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
199public:
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"
375// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
376
377#ifdef NoRepository
379#endif
380
381// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
382
383#endif
384
385// ************************************************************************* //
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: Enum.H:61
A FIFO stack based on a singly-linked list.
Definition: FIFOStack.H:54
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Helper class to describe what form of averaging to apply. A set will be applied to each base field in...
bool calculatePrime2MeanField(const objectRegistry &obr) const
Calculate prime-squared average fields.
baseType
Enumeration defining the averaging base type.
bool allowRestart() const
Return the allow restart flag.
const FIFOStack< word > & windowFieldNames() const
Return the list of window field names (windowType = EXACT)
const word & base() const
Return averaging base type name.
const word & fieldName() const
Return const access to the field name.
bool writeWindowFields() const
Return true if we wish to write window fields.
bool mean() const
Return const access to the mean flag.
friend Istream & operator>>(Istream &, fieldAverageItem &)
static const word EXT_PRIME2MEAN
Prime-squared average.
void evolve(const objectRegistry &obr)
Evolve and update.
bool storeWindowFields() const
Return true if we wish to store window fields.
const word & windowName() const
Return the (optional) window name.
windowType
Enumeration defining the averaging window type.
bool inWindow(const scalar t) const
Return true if time is inside window (including boundaries)
friend Ostream & operator<<(Ostream &, const fieldAverageItem &)
scalar totalTime() const
Return the total time item has been evolved.
void addToWindow(const word &fieldName, const scalar deltaT)
Add field to window.
scalar window() const
Return the window length (iterations or seconds)
scalar dt(const scalar deltaT) const
Return the current time interval.
label totalIter() const
Return the total number of iterations item has been evolved.
scalar Dt() const
Return the total time interval.
word windowFieldName(const word &prefix) const
Helper function to construct a window field name.
void setPrime2MeanFieldName(const word &name)
Set the prime-squared mean field name.
bool calculateMeanField(const objectRegistry &obr) const
Calculate the mean field value.
bool prime2Mean() const
Return const access to the prime-squared mean flag.
void setMeanFieldName(const word &name)
Set the mean field name.
const FIFOStack< scalar > & windowTimes() const
Return the list of window times (windowType = EXACT)
const word & prime2MeanFieldName() const
Return const access to the prime-squared mean field name.
bool active() const
Return const access to the active flag.
void writeState(dictionary &dict) const
Write state for restart.
const word & meanFieldName() const
Return const access to the mean field name.
void operator=(const fieldAverageItem &)
static const word EXT_MEAN
Mean average.
bool readState(const dictionary &dict)
Read state and re-initialise values.
Registry of regIOobjects.
A class for handling words, derived from Foam::string.
Definition: word.H:68
patchWriters clear()
Istream & operator>>(Istream &, fieldInfo &)
Definition: fieldInfo.H:138
Ostream & operator<<(Ostream &, const fieldInfo &)
Definition: fieldInfo.H:143
Namespace for OpenFOAM.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
dictionary dict
volScalarField & b
Definition: createFields.H:27