diff --git a/opm/simulators/flow/FlowGenericProblem_impl.hpp b/opm/simulators/flow/FlowGenericProblem_impl.hpp index ac2850f3ed..f50daa4422 100644 --- a/opm/simulators/flow/FlowGenericProblem_impl.hpp +++ b/opm/simulators/flow/FlowGenericProblem_impl.hpp @@ -139,10 +139,12 @@ readRockParameters_(const std::vector& cellCenterDepths, { const auto& comp = rock_config.comp(); rockParams_.clear(); - for (const auto& c : comp) { - rockParams_.push_back({static_cast(c.pref), - static_cast(c.compressibility)}); - } + std::transform(comp.begin(), comp.end(), std::back_inserter(rockParams_), + [](const auto& c) + { + return RockParams{static_cast(c.pref), + static_cast(c.compressibility)}; + }); } // Warn that ROCK and ROCKOPTS item 2 = STORE is used together diff --git a/opm/simulators/flow/FlowProblemBlackoil.hpp b/opm/simulators/flow/FlowProblemBlackoil.hpp index 5c23784a7c..59c301503c 100644 --- a/opm/simulators/flow/FlowProblemBlackoil.hpp +++ b/opm/simulators/flow/FlowProblemBlackoil.hpp @@ -346,9 +346,8 @@ public: { std::array coords; simulator.vanguard().cartesianCoordinate(idx, coords); - for (auto& c : coords) { - ++c; - } + std::transform(coords.begin(), coords.end(), coords.begin(), + [](const auto c) { return c + 1; }); return coords; }); diff --git a/opm/simulators/flow/FlowProblemComp.hpp b/opm/simulators/flow/FlowProblemComp.hpp index fc561849a9..796d53b042 100644 --- a/opm/simulators/flow/FlowProblemComp.hpp +++ b/opm/simulators/flow/FlowProblemComp.hpp @@ -196,9 +196,8 @@ public: this->readRockParameters_(simulator.vanguard().cellCenterDepths(), [&simulator](const unsigned idx) { std::array coords; simulator.vanguard().cartesianCoordinate(idx, coords); - for (auto& c : coords) { - ++c; - } + std::transform(coords.begin(), coords.end(), coords.begin(), + [](const auto c) { return c + 1; }); return coords; }); FlowProblemType::readMaterialParameters_(); diff --git a/opm/simulators/flow/GenericOutputBlackoilModule.cpp b/opm/simulators/flow/GenericOutputBlackoilModule.cpp index d9ed173939..7a6f3ad769 100644 --- a/opm/simulators/flow/GenericOutputBlackoilModule.cpp +++ b/opm/simulators/flow/GenericOutputBlackoilModule.cpp @@ -76,12 +76,13 @@ namespace { defineInterRegionFlowArrays(const Opm::EclipseState& eclState, const Opm::SummaryConfig& summaryConfig) { - auto regions = std::vector{}; - - const auto& fprops = eclState.fieldProps(); - for (const auto& arrayName : summaryConfig.fip_regions_interreg_flow()) { - regions.push_back({ arrayName, std::cref(fprops.get_int(arrayName)) }); - } + using SRegion = Opm::InterRegFlowMap::SingleRegion; + auto regions = std::vector{}; + const auto fip_regions = summaryConfig.fip_regions_interreg_flow(); + std::transform(fip_regions.begin(), fip_regions.end(), + std::back_inserter(regions), + [&fprops = eclState.fieldProps()](const auto& arrayName) + { return SRegion{arrayName, std::cref(fprops.get_int(arrayName))}; }); return regions; } diff --git a/opm/simulators/flow/InterRegFlows.cpp b/opm/simulators/flow/InterRegFlows.cpp index d7db02e720..905ea3b47d 100644 --- a/opm/simulators/flow/InterRegFlows.cpp +++ b/opm/simulators/flow/InterRegFlows.cpp @@ -190,9 +190,11 @@ Opm::InterRegFlowMap::getInterRegFlows() const auto maps = std::vector{}; maps.reserve(this->regionMaps_.size()); - for (const auto& regionMap : this->regionMaps_) { - maps.push_back(regionMap.getInterRegFlows()); - } + std::transform(this->regionMaps_.begin(), + this->regionMaps_.end(), + std::back_inserter(maps), + [](const auto& regionMap) + { return regionMap.getInterRegFlows(); }); return maps; } @@ -203,9 +205,11 @@ Opm::InterRegFlowMap::getLocalMaxRegionID() const auto maxLocalRegionID = std::vector{}; maxLocalRegionID.reserve(this->regionMaps_.size()); - for (const auto& regionMap : this->regionMaps_) { - maxLocalRegionID.push_back(regionMap.getLocalMaxRegionID()); - } + std::transform(this->regionMaps_.begin(), + this->regionMaps_.end(), + std::back_inserter(maxLocalRegionID), + [](const auto& regionMap) + { return regionMap.getLocalMaxRegionID(); }); return maxLocalRegionID; } diff --git a/opm/simulators/flow/NonlinearSolver.cpp b/opm/simulators/flow/NonlinearSolver.cpp index 03915ade21..585c1673be 100644 --- a/opm/simulators/flow/NonlinearSolver.cpp +++ b/opm/simulators/flow/NonlinearSolver.cpp @@ -82,9 +82,8 @@ void stabilizeNonlinearUpdate(BVector& dx, BVector& dxOld, if (omega == 1.) { return; } - for (auto& d : dx) { - d *= omega; - } + std::transform(dx.begin(), dx.end(), dx.begin(), + [omega](const auto d) { return d*omega; }); return; } case NonlinearRelaxType::SOR: { diff --git a/opm/simulators/flow/partitionCells.cpp b/opm/simulators/flow/partitionCells.cpp index 9dfa1ac6ec..c51856ed05 100644 --- a/opm/simulators/flow/partitionCells.cpp +++ b/opm/simulators/flow/partitionCells.cpp @@ -506,9 +506,8 @@ namespace { comm.broadcast(startPtr.data(), comm.size() + 1, 0); // We're scattering two ints per cell - for (auto& startIx : startPtr) { - startIx *= 2; - } + std::transform(startPtr.begin(), startPtr.end(), startPtr.begin(), + [](const auto startIx) { return startIx * 2; }); auto sendLength = std::vector(comm.size()); std::adjacent_difference(startPtr.begin() + 1, diff --git a/opm/simulators/linalg/PropertyTree.cpp b/opm/simulators/linalg/PropertyTree.cpp index d52dd0d11b..94ff903466 100644 --- a/opm/simulators/linalg/PropertyTree.cpp +++ b/opm/simulators/linalg/PropertyTree.cpp @@ -108,9 +108,10 @@ PropertyTree::get_child_items_as_vector(const std::string& child) const } items.emplace(); - for (const auto& childItem : *subTree) { - items->push_back(childItem.second.template get_value()); - } + std::transform(subTree->begin(), subTree->end(), + std::back_inserter(*items), + [](const auto& childItem) + { return childItem.second.template get_value(); }); return items; } diff --git a/opm/simulators/wells/BlackoilWellModelGasLift_impl.hpp b/opm/simulators/wells/BlackoilWellModelGasLift_impl.hpp index a2c148c97c..9463a9a24a 100644 --- a/opm/simulators/wells/BlackoilWellModelGasLift_impl.hpp +++ b/opm/simulators/wells/BlackoilWellModelGasLift_impl.hpp @@ -118,9 +118,10 @@ maybeDoGasLiftOptimize(const Simulator& simulator, if constexpr (glift_debug) { std::vector*> wc; wc.reserve(well_container.size()); - for (const auto& w : well_container) { - wc.push_back(static_cast*>(w.get())); - } + std::transform(well_container.begin(), well_container.end(), + std::back_inserter(wc), + [](const auto& w) + { return static_cast*>(w.get()); }); this->gliftDebugShowALQ(wc, wellState, deferred_logger); diff --git a/opm/simulators/wells/BlackoilWellModel_impl.hpp b/opm/simulators/wells/BlackoilWellModel_impl.hpp index c275eb35cf..7436422ddc 100644 --- a/opm/simulators/wells/BlackoilWellModel_impl.hpp +++ b/opm/simulators/wells/BlackoilWellModel_impl.hpp @@ -2177,11 +2177,10 @@ namespace Opm { // compute global average grid.comm().sum(B_avg.data(), B_avg.size()); - for (auto& bval : B_avg) - { - bval /= global_num_cells_; - } - B_avg_ = B_avg; + B_avg_.resize(B_avg.size()); + std::transform(B_avg.begin(), B_avg.end(), B_avg_.begin(), + [gcells = global_num_cells_](const auto bval) + { return bval / gcells; }); } diff --git a/opm/simulators/wells/GasLiftGroupInfo.cpp b/opm/simulators/wells/GasLiftGroupInfo.cpp index 5fc09ad606..dc260a271f 100644 --- a/opm/simulators/wells/GasLiftGroupInfo.cpp +++ b/opm/simulators/wells/GasLiftGroupInfo.cpp @@ -687,9 +687,9 @@ initializeWell2GroupMapRecursive_(const Group& group, { Scalar gfac = group.getGroupEfficiencyFactor(); cur_efficiency = gfac * cur_efficiency; - for (auto &item : group_efficiency) { - item *= gfac; - } + std::transform(group_efficiency.begin(), group_efficiency.end(), + group_efficiency.begin(), + [gfac](const auto& item) { return item * gfac; }); if (this->group_rate_map_.count(group.name()) == 1) { // extract the subset of groups that has limits or targets that can affect // gas lift optimization. diff --git a/opm/simulators/wells/GasLiftSingleWell_impl.hpp b/opm/simulators/wells/GasLiftSingleWell_impl.hpp index 14875bf939..51c35a5589 100644 --- a/opm/simulators/wells/GasLiftSingleWell_impl.hpp +++ b/opm/simulators/wells/GasLiftSingleWell_impl.hpp @@ -26,6 +26,8 @@ #include #endif +#include + #include #include @@ -128,9 +130,10 @@ computeWellRates_(Scalar bhp, bool bhp_is_limited, bool debug_output ) const this->displayDebugMessage_(msg); } - for (auto& potential : potentials) { - potential = std::min(Scalar{0.0}, potential); - } + std::transform(potentials.begin(), potentials.end(), + potentials.begin(), + [](const auto& potential) + { return std::min(Scalar{0}, potential); }); return {-potentials[this->oil_pos_], -potentials[this->gas_pos_], -potentials[this->water_pos_], diff --git a/opm/simulators/wells/RateConverter.cpp b/opm/simulators/wells/RateConverter.cpp index 23ae600caa..558fac37d3 100644 --- a/opm/simulators/wells/RateConverter.cpp +++ b/opm/simulators/wells/RateConverter.cpp @@ -81,8 +81,8 @@ sumRates(std::unordered_map& attributes_hpv, assert(ra.pv > 0.); } const Scalar pv_sum = ra.pv; - for (Scalar & d : ra.data) - d /= pv_sum; + std::transform(ra.data.begin(), ra.data.end(), ra.data.begin(), + [pv_sum](const auto d) { return d / pv_sum; }); ra.pv = pv_sum; } } diff --git a/opm/simulators/wells/WellGroupHelpers.cpp b/opm/simulators/wells/WellGroupHelpers.cpp index fc9b28c9fa..331ad48cef 100644 --- a/opm/simulators/wells/WellGroupHelpers.cpp +++ b/opm/simulators/wells/WellGroupHelpers.cpp @@ -46,6 +46,7 @@ #include #include #include + #include #include #include @@ -1009,7 +1010,8 @@ computeNetworkPressures(const Network::ExtNetwork& network, // convention that production rates are negative, so we must // take a copy and flip signs. auto rates = node_inflows[node]; - for (auto& r : rates) { r *= -1.0; } + std::transform(rates.begin(), rates.end(), rates.begin(), + [](const auto r) { return -r; }); assert(rates.size() == 3); // NB! ALQ in extended network is never implicitly the gas lift rate (GRAT), i.e., the // gas lift rates only enters the network pressure calculations through the rates diff --git a/opm/simulators/wells/WellInterface_impl.hpp b/opm/simulators/wells/WellInterface_impl.hpp index a5ef34179d..3a6dc02a48 100644 --- a/opm/simulators/wells/WellInterface_impl.hpp +++ b/opm/simulators/wells/WellInterface_impl.hpp @@ -1920,9 +1920,9 @@ namespace Opm const auto& connections = this->well_ecl_.getConnections(); const auto& connection = connections[perf_ecl_index]; if (connection.filterCakeActive()) { - for (auto& val : mob) { - val *= this->inj_fc_multiplier_[perf]; - } + std::transform(mob.begin(), mob.end(), mob.begin(), + [mult = this->inj_fc_multiplier_[perf] ](const auto val) + { return val * mult; }); } } } diff --git a/tests/test_norne_pvt.cpp b/tests/test_norne_pvt.cpp index 2fc8f15fcc..cd41edec1c 100644 --- a/tests/test_norne_pvt.cpp +++ b/tests/test_norne_pvt.cpp @@ -31,9 +31,6 @@ #endif #include -#include -#include - #include #include #include @@ -47,6 +44,7 @@ #include +#include using namespace Opm; @@ -107,15 +105,13 @@ void verify_norne_oil_pvt_region1(const Opm::EclipseState& eclState, const Opm:: 0.77691738473}; { - std::vector tableIndex(P.size() , 0); - // convert the pressures to SI units (bar to Pascal) - for (auto& value : P) - value *= Metric::Pressure; + std::transform(P.begin(), P.end(), P.begin(), + [](const auto value) { return value * Metric::Pressure; }); // convert the gas dissolution factors to SI units - for (auto& value : rs) - value *= Metric::GasDissolutionFactor; + std::transform(rs.begin(), rs.end(), rs.begin(), + [](const auto value) { return value * Metric::GasDissolutionFactor; }); for (unsigned i = 0; i < P.size(); ++i) { double mu; @@ -255,12 +251,12 @@ void verify_norne_oil_pvt_region2(const Opm::EclipseState& eclState, const Opm:: 0.55474601877, 0.55809201119, 0.54526832277}; // convert the pressures to SI units (bar to Pascal) - for (auto& value : P) - value *= Metric::Pressure; + std::transform(P.begin(), P.end(), P.begin(), + [](const auto value) { return value * Metric::Pressure; }); // convert the gas dissolution factors to SI units - for (auto& value : rs) - value *= Metric::GasDissolutionFactor; + std::transform(rs.begin(), rs.end(), rs.begin(), + [](const auto value) { return value * Metric::GasDissolutionFactor; }); for (unsigned i = 0; i < P.size(); ++i) { double mu; diff --git a/tests/test_parallelwellinfo.cpp b/tests/test_parallelwellinfo.cpp index 2da84d22d5..2c342d3086 100644 --- a/tests/test_parallelwellinfo.cpp +++ b/tests/test_parallelwellinfo.cpp @@ -118,10 +118,11 @@ BOOST_AUTO_TEST_CASE(ParallelWellComparison) pairs = {{"Test1", false},{"Test2", true}, {"Test1", true} }; std::vector> well_info; - - for (const auto& wellinfo : pairs) { - well_info.emplace_back(wellinfo, Opm::Parallel::Communication()); - } + + std::transform(pairs.begin(), pairs.end(), + std::back_inserter(well_info), + [](const auto& wellinfo) -> Opm::ParallelWellInfo + { return {wellinfo, Opm::Parallel::Communication()}; }); //well_info.assign(pairs.begin(), pairs.end());