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-2024 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 Foam_clockTime_H
50 #define Foam_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  //- Also updated by resetTime and resetTimeIncrement.
72  mutable clockValue last_;
73 
74 
75 public:
76 
77  // Constructors
78 
79  //- Construct with the current clock value for the start point
80  inline clockTime();
81 
82  //- Implicit construct from the clock value as the start point
83  inline clockTime(const clockValue& clockval);
84 
85 
86  // Member Functions
87 
88  //- Reset to use the current clock value for the start
89  //- and increment points
90  inline void resetTime();
91 
92  //- Reset to use the current clock value for the increment point
93  inline void resetTimeIncrement() const;
94 
95  //- The time [seconds] since the start point
96  inline double elapsedTime() const;
97 
98  //- The time [seconds] since the last call to elapsedTime(),
99  //- timeIncrement() or resetTime(), resetTimeIncrement()
100  inline double timeIncrement() const;
101 };
102 
103 
104 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
105 
106 } // End namespace Foam
107 
108 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
109 
110 #include "clockTimeI.H"
111 
112 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
113 
114 #endif
115 
116 // ************************************************************************* //
double elapsedTime() const
The time [seconds] since the start point.
Definition: clockTimeI.H:52
Access to high-resolution clock value with some basic operations. Used to calculate time durations...
Definition: clockValue.H:49
void resetTime()
Reset to use the current clock value for the start and increment points.
Definition: clockTimeI.H:39
clockTime()
Construct with the current clock value for the start point.
Definition: clockTimeI.H:23
double timeIncrement() const
The time [seconds] since the last call to elapsedTime(), timeIncrement() or resetTime(), resetTimeIncrement()
Definition: clockTimeI.H:59
void resetTimeIncrement() const
Reset to use the current clock value for the increment point.
Definition: clockTimeI.H:46
Namespace for OpenFOAM.
Starts timing and returns elapsed time from start. Uses std::chrono::high_resolution_clock for better...
Definition: clockTime.H:58