FreeFOAM The Cross-Platform CFD Toolkit
TimeIO.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) 1991-2010 OpenCFD Ltd.
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 "Time.H"
28 
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
30 
32 {
33  if (!deltaTchanged_)
34  {
35  deltaT_ = readScalar(controlDict_.lookup("deltaT"));
36  }
37 
38  if (controlDict_.found("writeControl"))
39  {
41  (
42  controlDict_.lookup("writeControl")
43  );
44  }
45 
46  scalar oldWriteInterval = writeInterval_;
47  if (controlDict_.readIfPresent("writeInterval", writeInterval_))
48  {
49  if (writeControl_ == wcTimeStep && label(writeInterval_) < 1)
50  {
51  FatalIOErrorIn("Time::readDict()", controlDict_)
52  << "writeInterval < 1 for writeControl timeStep"
53  << exit(FatalIOError);
54  }
55  }
56  else
57  {
58  controlDict_.lookup("writeFrequency") >> writeInterval_;
59  }
60 
61  if (oldWriteInterval != writeInterval_)
62  {
63  switch (writeControl_)
64  {
65  case wcRunTime:
67  // Recalculate outputTimeIndex_ to be in units of current
68  // writeInterval.
69  outputTimeIndex_ = label
70  (
72  * oldWriteInterval
74  );
75  break;
76 
77  default:
78  break;
79  }
80  }
81 
82  if (controlDict_.readIfPresent("purgeWrite", purgeWrite_))
83  {
84  if (purgeWrite_ < 0)
85  {
86  WarningIn("Time::readDict()")
87  << "invalid value for purgeWrite " << purgeWrite_
88  << ", should be >= 0, setting to 0"
89  << endl;
90 
91  purgeWrite_ = 0;
92  }
93  }
94 
95  if (controlDict_.found("timeFormat"))
96  {
97  word formatName(controlDict_.lookup("timeFormat"));
98 
99  if (formatName == "general")
100  {
101  format_ = general;
102  }
103  else if (formatName == "fixed")
104  {
105  format_ = fixed;
106  }
107  else if (formatName == "scientific")
108  {
110  }
111  else
112  {
113  WarningIn("Time::readDict()")
114  << "unsupported time format " << formatName
115  << endl;
116  }
117  }
118 
119  controlDict_.readIfPresent("timePrecision", precision_);
120 
121  // stopAt at 'endTime' or a specified value
122  // if nothing is specified, the endTime is zero
123  if (controlDict_.found("stopAt"))
124  {
125  stopAt_ = stopAtControlNames_.read(controlDict_.lookup("stopAt"));
126 
127  if (stopAt_ == saEndTime)
128  {
129  controlDict_.lookup("endTime") >> endTime_;
130  }
131  else
132  {
133  endTime_ = GREAT;
134  }
135  }
136  else if (!controlDict_.readIfPresent("endTime", endTime_))
137  {
138  endTime_ = 0;
139  }
140 
142 
143  if (controlDict_.found("writeVersion"))
144  {
145  writeVersion_ = IOstream::versionNumber
146  (
147  controlDict_.lookup("writeVersion")
148  );
149  }
150 
151  if (controlDict_.found("writeFormat"))
152  {
153  writeFormat_ = IOstream::formatEnum
154  (
155  controlDict_.lookup("writeFormat")
156  );
157  }
158 
159  if (controlDict_.found("writePrecision"))
160  {
162  (
163  readUint(controlDict_.lookup("writePrecision"))
164  );
165 
168 
171  }
172 
173  if (controlDict_.found("writeCompression"))
174  {
175  writeCompression_ = IOstream::compressionEnum
176  (
177  controlDict_.lookup("writeCompression")
178  );
179  }
180 
181  controlDict_.readIfPresent("graphFormat", graphFormat_);
182  controlDict_.readIfPresent("runTimeModifiable", runTimeModifiable_);
183 }
184 
185 
187 {
188  if (controlDict_.regIOobject::read())
189  {
190  readDict();
191  return true;
192  }
193  else
194  {
195  return false;
196  }
197 }
198 
199 
201 {
202  if (runTimeModifiable_)
203  {
204  // For parallel runs check if any object's file has been modified
205  // and only call readIfModified on each object if this is the case
206  // to avoid unnecessary reductions in readIfModified for each object
207 
208  bool anyModified = true;
209 
210  if (Pstream::parRun())
211  {
212  anyModified = controlDict_.modified() || objectRegistry::modified();
213  bool anyModifiedOnThisProc = anyModified;
214  reduce(anyModified, andOp<bool>());
215 
216  if (anyModifiedOnThisProc && !anyModified)
217  {
218  WarningIn("Time::readModifiedObjects()")
219  << "Delaying reading objects due to inconsistent "
220  "file time-stamps between processors"
221  << endl;
222  }
223  }
224 
225  if (anyModified)
226  {
227  if (controlDict_.readIfModified())
228  {
229  readDict();
230  functionObjects_.read();
231  }
232 
234  }
235  }
236 }
237 
238 
240 (
244 ) const
245 {
246  if (outputTime())
247  {
248  IOdictionary timeDict
249  (
250  IOobject
251  (
252  "time",
253  timeName(),
254  "uniform",
255  *this,
258  false
259  )
260  );
261 
262  timeDict.add("index", timeIndex_);
263  timeDict.add("deltaT", deltaT_);
264  timeDict.add("deltaT0", deltaT0_);
265 
266  timeDict.regIOobject::writeObject(fmt, ver, cmp);
267  bool writeOK = objectRegistry::writeObject(fmt, ver, cmp);
268 
269  if (writeOK && purgeWrite_)
270  {
271  previousOutputTimes_.push(timeName());
272 
273  while (previousOutputTimes_.size() > purgeWrite_)
274  {
275  rmDir(objectRegistry::path(previousOutputTimes_.pop()));
276  }
277  }
278 
279  return writeOK;
280  }
281  else
282  {
283  return false;
284  }
285 }
286 
287 
289 {
290  outputTime_ = true;
291  return write();
292 }
293 
294 
296 {
297  stopAt_ = saWriteNow;
298  endTime_ = value();
299 
300  return writeNow();
301 }
302 
303 
304 // ************************ vim: set sw=4 sts=4 et: ************************ //