Better error messages when the RESTART keyword is invalid

This commit is contained in:
Joakim Hove 2021-10-17 19:59:29 +02:00
parent 3b2d650f8d
commit a13376c2d1
4 changed files with 104 additions and 1 deletions

View File

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

View File

@ -25,8 +25,10 @@
#include <opm/common/OpmLog/InfoLogger.hpp>
#include <opm/common/OpmLog/LogUtil.hpp>
#include <opm/common/utility/OpmInputError.hpp>
#include <opm/common/utility/FileSystem.hpp>
#include <opm/io/eclipse/rst/aquifer.hpp>
#include <opm/io/eclipse/ERst.hpp>
#include <opm/parser/eclipse/Deck/DeckSection.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
@ -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());

BIN
tests/BASE.UNRST Normal file

Binary file not shown.

View File

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