From 5ac53f81066f3bf775d0f6a10db6e84ec9d4a9a1 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Wed, 26 May 2021 17:38:09 +0200 Subject: [PATCH] Use well index for segment rates --- opm/simulators/wells/BlackoilWellModel_impl.hpp | 3 +-- opm/simulators/wells/MultisegmentWell_impl.hpp | 9 +++------ opm/simulators/wells/WellState.cpp | 12 ++++-------- opm/simulators/wells/WellState.hpp | 11 +++++++---- tests/test_wellstate.cpp | 11 +++++------ 5 files changed, 20 insertions(+), 26 deletions(-) diff --git a/opm/simulators/wells/BlackoilWellModel_impl.hpp b/opm/simulators/wells/BlackoilWellModel_impl.hpp index 766ac8b83..6043805f6 100644 --- a/opm/simulators/wells/BlackoilWellModel_impl.hpp +++ b/opm/simulators/wells/BlackoilWellModel_impl.hpp @@ -2011,14 +2011,13 @@ namespace Opm { const WellSegments& segment_set = well_ecl.getSegments(); - const int top_segment_index = well_state.topSegmentIndex(well_index); const auto& rst_segments = rst_well.segments; // \Note: eventually we need to hanlde the situations that some segments are shut assert(0u + segment_set.size() == rst_segments.size()); - auto * segment_rates = &well_state.segRates()[top_segment_index*np]; auto segment_pressure = well_state.segPress(well_index); + auto segment_rates = well_state.segRates(well_index); for (const auto& rst_segment : rst_segments) { const int segment_index = segment_set.segmentNumberToIndex(rst_segment.first); diff --git a/opm/simulators/wells/MultisegmentWell_impl.hpp b/opm/simulators/wells/MultisegmentWell_impl.hpp index 36fd6fffd..0d0ad6221 100644 --- a/opm/simulators/wells/MultisegmentWell_impl.hpp +++ b/opm/simulators/wells/MultisegmentWell_impl.hpp @@ -278,8 +278,7 @@ namespace Opm MultisegmentWell:: scaleSegmentRatesWithWellRates(WellState& well_state) const { - const int top_segment_index = well_state.topSegmentIndex(index_of_well_); - auto * segment_rates = &well_state.segRates()[top_segment_index*this->number_of_phases_]; + auto segment_rates = well_state.segRates(index_of_well_); for (int phase = 0; phase < number_of_phases_; ++phase) { const double unscaled_top_seg_rate = segment_rates[phase]; const double well_phase_rate = well_state.wellRates(index_of_well_)[phase]; @@ -316,7 +315,6 @@ namespace Opm scaleSegmentPressuresWithBhp(WellState& well_state) const { //scale segment pressures - const int top_segment_index = well_state.topSegmentIndex(index_of_well_); const double bhp = well_state.bhp(index_of_well_); auto segment_pressure = well_state.segPress(index_of_well_); const double unscaled_top_seg_pressure = segment_pressure[0]; @@ -722,8 +720,7 @@ namespace Opm const Well& well = Base::wellEcl(); // the index of the top segment in the WellState - const int top_segment_index = well_state.topSegmentIndex(index_of_well_); - const auto * segment_rates = &well_state.segRates()[top_segment_index * this->number_of_phases_]; + const auto segment_rates = well_state.segRates(index_of_well_); const auto segment_pressure = well_state.segPress(index_of_well_); const PhaseUsage& pu = phaseUsage(); @@ -2340,7 +2337,7 @@ namespace Opm assert( FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) ); const int oil_pos = pu.phase_pos[Oil]; - auto * segment_rates = &well_state.segRates()[well_state.topSegmentIndex(this->index_of_well_) * this->number_of_phases_]; + auto segment_rates = well_state.segRates(this->index_of_well_); auto segment_pressure = well_state.segPress(this->index_of_well_); for (int seg = 0; seg < numberOfSegments(); ++seg) { std::vector fractions(number_of_phases_, 0.0); diff --git a/opm/simulators/wells/WellState.cpp b/opm/simulators/wells/WellState.cpp index d208d55a9..9454678cf 100644 --- a/opm/simulators/wells/WellState.cpp +++ b/opm/simulators/wells/WellState.cpp @@ -965,7 +965,6 @@ void WellState::initWellStateMSWell(const std::vector& wells_ecl, continue; } - const int old_top_segment_index = prev_well_state->topSegmentIndex(old_index_well); const int new_top_segment_index = topSegmentIndex(new_index_well); int number_of_segment = 0; // if it is the last well in list @@ -975,10 +974,10 @@ void WellState::initWellStateMSWell(const std::vector& wells_ecl, number_of_segment = topSegmentIndex(new_index_well + 1) - new_top_segment_index; } - auto * segment_rates = &this->seg_rates_[new_top_segment_index*np]; + auto segment_rates = this->segRates(w); auto segment_pressure = this->segPress(w); - const auto * prev_segment_rates = &prev_well_state->segRates()[old_top_segment_index*np]; + const auto prev_segment_rates = prev_well_state->segRates(old_index_well); const auto prev_segment_pressure = prev_well_state->segPress(old_index_well); for (int seg=0; seg < number_of_segment; ++seg) { @@ -1152,13 +1151,8 @@ WellState::reportSegmentResults(const PhaseUsage& pu, const int seg_no) const { auto seg_res = data::Segment{}; - const auto seg_dof = this->topSegmentIndex(well_id) + seg_ix; - - const auto* rate = - &this->segRates()[seg_dof * this->numPhases()]; - { using Value = data::SegmentPressures::Value; auto& segpress = seg_res.pressures; @@ -1169,6 +1163,8 @@ WellState::reportSegmentResults(const PhaseUsage& pu, segpress[Value::PDropAccel] = this->segPressDropAcceleration()[seg_dof]; } + const auto segment_rates = this->segRates(well_id); + const auto rate = &segment_rates[seg_ix * this->numPhases()]; if (pu.phase_used[Water]) { seg_res.rates.set(data::Rates::opt::wat, rate[pu.phase_pos[Water]]); diff --git a/opm/simulators/wells/WellState.hpp b/opm/simulators/wells/WellState.hpp index 31da880e6..f1bf546f0 100644 --- a/opm/simulators/wells/WellState.hpp +++ b/opm/simulators/wells/WellState.hpp @@ -192,14 +192,17 @@ public: return well_vaporized_oil_rates_[well_index]; } - const std::vector& segRates() const + + const double * segRates(std::size_t well_index) const { - return seg_rates_; + const int top_segment_index = this->top_segment_index_[well_index]; + return &this->seg_rates_[top_segment_index * this->phase_usage_.num_phases]; } - std::vector& segRates() + double * segRates(std::size_t well_index) { - return seg_rates_; + const int top_segment_index = this->top_segment_index_[well_index]; + return &this->seg_rates_[top_segment_index * this->phase_usage_.num_phases]; } double * segPress(std::size_t well_index) diff --git a/tests/test_wellstate.cpp b/tests/test_wellstate.cpp index f8626efcb..587d9b552 100644 --- a/tests/test_wellstate.cpp +++ b/tests/test_wellstate.cpp @@ -206,16 +206,15 @@ namespace { const auto nWell = wells.size(); - auto& segRates = wstate.segRates(); for (auto wellID = 0*nWell; wellID < nWell; ++wellID) { const auto& well = wells[wellID]; - const auto topSegIx = wstate.topSegmentIndex(wellID); const auto rateTop = 1000.0 * wellID; + auto segRates = wstate.segRates(wellID); - if (wat) { segRates[np*topSegIx + iw] = rateTop; } - if (oil) { segRates[np*topSegIx + io] = rateTop; } - if (gas) { segRates[np*topSegIx + ig] = rateTop; } + if (wat) { segRates[iw] = rateTop; } + if (oil) { segRates[io] = rateTop; } + if (gas) { segRates[ig] = rateTop; } if (! well.isMultiSegment()) { continue; @@ -228,7 +227,7 @@ namespace { // One-based numbering scheme for segments. const auto segNo = segSet[segID].segmentNumber(); - auto* rates = &segRates[(topSegIx + segNo - 1) * np]; + auto* rates = &segRates[(segNo - 1) * np]; if (wat) { rates[iw] = rateTop + 100.0*(segNo - 1); } if (oil) { rates[io] = rateTop + 200.0*(segNo - 1); }