fieldAverageItemIO.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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  fieldName_("unknown"),
35  mean_(0),
36  meanFieldName_("unknown"),
37  prime2Mean_(0),
38  prime2MeanFieldName_("unknown"),
39  base_(baseType::iter),
40  window_(-1.0)
41 {
42  is.check
43  (
44  "Foam::functionObjects::fieldAverageItem::fieldAverageItem"
45  "(Foam::Istream&)"
46  );
47 
49 
50  fieldName_ = entry.keyword();
51  entry.lookup("mean") >> mean_;
52  entry.lookup("prime2Mean") >> prime2Mean_;
53  base_ = baseTypeNames_[entry.lookup("base")];
54  window_ = entry.lookupOrDefault<scalar>("window", -1.0);
55  windowName_ = entry.lookupOrDefault<word>("windowName", "");
56 
57  meanFieldName_ = fieldName_ + EXT_MEAN;
58  prime2MeanFieldName_ = fieldName_ + EXT_PRIME2MEAN;
59  if ((window_ > 0) && (windowName_ != ""))
60  {
61  meanFieldName_ = meanFieldName_ + "_" + windowName_;
62  prime2MeanFieldName_ = prime2MeanFieldName_ + "_" + windowName_;
63  }
64 }
65 
66 
67 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
68 
69 Foam::Istream& Foam::functionObjects::operator>>
70 (
71  Istream& is,
72  fieldAverageItem& faItem
73 )
74 {
75  is.check
76  (
77  "Foam::Istream& Foam::operator>>"
78  "(Foam::Istream&, Foam::functionObjects::fieldAverageItem&)"
79  );
80 
82 
83  faItem.fieldName_ = entry.keyword();
84  entry.lookup("mean") >> faItem.mean_;
85  entry.lookup("prime2Mean") >> faItem.prime2Mean_;
86  faItem.base_ = faItem.baseTypeNames_[entry.lookup("base")];
87  faItem.window_ = entry.lookupOrDefault<scalar>("window", -1.0);
88  faItem.windowName_ = entry.lookupOrDefault<word>("windowName", "");
89 
90  faItem.meanFieldName_ = faItem.fieldName_ + fieldAverageItem::EXT_MEAN;
91  faItem.prime2MeanFieldName_ =
92  faItem.fieldName_ + fieldAverageItem::EXT_PRIME2MEAN;
93 
94  if ((faItem.window_ > 0) && (faItem.windowName_ != ""))
95  {
96  faItem.meanFieldName_ =
97  faItem.meanFieldName_ + "_" + faItem.windowName_;
98 
99  faItem.prime2MeanFieldName_ =
100  faItem.prime2MeanFieldName_ + "_" + faItem.windowName_;
101  }
102  return is;
103 }
104 
105 
106 Foam::Ostream& Foam::functionObjects::operator<<
107 (
108  Ostream& os,
109  const fieldAverageItem& faItem
110 )
111 {
112  os.check
113  (
114  "Foam::Ostream& Foam::operator<<"
115  "(Foam::Ostream&, const Foam::functionObjects::fieldAverageItem&)"
116  );
117 
118  os << faItem.fieldName_ << nl << token::BEGIN_BLOCK << nl;
119  os.writeKeyword("mean") << faItem.mean_ << token::END_STATEMENT << nl;
120  os.writeKeyword("prime2Mean") << faItem.mean_
121  << token::END_STATEMENT << nl;
122  os.writeKeyword("base") << faItem.baseTypeNames_[faItem.base_]
123  << token::END_STATEMENT << nl;
124 
125  if (faItem.window_ > 0)
126  {
127  os.writeKeyword("window") << faItem.window_
128  << token::END_STATEMENT << nl;
129 
130  if (faItem.windowName_ != "")
131  {
132  os.writeKeyword("windowName") << faItem.windowName_
133  << token::END_STATEMENT << nl;
134  }
135  }
136 
137  os << token::END_BLOCK << nl;
138 
139  os.check
140  (
141  "Foam::Ostream& Foam::operator<<"
142  "(Foam::Ostream&, const Foam::functionObjects::fieldAverageItem&)"
143  );
144 
145  return os;
146 }
147 
148 
149 // ************************************************************************* //
const keyType & keyword() const
Return keyword.
Definition: entry.H:123
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
static const dictionary null
Null dictionary.
Definition: dictionary.H:202
baseType
Enumeration defining the averaging base type.
A keyword and a list of tokens is a &#39;dictionaryEntry&#39;.
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
static const word EXT_PRIME2MEAN
Prime-squared average.
A class for handling words, derived from string.
Definition: word.H:59
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static const char nl
Definition: Ostream.H:265
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:54
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
Helper class to describe what form of averaging to apply. A set will be applied to each base field in...
static const word EXT_MEAN
Mean average.
A keyword and a list of tokens is an &#39;entry&#39;.
Definition: entry.H:65
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:576