From 61e5a3dd7f4487f12eba603cab0655eede857fbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20H=C3=A6gland?= Date: Sun, 22 Jun 2025 12:09:14 +0200 Subject: [PATCH] Use try_emplace() instead of emplace() Fix bug where emplace() did not update existing keys in the map. Instead use try_emplace() for efficient conditional construction and assignment. --- opm/simulators/wells/GroupState.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/opm/simulators/wells/GroupState.cpp b/opm/simulators/wells/GroupState.cpp index 439da83e77..3163757b6a 100644 --- a/opm/simulators/wells/GroupState.cpp +++ b/opm/simulators/wells/GroupState.cpp @@ -514,9 +514,12 @@ void GroupState:: update_group_production_potential(const std::string& gname, Scalar oil_rate, Scalar gas_rate, Scalar water_rate) { - this->production_group_potentials.emplace( - gname, GroupPotential{oil_rate, gas_rate, water_rate} + auto [it, inserted] = production_group_potentials.try_emplace( + gname, oil_rate, gas_rate, water_rate ); + if (!inserted) { + it->second = GroupPotential{oil_rate, gas_rate, water_rate}; + } } template