opm-common
Toggle main menu visibility
Loading...
Searching...
No Matches
PythonInterp.hpp
1
/*
2
Copyright 2019 Equinor ASA.
3
4
This file is part of the Open Porous Media project (OPM).
5
6
OPM is free software: you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation, either version 3 of the License, or
9
(at your option) any later version.
10
11
OPM is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
15
16
You should have received a copy of the GNU General Public License
17
along with OPM. If not, see <http://www.gnu.org/licenses/>.
18
*/
19
20
21
#ifndef PYTHON_INTERP
22
#define PYTHON_INTERP
23
24
#include <string>
25
#include <stdexcept>
26
#include <memory>
27
28
#include <opm/input/eclipse/Schedule/SummaryState.hpp>
29
#include <opm/input/eclipse/Schedule/Action/PyAction.hpp>
30
31
32
#ifdef EMBEDDED_PYTHON
33
34
#include <pybind11/embed.h>
35
namespace
py = pybind11;
36
#endif
37
38
39
40
namespace
Opm
{
41
42
#ifdef EMBEDDED_PYTHON
43
class
Deck
;
44
class
Parser
;
45
46
47
class
__attribute__ ((visibility(
"hidden"
)))
PythonInterp
{
48
public
:
49
explicit
PythonInterp(
bool
enable);
50
bool
exec(
const
std::string& python_code);
51
bool
exec(
const
std::string& python_code,
const
Parser& parser, Deck& deck);
52
static
bool
supported() {
return
true
; };
53
explicit
operator
bool()
const
{
return
bool(this->guard); }
54
private
:
55
void
load_module(
const
std::string& python_file);
56
bool
exec(
const
std::string& python_code, py::module& context);
57
58
std::unique_ptr<py::scoped_interpreter> guard;
59
};
60
61
62
#else
63
64
class
EclipseState
;
65
class
Schedule
;
66
67
class
PythonInterp {
68
public
:
69
explicit
PythonInterp(
bool
enable) {
70
if
(enable)
71
this->fail();
72
}
73
74
bool
exec(
const
std::string&) {
75
return
this->fail();
76
};
77
78
bool
exec(
const
std::string&,
const
Parser
&,
Deck
&) {
79
return
this->fail();
80
}
81
82
bool
exec(
const
Action::PyAction
&,
EclipseState
&,
Schedule
&, std::size_t,
SummaryState
& ) {
83
return
this->fail();
84
}
85
86
static
bool
supported() {
return
false
; };
87
explicit
operator
bool()
const
{
return
false
; }
88
private
:
89
bool
fail() {
throw
std::logic_error(
"The current opm code has been built without Python support;"
); }
90
};
91
92
#endif
93
94
}
95
96
#endif
Opm::Action::PyAction
Definition
PyAction.hpp:40
Opm::Deck
Definition
Deck.hpp:46
Opm::EclipseState
Definition
EclipseState.hpp:62
Opm::Parser
The hub of the parsing process.
Definition
Parser.hpp:60
Opm::PythonInterp
Definition
PythonInterp.hpp:67
Opm::Schedule
Definition
Schedule.hpp:101
Opm::SummaryState
Definition
SummaryState.hpp:72
Opm
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition
Exceptions.hpp:30
opm
input
eclipse
Python
PythonInterp.hpp
Generated by
1.17.0