From ef6e0b084d8059e2744f08dd885bd5feba80325a Mon Sep 17 00:00:00 2001 From: Jostein Alvestad Date: Thu, 13 Sep 2018 15:54:31 +0200 Subject: [PATCH] Corrected merge conflicts with upstream master Write cumulative production / injection only in eclipse compatible mode --- opm/output/eclipse/AggregateGroupData.hpp | 1 + opm/output/eclipse/AggregateWellData.hpp | 1 + .../eclipse/AggregateConnectionData.cpp | 34 +++++---------- src/opm/output/eclipse/AggregateGroupData.cpp | 32 ++++++++++++-- src/opm/output/eclipse/AggregateMSWData.cpp | 2 +- src/opm/output/eclipse/AggregateWellData.cpp | 42 ++++++++++++------- src/opm/output/eclipse/LoadRestart.cpp | 2 +- src/opm/output/eclipse/RestartIO.cpp | 8 ++-- .../EclipseState/Schedule/Connection.cpp | 2 +- .../EclipseState/Schedule/WellConnections.cpp | 2 +- tests/parser/ConnectionTests.cpp | 3 +- tests/parser/MultisegmentWellTests.cpp | 1 + tests/test_AggregateWellData.cpp | 4 +- tests/test_Restart.cpp | 3 ++ 14 files changed, 84 insertions(+), 53 deletions(-) diff --git a/opm/output/eclipse/AggregateGroupData.hpp b/opm/output/eclipse/AggregateGroupData.hpp index 6ead2141b..bfaa61677 100644 --- a/opm/output/eclipse/AggregateGroupData.hpp +++ b/opm/output/eclipse/AggregateGroupData.hpp @@ -61,6 +61,7 @@ namespace Opm { namespace RestartIO { namespace Helpers { const std::vector& restart_field_keys, const std::map& groupKeyToIndex, const std::map& fieldKeyToIndex, + const bool ecl_compatible_rst, const std::size_t simStep, const Opm::SummaryState& sumState, const std::vector& inteHead); diff --git a/opm/output/eclipse/AggregateWellData.hpp b/opm/output/eclipse/AggregateWellData.hpp index 09dc64cea..eacd17277 100644 --- a/opm/output/eclipse/AggregateWellData.hpp +++ b/opm/output/eclipse/AggregateWellData.hpp @@ -52,6 +52,7 @@ namespace Opm { namespace RestartIO { namespace Helpers { void captureDynamicWellData(const Opm::Schedule& sched, const std::size_t sim_step, + const bool ecl_compatible_rst, const Opm::data::WellRates& xw, const Opm::SummaryState& smry); diff --git a/src/opm/output/eclipse/AggregateConnectionData.cpp b/src/opm/output/eclipse/AggregateConnectionData.cpp index 598b0260c..31ede1026 100755 --- a/src/opm/output/eclipse/AggregateConnectionData.cpp +++ b/src/opm/output/eclipse/AggregateConnectionData.cpp @@ -150,11 +150,11 @@ namespace { iConn[Ix::CellJ] = conn.getJ() + 1; iConn[Ix::CellK] = conn.getK() + 1; - iConn[Ix::ConnStat] = (conn.state == ConnState::OPEN) + iConn[Ix::ConnStat] = (conn.state() == ConnState::OPEN) ? 1 : -1000; iConn[Ix::Drainage] = conn.getDefaultSatTabId() - ? 0 : conn.sat_tableId; + ? 0 : conn.satTableId(); // Don't support differing sat-func tables for // draining and imbibition curves at connections. @@ -163,9 +163,9 @@ namespace { //iConn[Ix::ComplNum] = std::abs(conn.complnum); iConn[Ix::ComplNum] = iConn[Ix::SeqIndex]; - iConn[Ix::ConnDir] = conn.dir; + iConn[Ix::ConnDir] = conn.dir(); iConn[Ix::Segment] = conn.attachedToSegment() - ? conn.segment_number : 0; + ? conn.segment() : 0; } } // IConn @@ -200,28 +200,14 @@ namespace { return static_cast(units.from_si(u, x)); }; - { - const auto& ctf = conn - .getConnectionTransmissibilityFactorAsValueObject(); + sConn[Ix::ConnTrans] = + scprop(M::transmissibility, conn.CF()); - if (ctf.hasValue()) { - sConn[Ix::ConnTrans] = - scprop(M::transmissibility, ctf.getValue()); - } - } + sConn[Ix::Depth] = scprop(M::length, conn.depth()); + sConn[Ix::Diameter] = scprop(M::length, 2*conn.rw()); - sConn[Ix::Depth] = scprop(M::length, conn.center_depth); - sConn[Ix::Diameter] = scprop(M::length, conn.getDiameter()); - - { - const auto& ckh = conn - .getEffectiveKhAsValueObject(); - - if (ckh.hasValue()) { - sConn[Ix::EffectiveKH] = - scprop(M::effective_Kh, ckh.getValue()); - } - } + sConn[Ix::EffectiveKH] = + scprop(M::effective_Kh, conn.Kh()); sConn[Ix::item12] = sConn[Ix::ConnTrans]; diff --git a/src/opm/output/eclipse/AggregateGroupData.cpp b/src/opm/output/eclipse/AggregateGroupData.cpp index f034fc0f1..4154c7d82 100644 --- a/src/opm/output/eclipse/AggregateGroupData.cpp +++ b/src/opm/output/eclipse/AggregateGroupData.cpp @@ -430,6 +430,30 @@ namespace { }; } + std::vector + filter_cumulative(const bool ecl_compatible_rst, + const std::vector& keys) + { + if (ecl_compatible_rst) { + // User wants ECLIPSE-compatible output. Write all vectors. + return keys; + } + + auto ret = std::vector{}; + ret.reserve(keys.size()); + + for (const auto& key : keys) { + if ((key[3] == 'T') && ((key[2] == 'I') || (key[2] == 'P'))) { + // Don't write cumulative quantities in case of + continue; + } + + ret.push_back(key); + } + + return ret; + } + // here define the dynamic group quantities to be written to the restart file template void dynamicContrib(const std::vector& restart_group_keys, @@ -438,6 +462,7 @@ namespace { const std::map& fieldKeyToIndex, const Opm::Group& group, const Opm::SummaryState& sumState, + const bool ecl_compatible_rst, XGrpArray& xGrp) { std::string groupName = group.name(); @@ -446,7 +471,7 @@ namespace { const std::map& keyToIndex = (groupName == "FIELD") ? fieldKeyToIndex : groupKeyToIndex; - for (const auto key : keys) { + for (const auto key : filter_cumulative(ecl_compatible_rst,keys)) { std::string compKey = (groupName == "FIELD") ? key : key + ":" + groupName; @@ -548,6 +573,7 @@ captureDeclaredGroupData(const Opm::Schedule& sched, const std::vector& restart_field_keys, const std::map& groupKeyToIndex, const std::map& fieldKeyToIndex, + const bool ecl_compatible_rst, const std::size_t simStep, const Opm::SummaryState& sumState, const std::vector& inteHead) @@ -586,11 +612,11 @@ captureDeclaredGroupData(const Opm::Schedule& sched, // Define DynamicContributions to XGrp Array. groupLoop(curGroups, - [restart_group_keys, restart_field_keys, groupKeyToIndex, fieldKeyToIndex, sumState, this] + [restart_group_keys, restart_field_keys, groupKeyToIndex, fieldKeyToIndex, ecl_compatible_rst, sumState, this] (const Group& group, const std::size_t groupID) -> void { auto xg = this->xGroup_[groupID]; - XGrp::dynamicContrib( restart_group_keys, restart_field_keys, groupKeyToIndex, fieldKeyToIndex, group, sumState, xg); + XGrp::dynamicContrib( restart_group_keys, restart_field_keys, groupKeyToIndex, fieldKeyToIndex, group, sumState, ecl_compatible_rst, xg); }); } diff --git a/src/opm/output/eclipse/AggregateMSWData.cpp b/src/opm/output/eclipse/AggregateMSWData.cpp index b68a0f6a7..17ee545eb 100644 --- a/src/opm/output/eclipse/AggregateMSWData.cpp +++ b/src/opm/output/eclipse/AggregateMSWData.cpp @@ -139,7 +139,7 @@ namespace { auto segNumber = segSet[segIndex].segmentNumber(); int noConnections = 0; for (auto it : compSet) { - auto cSegment = it.segment_number; + auto cSegment = it.segment(); if (segNumber == cSegment) { noConnections+=1; } diff --git a/src/opm/output/eclipse/AggregateWellData.cpp b/src/opm/output/eclipse/AggregateWellData.cpp index 410ddeb60..3db85b010 100644 --- a/src/opm/output/eclipse/AggregateWellData.cpp +++ b/src/opm/output/eclipse/AggregateWellData.cpp @@ -614,6 +614,7 @@ namespace { template void assignProducer(const std::string& well, const ::Opm::SummaryState& smry, + const bool ecl_compatible_rst, XWellArray& xWell) { using Ix = ::Opm::RestartIO::Helpers::VectorItems::XWell::index; @@ -636,11 +637,12 @@ namespace { xWell[Ix::WatCut] = get("WWCT"); xWell[Ix::GORatio] = get("WGOR"); - xWell[Ix::OilPrTotal] = get("WOPT"); - xWell[Ix::WatPrTotal] = get("WWPT"); - xWell[Ix::GasPrTotal] = get("WGPT"); - xWell[Ix::VoidPrTotal] = get("WVPT"); - + if (ecl_compatible_rst) { + xWell[Ix::OilPrTotal] = get("WOPT"); + xWell[Ix::WatPrTotal] = get("WWPT"); + xWell[Ix::GasPrTotal] = get("WGPT"); + xWell[Ix::VoidPrTotal] = get("WVPT"); + } // Not fully characterised. xWell[Ix::item37] = xWell[Ix::WatPrRate]; xWell[Ix::item38] = xWell[Ix::GasPrRate]; @@ -649,6 +651,7 @@ namespace { template void assignWaterInjector(const std::string& well, const ::Opm::SummaryState& smry, + const bool ecl_compatible_rst, XWellArray& xWell) { using Ix = ::Opm::RestartIO::Helpers::VectorItems::XWell::index; @@ -664,8 +667,10 @@ namespace { xWell[Ix::LiqPrRate] = xWell[Ix::WatPrRate]; xWell[Ix::FlowBHP] = get("WBHP"); - - xWell[Ix::WatInjTotal] = get("WWIT"); + + if (ecl_compatible_rst) { + xWell[Ix::WatInjTotal] = get("WWIT"); + } xWell[Ix::item37] = xWell[Ix::WatPrRate]; xWell[Ix::item82] = xWell[Ix::WatInjTotal]; @@ -676,6 +681,7 @@ namespace { template void assignGasInjector(const std::string& well, const ::Opm::SummaryState& smry, + const bool ecl_compatible_rst, XWellArray& xWell) { using Ix = ::Opm::RestartIO::Helpers::VectorItems::XWell::index; @@ -692,8 +698,10 @@ namespace { xWell[Ix::FlowBHP] = get("WBHP"); - xWell[Ix::GasInjTotal] = get("WGIT"); - + if (ecl_compatible_rst) { + xWell[Ix::GasInjTotal] = get("WGIT"); + } + xWell[Ix::GasFVF] = xWell[Ix::VoidPrRate] / xWell[Ix::GasPrRate]; @@ -708,10 +716,11 @@ namespace { void dynamicContrib(const ::Opm::Well& well, const ::Opm::SummaryState& smry, const std::size_t sim_step, + const bool ecl_compatible_rst, XWellArray& xWell) { if (well.isProducer(sim_step)) { - assignProducer(well.name(), smry, xWell); + assignProducer(well.name(), smry, ecl_compatible_rst, xWell); } else if (well.isInjector(sim_step)) { using IType = ::Opm::WellInjector::TypeEnum; @@ -725,16 +734,16 @@ namespace { break; case IType::WATER: - assignWaterInjector(well.name(), smry, xWell); + assignWaterInjector(well.name(), smry, ecl_compatible_rst, xWell); break; case IType::GAS: - assignGasInjector(well.name(), smry, xWell); + assignGasInjector(well.name(), smry, ecl_compatible_rst, xWell); break; case IType::MULTI: - assignWaterInjector(well.name(), smry, xWell); - assignGasInjector (well.name(), smry, xWell); + assignWaterInjector(well.name(), smry, ecl_compatible_rst, xWell); + assignGasInjector (well.name(), smry, ecl_compatible_rst, xWell); break; } } @@ -849,6 +858,7 @@ void Opm::RestartIO::Helpers::AggregateWellData:: captureDynamicWellData(const Schedule& sched, const std::size_t sim_step, + const bool ecl_compatible_rst, const Opm::data::WellRates& xw, const ::Opm::SummaryState& smry) { @@ -870,11 +880,11 @@ captureDynamicWellData(const Schedule& sched, }); // Dynamic contributions to XWEL array. - wellLoop(wells, [this, sim_step, &smry] + wellLoop(wells, [this, sim_step, ecl_compatible_rst, &smry] (const Well& well, const std::size_t wellID) -> void { auto xw = this->xWell_[wellID]; - XWell::dynamicContrib(well, smry, sim_step, xw); + XWell::dynamicContrib(well, smry, sim_step, ecl_compatible_rst, xw); }); } diff --git a/src/opm/output/eclipse/LoadRestart.cpp b/src/opm/output/eclipse/LoadRestart.cpp index 8358ef531..34b10a07a 100644 --- a/src/opm/output/eclipse/LoadRestart.cpp +++ b/src/opm/output/eclipse/LoadRestart.cpp @@ -327,7 +327,7 @@ namespace { for (const auto& sc : sched_well->getConnections(rst_view.simStep())) { const auto i = sc.getI(), j = sc.getJ(), k = sc.getK(); - if (!grid.cellActive(i, j, k) || sc.state == Opm::WellCompletion::SHUT) { + if (!grid.cellActive(i, j, k) || sc.state() == Opm::WellCompletion::SHUT) { opm_xwel_data += Opm::data::Connection::restart_size + phases.size(); continue; } diff --git a/src/opm/output/eclipse/RestartIO.cpp b/src/opm/output/eclipse/RestartIO.cpp index 0e9667b2e..696965c86 100644 --- a/src/opm/output/eclipse/RestartIO.cpp +++ b/src/opm/output/eclipse/RestartIO.cpp @@ -289,6 +289,7 @@ namespace { void writeGroup(::Opm::RestartIO::ecl_rst_file_type* rst_file, int sim_step, + const bool ecl_compatible_rst, const Schedule& schedule, const Opm::SummaryState& sumState, const std::vector& ih) @@ -306,6 +307,7 @@ namespace { groupData.captureDeclaredGroupData(schedule, rst_g_keys, rst_f_keys, grpKeyToInd, fldKeyToInd, + ecl_compatible_rst, simStep, sumState, ih); write_kw(rst_file, "IGRP", groupData.getIGroup()); @@ -344,7 +346,7 @@ namespace { { auto wellData = Helpers::AggregateWellData(ih); wellData.captureDeclaredWellData(schedule, units, sim_step, sumState, ih); - wellData.captureDynamicWellData(schedule, sim_step, wells, sumState); + wellData.captureDynamicWellData(schedule, sim_step, ecl_compatible_rst, wells, sumState); write_kw(rst_file, "IWEL", wellData.getIWell()); write_kw(rst_file, "SWEL", wellData.getSWell()); @@ -370,7 +372,7 @@ namespace { write_kw(rst_file, "ICON", connectionData.getIConn()); write_kw(rst_file, "SCON", connectionData.getSConn()); - write_kw(rst_file, "XCON", connectionData.getXConn()); + //write_kw(rst_file, "XCON", connectionData.getXConn()); } void writeSolution(ecl_rst_file_type* rst_file, @@ -466,7 +468,7 @@ void save(const std::string& filename, const auto inteHD = writeHeader(rst_file.get(), sim_step, report_step, seconds_elapsed, schedule, grid, es); - writeGroup(rst_file.get(), sim_step, schedule, sumState, inteHD); + writeGroup(rst_file.get(), sim_step, ecl_compatible_rst, schedule, sumState, inteHD); writeMSWData(rst_file.get(), sim_step, units, schedule, grid, inteHD); diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Connection.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Connection.cpp index b87cfbe6b..aa53dbbd0 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Connection.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Connection.cpp @@ -180,7 +180,7 @@ namespace Opm { void Connection::updateSegment(int segment_number, double center_depth, std::size_t seqIndex) { this->segment_number = segment_number; this->center_depth = center_depth; - this->seqIndex = seqIndex; + this->m_seqIndex = seqIndex; } int Connection::segment() const { diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/WellConnections.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/WellConnections.cpp index ee830a834..a008a1f72 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/WellConnections.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/WellConnections.cpp @@ -304,7 +304,7 @@ namespace { std::size_t noConn = prev->getSeqIndex(); // The complnum value carries over; the rest of the state is fully specified by // the current COMPDAT keyword. - int complnum = prev->complnum; + int complnum = prev->complnum(); *prev = Connection(I,J,k, complnum, grid.getCellDepth(I,J,k), diff --git a/tests/parser/ConnectionTests.cpp b/tests/parser/ConnectionTests.cpp index f508f96cd..4eb352165 100644 --- a/tests/parser/ConnectionTests.cpp +++ b/tests/parser/ConnectionTests.cpp @@ -151,8 +151,9 @@ Opm::WellConnections loadCOMPDAT(const std::string& compdat_keyword) { Opm::Eclipse3DProperties props(deck, tables, grid ); const auto& keyword = deck.getKeyword("COMPDAT", 0); Opm::WellConnections connections; + std::size_t totnc = 0; for (const auto& rec : keyword) - connections.loadCOMPDAT(rec, grid, props); + connections.loadCOMPDAT(rec, grid, props, totnc); return connections; } diff --git a/tests/parser/MultisegmentWellTests.cpp b/tests/parser/MultisegmentWellTests.cpp index 500ab9b1b..6092c59f0 100644 --- a/tests/parser/MultisegmentWellTests.cpp +++ b/tests/parser/MultisegmentWellTests.cpp @@ -44,6 +44,7 @@ BOOST_AUTO_TEST_CASE(MultisegmentWellTest) { Opm::WellCompletion::DirectionEnum dir = Opm::WellCompletion::DirectionEnum::Z; Opm::WellConnections connection_set; + Opm::EclipseGrid grid(20,20,20); connection_set.add(Opm::Connection( 19, 0, 0, 1, 0.0, Opm::WellCompletion::OPEN , 200, 17.29, 0.25, 0, dir,0, 0., 0., true) ); connection_set.add(Opm::Connection( 19, 0, 1, 1, 0.0, Opm::WellCompletion::OPEN , 200, 17.29, 0.25, 0, dir,0, 0., 0., true) ); connection_set.add(Opm::Connection( 19, 0, 2, 1, 0.0, Opm::WellCompletion::OPEN , 200, 17.29, 0.25, 0, dir,0, 0., 0., true) ); diff --git a/tests/test_AggregateWellData.cpp b/tests/test_AggregateWellData.cpp index 9b544a3dd..a26b5f3cf 100644 --- a/tests/test_AggregateWellData.cpp +++ b/tests/test_AggregateWellData.cpp @@ -523,7 +523,7 @@ BOOST_AUTO_TEST_CASE (Dynamic_Well_Data_Step1) const auto smry = sim_state(); auto awd = Opm::RestartIO::Helpers::AggregateWellData{ih.value}; - awd.captureDynamicWellData(simCase.sched, rptStep, xw, smry); + awd.captureDynamicWellData(simCase.sched, rptStep, true, xw, smry); // IWEL (OP_1) { @@ -619,7 +619,7 @@ BOOST_AUTO_TEST_CASE (Dynamic_Well_Data_Step2) const auto smry = sim_state(); auto awd = Opm::RestartIO::Helpers::AggregateWellData{ih.value}; - awd.captureDynamicWellData(simCase.sched, rptStep, xw, smry); + awd.captureDynamicWellData(simCase.sched, rptStep, true, xw, smry); // IWEL (OP_1) -- closed producer { diff --git a/tests/test_Restart.cpp b/tests/test_Restart.cpp index bfe89d91e..d05efd058 100644 --- a/tests/test_Restart.cpp +++ b/tests/test_Restart.cpp @@ -503,6 +503,7 @@ BOOST_AUTO_TEST_CASE(ECL_FORMATTED) { auto num_cells = setup.grid.getNumActive( ); auto cells = mkSolution( num_cells ); auto wells = mkWells(); + auto sumState = sim_state(); { RestartValue restart_value(cells, wells); @@ -514,6 +515,7 @@ BOOST_AUTO_TEST_CASE(ECL_FORMATTED) { setup.es, setup.grid, setup.schedule, + sumState, true); { @@ -532,6 +534,7 @@ BOOST_AUTO_TEST_CASE(ECL_FORMATTED) { setup.es, setup.grid, setup.schedule, + sumState, true); { ecl_file_type * rst_file = ecl_file_open( "ECL_FILE.UNRST" , 0 );