From 295ef910631b4b64ad3f2113b2f68f0549124aba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Kvalsvik?= Date: Wed, 20 Jul 2016 16:26:46 +0200 Subject: [PATCH] Moved RestartConfig out of IOConfig RestartConfig is a first-class citizen of EclipseConfig rather than being embedded in IOConfig. This narrows IOConfig's responsibility to only that of paths file system definitions and interactions, and RestartConfig to what and when to output the restart file. --- .../eclipse/EclipseState/EclipseConfig.cpp | 13 ++++- .../eclipse/EclipseState/EclipseConfig.hpp | 4 ++ .../eclipse/EclipseState/EclipseState.cpp | 8 +++ .../eclipse/EclipseState/EclipseState.hpp | 3 ++ .../EclipseState/IOConfig/IOConfig.cpp | 31 +----------- .../EclipseState/IOConfig/IOConfig.hpp | 10 +--- .../EclipseState/IOConfig/RestartConfig.cpp | 35 +++++++------ .../EclipseState/IOConfig/RestartConfig.hpp | 49 +++++++++++-------- .../IOConfig/tests/IOConfigTest.cpp | 39 --------------- .../EclipseState/tests/EclipseStateTests.cpp | 8 +-- .../IOConfigIntegrationTest.cpp | 18 +++---- 11 files changed, 87 insertions(+), 131 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/EclipseConfig.cpp b/opm/parser/eclipse/EclipseState/EclipseConfig.cpp index 6a5799b4c..29daf4276 100644 --- a/opm/parser/eclipse/EclipseState/EclipseConfig.cpp +++ b/opm/parser/eclipse/EclipseState/EclipseConfig.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -41,7 +42,8 @@ namespace Opm { m_ioConfig( std::make_shared(deck)), m_initConfig( deck), m_simulationConfig(deck, eclipse3DProperties), - m_summaryConfig( deck, schedule, eclipse3DProperties, parseContext , inputGrid.getNXYZ()) + m_summaryConfig( deck, schedule, eclipse3DProperties, parseContext , inputGrid.getNXYZ()), + m_restartConfig( deck ) { m_ioConfig->initFirstRFTOutput(schedule); } @@ -67,11 +69,20 @@ namespace Opm { return m_summaryConfig; } + const RestartConfig& EclipseConfig::restart() const { + return this->m_restartConfig; + } + // [[deprecated]] --- use summary() const SummaryConfig& EclipseConfig::getSummaryConfig() const { return summary(); } + // [[deprecated]] --- use restart() + const RestartConfig& EclipseConfig::getRestartConfig() const { + return this->restart(); + } + IOConfigConstPtr EclipseConfig::getIOConfigConst() const { return m_ioConfig; } diff --git a/opm/parser/eclipse/EclipseState/EclipseConfig.hpp b/opm/parser/eclipse/EclipseState/EclipseConfig.hpp index 00d180bcc..248c80511 100644 --- a/opm/parser/eclipse/EclipseState/EclipseConfig.hpp +++ b/opm/parser/eclipse/EclipseState/EclipseConfig.hpp @@ -25,6 +25,7 @@ #include #include #include +#include namespace Opm { @@ -48,18 +49,21 @@ namespace Opm { IOConfig& io(); const SimulationConfig & simulation() const; const SummaryConfig& summary() const; + const RestartConfig& restart() const; std::shared_ptr getIOConfigConst() const; std::shared_ptr getIOConfig() const; const InitConfig& getInitConfig() const; const SimulationConfig & getSimulationConfig() const; const SummaryConfig& getSummaryConfig() const; + const RestartConfig& getRestartConfig() const; private: std::shared_ptr m_ioConfig; const InitConfig m_initConfig; const SimulationConfig m_simulationConfig; SummaryConfig m_summaryConfig; + RestartConfig m_restartConfig; }; } diff --git a/opm/parser/eclipse/EclipseState/EclipseState.cpp b/opm/parser/eclipse/EclipseState/EclipseState.cpp index 19af68219..93602bd7c 100644 --- a/opm/parser/eclipse/EclipseState/EclipseState.cpp +++ b/opm/parser/eclipse/EclipseState/EclipseState.cpp @@ -111,6 +111,14 @@ namespace Opm { return m_eclipseConfig.getSummaryConfig(); } + const RestartConfig& EclipseState::getRestartConfig() const { + return m_eclipseConfig.getRestartConfig(); + } + + RestartConfig& EclipseState::getRestartConfig() { + return const_cast< RestartConfig& >( m_eclipseConfig.getRestartConfig() ); + } + const Eclipse3DProperties& EclipseState::get3DProperties() const { return m_eclipseProperties; } diff --git a/opm/parser/eclipse/EclipseState/EclipseState.hpp b/opm/parser/eclipse/EclipseState/EclipseState.hpp index 21c209674..3be3afa5c 100644 --- a/opm/parser/eclipse/EclipseState/EclipseState.hpp +++ b/opm/parser/eclipse/EclipseState/EclipseState.hpp @@ -47,6 +47,7 @@ namespace Opm { class InitConfig; class IOConfig; class ParseContext; + class RestartConfig; class Schedule; class Section; class SimulationConfig; @@ -76,6 +77,8 @@ namespace Opm { const InitConfig& getInitConfig() const; const SimulationConfig& getSimulationConfig() const; const SummaryConfig& getSummaryConfig() const; + const RestartConfig& getRestartConfig() const; + RestartConfig& getRestartConfig(); std::shared_ptr< const EclipseGrid > getInputGrid() const; std::shared_ptr< EclipseGrid > getInputGridCopy() const; diff --git a/opm/parser/eclipse/EclipseState/IOConfig/IOConfig.cpp b/opm/parser/eclipse/EclipseState/IOConfig/IOConfig.cpp index 44ed8d45e..5a66b4be1 100644 --- a/opm/parser/eclipse/EclipseState/IOConfig/IOConfig.cpp +++ b/opm/parser/eclipse/EclipseState/IOConfig/IOConfig.cpp @@ -59,8 +59,6 @@ namespace Opm { IOConfig::IOConfig( const Deck& deck ) : IOConfig( GRIDSection( deck ), RUNSPECSection( deck ), - SOLUTIONSection( deck ), - SCHEDULESection( deck ), std::make_shared< const TimeMap >( deck ), deck.hasKeyword("NOSIM"), deck.getDataFile() ) @@ -99,8 +97,6 @@ namespace Opm { IOConfig::IOConfig( const GRIDSection& grid, const RUNSPECSection& runspec, - const SOLUTIONSection& solution, - const SCHEDULESection& schedule, std::shared_ptr< const TimeMap > timemap, bool nosim, const std::string& input_path ) : @@ -114,16 +110,10 @@ namespace Opm { m_deck_filename( input_path ), m_output_dir( outputdir( input_path ) ), m_base_name( basename( input_path ) ), - m_nosim( nosim ), - m_restart_config( RestartConfig( schedule , solution , timemap)) + m_nosim( nosim ) {} - const RestartConfig& IOConfig::restartConfig() const { - return m_restart_config; - } - - bool IOConfig::getWriteEGRIDFile() const { return m_write_EGRID_file; } @@ -256,23 +246,4 @@ namespace Opm { remove these forwarding methods. */ - - - void IOConfig::overrideRestartWriteInterval(size_t interval) { - m_restart_config.overrideRestartWriteInterval(interval); - } - - - bool IOConfig::getWriteRestartFile(size_t timestep) const { - return m_restart_config.getWriteRestartFile( timestep ); - } - - int IOConfig::getFirstRestartStep() const { - return m_restart_config.getFirstRestartStep(); - } - - void IOConfig::setWriteInitialRestartFile(bool writeInitialRestartFile) { - m_restart_config.setWriteInitialRestartFile( writeInitialRestartFile ); - } - } //namespace Opm diff --git a/opm/parser/eclipse/EclipseState/IOConfig/IOConfig.hpp b/opm/parser/eclipse/EclipseState/IOConfig/IOConfig.hpp index 3539a8d70..44c8d0d3d 100644 --- a/opm/parser/eclipse/EclipseState/IOConfig/IOConfig.hpp +++ b/opm/parser/eclipse/EclipseState/IOConfig/IOConfig.hpp @@ -22,8 +22,6 @@ #include -#include - namespace Opm { template< typename > class DynamicState; @@ -32,8 +30,6 @@ namespace Opm { class DeckKeyword; class GRIDSection; class RUNSPECSection; - class SCHEDULESection; - class SOLUTIONSection; class TimeMap; class Schedule; @@ -158,7 +154,6 @@ namespace Opm { std::string fullBasePath( ) const; bool initOnly() const; - const RestartConfig& restartConfig() const; void initFirstRFTOutput(const Schedule& schedule); // Proxy methods forwarding directly to corresponding RestartConfig @@ -166,6 +161,7 @@ namespace Opm { int getFirstRestartStep() const; void overrideRestartWriteInterval(size_t interval); void setWriteInitialRestartFile(bool writeInitialRestartFile); + private: std::shared_ptr< const TimeMap > m_timemap; bool m_write_INIT_file = false; @@ -181,13 +177,9 @@ namespace Opm { std::string m_output_dir; std::string m_base_name; bool m_nosim; - RestartConfig m_restart_config; - IOConfig( const GRIDSection&, const RUNSPECSection&, - const SOLUTIONSection&, - const SCHEDULESection&, std::shared_ptr< const TimeMap >, bool nosim, const std::string& input_path ); diff --git a/opm/parser/eclipse/EclipseState/IOConfig/RestartConfig.cpp b/opm/parser/eclipse/EclipseState/IOConfig/RestartConfig.cpp index e92c0e24e..03a453d46 100644 --- a/opm/parser/eclipse/EclipseState/IOConfig/RestartConfig.cpp +++ b/opm/parser/eclipse/EclipseState/IOConfig/RestartConfig.cpp @@ -261,9 +261,9 @@ namespace Opm { void RestartConfig::update( size_t step, const RestartSchedule& rs) { if (step == 0) - this->restart_schedule->updateInitial( rs ); + this->restart_schedule.updateInitial( rs ); else - this->restart_schedule->update( step, rs ); + this->restart_schedule.update( step, rs ); } @@ -278,14 +278,14 @@ namespace Opm { void RestartConfig::addKeywords( size_t step, const std::vector& keywords) { if (keywords.size() > 0) { - std::set kw_set = this->restart_keywords->back(); + std::set kw_set = this->restart_keywords.back(); for (const auto& kw : keywords ) insertKeyword( kw_set , kw ); if (step == 0) - this->restart_keywords->updateInitial( kw_set ); + this->restart_keywords.updateInitial( kw_set ); else - this->restart_keywords->update( step , kw_set ); + this->restart_keywords.update( step , kw_set ); } } @@ -298,7 +298,7 @@ namespace Opm { */ void RestartConfig::updateKeywords( size_t step, const std::vector& integer_controls) { - std::set keywords = this->restart_keywords->back(); + std::set keywords = this->restart_keywords.back(); for (size_t index = 0; index < integer_controls.size(); index++) { if (index == 26) { @@ -324,9 +324,9 @@ namespace Opm { } if (step == 0) - this->restart_keywords->updateInitial( keywords ); + this->restart_keywords.updateInitial( keywords ); else - this->restart_keywords->update( step , keywords ); + this->restart_keywords.update( step , keywords ); } @@ -359,7 +359,7 @@ namespace Opm { if (is_RPTRST) { handleRPTRST( keyword, current_step ); // Was -1?? - const auto& rs = this->restart_schedule->back(); + const auto& rs = this->restart_schedule.back(); if (rs.basic > 2) ignore_RPTSCHED_restart = true; } else { @@ -421,20 +421,19 @@ namespace Opm { const SOLUTIONSection& solution, std::shared_ptr< const TimeMap > timemap) : m_timemap( timemap ), - m_first_restart_step( -1 ) + m_first_restart_step( -1 ), + restart_schedule( timemap, { 0, 0, 1 } ), + restart_keywords( timemap, {} ) { - restart_schedule.reset( new DynamicState(timemap , RestartSchedule(0 ,0 ,1)) ); - restart_keywords.reset( new DynamicState>( timemap, {})); - - handleSolutionSection( solution ) ; - handleScheduleSection( schedule ) ; + handleSolutionSection( solution ); + handleScheduleSection( schedule ); initFirstOutput( ); } RestartSchedule RestartConfig::getNode( size_t timestep ) const{ - return restart_schedule->get(timestep); + return restart_schedule.get(timestep); } @@ -450,7 +449,7 @@ namespace Opm { const std::set& RestartConfig::getRestartKeywords( size_t timestep ) const { - return restart_keywords->at( timestep ); + return restart_keywords.at( timestep ); } @@ -507,7 +506,7 @@ namespace Opm { size_t basic = interval > 0 ? 3 : 0; RestartSchedule rs( step, basic, interval ); - restart_schedule->globalReset( rs ); + restart_schedule.globalReset( rs ); setWriteInitialRestartFile( interval > 0 ); } diff --git a/opm/parser/eclipse/EclipseState/IOConfig/RestartConfig.hpp b/opm/parser/eclipse/EclipseState/IOConfig/RestartConfig.hpp index 5ca12027d..6a3f64012 100644 --- a/opm/parser/eclipse/EclipseState/IOConfig/RestartConfig.hpp +++ b/opm/parser/eclipse/EclipseState/IOConfig/RestartConfig.hpp @@ -22,6 +22,8 @@ #include #include +#include +#include /* The RestartConfig class internalizes information of when (at which @@ -283,30 +285,30 @@ namespace Opm { class RestartSchedule { /* - The content of this struct is logically divided in two; either the - restart behaviour is governed by { timestep , basic , frequency }, or - alternatively by { rptshec_restart_set , rptsched_restart }. + The content of this struct is logically divided in two; either the + restart behaviour is governed by { timestep , basic , frequency }, or + alternatively by { rptshec_restart_set , rptsched_restart }. - The former triplet is mainly governed by the RPTRST keyword and the - latter pair by the RPTSCHED keyword. - */ - public: + The former triplet is mainly governed by the RPTRST keyword and the + latter pair by the RPTSCHED keyword. + */ + public: - RestartSchedule() = default; - RestartSchedule( size_t sched_restart); - RestartSchedule( size_t step, size_t b, size_t freq); - bool writeRestartFile( size_t timestep , const TimeMap& timemap) const; - bool operator!=(const RestartSchedule& rhs) const; - bool operator==( const RestartSchedule& rhs ) const; + RestartSchedule() = default; + RestartSchedule( size_t sched_restart); + RestartSchedule( size_t step, size_t b, size_t freq); + bool writeRestartFile( size_t timestep , const TimeMap& timemap) const; + bool operator!=(const RestartSchedule& rhs) const; + bool operator==( const RestartSchedule& rhs ) const; //private: - size_t timestep = 0; - size_t basic = 0; - size_t frequency = 0; - bool rptsched_restart_set = false; - size_t rptsched_restart = 0; + size_t timestep = 0; + size_t basic = 0; + size_t frequency = 0; + bool rptsched_restart_set = false; + size_t rptsched_restart = 0; }; // } @@ -314,7 +316,7 @@ namespace Opm { public: - RestartConfig() = default; + RestartConfig(); explicit RestartConfig( const Deck& ); RestartConfig( const SCHEDULESection& schedule, const SOLUTIONSection& solution, @@ -329,6 +331,11 @@ namespace Opm { void handleSolutionSection(const SOLUTIONSection& solutionSection); void setWriteInitialRestartFile(bool writeInitialRestartFile); + boost::gregorian::date getTimestepDate(size_t reportStep) const { + auto time = (*m_timemap)[reportStep]; + return time.date(); + } + RestartSchedule getNode( size_t timestep ) const; static std::string getRestartFileName(const std::string& restart_base, int report_step, bool unified, bool fmt_file); private: @@ -360,8 +367,8 @@ namespace Opm { void handleRPTRST( const DeckKeyword&, size_t ); static RestartSchedule rptsched( const DeckKeyword& ); - std::shared_ptr> restart_schedule; - std::shared_ptr>> restart_keywords; + DynamicState< RestartSchedule > restart_schedule; + DynamicState< std::set< std::string > > restart_keywords; }; } //namespace Opm diff --git a/opm/parser/eclipse/EclipseState/IOConfig/tests/IOConfigTest.cpp b/opm/parser/eclipse/EclipseState/IOConfig/tests/IOConfigTest.cpp index 1646a205a..feac4b953 100644 --- a/opm/parser/eclipse/EclipseState/IOConfig/tests/IOConfigTest.cpp +++ b/opm/parser/eclipse/EclipseState/IOConfig/tests/IOConfigTest.cpp @@ -317,42 +317,3 @@ BOOST_AUTO_TEST_CASE(OutputPaths) { BOOST_CHECK_EQUAL( "testString", config3.getBaseName() ); BOOST_CHECK_EQUAL( testpath, config3.fullBasePath() ); } - - -BOOST_AUTO_TEST_CASE(RPTSCHED_and_RPTRST) { - const char *deckData = - "RUNSPEC\n" - "DIMENS\n" - " 10 10 10 /\n" - "GRID\n" - "START -- 0 \n" - "19 JUN 2007 / \n" - "SCHEDULE\n" - "DATES -- 1\n" - " 10 OKT 2008 / \n" - "/\n" - "RPTRST\n" - "BASIC=3 FREQ=3\n" - "/\n" - "DATES -- 2\n" - " 20 JAN 2010 / \n" - "/\n" - "DATES -- 3\n" - " 20 FEB 2010 / \n" - "/\n" - "RPTSCHED\n" - "RESTART=1\n" - "/\n"; - - - Opm::Parser parser; - ParseContext ctx; - - auto deck = parser.parseString( deckData, ctx ); - IOConfig ioConfig( *deck ); - - BOOST_CHECK( !ioConfig.getWriteRestartFile( 0 ) ); - BOOST_CHECK( !ioConfig.getWriteRestartFile( 1 ) ); - BOOST_CHECK( !ioConfig.getWriteRestartFile( 2 ) ); - BOOST_CHECK( ioConfig.getWriteRestartFile( 3 ) ); -} diff --git a/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp b/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp index 1c7a50a32..e27fe00e4 100644 --- a/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp +++ b/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp @@ -498,7 +498,7 @@ BOOST_AUTO_TEST_CASE(TestIOConfigCreation) { EclipseState state(*deck , ParseContext()); const IOConfig& ioConfig = state.cfg().io(); - const RestartConfig& rstConfig = ioConfig.restartConfig(); + const RestartConfig& rstConfig = state.cfg().restart(); BOOST_CHECK_EQUAL(false, rstConfig.getWriteRestartFile(0)); BOOST_CHECK_EQUAL(false, rstConfig.getWriteRestartFile(1)); @@ -550,7 +550,7 @@ BOOST_AUTO_TEST_CASE(TestIOConfigCreationWithSolutionRPTRST) { EclipseState state(*deck, parseContext); const IOConfig& ioConfig = state.cfg().io(); - const RestartConfig& rstConfig = ioConfig.restartConfig(); + const RestartConfig& rstConfig = state.cfg().restart(); BOOST_CHECK_EQUAL(true , rstConfig.getWriteRestartFile(0)); BOOST_CHECK_EQUAL(false , rstConfig.getWriteRestartFile(1)); @@ -642,7 +642,7 @@ BOOST_AUTO_TEST_CASE(TestIOConfigCreationWithSolutionRPTSOL) { EclipseState state(*deck, parseContext); const IOConfig& ioConfig = state.cfg().io(); - const RestartConfig& rstConfig = ioConfig.restartConfig(); + const RestartConfig& rstConfig = state.cfg().restart(); BOOST_CHECK_EQUAL(true, rstConfig.getWriteRestartFile(0)); } @@ -652,7 +652,7 @@ BOOST_AUTO_TEST_CASE(TestIOConfigCreationWithSolutionRPTSOL) { EclipseState state(*deck, parseContext); const IOConfig& ioConfig = state.cfg().io(); - const RestartConfig& rstConfig = ioConfig.restartConfig(); + const RestartConfig& rstConfig = state.cfg().restart(); BOOST_CHECK_EQUAL(true, rstConfig.getWriteRestartFile(0)); } diff --git a/opm/parser/eclipse/IntegrationTests/IOConfigIntegrationTest.cpp b/opm/parser/eclipse/IntegrationTests/IOConfigIntegrationTest.cpp index eeb6c86d8..c327b9ec7 100644 --- a/opm/parser/eclipse/IntegrationTests/IOConfigIntegrationTest.cpp +++ b/opm/parser/eclipse/IntegrationTests/IOConfigIntegrationTest.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include @@ -36,16 +36,16 @@ using namespace Opm; -inline void verifyRestartConfig(const IOConfig& io, std::vector>& rptConfig) { +inline void verifyRestartConfig( const RestartConfig& rst, std::vector>& rptConfig) { for (auto rptrst : rptConfig) { int report_step = std::get<0>(rptrst); bool save = std::get<1>(rptrst); boost::gregorian::date report_date = std::get<2>(rptrst); - BOOST_CHECK_EQUAL( save , io.restartConfig().getWriteRestartFile( report_step )); + BOOST_CHECK_EQUAL( save, rst.getWriteRestartFile( report_step ) ); if (save) { - BOOST_CHECK_EQUAL( report_date, io.getTimestepDate( report_step )); + BOOST_CHECK_EQUAL( report_date, rst.getTimestepDate( report_step )); } } } @@ -297,7 +297,7 @@ BOOST_AUTO_TEST_CASE( NorneRestartConfig ) { auto state = Parser::parse("testdata/integration_tests/IOConfig/RPTRST_DECK.DATA"); - verifyRestartConfig(state.cfg().io(), rptConfig); + verifyRestartConfig(state.cfg().restart(), rptConfig); } @@ -338,11 +338,11 @@ BOOST_AUTO_TEST_CASE( RestartConfig2 ) { ParseContext parseContext; ParserPtr parser(new Parser()); DeckConstPtr deck = parser->parseFile("testdata/integration_tests/IOConfig/RPT_TEST2.DATA", parseContext); - EclipseState state( *deck , parseContext ); - const IOConfig& ioConfig = state.cfg().io(); - verifyRestartConfig(ioConfig, rptConfig); + EclipseState state( deck , parseContext ); + const auto& rstConfig = state.cfg().restart(); + verifyRestartConfig( rstConfig, rptConfig ); - BOOST_CHECK_EQUAL( ioConfig.getFirstRestartStep() , 0 ); + BOOST_CHECK_EQUAL( rstConfig.getFirstRestartStep() , 0 ); }