opm-simulators
SimulatorTimer.hpp
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 
23 #include <opm/simulators/timestepping/SimulatorTimerInterface.hpp>
24 
25 #include <boost/date_time/gregorian/gregorian_types.hpp>
26 
27 #include <cstddef>
28 #include <iosfwd>
29 #include <memory>
30 #include <vector>
31 
32 namespace Opm
33 {
34 
35  class ParameterGroup;
36  class Schedule;
37 
39  {
40  public:
41  // use default implementation of these methods
44 
47 
48  static SimulatorTimer serializationTestObject();
49 
53  void init(const ParameterGroup& param);
54 
56  void init(const Schedule& schedule, std::size_t report_step = 0);
57 
59  bool initialStep() const override;
60 
62  int numSteps() const;
63 
68  int currentStepNum() const override;
69 
71  void setCurrentStepNum(int step);
72 
77  double currentStepLength() const override;
78 
85  double stepLengthTaken () const override;
86 
89  double simulationTimeElapsed() const override;
90 
92  double totalTime() const;
93 
95  boost::posix_time::ptime startDateTime() const override;
96 
101  void setTotalTime(double time);
102 
105  void report(std::ostream& os) const;
106 
109 
111  void advance() override { this->operator++(); }
112 
114  bool done() const override;
115 
118  bool lastStepFailed() const override { return false; }
119 
121  std::unique_ptr<SimulatorTimerInterface> clone() const override;
122 
123  template<class Serializer>
124  void serializeOp(Serializer& serializer)
125  {
126  serializer(timesteps_);
127  serializer(current_step_);
128  serializer(current_time_);
129  serializer(total_time_);
130  serializer(start_date_);
131  }
132 
133  bool operator==(const SimulatorTimer& rhs) const;
134 
135  private:
136  std::vector<double> timesteps_;
137  int current_step_;
138  double current_time_;
139  double total_time_;
140  boost::gregorian::date start_date_;
141  };
142 
143 
144 } // namespace Opm
145 
146 #endif // OPM_SIMULATORTIMER_HEADER_INCLUDED
double simulationTimeElapsed() const override
Time elapsed since the start of the simulation until the beginning of the current time step [s]...
Definition: SimulatorTimer.cpp:122
int numSteps() const
Total number of steps.
Definition: SimulatorTimer.cpp:89
double totalTime() const
Total time.
Definition: SimulatorTimer.cpp:134
void report(std::ostream &os) const
Print a report with current and total time etc.
Definition: SimulatorTimer.cpp:149
void advance() override
advance time by currentStepLength
Definition: SimulatorTimer.hpp:111
SimulatorTimer & operator++()
advance time by currentStepLength
Definition: SimulatorTimer.cpp:159
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
void init(const ParameterGroup &param)
Initialize from parameters.
Definition: SimulatorTimer.cpp:59
virtual time_t currentPosixTime() const
Time elapsed since the start of the POSIX epoch (Jan 1st, 1970) until the current time step begins [s...
Definition: SimulatorTimerInterface.cpp:37
double currentStepLength() const override
Current step length.
Definition: SimulatorTimer.cpp:109
void setTotalTime(double time)
Set total time.
Definition: SimulatorTimer.cpp:143
void setCurrentStepNum(int step)
Set current step number.
Definition: SimulatorTimer.cpp:101
int currentStepNum() const override
Current step number.
Definition: SimulatorTimer.cpp:95
bool done() const override
Return true if op++() has been called numSteps() times.
Definition: SimulatorTimer.cpp:168
double stepLengthTaken() const override
Previous step length.
Definition: SimulatorTimer.cpp:115
Interface class for SimulatorTimer objects, to be improved.
Definition: SimulatorTimerInterface.hpp:33
bool lastStepFailed() const override
Always return false.
Definition: SimulatorTimer.hpp:118
bool initialStep() const override
Whether the current step is the first step.
Definition: SimulatorTimer.cpp:83
Definition: SimulatorTimer.hpp:38
boost::posix_time::ptime startDateTime() const override
Return start date of simulation.
Definition: SimulatorTimer.cpp:127
SimulatorTimer()
Default constructor.
Definition: SimulatorTimer.cpp:37
std::unique_ptr< SimulatorTimerInterface > clone() const override
return copy of object
Definition: SimulatorTimer.cpp:175
virtual boost::posix_time::ptime currentDateTime() const
Return the current time as a posix time object.
Definition: SimulatorTimerInterface.cpp:28