From c82286f7d82aa713ca1894d437be948279c9393c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Thu, 10 Mar 2022 17:43:31 +0100 Subject: [PATCH] Disallow Wells Parented Directly to FIELD The commercial simulator does not support parenting a well directly to the FIELD group and Flow in multiple locations implicitly assumes that no well is parented directly to FIELD either. With this commit we detect this situation at the parser stage and stop reading the input file. In this case, we issue a diagnostic message of the form Error: Problem with keyword WELSPECS In SPE1CASE1.DATA line 384 Wells cannot be parented directly to 'FIELD'. Wells entered with disallowed 'FIELD' parent group: * PROD * INJ Error: Unrecoverable errors were encountered while loading input --- .../eclipse/Schedule/KeywordHandlers.cpp | 43 ++++++++++++++----- .../integration_tests/IOConfig/RPT_TEST2.DATA | 2 +- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/opm/input/eclipse/Schedule/KeywordHandlers.cpp b/src/opm/input/eclipse/Schedule/KeywordHandlers.cpp index 8c6ba23fb..788899157 100644 --- a/src/opm/input/eclipse/Schedule/KeywordHandlers.cpp +++ b/src/opm/input/eclipse/Schedule/KeywordHandlers.cpp @@ -1404,23 +1404,36 @@ File {} line {}.)", wname, location.keyword, location.filename, location.lineno) } } - void Schedule::handleWELSPECS(HandlerContext& handlerContext) { - const auto& keyword = handlerContext.keyword; - for (std::size_t recordNr = 0; recordNr < keyword.size(); recordNr++) { - const auto& record = keyword.getRecord(recordNr); - const std::string& wellName = trim_wgname(keyword, record.getItem().get(0), handlerContext.parseContext, handlerContext.errors); - const std::string& groupName = trim_wgname(keyword, record.getItem().get(0), handlerContext.parseContext, handlerContext.errors); - auto density_calc_type = record.getItem().get(0); - auto fip_region_number = record.getItem().get(0); + void Schedule::handleWELSPECS(HandlerContext& handlerContext) + { + auto getTrimmedName = [&handlerContext](const auto& item) + { + return trim_wgname(handlerContext.keyword, + item.template get(0), + handlerContext.parseContext, + handlerContext.errors); + }; + auto fieldWells = std::vector{}; + for (const auto& record : handlerContext.keyword) { + const auto wellName = getTrimmedName(record.getItem()); + const auto groupName = getTrimmedName(record.getItem()); + + if (groupName == "FIELD") { + fieldWells.push_back(wellName); + continue; + } + + const auto fip_region_number = record.getItem().get(0); if (fip_region_number != 0) { - const auto& location = keyword.location(); + const auto& location = handlerContext.keyword.location(); std::string msg = "The FIP_REGION item in the WELSPECS keyword in file: " + location.filename + " line: " + std::to_string(location.lineno) + " using default value: " + std::to_string(ParserKeywords::WELSPECS::FIP_REGION::defaultValue); OpmLog::warning(msg); } + const auto& density_calc_type = record.getItem().get(0); if (density_calc_type != "SEG") { - const auto& location = keyword.location(); + const auto& location = handlerContext.keyword.location(); std::string msg = "The DENSITY_CALC item in the WELSPECS keyword in file: " + location.filename + " line: " + std::to_string(location.lineno) + " using default value: " + ParserKeywords::WELSPECS::DENSITY_CALC::defaultValue; OpmLog::warning(msg); } @@ -1474,6 +1487,16 @@ File {} line {}.)", wname, location.keyword, location.filename, location.lineno) this->addWellToGroup(groupName, wellName, handlerContext.currentStep); } + + if (! fieldWells.empty()) { + const auto* plural = (fieldWells.size() == 1) ? "" : "s"; + + throw OpmInputError { + fmt::format(R"(Well{0} cannot be parented directly to 'FIELD'. +Well{0} entered with disallowed 'FIELD' parent group: + * {1})", plural, fmt::join(fieldWells, "\n * ")), handlerContext.keyword.location() + }; + } } /* diff --git a/tests/parser/data/integration_tests/IOConfig/RPT_TEST2.DATA b/tests/parser/data/integration_tests/IOConfig/RPT_TEST2.DATA index 043ee154b..02d38ce54 100644 --- a/tests/parser/data/integration_tests/IOConfig/RPT_TEST2.DATA +++ b/tests/parser/data/integration_tests/IOConfig/RPT_TEST2.DATA @@ -43,7 +43,7 @@ RPTRST --NORST=1 --> output for visualization only WELSPECS - 'F-14A' 'FIELD' 12 85 99.00 'OIL' 7* / + 'F-14A' 'G' 12 85 99.00 'OIL' 7* / / DATES