2014-05-16 15:31:20 +02:00
|
|
|
/*
|
|
|
|
|
Copyright 2014 Statoil ASA.
|
|
|
|
|
|
|
|
|
|
This file is part of the Open Porous Media project (OPM).
|
|
|
|
|
|
|
|
|
|
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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
|
|
|
|
|
|
#define BOOST_TEST_MODULE EclipseGridTests
|
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
|
|
|
|
|
|
|
|
|
#include <opm/parser/eclipse/Deck/Section.hpp>
|
|
|
|
|
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
|
|
|
|
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
|
|
|
|
|
#include <opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp>
|
|
|
|
|
|
2014-06-02 12:47:35 +02:00
|
|
|
// forward declarations
|
|
|
|
|
Opm::DeckKeywordConstPtr createSATNUMKeyword();
|
|
|
|
|
Opm::DeckKeywordConstPtr createTABDIMSKeyword();
|
2014-05-16 15:31:20 +02:00
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(Empty) {
|
2014-05-30 10:07:24 +02:00
|
|
|
Opm::GridProperty<int> gridProperties( 5 , 5 , 4 , "SATNUM" , 77);
|
2014-05-16 15:31:20 +02:00
|
|
|
const std::vector<int>& data = gridProperties.getData();
|
|
|
|
|
BOOST_CHECK_EQUAL( 100U , data.size());
|
|
|
|
|
BOOST_CHECK_EQUAL( 100U , gridProperties.size());
|
2014-05-30 10:07:24 +02:00
|
|
|
for (size_t k=0; k < 4; k++) {
|
|
|
|
|
for (size_t j=0; j < 5; j++) {
|
|
|
|
|
for (size_t i=0; i < 5; i++) {
|
|
|
|
|
size_t g = i + j*5 + k*25;
|
|
|
|
|
BOOST_CHECK_EQUAL( 77 , data[g] );
|
|
|
|
|
BOOST_CHECK_EQUAL( 77 , gridProperties.iget( g ));
|
|
|
|
|
BOOST_CHECK_EQUAL( 77 , gridProperties.iget( i,j,k ));
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-05-16 15:31:20 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(EmptyDefault) {
|
2014-05-30 10:07:24 +02:00
|
|
|
Opm::GridProperty<int> gridProperties( 10,10,1 , "SATNUM");
|
2014-05-16 15:31:20 +02:00
|
|
|
const std::vector<int>& data = gridProperties.getData();
|
|
|
|
|
BOOST_CHECK_EQUAL( 100U , data.size());
|
|
|
|
|
for (size_t i=0; i < data.size(); i++)
|
|
|
|
|
BOOST_CHECK_EQUAL( 0 , data[i] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Opm::DeckKeywordConstPtr createSATNUMKeyword( ) {
|
|
|
|
|
const char *deckData =
|
|
|
|
|
"SATNUM \n"
|
2014-05-30 10:07:24 +02:00
|
|
|
" 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 / \n"
|
2014-05-16 15:31:20 +02:00
|
|
|
"\n";
|
|
|
|
|
|
|
|
|
|
Opm::ParserPtr parser(new Opm::Parser());
|
|
|
|
|
Opm::DeckPtr deck = parser->parseString(deckData);
|
|
|
|
|
return deck->getKeyword("SATNUM");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Opm::DeckKeywordConstPtr createTABDIMSKeyword( ) {
|
|
|
|
|
const char *deckData =
|
|
|
|
|
"TABDIMS\n"
|
|
|
|
|
" 0 1 2 3 4 5 / \n"
|
|
|
|
|
"\n";
|
|
|
|
|
|
|
|
|
|
Opm::ParserPtr parser(new Opm::Parser());
|
|
|
|
|
Opm::DeckPtr deck = parser->parseString(deckData);
|
|
|
|
|
return deck->getKeyword("TABDIMS");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(SetFromDeckKeyword_notData_Throws) {
|
|
|
|
|
Opm::DeckKeywordConstPtr tabdimsKw = createTABDIMSKeyword();
|
2014-05-30 10:07:24 +02:00
|
|
|
Opm::GridProperty<int> gridProperty( 6 ,1,1 , "TABDIMS" , 100);
|
2014-05-16 15:31:20 +02:00
|
|
|
BOOST_CHECK_THROW( gridProperty.loadFromDeckKeyword( tabdimsKw ) , std::invalid_argument );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(SetFromDeckKeyword_wrong_size_throws) {
|
|
|
|
|
Opm::DeckKeywordConstPtr satnumKw = createSATNUMKeyword();
|
2014-05-30 10:07:24 +02:00
|
|
|
Opm::GridProperty<int> gridProperty( 15 ,1,1, "SATNUM",66);
|
2014-05-16 15:31:20 +02:00
|
|
|
BOOST_CHECK_THROW( gridProperty.loadFromDeckKeyword( satnumKw ) , std::invalid_argument );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(SetFromDeckKeyword) {
|
|
|
|
|
Opm::DeckKeywordConstPtr satnumKw = createSATNUMKeyword();
|
2014-05-30 10:07:24 +02:00
|
|
|
Opm::GridProperty<int> gridProperty( 4 , 4 , 2 , "SATNUM" , 99);
|
2014-05-16 15:31:20 +02:00
|
|
|
gridProperty.loadFromDeckKeyword( satnumKw );
|
|
|
|
|
const std::vector<int>& data = gridProperty.getData();
|
2014-05-30 10:07:24 +02:00
|
|
|
for (size_t k=0; k < 2; k++) {
|
|
|
|
|
for (size_t j=0; j < 4; j++) {
|
|
|
|
|
for (size_t i=0; i < 4; i++) {
|
|
|
|
|
size_t g = i + j*4 + k*16;
|
|
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( g , data[g] );
|
|
|
|
|
BOOST_CHECK_EQUAL( g , gridProperty.iget(g) );
|
|
|
|
|
BOOST_CHECK_EQUAL( g , gridProperty.iget(i,j,k) );
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-05-16 15:31:20 +02:00
|
|
|
}
|