From 99c019a6bb1f8a22a17f80ef28d02051176e1c62 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Wed, 12 Feb 2020 15:38:02 +0100 Subject: [PATCH] adjust serialization of VFPProdTable --- opm/simulators/utils/ParallelRestart.cpp | 16 +++------------- opm/simulators/wells/VFPHelpers.hpp | 6 +++--- opm/simulators/wells/VFPProdProperties.cpp | 5 ++--- opm/simulators/wells/VFPProdProperties.hpp | 2 +- tests/test_ParallelRestart.cpp | 13 +++---------- tests/test_vfpproperties.cpp | 16 +++++++++------- 6 files changed, 21 insertions(+), 37 deletions(-) diff --git a/opm/simulators/utils/ParallelRestart.cpp b/opm/simulators/utils/ParallelRestart.cpp index 5e7ddf4c8..9dda2019e 100644 --- a/opm/simulators/utils/ParallelRestart.cpp +++ b/opm/simulators/utils/ParallelRestart.cpp @@ -1132,8 +1132,7 @@ std::size_t packSize(const VFPProdTable& data, packSize(data.getWFRAxis(), comm) + packSize(data.getGFRAxis(), comm) + packSize(data.getALQAxis(), comm) + - data.getTable().num_elements() * - packSize(double(), comm); + packSize(data.getTable(), comm); } std::size_t packSize(const WellTestConfig::WTESTWell& data, @@ -2868,8 +2867,7 @@ void pack(const VFPProdTable& data, pack(data.getWFRAxis(), buffer, position, comm); pack(data.getGFRAxis(), buffer, position, comm); pack(data.getALQAxis(), buffer, position, comm); - for (size_t i = 0; i < data.getTable().num_elements(); ++i) - pack(*(data.getTable().data() + i), buffer, position, comm); + pack(data.getTable(), buffer, position, comm); } void pack(const WellTestConfig::WTESTWell& data, @@ -5070,15 +5068,7 @@ void unpack(VFPProdTable& data, unpack(wfrAxis, buffer, position, comm); unpack(gfrAxis, buffer, position, comm); unpack(alqAxis, buffer, position, comm); - VFPProdTable::extents extents; - extents[0] = thpAxis.size(); - extents[1] = wfrAxis.size(); - extents[2] = gfrAxis.size(); - extents[3] = alqAxis.size(); - extents[4] = floAxis.size(); - table.resize(extents); - for (size_t i = 0; i < table.num_elements(); ++i) - unpack(*(table.data() + i), buffer, position, comm); + unpack(table, buffer, position, comm); data = VFPProdTable(tableNum, datumDepth, floType, wfrType, gfrType, alqType, floAxis, thpAxis, diff --git a/opm/simulators/wells/VFPHelpers.hpp b/opm/simulators/wells/VFPHelpers.hpp index e97cda9a6..60a965df6 100644 --- a/opm/simulators/wells/VFPHelpers.hpp +++ b/opm/simulators/wells/VFPHelpers.hpp @@ -332,7 +332,7 @@ inline VFPEvaluation operator*( * Helper function which interpolates data using the indices etc. given in the inputs. */ inline VFPEvaluation interpolate( - const VFPProdTable::array_type& array, + const VFPProdTable& table, const InterpData& flo_i, const InterpData& thp_i, const InterpData& wfr_i, @@ -361,7 +361,7 @@ inline VFPEvaluation interpolate( const int fi = flo_i.ind_[f]; //Copy element - nn[t][w][g][a][f].value = array[ti][wi][gi][ai][fi]; + nn[t][w][g][a][f].value = table(ti,wi,gi,ai,fi); } } } @@ -522,7 +522,7 @@ inline VFPEvaluation bhp(const VFPProdTable* table, auto gfr_i = detail::findInterpData( gfr, table->getGFRAxis()); auto alq_i = detail::findInterpData( alq, table->getALQAxis()); - detail::VFPEvaluation retval = detail::interpolate(table->getTable(), flo_i, thp_i, wfr_i, gfr_i, alq_i); + detail::VFPEvaluation retval = detail::interpolate(*table, flo_i, thp_i, wfr_i, gfr_i, alq_i); return retval; } diff --git a/opm/simulators/wells/VFPProdProperties.cpp b/opm/simulators/wells/VFPProdProperties.cpp index a83b67afb..3dc51b3a8 100644 --- a/opm/simulators/wells/VFPProdProperties.cpp +++ b/opm/simulators/wells/VFPProdProperties.cpp @@ -57,7 +57,6 @@ double VFPProdProperties::thp(int table_id, const double& bhp_arg, const double& alq) const { const VFPProdTable* table = detail::getTable(m_tables, table_id); - const VFPProdTable::array_type& data = table->getTable(); //Find interpolation variables double flo = detail::getFlo(aqua, liquid, vapour, table->getFloType()); @@ -80,7 +79,7 @@ double VFPProdProperties::thp(int table_id, std::vector bhp_array(nthp); for (int i=0; i& flos, for (size_t i = 0; i < flos.size(); ++i) { // Value of FLO is negative in OPM for producers, but positive in VFP table const auto flo_i = detail::findInterpData(-flos[i], table->getFloAxis()); - const detail::VFPEvaluation bhp_val = detail::interpolate(table->getTable(), flo_i, thp_i, wfr_i, gfr_i, alq_i); + const detail::VFPEvaluation bhp_val = detail::interpolate(*table, flo_i, thp_i, wfr_i, gfr_i, alq_i); // TODO: this kind of breaks the conventions for the functions here by putting dp within the function bhps[i] = bhp_val.value - dp; diff --git a/opm/simulators/wells/VFPProdProperties.hpp b/opm/simulators/wells/VFPProdProperties.hpp index 0338a48b1..3183fd0d0 100644 --- a/opm/simulators/wells/VFPProdProperties.hpp +++ b/opm/simulators/wells/VFPProdProperties.hpp @@ -102,7 +102,7 @@ public: auto gfr_i = detail::findInterpData( gfr.value(), table->getGFRAxis()); auto alq_i = detail::findInterpData( alq, table->getALQAxis()); //assume constant - detail::VFPEvaluation bhp_val = detail::interpolate(table->getTable(), flo_i, thp_i, wfr_i, gfr_i, alq_i); + detail::VFPEvaluation bhp_val = detail::interpolate(*table, flo_i, thp_i, wfr_i, gfr_i, alq_i); bhp = (bhp_val.dwfr * wfr) + (bhp_val.dgfr * gfr) - (bhp_val.dflo * flo); bhp.setValue(bhp_val.value); diff --git a/tests/test_ParallelRestart.cpp b/tests/test_ParallelRestart.cpp index 3781be7ba..47fe16baa 100644 --- a/tests/test_ParallelRestart.cpp +++ b/tests/test_ParallelRestart.cpp @@ -321,16 +321,9 @@ Opm::VFPInjTable getVFPInjTable() Opm::VFPProdTable getVFPProdTable() { Opm::VFPProdTable::array_type table; - Opm::VFPProdTable::extents shape; - shape[0] = 1; - shape[1] = 2; - shape[2] = 3; - shape[3] = 4; - shape[4] = 5; - table.resize(shape); - double foo = 1.0; - for (size_t i = 0; i < table.num_elements(); ++i) - *(table.data() + i) = foo++; + table.resize(1*2*3*4*5); + std::iota(table.begin(), table.end(), 1.0); + return Opm::VFPProdTable(1, 2.0, Opm::VFPProdTable::FLO_OIL, Opm::VFPProdTable::WFR_WOR, Opm::VFPProdTable::GFR_GLR, diff --git a/tests/test_vfpproperties.cpp b/tests/test_vfpproperties.cpp index b62d7d2f7..ec3601eee 100644 --- a/tests/test_vfpproperties.cpp +++ b/tests/test_vfpproperties.cpp @@ -124,10 +124,8 @@ struct TrivialFixture { nz(gfr_axis.size()), nu(alq_axis.size()), nv(flo_axis.size()), - size{{ nx, ny, nz, nu, nv }}, - data(size) + data(nx*ny*nz*nu*nv) { - } ~TrivialFixture() { @@ -143,7 +141,7 @@ struct TrivialFixture { for (int k=0; k(nv-1); // table[thp_idx][wfr_idx][gfr_idx][alq_idx][flo_idx]; - data[i][j][k][l][m] = x + 2*y + 3*z + 4*u + 5*v; + (*this)(i,j,k,l,m) = x + 2*y + 3*z + 4*u + 5*v; } } } @@ -187,7 +185,7 @@ struct TrivialFixture { for (int k=0; k properties; @@ -231,7 +234,6 @@ private: int nz; int nu; int nv; - Opm::VFPProdTable::extents size; Opm::VFPProdTable::array_type data; };