WellGroupHelpers: use an array to allow for one sum call

This commit is contained in:
Arne Morten Kvarving 2021-11-09 12:51:49 +01:00
parent 04ed31f800
commit 09f61e0e6f

View File

@ -1480,21 +1480,18 @@ namespace WellGroupHelpers
} }
} }
double oilPot = 0.0; std::array<double,3> potentials{};
auto& [oilPot, gasPot, waterPot] = potentials;
if (pu.phase_used[BlackoilPhases::Liquid]) if (pu.phase_used[BlackoilPhases::Liquid])
oilPot = pot[pu.phase_pos[BlackoilPhases::Liquid]]; oilPot = pot[pu.phase_pos[BlackoilPhases::Liquid]];
double gasPot = 0.0;
if (pu.phase_used[BlackoilPhases::Vapour]) if (pu.phase_used[BlackoilPhases::Vapour])
gasPot = pot[pu.phase_pos[BlackoilPhases::Vapour]]; gasPot = pot[pu.phase_pos[BlackoilPhases::Vapour]];
double waterPot = 0.0;
if (pu.phase_used[BlackoilPhases::Aqua]) if (pu.phase_used[BlackoilPhases::Aqua])
waterPot = pot[pu.phase_pos[BlackoilPhases::Aqua]]; waterPot = pot[pu.phase_pos[BlackoilPhases::Aqua]];
oilPot = comm.sum(oilPot); comm.sum(potentials.data(), potentials.size());
gasPot = comm.sum(gasPot);
waterPot = comm.sum(waterPot);
const UnitSystem& unit_system = schedule.getUnits(); const UnitSystem& unit_system = schedule.getUnits();
oilPot = unit_system.from_si(UnitSystem::measure::liquid_surface_rate, oilPot); oilPot = unit_system.from_si(UnitSystem::measure::liquid_surface_rate, oilPot);
waterPot = unit_system.from_si(UnitSystem::measure::liquid_surface_rate, waterPot); waterPot = unit_system.from_si(UnitSystem::measure::liquid_surface_rate, waterPot);
@ -1512,9 +1509,8 @@ namespace WellGroupHelpers
GuideRate* guideRate) GuideRate* guideRate)
{ {
for (const auto& well : schedule.getWells(reportStepIdx)) { for (const auto& well : schedule.getWells(reportStepIdx)) {
double oilpot = 0.0; std::array<double,3> potentials{};
double gaspot = 0.0; auto& [oilpot, gaspot, waterpot] = potentials;
double waterpot = 0.0;
const auto& well_index = wellState.index(well.name()); const auto& well_index = wellState.index(well.name());
if (well_index.has_value() && wellState.wellIsOwned(well_index.value(), well.name())) if (well_index.has_value() && wellState.wellIsOwned(well_index.value(), well.name()))
@ -1531,9 +1527,7 @@ namespace WellGroupHelpers
if (pu.phase_used[BlackoilPhases::Aqua] > 0) if (pu.phase_used[BlackoilPhases::Aqua] > 0)
waterpot = wpot[pu.phase_pos[BlackoilPhases::Aqua]]; waterpot = wpot[pu.phase_pos[BlackoilPhases::Aqua]];
} }
oilpot = comm.sum(oilpot); comm.sum(potentials.data(), potentials.size());
gaspot = comm.sum(gaspot);
waterpot = comm.sum(waterpot);
const UnitSystem& unit_system = schedule.getUnits(); const UnitSystem& unit_system = schedule.getUnits();
oilpot = unit_system.from_si(UnitSystem::measure::liquid_surface_rate, oilpot); oilpot = unit_system.from_si(UnitSystem::measure::liquid_surface_rate, oilpot);
waterpot = unit_system.from_si(UnitSystem::measure::liquid_surface_rate, waterpot); waterpot = unit_system.from_si(UnitSystem::measure::liquid_surface_rate, waterpot);