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>
|
|
|
|
|
|
2017-09-07 14:38:31 +02:00
|
|
|
#include "sunbeam.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
|
|
|
|
|
|
|
|
Deck parseDeck( const std::string& deckStr,
|
|
|
|
|
const boost::python::list& keywords,
|
|
|
|
|
bool isFile,
|
|
|
|
|
const ParseContext& pc ) {
|
|
|
|
|
Parser p;
|
|
|
|
|
size_t len = py::extract<size_t>(keywords.attr("__len__")());
|
|
|
|
|
for (size_t i = 0; i < len; i++) {
|
|
|
|
|
const std::string kw = py::extract<const std::string>(py::str(keywords[i]));
|
|
|
|
|
const Json::JsonObject jkw(kw);
|
|
|
|
|
p.addParserKeyword(jkw);
|
|
|
|
|
}
|
2017-09-05 16:29:27 +02:00
|
|
|
return isFile ? p.parseFile(deckStr, pc) : p.parseString(deckStr, pc);
|
2017-08-31 13:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EclipseState (*parse)( const std::string&, const ParseContext& ) = &Parser::parse;
|
|
|
|
|
EclipseState (*parseData) (const std::string &data, const ParseContext& context) = &Parser::parseData;
|
|
|
|
|
|
|
|
|
|
void (ParseContext::*ctx_update)(const std::string&, InputError::Action) = &ParseContext::update;
|
|
|
|
|
|
2017-09-07 14:38:31 +02:00
|
|
|
}
|
2017-08-31 13:49:09 +02:00
|
|
|
|
2017-09-07 14:38:31 +02:00
|
|
|
void sunbeam::export_Parser() {
|
2017-08-31 13:49:09 +02:00
|
|
|
|
2017-09-07 14:38:31 +02:00
|
|
|
py::def( "parse", parse );
|
|
|
|
|
py::def( "parse_data", parseData );
|
|
|
|
|
py::def( "parse_deck", &parseDeck );
|
2017-08-31 13:49:09 +02:00
|
|
|
|
2017-09-07 14:38:31 +02:00
|
|
|
py::class_< ParseContext >( "ParseContext" )
|
|
|
|
|
.def( "update", ctx_update )
|
|
|
|
|
;
|
2017-08-31 13:49:09 +02:00
|
|
|
|
2017-09-07 14:38:31 +02:00
|
|
|
py::enum_< InputError::Action >( "action" )
|
|
|
|
|
.value( "throw", InputError::Action::THROW_EXCEPTION )
|
|
|
|
|
.value( "warn", InputError::Action::WARN )
|
|
|
|
|
.value( "ignore", InputError::Action::IGNORE )
|
|
|
|
|
;
|
2017-08-31 13:49:09 +02:00
|
|
|
|
|
|
|
|
}
|