2014-10-03 06:33:13 -05:00
|
|
|
/*
|
|
|
|
Copyright 2014 IRIS AS
|
|
|
|
|
|
|
|
This file is part of the Open Porous Media project (OPM).
|
|
|
|
|
|
|
|
OPM is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
OPM is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#ifndef OPM_ADAPTIVESIMULATORTIMER_HEADER_INCLUDED
|
|
|
|
#define OPM_ADAPTIVESIMULATORTIMER_HEADER_INCLUDED
|
|
|
|
|
|
|
|
#include <cassert>
|
2023-01-03 08:25:20 -06:00
|
|
|
#include <iosfwd>
|
2014-10-03 06:33:13 -05:00
|
|
|
#include <vector>
|
2021-11-15 03:49:54 -06:00
|
|
|
#include <limits>
|
2014-10-03 06:33:13 -05:00
|
|
|
#include <algorithm>
|
2021-06-08 08:35:37 -05:00
|
|
|
#include <memory>
|
2014-10-03 06:33:13 -05:00
|
|
|
#include <numeric>
|
|
|
|
|
2017-02-10 06:01:50 -06:00
|
|
|
#include <opm/simulators/timestepping/SimulatorTimerInterface.hpp>
|
2015-01-08 05:06:37 -06:00
|
|
|
|
2014-10-03 06:33:13 -05:00
|
|
|
namespace Opm
|
|
|
|
{
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
///
|
2014-10-03 07:14:01 -05:00
|
|
|
/// \brief Simulation timer for adaptive time stepping
|
|
|
|
///
|
2014-10-03 06:33:13 -05:00
|
|
|
/////////////////////////////////////////////////////////
|
2015-01-08 05:06:37 -06:00
|
|
|
class AdaptiveSimulatorTimer : public SimulatorTimerInterface
|
2014-10-03 06:33:13 -05:00
|
|
|
{
|
|
|
|
public:
|
2014-10-03 07:14:01 -05:00
|
|
|
/// \brief constructor taking a simulator timer to determine start and end time
|
2015-02-05 07:43:43 -06:00
|
|
|
/// \param timer in case of sub stepping this is the outer timer
|
|
|
|
/// \param lastStepTaken last suggested time step
|
|
|
|
/// \param maxTimeStep maximum time step allowed
|
|
|
|
AdaptiveSimulatorTimer( const SimulatorTimerInterface& timer,
|
|
|
|
const double lastStepTaken,
|
|
|
|
const double maxTimeStep = std::numeric_limits<double>::max() );
|
2014-10-03 06:33:13 -05:00
|
|
|
|
2014-10-03 06:44:05 -05:00
|
|
|
/// \brief advance time by currentStepLength
|
2014-10-06 07:26:23 -05:00
|
|
|
AdaptiveSimulatorTimer& operator++ ();
|
2014-10-03 06:33:13 -05:00
|
|
|
|
2015-01-28 08:25:11 -06:00
|
|
|
/// \brief advance time by currentStepLength
|
|
|
|
void advance() { this->operator++ (); }
|
|
|
|
|
2014-10-03 06:44:05 -05:00
|
|
|
/// \brief provide and estimate for new time step size
|
2014-10-06 07:26:23 -05:00
|
|
|
void provideTimeStepEstimate( const double dt_estimate );
|
2014-10-03 06:33:13 -05:00
|
|
|
|
2017-07-20 05:11:11 -05:00
|
|
|
/// \brief Whether this is the first step
|
|
|
|
bool initialStep () const;
|
|
|
|
|
2014-10-03 07:14:01 -05:00
|
|
|
/// \brief \copydoc SimulationTimer::currentStepNum
|
2014-10-06 07:26:23 -05:00
|
|
|
int currentStepNum () const;
|
2014-10-03 06:33:13 -05:00
|
|
|
|
2015-01-08 05:06:37 -06:00
|
|
|
/// \brief return current report step
|
|
|
|
int reportStepNum() const;
|
|
|
|
|
2014-10-03 07:14:01 -05:00
|
|
|
/// \brief \copydoc SimulationTimer::currentStepLength
|
2014-10-06 07:26:23 -05:00
|
|
|
double currentStepLength () const;
|
2014-10-03 06:33:13 -05:00
|
|
|
|
|
|
|
/// \brief \copydoc SimulationTimer::totalTime
|
2014-10-06 07:26:23 -05:00
|
|
|
double totalTime() const;
|
2014-10-03 06:33:13 -05:00
|
|
|
|
|
|
|
/// \brief \copydoc SimulationTimer::simulationTimeElapsed
|
2014-10-06 07:26:23 -05:00
|
|
|
double simulationTimeElapsed() const;
|
2014-10-03 06:33:13 -05:00
|
|
|
|
|
|
|
/// \brief \copydoc SimulationTimer::done
|
2014-10-06 07:26:23 -05:00
|
|
|
bool done () const;
|
2014-10-03 06:33:13 -05:00
|
|
|
|
|
|
|
/// \brief return average step length used so far
|
2014-10-06 07:26:23 -05:00
|
|
|
double averageStepLength() const;
|
2014-10-03 06:33:13 -05:00
|
|
|
|
|
|
|
/// \brief return max step length used so far
|
2014-10-06 07:26:23 -05:00
|
|
|
double maxStepLength () const;
|
2014-10-03 06:33:13 -05:00
|
|
|
|
|
|
|
/// \brief return min step length used so far
|
2014-10-06 07:26:23 -05:00
|
|
|
double minStepLength () const;
|
2014-10-03 06:33:13 -05:00
|
|
|
|
2015-01-08 05:06:37 -06:00
|
|
|
/// \brief Previous step length. This is the length of the step that
|
|
|
|
/// was taken to arrive at this time.
|
|
|
|
double stepLengthTaken () const;
|
|
|
|
|
2014-10-03 06:33:13 -05:00
|
|
|
/// \brief report start and end time as well as used steps so far
|
2014-10-06 07:26:23 -05:00
|
|
|
void report(std::ostream& os) const;
|
2014-10-03 08:53:18 -05:00
|
|
|
|
2015-01-09 08:10:56 -06:00
|
|
|
/// \brief start date time of simulation
|
|
|
|
boost::posix_time::ptime startDateTime() const;
|
2015-01-08 05:06:37 -06:00
|
|
|
|
2016-12-05 02:37:30 -06:00
|
|
|
/// \brief Return true if last time step failed
|
|
|
|
bool lastStepFailed() const {return lastStepFailed_;}
|
|
|
|
|
|
|
|
/// \brief tell the timestepper whether timestep failed or not
|
|
|
|
void setLastStepFailed(bool lastStepFailed) {lastStepFailed_ = lastStepFailed;}
|
|
|
|
|
2016-03-21 04:53:54 -05:00
|
|
|
/// return copy of object
|
|
|
|
virtual std::unique_ptr< SimulatorTimerInterface > clone() const;
|
|
|
|
|
2014-10-03 08:53:18 -05:00
|
|
|
protected:
|
2021-06-08 08:35:37 -05:00
|
|
|
std::shared_ptr<boost::posix_time::ptime> start_date_time_;
|
2014-10-03 08:53:18 -05:00
|
|
|
const double start_time_;
|
|
|
|
const double total_time_;
|
2015-01-08 05:06:37 -06:00
|
|
|
const int report_step_;
|
2015-02-05 07:43:43 -06:00
|
|
|
const double max_time_step_;
|
2015-01-08 05:06:37 -06:00
|
|
|
|
2014-10-03 08:53:18 -05:00
|
|
|
double current_time_;
|
|
|
|
double dt_;
|
|
|
|
int current_step_;
|
|
|
|
|
|
|
|
std::vector< double > steps_;
|
2016-12-05 02:37:30 -06:00
|
|
|
bool lastStepFailed_;
|
|
|
|
|
2014-10-03 06:33:13 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Opm
|
|
|
|
|
|
|
|
#endif // OPM_SIMULATORTIMER_HEADER_INCLUDED
|