Skip to content
Snippets Groups Projects
Forked from ogs / ogs
12949 commits behind the upstream repository.
  • Shuang Chen's avatar
    d6dd5146
    Add BHEInflowPythonBoundaryCondition · d6dd5146
    Shuang Chen authored
    Add BHEinflowPythonBoundaryCondition into following places
    1) PythonBoundaryCondition
    2) Pybind11_Embedded_Module
    3) The CMakeList
    4) Switch on the compiling flag OGS_USE_PYTHON when pipe network is present
    Add OGS_USE_PYTHON option in HeatTransportBHE process cmakelist
    d6dd5146
    History
    Add BHEInflowPythonBoundaryCondition
    Shuang Chen authored
    Add BHEinflowPythonBoundaryCondition into following places
    1) PythonBoundaryCondition
    2) Pybind11_Embedded_Module
    3) The CMakeList
    4) Switch on the compiling flag OGS_USE_PYTHON when pipe network is present
    Add OGS_USE_PYTHON option in HeatTransportBHE process cmakelist
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
ogs_embedded_python.cpp 1.62 KiB
/**
 * \copyright
 * Copyright (c) 2012-2020, OpenGeoSys Community (http://www.opengeosys.org)
 *            Distributed under a Modified BSD License.
 *              See accompanying file LICENSE.txt or
 *              http://www.opengeosys.org/project/license
 *
 */

#include "ogs_embedded_python.h"

#include <pybind11/embed.h>

#include <logog/include/logog.hpp>

#include "ProcessLib/BoundaryCondition/Python/BHEInflowPythonBoundaryConditionModule.h"
#include "ProcessLib/BoundaryCondition/Python/PythonBoundaryConditionModule.h"
#include "ProcessLib/SourceTerms/Python/PythonSourceTermModule.h"

PYBIND11_EMBEDDED_MODULE(OpenGeoSys, m)
{
    DBUG("Binding Python module OpenGeoSys.");

    ProcessLib::pythonBindBoundaryCondition(m);
    ProcessLib::bheInflowpythonBindBoundaryCondition(m);
    ProcessLib::SourceTerms::Python::pythonBindSourceTerm(m);
}

#ifndef OGS_BUILD_SHARED_LIBS

// Hackish trick that hopefully ensures that the linker won't strip the symbol
// pointed to by p from the library being built.
template <typename T>
void mark_used(T p)
{
    volatile T vp = p;
    vp = vp;
}

#endif  // OGS_BUILD_SHARED_LIBS

namespace ApplicationsLib
{
pybind11::scoped_interpreter setupEmbeddedPython()
{
#ifndef OGS_BUILD_SHARED_LIBS
    // pybind11_init_impl_OpenGeoSys is the function initializing the embedded
    // OpenGeoSys Python module. The name is generated by pybind11. If it is not
    // obvious that this symbol is actually used, the linker might remove it
    // under certain circumstances.
    mark_used(&pybind11_init_impl_OpenGeoSys);
#endif

    return pybind11::scoped_interpreter{};
}

}  // namespace ApplicationsLib