mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Refactor get_error_report() for more flexibility.
This commit is contained in:
parent
4bf2dd7269
commit
77d151e0b5
@ -31,6 +31,7 @@
|
|||||||
#include <opm/input/eclipse/Deck/Deck.hpp>
|
#include <opm/input/eclipse/Deck/Deck.hpp>
|
||||||
#include <opm/input/eclipse/Deck/DeckKeyword.hpp>
|
#include <opm/input/eclipse/Deck/DeckKeyword.hpp>
|
||||||
#include <opm/input/eclipse/Parser/ErrorGuard.hpp>
|
#include <opm/input/eclipse/Parser/ErrorGuard.hpp>
|
||||||
|
#include <opm/input/eclipse/Parser/InputErrorAction.hpp>
|
||||||
#include <opm/input/eclipse/Parser/ParseContext.hpp>
|
#include <opm/input/eclipse/Parser/ParseContext.hpp>
|
||||||
#include <opm/simulators/flow/KeywordValidation.hpp>
|
#include <opm/simulators/flow/KeywordValidation.hpp>
|
||||||
|
|
||||||
@ -43,7 +44,7 @@ namespace KeywordValidation
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
std::string get_error_report(const std::vector<ValidationError>& errors, const bool critical)
|
std::string get_error_report(const std::vector<ValidationError>& errors, const bool include_noncritical, const bool include_critical)
|
||||||
{
|
{
|
||||||
const std::string keyword_format = " {keyword}: keyword not supported\n";
|
const std::string keyword_format = " {keyword}: keyword not supported\n";
|
||||||
const std::string item_format1 = " {{keyword}}: invalid value '{}' for item {}\n";
|
const std::string item_format1 = " {{keyword}}: invalid value '{}' for item {}\n";
|
||||||
@ -52,7 +53,7 @@ namespace KeywordValidation
|
|||||||
|
|
||||||
std::string report;
|
std::string report;
|
||||||
for (const ValidationError& err : errors) {
|
for (const ValidationError& err : errors) {
|
||||||
if (err.critical == critical) {
|
if ((err.critical && include_critical) || (!err.critical && include_noncritical)) {
|
||||||
if (err.item_number && err.item_value) {
|
if (err.item_number && err.item_value) {
|
||||||
std::string message;
|
std::string message;
|
||||||
if (err.record_number == 0) {
|
if (err.record_number == 0) {
|
||||||
@ -99,14 +100,14 @@ namespace KeywordValidation
|
|||||||
}
|
}
|
||||||
|
|
||||||
// First report non-critical problems as a warning.
|
// First report non-critical problems as a warning.
|
||||||
auto warning_report = get_error_report(errors, false);
|
auto warning_report = get_error_report(errors, true, false);
|
||||||
if (!warning_report.empty()) {
|
if (!warning_report.empty()) {
|
||||||
parse_context.handleError(
|
parse_context.handleError(
|
||||||
ParseContext::SIMULATOR_KEYWORD_NOT_SUPPORTED, warning_report, std::nullopt, error_guard);
|
ParseContext::SIMULATOR_KEYWORD_NOT_SUPPORTED, warning_report, std::nullopt, error_guard);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then report critical problems as an error.
|
// Then report critical problems as an error.
|
||||||
auto error_report = get_error_report(errors, true);
|
auto error_report = get_error_report(errors, false, true);
|
||||||
if (!error_report.empty()) {
|
if (!error_report.empty()) {
|
||||||
parse_context.handleError(
|
parse_context.handleError(
|
||||||
ParseContext::SIMULATOR_KEYWORD_NOT_SUPPORTED_CRITICAL, error_report, std::nullopt, error_guard);
|
ParseContext::SIMULATOR_KEYWORD_NOT_SUPPORTED_CRITICAL, error_report, std::nullopt, error_guard);
|
||||||
|
@ -78,11 +78,12 @@ namespace KeywordValidation
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Get a formatted error report from a vector of validation errors. Set
|
// Get a formatted error report from a vector of validation errors. Set
|
||||||
// critical to true if the report should contain only critical errors. If
|
// include_noncritical to true if the report should include noncritical errors, and
|
||||||
// critical is false, only non-critical errors are reported. If not
|
// include_critical to true if the report should include critical errors. These may
|
||||||
// critical/non-critical errors are present, but the critical flag to reset
|
// be set independently. If no errors are included the result will be an empty string.
|
||||||
// them, the result will be an empty string.
|
std::string get_error_report(const std::vector<ValidationError>& errors,
|
||||||
std::string get_error_report(const std::vector<ValidationError>& errors, const bool critical);
|
const bool include_noncritical,
|
||||||
|
const bool include_critical);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -277,7 +277,7 @@ ECHO
|
|||||||
KeywordValidator validator(test_unsupported_keywords, test_string_items, test_int_items, test_double_items, {});
|
KeywordValidator validator(test_unsupported_keywords, test_string_items, test_int_items, test_double_items, {});
|
||||||
std::vector<ValidationError> errors;
|
std::vector<ValidationError> errors;
|
||||||
validator.validateDeckKeyword(test_keyword, errors);
|
validator.validateDeckKeyword(test_keyword, errors);
|
||||||
const auto report = get_error_report(errors, false);
|
const auto report = get_error_report(errors, true, false);
|
||||||
BOOST_CHECK(report
|
BOOST_CHECK(report
|
||||||
== "Unsupported keywords or keyword items:\n\n"
|
== "Unsupported keywords or keyword items:\n\n"
|
||||||
" ECHO: keyword not supported\n"
|
" ECHO: keyword not supported\n"
|
||||||
@ -296,7 +296,7 @@ ECHO
|
|||||||
KeywordValidator validator(test_unsupported_keywords, test_string_items, test_int_items, test_double_items, {});
|
KeywordValidator validator(test_unsupported_keywords, test_string_items, test_int_items, test_double_items, {});
|
||||||
std::vector<ValidationError> errors;
|
std::vector<ValidationError> errors;
|
||||||
validator.validateDeckKeyword(test_keyword, errors);
|
validator.validateDeckKeyword(test_keyword, errors);
|
||||||
const auto report = get_error_report(errors, true);
|
const auto report = get_error_report(errors, false, true);
|
||||||
BOOST_CHECK(report.empty());
|
BOOST_CHECK(report.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,7 +311,7 @@ NOECHO
|
|||||||
KeywordValidator validator(test_unsupported_keywords, test_string_items, test_int_items, test_double_items, {});
|
KeywordValidator validator(test_unsupported_keywords, test_string_items, test_int_items, test_double_items, {});
|
||||||
std::vector<ValidationError> errors;
|
std::vector<ValidationError> errors;
|
||||||
validator.validateDeckKeyword(test_keyword, errors);
|
validator.validateDeckKeyword(test_keyword, errors);
|
||||||
const auto report = get_error_report(errors, true);
|
const auto report = get_error_report(errors, false, true);
|
||||||
BOOST_CHECK(report
|
BOOST_CHECK(report
|
||||||
== "Unsupported keywords or keyword items:\n\n"
|
== "Unsupported keywords or keyword items:\n\n"
|
||||||
" NOECHO: keyword not supported\n"
|
" NOECHO: keyword not supported\n"
|
||||||
@ -329,7 +329,7 @@ NOECHO
|
|||||||
KeywordValidator validator(test_unsupported_keywords, test_string_items, test_int_items, test_double_items, {});
|
KeywordValidator validator(test_unsupported_keywords, test_string_items, test_int_items, test_double_items, {});
|
||||||
std::vector<ValidationError> errors;
|
std::vector<ValidationError> errors;
|
||||||
validator.validateDeckKeyword(test_keyword, errors);
|
validator.validateDeckKeyword(test_keyword, errors);
|
||||||
const auto report = get_error_report(errors, false);
|
const auto report = get_error_report(errors, true, false);
|
||||||
BOOST_CHECK(report.empty());
|
BOOST_CHECK(report.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -345,7 +345,7 @@ PINCH
|
|||||||
KeywordValidator validator(test_unsupported_keywords, test_string_items, test_int_items, test_double_items, {});
|
KeywordValidator validator(test_unsupported_keywords, test_string_items, test_int_items, test_double_items, {});
|
||||||
std::vector<ValidationError> errors;
|
std::vector<ValidationError> errors;
|
||||||
validator.validateDeckKeyword(test_keyword, errors);
|
validator.validateDeckKeyword(test_keyword, errors);
|
||||||
const auto report = get_error_report(errors, false);
|
const auto report = get_error_report(errors, true, false);
|
||||||
BOOST_CHECK(report
|
BOOST_CHECK(report
|
||||||
== "Unsupported keywords or keyword items:\n\n"
|
== "Unsupported keywords or keyword items:\n\n"
|
||||||
" PINCH: invalid value 'FOO' for item 2\n"
|
" PINCH: invalid value 'FOO' for item 2\n"
|
||||||
@ -368,7 +368,7 @@ COMPDAT
|
|||||||
KeywordValidator validator(test_unsupported_keywords, test_string_items, test_int_items, test_double_items, {});
|
KeywordValidator validator(test_unsupported_keywords, test_string_items, test_int_items, test_double_items, {});
|
||||||
std::vector<ValidationError> errors;
|
std::vector<ValidationError> errors;
|
||||||
validator.validateDeckKeyword(test_keyword, errors);
|
validator.validateDeckKeyword(test_keyword, errors);
|
||||||
const auto report = get_error_report(errors, false);
|
const auto report = get_error_report(errors, true, false);
|
||||||
BOOST_CHECK(report
|
BOOST_CHECK(report
|
||||||
== "Unsupported keywords or keyword items:\n\n"
|
== "Unsupported keywords or keyword items:\n\n"
|
||||||
" COMPDAT: invalid value '0' in record 1 for item 2\n"
|
" COMPDAT: invalid value '0' in record 1 for item 2\n"
|
||||||
@ -389,7 +389,7 @@ PINCH
|
|||||||
KeywordValidator validator(test_unsupported_keywords, test_string_items, test_int_items, test_double_items, {});
|
KeywordValidator validator(test_unsupported_keywords, test_string_items, test_int_items, test_double_items, {});
|
||||||
std::vector<ValidationError> errors;
|
std::vector<ValidationError> errors;
|
||||||
validator.validateDeckKeyword(test_keyword, errors);
|
validator.validateDeckKeyword(test_keyword, errors);
|
||||||
const auto report = get_error_report(errors, true);
|
const auto report = get_error_report(errors, false, true);
|
||||||
BOOST_CHECK(report.empty());
|
BOOST_CHECK(report.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -405,7 +405,7 @@ ENDSCALE
|
|||||||
KeywordValidator validator(test_unsupported_keywords, test_string_items, test_int_items, test_double_items, {});
|
KeywordValidator validator(test_unsupported_keywords, test_string_items, test_int_items, test_double_items, {});
|
||||||
std::vector<ValidationError> errors;
|
std::vector<ValidationError> errors;
|
||||||
validator.validateDeckKeyword(test_keyword, errors);
|
validator.validateDeckKeyword(test_keyword, errors);
|
||||||
const auto report = get_error_report(errors, false);
|
const auto report = get_error_report(errors, true, false);
|
||||||
BOOST_CHECK(report
|
BOOST_CHECK(report
|
||||||
== "Unsupported keywords or keyword items:\n\n"
|
== "Unsupported keywords or keyword items:\n\n"
|
||||||
" ENDSCALE: invalid value '0' for item 3\n"
|
" ENDSCALE: invalid value '0' for item 3\n"
|
||||||
@ -424,7 +424,7 @@ ENDSCALE
|
|||||||
KeywordValidator validator(test_unsupported_keywords, test_string_items, test_int_items, test_double_items, {});
|
KeywordValidator validator(test_unsupported_keywords, test_string_items, test_int_items, test_double_items, {});
|
||||||
std::vector<ValidationError> errors;
|
std::vector<ValidationError> errors;
|
||||||
validator.validateDeckKeyword(test_keyword, errors);
|
validator.validateDeckKeyword(test_keyword, errors);
|
||||||
const auto report = get_error_report(errors, true);
|
const auto report = get_error_report(errors, false, true);
|
||||||
BOOST_CHECK(report.empty());
|
BOOST_CHECK(report.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -440,7 +440,7 @@ ENDSCALE
|
|||||||
KeywordValidator validator(test_unsupported_keywords, test_string_items, test_int_items, test_double_items, {});
|
KeywordValidator validator(test_unsupported_keywords, test_string_items, test_int_items, test_double_items, {});
|
||||||
std::vector<ValidationError> errors;
|
std::vector<ValidationError> errors;
|
||||||
validator.validateDeckKeyword(test_keyword, errors);
|
validator.validateDeckKeyword(test_keyword, errors);
|
||||||
const auto report = get_error_report(errors, true);
|
const auto report = get_error_report(errors, false, true);
|
||||||
BOOST_CHECK(report
|
BOOST_CHECK(report
|
||||||
== "Unsupported keywords or keyword items:\n\n"
|
== "Unsupported keywords or keyword items:\n\n"
|
||||||
" ENDSCALE: invalid value '0' for item 4\n"
|
" ENDSCALE: invalid value '0' for item 4\n"
|
||||||
@ -459,7 +459,7 @@ ENDSCALE
|
|||||||
KeywordValidator validator(test_unsupported_keywords, test_string_items, test_int_items, test_double_items, {});
|
KeywordValidator validator(test_unsupported_keywords, test_string_items, test_int_items, test_double_items, {});
|
||||||
std::vector<ValidationError> errors;
|
std::vector<ValidationError> errors;
|
||||||
validator.validateDeckKeyword(test_keyword, errors);
|
validator.validateDeckKeyword(test_keyword, errors);
|
||||||
const auto report = get_error_report(errors, false);
|
const auto report = get_error_report(errors, true, false);
|
||||||
BOOST_CHECK(report.empty());
|
BOOST_CHECK(report.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -485,7 +485,7 @@ ENDSCALE
|
|||||||
validator.validateDeckKeyword(test_keyword2, errors);
|
validator.validateDeckKeyword(test_keyword2, errors);
|
||||||
validator.validateDeckKeyword(test_keyword3, errors);
|
validator.validateDeckKeyword(test_keyword3, errors);
|
||||||
validator.validateDeckKeyword(test_keyword4, errors);
|
validator.validateDeckKeyword(test_keyword4, errors);
|
||||||
const auto report = get_error_report(errors, false);
|
const auto report = get_error_report(errors, true, false);
|
||||||
BOOST_CHECK(report
|
BOOST_CHECK(report
|
||||||
== "Unsupported keywords or keyword items:\n\n"
|
== "Unsupported keywords or keyword items:\n\n"
|
||||||
" ECHO: keyword not supported\n"
|
" ECHO: keyword not supported\n"
|
||||||
@ -516,7 +516,7 @@ ENDSCALE
|
|||||||
validator.validateDeckKeyword(test_keyword2, errors);
|
validator.validateDeckKeyword(test_keyword2, errors);
|
||||||
validator.validateDeckKeyword(test_keyword3, errors);
|
validator.validateDeckKeyword(test_keyword3, errors);
|
||||||
validator.validateDeckKeyword(test_keyword4, errors);
|
validator.validateDeckKeyword(test_keyword4, errors);
|
||||||
const auto report = get_error_report(errors, true);
|
const auto report = get_error_report(errors, false, true);
|
||||||
BOOST_CHECK(report
|
BOOST_CHECK(report
|
||||||
== "Unsupported keywords or keyword items:\n\n"
|
== "Unsupported keywords or keyword items:\n\n"
|
||||||
" NOECHO: keyword not supported\n"
|
" NOECHO: keyword not supported\n"
|
||||||
|
Loading…
Reference in New Issue
Block a user