SimulatorTimer.hpp
Go to the documentation of this file.
1/*
2 Copyright 2012 SINTEF ICT, Applied Mathematics.
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef OPM_SIMULATORTIMER_HEADER_INCLUDED
21#define OPM_SIMULATORTIMER_HEADER_INCLUDED
22
24
25#include <boost/date_time/gregorian/gregorian_types.hpp>
26
27#include <cstddef>
28#include <iosfwd>
29#include <memory>
30#include <vector>
31
32namespace Opm
33{
34
35 class Schedule;
36
38 {
39 public:
40 // use default implementation of these methods
43
46
48
52 void init(const Schedule& schedule,
53 std::size_t report_step = 0,
54 int end_step = -1);
55
57 bool initialStep() const override;
58
60 int numSteps() const;
61
66 int currentStepNum() const override;
67
69 void setCurrentStepNum(int step);
70
75 double currentStepLength() const override;
76
83 double stepLengthTaken () const override;
84
87 double simulationTimeElapsed() const override;
88
90 double totalTime() const;
91
93 boost::posix_time::ptime startDateTime() const override;
94
99 void setTotalTime(double time);
100
103 void report(std::ostream& os) const;
104
107
109 void advance() override { this->operator++(); }
110
112 bool done() const override;
113
116 bool lastStepFailed() const override { return false; }
117
119 std::unique_ptr<SimulatorTimerInterface> clone() const override;
120
121 template<class Serializer>
122 void serializeOp(Serializer& serializer)
123 {
124 serializer(timesteps_);
125 serializer(current_step_);
126 serializer(current_time_);
127 serializer(total_time_);
128 serializer(end_step_);
129 serializer(start_date_);
130 }
131
132 bool operator==(const SimulatorTimer& rhs) const;
133
134 private:
135 std::vector<double> timesteps_;
136 int current_step_;
137 double current_time_;
138 double total_time_;
139 int end_step_{-1};
140 boost::gregorian::date start_date_;
141 };
142
143
144} // namespace Opm
145
146#endif // OPM_SIMULATORTIMER_HEADER_INCLUDED
Interface class for SimulatorTimer objects, to be improved.
Definition: SimulatorTimerInterface.hpp:34
virtual time_t currentPosixTime() const
virtual boost::posix_time::ptime currentDateTime() const
Return the current time as a posix time object.
Definition: SimulatorTimer.hpp:38
void setTotalTime(double time)
double totalTime() const
Total time.
bool lastStepFailed() const override
Definition: SimulatorTimer.hpp:116
static SimulatorTimer serializationTestObject()
boost::posix_time::ptime startDateTime() const override
Return start date of simulation.
int numSteps() const
Total number of steps.
void serializeOp(Serializer &serializer)
Definition: SimulatorTimer.hpp:122
double currentStepLength() const override
bool initialStep() const override
Whether the current step is the first step.
void advance() override
advance time by currentStepLength
Definition: SimulatorTimer.hpp:109
std::unique_ptr< SimulatorTimerInterface > clone() const override
return copy of object
void setCurrentStepNum(int step)
Set current step number.
void report(std::ostream &os) const
double simulationTimeElapsed() const override
int currentStepNum() const override
double stepLengthTaken() const override
void init(const Schedule &schedule, std::size_t report_step=0, int end_step=-1)
SimulatorTimer()
Default constructor.
SimulatorTimer & operator++()
advance time by currentStepLength
bool done() const override
Return true if op++() has been called numSteps() times.
bool operator==(const SimulatorTimer &rhs) const
Definition: blackoilbioeffectsmodules.hh:45