Make the Builtin class available from Python
This commit is contained in:
@@ -20,6 +20,7 @@ void python::common::export_all(py::module& module) {
|
||||
export_Log(module);
|
||||
export_IO(module);
|
||||
export_SummaryState(module);
|
||||
export_ParserKeywords(module);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -31,6 +31,10 @@ void export_Well(py::module& module);
|
||||
void export_Log(py::module& module);
|
||||
void export_IO(py::module& module);
|
||||
void export_SummaryState(py::module& module);
|
||||
|
||||
// The export_ParserKeywords() function is implemented in the source file
|
||||
// ${BUILD}/builtin_pybind11.cpp which is generated by the build system.
|
||||
void export_ParserKeywords(py::module& module);
|
||||
}
|
||||
|
||||
#endif //SUNBEAM_HPP
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <opm/json/JsonObject.hpp>
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserKeywords/Builtin.hpp>
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
#include <pybind11/stl.h>
|
||||
#include <opm/parser/eclipse/Parser/ErrorGuard.hpp>
|
||||
@@ -51,11 +52,12 @@ void python::common::export_Parser(py::module& module) {
|
||||
|
||||
|
||||
py::class_<Parser>(module, "Parser")
|
||||
.def(py::init<>())
|
||||
.def(py::init<bool>(), py::arg("add_default") = true)
|
||||
.def("parse", py::overload_cast<const std::string&>(&Parser::parseFile, py::const_))
|
||||
.def("parse" , py::overload_cast<const std::string&, const ParseContext&>(&Parser::parseFile, py::const_))
|
||||
.def("parse_string", py::overload_cast<const std::string&>(&Parser::parseString, py::const_))
|
||||
.def("parse_string", py::overload_cast<const std::string&, const ParseContext&>(&Parser::parseString, py::const_))
|
||||
.def("add_keyword", py::overload_cast<ParserKeyword>(&Parser::addParserKeyword))
|
||||
.def("add_keyword", add_keyword)
|
||||
.def("__getitem__", &Parser::getKeyword, ref_internal);
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
from __future__ import absolute_import
|
||||
from .libopmcommon_python import action
|
||||
|
||||
from .libopmcommon_python import Parser, ParseContext
|
||||
from .libopmcommon_python import Parser, ParseContext, Builtin
|
||||
from .libopmcommon_python import DeckKeyword
|
||||
from .libopmcommon_python import DeckItem
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from opm._common import action
|
||||
from opm._common import Parser
|
||||
from opm._common import ParseContext
|
||||
from opm._common import Builtin
|
||||
|
||||
@@ -4,6 +4,7 @@ import sys
|
||||
|
||||
import numpy as np
|
||||
|
||||
from opm.io.parser import Builtin
|
||||
from opm.io.parser import Parser
|
||||
from opm.io.parser import ParseContext
|
||||
from opm.io.deck import DeckKeyword
|
||||
@@ -44,6 +45,33 @@ FIPNUM
|
||||
self.spe3fn = test_path('spe3/SPE3CASE1.DATA')
|
||||
self.norne_fname = test_path('../examples/data/norne/NORNE_ATW2013.DATA')
|
||||
|
||||
def test_dynamic_parser(self):
|
||||
parser = Parser(add_default = False)
|
||||
builtin = Builtin()
|
||||
parser.add_keyword( builtin.START )
|
||||
parser.add_keyword( builtin.RUNSPEC )
|
||||
parser.add_keyword( builtin.FIELD )
|
||||
parser.add_keyword( builtin.DIMENS )
|
||||
parser.add_keyword( builtin.GRID )
|
||||
parser.add_keyword( builtin.DX )
|
||||
parser.add_keyword( builtin.DY )
|
||||
parser.add_keyword( builtin.DZ )
|
||||
parser.add_keyword( builtin.TOPS )
|
||||
parser.add_keyword( builtin.REGIONS )
|
||||
parser.add_keyword( builtin.OPERNUM )
|
||||
parser.add_keyword( builtin.FIPNUM )
|
||||
|
||||
deck = parser.parse_string(self.REGIONDATA)
|
||||
|
||||
def test_dynamic_parser2(self):
|
||||
parser = Parser(add_default = False)
|
||||
builtin = Builtin()
|
||||
kw_list = ["START", "RUNSPEC", "FIELD", "REGIONS", "DIMENS", "GRID", "DX", "DY", "DZ", "TOPS", "OPERNUM", "FIPNUM"]
|
||||
for kw in kw_list:
|
||||
parser.add_keyword( builtin[kw] )
|
||||
|
||||
deck = parser.parse_string(self.REGIONDATA)
|
||||
|
||||
def test_create(self):
|
||||
parser = Parser()
|
||||
deck = parser.parse(self.spe3fn)
|
||||
|
||||
Reference in New Issue
Block a user