OpenFOAM logo
Open Source CFD Toolkit

Time.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2005 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     Time
00027 
00028 Description
00029     Class to control time during FOAM simulations which is also the
00030     top-level objectRegistry.
00031 
00032 SourceFiles
00033     Time.C
00034     TimeIO.C
00035     findInstance.C
00036 
00037 \*---------------------------------------------------------------------------*/
00038 
00039 #ifndef Time_H
00040 #define Time_H
00041 
00042 #include "TimePaths.H"
00043 #include "objectRegistry.H"
00044 #include "IOdictionary.H"
00045 #include "FIFOStack.H"
00046 #include "clock.H"
00047 #include "cpuTime.H"
00048 #include "TimeState.H"
00049 #include "Switch.H"
00050 #include "instantList.H"
00051 #include "NamedEnum.H"
00052 #include "typeInfo.H"
00053 
00054 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00055 
00056 namespace Foam
00057 {
00058 
00059 /*---------------------------------------------------------------------------*\
00060                              Class Time Declaration
00061 \*---------------------------------------------------------------------------*/
00062 
00063 class Time
00064 :
00065     public clock,
00066     public cpuTime,
00067     public TimePaths,
00068     public objectRegistry,
00069     public TimeState
00070 {
00071     // Private data
00072 
00073         //- The controlDict
00074         IOdictionary controlDict_;
00075 
00076 
00077 public:
00078 
00079         //- Write control options
00080         enum writeControls
00081         {
00082             wcTimeStep,
00083             wcRunTime,
00084             wcAdjustableRunTime,
00085             wcClockTime,
00086             wcCpuTime
00087         };
00088 
00089         //- Stop-run control options
00090         enum stopAtControls
00091         {
00092             saEndTime,
00093             saNoWriteNow,
00094             saWriteNow,
00095             saNextWrite
00096         };
00097 
00098         //- Suported time directory name formats
00099         enum fmtflags
00100         {
00101             general = 0,
00102             fixed = ios_base::fixed,
00103             scientific = ios_base::scientific
00104         };
00105 
00106 
00107 protected:
00108 
00109     // Protected data
00110 
00111         scalar startTime_;
00112         scalar endTime_;
00113 
00114         static const NamedEnum<stopAtControls, 4> stopAtControlNames_;
00115         stopAtControls stopAt_;
00116 
00117         static const NamedEnum<writeControls, 5> writeControlNames_;
00118         writeControls writeControl_;
00119 
00120         scalar writeInterval_;
00121 
00122         label purgeWrite_;
00123         mutable FIFOStack<word> previousOutputTimes_;
00124 
00125         //- Time directory name format
00126         static fmtflags format_;
00127 
00128         //- Time directory name precision
00129         static int precision_;
00130 
00131         //- Adjust the time step so that writing occurs at the specified time
00132         void adjustDeltaT();
00133 
00134         //- Read the control dictionary and set the write controls etc.
00135         virtual void readDict();
00136 
00137 
00138 private:
00139 
00140         //- Default write option
00141         IOstream::streamFormat writeFormat_;
00142 
00143         //- Default output file format version number
00144         IOstream::versionNumber writeVersion_;
00145 
00146         //- Default output compression
00147         IOstream::compressionType writeCompression_;
00148 
00149         //- Default graph format
00150         word graphFormat_;
00151 
00152         //- Is runtim modification of dictionaries allowed
00153         Switch runTimeModifiable_;
00154 
00155 
00156 public:
00157 
00158     TypeName("time");
00159 
00160     //- Return the default control dictionary name
00161     static word controlDictName;
00162 
00163 
00164     // Constructors
00165 
00166         //- Construct given name, rootPath and casePath
00167         Time
00168         (
00169             const word& name,
00170             const fileName& rootPath,
00171             const fileName& caseName,
00172             const word& systemName = "system",
00173             const word& constantName = "constant"
00174         );
00175 
00176 
00177     // Destructor
00178 
00179         //- Virtual destructor
00180         virtual ~Time();
00181 
00182 
00183     // Member functions
00184 
00185         // Database functions
00186 
00187             //- Return root path
00188             const fileName& rootPath() const
00189             {
00190                 return TimePaths::rootPath();
00191             }
00192 
00193             //- Return case name
00194             const fileName& caseName() const
00195             {
00196                 return TimePaths::caseName();
00197             }
00198 
00199             //- Return path
00200             fileName path() const
00201             {
00202                 return rootPath()/caseName();
00203             }
00204 
00205             const dictionary& controlDict() const
00206             {
00207                 return controlDict_;
00208             }
00209 
00210             virtual const fileName& dbDir() const
00211             {
00212                 return fileName::null;
00213             }
00214 
00215             //- Return current time path
00216             fileName timePath() const
00217             {
00218                 return path()/timeName();
00219             }
00220 
00221             //- Default write format
00222             IOstream::streamFormat writeFormat() const
00223             {
00224                 return writeFormat_;
00225             }
00226 
00227             //- Default write version number
00228             IOstream::versionNumber writeVersion() const
00229             {
00230                 return writeVersion_;
00231             }
00232 
00233             //- Default write compression
00234             IOstream::compressionType writeCompression() const
00235             {
00236                 return writeCompression_;
00237             }
00238 
00239             //- Default graph format
00240             const word& graphFormat() const
00241             {
00242                 return graphFormat_;
00243             }
00244 
00245             //- Read control dictionary, update controls and time
00246             virtual bool read();
00247 
00248             //- Read the objects that have been modified
00249             void readModifiedObjects();
00250 
00251             //- Return the location of "dir" containing the file "name".
00252             //  (Used in reading mesh data)
00253             word findInstance
00254             (
00255                 const fileName& dir,
00256                 const word& name,
00257                 const IOobject::readOption rOpt = IOobject::MUST_READ
00258             ) const;
00259 
00260             //- Search tha case for valid time directories
00261             instantList times() const;
00262 
00263             //- Search the case for the time directory path
00264             //  corresponding to the given instance
00265             word findInstancePath(const instant&) const;
00266 
00267             //- Search the case for the time closest to the given time
00268             instant findClosestTime(const scalar) const;
00269 
00270             //- Write using given format, version and compression
00271             virtual bool write
00272             (
00273                 IOstream::streamFormat fmt,
00274                 IOstream::versionNumber ver,
00275                 IOstream::compressionType cmp
00276             ) const;
00277 
00278             //- Write using pre-selected format, version and compression
00279             bool write() const;
00280 
00281 
00282         // Access
00283 
00284             //- Return time name of given scalar time
00285             static word timeName(const scalar);
00286 
00287             //- Return current time name
00288             virtual word timeName() const;
00289 
00290             //- Search a given directory for valid time directories
00291             static instantList findTimes(const fileName&);
00292 
00293             //- Return start time
00294             virtual dimensionedScalar startTime() const;
00295 
00296             //- Return end time
00297             virtual dimensionedScalar endTime() const;
00298 
00299 
00300         // Check
00301 
00302             //- Return true if run should continue
00303             virtual bool run() const;
00304 
00305             //- Return true if end of run
00306             virtual bool end() const;
00307 
00308 
00309         // Edit
00310 
00311             //- Reset the time and time-index to those of the given time
00312             virtual void setTime(const Time&);
00313 
00314             //- Reset the time and time-index
00315             virtual void setTime(const instant&, const label newIndex);
00316 
00317             //- Reset the time and time-index
00318             virtual void setTime(const dimensionedScalar&,const label newIndex);
00319 
00320             //- Reset the time and time-index
00321             virtual void setTime(const scalar, const label newIndex);
00322 
00323             //- Reset end time
00324             virtual void setEndTime(const dimensionedScalar&);
00325 
00326             //- Reset end time
00327             virtual void setEndTime(const scalar);
00328 
00329             //- Reset time step
00330             virtual void setDeltaT(const dimensionedScalar&);
00331 
00332             //- Reset time step
00333             virtual void setDeltaT(const scalar);
00334 
00335             //- Set time to sub-cycle for the given number of steps
00336             virtual TimeState subCycle(const label nSubCycles);
00337 
00338             //- Reset time after sub-cycling back to given TimeState
00339             virtual void endSubCycle(const TimeState&);
00340 
00341 
00342     // Member operators
00343 
00344         //- Set deltaT to that specified and increment time
00345         virtual Time& operator+=(const dimensionedScalar&);
00346 
00347         //- Set deltaT to that specified and increment time
00348         virtual Time& operator+=(const scalar);
00349 
00350         //- Prefix increment
00351         virtual Time& operator++();
00352 
00353         //- Postfix increment
00354         virtual Time& operator++(int);
00355 };
00356 
00357 
00358 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00359 
00360 } // End namespace Foam
00361 
00362 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00363 
00364 #endif
00365 
00366 // ************************************************************************* //
For further information go to www.openfoam.org