From 3010b966115069440456c4452a61916a65ee7fdc Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Sun, 6 Jun 2021 17:09:44 +0200 Subject: [PATCH] Use PerfData for perforation rates --- .../wells/BlackoilWellModelGeneric.cpp | 5 ++- .../wells/BlackoilWellModel_impl.hpp | 3 +- .../wells/MultisegmentWell_impl.hpp | 2 +- opm/simulators/wells/StandardWell_impl.hpp | 10 +++--- .../wells/WellInterfaceFluidSystem.cpp | 3 +- opm/simulators/wells/WellState.cpp | 32 ++++++++----------- opm/simulators/wells/WellState.hpp | 21 ------------ 7 files changed, 26 insertions(+), 50 deletions(-) diff --git a/opm/simulators/wells/BlackoilWellModelGeneric.cpp b/opm/simulators/wells/BlackoilWellModelGeneric.cpp index 8bdc386eb..ac519656d 100644 --- a/opm/simulators/wells/BlackoilWellModelGeneric.cpp +++ b/opm/simulators/wells/BlackoilWellModelGeneric.cpp @@ -188,11 +188,10 @@ loadRestartData(const data::Wells& rst_wells, well_state.wellRates(well_index)[i] = rst_well.rates.get(phs[i]); } - auto& perf_rates = well_state.perfRates(well_index); - auto& perf_phase_rates = well_state.perfPhaseRates(well_index); - auto& perf_data = well_state.perfData(well_index); auto& perf_pressure = perf_data.pressure; + auto& perf_rates = perf_data.rates; + auto& perf_phase_rates = perf_data.phase_rates; const auto& old_perf_data = this->well_perf_data_[well_index]; for (std::size_t perf_index = 0; perf_index < old_perf_data.size(); perf_index++) { diff --git a/opm/simulators/wells/BlackoilWellModel_impl.hpp b/opm/simulators/wells/BlackoilWellModel_impl.hpp index abe75f549..61afa1281 100644 --- a/opm/simulators/wells/BlackoilWellModel_impl.hpp +++ b/opm/simulators/wells/BlackoilWellModel_impl.hpp @@ -1536,7 +1536,8 @@ namespace Opm { auto& well_info = *local_parallel_well_info_[wellID]; const int num_perf_this_well = well_info.communication().sum(well_perf_data_[wellID].size()); - auto& perf_phase_rate = this->wellState().perfPhaseRates(wellID); + auto& perf_data = this->wellState().perfData(wellID); + auto& perf_phase_rate = perf_data.phase_rates; for (int perf = 0; perf < num_perf_this_well; ++perf) { const int cell_idx = well_perf_data_[wellID][perf].cell_index; diff --git a/opm/simulators/wells/MultisegmentWell_impl.hpp b/opm/simulators/wells/MultisegmentWell_impl.hpp index 70bb88322..3a6dc1317 100644 --- a/opm/simulators/wells/MultisegmentWell_impl.hpp +++ b/opm/simulators/wells/MultisegmentWell_impl.hpp @@ -1248,7 +1248,7 @@ namespace Opm // calculating the perforation rate for each perforation that belongs to this segment const EvalWell seg_pressure = this->getSegmentPressure(seg); auto& perf_data = well_state.perfData(this->index_of_well_); - auto& perf_rates = well_state.perfPhaseRates(this->index_of_well_); + auto& perf_rates = perf_data.phase_rates; auto& perf_press_state = perf_data.pressure; for (const int perf : this->segment_perforations_[seg]) { const int cell_idx = well_cells_[perf]; diff --git a/opm/simulators/wells/StandardWell_impl.hpp b/opm/simulators/wells/StandardWell_impl.hpp index 28bd7abca..d61c9a0ea 100644 --- a/opm/simulators/wells/StandardWell_impl.hpp +++ b/opm/simulators/wells/StandardWell_impl.hpp @@ -202,7 +202,8 @@ namespace Opm const int np = number_of_phases_; std::vector connectionRates = connectionRates_; // Copy to get right size. - auto& perf_rates = well_state.perfPhaseRates(this->index_of_well_); + auto& perf_data = well_state.perfData(this->index_of_well_); + auto& perf_rates = perf_data.phase_rates; for (int perf = 0; perf < number_of_perforations_; ++perf) { // Calculate perforation quantities. std::vector cq_s(num_components_, {this->numWellEq_ + numEq, 0.0}); @@ -316,6 +317,7 @@ namespace Opm computePerfRate(intQuants, mob, bhp, Tw, perf, allow_cf, cq_s, perf_dis_gas_rate, perf_vap_oil_rate, deferred_logger); + auto& perf_data = well_state.perfData(this->index_of_well_); if constexpr (has_polymer && Base::has_polymermw) { if (this->isInjector()) { // Store the original water flux computed from the reservoir quantities. @@ -455,7 +457,7 @@ namespace Opm cq_s_sm *= this->extendEval(intQuants.fluidState().saltConcentration()); } // Note. Efficiency factor is handled in the output layer - auto& perf_rate_brine = well_state.perfRateBrine(this->index_of_well_); + auto& perf_rate_brine = perf_data.brine_rates; perf_rate_brine[perf] = cq_s_sm.value(); cq_s_sm *= well_efficiency_factor_; @@ -463,7 +465,6 @@ namespace Opm } // Store the perforation pressure for later usage. - auto& perf_data = well_state.perfData(this->index_of_well_); perf_data.pressure[perf] = well_state.bhp(this->index_of_well_) + this->perf_pressure_diffs_[perf]; } @@ -1133,7 +1134,8 @@ namespace Opm const int nperf = number_of_perforations_; const int np = number_of_phases_; std::vector perfRates(b_perf.size(),0.0); - const auto& perf_rates_state = well_state.perfPhaseRates(this->index_of_well_); + const auto& perf_data = well_state.perfData(this->index_of_well_); + const auto& perf_rates_state = perf_data.phase_rates; for (int perf = 0; perf < nperf; ++perf) { for (int comp = 0; comp < np; ++comp) { diff --git a/opm/simulators/wells/WellInterfaceFluidSystem.cpp b/opm/simulators/wells/WellInterfaceFluidSystem.cpp index e06209990..3b84801f4 100644 --- a/opm/simulators/wells/WellInterfaceFluidSystem.cpp +++ b/opm/simulators/wells/WellInterfaceFluidSystem.cpp @@ -844,7 +844,8 @@ checkMaxRatioLimitCompletions(const WellState& well_state, double max_ratio_completion = 0; const int np = number_of_phases_; - const auto& perf_phase_rates = well_state.perfPhaseRates(this->index_of_well_); + const auto& perf_data = well_state.perfData(this->index_of_well_); + const auto& perf_phase_rates = perf_data.phase_rates; // look for the worst_offending_completion for (const auto& completion : completions_) { std::vector completion_rates(np, 0.0); diff --git a/opm/simulators/wells/WellState.cpp b/opm/simulators/wells/WellState.cpp index 0b134b67d..0920fc20f 100644 --- a/opm/simulators/wells/WellState.cpp +++ b/opm/simulators/wells/WellState.cpp @@ -44,8 +44,6 @@ void WellState::base_init(const std::vector& cellPressures, this->perf_skin_pressure_.clear(); this->perf_water_throughput_.clear(); this->perf_water_velocity_.clear(); - this->perfphaserates_.clear(); - this->perfRateBrine_.clear(); this->perfRateSolvent_.clear(); this->perfRatePolymer_.clear(); this->status_.clear(); @@ -109,7 +107,6 @@ void WellState::initSingleWell(const std::vector& cellPressures, const int num_perf_this_well = well_info->communication().sum(well_perf_data_[w].size()); this->segment_state.add(well.name(), SegmentState{}); this->perfdata.add(well.name(), PerfData{num_perf_this_well, this->phase_usage_}); - this->perfphaserates_.add(well.name(), std::vector(np*num_perf_this_well, 0)); this->perf_skin_pressure_.add(well.name(), std::vector(num_perf_this_well, 0)); this->perf_water_velocity_.add(well.name(), std::vector(num_perf_this_well, 0)); this->perf_water_throughput_.add(well.name(), std::vector(num_perf_this_well, 0)); @@ -303,13 +300,12 @@ void WellState::init(const std::vector& cellPressures, const int num_perf_this_well = well_info[2]; const int global_num_perf_this_well = ecl_well.getConnections().num_open(); auto& perf_data = this->perfData(w); - - auto& phase_rates = this->perfPhaseRates(w); + auto& phase_rates = perf_data.phase_rates; for (int perf = 0; perf < num_perf_this_well; ++perf) { if (wells_ecl[w].getStatus() == Well::Status::OPEN) { for (int p = 0; p < this->numPhases(); ++p) { - phase_rates[this->numPhases()*perf + p] = wellRates(w)[p] / double(global_num_perf_this_well); + perf_data.phase_rates[this->numPhases()*perf + p] = wellRates(w)[p] / double(global_num_perf_this_well); } } perf_data.pressure[perf] = cellPressures[well_perf_data[w][perf].cell_index]; @@ -427,16 +423,13 @@ void WellState::init(const std::vector& cellPressures, // number of perforations. if (global_num_perf_same) { - const auto& src_rates = prevState->perfPhaseRates(oldIndex); - auto& target_rates = this->perfPhaseRates(newIndex); - for (int perf_index = 0; perf_index < num_perf_this_well; perf_index++) { - for (int p = 0; p < np; p++) { - target_rates[perf_index*np + p] = src_rates[perf_index*np + p]; - } - } + auto& perf_data = this->perfData(w); + const auto& prev_perf_data = prevState->perfData(w); + perf_data.try_assign(prev_perf_data); } else { const int global_num_perf_this_well = well.getConnections().num_open(); - auto& target_rates = this->perfPhaseRates(newIndex); + auto& perf_data = this->perfData(w); + auto& target_rates = perf_data.phase_rates; for (int perf_index = 0; perf_index < num_perf_this_well; perf_index++) { for (int p = 0; p < np; ++p) { target_rates[perf_index*np + p] = wellRates(w)[p] / double(global_num_perf_this_well); @@ -736,7 +729,7 @@ void WellState::reportConnections(data::Well& well, pi .at( pu.phase_pos[Gas] ) = rt::productivity_index_gas; } for( auto& comp : well.connections) { - const auto * rates = &this->perfPhaseRates(well_index)[np*local_comp_index]; + const auto * rates = &perf_data.phase_rates[np*local_comp_index]; const auto& connPI = this->connectionProductivityIndex(well_index); for( int i = 0; i < np; ++i ) { @@ -748,7 +741,7 @@ void WellState::reportConnections(data::Well& well, comp.rates.set( rt::polymer, perf_polymer_rate[local_comp_index]); } if ( pu.has_brine ) { - const auto& perf_brine_rate = this->perfRateBrine(well_index); + const auto& perf_brine_rate = perf_data.brine_rates; comp.rates.set( rt::brine, perf_brine_rate[local_comp_index]); } if ( pu.has_solvent ) { @@ -819,7 +812,7 @@ void WellState::initWellStateMSWell(const std::vector& wells_ecl, "Inconsistent number of reservoir connections in well"); if (pu.phase_used[Gas]) { - auto& perf_rates = this->perfPhaseRates(w); + auto& perf_rates = perf_data.phase_rates; const int gaspos = pu.phase_pos[Gas]; // scale the phase rates for Gas to avoid too bad initial guess for gas fraction // it will probably benefit the standard well too, while it needs to be justified @@ -830,7 +823,7 @@ void WellState::initWellStateMSWell(const std::vector& wells_ecl, perf_rates[perf*np + gaspos] *= 100; } - const auto& perf_rates = this->perfPhaseRates(w); + const auto& perf_rates = perf_data.phase_rates; std::vector perforation_rates(perf_rates.begin(), perf_rates.end()); auto& segments = this->segments(w); @@ -928,7 +921,8 @@ double WellState::polymerWellRate(const int w) const double WellState::brineWellRate(const int w) const { - const auto& perf_rates_brine = this->perfRateBrine(w); + const auto& perf_data = this->perfData(w); + const auto& perf_rates_brine = perf_data.brine_rates; return parallel_well_info_[w]->sumPerfValues(perf_rates_brine.begin(), perf_rates_brine.end()); } diff --git a/opm/simulators/wells/WellState.hpp b/opm/simulators/wells/WellState.hpp index 59b2e44f1..6c4f3d6b3 100644 --- a/opm/simulators/wells/WellState.hpp +++ b/opm/simulators/wells/WellState.hpp @@ -100,16 +100,6 @@ public: const std::vector>& well_perf_data, const SummaryState& summary_state); - /// One rate per phase and well connection. - - std::vector& perfPhaseRates(std::size_t well_index) { - return this->perfphaserates_[well_index]; - } - - const std::vector& perfPhaseRates(std::size_t well_index) const { - return this->perfphaserates_[well_index]; - } - /// One current control per injecting well. Well::InjectorCMode currentInjectionControl(std::size_t well_index) const { return current_injection_controls_[well_index]; } void currentInjectionControl(std::size_t well_index, Well::InjectorCMode cmode) { current_injection_controls_[well_index] = cmode; } @@ -178,15 +168,6 @@ public: /// One rate pr well double polymerWellRate(const int w) const; - /// One rate pr well connection. - std::vector& perfRateBrine(std::size_t well_index) { - return this->perfRateBrine_[well_index]; - } - - const std::vector& perfRateBrine(std::size_t well_index) const { - return this->perfRateBrine_[well_index]; - } - /// One rate pr well double brineWellRate(const int w) const; @@ -435,7 +416,6 @@ private: PhaseUsage phase_usage_; WellContainer perfdata; - WellContainer> perfphaserates_; WellContainer is_producer_; // Size equal to number of local wells. // vector with size number of wells +1. @@ -454,7 +434,6 @@ private: // only for output WellContainer> perfRatePolymer_; - WellContainer> perfRateBrine_; // it is the throughput of water flow through the perforations // it is used as a measure of formation damage around well-bore due to particle deposition