Use std::reference_wrapper<> for parallel well info

This commit is contained in:
Joakim Hove 2021-09-27 12:00:39 +02:00
parent cf340644b2
commit 86a0662381
8 changed files with 54 additions and 54 deletions

View File

@ -265,7 +265,7 @@ initFromRestartFile(const RestartValue& restartValues,
const int report_step = std::max(eclState_.getInitConfig().getRestartStep() - 1, 0);
// wells_ecl_ should only contain wells on this processor.
wells_ecl_ = getLocalWells(report_step);
local_parallel_well_info_ = createLocalParallelWellInfo(wells_ecl_);
this->local_parallel_well_info_ = createLocalParallelWellInfo(wells_ecl_);
this->initializeWellProdIndCalculators();
initializeWellPerfData();
@ -273,7 +273,7 @@ initFromRestartFile(const RestartValue& restartValues,
const int nw = wells_ecl_.size();
if (nw > 0) {
handle_ms_well &= anyMSWellOpenLocal();
this->wellState().resize(wells_ecl_, local_parallel_well_info_, schedule(), handle_ms_well, numCells, well_perf_data_, summaryState_); // Resize for restart step
this->wellState().resize(wells_ecl_, this->local_parallel_well_info_, schedule(), handle_ms_well, numCells, well_perf_data_, summaryState_); // Resize for restart step
loadRestartData(restartValues.wells, restartValues.grp_nwrk, phase_usage_, handle_ms_well, this->wellState());
}
@ -297,11 +297,11 @@ getLocalWells(const int timeStepIdx) const
return w;
}
std::vector<ParallelWellInfo*>
std::vector<std::reference_wrapper<ParallelWellInfo>>
BlackoilWellModelGeneric::
createLocalParallelWellInfo(const std::vector<Well>& wells)
{
std::vector<ParallelWellInfo*> local_parallel_well_info;
std::vector<std::reference_wrapper<ParallelWellInfo>> local_parallel_well_info;
local_parallel_well_info.reserve(wells.size());
for (const auto& well : wells)
{
@ -311,7 +311,7 @@ createLocalParallelWellInfo(const std::vector<Well>& wells)
wellPair);
assert(pwell != parallel_well_info_.end() &&
*pwell == wellPair);
local_parallel_well_info.push_back(&(*pwell));
local_parallel_well_info.push_back(std::ref(*pwell));
}
return local_parallel_well_info;
}
@ -339,10 +339,10 @@ initializeWellPerfData()
int completion_index_above = ParallelWellInfo::INVALID_ECL_INDEX;
well_perf_data_[well_index].clear();
well_perf_data_[well_index].reserve(well.getConnections().size());
CheckDistributedWellConnections checker(well, *local_parallel_well_info_[well_index]);
CheckDistributedWellConnections checker(well, local_parallel_well_info_[well_index].get());
bool hasFirstPerforation = false;
bool firstOpenCompletion = true;
auto& parallelWellInfo = *local_parallel_well_info_[well_index];
auto& parallelWellInfo = this->local_parallel_well_info_[well_index].get();
parallelWellInfo.beginReset();
for (const auto& completion : well.getConnections()) {

View File

@ -241,7 +241,7 @@ protected:
/// \brief Create the parallel well information
/// \param localWells The local wells from ECL schedule
std::vector<ParallelWellInfo*> createLocalParallelWellInfo(const std::vector<Well>& wells);
std::vector<std::reference_wrapper<ParallelWellInfo>> createLocalParallelWellInfo(const std::vector<Well>& wells);
void initializeWellProdIndCalculators();
void initializeWellPerfData();
@ -396,7 +396,7 @@ protected:
std::vector<int> local_shut_wells_{};
std::vector<ParallelWellInfo> parallel_well_info_;
std::vector<ParallelWellInfo*> local_parallel_well_info_;
std::vector<std::reference_wrapper<ParallelWellInfo>> local_parallel_well_info_;
std::vector<WellProdIndexCalculator> prod_index_calc_;

View File

@ -183,7 +183,7 @@ namespace Opm {
const auto& summaryState = ebosSimulator_.vanguard().summaryState();
// Make wells_ecl_ contain only this partition's wells.
wells_ecl_ = getLocalWells(timeStepIdx);
local_parallel_well_info_ = createLocalParallelWellInfo(wells_ecl_);
this->local_parallel_well_info_ = createLocalParallelWellInfo(wells_ecl_);
// at least initializeWellState might be throw
// exception in opm-material (UniformTabulated2DFunction.hpp)
@ -416,9 +416,9 @@ namespace Opm {
endReportStep()
{
// Clear the communication data structures for above values.
for (auto&& pinfo : local_parallel_well_info_)
for (auto&& pinfo : this->local_parallel_well_info_)
{
pinfo->clear();
pinfo.get().clear();
}
}
@ -736,7 +736,7 @@ namespace Opm {
const auto pvtreg = perf_data.empty()
? 0 : pvt_region_idx_[perf_data.front().cell_index];
const auto& parallel_well_info = *local_parallel_well_info_[wellID];
const auto& parallel_well_info = this->local_parallel_well_info_[wellID].get();
const auto global_pvtreg = parallel_well_info.broadcastFirstPerforationValue(pvtreg);
return std::make_unique<WellType>(this->wells_ecl_[wellID],
@ -1685,7 +1685,7 @@ namespace Opm {
double weighted_temperature = 0.0;
double total_weight = 0.0;
auto& well_info = *local_parallel_well_info_[wellID];
auto& well_info = local_parallel_well_info_[wellID].get();
const int num_perf_this_well = well_info.communication().sum(well_perf_data_[wellID].size());
auto& ws = this->wellState().well(wellID);
auto& perf_data = ws.perf_data;

View File

@ -21,7 +21,7 @@
namespace Opm {
SingleWellState::SingleWellState(const ParallelWellInfo* pinfo, bool is_producer, std::size_t num_perf, std::size_t num_phases, double temp)
SingleWellState::SingleWellState(const ParallelWellInfo& pinfo, bool is_producer, std::size_t num_perf, std::size_t num_phases, double temp)
: parallel_info(pinfo)
, producer(is_producer)
, temperature(temp)

View File

@ -20,6 +20,7 @@
#ifndef OPM_SINGLE_WELL_STATE_HEADER_INCLUDED
#define OPM_SINGLE_WELL_STATE_HEADER_INCLUDED
#include <functional>
#include <vector>
#include <opm/simulators/wells/SegmentState.hpp>
@ -32,9 +33,9 @@ namespace Opm {
class SingleWellState {
public:
SingleWellState(const ParallelWellInfo* pinfo, bool is_producer, std::size_t num_perf, std::size_t num_phases, double temp);
SingleWellState(const ParallelWellInfo& pinfo, bool is_producer, std::size_t num_perf, std::size_t num_phases, double temp);
const ParallelWellInfo* parallel_info;
std::reference_wrapper<const ParallelWellInfo> parallel_info;
Well::Status status{Well::Status::OPEN};
bool producer;

View File

@ -33,10 +33,10 @@ namespace Opm
{
void WellState::base_init(const std::vector<double>& cellPressures,
const std::vector<Well>& wells_ecl,
const std::vector<ParallelWellInfo*>& parallel_well_info,
const std::vector<std::vector<PerforationData>>& well_perf_data,
const SummaryState& summary_state)
const std::vector<Well>& wells_ecl,
const std::vector<std::reference_wrapper<ParallelWellInfo>>& parallel_well_info,
const std::vector<std::vector<PerforationData>>& well_perf_data,
const SummaryState& summary_state)
{
// clear old name mapping
this->wells_.clear();
@ -60,7 +60,7 @@ void WellState::base_init(const std::vector<double>& cellPressures,
void WellState::initSingleWell(const std::vector<double>& cellPressures,
const Well& well,
const std::vector<PerforationData>& well_perf_data,
const ParallelWellInfo* well_info,
const ParallelWellInfo& well_info,
const SummaryState& summary_state)
{
assert(well.isInjector() || well.isProducer());
@ -89,7 +89,7 @@ void WellState::initSingleWell(const std::vector<double>& cellPressures,
const double local_pressure = well_perf_data.empty() ?
0 : cellPressures[well_perf_data[0].cell_index];
const double global_pressure = well_info->broadcastFirstPerforationValue(local_pressure);
const double global_pressure = well_info.broadcastFirstPerforationValue(local_pressure);
if (well.getStatus() == Well::Status::OPEN) {
ws.status = Well::Status::OPEN;
@ -192,13 +192,13 @@ void WellState::initSingleWell(const std::vector<double>& cellPressures,
void WellState::init(const std::vector<double>& cellPressures,
const Schedule& schedule,
const std::vector<Well>& wells_ecl,
const std::vector<ParallelWellInfo*>& parallel_well_info,
const int report_step,
const WellState* prevState,
const std::vector<std::vector<PerforationData>>& well_perf_data,
const SummaryState& summary_state)
const Schedule& schedule,
const std::vector<Well>& wells_ecl,
const std::vector<std::reference_wrapper<ParallelWellInfo>>& parallel_well_info,
const int report_step,
const WellState* prevState,
const std::vector<std::vector<PerforationData>>& well_perf_data,
const SummaryState& summary_state)
{
// call init on base class
this->base_init(cellPressures, wells_ecl, parallel_well_info, well_perf_data, summary_state);
@ -209,7 +209,7 @@ void WellState::init(const std::vector<double>& cellPressures,
}
for (const auto& winfo: parallel_well_info)
{
well_rates[winfo->name()].first = winfo->isOwner();
well_rates[winfo.get().name()].first = winfo.get().isOwner();
}
const int nw = wells_ecl.size();
@ -369,12 +369,12 @@ void WellState::init(const std::vector<double>& cellPressures,
}
void WellState::resize(const std::vector<Well>& wells_ecl,
const std::vector<ParallelWellInfo*>& parallel_well_info,
const Schedule& schedule,
const bool handle_ms_well,
const size_t numCells,
const std::vector<std::vector<PerforationData>>& well_perf_data,
const SummaryState& summary_state)
const std::vector<std::reference_wrapper<ParallelWellInfo>>& parallel_well_info,
const Schedule& schedule,
const bool handle_ms_well,
const size_t numCells,
const std::vector<std::vector<PerforationData>>& well_perf_data,
const SummaryState& summary_state)
{
const std::vector<double> tmp(numCells, 0.0); // <- UGLY HACK to pass the size
init(tmp, schedule, wells_ecl, parallel_well_info, 0, nullptr, well_perf_data, summary_state);
@ -498,7 +498,7 @@ WellState::report(const int* globalCellIdxMap,
curr.inj = ws.injection_cmode;
}
const auto& pwinfo = *ws.parallel_info;
const auto& pwinfo = ws.parallel_info.get();
if (pwinfo.communication().size()==1)
{
reportConnections(well.connections, pu, well_index, globalCellIdxMap);
@ -740,7 +740,7 @@ double WellState::solventWellRate(const int w) const
auto& ws = this->well(w);
const auto& perf_data = ws.perf_data;
const auto& perf_rates_solvent = perf_data.solvent_rates;
return ws.parallel_info->sumPerfValues(perf_rates_solvent.begin(), perf_rates_solvent.end());
return ws.parallel_info.get().sumPerfValues(perf_rates_solvent.begin(), perf_rates_solvent.end());
}
double WellState::polymerWellRate(const int w) const
@ -748,7 +748,7 @@ double WellState::polymerWellRate(const int w) const
auto& ws = this->well(w);
const auto& perf_data = ws.perf_data;
const auto& perf_rates_polymer = perf_data.polymer_rates;
return ws.parallel_info->sumPerfValues(perf_rates_polymer.begin(), perf_rates_polymer.end());
return ws.parallel_info.get().sumPerfValues(perf_rates_polymer.begin(), perf_rates_polymer.end());
}
double WellState::brineWellRate(const int w) const
@ -756,7 +756,7 @@ double WellState::brineWellRate(const int w) const
auto& ws = this->well(w);
const auto& perf_data = ws.perf_data;
const auto& perf_rates_brine = perf_data.brine_rates;
return ws.parallel_info->sumPerfValues(perf_rates_brine.begin(), perf_rates_brine.end());
return ws.parallel_info.get().sumPerfValues(perf_rates_brine.begin(), perf_rates_brine.end());
}
@ -906,7 +906,7 @@ WellState::reportSegmentResults(const PhaseUsage& pu,
bool WellState::wellIsOwned(std::size_t well_index,
[[maybe_unused]] const std::string& wellName) const
{
const auto& well_info = parallelWellInfo(well_index);
const auto& well_info = this->parallelWellInfo(well_index);
assert(well_info.name() == wellName);
return well_info.isOwner();
@ -985,7 +985,7 @@ const ParallelWellInfo&
WellState::parallelWellInfo(std::size_t well_index) const
{
const auto& ws = this->well(well_index);
return *ws.parallel_info;
return ws.parallel_info;
}
template void WellState::updateGlobalIsGrup<ParallelWellInfo::Communication>(const ParallelWellInfo::Communication& comm);

View File

@ -86,14 +86,14 @@ public:
void init(const std::vector<double>& cellPressures,
const Schedule& schedule,
const std::vector<Well>& wells_ecl,
const std::vector<ParallelWellInfo*>& parallel_well_info,
const std::vector<std::reference_wrapper<ParallelWellInfo>>& parallel_well_info,
const int report_step,
const WellState* prevState,
const std::vector<std::vector<PerforationData>>& well_perf_data,
const SummaryState& summary_state);
void resize(const std::vector<Well>& wells_ecl,
const std::vector<ParallelWellInfo*>& parallel_well_info,
const std::vector<std::reference_wrapper<ParallelWellInfo>>& parallel_well_info,
const Schedule& schedule,
const bool handle_ms_well,
const size_t numCells,
@ -302,14 +302,14 @@ private:
/// with -1e100.
void base_init(const std::vector<double>& cellPressures,
const std::vector<Well>& wells_ecl,
const std::vector<ParallelWellInfo*>& parallel_well_info,
const std::vector<std::reference_wrapper<ParallelWellInfo>>& parallel_well_info,
const std::vector<std::vector<PerforationData>>& well_perf_data,
const SummaryState& summary_state);
void initSingleWell(const std::vector<double>& cellPressures,
const Well& well,
const std::vector<PerforationData>& well_perf_data,
const ParallelWellInfo* well_info,
const ParallelWellInfo& well_info,
const SummaryState& summary_state);

View File

@ -18,6 +18,7 @@
*/
#include <config.h>
#include <functional>
#define BOOST_TEST_MODULE WellStateFIBOTest
@ -138,17 +139,15 @@ namespace {
auto wells = setup.sched.getWells(timeStep);
pinfos.resize(wells.size());
std::vector<Opm::ParallelWellInfo*> ppinfos(wells.size());
std::vector<std::reference_wrapper<Opm::ParallelWellInfo>> ppinfos;
auto pw = pinfos.begin();
auto ppw = ppinfos.begin();
for (const auto& well : wells)
{
*pw = {well.name()};
*ppw = &(*pw);
ppinfos.push_back(std::ref(*pw));
pw->communicateFirstPerforation(true);
++pw;
++ppw;
}
state.init(cpress, setup.sched,
@ -570,9 +569,9 @@ BOOST_AUTO_TEST_CASE(TESTPerfData) {
BOOST_AUTO_TEST_CASE(TestSingleWellState) {
Opm::ParallelWellInfo pinfo;
Opm::SingleWellState ws1(&pinfo, true, 10, 3, 1);
Opm::SingleWellState ws2(&pinfo, true, 10, 3, 2);
Opm::SingleWellState ws3(&pinfo, false, 10, 3, 3);
Opm::SingleWellState ws1(pinfo, true, 10, 3, 1);
Opm::SingleWellState ws2(pinfo, true, 10, 3, 2);
Opm::SingleWellState ws3(pinfo, false, 10, 3, 3);
ws1.bhp = 100;
ws1.thp = 200;