2019-09-02 18:27:22 +02:00
|
|
|
/*
|
|
|
|
|
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 OPM_EMBEDDED_PYTHON
|
|
|
|
|
#define OPM_EMBEDDED_PYTHON
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
2019-12-27 08:58:26 +01:00
|
|
|
#include <opm/parser/eclipse/EclipseState/Schedule/Action/PyAction.hpp>
|
2019-09-02 18:27:22 +02:00
|
|
|
|
|
|
|
|
namespace Opm {
|
|
|
|
|
class PythonInterp;
|
2019-09-12 16:34:37 +02:00
|
|
|
class Parser;
|
|
|
|
|
class Deck;
|
2019-09-02 18:27:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
This class is a thin wrapper around the PythonInterp class. The Python class
|
|
|
|
|
can always be safely instantiated, but the actual PythonInterp implementation
|
|
|
|
|
depends on whether Python support was enabled when this library instance was
|
|
|
|
|
compiled.
|
|
|
|
|
|
|
|
|
|
If one the methods actually invoking the Python interpreter is invoked without
|
|
|
|
|
proper Python support a dummy PythinInterp instance will be used; and that
|
|
|
|
|
will just throw std::logic_error. The operator bool can be used to check if
|
|
|
|
|
this Python manager indeed has a valid Python runtime:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Python python;
|
|
|
|
|
|
|
|
|
|
if (python)
|
|
|
|
|
python.exec("print('Hello world')")
|
|
|
|
|
else
|
|
|
|
|
OpmLog::Error("This version of opmcommon has been built with support for embedded Python");
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
class Python {
|
|
|
|
|
public:
|
|
|
|
|
Python();
|
2019-09-12 16:34:37 +02:00
|
|
|
bool exec(const std::string& python_code) const;
|
|
|
|
|
bool exec(const std::string& python_code, const Parser& parser, Deck& deck) const;
|
2019-12-27 08:58:26 +01:00
|
|
|
bool exec(const PyAction& py_action) const;
|
2019-09-02 18:27:22 +02:00
|
|
|
explicit operator bool() const;
|
|
|
|
|
private:
|
|
|
|
|
std::shared_ptr<PythonInterp> interp;
|
|
|
|
|
};
|
2019-11-13 15:03:47 +01:00
|
|
|
|
|
|
|
|
std::unique_ptr<Python> PythonInstance();
|
|
|
|
|
|
2019-09-02 18:27:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-11-13 15:03:47 +01:00
|
|
|
|
2019-09-02 18:27:22 +02:00
|
|
|
#endif
|
|
|
|
|
|