Moved PyAction class into Action:: namespace

This commit is contained in:
Joakim Hove
2020-03-16 13:48:46 +01:00
parent 7852203d39
commit d06a5a78e0
9 changed files with 15 additions and 12 deletions

View File

@@ -26,6 +26,7 @@
#include <vector>
#include <opm/parser/eclipse/EclipseState/Schedule/Action/ActionX.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Action/PyAction.hpp>
namespace Opm {
namespace Action {

View File

@@ -25,6 +25,7 @@
#include <string>
namespace Opm {
namespace Action {
class PyAction {
public:
@@ -61,6 +62,7 @@ private:
std::string input_code;
void * m_storage;
};
}
}

View File

@@ -59,7 +59,7 @@ public:
Python();
bool exec(const std::string& python_code) const;
bool exec(const std::string& python_code, const Parser& parser, Deck& deck) const;
bool exec(const PyAction& py_action, EclipseState& ecl_state, Schedule& schedule, std::size_t report_step, SummaryState& st) const;
bool exec(const Action::PyAction& py_action, EclipseState& ecl_state, Schedule& schedule, std::size_t report_step, SummaryState& st) const;
explicit operator bool() const;
private:
std::shared_ptr<PythonInterp> interp;

View File

@@ -34,7 +34,7 @@ using dict = int;
#include <opm/parser/eclipse/EclipseState/Schedule/Action/PyAction.hpp>
namespace Opm {
namespace Action {
PyAction::RunCount PyAction::from_string(std::string run_count) {
run_count = uppercase(run_count);
@@ -109,5 +109,5 @@ void * PyAction::storage() const {
return this->m_storage;
}
}
}

View File

@@ -41,7 +41,7 @@ bool Python::exec(const std::string& python_code, const Parser& parser, Deck& de
return true;
}
bool Python::exec(const PyAction& py_action, EclipseState& ecl_state, Schedule& schedule, std::size_t report_step, SummaryState& st) const {
bool Python::exec(const Action::PyAction& py_action, EclipseState& ecl_state, Schedule& schedule, std::size_t report_step, SummaryState& st) const {
this->interp->exec(py_action, ecl_state, schedule, report_step, st);
return true;
}

View File

@@ -46,7 +46,7 @@ bool PythonInterp::exec(const std::string& python_code, const Parser& parser, De
}
bool PythonInterp::exec(const PyAction& py_action, EclipseState& ecl_state, Schedule& schedule, std::size_t report_step, SummaryState& st) {
bool PythonInterp::exec(const Action::PyAction& py_action, EclipseState& ecl_state, Schedule& schedule, std::size_t report_step, SummaryState& st) {
auto context = py::module::import("context");
context.attr("schedule") = &schedule;

View File

@@ -50,7 +50,7 @@ class __attribute__ ((visibility("hidden"))) PythonInterp {
public:
bool exec(const std::string& python_code);
bool exec(const std::string& python_code, const Parser& parser, Deck& deck);
bool exec(const PyAction& py_action, EclipseState& ecl_state, Schedule& schedule, std::size_t report_step, SummaryState& st);
bool exec(const Action::PyAction& py_action, EclipseState& ecl_state, Schedule& schedule, std::size_t report_step, SummaryState& st);
explicit operator bool() const { return true; }
private:
py::scoped_interpreter guard = {};
@@ -69,7 +69,7 @@ public:
return this->fail();
}
bool exec(const PyAction&, EclipseState&, Schedule&, std::size_t, SummaryState& ) {
bool exec(const Action::PyAction&, EclipseState&, Schedule&, std::size_t, SummaryState& ) {
return this->fail();
}

View File

@@ -109,7 +109,7 @@ BOOST_AUTO_TEST_CASE(PYACTION) {
SummaryState st(std::chrono::system_clock::now());
const auto& pyaction_kw = deck.getKeyword<ParserKeywords::PYACTION>(0);
const std::string& fname = pyaction_kw.getRecord(1).getItem(0).get<std::string>(0);
PyAction py_action("WCLOSE", PyAction::RunCount::unlimited, PyAction::load(deck.getInputPath(), fname));
Action::PyAction py_action("WCLOSE", Action::PyAction::RunCount::unlimited, Action::PyAction::load(deck.getInputPath(), fname));
st.update_well_var("PROD1", "WWCT", 0);
python.exec(py_action, ecl_state, schedule, 10, st);

View File

@@ -36,8 +36,8 @@ BOOST_AUTO_TEST_CASE(ParsePYACTION) {
const auto& record1 = keyword.getRecord(1);
const auto& name = record0.getItem(0).get<std::string>(0);
auto run_count = PyAction::from_string(record0.getItem(1).get<std::string>(0));
std::string code = PyAction::load(deck.getInputPath(), record1.getItem(0).get<std::string>(0));
auto run_count = Action::PyAction::from_string(record0.getItem(1).get<std::string>(0));
std::string code = Action::PyAction::load(deck.getInputPath(), record1.getItem(0).get<std::string>(0));
std::string literal_code =R"(from math import sin
import random
@@ -52,8 +52,8 @@ B = A / 10
C = B * 20
)";
PyAction pyaction("ACT1", run_count, code);
Action::PyAction pyaction("ACT1", run_count, code);
BOOST_CHECK_EQUAL(pyaction.name(), "ACT1");
BOOST_CHECK_EQUAL(pyaction.code(), literal_code);
BOOST_CHECK(pyaction.run_count() == PyAction::RunCount::single);
BOOST_CHECK(pyaction.run_count() == Action::PyAction::RunCount::single);
}