From 380fe6e2fd2f6b075e3c54b5f379d27ac5719cb3 Mon Sep 17 00:00:00 2001 From: Tor Harald Sandve Date: Thu, 15 Sep 2016 12:21:59 +0200 Subject: [PATCH] Timestepper based on userInput A new timestepper that reads timesteps from a file generated using ecl_summary "DECK" TIME and applies it to the simulator Also a parameter timestep.initial_step_length (default 1 day) is added to controll the frist timestep. --- .../AdaptiveTimeStepping_impl.hpp | 8 +++- .../timestepping/TimeStepControl.cpp | 43 +++++++++++++++++-- .../timestepping/TimeStepControl.hpp | 27 ++++++++++-- .../timestepping/TimeStepControlInterface.hpp | 2 +- 4 files changed, 70 insertions(+), 10 deletions(-) diff --git a/opm/simulators/timestepping/AdaptiveTimeStepping_impl.hpp b/opm/simulators/timestepping/AdaptiveTimeStepping_impl.hpp index 56a11dec1..0ac481ac2 100644 --- a/opm/simulators/timestepping/AdaptiveTimeStepping_impl.hpp +++ b/opm/simulators/timestepping/AdaptiveTimeStepping_impl.hpp @@ -72,7 +72,7 @@ namespace Opm { , solver_restart_max_( param.getDefault("solver.restart", int(10) ) ) , solver_verbose_( param.getDefault("solver.verbose", bool(true) ) && terminal_output ) , timestep_verbose_( param.getDefault("timestep.verbose", bool(true) ) && terminal_output ) - , suggested_next_timestep_( -1.0 ) + , suggested_next_timestep_( unit::convert::from(param.getDefault("timestep.initial_step_length", double(1.0) ), unit::day) ) , full_timestep_initially_( param.getDefault("full_timestep_initially", bool(false) ) ) { // valid are "pid" and "pid+iteration" @@ -95,6 +95,10 @@ namespace Opm { const double decayrate = param.getDefault("timestep.control.decayrate", double(0.75) ); const double growthrate = param.getDefault("timestep.control.growthrate", double(1.25) ); timeStepControl_ = TimeStepControlType( new SimpleIterationCountTimeStepControl( iterations, decayrate, growthrate ) ); + } else if ( control == "hardcoded") { + const std::string filename = param.getDefault("timestep.control.filename", std::string("timesteps")); + timeStepControl_ = TimeStepControlType( new HardcodedTimeStepControl( filename ) ); + } else OPM_THROW(std::runtime_error,"Unsupported time step control selected "<< control ); @@ -202,7 +206,7 @@ namespace Opm { // compute new time step estimate double dtEstimate = - timeStepControl_->computeTimeStepSize( dt, linearIterations, relativeChange ); + timeStepControl_->computeTimeStepSize( dt, linearIterations, relativeChange, substepTimer.simulationTimeElapsed()); // limit the growth of the timestep size by the growth factor dtEstimate = std::min( dtEstimate, double(max_growth_ * dt) ); diff --git a/opm/simulators/timestepping/TimeStepControl.cpp b/opm/simulators/timestepping/TimeStepControl.cpp index e7d110434..0c01b24e3 100644 --- a/opm/simulators/timestepping/TimeStepControl.cpp +++ b/opm/simulators/timestepping/TimeStepControl.cpp @@ -23,6 +23,9 @@ #include #include #include +#include +#include +#include #include #include @@ -55,7 +58,7 @@ namespace Opm } double SimpleIterationCountTimeStepControl:: - computeTimeStepSize( const double dt, const int iterations, const RelativeChangeInterface& /* relativeChange */ ) const + computeTimeStepSize( const double dt, const int iterations, const RelativeChangeInterface& /* relativeChange */, const double /*simulationTimeElapsed */) const { double dtEstimate = dt ; @@ -74,6 +77,38 @@ namespace Opm return dtEstimate; } + //////////////////////////////////////////////////////// + // + // HardcodedTimeStepControl Implementation + // + //////////////////////////////////////////////////////// + + HardcodedTimeStepControl:: + HardcodedTimeStepControl( const std::string filename) + { + std::ifstream infile (filename); + double time; + std::string line; + std::getline(infile, line); //assumes two lines before the timing starts. + std::getline(infile, line); + + while (!infile.eof() ) { + infile >> time; // read the time in days + std::string line; + std::getline(infile, line); // skip the rest of the line + timesteps_.push_back( time * unit::day ); + } + + } + + double HardcodedTimeStepControl:: + computeTimeStepSize( const double /*dt */, const int /*iterations */, const RelativeChangeInterface& /* relativeChange */ , const double simulationTimeElapsed) const + { + auto nextTime = std::upper_bound(timesteps_.begin(), timesteps_.end(), simulationTimeElapsed); + double dtEstimate = (*nextTime - simulationTimeElapsed); + return dtEstimate; + } + //////////////////////////////////////////////////////// @@ -90,7 +125,7 @@ namespace Opm {} double PIDTimeStepControl:: - computeTimeStepSize( const double dt, const int /* iterations */, const RelativeChangeInterface& relChange ) const + computeTimeStepSize( const double dt, const int /* iterations */, const RelativeChangeInterface& relChange, const double /*simulationTimeElapsed */) const { // shift errors for( int i=0; i<2; ++i ) { @@ -141,9 +176,9 @@ namespace Opm {} double PIDAndIterationCountTimeStepControl:: - computeTimeStepSize( const double dt, const int iterations, const RelativeChangeInterface& relChange ) const + computeTimeStepSize( const double dt, const int iterations, const RelativeChangeInterface& relChange, const double simulationTimeElapsed ) const { - double dtEstimate = BaseType :: computeTimeStepSize( dt, iterations, relChange ); + double dtEstimate = BaseType :: computeTimeStepSize( dt, iterations, relChange, simulationTimeElapsed); // further reduce step size if to many iterations were used if( iterations > target_iterations_ ) diff --git a/opm/simulators/timestepping/TimeStepControl.hpp b/opm/simulators/timestepping/TimeStepControl.hpp index ec14ddbef..40f5db6e0 100644 --- a/opm/simulators/timestepping/TimeStepControl.hpp +++ b/opm/simulators/timestepping/TimeStepControl.hpp @@ -48,7 +48,7 @@ namespace Opm const bool verbose = false); /// \brief \copydoc TimeStepControlInterface::computeTimeStepSize - double computeTimeStepSize( const double dt, const int iterations, const RelativeChangeInterface& /* relativeChange */ ) const; + double computeTimeStepSize( const double dt, const int iterations, const RelativeChangeInterface& /* relativeChange */, const double /*simulationTimeElapsed */ ) const; protected: const int target_iterations_; @@ -82,7 +82,7 @@ namespace Opm const bool verbose = false ); /// \brief \copydoc TimeStepControlInterface::computeTimeStepSize - double computeTimeStepSize( const double dt, const int /* iterations */, const RelativeChangeInterface& relativeChange ) const; + double computeTimeStepSize( const double dt, const int /* iterations */, const RelativeChangeInterface& relativeChange, const double /*simulationTimeElapsed */ ) const; protected: const double tol_; @@ -111,12 +111,33 @@ namespace Opm const bool verbose = false); /// \brief \copydoc TimeStepControlInterface::computeTimeStepSize - double computeTimeStepSize( const double dt, const int iterations, const RelativeChangeInterface& relativeChange ) const; + double computeTimeStepSize( const double dt, const int iterations, const RelativeChangeInterface& relativeChange, const double /*simulationTimeElapsed */ ) const; protected: const int target_iterations_; }; + /////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// + /// HardcodedTimeStepControl + /// Input generated from summary file using the ert application: + /// ecl_summary DECK TIME > filename + // + /////////////////////////////////////////////////////////////////////////////////////////////////////////////// + class HardcodedTimeStepControl : public TimeStepControlInterface + { + public: + /// \brief constructor + /// \param filename filename contaning the timesteps + HardcodedTimeStepControl( const std::string filename); + + /// \brief \copydoc TimeStepControlInterface::computeTimeStepSize + double computeTimeStepSize( const double dt, const int /* iterations */, const RelativeChangeInterface& /*relativeChange */, const double simulationTimeElapsed) const; + + protected: + std::vector timesteps_; + }; + } // end namespace Opm #endif diff --git a/opm/simulators/timestepping/TimeStepControlInterface.hpp b/opm/simulators/timestepping/TimeStepControlInterface.hpp index 2aee5aebe..bdab5e3a4 100644 --- a/opm/simulators/timestepping/TimeStepControlInterface.hpp +++ b/opm/simulators/timestepping/TimeStepControlInterface.hpp @@ -56,7 +56,7 @@ namespace Opm /// \param timeError object to compute || u^n+1 - u^n || / || u^n+1 || /// /// \return suggested time step size for the next step - virtual double computeTimeStepSize( const double dt, const int iterations, const RelativeChangeInterface& relativeChange ) const = 0; + virtual double computeTimeStepSize( const double dt, const int iterations, const RelativeChangeInterface& relativeChange , const double simulationTimeElapsed) const = 0; /// virtual destructor (empty) virtual ~TimeStepControlInterface () {}