Parser: handles PYINPUT. Python code in eclipse .Data files now possible!!!

test EmbeddedPython: now with actual python code.

parser.cpp: parsing python code.

introduced RawConst::pyinput.

EmbeddedPython: tests with data keyword.
This commit is contained in:
Steinar Foss
2019-12-05 09:19:43 +01:00
parent 277ec850a7
commit f3701c3f93
3 changed files with 59 additions and 10 deletions
+44 -4
View File
@@ -29,10 +29,12 @@
#include <opm/parser/eclipse/Parser/Parser.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
using namespace Opm;
#ifndef EMBEDDED_PYTHON
BOOST_AUTO_TEST_CASE(INSTANTIATE) {
Opm::Python python;
Python python;
BOOST_CHECK(!python);
BOOST_CHECK_THROW(python.exec("print('Hello world')"), std::logic_error);
}
@@ -40,12 +42,12 @@ BOOST_AUTO_TEST_CASE(INSTANTIATE) {
#else
BOOST_AUTO_TEST_CASE(INSTANTIATE) {
Opm::Python python;
Python python;
BOOST_CHECK(python);
BOOST_CHECK_NO_THROW(python.exec("print('Hello world')"));
Opm::Parser parser;
Opm::Deck deck;
Parser parser;
Deck deck;
std::string python_code = R"(
print('Parser: {}'.format(context.parser))
print('Deck: {}'.format(context.deck))
@@ -56,5 +58,43 @@ context.deck.add(kw)
BOOST_CHECK( deck.hasKeyword("FIELD") );
}
BOOST_AUTO_TEST_CASE(PYINPUT_BASIC) {
Parser parser;
std::string input = R"(
START -- 0
31 AUG 1993 /
RUNSPEC
PYINPUT
kw = context.DeckKeyword( context.parser['FIELD'] )
context.deck.add(kw)
<<<
DIMENS
2 2 1 /
PYINPUT
import numpy as np
dx = np.array([0.25, 0.25, 0.25, 0.25])
active_unit_system = context.deck.active_unit_system()
default_unit_system = context.deck.default_unit_system()
kw = context.DeckKeyword( context.parser['DX'], dx, active_unit_system, default_unit_system )
context.deck.add(kw)
<<<
DY
4*0.25 /
)";
Deck deck = parser.parseString(input);
BOOST_CHECK( deck.hasKeyword("START") );
BOOST_CHECK( deck.hasKeyword("FIELD") );
BOOST_CHECK( deck.hasKeyword("DIMENS") );
BOOST_CHECK( deck.hasKeyword("DX") );
auto DX = deck.getKeyword("DX");
std::vector<double> dx_data = DX.getSIDoubleData();
BOOST_CHECK_EQUAL( dx_data.size(), 4 );
BOOST_CHECK_EQUAL( dx_data[2], 0.25 * 0.3048 );
BOOST_CHECK( deck.hasKeyword("DY") );
}
#endif