Loading...
Searching...
No Matches
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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2016-2020 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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\*---------------------------------------------------------------------------*/
29#include "fieldAverageItem.H"
30#include "IOstreams.H"
31#include "dictionaryEntry.H"
32
33// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34
36:
37 active_(false),
38 fieldName_("unknown"),
39 mean_(false),
40 meanFieldName_("unknown"),
41 prime2Mean_(false),
42 prime2MeanFieldName_("unknown"),
43 base_(baseType::ITER),
44 totalIter_(0),
45 totalTime_(-1),
46 window_(-1.0),
47 windowName_(""),
48 windowType_(windowType::NONE),
49
50 windowTimes_(),
51 windowFieldNames_(),
52 allowRestart_(true)
54 is >> *this;
55}
56
57
58// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
59
60Foam::Istream& Foam::functionObjects::operator>>
61(
62 Istream& is,
63 fieldAverageItem& faItem
64)
65{
66 is.check(FUNCTION_NAME);
67
68 const dictionaryEntry dictEntry(dictionary::null, is);
69 const dictionary& dict = dictEntry.dict();
70
71 faItem.active_ = false;
72 faItem.fieldName_ = dictEntry.keyword();
73 faItem.mean_ = dict.get<bool>("mean");
74 faItem.prime2Mean_ = dict.get<bool>("prime2Mean");
75 faItem.base_ = faItem.baseTypeNames_.get("base", dict);
76 faItem.window_ = dict.getOrDefault<scalar>("window", -1);
77
78 if (faItem.window_ > 0)
79 {
80 faItem.windowType_ = faItem.windowTypeNames_.get("windowType", dict);
81
82 if (faItem.windowType_ != fieldAverageItem::windowType::NONE)
83 {
84 if
85 (
86 faItem.base_ == fieldAverageItem::baseType::ITER
87 && label(faItem.window_) < 1
88 )
89 {
90 FatalIOErrorInFunction(dictEntry)
91 << "Window must be 1 or more for base type "
92 << faItem.baseTypeNames_[fieldAverageItem::baseType::ITER]
94 }
95
96 faItem.windowName_ = dict.getOrDefault<word>("windowName", "");
97
98 if (faItem.windowType_ == fieldAverageItem::windowType::EXACT)
99 {
100 faItem.allowRestart_ = dict.get<bool>("allowRestart");
101
102 if (!faItem.allowRestart_)
103 {
105 << faItem.windowTypeNames_[faItem.windowType_]
106 << " windowing for field " << faItem.fieldName_
107 << " will not write intermediate files and restart will"
108 << " not be possible. To enable, please set"
109 << " 'allowRestart' to 'yes'"
110 << endl;
111 }
112 }
113 }
114 else
115 {
116 // Deactivate windowing
117 faItem.window_ = -1;
118 }
119 }
120 else
121 {
122 // Deactivate windowing
123 faItem.window_ = -1;
124 }
125
126 faItem.meanFieldName_ = faItem.fieldName_ + fieldAverageItem::EXT_MEAN;
127 faItem.prime2MeanFieldName_ =
128 faItem.fieldName_ + fieldAverageItem::EXT_PRIME2MEAN;
129
130 if ((faItem.window_ > 0) && (!faItem.windowName_.empty()))
131 {
132 faItem.meanFieldName_ =
133 faItem.meanFieldName_ + "_" + faItem.windowName_;
134
135 faItem.prime2MeanFieldName_ =
136 faItem.prime2MeanFieldName_ + "_" + faItem.windowName_;
137 }
138
139 return is;
140}
141
142
143Foam::Ostream& Foam::functionObjects::operator<<
144(
145 Ostream& os,
146 const fieldAverageItem& faItem
147)
148{
149 os.check(FUNCTION_NAME);
150
151 os.beginBlock(faItem.fieldName_);
152
153 os.writeEntry("mean", faItem.mean_);
154 os.writeEntry("prime2Mean", faItem.prime2Mean_);
155 os.writeEntry("base", faItem.baseTypeNames_[faItem.base_]);
156
157 if (faItem.window_ > 0)
158 {
159 os.writeEntry("window", faItem.window_);
160
161 if (!faItem.windowName_.empty())
162 {
163 os.writeEntry("windowName", faItem.windowName_);
164 }
165
166 os.writeEntry
167 (
168 "windowType",
169 faItem.windowTypeNames_[faItem.windowType_]
170 );
171
172 os.writeEntry("allowRestart", faItem.allowRestart_);
173 }
174
175 os.endBlock();
176
177 os.check(FUNCTION_NAME);
178
179 return os;
180}
181
182
183// ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A keyword and a list of tokens is a 'dictionaryEntry'.
virtual const dictionary & dict() const noexcept
Return dictionary (ie, this).
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition dictionary.H:487
const keyType & keyword() const noexcept
Return keyword.
Definition entry.H:231
Helper class to describe what form of averaging to apply. A set will be applied to each base field in...
baseType
Enumeration defining the averaging base type.
static const word EXT_PRIME2MEAN
Prime-squared average.
windowType
Enumeration defining the averaging window type.
static const word EXT_MEAN
Mean average.
A class for handling words, derived from Foam::string.
Definition word.H:66
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
OBJstream os(runTime.globalPath()/outputName)
#define WarningInFunction
Report a warning using Foam::Warning.
#define FUNCTION_NAME
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
dictionary dict