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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011 OpenFOAM Foundation
9  Copyright (C) 2018-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::clockTime
29 
30 Description
31  Starts timing and returns elapsed time from start.
32  Uses std::chrono::high_resolution_clock for better resolution
33  (2uSec instead of ~20mSec) than cpuTime.
34 
35 Note
36  It has twice the storage requirement of a simple clockValue since
37  it tracks both total and incremental elapsed times.
38  Additionally, it always invokes a clock query on construction
39  which may make it less desirable for arrays of values (for example).
40 
41 See Also
42  Foam::clockValue
43 
44 SourceFiles
45  clockTimeI.H
46 
47 \*---------------------------------------------------------------------------*/
48 
49 #ifndef clockTime_H
50 #define clockTime_H
51 
52 #include "clockValue.H"
53 
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 
56 namespace Foam
57 {
58 
59 /*---------------------------------------------------------------------------*\
60  Class clockTime Declaration
61 \*---------------------------------------------------------------------------*/
62 
63 class clockTime
64 {
65  // Private Data
66 
67  //- Time point at start, or after resetTime
68  clockValue start_;
69 
70  //- Time point when elapsedTime or timeIncrement was called
71  mutable clockValue last_;
72 
73 
74 public:
75 
76  // Constructors
77 
78  //- Construct with the current clock value for the start point
79  inline clockTime();
80 
81  //- Implicit construct from the clock value as the start point
82  inline clockTime(const clockValue& clockval);
83 
84 
85  // Member Functions
86 
87  //- Reset to use the current clock value for the start point
88  inline void resetTime();
89 
90  //- The time [seconds] since the start point
91  inline double elapsedTime() const;
92 
93  //- The time [seconds] since the last call to timeIncrement()
94  inline double timeIncrement() const;
95 };
96 
97 
98 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
99 
100 } // End namespace Foam
101 
102 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
103 
104 #include "clockTimeI.H"
105 
106 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
107 
108 #endif
109 
110 // ************************************************************************* //
Foam::clockTime::timeIncrement
double timeIncrement() const
The time [seconds] since the last call to timeIncrement()
Definition: clockTimeI.H:60
Foam::clockTime::elapsedTime
double elapsedTime() const
The time [seconds] since the start point.
Definition: clockTimeI.H:53
clockTimeI.H
clockValue.H
Foam::clockValue
Access to high-resolution clock value with some basic operations. Used to calculate time durations,...
Definition: clockValue.H:53
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::clockTime::resetTime
void resetTime()
Reset to use the current clock value for the start point.
Definition: clockTimeI.H:46
Foam::clockTime::clockTime
clockTime()
Construct with the current clock value for the start point.
Definition: clockTimeI.H:30
Foam::clockTime
Starts timing and returns elapsed time from start. Uses std::chrono::high_resolution_clock for better...
Definition: clockTime.H:62