1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
24 \*---------------------------------------------------------------------------*/
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
31 void Foam::Time::readDict()
35 deltaT_ = readScalar(controlDict_.lookup("deltaT"));
38 if (controlDict_.found("writeControl"))
40 writeControl_ = writeControlNames_.read
42 controlDict_.lookup("writeControl")
46 scalar oldWriteInterval = writeInterval_;
47 if (controlDict_.readIfPresent("writeInterval", writeInterval_))
49 if (writeControl_ == wcTimeStep && label(writeInterval_) < 1)
51 FatalIOErrorIn("Time::readDict()", controlDict_)
52 << "writeInterval < 1 for writeControl timeStep"
53 << exit(FatalIOError);
58 controlDict_.lookup("writeFrequency") >> writeInterval_;
61 if (oldWriteInterval != writeInterval_)
63 switch (writeControl_)
66 case wcAdjustableRunTime:
67 // Recalculate outputTimeIndex_ to be in units of current
69 outputTimeIndex_ = label
82 if (controlDict_.readIfPresent("purgeWrite", purgeWrite_))
86 WarningIn("Time::readDict()")
87 << "invalid value for purgeWrite " << purgeWrite_
88 << ", should be >= 0, setting to 0"
95 if (controlDict_.found("timeFormat"))
97 const word formatName(controlDict_.lookup("timeFormat"));
99 if (formatName == "general")
103 else if (formatName == "fixed")
107 else if (formatName == "scientific")
109 format_ = scientific;
113 WarningIn("Time::readDict()")
114 << "unsupported time format " << formatName
119 controlDict_.readIfPresent("timePrecision", precision_);
121 // stopAt at 'endTime' or a specified value
122 // if nothing is specified, the endTime is zero
123 if (controlDict_.found("stopAt"))
125 stopAt_ = stopAtControlNames_.read(controlDict_.lookup("stopAt"));
127 if (stopAt_ == saEndTime)
129 controlDict_.lookup("endTime") >> endTime_;
136 else if (!controlDict_.readIfPresent("endTime", endTime_))
141 dimensionedScalar::name() = timeName(value());
143 if (controlDict_.found("writeVersion"))
145 writeVersion_ = IOstream::versionNumber
147 controlDict_.lookup("writeVersion")
151 if (controlDict_.found("writeFormat"))
153 writeFormat_ = IOstream::formatEnum
155 controlDict_.lookup("writeFormat")
159 if (controlDict_.found("writePrecision"))
161 IOstream::defaultPrecision
163 readUint(controlDict_.lookup("writePrecision"))
166 Sout.precision(IOstream::defaultPrecision());
167 Serr.precision(IOstream::defaultPrecision());
169 Pout.precision(IOstream::defaultPrecision());
170 Perr.precision(IOstream::defaultPrecision());
172 FatalError().precision(IOstream::defaultPrecision());
173 FatalIOError.error::operator()().precision
175 IOstream::defaultPrecision()
179 if (controlDict_.found("writeCompression"))
181 writeCompression_ = IOstream::compressionEnum
183 controlDict_.lookup("writeCompression")
187 controlDict_.readIfPresent("graphFormat", graphFormat_);
188 controlDict_.readIfPresent("runTimeModifiable", runTimeModifiable_);
190 if (!runTimeModifiable_ && controlDict_.watchIndex() != -1)
192 removeWatch(controlDict_.watchIndex());
193 controlDict_.watchIndex() = -1;
198 bool Foam::Time::read()
200 if (controlDict_.regIOobject::read())
212 void Foam::Time::readModifiedObjects()
214 if (runTimeModifiable_)
216 // Get state of all monitored objects (=registered objects with a
218 // Note: requires same ordering in objectRegistries on different
220 monitorPtr_().updateStates
223 regIOobject::fileModificationChecking == inotifyMaster
224 || regIOobject::fileModificationChecking == timeStampMaster
229 // Time handling is special since controlDict_ is the one dictionary
230 // that is not registered to any database.
232 if (controlDict_.readIfModified())
235 functionObjects_.read();
238 bool registryModified = objectRegistry::modified();
240 if (registryModified)
242 objectRegistry::readModifiedObjects();
248 bool Foam::Time::writeObject
250 IOstream::streamFormat fmt,
251 IOstream::versionNumber ver,
252 IOstream::compressionType cmp
257 IOdictionary timeDict
271 timeDict.add("index", timeIndex_);
272 timeDict.add("deltaT", deltaT_);
273 timeDict.add("deltaT0", deltaT0_);
275 timeDict.regIOobject::writeObject(fmt, ver, cmp);
276 bool writeOK = objectRegistry::writeObject(fmt, ver, cmp);
278 if (writeOK && purgeWrite_)
280 previousOutputTimes_.push(timeName());
282 while (previousOutputTimes_.size() > purgeWrite_)
284 rmDir(objectRegistry::path(previousOutputTimes_.pop()));
297 bool Foam::Time::writeNow()
304 bool Foam::Time::writeAndEnd()
306 stopAt_ = saWriteNow;
313 // ************************************************************************* //