2014-03-21 14:39:24 +01:00
|
|
|
/*
|
|
|
|
|
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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2014-03-21 15:40:44 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
#include <exception>
|
2014-03-24 14:48:23 +01:00
|
|
|
#include <algorithm>
|
2014-08-20 18:17:29 +02:00
|
|
|
#include <cassert>
|
2014-08-21 14:16:52 +02:00
|
|
|
#include <set>
|
|
|
|
|
#include <string>
|
2014-03-21 15:40:44 +01:00
|
|
|
|
2015-01-16 14:51:57 +01:00
|
|
|
#include <opm/parser/eclipse/OpmLog/OpmLog.hpp>
|
2015-01-16 13:01:10 +01:00
|
|
|
#include <opm/parser/eclipse/OpmLog/LogUtil.hpp>
|
2014-12-12 20:56:34 +01:00
|
|
|
|
2014-03-21 14:39:24 +01:00
|
|
|
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
2016-01-24 21:49:39 +01:00
|
|
|
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
|
2014-03-21 14:39:24 +01:00
|
|
|
#include <opm/parser/eclipse/Deck/Section.hpp>
|
2014-10-12 14:53:49 +02:00
|
|
|
#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>
|
2014-03-21 14:39:24 +01:00
|
|
|
|
|
|
|
|
namespace Opm {
|
2015-07-26 23:01:54 +02:00
|
|
|
|
2016-02-09 12:16:44 +01:00
|
|
|
static bool isSectionDelimiter( const DeckKeyword& keyword ) {
|
|
|
|
|
const auto& name = keyword.name();
|
|
|
|
|
for( const auto& x : { "RUNSPEC", "GRID", "EDIT", "PROPS",
|
|
|
|
|
"REGIONS", "SOLUTION", "SUMMARY", "SCHEDULE" } )
|
|
|
|
|
if( name == x ) return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
2014-03-24 10:05:22 +01:00
|
|
|
}
|
|
|
|
|
|
2016-02-09 12:16:44 +01:00
|
|
|
static bool isDelim( const std::shared_ptr< const DeckKeyword >& x ) {
|
|
|
|
|
return isSectionDelimiter( *x );
|
|
|
|
|
}
|
2015-04-13 17:05:29 +02:00
|
|
|
|
2016-02-09 12:16:44 +01:00
|
|
|
static std::pair< DeckView::const_iterator, DeckView::const_iterator >
|
|
|
|
|
find_section( const Deck& deck, const std::string& keyword ) {
|
2015-04-13 17:05:29 +02:00
|
|
|
|
2016-02-09 12:16:44 +01:00
|
|
|
const auto fn = [&keyword]( const Deck::const_iterator::reference kw ) {
|
|
|
|
|
return kw->name() == keyword;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto first = std::find_if( deck.begin(), deck.end(), fn );
|
|
|
|
|
if( first == deck.end() )
|
|
|
|
|
throw std::invalid_argument( std::string( "Deck requires a '" ) + keyword + "' section" );
|
2014-03-21 15:40:44 +01:00
|
|
|
|
2016-02-09 12:16:44 +01:00
|
|
|
auto last = std::find_if( first + 1, deck.end(), &isDelim );
|
2015-04-13 17:05:29 +02:00
|
|
|
|
2016-02-09 12:16:44 +01:00
|
|
|
if( last != deck.end() && (*last)->name() == keyword )
|
|
|
|
|
throw std::invalid_argument( std::string( "Deck contains the '" ) + keyword + "' section multiple times" );
|
|
|
|
|
|
|
|
|
|
return { first, last };
|
2014-07-05 13:31:40 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-09 12:16:44 +01:00
|
|
|
Section::Section( std::shared_ptr< const Deck > deck, const std::string& section )
|
|
|
|
|
: DeckView( find_section( *deck, section ) ),
|
|
|
|
|
section_name( section )
|
|
|
|
|
{}
|
|
|
|
|
|
2014-06-02 09:06:09 +02:00
|
|
|
const std::string& Section::name() const {
|
2016-02-09 12:16:44 +01:00
|
|
|
return this->section_name;
|
2014-06-02 09:06:09 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-09 12:16:44 +01:00
|
|
|
bool Section::hasRUNSPEC(std::shared_ptr< const Deck > deck) { return deck->hasKeyword( "RUNSPEC" ); }
|
|
|
|
|
bool Section::hasGRID(std::shared_ptr< const Deck > deck) { return deck->hasKeyword( "GRID" ); }
|
|
|
|
|
bool Section::hasEDIT(std::shared_ptr< const Deck > deck) { return deck->hasKeyword( "EDIT" ); }
|
|
|
|
|
bool Section::hasPROPS(std::shared_ptr< const Deck > deck) { return deck->hasKeyword( "PROPS" ); }
|
|
|
|
|
bool Section::hasREGIONS(std::shared_ptr< const Deck > deck) { return deck->hasKeyword( "REGIONS" ); }
|
|
|
|
|
bool Section::hasSOLUTION(std::shared_ptr< const Deck > deck) { return deck->hasKeyword( "SOLUTION" ); }
|
|
|
|
|
bool Section::hasSUMMARY(std::shared_ptr< const Deck > deck) { return deck->hasKeyword( "SUMMARY" ); }
|
|
|
|
|
bool Section::hasSCHEDULE(std::shared_ptr< const Deck > deck) { return deck->hasKeyword( "SCHEDULE" ); }
|
2014-03-25 16:05:36 +01:00
|
|
|
|
2016-02-09 12:16:44 +01:00
|
|
|
bool Section::checkSectionTopology(std::shared_ptr< const Deck > deck,
|
2014-10-12 14:53:49 +02:00
|
|
|
bool ensureKeywordSectionAffiliation)
|
2014-08-21 14:16:52 +02:00
|
|
|
{
|
|
|
|
|
if (deck->size() == 0) {
|
2014-10-01 16:07:44 +02:00
|
|
|
std::string msg = "empty decks are invalid\n";
|
2015-01-16 14:51:57 +01:00
|
|
|
OpmLog::addMessage(Log::MessageType::Warning , msg);
|
2014-08-21 14:16:52 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-03 15:32:56 +02:00
|
|
|
bool deckValid = true;
|
|
|
|
|
|
2014-08-21 14:16:52 +02:00
|
|
|
if (deck->getKeyword(0)->name() != "RUNSPEC") {
|
2014-10-01 16:07:44 +02:00
|
|
|
std::string msg = "The first keyword of a valid deck must be RUNSPEC\n";
|
2015-01-16 13:01:10 +01:00
|
|
|
auto curKeyword = deck->getKeyword(0);
|
2015-01-16 14:51:57 +01:00
|
|
|
OpmLog::addMessage(Log::MessageType::Warning , Log::fileMessage(curKeyword->getFileName() , curKeyword->getLineNumber() , msg));
|
2014-10-03 15:32:56 +02:00
|
|
|
deckValid = false;
|
2014-08-21 14:16:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string curSectionName = deck->getKeyword(0)->name();
|
|
|
|
|
size_t curKwIdx = 1;
|
|
|
|
|
for (; curKwIdx < deck->size(); ++curKwIdx) {
|
2014-10-12 14:53:49 +02:00
|
|
|
const auto& curKeyword = deck->getKeyword(curKwIdx);
|
2014-10-01 16:07:44 +02:00
|
|
|
const std::string& curKeywordName = curKeyword->name();
|
2014-10-12 14:53:49 +02:00
|
|
|
|
|
|
|
|
if (!isSectionDelimiter(curKeywordName)) {
|
|
|
|
|
if (!curKeyword->hasParserKeyword())
|
|
|
|
|
// ignore unknown keywords for now (i.e. they can appear in any section)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
const auto &parserKeyword = curKeyword->getParserKeyword();
|
|
|
|
|
if (ensureKeywordSectionAffiliation && !parserKeyword->isValidSection(curSectionName)) {
|
|
|
|
|
std::string msg =
|
|
|
|
|
"The keyword '"+curKeywordName+"' is located in the '"+curSectionName
|
|
|
|
|
+"' section where it is invalid";
|
|
|
|
|
|
2015-01-16 14:51:57 +01:00
|
|
|
OpmLog::addMessage(Log::MessageType::Warning , Log::fileMessage(curKeyword->getFileName() , curKeyword->getLineNumber() , msg));
|
2014-10-12 14:53:49 +02:00
|
|
|
deckValid = false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-21 14:16:52 +02:00
|
|
|
continue;
|
2014-10-12 14:53:49 +02:00
|
|
|
}
|
2014-08-21 14:16:52 +02:00
|
|
|
|
|
|
|
|
if (curSectionName == "RUNSPEC") {
|
|
|
|
|
if (curKeywordName != "GRID") {
|
2014-10-01 16:07:44 +02:00
|
|
|
std::string msg =
|
|
|
|
|
"The RUNSPEC section must be followed by GRID instead of "+curKeywordName;
|
2015-01-16 14:51:57 +01:00
|
|
|
OpmLog::addMessage(Log::MessageType::Warning , Log::fileMessage(curKeyword->getFileName() , curKeyword->getLineNumber() , msg));
|
2014-10-03 15:32:56 +02:00
|
|
|
deckValid = false;
|
2014-08-21 14:16:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
curSectionName = curKeywordName;
|
|
|
|
|
}
|
|
|
|
|
else if (curSectionName == "GRID") {
|
|
|
|
|
if (curKeywordName != "EDIT" && curKeywordName != "PROPS") {
|
2014-10-01 16:07:44 +02:00
|
|
|
std::string msg =
|
|
|
|
|
"The GRID section must be followed by EDIT or PROPS instead of "+curKeywordName;
|
2015-01-16 14:51:57 +01:00
|
|
|
OpmLog::addMessage(Log::MessageType::Warning , Log::fileMessage(curKeyword->getFileName() , curKeyword->getLineNumber() , msg));
|
2014-10-03 15:32:56 +02:00
|
|
|
deckValid = false;
|
2014-08-21 14:16:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
curSectionName = curKeywordName;
|
|
|
|
|
}
|
|
|
|
|
else if (curSectionName == "EDIT") {
|
|
|
|
|
if (curKeywordName != "PROPS") {
|
2014-10-01 16:07:44 +02:00
|
|
|
std::string msg =
|
|
|
|
|
"The EDIT section must be followed by PROPS instead of "+curKeywordName;
|
2015-01-16 14:51:57 +01:00
|
|
|
OpmLog::addMessage(Log::MessageType::Warning , Log::fileMessage(curKeyword->getFileName() , curKeyword->getLineNumber() , msg));
|
2014-10-03 15:32:56 +02:00
|
|
|
deckValid = false;
|
2014-08-21 14:16:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
curSectionName = curKeywordName;
|
|
|
|
|
}
|
|
|
|
|
else if (curSectionName == "PROPS") {
|
|
|
|
|
if (curKeywordName != "REGIONS" && curKeywordName != "SOLUTION") {
|
2014-10-01 16:07:44 +02:00
|
|
|
std::string msg =
|
|
|
|
|
"The PROPS section must be followed by REGIONS or SOLUTION instead of "+curKeywordName;
|
2015-01-16 14:51:57 +01:00
|
|
|
OpmLog::addMessage(Log::MessageType::Warning , Log::fileMessage(curKeyword->getFileName() , curKeyword->getLineNumber() , msg));
|
2014-10-03 15:32:56 +02:00
|
|
|
deckValid = false;
|
2014-08-21 14:16:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
curSectionName = curKeywordName;
|
|
|
|
|
}
|
|
|
|
|
else if (curSectionName == "REGIONS") {
|
|
|
|
|
if (curKeywordName != "SOLUTION") {
|
2014-10-01 16:07:44 +02:00
|
|
|
std::string msg =
|
|
|
|
|
"The REGIONS section must be followed by SOLUTION instead of "+curKeywordName;
|
2015-01-16 14:51:57 +01:00
|
|
|
OpmLog::addMessage(Log::MessageType::Warning , Log::fileMessage(curKeyword->getFileName() , curKeyword->getLineNumber() , msg));
|
2014-10-03 15:32:56 +02:00
|
|
|
deckValid = false;
|
2014-08-21 14:16:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
curSectionName = curKeywordName;
|
|
|
|
|
}
|
|
|
|
|
else if (curSectionName == "SOLUTION") {
|
|
|
|
|
if (curKeywordName != "SUMMARY" && curKeywordName != "SCHEDULE") {
|
2014-10-01 16:07:44 +02:00
|
|
|
std::string msg =
|
|
|
|
|
"The SOLUTION section must be followed by SUMMARY or SCHEDULE instead of "+curKeywordName;
|
2015-01-16 14:51:57 +01:00
|
|
|
OpmLog::addMessage(Log::MessageType::Warning , Log::fileMessage(curKeyword->getFileName() , curKeyword->getLineNumber() , msg));
|
2014-10-03 15:32:56 +02:00
|
|
|
deckValid = false;
|
2014-08-21 14:16:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
curSectionName = curKeywordName;
|
|
|
|
|
}
|
|
|
|
|
else if (curSectionName == "SUMMARY") {
|
|
|
|
|
if (curKeywordName != "SCHEDULE") {
|
2014-10-01 16:07:44 +02:00
|
|
|
std::string msg =
|
|
|
|
|
"The SUMMARY section must be followed by SCHEDULE instead of "+curKeywordName;
|
2015-01-16 14:51:57 +01:00
|
|
|
OpmLog::addMessage(Log::MessageType::Warning , Log::fileMessage(curKeyword->getFileName() , curKeyword->getLineNumber() , msg));
|
2014-10-03 15:32:56 +02:00
|
|
|
deckValid = false;
|
2014-08-21 14:16:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
curSectionName = curKeywordName;
|
|
|
|
|
}
|
|
|
|
|
else if (curSectionName == "SCHEDULE") {
|
|
|
|
|
// schedule is the last section, so every section delimiter after it is wrong...
|
2014-10-01 16:07:44 +02:00
|
|
|
std::string msg =
|
|
|
|
|
"The SCHEDULE section must be the last one ("
|
|
|
|
|
+curKeywordName+" specified after SCHEDULE)";
|
2015-01-16 14:51:57 +01:00
|
|
|
OpmLog::addMessage(Log::MessageType::Warning , Log::fileMessage(curKeyword->getFileName() , curKeyword->getLineNumber() , msg));
|
2014-10-03 15:32:56 +02:00
|
|
|
deckValid = false;
|
2014-08-21 14:16:52 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SCHEDULE is the last section and it is mandatory, so make sure it is there
|
|
|
|
|
if (curSectionName != "SCHEDULE") {
|
2014-10-01 16:07:44 +02:00
|
|
|
const auto& curKeyword = deck->getKeyword(deck->size() - 1);
|
|
|
|
|
std::string msg =
|
|
|
|
|
"The last section of a valid deck must be SCHEDULE (is "+curSectionName+")";
|
2016-02-09 12:16:44 +01:00
|
|
|
OpmLog::addMessage(Log::MessageType::Warning, Log::fileMessage(curKeyword->getFileName(), curKeyword->getLineNumber(), msg));
|
2014-10-03 15:32:56 +02:00
|
|
|
deckValid = false;
|
2014-08-21 14:16:52 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-03 15:32:56 +02:00
|
|
|
return deckValid;
|
2014-08-21 14:16:52 +02:00
|
|
|
}
|
2014-03-21 14:39:24 +01:00
|
|
|
}
|