From 12891f668bed21be10c8a6223b9eb6b21187003e Mon Sep 17 00:00:00 2001 From: Robert K Date: Fri, 24 Oct 2014 12:32:00 +0200 Subject: [PATCH] fix problem with solver reastart, variable was not reset. Also, the time step does only grow moderately after a solver restart. --- opm/core/simulator/AdaptiveTimeStepping.hpp | 1 + .../simulator/AdaptiveTimeStepping_impl.hpp | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/opm/core/simulator/AdaptiveTimeStepping.hpp b/opm/core/simulator/AdaptiveTimeStepping.hpp index 10428550..e73790db 100644 --- a/opm/core/simulator/AdaptiveTimeStepping.hpp +++ b/opm/core/simulator/AdaptiveTimeStepping.hpp @@ -38,6 +38,7 @@ namespace Opm { TimeStepControlType timeStepControl_; //!< time step control object const double initial_fraction_; //!< fraction to take as a guess for initial time interval const double restart_factor_; //!< factor to multiply time step with when solver fails to converge + const double growth_factor_; //!< factor to multiply time step when solver recovered from failed convergence const int solver_restart_max_; //!< how many restart of solver are allowed const bool solver_verbose_; //!< solver verbosity const bool timestep_verbose_; //!< timestep verbosity diff --git a/opm/core/simulator/AdaptiveTimeStepping_impl.hpp b/opm/core/simulator/AdaptiveTimeStepping_impl.hpp index 43900f6d..8e1bdda4 100644 --- a/opm/core/simulator/AdaptiveTimeStepping_impl.hpp +++ b/opm/core/simulator/AdaptiveTimeStepping_impl.hpp @@ -17,6 +17,7 @@ namespace Opm { : timeStepControl_() , initial_fraction_( param.getDefault("solver.initialfraction", double(0.25) ) ) , restart_factor_( param.getDefault("solver.restartfactor", double(0.1) ) ) + , growth_factor_( param.getDefault("solver.growthfactor", double(1.25) ) ) , solver_restart_max_( param.getDefault("solver.restart", int(3) ) ) , solver_verbose_( param.getDefault("solver.verbose", bool(false) ) ) , timestep_verbose_( param.getDefault("timestep.verbose", bool(false) ) ) @@ -36,6 +37,9 @@ namespace Opm { } else OPM_THROW(std::runtime_error,"Unsupported time step control selected "<< control ); + + // make sure growth factor is something reasonable + assert( growth_factor_ >= 1.0 ); } @@ -78,11 +82,11 @@ namespace Opm { std::cout << "Overall linear iterations used: " << linearIterations << std::endl; } } - catch (Opm::NumericalProblem e) { + catch (const Opm::NumericalProblem& e) { std::cerr << e.what() << std::endl; // since linearIterations is < 0 this will restart the solver } - catch (std::runtime_error e) { + catch (const std::runtime_error& e) { std::cerr << e.what() << std::endl; // also catch linear solver not converged } @@ -94,8 +98,16 @@ namespace Opm { ++timer; // compute new time step estimate - const double dtEstimate = + double dtEstimate = timeStepControl_->computeTimeStepSize( dt, linearIterations, state ); + + // avoid time step size growth + if( restarts > 0 ) { + dtEstimate = std::min( growth_factor_ * dt, dtEstimate ); + // solver converged, reset restarts counter + restarts = 0; + } + if( timestep_verbose_ ) std::cout << "Suggested time step size = " << unit::convert::to(dtEstimate, unit::day) << " (days)" << std::endl;