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>
|
2016-02-15 13:00:33 +01:00
|
|
|
#include <opm/parser/eclipse/Parser/Parser.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 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:25:01 +01:00
|
|
|
const auto fn = [&keyword]( const DeckKeyword& kw ) {
|
|
|
|
|
return kw.name() == keyword;
|
2016-02-09 12:16:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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:25:01 +01:00
|
|
|
auto last = std::find_if( first + 1, deck.end(), &isSectionDelimiter );
|
2015-04-13 17:05:29 +02:00
|
|
|
|
2016-02-09 12:25:01 +01:00
|
|
|
if( last != deck.end() && last->name() == keyword )
|
2016-02-09 12:16:44 +01:00
|
|
|
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:25:01 +01:00
|
|
|
Section::Section( const Deck& deck, const std::string& section )
|
|
|
|
|
: DeckView( find_section( deck, section ) ),
|
2016-02-09 12:16:44 +01:00
|
|
|
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:25:01 +01:00
|
|
|
bool Section::hasRUNSPEC(const Deck& deck) { return deck.hasKeyword( "RUNSPEC" ); }
|
|
|
|
|
bool Section::hasGRID(const Deck& deck) { return deck.hasKeyword( "GRID" ); }
|
|
|
|
|
bool Section::hasEDIT(const Deck& deck) { return deck.hasKeyword( "EDIT" ); }
|
|
|
|
|
bool Section::hasPROPS(const Deck& deck) { return deck.hasKeyword( "PROPS" ); }
|
|
|
|
|
bool Section::hasREGIONS(const Deck& deck) { return deck.hasKeyword( "REGIONS" ); }
|
|
|
|
|
bool Section::hasSOLUTION(const Deck& deck) { return deck.hasKeyword( "SOLUTION" ); }
|
|
|
|
|
bool Section::hasSUMMARY(const Deck& deck) { return deck.hasKeyword( "SUMMARY" ); }
|
|
|
|
|
bool Section::hasSCHEDULE(const Deck& deck) { return deck.hasKeyword( "SCHEDULE" ); }
|
2014-03-25 16:05:36 +01:00
|
|
|
|
2014-03-21 14:39:24 +01:00
|
|
|
}
|