OpenFOAM logo
The Open Source CFD Toolbox
  Programmer’s C++ Doxygen OpenCFD Solutions Contact OpenFOAM

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-2007 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 #include "dlLibraryTable.H"
00054 #include "functionObjectList.H"
00055 
00056 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00057 
00058 namespace Foam
00059 {
00060 
00061 /*---------------------------------------------------------------------------*\
00062                              Class Time Declaration
00063 \*---------------------------------------------------------------------------*/
00064 
00065 class Time
00066 :
00067     public clock,
00068     public cpuTime,
00069     public TimePaths,
00070     public objectRegistry,
00071     public TimeState
00072 {
00073     // Private data
00074 
00075         //- The controlDict
00076         IOdictionary controlDict_;
00077 
00078 public:
00079 
00080         //- Write control options
00081         enum writeControls
00082         {
00083             wcTimeStep,
00084             wcRunTime,
00085             wcAdjustableRunTime,
00086             wcClockTime,
00087             wcCpuTime
00088         };
00089 
00090         //- Stop-run control options
00091         enum stopAtControls
00092         {
00093             saEndTime,
00094             saNoWriteNow,
00095             saWriteNow,
00096             saNextWrite
00097         };
00098 
00099         //- Suported time directory name formats
00100         enum fmtflags
00101         {
00102             general = 0,
00103             fixed = ios_base::fixed,
00104             scientific = ios_base::scientific
00105         };
00106 
00107 
00108 protected:
00109 
00110     // Protected data
00111 
00112         label startTimeIndex_;
00113         scalar startTime_;
00114         scalar endTime_;
00115 
00116         static const NamedEnum<stopAtControls, 4> stopAtControlNames_;
00117         stopAtControls stopAt_;
00118 
00119         static const NamedEnum<writeControls, 5> writeControlNames_;
00120         writeControls writeControl_;
00121 
00122         scalar writeInterval_;
00123 
00124         label purgeWrite_;
00125         mutable FIFOStack<word> previousOutputTimes_;
00126 
00127         //- Time directory name format
00128         static fmtflags format_;
00129 
00130         //- Time directory name precision
00131         static int precision_;
00132 
00133         //- Adjust the time step so that writing occurs at the specified time
00134         void adjustDeltaT();
00135 
00136         //- Set the controls from the current controlDict
00137         void setControls();
00138 
00139         //- Read the control dictionary and set the write controls etc.
00140         virtual void readDict();
00141 
00142 
00143 private:
00144 
00145         //- Default write option
00146         IOstream::streamFormat writeFormat_;
00147 
00148         //- Default output file format version number
00149         IOstream::versionNumber writeVersion_;
00150 
00151         //- Default output compression
00152         IOstream::compressionType writeCompression_;
00153 
00154         //- Default graph format
00155         word graphFormat_;
00156 
00157         //- Is runtim modification of dictionaries allowed
00158         Switch runTimeModifiable_;
00159 
00160         //- Instantiate a dummy class to cause the reading of dynamic libraries
00161         dlLibraryTable::readDlLibrary readLibs_;
00162 
00163         //- Function objects executed at start and on ++, +=
00164         functionObjectList functionObjects_;
00165 
00166 
00167 public:
00168 
00169     TypeName("time");
00170 
00171     //- Return the default control dictionary name
00172     static word controlDictName;
00173 
00174 
00175     // Constructors
00176 
00177         //- Construct given name, rootPath and casePath
00178         Time
00179         (
00180             const word& name,
00181             const fileName& rootPath,
00182             const fileName& caseName,
00183             const word& systemName = "system",
00184             const word& constantName = "constant"
00185         );
00186 
00187         //- Construct given dictionary, rootPath and casePath
00188         Time
00189         (
00190             const dictionary& dict,
00191             const fileName& rootPath,
00192             const fileName& caseName,
00193             const word& systemName = "system",
00194             const word& constantName = "constant"
00195         );
00196 
00197         //- Construct given endTime, rootPath and casePath
00198         Time
00199         (
00200             const fileName& rootPath,
00201             const fileName& caseName,
00202             const word& systemName = "system",
00203             const word& constantName = "constant"
00204         );
00205 
00206 
00207     // Destructor
00208 
00209         //- Virtual destructor
00210         virtual ~Time();
00211 
00212 
00213     // Member functions
00214 
00215         // Database functions
00216 
00217             //- Return root path
00218             const fileName& rootPath() const
00219             {
00220                 return TimePaths::rootPath();
00221             }
00222 
00223             //- Return case name
00224             const fileName& caseName() const
00225             {
00226                 return TimePaths::caseName();
00227             }
00228 
00229             //- Return path
00230             fileName path() const
00231             {
00232                 return rootPath()/caseName();
00233             }
00234 
00235             const dictionary& controlDict() const
00236             {
00237                 return controlDict_;
00238             }
00239 
00240             virtual const fileName& dbDir() const
00241             {
00242                 return fileName::null;
00243             }
00244 
00245             //- Return current time path
00246             fileName timePath() const
00247             {
00248                 return path()/timeName();
00249             }
00250 
00251             //- Default write format
00252             IOstream::streamFormat writeFormat() const
00253             {
00254                 return writeFormat_;
00255             }
00256 
00257             //- Default write version number
00258             IOstream::versionNumber writeVersion() const
00259             {
00260                 return writeVersion_;
00261             }
00262 
00263             //- Default write compression
00264             IOstream::compressionType writeCompression() const
00265             {
00266                 return writeCompression_;
00267             }
00268 
00269             //- Default graph format
00270             const word& graphFormat() const
00271             {
00272                 return graphFormat_;
00273             }
00274 
00275             //- Read control dictionary, update controls and time
00276             virtual bool read();
00277 
00278             //- Read the objects that have been modified
00279             void readModifiedObjects();
00280 
00281             //- Return the location of "dir" containing the file "name".
00282             //  (Used in reading mesh data)
00283             word findInstance
00284             (
00285                 const fileName& dir,
00286                 const word& name,
00287                 const IOobject::readOption rOpt = IOobject::MUST_READ
00288             ) const;
00289 
00290             //- Search tha case for valid time directories
00291             instantList times() const;
00292 
00293             //- Search the case for the time directory path
00294             //  corresponding to the given instance
00295             word findInstancePath(const instant&) const;
00296 
00297             //- Search the case for the time closest to the given time
00298             instant findClosestTime(const scalar) const;
00299 
00300             //- Write using given format, version and compression
00301             virtual bool writeObject
00302             (
00303                 IOstream::streamFormat fmt,
00304                 IOstream::versionNumber ver,
00305                 IOstream::compressionType cmp
00306             ) const;
00307 
00308             //- Write the objects now and continue the run
00309             bool writeNow();
00310 
00311             //- Write the objects now and end the run
00312             bool writeAndEnd();
00313 
00314 
00315         // Access
00316 
00317             //- Return time name of given scalar time
00318             static word timeName(const scalar);
00319 
00320             //- Return current time name
00321             virtual word timeName() const;
00322 
00323             //- Search a given directory for valid time directories
00324             static instantList findTimes(const fileName&);
00325 
00326             //- Return start time index
00327             virtual label startTimeIndex() const;
00328 
00329             //- Return start time
00330             virtual dimensionedScalar startTime() const;
00331 
00332             //- Return end time
00333             virtual dimensionedScalar endTime() const;
00334 
00335             //- Return the list of function objects
00336             const functionObjectList& functionObjects() const
00337             {
00338                 return functionObjects_;
00339             }
00340 
00341 
00342         // Check
00343 
00344             //- Return true if run should continue
00345             virtual bool run() const;
00346 
00347             //- Return true if end of run
00348             virtual bool end() const;
00349 
00350 
00351         // Edit
00352 
00353             //- Reset the time and time-index to those of the given time
00354             virtual void setTime(const Time&);
00355 
00356             //- Reset the time and time-index
00357             virtual void setTime(const instant&, const label newIndex);
00358 
00359             //- Reset the time and time-index
00360             virtual void setTime
00361             (
00362                 const dimensionedScalar&,
00363                 const label newIndex
00364             );
00365 
00366             //- Reset the time and time-index
00367             virtual void setTime(const scalar, const label newIndex);
00368 
00369             //- Reset end time
00370             virtual void setEndTime(const dimensionedScalar&);
00371 
00372             //- Reset end time
00373             virtual void setEndTime(const scalar);
00374 
00375             //- Reset time step
00376             virtual void setDeltaT(const dimensionedScalar&);
00377 
00378             //- Reset time step
00379             virtual void setDeltaT(const scalar);
00380 
00381             //- Set time to sub-cycle for the given number of steps
00382             virtual TimeState subCycle(const label nSubCycles);
00383 
00384             //- Reset time after sub-cycling back to given TimeState
00385             virtual void endSubCycle(const TimeState&);
00386 
00387             //- Return non-const access to the list of function objects
00388             functionObjectList& functionObjects()
00389             {
00390                 return functionObjects_;
00391             }
00392 
00393 
00394     // Member operators
00395 
00396         //- Set deltaT to that specified and increment time
00397         virtual Time& operator+=(const dimensionedScalar&);
00398 
00399         //- Set deltaT to that specified and increment time
00400         virtual Time& operator+=(const scalar);
00401 
00402         //- Prefix increment
00403         virtual Time& operator++();
00404 
00405         //- Postfix increment
00406         virtual Time& operator++(int);
00407 };
00408 
00409 
00410 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00411 
00412 } // End namespace Foam
00413 
00414 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00415 
00416 #endif
00417 
00418 // ************************************************************************* //
Copyright © 2000-2007 OpenCFD Ltd