add class for simple tables
This is intended for keywords like SWOF which currently is a big
vector of doubles but one needs to use the data in a column oriented
way.
This class is intended to be used like this:
Opm::DeckKeywordConstPtr swofKeyword = newParserDeck->getKeyword("SWOF");
Opm::SimpleTable swofTable(swofKeyword,
/*columns=*/std::vector<std::string>{"SW", "KRW", "KROW", "PCOW"},
/*recordIdx=*/table_num);
const std::vector<double>& sw = swofTable.getColumn(0);
// ...
what might be useful is to move the column names into the JSON
description of the keywords, but I could not find a way to go back to
the parser from the deck/keyword. maybe this is not even desireable as
decks might also be created by other means...
Also, a multi-record variant of the class is available. That one is
intended for keywords like PVTO where the first few items of each
record form a table (in the case of PVTO: Rs, pressure, Bo, and
viscosity for staturated oil) and the next entries constitute another
table (in the case of PVTO: pressure, Bo and viscosity for
undersaturated oil with the same RS factor as the first entry).
The second kind of tables can be constructed using the item-based
variant of SimpleTable.
2013-12-16 13:45:02 +01:00
|
|
|
/*
|
|
|
|
|
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_TABLE_HPP
|
|
|
|
|
#define OPM_PARSER_SIMPLE_TABLE_HPP
|
|
|
|
|
|
|
|
|
|
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
|
|
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
|
|
namespace Opm {
|
|
|
|
|
class SimpleTable {
|
|
|
|
|
protected:
|
|
|
|
|
// protected default constructor for the derived classes
|
|
|
|
|
SimpleTable() {}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Read simple tables from keywords like SWOF
|
|
|
|
|
*
|
|
|
|
|
* This requires all data to be a list of doubles in the first
|
|
|
|
|
* item of a given record index.
|
|
|
|
|
*/
|
|
|
|
|
SimpleTable(Opm::DeckKeywordConstPtr keyword,
|
|
|
|
|
const std::vector<std::string> &columnNames,
|
2014-01-17 08:13:08 +01:00
|
|
|
size_t recordIdx = 0,
|
|
|
|
|
size_t firstEntityOffset = 0);
|
add class for simple tables
This is intended for keywords like SWOF which currently is a big
vector of doubles but one needs to use the data in a column oriented
way.
This class is intended to be used like this:
Opm::DeckKeywordConstPtr swofKeyword = newParserDeck->getKeyword("SWOF");
Opm::SimpleTable swofTable(swofKeyword,
/*columns=*/std::vector<std::string>{"SW", "KRW", "KROW", "PCOW"},
/*recordIdx=*/table_num);
const std::vector<double>& sw = swofTable.getColumn(0);
// ...
what might be useful is to move the column names into the JSON
description of the keywords, but I could not find a way to go back to
the parser from the deck/keyword. maybe this is not even desireable as
decks might also be created by other means...
Also, a multi-record variant of the class is available. That one is
intended for keywords like PVTO where the first few items of each
record form a table (in the case of PVTO: Rs, pressure, Bo, and
viscosity for staturated oil) and the next entries constitute another
table (in the case of PVTO: pressure, Bo and viscosity for
undersaturated oil with the same RS factor as the first entry).
The second kind of tables can be constructed using the item-based
variant of SimpleTable.
2013-12-16 13:45:02 +01:00
|
|
|
|
2014-01-09 15:53:35 +01:00
|
|
|
// constructor to make the base class compatible with specialized table implementations
|
|
|
|
|
SimpleTable(Opm::DeckKeywordConstPtr keyword,
|
2014-01-17 08:13:08 +01:00
|
|
|
size_t recordIdx = 0,
|
|
|
|
|
size_t firstEntityOffset = 0)
|
2014-01-09 15:53:35 +01:00
|
|
|
{
|
|
|
|
|
throw std::logic_error("The base class of simple tables can't be "
|
|
|
|
|
"instantiated without specifying columns!");
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-17 08:13:08 +01:00
|
|
|
size_t numColumns() const
|
add class for simple tables
This is intended for keywords like SWOF which currently is a big
vector of doubles but one needs to use the data in a column oriented
way.
This class is intended to be used like this:
Opm::DeckKeywordConstPtr swofKeyword = newParserDeck->getKeyword("SWOF");
Opm::SimpleTable swofTable(swofKeyword,
/*columns=*/std::vector<std::string>{"SW", "KRW", "KROW", "PCOW"},
/*recordIdx=*/table_num);
const std::vector<double>& sw = swofTable.getColumn(0);
// ...
what might be useful is to move the column names into the JSON
description of the keywords, but I could not find a way to go back to
the parser from the deck/keyword. maybe this is not even desireable as
decks might also be created by other means...
Also, a multi-record variant of the class is available. That one is
intended for keywords like PVTO where the first few items of each
record form a table (in the case of PVTO: Rs, pressure, Bo, and
viscosity for staturated oil) and the next entries constitute another
table (in the case of PVTO: pressure, Bo and viscosity for
undersaturated oil with the same RS factor as the first entry).
The second kind of tables can be constructed using the item-based
variant of SimpleTable.
2013-12-16 13:45:02 +01:00
|
|
|
{ return m_columns.size(); }
|
|
|
|
|
|
2014-01-17 08:13:08 +01:00
|
|
|
size_t numRows() const
|
add class for simple tables
This is intended for keywords like SWOF which currently is a big
vector of doubles but one needs to use the data in a column oriented
way.
This class is intended to be used like this:
Opm::DeckKeywordConstPtr swofKeyword = newParserDeck->getKeyword("SWOF");
Opm::SimpleTable swofTable(swofKeyword,
/*columns=*/std::vector<std::string>{"SW", "KRW", "KROW", "PCOW"},
/*recordIdx=*/table_num);
const std::vector<double>& sw = swofTable.getColumn(0);
// ...
what might be useful is to move the column names into the JSON
description of the keywords, but I could not find a way to go back to
the parser from the deck/keyword. maybe this is not even desireable as
decks might also be created by other means...
Also, a multi-record variant of the class is available. That one is
intended for keywords like PVTO where the first few items of each
record form a table (in the case of PVTO: Rs, pressure, Bo, and
viscosity for staturated oil) and the next entries constitute another
table (in the case of PVTO: pressure, Bo and viscosity for
undersaturated oil with the same RS factor as the first entry).
The second kind of tables can be constructed using the item-based
variant of SimpleTable.
2013-12-16 13:45:02 +01:00
|
|
|
{ return m_columns[0].size(); }
|
|
|
|
|
|
|
|
|
|
const std::vector<double> &getColumn(const std::string &name) const
|
|
|
|
|
{
|
|
|
|
|
const auto &colIt = m_columnNames.find(name);
|
|
|
|
|
if (colIt == m_columnNames.end())
|
|
|
|
|
throw std::runtime_error("Unknown column name \""+name+"\"");
|
|
|
|
|
|
2014-01-24 09:41:32 +01:00
|
|
|
size_t colIdx = colIt->second;
|
|
|
|
|
assert(0 <= colIdx && colIdx < static_cast<size_t>(m_columns.size()));
|
add class for simple tables
This is intended for keywords like SWOF which currently is a big
vector of doubles but one needs to use the data in a column oriented
way.
This class is intended to be used like this:
Opm::DeckKeywordConstPtr swofKeyword = newParserDeck->getKeyword("SWOF");
Opm::SimpleTable swofTable(swofKeyword,
/*columns=*/std::vector<std::string>{"SW", "KRW", "KROW", "PCOW"},
/*recordIdx=*/table_num);
const std::vector<double>& sw = swofTable.getColumn(0);
// ...
what might be useful is to move the column names into the JSON
description of the keywords, but I could not find a way to go back to
the parser from the deck/keyword. maybe this is not even desireable as
decks might also be created by other means...
Also, a multi-record variant of the class is available. That one is
intended for keywords like PVTO where the first few items of each
record form a table (in the case of PVTO: Rs, pressure, Bo, and
viscosity for staturated oil) and the next entries constitute another
table (in the case of PVTO: pressure, Bo and viscosity for
undersaturated oil with the same RS factor as the first entry).
The second kind of tables can be constructed using the item-based
variant of SimpleTable.
2013-12-16 13:45:02 +01:00
|
|
|
return m_columns[colIdx];
|
|
|
|
|
}
|
2014-01-17 08:13:08 +01:00
|
|
|
const std::vector<double> &getColumn(size_t colIdx) const
|
add class for simple tables
This is intended for keywords like SWOF which currently is a big
vector of doubles but one needs to use the data in a column oriented
way.
This class is intended to be used like this:
Opm::DeckKeywordConstPtr swofKeyword = newParserDeck->getKeyword("SWOF");
Opm::SimpleTable swofTable(swofKeyword,
/*columns=*/std::vector<std::string>{"SW", "KRW", "KROW", "PCOW"},
/*recordIdx=*/table_num);
const std::vector<double>& sw = swofTable.getColumn(0);
// ...
what might be useful is to move the column names into the JSON
description of the keywords, but I could not find a way to go back to
the parser from the deck/keyword. maybe this is not even desireable as
decks might also be created by other means...
Also, a multi-record variant of the class is available. That one is
intended for keywords like PVTO where the first few items of each
record form a table (in the case of PVTO: Rs, pressure, Bo, and
viscosity for staturated oil) and the next entries constitute another
table (in the case of PVTO: pressure, Bo and viscosity for
undersaturated oil with the same RS factor as the first entry).
The second kind of tables can be constructed using the item-based
variant of SimpleTable.
2013-12-16 13:45:02 +01:00
|
|
|
{
|
2014-01-17 08:13:08 +01:00
|
|
|
assert(0 <= colIdx && colIdx < static_cast<size_t>(m_columns.size()));
|
add class for simple tables
This is intended for keywords like SWOF which currently is a big
vector of doubles but one needs to use the data in a column oriented
way.
This class is intended to be used like this:
Opm::DeckKeywordConstPtr swofKeyword = newParserDeck->getKeyword("SWOF");
Opm::SimpleTable swofTable(swofKeyword,
/*columns=*/std::vector<std::string>{"SW", "KRW", "KROW", "PCOW"},
/*recordIdx=*/table_num);
const std::vector<double>& sw = swofTable.getColumn(0);
// ...
what might be useful is to move the column names into the JSON
description of the keywords, but I could not find a way to go back to
the parser from the deck/keyword. maybe this is not even desireable as
decks might also be created by other means...
Also, a multi-record variant of the class is available. That one is
intended for keywords like PVTO where the first few items of each
record form a table (in the case of PVTO: Rs, pressure, Bo, and
viscosity for staturated oil) and the next entries constitute another
table (in the case of PVTO: pressure, Bo and viscosity for
undersaturated oil with the same RS factor as the first entry).
The second kind of tables can be constructed using the item-based
variant of SimpleTable.
2013-12-16 13:45:02 +01:00
|
|
|
return m_columns[colIdx];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void createColumns_(const std::vector<std::string> &columnNames);
|
|
|
|
|
|
2014-01-17 08:13:08 +01:00
|
|
|
size_t getNumFlatItems_(Opm::DeckRecordConstPtr deckRecord) const;
|
|
|
|
|
double getFlatSiDoubleData_(Opm::DeckRecordConstPtr deckRecord, size_t flatItemIdx) const;
|
add class for simple tables
This is intended for keywords like SWOF which currently is a big
vector of doubles but one needs to use the data in a column oriented
way.
This class is intended to be used like this:
Opm::DeckKeywordConstPtr swofKeyword = newParserDeck->getKeyword("SWOF");
Opm::SimpleTable swofTable(swofKeyword,
/*columns=*/std::vector<std::string>{"SW", "KRW", "KROW", "PCOW"},
/*recordIdx=*/table_num);
const std::vector<double>& sw = swofTable.getColumn(0);
// ...
what might be useful is to move the column names into the JSON
description of the keywords, but I could not find a way to go back to
the parser from the deck/keyword. maybe this is not even desireable as
decks might also be created by other means...
Also, a multi-record variant of the class is available. That one is
intended for keywords like PVTO where the first few items of each
record form a table (in the case of PVTO: Rs, pressure, Bo, and
viscosity for staturated oil) and the next entries constitute another
table (in the case of PVTO: pressure, Bo and viscosity for
undersaturated oil with the same RS factor as the first entry).
The second kind of tables can be constructed using the item-based
variant of SimpleTable.
2013-12-16 13:45:02 +01:00
|
|
|
|
2014-01-17 08:13:08 +01:00
|
|
|
std::map<std::string, size_t> m_columnNames;
|
add class for simple tables
This is intended for keywords like SWOF which currently is a big
vector of doubles but one needs to use the data in a column oriented
way.
This class is intended to be used like this:
Opm::DeckKeywordConstPtr swofKeyword = newParserDeck->getKeyword("SWOF");
Opm::SimpleTable swofTable(swofKeyword,
/*columns=*/std::vector<std::string>{"SW", "KRW", "KROW", "PCOW"},
/*recordIdx=*/table_num);
const std::vector<double>& sw = swofTable.getColumn(0);
// ...
what might be useful is to move the column names into the JSON
description of the keywords, but I could not find a way to go back to
the parser from the deck/keyword. maybe this is not even desireable as
decks might also be created by other means...
Also, a multi-record variant of the class is available. That one is
intended for keywords like PVTO where the first few items of each
record form a table (in the case of PVTO: Rs, pressure, Bo, and
viscosity for staturated oil) and the next entries constitute another
table (in the case of PVTO: pressure, Bo and viscosity for
undersaturated oil with the same RS factor as the first entry).
The second kind of tables can be constructed using the item-based
variant of SimpleTable.
2013-12-16 13:45:02 +01:00
|
|
|
std::vector<std::vector<double> > m_columns;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef std::shared_ptr<SimpleTable> SimpleTablePtr;
|
|
|
|
|
typedef std::shared_ptr<const SimpleTable> SimpleTableConstPtr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif // OPM_PARSER_SIMPLE_TABLE_HPP
|
|
|
|
|
|