Skip to content

Commit

Permalink
Wrap the export statements of opmcommon_python and opm_embedded in if…
Browse files Browse the repository at this point in the history
…def statements

Like this, the resulting python libraries really are different
The respective compiler flag is set in the CMakeLists.txt
  • Loading branch information
lisajulia committed Apr 18, 2024
1 parent 2f6f260 commit 6f22c00
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,15 @@ if (OPM_ENABLE_PYTHON)
pybind11_add_module(opmcommon_python
${PYTHON_CXX_SOURCE_FILES}
${PROJECT_BINARY_DIR}/python/cxx/builtin_pybind11.cpp)
target_compile_definitions(opmcommon_python PRIVATE OPMCOMMON_PYTHON=1)

target_link_libraries(opmcommon_python PRIVATE
opmcommon)
if(OPM_ENABLE_EMBEDDED_PYTHON)
pybind11_add_module(opm_embedded
${PYTHON_CXX_SOURCE_FILES}
${PROJECT_BINARY_DIR}/python/cxx/builtin_pybind11.cpp)
target_compile_definitions(opm_embedded PRIVATE OPM_EMBEDDED=1)
target_link_libraries(opm_embedded PRIVATE
opmcommon)
endif()
Expand Down
3 changes: 2 additions & 1 deletion opm/input/eclipse/Python/PythonInterp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
namespace py = pybind11;
namespace Opm {


#ifdef OPM_EMBEDDED
/*
OPM_EMBEDDED_MODULE create a Python of all the Python/C++ classes which are
generated in the python::common::export_all_opm_embedded() function in the wrapping code.
Expand All @@ -44,6 +44,7 @@ namespace Opm {
OPM_EMBEDDED_MODULE(opm_embedded, module) {
python::common::export_all_opm_embedded(module);
}
#endif


bool PythonInterp::exec(const std::string& python_code, py::module& context) {
Expand Down
3 changes: 3 additions & 0 deletions python/cxx/eclipse_config.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef OPMCOMMON_PYTHON

#include <vector>
#include <opm/input/eclipse/Deck/Deck.hpp>
#include <opm/input/eclipse/EclipseState/EclipseConfig.hpp>
Expand Down Expand Up @@ -39,3 +41,4 @@ void python::common::export_EclipseConfig(py::module& module)
py::class_< IOConfig >( module, "IOConfig");
}

#endif
3 changes: 3 additions & 0 deletions python/cxx/eclipse_io.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef OPMCOMMON_PYTHON

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/numpy.h>
Expand Down Expand Up @@ -483,3 +485,4 @@ void python::common::export_IO(py::module& m) {
.def("__write_doub_array", (void (EclOutputBind::*)(const std::string&,
const std::vector<double>&)) &EclOutputBind::writeArray);
}
#endif
4 changes: 4 additions & 0 deletions python/cxx/eclipse_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ namespace {
}
}

#ifdef OPM_EMBEDDED
/**
* @brief Function to export the EclipseState class and some methods to the opm_embedded python module.
*
Expand All @@ -128,7 +129,9 @@ void python::common::export_EclipseState_embedded(py::module& module) {

add_shared_EclipseState_methods(c);
}
#endif

#ifdef OPMCOMMON_PYTHON
/**
* @brief Function to export the EclipseState class and some methods to the opmcommon_python module, for the Python bindings.
*
Expand All @@ -145,3 +148,4 @@ void python::common::export_EclipseState(py::module& module) {

add_shared_EclipseState_methods(c);
}
#endif
3 changes: 3 additions & 0 deletions python/cxx/emodel_util.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef OPMCOMMON_PYTHON

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/numpy.h>
Expand Down Expand Up @@ -104,3 +106,4 @@ void python::common::export_EModel(py::module& m) {
.def("__add_filter", &add_float_filter_2values);

}
#endif
6 changes: 5 additions & 1 deletion python/cxx/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <opm/input/eclipse/Schedule/Schedule.hpp>
#include <opm/input/eclipse/Schedule/SummaryState.hpp>

#ifdef OPMCOMMON_PYTHON
void python::common::export_all(py::module& module) {
export_ParseContext(module);
export_Parser(module);
Expand Down Expand Up @@ -32,7 +33,9 @@ void python::common::export_all(py::module& module) {
PYBIND11_MODULE(opmcommon_python, module) {
python::common::export_all(module);
}
#endif

#ifdef OPM_EMBEDDED
/**
* @brief Function to export several classes to the opm_embedded module that is created as a shared library.
*
Expand Down Expand Up @@ -85,4 +88,5 @@ void python::common::export_all_opm_embedded(py::module& module) {
*/
PYBIND11_MODULE(opm_embedded, module) {
python::common::export_all_opm_embedded_for_sl(module);
}
}
#endif
21 changes: 14 additions & 7 deletions python/cxx/export.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,39 @@ const py::return_value_policy python_owner = py::return_value_policy::take_owner
const py::return_value_policy move = py::return_value_policy::move;

