mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Merge pull request #5731 from akva2/validation_cleanup
ValidationFunctions: some cleanup
This commit is contained in:
commit
5d4f578319
@ -21,6 +21,7 @@
|
||||
#define OPM_KEYWORDVALIDATION_HEADER_INCLUDED
|
||||
|
||||
#include <opm/common/OpmLog/KeywordLocation.hpp>
|
||||
#include <opm/simulators/flow/ValidationFunctions.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
@ -87,13 +88,6 @@ namespace KeywordValidation
|
||||
const bool include_noncritical,
|
||||
const bool include_critical);
|
||||
|
||||
|
||||
|
||||
// These are special case validation functions for keyword which do not fit nicely into the general
|
||||
// validation framework. The validation function itself is void, but error conditions are signalled by
|
||||
// appending ValidationError instances to the @errors vector.
|
||||
void validateBRINE(const DeckKeyword& keyword, std::vector<ValidationError>& errors);
|
||||
|
||||
class KeywordValidator
|
||||
{
|
||||
public:
|
||||
@ -101,7 +95,7 @@ namespace KeywordValidation
|
||||
const PartiallySupportedKeywords<std::string>& string_items,
|
||||
const PartiallySupportedKeywords<int>& int_items,
|
||||
const PartiallySupportedKeywords<double>& double_items,
|
||||
const std::unordered_map<std::string, std::function<void(const DeckKeyword& keyword, std::vector<ValidationError>& errors)>>& special_validation)
|
||||
const std::unordered_map<std::string, ValidationFunction>& special_validation)
|
||||
: m_keywords(keywords)
|
||||
, m_string_items(string_items)
|
||||
, m_int_items(int_items)
|
||||
@ -144,7 +138,7 @@ namespace KeywordValidation
|
||||
const PartiallySupportedKeywords<std::string> m_string_items;
|
||||
const PartiallySupportedKeywords<int> m_int_items;
|
||||
const PartiallySupportedKeywords<double> m_double_items;
|
||||
const std::unordered_map<std::string, std::function<void(const DeckKeyword& keyword, std::vector<ValidationError>& errors)>> m_special_validation;
|
||||
const std::unordered_map<std::string, ValidationFunction> m_special_validation;
|
||||
};
|
||||
|
||||
|
||||
|
@ -16,32 +16,37 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif // HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#include <opm/simulators/flow/ValidationFunctions.hpp>
|
||||
|
||||
#include <opm/input/eclipse/Deck/Deck.hpp>
|
||||
#include <opm/simulators/flow/KeywordValidation.hpp>
|
||||
|
||||
namespace Opm
|
||||
namespace {
|
||||
void validateBRINE(const Opm::DeckKeyword& keyword,
|
||||
std::vector<Opm::KeywordValidation::ValidationError>& errors)
|
||||
{
|
||||
if (keyword.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
errors.emplace_back(Opm::KeywordValidation::ValidationError {
|
||||
false,
|
||||
keyword.location(),
|
||||
0, // not relevant
|
||||
0, // not relevant
|
||||
std::nullopt,
|
||||
std::string{"The BRINE keyword does not accept any salt name arguments"}}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
namespace Opm::KeywordValidation {
|
||||
|
||||
std::unordered_map<std::string, ValidationFunction>
|
||||
specialValidation()
|
||||
{
|
||||
|
||||
namespace KeywordValidation
|
||||
{
|
||||
|
||||
|
||||
void validateBRINE(const DeckKeyword& keyword, std::vector<ValidationError>& errors) {
|
||||
if (keyword.size() == 0)
|
||||
return;
|
||||
|
||||
bool critical = false;
|
||||
errors.push_back( ValidationError{ critical,
|
||||
keyword.location(),
|
||||
0, // not relevant
|
||||
0, // not relevant
|
||||
std::nullopt,
|
||||
std::string{"The BRINE keyword does not accept any salt name arguments"}} );
|
||||
}
|
||||
return {{"BRINE", validateBRINE}};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,29 +17,30 @@
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef VALIDATION_FUNCTIONS_HPP
|
||||
#define VALIDATION_FUNCTIONS_HPP
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include <opm/simulators/flow/KeywordValidation.hpp>
|
||||
namespace Opm {
|
||||
class DeckKeyword;
|
||||
}
|
||||
|
||||
namespace Opm::KeywordValidation {
|
||||
|
||||
namespace Opm
|
||||
{
|
||||
namespace KeywordValidation
|
||||
{
|
||||
|
||||
|
||||
void validateBRINE(const DeckKeyword& keyword, std::vector<ValidationError>& errors);
|
||||
|
||||
struct ValidationError;
|
||||
|
||||
using ValidationFunction = std::function<void(const DeckKeyword&,
|
||||
std::vector<ValidationError>&)>;
|
||||
|
||||
// This is a mapping between keyword names and small functions
|
||||
// for validation of special keywords.
|
||||
std::unordered_map<std::string, std::function<void(const DeckKeyword& keyword, std::vector<KeywordValidation::ValidationError>& errors)>> specialValidation() {
|
||||
return {{"BRINE", validateBRINE}};
|
||||
};
|
||||
std::unordered_map<std::string, ValidationFunction>
|
||||
specialValidation();
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace Opm::KeywordValidation
|
||||
|
||||
#endif // VALIDATION_FUNCTIONS_HPP
|
||||
|
Loading…
Reference in New Issue
Block a user