Merge pull request #397 from chflo/OPM-145

Opm 145
This commit is contained in:
Joakim Hove 2015-01-16 13:20:37 +01:00
commit b7127ae2c9
12 changed files with 47 additions and 181 deletions

View File

@ -67,10 +67,6 @@ add_executable(runCompletionsFromDeck CompletionsFromDeck.cpp)
target_link_libraries(runCompletionsFromDeck Parser ${Boost_LIBRARIES})
add_test(NAME runCompletionsFromDeck WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND ${TEST_MEMCHECK_TOOL} ${EXECUTABLE_OUTPUT_PATH}/runCompletionsFromDeck)
add_executable(runParseACTION ParseACTION.cpp)
target_link_libraries(runParseACTION Parser ${Boost_LIBRARIES})
add_test(NAME runParseACTION WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND ${TEST_MEMCHECK_TOOL} ${EXECUTABLE_OUTPUT_PATH}/runParseACTION)
add_executable(runParseEND ParseEND.cpp)
target_link_libraries(runParseEND Parser ${Boost_LIBRARIES})
add_test(NAME runParseEND WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND runParseEND)

View File

@ -1,85 +0,0 @@
/*
Copyright 2013 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/>.
*/
#define BOOST_TEST_MODULE ParserIntegrationTests
#include <boost/test/unit_test.hpp>
#include <boost/test/test_tools.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/Parser/Parser.hpp>
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
using namespace Opm;
BOOST_AUTO_TEST_CASE( parse_ACTION_OK ) {
ParserPtr parser(new Parser( false ));
boost::filesystem::path actionFile("testdata/integration_tests/ACTION/ACTION.txt");
boost::filesystem::path actionFile2("testdata/integration_tests/ACTION/ACTION_EXCEPTION.txt");
ParserKeywordConstPtr DIMENS = ParserKeyword::createFixedSized("DIMENS" , (size_t) 1 , IGNORE_WARNING );
ParserKeywordConstPtr THROW = ParserKeyword::createFixedSized("THROW" , UNKNOWN , THROW_EXCEPTION );
BOOST_REQUIRE( parser->loadKeywordFromFile( boost::filesystem::path( std::string(KEYWORD_DIRECTORY) + std::string("/W/WCONHIST") )) );
parser->addParserKeyword( DIMENS );
parser->addParserKeyword( THROW );
BOOST_REQUIRE( parser->isRecognizedKeyword( "DIMENS" ));
BOOST_REQUIRE( parser->isRecognizedKeyword( "WCONHIST" ));
BOOST_REQUIRE( parser->isRecognizedKeyword( "THROW" ));
BOOST_REQUIRE_THROW( parser->parseFile(actionFile2.string()) , std::invalid_argument );
LoggerPtr logger(new Logger);
DeckPtr deck = parser->parseFile(actionFile.string(), logger);
DeckKeywordConstPtr kw1 = deck->getKeyword("WCONHIST" , 0);
BOOST_CHECK_EQUAL( 3U , kw1->size() );
DeckRecordConstPtr rec1 = kw1->getRecord(0);
BOOST_CHECK_EQUAL( 11U , rec1->size() );
DeckRecordConstPtr rec3 = kw1->getRecord(2);
BOOST_CHECK_EQUAL( 11U , rec3->size() );
DeckItemConstPtr item1 = rec1->getItem("WELL");
DeckItemConstPtr item1_index = rec1->getItem(0);
BOOST_CHECK_EQUAL( item1 , item1_index );
BOOST_CHECK_EQUAL( "OP_1" , item1->getString(0));
item1 = rec3->getItem("WELL");
BOOST_CHECK_EQUAL( "OP_3" , item1->getString(0));
BOOST_CHECK_EQUAL( false , deck->hasKeyword( "DIMENS" ));
BOOST_CHECK_EQUAL( 1U , logger->size() );
{
BOOST_CHECK_EQUAL( actionFile.string() , logger->getFileName(0));
BOOST_CHECK_EQUAL( 2U , logger->getLineNumber(0));
}
}

View File

