@@ -21,12 +21,14 @@
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
|
||||
#include <iostream>
|
||||
#include <boost/algorithm/string/join.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
EclipseState::EclipseState(DeckConstPtr deck) {
|
||||
initPhases(deck);
|
||||
initSchedule(deck);
|
||||
initTitle(deck);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +37,10 @@ namespace Opm {
|
||||
}
|
||||
|
||||
|
||||
std::string EclipseState::getTitle() const {
|
||||
return m_title;
|
||||
}
|
||||
|
||||
void EclipseState::initSchedule(DeckConstPtr deck) {
|
||||
schedule = ScheduleConstPtr( new Schedule(deck) );
|
||||
}
|
||||
@@ -56,4 +62,13 @@ namespace Opm {
|
||||
return (phases.count(phase) == 1);
|
||||
}
|
||||
|
||||
void EclipseState::initTitle(DeckConstPtr deck){
|
||||
if (deck->hasKeyword("TITLE")) {
|
||||
DeckKeywordConstPtr titleKeyword = deck->getKeyword("TITLE");
|
||||
DeckRecordConstPtr record = titleKeyword->getRecord(0);
|
||||
DeckItemPtr item = record->getItem(0);
|
||||
std::vector<std::string> itemValue = item->getStringData();
|
||||
m_title = boost::algorithm::join(itemValue, " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,13 +34,16 @@ namespace Opm {
|
||||
EclipseState(DeckConstPtr deck);
|
||||
ScheduleConstPtr getSchedule() const;
|
||||
bool hasPhase(enum Phase::PhaseEnum phase) const;
|
||||
std::string getTitle() const;
|
||||
|
||||
private:
|
||||
void initSchedule(DeckConstPtr deck);
|
||||
void initPhases(DeckConstPtr deck);
|
||||
void initTitle(DeckConstPtr deck);
|
||||
|
||||
ScheduleConstPtr schedule;
|
||||
std::set<enum Phase::PhaseEnum> phases;
|
||||
std::string m_title;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<EclipseState> EclipseStatePtr;
|
||||
|
||||
@@ -39,6 +39,9 @@ DeckPtr createDeck() {
|
||||
DeckKeywordPtr oilKeyword(new DeckKeyword("OIL"));
|
||||
DeckKeywordPtr gasKeyword(new DeckKeyword("GAS"));
|
||||
|
||||
DeckKeywordPtr titleKeyword(new DeckKeyword("TITLE"));
|
||||
DeckRecordPtr titleRecord(new DeckRecord());
|
||||
DeckStringItemPtr titleItem(new DeckStringItem("TITLE") );
|
||||
|
||||
DeckKeywordPtr scheduleKeyword(new DeckKeyword("SCHEDULE"));
|
||||
DeckKeywordPtr startKeyword(new DeckKeyword("START"));
|
||||
@@ -57,10 +60,16 @@ DeckPtr createDeck() {
|
||||
startRecord->addItem( yearItem );
|
||||
startKeyword->addRecord( startRecord );
|
||||
|
||||
titleItem->push_back( "The" );
|
||||
titleItem->push_back( "title" );
|
||||
titleRecord->addItem( titleItem );
|
||||
titleKeyword->addRecord( titleRecord );
|
||||
|
||||
deck->addKeyword( oilKeyword );
|
||||
deck->addKeyword( gasKeyword );
|
||||
deck->addKeyword( startKeyword );
|
||||
deck->addKeyword( scheduleKeyword );
|
||||
deck->addKeyword( titleKeyword );
|
||||
|
||||
return deck;
|
||||
}
|
||||
@@ -85,3 +94,11 @@ BOOST_AUTO_TEST_CASE(PhasesCorrect) {
|
||||
BOOST_CHECK( state.hasPhase( Phase::PhaseEnum::GAS ));
|
||||
BOOST_CHECK( !state.hasPhase( Phase::PhaseEnum::WATER ));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TitleCorrect) {
|
||||
DeckPtr deck = createDeck();
|
||||
EclipseState state(deck);
|
||||
|
||||
BOOST_CHECK_EQUAL( state.getTitle(), "The title");
|
||||
}
|
||||
|
||||
@@ -6,6 +6,10 @@ add_test(NAME runIntegrationTests WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} CO
|
||||
set_property(SOURCE IntegrationTests.cpp PROPERTY COMPILE_FLAGS "-Wno-error")
|
||||
|
||||
|
||||
add_executable(runParseTITLE ParseTITLE.cpp)
|
||||
target_link_libraries(runParseTITLE Parser ${Boost_LIBRARIES})
|
||||
add_test(NAME runParseTITLE WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND runParseTITLE)
|
||||
|
||||
add_executable(runParseWCONHIST ParseWCONHIST.cpp)
|
||||
target_link_libraries(runParseWCONHIST Parser ${Boost_LIBRARIES})
|
||||
add_test(NAME runParseWCONHIST WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND runParseWCONHIST)
|
||||
@@ -38,6 +42,10 @@ add_executable(runParseACTION ParseACTION.cpp)
|
||||
target_link_libraries(runParseACTION Parser ${Boost_LIBRARIES})
|
||||
add_test(NAME runParseACTION WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND runParseACTION)
|
||||
|
||||
add_executable(runParseEND ParseEND.cpp)
|
||||
target_link_libraries(runParseEND Parser ${Boost_LIBRARIES})
|
||||
add_test(NAME runParseEND WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND runParseEND)
|
||||
|
||||
add_executable(runIncludeTest IncludeTest.cpp)
|
||||
target_link_libraries(runIncludeTest Parser ${Boost_LIBRARIES})
|
||||
add_test(NAME runIncludeTest WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND runIncludeTest)
|
||||
|
||||
@@ -36,7 +36,7 @@ using namespace Opm;
|
||||
using namespace boost::filesystem;
|
||||
|
||||
void
|
||||
createDeckWithInclude(path& datafile)
|
||||
createDeckWithInclude(path& datafile, std::string addEndKeyword)
|
||||
{
|
||||
path root = unique_path("/tmp/%%%%-%%%%");
|
||||
path absoluteInclude = root / "absolute.include";
|
||||
@@ -65,13 +65,6 @@ createDeckWithInclude(path& datafile)
|
||||
|
||||
of.close();
|
||||
}
|
||||
{
|
||||
std::ofstream of(absoluteInclude.string().c_str());
|
||||
|
||||
of << "DIMENS" << std::endl;
|
||||
of << " 10 20 30 /" << std::endl;
|
||||
of.close();
|
||||
}
|
||||
|
||||
{
|
||||
path relativeInclude = root / "relative.include";
|
||||
@@ -82,6 +75,17 @@ createDeckWithInclude(path& datafile)
|
||||
of.close();
|
||||
}
|
||||
|
||||
{
|
||||
std::ofstream of(absoluteInclude.string().c_str());
|
||||
|
||||
if (addEndKeyword.length() > 0) {
|
||||
of << addEndKeyword << std::endl;
|
||||
}
|
||||
of << "DIMENS" << std::endl;
|
||||
of << " 10 20 30 /" << std::endl;
|
||||
of.close();
|
||||
}
|
||||
|
||||
{
|
||||
path nestedInclude = includePath / "nested.include";
|
||||
path gridInclude = includePath / "grid.include";
|
||||
@@ -96,6 +100,7 @@ createDeckWithInclude(path& datafile)
|
||||
of2 << "/" << std::endl;
|
||||
of2.close();
|
||||
}
|
||||
std::cout << datafile << std::endl;
|
||||
|
||||
|
||||
}
|
||||
@@ -106,11 +111,32 @@ createDeckWithInclude(path& datafile)
|
||||
BOOST_AUTO_TEST_CASE(parse_fileWithWWCTKeyword_deckReturned) {
|
||||
path datafile;
|
||||
ParserPtr parser(new Parser());
|
||||
createDeckWithInclude (datafile);
|
||||
createDeckWithInclude (datafile, "");
|
||||
DeckConstPtr deck = parser->parseFile(datafile.string());
|
||||
|
||||
BOOST_CHECK( deck->hasKeyword("DIMENS"));
|
||||
BOOST_CHECK( deck->hasKeyword("START"));
|
||||
BOOST_CHECK( deck->hasKeyword("DIMENS"));
|
||||
BOOST_CHECK( deck->hasKeyword("GRIDUNIT"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_fileWithENDINCKeyword_deckReturned) {
|
||||
path datafile;
|
||||
ParserPtr parser(new Parser());
|
||||
createDeckWithInclude (datafile, "ENDINC");
|
||||
DeckConstPtr deck = parser->parseFile(datafile.string());
|
||||
|
||||
BOOST_CHECK( deck->hasKeyword("START"));
|
||||
BOOST_CHECK( !deck->hasKeyword("DIMENS"));
|
||||
BOOST_CHECK( deck->hasKeyword("GRIDUNIT"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_fileWithENDKeyword_deckReturned) {
|
||||
path datafile;
|
||||
ParserPtr parser(new Parser());
|
||||
createDeckWithInclude (datafile, "END");
|
||||
DeckConstPtr deck = parser->parseFile(datafile.string());
|
||||
|
||||
BOOST_CHECK( deck->hasKeyword("START"));
|
||||
BOOST_CHECK( !deck->hasKeyword("DIMENS"));
|
||||
BOOST_CHECK( !deck->hasKeyword("GRIDUNIT"));
|
||||
}
|
||||
|
||||
61
opm/parser/eclipse/IntegrationTests/ParseEND.cpp
Normal file
61
opm/parser/eclipse/IntegrationTests/ParseEND.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
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_END_OK ) {
|
||||
ParserPtr parser(new Parser());
|
||||
boost::filesystem::path fileWithTitleKeyword("testdata/integration_tests/END/END1.txt");
|
||||
|
||||
DeckPtr deck = parser->parseFile (fileWithTitleKeyword.string(), true);
|
||||
|
||||
BOOST_CHECK_EQUAL(size_t(1), deck->size());
|
||||
BOOST_CHECK_EQUAL (true, deck->hasKeyword("OIL"));
|
||||
BOOST_CHECK_EQUAL (false, deck->hasKeyword("GAS"));
|
||||
BOOST_CHECK_EQUAL (false, deck->hasKeyword("END"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( parse_ENDINC_OK ) {
|
||||
ParserPtr parser(new Parser());
|
||||
boost::filesystem::path fileWithTitleKeyword("testdata/integration_tests/END/ENDINC1.txt");
|
||||
|
||||
DeckPtr deck = parser->parseFile (fileWithTitleKeyword.string(), true);
|
||||
|
||||
BOOST_CHECK_EQUAL(size_t(1), deck->size());
|
||||
BOOST_CHECK_EQUAL (true, deck->hasKeyword("OIL"));
|
||||
BOOST_CHECK_EQUAL (false, deck->hasKeyword("GAS"));
|
||||
BOOST_CHECK_EQUAL (false, deck->hasKeyword("ENDINC"));
|
||||
}
|
||||
|
||||
58
opm/parser/eclipse/IntegrationTests/ParseTITLE.cpp
Normal file
58
opm/parser/eclipse/IntegrationTests/ParseTITLE.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
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 <boost/algorithm/string/join.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_TITLE_OK ) {
|
||||
ParserPtr parser(new Parser());
|
||||
boost::filesystem::path fileWithTitleKeyword("testdata/integration_tests/TITLE/TITLE1.txt");
|
||||
|
||||
DeckPtr deck = parser->parseFile (fileWithTitleKeyword.string(), true);
|
||||
|
||||
BOOST_CHECK_EQUAL(size_t(2), deck->size());
|
||||
BOOST_CHECK_EQUAL (true, deck->hasKeyword("TITLE"));
|
||||
DeckKeywordConstPtr titleKeyword = deck->getKeyword("TITLE");
|
||||
DeckRecordConstPtr record = titleKeyword->getRecord(0);
|
||||
DeckItemPtr item = record->getItem(0);
|
||||
std::vector<std::string> itemValue = item->getStringData();
|
||||
std::string itemValueString = boost::algorithm::join(itemValue, " ");
|
||||
|
||||
BOOST_CHECK_EQUAL (0, itemValueString.compare("This is the title of the model."));
|
||||
BOOST_CHECK_EQUAL (true, deck->hasKeyword("START"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -179,14 +179,22 @@ namespace Opm {
|
||||
}
|
||||
|
||||
|
||||
void Parser::parseStream(std::shared_ptr<ParserState> parserState) const {
|
||||
bool Parser::parseStream(std::shared_ptr<ParserState> parserState) const {
|
||||
bool verbose = false;
|
||||
bool stopParsing = false;
|
||||
|
||||
if (parserState->inputstream) {
|
||||
while (true) {
|
||||
bool streamOK = tryParseKeyword(parserState);
|
||||
if (parserState->rawKeyword) {
|
||||
if (parserState->rawKeyword->getKeywordName() == Opm::RawConsts::include) {
|
||||
if (parserState->rawKeyword->getKeywordName() == Opm::RawConsts::end) {
|
||||
stopParsing = true;
|
||||
break;
|
||||
}
|
||||
else if (parserState->rawKeyword->getKeywordName() == Opm::RawConsts::endinclude) {
|
||||
break;
|
||||
}
|
||||
else if (parserState->rawKeyword->getKeywordName() == Opm::RawConsts::include) {
|
||||
RawRecordConstPtr firstRecord = parserState->rawKeyword->getRecord(0);
|
||||
std::string includeFileString = firstRecord->getItem(0);
|
||||
boost::filesystem::path includeFile(includeFileString);
|
||||
@@ -198,7 +206,8 @@ namespace Opm {
|
||||
std::cout << parserState->rawKeyword->getKeywordName() << " " << includeFile << std::endl;
|
||||
|
||||
std::shared_ptr<ParserState> newParserState (new ParserState(includeFile.string(), parserState->deck, parserState->rootPath, parserState->strictParsing));
|
||||
parseStream(newParserState);
|
||||
stopParsing = parseStream(newParserState);
|
||||
if (stopParsing) break;
|
||||
} else {
|
||||
if (verbose)
|
||||
std::cout << parserState->rawKeyword->getKeywordName() << std::endl;
|
||||
@@ -224,6 +233,7 @@ namespace Opm {
|
||||
}
|
||||
} else
|
||||
throw std::invalid_argument("Failed to open file: " + parserState->dataFile.string());
|
||||
return stopParsing;
|
||||
}
|
||||
|
||||
|
||||
@@ -282,6 +292,12 @@ namespace Opm {
|
||||
}
|
||||
|
||||
|
||||
std::string Parser::doSpecialHandlingForTitleKeyword(std::string line, std::shared_ptr<ParserState> parserState) const {
|
||||
if ((parserState->rawKeyword != NULL) && (parserState->rawKeyword->getKeywordName() == "TITLE"))
|
||||
line = line.append("/");
|
||||
return line;
|
||||
}
|
||||
|
||||
bool Parser::tryParseKeyword(std::shared_ptr<ParserState> parserState) const {
|
||||
std::string line;
|
||||
|
||||
@@ -292,6 +308,7 @@ namespace Opm {
|
||||
|
||||
while (std::getline(*parserState->inputstream, line)) {
|
||||
boost::algorithm::trim_right(line); // Removing garbage (eg. \r)
|
||||
line = doSpecialHandlingForTitleKeyword(line, parserState);
|
||||
std::string keywordString;
|
||||
parserState->lineNR++;
|
||||
if (parserState->rawKeyword == NULL) {
|
||||
|
||||
@@ -71,11 +71,12 @@ namespace Opm {
|
||||
ParserKeywordConstPtr matchingKeyword(const std::string& keyword) const;
|
||||
|
||||
bool tryParseKeyword(std::shared_ptr<ParserState> parserState) const;
|
||||
void parseStream(std::shared_ptr<ParserState> parserState) const;
|
||||
bool parseStream(std::shared_ptr<ParserState> parserState) const;
|
||||
RawKeywordPtr createRawKeyword(const std::string& keywordString, std::shared_ptr<ParserState> parserState) const;
|
||||
void addDefaultKeywords();
|
||||
|
||||
boost::filesystem::path getRootPathFromFile(const boost::filesystem::path &inputDataFile) const;
|
||||
std::string doSpecialHandlingForTitleKeyword(std::string line, std::shared_ptr<ParserState> parserState) const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@ namespace Opm {
|
||||
const char quote = '\'';
|
||||
const std::string separators = "\t ";
|
||||
const std::string include = "INCLUDE";
|
||||
const std::string end = "END";
|
||||
const std::string endinclude = "ENDINC";
|
||||
const unsigned int maxKeywordLength = 8;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"name":"END", "action":"IGNORE_WARNING"}
|
||||
{"name" : "END"}
|
||||
|
||||
1
opm/parser/share/keywords/E/ENDINC
Normal file
1
opm/parser/share/keywords/E/ENDINC
Normal file
@@ -0,0 +1 @@
|
||||
{"name" : "ENDINC"}
|
||||
2
opm/parser/share/keywords/T/TITLE
Normal file
2
opm/parser/share/keywords/T/TITLE
Normal file
@@ -0,0 +1,2 @@
|
||||
{"name" : "TITLE" , "size" : 1 , "items" : [
|
||||
{"name" : "TitleText" , "value_type" : "STRING", "size_type" : "ALL"}]}
|
||||
14
testdata/integration_tests/END/END1.txt
vendored
Normal file
14
testdata/integration_tests/END/END1.txt
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
OIL
|
||||
-- Comment
|
||||
|
||||
END
|
||||
-- This keyword should cause the parser to terminate
|
||||
/
|
||||
|
||||
GAS
|
||||
-- Comment
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
14
testdata/integration_tests/END/ENDINC1.txt
vendored
Normal file
14
testdata/integration_tests/END/ENDINC1.txt
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
OIL
|
||||
-- Comment
|
||||
|
||||
ENDINC
|
||||
-- This keyword should cause the parser to terminate
|
||||
|
||||
|
||||
GAS
|
||||
-- Comment
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
4
testdata/integration_tests/TITLE/TITLE1.txt
vendored
Normal file
4
testdata/integration_tests/TITLE/TITLE1.txt
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
TITLE
|
||||
This is the title of the model.
|
||||
START
|
||||
10 'FEB' 2012
|
||||
Reference in New Issue
Block a user