TimeIO.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "Time.H"
00028 #include "PstreamReduceOps.H"
00029
00030
00031
00032 void Foam::Time::readDict()
00033 {
00034 if (!deltaTchanged_)
00035 {
00036 deltaT_ = readScalar(controlDict_.lookup("deltaT"));
00037 }
00038
00039 if (controlDict_.found("writeControl"))
00040 {
00041 writeControl_ = writeControlNames_.read
00042 (
00043 controlDict_.lookup("writeControl")
00044 );
00045 }
00046
00047 scalar oldWriteInterval = writeInterval_;
00048 if (controlDict_.readIfPresent("writeInterval", writeInterval_))
00049 {
00050 if (writeControl_ == wcTimeStep && label(writeInterval_) < 1)
00051 {
00052 FatalIOErrorIn("Time::readDict()", controlDict_)
00053 << "writeInterval < 1 for writeControl timeStep"
00054 << exit(FatalIOError);
00055 }
00056 }
00057 else
00058 {
00059 controlDict_.lookup("writeFrequency") >> writeInterval_;
00060 }
00061
00062 if (oldWriteInterval != writeInterval_)
00063 {
00064 switch (writeControl_)
00065 {
00066 case wcRunTime:
00067 case wcAdjustableRunTime:
00068
00069
00070 outputTimeIndex_ = label
00071 (
00072 outputTimeIndex_
00073 * oldWriteInterval
00074 / writeInterval_
00075 );
00076 break;
00077
00078 default:
00079 break;
00080 }
00081 }
00082
00083 if (controlDict_.readIfPresent("purgeWrite", purgeWrite_))
00084 {
00085 if (purgeWrite_ < 0)
00086 {
00087 WarningIn("Time::readDict()")
00088 << "invalid value for purgeWrite " << purgeWrite_
00089 << ", should be >= 0, setting to 0"
00090 << endl;
00091
00092 purgeWrite_ = 0;
00093 }
00094 }
00095
00096 if (controlDict_.found("timeFormat"))
00097 {
00098 word formatName(controlDict_.lookup("timeFormat"));
00099
00100 if (formatName == "general")
00101 {
00102 format_ = general;
00103 }
00104 else if (formatName == "fixed")
00105 {
00106 format_ = fixed;
00107 }
00108 else if (formatName == "scientific")
00109 {
00110 format_ = scientific;
00111 }
00112 else
00113 {
00114 WarningIn("Time::readDict()")
00115 << "unsupported time format " << formatName
00116 << endl;
00117 }
00118 }
00119
00120 controlDict_.readIfPresent("timePrecision", precision_);
00121
00122
00123
00124 if (controlDict_.found("stopAt"))
00125 {
00126 stopAt_ = stopAtControlNames_.read(controlDict_.lookup("stopAt"));
00127
00128 if (stopAt_ == saEndTime)
00129 {
00130 controlDict_.lookup("endTime") >> endTime_;
00131 }
00132 else
00133 {
00134 endTime_ = GREAT;
00135 }
00136 }
00137 else if (!controlDict_.readIfPresent("endTime", endTime_))
00138 {
00139 endTime_ = 0;
00140 }
00141
00142 dimensionedScalar::name() = timeName(value());
00143
00144 if (controlDict_.found("writeVersion"))
00145 {
00146 writeVersion_ = IOstream::versionNumber
00147 (
00148 controlDict_.lookup("writeVersion")
00149 );
00150 }
00151
00152 if (controlDict_.found("writeFormat"))
00153 {
00154 writeFormat_ = IOstream::formatEnum
00155 (
00156 controlDict_.lookup("writeFormat")
00157 );
00158 }
00159
00160 if (controlDict_.found("writePrecision"))
00161 {
00162 IOstream::defaultPrecision
00163 (
00164 readUint(controlDict_.lookup("writePrecision"))
00165 );
00166
00167 Sout.precision(IOstream::defaultPrecision());
00168 Serr.precision(IOstream::defaultPrecision());
00169
00170 Pout.precision(IOstream::defaultPrecision());
00171 Perr.precision(IOstream::defaultPrecision());
00172 }
00173
00174 if (controlDict_.found("writeCompression"))
00175 {
00176 writeCompression_ = IOstream::compressionEnum
00177 (
00178 controlDict_.lookup("writeCompression")
00179 );
00180 }
00181
00182 controlDict_.readIfPresent("graphFormat", graphFormat_);
00183 controlDict_.readIfPresent("runTimeModifiable", runTimeModifiable_);
00184 }
00185
00186
00187 bool Foam::Time::read()
00188 {
00189 if (controlDict_.regIOobject::read())
00190 {
00191 readDict();
00192 return true;
00193 }
00194 else
00195 {
00196 return false;
00197 }
00198 }
00199
00200
00201 void Foam::Time::readModifiedObjects()
00202 {
00203 if (runTimeModifiable_)
00204 {
00205
00206
00207
00208
00209 bool anyModified = true;
00210
00211 if (Pstream::parRun())
00212 {
00213 anyModified = controlDict_.modified() || objectRegistry::modified();
00214 bool anyModifiedOnThisProc = anyModified;
00215 reduce(anyModified, andOp<bool>());
00216
00217 if (anyModifiedOnThisProc && !anyModified)
00218 {
00219 WarningIn("Time::readModifiedObjects()")
00220 << "Delaying reading objects due to inconsistent "
00221 "file time-stamps between processors"
00222 << endl;
00223 }
00224 }
00225
00226 if (anyModified)
00227 {
00228 if (controlDict_.readIfModified())
00229 {
00230 readDict();
00231 functionObjects_.read();
00232 }
00233
00234 objectRegistry::readModifiedObjects();
00235 }
00236 }
00237 }
00238
00239
00240 bool Foam::Time::writeObject
00241 (
00242 IOstream::streamFormat fmt,
00243 IOstream::versionNumber ver,
00244 IOstream::compressionType cmp
00245 ) const
00246 {
00247 if (outputTime())
00248 {
00249 IOdictionary timeDict
00250 (
00251 IOobject
00252 (
00253 "time",
00254 timeName(),
00255 "uniform",
00256 *this,
00257 IOobject::NO_READ,
00258 IOobject::NO_WRITE,
00259 false
00260 )
00261 );
00262
00263 timeDict.add("index", timeIndex_);
00264 timeDict.add("deltaT", deltaT_);
00265 timeDict.add("deltaT0", deltaT0_);
00266
00267 timeDict.regIOobject::writeObject(fmt, ver, cmp);
00268 bool writeOK = objectRegistry::writeObject(fmt, ver, cmp);
00269
00270 if (writeOK && purgeWrite_)
00271 {
00272 previousOutputTimes_.push(timeName());
00273
00274 while (previousOutputTimes_.size() > purgeWrite_)
00275 {
00276 rmDir(objectRegistry::path(previousOutputTimes_.pop()));
00277 }
00278 }
00279
00280 return writeOK;
00281 }
00282 else
00283 {
00284 return false;
00285 }
00286 }
00287
00288
00289 bool Foam::Time::writeNow()
00290 {
00291 outputTime_ = true;
00292 return write();
00293 }
00294
00295
00296 bool Foam::Time::writeAndEnd()
00297 {
00298 stopAt_ = saWriteNow;
00299 endTime_ = value();
00300
00301 return writeNow();
00302 }
00303
00304
00305
Copyright © 2000-2009 OpenCFD Ltd