2018-07-11 03:26:16 -05:00
|
|
|
/*
|
|
|
|
Copyright 2018 Statoil ASA.
|
|
|
|
|
|
|
|
This file is part of the Open Porous Media project (OPM).
|
|
|
|
|
|
|
|
OPM is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
OPM is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <iostream>
|
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
|
|
|
|
#define BOOST_TEST_MODULE ACTIONX
|
|
|
|
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
2018-10-27 08:58:02 -05:00
|
|
|
|
2019-11-15 06:27:58 -06:00
|
|
|
#include <opm/common/utility/TimeService.hpp>
|
2020-09-25 01:46:27 -05:00
|
|
|
#include <opm/common/utility/OpmInputError.hpp>
|
2019-11-15 06:27:58 -06:00
|
|
|
|
2020-09-16 05:26:45 -05:00
|
|
|
#include <opm/common/OpmLog/KeywordLocation.hpp>
|
2019-11-21 04:44:06 -06:00
|
|
|
#include <opm/parser/eclipse/EclipseState/Grid/FieldPropsManager.hpp>
|
2018-07-11 06:54:49 -05:00
|
|
|
#include <opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp>
|
2020-01-16 11:20:31 -06:00
|
|
|
#include <opm/parser/eclipse/EclipseState/Runspec.hpp>
|
2018-11-09 14:42:21 -06:00
|
|
|
#include <opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp>
|
2018-07-11 06:54:49 -05:00
|
|
|
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
|
2019-01-17 04:22:49 -06:00
|
|
|
#include <opm/parser/eclipse/EclipseState/Schedule/Action/ActionAST.hpp>
|
|
|
|
#include <opm/parser/eclipse/EclipseState/Schedule/Action/ActionContext.hpp>
|
|
|
|
#include <opm/parser/eclipse/EclipseState/Schedule/Action/Actions.hpp>
|
2020-06-16 01:21:41 -05:00
|
|
|
#include <opm/parser/eclipse/EclipseState/Schedule/Action/State.hpp>
|
2019-01-17 04:22:49 -06:00
|
|
|
#include <opm/parser/eclipse/EclipseState/Schedule/Action/ActionX.hpp>
|
2020-07-09 00:39:03 -05:00
|
|
|
#include <opm/parser/eclipse/EclipseState/Schedule/Well/WList.hpp>
|
|
|
|
#include <opm/parser/eclipse/EclipseState/Schedule/Well/WListManager.hpp>
|
2018-07-11 03:26:16 -05:00
|
|
|
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
2019-10-17 08:25:13 -05:00
|
|
|
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
|
2018-07-11 03:26:16 -05:00
|
|
|
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
|
|
|
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
2019-01-03 11:05:19 -06:00
|
|
|
#include <opm/parser/eclipse/Parser/ErrorGuard.hpp>
|
2020-03-26 09:31:21 -05:00
|
|
|
#include <opm/parser/eclipse/Python/Python.hpp>
|
2018-07-11 03:26:16 -05:00
|
|
|
|
|
|
|
using namespace Opm;
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-11-15 06:27:58 -06:00
|
|
|
|
2018-07-11 03:26:16 -05:00
|
|
|
BOOST_AUTO_TEST_CASE(Create) {
|
|
|
|
const auto action_kw = std::string{ R"(
|
|
|
|
ACTIONX
|
|
|
|
'ACTION' /
|
|
|
|
WWCT OPX > 0.75 /
|
|
|
|
/
|
|
|
|
)"};
|
2019-11-15 06:27:58 -06:00
|
|
|
Action::ActionX action1("NAME", 10, 100, 0);
|
2018-07-11 03:26:16 -05:00
|
|
|
BOOST_CHECK_EQUAL(action1.name(), "NAME");
|
|
|
|
|
|
|
|
const auto deck = Parser{}.parseString( action_kw );
|
|
|
|
const auto& kw = deck.getKeyword("ACTIONX");
|
|
|
|
|
2019-11-15 06:27:58 -06:00
|
|
|
Action::ActionX action2(kw, 0);
|
2018-07-11 03:26:16 -05:00
|
|
|
BOOST_CHECK_EQUAL(action2.name(), "ACTION");
|
|
|
|
}
|
2018-07-11 06:54:49 -05:00
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(SCAN) {
|
|
|
|
const auto MISSING_END= std::string{ R"(
|
|
|
|
SCHEDULE
|
|
|
|
|
|
|
|
ACTIONX
|
|
|
|
'ACTION' /
|
|
|
|
WWCT OPX > 0.75 /
|
|
|
|
/
|
2018-10-27 08:58:02 -05:00
|
|
|
|
|
|
|
TSTEP
|
|
|
|
10 /
|
2018-07-11 06:54:49 -05:00
|
|
|
)"};
|
|
|
|
|
|
|
|
const auto WITH_WELSPECS = std::string{ R"(
|
|
|
|
SCHEDULE
|
|
|
|
|
|
|
|
WELSPECS
|
|
|
|
'W2' 'OP' 1 1 3.33 'OIL' 7*/
|
|
|
|
/
|
|
|
|
|
|
|
|
ACTIONX
|
|
|
|
'ACTION' /
|
|
|
|
WWCT OPX > 0.75 /
|
|
|
|
/
|
|
|
|
|
|
|
|
WELSPECS
|
|
|
|
'W1' 'OP' 1 1 3.33 'OIL' 7*/
|
|
|
|
/
|
|
|
|
|
2018-10-26 02:13:26 -05:00
|
|
|
ENDACTIO
|
2018-10-27 08:58:02 -05:00
|
|
|
|
|
|
|
TSTEP
|
|
|
|
10 /
|
2018-10-26 02:13:26 -05:00
|
|
|
)"};
|
|
|
|
|
|
|
|
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 /
|
|
|
|
|
2018-07-11 06:54:49 -05:00
|
|
|
ENDACTIO
|
2018-10-27 08:58:02 -05:00
|
|
|
|
|
|
|
TSTEP
|
|
|
|
10 /
|
2018-07-11 06:54:49 -05:00
|
|
|
)"};
|
2020-03-31 03:26:55 -05:00
|
|
|
auto python = std::make_shared<Python>();
|
2018-07-11 06:54:49 -05:00
|
|
|
Opm::Parser parser;
|
2019-01-03 11:05:19 -06:00
|
|
|
auto deck1 = parser.parseString(MISSING_END);
|
|
|
|
auto deck2 = parser.parseString(WITH_WELSPECS);
|
|
|
|
auto deck3 = parser.parseString(WITH_GRID);
|
2018-07-11 06:54:49 -05:00
|
|
|
EclipseGrid grid1(10,10,10);
|
|
|
|
TableManager table ( deck1 );
|
2020-01-16 11:20:31 -06:00
|
|
|
FieldPropsManager fp( deck1, Phases{true, true, true}, grid1, table);
|
2018-10-17 06:35:25 -05:00
|
|
|
Runspec runspec (deck1);
|
2018-07-11 06:54:49 -05:00
|
|
|
|
|
|
|
// The ACTIONX keyword has no matching 'ENDACTIO' -> exception
|
2020-09-25 01:46:27 -05:00
|
|
|
BOOST_CHECK_THROW(Schedule(deck1, grid1, fp, runspec, python), OpmInputError);
|
2018-07-11 06:54:49 -05:00
|
|
|
|
2020-03-26 09:31:21 -05:00
|
|
|
Schedule sched(deck2, grid1, fp, runspec, python);
|
2018-07-11 06:54:49 -05:00
|
|
|
BOOST_CHECK( !sched.hasWell("W1") );
|
|
|
|
BOOST_CHECK( sched.hasWell("W2"));
|
2018-10-26 02:13:26 -05:00
|
|
|
|
|
|
|
// 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}} );
|
2019-01-03 11:05:19 -06:00
|
|
|
ErrorGuard errors;
|
2020-09-25 01:46:27 -05:00
|
|
|
BOOST_CHECK_THROW(Schedule(deck3, grid1, fp, runspec, parseContext, errors, python), OpmInputError);
|
2018-07-11 06:54:49 -05:00
|
|
|
}
|
2018-10-27 08:58:02 -05:00
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(TestActions) {
|
2019-11-15 06:27:58 -06:00
|
|
|
Opm::SummaryState st(std::chrono::system_clock::now());
|
2020-07-09 00:39:03 -05:00
|
|
|
Opm::WListManager wlm;
|
|
|
|
Opm::Action::Context context(st, wlm);
|
2019-11-15 06:27:58 -06:00
|
|
|
Opm::Action::Actions config;
|
2019-01-28 03:00:08 -06:00
|
|
|
std::vector<std::string> matching_wells;
|
2020-03-22 15:02:32 -05:00
|
|
|
auto python = std::make_shared<Opm::Python>();
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL(config.size(), 0U);
|
2018-11-19 02:43:50 -06:00
|
|
|
BOOST_CHECK(config.empty());
|
2018-10-27 08:58:02 -05:00
|
|
|
|
2019-11-15 06:27:58 -06:00
|
|
|
Opm::Action::ActionX action1("NAME", 10, 100, 0);
|
2018-10-27 08:58:02 -05:00
|
|
|
config.add(action1);
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL(config.size(), 1U);
|
2018-11-19 02:43:50 -06:00
|
|
|
BOOST_CHECK(!config.empty());
|
2018-10-27 08:58:02 -05:00
|
|
|
|
|
|
|
double min_wait = 86400;
|
|
|
|
size_t max_eval = 3;
|
|
|
|
{
|
2019-11-15 06:27:58 -06:00
|
|
|
Opm::Action::ActionX action("NAME", max_eval, min_wait, asTimeT(TimeStampUTC(TimeStampUTC::YMD{ 2000, 7, 1 })) );
|
2018-10-27 08:58:02 -05:00
|
|
|
config.add(action);
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL(config.size(), 1U);
|
2018-10-27 08:58:02 -05:00
|
|
|
|
|
|
|
|
2019-11-15 06:27:58 -06:00
|
|
|
Opm::Action::ActionX action3("NAME3", 1000000, 0, asTimeT(TimeStampUTC(TimeStampUTC::YMD{ 2000, 7, 1 })) );
|
2018-10-27 08:58:02 -05:00
|
|
|
config.add(action3);
|
2020-03-22 13:31:39 -05:00
|
|
|
|
2020-03-22 15:02:32 -05:00
|
|
|
Opm::Action::PyAction py_action1(python, "PYTHON1", Opm::Action::PyAction::RunCount::single, "act1.py");
|
2020-03-22 13:31:39 -05:00
|
|
|
config.add(py_action1);
|
|
|
|
|
2020-03-22 15:02:32 -05:00
|
|
|
Opm::Action::PyAction py_action2(python, "PYTHON2", Opm::Action::PyAction::RunCount::single, "act1.py");
|
2020-03-22 13:31:39 -05:00
|
|
|
config.add(py_action2);
|
2018-10-27 08:58:02 -05:00
|
|
|
}
|
2019-11-15 06:27:58 -06:00
|
|
|
const Opm::Action::ActionX& action2 = config.get("NAME");
|
2020-06-16 07:09:49 -05:00
|
|
|
Opm::Action::State action_state;
|
2019-01-28 03:00:08 -06:00
|
|
|
// The action2 instance has an empty condition, so it will never evaluate to true.
|
2020-06-16 07:09:49 -05:00
|
|
|
BOOST_CHECK(action2.ready( action_state, asTimeT(TimeStampUTC(TimeStampUTC::YMD{ 2000, 7, 1 })) ));
|
|
|
|
BOOST_CHECK(!action2.ready( action_state, asTimeT(TimeStampUTC(TimeStampUTC::YMD{ 2000, 6, 1 })) ));
|
|
|
|
BOOST_CHECK(!action2.eval(context));
|
2018-10-27 08:58:02 -05:00
|
|
|
|
2020-06-16 07:09:49 -05:00
|
|
|
auto pending = config.pending( action_state, asTimeT(TimeStampUTC(TimeStampUTC::YMD{ 2000, 8, 7 })) );
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL( pending.size(), 2U);
|
2018-10-27 08:58:02 -05:00
|
|
|
for (auto& ptr : pending) {
|
2020-06-16 07:09:49 -05:00
|
|
|
BOOST_CHECK( ptr->ready( action_state, asTimeT(TimeStampUTC(TimeStampUTC::YMD{ 2000, 8, 7 })) ));
|
|
|
|
BOOST_CHECK( !ptr->eval( context));
|
2018-10-27 08:58:02 -05:00
|
|
|
}
|
2020-06-16 07:09:49 -05:00
|
|
|
BOOST_CHECK(!action2.eval(context));
|
2020-03-22 13:31:39 -05:00
|
|
|
|
|
|
|
|
|
|
|
const auto& python_actions = config.pending_python();
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL(python_actions.size(), 2U);
|
2018-10-27 08:58:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(TestContext) {
|
2019-11-15 06:27:58 -06:00
|
|
|
Opm::SummaryState st(std::chrono::system_clock::now());
|
2019-05-12 03:01:26 -05:00
|
|
|
st.update_well_var("OP1", "WOPR", 100);
|
2020-07-09 00:39:03 -05:00
|
|
|
Opm::WListManager wlm;
|
|
|
|
Opm::Action::Context context(st, wlm);
|
2018-10-27 08:58:02 -05:00
|
|
|
|
|
|
|
BOOST_REQUIRE_THROW(context.get("func", "arg"), std::out_of_range);
|
|
|
|
|
|
|
|
context.add("FUNC", "ARG", 100);
|
|
|
|
BOOST_CHECK_EQUAL(context.get("FUNC", "ARG"), 100);
|
2019-01-02 04:30:56 -06:00
|
|
|
|
|
|
|
const auto& wopr_wells = context.wells("WOPR");
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL(wopr_wells.size(), 1U);
|
2019-01-02 04:30:56 -06:00
|
|
|
BOOST_CHECK_EQUAL(wopr_wells[0], "OP1");
|
|
|
|
|
|
|
|
const auto& wwct_wells = context.wells("WWCT");
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL(wwct_wells.size(), 0U);
|
2018-10-27 08:58:02 -05:00
|
|
|
}
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Opm::Schedule make_action(const std::string& action_string) {
|
|
|
|
std::string start = std::string{ R"(
|
|
|
|
SCHEDULE
|
|
|
|
)"};
|
|
|
|
std::string end = std::string{ R"(
|
|
|
|
ENDACTIO
|
|
|
|
|
|
|
|
TSTEP
|
|
|
|
10 /
|
|
|
|
)"};
|
|
|
|
|
|
|
|
std::string deck_string = start + action_string + end;
|
|
|
|
Opm::Parser parser;
|
2019-01-03 11:05:19 -06:00
|
|
|
auto deck = parser.parseString(deck_string);
|
2020-03-31 03:26:55 -05:00
|
|
|
auto python = std::make_shared<Python>();
|
2018-11-07 08:45:48 -06:00
|
|
|
EclipseGrid grid1(10,10,10);
|
|
|
|
TableManager table ( deck );
|
2020-01-16 11:20:31 -06:00
|
|
|
FieldPropsManager fp( deck, Phases{true, true, true}, grid1, table);
|
2018-11-07 08:45:48 -06:00
|
|
|
Runspec runspec(deck);
|
|
|
|
|
2020-03-26 09:31:21 -05:00
|
|
|
return Schedule(deck, grid1, fp, runspec, python);
|
2018-11-07 08:45:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-15 06:27:58 -06:00
|
|
|
BOOST_AUTO_TEST_CASE(TestAction_AST_BASIC) {
|
2018-11-07 08:45:48 -06:00
|
|
|
// Missing comparator
|
2019-12-16 07:27:16 -06:00
|
|
|
BOOST_REQUIRE_THROW( Action::AST( std::vector<std::string>{"WWCT", "OPX", "0.75"} ), std::invalid_argument);
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
// Left hand side must be function expression
|
2019-12-16 07:27:16 -06:00
|
|
|
BOOST_REQUIRE_THROW( Action::AST(std::vector<std::string>{"0.75", "<", "1.0"}), std::invalid_argument);
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
//Extra data
|
2019-12-16 07:27:16 -06:00
|
|
|
BOOST_REQUIRE_THROW(Action::AST(std::vector<std::string>{"0.75", "<", "1.0", "EXTRA"}), std::invalid_argument);
|
2018-11-07 08:45:48 -06:00
|
|
|
|
2019-07-01 01:27:07 -05:00
|
|
|
Action::AST ast1({"WWCT", "OPX", ">", "0.75"});
|
|
|
|
Action::AST ast2({"WWCT", "OPX", "=", "WWCT", "OPX"});
|
|
|
|
Action::AST ast3({"WWCT", "OPY", ">", "0.75"});
|
2019-11-15 06:27:58 -06:00
|
|
|
SummaryState st(std::chrono::system_clock::now());
|
2020-07-09 00:39:03 -05:00
|
|
|
WListManager wlm;
|
|
|
|
Action::Context context(st, wlm);
|
2019-01-02 04:42:50 -06:00
|
|
|
std::vector<std::string> matching_wells;
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
context.add("WWCT", "OPX", 100);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK(ast1.eval(context));
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
context.add("WWCT", "OPX", -100);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK(!ast1.eval(context));
|
2018-11-07 08:45:48 -06:00
|
|
|
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK(ast2.eval(context));
|
|
|
|
BOOST_REQUIRE_THROW(ast3.eval(context), std::out_of_range);
|
2018-11-07 08:45:48 -06:00
|
|
|
}
|
|
|
|
|
2019-11-15 06:27:58 -06:00
|
|
|
BOOST_AUTO_TEST_CASE(TestAction_AST_OR_AND) {
|
2019-07-01 01:27:07 -05:00
|
|
|
Action::AST ast_or({"WWCT", "OPX", ">", "0.75", "OR", "WWCT", "OPY", ">", "0.75"});
|
|
|
|
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", ")"});
|
2019-11-15 06:27:58 -06:00
|
|
|
SummaryState st(std::chrono::system_clock::now());
|
2020-07-09 00:39:03 -05:00
|
|
|
WListManager wlm;
|
|
|
|
Action::Context context(st, wlm);
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
context.add("WWCT", "OPX", 100);
|
|
|
|
context.add("WWCT", "OPY", -100);
|
|
|
|
context.add("WWCT", "OPZ", 100);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK( ast_or.eval(context) );
|
|
|
|
BOOST_CHECK( !ast_and.eval(context) );
|
|
|
|
BOOST_CHECK( par.eval(context));
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
|
|
|
|
context.add("WWCT", "OPX", -100);
|
|
|
|
context.add("WWCT", "OPY", 100);
|
|
|
|
context.add("WWCT", "OPZ", 100);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK( ast_or.eval(context));
|
|
|
|
BOOST_CHECK( !ast_and.eval(context) );
|
|
|
|
BOOST_CHECK( !par.eval(context));
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
|
|
|
|
context.add("WWCT", "OPX", 100);
|
|
|
|
context.add("WWCT", "OPY", 100);
|
|
|
|
context.add("WWCT", "OPZ", -100);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK( ast_or.eval(context));
|
|
|
|
BOOST_CHECK( ast_and.eval(context) );
|
|
|
|
BOOST_CHECK( par.eval(context));
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
context.add("WWCT", "OPX", -100);
|
|
|
|
context.add("WWCT", "OPY", -100);
|
|
|
|
context.add("WWCT", "OPZ", -100);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK( !ast_or.eval(context) );
|
|
|
|
BOOST_CHECK( !ast_and.eval(context) );
|
|
|
|
BOOST_CHECK( !par.eval(context));
|
2018-11-07 08:45:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(DATE) {
|
2019-12-16 07:27:16 -06:00
|
|
|
Action::AST ast(std::vector<std::string>{"MNTH", ">=", "JUN"});
|
2019-11-15 06:27:58 -06:00
|
|
|
SummaryState st(std::chrono::system_clock::now());
|
2020-07-09 00:39:03 -05:00
|
|
|
WListManager wlm;
|
|
|
|
Action::Context context(st, wlm);
|
2019-01-02 04:42:50 -06:00
|
|
|
|
2018-11-07 08:45:48 -06:00
|
|
|
context.add("MNTH", 6);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK( ast.eval(context));
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
context.add("MNTH", 8);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK( ast.eval(context) );
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
context.add("MNTH", 5);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK( !ast.eval(context));
|
2018-11-07 08:45:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(MANUAL1) {
|
2019-07-01 01:27:07 -05:00
|
|
|
Action::AST ast({"GGPR", "FIELD", ">", "50000", "AND", "WGOR", "PR", ">" ,"GGOR", "FIELD"});
|
2019-11-15 06:27:58 -06:00
|
|
|
SummaryState st(std::chrono::system_clock::now());
|
2020-07-09 00:39:03 -05:00
|
|
|
WListManager wlm;
|
|
|
|
Action::Context context(st, wlm);
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
context.add("GGPR", "FIELD", 60000 );
|
|
|
|
context.add("WGOR", "PR" , 300 );
|
|
|
|
context.add("GGOR", "FIELD", 200);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK( ast.eval(context));
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
context.add("GGPR", "FIELD", 0 );
|
|
|
|
context.add("WGOR", "PR" , 300 );
|
|
|
|
context.add("GGOR", "FIELD", 200);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK( !ast.eval(context) );
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
context.add("GGPR", "FIELD", 60000 );
|
|
|
|
context.add("WGOR", "PR" , 100 );
|
|
|
|
context.add("GGOR", "FIELD", 200);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK( !ast.eval(context) );
|
2018-11-07 08:45:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(MANUAL2) {
|
2019-07-01 01:27:07 -05:00
|
|
|
Action::AST ast({"GWCT", "LIST1", ">", "0.70", "AND", "(", "GWPR", "LIST1", ">", "GWPR", "LIST2", "OR", "GWPR", "LIST1", ">", "GWPR", "LIST3", ")"});
|
2019-11-15 06:27:58 -06:00
|
|
|
SummaryState st(std::chrono::system_clock::now());
|
2020-07-09 00:39:03 -05:00
|
|
|
WListManager wlm;
|
|
|
|
Action::Context context(st, wlm);
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
context.add("GWCT", "LIST1", 1.0);
|
|
|
|
context.add("GWPR", "LIST1", 1 );
|
|
|
|
context.add("GWPR", "LIST2", 2 );
|
|
|
|
context.add("GWPR", "LIST3", 3 );
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK( !ast.eval(context));
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
context.add("GWCT", "LIST1", 1.0);
|
|
|
|
context.add("GWPR", "LIST1", 1 );
|
|
|
|
context.add("GWPR", "LIST2", 2 );
|
|
|
|
context.add("GWPR", "LIST3", 0 );
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK( ast.eval(context));
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
context.add("GWCT", "LIST1", 1.0);
|
|
|
|
context.add("GWPR", "LIST1", 1 );
|
|
|
|
context.add("GWPR", "LIST2", 0 );
|
|
|
|
context.add("GWPR", "LIST3", 3 );
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK( ast.eval(context));
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
context.add("GWCT", "LIST1", 1.0);
|
|
|
|
context.add("GWPR", "LIST1", 1 );
|
|
|
|
context.add("GWPR", "LIST2", 0 );
|
|
|
|
context.add("GWPR", "LIST3", 0 );
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK( ast.eval(context));
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
context.add("GWCT", "LIST1", 0.0);
|
|
|
|
context.add("GWPR", "LIST1", 1 );
|
|
|
|
context.add("GWPR", "LIST2", 0 );
|
|
|
|
context.add("GWPR", "LIST3", 3 );
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK( !ast.eval(context));
|
2018-11-07 08:45:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(MANUAL3) {
|
2019-07-01 01:27:07 -05:00
|
|
|
Action::AST ast({"MNTH", ".GE.", "MAR", "AND", "MNTH", ".LE.", "OCT", "AND", "GMWL", "HIGH", ".GE.", "4"});
|
2019-11-15 06:27:58 -06:00
|
|
|
SummaryState st(std::chrono::system_clock::now());
|
2020-07-09 00:39:03 -05:00
|
|
|
WListManager wlm;
|
|
|
|
Action::Context context(st, wlm);
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
context.add("MNTH", 4);
|
|
|
|
context.add("GMWL", "HIGH", 4);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK( ast.eval(context));
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
context.add("MNTH", 3);
|
|
|
|
context.add("GMWL", "HIGH", 4);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK( ast.eval(context));
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
context.add("MNTH", 11);
|
|
|
|
context.add("GMWL", "HIGH", 4);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK( !ast.eval(context));
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
context.add("MNTH", 3);
|
|
|
|
context.add("GMWL", "HIGH", 3);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK( !ast.eval(context));
|
2018-11-07 08:45:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(MANUAL4) {
|
2019-07-01 01:27:07 -05:00
|
|
|
Action::AST ast({"GWCT", "FIELD", ">", "0.8", "AND", "DAY", ">", "1", "AND", "MNTH", ">", "JUN", "AND", "YEAR", ">=", "2021"});
|
2019-11-15 06:27:58 -06:00
|
|
|
SummaryState st(std::chrono::system_clock::now());
|
2020-07-09 00:39:03 -05:00
|
|
|
WListManager wlm;
|
|
|
|
Action::Context context(st, wlm);
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
context.add("MNTH", 7);
|
|
|
|
context.add("DAY", 2);
|
|
|
|
context.add("YEAR", 2030);
|
|
|
|
context.add("GWCT", "FIELD", 1.0);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK( ast.eval(context) );
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
context.add("MNTH", 7);
|
|
|
|
context.add("DAY", 2);
|
|
|
|
context.add("YEAR", 2019);
|
|
|
|
context.add("GWCT", "FIELD", 1.0);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK( !ast.eval(context) );
|
2018-11-07 08:45:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(MANUAL5) {
|
2019-07-01 01:27:07 -05:00
|
|
|
Action::AST ast({"WCG2", "PROD1", ">", "WCG5", "PROD2", "AND", "GCG3", "G1", ">", "GCG7", "G2", "OR", "FCG1", ">", "FCG7"});
|
2019-11-15 06:27:58 -06:00
|
|
|
SummaryState st(std::chrono::system_clock::now());
|
2020-07-09 00:39:03 -05:00
|
|
|
WListManager wlm;
|
|
|
|
Action::Context context(st, wlm);
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
context.add("WCG2", "PROD1", 100);
|
|
|
|
context.add("WCG5", "PROD2", 50);
|
|
|
|
context.add("GCG3", "G1", 200);
|
|
|
|
context.add("GCG7", "G2", 100);
|
|
|
|
context.add("FCG1", 100);
|
|
|
|
context.add("FCG7", 50);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK(ast.eval(context));
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
context.add("WCG2", "PROD1", 100);
|
|
|
|
context.add("WCG5", "PROD2", 50);
|
|
|
|
context.add("GCG3", "G1", 200);
|
|
|
|
context.add("GCG7", "G2", 100);
|
|
|
|
context.add("FCG1", 100);
|
|
|
|
context.add("FCG7", 150);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK(ast.eval(context));
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
context.add("WCG2", "PROD1", 100);
|
|
|
|
context.add("WCG5", "PROD2", 50);
|
|
|
|
context.add("GCG3", "G1", 20);
|
|
|
|
context.add("GCG7", "G2", 100);
|
|
|
|
context.add("FCG1", 100);
|
|
|
|
context.add("FCG7", 150);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK(!ast.eval(context));
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
context.add("WCG2", "PROD1", 100);
|
|
|
|
context.add("WCG5", "PROD2", 50);
|
|
|
|
context.add("GCG3", "G1", 20);
|
|
|
|
context.add("GCG7", "G2", 100);
|
|
|
|
context.add("FCG1", 200);
|
|
|
|
context.add("FCG7", 150);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK(ast.eval(context));
|
2018-11-07 08:45:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(LGR) {
|
2019-07-01 01:27:07 -05:00
|
|
|
Action::AST ast({"LWCC" , "OPX", "LOCAL", "1", "2", "3", ">", "100"});
|
2019-11-15 06:27:58 -06:00
|
|
|
SummaryState st(std::chrono::system_clock::now());
|
2020-07-09 00:39:03 -05:00
|
|
|
WListManager wlm;
|
|
|
|
Action::Context context(st, wlm);
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
context.add("LWCC", "OPX:LOCAL:1:2:3", 200);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK(ast.eval(context));
|
2018-11-07 08:45:48 -06:00
|
|
|
|
|
|
|
context.add("LWCC", "OPX:LOCAL:1:2:3", 20);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK(!ast.eval(context));
|
2018-11-07 08:45:48 -06:00
|
|
|
}
|
2018-11-09 14:42:21 -06:00
|
|
|
|
|
|
|
|
2019-11-15 06:27:58 -06:00
|
|
|
BOOST_AUTO_TEST_CASE(Action_ContextTest) {
|
|
|
|
SummaryState st(std::chrono::system_clock::now());
|
2019-05-12 03:01:26 -05:00
|
|
|
st.update("WWCT:OP1", 100);
|
2020-07-09 00:39:03 -05:00
|
|
|
WListManager wlm;
|
|
|
|
Action::Context context(st, wlm);
|
2018-11-09 14:42:21 -06:00
|
|
|
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(context.get("WWCT", "OP1"), 100);
|
|
|
|
BOOST_REQUIRE_THROW(context.get("WGOR", "B37"), std::out_of_range);
|
|
|
|
context.add("WWCT", "OP1", 200);
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(context.get("WWCT", "OP1"), 200);
|
|
|
|
BOOST_REQUIRE_THROW(context.get("WGOR", "B37"), std::out_of_range);
|
|
|
|
}
|
2019-01-02 04:33:09 -06:00
|
|
|
|
2019-11-21 03:10:42 -06:00
|
|
|
//Note: that this is only temporary test.
|
|
|
|
//Groupnames w/ astirisks wil eventually work with ACTIONX
|
|
|
|
BOOST_AUTO_TEST_CASE(TestGroupList) {
|
|
|
|
Action::AST ast({"GWPR", "*", ">", "1.0"});
|
|
|
|
SummaryState st(std::chrono::system_clock::now());
|
2020-07-09 00:39:03 -05:00
|
|
|
WListManager wlm;
|
|
|
|
Action::Context context(st, wlm);
|
2019-11-21 03:10:42 -06:00
|
|
|
BOOST_CHECK_THROW( ast.eval(context), std::logic_error );
|
|
|
|
}
|
2019-01-02 04:33:09 -06:00
|
|
|
|
2019-01-02 04:42:50 -06:00
|
|
|
BOOST_AUTO_TEST_CASE(TestMatchingWells) {
|
2019-07-01 01:27:07 -05:00
|
|
|
Action::AST ast({"WOPR", "*", ">", "1.0"});
|
2019-11-15 06:27:58 -06:00
|
|
|
SummaryState st(std::chrono::system_clock::now());
|
2019-01-02 04:42:50 -06:00
|
|
|
|
2019-05-12 03:01:26 -05:00
|
|
|
st.update_well_var("OPX", "WOPR", 0);
|
|
|
|
st.update_well_var("OPY", "WOPR", 0.50);
|
|
|
|
st.update_well_var("OPZ", "WOPR", 2.0);
|
2019-01-02 04:42:50 -06:00
|
|
|
|
2020-07-09 00:39:03 -05:00
|
|
|
WListManager wlm;
|
|
|
|
Action::Context context(st, wlm);
|
2019-07-01 01:27:07 -05:00
|
|
|
auto res = ast.eval(context);
|
|
|
|
auto wells = res.wells();
|
|
|
|
BOOST_CHECK( res);
|
2019-01-02 04:42:50 -06:00
|
|
|
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL( wells.size(), 1U);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK_EQUAL( wells[0], "OPZ" );
|
2019-01-02 04:42:50 -06:00
|
|
|
}
|
2019-01-17 04:13:33 -06:00
|
|
|
|
2020-07-09 00:39:03 -05:00
|
|
|
|
2019-03-07 03:53:40 -06:00
|
|
|
BOOST_AUTO_TEST_CASE(TestMatchingWells2) {
|
2019-07-01 01:27:07 -05:00
|
|
|
Action::AST ast1({"WOPR", "P*", ">", "1.0"});
|
|
|
|
Action::AST ast2({"WOPR", "*", ">", "1.0"});
|
2019-11-15 06:27:58 -06:00
|
|
|
SummaryState st(std::chrono::system_clock::now());
|
2019-03-07 03:53:40 -06:00
|
|
|
|
2019-05-12 03:01:26 -05:00
|
|
|
st.update_well_var("PX", "WOPR", 0);
|
|
|
|
st.update_well_var("PY", "WOPR", 0.50);
|
|
|
|
st.update_well_var("PZ", "WOPR", 2.0);
|
2019-03-07 03:53:40 -06:00
|
|
|
|
2019-05-12 03:01:26 -05:00
|
|
|
st.update_well_var("IX", "WOPR", 0);
|
|
|
|
st.update_well_var("IY", "WOPR", 0.50);
|
|
|
|
st.update_well_var("IZ", "WOPR", 2.0);
|
2019-03-07 03:53:40 -06:00
|
|
|
|
2020-07-09 00:39:03 -05:00
|
|
|
WListManager wlm;
|
|
|
|
Action::Context context(st, wlm);
|
2019-07-01 01:27:07 -05:00
|
|
|
auto res1 = ast1.eval(context);
|
|
|
|
auto res2 = ast2.eval(context);
|
|
|
|
auto wells1 = res1.wells();
|
|
|
|
auto wells2 = res2.wells();
|
|
|
|
BOOST_CHECK(res1);
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL( wells1.size(), 1U);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK_EQUAL( wells1[0], "PZ" );
|
|
|
|
|
|
|
|
BOOST_CHECK(res2);
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL( wells2.size(), 2U);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK_EQUAL( std::count(wells2.begin(), wells2.end(), "PZ") , 1);
|
|
|
|
BOOST_CHECK_EQUAL( std::count(wells2.begin(), wells2.end(), "IZ") , 1);
|
2019-03-07 03:53:40 -06:00
|
|
|
}
|
2019-11-15 06:27:58 -06:00
|
|
|
|
2019-03-07 03:53:40 -06:00
|
|
|
|
2019-01-17 04:13:33 -06:00
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(TestMatchingWells_AND) {
|
2019-07-01 01:27:07 -05:00
|
|
|
Action::AST ast({"WOPR", "*", ">", "1.0", "AND", "WWCT", "*", "<", "0.50"});
|
2019-09-19 09:17:38 -05:00
|
|
|
SummaryState st(std::chrono::system_clock::now());
|
2019-01-17 04:13:33 -06:00
|
|
|
|
2019-05-12 03:01:26 -05:00
|
|
|
st.update_well_var("OPX", "WOPR", 0);
|
|
|
|
st.update_well_var("OPY", "WOPR", 0.50);
|
|
|
|
st.update_well_var("OPZ", "WOPR", 2.0); // The WOPR check matches this well.
|
2019-01-17 04:13:33 -06:00
|
|
|
|
2019-05-12 03:01:26 -05:00
|
|
|
st.update_well_var("OPX", "WWCT", 1.0);
|
|
|
|
st.update_well_var("OPY", "WWCT", 0.0); // The WWCT check matches this well.
|
|
|
|
st.update_well_var("OPZ", "WWCT", 1.0);
|
2019-01-17 04:13:33 -06:00
|
|
|
|
2020-07-09 00:39:03 -05:00
|
|
|
WListManager wlm;
|
|
|
|
Action::Context context(st, wlm);
|
2019-07-01 01:27:07 -05:00
|
|
|
auto res = ast.eval(context);
|
|
|
|
BOOST_CHECK(res);
|
2019-01-17 04:13:33 -06:00
|
|
|
|
|
|
|
// Even though condition as a whole matches, there is no finite set of wells
|
|
|
|
// which mathes both conditions when combined with AND - i.e. the matching_wells
|
|
|
|
// variable should be empty.
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK( res.wells().empty() );
|
2019-01-17 04:13:33 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(TestMatchingWells_OR) {
|
2019-07-01 01:27:07 -05:00
|
|
|
Action::AST ast({"WOPR", "*", ">", "1.0", "OR", "WWCT", "*", "<", "0.50"});
|
2019-09-19 09:17:38 -05:00
|
|
|
SummaryState st(std::chrono::system_clock::now());
|
2019-01-17 04:13:33 -06:00
|
|
|
|
2019-05-12 03:01:26 -05:00
|
|
|
st.update_well_var("OPX", "WOPR", 0);
|
|
|
|
st.update_well_var("OPY", "WOPR", 0.50);
|
|
|
|
st.update_well_var("OPZ", "WOPR", 2.0); // The WOPR check matches this well.
|
2019-01-17 04:13:33 -06:00
|
|
|
|
2019-05-12 03:01:26 -05:00
|
|
|
st.update_well_var("OPX", "WWCT", 1.0);
|
|
|
|
st.update_well_var("OPY", "WWCT", 0.0); // The WWCT check matches this well.
|
|
|
|
st.update_well_var("OPZ", "WWCT", 1.0);
|
2019-01-17 04:13:33 -06:00
|
|
|
|
2020-07-09 00:39:03 -05:00
|
|
|
WListManager wlm;
|
|
|
|
Action::Context context(st, wlm);
|
2019-07-01 01:27:07 -05:00
|
|
|
auto res = ast.eval(context);
|
|
|
|
auto wells = res.wells();
|
|
|
|
BOOST_CHECK(res);
|
2019-01-17 04:13:33 -06:00
|
|
|
|
|
|
|
// The well 'OPZ' matches the first condition and the well 'OPY' matches the
|
|
|
|
// second condition, since the two conditions are combined with || the
|
|
|
|
// resulting mathcing_wells variable should contain both these wells.
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL( wells.size(), 2U);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK( std::find(wells.begin(), wells.end(), "OPZ") != wells.end());
|
|
|
|
BOOST_CHECK( std::find(wells.begin(), wells.end(), "OPY") != wells.end());
|
|
|
|
}
|
|
|
|
|
2020-07-09 00:39:03 -05:00
|
|
|
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);
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL( wells.size(), 3U);
|
2020-07-09 00:39:03 -05:00
|
|
|
for (const auto& w : {"W1", "W3", "W5"}) {
|
|
|
|
auto find_iter = std::find(wells.begin(), wells.end(), w);
|
|
|
|
BOOST_CHECK( find_iter != wells.end() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_AUTO_TEST_CASE(TestFieldAND) {
|
|
|
|
Action::AST ast({"FMWPR", ">=", "4", "AND", "WUPR3", "OP*", "=", "1"});
|
2019-09-19 09:17:38 -05:00
|
|
|
SummaryState st(std::chrono::system_clock::now());
|
2020-07-09 00:39:03 -05:00
|
|
|
WListManager wlm;
|
|
|
|
Action::Context context(st, wlm);
|
2019-07-01 01:27:07 -05:00
|
|
|
|
|
|
|
st.update_well_var("OP1", "WUPR3", 3);
|
|
|
|
st.update_well_var("OP2", "WUPR3", 2);
|
|
|
|
st.update_well_var("OP3", "WUPR3", 1);
|
|
|
|
st.update_well_var("OP4", "WUPR3", 4);
|
|
|
|
|
|
|
|
st.update("FMWPR", 1);
|
|
|
|
{
|
|
|
|
auto res = ast.eval(context);
|
|
|
|
BOOST_CHECK(!res);
|
2020-05-05 12:18:39 -05:00
|
|
|
BOOST_CHECK_THROW(res.wells(), std::logic_error);
|
|
|
|
BOOST_CHECK_THROW(res.has_well("ABC"), std::logic_error);
|
2019-07-01 01:27:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
st.update("FMWPR", 4);
|
|
|
|
{
|
|
|
|
auto res = ast.eval(context);
|
|
|
|
auto wells = res.wells();
|
|
|
|
BOOST_CHECK(res);
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL(wells.size(), 1U);
|
2019-07-01 01:27:07 -05:00
|
|
|
BOOST_CHECK_EQUAL(wells[0], "OP3");
|
|
|
|
}
|
2019-01-17 04:13:33 -06:00
|
|
|
}
|
2019-08-29 11:17:37 -05:00
|
|
|
|
2019-09-13 13:24:56 -05:00
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(Conditions) {
|
2020-09-16 07:21:50 -05:00
|
|
|
auto location = KeywordLocation("Keyword", "File", 100);
|
2019-09-13 13:24:56 -05:00
|
|
|
|
|
|
|
// Missing comparator
|
|
|
|
BOOST_CHECK_THROW(Action::Condition cond({"WWCT", "OPX"}, location), std::invalid_argument);
|
|
|
|
|
|
|
|
// Missing right hand side
|
|
|
|
BOOST_CHECK_THROW(Action::Condition cond({"WWCT", "OPX", ">"}, location), std::invalid_argument);
|
|
|
|
|
|
|
|
Action::Condition cond({"WWCT", "OPX", ">", "0.75", "AND"}, location);
|
|
|
|
BOOST_CHECK(cond.cmp == Action::Condition::Comparator::GREATER);
|
|
|
|
BOOST_CHECK(cond.cmp_string == ">" );
|
|
|
|
BOOST_CHECK_EQUAL(cond.lhs.quantity, "WWCT");
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL(cond.lhs.args.size(), 1U);
|
2019-09-13 13:24:56 -05:00
|
|
|
BOOST_CHECK_EQUAL(cond.lhs.args[0], "OPX");
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(cond.rhs.quantity, "0.75");
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL(cond.rhs.args.size(), 0U);
|
2019-09-13 13:24:56 -05:00
|
|
|
BOOST_CHECK(cond.logic == Action::Condition::Logical::AND);
|
|
|
|
|
|
|
|
Action::Condition cond2({"WWCT", "OPX", "<=", "WSOPR", "OPX", "235"}, location);
|
|
|
|
BOOST_CHECK(cond2.cmp == Action::Condition::Comparator::LESS_EQUAL);
|
|
|
|
BOOST_CHECK(cond2.cmp_string == "<=" );
|
|
|
|
BOOST_CHECK_EQUAL(cond2.lhs.quantity, "WWCT");
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL(cond2.lhs.args.size(), 1U);
|
2019-09-13 13:24:56 -05:00
|
|
|
BOOST_CHECK_EQUAL(cond2.lhs.args[0], "OPX");
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(cond2.rhs.quantity, "WSOPR");
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL(cond2.rhs.args.size(), 2U);
|
2019-09-13 13:24:56 -05:00
|
|
|
BOOST_CHECK_EQUAL(cond2.rhs.args[0], "OPX");
|
|
|
|
BOOST_CHECK_EQUAL(cond2.rhs.args[1], "235");
|
|
|
|
BOOST_CHECK(cond2.logic == Action::Condition::Logical::END);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-29 11:17:37 -05:00
|
|
|
BOOST_AUTO_TEST_CASE(SCAN2) {
|
|
|
|
const auto deck_string = std::string{ R"(
|
|
|
|
SCHEDULE
|
|
|
|
|
|
|
|
TSTEP
|
|
|
|
10 /
|
|
|
|
|
|
|
|
ACTIONX
|
2019-08-30 06:07:45 -05:00
|
|
|
'B' /
|
2019-09-13 13:24:56 -05:00
|
|
|
WWCT 'OPX' > 0.75 AND /
|
2019-08-30 02:36:47 -05:00
|
|
|
FPR < 100 /
|
2019-08-29 11:17:37 -05:00
|
|
|
/
|
|
|
|
|
|
|
|
WELSPECS
|
|
|
|
'W1' 'OP' 1 1 3.33 'OIL' 7*/
|
|
|
|
/
|
|
|
|
|
|
|
|
ENDACTIO
|
|
|
|
|
|
|
|
TSTEP
|
|
|
|
10 /
|
2019-08-30 06:07:45 -05:00
|
|
|
|
|
|
|
|
|
|
|
ACTIONX
|
|
|
|
'A' /
|
|
|
|
WOPR 'OPX' = 1000 /
|
|
|
|
/
|
|
|
|
|
|
|
|
ENDACTIO
|
|
|
|
|
|
|
|
ACTIONX
|
|
|
|
'B' /
|
2019-09-07 00:08:22 -05:00
|
|
|
FWCT <= 0.50 /
|
2019-08-30 06:07:45 -05:00
|
|
|
/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ENDACTIO
|
|
|
|
|
|
|
|
TSTEP
|
|
|
|
10 /
|
|
|
|
|
2019-08-29 11:17:37 -05:00
|
|
|
)"};
|
|
|
|
|
|
|
|
Opm::Parser parser;
|
|
|
|
auto deck = parser.parseString(deck_string);
|
|
|
|
EclipseGrid grid1(10,10,10);
|
|
|
|
TableManager table ( deck );
|
2020-01-16 11:20:31 -06:00
|
|
|
FieldPropsManager fp( deck, Phases{true, true, true}, grid1, table);
|
2020-03-31 03:26:55 -05:00
|
|
|
auto python = std::make_shared<Python>();
|
2019-11-21 04:44:06 -06:00
|
|
|
|
2019-08-29 11:17:37 -05:00
|
|
|
Runspec runspec (deck);
|
2020-03-26 09:31:21 -05:00
|
|
|
Schedule sched(deck, grid1, fp, runspec, python);
|
2019-08-29 11:17:37 -05:00
|
|
|
const auto& actions0 = sched.actions(0);
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL(actions0.size(), 0U);
|
2019-08-29 11:17:37 -05:00
|
|
|
|
|
|
|
const auto& actions1 = sched.actions(1);
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL(actions1.size(), 1U);
|
2019-08-30 02:36:47 -05:00
|
|
|
|
|
|
|
|
2019-08-30 06:07:45 -05:00
|
|
|
const auto& act1 = actions1.get("B");
|
2019-08-30 02:36:47 -05:00
|
|
|
const auto& strings = act1.keyword_strings();
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL(strings.size(), 4U);
|
2019-08-30 02:36:47 -05:00
|
|
|
BOOST_CHECK_EQUAL(strings.back(), "ENDACTIO");
|
|
|
|
|
|
|
|
|
|
|
|
std::string rdeck_string = "";
|
|
|
|
for (std::size_t i = 0; i < strings.size(); i++)
|
|
|
|
rdeck_string += strings[i] + "\n";
|
|
|
|
|
|
|
|
auto deck2 = parser.parseString(rdeck_string);
|
|
|
|
BOOST_CHECK(deck2.getKeyword("WELSPECS") == deck.getKeyword("WELSPECS"));
|
|
|
|
|
|
|
|
|
|
|
|
const auto& conditions = act1.conditions();
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL(conditions.size() , 2U);
|
2019-08-30 02:36:47 -05:00
|
|
|
|
|
|
|
const auto& cond0 = conditions[0];
|
2019-09-13 13:24:56 -05:00
|
|
|
BOOST_CHECK_EQUAL(cond0.lhs.quantity, "WWCT");
|
2019-08-30 02:36:47 -05:00
|
|
|
BOOST_CHECK(cond0.cmp == Action::Condition::Comparator::GREATER);
|
|
|
|
BOOST_CHECK(cond0.logic == Action::Condition::Logical::AND);
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL(cond0.lhs.args.size(), 1U);
|
2019-09-13 13:24:56 -05:00
|
|
|
BOOST_CHECK_EQUAL(cond0.lhs.args[0], "OPX");
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL(cond0.rhs.args.size(), 0U);
|
2019-09-13 13:24:56 -05:00
|
|
|
BOOST_CHECK_EQUAL(cond0.rhs.quantity, "0.75");
|
2019-08-30 02:36:47 -05:00
|
|
|
|
|
|
|
const auto& cond1 = conditions[1];
|
2019-09-13 13:24:56 -05:00
|
|
|
BOOST_CHECK_EQUAL(cond1.lhs.quantity, "FPR");
|
2019-08-30 02:36:47 -05:00
|
|
|
BOOST_CHECK(cond1.cmp == Action::Condition::Comparator::LESS);
|
|
|
|
BOOST_CHECK(cond1.logic == Action::Condition::Logical::END);
|
2019-08-30 06:07:45 -05:00
|
|
|
|
|
|
|
/*****************************************************************/
|
|
|
|
|
|
|
|
const auto& actions2 = sched.actions(2);
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL(actions2.size(), 2U);
|
2019-08-30 06:07:45 -05:00
|
|
|
|
|
|
|
const auto& actB = actions2.get("B");
|
|
|
|
const auto& condB = actB.conditions();
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL(condB.size() , 1U);
|
2019-09-13 13:24:56 -05:00
|
|
|
BOOST_CHECK_EQUAL(condB[0].lhs.quantity, "FWCT");
|
2019-09-07 00:08:22 -05:00
|
|
|
BOOST_CHECK(condB[0].cmp == Action::Condition::Comparator::LESS_EQUAL);
|
2019-08-30 06:07:45 -05:00
|
|
|
BOOST_CHECK(condB[0].logic == Action::Condition::Logical::END);
|
2019-09-13 13:24:56 -05:00
|
|
|
BOOST_CHECK_EQUAL(condB[0].cmp_string, "<=");
|
2019-08-30 06:07:45 -05:00
|
|
|
|
|
|
|
const auto& actA = actions2.get("A");
|
|
|
|
const auto& condA = actA.conditions();
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL(condA.size() , 1U);
|
2019-09-13 13:24:56 -05:00
|
|
|
BOOST_CHECK_EQUAL(condA[0].lhs.quantity, "WOPR");
|
2019-08-30 06:07:45 -05:00
|
|
|
BOOST_CHECK(condA[0].cmp == Action::Condition::Comparator::EQUAL);
|
|
|
|
BOOST_CHECK(condA[0].logic == Action::Condition::Logical::END);
|
2019-09-13 13:24:56 -05:00
|
|
|
BOOST_CHECK_EQUAL(condA[0].cmp_string , "=");
|
2019-08-30 06:07:45 -05:00
|
|
|
|
|
|
|
std::size_t index = 0;
|
|
|
|
for (const auto& act : actions2) {
|
|
|
|
if (index == 0)
|
|
|
|
BOOST_CHECK_EQUAL("B", act.name());
|
|
|
|
|
|
|
|
if (index == 1)
|
|
|
|
BOOST_CHECK_EQUAL("A", act.name());
|
|
|
|
index++;
|
|
|
|
}
|
2019-08-29 11:17:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-04 05:51:44 -06:00
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(ACTIONRESULT_COPY_WELLS) {
|
|
|
|
Action::Result res1(true, {"W1", "W2", "W3"});
|
|
|
|
auto res2 = res1;
|
|
|
|
|
|
|
|
BOOST_CHECK(res1);
|
|
|
|
BOOST_CHECK(res2);
|
|
|
|
BOOST_CHECK(!res1.has_well("NO"));
|
|
|
|
BOOST_CHECK(!res2.has_well("NO"));
|
|
|
|
for (const auto& w : {"W1", "W2", "W3"}) {
|
|
|
|
BOOST_CHECK(res1.has_well(w));
|
|
|
|
BOOST_CHECK(res2.has_well(w));
|
|
|
|
}
|
|
|
|
}
|
2020-06-17 05:03:24 -05:00
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(ActionState) {
|
|
|
|
Action::State st;
|
2020-06-16 01:21:41 -05:00
|
|
|
Action::ActionX action1("NAME", 100, 100, 100); action1.update_id(100);
|
|
|
|
Action::ActionX action2("NAME", 100, 100, 100); action1.update_id(200);
|
2020-06-17 05:03:24 -05:00
|
|
|
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL(0U, st.run_count(action1));
|
2020-06-16 01:21:41 -05:00
|
|
|
BOOST_CHECK_THROW( st.run_time(action1), std::out_of_range);
|
2020-06-17 05:03:24 -05:00
|
|
|
|
2020-06-16 01:21:41 -05:00
|
|
|
st.add_run(action1, 100);
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL(1U, st.run_count(action1));
|
2020-06-16 01:21:41 -05:00
|
|
|
BOOST_CHECK_EQUAL(100, st.run_time(action1));
|
2020-06-17 05:03:24 -05:00
|
|
|
|
2020-06-16 01:21:41 -05:00
|
|
|
st.add_run(action1, 1000);
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL(2U, st.run_count(action1));
|
2020-06-16 01:21:41 -05:00
|
|
|
BOOST_CHECK_EQUAL(1000, st.run_time(action1));
|
|
|
|
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL(0U, st.run_count(action2));
|
2020-06-16 01:21:41 -05:00
|
|
|
BOOST_CHECK_THROW( st.run_time(action2), std::out_of_range);
|
|
|
|
|
|
|
|
st.add_run(action2, 100);
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL(1U, st.run_count(action2));
|
2020-06-16 01:21:41 -05:00
|
|
|
BOOST_CHECK_EQUAL(100, st.run_time(action2));
|
|
|
|
|
|
|
|
st.add_run(action2, 1000);
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL(2U, st.run_count(action2));
|
2020-06-16 01:21:41 -05:00
|
|
|
BOOST_CHECK_EQUAL(1000, st.run_time(action2));
|
2020-06-17 05:03:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(ActionID) {
|
|
|
|
const auto deck_string = std::string{ R"(
|
|
|
|
SCHEDULE
|
|
|
|
|
|
|
|
TSTEP
|
|
|
|
10 /
|
|
|
|
|
|
|
|
ACTIONX
|
|
|
|
'A' /
|
|
|
|
WWCT 'OPX' > 0.75 AND /
|
|
|
|
FPR < 100 /
|
|
|
|
/
|
|
|
|
|
|
|
|
WELSPECS
|
|
|
|
'W1' 'OP' 1 1 3.33 'OIL' 7*/
|
|
|
|
/
|
|
|
|
|
|
|
|
ENDACTIO
|
|
|
|
|
|
|
|
TSTEP
|
|
|
|
10 /
|
|
|
|
|
|
|
|
|
|
|
|
ACTIONX
|
|
|
|
'A' /
|
|
|
|
WOPR 'OPX' = 1000 /
|
|
|
|
/
|
|
|
|
|
|
|
|
ENDACTIO
|
|
|
|
|
|
|
|
)"};
|
|
|
|
|
|
|
|
Opm::Parser parser;
|
|
|
|
auto deck = parser.parseString(deck_string);
|
|
|
|
EclipseGrid grid1(10,10,10);
|
|
|
|
TableManager table ( deck );
|
|
|
|
FieldPropsManager fp( deck, Phases{true, true, true}, grid1, table);
|
|
|
|
auto python = std::make_shared<Python>();
|
|
|
|
|
|
|
|
Runspec runspec (deck);
|
|
|
|
Schedule sched(deck, grid1, fp, runspec, python);
|
|
|
|
const auto& action1 = sched.actions(1).get("A");
|
|
|
|
const auto& action2 = sched.actions(2).get("A");
|
|
|
|
|
|
|
|
BOOST_CHECK(action1.id() != action2.id());
|
2020-06-16 01:21:41 -05:00
|
|
|
|
|
|
|
Action::State st;
|
|
|
|
st.add_run(action1, 1000);
|
2020-09-29 06:54:21 -05:00
|
|
|
BOOST_CHECK_EQUAL( st.run_count(action1), 1U);
|
|
|
|
BOOST_CHECK_EQUAL( st.run_count(action2), 0U);
|
2020-06-17 05:03:24 -05:00
|
|
|
}
|