2019-10-08 00:31:52 -05:00
|
|
|
/*
|
|
|
|
Copyright 2019 Equinor ASA.
|
2019-09-26 03:13:33 -05:00
|
|
|
|
2019-10-08 00:31:52 -05:00
|
|
|
This file is part of the Open Porous Media project (OPM).
|
2019-09-26 03:13:33 -05:00
|
|
|
|
2019-10-08 00:31:52 -05:00
|
|
|
OPM is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
OPM is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2019-09-26 03:13:33 -05:00
|
|
|
|
|
|
|
#define BOOST_TEST_MODULE DeckValueTests
|
2019-09-26 09:20:02 -05:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
2019-09-26 03:13:33 -05:00
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
2019-09-26 08:08:21 -05:00
|
|
|
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
|
|
|
#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>
|
|
|
|
#include <opm/parser/eclipse/Parser/ParserKeywords/A.hpp>
|
2019-09-26 09:20:02 -05:00
|
|
|
#include <opm/parser/eclipse/Parser/ParserKeywords/B.hpp>
|
2019-09-26 08:08:21 -05:00
|
|
|
|
2019-09-26 03:13:33 -05:00
|
|
|
#include <opm/parser/eclipse/Deck/DeckValue.hpp>
|
2019-09-26 08:08:21 -05:00
|
|
|
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
|
|
|
|
|
|
|
|
using namespace Opm;
|
2019-09-26 03:13:33 -05:00
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(DeckValueTest) {
|
|
|
|
|
2019-09-26 09:20:02 -05:00
|
|
|
const DeckValue value0;
|
2019-09-26 03:13:33 -05:00
|
|
|
|
2019-09-26 09:20:02 -05:00
|
|
|
BOOST_CHECK(value0.is_default());
|
|
|
|
BOOST_CHECK(!value0.is_compatible<int>());
|
|
|
|
BOOST_CHECK(!value0.is_compatible<std::string>());
|
|
|
|
BOOST_CHECK(!value0.is_compatible<double>());
|
|
|
|
BOOST_CHECK_THROW( value0.get<int>(), std::invalid_argument);
|
2019-09-26 03:13:33 -05:00
|
|
|
BOOST_CHECK_THROW( value0.get<std::string>(), std::invalid_argument);
|
|
|
|
BOOST_CHECK_THROW( value0.get<double>(), std::invalid_argument);
|
|
|
|
|
|
|
|
DeckValue value1(10);
|
2019-09-26 09:20:02 -05:00
|
|
|
BOOST_CHECK(!value1.is_default());
|
|
|
|
BOOST_CHECK(value1.is_compatible<int>());
|
|
|
|
BOOST_CHECK(value1.is_compatible<double>());
|
|
|
|
BOOST_CHECK(!value1.is_compatible<std::string>());
|
2019-09-26 03:13:33 -05:00
|
|
|
BOOST_CHECK_EQUAL( value1.get<int>(), 10);
|
2019-09-26 09:20:02 -05:00
|
|
|
BOOST_CHECK_EQUAL( value1.get<double>(), 10);
|
2019-09-26 03:13:33 -05:00
|
|
|
|
|
|
|
DeckValue value2(10.0);
|
2019-09-26 09:20:02 -05:00
|
|
|
BOOST_CHECK(value2.is_compatible<double>());
|
|
|
|
BOOST_CHECK(!value2.is_compatible<int>());
|
|
|
|
BOOST_CHECK(!value2.is_compatible<std::string>());
|
2019-09-26 03:13:33 -05:00
|
|
|
BOOST_CHECK_EQUAL( value2.get<double>(), 10);
|
|
|
|
BOOST_CHECK_THROW( value2.get<std::string>(), std::invalid_argument);
|
|
|
|
BOOST_CHECK_THROW( value2.get<int>(), std::invalid_argument);
|
|
|
|
|
|
|
|
DeckValue value3("FUBHP");
|
2019-09-26 09:20:02 -05:00
|
|
|
BOOST_CHECK(!value3.is_compatible<double>());
|
|
|
|
BOOST_CHECK(value3.is_compatible<std::string>());
|
2019-09-26 03:13:33 -05:00
|
|
|
BOOST_CHECK_EQUAL( value3.get<std::string>(), std::string("FUBHP"));
|
|
|
|
BOOST_CHECK_THROW( value3.get<double>(), std::invalid_argument);
|
|
|
|
BOOST_CHECK_THROW( value3.get<int>(), std::invalid_argument);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2019-09-26 09:20:02 -05:00
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(DeckKeywordConstructor) {
|
2019-10-08 00:26:10 -05:00
|
|
|
|
2019-09-26 09:20:02 -05:00
|
|
|
Parser parser;
|
|
|
|
|
|
|
|
const ParserKeyword& big_model = parser.getKeyword("BIGMODEL");
|
|
|
|
BOOST_CHECK_THROW( DeckKeyword( big_model, {{DeckValue("WORD_A")}} ), std::invalid_argument );
|
|
|
|
|
|
|
|
const ParserKeyword& box = parser.getKeyword("BOX");
|
2019-10-08 00:26:10 -05:00
|
|
|
std::vector< DeckValue > record1 = {DeckValue(1), DeckValue(2), DeckValue(3), DeckValue(4), DeckValue(5), DeckValue(6)};
|
2019-10-11 07:14:19 -05:00
|
|
|
DeckKeyword dkw(box, {record1});
|
2019-09-26 09:20:02 -05:00
|
|
|
BOOST_CHECK_NO_THROW( DeckKeyword( box, {record1} ) );
|
2019-10-08 00:44:15 -05:00
|
|
|
BOOST_CHECK_THROW( DeckKeyword( box, {{ record1, record1 }}), std::invalid_argument );
|
2019-09-26 09:20:02 -05:00
|
|
|
|
|
|
|
const ParserKeyword& addreg = parser.getKeyword("ADDREG");
|
|
|
|
|
|
|
|
BOOST_CHECK_NO_THROW( DeckKeyword( addreg, {{ DeckValue("WORD_A") }} ) );
|
|
|
|
BOOST_CHECK_THROW( DeckKeyword( addreg, {{DeckValue("WORD_A"), DeckValue(77), DeckValue(16.25), DeckValue("WORD_B")}} ) , std::invalid_argument);
|
|
|
|
|
|
|
|
std::vector< DeckValue > record = {DeckValue("WORD_A"), DeckValue(16.25), DeckValue(77), DeckValue("WORD_B")};
|
|
|
|
DeckKeyword deck_kw(addreg, {record});
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( deck_kw.size(), 1 );
|
|
|
|
|
|
|
|
const DeckRecord& deck_record = deck_kw.getRecord(0);
|
|
|
|
BOOST_CHECK_EQUAL( deck_record.size(), 4 );
|
|
|
|
|
|
|
|
const auto& array = deck_record.getItem( 0 );
|
|
|
|
const auto& shift = deck_record.getItem( 1 );
|
|
|
|
const auto& number = deck_record.getItem( 2 );
|
|
|
|
const auto& name = deck_record.getItem( 3 );
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( array.get<std::string>(0), "WORD_A" );
|
|
|
|
BOOST_CHECK_EQUAL( shift.get<double>(0), 16.25 );
|
|
|
|
BOOST_CHECK_EQUAL( number.get<int>(0), 77 );
|
|
|
|
BOOST_CHECK_EQUAL( name.get<std::string>(0), "WORD_B" );
|
|
|
|
|
|
|
|
//checking default values:
|
|
|
|
record = {DeckValue("WORD_A"), DeckValue(), DeckValue(77)};
|
|
|
|
DeckKeyword deck_kw1(addreg, {record});
|
|
|
|
|
|
|
|
const DeckRecord& deck_record1 = deck_kw1.getRecord(0);
|
|
|
|
const auto& shift1 = deck_record1.getItem( 1 );
|
|
|
|
const auto& name1 = deck_record1.getItem( 3 );
|
|
|
|
BOOST_CHECK_EQUAL( shift1.get<double>(0), 0 );
|
|
|
|
BOOST_CHECK_EQUAL( name1.get<std::string>(0), "M" );
|
|
|
|
|
|
|
|
//check that int can substitute double
|
|
|
|
BOOST_CHECK_NO_THROW( DeckKeyword(addreg, {{DeckValue("WORD_A"), DeckValue(5), DeckValue(77)}} ) );
|
|
|
|
|
2019-10-08 00:26:10 -05:00
|
|
|
|
2019-09-26 09:20:02 -05:00
|
|
|
}
|
2019-10-10 07:40:32 -05:00
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(DeckKeywordVectorInt) {
|
|
|
|
|
|
|
|
Parser parser;
|
|
|
|
const ParserKeyword& hbnum = parser.getKeyword("HBNUM");
|
|
|
|
const ParserKeyword& box = parser.getKeyword("BOX");
|
|
|
|
|
|
|
|
std::vector<int> data = {0, 1, 2, 3, 4, 5, 6, 7, 8};
|
|
|
|
BOOST_CHECK_THROW( DeckKeyword(box, data), std::invalid_argument );
|
|
|
|
DeckKeyword hbnum_kw(hbnum, data);
|
|
|
|
BOOST_CHECK(hbnum_kw.isDataKeyword());
|
|
|
|
BOOST_CHECK_EQUAL(hbnum_kw.getDataSize(), 9);
|
|
|
|
BOOST_CHECK( hbnum_kw.getIntData() == data );
|
|
|
|
|
|
|
|
std::vector<double> data_double = {1.1, 2.2};
|
|
|
|
BOOST_CHECK_THROW(DeckKeyword(hbnum, data_double), std::invalid_argument);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(DeckKeywordVectorDouble) {
|
|
|
|
|
|
|
|
Parser parser;
|
|
|
|
const ParserKeyword& poro = parser.getKeyword("PORO");
|
|
|
|
const ParserKeyword& box = parser.getKeyword("BOX");
|
|
|
|
|
|
|
|
std::vector<double> data = {1.1, 2.2, 3.3};
|
|
|
|
BOOST_CHECK_THROW(DeckKeyword(box, data), std::invalid_argument);
|
|
|
|
DeckKeyword poro_kw(poro, data);
|
|
|
|
BOOST_CHECK(poro_kw.isDataKeyword());
|
|
|
|
BOOST_CHECK_EQUAL(poro_kw.getDataSize(), 3);
|
|
|
|
BOOST_CHECK( poro_kw.getRawDoubleData() == data );
|
|
|
|
|
|
|
|
std::vector<int> data_int = {1, 2};
|
|
|
|
poro_kw = DeckKeyword(poro, data_int);
|
|
|
|
std::vector<double> raw_int = {1.0, 2.0};
|
|
|
|
BOOST_CHECK( poro_kw.getRawDoubleData() == raw_int );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|