Add whitelist of keywords allowed in ACTIONX block

This commit is contained in:
Joakim Hove
2018-10-26 09:13:26 +02:00
parent e7660b0613
commit b8c5d8c129
5 changed files with 48 additions and 1 deletions

View File

@@ -253,6 +253,15 @@ namespace Opm {
*/
const static std::string SCHEDULE_INVALID_NAME;
/*
Only keywords explicitly white-listed can be included in the ACTIONX
block. This error flag controls what should happen when an illegal
keyword is encountered in an ACTIONX block.
*/
const static std::string ACTIONX_ILLEGAL_KEYWORD;
private:
void initDefault();
void initEnv();

View File

@@ -23,6 +23,9 @@
namespace Opm {
ActionX::ActionX(const std::string& name, size_t max_run, double max_wait) :
m_name(name),
max_run(max_run),

View File

@@ -21,6 +21,7 @@
#include <vector>
#include <stdexcept>
#include <iostream>
#include <set>
#include <boost/algorithm/string.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
@@ -61,6 +62,9 @@
namespace Opm {
static std::set<std::string> actionx_whitelist = {"WELSPECS","WELOPEN"};
Schedule::Schedule( const Deck& deck,
const EclipseGrid& grid,
const Eclipse3DProperties& eclipseProperties,
@@ -307,7 +311,11 @@ namespace Opm {
if (action_keyword.name() == "ENDACTIO")
break;
action.addKeyword(action_keyword);
if (actionx_whitelist.find(action_keyword.name()) == actionx_whitelist.end()) {
std::string msg = "The keyword " + action_keyword.name() + " is not supported in a ACTIONX block.";
parseContext.handleError( ParseContext::ACTIONX_ILLEGAL_KEYWORD, msg);
} else
action.addKeyword(action_keyword);
}
} else
this->handleKeyword(currentStep, section, keywordIdx, keyword, parseContext, grid, eclipseProperties, unit_system, rftProperties);

View File

@@ -86,6 +86,8 @@ namespace Opm {
addKey(SUMMARY_UNKNOWN_WELL, InputError::THROW_EXCEPTION);
addKey(SUMMARY_UNKNOWN_GROUP, InputError::THROW_EXCEPTION);
addKey(SCHEDULE_INVALID_NAME, InputError::THROW_EXCEPTION);
addKey(ACTIONX_ILLEGAL_KEYWORD, InputError::THROW_EXCEPTION);
}
void ParseContext::initEnv() {
@@ -272,6 +274,7 @@ namespace Opm {
const std::string ParseContext::SUMMARY_UNKNOWN_GROUP = "SUMMARY_UNKNOWN_GROUP";
const std::string ParseContext::SCHEDULE_INVALID_NAME = "SCHEDULE_INVALID_NAME";
const std::string ParseContext::ACTIONX_ILLEGAL_KEYWORD = "ACTIONX_ILLEGAL_KEYWORD";
}

View File

@@ -82,11 +82,30 @@ WELSPECS
'W1' 'OP' 1 1 3.33 'OIL' 7*/
/
ENDACTIO
)"};
const auto WITH_GRID = std::string{ R"(
SCHEDULE
WELSPECS
'W2' 'OP' 1 1 3.33 'OIL' 7*/
/
ACTIONX
'ACTION' /
WWCT OPX > 0.75 /
/
PORO
100*0.78 /
ENDACTIO
)"};
Opm::Parser parser;
auto deck1 = parser.parseString(MISSING_END, Opm::ParseContext());
auto deck2 = parser.parseString(WITH_WELSPECS, Opm::ParseContext());
auto deck3 = parser.parseString(WITH_GRID, Opm::ParseContext());
EclipseGrid grid1(10,10,10);
TableManager table ( deck1 );
Eclipse3DProperties eclipseProperties ( deck1 , table, grid1);
@@ -97,4 +116,9 @@ ENDACTIO
Schedule sched(deck2, grid1, eclipseProperties, Phases(true,true,true), ParseContext());
BOOST_CHECK( !sched.hasWell("W1") );
BOOST_CHECK( sched.hasWell("W2"));
// The deck3 contains the 'GRID' keyword in the ACTIONX block - that is not a whitelisted keyword.
ParseContext parseContext( {{ParseContext::ACTIONX_ILLEGAL_KEYWORD, InputError::THROW_EXCEPTION}} );
BOOST_CHECK_THROW(Schedule(deck3, grid1, eclipseProperties, Phases(true,true,true), parseContext), std::invalid_argument);
}