Can now parse file with several WCONHIST keywords

This commit is contained in:
Joakim Hove 2013-08-01 12:50:42 +02:00
parent 75954575d5
commit 475b607faf
12 changed files with 156 additions and 15 deletions

View File

@ -17,6 +17,8 @@
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <vector>
#include <opm/parser/eclipse/Deck/Deck.hpp>
namespace Opm {
@ -36,6 +38,15 @@ namespace Opm {
DeckKeywordConstPtr Deck::getKeyword(const std::string& keyword, size_t index) const {
return m_keywords->getKeyword(keyword , index);
}
size_t Deck::numKeywords(const std::string& keyword) {
return m_keywords->numKeywords( keyword );
}
const std::vector<DeckKeywordConstPtr>& Deck::getKeywordList(const std::string& keyword) {
return m_keywords->getKeywordList( keyword );
}
}

View File

@ -20,7 +20,10 @@
#ifndef DECK_HPP
#define DECK_HPP
#include <vector>
#include <boost/shared_ptr.hpp>
#include <opm/parser/eclipse/Deck/KeywordContainer.hpp>
namespace Opm {
@ -30,7 +33,9 @@ namespace Opm {
Deck();
bool hasKeyword( const std::string& keyword ) const;
void addKeyword( DeckKeywordConstPtr keyword);
DeckKeywordConstPtr getKeyword(const std::string& keyword , size_t index) const;
DeckKeywordConstPtr getKeyword(const std::string& keyword , size_t index) const;
size_t numKeywords(const std::string& keyword);
const std::vector<DeckKeywordConstPtr>& getKeywordList(const std::string& keyword);
private:
KeywordContainerPtr m_keywords;

View File

@ -48,18 +48,31 @@ namespace Opm {
keywordList.push_back(keyword);
}
}
DeckKeywordConstPtr KeywordContainer::getKeyword(const std::string& keyword, size_t index) const {
const std::vector<DeckKeywordConstPtr>& KeywordContainer::getKeywordList(const std::string& keyword) const {
if (hasKeyword(keyword)) {
const std::vector<DeckKeywordConstPtr>& keywordList = m_keywordMap.find(keyword)->second;
if (index < keywordList.size())
return keywordList[index];
else
throw std::invalid_argument("Keyword index is out of range.");
}
else
return keywordList;
} else
throw std::invalid_argument("Keyword: " + keyword + " is not found in the container");
}
DeckKeywordConstPtr KeywordContainer::getKeyword(const std::string& keyword, size_t index) const {
const std::vector<DeckKeywordConstPtr>& keywordList = getKeywordList( keyword );
if (index < keywordList.size())
return keywordList[index];
else
throw std::invalid_argument("Keyword index is out of range.");
}
size_t KeywordContainer::numKeywords(const std::string& keyword) const{
if (hasKeyword(keyword)) {
const std::vector<DeckKeywordConstPtr>& keywordList = getKeywordList( keyword );
return keywordList.size();
} else
return 0;
}
}

View File

@ -24,7 +24,8 @@ namespace Opm {
size_t size() const;
void addKeyword(DeckKeywordConstPtr keyword);
DeckKeywordConstPtr getKeyword(const std::string& keyword, size_t index) const;
const std::vector<DeckKeywordConstPtr>& getKeywordList(const std::string& keyword) const;
size_t numKeywords(const std::string& keyword) const;
private:
std::vector<DeckKeywordConstPtr> m_keywordList;

View File

@ -48,6 +48,11 @@ BOOST_AUTO_TEST_CASE(getKeyword_nosuchkeyword_throws) {
BOOST_CHECK_THROW(deck.getKeyword("TRULS" , 0), std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(getKeywordList_nosuchkeyword_throws) {
Deck deck;
BOOST_CHECK_THROW(deck.getKeywordList("TRULS"), std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(getKeyword_singlekeyword_keywordreturned) {
Deck deck;
DeckKeywordConstPtr keyword(new DeckKeyword("BJARNE"));
@ -64,5 +69,37 @@ BOOST_AUTO_TEST_CASE(getKeyword_singlekeyword_outRange_throws) {
}
BOOST_AUTO_TEST_CASE(getKeywordList_returnOK) {
Deck deck;
DeckKeywordConstPtr keyword(new DeckKeyword("BJARNE"));
deck.addKeyword(keyword);
BOOST_CHECK_NO_THROW(deck.getKeywordList("BJARNE") );
}
BOOST_AUTO_TEST_CASE(numKeyword_singlekeyword_return1) {
Deck deck;
DeckKeywordConstPtr keyword(new DeckKeyword("BJARNE"));
deck.addKeyword(keyword);
BOOST_CHECK_EQUAL(1U , deck.numKeywords("BJARNE"));
}
BOOST_AUTO_TEST_CASE(numKeyword_twokeyword_return2) {
Deck deck;
DeckKeywordConstPtr keyword(new DeckKeyword("BJARNE"));
deck.addKeyword(keyword);
deck.addKeyword(keyword);
BOOST_CHECK_EQUAL(2U , deck.numKeywords("BJARNE"));
}
BOOST_AUTO_TEST_CASE(numKeyword_nokeyword_return0) {
Deck deck;
DeckKeywordConstPtr keyword(new DeckKeyword("BJARNE"));
deck.addKeyword(keyword);
BOOST_CHECK_EQUAL(0U , deck.numKeywords("BJARNEX"));
}

View File

@ -67,7 +67,46 @@ BOOST_AUTO_TEST_CASE(getKeyword_outOfRange_throws) {
KeywordContainerPtr container(new KeywordContainer());
DeckKeywordPtr keyword = DeckKeywordPtr(new DeckKeyword("TRULS"));
container->addKeyword(keyword);
BOOST_CHECK_EQUAL(keyword, container->getKeyword("TRULS" , 2));
BOOST_CHECK_THROW( container->getKeyword("TRULS" , 3) , std::invalid_argument)
}
BOOST_AUTO_TEST_CASE(getKeywordList_notFound_throws) {
KeywordContainerPtr container(new KeywordContainer());
DeckKeywordPtr keyword = DeckKeywordPtr(new DeckKeyword("TRULS"));
container->addKeyword(keyword);
BOOST_CHECK_THROW( container->getKeywordList("TRULSX") , std::invalid_argument)
}
BOOST_AUTO_TEST_CASE(getKeywordList_OK) {
KeywordContainerPtr container(new KeywordContainer());
DeckKeywordPtr keyword1 = DeckKeywordPtr(new DeckKeyword("TRULS"));
DeckKeywordPtr keyword2 = DeckKeywordPtr(new DeckKeyword("TRULS"));
DeckKeywordPtr keyword3 = DeckKeywordPtr(new DeckKeyword("TRULS"));
container->addKeyword(keyword1);
container->addKeyword(keyword2);
container->addKeyword(keyword3);
const std::vector<DeckKeywordConstPtr>& keywordList = container->getKeywordList("TRULS");
BOOST_CHECK_EQUAL( 3U , keywordList.size() );
}
BOOST_AUTO_TEST_CASE(keywordList_getnum_OK) {
KeywordContainerPtr container(new KeywordContainer());
DeckKeywordPtr keyword1 = DeckKeywordPtr(new DeckKeyword("TRULS"));
DeckKeywordPtr keyword2 = DeckKeywordPtr(new DeckKeyword("TRULS"));
DeckKeywordPtr keyword3 = DeckKeywordPtr(new DeckKeyword("TRULSX"));
container->addKeyword(keyword1);
container->addKeyword(keyword2);
container->addKeyword(keyword3);
BOOST_CHECK_EQUAL( 0U , container->numKeywords( "TRULSY" ));
BOOST_CHECK_EQUAL( 2U , container->numKeywords( "TRULS" ));
BOOST_CHECK_EQUAL( 1U , container->numKeywords( "TRULSX" ));
}
@ -75,4 +114,3 @@ BOOST_AUTO_TEST_CASE(getKeyword_outOfRange_throws) {

View File

@ -32,6 +32,8 @@
using namespace Opm;
BOOST_AUTO_TEST_CASE( parse_WCHONHIST_OK ) {
ParserPtr parser(new Parser(JSON_CONFIG_FILE));
boost::filesystem::path wconhistFile("testdata/WCONHIST/WCONHIST1");
@ -55,4 +57,15 @@ BOOST_AUTO_TEST_CASE( parse_WCHONHIST_OK ) {
item1 = rec3->getItem("WellName");
BOOST_CHECK_EQUAL( "OP_3" , item1->getString(0));
/*****************************************************************/
BOOST_CHECK_EQUAL( 2U , deck->numKeywords("WCONHIST"));
kw1 = deck->getKeyword("WCONHIST" , 1 );
rec3 = kw1->getRecord(2);
BOOST_CHECK_EQUAL( "OP_3_B" , rec3->getItem("WellName")->getString(0));
}

View File

@ -43,7 +43,7 @@ namespace Opm {
DeckPtr deck(new Deck());
for (size_t i = 0; i < rawDeck->size(); i++) {
RawKeywordConstPtr rawKeyword = rawDeck->getKeyword(i);
if (hasKeyword(rawKeyword->getKeywordName())) {
ParserKeywordConstPtr parserKeyword = m_parserKeywords[rawKeyword->getKeywordName()];
DeckKeywordConstPtr deckKeyword = parserKeyword->parse(rawKeyword);
@ -94,6 +94,7 @@ namespace Opm {
return rawDeck;
}
/// The main data reading function, reads one and one keyword into the RawDeck
/// If the INCLUDE keyword is found, the specified include file is inline read into the RawDeck.
/// The data is read into a keyword, record by record, until the fixed number of records specified

View File

@ -1,3 +1,5 @@
add_definitions( -DJSON_CONFIG_FILE="${PROJECT_SOURCE_DIR}/opm/parser/share/parser_config.json")
add_executable(runParserTests ParserTests.cpp)
add_executable(runParserKeywordTests ParserKeywordTests.cpp)
add_executable(runParserRecordTests ParserRecordTests.cpp)

View File

@ -201,6 +201,17 @@ BOOST_AUTO_TEST_CASE(parseFromRawDeck_severalRawRecordsSeveralIntItem_deckReturn
BOOST_CHECK_EQUAL(10U, deck->getKeyword("RANDOM", 0)->size());
BOOST_CHECK_EQUAL(50U, deck->getKeyword("RANDOM", 0)->getRecord(0)->size());
}
/****************** readToRawDeck ***********************************************/
BOOST_AUTO_TEST_CASE(readToRawDeck_twoKeywords_sizeTwoReturned) {
ParserPtr parser(new Parser(JSON_CONFIG_FILE));
boost::filesystem::path wconhistFile("testdata/WCONHIST/WCONHIST1");
RawDeckPtr rawDeck = parser->readToRawDeck( wconhistFile.string() );
BOOST_CHECK_EQUAL( 2U , rawDeck->size() );
}
/***************** Simple String parsing ********************************/

View File

@ -26,8 +26,6 @@
#include <opm/parser/eclipse/RawDeck/RawKeyword.hpp>
#include <boost/test/test_tools.hpp>
#include "opm/parser/eclipse/Parser/Parser.hpp"
using namespace Opm;
BOOST_AUTO_TEST_CASE(Initialize_NoThrow) {
@ -61,3 +59,5 @@ BOOST_AUTO_TEST_CASE(addKeyword_withkeywords_keywordAdded) {

View File

@ -3,3 +3,12 @@ WCONHIST
'OP_2' 'OPEN' 'ORAT' 7998.000 2.000 1461075.000 5* /
'OP_3' 'OPEN' 'ORAT' 7999.000 1.000 1471824.000 1 0.25 0.25 0.25 1* /
/
WCONHIST
'OP_1_B' 'OPEN' 'ORAT' 2000.000 2.000 1.46402E+006 5* /
'OP_2_B' 'SHUT' 'ORAT' 2998.000 2.000 1461075.000 5* /
'OP_3_B' 'OPEN' 'GRAT' 2999.000 1.000 1471824.000 1 0.25 0.25 0.25 1* /
/