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,10 +6,12 @@
|
||||
|
||||
#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
|
||||
//---------------------
|
||||
|
||||
@ -32,7 +34,38 @@ namespace Opm {
|
||||
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
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include <opm/core/simulator/SimulatorTimer.hpp>
|
||||
#include <opm/core/simulator/AdaptiveSimulatorTimer.hpp>
|
||||
#include <opm/core/simulator/PIDTimeStepControl.hpp>
|
||||
|
||||
@ -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,20 +89,20 @@ 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 );
|
||||
@ -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
|
||||
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,7 +171,7 @@ namespace Opm {
|
||||
|
||||
const double newTimeStep = restart_factor_ * dt;
|
||||
// we need to revise this
|
||||
timer.provideTimeStepEstimate( newTimeStep );
|
||||
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;
|
||||
@ -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