2015-01-08 05:42:05 -06:00
|
|
|
/*
|
|
|
|
Copyright 2014 IRIS AS
|
2017-06-07 07:49:00 -05:00
|
|
|
|
2015-01-08 05:42:05 -06:00
|
|
|
This file is part of the Open Porous Media project (OPM).
|
2017-06-07 07:47:45 -05:00
|
|
|
|
2015-01-08 05:42:05 -06:00
|
|
|
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.
|
2017-06-07 07:47:45 -05:00
|
|
|
|
2015-01-08 05:42:05 -06:00
|
|
|
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.
|
2017-06-07 07:47:45 -05:00
|
|
|
|
2015-01-08 05:42:05 -06:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2014-10-06 07:06:07 -05:00
|
|
|
#ifndef OPM_ADAPTIVETIMESTEPPING_IMPL_HEADER_INCLUDED
|
|
|
|
#define OPM_ADAPTIVETIMESTEPPING_IMPL_HEADER_INCLUDED
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
|
2017-02-10 09:07:25 -06:00
|
|
|
#include <opm/simulators/timestepping/SimulatorTimer.hpp>
|
2017-02-10 06:01:50 -06:00
|
|
|
#include <opm/simulators/timestepping/AdaptiveSimulatorTimer.hpp>
|
|
|
|
#include <opm/simulators/timestepping/TimeStepControl.hpp>
|
2016-11-23 14:30:01 -06:00
|
|
|
#include <opm/core/utility/StopWatch.hpp>
|
2016-07-05 05:23:55 -05:00
|
|
|
#include <opm/common/Exceptions.hpp>
|
2016-05-09 00:31:04 -05:00
|
|
|
#include <opm/common/OpmLog/OpmLog.hpp>
|
2015-04-10 07:03:27 -05:00
|
|
|
#include <dune/istl/istlexception.hh>
|
2015-08-17 05:59:31 -05:00
|
|
|
#include <dune/istl/ilu.hh> // For MatrixBlockException
|
2016-09-28 02:59:50 -05:00
|
|
|
#include <opm/parser/eclipse/EclipseState/Schedule/Tuning.hpp>
|
2014-10-06 07:06:07 -05:00
|
|
|
|
|
|
|
namespace Opm {
|
|
|
|
|
2015-10-31 06:42:23 -05:00
|
|
|
namespace detail
|
|
|
|
{
|
|
|
|
template <class Solver, class State>
|
2015-11-13 04:37:53 -06:00
|
|
|
class SolutionTimeErrorSolverWrapper : public RelativeChangeInterface
|
2015-10-31 06:42:23 -05:00
|
|
|
{
|
|
|
|
const Solver& solver_;
|
|
|
|
const State& previous_;
|
|
|
|
const State& current_;
|
|
|
|
public:
|
|
|
|
SolutionTimeErrorSolverWrapper( const Solver& solver,
|
|
|
|
const State& previous,
|
|
|
|
const State& current )
|
|
|
|
: solver_( solver ),
|
|
|
|
previous_( previous ),
|
|
|
|
current_( current )
|
|
|
|
{}
|
|
|
|
|
|
|
|
/// return || u^n+1 - u^n || / || u^n+1 ||
|
2015-11-10 10:53:40 -06:00
|
|
|
double relativeChange() const
|
2015-10-31 06:42:23 -05:00
|
|
|
{
|
2015-11-10 10:53:40 -06:00
|
|
|
return solver_.model().relativeChange( previous_, current_ );
|
2015-10-31 06:42:23 -05:00
|
|
|
}
|
|
|
|
};
|
2016-09-19 12:44:41 -05:00
|
|
|
|
|
|
|
template<class E>
|
|
|
|
void logException(const E& exception, bool verbose)
|
|
|
|
{
|
|
|
|
if( verbose )
|
|
|
|
{
|
2017-06-07 07:40:18 -05:00
|
|
|
std::string message;
|
|
|
|
message = "Caught Exception: ";
|
|
|
|
message += exception.what();
|
|
|
|
OpmLog::debug(message);
|
2016-09-19 12:44:41 -05:00
|
|
|
}
|
|
|
|
}
|
2015-10-31 06:42:23 -05:00
|
|
|
}
|
|
|
|
|
2014-12-10 04:20:29 -06:00
|
|
|
// AdaptiveTimeStepping
|
2014-10-06 07:06:07 -05:00
|
|
|
//---------------------
|
2017-10-04 12:03:02 -05:00
|
|
|
inline AdaptiveTimeStepping::AdaptiveTimeStepping( const Tuning& tuning,
|
|
|
|
size_t time_step,
|
|
|
|
const ParameterGroup& param,
|
|
|
|
const bool terminal_output )
|
2016-09-28 02:59:50 -05:00
|
|
|
: timeStepControl_()
|
|
|
|
, restart_factor_( tuning.getTSFCNV(time_step) )
|
|
|
|
, growth_factor_(tuning.getTFDIFF(time_step) )
|
|
|
|
, max_growth_( tuning.getTSFMAX(time_step) )
|
|
|
|
// default is 1 year, convert to seconds
|
|
|
|
, max_time_step_( tuning.getTSMAXZ(time_step) )
|
|
|
|
, 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_( tuning.getTSINIT(time_step) )
|
|
|
|
, full_timestep_initially_( param.getDefault("full_timestep_initially", bool(false) ) )
|
2017-02-24 06:51:10 -06:00
|
|
|
, timestep_after_event_( tuning.getTMAXWC(time_step))
|
|
|
|
, use_newton_iteration_(false)
|
2016-09-28 02:59:50 -05:00
|
|
|
{
|
|
|
|
init(param);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-10-04 12:03:02 -05:00
|
|
|
inline AdaptiveTimeStepping::AdaptiveTimeStepping( const ParameterGroup& param,
|
|
|
|
const bool terminal_output )
|
2014-10-06 07:06:07 -05:00
|
|
|
: timeStepControl_()
|
2015-09-08 03:56:58 -05:00
|
|
|
, restart_factor_( param.getDefault("solver.restartfactor", double(0.33) ) )
|
|
|
|
, growth_factor_( param.getDefault("solver.growthfactor", double(2) ) )
|
2015-09-03 05:02:36 -05:00
|
|
|
, max_growth_( param.getDefault("timestep.control.maxgrowth", double(3.0) ) )
|
2015-02-05 07:43:43 -06:00
|
|
|
// default is 1 year, convert to seconds
|
|
|
|
, max_time_step_( unit::convert::from(param.getDefault("timestep.max_timestep_in_days", 365.0 ), unit::day) )
|
2015-04-21 04:41:45 -05:00
|
|
|
, solver_restart_max_( param.getDefault("solver.restart", int(10) ) )
|
2015-09-16 08:19:19 -05:00
|
|
|
, solver_verbose_( param.getDefault("solver.verbose", bool(true) ) && terminal_output )
|
2015-09-16 07:33:35 -05:00
|
|
|
, timestep_verbose_( param.getDefault("timestep.verbose", bool(true) ) && terminal_output )
|
2017-11-28 08:12:48 -06:00
|
|
|
, suggested_next_timestep_( unit::convert::from(param.getDefault("timestep.initial_timestep_in_days", 1.0 ), unit::day) )
|
2015-08-19 04:33:29 -05:00
|
|
|
, full_timestep_initially_( param.getDefault("full_timestep_initially", bool(false) ) )
|
2017-02-24 06:51:10 -06:00
|
|
|
, timestep_after_event_( unit::convert::from(param.getDefault("timestep.timestep_in_days_after_event", -1.0 ), unit::day))
|
|
|
|
, use_newton_iteration_(false)
|
2016-09-28 02:59:50 -05:00
|
|
|
{
|
|
|
|
init(param);
|
|
|
|
}
|
|
|
|
|
2017-10-04 12:03:02 -05:00
|
|
|
inline void AdaptiveTimeStepping::
|
2017-04-28 08:36:25 -05:00
|
|
|
init(const ParameterGroup& param)
|
2014-10-06 07:06:07 -05:00
|
|
|
{
|
|
|
|
// valid are "pid" and "pid+iteration"
|
2015-09-08 03:56:58 -05:00
|
|
|
std::string control = param.getDefault("timestep.control", std::string("pid") );
|
2015-02-05 07:43:43 -06:00
|
|
|
// iterations is the accumulation of all linear iterations over all newton steops per time step
|
2015-04-22 06:03:19 -05:00
|
|
|
const int defaultTargetIterations = 30;
|
2017-02-24 06:51:10 -06:00
|
|
|
const int defaultTargetNewtonIterations = 8;
|
2014-12-10 04:20:29 -06:00
|
|
|
|
2015-09-08 03:56:58 -05:00
|
|
|
const double tol = param.getDefault("timestep.control.tol", double(1e-1) );
|
2014-10-20 05:32:11 -05:00
|
|
|
if( control == "pid" ) {
|
2015-10-31 06:42:23 -05:00
|
|
|
timeStepControl_ = TimeStepControlType( new PIDTimeStepControl( tol ) );
|
2014-10-20 05:32:11 -05:00
|
|
|
}
|
2014-12-10 04:20:29 -06:00
|
|
|
else if ( control == "pid+iteration" )
|
2014-10-06 07:06:07 -05:00
|
|
|
{
|
2015-02-05 07:43:43 -06:00
|
|
|
const int iterations = param.getDefault("timestep.control.targetiteration", defaultTargetIterations );
|
2015-10-31 06:42:23 -05:00
|
|
|
timeStepControl_ = TimeStepControlType( new PIDAndIterationCountTimeStepControl( iterations, tol ) );
|
2014-10-06 07:06:07 -05:00
|
|
|
}
|
2017-02-24 06:51:10 -06:00
|
|
|
else if ( control == "pid+newtoniteration" )
|
|
|
|
{
|
|
|
|
const int iterations = param.getDefault("timestep.control.targetiteration", defaultTargetNewtonIterations );
|
|
|
|
timeStepControl_ = TimeStepControlType( new PIDAndIterationCountTimeStepControl( iterations, tol ) );
|
|
|
|
use_newton_iteration_ = true;
|
|
|
|
}
|
2015-02-05 07:43:43 -06:00
|
|
|
else if ( control == "iterationcount" )
|
|
|
|
{
|
|
|
|
const int iterations = param.getDefault("timestep.control.targetiteration", defaultTargetIterations );
|
|
|
|
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 ) );
|
2016-09-15 05:21:59 -05:00
|
|
|
} else if ( control == "hardcoded") {
|
|
|
|
const std::string filename = param.getDefault("timestep.control.filename", std::string("timesteps"));
|
|
|
|
timeStepControl_ = TimeStepControlType( new HardcodedTimeStepControl( filename ) );
|
|
|
|
|
2015-02-05 07:43:43 -06:00
|
|
|
}
|
2014-12-10 04:20:29 -06:00
|
|
|
else
|
2014-10-06 07:06:07 -05:00
|
|
|
OPM_THROW(std::runtime_error,"Unsupported time step control selected "<< control );
|
2014-10-24 05:32:00 -05:00
|
|
|
|
|
|
|
// make sure growth factor is something reasonable
|
|
|
|
assert( growth_factor_ >= 1.0 );
|
2014-10-06 07:06:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-28 02:59:50 -05:00
|
|
|
|
2014-12-10 04:20:29 -06:00
|
|
|
template <class Solver, class State, class WellState>
|
2016-11-23 14:30:01 -06:00
|
|
|
SimulatorReport AdaptiveTimeStepping::
|
2017-02-24 06:51:10 -06:00
|
|
|
step( const SimulatorTimer& simulatorTimer, Solver& solver, State& state, WellState& well_state, const bool event )
|
2014-12-10 04:20:29 -06:00
|
|
|
{
|
2017-02-24 06:51:10 -06:00
|
|
|
return stepImpl( simulatorTimer, solver, state, well_state, event, nullptr, nullptr );
|
2014-12-10 04:20:29 -06:00
|
|
|
}
|
|
|
|
|
2016-05-20 09:21:14 -05:00
|
|
|
template <class Solver, class State, class WellState, class Output>
|
2016-11-23 14:30:01 -06:00
|
|
|
SimulatorReport AdaptiveTimeStepping::
|
2017-02-09 02:33:32 -06:00
|
|
|
step( const SimulatorTimer& simulatorTimer,
|
|
|
|
Solver& solver, State& state, WellState& well_state,
|
2017-02-24 06:51:10 -06:00
|
|
|
const bool event,
|
2017-02-09 02:33:32 -06:00
|
|
|
Output& outputWriter,
|
|
|
|
const std::vector<int>* fipnum)
|
2014-12-10 04:20:29 -06:00
|
|
|
{
|
2017-02-24 06:51:10 -06:00
|
|
|
return stepImpl( simulatorTimer, solver, state, well_state, event, &outputWriter, fipnum );
|
2014-12-10 04:20:29 -06:00
|
|
|
}
|
|
|
|
|
2016-09-28 02:59:50 -05:00
|
|
|
|
2014-12-10 04:20:29 -06:00
|
|
|
// implementation of the step method
|
2016-05-20 09:21:14 -05:00
|
|
|
template <class Solver, class State, class WState, class Output >
|
2016-11-23 14:30:01 -06:00
|
|
|
SimulatorReport AdaptiveTimeStepping::
|
2015-01-08 05:42:05 -06:00
|
|
|
stepImpl( const SimulatorTimer& simulatorTimer,
|
|
|
|
Solver& solver, State& state, WState& well_state,
|
2017-02-24 06:51:10 -06:00
|
|
|
const bool event,
|
2017-02-09 02:33:32 -06:00
|
|
|
Output* outputWriter,
|
|
|
|
const std::vector<int>* fipnum)
|
2014-10-06 07:06:07 -05:00
|
|
|
{
|
2016-11-23 14:30:01 -06:00
|
|
|
SimulatorReport report;
|
2015-01-08 05:42:05 -06:00
|
|
|
const double timestep = simulatorTimer.currentStepLength();
|
|
|
|
|
2014-10-13 04:17:37 -05:00
|
|
|
// init last time step as a fraction of the given time step
|
2015-08-25 04:16:36 -05:00
|
|
|
if( suggested_next_timestep_ < 0 ) {
|
|
|
|
suggested_next_timestep_ = restart_factor_ * timestep;
|
2014-10-20 05:32:11 -05:00
|
|
|
}
|
2014-10-13 04:17:37 -05:00
|
|
|
|
2015-08-17 07:58:47 -05:00
|
|
|
if (full_timestep_initially_) {
|
2015-08-25 04:16:36 -05:00
|
|
|
suggested_next_timestep_ = timestep;
|
2015-08-17 07:58:47 -05:00
|
|
|
}
|
|
|
|
|
2017-02-24 06:51:10 -06:00
|
|
|
// use seperate time step after event
|
|
|
|
if (event && timestep_after_event_ > 0) {
|
|
|
|
suggested_next_timestep_ = timestep_after_event_;
|
|
|
|
}
|
2015-02-10 06:10:39 -06:00
|
|
|
|
2014-10-06 07:06:07 -05:00
|
|
|
// create adaptive step timer with previously used sub step size
|
2015-08-25 04:16:36 -05:00
|
|
|
AdaptiveSimulatorTimer substepTimer( simulatorTimer, suggested_next_timestep_, max_time_step_ );
|
2014-10-06 07:06:07 -05:00
|
|
|
|
|
|
|
// copy states in case solver has to be restarted (to be revised)
|
2014-12-10 04:20:29 -06:00
|
|
|
State last_state( state );
|
|
|
|
WState last_well_state( well_state );
|
2014-10-06 07:06:07 -05:00
|
|
|
|
2017-04-10 08:55:30 -05:00
|
|
|
// reset the statistics for the failed substeps
|
|
|
|
failureReport_ = SimulatorReport();
|
|
|
|
|
2014-10-06 07:06:07 -05:00
|
|
|
// counter for solver restarts
|
|
|
|
int restarts = 0;
|
|
|
|
|
|
|
|
// sub step time loop
|
2014-12-10 04:20:29 -06:00
|
|
|
while( ! substepTimer.done() )
|
2014-10-06 07:06:07 -05:00
|
|
|
{
|
2014-10-10 06:55:28 -05:00
|
|
|
// get current delta t
|
2014-12-10 04:20:29 -06:00
|
|
|
const double dt = substepTimer.currentStepLength() ;
|
2015-01-16 09:02:18 -06:00
|
|
|
if( timestep_verbose_ )
|
|
|
|
{
|
2016-05-10 01:13:33 -05:00
|
|
|
std::ostringstream ss;
|
2017-11-16 08:42:01 -06:00
|
|
|
ss <<"\nTime step " << substepTimer.currentStepNum() << ", stepsize "
|
2016-06-28 00:40:32 -05:00
|
|
|
<< unit::convert::to(substepTimer.currentStepLength(), unit::day) << " days.";
|
|
|
|
OpmLog::info(ss.str());
|
2015-01-16 09:02:18 -06:00
|
|
|
}
|
|
|
|
|
2016-11-23 14:30:01 -06:00
|
|
|
SimulatorReport substepReport;
|
2017-06-07 07:40:18 -05:00
|
|
|
std::string cause_of_failure = "";
|
2014-12-10 04:20:29 -06:00
|
|
|
try {
|
2016-11-23 14:30:01 -06:00
|
|
|
substepReport = solver.step( substepTimer, state, well_state);
|
|
|
|
report += substepReport;
|
2014-10-06 07:06:07 -05:00
|
|
|
|
|
|
|
if( solver_verbose_ ) {
|
|
|
|
// report number of linear iterations
|
2017-10-13 06:29:31 -05:00
|
|
|
OpmLog::debug("Overall linear iterations used: " + std::to_string(substepReport.total_linear_iterations));
|
2014-10-06 07:06:07 -05:00
|
|
|
}
|
|
|
|
}
|
2017-06-11 15:32:46 -05:00
|
|
|
catch (const Opm::TooManyIterations& e) {
|
|
|
|
substepReport += solver.failureReport();
|
|
|
|
cause_of_failure = "Solver convergence failure - Iteration limit reached";
|
|
|
|
|
|
|
|
detail::logException(e, solver_verbose_);
|
|
|
|
// since linearIterations is < 0 this will restart the solver
|
|
|
|
}
|
|
|
|
catch (const Opm::LinearSolverProblem& e) {
|
|
|
|
substepReport += solver.failureReport();
|
2017-06-26 05:46:09 -05:00
|
|
|
cause_of_failure = "Linear solver convergence failure";
|
2017-06-11 15:32:46 -05:00
|
|
|
|
|
|
|
detail::logException(e, solver_verbose_);
|
|
|
|
// since linearIterations is < 0 this will restart the solver
|
|
|
|
}
|
2014-10-24 05:32:00 -05:00
|
|
|
catch (const Opm::NumericalProblem& e) {
|
2017-04-10 08:55:30 -05:00
|
|
|
substepReport += solver.failureReport();
|
2017-06-12 03:48:07 -05:00
|
|
|
cause_of_failure = "Solver convergence failure - Numerical problem encountered";
|
2017-04-10 08:55:30 -05:00
|
|
|
|
2016-09-19 12:44:41 -05:00
|
|
|
detail::logException(e, solver_verbose_);
|
2014-10-06 07:06:07 -05:00
|
|
|
// since linearIterations is < 0 this will restart the solver
|
|
|
|
}
|
2014-10-24 05:32:00 -05:00
|
|
|
catch (const std::runtime_error& e) {
|
2017-04-10 08:55:30 -05:00
|
|
|
substepReport += solver.failureReport();
|
|
|
|
|
2016-09-19 12:44:41 -05:00
|
|
|
detail::logException(e, solver_verbose_);
|
2014-10-14 08:18:36 -05:00
|
|
|
// also catch linear solver not converged
|
|
|
|
}
|
2015-03-10 06:47:38 -05:00
|
|
|
catch (const Dune::ISTLError& e) {
|
2017-04-10 08:55:30 -05:00
|
|
|
substepReport += solver.failureReport();
|
|
|
|
|
2016-09-19 12:44:41 -05:00
|
|
|
detail::logException(e, solver_verbose_);
|
2015-08-17 05:59:31 -05:00
|
|
|
// also catch errors in ISTL AMG that occur when time step is too large
|
|
|
|
}
|
|
|
|
catch (const Dune::MatrixBlockError& e) {
|
2017-04-10 08:55:30 -05:00
|
|
|
substepReport += solver.failureReport();
|
|
|
|
|
2016-09-19 12:44:41 -05:00
|
|
|
detail::logException(e, solver_verbose_);
|
2015-08-17 06:02:37 -05:00
|
|
|
// this can be thrown by ISTL's ILU0 in block mode, yet is not an ISTLError
|
2015-03-10 06:47:38 -05:00
|
|
|
}
|
2014-10-06 07:06:07 -05:00
|
|
|
|
2016-11-23 14:30:01 -06:00
|
|
|
if( substepReport.converged )
|
2014-10-06 07:06:07 -05:00
|
|
|
{
|
|
|
|
// advance by current dt
|
2014-12-10 04:20:29 -06:00
|
|
|
++substepTimer;
|
2014-10-06 07:06:07 -05:00
|
|
|
|
2015-10-31 06:42:23 -05:00
|
|
|
// create object to compute the time error, simply forwards the call to the model
|
|
|
|
detail::SolutionTimeErrorSolverWrapper< Solver, State >
|
2015-11-10 10:53:40 -06:00
|
|
|
relativeChange( solver, last_state, state );
|
2015-10-31 06:42:23 -05:00
|
|
|
|
2014-10-06 07:06:07 -05:00
|
|
|
// compute new time step estimate
|
2017-02-24 06:51:10 -06:00
|
|
|
const int iterations = use_newton_iteration_ ? substepReport.total_newton_iterations
|
|
|
|
: substepReport.total_linear_iterations;
|
|
|
|
double dtEstimate = timeStepControl_->computeTimeStepSize( dt, iterations, relativeChange,
|
|
|
|
substepTimer.simulationTimeElapsed());
|
2014-10-24 05:32:00 -05:00
|
|
|
|
2015-09-03 05:02:36 -05:00
|
|
|
// limit the growth of the timestep size by the growth factor
|
|
|
|
dtEstimate = std::min( dtEstimate, double(max_growth_ * dt) );
|
|
|
|
|
|
|
|
// further restrict time step size growth after convergence problems
|
2014-10-24 05:32:00 -05:00
|
|
|
if( restarts > 0 ) {
|
|
|
|
dtEstimate = std::min( growth_factor_ * dt, dtEstimate );
|
|
|
|
// solver converged, reset restarts counter
|
|
|
|
restarts = 0;
|
|
|
|
}
|
|
|
|
|
2014-10-06 07:06:07 -05:00
|
|
|
if( timestep_verbose_ )
|
2014-12-10 04:20:29 -06:00
|
|
|
{
|
2016-06-28 00:40:32 -05:00
|
|
|
std::ostringstream ss;
|
2017-10-13 06:29:31 -05:00
|
|
|
ss << "Time step summary: ";
|
2017-04-06 07:54:08 -05:00
|
|
|
if (substepReport.total_well_iterations != 0) {
|
|
|
|
ss << "well its = " << std::setw(2) << substepReport.total_well_iterations << ", ";
|
2016-06-29 20:03:30 -05:00
|
|
|
}
|
2017-04-06 07:54:08 -05:00
|
|
|
ss << "newton its = " << std::setw(2) << substepReport.total_newton_iterations << ", "
|
|
|
|
<< "linearizations = " << std::setw(2) << substepReport.total_linearizations
|
|
|
|
<< " (" << std::fixed << std::setprecision(3) << std::setw(6) << substepReport.assemble_time << " sec), "
|
|
|
|
<< "linear its = " << std::setw(3) << substepReport.total_linear_iterations
|
|
|
|
<< " (" << std::fixed << std::setprecision(3) << std::setw(6) << substepReport.linear_solve_time << " sec)";
|
2016-06-28 00:40:32 -05:00
|
|
|
OpmLog::info(ss.str());
|
2015-01-09 08:10:56 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// write data if outputWriter was provided
|
2016-09-26 04:02:10 -05:00
|
|
|
// if the time step is done we do not need
|
|
|
|
// to write it as this will be done by the simulator
|
|
|
|
// anyway.
|
|
|
|
if( outputWriter && !substepTimer.done() ) {
|
2017-02-09 02:33:32 -06:00
|
|
|
if (fipnum) {
|
|
|
|
solver.computeFluidInPlace(state, *fipnum);
|
|
|
|
}
|
2016-11-23 14:30:01 -06:00
|
|
|
Opm::time::StopWatch perfTimer;
|
|
|
|
perfTimer.start();
|
2015-08-02 15:26:45 -05:00
|
|
|
bool substep = true;
|
2016-09-01 04:36:25 -05:00
|
|
|
const auto& physicalModel = solver.model();
|
2018-01-16 08:50:43 -06:00
|
|
|
outputWriter->writeTimeStep( substepTimer, state, well_state, physicalModel, substep, -1.0, substepReport);
|
2016-11-23 14:30:01 -06:00
|
|
|
report.output_write_time += perfTimer.secsSinceStart();
|
2014-12-10 04:20:29 -06:00
|
|
|
}
|
2014-10-06 07:06:07 -05:00
|
|
|
|
|
|
|
// set new time step length
|
2014-12-10 04:20:29 -06:00
|
|
|
substepTimer.provideTimeStepEstimate( dtEstimate );
|
2014-10-06 07:06:07 -05:00
|
|
|
|
2014-12-10 04:20:29 -06:00
|
|
|
// update states
|
2014-10-06 07:06:07 -05:00
|
|
|
last_state = state ;
|
|
|
|
last_well_state = well_state;
|
2014-12-10 04:20:29 -06:00
|
|
|
|
2016-11-23 14:30:01 -06:00
|
|
|
report.converged = substepTimer.done();
|
2016-12-05 02:37:30 -06:00
|
|
|
substepTimer.setLastStepFailed(false);
|
2016-11-23 14:30:01 -06:00
|
|
|
|
2014-10-06 07:06:07 -05:00
|
|
|
}
|
2014-10-20 05:32:11 -05:00
|
|
|
else // in case of no convergence (linearIterations < 0)
|
2014-10-06 07:06:07 -05:00
|
|
|
{
|
2016-12-05 02:37:30 -06:00
|
|
|
substepTimer.setLastStepFailed(true);
|
2017-04-10 08:55:30 -05:00
|
|
|
|
|
|
|
failureReport_ += substepReport;
|
|
|
|
|
2014-10-06 07:06:07 -05:00
|
|
|
// increase restart counter
|
|
|
|
if( restarts >= solver_restart_max_ ) {
|
2017-04-06 07:54:08 -05:00
|
|
|
const auto msg = std::string("Solver failed to converge after cutting timestep ")
|
|
|
|
+ std::to_string(restarts) + " times.";
|
2016-10-17 06:28:43 -05:00
|
|
|
if (solver_verbose_) {
|
|
|
|
OpmLog::error(msg);
|
|
|
|
}
|
|
|
|
OPM_THROW_NOLOG(Opm::NumericalProblem, msg);
|
2014-10-06 07:06:07 -05:00
|
|
|
}
|
|
|
|
|
2014-10-10 06:55:28 -05:00
|
|
|
const double newTimeStep = restart_factor_ * dt;
|
2014-10-06 07:06:07 -05:00
|
|
|
// we need to revise this
|
2014-12-10 04:20:29 -06:00
|
|
|
substepTimer.provideTimeStepEstimate( newTimeStep );
|
2016-05-15 20:04:54 -05:00
|
|
|
if( solver_verbose_ ) {
|
2016-05-10 01:13:33 -05:00
|
|
|
std::string msg;
|
2017-06-26 05:21:44 -05:00
|
|
|
msg = cause_of_failure + "\nTimestep chopped to "
|
2017-06-11 15:32:46 -05:00
|
|
|
+ std::to_string(unit::convert::to( substepTimer.currentStepLength(), unit::day )) + " days\n";
|
2016-10-17 06:29:11 -05:00
|
|
|
OpmLog::problem(msg);
|
2016-11-23 14:30:01 -06:00
|
|
|
}
|
2014-12-10 04:20:29 -06:00
|
|
|
// reset states
|
2014-10-06 07:06:07 -05:00
|
|
|
state = last_state;
|
|
|
|
well_state = last_well_state;
|
|
|
|
|
|
|
|
++restarts;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-24 23:31:55 -05:00
|
|
|
// store estimated time step for next reportStep
|
2015-08-25 04:16:36 -05:00
|
|
|
suggested_next_timestep_ = substepTimer.currentStepLength();
|
2014-10-06 07:06:07 -05:00
|
|
|
if( timestep_verbose_ )
|
|
|
|
{
|
2016-05-10 01:13:33 -05:00
|
|
|
std::ostringstream ss;
|
2016-05-09 00:31:04 -05:00
|
|
|
substepTimer.report(ss);
|
|
|
|
ss << "Suggested next step size = " << unit::convert::to( suggested_next_timestep_, unit::day ) << " (days)" << std::endl;
|
2017-10-13 06:29:31 -05:00
|
|
|
OpmLog::debug(ss.str());
|
2014-10-06 07:06:07 -05:00
|
|
|
}
|
|
|
|
|
2015-08-25 04:16:36 -05:00
|
|
|
if( ! std::isfinite( suggested_next_timestep_ ) ) { // check for NaN
|
|
|
|
suggested_next_timestep_ = timestep;
|
2014-10-20 05:32:11 -05:00
|
|
|
}
|
2016-11-23 14:30:01 -06:00
|
|
|
return report;
|
2014-10-06 07:06:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-07 07:46:04 -05:00
|
|
|
#endif
|