2013-05-27 14:27:22 +02: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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-08-01 12:50:42 +02:00
|
|
|
#include <vector>
|
2013-12-05 08:26:29 +01:00
|
|
|
#include <iostream>
|
2013-08-01 12:50:42 +02:00
|
|
|
|
2013-06-04 14:32:30 +02:00
|
|
|
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
2013-05-27 14:27:22 +02:00
|
|
|
|
|
|
|
|
namespace Opm {
|
|
|
|
|
|
|
|
|
|
Deck::Deck() {
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-03 15:54:16 +02:00
|
|
|
bool Deck::hasKeyword(const std::string& keyword) const {
|
2015-04-13 17:05:29 +02:00
|
|
|
return (m_keywordMap.find(keyword) != m_keywordMap.end());
|
2013-05-30 10:11:12 +02:00
|
|
|
}
|
2014-12-08 16:34:28 +01:00
|
|
|
|
2014-12-09 11:26:27 +01:00
|
|
|
void Deck::addKeyword( DeckKeywordConstPtr keyword) {
|
2015-04-13 17:05:29 +02:00
|
|
|
m_keywordList.push_back(keyword);
|
|
|
|
|
|
|
|
|
|
if (!hasKeyword(keyword->name())) {
|
|
|
|
|
m_keywordMap[keyword->name()] = std::vector<DeckKeywordConstPtr>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
std::vector<DeckKeywordConstPtr>& keywordList = m_keywordMap[keyword->name()];
|
|
|
|
|
keywordList.push_back(keyword);
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-27 14:27:22 +02:00
|
|
|
}
|
2014-12-08 16:34:28 +01:00
|
|
|
|
2014-12-09 11:26:27 +01:00
|
|
|
DeckKeywordConstPtr Deck::getKeyword(const std::string& keyword, size_t index) const {
|
2015-04-13 17:05:29 +02:00
|
|
|
const std::vector<DeckKeywordConstPtr>& keywordList = getKeywordList( keyword );
|
|
|
|
|
if (index < keywordList.size())
|
|
|
|
|
return keywordList[index];
|
|
|
|
|
else
|
|
|
|
|
throw std::out_of_range("Keyword index is out of range.");
|
2013-06-04 14:32:30 +02:00
|
|
|
}
|
2013-08-11 12:36:16 +02:00
|
|
|
|
2014-12-09 11:26:27 +01:00
|
|
|
DeckKeywordConstPtr Deck::getKeyword(const std::string& keyword) const {
|
2015-04-13 17:05:29 +02:00
|
|
|
const std::vector<DeckKeywordConstPtr>& keywordList = getKeywordList( keyword );
|
|
|
|
|
return keywordList.back();
|
2013-08-11 12:36:16 +02:00
|
|
|
}
|
2014-12-08 16:34:28 +01:00
|
|
|
|
2014-12-09 11:26:27 +01:00
|
|
|
DeckKeywordConstPtr Deck::getKeyword(size_t index) const {
|
2015-04-13 17:05:29 +02:00
|
|
|
if (index < m_keywordList.size())
|
|
|
|
|
return m_keywordList[index];
|
|
|
|
|
else
|
|
|
|
|
throw std::out_of_range("Keyword index is out of range.");
|
2013-08-20 15:51:19 +02:00
|
|
|
}
|
2014-12-08 16:34:28 +01:00
|
|
|
|
2014-09-18 16:13:48 +02:00
|
|
|
size_t Deck::numKeywords(const std::string& keyword) const {
|
2015-04-13 17:05:29 +02:00
|
|
|
if (hasKeyword(keyword)) {
|
|
|
|
|
const std::vector<DeckKeywordConstPtr>& keywordList = getKeywordList( keyword );
|
|
|
|
|
return keywordList.size();
|
|
|
|
|
} else
|
|
|
|
|
return 0;
|
2013-08-01 12:50:42 +02:00
|
|
|
}
|
|
|
|
|
|
2014-12-09 11:26:27 +01:00
|
|
|
const std::vector<DeckKeywordConstPtr>& Deck::getKeywordList(const std::string& keyword) const {
|
2015-04-13 17:05:29 +02:00
|
|
|
if (hasKeyword(keyword)) {
|
|
|
|
|
const std::vector<DeckKeywordConstPtr>& keywordList = m_keywordMap.find(keyword)->second;
|
|
|
|
|
return keywordList;
|
|
|
|
|
} else
|
|
|
|
|
throw std::invalid_argument("Keyword: " + keyword + " is not found in the container");
|
2013-08-01 12:50:42 +02:00
|
|
|
}
|
|
|
|
|
|
2015-04-13 17:05:29 +02:00
|
|
|
std::vector<DeckKeywordConstPtr>::const_iterator Deck::begin() const {
|
|
|
|
|
return m_keywordList.begin();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<DeckKeywordConstPtr>::const_iterator Deck::end() const {
|
|
|
|
|
return m_keywordList.end();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-08-13 14:49:58 +02:00
|
|
|
size_t Deck::size() const {
|
2015-04-13 17:05:29 +02:00
|
|
|
return m_keywordList.size();
|
2013-08-13 14:49:58 +02:00
|
|
|
}
|
|
|
|
|
|
2013-12-14 10:23:56 +01:00
|
|
|
void Deck::initUnitSystem() {
|
|
|
|
|
m_defaultUnits = std::shared_ptr<UnitSystem>( UnitSystem::newMETRIC() );
|
|
|
|
|
if (hasKeyword("FIELD"))
|
|
|
|
|
m_activeUnits = std::shared_ptr<UnitSystem>( UnitSystem::newFIELD() );
|
|
|
|
|
else
|
|
|
|
|
m_activeUnits = m_defaultUnits;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<UnitSystem> Deck::getActiveUnitSystem() const {
|
|
|
|
|
return m_activeUnits;
|
|
|
|
|
}
|
2014-12-08 16:34:28 +01:00
|
|
|
|
2013-12-14 10:23:56 +01:00
|
|
|
|
|
|
|
|
std::shared_ptr<UnitSystem> Deck::getDefaultUnitSystem() const {
|
|
|
|
|
return m_defaultUnits;
|
|
|
|
|
}
|
2013-06-04 14:32:30 +02:00
|
|
|
|
2013-05-27 14:27:22 +02:00
|
|
|
}
|
|
|
|
|
|