opm-simulators
Loading...
Searching...
No Matches
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 <iosfwd>
24#include <vector>
25#include <limits>
26#include <algorithm>
27#include <memory>
28#include <numeric>
29
30#include <opm/simulators/timestepping/SimulatorTimerInterface.hpp>
31
32namespace Opm
33{
34
41 {
42 public:
50 AdaptiveSimulatorTimer(const boost::posix_time::ptime simulation_start_time,
51 const double step_length,
52 const double elapsed_time,
53 const double last_step_taken,
54 const int report_step,
55 const double max_time_step = std::numeric_limits<double>::max());
56
59
61 void advance() override { this->operator++ (); }
62
64 void provideTimeStepEstimate( const double dt_estimate );
65
67 bool initialStep () const override;
68
70 int currentStepNum () const override;
71
73 int reportStepNum() const override;
74
76 double currentStepLength () const override;
77
78 // \brief Set next step length
79 void setCurrentStepLength(double dt);
80
82 double totalTime() const;
83
85 double simulationTimeElapsed() const override;
86
88 bool done () const override;
89
91 double averageStepLength() const;
92
94 double maxStepLength () const;
95
97 double minStepLength () const;
98
101 double stepLengthTaken () const override;
102
104 void report(std::ostream& os) const;
105
107 boost::posix_time::ptime startDateTime() const override;
108
110 bool lastStepFailed() const override { return last_step_failed_; }
111
113 void setLastStepFailed(bool last_step_failed) { last_step_failed_ = last_step_failed; }
114
116 std::unique_ptr<SimulatorTimerInterface> clone() const override;
117
118 protected:
119 std::shared_ptr<boost::posix_time::ptime> start_date_time_;
120 const double start_time_;
121 const double total_time_;
122 const int report_step_;
123 const double max_time_step_;
124
125 double current_time_;
126 double dt_;
127 int current_step_;
128
129 std::vector< double > steps_;
130 bool last_step_failed_;
131
132 };
133
134} // namespace Opm
135
136#endif // OPM_SIMULATORTIMER_HEADER_INCLUDED
void advance() override
advance time by currentStepLength
Definition AdaptiveSimulatorTimer.hpp:61
double stepLengthTaken() const override
Previous step length.
Definition AdaptiveSimulatorTimer.cpp:127
double minStepLength() const
return min step length used so far
Definition AdaptiveSimulatorTimer.cpp:158
std::unique_ptr< SimulatorTimerInterface > clone() const override
return copy of object
Definition AdaptiveSimulatorTimer.cpp:183
bool lastStepFailed() const override
Return true if last time step failed.
Definition AdaptiveSimulatorTimer.hpp:110
bool initialStep() const override
Whether this is the first step.
Definition AdaptiveSimulatorTimer.cpp:63
void provideTimeStepEstimate(const double dt_estimate)
provide and estimate for new time step size
Definition AdaptiveSimulatorTimer.cpp:79
boost::posix_time::ptime startDateTime() const override
start date time of simulation
Definition AdaptiveSimulatorTimer.cpp:176
void report(std::ostream &os) const
report start and end time as well as used steps so far
Definition AdaptiveSimulatorTimer.cpp:166
void setLastStepFailed(bool last_step_failed)
tell the timestepper whether timestep failed or not
Definition AdaptiveSimulatorTimer.hpp:113
double totalTime() const
Definition AdaptiveSimulatorTimer.cpp:135
double currentStepLength() const override
Definition AdaptiveSimulatorTimer.cpp:115
AdaptiveSimulatorTimer(const boost::posix_time::ptime simulation_start_time, const double step_length, const double elapsed_time, const double last_step_taken, const int report_step, const double max_time_step=std::numeric_limits< double >::max())
constructor taking a simulator timer to determine start and end time
Definition AdaptiveSimulatorTimer.cpp:39
bool done() const override
Definition AdaptiveSimulatorTimer.cpp:139
int currentStepNum() const override
Definition AdaptiveSimulatorTimer.cpp:110
double averageStepLength() const
return average step length used so far
Definition AdaptiveSimulatorTimer.cpp:141
int reportStepNum() const override
return current report step
Definition AdaptiveSimulatorTimer.cpp:113
double maxStepLength() const
return max step length used so far
Definition AdaptiveSimulatorTimer.cpp:151
AdaptiveSimulatorTimer & operator++()
advance time by currentStepLength
Definition AdaptiveSimulatorTimer.cpp:68
double simulationTimeElapsed() const override
Definition AdaptiveSimulatorTimer.cpp:137
SimulatorTimerInterface()
Default constructor, protected to not allow explicit instances of this class.
Definition SimulatorTimerInterface.hpp:37
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43