Merge pull request #2586 from joakim-hove/foam-validation

Enforce keyword requirement with "requires": []
This commit is contained in:
Joakim Hove 2021-08-04 07:53:15 +02:00 committed by GitHub
commit d36e5a86a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 22 deletions

View File

@ -21,6 +21,7 @@
#include <opm/parser/eclipse/Deck/DeckItem.hpp> #include <opm/parser/eclipse/Deck/DeckItem.hpp>
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp> #include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
#include <opm/parser/eclipse/Deck/DeckRecord.hpp> #include <opm/parser/eclipse/Deck/DeckRecord.hpp>
#include <opm/common/utility/OpmInputError.hpp>
#include <opm/parser/eclipse/EclipseState/InitConfig/FoamConfig.hpp> #include <opm/parser/eclipse/EclipseState/InitConfig/FoamConfig.hpp>
#include <opm/parser/eclipse/Parser/ParserKeywords/F.hpp> #include <opm/parser/eclipse/Parser/ParserKeywords/F.hpp>
@ -132,25 +133,19 @@ FoamConfig::FoamConfig(const Deck& deck)
// setup for foam at this point, so we detect and deal with it here even though we // setup for foam at this point, so we detect and deal with it here even though we
// do not store any data related to it. // do not store any data related to it.
const auto& kw_foamopts = deck.getKeyword<ParserKeywords::FOAMOPTS>(); const auto& kw_foamopts = deck.getKeyword<ParserKeywords::FOAMOPTS>();
transport_phase_ = get_phase(kw_foamopts.getRecord(0).getItem(0).get<std::string>(0)); this->transport_phase_ = get_phase(kw_foamopts.getRecord(0).getItem(0).get<std::string>(0));
std::string mobModel = kw_foamopts.getRecord(0).getItem(1).get<std::string>(0); if (!(this->transport_phase_ == Phase::GAS || this->transport_phase_ == Phase::WATER))
if (mobModel.empty()) { throw OpmInputError("Only WATER and GAS phases are allowed for foam transport", kw_foamopts.location());
if (transport_phase_ == Phase::GAS) {
mobility_model_ = MobilityModel::TAB; this->mobility_model_ = MobilityModel::TAB;
} else if (transport_phase_ == Phase::WATER) { if (this->transport_phase_ == Phase::WATER) {
mobility_model_ = MobilityModel::FUNC; auto mobModel = kw_foamopts.getRecord(0).getItem(1).get<std::string>(0);
} if (mobModel == "FUNC")
} else if (mobModel == "TAB") { this->mobility_model_ = MobilityModel::FUNC;
mobility_model_ = MobilityModel::TAB;
} else if (mobModel == "FUNC") {
mobility_model_ = MobilityModel::FUNC;
} }
} }
if (deck.hasKeyword<ParserKeywords::FOAMFSC>()) { if (deck.hasKeyword<ParserKeywords::FOAMFSC>()) {
if (!deck.hasKeyword<ParserKeywords::FOAMROCK>()) {
throw std::runtime_error("FOAMFSC present but no FOAMROCK keyword found.");
}
// We have both FOAMFSC and FOAMROCK.
const auto& kw_foamfsc = deck.getKeyword<ParserKeywords::FOAMFSC>(); const auto& kw_foamfsc = deck.getKeyword<ParserKeywords::FOAMFSC>();
const auto& kw_foamrock = deck.getKeyword<ParserKeywords::FOAMROCK>(); const auto& kw_foamrock = deck.getKeyword<ParserKeywords::FOAMROCK>();
if (kw_foamfsc.size() != kw_foamrock.size()) { if (kw_foamfsc.size() != kw_foamrock.size()) {

View File

@ -3,6 +3,7 @@
"sections": [ "sections": [
"PROPS" "PROPS"
], ],
"requires" : ["FOAMROCK"],
"size": { "size": {
"keyword": "TABDIMS", "keyword": "TABDIMS",
"item": "NTSFUN" "item": "NTSFUN"

View File

@ -82,15 +82,16 @@ PROPS
FOAMOPTS FOAMOPTS
GAS TAB / GAS TAB /
FOAMROCK
1 2000 /
2 1800 /
2 2400 /
FOAMFSC FOAMFSC
1 2 0.3 / 1 2 0.3 /
4 5 / 4 5 /
6 / 6 /
FOAMROCK
1 2000 /
2 1800 /
2 2400 /
REGIONS REGIONS
SWAT SWAT
@ -194,7 +195,6 @@ BOOST_AUTO_TEST_CASE(FoamConfigTest) {
} }
BOOST_AUTO_TEST_CASE(FoamConfigFailureTest) { BOOST_AUTO_TEST_CASE(FoamConfigFailureTest) {
auto deck = createFailingDeck(); BOOST_CHECK_THROW( createFailingDeck(), std::exception );
BOOST_CHECK_THROW(EclipseState state(deck), std::runtime_error);
} }