enabled solver restart again.

This commit is contained in:
Robert K 2014-10-03 16:01:59 +02:00
parent 9e9ef0155c
commit 2295718f59
2 changed files with 25 additions and 12 deletions

View File

@ -298,11 +298,12 @@ namespace Opm
typename FullyImplicitBlackoilSolver<T>::SolverParameter solverParam( param_ ); typename FullyImplicitBlackoilSolver<T>::SolverParameter solverParam( param_ );
// sub stepping flag, if false just the normal time steps will be used
const bool subStepping = param_.getDefault("substepping", bool(false) ); const bool subStepping = param_.getDefault("substepping", bool(false) );
// create time step control object, TODO introduce parameter // create time step control object, TODO introduce parameter
std::unique_ptr< TimeStepControlInterface > std::unique_ptr< TimeStepControlInterface >
timeStepControl( new PIDAndIterationCountTimeStepControl( 100, 1e-3 ) ); timeStepControl( new PIDAndIterationCountTimeStepControl( 50, 8e-4 ) );
// Main simulation loop. // Main simulation loop.
while (!timer.done()) { while (!timer.done()) {
@ -369,9 +370,9 @@ namespace Opm
const double end_time = start_time + timer.currentStepLength(); const double end_time = start_time + timer.currentStepLength();
AdaptiveSimulatorTimer subStepper( start_time, end_time, lastSubStep ); AdaptiveSimulatorTimer subStepper( start_time, end_time, lastSubStep );
// copy states in case solver has to be restarted // copy states in case solver has to be restarted (to be revised)
//BlackoilState last_state( state ); BlackoilState last_state( state );
//WellStateFullyImplicitBlackoil last_well_state( well_state ); WellStateFullyImplicitBlackoil last_well_state( well_state );
// sub step time loop // sub step time loop
while( ! subStepper.done() ) while( ! subStepper.done() )
@ -379,9 +380,18 @@ namespace Opm
// initialize time step control in case current state is needed later // initialize time step control in case current state is needed later
timeStepControl->initialize( state ); timeStepControl->initialize( state );
// keep last state for solver restart and time step control int linearIterations = -1;
// (linearIterations < 0 means on convergence in solver) try {
const int linearIterations = solver.step(subStepper.currentStepLength(), state, well_state); // (linearIterations < 0 means on convergence in solver)
linearIterations = solver.step(subStepper.currentStepLength(), state, well_state);
// report number of linear iterations
std::cout << "Overall linear iterations used: " << linearIterations << std::endl;
}
catch (Opm::NumericalProblem)
{
// since linearIterations is < 0 this will restart the solver
}
// (linearIterations < 0 means on convergence in solver) // (linearIterations < 0 means on convergence in solver)
if( linearIterations >= 0 ) if( linearIterations >= 0 )
@ -396,16 +406,19 @@ namespace Opm
// set new time step length // set new time step length
subStepper.provideTimeStepEstimate( dtEstimate ); subStepper.provideTimeStepEstimate( dtEstimate );
// update states
last_state = state ;
last_well_state = well_state;
} }
else // in case of no convergence else // in case of no convergence
{ {
// we need to revise this // we need to revise this
abort(); subStepper.provideTimeStepEstimate( 0.1 * subStepper.currentStepLength() );
subStepper.halfTimeStep();
std::cerr << "Solver convergence failed, restarting solver with half time step ("<< subStepper.currentStepLength()<<" days)." << std::endl; std::cerr << "Solver convergence failed, restarting solver with half time step ("<< subStepper.currentStepLength()<<" days)." << std::endl;
// reset states // reset states
// state = last_state; state = last_state;
// well_state = last_well_state; well_state = last_well_state;
} }
} }

View File

@ -137,7 +137,7 @@ namespace Opm
const double kD = 0.01 ; const double kD = 0.01 ;
double newDt = (dt * std::pow( errors_[ 1 ] / errors_[ 2 ], kP ) * double newDt = (dt * std::pow( errors_[ 1 ] / errors_[ 2 ], kP ) *
std::pow( tol_ / errors_[ 2 ], kI ) * std::pow( tol_ / errors_[ 2 ], kI ) *
std::pow( (errors_[0]*errors_[0]/errors_[ 1 ]*errors_[ 2 ]), kD )); std::pow( errors_[0]*errors_[0]/errors_[ 1 ]/errors_[ 2 ], kD ));
if( verbose_ ) if( verbose_ )
std::cout << "Computed step size (pow): " << newDt/86400.0 << " (days)" << std::endl; std::cout << "Computed step size (pow): " << newDt/86400.0 << " (days)" << std::endl;
return newDt; return newDt;