1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "objectRegistry.H"
28 #include "PstreamReduceOps.H"
30 #include "profiling.H"
32 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
34 void Foam::Time::readDict()
37 Info << "Time::readDict(): reading " << controlDict_.name() << endl;
41 deltaT_ = readScalar(controlDict_.lookup("deltaT"));
44 if (controlDict_.found("writeControl"))
46 word wcName(controlDict_.lookup("writeControl"));
48 if (writeControlNames_.found(wcName))
50 writeControl_ = writeControlNames_[wcName];
54 WarningIn("void Time::readDict()")
55 << wcName << " not found in enumeration "
56 << writeControlNames_.toc() << nl
57 << " setting writeControl to runTime" << endl;
59 writeControl_ = wcTimeStep;
64 scalar oldWriteInterval = writeInterval_;
65 if (controlDict_.readIfPresent("writeInterval", writeInterval_))
67 if (writeControl_ == wcTimeStep && label(writeInterval_) < 1)
69 WarningIn("Time::readDict()")
70 << "writeInterval < 1 for writeControl timeStep. "
79 controlDict_.lookup("writeFrequency") >> writeInterval_;
82 if (oldWriteInterval != writeInterval_)
84 switch (writeControl_)
87 case wcAdjustableRunTime:
88 // Recalculate outputTimeIndex_ to be in units of current
90 outputTimeIndex_ = label
103 if (controlDict_.readIfPresent("purgeWrite", purgeWrite_))
107 WarningIn("Time::readDict()")
108 << "invalid value for purgeWrite " << purgeWrite_
109 << ", should be >= 0, setting to 0"
116 if (controlDict_.found("timeFormat"))
118 word formatName(controlDict_.lookup("timeFormat"));
120 if (formatName == "general")
124 else if (formatName == "fixed")
128 else if (formatName == "scientific")
130 format_ = scientific;
134 WarningIn("void Time::readDict()")
135 << "unsupported time format " << formatName
140 controlDict_.readIfPresent("timePrecision", precision_);
142 // stopAt at 'endTime' or a specified value
143 // if nothing is specified, the endTime is zero
144 if (controlDict_.found("stopAt"))
146 word saName(controlDict_.lookup("stopAt"));
148 if (stopAtControlNames_.found(saName))
150 stopAt_ = stopAtControlNames_[saName];
154 WarningIn("void Time::readDict()")
155 << saName << " not found in enumeration "
156 << stopAtControlNames_.toc() << nl
157 << "Setting to writeNow" << endl;
159 stopAt_ = saWriteNow;
165 if (stopAt_ == saEndTime)
167 controlDict_.lookup("endTime") >> endTime_;
174 else if (!controlDict_.readIfPresent("endTime", endTime_))
179 dimensionedScalar::name() = timeName(value());
181 if (controlDict_.found("writeVersion"))
183 writeVersion_ = IOstream::versionNumber
185 controlDict_.lookup("writeVersion")
189 if (controlDict_.found("writeFormat"))
191 writeFormat_ = IOstream::formatEnum
193 controlDict_.lookup("writeFormat")
197 if (controlDict_.found("writePrecision"))
199 IOstream::defaultPrecision
201 readUint(controlDict_.lookup("writePrecision"))
204 Sout.precision(IOstream::defaultPrecision());
205 Serr.precision(IOstream::defaultPrecision());
207 Pout.precision(IOstream::defaultPrecision());
208 Perr.precision(IOstream::defaultPrecision());
211 if (controlDict_.found("writeCompression"))
213 writeCompression_ = IOstream::compressionEnum
215 controlDict_.lookup("writeCompression")
219 controlDict_.readIfPresent("graphFormat", graphFormat_);
220 controlDict_.readIfPresent("runTimeModifiable", runTimeModifiable_);
224 bool Foam::Time::read()
226 if (controlDict_.regIOobject::read())
239 void Foam::Time::readModifiedObjects()
241 if (runTimeModifiable_)
243 // For parallel runs check if any object's file has been modified
244 // and only call readIfModified on each object if this is the case
245 // to avoid unnecessary reductions in readIfModified for each object
247 bool anyModified = true;
249 if (Pstream::parRun())
251 anyModified = controlDict_.modified()
252 || objectRegistry::modified();
254 bool anyModifiedOnThisProc = anyModified;
255 reduce(anyModified, andOp<bool>());
257 if (anyModifiedOnThisProc && !anyModified)
259 WarningIn("Time::readModifiedObjects()")
260 << "Delaying reading objects due to inconsistent "
261 "file time-stamps between processors"
268 if (controlDict_.readIfModified())
271 functionObjects_.read();
274 objectRegistry::readModifiedObjects();
280 bool Foam::Time::writeObject
282 IOstream::streamFormat fmt,
283 IOstream::versionNumber ver,
284 IOstream::compressionType cmp
287 addProfile2(getCalled,"Foam::Time::writeObject");
291 addProfile2(actualOutput,"Foam::Time::writeObject - outputTime");
293 IOdictionary timeDict
307 timeDict.add("index", timeIndex_);
308 timeDict.add("deltaT", deltaT_);
309 timeDict.add("deltaT0", deltaT0_);
311 timeDict.regIOobject::writeObject(fmt, ver, cmp);
312 bool writeOK = objectRegistry::writeObject(fmt, ver, cmp);
314 if (writeOK && purgeWrite_)
316 previousOutputTimes_.push(timeName());
318 while (previousOutputTimes_.size() > purgeWrite_)
320 rmDir(objectRegistry::path(previousOutputTimes_.pop()));
333 bool Foam::Time::writeNow()
340 bool Foam::Time::writeAndEnd()
342 stopAt_ = saWriteNow;
349 // ************************************************************************* //