Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
10License
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
26Class
27 Foam::clockValue
28
29Description
30 Access to high-resolution clock value with some basic operations.
31 Used to calculate time durations, elapsed times etc.
32
33SourceFiles
34 clockValueI.H
35 clockValue.C
36
37\*---------------------------------------------------------------------------*/
38
39#ifndef Foam_clockValue_H
40#define Foam_clockValue_H
41
42#include <chrono>
43#include <string>
44
45// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46
47namespace Foam
48{
50/*---------------------------------------------------------------------------*\
51 Class clockValue Declaration
52\*---------------------------------------------------------------------------*/
53
54class clockValue
55{
56public:
57
58 // Public Types
59
60 //- Time structure used
61 typedef std::chrono::high_resolution_clock::duration value_type;
62
63
64private:
65
66 // Private Data
67
68 //- The time start point or the time duration.
69 value_type value_;
70
71
72public:
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 const value_type& value() const noexcept { return value_; }
97
98 //- Reset to zero
99 inline void clear();
100
101 //- Update to the current now() time from the system
102 inline void update();
103
104 //- The value in seconds (rounded)
105 inline long seconds() const;
107 //- The time duration elapsed until now() since the start point
108 inline clockValue elapsed() const;
109
110 //- The time elapsed [seconds] until now() since the start point
111 inline double elapsedTime() const;
112
113 //- Format as day-hh:mm:ss string
114 std::string str() const;
115
116
117 // Operators
118
119 //- Conversion operator to seconds in floating point
120 inline operator double() const;
121
122 //- Subtract clock value
123 inline clockValue& operator-=(const clockValue& rhs);
124
125 //- Add clock value
126 inline clockValue& operator+=(const clockValue& rhs);
127};
128
129
130// Global Operators
131
132//- Subtraction of clock values
133inline clockValue operator-(const clockValue& a, const clockValue& b)
134{
135 return clockValue(a.value() - b.value());
136}
137
138//- Addition of clock values
139inline clockValue operator+(const clockValue& a, const clockValue& b)
140{
141 return clockValue(a.value() + b.value());
142}
143
144
145// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
146
147} // End namespace Foam
148
149// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150
151#include "clockValueI.H"
152
153// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154
155#endif
156
157// ************************************************************************* //
Access to high-resolution clock value with some basic operations. Used to calculate time durations,...
Definition clockValue.H:50
long seconds() const
The value in seconds (rounded).
Definition clockValueI.H:63
const value_type & value() const noexcept
The time duration.
Definition clockValue.H:106
std::chrono::high_resolution_clock::duration value_type
Time structure used.
Definition clockValue.H:58
clockValue()
Construct zero initialized.
Definition clockValueI.H:31
clockValue & operator+=(const clockValue &rhs)
Add clock value.
static clockValue now()
The current clock value from the system.
Definition clockValueI.H:23
clockValue & operator-=(const clockValue &rhs)
Subtract clock value.
Definition clockValueI.H:93
void update()
Update to the current now() time from the system.
Definition clockValueI.H:57
clockValue elapsed() const
The time duration elapsed until now() since the start point.
Definition clockValueI.H:69
void clear()
Reset to zero.
Definition clockValueI.H:51
std::string str() const
Format as day-hh:mm:ss string.
Definition clockValue.C:27
double elapsedTime() const
The time elapsed [seconds] until now() since the start point.
Definition clockValueI.H:75
Namespace for OpenFOAM.
tmp< faMatrix< Type > > operator-(const faMatrix< Type > &)
Unary negation.
tmp< faMatrix< Type > > operator+(const faMatrix< Type > &, const faMatrix< Type > &)
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
const direction noexcept
Definition scalarImpl.H:265
volScalarField & b