diff --git a/src/opm/parser/eclipse/EclipseState/InitConfig/InitConfig.cpp b/src/opm/parser/eclipse/EclipseState/InitConfig/InitConfig.cpp index 741a59ae9..1b629d642 100644 --- a/src/opm/parser/eclipse/EclipseState/InitConfig/InitConfig.cpp +++ b/src/opm/parser/eclipse/EclipseState/InitConfig/InitConfig.cpp @@ -56,10 +56,14 @@ namespace Opm { "only from RESTART files"); } - const std::string& root = record.getItem( 0 ).get< std::string >( 0 ); int step = record.getItem( 1 ).get< int >(0); + const std::string& root = record.getItem( 0 ).get< std::string >( 0 ); + const std::string& input_path = deck.getInputPath(); - this->setRestart( root, step ); + if (root[0] == '/' || input_path.empty()) + this->setRestart(root, step); + else + this->setRestart( input_path + "/" + root, step ); } void InitConfig::setRestart( const std::string& root, int step) { diff --git a/tests/parser/InitConfigTest.cpp b/tests/parser/InitConfigTest.cpp index 5e7d03180..939506e1a 100644 --- a/tests/parser/InitConfigTest.cpp +++ b/tests/parser/InitConfigTest.cpp @@ -20,6 +20,8 @@ #define BOOST_TEST_MODULE InitConfigTests +#include +#include #include @@ -30,6 +32,7 @@ #include #include +#include using namespace Opm; @@ -84,6 +87,18 @@ const std::string& deckStr4 = "19 JUN 2007 / \n" "SCHEDULE\n"; +const std::string& deckStr5 = + "RUNSPEC\n" + "DIMENS\n" + " 10 10 10 /\n" + "SOLUTION\n" + "RESTART\n" + "'/abs/path/BASE' 5 /\n" + "GRID\n" + "START -- 0 \n" + "19 JUN 2007 / \n" + "SCHEDULE\n"; + const std::string& deckWithEquil = "RUNSPEC\n" "DIMENS\n" @@ -172,3 +187,51 @@ BOOST_AUTO_TEST_CASE( EquilOperations ) { BOOST_CHECK( !record.wetGasInitConstantRv() ); BOOST_CHECK_EQUAL( 20, record.initializationTargetAccuracy() ); } + +BOOST_AUTO_TEST_CASE(RestartCWD) { + test_work_area_type * work_area = test_work_area_alloc("restart_cwd"); + mkdir("simulation", 0777); + { + std::fstream fs; + fs.open ("simulation/CASE.DATA", std::fstream::out); + fs << deckStr4; + fs.close(); + + fs.open("simulation/CASE5.DATA", std::fstream::out); + fs << deckStr5; + fs.close(); + + fs.open("CASE5.DATA", std::fstream::out); + fs << deckStr5; + fs.close(); + + fs.open("CWD_CASE.DATA", std::fstream::out); + fs << deckStr4; + fs.close(); + } + Opm::Parser parser; + { + Opm::Deck deck = parser.parseFile("simulation/CASE.DATA", Opm::ParseContext()); + Opm::InitConfig init_config(deck); + BOOST_CHECK_EQUAL(init_config.getRestartRootName(), "simulation/BASE"); + } + { + Opm::Deck deck = parser.parseFile("simulation/CASE5.DATA", Opm::ParseContext()); + Opm::InitConfig init_config(deck); + BOOST_CHECK_EQUAL(init_config.getRestartRootName(), "/abs/path/BASE"); + } + { + Opm::Deck deck = parser.parseFile("CWD_CASE.DATA", Opm::ParseContext()); + Opm::InitConfig init_config(deck); + BOOST_CHECK_EQUAL(init_config.getRestartRootName(), "BASE"); + } + { + Opm::Deck deck = parser.parseFile("CASE5.DATA", Opm::ParseContext()); + Opm::InitConfig init_config(deck); + BOOST_CHECK_EQUAL(init_config.getRestartRootName(), "/abs/path/BASE"); + } + + test_work_area_free(work_area); +} + +