From 4b2ab72eef08bc06bf60f277183f50abe7b79d17 Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Thu, 24 Apr 2014 18:33:51 +0200 Subject: [PATCH 1/5] add numTables() method to the table classes For SimpleTable, that is simply the number of records in a keyword, for MultiRecordTables, it is the number of _empty_ records. this patch makes supporting multi-PVT easier and cleaner. --- opm/parser/eclipse/Utility/EnkrvdTable.hpp | 2 ++ opm/parser/eclipse/Utility/EnptvdTable.hpp | 2 ++ opm/parser/eclipse/Utility/FullTable.hpp | 3 +++ opm/parser/eclipse/Utility/PlyadsTable.hpp | 2 ++ opm/parser/eclipse/Utility/PlymaxTable.hpp | 2 ++ opm/parser/eclipse/Utility/PlyrockTable.hpp | 2 ++ opm/parser/eclipse/Utility/PlyviscTable.hpp | 2 ++ opm/parser/eclipse/Utility/PvcdoTable.hpp | 2 ++ opm/parser/eclipse/Utility/PvdgTable.hpp | 2 ++ opm/parser/eclipse/Utility/PvdoTable.hpp | 2 ++ opm/parser/eclipse/Utility/PvtgInnerTable.hpp | 2 ++ opm/parser/eclipse/Utility/PvtgOuterTable.hpp | 2 ++ opm/parser/eclipse/Utility/PvtgTable.hpp | 2 ++ opm/parser/eclipse/Utility/PvtoInnerTable.hpp | 2 ++ opm/parser/eclipse/Utility/PvtoOuterTable.hpp | 2 ++ opm/parser/eclipse/Utility/PvtoTable.hpp | 2 ++ opm/parser/eclipse/Utility/PvtwTable.hpp | 2 ++ opm/parser/eclipse/Utility/RockTable.hpp | 2 ++ opm/parser/eclipse/Utility/RocktabTable.hpp | 2 ++ opm/parser/eclipse/Utility/SgofTable.hpp | 2 ++ .../Utility/SimpleMultiRecordTable.cpp | 24 ++++++++++++++++++- .../Utility/SimpleMultiRecordTable.hpp | 8 ++++++- opm/parser/eclipse/Utility/SimpleTable.hpp | 9 +++++++ opm/parser/eclipse/Utility/SwofTable.hpp | 2 ++ opm/parser/eclipse/Utility/TlmixparTable.hpp | 2 ++ 25 files changed, 84 insertions(+), 2 deletions(-) diff --git a/opm/parser/eclipse/Utility/EnkrvdTable.hpp b/opm/parser/eclipse/Utility/EnkrvdTable.hpp index 0c7e90308..20da29acc 100644 --- a/opm/parser/eclipse/Utility/EnkrvdTable.hpp +++ b/opm/parser/eclipse/Utility/EnkrvdTable.hpp @@ -26,6 +26,8 @@ namespace Opm { typedef SimpleTable ParentType; public: + using ParentType::numTables; + /*! * \brief Read the ENKRVD keyword and provide some convenience * methods for it. diff --git a/opm/parser/eclipse/Utility/EnptvdTable.hpp b/opm/parser/eclipse/Utility/EnptvdTable.hpp index d454dcb41..5016875c4 100644 --- a/opm/parser/eclipse/Utility/EnptvdTable.hpp +++ b/opm/parser/eclipse/Utility/EnptvdTable.hpp @@ -26,6 +26,8 @@ namespace Opm { typedef SimpleTable ParentType; public: + using ParentType::numTables; + /*! * \brief Read the ENPTVD keyword and provide some convenience * methods for it. diff --git a/opm/parser/eclipse/Utility/FullTable.hpp b/opm/parser/eclipse/Utility/FullTable.hpp index b2e56b150..462988cce 100644 --- a/opm/parser/eclipse/Utility/FullTable.hpp +++ b/opm/parser/eclipse/Utility/FullTable.hpp @@ -59,6 +59,9 @@ namespace Opm { typedef std::shared_ptr Pointer; typedef std::shared_ptr ConstPointer; + static size_t numTables(Opm::DeckKeywordConstPtr keyword) + { return OuterTable::numTables(keyword); } + /*! * \brief Read full tables from keywords like PVTO * diff --git a/opm/parser/eclipse/Utility/PlyadsTable.hpp b/opm/parser/eclipse/Utility/PlyadsTable.hpp index cbb74a264..49f5e7cd4 100644 --- a/opm/parser/eclipse/Utility/PlyadsTable.hpp +++ b/opm/parser/eclipse/Utility/PlyadsTable.hpp @@ -26,6 +26,8 @@ namespace Opm { typedef SimpleTable ParentType; public: + using ParentType::numTables; + /*! * \brief Read the PLYADS keyword and provide some convenience * methods for it. diff --git a/opm/parser/eclipse/Utility/PlymaxTable.hpp b/opm/parser/eclipse/Utility/PlymaxTable.hpp index bb7a10c6e..17a4b46b9 100644 --- a/opm/parser/eclipse/Utility/PlymaxTable.hpp +++ b/opm/parser/eclipse/Utility/PlymaxTable.hpp @@ -26,6 +26,8 @@ namespace Opm { typedef SimpleTable ParentType; public: + using ParentType::numTables; + /*! * \brief Read the PLYMAX keyword and provide some convenience * methods for it. diff --git a/opm/parser/eclipse/Utility/PlyrockTable.hpp b/opm/parser/eclipse/Utility/PlyrockTable.hpp index 62bcc0aad..401618ebb 100644 --- a/opm/parser/eclipse/Utility/PlyrockTable.hpp +++ b/opm/parser/eclipse/Utility/PlyrockTable.hpp @@ -26,6 +26,8 @@ namespace Opm { typedef SimpleTable ParentType; public: + using ParentType::numTables; + /*! * \brief Read the PLYROCK keyword and provide some convenience * methods for it. diff --git a/opm/parser/eclipse/Utility/PlyviscTable.hpp b/opm/parser/eclipse/Utility/PlyviscTable.hpp index cee2cebf6..2d2d34e1e 100644 --- a/opm/parser/eclipse/Utility/PlyviscTable.hpp +++ b/opm/parser/eclipse/Utility/PlyviscTable.hpp @@ -26,6 +26,8 @@ namespace Opm { typedef SimpleTable ParentType; public: + using ParentType::numTables; + /*! * \brief Read the PLYVISC keyword and provide some convenience * methods for it. diff --git a/opm/parser/eclipse/Utility/PvcdoTable.hpp b/opm/parser/eclipse/Utility/PvcdoTable.hpp index bed946ca6..15fe01faa 100644 --- a/opm/parser/eclipse/Utility/PvcdoTable.hpp +++ b/opm/parser/eclipse/Utility/PvcdoTable.hpp @@ -26,6 +26,8 @@ namespace Opm { typedef SimpleTable ParentType; public: + using ParentType::numTables; + /*! * \brief Read the PVCDO keyword and provide some convenience * methods for it. diff --git a/opm/parser/eclipse/Utility/PvdgTable.hpp b/opm/parser/eclipse/Utility/PvdgTable.hpp index 3c62e1169..71622331c 100644 --- a/opm/parser/eclipse/Utility/PvdgTable.hpp +++ b/opm/parser/eclipse/Utility/PvdgTable.hpp @@ -26,6 +26,8 @@ namespace Opm { typedef SimpleTable ParentType; public: + using ParentType::numTables; + /*! * \brief Read the PVDG keyword and provide some convenience * methods for it. diff --git a/opm/parser/eclipse/Utility/PvdoTable.hpp b/opm/parser/eclipse/Utility/PvdoTable.hpp index 5af423813..5735e07bf 100644 --- a/opm/parser/eclipse/Utility/PvdoTable.hpp +++ b/opm/parser/eclipse/Utility/PvdoTable.hpp @@ -26,6 +26,8 @@ namespace Opm { typedef SimpleTable ParentType; public: + using ParentType::numTables; + /*! * \brief Read the PVDO keyword and provide some convenience * methods for it. diff --git a/opm/parser/eclipse/Utility/PvtgInnerTable.hpp b/opm/parser/eclipse/Utility/PvtgInnerTable.hpp index 8e584a9fa..bc818bd13 100644 --- a/opm/parser/eclipse/Utility/PvtgInnerTable.hpp +++ b/opm/parser/eclipse/Utility/PvtgInnerTable.hpp @@ -26,6 +26,8 @@ namespace Opm { typedef SimpleTable ParentType; public: + using ParentType::numTables; + /*! * \brief Read the per record table of the PVTG keyword and * provide some convenience methods for it. diff --git a/opm/parser/eclipse/Utility/PvtgOuterTable.hpp b/opm/parser/eclipse/Utility/PvtgOuterTable.hpp index 45468d34c..6c376b9c0 100644 --- a/opm/parser/eclipse/Utility/PvtgOuterTable.hpp +++ b/opm/parser/eclipse/Utility/PvtgOuterTable.hpp @@ -26,6 +26,8 @@ namespace Opm { typedef SimpleMultiRecordTable ParentType; public: + using ParentType::numTables; + /*! * \brief Read the per record table of the PVTG keyword and * provide some convenience methods for it. diff --git a/opm/parser/eclipse/Utility/PvtgTable.hpp b/opm/parser/eclipse/Utility/PvtgTable.hpp index bef80b9bd..29f506192 100644 --- a/opm/parser/eclipse/Utility/PvtgTable.hpp +++ b/opm/parser/eclipse/Utility/PvtgTable.hpp @@ -32,6 +32,8 @@ namespace Opm { typedef Opm::FullTable ParentType; public: + using ParentType::numTables; + /*! * \brief Read the table for the PVTG and provide convenient access to it. */ diff --git a/opm/parser/eclipse/Utility/PvtoInnerTable.hpp b/opm/parser/eclipse/Utility/PvtoInnerTable.hpp index e309d8a6b..8782d1284 100644 --- a/opm/parser/eclipse/Utility/PvtoInnerTable.hpp +++ b/opm/parser/eclipse/Utility/PvtoInnerTable.hpp @@ -26,6 +26,8 @@ namespace Opm { typedef SimpleTable ParentType; public: + using ParentType::numTables; + /*! * \brief Read the per record table of the PVTO keyword and * provide some convenience methods for it. diff --git a/opm/parser/eclipse/Utility/PvtoOuterTable.hpp b/opm/parser/eclipse/Utility/PvtoOuterTable.hpp index 62d5dafd7..0289d13eb 100644 --- a/opm/parser/eclipse/Utility/PvtoOuterTable.hpp +++ b/opm/parser/eclipse/Utility/PvtoOuterTable.hpp @@ -26,6 +26,8 @@ namespace Opm { typedef SimpleMultiRecordTable ParentType; public: + using ParentType::numTables; + /*! * \brief Read the per record table of the PVTO keyword and * provide some convenience methods for it. diff --git a/opm/parser/eclipse/Utility/PvtoTable.hpp b/opm/parser/eclipse/Utility/PvtoTable.hpp index 69cb3e26f..b5e888f4a 100644 --- a/opm/parser/eclipse/Utility/PvtoTable.hpp +++ b/opm/parser/eclipse/Utility/PvtoTable.hpp @@ -32,6 +32,8 @@ namespace Opm { typedef Opm::FullTable ParentType; public: + using ParentType::numTables; + /*! * \brief Read the table for the PVTO and provide convenient access to it. */ diff --git a/opm/parser/eclipse/Utility/PvtwTable.hpp b/opm/parser/eclipse/Utility/PvtwTable.hpp index f65fc14b3..3bcbf5ce4 100644 --- a/opm/parser/eclipse/Utility/PvtwTable.hpp +++ b/opm/parser/eclipse/Utility/PvtwTable.hpp @@ -26,6 +26,8 @@ namespace Opm { typedef SimpleTable ParentType; public: + using ParentType::numTables; + /*! * \brief Read the PVTW keyword and provide some convenience * methods for it. diff --git a/opm/parser/eclipse/Utility/RockTable.hpp b/opm/parser/eclipse/Utility/RockTable.hpp index 8fa478056..c354bef66 100644 --- a/opm/parser/eclipse/Utility/RockTable.hpp +++ b/opm/parser/eclipse/Utility/RockTable.hpp @@ -26,6 +26,8 @@ namespace Opm { typedef SimpleTable ParentType; public: + using ParentType::numTables; + /*! * \brief Read the ROCK keyword and provide some convenience * methods for it. diff --git a/opm/parser/eclipse/Utility/RocktabTable.hpp b/opm/parser/eclipse/Utility/RocktabTable.hpp index 7b31bef36..2a468ca5a 100644 --- a/opm/parser/eclipse/Utility/RocktabTable.hpp +++ b/opm/parser/eclipse/Utility/RocktabTable.hpp @@ -26,6 +26,8 @@ namespace Opm { typedef SimpleTable ParentType; public: + using ParentType::numTables; + /*! * \brief Read the ROCKTAB keyword and provide some convenience * methods for it. diff --git a/opm/parser/eclipse/Utility/SgofTable.hpp b/opm/parser/eclipse/Utility/SgofTable.hpp index 109d33551..08fa999c6 100644 --- a/opm/parser/eclipse/Utility/SgofTable.hpp +++ b/opm/parser/eclipse/Utility/SgofTable.hpp @@ -26,6 +26,8 @@ namespace Opm { typedef SimpleTable ParentType; public: + using ParentType::numTables; + /*! * \brief Read the SGOF keyword and provide some convenience * methods for it. diff --git a/opm/parser/eclipse/Utility/SimpleMultiRecordTable.cpp b/opm/parser/eclipse/Utility/SimpleMultiRecordTable.cpp index a953bdf23..0471fc336 100644 --- a/opm/parser/eclipse/Utility/SimpleMultiRecordTable.cpp +++ b/opm/parser/eclipse/Utility/SimpleMultiRecordTable.cpp @@ -19,6 +19,28 @@ #include namespace Opm { +/*! + * \brief Returns the number of tables which can be found in a + * given keyword. + */ +size_t SimpleMultiRecordTable::numTables(Opm::DeckKeywordConstPtr keyword) +{ + size_t result = 0; + + // first, go to the first record of the specified table. For this, + // we need to skip the right number of empty records... + for (size_t recordIdx = 0; + recordIdx < keyword->size(); + ++ recordIdx) + { + if (getNumFlatItems_(keyword->getRecord(recordIdx)) == 0) + // each table ends with an empty record + ++ result; + } + + return result; +} + // create table from first few items of multiple records (i.e. getSIDoubleData() throws an exception) SimpleMultiRecordTable::SimpleMultiRecordTable(Opm::DeckKeywordConstPtr keyword, const std::vector &columnNames, @@ -68,7 +90,7 @@ SimpleMultiRecordTable::SimpleMultiRecordTable(Opm::DeckKeywordConstPtr keyword, } } -size_t SimpleMultiRecordTable::getNumFlatItems_(Opm::DeckRecordConstPtr deckRecord) const +size_t SimpleMultiRecordTable::getNumFlatItems_(Opm::DeckRecordConstPtr deckRecord) { int result = 0; for (unsigned i = 0; i < deckRecord->size(); ++ i) { diff --git a/opm/parser/eclipse/Utility/SimpleMultiRecordTable.hpp b/opm/parser/eclipse/Utility/SimpleMultiRecordTable.hpp index 0da92818b..99f806aaf 100644 --- a/opm/parser/eclipse/Utility/SimpleMultiRecordTable.hpp +++ b/opm/parser/eclipse/Utility/SimpleMultiRecordTable.hpp @@ -33,6 +33,12 @@ namespace Opm { // create table from first few items of multiple records (i.e. getSIDoubleData() throws an exception) class SimpleMultiRecordTable : public SimpleTable { public: + /*! + * \brief Returns the number of tables which can be found in a + * given keyword. + */ + static size_t numTables(Opm::DeckKeywordConstPtr keyword); + /*! * \brief Read simple tables from multi-item keywords like PVTW * @@ -59,7 +65,7 @@ namespace Opm { { return m_numRecords; } private: - size_t getNumFlatItems_(Opm::DeckRecordConstPtr deckRecord) const; + static size_t getNumFlatItems_(Opm::DeckRecordConstPtr deckRecord); double getFlatSiDoubleData_(Opm::DeckRecordConstPtr deckRecord, unsigned flatItemIdx) const; size_t m_firstRecordIdx; diff --git a/opm/parser/eclipse/Utility/SimpleTable.hpp b/opm/parser/eclipse/Utility/SimpleTable.hpp index 4f80345f9..e455547a8 100644 --- a/opm/parser/eclipse/Utility/SimpleTable.hpp +++ b/opm/parser/eclipse/Utility/SimpleTable.hpp @@ -34,6 +34,15 @@ namespace Opm { SimpleTable() {} 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) + { return keyword->size(); } + /*! * \brief Read simple tables from keywords like SWOF * diff --git a/opm/parser/eclipse/Utility/SwofTable.hpp b/opm/parser/eclipse/Utility/SwofTable.hpp index 07c5d3453..6ae617676 100644 --- a/opm/parser/eclipse/Utility/SwofTable.hpp +++ b/opm/parser/eclipse/Utility/SwofTable.hpp @@ -26,6 +26,8 @@ namespace Opm { typedef SimpleTable ParentType; public: + using ParentType::numTables; + /*! * \brief Read the SWOF keyword and provide some convenience * methods for it. diff --git a/opm/parser/eclipse/Utility/TlmixparTable.hpp b/opm/parser/eclipse/Utility/TlmixparTable.hpp index e22aa37cb..28e84e144 100644 --- a/opm/parser/eclipse/Utility/TlmixparTable.hpp +++ b/opm/parser/eclipse/Utility/TlmixparTable.hpp @@ -26,6 +26,8 @@ namespace Opm { typedef SimpleTable ParentType; public: + using ParentType::numTables; + /*! * \brief Read the TLMIXPAR keyword and provide some convenience * methods for it. From 0713a3a7674d6983d146f121fc02d11b7a522b4a Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Mon, 28 Apr 2014 16:07:03 +0200 Subject: [PATCH 2/5] add some comments to the capillary pressure retrival methods of S{g,w}ofTable that's because the Eclipse capillary pressure definitions inconsistent: SWOF specifies the "water-oil capillary pressure" as $p_o - p_w$, while SGOF uses $p_g - p_o$ as the "oil-gas capillary pressure". --- opm/parser/eclipse/Utility/SgofTable.hpp | 4 ++++ opm/parser/eclipse/Utility/SwofTable.hpp | 2 ++ 2 files changed, 6 insertions(+) diff --git a/opm/parser/eclipse/Utility/SgofTable.hpp b/opm/parser/eclipse/Utility/SgofTable.hpp index 08fa999c6..a5d110fea 100644 --- a/opm/parser/eclipse/Utility/SgofTable.hpp +++ b/opm/parser/eclipse/Utility/SgofTable.hpp @@ -55,6 +55,10 @@ namespace Opm { const std::vector &getKrogColumn() const { return ParentType::getColumn(2); } + // this column is p_g - p_o (non-wetting phase pressure minus + // wetting phase pressure for a given gas saturation. the name + // is inconsistent, but it is the one used in the Eclipse + // manual...) const std::vector &getPcogColumn() const { return ParentType::getColumn(3); } }; diff --git a/opm/parser/eclipse/Utility/SwofTable.hpp b/opm/parser/eclipse/Utility/SwofTable.hpp index 6ae617676..bf3fe9554 100644 --- a/opm/parser/eclipse/Utility/SwofTable.hpp +++ b/opm/parser/eclipse/Utility/SwofTable.hpp @@ -55,6 +55,8 @@ namespace Opm { const std::vector &getKrowColumn() const { return ParentType::getColumn(2); } + // this column is p_o - p_w (non-wetting phase pressure minus + // wetting phase pressure for a given water saturation) const std::vector &getPcowColumn() const { return ParentType::getColumn(3); } }; From de38673ce4b2dd69e387f9356f88f5cefaa5271b Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Mon, 28 Apr 2014 18:16:23 +0200 Subject: [PATCH 3/5] table tests: expand them considerably and actually run them In the current version, the runTimeMapTest binary was run because of a copy-and-pasto. oops. Also, not all of the tests pass but that is because of another problem of opm-parser for which I don't know a good fix: It currently seems to be impossible to specify empty records if there are non-defaulted items in the JSON keyword specification, but such empty records are used as table separators by Eclipse... --- .../eclipse/Utility/tests/CMakeLists.txt | 6 +- .../Utility/tests/SimpleTableTests.cpp | 49 ---- .../eclipse/Utility/tests/TableTests.cpp | 254 ++++++++++++++++++ 3 files changed, 257 insertions(+), 52 deletions(-) delete mode 100644 opm/parser/eclipse/Utility/tests/SimpleTableTests.cpp create mode 100644 opm/parser/eclipse/Utility/tests/TableTests.cpp diff --git a/opm/parser/eclipse/Utility/tests/CMakeLists.txt b/opm/parser/eclipse/Utility/tests/CMakeLists.txt index 6841b1e37..a91949d86 100644 --- a/opm/parser/eclipse/Utility/tests/CMakeLists.txt +++ b/opm/parser/eclipse/Utility/tests/CMakeLists.txt @@ -1,3 +1,3 @@ -add_executable(runSimpleTableTests SimpleTableTests.cpp) -target_link_libraries(runSimpleTableTests Parser ${Boost_LIBRARIES}) -add_test(NAME runSimpleTableTests WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${TEST_MEMCHECK_TOOL} ${EXECUTABLE_OUTPUT_PATH}/runTimeMapTests ) +add_executable(runTableTests TableTests.cpp) +target_link_libraries(runTableTests Parser ${Boost_LIBRARIES}) +add_test(NAME runTableTests WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${TEST_MEMCHECK_TOOL} ${EXECUTABLE_OUTPUT_PATH}/runTableTests ) diff --git a/opm/parser/eclipse/Utility/tests/SimpleTableTests.cpp b/opm/parser/eclipse/Utility/tests/SimpleTableTests.cpp deleted file mode 100644 index 8186cd74f..000000000 --- a/opm/parser/eclipse/Utility/tests/SimpleTableTests.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - 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 . - */ -#include -#include -#include - -#define BOOST_TEST_MODULE SimpleTableTests -#include -#include - -#include - -#include -#include - - -BOOST_AUTO_TEST_CASE(CreateSimpleTable_InvalidDeck) { - Opm::DeckKeywordPtr keyword(new Opm::DeckKeyword("SWOF")); - Opm::DeckRecordPtr record(new Opm::DeckRecord()); - Opm::DeckDoubleItemPtr item = Opm::DeckDoubleItemPtr(new Opm::DeckDoubleItem(/*name=*/"foo")); - - item->push_back(1); - item->push_back(2); - item->push_back(3); - - record->addItem(item); - keyword->addRecord(record); - - std::vector columnNames{"SW", "KRW", "KROW", "PCOW"}; - - BOOST_CHECK_THROW(Opm::SimpleTable(keyword, columnNames, /*recordIdx=*/0) , std::runtime_error); -} - diff --git a/opm/parser/eclipse/Utility/tests/TableTests.cpp b/opm/parser/eclipse/Utility/tests/TableTests.cpp new file mode 100644 index 000000000..82ddd02a9 --- /dev/null +++ b/opm/parser/eclipse/Utility/tests/TableTests.cpp @@ -0,0 +1,254 @@ +/* + 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 . + */ +#include +#include + +// generic table classes +#include +#include +#include + +// keyword specific table classes +#include +#include +#include + +#define BOOST_TEST_MODULE SimpleTableTests +#include +#include + +#include + +#include +#include + +BOOST_AUTO_TEST_CASE(CreateSimpleTable) { + const char *deckData = + "TABDIMS\n" + " 2 /\n" + "\n" + "SWOF\n" + " 1 2 3 4\n" + " 5 6 7 8 /\n" + " 9 10 11 12 /\n"; + + Opm::ParserPtr parser(new Opm::Parser); + Opm::DeckConstPtr deck(parser->parseString(deckData)); + + std::vector tooFewColumnNames{"A", "B", "C"}; + std::vector justRightColumnNames{"A", "B", "C", "D"}; + std::vector tooManyColumnNames{"A", "B", "C", "D", "E"}; + + BOOST_CHECK_EQUAL(Opm::SimpleTable::numTables(deck->getKeyword("SWOF")), 2); + BOOST_CHECK_THROW(Opm::SimpleTable(deck->getKeyword("SWOF"), + tooFewColumnNames, + /*recordIdx=*/0), + std::runtime_error); + BOOST_CHECK_THROW(Opm::SimpleTable(deck->getKeyword("SWOF"), + tooManyColumnNames, + /*recordIdx=*/0), + std::runtime_error); + + Opm::SimpleTable foo(deck->getKeyword("SWOF"), + justRightColumnNames, + /*recordIdx=*/0); +} + +BOOST_AUTO_TEST_CASE(CreateMultiTable) { + const char *deckData = + "TABDIMS\n" + "1 2 /\n" + "\n" + "PVTO\n" + " 1 2 3 4" + " 5 6 7/\n" + " 8 9 10 11 /\n" + "/\n" + "12 13 14 15\n" + " 16 17 18/\n" + "19 20 21 22/\n" + "/\n"; + + Opm::ParserPtr parser(new Opm::Parser); + Opm::DeckConstPtr deck(parser->parseString(deckData)); + + std::vector tooFewColumnNames{"A", "B", "C"}; + std::vector justRightColumnNames{"A", "B", "C", "D"}; + std::vector tooManyColumnNames{"A", "B", "C", "D", "E"}; + + BOOST_CHECK_EQUAL(Opm::SimpleMultiRecordTable::numTables(deck->getKeyword("PVTO")), 2); + // this mistake can't be detected as the MultiRecordTable takes + // the first $N items as the column names... + /* + BOOST_CHECK_THROW(Opm::SimpleMultiRecordTable(deck->getKeyword("PVTO"), + tooFewColumnNames, + 0), + std::runtime_error); + */ + BOOST_CHECK_THROW(Opm::SimpleMultiRecordTable(deck->getKeyword("PVTO"), + tooManyColumnNames, + /*tableIdx=*/0), + std::runtime_error); + + Opm::SimpleMultiRecordTable foo(deck->getKeyword("PVTO"), + justRightColumnNames, + /*recordIdx=*/0); +} + +BOOST_AUTO_TEST_CASE(SwofTable_Tests) { + const char *deckData = + "TABDIMS\n" + "2 /\n" + "\n" + "SWOF\n" + " 1 2 3 4\n" + " 5 6 7 8/\n" + " 9 10 11 12\n" + " 13 14 15 16\n" + " 17 18 19 20/\n"; + + Opm::ParserPtr parser(new Opm::Parser); + Opm::DeckConstPtr deck(parser->parseString(deckData)); + Opm::DeckKeywordConstPtr swofKeyword = deck->getKeyword("SWOF"); + + BOOST_CHECK_EQUAL(Opm::SwofTable::numTables(swofKeyword), 2); + + Opm::SwofTable swof1Table(deck->getKeyword("SWOF"), /*tableIdx=*/0); + Opm::SwofTable swof2Table(deck->getKeyword("SWOF"), /*tableIdx=*/1); + + BOOST_CHECK_EQUAL(swof1Table.numRows(), 2); + BOOST_CHECK_EQUAL(swof2Table.numRows(), 3); + + BOOST_CHECK_EQUAL(swof1Table.numColumns(), 4); + BOOST_CHECK_EQUAL(swof2Table.numColumns(), 4); + + BOOST_CHECK_EQUAL(swof1Table.getSwColumn().front(), 1.0); + BOOST_CHECK_EQUAL(swof1Table.getSwColumn().back(), 5.0); + + BOOST_CHECK_EQUAL(swof1Table.getKrwColumn().front(), 2.0); + BOOST_CHECK_EQUAL(swof1Table.getKrwColumn().back(), 6.0); + + BOOST_CHECK_EQUAL(swof1Table.getKrowColumn().front(), 3.0); + BOOST_CHECK_EQUAL(swof1Table.getKrowColumn().back(), 7.0); + + BOOST_CHECK_EQUAL(swof1Table.getPcowColumn().front(), 4.0e5); + BOOST_CHECK_EQUAL(swof1Table.getPcowColumn().back(), 8.0e5); + + // for the second table, we only check the first column and trust + // that everything else is fine... + BOOST_CHECK_EQUAL(swof2Table.getSwColumn().front(), 9.0); + BOOST_CHECK_EQUAL(swof2Table.getSwColumn().back(), 17.0); +} + +BOOST_AUTO_TEST_CASE(SgofTable_Tests) { + const char *deckData = + "TABDIMS\n" + "2 /\n" + "\n" + "SGOF\n" + " 1 2 3 4\n" + " 5 6 7 8/\n" + " 9 10 11 12\n" + " 13 14 15 16\n" + " 17 18 19 20/\n"; + + Opm::ParserPtr parser(new Opm::Parser); + Opm::DeckConstPtr deck(parser->parseString(deckData)); + Opm::DeckKeywordConstPtr sgofKeyword = deck->getKeyword("SGOF"); + + BOOST_CHECK_EQUAL(Opm::SgofTable::numTables(sgofKeyword), 2); + + Opm::SgofTable sgof1Table(deck->getKeyword("SGOF"), /*tableIdx=*/0); + Opm::SgofTable sgof2Table(deck->getKeyword("SGOF"), /*tableIdx=*/1); + + BOOST_CHECK_EQUAL(sgof1Table.numRows(), 2); + BOOST_CHECK_EQUAL(sgof2Table.numRows(), 3); + + BOOST_CHECK_EQUAL(sgof1Table.numColumns(), 4); + BOOST_CHECK_EQUAL(sgof2Table.numColumns(), 4); + + BOOST_CHECK_EQUAL(sgof1Table.getSgColumn().front(), 1.0); + BOOST_CHECK_EQUAL(sgof1Table.getSgColumn().back(), 5.0); + + BOOST_CHECK_EQUAL(sgof1Table.getKrgColumn().front(), 2.0); + BOOST_CHECK_EQUAL(sgof1Table.getKrgColumn().back(), 6.0); + + BOOST_CHECK_EQUAL(sgof1Table.getKrogColumn().front(), 3.0); + BOOST_CHECK_EQUAL(sgof1Table.getKrogColumn().back(), 7.0); + + BOOST_CHECK_EQUAL(sgof1Table.getPcogColumn().front(), 4.0e5); + BOOST_CHECK_EQUAL(sgof1Table.getPcogColumn().back(), 8.0e5); + + // for the second table, we only check the first column and trust + // that everything else is fine... + BOOST_CHECK_EQUAL(sgof2Table.getSgColumn().front(), 9.0); + BOOST_CHECK_EQUAL(sgof2Table.getSgColumn().back(), 17.0); +} + +BOOST_AUTO_TEST_CASE(PvtoTable_Tests) { + const char *deckData = + "TABDIMS\n" + "1 2 /\n" + "\n" + "PVTO\n" + " 1 2 3 4" + " 5 6 7/\n" + " 8 9 10 11 /\n" + "/\n" + "12 13 14 15\n" + " 16 17 18/\n" + "19 20 21 22/\n" + "23 24 25 26/\n" + "/\n"; + + Opm::ParserPtr parser(new Opm::Parser); + Opm::DeckConstPtr deck(parser->parseString(deckData)); + Opm::DeckKeywordConstPtr pvtoKeyword = deck->getKeyword("PVTO"); + + BOOST_CHECK_EQUAL(Opm::PvtoTable::numTables(pvtoKeyword), 2); + + Opm::PvtoTable pvto1Table(deck->getKeyword("PVTO"), /*tableIdx=*/0); + Opm::PvtoTable pvto2Table(deck->getKeyword("PVTO"), /*tableIdx=*/1); + + const auto pvto1OuterTable = pvto1Table.getOuterTable(); + const auto pvto2OuterTable = pvto2Table.getOuterTable(); + + BOOST_CHECK_EQUAL(pvto1OuterTable->numRows(), 2); + BOOST_CHECK_EQUAL(pvto2OuterTable->numRows(), 3); + + BOOST_CHECK_EQUAL(pvto1OuterTable->numColumns(), 4); + BOOST_CHECK_EQUAL(pvto2OuterTable->numColumns(), 4); + + BOOST_CHECK_EQUAL(pvto1OuterTable->getGasSolubilityColumn().front(), 1.0); + BOOST_CHECK_EQUAL(pvto1OuterTable->getGasSolubilityColumn().back(), 8.0); + + BOOST_CHECK_EQUAL(pvto1OuterTable->getPressureColumn().front(), 2.0e5); + BOOST_CHECK_EQUAL(pvto1OuterTable->getPressureColumn().back(), 9.0e5); + + BOOST_CHECK_EQUAL(pvto1OuterTable->getOilFormationFactorColumn().front(), 3.0); + BOOST_CHECK_EQUAL(pvto1OuterTable->getOilFormationFactorColumn().back(), 10.0); + + BOOST_CHECK_EQUAL(pvto1OuterTable->getOilViscosityColumn().front(), 4.0e-3); + BOOST_CHECK_EQUAL(pvto1OuterTable->getOilViscosityColumn().back(), 11.0e-3); + + // for the second table, we only check the first column and trust + // that everything else is fine... + BOOST_CHECK_EQUAL(pvto2OuterTable->getGasSolubilityColumn().front(), 12.0); + BOOST_CHECK_EQUAL(pvto2OuterTable->getGasSolubilityColumn().back(), 23.0); +} From 808e2d3717ed8fc20559235798dea40686bf5a0f Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Mon, 28 Apr 2014 18:29:44 +0200 Subject: [PATCH 4/5] rename SimpleTable to SingleRecordTable and SimpleMultiRecordTable to MultiRecordTable because what's simple is in the eye of the beholder... --- opm/parser/eclipse/CMakeLists.txt | 4 ++-- opm/parser/eclipse/Utility/EnkrvdTable.hpp | 8 +++---- opm/parser/eclipse/Utility/EnptvdTable.hpp | 8 +++---- opm/parser/eclipse/Utility/FullTable.hpp | 16 ++++++------- ...tiRecordTable.cpp => MultiRecordTable.cpp} | 10 ++++---- ...tiRecordTable.hpp => MultiRecordTable.hpp} | 14 +++++------ opm/parser/eclipse/Utility/PlyadsTable.hpp | 6 ++--- opm/parser/eclipse/Utility/PlymaxTable.hpp | 6 ++--- opm/parser/eclipse/Utility/PlyrockTable.hpp | 6 ++--- opm/parser/eclipse/Utility/PlyviscTable.hpp | 6 ++--- opm/parser/eclipse/Utility/PvcdoTable.hpp | 8 +++---- opm/parser/eclipse/Utility/PvdgTable.hpp | 8 +++---- opm/parser/eclipse/Utility/PvdoTable.hpp | 8 +++---- opm/parser/eclipse/Utility/PvtgInnerTable.hpp | 8 +++---- opm/parser/eclipse/Utility/PvtgOuterTable.hpp | 6 ++--- opm/parser/eclipse/Utility/PvtoInnerTable.hpp | 8 +++---- opm/parser/eclipse/Utility/PvtoOuterTable.hpp | 6 ++--- opm/parser/eclipse/Utility/PvtwTable.hpp | 8 +++---- opm/parser/eclipse/Utility/RockTable.hpp | 8 +++---- opm/parser/eclipse/Utility/RocktabTable.hpp | 8 +++---- opm/parser/eclipse/Utility/SgofTable.hpp | 8 +++---- ...{SimpleTable.cpp => SingleRecordTable.cpp} | 10 ++++---- ...{SimpleTable.hpp => SingleRecordTable.hpp} | 16 ++++++------- opm/parser/eclipse/Utility/SwofTable.hpp | 8 +++---- opm/parser/eclipse/Utility/TlmixparTable.hpp | 6 ++--- .../eclipse/Utility/tests/TableTests.cpp | 24 +++++++++---------- 26 files changed, 116 insertions(+), 116 deletions(-) rename opm/parser/eclipse/Utility/{SimpleMultiRecordTable.cpp => MultiRecordTable.cpp} (90%) rename opm/parser/eclipse/Utility/{SimpleMultiRecordTable.hpp => MultiRecordTable.hpp} (84%) rename opm/parser/eclipse/Utility/{SimpleTable.cpp => SingleRecordTable.cpp} (86%) rename opm/parser/eclipse/Utility/{SimpleTable.hpp => SingleRecordTable.hpp} (88%) diff --git a/opm/parser/eclipse/CMakeLists.txt b/opm/parser/eclipse/CMakeLists.txt index 45029793c..f1c46425e 100644 --- a/opm/parser/eclipse/CMakeLists.txt +++ b/opm/parser/eclipse/CMakeLists.txt @@ -77,8 +77,8 @@ EclipseState/Schedule/GroupTree.cpp EclipseState/Grid/EclipseGrid.cpp) set (utility_source -Utility/SimpleTable.cpp -Utility/SimpleMultiRecordTable.cpp) +Utility/SingleRecordTable.cpp +Utility/MultiRecordTable.cpp) set( HEADER_FILES RawDeck/RawConsts.hpp diff --git a/opm/parser/eclipse/Utility/EnkrvdTable.hpp b/opm/parser/eclipse/Utility/EnkrvdTable.hpp index 20da29acc..37aa62634 100644 --- a/opm/parser/eclipse/Utility/EnkrvdTable.hpp +++ b/opm/parser/eclipse/Utility/EnkrvdTable.hpp @@ -19,11 +19,11 @@ #ifndef OPM_PARSER_ENKRVD_TABLE_HPP #define OPM_PARSER_ENKRVD_TABLE_HPP -#include "SimpleTable.hpp" +#include "SingleRecordTable.hpp" namespace Opm { - class EnkrvdTable : protected SimpleTable { - typedef SimpleTable ParentType; + class EnkrvdTable : protected SingleRecordTable { + typedef SingleRecordTable ParentType; public: using ParentType::numTables; @@ -35,7 +35,7 @@ namespace Opm { EnkrvdTable(Opm::DeckKeywordConstPtr keyword, int recordIdx = 0, int firstEntityOffset = 0) - : SimpleTable(keyword, + : SingleRecordTable(keyword, std::vector{"DEPTH", "KRWMAX", "KRGMAX", diff --git a/opm/parser/eclipse/Utility/EnptvdTable.hpp b/opm/parser/eclipse/Utility/EnptvdTable.hpp index 5016875c4..5c60499fe 100644 --- a/opm/parser/eclipse/Utility/EnptvdTable.hpp +++ b/opm/parser/eclipse/Utility/EnptvdTable.hpp @@ -19,11 +19,11 @@ #ifndef OPM_PARSER_ENPTVD_TABLE_HPP #define OPM_PARSER_ENPTVD_TABLE_HPP -#include "SimpleTable.hpp" +#include "SingleRecordTable.hpp" namespace Opm { - class EnptvdTable : protected SimpleTable { - typedef SimpleTable ParentType; + class EnptvdTable : protected SingleRecordTable { + typedef SingleRecordTable ParentType; public: using ParentType::numTables; @@ -35,7 +35,7 @@ namespace Opm { EnptvdTable(Opm::DeckKeywordConstPtr keyword, int recordIdx = 0, int firstEntityOffset = 0) - : SimpleTable(keyword, + : SingleRecordTable(keyword, std::vector{"DEPTH", "SWCO", "SWCRIT", diff --git a/opm/parser/eclipse/Utility/FullTable.hpp b/opm/parser/eclipse/Utility/FullTable.hpp index 462988cce..143856af9 100644 --- a/opm/parser/eclipse/Utility/FullTable.hpp +++ b/opm/parser/eclipse/Utility/FullTable.hpp @@ -19,8 +19,8 @@ #ifndef OPM_PARSER_FULL_TABLE_HPP #define OPM_PARSER_FULL_TABLE_HPP -#include -#include +#include +#include #include #include @@ -30,7 +30,7 @@ #include namespace Opm { - template + template class FullTable { typedef FullTable Self; @@ -79,11 +79,11 @@ namespace Opm { const std::vector &innerColumnNames, size_t tableIdx) { - m_outerTable.reset(new SimpleMultiRecordTable(keyword, outerColumnNames, tableIdx)); + m_outerTable.reset(new MultiRecordTable(keyword, outerColumnNames, tableIdx)); for (size_t rowIdx = 0; rowIdx < m_outerTable->numRecords(); ++rowIdx) { - Opm::SimpleTableConstPtr curRow( - new SimpleTable(keyword, + Opm::SingleRecordTableConstPtr curRow( + new SingleRecordTable(keyword, innerColumnNames, /*recordIdx=*/m_outerTable->firstRecordIndex() + rowIdx, /*firstColumnOffset=*/1)); @@ -107,8 +107,8 @@ namespace Opm { }; - typedef FullTable::Pointer FullTablePtr; - typedef FullTable::ConstPointer FullTableConstPtr; + typedef FullTable::Pointer FullTablePtr; + typedef FullTable::ConstPointer FullTableConstPtr; } #endif // OPM_PARSER_FULL_TABLE_HPP diff --git a/opm/parser/eclipse/Utility/SimpleMultiRecordTable.cpp b/opm/parser/eclipse/Utility/MultiRecordTable.cpp similarity index 90% rename from opm/parser/eclipse/Utility/SimpleMultiRecordTable.cpp rename to opm/parser/eclipse/Utility/MultiRecordTable.cpp index 0471fc336..de3f467de 100644 --- a/opm/parser/eclipse/Utility/SimpleMultiRecordTable.cpp +++ b/opm/parser/eclipse/Utility/MultiRecordTable.cpp @@ -16,14 +16,14 @@ You should have received a copy of the GNU General Public License along with OPM. If not, see . */ -#include +#include namespace Opm { /*! * \brief Returns the number of tables which can be found in a * given keyword. */ -size_t SimpleMultiRecordTable::numTables(Opm::DeckKeywordConstPtr keyword) +size_t MultiRecordTable::numTables(Opm::DeckKeywordConstPtr keyword) { size_t result = 0; @@ -42,7 +42,7 @@ size_t SimpleMultiRecordTable::numTables(Opm::DeckKeywordConstPtr keyword) } // create table from first few items of multiple records (i.e. getSIDoubleData() throws an exception) -SimpleMultiRecordTable::SimpleMultiRecordTable(Opm::DeckKeywordConstPtr keyword, +MultiRecordTable::MultiRecordTable(Opm::DeckKeywordConstPtr keyword, const std::vector &columnNames, size_t tableIdx, size_t firstEntityOffset) @@ -90,7 +90,7 @@ SimpleMultiRecordTable::SimpleMultiRecordTable(Opm::DeckKeywordConstPtr keyword, } } -size_t SimpleMultiRecordTable::getNumFlatItems_(Opm::DeckRecordConstPtr deckRecord) +size_t MultiRecordTable::getNumFlatItems_(Opm::DeckRecordConstPtr deckRecord) { int result = 0; for (unsigned i = 0; i < deckRecord->size(); ++ i) { @@ -103,7 +103,7 @@ size_t SimpleMultiRecordTable::getNumFlatItems_(Opm::DeckRecordConstPtr deckReco return result; } -double SimpleMultiRecordTable::getFlatSiDoubleData_(Opm::DeckRecordConstPtr deckRecord, unsigned flatItemIdx) const +double MultiRecordTable::getFlatSiDoubleData_(Opm::DeckRecordConstPtr deckRecord, unsigned flatItemIdx) const { unsigned itemFirstFlatIdx = 0; for (unsigned i = 0; i < deckRecord->size(); ++ i) { diff --git a/opm/parser/eclipse/Utility/SimpleMultiRecordTable.hpp b/opm/parser/eclipse/Utility/MultiRecordTable.hpp similarity index 84% rename from opm/parser/eclipse/Utility/SimpleMultiRecordTable.hpp rename to opm/parser/eclipse/Utility/MultiRecordTable.hpp index 99f806aaf..2f2839349 100644 --- a/opm/parser/eclipse/Utility/SimpleMultiRecordTable.hpp +++ b/opm/parser/eclipse/Utility/MultiRecordTable.hpp @@ -16,10 +16,10 @@ You should have received a copy of the GNU General Public License along with OPM. If not, see . */ -#ifndef OPM_PARSER_SIMPLE_MULTI_RECORD_TABLE_HPP -#define OPM_PARSER_SIMPLE_MULTI_RECORD_TABLE_HPP +#ifndef OPM_PARSER_MULTI_RECORD_TABLE_HPP +#define OPM_PARSER_MULTI_RECORD_TABLE_HPP -#include +#include #include @@ -31,7 +31,7 @@ namespace Opm { // create table from first few items of multiple records (i.e. getSIDoubleData() throws an exception) - class SimpleMultiRecordTable : public SimpleTable { + class MultiRecordTable : public SingleRecordTable { public: /*! * \brief Returns the number of tables which can be found in a @@ -45,7 +45,7 @@ namespace Opm { * 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, + MultiRecordTable(Opm::DeckKeywordConstPtr keyword, const std::vector &columnNames, size_t tableIndex, size_t firstEntityOffset = 0); @@ -72,8 +72,8 @@ namespace Opm { size_t m_numRecords; }; - typedef std::shared_ptr SimpleMultiRecordTablePtr; - typedef std::shared_ptr SimpleMultiRecordTableConstPtr; + typedef std::shared_ptr MultiRecordTablePtr; + typedef std::shared_ptr MultiRecordTableConstPtr; } diff --git a/opm/parser/eclipse/Utility/PlyadsTable.hpp b/opm/parser/eclipse/Utility/PlyadsTable.hpp index 49f5e7cd4..eb204c2ac 100644 --- a/opm/parser/eclipse/Utility/PlyadsTable.hpp +++ b/opm/parser/eclipse/Utility/PlyadsTable.hpp @@ -19,11 +19,11 @@ #ifndef OPM_PARSER_PLYADS_TABLE_HPP #define OPM_PARSER_PLYADS_TABLE_HPP -#include "SimpleTable.hpp" +#include "SingleRecordTable.hpp" namespace Opm { - class PlyadsTable : protected SimpleTable { - typedef SimpleTable ParentType; + class PlyadsTable : protected SingleRecordTable { + typedef SingleRecordTable ParentType; public: using ParentType::numTables; diff --git a/opm/parser/eclipse/Utility/PlymaxTable.hpp b/opm/parser/eclipse/Utility/PlymaxTable.hpp index 17a4b46b9..7a76347b8 100644 --- a/opm/parser/eclipse/Utility/PlymaxTable.hpp +++ b/opm/parser/eclipse/Utility/PlymaxTable.hpp @@ -19,11 +19,11 @@ #ifndef OPM_PARSER_PLYMAX_TABLE_HPP #define OPM_PARSER_PLYMAX_TABLE_HPP -#include "SimpleTable.hpp" +#include "SingleRecordTable.hpp" namespace Opm { - class PlymaxTable : protected SimpleTable { - typedef SimpleTable ParentType; + class PlymaxTable : protected SingleRecordTable { + typedef SingleRecordTable ParentType; public: using ParentType::numTables; diff --git a/opm/parser/eclipse/Utility/PlyrockTable.hpp b/opm/parser/eclipse/Utility/PlyrockTable.hpp index 401618ebb..7004c4bc0 100644 --- a/opm/parser/eclipse/Utility/PlyrockTable.hpp +++ b/opm/parser/eclipse/Utility/PlyrockTable.hpp @@ -19,11 +19,11 @@ #ifndef OPM_PARSER_PLYROCK_TABLE_HPP #define OPM_PARSER_PLYROCK_TABLE_HPP -#include "SimpleTable.hpp" +#include "SingleRecordTable.hpp" namespace Opm { - class PlyrockTable : protected SimpleTable { - typedef SimpleTable ParentType; + class PlyrockTable : protected SingleRecordTable { + typedef SingleRecordTable ParentType; public: using ParentType::numTables; diff --git a/opm/parser/eclipse/Utility/PlyviscTable.hpp b/opm/parser/eclipse/Utility/PlyviscTable.hpp index 2d2d34e1e..7f2bdb040 100644 --- a/opm/parser/eclipse/Utility/PlyviscTable.hpp +++ b/opm/parser/eclipse/Utility/PlyviscTable.hpp @@ -19,11 +19,11 @@ #ifndef OPM_PARSER_PLYVISC_TABLE_HPP #define OPM_PARSER_PLYVISC_TABLE_HPP -#include "SimpleTable.hpp" +#include "SingleRecordTable.hpp" namespace Opm { - class PlyviscTable : protected SimpleTable { - typedef SimpleTable ParentType; + class PlyviscTable : protected SingleRecordTable { + typedef SingleRecordTable ParentType; public: using ParentType::numTables; diff --git a/opm/parser/eclipse/Utility/PvcdoTable.hpp b/opm/parser/eclipse/Utility/PvcdoTable.hpp index 15fe01faa..55a36be31 100644 --- a/opm/parser/eclipse/Utility/PvcdoTable.hpp +++ b/opm/parser/eclipse/Utility/PvcdoTable.hpp @@ -19,11 +19,11 @@ #ifndef OPM_PARSER_PVCDO_TABLE_HPP #define OPM_PARSER_PVCDO_TABLE_HPP -#include "SimpleTable.hpp" +#include "SingleRecordTable.hpp" namespace Opm { - class PvcdoTable : protected SimpleTable { - typedef SimpleTable ParentType; + class PvcdoTable : protected SingleRecordTable { + typedef SingleRecordTable ParentType; public: using ParentType::numTables; @@ -35,7 +35,7 @@ namespace Opm { PvcdoTable(Opm::DeckKeywordConstPtr keyword, int recordIdx = 0, int firstEntityOffset = 0) - : SimpleTable(keyword, + : SingleRecordTable(keyword, std::vector{"P", "BW", "CW", "MUW", "CMUW"}, recordIdx, firstEntityOffset) {} diff --git a/opm/parser/eclipse/Utility/PvdgTable.hpp b/opm/parser/eclipse/Utility/PvdgTable.hpp index 71622331c..ad0a45cad 100644 --- a/opm/parser/eclipse/Utility/PvdgTable.hpp +++ b/opm/parser/eclipse/Utility/PvdgTable.hpp @@ -19,11 +19,11 @@ #ifndef OPM_PARSER_PVDG_TABLE_HPP #define OPM_PARSER_PVDG_TABLE_HPP -#include "SimpleTable.hpp" +#include "SingleRecordTable.hpp" namespace Opm { - class PvdgTable : protected SimpleTable { - typedef SimpleTable ParentType; + class PvdgTable : protected SingleRecordTable { + typedef SingleRecordTable ParentType; public: using ParentType::numTables; @@ -35,7 +35,7 @@ namespace Opm { PvdgTable(Opm::DeckKeywordConstPtr keyword, int recordIdx = 0, int firstEntityOffset = 0) - : SimpleTable(keyword, + : SingleRecordTable(keyword, std::vector{"P", "BG", "MUG"}, recordIdx, firstEntityOffset) {} diff --git a/opm/parser/eclipse/Utility/PvdoTable.hpp b/opm/parser/eclipse/Utility/PvdoTable.hpp index 5735e07bf..4459f979e 100644 --- a/opm/parser/eclipse/Utility/PvdoTable.hpp +++ b/opm/parser/eclipse/Utility/PvdoTable.hpp @@ -19,11 +19,11 @@ #ifndef OPM_PARSER_PVDO_TABLE_HPP #define OPM_PARSER_PVDO_TABLE_HPP -#include "SimpleTable.hpp" +#include "SingleRecordTable.hpp" namespace Opm { - class PvdoTable : protected SimpleTable { - typedef SimpleTable ParentType; + class PvdoTable : protected SingleRecordTable { + typedef SingleRecordTable ParentType; public: using ParentType::numTables; @@ -35,7 +35,7 @@ namespace Opm { PvdoTable(Opm::DeckKeywordConstPtr keyword, int recordIdx = 0, int firstEntityOffset = 0) - : SimpleTable(keyword, + : SingleRecordTable(keyword, std::vector{"P", "BO", "MUO"}, recordIdx, firstEntityOffset) {} diff --git a/opm/parser/eclipse/Utility/PvtgInnerTable.hpp b/opm/parser/eclipse/Utility/PvtgInnerTable.hpp index bc818bd13..1eff76096 100644 --- a/opm/parser/eclipse/Utility/PvtgInnerTable.hpp +++ b/opm/parser/eclipse/Utility/PvtgInnerTable.hpp @@ -19,11 +19,11 @@ #ifndef OPM_PARSER_PVTG_INNER_TABLE_HPP #define OPM_PARSER_PVTG_INNER_TABLE_HPP -#include "SimpleTable.hpp" +#include "SingleRecordTable.hpp" namespace Opm { - class PvtgInnerTable : protected SimpleTable { - typedef SimpleTable ParentType; + class PvtgInnerTable : protected SingleRecordTable { + typedef SingleRecordTable ParentType; public: using ParentType::numTables; @@ -35,7 +35,7 @@ namespace Opm { * The first value of the record (-> Rv) is skipped. */ PvtgInnerTable(Opm::DeckKeywordConstPtr keyword, size_t recordIdx = 0) - : SimpleTable(keyword, + : SingleRecordTable(keyword, std::vector{"RV", "BG", "MUG"}, recordIdx, 1U) {} diff --git a/opm/parser/eclipse/Utility/PvtgOuterTable.hpp b/opm/parser/eclipse/Utility/PvtgOuterTable.hpp index 6c376b9c0..ad832bc7f 100644 --- a/opm/parser/eclipse/Utility/PvtgOuterTable.hpp +++ b/opm/parser/eclipse/Utility/PvtgOuterTable.hpp @@ -19,11 +19,11 @@ #ifndef OPM_PARSER_PVTG_OUTER_TABLE_HPP #define OPM_PARSER_PVTG_OUTER_TABLE_HPP -#include "SimpleMultiRecordTable.hpp" +#include "MultiRecordTable.hpp" namespace Opm { - class PvtgOuterTable : protected SimpleMultiRecordTable { - typedef SimpleMultiRecordTable ParentType; + class PvtgOuterTable : protected MultiRecordTable { + typedef MultiRecordTable ParentType; public: using ParentType::numTables; diff --git a/opm/parser/eclipse/Utility/PvtoInnerTable.hpp b/opm/parser/eclipse/Utility/PvtoInnerTable.hpp index 8782d1284..1761736b1 100644 --- a/opm/parser/eclipse/Utility/PvtoInnerTable.hpp +++ b/opm/parser/eclipse/Utility/PvtoInnerTable.hpp @@ -19,11 +19,11 @@ #ifndef OPM_PARSER_PVTO_INNER_TABLE_HPP #define OPM_PARSER_PVTO_INNER_TABLE_HPP -#include "SimpleTable.hpp" +#include "SingleRecordTable.hpp" namespace Opm { - class PvtoInnerTable : protected SimpleTable { - typedef SimpleTable ParentType; + class PvtoInnerTable : protected SingleRecordTable { + typedef SingleRecordTable ParentType; public: using ParentType::numTables; @@ -35,7 +35,7 @@ namespace Opm { * The first value of the record (-> Rs) is skipped. */ PvtoInnerTable(Opm::DeckKeywordConstPtr keyword, int recordIdx = 0) - : SimpleTable(keyword, + : SingleRecordTable(keyword, std::vector{"P", "BO", "MU"}, recordIdx, /*firstEntityOffset=*/1) {} diff --git a/opm/parser/eclipse/Utility/PvtoOuterTable.hpp b/opm/parser/eclipse/Utility/PvtoOuterTable.hpp index 0289d13eb..e9139a009 100644 --- a/opm/parser/eclipse/Utility/PvtoOuterTable.hpp +++ b/opm/parser/eclipse/Utility/PvtoOuterTable.hpp @@ -19,11 +19,11 @@ #ifndef OPM_PARSER_PVTO_OUTER_TABLE_HPP #define OPM_PARSER_PVTO_OUTER_TABLE_HPP -#include "SimpleMultiRecordTable.hpp" +#include "MultiRecordTable.hpp" namespace Opm { - class PvtoOuterTable : protected SimpleMultiRecordTable { - typedef SimpleMultiRecordTable ParentType; + class PvtoOuterTable : protected MultiRecordTable { + typedef MultiRecordTable ParentType; public: using ParentType::numTables; diff --git a/opm/parser/eclipse/Utility/PvtwTable.hpp b/opm/parser/eclipse/Utility/PvtwTable.hpp index 3bcbf5ce4..1c2ca459a 100644 --- a/opm/parser/eclipse/Utility/PvtwTable.hpp +++ b/opm/parser/eclipse/Utility/PvtwTable.hpp @@ -19,11 +19,11 @@ #ifndef OPM_PARSER_PVTW_TABLE_HPP #define OPM_PARSER_PVTW_TABLE_HPP -#include "SimpleTable.hpp" +#include "SingleRecordTable.hpp" namespace Opm { - class PvtwTable : protected SimpleTable { - typedef SimpleTable ParentType; + class PvtwTable : protected SingleRecordTable { + typedef SingleRecordTable ParentType; public: using ParentType::numTables; @@ -35,7 +35,7 @@ namespace Opm { PvtwTable(Opm::DeckKeywordConstPtr keyword, int recordIdx = 0, int firstEntityOffset = 0) - : SimpleTable(keyword, + : SingleRecordTable(keyword, std::vector{"P", "BW", "CW", "MUW", "CMUW"}, recordIdx, firstEntityOffset) {} diff --git a/opm/parser/eclipse/Utility/RockTable.hpp b/opm/parser/eclipse/Utility/RockTable.hpp index c354bef66..24ccff5ee 100644 --- a/opm/parser/eclipse/Utility/RockTable.hpp +++ b/opm/parser/eclipse/Utility/RockTable.hpp @@ -19,11 +19,11 @@ #ifndef OPM_PARSER_ROCK_TABLE_HPP #define OPM_PARSER_ROCK_TABLE_HPP -#include "SimpleTable.hpp" +#include "SingleRecordTable.hpp" namespace Opm { - class RockTable : protected SimpleTable { - typedef SimpleTable ParentType; + class RockTable : protected SingleRecordTable { + typedef SingleRecordTable ParentType; public: using ParentType::numTables; @@ -35,7 +35,7 @@ namespace Opm { RockTable(Opm::DeckKeywordConstPtr keyword, int recordIdx = 0, int firstEntityOffset = 0) - : SimpleTable(keyword, + : SingleRecordTable(keyword, std::vector{"P_REF", "COMPRESSIBILITY"}, recordIdx, firstEntityOffset) {} diff --git a/opm/parser/eclipse/Utility/RocktabTable.hpp b/opm/parser/eclipse/Utility/RocktabTable.hpp index 2a468ca5a..f3d794503 100644 --- a/opm/parser/eclipse/Utility/RocktabTable.hpp +++ b/opm/parser/eclipse/Utility/RocktabTable.hpp @@ -19,11 +19,11 @@ #ifndef OPM_PARSER_ROCKTAB_TABLE_HPP #define OPM_PARSER_ROCKTAB_TABLE_HPP -#include "SimpleTable.hpp" +#include "SingleRecordTable.hpp" namespace Opm { - class RocktabTable : protected SimpleTable { - typedef SimpleTable ParentType; + class RocktabTable : protected SingleRecordTable { + typedef SingleRecordTable ParentType; public: using ParentType::numTables; @@ -36,7 +36,7 @@ namespace Opm { bool isDirectional, int recordIdx = 0, int firstEntityOffset = 0) - : SimpleTable(keyword, + : SingleRecordTable(keyword, isDirectional ? std::vector{"PO", "PV_MULT", "TRANSMIS_MULT_X", "TRANSMIS_MULT_Y", "TRANSMIS_MULT_Z"} : std::vector{"PO", "PV_MULT", "TRANSMIS_MULT"}, diff --git a/opm/parser/eclipse/Utility/SgofTable.hpp b/opm/parser/eclipse/Utility/SgofTable.hpp index a5d110fea..1c01dc203 100644 --- a/opm/parser/eclipse/Utility/SgofTable.hpp +++ b/opm/parser/eclipse/Utility/SgofTable.hpp @@ -19,11 +19,11 @@ #ifndef OPM_PARSER_SGOF_TABLE_HPP #define OPM_PARSER_SGOF_TABLE_HPP -#include "SimpleTable.hpp" +#include "SingleRecordTable.hpp" namespace Opm { - class SgofTable : protected SimpleTable { - typedef SimpleTable ParentType; + class SgofTable : protected SingleRecordTable { + typedef SingleRecordTable ParentType; public: using ParentType::numTables; @@ -35,7 +35,7 @@ namespace Opm { SgofTable(Opm::DeckKeywordConstPtr keyword, int recordIdx = 0, int firstEntityOffset = 0) - : SimpleTable(keyword, + : SingleRecordTable(keyword, std::vector{"SG", "KRG", "KROG", "PCOG"}, recordIdx, firstEntityOffset) {} diff --git a/opm/parser/eclipse/Utility/SimpleTable.cpp b/opm/parser/eclipse/Utility/SingleRecordTable.cpp similarity index 86% rename from opm/parser/eclipse/Utility/SimpleTable.cpp rename to opm/parser/eclipse/Utility/SingleRecordTable.cpp index fc4c4d283..df6534e7f 100644 --- a/opm/parser/eclipse/Utility/SimpleTable.cpp +++ b/opm/parser/eclipse/Utility/SingleRecordTable.cpp @@ -16,11 +16,11 @@ You should have received a copy of the GNU General Public License along with OPM. If not, see . */ -#include +#include namespace Opm { // create table from single record -SimpleTable::SimpleTable(Opm::DeckKeywordConstPtr keyword, +SingleRecordTable::SingleRecordTable(Opm::DeckKeywordConstPtr keyword, const std::vector &columnNames, size_t recordIdx, size_t firstEntityOffset) @@ -47,7 +47,7 @@ SimpleTable::SimpleTable(Opm::DeckKeywordConstPtr keyword, } } -void SimpleTable::createColumns_(const std::vector &columnNames) +void SingleRecordTable::createColumns_(const std::vector &columnNames) { // Allocate column names. TODO (?): move the column names into // the json description of the keyword. @@ -60,7 +60,7 @@ void SimpleTable::createColumns_(const std::vector &columnNames) m_columns.resize(columnIdx); } -size_t SimpleTable::getNumFlatItems_(Opm::DeckRecordConstPtr deckRecord) const +size_t SingleRecordTable::getNumFlatItems_(Opm::DeckRecordConstPtr deckRecord) const { size_t result = 0; for (size_t i = 0; i < deckRecord->size(); ++ i) { @@ -70,7 +70,7 @@ size_t SimpleTable::getNumFlatItems_(Opm::DeckRecordConstPtr deckRecord) const return result; } -double SimpleTable::getFlatSiDoubleData_(Opm::DeckRecordConstPtr deckRecord, size_t flatItemIdx) const +double SingleRecordTable::getFlatSiDoubleData_(Opm::DeckRecordConstPtr deckRecord, size_t flatItemIdx) const { size_t itemFirstFlatIdx = 0; for (unsigned i = 0; i < deckRecord->size(); ++ i) { diff --git a/opm/parser/eclipse/Utility/SimpleTable.hpp b/opm/parser/eclipse/Utility/SingleRecordTable.hpp similarity index 88% rename from opm/parser/eclipse/Utility/SimpleTable.hpp rename to opm/parser/eclipse/Utility/SingleRecordTable.hpp index e455547a8..53cbf95dd 100644 --- a/opm/parser/eclipse/Utility/SimpleTable.hpp +++ b/opm/parser/eclipse/Utility/SingleRecordTable.hpp @@ -16,8 +16,8 @@ You should have received a copy of the GNU General Public License along with OPM. If not, see . */ -#ifndef OPM_PARSER_SIMPLE_TABLE_HPP -#define OPM_PARSER_SIMPLE_TABLE_HPP +#ifndef OPM_PARSER_SINGLE_RECORD_TABLE_HPP +#define OPM_PARSER_SINGLE_RECORD_TABLE_HPP #include @@ -28,10 +28,10 @@ #include namespace Opm { - class SimpleTable { + class SingleRecordTable { protected: // protected default constructor for the derived classes - SimpleTable() {} + SingleRecordTable() {} public: /*! @@ -49,13 +49,13 @@ namespace Opm { * This requires all data to be a list of doubles in the first * item of a given record index. */ - SimpleTable(Opm::DeckKeywordConstPtr keyword, + SingleRecordTable(Opm::DeckKeywordConstPtr keyword, const std::vector &columnNames, size_t recordIdx = 0, size_t firstEntityOffset = 0); // constructor to make the base class compatible with specialized table implementations - SimpleTable(Opm::DeckKeywordConstPtr /* keyword */, + SingleRecordTable(Opm::DeckKeywordConstPtr /* keyword */, size_t /* recordIdx = 0 */, size_t /* firstEntityOffset = 0 */) { @@ -95,8 +95,8 @@ namespace Opm { std::vector > m_columns; }; - typedef std::shared_ptr SimpleTablePtr; - typedef std::shared_ptr SimpleTableConstPtr; + typedef std::shared_ptr SingleRecordTablePtr; + typedef std::shared_ptr SingleRecordTableConstPtr; } #endif // OPM_PARSER_SIMPLE_TABLE_HPP diff --git a/opm/parser/eclipse/Utility/SwofTable.hpp b/opm/parser/eclipse/Utility/SwofTable.hpp index bf3fe9554..7732ef0f7 100644 --- a/opm/parser/eclipse/Utility/SwofTable.hpp +++ b/opm/parser/eclipse/Utility/SwofTable.hpp @@ -19,11 +19,11 @@ #ifndef OPM_PARSER_SWOF_TABLE_HPP #define OPM_PARSER_SWOF_TABLE_HPP -#include "SimpleTable.hpp" +#include "SingleRecordTable.hpp" namespace Opm { - class SwofTable : protected SimpleTable { - typedef SimpleTable ParentType; + class SwofTable : protected SingleRecordTable { + typedef SingleRecordTable ParentType; public: using ParentType::numTables; @@ -35,7 +35,7 @@ namespace Opm { SwofTable(Opm::DeckKeywordConstPtr keyword, int recordIdx = 0, int firstEntityOffset = 0) - : SimpleTable(keyword, + : SingleRecordTable(keyword, std::vector{"SW", "KRW", "KROW", "PCOW"}, recordIdx, firstEntityOffset) {} diff --git a/opm/parser/eclipse/Utility/TlmixparTable.hpp b/opm/parser/eclipse/Utility/TlmixparTable.hpp index 28e84e144..c3725831e 100644 --- a/opm/parser/eclipse/Utility/TlmixparTable.hpp +++ b/opm/parser/eclipse/Utility/TlmixparTable.hpp @@ -19,11 +19,11 @@ #ifndef OPM_PARSER_TLMIXPAR_TABLE_HPP #define OPM_PARSER_TLMIXPAR_TABLE_HPP -#include "SimpleTable.hpp" +#include "SingleRecordTable.hpp" namespace Opm { - class TlmixparTable : protected SimpleTable { - typedef SimpleTable ParentType; + class TlmixparTable : protected SingleRecordTable { + typedef SingleRecordTable ParentType; public: using ParentType::numTables; diff --git a/opm/parser/eclipse/Utility/tests/TableTests.cpp b/opm/parser/eclipse/Utility/tests/TableTests.cpp index 82ddd02a9..70a44c60d 100644 --- a/opm/parser/eclipse/Utility/tests/TableTests.cpp +++ b/opm/parser/eclipse/Utility/tests/TableTests.cpp @@ -20,8 +20,8 @@ #include // generic table classes -#include -#include +#include +#include #include // keyword specific table classes @@ -29,7 +29,7 @@ #include #include -#define BOOST_TEST_MODULE SimpleTableTests +#define BOOST_TEST_MODULE SingleRecordTableTests #include #include @@ -38,7 +38,7 @@ #include #include -BOOST_AUTO_TEST_CASE(CreateSimpleTable) { +BOOST_AUTO_TEST_CASE(CreateSingleRecordTable) { const char *deckData = "TABDIMS\n" " 2 /\n" @@ -55,17 +55,17 @@ BOOST_AUTO_TEST_CASE(CreateSimpleTable) { std::vector justRightColumnNames{"A", "B", "C", "D"}; std::vector tooManyColumnNames{"A", "B", "C", "D", "E"}; - BOOST_CHECK_EQUAL(Opm::SimpleTable::numTables(deck->getKeyword("SWOF")), 2); - BOOST_CHECK_THROW(Opm::SimpleTable(deck->getKeyword("SWOF"), + BOOST_CHECK_EQUAL(Opm::SingleRecordTable::numTables(deck->getKeyword("SWOF")), 2); + BOOST_CHECK_THROW(Opm::SingleRecordTable(deck->getKeyword("SWOF"), tooFewColumnNames, /*recordIdx=*/0), std::runtime_error); - BOOST_CHECK_THROW(Opm::SimpleTable(deck->getKeyword("SWOF"), + BOOST_CHECK_THROW(Opm::SingleRecordTable(deck->getKeyword("SWOF"), tooManyColumnNames, /*recordIdx=*/0), std::runtime_error); - Opm::SimpleTable foo(deck->getKeyword("SWOF"), + Opm::SingleRecordTable foo(deck->getKeyword("SWOF"), justRightColumnNames, /*recordIdx=*/0); } @@ -92,21 +92,21 @@ BOOST_AUTO_TEST_CASE(CreateMultiTable) { std::vector justRightColumnNames{"A", "B", "C", "D"}; std::vector tooManyColumnNames{"A", "B", "C", "D", "E"}; - BOOST_CHECK_EQUAL(Opm::SimpleMultiRecordTable::numTables(deck->getKeyword("PVTO")), 2); + BOOST_CHECK_EQUAL(Opm::MultiRecordTable::numTables(deck->getKeyword("PVTO")), 2); // this mistake can't be detected as the MultiRecordTable takes // the first $N items as the column names... /* - BOOST_CHECK_THROW(Opm::SimpleMultiRecordTable(deck->getKeyword("PVTO"), + BOOST_CHECK_THROW(Opm::MultiRecordTable(deck->getKeyword("PVTO"), tooFewColumnNames, 0), std::runtime_error); */ - BOOST_CHECK_THROW(Opm::SimpleMultiRecordTable(deck->getKeyword("PVTO"), + BOOST_CHECK_THROW(Opm::MultiRecordTable(deck->getKeyword("PVTO"), tooManyColumnNames, /*tableIdx=*/0), std::runtime_error); - Opm::SimpleMultiRecordTable foo(deck->getKeyword("PVTO"), + Opm::MultiRecordTable foo(deck->getKeyword("PVTO"), justRightColumnNames, /*recordIdx=*/0); } From 1909e22f48faf5f13924801e36aa412c85e70993 Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Mon, 28 Apr 2014 21:04:38 +0200 Subject: [PATCH 5/5] fix the "number of table" calculation for multi-record tables It turns out that the empty-record detection worked fine, but that the last empty record of a keyword is ignored by opm-parser for reasons which are not clear to me... Now all unit tests pass. --- opm/parser/eclipse/Utility/MultiRecordTable.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/opm/parser/eclipse/Utility/MultiRecordTable.cpp b/opm/parser/eclipse/Utility/MultiRecordTable.cpp index de3f467de..8696b10f4 100644 --- a/opm/parser/eclipse/Utility/MultiRecordTable.cpp +++ b/opm/parser/eclipse/Utility/MultiRecordTable.cpp @@ -38,6 +38,10 @@ size_t MultiRecordTable::numTables(Opm::DeckKeywordConstPtr keyword) ++ result; } + // the last empty record of a keyword seems to go MIA for some + // strange reason... + ++result; + return result; }