mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
EclipseWriter: allow for writing of substeps in addition to report steps.
This commit is contained in:
parent
1c5e4e9ef3
commit
aa9fe2a631
@ -6,33 +6,66 @@
|
||||
|
||||
#include <opm/core/utility/parameters/ParameterGroup.hpp>
|
||||
#include <opm/core/utility/ErrorMacros.hpp>
|
||||
#include <opm/core/simulator/SimulatorTimer.hpp>
|
||||
#include <opm/core/simulator/TimeStepControlInterface.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
// AdaptiveTimeStepping
|
||||
|
||||
// AdaptiveTimeStepping
|
||||
//---------------------
|
||||
|
||||
|
||||
class AdaptiveTimeStepping
|
||||
{
|
||||
public:
|
||||
public:
|
||||
//! \brief contructor taking parameter object
|
||||
AdaptiveTimeStepping( const parameter::ParameterGroup& param );
|
||||
|
||||
/** \brief step method that acts like the solver::step method
|
||||
in a sub cycle of time steps
|
||||
|
||||
in a sub cycle of time steps
|
||||
|
||||
\param solver solver object that must implement a method step( dt, state, well_state )
|
||||
\param state current state of the solution variables
|
||||
\param state current state of the solution variables
|
||||
\param well_state additional well state object
|
||||
\param time current simulation time
|
||||
\param timestep current time step length that is to be sub cycled
|
||||
*/
|
||||
\param timestep current time step length that is to be sub cycled
|
||||
*/
|
||||
template <class Solver, class State, class WellState>
|
||||
void step( Solver& solver, State& state, WellState& well_state,
|
||||
const double time, const double timestep );
|
||||
|
||||
/** \brief step method that acts like the solver::step method
|
||||
in a sub cycle of time steps
|
||||
|
||||
\param timer simulator timer providing time and timestep
|
||||
\param solver solver object that must implement a method step( dt, state, well_state )
|
||||
\param state current state of the solution variables
|
||||
\param well_state additional well state object
|
||||
*/
|
||||
template <class Solver, class State, class WellState>
|
||||
void step( const SimulatorTimer& timer,
|
||||
Solver& solver, State& state, WellState& well_state );
|
||||
|
||||
/** \brief step method that acts like the solver::step method
|
||||
in a sub cycle of time steps
|
||||
|
||||
\param timer simulator timer providing time and timestep
|
||||
\param solver solver object that must implement a method step( dt, state, well_state )
|
||||
\param state current state of the solution variables
|
||||
\param well_state additional well state object
|
||||
\param outputWriter writer object to write sub steps
|
||||
*/
|
||||
template <class Solver, class State, class WellState>
|
||||
void step( const SimulatorTimer& timer,
|
||||
Solver& solver, State& state, WellState& well_state,
|
||||
OutputWriter& outputWriter );
|
||||
|
||||
protected:
|
||||
template <class Solver, class State, class WellState>
|
||||
void stepImpl( Solver& solver, State& state, WellState& well_state,
|
||||
const double time, const double timestep,
|
||||
const SimulatorTimer* timer, OutputWriter* outputWriter);
|
||||
|
||||
typedef std::unique_ptr< TimeStepControlInterface > TimeStepControlType;
|
||||
|
||||
TimeStepControlType timeStepControl_; //!< time step control object
|
||||
@ -40,8 +73,8 @@ namespace Opm {
|
||||
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
|
||||
const bool solver_verbose_; //!< solver verbosity
|
||||
const bool timestep_verbose_; //!< timestep verbosity
|
||||
double last_timestep_; //!< size of last timestep
|
||||
};
|
||||
}
|
||||
|
@ -5,15 +5,16 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include <opm/core/simulator/SimulatorTimer.hpp>
|
||||
#include <opm/core/simulator/AdaptiveSimulatorTimer.hpp>
|
||||
#include <opm/core/simulator/PIDTimeStepControl.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
// AdaptiveTimeStepping
|
||||
// AdaptiveTimeStepping
|
||||
//---------------------
|
||||
|
||||
AdaptiveTimeStepping::AdaptiveTimeStepping( const parameter::ParameterGroup& param )
|
||||
|
||||
AdaptiveTimeStepping::AdaptiveTimeStepping( const parameter::ParameterGroup& param )
|
||||
: timeStepControl_()
|
||||
, initial_fraction_( param.getDefault("solver.initialfraction", double(0.25) ) )
|
||||
, restart_factor_( param.getDefault("solver.restartfactor", double(0.1) ) )
|
||||
@ -25,17 +26,17 @@ namespace Opm {
|
||||
{
|
||||
// valid are "pid" and "pid+iteration"
|
||||
std::string control = param.getDefault("timestep.control", std::string("pid") );
|
||||
|
||||
|
||||
const double tol = param.getDefault("timestep.control.tol", double(1e-3) );
|
||||
if( control == "pid" ) {
|
||||
timeStepControl_ = TimeStepControlType( new PIDTimeStepControl( tol ) );
|
||||
}
|
||||
else if ( control == "pid+iteration" )
|
||||
else if ( control == "pid+iteration" )
|
||||
{
|
||||
const int iterations = param.getDefault("timestep.control.targetiteration", int(25) );
|
||||
timeStepControl_ = TimeStepControlType( new PIDAndIterationCountTimeStepControl( iterations, tol ) );
|
||||
}
|
||||
else
|
||||
else
|
||||
OPM_THROW(std::runtime_error,"Unsupported time step control selected "<< control );
|
||||
|
||||
// make sure growth factor is something reasonable
|
||||
@ -43,10 +44,44 @@ namespace Opm {
|
||||
}
|
||||
|
||||
|
||||
template <class Solver, class State, class WellState>
|
||||
void AdaptiveTimeStepping::
|
||||
step( const SimulatorTimer& simulatorTimer, Solver& solver, State& state, WellState& well_state )
|
||||
{
|
||||
const double time = simulatorTimer.simulationTimeElapsed();
|
||||
const double timestep = simulatorTimer.currentStepLength();
|
||||
|
||||
step( solver, state, well_state, time, timestep );
|
||||
}
|
||||
|
||||
template <class Solver, class State, class WellState>
|
||||
void AdaptiveTimeStepping::
|
||||
step( const SimulatorTimer& simulatorTimer, Solver& solver, State& state, WellState& well_state,
|
||||
OutputWriter& outputWriter )
|
||||
{
|
||||
const double time = simulatorTimer.simulationTimeElapsed();
|
||||
const double timestep = simulatorTimer.currentStepLength();
|
||||
|
||||
stepImpl( solver, state, well_state, time, timestep, &simulatorTimer, &outputWriter );
|
||||
}
|
||||
|
||||
// implementation of the step method
|
||||
template <class Solver, class State, class WellState>
|
||||
void AdaptiveTimeStepping::
|
||||
step( Solver& solver, State& state, WellState& well_state,
|
||||
const double time, const double timestep )
|
||||
{
|
||||
stepImpl( solver, state, well_state, time, timestep,
|
||||
(SimulatorTimer *) 0, (OutputWriter *) 0 );
|
||||
}
|
||||
|
||||
// implementation of the step method
|
||||
template <class Solver, class State, class WState>
|
||||
void AdaptiveTimeStepping::
|
||||
stepImpl( Solver& solver, State& state, WState& well_state,
|
||||
const double time, const double timestep,
|
||||
const SimulatorTimer* simulatorTimer,
|
||||
OutputWriter* outputWriter )
|
||||
{
|
||||
// init last time step as a fraction of the given time step
|
||||
if( last_timestep_ < 0 ) {
|
||||
@ -54,26 +89,26 @@ namespace Opm {
|
||||
}
|
||||
|
||||
// create adaptive step timer with previously used sub step size
|
||||
AdaptiveSimulatorTimer timer( time, time+timestep, last_timestep_ );
|
||||
AdaptiveSimulatorTimer substepTimer( time, time+timestep, last_timestep_ );
|
||||
|
||||
// copy states in case solver has to be restarted (to be revised)
|
||||
State last_state( state );
|
||||
WellState last_well_state( well_state );
|
||||
State last_state( state );
|
||||
WState last_well_state( well_state );
|
||||
|
||||
// counter for solver restarts
|
||||
int restarts = 0;
|
||||
|
||||
// sub step time loop
|
||||
while( ! timer.done() )
|
||||
while( ! substepTimer.done() )
|
||||
{
|
||||
// get current delta t
|
||||
const double dt = timer.currentStepLength() ;
|
||||
const double dt = substepTimer.currentStepLength() ;
|
||||
|
||||
// initialize time step control in case current state is needed later
|
||||
timeStepControl_->initialize( state );
|
||||
|
||||
int linearIterations = -1;
|
||||
try {
|
||||
try {
|
||||
// (linearIterations < 0 means on convergence in solver)
|
||||
linearIterations = solver.step( dt, state, well_state);
|
||||
|
||||
@ -95,7 +130,7 @@ namespace Opm {
|
||||
if( linearIterations >= 0 )
|
||||
{
|
||||
// advance by current dt
|
||||
++timer;
|
||||
++substepTimer;
|
||||
|
||||
// compute new time step estimate
|
||||
double dtEstimate =
|
||||
@ -109,14 +144,23 @@ namespace Opm {
|
||||
}
|
||||
|
||||
if( timestep_verbose_ )
|
||||
{
|
||||
std::cout << "Substep[ " << substepTimer.currentStepNum() << " ] " << unit::convert::to(substepTimer.simulationTimeElapsed(),unit::day) << std::endl;
|
||||
std::cout << "Suggested time step size = " << unit::convert::to(dtEstimate, unit::day) << " (days)" << std::endl;
|
||||
}
|
||||
|
||||
// set new time step length
|
||||
timer.provideTimeStepEstimate( dtEstimate );
|
||||
substepTimer.provideTimeStepEstimate( dtEstimate );
|
||||
|
||||
// update states
|
||||
// update states
|
||||
last_state = state ;
|
||||
last_well_state = well_state;
|
||||
|
||||
// write data if outputWriter was provided
|
||||
if( outputWriter ) {
|
||||
assert( simulatorTimer );
|
||||
outputWriter->writeTimeStep( *simulatorTimer, substepTimer, state, well_state );
|
||||
}
|
||||
}
|
||||
else // in case of no convergence (linearIterations < 0)
|
||||
{
|
||||
@ -127,12 +171,12 @@ namespace Opm {
|
||||
|
||||
const double newTimeStep = restart_factor_ * dt;
|
||||
// we need to revise this
|
||||
timer.provideTimeStepEstimate( newTimeStep );
|
||||
if( solver_verbose_ )
|
||||
substepTimer.provideTimeStepEstimate( newTimeStep );
|
||||
if( solver_verbose_ )
|
||||
std::cerr << "Solver convergence failed, restarting solver with new time step ("
|
||||
<< unit::convert::to( newTimeStep, unit::day ) <<" days)." << std::endl;
|
||||
|
||||
// reset states
|
||||
// reset states
|
||||
state = last_state;
|
||||
well_state = last_well_state;
|
||||
|
||||
@ -142,10 +186,10 @@ namespace Opm {
|
||||
|
||||
|
||||
// store last small time step for next reportStep
|
||||
last_timestep_ = timer.suggestedAverage();
|
||||
last_timestep_ = substepTimer.suggestedAverage();
|
||||
if( timestep_verbose_ )
|
||||
{
|
||||
timer.report( std::cout );
|
||||
substepTimer.report( std::cout );
|
||||
std::cout << "Last suggested step size = " << unit::convert::to( last_timestep_, unit::day ) << " (days)" << std::endl;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user