Add method Actions::pending_python() to get active Python functions
This commit is contained in:
@@ -52,6 +52,7 @@ public:
|
||||
const ActionX& get(const std::string& name) const;
|
||||
const ActionX& get(std::size_t index) const;
|
||||
std::vector<const ActionX *> pending(std::time_t sim_time) const;
|
||||
std::vector<const PyAction *> pending_python() const;
|
||||
|
||||
std::vector<ActionX>::const_iterator begin() const;
|
||||
std::vector<ActionX>::const_iterator end() const;
|
||||
|
||||
@@ -97,6 +97,16 @@ bool Actions::ready(std::time_t sim_time) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<const PyAction *> Actions::pending_python() const {
|
||||
std::vector<const PyAction *> pyaction_vector;
|
||||
for (const auto& pyaction : this->pyactions) {
|
||||
if (pyaction.active())
|
||||
pyaction_vector.push_back( &pyaction );
|
||||
}
|
||||
return pyaction_vector;
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::vector<const ActionX *> Actions::pending(std::time_t sim_time) const {
|
||||
std::vector<const ActionX *> action_vector;
|
||||
|
||||
@@ -168,6 +168,12 @@ BOOST_AUTO_TEST_CASE(TestActions) {
|
||||
|
||||
Opm::Action::ActionX action3("NAME3", 1000000, 0, asTimeT(TimeStampUTC(TimeStampUTC::YMD{ 2000, 7, 1 })) );
|
||||
config.add(action3);
|
||||
|
||||
Opm::Action::PyAction py_action1("PYTHON1", Opm::Action::PyAction::RunCount::single, "import sys");
|
||||
config.add(py_action1);
|
||||
|
||||
Opm::Action::PyAction py_action2("PYTHON2", Opm::Action::PyAction::RunCount::single, "import sys");
|
||||
config.add(py_action2);
|
||||
}
|
||||
const Opm::Action::ActionX& action2 = config.get("NAME");
|
||||
// The action2 instance has an empty condition, so it will never evaluate to true.
|
||||
@@ -182,6 +188,10 @@ BOOST_AUTO_TEST_CASE(TestActions) {
|
||||
BOOST_CHECK( !ptr->eval(asTimeT(TimeStampUTC(TimeStampUTC::YMD{ 2000, 8, 7 })), context));
|
||||
}
|
||||
BOOST_CHECK(!action2.eval(asTimeT(TimeStampUTC(TimeStampUTC::YMD{ 2000, 8, 7 })), context));
|
||||
|
||||
|
||||
const auto& python_actions = config.pending_python();
|
||||
BOOST_CHECK_EQUAL(python_actions.size(), 2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user