From bd73bb6c556d639f4416acb527d28bd7caab669a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Thu, 28 Mar 2019 11:25:14 +0100 Subject: [PATCH] Linearised Table: Add Constructor with User-Defined Fill Value Reimplement original constructor in terms of the new constructor. The main purpose of the new constructor is to support PVT tables which use a fill/padding value different from 1.0e+20. --- opm/output/eclipse/LinearisedOutputTable.hpp | 30 +++++++++++++ .../output/eclipse/LinearisedOutputTable.cpp | 32 +++++++++++++- tests/test_LinearisedOutputTable.cpp | 42 +++++++++++++++++++ 3 files changed, 103 insertions(+), 1 deletion(-) diff --git a/opm/output/eclipse/LinearisedOutputTable.hpp b/opm/output/eclipse/LinearisedOutputTable.hpp index 337383794..11a0a9664 100644 --- a/opm/output/eclipse/LinearisedOutputTable.hpp +++ b/opm/output/eclipse/LinearisedOutputTable.hpp @@ -1,4 +1,5 @@ /* + Copyright 2019 Equinor. Copyright 2017 Statoil ASA. This file is part of the Open Porous Media project (OPM). @@ -35,6 +36,8 @@ namespace Opm { public: /// Constructor. /// + /// Padded table entries set to +1.0e+20. + /// /// \param[in] numTables Number of tables managed by internal /// buffer. Typically corresponds to maximum value of a region /// ID vector such as SATNUM, IMBNUM, or PVTNUM. @@ -57,6 +60,33 @@ namespace Opm { const std::size_t numRows, const std::size_t numCols); + /// Constructor. + /// + /// \param[in] numTables Number of tables managed by internal + /// buffer. Typically corresponds to maximum value of a region + /// ID vector such as SATNUM, IMBNUM, or PVTNUM. + /// + /// \param[in] numPrimary Number of primary look-up keys for the + /// tabular data managed by the internal buffer. Mostly relevant + /// (i.e., greater than one) for miscible oil ("PVTO") or + /// miscible gas ("PVTG") tables and typically corresponds to the + /// number of Rs/Rv entries from the TABDIMS keyword. + /// + /// \param[in] numRows Number of rows in each sub-table + /// corresponding to a single primary look-up key. Typically the + /// number of nodes (e.g., NSSFUN or NPPVT) of the corresponding + /// input keyword. + /// + /// \param[in] numCols Number of columns in each sub-table (and main + /// table). Typically 5. + /// + /// \param[in] fillValue Data element value for padded table entries. + LinearisedOutputTable(const std::size_t numTables, + const std::size_t numPrimary, + const std::size_t numRows, + const std::size_t numCols, + const double fillValue); + /// Retrieve iterator to start of \c numRows (contiguous) column /// elements of a particular sub-table of a particular main table. /// diff --git a/src/opm/output/eclipse/LinearisedOutputTable.cpp b/src/opm/output/eclipse/LinearisedOutputTable.cpp index 5f5c4e96a..3ddb7365b 100644 --- a/src/opm/output/eclipse/LinearisedOutputTable.cpp +++ b/src/opm/output/eclipse/LinearisedOutputTable.cpp @@ -1,3 +1,23 @@ +/* + Copyright 2019 Equinor. + Copyright 2017 Statoil ASA. + + This file is part of the Open Porous Media project (OPM). + + OPM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OPM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with OPM. If not, see . +*/ + #include #include @@ -10,7 +30,17 @@ LinearisedOutputTable(const std::size_t numTables0, const std::size_t numPrimary0, const std::size_t numRows0, const std::size_t numCols0) - : data (numTables0 * numPrimary0 * numRows0 * numCols0, 1.0e20) + : LinearisedOutputTable(numTables0, numPrimary0, + numRows0, numCols0, 1.0e20) +{} + +Opm::LinearisedOutputTable:: +LinearisedOutputTable(const std::size_t numTables0, + const std::size_t numPrimary0, + const std::size_t numRows0, + const std::size_t numCols0, + const double fillValue) + : data (numTables0 * numPrimary0 * numRows0 * numCols0, fillValue) , numTables (numTables0) , numPrimary(numPrimary0) , numRows (numRows0) diff --git a/tests/test_LinearisedOutputTable.cpp b/tests/test_LinearisedOutputTable.cpp index f8f0c6ddc..20e136eb8 100644 --- a/tests/test_LinearisedOutputTable.cpp +++ b/tests/test_LinearisedOutputTable.cpp @@ -125,6 +125,48 @@ namespace { } } // Anonymous +// --------------------------------------------------------------------- +// Constructors + +BOOST_AUTO_TEST_SUITE (Basic_Operations) + +BOOST_AUTO_TEST_CASE (Construct_Defaulted_FillVal) +{ + const auto numTables = std::size_t{2}; + const auto numPrimary = std::size_t{3}; + const auto numRows = std::size_t{4}; + const auto numCols = std::size_t{5}; + + auto linTable = ::Opm::LinearisedOutputTable { + numTables, numPrimary, numRows, numCols + }; + + const auto expect_initial = std::vector( + numTables * numPrimary * numRows * numCols, 1.0e20); + + check_is_close(linTable.getData(), expect_initial); +} + +BOOST_AUTO_TEST_CASE (Construct_UserDefined_FillVal) +{ + const auto numTables = std::size_t{2}; + const auto numPrimary = std::size_t{3}; + const auto numRows = std::size_t{4}; + const auto numCols = std::size_t{5}; + const auto fillVal = 1.234e-5; + + auto linTable = ::Opm::LinearisedOutputTable { + numTables, numPrimary, numRows, numCols, fillVal + }; + + const auto expect_initial = std::vector( + numTables * numPrimary * numRows * numCols, fillVal); + + check_is_close(linTable.getData(), expect_initial); +} + +BOOST_AUTO_TEST_SUITE_END () + // --------------------------------------------------------------------- // Saturation Functions