namespace python::common {
#ifdef OPMCOMMON_PYTHON
void export_all(py::module& module);
void export_all_opm_embedded(py::module& module);
void export_all_opm_embedded_for_sl(py::module& module);
void export_EclipseConfig(py::module& module);
void export_IO(py::module& module);
void export_EModel(py::module& module);
#endif

void export_UnitSystem(py::module& module);
void export_Connection(py::module& module);
void export_Deck(py::module& module);
void export_DeckKeyword(py::module& module);
void export_FieldProperties(py::module& module);
void export_EclipseConfig(py::module& module);
void export_EclipseGrid(py::module& module);
void export_EclipseState(py::module& module);
void export_EclipseState_embedded(py::module& module);
void export_Group(py::module& module);
void export_ParseContext(py::module& module);
void export_Parser(py::module& module);
void export_SimulationConfig(py::module& module);
void export_Schedule(py::module& module);
void export_Schedule_embedded(py::module& module);
void export_ScheduleState(py::module& module);
void export_TableManager(py::module& module);
void export_Well(py::module& module);
void export_Log(py::module& module);
void export_IO(py::module& module);
void export_EModel(py::module& module);
void export_SummaryState(py::module& module);

#ifdef OPM_EMBEDDED
void export_all_opm_embedded(py::module& module);
void export_all_opm_embedded_for_sl(py::module& module);

void export_EclipseState_embedded(py::module& module);
void export_Schedule_embedded(py::module& module);
void export_SummaryState_embedded(py::module& module);
#endif

// The export_ParserKeywords() function is implemented in the source file
// ${BUILD}/builtin_pybind11.cpp which is generated by the build system.
Expand Down
7 changes: 7 additions & 0 deletions python/cxx/schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,14 @@ namespace {
}
return keywords;
}

#ifdef OPMCOMMON_PYTHON
void insert_keywords(Schedule& sch, const std::string& deck_string, std::size_t report_step, const UnitSystem& unit_system)
{
auto kws = parseKeywords(deck_string, unit_system);
sch.applyKeywords(kws, report_step);
}
#endif

void insert_keywords(Schedule& sch, const std::string& deck_string, std::size_t report_step)
{
Expand Down Expand Up @@ -215,6 +218,7 @@ namespace {
}
}

#ifdef OPM_EMBEDDED
/**
* @brief Function to export the Schedule class and some methods to the opm_embedded python module.
*
Expand All @@ -231,7 +235,9 @@ void python::common::export_Schedule_embedded(py::module& module) {

add_shared_Schedule_methods(c);
}
#endif

#ifdef OPMCOMMON_PYTHON
/**
* @brief Function to export the Schedule class and some methods to the opmcommon_python module, for the Python bindings.
*
Expand All @@ -256,3 +262,4 @@ void python::common::export_Schedule(py::module& module) {

add_shared_Schedule_methods(c);
}
#endif
4 changes: 4 additions & 0 deletions python/cxx/summary_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ void add_shared_SummaryState_methods(py::class_< SummaryState, std::shared_ptr<S
}

}
#ifdef OPM_EMBEDDED
/**
* @brief Function to export the SummaryState class and some methods to the opm_embedded python module.
*
Expand All @@ -78,7 +79,9 @@ void python::common::export_SummaryState_embedded(py::module& module) {

add_shared_SummaryState_methods(c);
}
#endif

#ifdef OPMCOMMON_PYTHON
/**
* @brief Function to export the SummaryState class and some methods to the opmcommon_python module, for the Python bindings.
*
Expand All @@ -94,3 +97,4 @@ void python::common::export_SummaryState(py::module& module) {

add_shared_SummaryState_methods(c);
}
#endif

0 comments on commit 6f22c00

Please sign in to comment.