diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index b5af3d043..1f8ef5a57 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -564,6 +564,7 @@ if(ENABLE_ECL_INPUT) tests/UDQ_WCONPROD_GRID.grdecl tests/UDQ_WCONPROD_RESTART.DATA tests/UDQ_WCONPROD.X0006 + tests/BASE.UNRST ) list (APPEND EXAMPLE_SOURCE_FILES examples/opmi.cpp diff --git a/src/opm/parser/eclipse/EclipseState/EclipseState.cpp b/src/opm/parser/eclipse/EclipseState/EclipseState.cpp index e94ec1160..5735eec3b 100644 --- a/src/opm/parser/eclipse/EclipseState/EclipseState.cpp +++ b/src/opm/parser/eclipse/EclipseState/EclipseState.cpp @@ -25,8 +25,10 @@ #include #include #include +#include #include +#include #include #include @@ -151,6 +153,21 @@ AquiferConfig load_aquifers(const Deck& deck, const TableManager& tables, NNC& i if (deck.hasKeyword( "MICPPARA" )) { this->initPara(deck); } + + const auto& init_config = this->getInitConfig(); + if (init_config.restartRequested()) { + const auto& io_config = this->getIOConfig(); + const int report_step = init_config.getRestartStep(); + const auto& restart_file = io_config.getRestartFileName( init_config.getRestartRootName(), report_step, false); + if (!filesystem::exists(restart_file)) + throw std::logic_error(fmt::format("The restart file: {} does not exist", restart_file)); + + if (io_config.getUNIFIN()) { + EclIO::ERst rst{restart_file}; + if (!rst.hasReportStepNumber(report_step)) + throw std::logic_error(fmt::format("Report step: {} not found in restart file: {}", report_step, restart_file)); + } + } } catch (const OpmInputError& opm_error) { OpmLog::error(opm_error.what()); diff --git a/tests/BASE.UNRST b/tests/BASE.UNRST new file mode 100644 index 000000000..7bdf08bdf Binary files /dev/null and b/tests/BASE.UNRST differ diff --git a/tests/parser/InitConfigTest.cpp b/tests/parser/InitConfigTest.cpp index c1aa65792..3b512e944 100644 --- a/tests/parser/InitConfigTest.cpp +++ b/tests/parser/InitConfigTest.cpp @@ -34,6 +34,76 @@ using namespace Opm; + +const std::string full_deck1 = R"( +START +7 OCT 2020 / + +RUNSPEC + +DIMENS + 10 10 3 / + +UNIFIN + +GRID +DXV + 10*100.0 / +DYV + 10*100.0 / +DZV + 3*10.0 / + +DEPTHZ + 121*2000.0 / + +PORO + 300*0.3 / + +SOLUTION + +RESTART + NOBASE 6 / + +SCHEDULE +)"; + +const std::string full_deck2 = R"( +START +7 OCT 2020 / + +RUNSPEC + +DIMENS + 10 10 3 / + +UNIFIN + +GRID +DXV + 10*100.0 / +DYV + 10*100.0 / +DZV + 3*10.0 / + +DEPTHZ + 121*2000.0 / + +PORO + 300*0.3 / + +SOLUTION + +RESTART + BASE 6 / + +SCHEDULE +)"; + + + + const std::string& deckStr = "RUNSPEC\n" "DIMENS\n" @@ -117,7 +187,22 @@ const std::string& deckWithEquil = static Deck createDeck(const std::string& input) { Opm::Parser parser; - return parser.parseString(input); + auto deck = parser.parseString(input); + // The call to setDataFile is completely bogus, it is just to ensure that a + // meaningfull path for the input file has been specified - so that we can + // locate restart files. + deck.setDataFile("SPE1CASE1.DATA"); + return deck; +} + +BOOST_AUTO_TEST_CASE(EclipseStateTest) { + Deck deck1 = createDeck(full_deck1); + // This throws because the restart file does not exist + BOOST_CHECK_THROW(EclipseState{deck1}, std::exception); + + Deck deck2 = createDeck(full_deck2); + // This throws because the restart file does not contain the requested report step + BOOST_CHECK_THROW(EclipseState{deck2}, std::exception); } BOOST_AUTO_TEST_CASE(InitConfigTest) {