diff --git a/opm/simulators/wells/BlackoilWellModel_impl.hpp b/opm/simulators/wells/BlackoilWellModel_impl.hpp index b39824f40..21afaac03 100644 --- a/opm/simulators/wells/BlackoilWellModel_impl.hpp +++ b/opm/simulators/wells/BlackoilWellModel_impl.hpp @@ -1996,7 +1996,7 @@ namespace Opm { auto& perf_pressure = well_state.perfPress(well_index); auto& perf_rates = well_state.perfRates(well_index); - auto * perf_phase_rates = well_state.perfPhaseRates(well_index); + auto& perf_phase_rates = well_state.perfPhaseRates(well_index); const auto& perf_data = this->well_perf_data_[well_index]; for (std::size_t perf_index = 0; perf_index < perf_data.size(); perf_index++) { @@ -3373,7 +3373,7 @@ 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_phase_rate = this->wellState().perfPhaseRates(wellID); 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 569815636..8c98c32f0 100644 --- a/opm/simulators/wells/MultisegmentWell_impl.hpp +++ b/opm/simulators/wells/MultisegmentWell_impl.hpp @@ -2637,7 +2637,7 @@ namespace Opm // calculating the perforation rate for each perforation that belongs to this segment const EvalWell seg_pressure = getSegmentPressure(seg); - auto * perf_rates = well_state.perfPhaseRates(this->index_of_well_); + auto& perf_rates = well_state.perfPhaseRates(this->index_of_well_); auto& perf_press_state = well_state.perfPress(this->index_of_well_); for (const int perf : 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 894ca7d7e..047467d26 100644 --- a/opm/simulators/wells/StandardWell_impl.hpp +++ b/opm/simulators/wells/StandardWell_impl.hpp @@ -591,7 +591,7 @@ 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_rates = well_state.perfPhaseRates(this->index_of_well_); for (int perf = 0; perf < number_of_perforations_; ++perf) { // Calculate perforation quantities. std::vector cq_s(num_components_, {numWellEq_ + numEq, 0.0}); @@ -2104,7 +2104,7 @@ 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_rates_state = well_state.perfPhaseRates(this->index_of_well_); 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 7b735fdb2..093a7304d 100644 --- a/opm/simulators/wells/WellInterfaceFluidSystem.cpp +++ b/opm/simulators/wells/WellInterfaceFluidSystem.cpp @@ -846,7 +846,7 @@ 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_phase_rates = well_state.perfPhaseRates(this->index_of_well_); // 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 d96cb2d15..ff907f1a1 100644 --- a/opm/simulators/wells/WellState.cpp +++ b/opm/simulators/wells/WellState.cpp @@ -44,6 +44,7 @@ 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->perfrates_.clear(); this->perfRateBrine_.clear(); this->perfRateSolvent_.clear(); @@ -107,6 +108,7 @@ void WellState::initSingleWell(const std::vector& cellPressures, this->segment_state.add(well.name(), SegmentState{}); this->perfpress_.add(well.name(), std::vector(num_perf_this_well, -1e100)); this->perfrates_.add(well.name(), std::vector(num_perf_this_well, 0)); + 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)); @@ -287,9 +289,6 @@ void WellState::init(const std::vector& cellPressures, this->events_.add( wname, Events() ); } } - // Ensure that we start out with zero rates by default. - perfphaserates_.clear(); - perfphaserates_.resize(nperf * this->numPhases(), 0.0); first_perf_index_.resize(nw, 0); first_perf_index_[0] = 0; @@ -304,7 +303,7 @@ void WellState::init(const std::vector& cellPressures, auto& perf_press = this->perfPress(w); first_perf_index_[w] = connpos; - auto phase_rates = this->perfPhaseRates(w); + auto& phase_rates = this->perfPhaseRates(w); for (int perf = 0; perf < num_perf_this_well; ++perf) { if (wells_ecl[w].getStatus() == Well::Status::OPEN) { @@ -432,8 +431,8 @@ 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); + 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]; @@ -441,7 +440,7 @@ void WellState::init(const std::vector& cellPressures, } } else { const int global_num_perf_this_well = parallel_well_info[w]->communication().sum(num_perf_this_well); - auto * target_rates = this->perfPhaseRates(newIndex); + 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] = wellRates(w)[p] / double(global_num_perf_this_well); @@ -755,7 +754,7 @@ void WellState::reportConnections(data::Well& well, for( auto& comp : well.connections) { const auto connPhaseOffset = np * (wt.second[1] + local_comp_index); - const auto * rates = &this->perfPhaseRates(well_index)[np*local_comp_index]; + const auto& rates = &this->perfPhaseRates(well_index)[np*local_comp_index]; const auto connPI = this->connectionProductivityIndex().begin() + connPhaseOffset; for( int i = 0; i < np; ++i ) { @@ -796,8 +795,6 @@ void WellState::initWellStateMSWell(const std::vector& wells_ecl, for (int w = 0; w < nw; ++w) { const auto& well_ecl = wells_ecl[w]; const auto& wname = wells_ecl[w].name(); - const auto& well_info = this->wellMap().at(wname); - const int num_perf_this_well = well_info[2]; if ( well_ecl.isMultiSegment() ) { const WellSegments& segment_set = well_ecl.getSegments(); @@ -840,7 +837,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 = this->perfPhaseRates(w); 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 @@ -851,8 +848,8 @@ void WellState::initWellStateMSWell(const std::vector& wells_ecl, perf_rates[perf*np + gaspos] *= 100; } - const auto * perf_rates = this->perfPhaseRates(w); - std::vector perforation_rates(perf_rates, perf_rates + num_perf_this_well*np); + const auto& perf_rates = this->perfPhaseRates(w); + std::vector perforation_rates(perf_rates.begin(), perf_rates.end()); auto& segments = this->segments(w); calculateSegmentRates(segment_inlets, segment_perforations, perforation_rates, np, 0 /* top segment */, segments.rates); diff --git a/opm/simulators/wells/WellState.hpp b/opm/simulators/wells/WellState.hpp index 3c8153424..541d47d5c 100644 --- a/opm/simulators/wells/WellState.hpp +++ b/opm/simulators/wells/WellState.hpp @@ -81,7 +81,7 @@ public: /// Allocate and initialize if wells is non-null. Also tries /// to give useful initial values to the bhp(), wellRates() - /// and perfPhaseRates() fields, depending on controls + /// and perfPhaseRatesORG() fields, depending on controls void init(const std::vector& cellPressures, const Schedule& schedule, const std::vector& wells_ecl, @@ -100,12 +100,13 @@ public: const SummaryState& summary_state); /// One rate per phase and well connection. - double * perfPhaseRates(std::size_t well_index) { - return &this->perfphaserates_[this->first_perf_index_[well_index] * this->numPhases()]; + + std::vector& perfPhaseRates(std::size_t well_index) { + return this->perfphaserates_[well_index]; } - const double * perfPhaseRates(std::size_t well_index) const { - return &this->perfphaserates_[this->first_perf_index_[well_index] * this->numPhases()]; + const std::vector& perfPhaseRates(std::size_t well_index) const { + return this->perfphaserates_[well_index]; } /// One current control per injecting well. @@ -436,7 +437,7 @@ private: WellContainer> perfrates_; WellContainer> perfpress_; - std::vector perfphaserates_; + WellContainer> perfphaserates_; WellContainer is_producer_; // Size equal to number of local wells. // vector with size number of wells +1.