Started exposing deck

This commit is contained in:
Jens Gåsemyr Magnus
2017-09-05 16:29:27 +02:00
parent 11fe32df4f
commit e1d860506a
6 changed files with 30 additions and 7 deletions

View File

@@ -54,5 +54,5 @@ def parse_deck(deck, **kwargs):
if 'actions' in kwargs:
args.append(_parse_context(kwargs['actions']))
return lib.parse_deck(*args)

View File

@@ -1,3 +1,5 @@
#include <sstream>
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
#include "deck.hpp"
@@ -12,9 +14,6 @@ using copy = py::return_value_policy< py::copy_const_reference >;
namespace deck {
/*
* Deck methods inherited from DeckView
*/
size_t size( const Deck& deck ) {
return deck.size();
}
@@ -40,6 +39,11 @@ namespace deck {
const DeckView::const_iterator begin( const Deck& deck ) { return deck.begin(); }
const DeckView::const_iterator end( const Deck& deck ) { return deck.end(); }
std::string write( const Deck& deck ) {
std::stringstream stream;
stream << deck;
return stream.str();
}
void export_Deck() {
@@ -50,6 +54,7 @@ namespace deck {
.def( "__getitem__", &getKeyword0, ref() )
.def( "__getitem__", &getKeyword1, ref() )
.def( "__getitem__", &getKeyword2, ref() )
.def( "__str__", &write )
.def( "count", &count )
;

View File

@@ -19,6 +19,7 @@ namespace deck {
const DeckKeyword& getKeyword2( const Deck& deck, size_t index );
const DeckView::const_iterator begin( const Deck& deck );
const DeckView::const_iterator end( const Deck& deck );
std::string write( const Deck& deck );
void export_Deck();

View File

@@ -1,5 +1,8 @@
#include <iostream>
#include <sstream>
#include <boost/python.hpp>
#include <opm/parser/eclipse/Deck/DeckItem.hpp>
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
#include <opm/parser/eclipse/Deck/DeckRecord.hpp>
@@ -14,10 +17,18 @@ using copy = py::return_value_policy< py::copy_const_reference >;
namespace deck_keyword {
std::string write( const DeckKeyword& kw ) {
std::stringstream stream;
stream << kw;
return stream.str();
}
void export_DeckKeyword() {
py::class_< DeckKeyword >( "DeckKeyword", py::no_init )
.def( "__repr__", &DeckKeyword::name, copy() )
.def( "__str__", &write )
.def( "__len__", &DeckKeyword::size )
;
}

View File

@@ -1,6 +1,14 @@
#include <string>
namespace Opm {
class DeckKeyword;
}
namespace deck_keyword {
using namespace Opm;
std::string write( const DeckKeyword& kw );
void export_DeckKeyword();

View File

@@ -21,9 +21,7 @@ namespace parser {
const Json::JsonObject jkw(kw);
p.addParserKeyword(jkw);
}
if (isFile)
return p.parseFile(deckStr, pc);
return p.parseString(deckStr, pc);
return isFile ? p.parseFile(deckStr, pc) : p.parseString(deckStr, pc);
}
EclipseState (*parse)( const std::string&, const ParseContext& ) = &Parser::parse;