2017-08-31 13:49:09 +02:00
|
|
|
#include <opm/json/JsonObject.hpp>
|
|
|
|
|
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
|
|
|
|
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
2018-01-30 07:46:03 +01:00
|
|
|
#include <pybind11/stl.h>
|
|
|
|
|
|
2019-08-15 11:19:18 +02:00
|
|
|
#include "common_state.hpp"
|
|
|
|
|
#include "common.hpp"
|
2017-08-31 13:49:09 +02:00
|
|
|
|
|
|
|
|
|
2017-09-07 14:38:31 +02:00
|
|
|
namespace {
|
2017-08-31 13:49:09 +02:00
|
|
|
|
2018-02-14 17:27:18 +01:00
|
|
|
Deck create_deck( const std::string& deckStr,
|
|
|
|
|
const ParseContext& pc,
|
|
|
|
|
const Parser& parser) {
|
2019-01-17 15:04:57 +01:00
|
|
|
|
|
|
|
|
Opm::ErrorGuard guard;
|
|
|
|
|
auto p = parser.parseFile( deckStr, pc, guard );
|
|
|
|
|
guard.clear();
|
|
|
|
|
return p;
|
2018-02-14 17:27:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Deck create_deck_string( const std::string& deckStr,
|
|
|
|
|
const ParseContext& pc,
|
|
|
|
|
const Parser& parser) {
|
2019-01-17 15:04:57 +01:00
|
|
|
Opm::ErrorGuard guard;
|
|
|
|
|
auto p = parser.parseString( deckStr, pc, guard );
|
|
|
|
|
guard.clear();
|
|
|
|
|
return p;
|
2017-08-31 13:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
2018-02-14 17:27:18 +01:00
|
|
|
|
|
|
|
|
SunbeamState * parse_file(const std::string& filename, const ParseContext& context, const Parser& parser) {
|
|
|
|
|
return new SunbeamState(true, filename, context, parser);
|
2018-02-08 10:54:12 +01:00
|
|
|
}
|
|
|
|
|
|
2018-02-14 17:27:18 +01:00
|
|
|
SunbeamState * parse_string(const std::string& filename, const ParseContext& context, const Parser& parser) {
|
|
|
|
|
return new SunbeamState(false, filename, context, parser);
|
2018-02-08 10:54:12 +01:00
|
|
|
}
|
2017-08-31 13:49:09 +02:00
|
|
|
|
|
|
|
|
void (ParseContext::*ctx_update)(const std::string&, InputError::Action) = &ParseContext::update;
|
2018-02-14 17:27:18 +01:00
|
|
|
|
|
|
|
|
void add_keyword(Parser* parser, const std::string& json_string) {
|
|
|
|
|
const Json::JsonObject keyword(json_string);
|
|
|
|
|
parser->addParserKeyword(keyword);
|
|
|
|
|
}
|
2017-09-07 14:38:31 +02:00
|
|
|
}
|
2017-08-31 13:49:09 +02:00
|
|
|
|
2019-08-15 11:35:28 +02:00
|
|
|
void opmcommon_python::export_Parser(py::module& module) {
|
2017-08-31 13:49:09 +02:00
|
|
|
|
2018-02-14 17:27:18 +01:00
|
|
|
module.def( "parse", parse_file );
|
|
|
|
|
module.def( "parse_string", parse_string);
|
|
|
|
|
module.def( "create_deck", &create_deck );
|
|
|
|
|
module.def( "create_deck_string", &create_deck_string);
|
|
|
|
|
|
|
|
|
|
py::class_<SunbeamState>(module, "SunbeamState")
|
|
|
|
|
.def("_schedule", &SunbeamState::getSchedule, ref_internal)
|
|
|
|
|
.def("_state", &SunbeamState::getEclipseState, ref_internal)
|
|
|
|
|
.def("_deck", &SunbeamState::getDeck, ref_internal)
|
|
|
|
|
.def("_summary_config", &SunbeamState::getSummmaryConfig, ref_internal);
|
2017-08-31 13:49:09 +02:00
|
|
|
|
2018-01-30 07:46:03 +01:00
|
|
|
py::class_< ParseContext >(module, "ParseContext" )
|
|
|
|
|
.def(py::init<>())
|
2018-02-14 17:27:18 +01:00
|
|
|
.def(py::init<const std::vector<std::pair<std::string, InputError::Action>>>())
|
2018-01-30 07:46:03 +01:00
|
|
|
.def( "update", ctx_update );
|
2017-08-31 13:49:09 +02:00
|
|
|
|
2018-01-30 07:46:03 +01:00
|
|
|
py::enum_< InputError::Action >( module, "action" )
|
|
|
|
|
.value( "throw", InputError::Action::THROW_EXCEPTION )
|
|
|
|
|
.value( "warn", InputError::Action::WARN )
|
|
|
|
|
.value( "ignore", InputError::Action::IGNORE );
|
2018-02-14 17:27:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
py::class_<Parser>(module, "Parser")
|
|
|
|
|
.def(py::init<>())
|
|
|
|
|
.def("add_keyword", add_keyword);
|
2017-08-31 13:49:09 +02:00
|
|
|
}
|