From d155d4b76ab9596502c4ddbf15dc36a4a17cc3a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Thu, 31 Oct 2024 14:43:50 +0100 Subject: [PATCH] Simplify Logic for Exchanging PI/II Values in ACTIONX/WELPI This commit switches to using the new guarantees provided by ActionX::wellpi_wells (PR OPM/opm-common#4296), namely that the well names are returned in sorted order on all ranks, to simplify how we exchange the PI/II values. In particular, given this guarantee, we can calculate the maximum values across all ranks because zero values correspond to missing entries and non-zero values correspond to known entries. --- opm/simulators/flow/ActionHandler.cpp | 35 ++++++--------------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/opm/simulators/flow/ActionHandler.cpp b/opm/simulators/flow/ActionHandler.cpp index ed97bee32..067686f08 100644 --- a/opm/simulators/flow/ActionHandler.cpp +++ b/opm/simulators/flow/ActionHandler.cpp @@ -151,38 +151,17 @@ namespace { return wellpi; } - const auto num_wells = schedule[reportStep].well_order().size(); - - std::vector wellpi_vector(num_wells); - for (const auto& wname : wellpi_wells) { - if (wellModel.hasWell(wname)) { - const auto& well = schedule.getWell(wname, reportStep); - wellpi_vector[well.seqIndex()] = wellModel.wellPI(wname); + auto wellPI = std::vector(wellpi_wells.size()); + for (auto i = 0*wellpi_wells.size(); i < wellpi_wells.size(); ++i) { + if (wellModel.hasWell(wellpi_wells[i])) { + wellPI[i] = wellModel.wellPI(wellpi_wells[i]); } } - if (comm.size() > 1) { - std::vector wellpi_buffer(num_wells * comm.size()); - comm.gather(wellpi_vector.data(), wellpi_buffer.data(), num_wells, 0); + comm.max(wellPI.data(), wellPI.size()); - if (comm.rank() == 0) { - for (int rank = 1; rank < comm.size(); ++rank) { - for (std::size_t well_index = 0; well_index < num_wells; ++well_index) { - const auto global_index = rank*num_wells + well_index; - const auto value = wellpi_buffer[global_index]; - if (value != Scalar{0}) { - wellpi_vector[well_index] = value; - } - } - } - } - - comm.broadcast(wellpi_vector.data(), wellpi_vector.size(), 0); - } - - for (const auto& wname : wellpi_wells) { - const auto& well = schedule.getWell(wname, reportStep); - wellpi.insert_or_assign(wname, wellpi_vector[well.seqIndex()]); + for (auto i = 0*wellpi_wells.size(); i < wellpi_wells.size(); ++i) { + wellpi.emplace(wellpi_wells[i], wellPI[i]); } return wellpi;