clockValue.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) 2018-2020 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::clockValue
28 
29 Description
30  Access to high-resolution clock value with some basic operations.
31  Used to calculate time durations, elapsed times etc.
32 
33 SourceFiles
34  clockValueI.H
35  clockValue.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef clockValue_H
40 #define clockValue_H
41 
42 #include <chrono>
43 #include <string>
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class clockValue Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 class clockValue
55 {
56 public:
57 
58  // Public Types
59 
60  //- Time structure used
61  typedef std::chrono::high_resolution_clock::duration value_type;
62 
63 
64 private:
65 
66  // Private Data
67 
68  //- The time start point or the time duration.
69  value_type value_;
70 
71 
72 public:
73 
74  // Constructors
75 
76  //- Construct zero initialized
77  inline clockValue();
78 
79  //- Construct with current time.
80  // The bool is for tagged dispatch only (its value is ignored).
81  inline explicit clockValue(bool);
82 
83  //- Copy construct from duration with the same clock base
84  inline explicit clockValue(const value_type& value);
85 
86 
87  // Factory Methods
88 
89  //- The current clock value from the system
90  inline static clockValue now();
91 
92 
93  // Member Functions
94 
95  //- The time duration
96  inline const value_type& value() const
97  {
98  return value_;
99  }
100 
101  //- Reset to zero
102  inline void clear();
103 
104  //- Update to the current now() time from the system
105  inline void update();
106 
107  //- The value in seconds (rounded)
108  inline long seconds() const;
109 
110  //- The time duration elapsed until now() since the start point
111  inline clockValue elapsed() const;
112 
113  //- The time elapsed [seconds] until now() since the start point
114  inline double elapsedTime() const;
115 
116  //- Format as day-hh:mm:ss string
117  std::string str() const;
118 
119 
120  // Operators
121 
122  //- Conversion operator to seconds in floating point
123  inline operator double() const;
124 
125  //- Subtract clock value
126  inline clockValue& operator-=(const clockValue& rhs);
127 
128  //- Add clock value
129  inline clockValue& operator+=(const clockValue& rhs);
130 };
131 
132 
133 // Global Operators
134 
135 //- Subtraction of clock values
136 inline clockValue operator-(const clockValue& a, const clockValue& b)
137 {
138  return clockValue(a.value() - b.value());
139 }
140 
141 //- Addition of clock values
142 inline clockValue operator+(const clockValue& a, const clockValue& b)
143 {
144  return clockValue(a.value() + b.value());
145 }
146 
147 
148 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149 
150 } // End namespace Foam
151 
152 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
153 
154 #include "clockValueI.H"
155 
156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
157 
158 #endif
159 
160 // ************************************************************************* //
Foam::clockValue::seconds
long seconds() const
The value in seconds (rounded)
Definition: clockValueI.H:70
Foam::clockValue::elapsedTime
double elapsedTime() const
The time elapsed [seconds] until now() since the start point.
Definition: clockValueI.H:82
clockValueI.H
Foam::operator-
tmp< faMatrix< Type > > operator-(const faMatrix< Type > &)
Foam::clockValue::operator-=
clockValue & operator-=(const clockValue &rhs)
Subtract clock value.
Definition: clockValueI.H:100
Foam::dimensioned::value
const Type & value() const
Return const reference to value.
Definition: dimensionedType.C:434
Foam::clockValue::elapsed
clockValue elapsed() const
The time duration elapsed until now() since the start point.
Definition: clockValueI.H:76
Foam::clockValue::clockValue
clockValue()
Construct zero initialized.
Definition: clockValueI.H:38
Foam::clockValue::value
const value_type & value() const
The time duration.
Definition: clockValue.H:95
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
Foam::clockValue::update
void update()
Update to the current now() time from the system.
Definition: clockValueI.H:64
Foam::clockValue::str
std::string str() const
Format as day-hh:mm:ss string.
Definition: clockValue.C:34
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::clockValue::clear
void clear()
Reset to zero.
Definition: clockValueI.H:58
Foam::operator+
tmp< faMatrix< Type > > operator+(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::clockValue::operator+=
clockValue & operator+=(const clockValue &rhs)
Add clock value.
Definition: clockValueI.H:107
Foam::clockValue::now
static clockValue now()
The current clock value from the system.
Definition: clockValueI.H:30
Foam::clockValue::value_type
std::chrono::high_resolution_clock::duration value_type
Time structure used.
Definition: clockValue.H:60