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-2017 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);
40 
42  (
43  functionObject,
44  valueAverage,
45  dictionary
46  );
47 }
48 }
49 
50 
51 // * * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * //
52 
54 {
55  writeHeader(os, "Value averages");
56  writeCommented(os, "Time");
57  forAll(fieldNames_, fieldi)
58  {
59  writeTabbed(os, fieldNames_[fieldi]);
60  }
61  os << endl;
62 }
63 
64 
65 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
66 
68 (
69  const word& name,
70  const Time& runTime,
71  const dictionary& dict
72 )
73 :
75  writeFile(obr_, name, typeName, dict),
76  functionObjectName_("unknown-functionObject"),
77  fieldNames_(),
78  window_(-1),
79  totalTime_(),
80  resetOnRestart_(false)
81 {
82  read(dict);
83 
84  if (resetOnRestart_)
85  {
86  forAll(fieldNames_, fieldi)
87  {
88  const word& fieldName = fieldNames_[fieldi];
89 
90  if (dict.found(fieldName))
91  {
92  const dictionary& valueDict = dict.subDict(fieldName);
93  valueDict.readEntry("totalTime", totalTime_[fieldi]);
94  }
95  }
96  }
97 
98  writeFileHeader(file());
99 }
100 
101 
102 // * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
103 
105 {}
106 
107 
108 // * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
109 
111 {
114 
115  // Make certain that the values are consistent with the defaults:
116  resetOnRestart_ = false;
117 
118  dict.readEntry("functionObject", functionObjectName_);
119  dict.readEntry("fields", fieldNames_);
120  if (dict.readIfPresent("window", window_))
121  {
122  window_ = obr().time().userTimeToTime(window_);
123  }
124 
125  totalTime_.setSize(fieldNames_.size());
126  forAll(totalTime_, i)
127  {
128  totalTime_[i] = time_.deltaTValue();
129  }
130 
131  dict.readIfPresent("resetOnRestart", resetOnRestart_);
132 
133  return true;
134 }
135 
136 
138 {
139  scalar dt = obr_.time().deltaTValue();
140 
141  Log << type() << ": " << name() << " averages:" << nl;
142 
143  file() << time_.timeName();
144 
145  DynamicList<label> unprocessedFields(fieldNames_.size());
146 
147  forAll(fieldNames_, fieldi)
148  {
149  const word& fieldName(fieldNames_[fieldi]);
150  const word meanName(fieldName + "Mean");
151 
152  scalar Dt = totalTime_[fieldi];
153  scalar alpha = (Dt - dt)/Dt;
154  scalar beta = dt/Dt;
155 
156  if (window_ > 0)
157  {
158  if (Dt - dt >= window_)
159  {
160  alpha = (window_ - dt)/window_;
161  beta = dt/window_;
162  }
163  }
164 
165  bool processed = false;
166  calc<scalar>(fieldName, meanName, alpha, beta, processed);
167  calc<vector>(fieldName, meanName, alpha, beta, processed);
168  calc<sphericalTensor>(fieldName, meanName, alpha, beta, processed);
169  calc<symmTensor>(fieldName, meanName, alpha, beta, processed);
170  calc<tensor>(fieldName, meanName, alpha, beta, processed);
171 
172  if (!processed)
173  {
174  unprocessedFields.append(fieldi);
175 
176  if (writeToFile())
177  {
178  file() << tab << "n/a";
179  }
180  }
181 
182  totalTime_[fieldi] += dt;
183  }
184 
185  file()<< endl;
186 
187  if (unprocessedFields.size())
188  {
190  << "From function object: " << functionObjectName_ << nl
191  << "Unprocessed fields:" << nl;
192 
193  forAll(unprocessedFields, i)
194  {
195  label fieldi = unprocessedFields[i];
196  Log << " " << fieldNames_[fieldi] << nl;
197  }
198  Log << endl;
199  }
200 
201  Log << endl;
202 
203  return true;
204 }
205 
206 
208 {
209  return true;
210 }
211 
212 
213 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::functionObjects::valueAverage::writeFileHeader
virtual void writeFileHeader(Ostream &os) const
Output file header information.
Definition: valueAverage.C:53
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::DynamicList< label >
Foam::functionObjects::valueAverage::execute
virtual bool execute()
Execute.
Definition: valueAverage.C:137
Foam::constant::atomic::alpha
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
Definition: readThermalProperties.H:212
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
valueAverage.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, add, dictionary)
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::functionObjects::writeFile::writeHeader
virtual void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition: writeFile.C:284
Foam::functionObjects::writeFile::read
virtual bool read(const dictionary &dict)
Read.
Definition: writeFile.C:212
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::functionObjects::valueAverage::read
virtual bool read(const dictionary &)
Read the field value average data.
Definition: valueAverage.C:110
Foam::functionObjects::valueAverage::fieldNames_
wordList fieldNames_
List of fields on which to operate.
Definition: valueAverage.H:142
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:314
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:121
Foam::functionObjects::regionFunctionObject::read
virtual bool read(const dictionary &dict)
Read optional controls.
Definition: regionFunctionObject.C:166
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::functionObjects::valueAverage::write
virtual bool write()
Write the value average.
Definition: valueAverage.C:207
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionObjects::valueAverage::valueAverage
valueAverage(const valueAverage &)=delete
No copy construct.
Foam::functionObjects::valueAverage::~valueAverage
virtual ~valueAverage()
Destructor.
Definition: valueAverage.C:104
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
Time.H
Foam::functionObjects::writeFile::writeCommented
virtual void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:258
Foam::tab
constexpr char tab
Definition: Ostream.H:371
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::functionObjects::regionFunctionObject
Specialization of Foam::functionObject for a region and providing a reference to the region Foam::obj...
Definition: regionFunctionObject.H:87
Foam::functionObjects::writeFile
functionObject base class for writing single files
Definition: writeFile.H:59
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:294
Foam::functionObjects::writeFile::writeTabbed
virtual void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: writeFile.C:274
Log
#define Log
Report write to Foam::Info if the local log switch is true.
Definition: messageStream.H:332