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);
40  addToRunTimeSelectionTable(functionObject, valueAverage, dictionary);
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 
92  writeFileHeader(file());
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:35
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:47
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::DynamicList< label >
Foam::functionObjects::valueAverage::execute
virtual bool execute()
Execute.
Definition: valueAverage.C:125
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:369
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::functionObjects::writeFile::writeHeader
virtual void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition: writeFile.C:298
Foam::functionObjects::writeFile::read
virtual bool read(const dictionary &dict)
Read.
Definition: writeFile.C:213
Foam::functionObjects::valueAverage::read
virtual bool read(const dictionary &)
Read the field value average data.
Definition: valueAverage.C:98
Foam::functionObjects::valueAverage::fieldNames_
wordList fieldNames_
List of fields on which to operate.
Definition: valueAverage.H:185
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:302
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:123
Foam::functionObjects::regionFunctionObject::read
virtual bool read(const dictionary &dict)
Read optional controls.
Definition: regionFunctionObject.C:173
os
OBJstream os(runTime.globalPath()/outputName)
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:195
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionObjects::valueAverage::valueAverage
valueAverage(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: valueAverage.C:62
Time.H
Foam::functionObjects::writeFile::writeCommented
virtual void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:272
Foam::tab
constexpr char tab
Definition: Ostream.H:403
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
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::defineTypeNameAndDebug
defineTypeNameAndDebug(ObukhovLength, 0)
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::functionObjects::regionFunctionObject
Specialization of Foam::functionObject for a region and providing a reference to the region Foam::obj...
Definition: regionFunctionObject.H:90
Foam::functionObjects::writeFile
Base class for writing single files from the function objects.
Definition: writeFile.H:119
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:328
Foam::functionObjects::writeFile::writeTabbed
virtual void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: writeFile.C:288