Add PyAction skeleton code

This commit is contained in:
Joakim Hove
2019-12-27 08:58:26 +01:00
parent 4e899503e2
commit d2392c4ea4
6 changed files with 86 additions and 2 deletions

View File

@@ -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

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef PYACTION_HPP_
#define PYACTION_HPP_
#include <string>
namespace Opm {
class PyAction {
public:
explicit PyAction(const std::string& code_arg);
const std::string& code() const;
private:
std::string input_code;
};
}
#endif

View File

@@ -23,6 +23,7 @@
#include <memory>
#include <string>
#include <opm/parser/eclipse/EclipseState/Schedule/Action/PyAction.hpp>
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<PythonInterp> interp;

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#include <opm/parser/eclipse/EclipseState/Schedule/Action/PyAction.hpp>
namespace Opm {
PyAction::PyAction(const std::string& code_arg) :
input_code(code_arg)
{}
const std::string& PyAction::code() const {
return this->input_code;
}
}

View File

@@ -24,7 +24,7 @@
namespace Opm {
Python::Python() :
interp(std::make_shared<PythonInterp>())
interp(std::make_shared<PythonInterp>())
{
}
@@ -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<Python> PythonInstance() {
if (Py_IsInitialized())
return NULL;
#endif
return std::make_unique<Python>();
}

View File

@@ -22,6 +22,7 @@
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <opm/parser/eclipse/Parser/Parser.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Action/PyAction.hpp>
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);
}