Skip to content

Commit

Permalink
Merge pull request #4414 from lisajulia/documentation/python
Browse files Browse the repository at this point in the history
Documentation/python
  • Loading branch information
blattms authored Jan 14, 2025
2 parents 4410b29 + fb0befb commit a4bde19
Show file tree
Hide file tree
Showing 4 changed files with 253 additions and 61 deletions.
24 changes: 13 additions & 11 deletions python/cxx/eclipse_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
#include <opm/input/eclipse/EclipseState/EclipseState.hpp>
#include <opm/input/eclipse/Schedule/Schedule.hpp>


#include "export.hpp"

#include <python/cxx/OpmCommonPythonDoc.hpp>

void python::common::export_EclipseConfig(py::module& module)
{
py::class_< EclipseConfig >( module, "EclipseConfig" )
.def( "init", py::overload_cast<>(&EclipseConfig::init, py::const_));
using namespace Opm::Common::DocStrings;

py::class_< EclipseConfig >( module, "EclipseConfig" , EclipseConfig_docstring)
.def( "init", py::overload_cast<>(&EclipseConfig::init, py::const_), EclipseConfig_init_docstring);

// Note: In the below class we std::shared_ptr as the holder type, see:
//
Expand All @@ -24,18 +26,18 @@ void python::common::export_EclipseConfig(py::module& module)
// this makes it possible to share the returned object with e.g. and
// opm.simulators.BlackOilSimulator Python object
//
py::class_< SummaryConfig, std::shared_ptr<SummaryConfig> >( module, "SummaryConfig")
py::class_< SummaryConfig, std::shared_ptr<SummaryConfig> >( module, "SummaryConfig", SummaryConfig_docstring )
.def(py::init([](const Deck& deck, const EclipseState& state, const Schedule& schedule) {
return SummaryConfig( deck, schedule, state.fieldProps(), state.aquifer() );
} ) )
}), SummaryConfig_init_docstring )
.def( "__contains__", &SummaryConfig::hasKeyword, SummaryConfig_contains_docstring );

.def( "__contains__", &SummaryConfig::hasKeyword );
py::class_< InitConfig >( module, "InitConfig", InitConfig_docstring )
.def( "hasEquil", &InitConfig::hasEquil, InitConfig_hasEquil_docstring )
.def( "restartRequested", &InitConfig::restartRequested, InitConfig_restartRequested_docstring )
.def( "getRestartStep", &InitConfig::getRestartStep, InitConfig_getRestartStep_docstring );

py::class_< InitConfig >( module, "InitConfig")
.def( "hasEquil", &InitConfig::hasEquil )
.def( "restartRequested", &InitConfig::restartRequested )
.def( "getRestartStep" , &InitConfig::getRestartStep );
py::class_< IOConfig >( module, "IOConfig", IOConfig_docstring );

py::class_< IOConfig >( module, "IOConfig");
}

39 changes: 21 additions & 18 deletions python/cxx/eclipse_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "converters.hpp"
#include "export.hpp"

#include <python/cxx/OpmCommonPythonDoc.hpp>

