diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake
index 9702f27f6..ab8b1d922 100644
--- a/CMakeLists_files.cmake
+++ b/CMakeLists_files.cmake
@@ -94,6 +94,7 @@ if(ENABLE_ECL_INPUT)
src/opm/parser/eclipse/EclipseState/Schedule/Action/ActionValue.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Action/ASTNode.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Action/Condition.cpp
+ src/opm/parser/eclipse/EclipseState/Schedule/Action/PyAction.cpp
src/opm/parser/eclipse/EclipseState/Schedule/ArrayDimChecker.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Events.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Group/Group.cpp
@@ -607,6 +608,7 @@ if(ENABLE_ECL_INPUT)
opm/parser/eclipse/EclipseState/Schedule/Action/ActionX.hpp
opm/parser/eclipse/EclipseState/Schedule/Action/Condition.hpp
opm/parser/eclipse/EclipseState/Schedule/Action/ASTNode.hpp
+ opm/parser/eclipse/EclipseState/Schedule/Action/PyAction.hpp
opm/parser/eclipse/EclipseState/Schedule/ArrayDimChecker.hpp
opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp
opm/parser/eclipse/EclipseState/Schedule/VFPInjTable.hpp
diff --git a/opm/parser/eclipse/EclipseState/Schedule/Action/PyAction.hpp b/opm/parser/eclipse/EclipseState/Schedule/Action/PyAction.hpp
new file mode 100644
index 000000000..19235a2db
--- /dev/null
+++ b/opm/parser/eclipse/EclipseState/Schedule/Action/PyAction.hpp
@@ -0,0 +1,39 @@
+/*
+ Copyright 2019 Equinor 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 .
+*/
+
+
+#ifndef PYACTION_HPP_
+#define PYACTION_HPP_
+
+
+#include
+
+namespace Opm {
+
+class PyAction {
+public:
+ explicit PyAction(const std::string& code_arg);
+ const std::string& code() const;
+private:
+ std::string input_code;
+};
+
+}
+
+#endif
diff --git a/opm/parser/eclipse/Python/Python.hpp b/opm/parser/eclipse/Python/Python.hpp
index 13c023f71..0120888d3 100644
--- a/opm/parser/eclipse/Python/Python.hpp
+++ b/opm/parser/eclipse/Python/Python.hpp
@@ -23,6 +23,7 @@
#include
#include
+#include
namespace Opm {
class PythonInterp;
@@ -56,6 +57,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) const;
explicit operator bool() const;
private:
std::shared_ptr interp;
diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Action/PyAction.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Action/PyAction.cpp
new file mode 100644
index 000000000..40b52120f
--- /dev/null
+++ b/src/opm/parser/eclipse/EclipseState/Schedule/Action/PyAction.cpp
@@ -0,0 +1,34 @@
+/*
+ Copyright 2019 Equinor 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 .
+*/
+
+#include
+
+namespace Opm {
+
+PyAction::PyAction(const std::string& code_arg) :
+ input_code(code_arg)
+{}
+
+
+const std::string& PyAction::code() const {
+ return this->input_code;
+}
+
+
+}
diff --git a/src/opm/parser/eclipse/Python/Python.cpp b/src/opm/parser/eclipse/Python/Python.cpp
index cb94bbc90..089f5cae8 100644
--- a/src/opm/parser/eclipse/Python/Python.cpp
+++ b/src/opm/parser/eclipse/Python/Python.cpp
@@ -24,7 +24,7 @@
namespace Opm {
Python::Python() :
- interp(std::make_shared())
+ interp(std::make_shared())
{
}
@@ -40,6 +40,10 @@ bool Python::exec(const std::string& python_code, const Parser& parser, Deck& de
return true;
}
+bool Python::exec(const PyAction& py_action) const {
+ this->interp->exec(py_action.code());
+ return true;
+}
Python::operator bool() const {
@@ -54,7 +58,7 @@ std::unique_ptr PythonInstance() {
if (Py_IsInitialized())
return NULL;
#endif
-
+
return std::make_unique();
}
diff --git a/tests/parser/PYACTION.cpp b/tests/parser/PYACTION.cpp
index 50c259a59..71f912e1a 100644
--- a/tests/parser/PYACTION.cpp
+++ b/tests/parser/PYACTION.cpp
@@ -22,6 +22,7 @@
#include
#include
#include
+#include
using namespace Opm;
@@ -76,4 +77,6 @@ PYACTION -- Comment
BOOST_CHECK_EQUAL(parsed_code, input_code);
BOOST_CHECK( deck.hasKeyword("GRID"));
}
+
+ PyAction pyact(input_code);
}