Added GridProperty class.
This commit is contained in:
@@ -129,6 +129,7 @@ EclipseState/Schedule/GroupTree.hpp
|
||||
EclipseState/Schedule/OrderedMap.hpp
|
||||
#
|
||||
EclipseState/Grid/EclipseGrid.hpp
|
||||
EclipseState/Grid/GridProperty.hpp
|
||||
#
|
||||
Utility/WconinjeWrapper.hpp
|
||||
Utility/CompdatWrapper.hpp
|
||||
|
||||
100
opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp
Normal file
100
opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
#ifndef ECLIPSE_GRIDPROPERTY_HPP_
|
||||
#define ECLIPSE_GRIDPROPERTY_HPP_
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
/*
|
||||
This class implemenents a class representing properties which are
|
||||
define over an ECLIPSE grid, i.e. with one value for each logical
|
||||
cartesian cell in the grid.
|
||||
|
||||
The class is implemented as a thin wrapper around std::vector<T>;
|
||||
where the most relevant specialisations of T are 'int' and 'float'.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
namespace Opm {
|
||||
|
||||
template <typename T>
|
||||
class GridProperty {
|
||||
public:
|
||||
|
||||
GridProperty(size_t gridVolume , const std::string& keyword , T defaultValue = 0) {
|
||||
m_keyword = keyword;
|
||||
m_data.resize( gridVolume );
|
||||
std::fill( m_data.begin() , m_data.end() , defaultValue );
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return m_data.size();
|
||||
}
|
||||
|
||||
|
||||
T iget(size_t index) const {
|
||||
if (index < m_data.size()) {
|
||||
return m_data[index];
|
||||
} else {
|
||||
throw std::invalid_argument("Index out of range \n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const std::vector<T>& getData() {
|
||||
return m_data;
|
||||
}
|
||||
|
||||
void loadFromDeckKeyword( DeckKeywordConstPtr deckKeyword);
|
||||
|
||||
private:
|
||||
|
||||
void setFromVector(const std::vector<T>& data) {
|
||||
if (data.size() == m_data.size()) {
|
||||
for (size_t i = 0; i < m_data.size(); i++)
|
||||
m_data[i] = data[i];
|
||||
} else
|
||||
throw std::invalid_argument("Size mismatch");
|
||||
}
|
||||
|
||||
std::string m_keyword;
|
||||
std::vector<T> m_data;
|
||||
};
|
||||
|
||||
|
||||
template<>
|
||||
void GridProperty<int>::loadFromDeckKeyword(DeckKeywordConstPtr deckKeyword) {
|
||||
if (deckKeyword->isDataKeyword()) {
|
||||
const std::vector<int>& data = deckKeyword->getIntData();
|
||||
setFromVector(data);
|
||||
} else
|
||||
throw std::invalid_argument("Can only load from DATA keywords");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -1,3 +1,11 @@
|
||||
add_executable(runEclipseGridTests EclipseGridTests.cpp)
|
||||
target_link_libraries(runEclipseGridTests Parser ${Boost_LIBRARIES})
|
||||
add_test(NAME runEclipseGridTests WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${TEST_MEMCHECK_TOOL} ${EXECUTABLE_OUTPUT_PATH}/runEclipseGridTests )
|
||||
|
||||
|
||||
add_executable(runGridPropertyTests GridPropertyTests.cpp)
|
||||
target_link_libraries(runGridPropertyTests Parser ${Boost_LIBRARIES})
|
||||
add_test(NAME runGridPropertyTests WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${TEST_MEMCHECK_TOOL} ${EXECUTABLE_OUTPUT_PATH}/runGridPropertyTests )
|
||||
|
||||
|
||||
|
||||
|
||||
106
opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp
Normal file
106
opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
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>
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Empty) {
|
||||
Opm::GridProperty<int> gridProperties( 100 , "SATNUM" , 77);
|
||||
const std::vector<int>& data = gridProperties.getData();
|
||||
BOOST_CHECK_EQUAL( 100U , data.size());
|
||||
BOOST_CHECK_EQUAL( 100U , gridProperties.size());
|
||||
for (size_t i=0; i < data.size(); i++) {
|
||||
BOOST_CHECK_EQUAL( 77 , data[i] );
|
||||
BOOST_CHECK_EQUAL( 77 , gridProperties.iget( i ));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(EmptyDefault) {
|
||||
Opm::GridProperty<int> gridProperties( 100 , "SATNUM");
|
||||
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"
|
||||
" 0 1 2 3 4 5 6 7 8 9 / \n"
|
||||
"\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();
|
||||
Opm::GridProperty<int> gridProperty( 6 , "TABDIMS" , 100);
|
||||
BOOST_CHECK_THROW( gridProperty.loadFromDeckKeyword( tabdimsKw ) , std::invalid_argument );
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(SetFromDeckKeyword_wrong_size_throws) {
|
||||
Opm::DeckKeywordConstPtr satnumKw = createSATNUMKeyword();
|
||||
Opm::GridProperty<int> gridProperty( 15 , "SATNUM",66);
|
||||
BOOST_CHECK_THROW( gridProperty.loadFromDeckKeyword( satnumKw ) , std::invalid_argument );
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(SetFromDeckKeyword) {
|
||||
Opm::DeckKeywordConstPtr satnumKw = createSATNUMKeyword();
|
||||
Opm::GridProperty<int> gridProperty( 10 , "SATNUM" , 99);
|
||||
gridProperty.loadFromDeckKeyword( satnumKw );
|
||||
const std::vector<int>& data = gridProperty.getData();
|
||||
for (size_t i=0; i < data.size(); i++)
|
||||
BOOST_CHECK_EQUAL( i , data[i] );
|
||||
}
|
||||
Reference in New Issue
Block a user