From 04d2b8f39d69936c5c660e990f457b750f4e3c60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Tue, 25 Apr 2023 10:44:59 +0200 Subject: [PATCH] Make KeywordValidation::validateDeck() more flexible. Adding a bool argument 'treat_critical_as_noncritical' to possibly reduce terminating errors to warnings. --- opm/simulators/flow/KeywordValidation.cpp | 32 +++++++++++++++-------- opm/simulators/flow/KeywordValidation.hpp | 5 +++- opm/simulators/utils/readDeck.cpp | 2 +- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/opm/simulators/flow/KeywordValidation.cpp b/opm/simulators/flow/KeywordValidation.cpp index 1a3dfa8e5..523470be3 100644 --- a/opm/simulators/flow/KeywordValidation.cpp +++ b/opm/simulators/flow/KeywordValidation.cpp @@ -85,6 +85,7 @@ namespace KeywordValidation void KeywordValidator::validateDeck(const Deck& deck, const ParseContext& parse_context, + const bool treat_critical_as_noncritical, ErrorGuard& error_guard) const { // Make a vector with all problems encountered in the deck. @@ -99,18 +100,27 @@ namespace KeywordValidation } } - // First report non-critical problems as a warning. - auto warning_report = get_error_report(errors, true, false); - if (!warning_report.empty()) { - parse_context.handleError( - ParseContext::SIMULATOR_KEYWORD_NOT_SUPPORTED, warning_report, std::nullopt, error_guard); - } + if (treat_critical_as_noncritical) { + // Get both critical and noncritical errors. + auto warning_report = get_error_report(errors, true, true); + if (!warning_report.empty()) { + // Report all as warnings. + parse_context.handleError(ParseContext::SIMULATOR_KEYWORD_NOT_SUPPORTED, warning_report, std::nullopt, error_guard); + } + } else { + // First report non-critical problems as a warning. + auto warning_report = get_error_report(errors, true, false); + if (!warning_report.empty()) { + parse_context.handleError( + ParseContext::SIMULATOR_KEYWORD_NOT_SUPPORTED, warning_report, std::nullopt, error_guard); + } - // Then report critical problems as an error. - auto error_report = get_error_report(errors, false, true); - if (!error_report.empty()) { - parse_context.handleError( - ParseContext::SIMULATOR_KEYWORD_NOT_SUPPORTED_CRITICAL, error_report, std::nullopt, error_guard); + // Then report critical problems as an error. + auto error_report = get_error_report(errors, false, true); + if (!error_report.empty()) { + parse_context.handleError( + ParseContext::SIMULATOR_KEYWORD_NOT_SUPPORTED_CRITICAL, error_report, std::nullopt, error_guard); + } } } diff --git a/opm/simulators/flow/KeywordValidation.hpp b/opm/simulators/flow/KeywordValidation.hpp index cc0f01d39..e78df09ed 100644 --- a/opm/simulators/flow/KeywordValidation.hpp +++ b/opm/simulators/flow/KeywordValidation.hpp @@ -110,9 +110,12 @@ namespace KeywordValidation // Validate a deck, reporting warnings and errors. If there are only // warnings, these will be reported. If there are errors, these are - // reported, and execution of the program is halted. + // reported, and execution of the program is halted, unless the argument + // treat_critical_as_noncritical is true, then these also will only be + // reported and not cause termination. void validateDeck(const Deck& deck, const ParseContext& parse_context, + const bool treat_critical_as_noncritical, ErrorGuard& error_guard) const; // Validate a single deck keyword. If a problem is encountered, add the diff --git a/opm/simulators/utils/readDeck.cpp b/opm/simulators/utils/readDeck.cpp index e9d0b5825..9d745a4b2 100644 --- a/opm/simulators/utils/readDeck.cpp +++ b/opm/simulators/utils/readDeck.cpp @@ -203,7 +203,7 @@ namespace { Opm::KeywordValidation::specialValidation() }; - keyword_validator.validateDeck(deck, parseContext, errorGuard); + keyword_validator.validateDeck(deck, parseContext, true, errorGuard); if (checkDeck) { Opm::checkDeck(deck, parser, parseContext, errorGuard);