valueAverageBase.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) 2015 OpenFOAM Foundation
9  Copyright (C) 2016-2022 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::valueAverageBase
29 
30 Description
31  Base class that computes the ensemble- or time-based singular-value average
32  values, with optional windowing, from the output of function objects
33  that generate non-field type values, e.g. \c Cd of \c forceCoeffs or
34  \c momentum_x in \c momentum function objects.
35 
36 See also
37  - Foam::functionObjects::writeFile
38 
39 SourceFiles
40  valueAverageBase.C
41  valueAverageBaseTemplates.C
42 
43 \*---------------------------------------------------------------------------*/
44 
45 #ifndef functionObjects_valueAverageBase_H
46 #define functionObjects_valueAverageBase_H
47 
48 #include "writeFile.H"
49 #include "Enum.H"
50 #include "stateFunctionObject.H"
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 namespace Foam
55 {
56 namespace functionObjects
57 {
58 
59 /*---------------------------------------------------------------------------*\
60  Class valueAverageBase Declaration
61 \*---------------------------------------------------------------------------*/
62 
63 class valueAverageBase
64 :
66 {
67 public:
68 
69  // Public Enumerations
70 
71  //- Averaging window types
72  enum class windowType : uint8_t
73  {
74  NONE,
75  APPROXIMATE,
76  EXACT
77  };
78 
79  //- Names for windowType enumeration
80  static const Enum<windowType> windowTypeNames;
81 
82 private:
83 
84  // Private Data
85 
86  //- Log flag
87  bool log;
88 
89 
90 protected:
91 
92  // Protected Data
93 
94  //- Reset the averaging process on restart
95  bool resetOnRestart_;
96 
97  //- Window type
99 
100  //- Reference to the state functionObject
102 
103  //- Name of function object to retrieve data from
105 
106  //- List of fields on which to operate
109  //- Optional tolerance to check for converged results
110  scalar tolerance_;
111 
112  //- Averaging window
113  scalar window_;
114 
115  //- Average time per field
117 
119  // Protected Member Functions
120 
121  //- Templated function to calculate the average
122  // Return true if processed
123  template<class Type, class Type2=Type>
124  bool calc(const label fieldi, bool& converged, dictionary& dict);
125 
126  //- Output file header information
127  virtual void writeFileHeader(Ostream& os) const;
129  //- Read state from dictionary
130  virtual void readState(dictionary& dict);
131 
132  //- Write state to dictionary for restarts
133  virtual void writeState(dictionary& dict);
134 
135  //- Reset state
136  virtual void resetState(dictionary& dict);
137 
138 
139 public:
140 
141  // Constructors
142 
143  //- Construct from Time and dictionary
145  (
146  const word& name,
147  const objectRegistry& obr,
148  const dictionary& dict,
149  stateFunctionObject& state,
150  const bool writeToFile = true
151  );
152 
153  //- No copy construct
154  valueAverageBase(const valueAverageBase&) = delete;
155 
156  //- No copy assignment
157  void operator=(const valueAverageBase&) = delete;
158 
159 
160  //- Destructor
161  virtual ~valueAverageBase() = default;
162 
163 
164  // Public Member Functions
165 
166  //- Read the field value average data
167  virtual bool read(const dictionary& dict);
168 
169  //- Calculate the averages
170  virtual bool calculate(dictionary& dict);
171 };
172 
173 
174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
175 
176 } // End namespace functionObjects
177 } // End namespace Foam
178 
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
180 
181 #ifdef NoRepository
182  #include "valueAverageBaseTemplates.C"
183 #endif
184 
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 
187 #endif
188 
189 // ************************************************************************* //
stateFunctionObject & state_
Reference to the state functionObject.
Computes the natural logarithm of an input volScalarField.
Definition: log.H:223
dictionary dict
virtual void writeState(dictionary &dict)
Write state to dictionary for restarts.
bool calc(const label fieldi, bool &converged, dictionary &dict)
Templated function to calculate the average.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
word functionObjectName_
Name of function object to retrieve data from.
static const Enum< windowType > windowTypeNames
Names for windowType enumeration.
virtual bool calculate(dictionary &dict)
Calculate the averages.
wordList fieldNames_
List of fields on which to operate.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
virtual void readState(dictionary &dict)
Read state from dictionary.
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual bool read(const dictionary &dict)
Read the field value average data.
virtual bool writeToFile() const
Flag to allow writing to file.
Definition: writeFile.C:281
virtual void writeFileHeader(Ostream &os) const
Output file header information.
virtual ~valueAverageBase()=default
Destructor.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
void operator=(const valueAverageBase &)=delete
No copy assignment.
List< scalar > totalTime_
Average time per field.
valueAverageBase(const word &name, const objectRegistry &obr, const dictionary &dict, stateFunctionObject &state, const bool writeToFile=true)
Construct from Time and dictionary.
Base class for function objects, adding functionality to read/write state information (data required ...
Registry of regIOobjects.
bool resetOnRestart_
Reset the averaging process on restart.
Base class for writing single files from the function objects.
Definition: writeFile.H:112
scalar tolerance_
Optional tolerance to check for converged results.
Base class that computes the ensemble- or time-based singular-value average values, with optional windowing, from the output of function objects that generate non-field type values, e.g. Cd of forceCoeffs or momentum_x in momentum function objects.
virtual void resetState(dictionary &dict)
Reset state.
Namespace for OpenFOAM.