valueAverage.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) 2015 OpenFOAM Foundation
9  Copyright (C) 2015-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 \*---------------------------------------------------------------------------*/
28 
29 #include "valueAverage.H"
31 #include "Time.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace functionObjects
38 {
39  defineTypeNameAndDebug(valueAverage, 0);
41 }
42 }
43 
44 
45 // * * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * //
46 
48 {
49  writeHeader(os, "Value averages");
50  writeCommented(os, "Time");
51  forAll(fieldNames_, fieldi)
52  {
53  writeTabbed(os, fieldNames_[fieldi]);
54  }
55  os << endl;
56 }
57 
58 
59 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
60 
62 (
63  const word& name,
64  const Time& runTime,
65  const dictionary& dict
66 )
67 :
69  writeFile(obr_, name, typeName, dict),
70  functionObjectName_("unknown-functionObject"),
71  fieldNames_(),
72  window_(-1),
73  totalTime_(),
74  resetOnRestart_(false)
75 {
76  read(dict);
77 
78  if (resetOnRestart_)
79  {
80  forAll(fieldNames_, fieldi)
81  {
82  const word& fieldName = fieldNames_[fieldi];
83 
84  if (dict.found(fieldName))
85  {
86  const dictionary& valueDict = dict.subDict(fieldName);
87  valueDict.readEntry("totalTime", totalTime_[fieldi]);
88  }
89  }
90  }
91 
93 }
94 
95 
96 // * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
97 
99 {
102 
103  // Make certain that the values are consistent with the defaults:
104  resetOnRestart_ = false;
105 
106  dict.readEntry("functionObject", functionObjectName_);
107  dict.readEntry("fields", fieldNames_);
108  if (dict.readIfPresent("window", window_))
109  {
110  window_ = obr().time().userTimeToTime(window_);
111  }
112 
113  totalTime_.setSize(fieldNames_.size());
114  forAll(totalTime_, i)
115  {
116  totalTime_[i] = time_.deltaTValue();
117  }
118 
119  dict.readIfPresent("resetOnRestart", resetOnRestart_);
120 
121  return true;
122 }
123 
124 
126 {
127  scalar dt = obr_.time().deltaTValue();
128 
129  Log << type() << ": " << name() << " averages:" << nl;
130 
131  file() << time_.timeName();
132 
133  DynamicList<label> unprocessedFields(fieldNames_.size());
134 
135  forAll(fieldNames_, fieldi)
136  {
137  const word& fieldName(fieldNames_[fieldi]);
138  const word meanName(fieldName + "Mean");
139 
140  scalar Dt = totalTime_[fieldi];
141  scalar alpha = (Dt - dt)/Dt;
142  scalar beta = dt/Dt;
143 
144  if (window_ > 0)
145  {
146  if (Dt - dt >= window_)
147  {
148  alpha = (window_ - dt)/window_;
149  beta = dt/window_;
150  }
151  }
152 
153  bool processed = false;
154  calc<scalar>(fieldName, meanName, alpha, beta, processed);
155  calc<vector>(fieldName, meanName, alpha, beta, processed);
156  calc<sphericalTensor>(fieldName, meanName, alpha, beta, processed);
157  calc<symmTensor>(fieldName, meanName, alpha, beta, processed);
158  calc<tensor>(fieldName, meanName, alpha, beta, processed);
159 
160  if (!processed)
161  {
162  unprocessedFields.append(fieldi);
163 
164  if (writeToFile())
165  {
166  file() << tab << "n/a";
167  }
168  }
169 
170  totalTime_[fieldi] += dt;
171  }
172 
173  file()<< endl;
174 
175  if (unprocessedFields.size())
176  {
178  << "From function object: " << functionObjectName_ << nl
179  << "Unprocessed fields:" << nl;
180 
181  forAll(unprocessedFields, i)
182  {
183  label fieldi = unprocessedFields[i];
184  Log << " " << fieldNames_[fieldi] << nl;
185  }
186  Log << endl;
187  }
188 
189  Log << endl;
190 
191  return true;
192 }
193 
194 
196 {
197  return true;
198 }
199 
200 
201 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Log
#define Log
Definition: PDRblock.C:28
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
Foam::functionObjects::valueAverage
Computes the ensemble- or time-based singular-value average values, with optional windowing,...
Definition: valueAverage.H:168
Foam::functionObjects::valueAverage::writeFileHeader
virtual void writeFileHeader(Ostream &os) const
Definition: valueAverage.C:40
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:63
Foam::functionObjects::writeFile::file
virtual OFstream & file()
Definition: writeFile.C:229
Foam::DynamicList< label >
Foam::functionObjects::valueAverage::execute
virtual bool execute()
Definition: valueAverage.C:118
Foam::constant::atomic::alpha
const dimensionedScalar alpha
Definition: readThermalProperties.H:212
Foam::read
bool read(const char *buf, int32_t &val)
Definition: int32.H:125
valueAverage.H
Foam::endl
Ostream & endl(Ostream &os)
Definition: Ostream.H:381
Foam::functionObjects::valueAverage::totalTime_
List< scalar > totalTime_
Definition: valueAverage.H:187
Foam::functionObject
Abstract base-class for Time/database function objects.
Definition: functionObject.H:329
forAll
#define forAll(list, i)
Definition: stdFoam.H:349
Foam::functionObjects::writeFile::writeHeader
virtual void writeHeader(Ostream &os, const string &str) const
Definition: writeFile.C:291
Foam::functionObjects::writeFile::read
virtual bool read(const dictionary &dict)
Definition: writeFile.C:206
Foam::DynamicList::append
DynamicList< T, SizeMin > & append(const T &val)
Definition: DynamicListI.H:504
Foam::functionObjects::valueAverage::read
virtual bool read(const dictionary &)
Definition: valueAverage.C:91
Foam::functionObjects::valueAverage::fieldNames_
wordList fieldNames_
Definition: valueAverage.H:181
beta
dimensionedScalar beta("beta", dimless/dimTemperature, laminarTransport)
Foam::dictionary::readEntry
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Definition: dictionaryTemplates.C:295
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:119
Foam::functionObjects::regionFunctionObject::read
virtual bool read(const dictionary &dict)
Definition: regionFunctionObject.C:166
os
OBJstream os(runTime.globalPath()/outputName)
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::functionObjects::valueAverage::write
virtual bool write()
Definition: valueAverage.C:188
Foam
Definition: atmBoundaryLayer.C:26
Foam::functionObjects::valueAverage::valueAverage
valueAverage(const word &name, const Time &runTime, const dictionary &dict)
Definition: valueAverage.C:55
Time.H
Foam::functionObjects::writeFile::writeCommented
virtual void writeCommented(Ostream &os, const string &str) const
Definition: writeFile.C:265
Foam::tab
constexpr char tab
Definition: Ostream.H:423
Foam::nl
constexpr char nl
Definition: Ostream.H:424
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Definition: POSIX.C:717
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(ObukhovLength, 0)
Foam::name
word name(const expressions::valueTypeCode typeCode)
Definition: exprTraits.C:52
Foam::functionObjects::regionFunctionObject
Specialization of Foam::functionObject for a region and providing a reference to the region Foam::obj...
Definition: regionFunctionObject.H:86
Foam::functionObjects::writeFile
Base class for writing single files from the function objects.
Definition: writeFile.H:115
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:52
Foam::functionObjects::valueAverage::resetOnRestart_
Switch resetOnRestart_
Definition: valueAverage.H:190
WarningInFunction
#define WarningInFunction
Definition: messageStream.H:353
Foam::functionObjects::writeFile::writeTabbed
virtual void writeTabbed(Ostream &os, const string &str) const
Definition: writeFile.C:281