AdaptiveSimulatorTimer.hpp
Go to the documentation of this file.
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 <iosfwd>
24#include <vector>
25#include <limits>
26#include <algorithm>
27#include <memory>
28#include <numeric>
29
31
32namespace Opm
33{
34
41 {
42 public:
48 const double lastStepTaken,
49 const double maxTimeStep = std::numeric_limits<double>::max() );
50
53
55 void advance() { this->operator++ (); }
56
58 void provideTimeStepEstimate( const double dt_estimate );
59
61 bool initialStep () const;
62
64 int currentStepNum () const;
65
67 int reportStepNum() const;
68
70 double currentStepLength () const;
71
72 // \brief Set next step length
73 void setCurrentStepLength(double dt);
74
76 double totalTime() const;
77
79 double simulationTimeElapsed() const;
80
82 bool done () const;
83
85 double averageStepLength() const;
86
88 double maxStepLength () const;
89
91 double minStepLength () const;
92
95 double stepLengthTaken () const;
96
98 void report(std::ostream& os) const;
99
101 boost::posix_time::ptime startDateTime() const;
102
104 bool lastStepFailed() const {return lastStepFailed_;}
105
108
110 virtual std::unique_ptr< SimulatorTimerInterface > clone() const;
111
112 protected:
113 std::shared_ptr<boost::posix_time::ptime> start_date_time_;
114 const double start_time_;
115 const double total_time_;
116 const int report_step_;
117 const double max_time_step_;
118
120 double dt_;
122
123 std::vector< double > steps_;
125
126 };
127
128} // namespace Opm
129
130#endif // OPM_SIMULATORTIMER_HEADER_INCLUDED
Simulation timer for adaptive time stepping.
Definition: AdaptiveSimulatorTimer.hpp:41
const double start_time_
Definition: AdaptiveSimulatorTimer.hpp:114
boost::posix_time::ptime startDateTime() const
start date time of simulation
int current_step_
Definition: AdaptiveSimulatorTimer.hpp:121
bool lastStepFailed_
Definition: AdaptiveSimulatorTimer.hpp:124
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
double currentStepLength() const
std::vector< double > steps_
Definition: AdaptiveSimulatorTimer.hpp:123
const int report_step_
Definition: AdaptiveSimulatorTimer.hpp:116
int reportStepNum() const
return current report step
double minStepLength() const
return min step length used so far
void provideTimeStepEstimate(const double dt_estimate)
provide and estimate for new time step size
double current_time_
Definition: AdaptiveSimulatorTimer.hpp:119
virtual std::unique_ptr< SimulatorTimerInterface > clone() const
return copy of object
void report(std::ostream &os) const
report start and end time as well as used steps so far
const double total_time_
Definition: AdaptiveSimulatorTimer.hpp:115
double stepLengthTaken() const
Previous step length. This is the length of the step that was taken to arrive at this time.
std::shared_ptr< boost::posix_time::ptime > start_date_time_
Definition: AdaptiveSimulatorTimer.hpp:113
void advance()
advance time by currentStepLength
Definition: AdaptiveSimulatorTimer.hpp:55
double simulationTimeElapsed() const
void setCurrentStepLength(double dt)
bool lastStepFailed() const
Return true if last time step failed.
Definition: AdaptiveSimulatorTimer.hpp:104
double averageStepLength() const
return average step length used so far
const double max_time_step_
Definition: AdaptiveSimulatorTimer.hpp:117
double maxStepLength() const
return max step length used so far
bool initialStep() const
Whether this is the first step.
AdaptiveSimulatorTimer & operator++()
advance time by currentStepLength
void setLastStepFailed(bool lastStepFailed)
tell the timestepper whether timestep failed or not
Definition: AdaptiveSimulatorTimer.hpp:107
double dt_
Definition: AdaptiveSimulatorTimer.hpp:120
Interface class for SimulatorTimer objects, to be improved.
Definition: SimulatorTimerInterface.hpp:34
Definition: BlackoilPhases.hpp:27