move the SimpleMultiRecordTable class into its own files.
This commit is contained in:
@@ -68,7 +68,8 @@ EclipseState/Schedule/GroupTreeNode.cpp
|
||||
EclipseState/Schedule/GroupTree.cpp)
|
||||
|
||||
set (utility_source
|
||||
Utility/SimpleTable.cpp)
|
||||
Utility/SimpleTable.cpp
|
||||
Utility/SimpleMultiRecordTable.cpp)
|
||||
|
||||
set( HEADER_FILES
|
||||
RawDeck/RawConsts.hpp
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#define OPM_PARSER_FULL_TABLE_HPP
|
||||
|
||||
#include "SimpleTable.hpp"
|
||||
#include "SimpleMultiRecordTable.hpp"
|
||||
|
||||
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#ifndef OPM_PARSER_PVTG_OUTER_TABLE_HPP
|
||||
#define OPM_PARSER_PVTG_OUTER_TABLE_HPP
|
||||
|
||||
#include "SimpleTable.hpp"
|
||||
#include "SimpleMultiRecordTable.hpp"
|
||||
|
||||
namespace Opm {
|
||||
class PvtgOuterTable : protected SimpleMultiRecordTable {
|
||||
@@ -55,5 +55,5 @@ namespace Opm {
|
||||
};
|
||||
}
|
||||
|
||||
#endif // OPM_PARSER_SIMPLE_TABLE_HPP
|
||||
#endif // OPM_PARSER_PVTO_OUTER_TABLE_HPP
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#ifndef OPM_PARSER_PVTO_OUTER_TABLE_HPP
|
||||
#define OPM_PARSER_PVTO_OUTER_TABLE_HPP
|
||||
|
||||
#include "SimpleTable.hpp"
|
||||
#include "SimpleMultiRecordTable.hpp"
|
||||
|
||||
namespace Opm {
|
||||
class PvtoOuterTable : protected SimpleMultiRecordTable {
|
||||
@@ -57,5 +57,5 @@ namespace Opm {
|
||||
};
|
||||
}
|
||||
|
||||
#endif // OPM_PARSER_SIMPLE_TABLE_HPP
|
||||
#endif // OPM_PARSER_PVTO_OUTER_TABLE_HPP
|
||||
|
||||
|
||||
68
opm/parser/eclipse/Utility/SimpleMultiRecordTable.cpp
Normal file
68
opm/parser/eclipse/Utility/SimpleMultiRecordTable.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
Copyright (C) 2013 by Andreas Lauser
|
||||
|
||||
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 "SimpleMultiRecordTable.hpp"
|
||||
|
||||
namespace Opm {
|
||||
// create table from first few items of multiple records (i.e. getSIDoubleData() throws an exception)
|
||||
SimpleMultiRecordTable::SimpleMultiRecordTable(Opm::DeckKeywordConstPtr keyword,
|
||||
const std::vector<std::string> &columnNames,
|
||||
int firstEntityOffset)
|
||||
{
|
||||
createColumns_(columnNames);
|
||||
for (int rowIdx = 0; rowIdx < keyword->size(); ++ rowIdx) {
|
||||
// extract the actual data from the records of the keyword of
|
||||
// the deck
|
||||
Opm::DeckRecordConstPtr deckRecord =
|
||||
keyword->getRecord(rowIdx);
|
||||
|
||||
if ( (getNumFlatItems_(deckRecord) - firstEntityOffset) < numColumns())
|
||||
throw std::runtime_error("Number of columns in the data file is"
|
||||
"inconsistent with the ones specified");
|
||||
|
||||
for (int colIdx = 0; colIdx < numColumns(); ++colIdx) {
|
||||
int deckItemIdx = colIdx + firstEntityOffset;
|
||||
m_columns[colIdx].push_back(getFlatSiDoubleData_(deckRecord, deckItemIdx));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int SimpleMultiRecordTable::getNumFlatItems_(Opm::DeckRecordConstPtr deckRecord) const
|
||||
{
|
||||
int result = 0;
|
||||
for (int i = 0; i < deckRecord->size(); ++ i) {
|
||||
result += deckRecord->getItem(i)->size();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
double SimpleMultiRecordTable::getFlatSiDoubleData_(Opm::DeckRecordConstPtr deckRecord, int flatItemIdx) const
|
||||
{
|
||||
int itemFirstFlatIdx = 0;
|
||||
for (int i = 0; i < deckRecord->size(); ++ i) {
|
||||
Opm::DeckItemConstPtr item = deckRecord->getItem(i);
|
||||
if (itemFirstFlatIdx + item->size() > flatItemIdx)
|
||||
return item->getSIDouble(flatItemIdx - itemFirstFlatIdx);
|
||||
else
|
||||
itemFirstFlatIdx += item->size();
|
||||
}
|
||||
|
||||
throw std::range_error("Tried to access out-of-range flat item");
|
||||
}
|
||||
}
|
||||
57
opm/parser/eclipse/Utility/SimpleMultiRecordTable.hpp
Normal file
57
opm/parser/eclipse/Utility/SimpleMultiRecordTable.hpp
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
Copyright (C) 2013 by Andreas Lauser
|
||||
|
||||
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 OPM_PARSER_SIMPLE_MULTI_RECORD_TABLE_HPP
|
||||
#define OPM_PARSER_SIMPLE_MULTI_RECORD_TABLE_HPP
|
||||
|
||||
#include "SimpleTable.hpp"
|
||||
|
||||
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
namespace Opm {
|
||||
// create table from first few items of multiple records (i.e. getSIDoubleData() throws an exception)
|
||||
class SimpleMultiRecordTable : public SimpleTable {
|
||||
public:
|
||||
/*!
|
||||
* \brief Read simple tables from multi-item keywords like PVTW
|
||||
*
|
||||
* This creates a table out of the first N items of each of
|
||||
* the keyword's records. (N is the number of columns.)
|
||||
*/
|
||||
SimpleMultiRecordTable(Opm::DeckKeywordConstPtr keyword,
|
||||
const std::vector<std::string> &columnNames,
|
||||
int firstEntityOffset = 0);
|
||||
|
||||
private:
|
||||
int getNumFlatItems_(Opm::DeckRecordConstPtr deckRecord) const;
|
||||
double getFlatSiDoubleData_(Opm::DeckRecordConstPtr deckRecord, int flatItemIdx) const;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<SimpleMultiRecordTable> SimpleMultiRecordTablePtr;
|
||||
typedef std::shared_ptr<const SimpleMultiRecordTable> SimpleMultiRecordTableConstPtr;
|
||||
|
||||
}
|
||||
|
||||
#endif // OPM_PARSER_SIMPLE_MULTI_RECORD_TABLE_HPP
|
||||
|
||||
@@ -83,52 +83,4 @@ double SimpleTable::getFlatSiDoubleData_(Opm::DeckRecordConstPtr deckRecord, int
|
||||
|
||||
throw std::range_error("Tried to access out-of-range flat item");
|
||||
}
|
||||
|
||||
// create table from first few items of multiple records (i.e. getSIDoubleData() throws an exception)
|
||||
SimpleMultiRecordTable::SimpleMultiRecordTable(Opm::DeckKeywordConstPtr keyword,
|
||||
const std::vector<std::string> &columnNames,
|
||||
int firstEntityOffset)
|
||||
{
|
||||
createColumns_(columnNames);
|
||||
for (int rowIdx = 0; rowIdx < keyword->size(); ++ rowIdx) {
|
||||
// extract the actual data from the records of the keyword of
|
||||
// the deck
|
||||
Opm::DeckRecordConstPtr deckRecord =
|
||||
keyword->getRecord(rowIdx);
|
||||
|
||||
if ( (getNumFlatItems_(deckRecord) - firstEntityOffset) < numColumns())
|
||||
throw std::runtime_error("Number of columns in the data file is"
|
||||
"inconsistent with the ones specified");
|
||||
|
||||
for (int colIdx = 0; colIdx < numColumns(); ++colIdx) {
|
||||
int deckItemIdx = colIdx + firstEntityOffset;
|
||||
m_columns[colIdx].push_back(getFlatSiDoubleData_(deckRecord, deckItemIdx));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int SimpleMultiRecordTable::getNumFlatItems_(Opm::DeckRecordConstPtr deckRecord) const
|
||||
{
|
||||
int result = 0;
|
||||
for (int i = 0; i < deckRecord->size(); ++ i) {
|
||||
result += deckRecord->getItem(i)->size();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
double SimpleMultiRecordTable::getFlatSiDoubleData_(Opm::DeckRecordConstPtr deckRecord, int flatItemIdx) const
|
||||
{
|
||||
int itemFirstFlatIdx = 0;
|
||||
for (int i = 0; i < deckRecord->size(); ++ i) {
|
||||
Opm::DeckItemConstPtr item = deckRecord->getItem(i);
|
||||
if (itemFirstFlatIdx + item->size() > flatItemIdx)
|
||||
return item->getSIDouble(flatItemIdx - itemFirstFlatIdx);
|
||||
else
|
||||
itemFirstFlatIdx += item->size();
|
||||
}
|
||||
|
||||
throw std::range_error("Tried to access out-of-range flat item");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -88,28 +88,6 @@ namespace Opm {
|
||||
|
||||
typedef std::shared_ptr<SimpleTable> SimpleTablePtr;
|
||||
typedef std::shared_ptr<const SimpleTable> SimpleTableConstPtr;
|
||||
|
||||
// create table from first few items of multiple records (i.e. getSIDoubleData() throws an exception)
|
||||
class SimpleMultiRecordTable : public SimpleTable {
|
||||
public:
|
||||
/*!
|
||||
* \brief Read simple tables from multi-item keywords like PVTW
|
||||
*
|
||||
* This creates a table out of the first N items of each of
|
||||
* the keyword's records. (N is the number of columns.)
|
||||
*/
|
||||
SimpleMultiRecordTable(Opm::DeckKeywordConstPtr keyword,
|
||||
const std::vector<std::string> &columnNames,
|
||||
int firstEntityOffset = 0);
|
||||
|
||||
private:
|
||||
int getNumFlatItems_(Opm::DeckRecordConstPtr deckRecord) const;
|
||||
double getFlatSiDoubleData_(Opm::DeckRecordConstPtr deckRecord, int flatItemIdx) const;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<SimpleMultiRecordTable> SimpleMultiRecordTablePtr;
|
||||
typedef std::shared_ptr<const SimpleMultiRecordTable> SimpleMultiRecordTableConstPtr;
|
||||
|
||||
}
|
||||
|
||||
#endif // OPM_PARSER_SIMPLE_TABLE_HPP
|
||||
|
||||
Reference in New Issue
Block a user