From 10cffa770bac55ba17c30eb6814ad066bafab918 Mon Sep 17 00:00:00 2001 From: Robert K Date: Wed, 10 Dec 2014 11:20:29 +0100 Subject: [PATCH 1/5] EclipseWriter: allow for writing of substeps in addition to report steps. --- opm/core/io/OutputWriter.cpp | 9 ++ opm/core/io/OutputWriter.hpp | 21 +++- opm/core/io/eclipse/EclipseWriter.cpp | 107 ++++++++++++++---- opm/core/io/eclipse/EclipseWriter.hpp | 35 +++++- opm/core/simulator/AdaptiveTimeStepping.hpp | 53 +++++++-- .../simulator/AdaptiveTimeStepping_impl.hpp | 84 ++++++++++---- 6 files changed, 254 insertions(+), 55 deletions(-) diff --git a/opm/core/io/OutputWriter.cpp b/opm/core/io/OutputWriter.cpp index fcdc2b5d..4c7e25ca 100644 --- a/opm/core/io/OutputWriter.cpp +++ b/opm/core/io/OutputWriter.cpp @@ -40,6 +40,15 @@ struct MultiWriter : public OutputWriter { } } + virtual void writeTimeStep(const SimulatorTimer& timer, + const AdaptiveSimulatorTimer& substepTimer, + const SimulatorState& reservoirState, + const WellState& wellState) { + for (it_t it = writers_->begin (); it != writers_->end(); ++it) { + (*it)->writeTimeStep (timer, substepTimer, reservoirState, wellState); + } + } + private: ptr_t writers_; }; diff --git a/opm/core/io/OutputWriter.hpp b/opm/core/io/OutputWriter.hpp index 84d2591b..c4d71c79 100644 --- a/opm/core/io/OutputWriter.hpp +++ b/opm/core/io/OutputWriter.hpp @@ -31,6 +31,7 @@ class EclipseState; namespace parameter { class ParameterGroup; } class SimulatorState; class SimulatorTimer; +class AdaptiveSimulatorTimer; class WellState; struct PhaseUsage; @@ -79,8 +80,9 @@ public: * \brief Write a blackoil reservoir state to disk for later inspection with * visualization tools like ResInsight * + * \param[in] timer The timer providing time, time step, etc. information * \param[in] reservoirState The thermodynamic state of the reservoir - * \param[in] wellState The production/injection data for all wells + * \param[in] wellState The production/injection data for all wells * * This routine should be called after the timestep has been advanced, * i.e. timer.currentStepNum () > 0. @@ -89,6 +91,23 @@ public: const SimulatorState& reservoirState, const WellState& wellState) = 0; + /*! + * \brief Write a blackoil reservoir state to disk for later inspection with + * visualization tools like ResInsight + * + * \param[in] timer The timer providing time, time step, etc. information + * \param[in] subStepTimer The timer providing sub step time information + * \param[in] reservoirState The thermodynamic state of the reservoir + * \param[in] wellState The production/injection data for all wells + * + * This routine should be called after the timestep has been advanced, + * i.e. timer.currentStepNum () > 0. + */ + virtual void writeTimeStep(const SimulatorTimer& timer, + const AdaptiveSimulatorTimer& subStepTimer, + const SimulatorState& reservoirState, + const WellState& wellState) = 0; + /*! * Create a suitable set of output formats based on configuration. * diff --git a/opm/core/io/eclipse/EclipseWriter.cpp b/opm/core/io/eclipse/EclipseWriter.cpp index 3e7aac62..1e9d56a4 100644 --- a/opm/core/io/eclipse/EclipseWriter.cpp +++ b/opm/core/io/eclipse/EclipseWriter.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -125,6 +126,38 @@ int ertPhaseMask(const PhaseUsage uses) } +// wrapper class to make EclipseWriter work with either the SimulatorTimer or a +// combination of SimulatorTimer and AdaptiveSimulatorTimer. +struct WriterTimer +{ + const double time_; + const double stepLength_; + const time_t posixTime_; + const int deckReportStep_; + + // copy values from SimulatorTimer + WriterTimer( const SimulatorTimer& timer ) + : time_( timer.simulationTimeElapsed() ), + stepLength_( timer.stepLengthTaken() ), + posixTime_( timer.currentPosixTime() ), + deckReportStep_( timer.currentStepNum() ) + {} + + // copy values from SimulatorTimer and add values from + // AdaptiveSimulatorTimer, except the deck's reportStep + WriterTimer( const SimulatorTimer& timer, const AdaptiveSimulatorTimer& subStepTimer ) + : time_( subStepTimer.simulationTimeElapsed() ), + stepLength_( subStepTimer.currentStepLength() ), + posixTime_( timer.currentPosixTime() + time_t(time_ - timer.simulationTimeElapsed()) ), + deckReportStep_( timer.currentStepNum() ) + {} + + int deckReportStep () const { return deckReportStep_; } + double simulationTimeElapsed() const { return time_; } + /// time elapsed since the start of the POSIX epoch (Jan 1st, 1970) [s]. + time_t currentPosixTime() const { return posixTime_; } + double stepLengthTaken () const { return stepLength_; } +}; /** @@ -372,7 +405,7 @@ public: ecl_rst_file_close(restartFileHandle_); } - void writeHeader(const SimulatorTimer& timer, + void writeHeader(const WriterTimer& timer, int reportStepIdx, ecl_rsthead_type * rsthead_data) { @@ -427,7 +460,7 @@ class Summary : private boost::noncopyable public: Summary(const std::string& outputDir, const std::string& baseName, - const SimulatorTimer& timer, + const WriterTimer& timer, int nx, int ny, int nz) @@ -464,7 +497,7 @@ public: void addAllWells(Opm::EclipseStateConstPtr eclipseState, const PhaseUsage& uses); void writeTimeStep(int reportStepIdx, - const SimulatorTimer& timer, + const WriterTimer& timer, const WellState& wellState); ecl_sum_type *ertHandle() const @@ -482,7 +515,7 @@ class SummaryTimeStep : private boost::noncopyable public: SummaryTimeStep(Summary& summaryHandle, int reportStepIdx, - const SimulatorTimer &timer) + const WriterTimer &timer) { ertHandle_ = ecl_sum_add_tstep(summaryHandle.ertHandle(), reportStepIdx, @@ -537,7 +570,7 @@ public: void writeHeader(int numCells, const int* compressedToCartesianCellIdx, - const SimulatorTimer& timer, + const WriterTimer& timer, Opm::EclipseStateConstPtr eclipseState, const PhaseUsage uses) { @@ -621,7 +654,8 @@ protected: public: /// Retrieve the value which the monitor is supposed to write to the summary file /// according to the state of the well. - virtual double retrieveValue(const SimulatorTimer& timer, + virtual double retrieveValue(const int reportStepIdx, + const WriterTimer& timer, const WellState& wellState, const std::map& nameToIdxMap) = 0; @@ -752,7 +786,8 @@ public: "SM3/DAY" /* surf. cub. m. per day */) { } - virtual double retrieveValue(const SimulatorTimer& timer, + virtual double retrieveValue(const int reportStepIdx, + const WriterTimer& timer, const WellState& wellState, const std::map& wellNameToIdxMap) { @@ -763,7 +798,7 @@ public: return 0.0; } - if (well_->getStatus(timer.currentStepNum()) == WellCommon::SHUT) { + if (well_->getStatus(timer.deckReportStep()) == WellCommon::SHUT) { // well is shut in the current time step return 0.0; } @@ -797,17 +832,18 @@ public: , total_(0.) { } - virtual double retrieveValue(const SimulatorTimer& timer, + virtual double retrieveValue(const int reportStepIdx, + const WriterTimer& timer, const WellState& wellState, const std::map& wellNameToIdxMap) { - if (timer.currentStepNum() == 0) { + if (reportStepIdx == 0) { // We are at the initial state. // No step has been taken yet. return 0.0; } - if (well_->getStatus(timer.currentStepNum()) == WellCommon::SHUT) { + if (well_->getStatus(timer.deckReportStep()) == WellCommon::SHUT) { // well is shut in the current time step return 0.0; } @@ -855,7 +891,8 @@ public: "Pascal") { } - virtual double retrieveValue(const SimulatorTimer& timer, + virtual double retrieveValue(const int reportStepIdx, + const WriterTimer& timer, const WellState& wellState, const std::map& wellNameToIdxMap) { @@ -865,7 +902,7 @@ public: // well not active in current time step return 0.0; } - if (well_->getStatus(timer.currentStepNum()) == WellCommon::SHUT) { + if (well_->getStatus(timer.deckReportStep()) == WellCommon::SHUT) { // well is shut in the current time step return 0.0; } @@ -877,16 +914,16 @@ public: // no inline implementation of this since it depends on the // WellReport type being completed first void Summary::writeTimeStep(int reportStepIdx, - const SimulatorTimer& timer, + const WriterTimer& timer, const WellState& wellState) { // create a name -> well index map const Opm::ScheduleConstPtr schedule = eclipseState_->getSchedule(); - const auto& timeStepWells = schedule->getWells(reportStepIdx); + const auto& timeStepWells = schedule->getWells(timer.deckReportStep()); std::map wellNameToIdxMap; int openWellIdx = 0; for (size_t tsWellIdx = 0; tsWellIdx < timeStepWells.size(); ++tsWellIdx) { - if (timeStepWells[tsWellIdx]->getStatus(timer.currentStepNum()) != WellCommon::SHUT ) { + if (timeStepWells[tsWellIdx]->getStatus(timer.deckReportStep()) != WellCommon::SHUT ) { wellNameToIdxMap[timeStepWells[tsWellIdx]->name()] = openWellIdx; openWellIdx++; } @@ -898,7 +935,7 @@ void Summary::writeTimeStep(int reportStepIdx, for (auto varIt = summaryReportVars_.begin(); varIt != summaryReportVars_.end(); ++varIt) { ecl_sum_tstep_iset(tstep.ertHandle(), smspec_node_get_params_index((*varIt)->ertHandle()), - (*varIt)->retrieveValue(timer, wellState, wellNameToIdxMap)); + (*varIt)->retrieveValue(reportStepIdx, timer, wellState, wellNameToIdxMap)); } // write the summary file to disk @@ -1014,6 +1051,12 @@ int EclipseWriter::eclipseWellStatusMask(WellCommon::StatusEnum wellStatus) void EclipseWriter::writeInit(const SimulatorTimer &timer) +{ + EclipseWriterDetails::WriterTimer writerTimer( timer ); + writeInit( writerTimer ); +} + +void EclipseWriter::writeInit(const EclipseWriterDetails::WriterTimer &timer) { // if we don't want to write anything, this method becomes a // no-op... @@ -1062,6 +1105,24 @@ void EclipseWriter::writeInit(const SimulatorTimer &timer) void EclipseWriter::writeTimeStep(const SimulatorTimer& timer, const SimulatorState& reservoirState, const WellState& wellState) +{ + EclipseWriterDetails::WriterTimer writerTimer ( timer ); + writeTimeStep( writerTimer, reservoirState, wellState ); +} + +void EclipseWriter::writeTimeStep(const SimulatorTimer& timer, + const AdaptiveSimulatorTimer& subStepTimer, + const SimulatorState& reservoirState, + const WellState& wellState) +{ + EclipseWriterDetails::WriterTimer writerTimer ( timer, subStepTimer ); + writeTimeStep( writerTimer, reservoirState, wellState ); +} + +// implementation of the writeTimeStep method +void EclipseWriter::writeTimeStep(const EclipseWriterDetails::WriterTimer& timer, + const SimulatorState& reservoirState, + const WellState& wellState) { // if we don't want to write anything, this method becomes a // no-op... @@ -1075,7 +1136,7 @@ void EclipseWriter::writeTimeStep(const SimulatorTimer& timer, } - std::vector wells_ptr = eclipseState_->getSchedule()->getWells(timer.currentStepNum()); + std::vector wells_ptr = eclipseState_->getSchedule()->getWells(timer.deckReportStep()); std::vector iwell_data; std::vector zwell_data; std::vector icon_data; @@ -1086,7 +1147,7 @@ void EclipseWriter::writeTimeStep(const SimulatorTimer& timer, rsthead_data.nx = cartesianSize_[0]; rsthead_data.ny = cartesianSize_[1]; rsthead_data.nz = cartesianSize_[2]; - rsthead_data.nwells = eclipseState_->getSchedule()->numWells(timer.currentStepNum()); + rsthead_data.nwells = eclipseState_->getSchedule()->numWells(timer.deckReportStep()); rsthead_data.niwelz = 0; rsthead_data.nzwelz = 0; rsthead_data.niconz = 0; @@ -1098,10 +1159,10 @@ void EclipseWriter::writeTimeStep(const SimulatorTimer& timer, for (std::vector::const_iterator c_iter = wells_ptr.begin(); c_iter != wells_ptr.end(); ++c_iter) { WellConstPtr well_ptr = *c_iter; - rsthead_data.ncwmax = eclipseState_->getSchedule()->getMaxNumCompletionsForWells(timer.currentStepNum()); - restartHandle.addRestartFileIwelData(iwell_data, timer.currentStepNum(), well_ptr); - restartHandle.addRestartFileZwelData(zwell_data, timer.currentStepNum(), well_ptr); - restartHandle.addRestartFileIconData(icon_data, timer.currentStepNum(), rsthead_data.ncwmax, well_ptr); + rsthead_data.ncwmax = eclipseState_->getSchedule()->getMaxNumCompletionsForWells(timer.deckReportStep()); + restartHandle.addRestartFileIwelData(iwell_data, timer.deckReportStep(), well_ptr); + restartHandle.addRestartFileZwelData(zwell_data, timer.deckReportStep(), well_ptr); + restartHandle.addRestartFileIconData(icon_data, timer.deckReportStep(), rsthead_data.ncwmax, well_ptr); rsthead_data.niwelz = EclipseWriterDetails::Restart::NIWELZ; rsthead_data.nzwelz = EclipseWriterDetails::Restart::NZWELZ; diff --git a/opm/core/io/eclipse/EclipseWriter.hpp b/opm/core/io/eclipse/EclipseWriter.hpp index 5e715274..c9cdc3b0 100644 --- a/opm/core/io/eclipse/EclipseWriter.hpp +++ b/opm/core/io/eclipse/EclipseWriter.hpp @@ -1,6 +1,7 @@ /* Copyright (c) 2013 Andreas Lauser Copyright (c) 2013 Uni Research AS + Copyright (c) 2014 IRIS AS This file is part of the Open Porous Media project (OPM). @@ -39,10 +40,12 @@ namespace Opm { // forward declarations namespace EclipseWriterDetails { class Summary; +struct WriterTimer; } class SimulatorState; class SimulatorTimer; +class AdaptiveSimulatorTimer; class WellState; namespace parameter { class ParameterGroup; } @@ -91,13 +94,36 @@ public: * ERT or ECLIPSE. Note that calling this method is only * meaningful after the first time step has been completed. * + * \param[in] timer The timer providing time step and time information * \param[in] reservoirState The thermodynamic state of the reservoir - * \param[in] wellState The production/injection data for all wells + * \param[in] wellState The production/injection data for all wells */ virtual void writeTimeStep(const SimulatorTimer& timer, const SimulatorState& reservoirState, const WellState& wellState); + + /*! + * \brief Write a reservoir state and summary information to disk. + * + * + * The reservoir state can be inspected with visualization tools like + * ResInsight. + * + * The summary information can then be visualized using tools from + * ERT or ECLIPSE. Note that calling this method is only + * meaningful after the first time step has been completed. + * + * \param[in] timer The timer providing time step and time information + * \param[in] subStepTimer The timer providing sub step information + * \param[in] reservoirState The thermodynamic state of the reservoir + * \param[in] wellState The production/injection data for all wells + */ + virtual void writeTimeStep(const SimulatorTimer& timer, + const AdaptiveSimulatorTimer& subStepTimer, + const SimulatorState& reservoirState, + const WellState& wellState); + static int eclipseWellTypeMask(WellType wellType, WellInjector::TypeEnum injectorType); static int eclipseWellStatusMask(WellCommon::StatusEnum wellStatus); @@ -117,6 +143,13 @@ private: std::shared_ptr summary_; void init(const parameter::ParameterGroup& params); + // implementation of writeInit + void writeInit(const EclipseWriterDetails::WriterTimer &timer); + // implementation of writeTimeStep + void writeTimeStep(const EclipseWriterDetails::WriterTimer& timer, + const SimulatorState& reservoirState, + const WellState& wellState); + }; typedef std::shared_ptr EclipseWriterPtr; diff --git a/opm/core/simulator/AdaptiveTimeStepping.hpp b/opm/core/simulator/AdaptiveTimeStepping.hpp index e73790db..0b1af84b 100644 --- a/opm/core/simulator/AdaptiveTimeStepping.hpp +++ b/opm/core/simulator/AdaptiveTimeStepping.hpp @@ -6,33 +6,66 @@ #include #include +#include #include 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 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 + 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 + void step( const SimulatorTimer& timer, + Solver& solver, State& state, WellState& well_state, + OutputWriter& outputWriter ); + protected: + template + 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 }; } diff --git a/opm/core/simulator/AdaptiveTimeStepping_impl.hpp b/opm/core/simulator/AdaptiveTimeStepping_impl.hpp index 8e1bdda4..4ec083df 100644 --- a/opm/core/simulator/AdaptiveTimeStepping_impl.hpp +++ b/opm/core/simulator/AdaptiveTimeStepping_impl.hpp @@ -5,15 +5,16 @@ #include #include +#include #include #include 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 + 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 + 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 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 + 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; } From 4d1a2ad9180a3847cc26fa2782dbc24af8b2dbc1 Mon Sep 17 00:00:00 2001 From: Robert K Date: Thu, 8 Jan 2015 12:06:37 +0100 Subject: [PATCH 2/5] Introduce an interface for SimulatorTimer and AdaptiveSimulatorTimer. currentDateTime and currentPosixTime are default implementations. --- CMakeLists_files.cmake | 1 + opm/core/simulator/AdaptiveSimulatorTimer.cpp | 28 +++++- opm/core/simulator/AdaptiveSimulatorTimer.hpp | 23 ++++- opm/core/simulator/SimulatorTimer.cpp | 12 +-- opm/core/simulator/SimulatorTimer.hpp | 19 ++-- .../simulator/SimulatorTimerInterface.hpp | 95 +++++++++++++++++++ 6 files changed, 148 insertions(+), 30 deletions(-) create mode 100644 opm/core/simulator/SimulatorTimerInterface.hpp diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index 3a1ce398..149f73f9 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -367,6 +367,7 @@ list (APPEND PUBLIC_HEADER_FILES opm/core/simulator/SimulatorOutput.hpp opm/core/simulator/SimulatorReport.hpp opm/core/simulator/SimulatorState.hpp + opm/core/simulator/SimulatorTimerInterface.hpp opm/core/simulator/SimulatorTimer.hpp opm/core/simulator/TimeStepControlInterface.hpp opm/core/simulator/TwophaseState.hpp diff --git a/opm/core/simulator/AdaptiveSimulatorTimer.cpp b/opm/core/simulator/AdaptiveSimulatorTimer.cpp index 576e4fae..72add45a 100644 --- a/opm/core/simulator/AdaptiveSimulatorTimer.cpp +++ b/opm/core/simulator/AdaptiveSimulatorTimer.cpp @@ -1,5 +1,5 @@ /* - Copyright 2014 IRIS AS + Copyright (c) 2014 IRIS AS This file is part of the Open Porous Media project (OPM). @@ -30,11 +30,13 @@ namespace Opm { AdaptiveSimulatorTimer:: - AdaptiveSimulatorTimer( const double start_time, const double total_time, const double lastDt ) - : start_time_( start_time ) - , total_time_( total_time ) + AdaptiveSimulatorTimer( const SimulatorTimerInterface& timer, const double lastStepTaken ) + : start_date_( timer.startDate() ) + , start_time_( timer.simulationTimeElapsed() ) + , total_time_( start_time_ + timer.currentStepLength() ) + , report_step_( timer.reportStepNum() ) , current_time_( start_time_ ) - , dt_( computeInitialTimeStep( lastDt ) ) + , dt_( computeInitialTimeStep( lastStepTaken ) ) , current_step_( 0 ) , steps_() , suggestedMax_( 0.0 ) @@ -86,12 +88,23 @@ namespace Opm int AdaptiveSimulatorTimer:: currentStepNum () const { return current_step_; } + int AdaptiveSimulatorTimer:: + reportStepNum () const { return report_step_; } + double AdaptiveSimulatorTimer::currentStepLength () const { assert( ! done () ); return dt_; } + double AdaptiveSimulatorTimer::stepLengthTaken() const + { + assert( ! steps_.empty() ); + return *(steps_.rbegin()); + } + + + double AdaptiveSimulatorTimer::totalTime() const { return total_time_; } double AdaptiveSimulatorTimer::simulationTimeElapsed() const { return current_time_; } @@ -143,6 +156,11 @@ namespace Opm std::cout << "sub steps end time = " << unit::convert::to( simulationTimeElapsed(), unit::day ) << " (days)" << std::endl; } + boost::gregorian::date AdaptiveSimulatorTimer::startDate() const + { + return start_date_; + } + double AdaptiveSimulatorTimer:: computeInitialTimeStep( const double lastDt ) const { diff --git a/opm/core/simulator/AdaptiveSimulatorTimer.hpp b/opm/core/simulator/AdaptiveSimulatorTimer.hpp index 3336a69c..9958f4c9 100644 --- a/opm/core/simulator/AdaptiveSimulatorTimer.hpp +++ b/opm/core/simulator/AdaptiveSimulatorTimer.hpp @@ -27,6 +27,8 @@ #include #include +#include + namespace Opm { @@ -35,14 +37,12 @@ namespace Opm /// \brief Simulation timer for adaptive time stepping /// ///////////////////////////////////////////////////////// - class AdaptiveSimulatorTimer + class AdaptiveSimulatorTimer : public SimulatorTimerInterface { public: /// \brief constructor taking a simulator timer to determine start and end time - /// \param start_time start time of timer - /// \param total_time total time of timer - /// \param lastDt last suggested length of time step interval - AdaptiveSimulatorTimer( const double start_time, const double total_time, const double lastDt ); + /// \param timer in case of sub stepping this is the outer timer + explicit AdaptiveSimulatorTimer( const SimulatorTimerInterface& timer, const double lastStepTaken ); /// \brief advance time by currentStepLength AdaptiveSimulatorTimer& operator++ (); @@ -53,6 +53,9 @@ namespace Opm /// \brief \copydoc SimulationTimer::currentStepNum int currentStepNum () const; + /// \brief return current report step + int reportStepNum() const; + /// \brief \copydoc SimulationTimer::currentStepLength double currentStepLength () const; @@ -80,12 +83,22 @@ namespace Opm /// \brief return average suggested step length double suggestedAverage () const; + /// \brief Previous step length. This is the length of the step that + /// was taken to arrive at this time. + double stepLengthTaken () const; + /// \brief report start and end time as well as used steps so far void report(std::ostream& os) const; + /// \brief start date of simulation + boost::gregorian::date startDate() const; + protected: + const boost::gregorian::date start_date_; const double start_time_; const double total_time_; + const int report_step_; + double current_time_; double dt_; int current_step_; diff --git a/opm/core/simulator/SimulatorTimer.cpp b/opm/core/simulator/SimulatorTimer.cpp index add8b738..a7e368d1 100644 --- a/opm/core/simulator/SimulatorTimer.cpp +++ b/opm/core/simulator/SimulatorTimer.cpp @@ -100,19 +100,11 @@ namespace Opm return current_time_; } - /// time elapsed since the start of the POSIX epoch (Jan 1st, 1970) [s]. - time_t SimulatorTimer::currentPosixTime() const + boost::gregorian::date SimulatorTimer::startDate() const { - tm t = boost::posix_time::to_tm(currentDateTime()); - return std::mktime(&t); + return start_date_; } - boost::posix_time::ptime SimulatorTimer::currentDateTime() const - { - return boost::posix_time::ptime(start_date_) + boost::posix_time::seconds( (int) current_time_ ); - } - - /// Total time. double SimulatorTimer::totalTime() const diff --git a/opm/core/simulator/SimulatorTimer.hpp b/opm/core/simulator/SimulatorTimer.hpp index 61faef09..5c933935 100644 --- a/opm/core/simulator/SimulatorTimer.hpp +++ b/opm/core/simulator/SimulatorTimer.hpp @@ -21,20 +21,23 @@ #define OPM_SIMULATORTIMER_HEADER_INCLUDED #include +#include #include #include -#include -#include namespace Opm { namespace parameter { class ParameterGroup; } - class SimulatorTimer + class SimulatorTimer : public SimulatorTimerInterface { public: + // use default implementation of these methods + using SimulatorTimerInterface::currentDateTime; + using SimulatorTimerInterface::currentPosixTime; + /// Default constructor. SimulatorTimer(); @@ -72,20 +75,16 @@ namespace Opm /// it is an error to call stepLengthTaken(). double stepLengthTaken () const; - /// Time elapsed since the start of the POSIX epoch (Jan 1st, - /// 1970) until the current time step begins [s]. - time_t currentPosixTime() const; - /// Time elapsed since the start of the simulation until the /// beginning of the current time step [s]. double simulationTimeElapsed() const; - /// Return the current time as a posix time object. - boost::posix_time::ptime currentDateTime() const; - /// Total time. double totalTime() const; + /// Return start date of simulation + boost::gregorian::date startDate() const; + /// Set total time. /// This is primarily intended for multi-epoch schedules, /// where a timer for a given epoch does not have diff --git a/opm/core/simulator/SimulatorTimerInterface.hpp b/opm/core/simulator/SimulatorTimerInterface.hpp new file mode 100644 index 00000000..8028a7f0 --- /dev/null +++ b/opm/core/simulator/SimulatorTimerInterface.hpp @@ -0,0 +1,95 @@ +/* + Copyright (c) 2014 IRIS AS + + This file is part of the Open Porous Media project (OPM). + + 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. + + 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. + + You should have received a copy of the GNU General Public License + along with OPM. If not, see . +*/ + +#ifndef OPM_SIMULATORTIMERINTERFACE_HEADER_INCLUDED +#define OPM_SIMULATORTIMERINTERFACE_HEADER_INCLUDED + +#include +#include +#include + +namespace Opm +{ + + namespace parameter { class ParameterGroup; } + + /// Interface class for SimulatorTimer objects, to be improved. + class SimulatorTimerInterface + { + protected: + /// Default constructor, protected to not allow explicit instances of this class. + SimulatorTimerInterface() {} + + public: + /// Current step number. This is the number of timesteps that + /// has been completed from the start of the run. The time + /// after initialization but before the simulation has started + /// is timestep number zero. + virtual int currentStepNum() const = 0; + + /// Current report step number. This might differ from currentStepNum in case of sub stepping + virtual int reportStepNum() const { return currentStepNum(); } + + /// Current step length. This is the length of the step + /// the simulator will take in the next iteration. + /// + /// @note if done(), it is an error to call currentStepLength(). + virtual double currentStepLength() const = 0; + + /// Previous step length. This is the length of the step that + /// was taken to arrive at this time. + /// + /// @note if no increments have been done (i.e. the timer is + /// still in its constructed state and currentStepNum() == 0), + /// it is an error to call stepLengthTaken(). + virtual double stepLengthTaken () const = 0; + + /// Time elapsed since the start of the simulation until the + /// beginning of the current time step [s]. + virtual double simulationTimeElapsed() const = 0; + + /// Return true if timer indicates that simulation of timer interval is finished + virtual bool done() const = 0; + + /// Return start date of simulation + virtual boost::gregorian::date startDate() const = 0; + + /// Return the current time as a posix time object. + virtual boost::posix_time::ptime currentDateTime() const + { + return boost::posix_time::ptime(startDate()) + boost::posix_time::seconds( (int) simulationTimeElapsed()); + } + + /// Time elapsed since the start of the POSIX epoch (Jan 1st, + /// 1970) until the current time step begins [s]. + virtual time_t currentPosixTime() const + { + tm t = boost::posix_time::to_tm(currentDateTime()); + return std::mktime(&t); + } + + /// Print a report with current and total time etc. + /// Note: if done(), it is an error to call report(). + //virtual void report(std::ostream& os) const = 0; + }; + + +} // namespace Opm + +#endif // OPM_SIMULATORTIMER_HEADER_INCLUDED From 6eeecbb02b80d19b3ebf81199f07f05acd661627 Mon Sep 17 00:00:00 2001 From: Robert K Date: Thu, 8 Jan 2015 12:42:05 +0100 Subject: [PATCH 3/5] - adjust OutputWriter to SimulatorTimerInterface - remove WriterTimer from EclipseWriter and use SimulatorTimerInterface - adjust to the above in AdaptiveTimeStepping. --- opm/core/io/OutputWriter.cpp | 15 +-- opm/core/io/OutputWriter.hpp | 24 +--- opm/core/io/eclipse/EclipseWriter.cpp | 107 ++++-------------- opm/core/io/eclipse/EclipseWriter.hpp | 28 +---- opm/core/simulator/AdaptiveSimulatorTimer.hpp | 1 - opm/core/simulator/AdaptiveTimeStepping.hpp | 37 +++--- .../simulator/AdaptiveTimeStepping_impl.hpp | 58 +++++----- 7 files changed, 85 insertions(+), 185 deletions(-) diff --git a/opm/core/io/OutputWriter.cpp b/opm/core/io/OutputWriter.cpp index 4c7e25ca..1431ad46 100644 --- a/opm/core/io/OutputWriter.cpp +++ b/opm/core/io/OutputWriter.cpp @@ -26,26 +26,17 @@ struct MultiWriter : public OutputWriter { MultiWriter (ptr_t writers) : writers_ (std::move (writers)) { } /// Forward the call to all writers - virtual void writeInit(const SimulatorTimer &timer) { + virtual void writeInit(const SimulatorTimerInterface &timer) { for (it_t it = writers_->begin (); it != writers_->end (); ++it) { (*it)->writeInit (timer); } } - virtual void writeTimeStep(const SimulatorTimer& timer, - const SimulatorState& reservoirState, - const WellState& wellState) { - for (it_t it = writers_->begin (); it != writers_->end(); ++it) { - (*it)->writeTimeStep (timer, reservoirState, wellState); - } - } - - virtual void writeTimeStep(const SimulatorTimer& timer, - const AdaptiveSimulatorTimer& substepTimer, + virtual void writeTimeStep(const SimulatorTimerInterface& timer, const SimulatorState& reservoirState, const WellState& wellState) { for (it_t it = writers_->begin (); it != writers_->end(); ++it) { - (*it)->writeTimeStep (timer, substepTimer, reservoirState, wellState); + (*it)->writeTimeStep (timer, reservoirState, wellState); } } diff --git a/opm/core/io/OutputWriter.hpp b/opm/core/io/OutputWriter.hpp index c4d71c79..27f4dd3b 100644 --- a/opm/core/io/OutputWriter.hpp +++ b/opm/core/io/OutputWriter.hpp @@ -21,6 +21,7 @@ #define OPM_OUTPUT_WRITER_HPP #include // unique_ptr, shared_ptr +#include struct UnstructuredGrid; @@ -30,8 +31,6 @@ namespace Opm { class EclipseState; namespace parameter { class ParameterGroup; } class SimulatorState; -class SimulatorTimer; -class AdaptiveSimulatorTimer; class WellState; struct PhaseUsage; @@ -74,7 +73,7 @@ public: * This routine should be called before the first timestep (i.e. when * timer.currentStepNum () == 0) */ - virtual void writeInit(const SimulatorTimer &timer) = 0; + virtual void writeInit(const SimulatorTimerInterface &timer) = 0; /*! * \brief Write a blackoil reservoir state to disk for later inspection with @@ -87,24 +86,7 @@ public: * This routine should be called after the timestep has been advanced, * i.e. timer.currentStepNum () > 0. */ - virtual void writeTimeStep(const SimulatorTimer& timer, - const SimulatorState& reservoirState, - const WellState& wellState) = 0; - - /*! - * \brief Write a blackoil reservoir state to disk for later inspection with - * visualization tools like ResInsight - * - * \param[in] timer The timer providing time, time step, etc. information - * \param[in] subStepTimer The timer providing sub step time information - * \param[in] reservoirState The thermodynamic state of the reservoir - * \param[in] wellState The production/injection data for all wells - * - * This routine should be called after the timestep has been advanced, - * i.e. timer.currentStepNum () > 0. - */ - virtual void writeTimeStep(const SimulatorTimer& timer, - const AdaptiveSimulatorTimer& subStepTimer, + virtual void writeTimeStep(const SimulatorTimerInterface& timer, const SimulatorState& reservoirState, const WellState& wellState) = 0; diff --git a/opm/core/io/eclipse/EclipseWriter.cpp b/opm/core/io/eclipse/EclipseWriter.cpp index 1e9d56a4..8af5080d 100644 --- a/opm/core/io/eclipse/EclipseWriter.cpp +++ b/opm/core/io/eclipse/EclipseWriter.cpp @@ -27,8 +27,7 @@ #include #include #include -#include -#include +#include #include #include #include @@ -126,40 +125,6 @@ int ertPhaseMask(const PhaseUsage uses) } -// wrapper class to make EclipseWriter work with either the SimulatorTimer or a -// combination of SimulatorTimer and AdaptiveSimulatorTimer. -struct WriterTimer -{ - const double time_; - const double stepLength_; - const time_t posixTime_; - const int deckReportStep_; - - // copy values from SimulatorTimer - WriterTimer( const SimulatorTimer& timer ) - : time_( timer.simulationTimeElapsed() ), - stepLength_( timer.stepLengthTaken() ), - posixTime_( timer.currentPosixTime() ), - deckReportStep_( timer.currentStepNum() ) - {} - - // copy values from SimulatorTimer and add values from - // AdaptiveSimulatorTimer, except the deck's reportStep - WriterTimer( const SimulatorTimer& timer, const AdaptiveSimulatorTimer& subStepTimer ) - : time_( subStepTimer.simulationTimeElapsed() ), - stepLength_( subStepTimer.currentStepLength() ), - posixTime_( timer.currentPosixTime() + time_t(time_ - timer.simulationTimeElapsed()) ), - deckReportStep_( timer.currentStepNum() ) - {} - - int deckReportStep () const { return deckReportStep_; } - double simulationTimeElapsed() const { return time_; } - /// time elapsed since the start of the POSIX epoch (Jan 1st, 1970) [s]. - time_t currentPosixTime() const { return posixTime_; } - double stepLengthTaken () const { return stepLength_; } -}; - - /** * Eclipse "keyword" (i.e. named data) for a vector. */ @@ -405,7 +370,7 @@ public: ecl_rst_file_close(restartFileHandle_); } - void writeHeader(const WriterTimer& timer, + void writeHeader(const SimulatorTimerInterface& timer, int reportStepIdx, ecl_rsthead_type * rsthead_data) { @@ -460,7 +425,7 @@ class Summary : private boost::noncopyable public: Summary(const std::string& outputDir, const std::string& baseName, - const WriterTimer& timer, + const SimulatorTimerInterface& timer, int nx, int ny, int nz) @@ -497,7 +462,7 @@ public: void addAllWells(Opm::EclipseStateConstPtr eclipseState, const PhaseUsage& uses); void writeTimeStep(int reportStepIdx, - const WriterTimer& timer, + const SimulatorTimerInterface& timer, const WellState& wellState); ecl_sum_type *ertHandle() const @@ -515,7 +480,7 @@ class SummaryTimeStep : private boost::noncopyable public: SummaryTimeStep(Summary& summaryHandle, int reportStepIdx, - const WriterTimer &timer) + const SimulatorTimerInterface &timer) { ertHandle_ = ecl_sum_add_tstep(summaryHandle.ertHandle(), reportStepIdx, @@ -570,7 +535,7 @@ public: void writeHeader(int numCells, const int* compressedToCartesianCellIdx, - const WriterTimer& timer, + const SimulatorTimerInterface& timer, Opm::EclipseStateConstPtr eclipseState, const PhaseUsage uses) { @@ -655,7 +620,7 @@ public: /// Retrieve the value which the monitor is supposed to write to the summary file /// according to the state of the well. virtual double retrieveValue(const int reportStepIdx, - const WriterTimer& timer, + const SimulatorTimerInterface& timer, const WellState& wellState, const std::map& nameToIdxMap) = 0; @@ -787,7 +752,7 @@ public: { } virtual double retrieveValue(const int reportStepIdx, - const WriterTimer& timer, + const SimulatorTimerInterface& timer, const WellState& wellState, const std::map& wellNameToIdxMap) { @@ -798,7 +763,7 @@ public: return 0.0; } - if (well_->getStatus(timer.deckReportStep()) == WellCommon::SHUT) { + if (well_->getStatus(timer.reportStepNum()) == WellCommon::SHUT) { // well is shut in the current time step return 0.0; } @@ -833,7 +798,7 @@ public: { } virtual double retrieveValue(const int reportStepIdx, - const WriterTimer& timer, + const SimulatorTimerInterface& timer, const WellState& wellState, const std::map& wellNameToIdxMap) { @@ -843,7 +808,7 @@ public: return 0.0; } - if (well_->getStatus(timer.deckReportStep()) == WellCommon::SHUT) { + if (well_->getStatus(timer.reportStepNum()) == WellCommon::SHUT) { // well is shut in the current time step return 0.0; } @@ -892,7 +857,7 @@ public: { } virtual double retrieveValue(const int reportStepIdx, - const WriterTimer& timer, + const SimulatorTimerInterface& timer, const WellState& wellState, const std::map& wellNameToIdxMap) { @@ -902,7 +867,7 @@ public: // well not active in current time step return 0.0; } - if (well_->getStatus(timer.deckReportStep()) == WellCommon::SHUT) { + if (well_->getStatus(timer.reportStepNum()) == WellCommon::SHUT) { // well is shut in the current time step return 0.0; } @@ -914,16 +879,16 @@ public: // no inline implementation of this since it depends on the // WellReport type being completed first void Summary::writeTimeStep(int reportStepIdx, - const WriterTimer& timer, + const SimulatorTimerInterface& timer, const WellState& wellState) { // create a name -> well index map const Opm::ScheduleConstPtr schedule = eclipseState_->getSchedule(); - const auto& timeStepWells = schedule->getWells(timer.deckReportStep()); + const auto& timeStepWells = schedule->getWells(timer.reportStepNum()); std::map wellNameToIdxMap; int openWellIdx = 0; for (size_t tsWellIdx = 0; tsWellIdx < timeStepWells.size(); ++tsWellIdx) { - if (timeStepWells[tsWellIdx]->getStatus(timer.deckReportStep()) != WellCommon::SHUT ) { + if (timeStepWells[tsWellIdx]->getStatus(timer.reportStepNum()) != WellCommon::SHUT ) { wellNameToIdxMap[timeStepWells[tsWellIdx]->name()] = openWellIdx; openWellIdx++; } @@ -1050,13 +1015,7 @@ int EclipseWriter::eclipseWellStatusMask(WellCommon::StatusEnum wellStatus) } -void EclipseWriter::writeInit(const SimulatorTimer &timer) -{ - EclipseWriterDetails::WriterTimer writerTimer( timer ); - writeInit( writerTimer ); -} - -void EclipseWriter::writeInit(const EclipseWriterDetails::WriterTimer &timer) +void EclipseWriter::writeInit(const SimulatorTimerInterface &timer) { // if we don't want to write anything, this method becomes a // no-op... @@ -1101,26 +1060,8 @@ void EclipseWriter::writeInit(const EclipseWriterDetails::WriterTimer &timer) summary_->addAllWells(eclipseState_, phaseUsage_); } - -void EclipseWriter::writeTimeStep(const SimulatorTimer& timer, - const SimulatorState& reservoirState, - const WellState& wellState) -{ - EclipseWriterDetails::WriterTimer writerTimer ( timer ); - writeTimeStep( writerTimer, reservoirState, wellState ); -} - -void EclipseWriter::writeTimeStep(const SimulatorTimer& timer, - const AdaptiveSimulatorTimer& subStepTimer, - const SimulatorState& reservoirState, - const WellState& wellState) -{ - EclipseWriterDetails::WriterTimer writerTimer ( timer, subStepTimer ); - writeTimeStep( writerTimer, reservoirState, wellState ); -} - // implementation of the writeTimeStep method -void EclipseWriter::writeTimeStep(const EclipseWriterDetails::WriterTimer& timer, +void EclipseWriter::writeTimeStep(const SimulatorTimerInterface& timer, const SimulatorState& reservoirState, const WellState& wellState) { @@ -1136,7 +1077,7 @@ void EclipseWriter::writeTimeStep(const EclipseWriterDetails::WriterTimer& timer } - std::vector wells_ptr = eclipseState_->getSchedule()->getWells(timer.deckReportStep()); + std::vector wells_ptr = eclipseState_->getSchedule()->getWells(timer.reportStepNum()); std::vector iwell_data; std::vector zwell_data; std::vector icon_data; @@ -1147,7 +1088,7 @@ void EclipseWriter::writeTimeStep(const EclipseWriterDetails::WriterTimer& timer rsthead_data.nx = cartesianSize_[0]; rsthead_data.ny = cartesianSize_[1]; rsthead_data.nz = cartesianSize_[2]; - rsthead_data.nwells = eclipseState_->getSchedule()->numWells(timer.deckReportStep()); + rsthead_data.nwells = eclipseState_->getSchedule()->numWells(timer.reportStepNum()); rsthead_data.niwelz = 0; rsthead_data.nzwelz = 0; rsthead_data.niconz = 0; @@ -1159,10 +1100,10 @@ void EclipseWriter::writeTimeStep(const EclipseWriterDetails::WriterTimer& timer for (std::vector::const_iterator c_iter = wells_ptr.begin(); c_iter != wells_ptr.end(); ++c_iter) { WellConstPtr well_ptr = *c_iter; - rsthead_data.ncwmax = eclipseState_->getSchedule()->getMaxNumCompletionsForWells(timer.deckReportStep()); - restartHandle.addRestartFileIwelData(iwell_data, timer.deckReportStep(), well_ptr); - restartHandle.addRestartFileZwelData(zwell_data, timer.deckReportStep(), well_ptr); - restartHandle.addRestartFileIconData(icon_data, timer.deckReportStep(), rsthead_data.ncwmax, well_ptr); + rsthead_data.ncwmax = eclipseState_->getSchedule()->getMaxNumCompletionsForWells(timer.reportStepNum()); + restartHandle.addRestartFileIwelData(iwell_data, timer.reportStepNum(), well_ptr); + restartHandle.addRestartFileZwelData(zwell_data, timer.reportStepNum(), well_ptr); + restartHandle.addRestartFileIconData(icon_data, timer.reportStepNum(), rsthead_data.ncwmax, well_ptr); rsthead_data.niwelz = EclipseWriterDetails::Restart::NIWELZ; rsthead_data.nzwelz = EclipseWriterDetails::Restart::NZWELZ; diff --git a/opm/core/io/eclipse/EclipseWriter.hpp b/opm/core/io/eclipse/EclipseWriter.hpp index c9cdc3b0..533781ec 100644 --- a/opm/core/io/eclipse/EclipseWriter.hpp +++ b/opm/core/io/eclipse/EclipseWriter.hpp @@ -25,6 +25,7 @@ #include #include #include // WellType +#include #include @@ -44,8 +45,6 @@ struct WriterTimer; } class SimulatorState; -class SimulatorTimer; -class AdaptiveSimulatorTimer; class WellState; namespace parameter { class ParameterGroup; } @@ -81,7 +80,7 @@ public: /** * Write the static eclipse data (grid, PVT curves, etc) to disk. */ - virtual void writeInit(const SimulatorTimer &timer); + virtual void writeInit(const SimulatorTimerInterface &timer); /*! * \brief Write a reservoir state and summary information to disk. @@ -98,32 +97,11 @@ public: * \param[in] reservoirState The thermodynamic state of the reservoir * \param[in] wellState The production/injection data for all wells */ - virtual void writeTimeStep(const SimulatorTimer& timer, + virtual void writeTimeStep(const SimulatorTimerInterface& timer, const SimulatorState& reservoirState, const WellState& wellState); - /*! - * \brief Write a reservoir state and summary information to disk. - * - * - * The reservoir state can be inspected with visualization tools like - * ResInsight. - * - * The summary information can then be visualized using tools from - * ERT or ECLIPSE. Note that calling this method is only - * meaningful after the first time step has been completed. - * - * \param[in] timer The timer providing time step and time information - * \param[in] subStepTimer The timer providing sub step information - * \param[in] reservoirState The thermodynamic state of the reservoir - * \param[in] wellState The production/injection data for all wells - */ - virtual void writeTimeStep(const SimulatorTimer& timer, - const AdaptiveSimulatorTimer& subStepTimer, - const SimulatorState& reservoirState, - const WellState& wellState); - static int eclipseWellTypeMask(WellType wellType, WellInjector::TypeEnum injectorType); static int eclipseWellStatusMask(WellCommon::StatusEnum wellStatus); diff --git a/opm/core/simulator/AdaptiveSimulatorTimer.hpp b/opm/core/simulator/AdaptiveSimulatorTimer.hpp index 9958f4c9..d82dda41 100644 --- a/opm/core/simulator/AdaptiveSimulatorTimer.hpp +++ b/opm/core/simulator/AdaptiveSimulatorTimer.hpp @@ -16,7 +16,6 @@ You should have received a copy of the GNU General Public License along with OPM. If not, see . */ - #ifndef OPM_ADAPTIVESIMULATORTIMER_HEADER_INCLUDED #define OPM_ADAPTIVESIMULATORTIMER_HEADER_INCLUDED diff --git a/opm/core/simulator/AdaptiveTimeStepping.hpp b/opm/core/simulator/AdaptiveTimeStepping.hpp index 0b1af84b..fe5f860a 100644 --- a/opm/core/simulator/AdaptiveTimeStepping.hpp +++ b/opm/core/simulator/AdaptiveTimeStepping.hpp @@ -1,3 +1,21 @@ +/* + Copyright 2014 IRIS AS + + This file is part of the Open Porous Media project (OPM). + + 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. + + 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. + + You should have received a copy of the GNU General Public License + along with OPM. If not, see . +*/ #ifndef OPM_SUBSTEPPING_HEADER_INCLUDED #define OPM_SUBSTEPPING_HEADER_INCLUDED @@ -21,19 +39,6 @@ namespace Opm { //! \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 - - \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 time current simulation time - \param timestep current time step length that is to be sub cycled - */ - template - 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 @@ -62,9 +67,9 @@ namespace Opm { protected: template - void stepImpl( Solver& solver, State& state, WellState& well_state, - const double time, const double timestep, - const SimulatorTimer* timer, OutputWriter* outputWriter); + void stepImpl( const SimulatorTimer& timer, + Solver& solver, State& state, WellState& well_state, + OutputWriter* outputWriter); typedef std::unique_ptr< TimeStepControlInterface > TimeStepControlType; diff --git a/opm/core/simulator/AdaptiveTimeStepping_impl.hpp b/opm/core/simulator/AdaptiveTimeStepping_impl.hpp index 4ec083df..ace9eafa 100644 --- a/opm/core/simulator/AdaptiveTimeStepping_impl.hpp +++ b/opm/core/simulator/AdaptiveTimeStepping_impl.hpp @@ -1,3 +1,21 @@ +/* + Copyright 2014 IRIS AS + + This file is part of the Open Porous Media project (OPM). + + 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. + + 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. + + You should have received a copy of the GNU General Public License + along with OPM. If not, see . +*/ #ifndef OPM_ADAPTIVETIMESTEPPING_IMPL_HEADER_INCLUDED #define OPM_ADAPTIVETIMESTEPPING_IMPL_HEADER_INCLUDED @@ -48,10 +66,7 @@ namespace Opm { 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 ); + stepImpl( simulatorTimer, solver, state, well_state ); } template @@ -59,37 +74,25 @@ namespace Opm { 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 - 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 ); + stepImpl( simulatorTimer, solver, state, well_state, &outputWriter ); } // implementation of the step method template void AdaptiveTimeStepping:: - stepImpl( Solver& solver, State& state, WState& well_state, - const double time, const double timestep, - const SimulatorTimer* simulatorTimer, + stepImpl( const SimulatorTimer& simulatorTimer, + Solver& solver, State& state, WState& well_state, OutputWriter* outputWriter ) { + const double timestep = simulatorTimer.currentStepLength(); + // init last time step as a fraction of the given time step if( last_timestep_ < 0 ) { - last_timestep_ = initial_fraction_ * timestep ; + last_timestep_ = initial_fraction_ * timestep; } // create adaptive step timer with previously used sub step size - AdaptiveSimulatorTimer substepTimer( time, time+timestep, last_timestep_ ); + AdaptiveSimulatorTimer substepTimer( simulatorTimer, last_timestep_ ); // copy states in case solver has to be restarted (to be revised) State last_state( state ); @@ -145,8 +148,10 @@ 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; + std::cout << std::endl + <<"Substep( " << substepTimer.currentStepNum() + << " ): Current time (days) " << unit::convert::to(substepTimer.simulationTimeElapsed(),unit::day) << std::endl + << " Current stepsize est (days) " << unit::convert::to(dtEstimate, unit::day) << std::endl; } // set new time step length @@ -158,8 +163,7 @@ namespace Opm { // write data if outputWriter was provided if( outputWriter ) { - assert( simulatorTimer ); - outputWriter->writeTimeStep( *simulatorTimer, substepTimer, state, well_state ); + outputWriter->writeTimeStep( substepTimer, state, well_state ); } } else // in case of no convergence (linearIterations < 0) From 65a314db92230d0bde355b6348f16745842f7d0a Mon Sep 17 00:00:00 2001 From: Robert K Date: Fri, 9 Jan 2015 15:10:56 +0100 Subject: [PATCH 4/5] cleanup: reportStepIdx --> writeStepIdx. startDate --> startDateTime removal of debug output. --- opm/core/io/eclipse/EclipseWriter.cpp | 56 +++++++++---------- opm/core/io/eclipse/EclipseWriter.hpp | 2 +- opm/core/simulator/AdaptiveSimulatorTimer.cpp | 6 +- opm/core/simulator/AdaptiveSimulatorTimer.hpp | 6 +- .../simulator/AdaptiveTimeStepping_impl.hpp | 11 ++-- opm/core/simulator/SimulatorTimer.cpp | 4 +- opm/core/simulator/SimulatorTimer.hpp | 2 +- .../simulator/SimulatorTimerInterface.hpp | 20 +++++-- 8 files changed, 58 insertions(+), 49 deletions(-) diff --git a/opm/core/io/eclipse/EclipseWriter.cpp b/opm/core/io/eclipse/EclipseWriter.cpp index 8af5080d..f3908583 100644 --- a/opm/core/io/eclipse/EclipseWriter.cpp +++ b/opm/core/io/eclipse/EclipseWriter.cpp @@ -235,13 +235,13 @@ public: FileName(const std::string& outputDir, const std::string& baseName, ecl_file_enum type, - int reportStepIdx) + int writeStepIdx) { ertHandle_ = ecl_util_alloc_filename(outputDir.c_str(), baseName.c_str(), type, false, // formatted? - reportStepIdx); + writeStepIdx); } ~FileName() @@ -276,15 +276,15 @@ public: Restart(const std::string& outputDir, const std::string& baseName, - int reportStepIdx) + int writeStepIdx) { restartFileName_ = ecl_util_alloc_filename(outputDir.c_str(), baseName.c_str(), /*type=*/ECL_UNIFIED_RESTART_FILE, false, // use formatted instead of binary output? - reportStepIdx); + writeStepIdx); - if (reportStepIdx == 0) { + if (writeStepIdx == 0) { restartFileHandle_ = ecl_rst_file_open_write(restartFileName_); } else { @@ -371,12 +371,12 @@ public: } void writeHeader(const SimulatorTimerInterface& timer, - int reportStepIdx, + int writeStepIdx, ecl_rsthead_type * rsthead_data) { ecl_rst_file_fwrite_header(restartFileHandle_, - reportStepIdx, + writeStepIdx, rsthead_data); } @@ -461,7 +461,7 @@ public: // add rate variables for each of the well in the input file void addAllWells(Opm::EclipseStateConstPtr eclipseState, const PhaseUsage& uses); - void writeTimeStep(int reportStepIdx, + void writeTimeStep(int writeStepIdx, const SimulatorTimerInterface& timer, const WellState& wellState); @@ -479,11 +479,11 @@ class SummaryTimeStep : private boost::noncopyable { public: SummaryTimeStep(Summary& summaryHandle, - int reportStepIdx, + int writeStepIdx, const SimulatorTimerInterface &timer) { ertHandle_ = ecl_sum_add_tstep(summaryHandle.ertHandle(), - reportStepIdx, + writeStepIdx, Opm::unit::convert::to(timer.simulationTimeElapsed(), Opm::unit::day)); } @@ -508,16 +508,16 @@ class Init : private boost::noncopyable public: Init(const std::string& outputDir, const std::string& baseName, - int reportStepIdx) + int writeStepIdx) : egridFileName_(outputDir, baseName, ECL_EGRID_FILE, - reportStepIdx) + writeStepIdx) { FileName initFileName(outputDir, baseName, ECL_INIT_FILE, - reportStepIdx); + writeStepIdx); bool isFormatted; if (!ecl_util_fmt_file(initFileName.ertHandle(), &isFormatted)) { @@ -619,7 +619,7 @@ protected: public: /// Retrieve the value which the monitor is supposed to write to the summary file /// according to the state of the well. - virtual double retrieveValue(const int reportStepIdx, + virtual double retrieveValue(const int writeStepIdx, const SimulatorTimerInterface& timer, const WellState& wellState, const std::map& nameToIdxMap) = 0; @@ -751,7 +751,7 @@ public: "SM3/DAY" /* surf. cub. m. per day */) { } - virtual double retrieveValue(const int reportStepIdx, + virtual double retrieveValue(const int writeStepIdx, const SimulatorTimerInterface& timer, const WellState& wellState, const std::map& wellNameToIdxMap) @@ -797,12 +797,12 @@ public: , total_(0.) { } - virtual double retrieveValue(const int reportStepIdx, + virtual double retrieveValue(const int writeStepIdx, const SimulatorTimerInterface& timer, const WellState& wellState, const std::map& wellNameToIdxMap) { - if (reportStepIdx == 0) { + if (writeStepIdx == 0) { // We are at the initial state. // No step has been taken yet. return 0.0; @@ -856,7 +856,7 @@ public: "Pascal") { } - virtual double retrieveValue(const int reportStepIdx, + virtual double retrieveValue(const int writeStepIdx, const SimulatorTimerInterface& timer, const WellState& wellState, const std::map& wellNameToIdxMap) @@ -878,7 +878,7 @@ public: // no inline implementation of this since it depends on the // WellReport type being completed first -void Summary::writeTimeStep(int reportStepIdx, +void Summary::writeTimeStep(int writeStepIdx, const SimulatorTimerInterface& timer, const WellState& wellState) { @@ -895,12 +895,12 @@ void Summary::writeTimeStep(int reportStepIdx, } // internal view; do not move this code out of Summary! - SummaryTimeStep tstep(*this, reportStepIdx, timer); + SummaryTimeStep tstep(*this, writeStepIdx, timer); // write all the variables for (auto varIt = summaryReportVars_.begin(); varIt != summaryReportVars_.end(); ++varIt) { ecl_sum_tstep_iset(tstep.ertHandle(), smspec_node_get_params_index((*varIt)->ertHandle()), - (*varIt)->retrieveValue(reportStepIdx, timer, wellState, wellNameToIdxMap)); + (*varIt)->retrieveValue(writeStepIdx, timer, wellState, wellNameToIdxMap)); } // write the summary file to disk @@ -1023,7 +1023,7 @@ void EclipseWriter::writeInit(const SimulatorTimerInterface &timer) return; } - reportStepIdx_ = 0; + writeStepIdx_ = 0; EclipseWriterDetails::Init fortio(outputDir_, baseName_, /*stepIdx=*/0); fortio.writeHeader(numCells_, @@ -1072,7 +1072,7 @@ void EclipseWriter::writeTimeStep(const SimulatorTimerInterface& timer, } // respected the output_interval parameter - if (reportStepIdx_ % outputInterval_ != 0) { + if (writeStepIdx_ % outputInterval_ != 0) { return; } @@ -1095,7 +1095,7 @@ void EclipseWriter::writeTimeStep(const SimulatorTimerInterface& timer, rsthead_data.ncwmax = 0; rsthead_data.phase_sum = Opm::EclipseWriterDetails::ertPhaseMask(phaseUsage_); - EclipseWriterDetails::Restart restartHandle(outputDir_, baseName_, reportStepIdx_); + EclipseWriterDetails::Restart restartHandle(outputDir_, baseName_, writeStepIdx_); for (std::vector::const_iterator c_iter = wells_ptr.begin(); c_iter != wells_ptr.end(); ++c_iter) { WellConstPtr well_ptr = *c_iter; @@ -1113,7 +1113,7 @@ void EclipseWriter::writeTimeStep(const SimulatorTimerInterface& timer, rsthead_data.sim_days = Opm::unit::convert::to(timer.simulationTimeElapsed(), Opm::unit::day); //data for doubhead restartHandle.writeHeader(timer, - reportStepIdx_, + writeStepIdx_, &rsthead_data); @@ -1165,9 +1165,9 @@ void EclipseWriter::writeTimeStep(const SimulatorTimerInterface& timer, // instead of creating a temporary EclipseWriterDetails::Summary in this function // every time it is called. This has been changed so that the final summary file // will contain data from the whole simulation, instead of just the last step. - summary_->writeTimeStep(reportStepIdx_, timer, wellState); + summary_->writeTimeStep(writeStepIdx_, timer, wellState); - ++reportStepIdx_; + ++writeStepIdx_; } @@ -1243,7 +1243,7 @@ void EclipseWriter::init(const parameter::ParameterGroup& params) outputDir_ = params.getDefault("output_dir", "."); // set the index of the first time step written to 0... - reportStepIdx_ = 0; + writeStepIdx_ = 0; if (enableOutput_) { // make sure that the output directory exists, if not try to create it diff --git a/opm/core/io/eclipse/EclipseWriter.hpp b/opm/core/io/eclipse/EclipseWriter.hpp index 533781ec..0c6153d4 100644 --- a/opm/core/io/eclipse/EclipseWriter.hpp +++ b/opm/core/io/eclipse/EclipseWriter.hpp @@ -114,7 +114,7 @@ private: double deckToSiPressure_; bool enableOutput_; int outputInterval_; - int reportStepIdx_; + int writeStepIdx_; std::string outputDir_; std::string baseName_; PhaseUsage phaseUsage_; // active phases in the input deck diff --git a/opm/core/simulator/AdaptiveSimulatorTimer.cpp b/opm/core/simulator/AdaptiveSimulatorTimer.cpp index 72add45a..46a07778 100644 --- a/opm/core/simulator/AdaptiveSimulatorTimer.cpp +++ b/opm/core/simulator/AdaptiveSimulatorTimer.cpp @@ -31,7 +31,7 @@ namespace Opm { AdaptiveSimulatorTimer:: AdaptiveSimulatorTimer( const SimulatorTimerInterface& timer, const double lastStepTaken ) - : start_date_( timer.startDate() ) + : start_date_time_( timer.startDateTime() ) , start_time_( timer.simulationTimeElapsed() ) , total_time_( start_time_ + timer.currentStepLength() ) , report_step_( timer.reportStepNum() ) @@ -156,9 +156,9 @@ namespace Opm std::cout << "sub steps end time = " << unit::convert::to( simulationTimeElapsed(), unit::day ) << " (days)" << std::endl; } - boost::gregorian::date AdaptiveSimulatorTimer::startDate() const + boost::posix_time::ptime AdaptiveSimulatorTimer::startDateTime() const { - return start_date_; + return start_date_time_; } double AdaptiveSimulatorTimer:: diff --git a/opm/core/simulator/AdaptiveSimulatorTimer.hpp b/opm/core/simulator/AdaptiveSimulatorTimer.hpp index d82dda41..c2082619 100644 --- a/opm/core/simulator/AdaptiveSimulatorTimer.hpp +++ b/opm/core/simulator/AdaptiveSimulatorTimer.hpp @@ -89,11 +89,11 @@ namespace Opm /// \brief report start and end time as well as used steps so far void report(std::ostream& os) const; - /// \brief start date of simulation - boost::gregorian::date startDate() const; + /// \brief start date time of simulation + boost::posix_time::ptime startDateTime() const; protected: - const boost::gregorian::date start_date_; + const boost::posix_time::ptime start_date_time_; const double start_time_; const double total_time_; const int report_step_; diff --git a/opm/core/simulator/AdaptiveTimeStepping_impl.hpp b/opm/core/simulator/AdaptiveTimeStepping_impl.hpp index ace9eafa..b1d5ed71 100644 --- a/opm/core/simulator/AdaptiveTimeStepping_impl.hpp +++ b/opm/core/simulator/AdaptiveTimeStepping_impl.hpp @@ -151,7 +151,12 @@ namespace Opm { std::cout << std::endl <<"Substep( " << substepTimer.currentStepNum() << " ): Current time (days) " << unit::convert::to(substepTimer.simulationTimeElapsed(),unit::day) << std::endl - << " Current stepsize est (days) " << unit::convert::to(dtEstimate, unit::day) << std::endl; + << " Current stepsize est (days) " << unit::convert::to(dtEstimate, unit::day) << std::endl; + } + + // write data if outputWriter was provided + if( outputWriter ) { + outputWriter->writeTimeStep( substepTimer, state, well_state ); } // set new time step length @@ -161,10 +166,6 @@ namespace Opm { last_state = state ; last_well_state = well_state; - // write data if outputWriter was provided - if( outputWriter ) { - outputWriter->writeTimeStep( substepTimer, state, well_state ); - } } else // in case of no convergence (linearIterations < 0) { diff --git a/opm/core/simulator/SimulatorTimer.cpp b/opm/core/simulator/SimulatorTimer.cpp index a7e368d1..75785751 100644 --- a/opm/core/simulator/SimulatorTimer.cpp +++ b/opm/core/simulator/SimulatorTimer.cpp @@ -100,9 +100,9 @@ namespace Opm return current_time_; } - boost::gregorian::date SimulatorTimer::startDate() const + boost::posix_time::ptime SimulatorTimer::startDateTime() const { - return start_date_; + return boost::posix_time::ptime(start_date_); } diff --git a/opm/core/simulator/SimulatorTimer.hpp b/opm/core/simulator/SimulatorTimer.hpp index 5c933935..8f9e7b0b 100644 --- a/opm/core/simulator/SimulatorTimer.hpp +++ b/opm/core/simulator/SimulatorTimer.hpp @@ -83,7 +83,7 @@ namespace Opm double totalTime() const; /// Return start date of simulation - boost::gregorian::date startDate() const; + boost::posix_time::ptime startDateTime() const; /// Set total time. /// This is primarily intended for multi-epoch schedules, diff --git a/opm/core/simulator/SimulatorTimerInterface.hpp b/opm/core/simulator/SimulatorTimerInterface.hpp index 8028a7f0..25118fd2 100644 --- a/opm/core/simulator/SimulatorTimerInterface.hpp +++ b/opm/core/simulator/SimulatorTimerInterface.hpp @@ -37,6 +37,9 @@ namespace Opm SimulatorTimerInterface() {} public: + /// destructor + virtual ~SimulatorTimerInterface() {} + /// Current step number. This is the number of timesteps that /// has been completed from the start of the run. The time /// after initialization but before the simulation has started @@ -60,6 +63,14 @@ namespace Opm /// it is an error to call stepLengthTaken(). virtual double stepLengthTaken () const = 0; + /// Previous report step length. This is the length of the step that + /// was taken to arrive at this report step time. + /// + /// @note if no increments have been done (i.e. the timer is + /// still in its constructed state and reportStepNum() == 0), + /// it is an error to call stepLengthTaken(). + virtual double reportStepLengthTaken () const { return stepLengthTaken(); } + /// Time elapsed since the start of the simulation until the /// beginning of the current time step [s]. virtual double simulationTimeElapsed() const = 0; @@ -68,12 +79,13 @@ namespace Opm virtual bool done() const = 0; /// Return start date of simulation - virtual boost::gregorian::date startDate() const = 0; + virtual boost::posix_time::ptime startDateTime() const = 0; /// Return the current time as a posix time object. virtual boost::posix_time::ptime currentDateTime() const { - return boost::posix_time::ptime(startDate()) + boost::posix_time::seconds( (int) simulationTimeElapsed()); + return startDateTime() + boost::posix_time::seconds( (int) simulationTimeElapsed()); + //boost::posix_time::ptime(startDate()) + boost::posix_time::seconds( (int) simulationTimeElapsed()); } /// Time elapsed since the start of the POSIX epoch (Jan 1st, @@ -83,10 +95,6 @@ namespace Opm tm t = boost::posix_time::to_tm(currentDateTime()); return std::mktime(&t); } - - /// Print a report with current and total time etc. - /// Note: if done(), it is an error to call report(). - //virtual void report(std::ostream& os) const = 0; }; From d97f622f913df4d7e21dba1571fdd161d25544d8 Mon Sep 17 00:00:00 2001 From: Robert K Date: Thu, 15 Jan 2015 11:34:59 +0100 Subject: [PATCH 5/5] EclipseWriter: remove leftovers of WriterTimer. AdaptiveSimulatorTimer: use back instead of rbegin. --- opm/core/io/eclipse/EclipseWriter.hpp | 8 -------- opm/core/simulator/AdaptiveSimulatorTimer.cpp | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/opm/core/io/eclipse/EclipseWriter.hpp b/opm/core/io/eclipse/EclipseWriter.hpp index 0c6153d4..5ff4e7f3 100644 --- a/opm/core/io/eclipse/EclipseWriter.hpp +++ b/opm/core/io/eclipse/EclipseWriter.hpp @@ -41,7 +41,6 @@ namespace Opm { // forward declarations namespace EclipseWriterDetails { class Summary; -struct WriterTimer; } class SimulatorState; @@ -121,13 +120,6 @@ private: std::shared_ptr summary_; void init(const parameter::ParameterGroup& params); - // implementation of writeInit - void writeInit(const EclipseWriterDetails::WriterTimer &timer); - // implementation of writeTimeStep - void writeTimeStep(const EclipseWriterDetails::WriterTimer& timer, - const SimulatorState& reservoirState, - const WellState& wellState); - }; typedef std::shared_ptr EclipseWriterPtr; diff --git a/opm/core/simulator/AdaptiveSimulatorTimer.cpp b/opm/core/simulator/AdaptiveSimulatorTimer.cpp index 46a07778..83716dfe 100644 --- a/opm/core/simulator/AdaptiveSimulatorTimer.cpp +++ b/opm/core/simulator/AdaptiveSimulatorTimer.cpp @@ -100,7 +100,7 @@ namespace Opm double AdaptiveSimulatorTimer::stepLengthTaken() const { assert( ! steps_.empty() ); - return *(steps_.rbegin()); + return steps_.back(); }