diff --git a/ebos/eclbasevanguard.hh b/ebos/eclbasevanguard.hh index 44c8fb7db..ef65595de 100644 --- a/ebos/eclbasevanguard.hh +++ b/ebos/eclbasevanguard.hh @@ -49,6 +49,7 @@ #include #include #include +#include #include @@ -448,7 +449,7 @@ public: std::move(parseContext_), /* initFromRestart = */ false, /* checkDeck = */ enableExperiments); - this->summaryState_ = std::make_unique( std::chrono::system_clock::from_time_t(this->eclSchedule_->getStartTime() )); + this->summaryState_ = std::make_unique( Opm::TimeService::from_time_t(this->eclSchedule_->getStartTime() )); this->udqState_ = std::make_unique( this->eclSchedule_->getUDQConfig(0).params().undefinedValue() ); this->actionState_ = std::make_unique() ; diff --git a/ebos/eclproblem.hh b/ebos/eclproblem.hh index 43ab9a41a..a8ab7b5d0 100644 --- a/ebos/eclproblem.hh +++ b/ebos/eclproblem.hh @@ -99,6 +99,7 @@ #include #include #include +#include #include #include @@ -858,11 +859,10 @@ public: auto& simulator = this->simulator(); const auto& eclState = simulator.vanguard().eclState(); const auto& schedule = simulator.vanguard().schedule(); - const auto& timeMap = schedule.getTimeMap(); // Set the start time of the simulation - simulator.setStartTime(timeMap.getStartTime(/*reportStepIdx=*/0)); - simulator.setEndTime(timeMap.getTotalTime()); + simulator.setStartTime(schedule.getStartTime()); + simulator.setEndTime(schedule.simTime(schedule.size() - 1)); // We want the episode index to be the same as the report step index to make // things simpler, so we have to set the episode index to -1 because it is @@ -968,7 +968,7 @@ public: // to the first "real" episode/report step // for restart the episode index and start is already set if (!initconfig.restartRequested()) { - simulator.startNextEpisode(timeMap.getTimeStepLength(0)); + simulator.startNextEpisode(schedule.seconds(0)); simulator.setEpisodeIndex(0); } } @@ -1027,7 +1027,6 @@ public: auto& eclState = simulator.vanguard().eclState(); const auto& schedule = simulator.vanguard().schedule(); const auto& events = schedule[episodeIdx].events(); - const auto& timeMap = schedule.getTimeMap(); if (episodeIdx >= 0 && events.hasEvent(Opm::ScheduleEvents::GEO_MODIFIER)) { // bring the contents of the keywords to the current state of the SCHEDULE @@ -1052,12 +1051,12 @@ public: std::ostringstream ss; boost::posix_time::time_facet* facet = new boost::posix_time::time_facet("%d-%b-%Y"); boost::posix_time::ptime curDateTime = - boost::posix_time::from_time_t(timeMap.getStartTime(episodeIdx)); + boost::posix_time::from_time_t(schedule.simTime(episodeIdx)); ss.imbue(std::locale(std::locale::classic(), facet)); ss << "Report step " << episodeIdx + 1 - << "/" << timeMap.numTimesteps() - << " at day " << timeMap.getTimePassedUntil(episodeIdx)/(24*3600) - << "/" << timeMap.getTotalTime()/(24*3600) + << "/" << schedule.size() - 1 + << " at day " << schedule.seconds(episodeIdx)/(24*3600) + << "/" << schedule.seconds(schedule.size() - 1)/(24*3600) << ", date = " << curDateTime.date() << "\n "; OpmLog::info(ss.str()); @@ -1241,18 +1240,17 @@ public: { auto& simulator = this->simulator(); auto& schedule = simulator.vanguard().schedule(); - const auto& timeMap = schedule.getTimeMap(); int episodeIdx = simulator.episodeIndex(); // check if we're finished ... - if (episodeIdx + 1 >= static_cast(timeMap.numTimesteps())) { + if (episodeIdx + 1 >= static_cast(schedule.size() - 1)) { simulator.setFinished(true); return; } // .. if we're not yet done, start the next episode (report step) - simulator.startNextEpisode(timeMap.getTimeStepLength(episodeIdx + 1)); + simulator.startNextEpisode(schedule.stepLength(episodeIdx + 1)); } /*! @@ -1381,7 +1379,7 @@ public: const auto& wellpi = this->fetchWellPI(reportStep, *action, schedule, matching_wells); - schedule.applyAction(reportStep, std::chrono::system_clock::from_time_t(simTime), *action, actionResult, wellpi); + schedule.applyAction(reportStep, Opm::TimeService::from_time_t(simTime), *action, actionResult, wellpi); actionState.add_run(*action, simTime); for ( const auto& [wname, _] : wellpi) { @@ -2742,16 +2740,15 @@ private: auto& simulator = this->simulator(); const auto& schedule = simulator.vanguard().schedule(); const auto& eclState = simulator.vanguard().eclState(); - const auto& timeMap = schedule.getTimeMap(); const auto& initconfig = eclState.getInitConfig(); { int restart_step = initconfig.getRestartStep(); - simulator.setStartTime(timeMap.getStartTime(/*timeStepIdx=*/0)); - simulator.setTime(timeMap.getTimePassedUntil(restart_step)); + simulator.setStartTime(schedule.simTime(0)); + simulator.setTime(schedule.seconds(restart_step)); simulator.startNextEpisode(simulator.startTime() + simulator.time(), - timeMap.getTimeStepLength(restart_step)); + schedule.stepLength(restart_step)); simulator.setEpisodeIndex(restart_step); } eclWriter_->beginRestart(); diff --git a/ebos/eclwellmanager.hh b/ebos/eclwellmanager.hh index 3036f365f..e986fbefc 100644 --- a/ebos/eclwellmanager.hh +++ b/ebos/eclwellmanager.hh @@ -605,7 +605,7 @@ public: if (wellTopologyChanged_(eclState, reportStepIdx)) return true; - if (schedule.getTimeMap().numTimesteps() <= (unsigned) reportStepIdx) + if ((schedule.size() - 1) <= (unsigned) reportStepIdx) // for the "until the universe dies" episode, the wells don't change return false; @@ -660,7 +660,7 @@ protected: return true; } - if (schedule.getTimeMap().numTimesteps() <= (unsigned) reportStepIdx) + if ((schedule.size() - 1) <= (unsigned) reportStepIdx) // for the "until the universe dies" episode, the wells don't change return false; diff --git a/examples/printvfp.cpp b/examples/printvfp.cpp index b52199948..a03eae381 100644 --- a/examples/printvfp.cpp +++ b/examples/printvfp.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -52,7 +53,7 @@ struct Setup const Runspec runspec(deck); python = std::make_shared(); schedule.reset( new Schedule(deck, *ecl_state, python)); - summary_state.reset( new SummaryState(std::chrono::system_clock::from_time_t(schedule->getStartTime()))); + summary_state.reset( new SummaryState(TimeService::from_time_t(schedule->getStartTime()))); } const int step = 0; const auto& sched_state = schedule->operator[](step); diff --git a/opm/simulators/flow/FlowMainEbos.hpp b/opm/simulators/flow/FlowMainEbos.hpp index 47f021d69..892f4d392 100644 --- a/opm/simulators/flow/FlowMainEbos.hpp +++ b/opm/simulators/flow/FlowMainEbos.hpp @@ -608,13 +608,12 @@ namespace Opm { const auto& schedule = this->schedule(); - const auto& timeMap = schedule.getTimeMap(); auto& ioConfig = eclState().getIOConfig(); simtimer_ = std::make_unique(); // initialize variables const auto& initConfig = eclState().getInitConfig(); - simtimer_->init(timeMap, (size_t)initConfig.getRestartStep()); + simtimer_->init(schedule, (size_t)initConfig.getRestartStep()); if (this->output_cout_) { std::ostringstream oss; diff --git a/opm/simulators/flow/SimulatorFullyImplicitBlackoilEbos.hpp b/opm/simulators/flow/SimulatorFullyImplicitBlackoilEbos.hpp index 61f7bc653..f74cc7eba 100644 --- a/opm/simulators/flow/SimulatorFullyImplicitBlackoilEbos.hpp +++ b/opm/simulators/flow/SimulatorFullyImplicitBlackoilEbos.hpp @@ -231,7 +231,7 @@ public: ebosSimulator_.startNextEpisode( ebosSimulator_.startTime() - + schedule().getTimeMap().getTimePassedUntil(timer.currentStepNum()), + + schedule().seconds(timer.currentStepNum()), timer.currentStepLength()); ebosSimulator_.setEpisodeIndex(timer.currentStepNum()); solver->model().beginReportStep(); diff --git a/opm/simulators/timestepping/SimulatorTimer.cpp b/opm/simulators/timestepping/SimulatorTimer.cpp index a5b441260..b2a5fdd42 100644 --- a/opm/simulators/timestepping/SimulatorTimer.cpp +++ b/opm/simulators/timestepping/SimulatorTimer.cpp @@ -49,16 +49,16 @@ namespace Opm } /// Use the SimulatorTimer as a shim around opm-parser's Opm::TimeMap - void SimulatorTimer::init(const TimeMap& timeMap, size_t report_step) + void SimulatorTimer::init(const Schedule& schedule, size_t report_step) { - total_time_ = timeMap.getTotalTime(); - timesteps_.resize(timeMap.numTimesteps()); - for ( size_t i = 0; i < timeMap.numTimesteps(); ++i ) { - timesteps_[i] = timeMap.getTimeStepLength(i); + total_time_ = schedule.seconds( schedule.size() - 1 ); + timesteps_.resize(schedule.size() - 1); + for ( size_t i = 0; i < schedule.size() - 1; ++i ) { + timesteps_[i] = schedule.stepLength(i); } setCurrentStepNum(report_step); - start_date_ = boost::posix_time::from_time_t( timeMap.getStartTime(0)).date(); + start_date_ = boost::posix_time::from_time_t(schedule.getStartTime()).date(); } /// Whether the current step is the first step. diff --git a/opm/simulators/timestepping/SimulatorTimer.hpp b/opm/simulators/timestepping/SimulatorTimer.hpp index 2dc894532..ec58ccb46 100644 --- a/opm/simulators/timestepping/SimulatorTimer.hpp +++ b/opm/simulators/timestepping/SimulatorTimer.hpp @@ -20,7 +20,7 @@ #ifndef OPM_SIMULATORTIMER_HEADER_INCLUDED #define OPM_SIMULATORTIMER_HEADER_INCLUDED -#include +#include #include #include @@ -46,8 +46,8 @@ namespace Opm /// stepsize_days (default 1) void init(const ParameterGroup& param); - /// Use the SimulatorTimer as a shim around opm-parser's Opm::TimeMap - void init(const TimeMap& timeMap, size_t report_step = 0); + /// Use the SimulatorTimer as a shim around opm-commons Schedule class + void init(const Schedule& schedule, size_t report_step = 0); /// Whether the current step is the first step. bool initialStep() const; diff --git a/opm/simulators/utils/ParallelRestart.cpp b/opm/simulators/utils/ParallelRestart.cpp index 347645eb0..6bef3d885 100644 --- a/opm/simulators/utils/ParallelRestart.cpp +++ b/opm/simulators/utils/ParallelRestart.cpp @@ -283,7 +283,7 @@ std::size_t packSize(const RestartValue& data, Dune::MPIHelper::MPICommunicator + packSize(data.extra, comm); } -std::size_t packSize(const std::chrono::system_clock::time_point&, Dune::MPIHelper::MPICommunicator comm) +std::size_t packSize(const Opm::time_point&, Dune::MPIHelper::MPICommunicator comm) { std::time_t tp; return packSize(tp, comm); @@ -576,10 +576,10 @@ void pack(const RestartValue& data, std::vector& buffer, int& position, pack(data.extra, buffer, position, comm); } -void pack(const std::chrono::system_clock::time_point& data, std::vector& buffer, int& position, +void pack(const Opm::time_point& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm) { - pack(std::chrono::system_clock::to_time_t(data), buffer, position, comm); + pack(Opm::TimeService::to_time_t(data), buffer, position, comm); } @@ -887,12 +887,12 @@ void unpack(RestartValue& data, std::vector& buffer, int& position, unpack(data.extra, buffer, position, comm); } -void unpack(std::chrono::system_clock::time_point& data, std::vector& buffer, int& position, +void unpack(Opm::time_point& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm) { std::time_t tp; unpack(tp, buffer, position, comm); - data = std::chrono::system_clock::from_time_t(tp); + data = Opm::TimeService::from_time_t(tp); } diff --git a/opm/simulators/utils/ParallelRestart.hpp b/opm/simulators/utils/ParallelRestart.hpp index fe8421860..f4bb80597 100644 --- a/opm/simulators/utils/ParallelRestart.hpp +++ b/opm/simulators/utils/ParallelRestart.hpp @@ -27,6 +27,7 @@ #include #include #include +#include #include @@ -321,7 +322,7 @@ ADD_PACK_PROTOTYPES(data::WellRates) ADD_PACK_PROTOTYPES(RestartKey) ADD_PACK_PROTOTYPES(RestartValue) ADD_PACK_PROTOTYPES(std::string) -ADD_PACK_PROTOTYPES(std::chrono::system_clock::time_point) +ADD_PACK_PROTOTYPES(Opm::time_point) } // end namespace Mpi diff --git a/tests/test_timer.cpp b/tests/test_timer.cpp index b1dbf871c..f78a1ebfb 100644 --- a/tests/test_timer.cpp +++ b/tests/test_timer.cpp @@ -29,6 +29,10 @@ #include #include #include +#include +#include +#include +#include #include #include @@ -40,14 +44,17 @@ BOOST_AUTO_TEST_CASE(CreateTimer) const std::string filename1 = "TESTTIMER.DATA"; Opm::Parser parser; Opm::Deck parserDeck = parser.parseFile( filename1); - - Opm::TimeMap timeMap( parserDeck ); + auto python = std::make_shared(); + Opm::EclipseGrid grid(10,10,10); + Opm::FieldPropsManager fp(parserDeck, Opm::Phases{true, true, true}, grid, Opm::TableManager()); + Opm::Runspec runspec(parserDeck); + Opm::Schedule schedule( parserDeck, grid, fp, runspec, python ); Opm::SimulatorTimer simtimer; boost::gregorian::date defaultStartDate( 2012, 1, 1); BOOST_CHECK_EQUAL( boost::posix_time::ptime(defaultStartDate), simtimer.currentDateTime() ); - simtimer.init(timeMap); + simtimer.init(schedule); boost::gregorian::date startDate( 2014, 3, 26); BOOST_CHECK_EQUAL( boost::posix_time::ptime(startDate), simtimer.currentDateTime() ); diff --git a/tests/test_wellmodel.cpp b/tests/test_wellmodel.cpp index 7e19ebb3b..71e250e0e 100644 --- a/tests/test_wellmodel.cpp +++ b/tests/test_wellmodel.cpp @@ -37,6 +37,7 @@ #include #include +#include #include #include @@ -73,7 +74,7 @@ struct SetupTest { const Opm::Runspec runspec (deck); python = std::make_shared(); schedule.reset( new Opm::Schedule(deck, *ecl_state, python)); - summaryState.reset( new Opm::SummaryState(std::chrono::system_clock::from_time_t(schedule->getStartTime()))); + summaryState.reset( new Opm::SummaryState(Opm::TimeService::from_time_t(schedule->getStartTime()))); } current_timestep = 0; }; diff --git a/tests/test_wellstatefullyimplicitblackoil.cpp b/tests/test_wellstatefullyimplicitblackoil.cpp index 97e3a6261..b480d509a 100644 --- a/tests/test_wellstatefullyimplicitblackoil.cpp +++ b/tests/test_wellstatefullyimplicitblackoil.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -57,7 +58,7 @@ struct Setup , grid (es.getInputGrid()) , python( std::make_shared() ) , sched(deck, es, python) - , st(std::chrono::system_clock::from_time_t(sched.getStartTime())) + , st(Opm::TimeService::from_time_t(sched.getStartTime())) { initWellPerfData(); }