Remove base class DeckViewInternal and create new class DeckView
This commit is contained in:
@@ -29,10 +29,12 @@
|
||||
#include <opm/parser/eclipse/Deck/DeckTree.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckOutput.hpp>
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckView.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ErrorGuard.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserKeywords/D.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
||||
#include <opm/common/OpmLog/KeywordLocation.hpp>
|
||||
@@ -44,7 +46,7 @@ using namespace Opm;
|
||||
BOOST_AUTO_TEST_CASE(hasKeyword_empty_returnFalse) {
|
||||
Deck deck;
|
||||
BOOST_CHECK_EQUAL(false, deck.hasKeyword("Bjarne"));
|
||||
BOOST_CHECK_THROW( deck.getKeyword("Bjarne") , std::invalid_argument);
|
||||
BOOST_CHECK_THROW( deck.getKeyword("Bjarne") , std::exception);
|
||||
}
|
||||
|
||||
std::pair<std::vector<Dimension>, std::vector<Dimension>> make_dims() {
|
||||
@@ -64,7 +66,7 @@ BOOST_AUTO_TEST_CASE(getKeyword_singlekeyword_outRange_throws) {
|
||||
Deck deck;
|
||||
Parser parser;
|
||||
deck.addKeyword( DeckKeyword( parser.getKeyword("GRID")));
|
||||
BOOST_CHECK_THROW(deck.getKeyword("GRID" , 10) , std::out_of_range);
|
||||
BOOST_CHECK_THROW(deck.getKeyword("GRID" , 10) , std::exception);
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +110,8 @@ BOOST_AUTO_TEST_CASE(size_twokeyword_return2) {
|
||||
deck.addKeyword(keyword);
|
||||
deck.addKeyword(keyword);
|
||||
BOOST_CHECK_EQUAL(2U , deck.size());
|
||||
BOOST_CHECK_THROW( deck.getKeyword("GRID" , 3) , std::out_of_range);
|
||||
|
||||
BOOST_CHECK_THROW( deck.getKeyword("GRID" , 3) , std::exception);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(getKeywordList_OK) {
|
||||
@@ -126,12 +129,12 @@ BOOST_AUTO_TEST_CASE(getKeywordList_OK) {
|
||||
BOOST_AUTO_TEST_CASE(keywordList_getbyindexoutofbounds_exceptionthrown) {
|
||||
Parser parser;
|
||||
Deck deck;
|
||||
BOOST_CHECK_THROW(deck.getKeyword(0), std::out_of_range);
|
||||
BOOST_CHECK_THROW(deck.getKeyword(0), std::exception);
|
||||
deck.addKeyword( DeckKeyword( parser.getKeyword("GRID")));
|
||||
deck.addKeyword( DeckKeyword( parser.getKeyword("GRID")));
|
||||
deck.addKeyword( DeckKeyword( parser.getKeyword("INIT")));
|
||||
BOOST_CHECK_NO_THROW(deck.getKeyword(2));
|
||||
BOOST_CHECK_THROW(deck.getKeyword(3), std::out_of_range);
|
||||
BOOST_CHECK_THROW(deck.getKeyword(3), std::exception);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(keywordList_getbyindex_correctkeywordreturned) {
|
||||
@@ -159,14 +162,14 @@ BOOST_AUTO_TEST_CASE(DummyDefaultsString) {
|
||||
deckStringItem.push_backDummyDefault<std::string>();
|
||||
BOOST_CHECK_EQUAL(deckStringItem.data_size(), 1U);
|
||||
BOOST_CHECK_EQUAL(true, deckStringItem.defaultApplied(0));
|
||||
BOOST_CHECK_THROW(deckStringItem.get< std::string >(0), std::invalid_argument);
|
||||
BOOST_CHECK_THROW(deckStringItem.get< std::string >(0), std::exception);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(GetStringAtIndex_NoData_ExceptionThrown) {
|
||||
DeckItem deckStringItem( "TEST", std::string() );
|
||||
BOOST_CHECK_THROW(deckStringItem.get< std::string >(0), std::out_of_range);
|
||||
BOOST_CHECK_THROW(deckStringItem.get< std::string >(0), std::exception);
|
||||
deckStringItem.push_back("SA");
|
||||
BOOST_CHECK_THROW(deckStringItem.get< std::string >(1), std::out_of_range);
|
||||
BOOST_CHECK_THROW(deckStringItem.get< std::string >(1), std::exception);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(size_variouspushes_sizecorrect) {
|
||||
@@ -216,9 +219,9 @@ BOOST_AUTO_TEST_CASE(GetDoubleAtIndex_NoData_ExceptionThrown) {
|
||||
printf("Current type: %s \n",tag_name(deckDoubleItem.getType()).c_str());
|
||||
BOOST_CHECK(deckDoubleItem.getType() == type_tag::fdouble);
|
||||
|
||||
BOOST_CHECK_THROW(deckDoubleItem.get< double >(0), std::out_of_range);
|
||||
BOOST_CHECK_THROW(deckDoubleItem.get< double >(0), std::exception);
|
||||
deckDoubleItem.push_back(1.89);
|
||||
BOOST_CHECK_THROW(deckDoubleItem.get< double >(1), std::out_of_range);
|
||||
BOOST_CHECK_THROW(deckDoubleItem.get< double >(1), std::exception);
|
||||
}
|
||||
|
||||
|
||||
@@ -263,7 +266,7 @@ BOOST_AUTO_TEST_CASE(DummyDefaultsDouble) {
|
||||
deckDoubleItem.push_backDummyDefault<double>();
|
||||
BOOST_CHECK_EQUAL(deckDoubleItem.data_size(), 1U);
|
||||
BOOST_CHECK_EQUAL(true, deckDoubleItem.defaultApplied(0));
|
||||
BOOST_CHECK_THROW(deckDoubleItem.get< double >(0), std::invalid_argument);
|
||||
BOOST_CHECK_THROW(deckDoubleItem.get< double >(0), std::exception);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(PushBackMultipleDouble) {
|
||||
@@ -280,8 +283,8 @@ BOOST_AUTO_TEST_CASE(GetSIWithoutDimensionThrows) {
|
||||
DeckItem item( "HEI", double() , {},{});
|
||||
item.push_back(10.22 , 100 );
|
||||
|
||||
BOOST_CHECK_THROW( item.getSIDouble(0) , std::invalid_argument );
|
||||
BOOST_CHECK_THROW( item.getSIDoubleData() , std::invalid_argument );
|
||||
BOOST_CHECK_THROW( item.getSIDouble(0) , std::exception );
|
||||
BOOST_CHECK_THROW( item.getSIDoubleData() , std::exception );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(GetSISingleDimensionCorrect) {
|
||||
@@ -339,14 +342,14 @@ BOOST_AUTO_TEST_CASE(DummyDefaultsInt) {
|
||||
BOOST_CHECK_EQUAL(true, deckIntItem.defaultApplied(0));
|
||||
BOOST_CHECK_EQUAL( false , deckIntItem.hasValue(0));
|
||||
BOOST_CHECK_EQUAL( false , deckIntItem.hasValue(1));
|
||||
BOOST_CHECK_THROW(deckIntItem.get< int >(0), std::invalid_argument);
|
||||
BOOST_CHECK_THROW(deckIntItem.get< int >(0), std::exception);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(GetIntAtIndex_NoData_ExceptionThrown) {
|
||||
DeckItem deckIntItem( "TEST", int() );
|
||||
deckIntItem.push_back(100);
|
||||
BOOST_CHECK(deckIntItem.get< int >(0) == 100);
|
||||
BOOST_CHECK_THROW(deckIntItem.get< int >(1), std::out_of_range);
|
||||
BOOST_CHECK_THROW(deckIntItem.get< int >(1), std::exception);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(InitializeDefaultApplied) {
|
||||
@@ -375,8 +378,8 @@ BOOST_AUTO_TEST_CASE(DefaultNotAppliedInt) {
|
||||
BOOST_CHECK( deckIntItem.get< int >(0) == 100 );
|
||||
BOOST_CHECK( !deckIntItem.defaultApplied(0) );
|
||||
|
||||
BOOST_CHECK_THROW( deckIntItem.defaultApplied(1), std::out_of_range );
|
||||
BOOST_CHECK_THROW( deckIntItem.get< int >(1), std::out_of_range );
|
||||
BOOST_CHECK_THROW( deckIntItem.defaultApplied(1), std::exception );
|
||||
BOOST_CHECK_THROW( deckIntItem.get< int >(1), std::exception );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(UseDefault) {
|
||||
@@ -387,8 +390,8 @@ BOOST_AUTO_TEST_CASE(UseDefault) {
|
||||
BOOST_CHECK( deckIntItem.defaultApplied(0) );
|
||||
BOOST_CHECK( deckIntItem.get< int >(0) == 100 );
|
||||
|
||||
BOOST_CHECK_THROW( deckIntItem.defaultApplied(1), std::out_of_range );
|
||||
BOOST_CHECK_THROW( deckIntItem.get< int >(1), std::out_of_range );
|
||||
BOOST_CHECK_THROW( deckIntItem.defaultApplied(1), std::exception );
|
||||
BOOST_CHECK_THROW( deckIntItem.get< int >(1), std::exception );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(DefaultAppliedInt) {
|
||||
@@ -439,9 +442,9 @@ BOOST_AUTO_TEST_CASE(addItem_multipleItems_sizecorrect) {
|
||||
BOOST_AUTO_TEST_CASE(addItem_differentItemsSameName_throws) {
|
||||
DeckRecord deckRecord;
|
||||
deckRecord.addItem( DeckItem { "TEST", int() } );
|
||||
BOOST_CHECK_THROW( deckRecord.addItem( DeckItem { "TEST", int() } ), std::invalid_argument );
|
||||
BOOST_CHECK_THROW( deckRecord.addItem( DeckItem { "TEST", int() } ), std::exception );
|
||||
std::vector< DeckItem > items = { DeckItem { "TEST", int() }, DeckItem { "TEST" , int() } };
|
||||
BOOST_CHECK_THROW( DeckRecord( std::move( items ) ), std::invalid_argument );
|
||||
BOOST_CHECK_THROW( DeckRecord( std::move( items ) ), std::exception );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(get_byIndex_returnsItem) {
|
||||
@@ -453,7 +456,7 @@ BOOST_AUTO_TEST_CASE(get_byIndex_returnsItem) {
|
||||
BOOST_AUTO_TEST_CASE(get_indexoutofbounds_throws) {
|
||||
DeckRecord deckRecord;
|
||||
deckRecord.addItem( DeckItem { "TEST", int() } );
|
||||
BOOST_CHECK_THROW(deckRecord.getItem(1), std::out_of_range);
|
||||
BOOST_CHECK_THROW(deckRecord.getItem(1), std::exception);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(get_byName_returnsItem) {
|
||||
@@ -465,7 +468,7 @@ BOOST_AUTO_TEST_CASE(get_byName_returnsItem) {
|
||||
BOOST_AUTO_TEST_CASE(get_byNameNonExisting_throws) {
|
||||
DeckRecord deckRecord;
|
||||
deckRecord.addItem( DeckItem { "TEST", int() } );
|
||||
BOOST_CHECK_THROW(deckRecord.getItem("INVALID"), std::invalid_argument);
|
||||
BOOST_CHECK_THROW(deckRecord.getItem("INVALID"), std::exception);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(StringsWithSpaceOK) {
|
||||
@@ -507,7 +510,7 @@ BOOST_AUTO_TEST_CASE(size_noRecords_returnszero) {
|
||||
Parser parser;
|
||||
DeckKeyword deckKeyword( parser.getKeyword("GRID"));;
|
||||
BOOST_CHECK_EQUAL(0U, deckKeyword.size());
|
||||
BOOST_CHECK_THROW(deckKeyword.getRecord(0), std::out_of_range);
|
||||
BOOST_CHECK_THROW(deckKeyword.getRecord(0), std::exception);
|
||||
}
|
||||
|
||||
|
||||
@@ -676,9 +679,170 @@ BOOST_AUTO_TEST_CASE(STRING_TO_BOOL) {
|
||||
BOOST_CHECK( !DeckItem::to_bool("N"));
|
||||
BOOST_CHECK( !DeckItem::to_bool("0") );
|
||||
//
|
||||
BOOST_CHECK_THROW(DeckItem::to_bool("NO - not valid"), std::invalid_argument);
|
||||
BOOST_CHECK_THROW(DeckItem::to_bool("YE"), std::invalid_argument);
|
||||
BOOST_CHECK_THROW(DeckItem::to_bool("YE"), std::invalid_argument);
|
||||
BOOST_CHECK_THROW(DeckItem::to_bool("NO - not valid"), std::exception);
|
||||
BOOST_CHECK_THROW(DeckItem::to_bool("YE"), std::exception);
|
||||
BOOST_CHECK_THROW(DeckItem::to_bool("YE"), std::exception);
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(DeckView2Test) {
|
||||
std::string deck_string = R"(
|
||||
START
|
||||
7 OCT 2020 /
|
||||
|
||||
DIMENS
|
||||
10 10 3 /
|
||||
|
||||
GRID
|
||||
DXV
|
||||
10*100.0 /
|
||||
DYV
|
||||
10*100.0 /
|
||||
DZV
|
||||
3*10.0 /
|
||||
|
||||
DEPTHZ
|
||||
121*2000.0 /
|
||||
|
||||
PORO
|
||||
300*0.3 /
|
||||
|
||||
SCHEDULE
|
||||
|
||||
VFPPROD
|
||||
-- table_num, datum_depth, flo, wfr, gfr, pressure, alq, unit, table_vals
|
||||
42 7.0E+03 LIQ WCT GOR THP ' ' METRIC BHP /
|
||||
1.0 / flo axis
|
||||
0.0 1.0 / THP axis
|
||||
0.0 / WFR axis
|
||||
0.0 / GFR axis
|
||||
0.0 / ALQ axis
|
||||
-- Table itself: thp_idx wfr_idx gfr_idx alq_idx <vals>
|
||||
1 1 1 1 0.0 /
|
||||
2 1 1 1 1.0 /
|
||||
|
||||
VFPPROD
|
||||
-- table_num, datum_depth, flo, wfr, gfr, pressure, alq, unit, table_vals
|
||||
43 7.0E+03 LIQ WCT GOR THP 'GRAT' METRIC BHP /
|
||||
1.0 / flo axis
|
||||
0.0 1.0 / THP axis
|
||||
0.0 / WFR axis
|
||||
0.0 / GFR axis
|
||||
0.0 / ALQ axis
|
||||
-- Table itself: thp_idx wfr_idx gfr_idx alq_idx <vals>
|
||||
1 1 1 1 0.0 /
|
||||
2 1 1 1 1.0 /
|
||||
|
||||
WELSPECS -- 0
|
||||
'P1' 'G' 10 10 2005 'LIQ' /
|
||||
'P2' 'G' 10 10 2005 'LIQ' /
|
||||
/
|
||||
|
||||
COMPDAT
|
||||
'P1' 9 9 1 1 'OPEN' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 /
|
||||
'P2' 9 9 1 1 'OPEN' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 /
|
||||
/
|
||||
|
||||
WCONPROD
|
||||
'P1' 'OPEN' 'ORAT' 123.4 0.0 0.0 0.0 0.0 100 100 42 'UDA' /
|
||||
'P2' 'OPEN' 'ORAT' 123.4 0.0 0.0 0.0 0.0 100 100 43 'UDA' /
|
||||
/
|
||||
|
||||
DATES
|
||||
10 'JAN' 2000 /
|
||||
/
|
||||
|
||||
DATES
|
||||
20 'JAN' 2000 /
|
||||
/
|
||||
|
||||
DATES
|
||||
30 'JAN' 2000 /
|
||||
/
|
||||
|
||||
)";
|
||||
|
||||
Parser parser;
|
||||
auto deck = parser.parseString(deck_string);
|
||||
DeckView dw;
|
||||
for (const auto& kw : deck)
|
||||
dw.add_keyword(kw);
|
||||
|
||||
BOOST_CHECK(dw.has_keyword("DATES"));
|
||||
BOOST_CHECK(!dw.has_keyword("RADIAL"));
|
||||
BOOST_CHECK(!dw.empty());
|
||||
BOOST_CHECK_EQUAL(dw.size(), 17);
|
||||
|
||||
BOOST_CHECK_THROW(dw[100], std::exception);
|
||||
const auto& start = dw[0];
|
||||
BOOST_CHECK_EQUAL(start.name(), "START");
|
||||
BOOST_CHECK_EQUAL(dw.front().name(), "START");
|
||||
BOOST_CHECK(dw.back() == dw[16]);
|
||||
{
|
||||
DeckView dw2;
|
||||
BOOST_CHECK_THROW(dw2.back(), std::exception);
|
||||
BOOST_CHECK_THROW(dw2.front(), std::exception);
|
||||
}
|
||||
const auto& radial_kw = dw["RADIAL"];
|
||||
BOOST_CHECK(radial_kw.empty());
|
||||
|
||||
|
||||
const auto& dates_view = dw["DATES"];
|
||||
BOOST_CHECK_EQUAL(dates_view.size(), 3);
|
||||
const auto& first_dates = dates_view.front();
|
||||
const auto& rec0 = first_dates[0];
|
||||
const auto& month = rec0.getItem(1).get<std::string>(0);
|
||||
BOOST_CHECK_EQUAL(month, "JAN");
|
||||
|
||||
const auto& last_dates = dates_view.back();
|
||||
const auto& rec1 = last_dates[0];
|
||||
const auto& day = rec1.getItem(0).get<int>(0);
|
||||
BOOST_CHECK_EQUAL(day, 30);
|
||||
|
||||
|
||||
BOOST_CHECK(dw.has_keyword<ParserKeywords::DATES>());
|
||||
std::vector<std::string> expected = {"START", "DIMENS", "GRID", "DXV", "DYV", "DZV", "DEPTHZ", "PORO",
|
||||
"SCHEDULE", "VFPPROD", "VFPPROD", "WELSPECS", "COMPDAT", "WCONPROD",
|
||||
"DATES", "DATES", "DATES"};
|
||||
std::vector<std::string> actual;
|
||||
for (const auto& kw : dw)
|
||||
actual.push_back(kw.name());
|
||||
|
||||
BOOST_CHECK( actual == expected );
|
||||
|
||||
const auto& radial_index = dw.index("RADIAL");
|
||||
BOOST_CHECK( radial_index.empty() );
|
||||
|
||||
auto dates_index = dw.index("DATES");
|
||||
std::vector<std::size_t> dates_expected = {14, 15, 16};
|
||||
BOOST_CHECK(dates_index == dates_expected);
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL(dw.count("RADIAL"), 0);
|
||||
BOOST_CHECK_EQUAL(dw.count("VFPPROD"), 2);
|
||||
BOOST_CHECK_EQUAL(dw.count("SCHEDULE"), 1);
|
||||
|
||||
|
||||
bool have_grid0 = std::any_of(dw.begin(), dw.end(), [](const DeckKeyword& kw) {
|
||||
return kw.name() == "GRID";
|
||||
});
|
||||
BOOST_CHECK( have_grid0 );
|
||||
|
||||
bool have_grid1 = std::any_of(dw.begin() + 3, dw.end(), [](const DeckKeyword& kw) {
|
||||
return kw.name() == "GRID";
|
||||
});
|
||||
BOOST_CHECK( !have_grid1 );
|
||||
|
||||
auto is_vfpprod = [](const DeckKeyword& kw) { return kw.name() == "VFPPROD"; };
|
||||
auto iter = std::find_if(dw.begin(), dw.end(), is_vfpprod);
|
||||
BOOST_CHECK( iter != dw.end() );
|
||||
|
||||
auto iter2 = std::find_if(iter + 1, dw.end(), is_vfpprod);
|
||||
BOOST_CHECK( iter2 != dw.end() );
|
||||
|
||||
auto iter3 = std::find_if(iter2 + 1, dw.end(), is_vfpprod);
|
||||
BOOST_CHECK( iter3 == dw.end() );
|
||||
|
||||
auto count = std::count_if(dw.begin(), dw.end(), is_vfpprod);
|
||||
BOOST_CHECK_EQUAL(count, 2);
|
||||
}
|
||||
|
||||
@@ -854,8 +854,8 @@ BOOST_AUTO_TEST_CASE(WCONPROD_BHP_CMode)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(BHP_CMODE)
|
||||
{
|
||||
BOOST_CHECK_THROW( WCONHIST::properties(WCONHIST::all_specified_CMODE_THP()) , std::invalid_argument);
|
||||
BOOST_CHECK_THROW( WCONPROD::properties(WCONPROD::all_specified_CMODE_BHP()) , std::invalid_argument);
|
||||
BOOST_CHECK_THROW( WCONHIST::properties(WCONHIST::all_specified_CMODE_THP()) , std::exception);
|
||||
BOOST_CHECK_THROW( WCONPROD::properties(WCONPROD::all_specified_CMODE_BHP()) , std::exception);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user