outputFilterOutputControl.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-2015 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 
27 #include "PstreamReduceOps.H"
28 
29 // * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33  template<>
34  const char* NamedEnum<outputFilterOutputControl::outputControls, 8>::
35  names[] =
36  {
37  "timeStep",
38  "outputTime",
39  "adjustableTime",
40  "runTime",
41  "clockTime",
42  "cpuTime",
43  "onEnd",
44  "none"
45  };
46 }
47 
50 
51 
52 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53 
55 (
56  const Time& t,
57  const dictionary& dict,
58  const word& prefix
59 )
60 :
61  time_(t),
62  prefix_(prefix),
63  outputControl_(ocTimeStep),
64  outputInterval_(0),
65  outputTimeLastDump_(0),
66  writeInterval_(-1)
67 {
68  read(dict);
69 }
70 
71 
72 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
73 
75 {}
76 
77 
78 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
79 
81 {
82  const word controlName(prefix_ + "Control");
83  const word intervalName(prefix_ + "Interval");
84 
85  if (dict.found(controlName))
86  {
87  outputControl_ = outputControlNames_.read(dict.lookup(controlName));
88  }
89  else
90  {
91  outputControl_ = ocTimeStep;
92  }
93 
94  switch (outputControl_)
95  {
96  case ocTimeStep:
97  {
98  outputInterval_ = dict.lookupOrDefault<label>(intervalName, 0);
99  break;
100  }
101 
102  case ocOutputTime:
103  {
104  outputInterval_ = dict.lookupOrDefault<label>(intervalName, 1);
105  break;
106  }
107 
108  case ocClockTime:
109  case ocRunTime:
110  case ocCpuTime:
111  case ocAdjustableTime:
112  {
113  writeInterval_ = readScalar(dict.lookup("writeInterval"));
114  break;
115  }
116 
117  case ocOnEnd:
118  default:
119  {
120  // do nothing
121  break;
122  }
123  }
124 }
125 
126 
128 {
129  switch (outputControl_)
130  {
131  case ocTimeStep:
132  {
133  return
134  (
135  (outputInterval_ <= 1)
136  || !(time_.timeIndex() % outputInterval_)
137  );
138  break;
139  }
140 
141  case ocOutputTime:
142  {
143  if (time_.outputTime())
144  {
145  outputTimeLastDump_ ++;
146  return !(outputTimeLastDump_ % outputInterval_);
147  }
148  break;
149  }
150 
151  case ocRunTime:
152  case ocAdjustableTime:
153  {
154  label outputIndex = label
155  (
156  (
157  (time_.value() - time_.startTime().value())
158  + 0.5*time_.deltaTValue()
159  )
160  / writeInterval_
161  );
162 
163  if (outputIndex > outputTimeLastDump_)
164  {
165  outputTimeLastDump_ = outputIndex;
166  return true;
167  }
168  break;
169  }
170 
171  case ocCpuTime:
172  {
173  label outputIndex = label
174  (
175  returnReduce(time_.elapsedCpuTime(), maxOp<double>())
176  / writeInterval_
177  );
178  if (outputIndex > outputTimeLastDump_)
179  {
180  outputTimeLastDump_ = outputIndex;
181  return true;
182  }
183  break;
184  }
185 
186  case ocClockTime:
187  {
188  label outputIndex = label
189  (
190  returnReduce(label(time_.elapsedClockTime()), maxOp<label>())
191  / writeInterval_
192  );
193  if (outputIndex > outputTimeLastDump_)
194  {
195  outputTimeLastDump_ = outputIndex;
196  return true;
197  }
198  break;
199  }
200 
201  case ocOnEnd:
202  {
203  scalar endTime = time_.endTime().value() - 0.5*time_.deltaTValue();
204  return time_.value() > endTime;
205  break;
206  }
207 
208  case ocNone:
209  {
210  return false;
211  }
212 
213  default:
214  {
215  // this error should not actually be possible
217  << "Undefined output control: "
218  << outputControlNames_[outputControl_] << nl
219  << abort(FatalError);
220  break;
221  }
222  }
223 
224  return false;
225 }
226 
227 
228 // ************************************************************************* //
Foam::maxOp
Definition: ops.H:172
Foam::outputFilterOutputControl::outputFilterOutputControl
outputFilterOutputControl(const outputFilterOutputControl &)
Disallow default bitwise copy construct and assignment.
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Foam::outputFilterOutputControl::outputControlNames_
static const NamedEnum< outputControls, 8 > outputControlNames_
String representation of outputControls enums.
Definition: outputFilterOutputControl.H:80
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:86
Foam::read
bool read(const char *, int32_t &)
Definition: int32IO.C:87
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::outputFilterOutputControl::~outputFilterOutputControl
~outputFilterOutputControl()
Destructor.
Definition: outputFilterOutputControl.C:74
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
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::outputFilterOutputControl::output
bool output()
Flag to indicate whether to output.
Definition: outputFilterOutputControl.C:127
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
PstreamReduceOps.H
outputFilterOutputControl.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
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::outputFilterOutputControl::read
void read(const dictionary &)
Read from dictionary.
Definition: outputFilterOutputControl.C:80
Foam::NamedEnum
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:52