All Classes Namespaces Files Functions Variables Typedefs Enumerator Pages
AdaptiveSimulatorTimer.hpp
1 /*
2  Copyright 2014 IRIS AS
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 #ifndef OPM_ADAPTIVESIMULATORTIMER_HEADER_INCLUDED
20 #define OPM_ADAPTIVESIMULATORTIMER_HEADER_INCLUDED
21 
22 #include <cassert>
23 #include <iostream>
24 #include <vector>
25 
26 #include <algorithm>
27 #include <numeric>
28 
29 #include <opm/simulators/timestepping/SimulatorTimerInterface.hpp>
30 
31 namespace Opm
32 {
33 
40  {
41  public:
47  const double lastStepTaken,
48  const double maxTimeStep = std::numeric_limits<double>::max() );
49 
52 
54  void advance() { this->operator++ (); }
55 
57  void provideTimeStepEstimate( const double dt_estimate );
58 
60  bool initialStep () const;
61 
63  int currentStepNum () const;
64 
66  int reportStepNum() const;
67 
69  double currentStepLength () const;
70 
72  double totalTime() const;
73 
75  double simulationTimeElapsed() const;
76 
78  bool done () const;
79 
81  double averageStepLength() const;
82 
84  double maxStepLength () const;
85 
87  double minStepLength () const;
88 
91  double stepLengthTaken () const;
92 
94  void report(std::ostream& os) const;
95 
97  boost::posix_time::ptime startDateTime() const;
98 
100  bool lastStepFailed() const {return lastStepFailed_;}
101 
103  void setLastStepFailed(bool lastStepFailed) {lastStepFailed_ = lastStepFailed;}
104 
106  virtual std::unique_ptr< SimulatorTimerInterface > clone() const;
107 
108  protected:
109  const boost::posix_time::ptime start_date_time_;
110  const double start_time_;
111  const double total_time_;
112  const int report_step_;
113  const double max_time_step_;
114 
115  double current_time_;
116  double dt_;
117  int current_step_;
118 
119  std::vector< double > steps_;
120  bool lastStepFailed_;
121 
122  };
123 
124 } // namespace Opm
125 
126 #endif // OPM_SIMULATORTIMER_HEADER_INCLUDED
Simulation timer for adaptive time stepping.
Definition: AdaptiveSimulatorTimer.hpp:39
AdaptiveSimulatorTimer & operator++()
advance time by currentStepLength
Definition: AdaptiveSimulatorTimer.cpp:59
void advance()
advance time by currentStepLength
Definition: AdaptiveSimulatorTimer.hpp:54
double maxStepLength() const
return max step length used so far
Definition: AdaptiveSimulatorTimer.cpp:132
bool lastStepFailed() const
Return true if last time step failed.
Definition: AdaptiveSimulatorTimer.hpp:100
virtual std::unique_ptr< SimulatorTimerInterface > clone() const
return copy of object
Definition: AdaptiveSimulatorTimer.cpp:164
void provideTimeStepEstimate(const double dt_estimate)
provide and estimate for new time step size
Definition: AdaptiveSimulatorTimer.cpp:69
double totalTime() const
Definition: AdaptiveSimulatorTimer.cpp:116
int currentStepNum() const
Definition: AdaptiveSimulatorTimer.cpp:98
int reportStepNum() const
return current report step
Definition: AdaptiveSimulatorTimer.cpp:101
double simulationTimeElapsed() const
Definition: AdaptiveSimulatorTimer.cpp:118
void setLastStepFailed(bool lastStepFailed)
tell the timestepper whether timestep failed or not
Definition: AdaptiveSimulatorTimer.hpp:103
void report(std::ostream &os) const
report start and end time as well as used steps so far
Definition: AdaptiveSimulatorTimer.cpp:147
double currentStepLength() const
Definition: AdaptiveSimulatorTimer.cpp:103
bool done() const
Definition: AdaptiveSimulatorTimer.cpp:120
bool initialStep() const
Whether this is the first step.
Definition: AdaptiveSimulatorTimer.cpp:54
double averageStepLength() const
return average step length used so far
Definition: AdaptiveSimulatorTimer.cpp:122
double minStepLength() const
return min step length used so far
Definition: AdaptiveSimulatorTimer.cpp:139
Interface class for SimulatorTimer objects, to be improved.
Definition: SimulatorTimerInterface.hpp:35
AdaptiveSimulatorTimer(const SimulatorTimerInterface &timer, const double lastStepTaken, const double maxTimeStep=std::numeric_limits< double >::max())
constructor taking a simulator timer to determine start and end time
Definition: AdaptiveSimulatorTimer.cpp:33
boost::posix_time::ptime startDateTime() const
start date time of simulation
Definition: AdaptiveSimulatorTimer.cpp:157
double stepLengthTaken() const
Previous step length.
Definition: AdaptiveSimulatorTimer.cpp:108