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