Files
opm-common/opm/parser/eclipse/Deck/Deck.cpp

116 lines
3.6 KiB
C++
Raw Normal View History

/*
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 <vector>
#include <iostream>
#include <opm/parser/eclipse/Deck/Deck.hpp>
namespace Opm {
Deck::Deck() {
}
bool Deck::hasKeyword(const std::string& keyword) const {
return (m_keywordMap.find(keyword) != m_keywordMap.end());
2013-05-30 10:11:12 +02:00
}
2014-12-09 11:26:27 +01:00
void Deck::addKeyword( DeckKeywordConstPtr keyword) {
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);
}
}
2014-12-09 11:26:27 +01:00
DeckKeywordConstPtr Deck::getKeyword(const std::string& keyword, size_t index) const {
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.");
}
2014-12-09 11:26:27 +01:00
DeckKeywordConstPtr Deck::getKeyword(const std::string& keyword) const {
const std::vector<DeckKeywordConstPtr>& keywordList = getKeywordList( keyword );
return keywordList.back();
}
2014-12-09 11:26:27 +01:00
DeckKeywordConstPtr Deck::getKeyword(size_t index) const {
if (index < m_keywordList.size())
return m_keywordList[index];
else
throw std::out_of_range("Keyword index is out of range.");
}
size_t Deck::numKeywords(const std::string& keyword) const {
if (hasKeyword(keyword)) {
const std::vector<DeckKeywordConstPtr>& keywordList = getKeywordList( keyword );
return keywordList.size();
} else
return 0;
}
2014-12-09 11:26:27 +01:00
const std::vector<DeckKeywordConstPtr>& Deck::getKeywordList(const std::string& keyword) const {
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");
}
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 {
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;
}
2013-12-14 10:23:56 +01:00
std::shared_ptr<UnitSystem> Deck::getDefaultUnitSystem() const {
return m_defaultUnits;
}
}