Review updates: Keyword can have numbers, comment lines can start with space, data can start at pos 0 on line, must explicitly have end-of-keyword control
This commit is contained in:
@@ -21,18 +21,50 @@
|
||||
namespace Opm {
|
||||
|
||||
Parser::Parser() {
|
||||
initializeFixedKeywordLenghts();
|
||||
|
||||
}
|
||||
|
||||
RawDeckPtr Parser::parse(const std::string &path) {
|
||||
Logger::initLogger();
|
||||
Logger::setLogLevel(Logger::DEBUG);
|
||||
Logger::info("Starting parsing of file: " + path);
|
||||
RawDeckPtr rawDeck(new RawDeck());
|
||||
rawDeck -> readDataIntoDeck(path);
|
||||
RawDeckPtr rawDeck(new RawDeck(m_keywordRecordLengths));
|
||||
rawDeck->readDataIntoDeck(path);
|
||||
Logger::info("Done parsing of file: " + path);
|
||||
return rawDeck;
|
||||
}
|
||||
|
||||
void Parser::initializeFixedKeywordLenghts() {
|
||||
m_keywordRecordLengths.insert(std::pair<std::string, int>("GRIDUNIT", 1));
|
||||
m_keywordRecordLengths.insert(std::pair<std::string, int>("INCLUDE", 1));
|
||||
m_keywordRecordLengths.insert(std::pair<std::string, int>("RADFIN4", 1));
|
||||
m_keywordRecordLengths.insert(std::pair<std::string, int>("DIMENS", 1));
|
||||
m_keywordRecordLengths.insert(std::pair<std::string, int>("START", 1));
|
||||
m_keywordRecordLengths.insert(std::pair<std::string, int>("GRIDOPTS", 1));
|
||||
m_keywordRecordLengths.insert(std::pair<std::string, int>("ENDSCALE", 1));
|
||||
m_keywordRecordLengths.insert(std::pair<std::string, int>("EQLOPTS", 1));
|
||||
m_keywordRecordLengths.insert(std::pair<std::string, int>("TABDIMS", 1));
|
||||
m_keywordRecordLengths.insert(std::pair<std::string, int>("EQLDIMS", 1));
|
||||
m_keywordRecordLengths.insert(std::pair<std::string, int>("REGDIMS", 1));
|
||||
m_keywordRecordLengths.insert(std::pair<std::string, int>("FAULTDIM", 1));
|
||||
m_keywordRecordLengths.insert(std::pair<std::string, int>("WELLDIMS", 1));
|
||||
m_keywordRecordLengths.insert(std::pair<std::string, int>("VFPPDIMS", 1));
|
||||
m_keywordRecordLengths.insert(std::pair<std::string, int>("RPTSCHED", 1));
|
||||
m_keywordRecordLengths.insert(std::pair<std::string, int>("TITLE", 0));
|
||||
m_keywordRecordLengths.insert(std::pair<std::string, int>("RUNSPEC", 0));
|
||||
m_keywordRecordLengths.insert(std::pair<std::string, int>("METRIC", 0));
|
||||
m_keywordRecordLengths.insert(std::pair<std::string, int>("SCHEDULE", 0));
|
||||
m_keywordRecordLengths.insert(std::pair<std::string, int>("SKIPREST", 0));
|
||||
m_keywordRecordLengths.insert(std::pair<std::string, int>("NOECHO", 0));
|
||||
m_keywordRecordLengths.insert(std::pair<std::string, int>("END", 0));
|
||||
m_keywordRecordLengths.insert(std::pair<std::string, int>("OIL", 0));
|
||||
m_keywordRecordLengths.insert(std::pair<std::string, int>("GAS", 0));
|
||||
m_keywordRecordLengths.insert(std::pair<std::string, int>("WATER", 0));
|
||||
m_keywordRecordLengths.insert(std::pair<std::string, int>("DISGAS", 0));
|
||||
m_keywordRecordLengths.insert(std::pair<std::string, int>("VAPOIL", 0));
|
||||
}
|
||||
|
||||
Parser::~Parser() {
|
||||
}
|
||||
} // namespace Opm
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#ifndef PARSER_H
|
||||
#define PARSER_H
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Logger.hpp>
|
||||
@@ -36,7 +36,8 @@ namespace Opm {
|
||||
RawDeckPtr parse(const std::string &path);
|
||||
virtual ~Parser();
|
||||
private:
|
||||
//Logger m_logger;
|
||||
std::map<std::string, int> m_keywordRecordLengths;
|
||||
void initializeFixedKeywordLenghts();
|
||||
};
|
||||
|
||||
typedef boost::shared_ptr<Parser> ParserPtr;
|
||||
|
||||
@@ -23,16 +23,17 @@
|
||||
|
||||
namespace Opm {
|
||||
|
||||
RawDeck::RawDeck() {
|
||||
RawDeck::RawDeck(std::map<std::string, int>& keywordsWithFixedRecordNums) {
|
||||
m_keywordsWithFixedRecordNums = keywordsWithFixedRecordNums;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Iterate through list of RawKeywords in search for the specified string.
|
||||
* O(n), not using map or hash because the keywords are not unique,
|
||||
* and the order matters. Returns first matching keyword.
|
||||
*/
|
||||
RawKeywordPtr RawDeck::getKeyword(const std::string& keyword) {
|
||||
for(std::list<RawKeywordPtr>::iterator it = m_keywords.begin(); it != m_keywords.end(); it++) {
|
||||
for (std::list<RawKeywordPtr>::iterator it = m_keywords.begin(); it != m_keywords.end(); it++) {
|
||||
if ((*it)->getKeyword() == keyword) {
|
||||
return (*it);
|
||||
}
|
||||
@@ -45,44 +46,38 @@ namespace Opm {
|
||||
* Throws invalid_argument exception if path not valid.
|
||||
*/
|
||||
void RawDeck::readDataIntoDeck(const std::string& path) {
|
||||
readDataIntoDeck(path, m_keywords);
|
||||
}
|
||||
|
||||
void RawDeck::readDataIntoDeck(const std::string& path, std::list<RawKeywordPtr>& keywordList) {
|
||||
checkInputFile(path);
|
||||
std::ifstream inputstream;
|
||||
Logger::info("Initializing from file: " + path);
|
||||
inputstream.open(path.c_str());
|
||||
{
|
||||
std::ifstream inputstream;
|
||||
Logger::info("Initializing from file: " + path);
|
||||
inputstream.open(path.c_str());
|
||||
|
||||
std::string line;
|
||||
std::string keywordString;
|
||||
RawKeywordPtr currentRawKeyword;
|
||||
while (std::getline(inputstream, line)) {
|
||||
if (RawKeyword::tryParseKeyword(line, keywordString)) {
|
||||
currentRawKeyword = RawKeywordPtr(new RawKeyword(keywordString));
|
||||
m_keywords.push_back(currentRawKeyword);
|
||||
} else if (currentRawKeyword != NULL) {
|
||||
addRawRecordStringToRawKeyword(line, currentRawKeyword);
|
||||
std::string line;
|
||||
RawKeywordPtr currentRawKeyword;
|
||||
int numberOfRecordsForCurrentKeyword = 0;
|
||||
bool previousKeywordFinished = true;
|
||||
while (std::getline(inputstream, line)) {
|
||||
std::string keywordString;
|
||||
|
||||
if (previousKeywordFinished && RawKeyword::tryParseKeyword(line, keywordString)) {
|
||||
currentRawKeyword = RawKeywordPtr(new RawKeyword(keywordString));
|
||||
keywordList.push_back(currentRawKeyword);
|
||||
previousKeywordFinished = isKeywordFinished(currentRawKeyword);
|
||||
}
|
||||
else if (currentRawKeyword != NULL && RawKeyword::lineContainsData(line)) {
|
||||
currentRawKeyword->addRawRecordString(line);
|
||||
numberOfRecordsForCurrentKeyword = currentRawKeyword->getNumberOfRecords();
|
||||
previousKeywordFinished = isKeywordFinished(currentRawKeyword);
|
||||
}
|
||||
else if (RawKeyword::lineTerminatesKeyword(line)) {
|
||||
previousKeywordFinished = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
inputstream.close();
|
||||
}
|
||||
|
||||
void RawDeck::addRawRecordStringToRawKeyword(const std::string& recordCandidate, RawKeywordPtr currentRawKeyword) {
|
||||
if (looksLikeData(recordCandidate)) {
|
||||
currentRawKeyword->addRawRecordString(recordCandidate);
|
||||
}
|
||||
}
|
||||
|
||||
bool RawDeck::looksLikeData(const std::string& line) {
|
||||
if (line.substr(0, 2) == "--") {
|
||||
Logger::debug("COMMENT LINE <" + line + ">");
|
||||
return false;
|
||||
} else if (boost::algorithm::trim_copy(line).length() == 0) {
|
||||
Logger::debug("EMPTY LINE <" + line + ">");
|
||||
return false;
|
||||
} else if (line.substr(0, 1) == "/") {
|
||||
Logger::debug("END OF RECORD <" + line + ">");
|
||||
return false;
|
||||
} else {
|
||||
Logger::debug("LOOKS LIKE DATA<" + line + ">");
|
||||
return true;
|
||||
inputstream.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,6 +93,32 @@ namespace Opm {
|
||||
return m_keywords.size();
|
||||
}
|
||||
|
||||
bool RawDeck::isKeywordFinished(RawKeywordPtr rawKeyword) {
|
||||
if ((unsigned)m_keywordsWithFixedRecordNums.count(rawKeyword->getKeyword()) != 0) {
|
||||
return rawKeyword->getNumberOfRecords() == (unsigned)m_keywordsWithFixedRecordNums[rawKeyword->getKeyword()];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const RawDeck& deck) {
|
||||
for (std::list<RawKeywordPtr>::const_iterator keyword = deck.m_keywords.begin(); keyword != deck.m_keywords.end(); keyword++) {
|
||||
os << (*keyword)->getKeyword() << " -- Keyword\n";
|
||||
std::list<RawRecordPtr> records;
|
||||
(*keyword)->getRecords(records);
|
||||
for (std::list<RawRecordPtr>::const_iterator record = records.begin(); record != records.end(); record++) {
|
||||
std::vector<std::string> recordItems;
|
||||
(*record)->getRecords(recordItems);
|
||||
|
||||
for (std::vector<std::string>::const_iterator recordItem = recordItems.begin(); recordItem != recordItems.end(); recordItem++) {
|
||||
os << (*recordItem) << " ";
|
||||
}
|
||||
os << " / -- Data\n";
|
||||
}
|
||||
os << "\n";
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
RawDeck::~RawDeck() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,27 @@
|
||||
/*
|
||||
* File: RawDeck.hpp
|
||||
* Author: kflik
|
||||
*
|
||||
* Created on March 21, 2013, 2:02 PM
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef RAWDECK_HPP
|
||||
#define RAWDECK_HPP
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
#include <map>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include "opm/parser/eclipse/Logger.hpp"
|
||||
#include "RawKeyword.hpp"
|
||||
@@ -17,18 +30,20 @@ namespace Opm {
|
||||
|
||||
class RawDeck {
|
||||
public:
|
||||
RawDeck();
|
||||
RawDeck(std::map<std::string, int>& keywordsWithFixedRecordNums);
|
||||
void readDataIntoDeck(const std::string& path);
|
||||
RawKeywordPtr getKeyword(const std::string& keyword);
|
||||
unsigned int getNumberOfKeywords();
|
||||
friend std::ostream& operator<<(std::ostream& os, const RawDeck& deck);
|
||||
virtual ~RawDeck();
|
||||
private:
|
||||
std::list<RawKeywordPtr> m_keywords;
|
||||
void addRawRecordStringToRawKeyword(const std::string& line, RawKeywordPtr currentRawKeyword);
|
||||
bool looksLikeData(const std::string& line);
|
||||
void checkInputFile(const std::string& inputPath);
|
||||
std::map<std::string, int> m_keywordsWithFixedRecordNums;
|
||||
void readDataIntoDeck(const std::string& path, std::list<RawKeywordPtr>& keywordList);
|
||||
bool isKeywordFinished(RawKeywordPtr rawKeyword);
|
||||
static void checkInputFile(const std::string& inputPath);
|
||||
};
|
||||
|
||||
|
||||
typedef boost::shared_ptr<RawDeck> RawDeckPtr;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <iostream>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
RawKeyword::RawKeyword() {
|
||||
}
|
||||
|
||||
@@ -30,7 +31,7 @@ namespace Opm {
|
||||
setKeyword(keyword);
|
||||
}
|
||||
|
||||
bool RawKeyword::tryParseKeyword(const std::string& keywordCandidate, std::string& result) {
|
||||
bool RawKeyword::tryParseKeyword(const std::string& keywordCandidate, std::string& result) {
|
||||
result = boost::trim_right_copy(keywordCandidate.substr(0, 8));
|
||||
if (isValidKeyword(result)) {
|
||||
Logger::debug("KEYWORD <" + keywordCandidate + ">");
|
||||
@@ -38,25 +39,45 @@ namespace Opm {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool RawKeyword::isValidKeyword(const std::string& keywordCandidate) {
|
||||
std::string keywordRegex = "^[A-Z]{1,8}$";
|
||||
std::string keywordRegex = "^[A-Z][A-Z,0-9]{1,7}$";
|
||||
int status;
|
||||
regex_t re;
|
||||
regex_t regularExpression;
|
||||
regmatch_t rm;
|
||||
if (regcomp(&re, keywordRegex.c_str(), REG_EXTENDED) != 0) {
|
||||
if (regcomp(®ularExpression, keywordRegex.c_str(), REG_EXTENDED) != 0) {
|
||||
throw std::runtime_error("Unable to compile regular expression for keyword! Expression: " + keywordRegex);
|
||||
}
|
||||
|
||||
status = regexec(&re, keywordCandidate.c_str(), 1, &rm, 0);
|
||||
regfree(&re);
|
||||
status = regexec(®ularExpression, keywordCandidate.c_str(), 1, &rm, 0);
|
||||
regfree(®ularExpression);
|
||||
|
||||
if (status == 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool RawKeyword::lineContainsData(const std::string& line) {
|
||||
if (boost::algorithm::trim_left_copy(line).substr(0, 2) == "--") {
|
||||
Logger::debug("COMMENT LINE <" + line + ">");
|
||||
return false;
|
||||
} else if (boost::algorithm::trim_copy(line).length() == 0) {
|
||||
Logger::debug("EMPTY LINE <" + line + ">");
|
||||
return false;
|
||||
} else if (lineTerminatesKeyword(line)) {
|
||||
Logger::debug("END OF RECORD <" + line + ">");
|
||||
return false;
|
||||
} else {
|
||||
Logger::debug("LOOKS LIKE DATA<" + line + ">");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool RawKeyword::lineTerminatesKeyword(const std::string& line) {
|
||||
return boost::algorithm::trim_left_copy(line).substr(0,1) == "/";
|
||||
}
|
||||
|
||||
void RawKeyword::setKeyword(const std::string& keyword) {
|
||||
m_keyword = boost::algorithm::trim_right_copy(keyword);
|
||||
if (!isValidKeyword(m_keyword)) {
|
||||
|
||||
@@ -1,8 +1,20 @@
|
||||
/*
|
||||
* File: KeywordRawData.hpp
|
||||
* Author: kflik
|
||||
*
|
||||
* Created on March 20, 2013, 3:59 PM
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef RAWKEYWORD_HPP
|
||||
@@ -17,11 +29,15 @@
|
||||
#include "RawRecord.hpp"
|
||||
|
||||
namespace Opm {
|
||||
|
||||
class RawKeyword {
|
||||
public:
|
||||
RawKeyword();
|
||||
RawKeyword(const std::string& keyword);
|
||||
static bool tryParseKeyword(const std::string& line, std::string& result);
|
||||
static bool lineContainsData(const std::string& line);
|
||||
static bool lineTerminatesKeyword(const std::string& line);
|
||||
|
||||
std::string getKeyword();
|
||||
void getRecords(std::list<RawRecordPtr>& records);
|
||||
unsigned int getNumberOfRecords();
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace Opm {
|
||||
void RawRecord::processQuoteCharacters(std::string& currentToken, const char& currentChar, char& tokenStartCharacter) {
|
||||
if (currentChar == tokenStartCharacter) {
|
||||
if (currentToken.size() > 0) {
|
||||
m_recordItems.push_back(currentToken);
|
||||
m_recordItems.push_back("'"+currentToken+"'"); //Adding quotes, not sure what is best.
|
||||
currentToken.clear();
|
||||
}
|
||||
tokenStartCharacter = '\0';
|
||||
|
||||
@@ -1,8 +1,20 @@
|
||||
/*
|
||||
* File: Record.hpp
|
||||
* Author: kflik
|
||||
*
|
||||
* Created on March 21, 2013, 10:44 AM
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef RECORD_HPP
|
||||
|
||||
Vendored
+17
-7
@@ -1,25 +1,35 @@
|
||||
-- Dette er en supertest - OK
|
||||
HALLOENZ
|
||||
OIL
|
||||
|
||||
-- Saa bare en - OK
|
||||
INCLUDE
|
||||
'sti til fil/den er her' /
|
||||
-- Saa kommer en for lang en, skal bli "trunkert", slik at keywordet blir ABCXYZFF - OK
|
||||
|
||||
ABCXYZFFD
|
||||
GRIDUNIT Tull kommer her
|
||||
-- Saa kommer det data
|
||||
METRES /
|
||||
|
||||
-- Og en med tall - IKKE OK
|
||||
-- Og en med tall - OK
|
||||
|
||||
ABC5ADFC
|
||||
RADFIN4
|
||||
213 123 123 /
|
||||
|
||||
-- Og en med tall først- Ikke OK
|
||||
|
||||
5ABCADFC
|
||||
|
||||
|
||||
-- Og en med mellomrom etter - OK
|
||||
-- Og en med mellomrom etter, og et ubestemt antall, terminert av / - OK
|
||||
|
||||
ABCDAD
|
||||
4.5 5 5 /
|
||||
3 3 fisk /
|
||||
3 3 'FISK_1' /
|
||||
/
|
||||
|
||||
-- Og en med liten bokstav i IKKE OK
|
||||
|
||||
ABCDAd
|
||||
ABCDAd
|
||||
|
||||
-- Og en kommentar med space foran, det er ok
|
||||
-- Hei her er jeg.
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
add_executable(runParserTests ParserTests.cpp)
|
||||
add_executable(runRawDataTests RawDataStructuresTests.cpp)
|
||||
add_executable(runRawDeckTests RawDeckTests.cpp)
|
||||
add_executable(runParserKWTests ParserKWTests.cpp)
|
||||
add_executable(runParserRecordSizeTests ParserRecordSizeTests.cpp)
|
||||
|
||||
|
||||
|
||||
target_link_libraries(runParserTests Parser Logger ${Boost_LIBRARIES})
|
||||
target_link_libraries(runRawDataTests Parser Logger ${Boost_LIBRARIES})
|
||||
target_link_libraries(runRawDeckTests Parser Logger ${Boost_LIBRARIES})
|
||||
target_link_libraries(runParserKWTests Parser Logger ${Boost_LIBRARIES})
|
||||
target_link_libraries(runParserRecordSizeTests Parser Logger ${Boost_LIBRARIES})
|
||||
|
||||
|
||||
add_test(NAME runParserTests WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserTests )
|
||||
add_test(NAME runRawDataTests WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND ${EXECUTABLE_OUTPUT_PATH}/runRawDataTests )
|
||||
add_test(NAME runParserTests WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserTests )
|
||||
add_test(NAME runRawDataTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runRawDataTests )
|
||||
add_test(NAME runRawDeckTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runRawDeckTests )
|
||||
add_test(NAME runParserKWTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserKWTests )
|
||||
add_test(NAME runParserRecordSizeTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserRecordSizeTests )
|
||||
|
||||
+86
-37
@@ -30,53 +30,61 @@
|
||||
#include "opm/parser/eclipse/RawDeck/RawDeck.hpp"
|
||||
using namespace Opm;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RawDeckPrintToOStream) {
|
||||
boost::filesystem::path singleKeywordFile("testdata/small.data");
|
||||
|
||||
ParserPtr parser(new Parser());
|
||||
|
||||
RawDeckPtr rawDeck = parser->parse(singleKeywordFile.string());
|
||||
std::cout << *rawDeck << "\n";
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Initializing) {
|
||||
BOOST_REQUIRE_NO_THROW(Parser parser);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParseWithInvalidInputFileThrows) {
|
||||
ParserPtr parser(new Parser());
|
||||
BOOST_REQUIRE_THROW(parser -> parse("nonexistingfile.asdf"), std::invalid_argument);
|
||||
BOOST_REQUIRE_THROW(parser->parse("nonexistingfile.asdf"), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParseWithValidFileSetOnParseCallNoThrow) {
|
||||
|
||||
boost::filesystem::path singleKeywordFile("testdata/small.data");
|
||||
ParserPtr parser(new Parser());
|
||||
|
||||
BOOST_REQUIRE_NO_THROW(parser -> parse(singleKeywordFile.string()));
|
||||
|
||||
BOOST_REQUIRE_NO_THROW(parser->parse(singleKeywordFile.string()));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParseWithInValidFileSetOnParseCallThrows) {
|
||||
boost::filesystem::path singleKeywordFile("testdata/nosuchfile.data");
|
||||
ParserPtr parser(new Parser());
|
||||
BOOST_REQUIRE_THROW(parser -> parse(singleKeywordFile.string()), std::invalid_argument);
|
||||
BOOST_REQUIRE_THROW(parser->parse(singleKeywordFile.string()), std::invalid_argument);
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParseFileWithOneKeyword) {
|
||||
boost::filesystem::path singleKeywordFile("testdata/mini.data");
|
||||
|
||||
ParserPtr parser(new Parser());
|
||||
|
||||
RawDeckPtr rawDeck = parser -> parse(singleKeywordFile.string());
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 1, rawDeck -> getNumberOfKeywords());
|
||||
RawDeckPtr rawDeck = parser->parse(singleKeywordFile.string());
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 1, rawDeck->getNumberOfKeywords());
|
||||
RawKeywordPtr rawKeyword = rawDeck->getKeyword("ENDSCALE");
|
||||
std::list<RawRecordPtr> records;
|
||||
rawKeyword -> getRecords(records);
|
||||
rawKeyword->getRecords(records);
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 1, records.size());
|
||||
RawRecordPtr record = records.back();
|
||||
|
||||
|
||||
std::string recordString;
|
||||
record -> getRecordString(recordString);
|
||||
record->getRecordString(recordString);
|
||||
BOOST_REQUIRE_EQUAL("'NODIR' 'REVERS' 1 20", recordString);
|
||||
|
||||
|
||||
std::vector<std::string> recordElements;
|
||||
record -> getRecords(recordElements);
|
||||
BOOST_REQUIRE_EQUAL((unsigned)4, recordElements.size());
|
||||
|
||||
BOOST_REQUIRE_EQUAL("NODIR", recordElements[0]);
|
||||
BOOST_REQUIRE_EQUAL("REVERS", recordElements[1]);
|
||||
record->getRecords(recordElements);
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 4, recordElements.size());
|
||||
|
||||
BOOST_REQUIRE_EQUAL("\'NODIR\'", recordElements[0]);
|
||||
BOOST_REQUIRE_EQUAL("\'REVERS\'", recordElements[1]);
|
||||
BOOST_REQUIRE_EQUAL("1", recordElements[2]);
|
||||
BOOST_REQUIRE_EQUAL("20", recordElements[3]);
|
||||
}
|
||||
@@ -86,27 +94,42 @@ BOOST_AUTO_TEST_CASE(ParseFileWithFewKeywords) {
|
||||
|
||||
ParserPtr parser(new Parser());
|
||||
|
||||
RawDeckPtr rawDeck = parser -> parse(singleKeywordFile.string());
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 4, rawDeck -> getNumberOfKeywords());
|
||||
|
||||
RawKeywordPtr matchingKeyword = rawDeck -> getKeyword("INCLUDE");
|
||||
BOOST_REQUIRE_EQUAL("INCLUDE", matchingKeyword->getKeyword());
|
||||
RawDeckPtr rawDeck = parser->parse(singleKeywordFile.string());
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 5, rawDeck->getNumberOfKeywords());
|
||||
|
||||
std::list<RawRecordPtr> records;
|
||||
|
||||
RawKeywordPtr matchingKeyword = rawDeck->getKeyword("OIL");
|
||||
matchingKeyword->getRecords(records);
|
||||
BOOST_REQUIRE_EQUAL("OIL", matchingKeyword->getKeyword());
|
||||
matchingKeyword->getRecords(records);
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 0, records.size());
|
||||
|
||||
matchingKeyword = rawDeck->getKeyword("INCLUDE");
|
||||
BOOST_REQUIRE_EQUAL("INCLUDE", matchingKeyword->getKeyword());
|
||||
matchingKeyword->getRecords(records);
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 1, records.size());
|
||||
RawRecordPtr theRecord = records.front();
|
||||
std::string recordString;
|
||||
theRecord->getRecordString(recordString);
|
||||
BOOST_REQUIRE_EQUAL("\'sti til fil/den er her\'", recordString);
|
||||
|
||||
|
||||
matchingKeyword = rawDeck->getKeyword("GRIDUNIT");
|
||||
matchingKeyword->getRecords(records);
|
||||
BOOST_REQUIRE_EQUAL("GRIDUNIT", matchingKeyword->getKeyword());
|
||||
matchingKeyword->getRecords(records);
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 1, records.size());
|
||||
|
||||
RawRecordPtr theRecord = records.front();
|
||||
std::string recordString;
|
||||
theRecord -> getRecordString(recordString);
|
||||
BOOST_REQUIRE_EQUAL("\'sti til fil/den er her\'", recordString);
|
||||
|
||||
RawKeywordPtr matchingKeyword2 = rawDeck -> getKeyword("ABCDAD");
|
||||
BOOST_REQUIRE_EQUAL("ABCDAD", matchingKeyword2->getKeyword());
|
||||
matchingKeyword = rawDeck->getKeyword("RADFIN4");
|
||||
matchingKeyword->getRecords(records);
|
||||
BOOST_REQUIRE_EQUAL("RADFIN4", matchingKeyword->getKeyword());
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 1, records.size());
|
||||
|
||||
std::list<RawRecordPtr> records2;
|
||||
matchingKeyword2->getRecords(records2);
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 2, records2.size());
|
||||
matchingKeyword = rawDeck->getKeyword("ABCDAD");
|
||||
BOOST_REQUIRE_EQUAL("ABCDAD", matchingKeyword->getKeyword());
|
||||
matchingKeyword->getRecords(records);
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 2, records.size());
|
||||
}
|
||||
|
||||
//NOTE: needs statoil dataset
|
||||
@@ -115,9 +138,9 @@ BOOST_AUTO_TEST_CASE(ParseFileWithManyKeywords) {
|
||||
boost::filesystem::path multipleKeywordFile("testdata/statoil/gurbat_trimmed.DATA");
|
||||
|
||||
ParserPtr parser(new Parser());
|
||||
|
||||
RawDeckPtr rawDeck = parser -> parse(multipleKeywordFile.string());
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 18, rawDeck -> getNumberOfKeywords());
|
||||
|
||||
RawDeckPtr rawDeck = parser->parse(multipleKeywordFile.string());
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 18, rawDeck->getNumberOfKeywords());
|
||||
}
|
||||
|
||||
//NOTE: needs statoil dataset
|
||||
@@ -126,7 +149,33 @@ BOOST_AUTO_TEST_CASE(ParseFullTestFile) {
|
||||
boost::filesystem::path multipleKeywordFile("testdata/statoil/ECLIPSE.DATA");
|
||||
|
||||
ParserPtr parser(new Parser());
|
||||
|
||||
RawDeckPtr rawDeck = parser -> parse(multipleKeywordFile.string());
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 73, rawDeck -> getNumberOfKeywords());
|
||||
|
||||
RawDeckPtr rawDeck = parser->parse(multipleKeywordFile.string());
|
||||
// Note, cannot check the number of keywords, since the number of
|
||||
// records are not defined (yet) for all these keywords.
|
||||
// But we can check a copule of keywords, and that they have the correct
|
||||
// number of records
|
||||
std::list<RawRecordPtr> records;
|
||||
RawKeywordPtr matchingKeyword = rawDeck->getKeyword("OIL");
|
||||
matchingKeyword->getRecords(records);
|
||||
BOOST_REQUIRE_EQUAL("OIL", matchingKeyword->getKeyword());
|
||||
matchingKeyword->getRecords(records);
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 0, records.size());
|
||||
|
||||
matchingKeyword = rawDeck->getKeyword("VFPPDIMS");
|
||||
matchingKeyword->getRecords(records);
|
||||
BOOST_REQUIRE_EQUAL("VFPPDIMS", matchingKeyword->getKeyword());
|
||||
matchingKeyword->getRecords(records);
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 1, records.size());
|
||||
|
||||
std::string recordString;
|
||||
records.front()->getRecordString(recordString);
|
||||
BOOST_REQUIRE_EQUAL("20 20 15 15 15 50", recordString);
|
||||
std::vector<std::string> recordItems;
|
||||
records.front()->getRecords(recordItems);
|
||||
BOOST_REQUIRE_EQUAL((unsigned)6, recordItems.size());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -64,22 +64,25 @@ BOOST_AUTO_TEST_CASE(RawKeywordSet8CharKeywordWithTrailingWhitespaceKeywordTrimm
|
||||
BOOST_CHECK(keyword.getKeyword() == "GOODONEE");
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RawRecordGetRecordStringReturnsTrimmedString) {
|
||||
Opm::RawRecordPtr record(new Opm::RawRecord(" 'NODIR ' 'REVERS' 1 20 /"));
|
||||
std::string recordString;
|
||||
record -> getRecordString(recordString);
|
||||
record->getRecordString(recordString);
|
||||
BOOST_REQUIRE_EQUAL("'NODIR ' 'REVERS' 1 20", recordString);
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RawRecordGetRecordsCorrectElementsReturned) {
|
||||
Opm::RawRecordPtr record(new Opm::RawRecord(" 'NODIR ' 'REVERS' 1 20 /"));
|
||||
|
||||
std::vector<std::string> recordElements;
|
||||
record -> getRecords(recordElements);
|
||||
record->getRecords(recordElements);
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 4, recordElements.size());
|
||||
|
||||
BOOST_REQUIRE_EQUAL("NODIR ", recordElements[0]);
|
||||
BOOST_REQUIRE_EQUAL("REVERS", recordElements[1]);
|
||||
BOOST_REQUIRE_EQUAL("\'NODIR \'", recordElements[0]);
|
||||
BOOST_REQUIRE_EQUAL("\'REVERS\'", recordElements[1]);
|
||||
BOOST_REQUIRE_EQUAL("1", recordElements[2]);
|
||||
BOOST_REQUIRE_EQUAL("20", recordElements[3]);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#define BOOST_TEST_MODULE RawDeckTests
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawDeck.hpp>
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ReadData_MissingFixedKeywords_WrongNumberOfKeywordsFound) {
|
||||
std::map<std::string, int> fixedKeywords;
|
||||
fixedKeywords.insert(std::pair<std::string, int>("GRIDUNIT", 1));
|
||||
Opm::RawDeck rawDeck(fixedKeywords);
|
||||
}
|
||||
Reference in New Issue
Block a user