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 | Copyright (C) 2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "valueAverage.H"
27 #include "Time.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33  defineTypeNameAndDebug(valueAverage, 0);
34 }
35 
36 
37 // * * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * //
38 
40 {
41  writeHeader(os, "Value averages");
42  writeCommented(os, "Time");
43  forAll(fieldNames_, fieldI)
44  {
45  writeTabbed(os, fieldNames_[fieldI]);
46  }
47  os << endl;
48 }
49 
50 
51 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52 
54 (
55  const word& name,
56  const objectRegistry& obr,
57  const dictionary& dict,
58  const bool loadFromFiles
59 )
60 :
62  functionObjectFile(obr, name, typeName, dict),
63  obr_(obr),
64  functionObjectName_(dict.lookup("functionObjectName")),
65  fieldNames_(dict.lookup("fields")),
66  window_(dict.lookupOrDefault<scalar>("window", -1)),
67  totalTime_(fieldNames_.size(), obr_.time().deltaTValue()),
68  resetOnRestart_(false),
69  log_(true)
70 {
71  if (resetOnRestart_)
72  {
73  forAll(fieldNames_, fieldI)
74  {
75  const word& fieldName = fieldNames_[fieldI];
76 
77  if (dict.found(fieldName))
78  {
79  const dictionary& valueDict = dict.subDict(fieldName);
80  totalTime_[fieldI] = readScalar(valueDict.lookup("totalTime"));
81  }
82  }
83  }
84 
85  writeFileHeader(file());
86 }
87 
88 
89 // * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
90 
92 {}
93 
94 
95 // * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
96 
98 {
99  if (active_)
100  {
102 
103  log_ = dict.lookupOrDefault<Switch>("log", true);
104  }
105 }
106 
107 
109 {
110  if (!active_)
111  {
112  return;
113  }
114 
115  scalar dt = obr_.time().deltaTValue();
116 
117  if (log_) Info<< type() << ": " << name_ << " averages:" << nl;
118 
119  file() << obr_.time().timeName();
120 
121  DynamicList<label> unprocessedFields(fieldNames_.size());
122 
123  forAll(fieldNames_, fieldI)
124  {
125  const word& fieldName(fieldNames_[fieldI]);
126  const word meanName(fieldName + "Mean");
127 
128  scalar Dt = totalTime_[fieldI];
129  scalar alpha = (Dt - dt)/Dt;
130  scalar beta = dt/Dt;
131 
132  if (window_ > 0)
133  {
134  if (Dt - dt >= window_)
135  {
136  alpha = (window_ - dt)/window_;
137  beta = dt/window_;
138  }
139  }
140 
141  bool processed = false;
142  calc<scalar>(fieldName, meanName, alpha, beta, processed);
143  calc<vector>(fieldName, meanName, alpha, beta, processed);
144  calc<sphericalTensor>(fieldName, meanName, alpha, beta, processed);
145  calc<symmTensor>(fieldName, meanName, alpha, beta, processed);
146  calc<tensor>(fieldName, meanName, alpha, beta, processed);
147 
148  if (!processed)
149  {
150  unprocessedFields.append(fieldI);
151 
152  if (writeToFile())
153  {
154  file() << tab << "n/a";
155  }
156  }
157 
158  totalTime_[fieldI] += dt;
159  }
160 
161  file()<< endl;
162 
163  if (unprocessedFields.size())
164  {
166  << "From function object: " << functionObjectName_ << nl
167  << "Unprocessed fields:" << nl;
168 
169  forAll(unprocessedFields, i)
170  {
171  label fieldI = unprocessedFields[i];
172  Info<< " " << fieldNames_[fieldI] << nl;
173  }
174  Info<< endl;
175  }
176 
177  if (log_) Info<< endl;
178 }
179 
180 
182 {
183  // Do nothing
184 }
185 
186 
188 {
189  // Do nothing
190 }
191 
192 
194 {
195  // Do nothing
196 }
197 
198 
199 // ************************************************************************* //
beta
dimensionedScalar beta("beta", dimless/dimTemperature, laminarTransport)
Foam::Switch
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:60
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::functionObjectState
Base class for function objects, adding functionality to read/write state information (data required ...
Definition: functionObjectState.H:54
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::DynamicList< label >
Foam::constant::atomic::alpha
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
Definition: readThermalProperties.H:216
valueAverage.H
Foam::functionObjectFile::writeTabbed
void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: functionObjectFile.C:230
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::dictionary::lookupOrDefault
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
Definition: dictionaryTemplates.C:33
Foam::functionObjectFile::read
void read(const dictionary &dict)
Read.
Definition: functionObjectFile.C:178
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::valueAverage::read
virtual void read(const dictionary &)
Read the field min/max data.
Definition: valueAverage.C:97
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::valueAverage::writeFileHeader
virtual void writeFileHeader(Ostream &os) const
Output file header information.
Definition: valueAverage.C:39
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:59
Foam::dictionary::found
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:304
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::valueAverage::write
virtual void write()
Write the fieldMinMax.
Definition: valueAverage.C:193
Foam::valueAverage::valueAverage
valueAverage(const valueAverage &)
Disallow default bitwise copy construct.
Foam::valueAverage::fieldNames_
wordList fieldNames_
List of fields on which to operate.
Definition: valueAverage.H:136
Foam::valueAverage::timeSet
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Definition: valueAverage.C:187
Foam::valueAverage::execute
virtual void execute()
Execute, currently does nothing.
Definition: valueAverage.C:108
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::valueAverage::~valueAverage
virtual ~valueAverage()
Destructor.
Definition: valueAverage.C:91
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::functionObjectFile::writeHeader
void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition: functionObjectFile.C:240
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::DynamicList::append
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Foam::tab
static const char tab
Definition: Ostream.H:259
Foam::readScalar
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
Foam::functionObjectFile
Base class for output file data handling.
Definition: functionObjectFile.H:57
Foam::valueAverage::end
virtual void end()
Execute at the final time-loop, currently does nothing.
Definition: valueAverage.C:181
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::dictionary::subDict
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:631
Foam::functionObjectFile::writeCommented
void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: functionObjectFile.C:219
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47