OGS
ogs_embedded_python.cpp
Go to the documentation of this file.
1 
10 #include "ogs_embedded_python.h"
11 
12 #include <pybind11/embed.h>
13 
14 #include "BaseLib/Logging.h"
18 
20 {
21  DBUG("Binding Python module OpenGeoSys.");
22 
26 }
27 
28 #ifndef OGS_BUILD_SHARED_LIBS
29 
30 // Hackish trick that hopefully ensures that the linker won't strip the symbol
31 // pointed to by p from the library being built.
32 template <typename T>
33 void mark_used(T p)
34 {
35  volatile T vp = p;
36  vp = vp;
37 }
38 
39 #endif // OGS_BUILD_SHARED_LIBS
40 
41 namespace ApplicationsLib
42 {
43 pybind11::scoped_interpreter setupEmbeddedPython()
44 {
45 #ifndef OGS_BUILD_SHARED_LIBS
46  // pybind11_init_impl_OpenGeoSys is the function initializing the embedded
47  // OpenGeoSys Python module. The name is generated by pybind11. If it is not
48  // obvious that this symbol is actually used, the linker might remove it
49  // under certain circumstances.
50  mark_used(&pybind11_init_impl_OpenGeoSys);
51 #endif
52 
53  // Allows ogs to be interrupted by SIGINT, which otherwise is handled by
54  // python. See
55  // https://docs.python.org/3/c-api/exceptions.html#c.PyErr_CheckSignals and
56  // https://pybind11.readthedocs.io/en/stable/faq.html#how-can-i-properly-handle-ctrl-c-in-long-running-functions
57  constexpr bool init_signal_handlers = false;
58  return pybind11::scoped_interpreter{init_signal_handlers};
59 }
60 
61 } // namespace ApplicationsLib
void DBUG(char const *fmt, Args const &... args)
Definition: Logging.h:27
pybind11::scoped_interpreter setupEmbeddedPython()
static const double p
void pythonBindSourceTerm(pybind11::module &m)
Creates Python bindings for the Python source term class.
void pythonBindBoundaryCondition(pybind11::module &m)
Creates Python bindings for the Python BC class.
void bheInflowpythonBindBoundaryCondition(pybind11::module &m)
Creates BHE Inflow Python bindings for the Python BC class.
void mark_used(T p)
PYBIND11_EMBEDDED_MODULE(OpenGeoSys, m)