namespace {
py::tuple getXYZ( const EclipseGrid& grid ) {
Expand Down Expand Up @@ -112,23 +113,25 @@ namespace {

void python::common::export_EclipseGrid(py::module& module) {

py::class_< EclipseGrid >( module, "EclipseGrid")
.def( "_getXYZ", &getXYZ )
.def_property_readonly("nx", &EclipseGrid::getNX)
.def_property_readonly("ny", &EclipseGrid::getNY)
.def_property_readonly("nz", &EclipseGrid::getNZ)
.def_property_readonly( "nactive", &getNumActive )
.def_property_readonly( "cartesianSize", &getCartesianSize )
.def( "globalIndex", &getGlobalIndex )
.def( "getIJK", &getIJK )
.def( "getCellVolume", &cellVolume1G)
.def( "getCellVolume", &cellVolume3)
.def( "getCellVolume", &cellVolumeAll)
.def( "getCellVolume", &cellVolumeMask)
.def( "getCellDepth", &cellDepth1G)
.def( "getCellDepth", &cellDepth3)
.def( "getCellDepth", &cellDepthAll)
.def( "getCellDepth", &cellDepthMask)
;
using namespace Opm::Common::DocStrings;

py::class_< EclipseGrid >( module, "EclipseGrid", EclipseGrid_docstring )
.def( "_getXYZ", &getXYZ, EclipseGrid_getXYZ_docstring )
.def_property_readonly("nx", &EclipseGrid::getNX, EclipseGrid_nx_docstring )
.def_property_readonly("ny", &EclipseGrid::getNY, EclipseGrid_ny_docstring )
.def_property_readonly("nz", &EclipseGrid::getNZ, EclipseGrid_nz_docstring )
.def_property_readonly( "nactive", &getNumActive, EclipseGrid_nactive_docstring )
.def_property_readonly( "cartesianSize", &getCartesianSize, EclipseGrid_cartesianSize_docstring )
.def("globalIndex", &getGlobalIndex, py::arg("i"), py::arg("j"), py::arg("k"), EclipseGrid_globalIndex_docstring)
.def( "getIJK", &getIJK, py::arg("g"), EclipseGrid_getIJK_docstring )
.def( "getCellVolume", &cellVolume1G, py::arg("g"), EclipseGrid_getCellVolume1G_docstring )
.def( "getCellVolume", &cellVolume3, py::arg("i"), py::arg("j"), py::arg("k"), EclipseGrid_getCellVolume3_docstring )
.def( "getCellVolume", &cellVolumeAll, EclipseGrid_getCellVolumeAll_docstring )
.def( "getCellVolume", &cellVolumeMask, py::arg("mask"), EclipseGrid_getCellVolumeMask_docstring )
.def( "getCellDepth", &cellDepth1G, py::arg("g"), EclipseGrid_getCellDepth1G_docstring )
.def( "getCellDepth", &cellDepth3, py::arg("i"), py::arg("j"), py::arg("k"), EclipseGrid_getCellDepth3_docstring )
.def( "getCellDepth", &cellDepthAll, EclipseGrid_getCellDepthAll_docstring )
.def( "getCellDepth", &cellDepthMask, py::arg("mask"), EclipseGrid_getCellDepthMask_docstring )
;

}
38 changes: 21 additions & 17 deletions python/cxx/eclipse_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "export.hpp"
#include "converters.hpp"

#include <python/cxx/OpmCommonPythonDoc.hpp>

namespace py = pybind11;


Expand Down Expand Up @@ -437,25 +439,27 @@ npArray get_rft_vector_Index(Opm::EclIO::ERft * file_ptr,const std::string& name

void python::common::export_IO(py::module& m) {

py::enum_<Opm::EclIO::eclArrType>(m, "eclArrType", py::arithmetic())
.value("INTE", Opm::EclIO::INTE)
.value("REAL", Opm::EclIO::REAL)
.value("DOUB", Opm::EclIO::DOUB)
.value("CHAR", Opm::EclIO::CHAR)
.value("C0nn", Opm::EclIO::C0NN)
.value("LOGI", Opm::EclIO::LOGI)
.value("MESS", Opm::EclIO::MESS)
using namespace Opm::Common::DocStrings;

py::enum_<Opm::EclIO::eclArrType>(m, "eclArrType", py::arithmetic(), eclArrType_docstring)
.value("INTE", Opm::EclIO::INTE, eclArrType_INTE_docstring)
.value("REAL", Opm::EclIO::REAL, eclArrType_REAL_docstring)
.value("DOUB", Opm::EclIO::DOUB, eclArrType_DOUB_docstring)
.value("CHAR", Opm::EclIO::CHAR, eclArrType_CHAR_docstring)
.value("C0nn", Opm::EclIO::C0NN, eclArrType_C0nn_docstring)
.value("LOGI", Opm::EclIO::LOGI, eclArrType_LOGI_docstring)
.value("MESS", Opm::EclIO::MESS, eclArrType_MESS_docstring)
.export_values();

py::class_<Opm::EclIO::EclFile>(m, "EclFile")
.def(py::init<const std::string &, bool>(), py::arg("filename"), py::arg("preload") = false)
.def_property_readonly("arrays", &Opm::EclIO::EclFile::getList)
.def("__contains__", &Opm::EclIO::EclFile::hasKey)
.def("__len__", &Opm::EclIO::EclFile::size)
.def("count", &Opm::EclIO::EclFile::count)
.def("__get_data", &get_vector_index)
.def("__get_data", &get_vector_name)
.def("__get_data", &get_vector_occurrence);
py::class_<Opm::EclIO::EclFile>(m, "EclFile", EclFile_docstring)
.def(py::init<const std::string &, bool>(), py::arg("filename"), py::arg("preload") = false, EclFile_init_docstring)
.def_property_readonly("arrays", &Opm::EclIO::EclFile::getList, EclFile_arrays_docstring)
.def("__contains__", &Opm::EclIO::EclFile::hasKey, py::arg("name"), EclFile_contains_docstring)
.def("__len__", &Opm::EclIO::EclFile::size, EclFile_len_docstring)
.def("count", &Opm::EclIO::EclFile::count, py::arg("name"), EclFile_count_docstring)
.def("__get_data", &get_vector_index, py::arg("index"), EclFile_get_data_index_docstring)
.def("__get_data", &get_vector_name, py::arg("name"), EclFile_get_data_name_docstring)
.def("__get_data", &get_vector_occurrence, py::arg("name"), py::arg("occurrence"), EclFile_get_data_occurrence_docstring);

py::class_<Opm::EclIO::ERst>(m, "ERst")
.def(py::init<const std::string &>())
Expand Down
Loading

0 comments on commit a4bde19

Please sign in to comment.