clockValueI.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) 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 \*---------------------------------------------------------------------------*/
27 
28 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
29 
31 {
32  return clockValue(true);
33 }
34 
35 
36 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37 
39 :
40  value_(value_type::zero())
41 {}
42 
43 
45 :
46  value_(std::chrono::high_resolution_clock::now().time_since_epoch())
47 {}
48 
49 
51 :
52  value_(value)
53 {}
54 
55 
56 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
57 
59 {
60  value_ = value_type::zero();
61 }
62 
63 
65 {
66  value_ = std::chrono::high_resolution_clock::now().time_since_epoch();
67 }
68 
69 
70 inline long Foam::clockValue::seconds() const
71 {
72  return std::chrono::duration_cast<std::chrono::seconds>(value_).count();
73 }
74 
75 
77 {
78  return (clockValue::now() -= *this);
79 }
80 
81 
82 inline double Foam::clockValue::elapsedTime() const
83 {
84  return static_cast<double>(this->elapsed());
85 }
86 
87 
88 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
89 
90 inline Foam::clockValue::operator double() const
91 {
92  return
93  (
94  (double(value_.count()) * value_type::period::num)
95  / value_type::period::den
96  );
97 }
98 
99 
101 {
102  value_ -= rhs.value_;
103  return *this;
104 }
105 
106 
108 {
109  value_ += rhs.value_;
110  return *this;
111 }
112 
113 
114 // ************************************************************************* //
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
Foam::clockValue::operator-=
clockValue & operator-=(const clockValue &rhs)
Subtract clock value.
Definition: clockValueI.H:100
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::update
void update()
Update to the current now() time from the system.
Definition: clockValueI.H:64
Foam::clockValue
Access to high-resolution clock value with some basic operations. Used to calculate time durations,...
Definition: clockValue.H:53
Foam::clockValue::clear
void clear()
Reset to zero.
Definition: clockValueI.H:58
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
Foam::zero
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:62