clockTime.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 Class
25  Foam::clockTime
26 
27 Description
28  Starts timing (using rtc) and returns elapsed time from start.
29  Better resolution (2uSec instead of ~20mSec) than cpuTime.
30 
31 SourceFiles
32  clockTime.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef clockTime_H
37 #define clockTime_H
38 
39 #include <sys/types.h>
40 
41 #ifdef DARWIN
42 #include <sys/time.h>
43 #endif
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class clockTime Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 class clockTime
55 {
56  // Private data
57 
58  //- Time structure used
59  typedef struct timeval timeType;
60 
62 
64  mutable timeType newTime_;
65 
66  // Private Member Functions
67 
68  //- Retrieve the current time values from the system
69  static void getTime(timeType&);
70 
71  //- Difference between two times
72  static double timeDifference(const timeType& beg, const timeType& end);
73 
74 
75 public:
76 
77  // Constructors
78 
79  //- Construct with the current clock time
80  clockTime();
81 
82 
83  // Member Functions
84 
85  //- Return time (in seconds) from the start
86  double elapsedTime() const;
87 
88  //- Return time (in seconds) since last call to timeIncrement()
89  double timeIncrement() const;
90 };
91 
92 
93 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
94 
95 } // End namespace Foam
96 
97 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
98 
99 #endif
100 
101 // ************************************************************************* //
Foam::clockTime::getTime
static void getTime(timeType &)
Retrieve the current time values from the system.
Definition: clockTime.C:31
Foam::clockTime::timeIncrement
double timeIncrement() const
Return time (in seconds) since last call to timeIncrement()
Definition: clockTime.C:62
Foam::clockTime::elapsedTime
double elapsedTime() const
Return time (in seconds) from the start.
Definition: clockTime.C:55
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::clockTime::clockTime
clockTime()
Construct with the current clock time.
Definition: clockTime.C:45
Foam::clockTime::newTime_
timeType newTime_
Definition: clockTime.H:63
Foam::clockTime::lastTime_
timeType lastTime_
Definition: clockTime.H:62
Foam::clockTime::timeType
struct timeval timeType
Time structure used.
Definition: clockTime.H:58
Foam::clockTime::timeDifference
static double timeDifference(const timeType &beg, const timeType &end)
Difference between two times.
Definition: clockTime.C:37
Foam::clockTime
Starts timing (using rtc) and returns elapsed time from start. Better resolution (2uSec instead of ~2...
Definition: clockTime.H:53
Foam::clockTime::startTime_
timeType startTime_
Definition: clockTime.H:60