diff --git a/opm/simulators/flow/KeywordValidation.cpp b/opm/simulators/flow/KeywordValidation.cpp index 274eac651..111f0ce93 100644 --- a/opm/simulators/flow/KeywordValidation.cpp +++ b/opm/simulators/flow/KeywordValidation.cpp @@ -39,15 +39,20 @@ namespace KeywordValidation std::string get_error_report(const std::vector& errors, const bool critical) { const std::string keyword_format = " {keyword}: keyword not supported\n"; - const std::string item_format = " {{keyword}}: invalid value '{}' in record {} for item {}\n"; + const std::string item_format1 = " {{keyword}}: invalid value '{}' for item {}\n"; + const std::string item_format2 = " {{keyword}}: invalid value '{}' in record {} for item {}\n"; const std::string location_format = " In file: {file}, line {line}\n"; std::string report; for (const ValidationError& err : errors) { if (err.critical == critical) { if (err.item_number && err.item_value) { - std::string message - = fmt::format(item_format, *(err.item_value), err.record_number, *(err.item_number)); + std::string message; + if (err.record_number == 0) { + message = fmt::format(item_format1, *(err.item_value), *(err.item_number)); + } else { + message = fmt::format(item_format2, *(err.item_value), err.record_number, *(err.item_number)); + } report.append(OpmInputError::format(message, err.location)); } else { report.append(OpmInputError::format(keyword_format, err.location)); @@ -124,8 +129,13 @@ namespace KeywordValidation const auto& item_properties = keyword_properties->second.find(item_index + 1); if (item_properties != keyword_properties->second.end()) { // Validate the item, if it is partially supported. - validateKeywordItem( - keyword, item_properties->second, record_index, item_index, item.get(0), errors); + validateKeywordItem(keyword, + item_properties->second, + keyword.size() > 1, + record_index, + item_index, + item.get(0), + errors); } } } @@ -136,6 +146,7 @@ namespace KeywordValidation template void KeywordValidator::validateKeywordItem(const DeckKeyword& keyword, const PartiallySupportedKeywordProperties& properties, + const bool multiple_records, const size_t record_index, const size_t item_index, const T& item_value, @@ -149,11 +160,13 @@ namespace KeywordValidation formatted_value = std::to_string(item_value); else formatted_value = item_value; - // Add the relevant information to the vector of errors. + // Add the relevant information to the vector of errors. Record and + // index numbers start at 1, so add 1. Pass zero for the record + // index if there is only a single record. errors.push_back(ValidationError {properties.critical, keyword.location(), - record_index + 1, // record numbers start at 1 - item_index + 1, // item numbers start at 1 + multiple_records ? record_index + 1 : 0, + item_index + 1, formatted_value, properties.message}); } diff --git a/opm/simulators/flow/KeywordValidation.hpp b/opm/simulators/flow/KeywordValidation.hpp index 0c5f4f0d7..547bcaf5a 100644 --- a/opm/simulators/flow/KeywordValidation.hpp +++ b/opm/simulators/flow/KeywordValidation.hpp @@ -106,6 +106,7 @@ namespace KeywordValidation template void validateKeywordItem(const DeckKeyword& keyword, const PartiallySupportedKeywordProperties& properties, + const bool multiple_records, const size_t record_number, const size_t item_number, const T& item_value, diff --git a/tests/test_keyword_validator.cpp b/tests/test_keyword_validator.cpp index 6518cf387..e65758f32 100644 --- a/tests/test_keyword_validator.cpp +++ b/tests/test_keyword_validator.cpp @@ -279,7 +279,7 @@ PINCH const auto report = get_error_report(errors, false); BOOST_CHECK(report == "Unsupported keywords or keyword items:\n\n" - " PINCH: invalid value 'FOO' in record 1 for item 2\n" + " PINCH: invalid value 'FOO' for item 2\n" " In file: , line 2"); } @@ -339,7 +339,7 @@ ENDSCALE const auto report = get_error_report(errors, false); BOOST_CHECK(report == "Unsupported keywords or keyword items:\n\n" - " ENDSCALE: invalid value '0' in record 1 for item 3\n" + " ENDSCALE: invalid value '0' for item 3\n" " In file: , line 2"); } @@ -374,7 +374,7 @@ ENDSCALE const auto report = get_error_report(errors, true); BOOST_CHECK(report == "Unsupported keywords or keyword items:\n\n" - " ENDSCALE: invalid value '0' in record 1 for item 4\n" + " ENDSCALE: invalid value '0' for item 4\n" " In file: , line 2"); } @@ -422,7 +422,7 @@ ENDSCALE " ECHO: keyword not supported\n" " In file: , line 2\n" " This is not a critical error\n\n" - " ENDSCALE: invalid value '0' in record 1 for item 3\n" + " ENDSCALE: invalid value '0' for item 3\n" " In file: , line 6"); } @@ -452,7 +452,7 @@ ENDSCALE == "Unsupported keywords or keyword items:\n\n" " NOECHO: keyword not supported\n" " In file: , line 3\n\n" - " PINCH: invalid value 'FOO' in record 1 for item 4\n" + " PINCH: invalid value 'FOO' for item 4\n" " In file: , line 4\n" " This is a critical error"); }