Add PyAction skeleton code
This commit is contained in:
@@ -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
|
||||
|
||||
39
opm/parser/eclipse/EclipseState/Schedule/Action/PyAction.hpp
Normal file
39
opm/parser/eclipse/EclipseState/Schedule/Action/PyAction.hpp
Normal 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
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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>();
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user