From fa572188fa040cb36c63e48119e78b398e4a7492 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Wed, 12 Feb 2020 15:04:21 +0100 Subject: [PATCH] changed: avoid use of boost::multi_array in VFPProdTable --- .../EclipseState/Schedule/VFPProdTable.hpp | 21 +-- .../EclipseState/Schedule/VFPProdTable.cpp | 125 ++++++++---------- tests/parser/TableManagerTests.cpp | 21 ++- 3 files changed, 76 insertions(+), 91 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/Schedule/VFPProdTable.hpp b/opm/parser/eclipse/EclipseState/Schedule/VFPProdTable.hpp index 495f90efc..916918e82 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/VFPProdTable.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/VFPProdTable.hpp @@ -21,7 +21,8 @@ #define OPM_PARSER_ECLIPSE_ECLIPSESTATE_TABLES_VFPPRODTABLE_HPP_ -#include +#include +#include namespace Opm { @@ -34,8 +35,7 @@ namespace Opm { */ class VFPProdTable { public: - typedef boost::multi_array array_type; - typedef boost::array extents; + typedef std::vector array_type; enum FLO_TYPE { FLO_OIL=1, @@ -130,12 +130,10 @@ public: } /** - * Returns the data of the table itself. The data is ordered so that + * Returns the data of the table itself. For ordered access + * use operator()(thp_idx, wfr_idx, gfr_idx, alq_idx, flo_idx) * - * table = getTable(); - * bhp = table[thp_idx][wfr_idx][gfr_idx][alq_idx][flo_idx]; - * - * gives the bottom hole pressure value in the table for the coordinate + * This gives the bottom hole pressure value in the table for the coordinate * given by * flo_axis = getFloAxis(); * thp_axis = getTHPAxis(); @@ -150,7 +148,10 @@ public: } bool operator==(const VFPProdTable& data) const; - VFPProdTable& operator=(const VFPProdTable& data); + + std::array shape() const; + + double operator()(size_t thp_idx, size_t wfr_idx, size_t gfr_idx, size_t alq_idx, size_t flo_idx) const; private: @@ -171,6 +172,8 @@ private: void check(const DeckKeyword& table, const double factor); + double& operator()(size_t thp_idx, size_t wfr_idx, size_t gfr_idx, size_t alq_idx, size_t flo_idx); + static void scaleValues(std::vector& values, const double& scaling_factor); diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/VFPProdTable.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/VFPProdTable.cpp index 744c594a3..cca2e5ec8 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/VFPProdTable.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/VFPProdTable.cpp @@ -18,6 +18,8 @@ */ #include +#include +#include #include #include @@ -159,14 +161,6 @@ VFPProdTable::VFPProdTable(int table_num, m_wfr_data = wfr_data; m_gfr_data = gfr_data; m_alq_data = alq_data; - - extents shape; - shape[0] = data.shape()[0]; - shape[1] = data.shape()[1]; - shape[2] = data.shape()[2]; - shape[3] = data.shape()[3]; - shape[4] = data.shape()[4]; - m_data.resize(shape); m_data = data; //check(); @@ -276,14 +270,8 @@ VFPProdTable::VFPProdTable( const DeckKeyword& table, const UnitSystem& deck_uni size_t ng = m_gfr_data.size(); size_t na = m_alq_data.size(); size_t nf = m_flo_data.size(); - extents shape; - shape[0] = nt; - shape[1] = nw; - shape[2] = ng; - shape[3] = na; - shape[4] = nf; - m_data.resize(shape); - std::fill_n(m_data.data(), m_data.num_elements(), std::nan("0")); + m_data.resize(nt*nw*ng*na*nf); + std::fill_n(m_data.data(), m_data.size(), std::nan("0")); //Check that size of table matches size of axis: if (table.size() != nt*nw*ng*na + 6) { @@ -315,7 +303,7 @@ VFPProdTable::VFPProdTable( const DeckKeyword& table, const UnitSystem& deck_uni << t << "," << w << "," << g << "," << a << "," << f << "]=" << bhp_tht[f] << " too large" << std::endl; } - m_data[t][w][g][a][f] = table_scaling_factor*bhp_tht[f]; + (*this)(t,w,g,a,f) = table_scaling_factor*bhp_tht[f]; } } @@ -355,54 +343,42 @@ void VFPProdTable::check(const DeckKeyword& keyword, const double table_scaling_ assert(std::is_sorted(m_gfr_data.begin(), m_gfr_data.end())); assert(std::is_sorted(m_alq_data.begin(), m_alq_data.end())); + size_t nt = m_thp_data.size(); + size_t nw = m_wfr_data.size(); + size_t ng = m_gfr_data.size(); + size_t na = m_alq_data.size(); + size_t nf = m_flo_data.size(); + //Check data size matches axes - assert(m_data.num_dimensions() == 5); - assert(m_data.shape()[0] == m_thp_data.size()); - assert(m_data.shape()[1] == m_wfr_data.size()); - assert(m_data.shape()[2] == m_gfr_data.size()); - assert(m_data.shape()[3] == m_alq_data.size()); - assert(m_data.shape()[4] == m_flo_data.size()); + assert(m_data.size() == nt*nw*ng*na*nf); - - //Check that all elements have been set + //Check that bhp(thp) is a monotonic increasing function. + //If this is not the case, we might not be able to determine + //the thp from the bhp easily typedef array_type::size_type size_type; - for (size_type t=0; t VFPProdTable::shape() const { + size_t nt = m_thp_data.size(); + size_t nw = m_wfr_data.size(); + size_t ng = m_gfr_data.size(); + size_t na = m_alq_data.size(); + size_t nf = m_flo_data.size(); + + return {nt, nw, ng, na, nf}; } } //Namespace opm diff --git a/tests/parser/TableManagerTests.cpp b/tests/parser/TableManagerTests.cpp index 099f20d48..8dd63162f 100644 --- a/tests/parser/TableManagerTests.cpp +++ b/tests/parser/TableManagerTests.cpp @@ -737,8 +737,7 @@ VFPPROD \n\ //The data itself { typedef Opm::VFPProdTable::array_type::size_type size_type; - const Opm::VFPProdTable::array_type& data = vfpprodTable.getTable(); - const size_type* size = data.shape(); + const auto size = vfpprodTable.shape(); BOOST_CHECK_EQUAL(size[0], 2); BOOST_CHECK_EQUAL(size[1], 2); @@ -750,13 +749,13 @@ VFPPROD \n\ double conversion_factor = 100000.0; double index = 0.5; - for (size_type a=0; a(vfpprodTable)(t,w,g,a,f), index*conversion_factor); } } } @@ -855,15 +854,13 @@ VFPPROD \n\ //The data itself { - typedef Opm::VFPProdTable::array_type::size_type size_type; - const Opm::VFPProdTable::array_type& data = vfpprodTable.getTable(); - const size_type* size = data.shape(); + const auto size = vfpprodTable.shape(); //Table given as BHP => barsa. Convert to pascal double conversion_factor = 100000.0; BOOST_CHECK_EQUAL(size[0]*size[1]*size[2]*size[3]*size[4], 1); - BOOST_CHECK_EQUAL(data[0][0][0][0][0], 1.5*conversion_factor); + BOOST_CHECK_EQUAL(const_cast(vfpprodTable)(0,0,0,0,0), 1.5*conversion_factor); } }