@ -291,15 +291,11 @@ namespace Opm {
if (isRecognizedKeyword(parserState->rawKeyword->getKeywordName())) {
ParserKeywordConstPtr parserKeyword = getParserKeywordFromDeckName(parserState->rawKeyword->getKeywordName());
ParserKeywordActionEnum action = parserKeyword->getAction();
if (action == INTERNALIZE) {
DeckKeywordPtr deckKeyword = parserKeyword->parse(parserState->rawKeyword);
deckKeyword->setParserKeyword(parserKeyword);
parserState->deck->addKeyword(deckKeyword);
} else if (action == IGNORE_WARNING)
parserState->logger.addWarning(parserState->dataFile.string(),
parserState->rawKeyword->getLineNR(),
"The keyword " + parserState->rawKeyword->getKeywordName() + " is ignored - this might potentially affect the results");
DeckKeywordPtr deckKeyword = parserKeyword->parse(parserState->rawKeyword);
deckKeyword->setParserKeyword(parserKeyword);
parserState->deck->addKeyword(deckKeyword);
} else {
DeckKeywordPtr deckKeyword(new DeckKeyword(parserState->rawKeyword->getKeywordName(), false));
deckKeyword->setLocation(parserState->rawKeyword->getFilename(),
@ -338,10 +334,6 @@ namespace Opm {
if (isRecognizedKeyword(keywordString)) {
ParserKeywordConstPtr parserKeyword = getParserKeywordFromDeckName( keywordString );
ParserKeywordActionEnum action = parserKeyword->getAction();
if (action == THROW_EXCEPTION)
throw std::invalid_argument("Parsing terminated by fatal keyword: " + keywordString);
if (parserKeyword->getSizeType() == SLASH_TERMINATED || parserKeyword->getSizeType() == UNKNOWN) {
Raw::KeywordSizeEnum rawSizeType;

View File

@ -33,11 +33,10 @@
namespace Opm {
void ParserKeyword::commonInit(const std::string& name, ParserKeywordSizeEnum sizeType , ParserKeywordActionEnum action) {
void ParserKeyword::commonInit(const std::string& name, ParserKeywordSizeEnum sizeType) {
m_isDataKeyword = false;
m_isTableCollection = false;
m_name = name;
m_action = action;
m_record = ParserRecordPtr(new ParserRecord);
m_keywordSizeType = sizeType;
m_Description = "";
@ -45,20 +44,20 @@ namespace Opm {
m_deckNames.insert(m_name);
}
ParserKeyword::ParserKeyword(const std::string& name, ParserKeywordSizeEnum sizeType, ParserKeywordActionEnum action) {
ParserKeyword::ParserKeyword(const std::string& name, ParserKeywordSizeEnum sizeType) {
if (!(sizeType == SLASH_TERMINATED || sizeType == UNKNOWN)) {
throw std::invalid_argument("Size type " + ParserKeywordSizeEnum2String(sizeType) + " cannot be set explicitly.");
}
commonInit(name, sizeType , action);
commonInit(name, sizeType);
}
ParserKeyword::ParserKeyword(const std::string& name, size_t fixedKeywordSize, ParserKeywordActionEnum action) {
commonInit(name, FIXED , action);
ParserKeyword::ParserKeyword(const std::string& name, size_t fixedKeywordSize) {
commonInit(name, FIXED);
m_fixedSize = fixedKeywordSize;
}
ParserKeyword::ParserKeyword(const std::string& name, const std::string& sizeKeyword, const std::string& sizeItem, ParserKeywordActionEnum action, bool _isTableCollection) {
commonInit(name, OTHER_KEYWORD_IN_DECK , action);
ParserKeyword::ParserKeyword(const std::string& name, const std::string& sizeKeyword, const std::string& sizeItem, bool _isTableCollection) {
commonInit(name, OTHER_KEYWORD_IN_DECK);
m_isTableCollection = _isTableCollection;
initSizeKeyword(sizeKeyword, sizeItem);
}
@ -122,14 +121,10 @@ namespace Opm {
}
ParserKeyword::ParserKeyword(const Json::JsonObject& jsonConfig) {
ParserKeywordActionEnum action = INTERNALIZE;
if (jsonConfig.has_item("action"))
action = ParserKeywordActionEnumFromString(jsonConfig.get_string("action"));
if (jsonConfig.has_item("name")) {
if (jsonConfig.has_item("name")) {
ParserKeywordSizeEnum sizeType = UNKNOWN;
commonInit(jsonConfig.get_string("name"), sizeType , action);
commonInit(jsonConfig.get_string("name"), sizeType);
} else
throw std::invalid_argument("Json object is missing the 'name' property");
@ -154,7 +149,7 @@ namespace Opm {
m_Description = jsonConfig.get_string("description");
}
if ((m_keywordSizeType == FIXED && m_fixedSize == 0) || (m_action != INTERNALIZE))
if (m_keywordSizeType == FIXED && m_fixedSize == 0)
return;
else {
if (numItems() == 0)
@ -163,23 +158,20 @@ namespace Opm {
}
ParserKeywordPtr ParserKeyword::createFixedSized(const std::string& name,
size_t fixedKeywordSize,
ParserKeywordActionEnum action) {
return ParserKeywordPtr(new ParserKeyword(name, fixedKeywordSize, action));
size_t fixedKeywordSize) {
return ParserKeywordPtr(new ParserKeyword(name, fixedKeywordSize));
}
ParserKeywordPtr ParserKeyword::createDynamicSized(const std::string& name,
ParserKeywordSizeEnum sizeType ,
ParserKeywordActionEnum action) {
return ParserKeywordPtr(new ParserKeyword(name, sizeType, action));
ParserKeywordSizeEnum sizeType) {
return ParserKeywordPtr(new ParserKeyword(name, sizeType));
}
ParserKeywordPtr ParserKeyword::createTable(const std::string& name,
const std::string& sizeKeyword,
const std::string& sizeItem,
ParserKeywordActionEnum action,
bool isTableCollection) {
return ParserKeywordPtr(new ParserKeyword(name, sizeKeyword, sizeItem, action, isTableCollection));
return ParserKeywordPtr(new ParserKeyword(name, sizeKeyword, sizeItem, isTableCollection));
}
ParserKeywordPtr ParserKeyword::createFromJson(const Json::JsonObject& jsonConfig) {
@ -481,9 +473,6 @@ namespace Opm {
return m_record;
}
ParserKeywordActionEnum ParserKeyword::getAction() const {
return m_action;
}
const std::string& ParserKeyword::getName() const {
return m_name;
@ -605,8 +594,7 @@ namespace Opm {
(m_record->equal(*(other.m_record))) &&
(m_keywordSizeType == other.m_keywordSizeType) &&
(m_isDataKeyword == other.m_isDataKeyword) &&
(m_isTableCollection == other.m_isTableCollection) &&
(m_action == other.m_action)) {
(m_isTableCollection == other.m_isTableCollection)) {
bool equal_ = false;
switch (m_keywordSizeType) {
case FIXED:
@ -630,23 +618,22 @@ namespace Opm {
void ParserKeyword::inlineNew(std::ostream& os, const std::string& lhs, const std::string& indent) const {
{
const std::string actionString(ParserKeywordActionEnum2String(m_action));
const std::string sizeString(ParserKeywordSizeEnum2String(m_keywordSizeType));
switch (m_keywordSizeType) {
case SLASH_TERMINATED:
os << lhs << " = ParserKeyword::createDynamicSized(\"" << m_name << "\"," << sizeString << "," << actionString << ");" << std::endl;
os << lhs << " = ParserKeyword::createDynamicSized(\"" << m_name << "\"," << sizeString << ");" << std::endl;
break;
case UNKNOWN:
os << lhs << " = ParserKeyword::createDynamicSized(\"" << m_name << "\"," << sizeString << "," << actionString << ");" << std::endl;
os << lhs << " = ParserKeyword::createDynamicSized(\"" << m_name << "\"," << sizeString << ");" << std::endl;
break;
case FIXED:
os << lhs << " = ParserKeyword::createFixedSized(\"" << m_name << "\",(size_t)" << m_fixedSize << "," << actionString << ");" << std::endl;
os << lhs << " = ParserKeyword::createFixedSized(\"" << m_name << "\",(size_t)" << m_fixedSize << ");" << std::endl;
break;
case OTHER_KEYWORD_IN_DECK:
if (isTableCollection())
os << lhs << " = ParserKeyword::createTable(\"" << m_name << "\",\"" << m_sizeDefinitionPair.first << "\",\"" << m_sizeDefinitionPair.second << "\"," << actionString << ", true);" << std::endl;
os << lhs << " = ParserKeyword::createTable(\"" << m_name << "\",\"" << m_sizeDefinitionPair.first << "\",\"" << m_sizeDefinitionPair.second << "\", true);" << std::endl;
else
os << lhs << " = ParserKeyword::createTable(\"" << m_name << "\",\"" << m_sizeDefinitionPair.first << "\",\"" << m_sizeDefinitionPair.second << "\"," << actionString << ");" << std::endl;
os << lhs << " = ParserKeyword::createTable(\"" << m_name << "\",\"" << m_sizeDefinitionPair.first << "\",\"" << m_sizeDefinitionPair.second << "\");" << std::endl;
break;
}
}

View File

@ -51,14 +51,11 @@ namespace Opm {
ParserKeyword(const std::string& name ,
const std::string& sizeKeyword ,
const std::string& sizeItem,
ParserKeywordActionEnum action = INTERNALIZE ,
bool isTableCollection = false);
ParserKeyword(const std::string& name ,
ParserKeywordSizeEnum sizeType = SLASH_TERMINATED ,
ParserKeywordActionEnum action = INTERNALIZE);
ParserKeywordSizeEnum sizeType = SLASH_TERMINATED);
ParserKeyword(const std::string& name ,
size_t fixedKeywordSize,
ParserKeywordActionEnum action = INTERNALIZE);
size_t fixedKeywordSize);
ParserKeyword(const Json::JsonObject& jsonConfig);
public:
@ -72,8 +69,7 @@ namespace Opm {
* This are for example well specifcation keywords like WCONPROD...
*/
static ParserKeywordPtr createFixedSized(const std::string& name,
size_t fixedKeywordSize,
ParserKeywordActionEnum action = INTERNALIZE);
size_t fixedKeywordSize);
/*!
* \brief Factory method to create a keyword with an per-se
@ -82,8 +78,7 @@ namespace Opm {
* This are for example grid properties like PERM?...
*/
static ParserKeywordPtr createDynamicSized(const std::string& name,
ParserKeywordSizeEnum sizeType = SLASH_TERMINATED ,
ParserKeywordActionEnum action = INTERNALIZE);
ParserKeywordSizeEnum sizeType = SLASH_TERMINATED);
/*!
* \brief Factory method to create a keyword which has a
@ -95,7 +90,6 @@ namespace Opm {
static ParserKeywordPtr createTable(const std::string& name,
const std::string& sizeKeyword,
const std::string& sizeItem,
ParserKeywordActionEnum action = INTERNALIZE,
bool isTableCollection = false);
/*!
@ -113,7 +107,6 @@ namespace Opm {
bool hasDimension() const;
ParserRecordPtr getRecord() const;
const std::string& getName() const;
ParserKeywordActionEnum getAction() const;
size_t getFixedSize() const;
bool hasFixedSize() const;
bool isTableCollection() const;
@ -159,7 +152,6 @@ namespace Opm {
size_t m_fixedSize;
bool m_isDataKeyword;
bool m_isTableCollection;
ParserKeywordActionEnum m_action;
std::string m_Description;
static bool validNameStart(const std::string& name);
@ -170,7 +162,7 @@ namespace Opm {
void initSize( const Json::JsonObject& jsonConfig );
void initSizeKeyword( const std::string& sizeKeyword, const std::string& sizeItem);
void initSizeKeyword(const Json::JsonObject& sizeObject);
void commonInit(const std::string& name, ParserKeywordSizeEnum sizeType , ParserKeywordActionEnum action);
void commonInit(const std::string& name, ParserKeywordSizeEnum sizeType);
void addItems( const Json::JsonObject& jsonConfig);
void initDoubleItemDimension( ParserDoubleItemPtr item, const Json::JsonObject itemConfig);
void initFloatItemDimension( ParserFloatItemPtr item, const Json::JsonObject itemConfig);

View File

@ -182,18 +182,7 @@ BOOST_AUTO_TEST_CASE(ConstructMultiNameFromJsonObject) {
BOOST_CHECK(!parserKeyword->matches("XXD"));
BOOST_CHECK(!parserKeyword->matches("XXX"));
}
BOOST_AUTO_TEST_CASE(ConstructFromJsonObjectWithActionInvalidThrows) {
Json::JsonObject jsonObject("{\"name\": \"XXX\", \"sections\":[], \"size\" : 0, \"action\" : \"WhatEver?\"}");
BOOST_CHECK_THROW(ParserKeyword::createFromJson(jsonObject) , std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(ConstructFromJsonObjectWithAction) {
Json::JsonObject jsonObject("{\"name\": \"XXX\", \"sections\":[], \"size\" : 0, \"action\" : \"IGNORE\"}");
ParserKeywordConstPtr parserKeyword = ParserKeyword::createFromJson(jsonObject);
BOOST_CHECK(parserKeyword->matches("XXX"));
BOOST_CHECK(!parserKeyword->hasMultipleDeckNames());
BOOST_CHECK_EQUAL( IGNORE , parserKeyword->getAction() );
}
BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_withSize) {
Json::JsonObject jsonObject("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : 100 , \"items\" :[{\"name\":\"ItemX\" , \"size_type\":\"SINGLE\" , \"value_type\" : \"DOUBLE\"}]}");
@ -211,10 +200,6 @@ BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_missingItemThrows) {
BOOST_CHECK_THROW( ParserKeyword::createFromJson(jsonObject) , std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_missingItemActionIgnoreOK) {
Json::JsonObject jsonObject("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : 100, \"action\" : \"IGNORE\"}");
BOOST_CHECK_NO_THROW( ParserKeyword::createFromJson(jsonObject));
}
BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_nosize_notItems_OK) {
Json::JsonObject jsonObject("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"]}");
@ -384,7 +369,7 @@ BOOST_AUTO_TEST_CASE(DefaultIsNot_TableKeyword) {
}
BOOST_AUTO_TEST_CASE(ConstructorIsTableCollection) {
ParserKeywordPtr parserKeyword = ParserKeyword::createTable("JA" , "TABDIMS" , "NTPVT" , INTERNALIZE , true);
ParserKeywordPtr parserKeyword = ParserKeyword::createTable("JA" , "TABDIMS" , "NTPVT" , true);
const std::pair<std::string,std::string>& sizeKW = parserKeyword->getSizeDefinitionPair();
BOOST_CHECK(parserKeyword->isTableCollection());
BOOST_CHECK(!parserKeyword->hasFixedSize());
@ -413,17 +398,7 @@ BOOST_AUTO_TEST_CASE(ParseEmptyRecord) {
BOOST_CHECK_EQUAL(0U , deckItem->size());
}
/*****************************************************************/
/* Action value */
BOOST_AUTO_TEST_CASE(DefaultActionISINTERNALIZE) {
ParserKeywordPtr parserKeyword = ParserKeyword::createDynamicSized("JA");
BOOST_CHECK_EQUAL(INTERNALIZE , parserKeyword->getAction());
}
BOOST_AUTO_TEST_CASE(CreateWithAction) {
ParserKeywordPtr parserKeyword = ParserKeyword::createDynamicSized("JA" , UNKNOWN , IGNORE);
BOOST_CHECK_EQUAL(IGNORE , parserKeyword->getAction());
}
/*****************************************************************/
/* Dimension */

View File

@ -1 +1 @@
{"name" : "EXCEL" , "sections" : ["SUMMARY"], "action" : "IGNORE_WARNING"}
{"name" : "EXCEL" , "sections" : ["SUMMARY"] }

View File

@ -1,4 +1,4 @@
{"name":"NEXTSTEP", "sections" : ["SCHEDULE"], "size" : 1 , "action" : "IGNORE_WARNING",
{"name":"NEXTSTEP", "sections" : ["SCHEDULE"], "size" : 1 ,
"items" : [
{"name" : "MAX_STEP" , "value_type" : "DOUBLE" , "dimension" : "Time"},
{"name" : "APPLY_TO_ALL" , "value_type" : "STRING" , "default" : "NO"}]}

View File

@ -1 +1 @@
{"name" : "RUNSUM" , "sections" : ["SUMMARY"], "action" : "IGNORE_WARNING"}
{"name" : "RUNSUM" , "sections" : ["SUMMARY"]}

View File

@ -1 +1 @@
{"name":"SEPARATE", "sections" : ["SUMMARY"], "action":"IGNORE_WARNING"}
{"name":"SEPARATE", "sections" : ["SUMMARY"]}

View File

@ -1 +1,10 @@
{"name" : "TUNING" , "sections" : ["SCHEDULE"], "size" : 3 , "action" : "IGNORE_WARNING"}
{"name" : "TUNING" ,
"sections" : ["SCHEDULE"],
"size" : 3 ,
"items" : [{
"name" : "tuning" ,
"value_type" : "STRING" ,
"size_type" : "ALL"}] }

View File

@ -1 +1 @@
{"name" : "WCONINJ" , "sections" : ["SCHEDULE"], "action" : "THROW_EXCEPTION"}
{"name" : "WCONINJ" , "sections" : ["SCHEDULE"]}