fieldAverageItem.C
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-2019 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
27\*---------------------------------------------------------------------------*/
28
29#include "fieldAverageItem.H"
30
31// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32
34(
35 "Mean"
36);
37
38
40(
41 "Prime2Mean"
42);
43
44
45const Foam::Enum
46<
48>
49Foam::functionObjects::fieldAverageItem::baseTypeNames_
50({
51 { baseType::ITER, "iteration" },
52 { baseType::TIME, "time" },
53});
54
55
56const Foam::Enum
57<
59>
60Foam::functionObjects::fieldAverageItem::windowTypeNames_
61({
62 { windowType::NONE, "none" },
63 { windowType::APPROXIMATE, "approximate" },
64 { windowType::EXACT, "exact" },
65});
66
67
68// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
69
71:
72 active_(false),
73 fieldName_("unknown"),
74 mean_(false),
75 meanFieldName_("unknown"),
76 prime2Mean_(false),
77 prime2MeanFieldName_("unknown"),
78 base_(baseType::ITER),
79 totalIter_(0),
80 totalTime_(-1),
81 window_(-1),
82 windowName_(""),
83 windowType_(windowType::NONE),
84
85 windowTimes_(),
86 windowFieldNames_(),
87 allowRestart_(true)
88{}
89
90
92(
93 const fieldAverageItem& faItem
94)
95:
96 active_(faItem.active_),
97 fieldName_(faItem.fieldName_),
98 mean_(faItem.mean_),
99 meanFieldName_(faItem.meanFieldName_),
100 prime2Mean_(faItem.prime2Mean_),
101 prime2MeanFieldName_(faItem.prime2MeanFieldName_),
102 base_(faItem.base_),
103 totalIter_(faItem.totalIter_),
104 totalTime_(faItem.totalTime_),
105 window_(faItem.window_),
106 windowName_(faItem.windowName_),
107 windowType_(faItem.windowType_),
108
109 windowTimes_(faItem.windowTimes_),
110 windowFieldNames_(faItem.windowFieldNames_),
111 allowRestart_(faItem.allowRestart_)
112{}
113
114
115// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
116
118{}
119
120
121// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
122
124(
125 const word& fieldName,
126 const scalar deltaT
127)
128{
129 windowTimes_.push(deltaT);
130 windowFieldNames_.push(fieldName);
131}
132
133
135{
136 totalIter_++;
137 totalTime_ += obr.time().deltaTValue();
138 forAllIters(windowTimes_, timeIter)
139 {
140 timeIter() += obr.time().deltaTValue();
141 }
142
143 // Remove any fields that have passed out of the window
144 bool removeItem = true;
145
146 while (removeItem && windowTimes_.size())
147 {
148 removeItem = !(inWindow(windowTimes_.first()));
149
150 if (removeItem)
151 {
152 windowTimes_.pop();
153 const word fieldName = windowFieldNames_.pop();
154
155 //Info<< "evolve: removing field: " << fieldName << endl;
156 obr.checkOut(fieldName);
157 }
158 }
159}
160
161
163(
164 const objectRegistry& obr,
165 bool fullClean
166)
167{
168 if (mean_)
169 {
170 obr.checkOut(meanFieldName_);
171 }
172
173 if (prime2Mean_)
174 {
175 obr.checkOut(prime2MeanFieldName_);
176 }
177
178 for (const word& fieldName : windowFieldNames_)
179 {
180 obr.checkOut(fieldName);
181 }
182
183 if (totalTime_ < 0 || fullClean)
184 {
185 totalIter_ = 0;
186 totalTime_ = 0;
187 windowTimes_.clear();
188 windowFieldNames_.clear();
189 }
190}
191
192
194{
195 dict.readEntry("totalIter", totalIter_);
196 dict.readEntry("totalTime", totalTime_);
197
198 if (window_ > 0)
199 {
200 dict.readEntry("windowTimes", windowTimes_);
201 dict.readEntry("windowFieldNames", windowFieldNames_);
202 }
203
204 return true;
205}
206
207
209(
211) const
212{
213 dict.add("totalIter", totalIter_);
214 dict.add("totalTime", totalTime_);
215
216 if (window_ > 0)
217 {
218 dict.add("windowTimes", windowTimes_);
219 dict.add("windowFieldNames", windowFieldNames_);
220 }
221}
222
223
224// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
225
227(
228 const fieldAverageItem& rhs
229)
230{
231 if (this == &rhs)
232 {
233 return; // Self-assignment is a no-op
234 }
235
236 // Set updated values
237 active_ = rhs.active_;
238 fieldName_ = rhs.fieldName_;
239 mean_ = rhs.mean_;
240 meanFieldName_ = rhs.meanFieldName_;
241 prime2Mean_ = rhs.prime2Mean_;
242 prime2MeanFieldName_ = rhs.prime2MeanFieldName_;
243 base_ = rhs.base_;
244 totalIter_ = rhs.totalIter_;
245 totalTime_ = rhs.totalTime_;
246 window_ = rhs.window_;
247 windowName_ = rhs.windowName_;
248 windowType_ = rhs.windowType_;
249 windowTimes_ = rhs.windowTimes_;
250 windowFieldNames_ = rhs.windowFieldNames_;
251 allowRestart_ = rhs.allowRestart_;
252}
253
254
255// ************************************************************************* //
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: Enum.H:61
scalar deltaTValue() const noexcept
Return time step value.
Definition: TimeStateI.H:43
void evolve()
Evolve the cloud collection.
Definition: coalCloudList.C:84
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
friend Ostream & operator(Ostream &, const faMatrix< Type > &)
Helper class to describe what form of averaging to apply. A set will be applied to each base field in...
baseType
Enumeration defining the averaging base type.
static const word EXT_PRIME2MEAN
Prime-squared average.
windowType
Enumeration defining the averaging window type.
void addToWindow(const word &fieldName, const scalar deltaT)
Add field to window.
void writeState(dictionary &dict) const
Write state for restart.
static const word EXT_MEAN
Mean average.
bool readState()
Read state from file, applying relaxation as requested.
Registry of regIOobjects.
const Time & time() const noexcept
Return time registry.
bool checkOut(regIOobject *io) const
A class for handling words, derived from Foam::string.
Definition: word.H:68
dictionary dict
#define forAllIters(container, iter)
Iterate across all elements in the container object.
Definition: stdFoam.H:260