opm-simulators
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 #include <optional>
30 
31 #include <opm/simulators/timestepping/SimulatorTimerInterface.hpp>
32 
33 namespace Opm
34 {
35 
42  {
43  public:
51  AdaptiveSimulatorTimer(const boost::posix_time::ptime simulation_start_time,
52  const double step_length,
53  const double elapsed_time,
54  const double last_step_taken,
55  const int report_step,
56  const double max_time_step = std::numeric_limits<double>::max());
57 
60 
62  void advance() override { this->operator++ (); }
63 
65  void provideTimeStepEstimate( const double dt_estimate );
66 
68  bool initialStep () const override;
69 
71  int currentStepNum () const override;
72 
74  int reportStepNum() const override;
75 
77  double currentStepLength () const override;
78 
79  // \brief Set next step length
80  void setCurrentStepLength(double dt);
81 
83  double totalTime() const;
84 
86  double simulationTimeElapsed() const override;
87 
89  bool done () const override;
90 
92  double averageStepLength() const;
93 
95  double maxStepLength () const;
96 
98  double minStepLength () const;
99 
102  double stepLengthTaken () const override;
103 
105  void report(std::ostream& os) const;
106 
108  boost::posix_time::ptime startDateTime() const override;
109 
111  bool lastStepFailed() const override { return last_step_failed_; }
112 
114  void setLastStepFailed(bool last_step_failed) { last_step_failed_ = last_step_failed; }
115 
124  double reportStepStartTime() const;
125  double reportStepTotalTime() const;
126  int reportStepSubstepNum() const;
127 
128  void setReportStepStartTime(double t) { report_step_start_time_ = t; }
129  void setReportStepTotalTime(double t) { report_step_total_time_ = t; }
130  void setReportStepSubstepOffset(int n) { report_step_substep_offset_ = n; }
131 
132  int reportStepSubstepOffset() const { return report_step_substep_offset_; }
133 
135  std::unique_ptr<SimulatorTimerInterface> clone() const override;
136 
137  protected:
138  std::shared_ptr<boost::posix_time::ptime> start_date_time_;
139  const double start_time_;
140  const double total_time_;
141  const int report_step_;
142  const double max_time_step_;
143 
144  double current_time_;
145  double dt_;
146  int current_step_;
147 
148  std::vector< double > steps_;
149  bool last_step_failed_;
150 
154  std::optional<double> report_step_start_time_;
157  std::optional<double> report_step_total_time_;
163 
164  };
165 
166 } // namespace Opm
167 
168 #endif // OPM_SIMULATORTIMER_HEADER_INCLUDED
std::optional< double > report_step_start_time_
Optional report-step start time for the "report step view" accessors.
Definition: AdaptiveSimulatorTimer.hpp:154
Simulation timer for adaptive time stepping.
Definition: AdaptiveSimulatorTimer.hpp:41
double maxStepLength() const
return max step length used so far
Definition: AdaptiveSimulatorTimer.cpp:151
double currentStepLength() const override
Definition: AdaptiveSimulatorTimer.cpp:115
AdaptiveSimulatorTimer & operator++()
advance time by currentStepLength
Definition: AdaptiveSimulatorTimer.cpp:68
void advance() override
advance time by currentStepLength
Definition: AdaptiveSimulatorTimer.hpp:62
int reportStepNum() const override
return current report step
Definition: AdaptiveSimulatorTimer.cpp:113
bool done() const override
Definition: AdaptiveSimulatorTimer.cpp:139
double reportStepStartTime() const
Reservoir coupling constructs a fresh timer per sync chunk, so start_time_, total_time_, and current_step_ describe the chunk rather than the enclosing report step.
Definition: AdaptiveSimulatorTimer.cpp:180
void provideTimeStepEstimate(const double dt_estimate)
provide and estimate for new time step size
Definition: AdaptiveSimulatorTimer.cpp:79
double stepLengthTaken() const override
Previous step length.
Definition: AdaptiveSimulatorTimer.cpp:127
bool lastStepFailed() const override
Return true if last time step failed.
Definition: AdaptiveSimulatorTimer.hpp:111
double averageStepLength() const
return average step length used so far
Definition: AdaptiveSimulatorTimer.cpp:141
int currentStepNum() const override
Definition: AdaptiveSimulatorTimer.cpp:110
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
void setLastStepFailed(bool last_step_failed)
tell the timestepper whether timestep failed or not
Definition: AdaptiveSimulatorTimer.hpp:114
std::optional< double > report_step_total_time_
Optional report-step end time for the "report step view" accessors.
Definition: AdaptiveSimulatorTimer.hpp:157
void report(std::ostream &os) const
report start and end time as well as used steps so far
Definition: AdaptiveSimulatorTimer.cpp:166
boost::posix_time::ptime startDateTime() const override
start date time of simulation
Definition: AdaptiveSimulatorTimer.cpp:195
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
double simulationTimeElapsed() const override
Definition: AdaptiveSimulatorTimer.cpp:137
Interface class for SimulatorTimer objects, to be improved.
Definition: SimulatorTimerInterface.hpp:33
int report_step_substep_offset_
Number of substeps already taken in this report step before this timer was constructed (i...
Definition: AdaptiveSimulatorTimer.hpp:162
double minStepLength() const
return min step length used so far
Definition: AdaptiveSimulatorTimer.cpp:158
bool initialStep() const override
Whether this is the first step.
Definition: AdaptiveSimulatorTimer.cpp:63
double totalTime() const
Definition: AdaptiveSimulatorTimer.cpp:135
std::unique_ptr< SimulatorTimerInterface > clone() const override
return copy of object
Definition: AdaptiveSimulatorTimer.cpp:202