tables: make them instantiable exclusively by EclipseState

since tables can be tricky, we now enforce that the compiler bails out
if the user tries to instantiate a table class manually.

Note that a bit of trickery is needed to keep the low-level unit
tests working...
This commit is contained in:
Andreas Lauser
2014-09-17 14:41:37 +02:00
parent aa0d7d2e6b
commit f6b2797e23
31 changed files with 379 additions and 194 deletions

View File

@@ -126,8 +126,6 @@ namespace Opm {
throw std::invalid_argument("The "+keywordName+" keyword must be unique in the deck");
const auto& tableKeyword = deck->getKeyword(keywordName);
tableVector.resize(tableKeyword->size());
for (size_t tableIdx = 0; tableIdx < tableKeyword->size(); ++tableIdx) {
if (tableKeyword->getRecord(tableIdx)->getItem(0)->size() == 0) {
// for simple tables, an empty record indicates that the previous table
@@ -135,10 +133,11 @@ namespace Opm {
if (tableIdx == 0)
throw std::invalid_argument("The first table for keyword "+keywordName+
" must be explicitly defined!");
tableVector[tableIdx] = tableVector[tableIdx - 1];
tableVector.push_back(tableVector.back());
continue;
}
tableVector.push_back(TableType());
tableVector[tableIdx].init(tableKeyword, tableIdx);
}
}
@@ -156,10 +155,10 @@ namespace Opm {
const auto& tableKeyword = deck->getKeyword(keywordName);
int numTables = TableType::numTables(tableKeyword);
tableVector.resize(numTables);
for (int tableIdx = 0; tableIdx < numTables; ++tableIdx)
for (int tableIdx = 0; tableIdx < numTables; ++tableIdx) {
tableVector.push_back(TableType());
tableVector[tableIdx].init(tableKeyword, tableIdx);
}
}
void initRocktabTables(DeckConstPtr deck);

View File

@@ -113,7 +113,7 @@ static void check_parser(ParserPtr parser) {
{
Opm::PvtgTable pvtgTable;
pvtgTable.init(kw1, 0);
pvtgTable.initFORUNITTESTONLY(kw1, 0);
const auto &outerTable = *pvtgTable.getOuterTable();
const auto &innerTable0 = *pvtgTable.getInnerTable(0);

View File

@@ -103,7 +103,7 @@ static void check_parser(ParserPtr parser) {
BOOST_CHECK_EQUAL(2U , record4->size());
Opm::PvtoTable pvtoTable;
pvtoTable.init(kw1, /*tableIdx=*/0);
pvtoTable.initFORUNITTESTONLY(kw1, /*tableIdx=*/0);
const auto &outerTable = *pvtoTable.getOuterTable();
const auto &innerTable0 = *pvtoTable.getInnerTable(0);

View File

@@ -49,7 +49,7 @@ static void check_parser(ParserPtr parser) {
static void check_SgofTable(ParserPtr parser) {
DeckPtr deck = parser->parseString(parserData);
Opm::SgofTable sgofTable;
sgofTable.init(deck->getKeyword("SGOF"), /*recordIdx=*/0);
sgofTable.initFORUNITTESTONLY(deck->getKeyword("SGOF"), /*recordIdx=*/0);
BOOST_CHECK_EQUAL(10U, sgofTable.getSgColumn().size());
BOOST_CHECK_EQUAL(0.1, sgofTable.getSgColumn()[0]);

View File

@@ -69,7 +69,7 @@ static void check_parser(ParserPtr parser) {
static void check_SwofTable(ParserPtr parser) {
DeckPtr deck = parser->parseString(parserData);
Opm::SwofTable swofTable;
swofTable.init(deck->getKeyword("SWOF"), /*recordIdx=*/0);
swofTable.initFORUNITTESTONLY(deck->getKeyword("SWOF"), /*recordIdx=*/0);
BOOST_CHECK_EQUAL(10U, swofTable.getSwColumn().size());
BOOST_CHECK_CLOSE(0.1, swofTable.getSwColumn()[0], 1e-8);

View File

@@ -22,21 +22,15 @@
#include "SingleRecordTable.hpp"
namespace Opm {
// forward declaration
class EclipseState;
class EnkrvdTable : protected SingleRecordTable {
typedef SingleRecordTable ParentType;
public:
friend class EclipseState;
EnkrvdTable() = default;
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
// using this method is strongly discouraged but the current endpoint scaling
// code makes it hard to avoid
using ParentType::getColumn;
/*!
* \brief Read the ENKRVD keyword and provide some convenience
* methods for it.
@@ -67,6 +61,16 @@ namespace Opm {
ParentType::applyDefaultsLinear("KROCRITW");
}
public:
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
// using this method is strongly discouraged but the current endpoint scaling
// code makes it hard to avoid
using ParentType::getColumn;
/*!
* \brief The datum depth for the remaining columns
*/

View File

@@ -22,21 +22,15 @@
#include "SingleRecordTable.hpp"
namespace Opm {
// forward declaration
class EclipseState;
class EnptvdTable : protected SingleRecordTable {
typedef SingleRecordTable ParentType;
public:
friend class EclipseState;
EnptvdTable() = default;
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
// using this method is strongly discouraged but the current endpoint scaling
// code makes it hard to avoid
using ParentType::getColumn;
/*!
* \brief Read the ENPTVD keyword and provide some convenience
* methods for it.
@@ -68,6 +62,16 @@ namespace Opm {
ParentType::applyDefaultsLinear("SOGCRIT");
}
public:
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
// using this method is strongly discouraged but the current endpoint scaling
// code makes it hard to avoid
using ParentType::getColumn;
const std::vector<double> &getDepthColumn() const
{ return ParentType::getColumn(0); }

View File

@@ -38,14 +38,8 @@ namespace Opm {
typedef std::shared_ptr<InnerTable> InnerTablePtr;
typedef std::shared_ptr<const InnerTable> InnerTableConstPtr;
public:
typedef std::shared_ptr<Self> Pointer;
typedef std::shared_ptr<const Self> ConstPointer;
static size_t numTables(Opm::DeckKeywordConstPtr keyword)
{ return OuterTable::numTables(keyword); }
FullTable() = default;
protected:
FullTable(const FullTable&) = default;
/*!
* \brief Read full tables from keywords like PVTO
@@ -73,6 +67,14 @@ namespace Opm {
}
}
public:
FullTable() = default;
typedef std::shared_ptr<Self> Pointer;
typedef std::shared_ptr<const Self> ConstPointer;
static size_t numTables(Opm::DeckKeywordConstPtr keyword)
{ return OuterTable::numTables(keyword); }
std::shared_ptr<const OuterTable> getOuterTable() const
{ return m_outerTable; }

View File

@@ -22,16 +22,15 @@
#include "SingleRecordTable.hpp"
namespace Opm {
// forward declaration
class EclipseState;
class ImkrvdTable : protected SingleRecordTable {
typedef SingleRecordTable ParentType;
public:
friend class EclipseState;
ImkrvdTable() = default;
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
/*!
* \brief Read the IMKRVD keyword and provide some convenience
* methods for it.
@@ -61,6 +60,12 @@ namespace Opm {
ParentType::applyDefaultsLinear("KROCRITW");
}
public:
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
/*!
* \brief The datum depth for the remaining columns
*/

View File

@@ -22,16 +22,15 @@
#include "SingleRecordTable.hpp"
namespace Opm {
// forward declaration
class EclipseState;
class ImptvdTable : protected SingleRecordTable {
typedef SingleRecordTable ParentType;
public:
friend class EclipseState;
ImptvdTable() = default;
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
/*!
* \brief Read the IMPTVD keyword and provide some convenience
* methods for it.
@@ -61,6 +60,12 @@ namespace Opm {
ParentType::applyDefaultsLinear("SOGCRIT");
}
public:
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
const std::vector<double> &getDepthColumn() const
{ return ParentType::getColumn(0); }

View File

@@ -30,15 +30,12 @@
#include <cassert>
namespace Opm {
// forward declaration
class EclipseState;
// create table from first few items of multiple records (i.e. getSIDoubleData() throws an exception)
class MultiRecordTable : public SingleRecordTable {
public:
/*!
* \brief Returns the number of tables which can be found in a
* given keyword.
*/
static size_t numTables(Opm::DeckKeywordConstPtr keyword);
protected:
/*!
* \brief Read simple tables from multi-item keywords like PVTW
*
@@ -50,6 +47,24 @@ namespace Opm {
size_t tableIndex,
size_t firstEntityOffset);
public:
MultiRecordTable() = default;
#ifdef BOOST_TEST_MODULE
// DO NOT TRY TO CALL THIS METHOD! it is only for the unit tests!
void initFORUNITTESTONLY(Opm::DeckKeywordConstPtr keyword,
const std::vector<std::string> &columnNames,
size_t tableIndex,
size_t firstEntityOffset)
{ init(keyword, columnNames, tableIndex, firstEntityOffset); }
#endif
/*!
* \brief Returns the number of tables which can be found in a
* given keyword.
*/
static size_t numTables(Opm::DeckKeywordConstPtr keyword);
/*!
* \brief Return the index of the first record which applies
* for this table object.

View File

@@ -22,16 +22,15 @@
#include "SingleRecordTable.hpp"
namespace Opm {
// forward declaration
class EclipseState;
class PlyadsTable : protected SingleRecordTable {
typedef SingleRecordTable ParentType;
public:
PlyadsTable() = default;
friend class EclipseState;
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
PlyadsTable() = default;
/*!
* \brief Read the PLYADS keyword and provide some convenience
@@ -53,6 +52,12 @@ namespace Opm {
ParentType::checkMonotonic("AdsorbedPolymer", /*isAscending=*/true);
}
public:
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
const std::vector<double> &getPolymerConcentrationColumn() const
{ return ParentType::getColumn(0); }

View File

@@ -22,17 +22,15 @@
#include "SingleRecordTable.hpp"
namespace Opm {
// forward declaration
class EclipseState;
class PlymaxTable : protected SingleRecordTable {
typedef SingleRecordTable ParentType;
public:
friend class EclipseState;
PlymaxTable() = default;
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
/*!
* \brief Read the PLYMAX keyword and provide some convenience
* methods for it.
@@ -50,6 +48,12 @@ namespace Opm {
ParentType::checkMonotonic("C_POLYMER_MAX", /*isAscending=*/false);
}
public:
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
const std::vector<double> &getPolymerConcentrationColumn() const
{ return ParentType::getColumn(0); }

View File

@@ -22,19 +22,15 @@
#include "SingleRecordTable.hpp"
namespace Opm {
// forward declaration
class EclipseState;
class PlyrockTable : protected SingleRecordTable {
typedef SingleRecordTable ParentType;
public:
friend class EclipseState;
PlyrockTable() = default;
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
// since this keyword is not necessarily monotonic, it cannot be evaluated!
//using ParentType::evaluate;
/*!
* \brief Read the PLYROCK keyword and provide some convenience
* methods for it.
@@ -70,6 +66,14 @@ namespace Opm {
}
}
public:
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
// since this keyword is not necessarily monotonic, it cannot be evaluated!
//using ParentType::evaluate;
const std::vector<double> &getDeadPoreVolumeColumn() const
{ return ParentType::getColumn(0); }

View File

@@ -22,17 +22,15 @@
#include "SingleRecordTable.hpp"
namespace Opm {
// forward declaration
class EclipseState;
class PlyviscTable : protected SingleRecordTable {
typedef SingleRecordTable ParentType;
public:
friend class EclipseState;
PlyviscTable() = default;
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
/*!
* \brief Read the PLYVISC keyword and provide some convenience
* methods for it.
@@ -53,6 +51,12 @@ namespace Opm {
ParentType::checkMonotonic("ViscosityMultiplier", /*isAscending=*/true);
}
public:
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
const std::vector<double> &getPolymerConcentrationColumn() const
{ return ParentType::getColumn(0); }

View File

@@ -22,16 +22,15 @@
#include "SingleRecordTable.hpp"
namespace Opm {
// forward declaration
class EclipseState;
class PvdgTable : protected SingleRecordTable {
typedef SingleRecordTable ParentType;
public:
PvdgTable() = default;
friend class EclipseState;
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
PvdgTable() = default;
/*!
* \brief Read the PVDG keyword and provide some convenience
@@ -55,6 +54,12 @@ namespace Opm {
ParentType::checkMonotonic("MUG", /*isAscending=*/true, /*strictlyMonotonic=*/false);
}
public:
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
const std::vector<double> &getPressureColumn() const
{ return ParentType::getColumn(0); }

View File

@@ -22,17 +22,15 @@
#include "SingleRecordTable.hpp"
namespace Opm {
// forward declaration
class EclipseState;
class PvdoTable : protected SingleRecordTable {
typedef SingleRecordTable ParentType;
public:
friend class EclipseState;
PvdoTable() = default;
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
/*!
* \brief Read the PVDO keyword and provide some convenience
* methods for it.
@@ -55,6 +53,12 @@ namespace Opm {
ParentType::checkMonotonic("MUO", /*isAscending=*/true, /*strictlyMonotonic=*/false);
}
public:
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
const std::vector<double> &getPressureColumn() const
{ return ParentType::getColumn(0); }

View File

@@ -22,17 +22,20 @@
#include "SingleRecordTable.hpp"
namespace Opm {
class PvtgInnerTable : protected SingleRecordTable {
// forward declarations
template <class OuterTable, class InnerTable>
class FullTable;
class PvtgTable;
class PvtgOuterTable;
class PvtgInnerTable;
class PvtgInnerTable : protected MultiRecordTable {
typedef SingleRecordTable ParentType;
public:
friend class PvtgTable;
friend class FullTable<PvtgOuterTable, PvtgInnerTable>;
PvtgInnerTable() = default;
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
/*!
* \brief Read the per record table of the PVTG keyword and
* provide some convenience methods for it.
@@ -51,6 +54,12 @@ namespace Opm {
ParentType::applyDefaultsLinear("MUG");
}
public:
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
const std::vector<double> &getOilSolubilityColumn() const
{ return ParentType::getColumn(0); }

View File

@@ -22,19 +22,20 @@
#include "MultiRecordTable.hpp"
namespace Opm {
// forward declarations
template <class OuterTable, class InnerTable>
class FullTable;
class PvtgTable;
class PvtgOuterTable;
class PvtgInnerTable;
class PvtgOuterTable : protected MultiRecordTable {
typedef MultiRecordTable ParentType;
public:
friend class PvtgTable;
friend class FullTable<PvtgOuterTable, PvtgInnerTable>;
PvtgOuterTable() = default;
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
using ParentType::firstRecordIndex;
using ParentType::numRecords;
/*!
* \brief Read the per record table of the PVTG keyword and
* provide some convenience methods for it.
@@ -53,6 +54,14 @@ namespace Opm {
ParentType::applyDefaultsLinear("MUG");
}
public:
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
using ParentType::firstRecordIndex;
using ParentType::numRecords;
const std::vector<double> &getPressureColumn() const
{ return ParentType::getColumn(0); }

View File

@@ -24,11 +24,29 @@
#include "PvtgOuterTable.hpp"
namespace Opm {
// forward declaration
class EclipseState;
/*!
* \brief Read the table for the PVTG and provide convenient access to it.
*/
class PvtgTable : public Opm::FullTable<Opm::PvtgOuterTable, Opm::PvtgInnerTable>
{ };
{
typedef Opm::FullTable<Opm::PvtgOuterTable, Opm::PvtgInnerTable> ParentType;
friend class EclipseState;
using ParentType::init;
public:
PvtgTable() = default;
#ifdef BOOST_TEST_MODULE
// DO NOT TRY TO CALL THIS METHOD! it is only for the unit tests!
void initFORUNITTESTONLY(Opm::DeckKeywordConstPtr keyword, size_t tableIdx)
{ init(keyword, tableIdx); }
#endif
};
typedef std::shared_ptr<PvtgTable> PvtgTablePtr;
typedef std::shared_ptr<const PvtgTable> PvtgConstTablePtr;

View File

@@ -22,17 +22,20 @@
#include "SingleRecordTable.hpp"
namespace Opm {
class PvtoInnerTable : protected SingleRecordTable {
// forward declarations
template <class OuterTable, class InnerTable>
class FullTable;
class PvtoTable;
class PvtoOuterTable;
class PvtoInnerTable;
class PvtoInnerTable : protected MultiRecordTable {
typedef SingleRecordTable ParentType;
public:
friend class PvtoTable;
friend class FullTable<PvtoOuterTable, PvtoInnerTable>;
PvtoInnerTable() = default;
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
/*!
* \brief Read the per record table of the PVTO keyword and
* provide some convenience methods for it.
@@ -52,6 +55,12 @@ namespace Opm {
ParentType::applyDefaultsLinear("MU");
}
public:
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
const std::vector<double> &getPressureColumn() const
{ return ParentType::getColumn(0); }

View File

@@ -22,10 +22,18 @@
#include "MultiRecordTable.hpp"
namespace Opm {
// forward declaration
template <class OuterTable, class InnerTable>
class FullTable;
class PvtoTable;
class PvtoOuterTable;
class PvtoInnerTable;
class PvtoOuterTable : protected MultiRecordTable {
typedef MultiRecordTable ParentType;
public:
friend class PvtoTable;
friend class FullTable<PvtoOuterTable, PvtoInnerTable>;
PvtoOuterTable() = default;
/*!
@@ -48,6 +56,7 @@ namespace Opm {
ParentType::applyDefaultsLinear("MU");
}
public:
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;

View File

@@ -24,11 +24,28 @@
#include "PvtoOuterTable.hpp"
namespace Opm {
// forward declaration
class EclipseState;
/*!
* \brief Read the table for the PVTO and provide convenient access to it.
*/
class PvtoTable : public Opm::FullTable<Opm::PvtoOuterTable, Opm::PvtoInnerTable>
{ };
{
typedef Opm::FullTable<Opm::PvtoOuterTable, Opm::PvtoInnerTable> ParentType;
friend class EclipseState;
using ParentType::init;
public:
PvtoTable() = default;
#ifdef BOOST_TEST_MODULE
// DO NOT TRY TO CALL THIS METHOD! it is only for the unit tests!
void initFORUNITTESTONLY(Opm::DeckKeywordConstPtr keyword, size_t tableIdx)
{ init(keyword, tableIdx); }
#endif
};
typedef std::shared_ptr<PvtoTable> PvtoTablePtr;
typedef std::shared_ptr<const PvtoTable> PvtoConstTablePtr;

View File

@@ -22,17 +22,15 @@
#include "SingleRecordTable.hpp"
namespace Opm {
// forward declaration
class EclipseState;
class RocktabTable : protected SingleRecordTable {
typedef SingleRecordTable ParentType;
public:
friend class EclipseState;
RocktabTable() = default;
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
/*!
* \brief Read the ROCKTAB keyword and provide some convenience
* methods for it.
@@ -62,6 +60,12 @@ namespace Opm {
}
}
public:
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
const std::vector<double> &getPressureColumn() const
{ return ParentType::getColumn(0); }

View File

@@ -22,17 +22,15 @@
#include "SingleRecordTable.hpp"
namespace Opm {
// forward declaration
class EclipseState;
class RsvdTable : protected SingleRecordTable {
typedef SingleRecordTable ParentType;
public:
friend class EclipseState;
RsvdTable() = default;
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
/*!
* \brief Read the RSVD keyword and provide some convenience
* methods for it.
@@ -49,6 +47,12 @@ namespace Opm {
ParentType::checkNonDefaultable("RS");
}
public:
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
const std::vector<double> &getDepthColumn() const
{ return ParentType::getColumn(0); }

View File

@@ -22,16 +22,15 @@
#include "SingleRecordTable.hpp"
namespace Opm {
// forward declaration
class EclipseState;
class RvvdTable : protected SingleRecordTable {
typedef SingleRecordTable ParentType;
public:
RvvdTable() = default;
friend class EclipseState;
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
RvvdTable() = default;
/*!
* \brief Read the RSVD keyword and provide some convenience
@@ -49,6 +48,12 @@ namespace Opm {
ParentType::checkNonDefaultable("RV");
}
public:
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
const std::vector<double> &getDepthColumn() const
{ return ParentType::getColumn(0); }

View File

@@ -22,16 +22,13 @@
#include "SingleRecordTable.hpp"
namespace Opm {
// forward declaration
class EclipseState;
class SgofTable : protected SingleRecordTable {
typedef SingleRecordTable ParentType;
public:
SgofTable() = default;
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
friend class EclipseState;
/*!
* \brief Read the SGOF keyword and provide some convenience
@@ -52,6 +49,20 @@ namespace Opm {
ParentType::applyDefaultsLinear("PCOG");
}
public:
SgofTable() = default;
#ifdef BOOST_TEST_MODULE
// DO NOT TRY TO CALL THIS METHOD! it is only for the unit tests!
void initFORUNITTESTONLY(Opm::DeckKeywordConstPtr keyword, size_t tableIdx)
{ init(keyword, tableIdx); }
#endif
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
const std::vector<double> &getSgColumn() const
{ return ParentType::getColumn(0); }

View File

@@ -29,14 +29,8 @@
namespace Opm {
class SingleRecordTable {
public:
/*!
* \brief Returns the number of tables in a keyword.
*
* For simple tables, that is identical to the number of
* records.
*/
static size_t numTables(Opm::DeckKeywordConstPtr keyword);
protected:
SingleRecordTable(const SingleRecordTable&) = default;
/*!
* \brief Read simple tables from keywords like SWOF
@@ -49,6 +43,26 @@ namespace Opm {
size_t recordIdx,
size_t firstEntityOffset);
public:
SingleRecordTable() = default;
/*!
* \brief Returns the number of tables in a keyword.
*
* For simple tables, that is identical to the number of
* records.
*/
static size_t numTables(Opm::DeckKeywordConstPtr keyword);
#ifdef BOOST_TEST_MODULE
// DO NOT TRY TO CALL THIS METHOD! it is only for the unit tests!
void initFORUNITTESTONLY(Opm::DeckKeywordConstPtr keyword,
const std::vector<std::string> &columnNames,
size_t recordIdx,
size_t firstEntityOffset)
{ init(keyword, columnNames, recordIdx, firstEntityOffset); }
#endif
size_t numColumns() const;
size_t numRows() const;
const std::vector<double> &getColumn(const std::string &name) const;

View File

@@ -22,16 +22,13 @@
#include "SingleRecordTable.hpp"
namespace Opm {
// forward declaration
class EclipseState;
class SwofTable : protected SingleRecordTable {
typedef SingleRecordTable ParentType;
public:
SwofTable() = default;
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
friend class EclipseState;
/*!
* \brief Read the SWOF keyword and provide some convenience
@@ -52,6 +49,20 @@ namespace Opm {
ParentType::applyDefaultsLinear("PCOW");
}
public:
SwofTable() = default;
#ifdef BOOST_TEST_MODULE
// DO NOT TRY TO CALL THIS METHOD! it is only for the unit tests!
void initFORUNITTESTONLY(Opm::DeckKeywordConstPtr keyword, size_t tableIdx)
{ init(keyword, tableIdx); }
#endif
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
using ParentType::evaluate;
const std::vector<double> &getSwColumn() const
{ return ParentType::getColumn(0); }

View File

@@ -22,19 +22,15 @@
#include "SingleRecordTable.hpp"
namespace Opm {
// forward declaration
class EclipseState;
class TlmixparTable : protected SingleRecordTable {
typedef SingleRecordTable ParentType;
public:
friend class EclipseState;
TlmixparTable() = default;
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
// this table is not necessarily monotonic, so it cannot be evaluated!
//using ParentType::evaluate;
/*!
* \brief Read the TLMIXPAR keyword and provide some convenience
* methods for it.
@@ -63,6 +59,14 @@ namespace Opm {
}
}
public:
using ParentType::numTables;
using ParentType::numRows;
using ParentType::numColumns;
// this table is not necessarily monotonic, so it cannot be evaluated!
//using ParentType::evaluate;
const std::vector<double> &getViscosityParameterColumn() const
{ return ParentType::getColumn(0); }

View File

@@ -16,6 +16,9 @@
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#define BOOST_TEST_MODULE SingleRecordTableTests
#include <boost/test/unit_test.hpp>
#include <opm/parser/eclipse/Parser/Parser.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
@@ -29,8 +32,6 @@
#include <opm/parser/eclipse/Utility/SwofTable.hpp>
#include <opm/parser/eclipse/Utility/SgofTable.hpp>
#define BOOST_TEST_MODULE SingleRecordTableTests
#include <boost/test/unit_test.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/filesystem.hpp>
@@ -57,21 +58,21 @@ BOOST_AUTO_TEST_CASE(CreateSingleRecordTable) {
BOOST_CHECK_EQUAL(Opm::SingleRecordTable::numTables(deck->getKeyword("SWOF")), 2);
Opm::SingleRecordTable tmpTable;
BOOST_CHECK_THROW(tmpTable.init(deck->getKeyword("SWOF"),
tooFewColumnNames,
/*recordIdx=*/0,
/*firstEntryOffset=*/0),
BOOST_CHECK_THROW(tmpTable.initFORUNITTESTONLY(deck->getKeyword("SWOF"),
tooFewColumnNames,
/*recordIdx=*/0,
/*firstEntryOffset=*/0),
std::runtime_error);
BOOST_CHECK_THROW(tmpTable.init(deck->getKeyword("SWOF"),
tooManyColumnNames,
/*recordIdx=*/0,
/*firstEntryOffset=*/0),
BOOST_CHECK_THROW(tmpTable.initFORUNITTESTONLY(deck->getKeyword("SWOF"),
tooManyColumnNames,
/*recordIdx=*/0,
/*firstEntryOffset=*/0),
std::runtime_error);
tmpTable.init(deck->getKeyword("SWOF"),
justRightColumnNames,
/*recordIdx=*/0,
/*firstEntryOffset=*/0);
tmpTable.initFORUNITTESTONLY(deck->getKeyword("SWOF"),
justRightColumnNames,
/*recordIdx=*/0,
/*firstEntryOffset=*/0);
}
BOOST_AUTO_TEST_CASE(CreateMultiTable) {
@@ -106,16 +107,16 @@ BOOST_AUTO_TEST_CASE(CreateMultiTable) {
std::runtime_error);
*/
Opm::MultiRecordTable mrt;
BOOST_CHECK_THROW(mrt.init(deck->getKeyword("PVTO"),
tooManyColumnNames,
/*tableIdx=*/0,
/*firstEntryOffset=*/0),
BOOST_CHECK_THROW(mrt.initFORUNITTESTONLY(deck->getKeyword("PVTO"),
tooManyColumnNames,
/*tableIdx=*/0,
/*firstEntryOffset=*/0),
std::runtime_error);
BOOST_CHECK_NO_THROW(mrt.init(deck->getKeyword("PVTO"),
justRightColumnNames,
/*recordIdx=*/0,
/*firstEntryOffset=*/0));
BOOST_CHECK_NO_THROW(mrt.initFORUNITTESTONLY(deck->getKeyword("PVTO"),
justRightColumnNames,
/*recordIdx=*/0,
/*firstEntryOffset=*/0));
}
BOOST_AUTO_TEST_CASE(SwofTable_Tests) {
@@ -139,8 +140,8 @@ BOOST_AUTO_TEST_CASE(SwofTable_Tests) {
Opm::SwofTable swof1Table;
Opm::SwofTable swof2Table;
swof1Table.init(deck->getKeyword("SWOF"), /*tableIdx=*/0);
swof2Table.init(deck->getKeyword("SWOF"), /*tableIdx=*/1);
swof1Table.initFORUNITTESTONLY(deck->getKeyword("SWOF"), /*tableIdx=*/0);
swof2Table.initFORUNITTESTONLY(deck->getKeyword("SWOF"), /*tableIdx=*/1);
BOOST_CHECK_EQUAL(swof1Table.numRows(), 2);
BOOST_CHECK_EQUAL(swof2Table.numRows(), 3);
@@ -187,8 +188,8 @@ BOOST_AUTO_TEST_CASE(SgofTable_Tests) {
Opm::SgofTable sgof1Table;
Opm::SgofTable sgof2Table;
sgof1Table.init(deck->getKeyword("SGOF"), /*tableIdx=*/0);
sgof2Table.init(deck->getKeyword("SGOF"), /*tableIdx=*/1);
sgof1Table.initFORUNITTESTONLY(deck->getKeyword("SGOF"), /*tableIdx=*/0);
sgof2Table.initFORUNITTESTONLY(deck->getKeyword("SGOF"), /*tableIdx=*/1);
BOOST_CHECK_EQUAL(sgof1Table.numRows(), 2);
BOOST_CHECK_EQUAL(sgof2Table.numRows(), 3);
@@ -239,8 +240,8 @@ BOOST_AUTO_TEST_CASE(PvtoTable_Tests) {
Opm::PvtoTable pvto1Table;
Opm::PvtoTable pvto2Table;
pvto1Table.init(deck->getKeyword("PVTO"), /*tableIdx=*/0);
pvto2Table.init(deck->getKeyword("PVTO"), /*tableIdx=*/1);
pvto1Table.initFORUNITTESTONLY(deck->getKeyword("PVTO"), /*tableIdx=*/0);
pvto2Table.initFORUNITTESTONLY(deck->getKeyword("PVTO"), /*tableIdx=*/1);
const auto pvto1OuterTable = pvto1Table.getOuterTable();
const auto pvto2OuterTable = pvto2Table.getOuterTable();