ACTIONX will handle WLIST well arguments
This commit is contained in:
parent
f4f993586a
commit
f500adba24
@ -75,7 +75,7 @@ void msim::post_step(Schedule& schedule, Action::State& action_state, SummarySta
|
||||
if (actions.empty())
|
||||
return;
|
||||
|
||||
Action::Context context( st );
|
||||
Action::Context context( st , schedule.getWListManager(report_step));
|
||||
|
||||
auto sim_time = schedule.simTime(report_step);
|
||||
for (const auto& action : actions.pending(action_state, sim_time)) {
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <map>
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Well/WListManager.hpp>
|
||||
|
||||
namespace Opm {
|
||||
namespace Action {
|
||||
@ -37,7 +38,7 @@ namespace Action {
|
||||
|
||||
class Context {
|
||||
public:
|
||||
explicit Context(const SummaryState& summary_state);
|
||||
explicit Context(const SummaryState& summary_state, const WListManager& wlm);
|
||||
|
||||
/*
|
||||
The get methods will first check the internal storage in the 'values' map
|
||||
@ -50,9 +51,11 @@ public:
|
||||
void add(const std::string& func, double value);
|
||||
|
||||
std::vector<std::string> wells(const std::string& func) const;
|
||||
const WListManager& wlist_manager() const;
|
||||
|
||||
private:
|
||||
const SummaryState& summary_state;
|
||||
const WListManager& wlm;
|
||||
std::map<std::string, double> values;
|
||||
};
|
||||
}
|
||||
|
@ -483,7 +483,7 @@ const std::map<cmp_enum, int> cmpToIndex = {
|
||||
act_res(const Opm::Schedule& sched, const Opm::Action::State& action_state, const Opm::SummaryState& smry, const std::size_t sim_step, std::vector<Opm::Action::ActionX>::const_iterator act_x) {
|
||||
auto sim_time = sched.simTime(sim_step);
|
||||
if (act_x->ready(action_state, sim_time)) {
|
||||
Opm::Action::Context context(smry);
|
||||
Opm::Action::Context context(smry, sched.getWListManager(sim_step));
|
||||
return act_x->eval(context);
|
||||
} else
|
||||
return Opm::Action::Result(false);
|
||||
|
@ -811,7 +811,7 @@ namespace {
|
||||
act_res_stat(const Opm::Schedule& sched, const Opm::Action::State& action_state, const Opm::SummaryState& smry, const std::size_t sim_step) {
|
||||
std::vector<std::pair<std::string, Opm::Action::Result>> results;
|
||||
const auto& acts = sched.actions(sim_step);
|
||||
Opm::Action::Context context(smry);
|
||||
Opm::Action::Context context(smry, sched.getWListManager(sim_step));
|
||||
auto sim_time = sched.simTime(sim_step);
|
||||
for (const auto& action : acts.pending(action_state, sim_time)) {
|
||||
auto result = action->eval(context);
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Action/ActionContext.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Action/ActionValue.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Action/ASTNode.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Well/WList.hpp>
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
@ -106,16 +107,27 @@ Action::Value ASTNode::value(const Action::Context& context) const {
|
||||
The matching code is special case to handle one-argument cases with
|
||||
well patterns like 'P*'.
|
||||
*/
|
||||
if ((this->arg_list.size() == 1) && (arg_list[0].find("*") != std::string::npos)) {
|
||||
if ((this->arg_list.size() == 1) && (this->arg_list[0].find("*") != std::string::npos)) {
|
||||
if (this->func_type != FuncType::well)
|
||||
throw std::logic_error(": attempted to action-evaluate list not of type well.");
|
||||
|
||||
const auto& well_arg = this->arg_list[0];
|
||||
Action::Value well_values;
|
||||
int fnmatch_flags = 0;
|
||||
for (const auto& well : context.wells(this->func)) {
|
||||
if (fnmatch(this->arg_list[0].c_str(), well.c_str(), fnmatch_flags) == 0)
|
||||
well_values.add_well(well, context.get(this->func, well));
|
||||
std::vector<std::string> wnames;
|
||||
|
||||
if (well_arg[0] == '*' && well_arg.size() > 1) {
|
||||
const auto& wlm = context.wlist_manager();
|
||||
wnames = wlm.wells(well_arg);
|
||||
} else {
|
||||
int fnmatch_flags = 0;
|
||||
for (const auto& well : context.wells(this->func)) {
|
||||
if (fnmatch(well_arg.c_str(), well.c_str(), fnmatch_flags) == 0)
|
||||
wnames.push_back(well);
|
||||
}
|
||||
}
|
||||
for (const auto& wname : wnames)
|
||||
well_values.add_well(wname, context.get(this->func, wname));
|
||||
|
||||
return well_values;
|
||||
} else {
|
||||
std::string arg_key = this->arg_list[0];
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Action/ActionContext.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp>
|
||||
|
||||
namespace Opm {
|
||||
namespace Action {
|
||||
@ -28,8 +27,9 @@ namespace Action {
|
||||
this->values[func + ":" + arg] = value;
|
||||
}
|
||||
|
||||
Context::Context(const SummaryState& summary_state_arg) :
|
||||
summary_state(summary_state_arg)
|
||||
Context::Context(const SummaryState& summary_state_arg, const WListManager& wlm_) :
|
||||
summary_state(summary_state_arg),
|
||||
wlm(wlm_)
|
||||
{
|
||||
for (const auto& pair : TimeMap::eclipseMonthIndices())
|
||||
this->add(pair.first, pair.second);
|
||||
@ -57,5 +57,9 @@ namespace Action {
|
||||
return this->summary_state.wells(key);
|
||||
}
|
||||
|
||||
|
||||
const WListManager& Context::wlist_manager() const {
|
||||
return this->wlm;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,6 +39,8 @@
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Action/Actions.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Action/State.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Action/ActionX.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Well/WList.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Well/WListManager.hpp>
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
@ -150,7 +152,8 @@ TSTEP
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestActions) {
|
||||
Opm::SummaryState st(std::chrono::system_clock::now());
|
||||
Opm::Action::Context context(st);
|
||||
Opm::WListManager wlm;
|
||||
Opm::Action::Context context(st, wlm);
|
||||
Opm::Action::Actions config;
|
||||
std::vector<std::string> matching_wells;
|
||||
auto python = std::make_shared<Opm::Python>();
|
||||
@ -204,7 +207,8 @@ BOOST_AUTO_TEST_CASE(TestActions) {
|
||||
BOOST_AUTO_TEST_CASE(TestContext) {
|
||||
Opm::SummaryState st(std::chrono::system_clock::now());
|
||||
st.update_well_var("OP1", "WOPR", 100);
|
||||
Opm::Action::Context context(st);
|
||||
Opm::WListManager wlm;
|
||||
Opm::Action::Context context(st, wlm);
|
||||
|
||||
BOOST_REQUIRE_THROW(context.get("func", "arg"), std::out_of_range);
|
||||
|
||||
@ -259,7 +263,8 @@ BOOST_AUTO_TEST_CASE(TestAction_AST_BASIC) {
|
||||
Action::AST ast2({"WWCT", "OPX", "=", "WWCT", "OPX"});
|
||||
Action::AST ast3({"WWCT", "OPY", ">", "0.75"});
|
||||
SummaryState st(std::chrono::system_clock::now());
|
||||
Action::Context context(st);
|
||||
WListManager wlm;
|
||||
Action::Context context(st, wlm);
|
||||
std::vector<std::string> matching_wells;
|
||||
|
||||
context.add("WWCT", "OPX", 100);
|
||||
@ -277,7 +282,8 @@ BOOST_AUTO_TEST_CASE(TestAction_AST_OR_AND) {
|
||||
Action::AST ast_and({"WWCT", "OPX", ">", "0.75", "AND", "WWCT", "OPY", ">", "0.75"});
|
||||
Action::AST par({"WWCT", "OPX", ">", "0.75", "AND", "(", "WWCT", "OPY", ">", "0.75", "OR", "WWCT", "OPZ", ">", "0.75", ")"});
|
||||
SummaryState st(std::chrono::system_clock::now());
|
||||
Action::Context context(st);
|
||||
WListManager wlm;
|
||||
Action::Context context(st, wlm);
|
||||
|
||||
context.add("WWCT", "OPX", 100);
|
||||
context.add("WWCT", "OPY", -100);
|
||||
@ -313,7 +319,8 @@ BOOST_AUTO_TEST_CASE(TestAction_AST_OR_AND) {
|
||||
BOOST_AUTO_TEST_CASE(DATE) {
|
||||
Action::AST ast(std::vector<std::string>{"MNTH", ">=", "JUN"});
|
||||
SummaryState st(std::chrono::system_clock::now());
|
||||
Action::Context context(st);
|
||||
WListManager wlm;
|
||||
Action::Context context(st, wlm);
|
||||
|
||||
context.add("MNTH", 6);
|
||||
BOOST_CHECK( ast.eval(context));
|
||||
@ -329,7 +336,8 @@ BOOST_AUTO_TEST_CASE(DATE) {
|
||||
BOOST_AUTO_TEST_CASE(MANUAL1) {
|
||||
Action::AST ast({"GGPR", "FIELD", ">", "50000", "AND", "WGOR", "PR", ">" ,"GGOR", "FIELD"});
|
||||
SummaryState st(std::chrono::system_clock::now());
|
||||
Action::Context context(st);
|
||||
WListManager wlm;
|
||||
Action::Context context(st, wlm);
|
||||
|
||||
context.add("GGPR", "FIELD", 60000 );
|
||||
context.add("WGOR", "PR" , 300 );
|
||||
@ -350,7 +358,8 @@ BOOST_AUTO_TEST_CASE(MANUAL1) {
|
||||
BOOST_AUTO_TEST_CASE(MANUAL2) {
|
||||
Action::AST ast({"GWCT", "LIST1", ">", "0.70", "AND", "(", "GWPR", "LIST1", ">", "GWPR", "LIST2", "OR", "GWPR", "LIST1", ">", "GWPR", "LIST3", ")"});
|
||||
SummaryState st(std::chrono::system_clock::now());
|
||||
Action::Context context(st);
|
||||
WListManager wlm;
|
||||
Action::Context context(st, wlm);
|
||||
|
||||
context.add("GWCT", "LIST1", 1.0);
|
||||
context.add("GWPR", "LIST1", 1 );
|
||||
@ -386,7 +395,8 @@ BOOST_AUTO_TEST_CASE(MANUAL2) {
|
||||
BOOST_AUTO_TEST_CASE(MANUAL3) {
|
||||
Action::AST ast({"MNTH", ".GE.", "MAR", "AND", "MNTH", ".LE.", "OCT", "AND", "GMWL", "HIGH", ".GE.", "4"});
|
||||
SummaryState st(std::chrono::system_clock::now());
|
||||
Action::Context context(st);
|
||||
WListManager wlm;
|
||||
Action::Context context(st, wlm);
|
||||
|
||||
context.add("MNTH", 4);
|
||||
context.add("GMWL", "HIGH", 4);
|
||||
@ -409,7 +419,8 @@ BOOST_AUTO_TEST_CASE(MANUAL3) {
|
||||
BOOST_AUTO_TEST_CASE(MANUAL4) {
|
||||
Action::AST ast({"GWCT", "FIELD", ">", "0.8", "AND", "DAY", ">", "1", "AND", "MNTH", ">", "JUN", "AND", "YEAR", ">=", "2021"});
|
||||
SummaryState st(std::chrono::system_clock::now());
|
||||
Action::Context context(st);
|
||||
WListManager wlm;
|
||||
Action::Context context(st, wlm);
|
||||
|
||||
context.add("MNTH", 7);
|
||||
context.add("DAY", 2);
|
||||
@ -429,7 +440,8 @@ BOOST_AUTO_TEST_CASE(MANUAL4) {
|
||||
BOOST_AUTO_TEST_CASE(MANUAL5) {
|
||||
Action::AST ast({"WCG2", "PROD1", ">", "WCG5", "PROD2", "AND", "GCG3", "G1", ">", "GCG7", "G2", "OR", "FCG1", ">", "FCG7"});
|
||||
SummaryState st(std::chrono::system_clock::now());
|
||||
Action::Context context(st);
|
||||
WListManager wlm;
|
||||
Action::Context context(st, wlm);
|
||||
|
||||
context.add("WCG2", "PROD1", 100);
|
||||
context.add("WCG5", "PROD2", 50);
|
||||
@ -469,7 +481,8 @@ BOOST_AUTO_TEST_CASE(MANUAL5) {
|
||||
BOOST_AUTO_TEST_CASE(LGR) {
|
||||
Action::AST ast({"LWCC" , "OPX", "LOCAL", "1", "2", "3", ">", "100"});
|
||||
SummaryState st(std::chrono::system_clock::now());
|
||||
Action::Context context(st);
|
||||
WListManager wlm;
|
||||
Action::Context context(st, wlm);
|
||||
|
||||
context.add("LWCC", "OPX:LOCAL:1:2:3", 200);
|
||||
BOOST_CHECK(ast.eval(context));
|
||||
@ -482,7 +495,8 @@ BOOST_AUTO_TEST_CASE(LGR) {
|
||||
BOOST_AUTO_TEST_CASE(Action_ContextTest) {
|
||||
SummaryState st(std::chrono::system_clock::now());
|
||||
st.update("WWCT:OP1", 100);
|
||||
Action::Context context(st);
|
||||
WListManager wlm;
|
||||
Action::Context context(st, wlm);
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL(context.get("WWCT", "OP1"), 100);
|
||||
@ -498,8 +512,8 @@ BOOST_AUTO_TEST_CASE(Action_ContextTest) {
|
||||
BOOST_AUTO_TEST_CASE(TestGroupList) {
|
||||
Action::AST ast({"GWPR", "*", ">", "1.0"});
|
||||
SummaryState st(std::chrono::system_clock::now());
|
||||
|
||||
Action::Context context(st);
|
||||
WListManager wlm;
|
||||
Action::Context context(st, wlm);
|
||||
BOOST_CHECK_THROW( ast.eval(context), std::logic_error );
|
||||
}
|
||||
|
||||
@ -511,7 +525,8 @@ BOOST_AUTO_TEST_CASE(TestMatchingWells) {
|
||||
st.update_well_var("OPY", "WOPR", 0.50);
|
||||
st.update_well_var("OPZ", "WOPR", 2.0);
|
||||
|
||||
Action::Context context(st);
|
||||
WListManager wlm;
|
||||
Action::Context context(st, wlm);
|
||||
auto res = ast.eval(context);
|
||||
auto wells = res.wells();
|
||||
BOOST_CHECK( res);
|
||||
@ -520,6 +535,7 @@ BOOST_AUTO_TEST_CASE(TestMatchingWells) {
|
||||
BOOST_CHECK_EQUAL( wells[0], "OPZ" );
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestMatchingWells2) {
|
||||
Action::AST ast1({"WOPR", "P*", ">", "1.0"});
|
||||
Action::AST ast2({"WOPR", "*", ">", "1.0"});
|
||||
@ -533,7 +549,8 @@ BOOST_AUTO_TEST_CASE(TestMatchingWells2) {
|
||||
st.update_well_var("IY", "WOPR", 0.50);
|
||||
st.update_well_var("IZ", "WOPR", 2.0);
|
||||
|
||||
Action::Context context(st);
|
||||
WListManager wlm;
|
||||
Action::Context context(st, wlm);
|
||||
auto res1 = ast1.eval(context);
|
||||
auto res2 = ast2.eval(context);
|
||||
auto wells1 = res1.wells();
|
||||
@ -562,7 +579,8 @@ BOOST_AUTO_TEST_CASE(TestMatchingWells_AND) {
|
||||
st.update_well_var("OPY", "WWCT", 0.0); // The WWCT check matches this well.
|
||||
st.update_well_var("OPZ", "WWCT", 1.0);
|
||||
|
||||
Action::Context context(st);
|
||||
WListManager wlm;
|
||||
Action::Context context(st, wlm);
|
||||
auto res = ast.eval(context);
|
||||
BOOST_CHECK(res);
|
||||
|
||||
@ -584,7 +602,8 @@ BOOST_AUTO_TEST_CASE(TestMatchingWells_OR) {
|
||||
st.update_well_var("OPY", "WWCT", 0.0); // The WWCT check matches this well.
|
||||
st.update_well_var("OPZ", "WWCT", 1.0);
|
||||
|
||||
Action::Context context(st);
|
||||
WListManager wlm;
|
||||
Action::Context context(st, wlm);
|
||||
auto res = ast.eval(context);
|
||||
auto wells = res.wells();
|
||||
BOOST_CHECK(res);
|
||||
@ -597,10 +616,38 @@ BOOST_AUTO_TEST_CASE(TestMatchingWells_OR) {
|
||||
BOOST_CHECK( std::find(wells.begin(), wells.end(), "OPY") != wells.end());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestWLIST) {
|
||||
WListManager wlm;
|
||||
Action::AST ast({"WOPR", "*LIST1", ">", "1.0"});
|
||||
SummaryState st(std::chrono::system_clock::now());
|
||||
|
||||
st.update_well_var("W1", "WOPR", 2.0);
|
||||
st.update_well_var("W2", "WOPR", 2.50);
|
||||
st.update_well_var("W3", "WOPR", 2.0);
|
||||
st.update_well_var("W4", "WOPR", 2.0);
|
||||
st.update_well_var("W5", "WOPR", 2.0);
|
||||
|
||||
|
||||
Action::Context context(st, wlm);
|
||||
auto& wl = wlm.newList("*LIST1");
|
||||
wl.add("W1");
|
||||
wl.add("W3");
|
||||
wl.add("W5");
|
||||
auto res = ast.eval(context);
|
||||
auto wells = res.wells();
|
||||
BOOST_CHECK(res);
|
||||
BOOST_CHECK_EQUAL( wells.size(), 3);
|
||||
for (const auto& w : {"W1", "W3", "W5"}) {
|
||||
auto find_iter = std::find(wells.begin(), wells.end(), w);
|
||||
BOOST_CHECK( find_iter != wells.end() );
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestFieldAND) {
|
||||
Action::AST ast({"FMWPR", ">=", "4", "AND", "WUPR3", "OP*", "=", "1"});
|
||||
SummaryState st(std::chrono::system_clock::now());
|
||||
Action::Context context(st);
|
||||
WListManager wlm;
|
||||
Action::Context context(st, wlm);
|
||||
|
||||
st.update_well_var("OP1", "WUPR3", 3);
|
||||
st.update_well_var("OP2", "WUPR3", 2);
|
||||
|
Loading…
Reference in New Issue
Block a user