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.
This commit is contained in:
Jørgen Kvalsvik
2016-07-20 16:26:46 +02:00
parent 0e53246009
commit 295ef91063
11 changed files with 87 additions and 131 deletions

View File

@@ -27,6 +27,7 @@
#include <opm/parser/eclipse/EclipseState/Grid/GridDims.hpp>
#include <opm/parser/eclipse/EclipseState/InitConfig/InitConfig.hpp>
#include <opm/parser/eclipse/EclipseState/IOConfig/IOConfig.hpp>
#include <opm/parser/eclipse/EclipseState/IOConfig/RestartConfig.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp>
#include <opm/parser/eclipse/EclipseState/SimulationConfig/SimulationConfig.hpp>
@@ -41,7 +42,8 @@ namespace Opm {
m_ioConfig( std::make_shared<IOConfig>(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;
}

View File

@@ -25,6 +25,7 @@
#include <opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.hpp>
#include <opm/parser/eclipse/EclipseState/InitConfig/InitConfig.hpp>
#include <opm/parser/eclipse/EclipseState/SimulationConfig/SimulationConfig.hpp>
#include <opm/parser/eclipse/EclipseState/IOConfig/RestartConfig.hpp>
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<const IOConfig> getIOConfigConst() const;
std::shared_ptr<IOConfig> getIOConfig() const;
const InitConfig& getInitConfig() const;
const SimulationConfig & getSimulationConfig() const;
const SummaryConfig& getSummaryConfig() const;
const RestartConfig& getRestartConfig() const;
private:
std::shared_ptr<IOConfig> m_ioConfig;
const InitConfig m_initConfig;
const SimulationConfig m_simulationConfig;
SummaryConfig m_summaryConfig;
RestartConfig m_restartConfig;
};
}

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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

View File

@@ -22,8 +22,6 @@
#include <boost/date_time/gregorian/gregorian_types.hpp>
#include <opm/parser/eclipse/EclipseState/IOConfig/RestartConfig.hpp>
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 );

View File

@@ -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<std::string>& keywords) {
if (keywords.size() > 0) {
std::set<std::string> kw_set = this->restart_keywords->back();
std::set<std::string> 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<int>& integer_controls) {
std::set<std::string> keywords = this->restart_keywords->back();
std::set<std::string> 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<RestartSchedule>(timemap , RestartSchedule(0 ,0 ,1)) );
restart_keywords.reset( new DynamicState<std::set<std::string>>( 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<std::string>& 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 );
}

View File

@@ -22,6 +22,8 @@
#include <vector>
#include <set>
#include <opm/parser/eclipse/EclipseState/Schedule/DynamicState.hpp>
#include <boost/date_time.hpp>
/*
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<DynamicState<RestartSchedule>> restart_schedule;
std::shared_ptr<DynamicState<std::set<std::string>>> restart_keywords;
DynamicState< RestartSchedule > restart_schedule;
DynamicState< std::set< std::string > > restart_keywords;
};
} //namespace Opm

View File

@@ -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 ) );
}

View File

@@ -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));
}

View File

@@ -28,7 +28,7 @@
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp>
#include <opm/parser/eclipse/EclipseState/IOConfig/IOConfig.hpp>
#include <opm/parser/eclipse/EclipseState/IOConfig/RestartConfig.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp>
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
@@ -36,16 +36,16 @@
using namespace Opm;
inline void verifyRestartConfig(const IOConfig& io, std::vector<std::tuple<int , bool, boost::gregorian::date>>& rptConfig) {
inline void verifyRestartConfig( const RestartConfig& rst, std::vector<std::tuple<int , bool, boost::gregorian::date>>& 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 );
}