fieldAverageItemIO.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) 2011-2013 OpenFOAM Foundation
6  \\/ M anipulation |
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 "fieldAverageItem.H"
27 #include "IOstreams.H"
28 #include "dictionaryEntry.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
33 :
34  active_(false),
35  fieldName_("unknown"),
36  mean_(0),
37  meanFieldName_("unknown"),
38  prime2Mean_(0),
39  prime2MeanFieldName_("unknown"),
40  base_(ITER),
41  window_(-1.0)
42 {
43  is.check("Foam::fieldAverageItem::fieldAverageItem(Foam::Istream&)");
44 
46 
48  entry.lookup("mean") >> mean_;
49  entry.lookup("prime2Mean") >> prime2Mean_;
50  base_ = baseTypeNames_[entry.lookup("base")];
51  window_ = entry.lookupOrDefault<scalar>("window", -1.0);
52  windowName_ = entry.lookupOrDefault<word>("windowName", "");
53 
56  if ((window_ > 0) && (windowName_ != ""))
57  {
60  }
61 }
62 
63 
64 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
65 
67 {
68  is.check
69  (
70  "Foam::Istream& Foam::operator>>"
71  "(Foam::Istream&, Foam::fieldAverageItem&)"
72  );
73 
75 
76  faItem.active_ = false;
77  faItem.fieldName_ = entry.keyword();
78  entry.lookup("mean") >> faItem.mean_;
79  entry.lookup("prime2Mean") >> faItem.prime2Mean_;
80  faItem.base_ = faItem.baseTypeNames_[entry.lookup("base")];
81  faItem.window_ = entry.lookupOrDefault<scalar>("window", -1.0);
82  faItem.windowName_ = entry.lookupOrDefault<word>("windowName", "");
83 
85  faItem.prime2MeanFieldName_ =
87 
88  if ((faItem.window_ > 0) && (faItem.windowName_ != ""))
89  {
90  faItem.meanFieldName_ =
91  faItem.meanFieldName_ + "_" + faItem.windowName_;
92 
93  faItem.prime2MeanFieldName_ =
94  faItem.prime2MeanFieldName_ + "_" + faItem.windowName_;
95  }
96  return is;
97 }
98 
99 
101 {
102  os.check
103  (
104  "Foam::Ostream& Foam::operator<<"
105  "(Foam::Ostream&, const Foam::fieldAverageItem&)"
106  );
107 
108  os << faItem.fieldName_ << nl << token::BEGIN_BLOCK << nl;
109  os.writeKeyword("mean") << faItem.mean_ << token::END_STATEMENT << nl;
110  os.writeKeyword("prime2Mean") << faItem.mean_
111  << token::END_STATEMENT << nl;
112  os.writeKeyword("base") << faItem.baseTypeNames_[faItem.base_]
113  << token::END_STATEMENT << nl;
114 
115  if (faItem.window_ > 0)
116  {
117  os.writeKeyword("window") << faItem.window_
118  << token::END_STATEMENT << nl;
119 
120  if (faItem.windowName_ != "")
121  {
122  os.writeKeyword("windowName") << faItem.windowName_
123  << token::END_STATEMENT << nl;
124  }
125  }
126 
127  os << token::END_BLOCK << nl;
128 
129  os.check
130  (
131  "Foam::Ostream& Foam::operator<<"
132  "(Foam::Ostream&, const Foam::fieldAverageItem&)"
133  );
134 
135  return os;
136 }
137 
138 
139 // ************************************************************************* //
Foam::fieldAverageItem
Helper class to describe what form of averaging to apply. A set will be applied to each base field in...
Definition: fieldAverageItem.H:74
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:65
Foam::fieldAverageItem::EXT_MEAN
static const word EXT_MEAN
Mean average.
Definition: fieldAverageItem.H:83
Foam::dictionaryEntry
A keyword and a list of tokens is a 'dictionaryEntry'.
Definition: dictionaryEntry.H:57
Foam::token::END_STATEMENT
@ END_STATEMENT
Definition: token.H:99
Foam::fieldAverageItem::fieldAverageItem
fieldAverageItem()
Construct null.
Definition: fieldAverageItem.C:54
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::entry::keyword
const keyType & keyword() const
Return keyword.
Definition: entry.H:120
Foam::fieldAverageItem::window_
scalar window_
Averaging window - defaults to -1 for 'all iters/time'.
Definition: fieldAverageItem.H:125
Foam::fieldAverageItem::mean_
Switch mean_
Compute mean flag.
Definition: fieldAverageItem.H:107
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::nl
static const char nl
Definition: Ostream.H:260
fieldAverageItem.H
Foam::fieldAverageItem::base_
baseType base_
Averaging base type.
Definition: fieldAverageItem.H:122
Foam::operator<<
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:130
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
Foam::fieldAverageItem::windowName_
word windowName_
Averaging window name - defaults to 'window'.
Definition: fieldAverageItem.H:128
Foam::fieldAverageItem::prime2Mean_
Switch prime2Mean_
Compute prime-squared mean flag.
Definition: fieldAverageItem.H:113
dictionaryEntry.H
Foam::fieldAverageItem::active_
Switch active_
Active flag.
Definition: fieldAverageItem.H:101
Foam::fieldAverageItem::fieldName_
word fieldName_
Field name.
Definition: fieldAverageItem.H:104
Foam::token::END_BLOCK
@ END_BLOCK
Definition: token.H:105
Foam::Ostream::writeKeyword
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:59
Foam::operator>>
Istream & operator>>(Istream &, edgeMesh &)
Definition: edgeMeshIO.C:141
Foam::fieldAverageItem::EXT_PRIME2MEAN
static const word EXT_PRIME2MEAN
Prime-squared average.
Definition: fieldAverageItem.H:86
Foam::fieldAverageItem::baseTypeNames_
static const NamedEnum< baseType, 2 > baseTypeNames_
Averaging base type names.
Definition: fieldAverageItem.H:119
Foam::token::BEGIN_BLOCK
@ BEGIN_BLOCK
Definition: token.H:104
Foam::fieldAverageItem::prime2MeanFieldName_
word prime2MeanFieldName_
Name of prime-squared mean field.
Definition: fieldAverageItem.H:116
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::dictionary::null
static const dictionary null
Null dictionary.
Definition: dictionary.H:193
Foam::fieldAverageItem::meanFieldName_
word meanFieldName_
Name of mean field.
Definition: fieldAverageItem.H:110