mirror of
https://github.com/OPM/opm-simulators.git
synced 2026-10-31 09:44:07 -05:00
replace std::transform with std::ranges::transform where appropriate
the c++-20 constrained algorithm is safer and code is more readable
This commit is contained in:
1 parent
91ad70dfb7
commit
670743f786
40 files changed
+141
-183
No files matched your search
@@ -108,13 +108,9 @@ public:
|
||||
this->alphai_.assign(this->size(), Scalar{0});
|
||||
}
|
||||
else {
|
||||
std::transform(this->faceArea_connected_.begin(),
|
||||
this->faceArea_connected_.end(),
|
||||
this->alphai_.begin(),
|
||||
[tfa](const Scalar area)
|
||||
{
|
||||
return area / tfa;
|
||||
});
|
||||
std::ranges::transform(this->faceArea_connected_, this->alphai_.begin(),
|
||||
[tfa](const Scalar area)
|
||||
{ return area / tfa; });
|
||||
}
|
||||
|
||||
this->area_fraction_ = this->totalFaceArea() / tfa;
|
||||
|
||||
@@ -726,14 +726,9 @@ private:
|
||||
const auto& src = aquNum;
|
||||
auto& dst = *aq.typeData.getMutable<data::AquiferType::Numerical>();
|
||||
|
||||
std::transform(src.initPressure.begin(),
|
||||
src.initPressure.end(),
|
||||
dst.initPressure.begin(),
|
||||
dst.initPressure.begin(),
|
||||
[](const double p0_1, const double p0_2)
|
||||
{
|
||||
return std::max(p0_1, p0_2);
|
||||
});
|
||||
std::ranges::transform(src.initPressure, dst.initPressure, dst.initPressure.begin(),
|
||||
[](const double p0_1, const double p0_2)
|
||||
{ return std::max(p0_1, p0_2); });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -143,12 +143,14 @@ readRockParameters_(const std::vector<Scalar>& cellCenterDepths,
|
||||
{
|
||||
const auto& comp = rock_config.comp();
|
||||
rockParams_.clear();
|
||||
std::transform(comp.begin(), comp.end(), std::back_inserter(rockParams_),
|
||||
[](const auto& c)
|
||||
{
|
||||
return RockParams{static_cast<Scalar>(c.pref),
|
||||
static_cast<Scalar>(c.compressibility)};
|
||||
});
|
||||
std::ranges::transform(comp, std::back_inserter(rockParams_),
|
||||
[](const auto& c)
|
||||
{
|
||||
return RockParams{
|
||||
static_cast<Scalar>(c.pref),
|
||||
static_cast<Scalar>(c.compressibility)
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
// Warn that ROCK and ROCKOPTS item 2 = STORE is used together
|
||||
|
||||
@@ -335,7 +335,7 @@ void FlowGenericVanguard::init()
|
||||
|
||||
// transform the result to ALL_UPPERCASE
|
||||
caseName_ = rawCaseName;
|
||||
std::transform(caseName_.begin(), caseName_.end(), caseName_.begin(), ::toupper);
|
||||
std::ranges::transform(caseName_, caseName_.begin(), ::toupper);
|
||||
}
|
||||
|
||||
// set communicator if not set as in opm flow
|
||||
|
||||
@@ -371,8 +371,8 @@ public:
|
||||
{
|
||||
std::array<int,dim> coords;
|
||||
simulator.vanguard().cartesianCoordinate(idx, coords);
|
||||
std::transform(coords.begin(), coords.end(), coords.begin(),
|
||||
[](const auto c) { return c + 1; });
|
||||
std::ranges::transform(coords, coords.begin(),
|
||||
[](const auto c) { return c + 1; });
|
||||
return coords;
|
||||
});
|
||||
|
||||
|
||||
@@ -196,8 +196,8 @@ public:
|
||||
this->readRockParameters_(simulator.vanguard().cellCenterDepths(), [&simulator](const unsigned idx) {
|
||||
std::array<int, dim> coords;
|
||||
simulator.vanguard().cartesianCoordinate(idx, coords);
|
||||
std::transform(coords.begin(), coords.end(), coords.begin(),
|
||||
[](const auto c) { return c + 1; });
|
||||
std::ranges::transform(coords, coords.begin(),
|
||||
[](const auto c) { return c + 1; });
|
||||
return coords;
|
||||
});
|
||||
FlowProblemType::readMaterialParameters_();
|
||||
|
||||
@@ -80,10 +80,9 @@ namespace {
|
||||
using SRegion = Opm::InterRegFlowMap::SingleRegion;
|
||||
auto regions = std::vector<SRegion>{};
|
||||
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))}; });
|
||||
std::ranges::transform(fip_regions, std::back_inserter(regions),
|
||||
[&fprops = eclState.fieldProps()](const auto& arrayName)
|
||||
{ return SRegion{arrayName, std::cref(fprops.get_int(arrayName))}; });
|
||||
|
||||
return regions;
|
||||
}
|
||||
|
||||
@@ -37,9 +37,8 @@ InterRegFlowMapSingleFIP(const std::vector<int>& region)
|
||||
*std::max_element(region.begin(), region.end());
|
||||
}
|
||||
|
||||
std::transform(region.begin(), region.end(),
|
||||
this->region_.begin(),
|
||||
[](const int regID) { return regID - 1; });
|
||||
std::ranges::transform(region, this->region_.begin(),
|
||||
[](const int regID) { return regID - 1; });
|
||||
}
|
||||
|
||||
void
|
||||
@@ -190,11 +189,9 @@ Opm::InterRegFlowMap::getInterRegFlows() const
|
||||
auto maps = std::vector<data::InterRegFlowMap>{};
|
||||
maps.reserve(this->regionMaps_.size());
|
||||
|
||||
std::transform(this->regionMaps_.begin(),
|
||||
this->regionMaps_.end(),
|
||||
std::back_inserter(maps),
|
||||
[](const auto& regionMap)
|
||||
{ return regionMap.getInterRegFlows(); });
|
||||
std::ranges::transform(this->regionMaps_, std::back_inserter(maps),
|
||||
[](const auto& regionMap)
|
||||
{ return regionMap.getInterRegFlows(); });
|
||||
|
||||
return maps;
|
||||
}
|
||||
@@ -205,11 +202,9 @@ Opm::InterRegFlowMap::getLocalMaxRegionID() const
|
||||
auto maxLocalRegionID = std::vector<std::size_t>{};
|
||||
maxLocalRegionID.reserve(this->regionMaps_.size());
|
||||
|
||||
std::transform(this->regionMaps_.begin(),
|
||||
this->regionMaps_.end(),
|
||||
std::back_inserter(maxLocalRegionID),
|
||||
[](const auto& regionMap)
|
||||
{ return regionMap.getLocalMaxRegionID(); });
|
||||
std::ranges::transform(this->regionMaps_, std::back_inserter(maxLocalRegionID),
|
||||
[](const auto& regionMap)
|
||||
{ return regionMap.getLocalMaxRegionID(); });
|
||||
|
||||
return maxLocalRegionID;
|
||||
}
|
||||
|
||||
@@ -82,8 +82,8 @@ void stabilizeNonlinearUpdate(BVector& dx, BVector& dxOld,
|
||||
if (omega == 1.) {
|
||||
return;
|
||||
}
|
||||
std::transform(dx.begin(), dx.end(), dx.begin(),
|
||||
[omega](const auto d) { return d*omega; });
|
||||
std::ranges::transform(dx, dx.begin(),
|
||||
[omega](const auto d) { return d*omega; });
|
||||
return;
|
||||
}
|
||||
case NonlinearRelaxType::SOR: {
|
||||
|
||||
@@ -1443,7 +1443,7 @@ equilnum(const EclipseState& eclipseState,
|
||||
|
||||
if (eclipseState.fieldProps().has_int("EQLNUM")) {
|
||||
const auto& e = eclipseState.fieldProps().get_int("EQLNUM");
|
||||
std::transform(e.begin(), e.end(), eqlnum.begin(), [](int n){ return n - 1;});
|
||||
std::ranges::transform(e, eqlnum.begin(), [](int n) { return n - 1; });
|
||||
}
|
||||
OPM_BEGIN_PARALLEL_TRY_CATCH();
|
||||
const int num_regions = eclipseState.getTableManager().getEqldims().getNumEquilRegions();
|
||||
|
||||
@@ -506,8 +506,8 @@ namespace {
|
||||
comm.broadcast(startPtr.data(), comm.size() + 1, 0);
|
||||
|
||||
// We're scattering two ints per cell
|
||||
std::transform(startPtr.begin(), startPtr.end(), startPtr.begin(),
|
||||
[](const auto startIx) { return startIx * 2; });
|
||||
std::ranges::transform(startPtr, startPtr.begin(),
|
||||
[](const auto startIx) { return startIx * 2; });
|
||||
|
||||
auto sendLength = std::vector<int>(comm.size());
|
||||
std::adjacent_difference(startPtr.begin() + 1,
|
||||
|
||||
@@ -359,7 +359,7 @@ std::unique_ptr<Matrix> blockJacobiAdjacency(const Grid& grid,
|
||||
// TODO: check all solvers, not just one.
|
||||
// We use lower case as the internal canonical representation of solver names
|
||||
std::string type = prm_[activeSolverNum_].template get<std::string>("preconditioner.type", "paroverilu0");
|
||||
std::transform(type.begin(), type.end(), type.begin(), ::tolower);
|
||||
std::ranges::transform(type, type.begin(), ::tolower);
|
||||
if (isParallel() && type != "paroverilu0") {
|
||||
detail::makeOverlapRowsInvalid(getMatrix(), overlapRows_);
|
||||
}
|
||||
@@ -576,7 +576,7 @@ std::unique_ptr<Matrix> blockJacobiAdjacency(const Grid& grid,
|
||||
|
||||
auto preconditionerType = prm.get("preconditioner.type"s, "cpr"s);
|
||||
// We use lower case as the internal canonical representation of solver names
|
||||
std::transform(preconditionerType.begin(), preconditionerType.end(), preconditionerType.begin(), ::tolower);
|
||||
std::ranges::transform(preconditionerType, preconditionerType.begin(), ::tolower);
|
||||
if (preconditionerType == "cpr" || preconditionerType == "cprt"
|
||||
|| preconditionerType == "cprw" || preconditionerType == "cprwt") {
|
||||
const bool transpose = preconditionerType == "cprt" || preconditionerType == "cprwt";
|
||||
|
||||
@@ -66,7 +66,8 @@ inline LinearSolverAcceleratorType
|
||||
linearSolverAcceleratorTypeFromString(const std::string& str)
|
||||
{
|
||||
std::string lowerStr = str;
|
||||
std::transform(lowerStr.begin(), lowerStr.end(), lowerStr.begin(), [](unsigned char c) { return std::tolower(c); });
|
||||
std::ranges::transform(lowerStr, lowerStr.begin(),
|
||||
[](unsigned char c) { return std::tolower(c); });
|
||||
if (lowerStr == "gpu") {
|
||||
return LinearSolverAcceleratorType::GPU;
|
||||
} else if (lowerStr == "cpu") {
|
||||
|
||||
@@ -56,7 +56,7 @@ MILU_VARIANT convertString2Milu(const std::string& milu)
|
||||
{
|
||||
// We use lower case as the internal canonical representation of solver names
|
||||
std::string milu_lower = milu;
|
||||
std::transform(milu_lower.begin(), milu_lower.end(), milu_lower.begin(), ::tolower);
|
||||
std::ranges::transform(milu_lower, milu_lower.begin(), ::tolower);
|
||||
|
||||
if( 0 == milu_lower.compare("milu_1") )
|
||||
{
|
||||
|
||||
@@ -93,7 +93,7 @@ PreconditionerFactory<Operator, Comm>::doCreate(const Operator& op,
|
||||
}
|
||||
std::string type = prm.get<std::string>("type", "paroverilu0");
|
||||
// We use lower case as the internal canonical representation of solver names
|
||||
std::transform(type.begin(), type.end(), type.begin(), ::tolower);
|
||||
std::ranges::transform(type, type.begin(), ::tolower);
|
||||
auto it = creators_.find(type);
|
||||
if (it == creators_.end()) {
|
||||
std::ostringstream msg;
|
||||
@@ -121,7 +121,7 @@ PreconditionerFactory<Operator, Comm>::doCreate(const Operator& op,
|
||||
}
|
||||
std::string type = prm.get<std::string>("type", "paroverilu0");
|
||||
// We use lower case as the internal canonical representation of solver names
|
||||
std::transform(type.begin(), type.end(), type.begin(), ::tolower);
|
||||
std::ranges::transform(type, type.begin(), ::tolower);
|
||||
auto it = parallel_creators_.find(type);
|
||||
if (it == parallel_creators_.end()) {
|
||||
std::ostringstream msg;
|
||||
|
||||
@@ -117,10 +117,9 @@ PropertyTree::get_child_items_as_vector(const std::string& child) const
|
||||
}
|
||||
|
||||
items.emplace();
|
||||
std::transform(subTree->begin(), subTree->end(),
|
||||
std::back_inserter(*items),
|
||||
[](const auto& childItem)
|
||||
{ return childItem.second.template get_value<T>(); });
|
||||
std::ranges::transform(*subTree, std::back_inserter(*items),
|
||||
[](const auto& childItem)
|
||||
{ return childItem.second.template get_value<T>(); });
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ struct StandardPreconditioners
|
||||
using PrecPtr = std::shared_ptr<Dune::PreconditionerWithUpdate<V, V>>;
|
||||
std::string smoother = prm.get<std::string>("smoother", "paroverilu0");
|
||||
// Make the smoother type lowercase for internal canonical representation
|
||||
std::transform(smoother.begin(), smoother.end(), smoother.begin(), ::tolower);
|
||||
std::ranges::transform(smoother, smoother.begin(), ::tolower);
|
||||
// TODO: merge this with ILUn, and possibly simplify the factory to only work with ILU?
|
||||
if (smoother == "ilu0" || smoother == "paroverilu0") {
|
||||
using Smoother = ParallelOverlappingILU0<M, V, V, C>;
|
||||
|
||||
@@ -121,7 +121,7 @@ struct StandardPreconditioners<Operator, Dune::Amg::SequentialInformation, typen
|
||||
F::addCreator("amg", [](const O& op, const P& prm, const std::function<V()>&, std::size_t) {
|
||||
std::string smoother = prm.get<std::string>("smoother", "paroverilu0");
|
||||
// Make the smoother type lowercase for internal canonical representation
|
||||
std::transform(smoother.begin(), smoother.end(), smoother.begin(), ::tolower);
|
||||
std::ranges::transform(smoother, smoother.begin(), ::tolower);
|
||||
if (smoother == "ilu0" || smoother == "paroverilu0") {
|
||||
using Smoother = SeqILU<M, V, V>;
|
||||
return AMGHelper<O, C, M, V>::template makeAmgPreconditioner<Smoother>(op, prm);
|
||||
@@ -150,7 +150,7 @@ struct StandardPreconditioners<Operator, Dune::Amg::SequentialInformation, typen
|
||||
F::addCreator("kamg", [](const O& op, const P& prm, const std::function<V()>&, std::size_t) {
|
||||
std::string smoother = prm.get<std::string>("smoother", "paroverilu0");
|
||||
// Make the smoother type lowercase for internal canonical representation
|
||||
std::transform(smoother.begin(), smoother.end(), smoother.begin(), ::tolower);
|
||||
std::ranges::transform(smoother, smoother.begin(), ::tolower);
|
||||
if (smoother == "ilu0" || smoother == "paroverilu0") {
|
||||
using Smoother = SeqILU<M, V, V>;
|
||||
return AMGHelper<O, C, M, V>::template makeAmgPreconditioner<Smoother>(op, prm, true);
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace
|
||||
|
||||
// Respect explicit request if user already set a backend
|
||||
std::string requested = prm.get(typeKey, "amg"s);
|
||||
std::transform(requested.begin(), requested.end(), requested.begin(), ::tolower);
|
||||
std::ranges::transform(requested, requested.begin(), ::tolower);
|
||||
|
||||
if (requested == "amgx") {
|
||||
#if HAVE_AMGX
|
||||
@@ -205,7 +205,7 @@ setupPropertyTree(FlowLinearSolverParameters p, // Note: copying the parameters
|
||||
}
|
||||
|
||||
// We use lower case as the internal canonical representation of solver names.
|
||||
std::transform(conf.begin(), conf.end(), conf.begin(), ::tolower);
|
||||
std::ranges::transform(conf, conf.begin(), ::tolower);
|
||||
|
||||
// Use CPR configuration.
|
||||
if ((conf == "cpr_trueimpes") || (conf == "cpr_quasiimpes") || (conf == "cpr_trueimpesanalytic")) {
|
||||
|
||||
@@ -59,11 +59,9 @@ std::vector<int> HDF5Serializer::reportSteps() const
|
||||
{
|
||||
const auto entries = m_h5file.list("/report_step");
|
||||
std::vector<int> result(entries.size());
|
||||
std::transform(entries.begin(), entries.end(), result.begin(),
|
||||
[](const std::string& input)
|
||||
{
|
||||
return std::atoi(input.c_str());
|
||||
});
|
||||
std::ranges::transform(entries, result.begin(),
|
||||
[](const std::string& input)
|
||||
{ return std::atoi(input.c_str()); });
|
||||
std::sort(result.begin(), result.end());
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -391,10 +391,9 @@ namespace {
|
||||
{
|
||||
auto fieldWidths = std::vector<std::size_t>(columnHeaders.size());
|
||||
|
||||
std::transform(columnHeaders.begin(), columnHeaders.end(),
|
||||
fieldWidths.begin(),
|
||||
[minColWidth](const std::string& header)
|
||||
{ return std::max(minColWidth, header.size()); });
|
||||
std::ranges::transform(columnHeaders, fieldWidths.begin(),
|
||||
[minColWidth](const std::string& header)
|
||||
{ return std::max(minColWidth, header.size()); });
|
||||
|
||||
return fieldWidths;
|
||||
}
|
||||
|
||||
@@ -125,10 +125,9 @@ maybeDoGasLiftOptimize(const Simulator& simulator,
|
||||
if constexpr (glift_debug) {
|
||||
std::vector<WellInterfaceGeneric<Scalar, IndexTraits>*> wc;
|
||||
wc.reserve(well_container.size());
|
||||
std::transform(well_container.begin(), well_container.end(),
|
||||
std::back_inserter(wc),
|
||||
[](const auto& w)
|
||||
{ return static_cast<WellInterfaceGeneric<Scalar, IndexTraits>*>(w.get()); });
|
||||
std::ranges::transform(well_container, std::back_inserter(wc),
|
||||
[](const auto& w)
|
||||
{ return static_cast<WellInterfaceGeneric<Scalar, IndexTraits>*>(w.get()); });
|
||||
this->gliftDebugShowALQ(wc,
|
||||
wellState,
|
||||
deferred_logger);
|
||||
|
||||
@@ -302,11 +302,10 @@ getLocalWells(const int timeStepIdx) const
|
||||
|
||||
w.reserve(wnames.size());
|
||||
|
||||
std::transform(wnames.begin(), wnames.end(),
|
||||
std::back_inserter(w),
|
||||
[&st = this->schedule()[timeStepIdx]]
|
||||
(const std::string& wname)
|
||||
{ return st.wells(wname); });
|
||||
std::ranges::transform(wnames, std::back_inserter(w),
|
||||
[&st = this->schedule()[timeStepIdx]]
|
||||
(const std::string& wname)
|
||||
{ return st.wells(wname); });
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
@@ -412,8 +412,7 @@ computePressures(const Network::ExtNetwork& network,
|
||||
// convention that production rates are negative, so we must
|
||||
// take a copy and flip signs.
|
||||
auto rates = node_inflows[node];
|
||||
std::transform(
|
||||
rates.begin(), rates.end(), rates.begin(), [](const auto r) { return -r; });
|
||||
std::ranges::transform(rates, 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
|
||||
|
||||
@@ -205,10 +205,9 @@ BlackoilWellModelNldd<TypeTag>::
|
||||
setupDomains(const std::vector<Domain>& domains)
|
||||
{
|
||||
std::vector<const SubDomainIndices*> genDomains;
|
||||
std::transform(domains.begin(), domains.end(),
|
||||
std::back_inserter(genDomains),
|
||||
[](const auto& domain)
|
||||
{ return static_cast<const SubDomainIndices*>(&domain); });
|
||||
std::ranges::transform(domains, std::back_inserter(genDomains),
|
||||
[](const auto& domain)
|
||||
{ return static_cast<const SubDomainIndices*>(&domain); });
|
||||
this->calcDomains(genDomains);
|
||||
}
|
||||
|
||||
|
||||
@@ -2055,9 +2055,9 @@ namespace Opm {
|
||||
// compute global average
|
||||
grid.comm().sum(B_avg.data(), B_avg.size());
|
||||
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; });
|
||||
std::ranges::transform(B_avg, B_avg_.begin(),
|
||||
[gcells = global_num_cells_](const auto bval)
|
||||
{ return bval / gcells; });
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -731,9 +731,8 @@ initializeWell2GroupMapRecursive_(const Group& group,
|
||||
{
|
||||
Scalar gfac = group.getGroupEfficiencyFactor();
|
||||
cur_efficiency = gfac * cur_efficiency;
|
||||
std::transform(group_efficiency.begin(), group_efficiency.end(),
|
||||
group_efficiency.begin(),
|
||||
[gfac](const auto& item) { return item * gfac; });
|
||||
std::ranges::transform(group_efficiency, 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.
|
||||
|
||||
@@ -129,10 +129,9 @@ computeWellRates_(Scalar bhp, bool bhp_is_limited, bool debug_output ) const
|
||||
this->displayDebugMessage_(msg);
|
||||
}
|
||||
|
||||
std::transform(potentials.begin(), potentials.end(),
|
||||
potentials.begin(),
|
||||
[](const auto& potential)
|
||||
{ return std::min(Scalar{0}, potential); });
|
||||
std::ranges::transform(potentials, potentials.begin(),
|
||||
[](const auto& potential)
|
||||
{ return std::min(Scalar{0}, potential); });
|
||||
return {-potentials[this->oil_pos_],
|
||||
-potentials[this->gas_pos_],
|
||||
-potentials[this->water_pos_],
|
||||
|
||||
@@ -122,9 +122,8 @@ void Opm::ParallelPAvgDynamicSourceData<Scalar>::defineCommunication()
|
||||
{
|
||||
// 1) Determine origins/owning ranks for all source terms.
|
||||
auto ixVec = std::vector<std::size_t>(this->locations_.size());
|
||||
std::transform(this->locations_.begin(), this->locations_.end(),
|
||||
ixVec.begin(),
|
||||
[](const auto& location) { return location.ix; });
|
||||
std::ranges::transform(this->locations_, ixVec.begin(),
|
||||
[](const auto& location) { return location.ix; });
|
||||
|
||||
constexpr auto numItems = ParallelPAvgDynamicSourceData<Scalar>::numSpanItems();
|
||||
|
||||
@@ -136,12 +135,9 @@ void Opm::ParallelPAvgDynamicSourceData<Scalar>::defineCommunication()
|
||||
// basic elements from each rank. There are 'numItems' basic data
|
||||
// elements for each source term.
|
||||
this->startPointers_.resize(allIxStart.size());
|
||||
std::transform(allIxStart.begin(), allIxStart.end(),
|
||||
this->startPointers_.begin(),
|
||||
[](const int start)
|
||||
{
|
||||
return numItems * start;
|
||||
});
|
||||
std::ranges::transform(allIxStart, this->startPointers_.begin(),
|
||||
[](const int start)
|
||||
{ return numItems * start; });
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -147,11 +147,9 @@ getLocalIndex(const std::vector<std::size_t>& globalIndex) const
|
||||
{
|
||||
auto localIdx = std::vector<int>(globalIndex.size());
|
||||
|
||||
std::transform(globalIndex.begin(), globalIndex.end(), localIdx.begin(),
|
||||
[this](const std::size_t globIx)
|
||||
{
|
||||
return this->localIdx_(globIx);
|
||||
});
|
||||
std::ranges::transform(globalIndex, localIdx.begin(),
|
||||
[this](const std::size_t globIx)
|
||||
{ return this->localIdx_(globIx); });
|
||||
|
||||
return localIdx;
|
||||
}
|
||||
|
||||
@@ -112,11 +112,11 @@ GlobalPerfContainerFactory(const IndexSet& local_indices,
|
||||
std::sort(global_pairs.begin(), global_pairs.end(),
|
||||
[](const Pair& p1, const Pair& p2){ return p1.first < p2.first; } );
|
||||
map_received_.resize(global_pairs.size());
|
||||
std::transform(global_pairs.begin(), global_pairs.end(), map_received_.begin(),
|
||||
[](const Pair& pair){ return pair.second; });
|
||||
std::ranges::transform(global_pairs, map_received_.begin(),
|
||||
[](const Pair& pair){ return pair.second; });
|
||||
perf_ecl_index_.resize(global_pairs.size());
|
||||
std::transform(global_pairs.begin(), global_pairs.end(), perf_ecl_index_.begin(),
|
||||
[](const Pair& pair){ return pair.first; });
|
||||
std::ranges::transform(global_pairs, perf_ecl_index_.begin(),
|
||||
[](const Pair& pair){ return pair.first; });
|
||||
num_global_perfs_ = global_pairs.size();
|
||||
}
|
||||
else
|
||||
@@ -351,8 +351,8 @@ void CommunicateAboveBelow<Scalar>::partialSumPerfValues(RAIterator begin, RAIte
|
||||
std::sort(global_pairs.begin(), global_pairs.end(),
|
||||
[](const Pair& p1, const Pair& p2){ return p1.first < p2.first; } );
|
||||
std::vector<Value> sums(global_pairs.size());
|
||||
std::transform(global_pairs.begin(), global_pairs.end(), sums.begin(),
|
||||
[](const Pair& p) { return p.second; });
|
||||
std::ranges::transform(global_pairs, sums.begin(),
|
||||
[](const Pair& p) { return p.second; });
|
||||
std::partial_sum(sums.begin(), sums.end(),sums.begin());
|
||||
// assign the values (both ranges are sorted by the ecl index)
|
||||
auto global_pair = global_pairs.begin();
|
||||
|
||||
@@ -88,8 +88,8 @@ sumRates(std::unordered_map<RegionId,Attributes>& attributes_hpv,
|
||||
assert(ra.pv > 0.);
|
||||
}
|
||||
const Scalar pv_sum = ra.pv;
|
||||
std::transform(ra.data.begin(), ra.data.end(), ra.data.begin(),
|
||||
[pv_sum](const auto d) { return d / pv_sum; });
|
||||
std::ranges::transform(ra.data, ra.data.begin(),
|
||||
[pv_sum](const auto d) { return d / pv_sum; });
|
||||
ra.pv = pv_sum;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,12 +38,9 @@ std::vector<int> make_segment_number(const Opm::WellSegments& segments)
|
||||
std::vector<int> segment_number;
|
||||
segment_number.reserve(segments.size());
|
||||
|
||||
std::transform(segments.begin(), segments.end(),
|
||||
std::back_inserter(segment_number),
|
||||
[](const Opm::Segment& segment)
|
||||
{
|
||||
return segment.segmentNumber();
|
||||
});
|
||||
std::ranges::transform(segments, std::back_inserter(segment_number),
|
||||
[](const Opm::Segment& segment)
|
||||
{ return segment.segmentNumber(); });
|
||||
|
||||
return segment_number;
|
||||
}
|
||||
@@ -116,10 +113,8 @@ void SegmentState<Scalar>::scale_pressure(const Scalar bhp)
|
||||
|
||||
const auto pressure_change = bhp - this->pressure[0];
|
||||
|
||||
std::transform(this->pressure.begin(),
|
||||
this->pressure.end(),
|
||||
this->pressure.begin(),
|
||||
[pressure_change] (const Scalar& p) { return p + pressure_change;});
|
||||
std::ranges::transform(this->pressure, this->pressure.begin(),
|
||||
[pressure_change] (const Scalar& p) { return p + pressure_change; });
|
||||
}
|
||||
|
||||
template<class Scalar>
|
||||
|
||||
@@ -364,16 +364,14 @@ update_type_and_targets(const Well& ecl_well, const SummaryState& st)
|
||||
if (switchedToProducer) {
|
||||
this->production_cmode = ecl_well.productionControls(st).cmode;
|
||||
// clear injection rates (those are positive)
|
||||
std::transform(this->surface_rates.begin(), this->surface_rates.end(),
|
||||
this->surface_rates.begin(),
|
||||
[](const Scalar& val){ return std::min(Scalar(), val);});
|
||||
std::ranges::transform(this->surface_rates, this->surface_rates.begin(),
|
||||
[](const Scalar& val){ return std::min(Scalar(), val);});
|
||||
} else {
|
||||
perf_data.prepareInjectorContainers();
|
||||
this->injection_cmode = ecl_well.injectionControls(st).cmode;
|
||||
// clear production rates (those are negative)
|
||||
std::transform(this->surface_rates.begin(), this->surface_rates.end(),
|
||||
this->surface_rates.begin(),
|
||||
[](const Scalar& val){ return std::max(Scalar(), val);});
|
||||
std::ranges::transform(this->surface_rates, this->surface_rates.begin(),
|
||||
[](const Scalar& val){ return std::max(Scalar(), val);});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1360,8 +1360,8 @@ namespace Opm
|
||||
{
|
||||
const auto& iq = model.intensiveQuantities(cell, /* time_idx = */ 0);
|
||||
|
||||
std::transform(phases.begin(), phases.end(), mob.begin(),
|
||||
[&iq](const int phase) { return iq.mobility(phase).value(); });
|
||||
std::ranges::transform(phases, mob.begin(),
|
||||
[&iq](const int phase) { return iq.mobility(phase).value(); });
|
||||
},
|
||||
|
||||
// densityInCell: Reservoir condition phase densities in
|
||||
@@ -1372,8 +1372,8 @@ namespace Opm
|
||||
{
|
||||
const auto& fs = model.intensiveQuantities(cell, /* time_idx = */ 0).fluidState();
|
||||
|
||||
std::transform(phases.begin(), phases.end(), rho.begin(),
|
||||
[&fs](const int phase) { return fs.density(phase).value(); });
|
||||
std::ranges::transform(phases, rho.begin(),
|
||||
[&fs](const int phase) { return fs.density(phase).value(); });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -2130,9 +2130,10 @@ namespace Opm
|
||||
const auto& connections = this->well_ecl_.getConnections();
|
||||
const auto& connection = connections[perf_ecl_index];
|
||||
if (connection.filterCakeActive()) {
|
||||
std::transform(mob.begin(), mob.end(), mob.begin(),
|
||||
[mult = this->inj_fc_multiplier_[local_perf_index] ](const auto val)
|
||||
{ return val * mult; });
|
||||
std::ranges::transform(mob, mob.begin(),
|
||||
[mult = this->inj_fc_multiplier_[local_perf_index]]
|
||||
(const auto val)
|
||||
{ return val * mult; });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,11 +62,9 @@ void standardConnFactorsExplicitDrainRadius(const Opm::Well& well,
|
||||
const auto& connections = well.getConnections();
|
||||
const auto rdrain = well.getDrainageRadius();
|
||||
|
||||
std::transform(connections.begin(), connections.end(), stdConnFact.begin(),
|
||||
[rdrain](const Opm::Connection& conn)
|
||||
{
|
||||
return conn.CF() * logRescale(conn.r0(), conn.rw(), rdrain, conn.skinFactor());
|
||||
});
|
||||
std::ranges::transform(connections, stdConnFact.begin(),
|
||||
[rdrain](const Opm::Connection& conn)
|
||||
{ return conn.CF() * logRescale(conn.r0(), conn.rw(), rdrain, conn.skinFactor()); });
|
||||
}
|
||||
|
||||
template<class Scalar>
|
||||
@@ -75,11 +73,9 @@ void standardConnFactorsDrainIsEquivalent(const Opm::Well& well,
|
||||
{
|
||||
const auto& connections = well.getConnections();
|
||||
|
||||
std::transform(connections.begin(), connections.end(), stdConnFact.begin(),
|
||||
[](const Opm::Connection& conn)
|
||||
{
|
||||
return conn.CF();
|
||||
});
|
||||
std::ranges::transform(connections, stdConnFact.begin(),
|
||||
[](const Opm::Connection& conn)
|
||||
{ return conn.CF(); });
|
||||
}
|
||||
|
||||
template<class Scalar>
|
||||
|
||||
@@ -112,12 +112,12 @@ verify_norne_oil_pvt_region1(const Opm::EclipseState& eclState,
|
||||
|
||||
{
|
||||
// convert the pressures to SI units (bar to Pascal)
|
||||
std::transform(P.begin(), P.end(), P.begin(),
|
||||
[](const auto value) { return value * Metric::Pressure; });
|
||||
std::ranges::transform(P, P.begin(),
|
||||
[](const auto value) { return value * Metric::Pressure; });
|
||||
|
||||
// convert the gas dissolution factors to SI units
|
||||
std::transform(rs.begin(), rs.end(), rs.begin(),
|
||||
[](const auto value) { return value * Metric::GasDissolutionFactor; });
|
||||
std::ranges::transform(rs, rs.begin(),
|
||||
[](const auto value) { return value * Metric::GasDissolutionFactor; });
|
||||
|
||||
for (unsigned i = 0; i < P.size(); ++i) {
|
||||
double mu;
|
||||
@@ -213,12 +213,12 @@ verify_norne_oil_pvt_region2(const Opm::EclipseState& eclState,
|
||||
|
||||
|
||||
// convert the pressures to SI units (bar to Pascal)
|
||||
std::transform(P.begin(), P.end(), P.begin(),
|
||||
[](const auto value) { return value * Metric::Pressure; });
|
||||
std::ranges::transform(P, P.begin(),
|
||||
[](const auto value) { return value * Metric::Pressure; });
|
||||
|
||||
// convert the gas dissolution factors to SI units
|
||||
std::transform(rs.begin(), rs.end(), rs.begin(),
|
||||
[](const auto value) { return value * Metric::GasDissolutionFactor; });
|
||||
std::ranges::transform(rs, rs.begin(),
|
||||
[](const auto value) { return value * Metric::GasDissolutionFactor; });
|
||||
|
||||
for (unsigned i = 0; i < P.size(); ++i) {
|
||||
double mu;
|
||||
|
||||
@@ -119,10 +119,9 @@ BOOST_AUTO_TEST_CASE(ParallelWellComparison)
|
||||
|
||||
std::vector<Opm::ParallelWellInfo<double>> well_info;
|
||||
|
||||
std::transform(pairs.begin(), pairs.end(),
|
||||
std::back_inserter(well_info),
|
||||
[](const auto& wellinfo) -> Opm::ParallelWellInfo<double>
|
||||
{ return {wellinfo, Opm::Parallel::Communication()}; });
|
||||
std::ranges::transform(pairs, std::back_inserter(well_info),
|
||||
[](const auto& wellinfo) -> Opm::ParallelWellInfo<double>
|
||||
{ return {wellinfo, Opm::Parallel::Communication()}; });
|
||||
|
||||
//well_info.assign(pairs.begin(), pairs.end());
|
||||
|
||||
@@ -177,8 +176,8 @@ BOOST_AUTO_TEST_CASE(CommunicateAboveBelowSelf)
|
||||
{
|
||||
std::vector<int> eclIndex = {0, 1, 2, 3, 7 , 8, 10, 11};
|
||||
std::vector<double> current(eclIndex.size());
|
||||
std::transform(eclIndex.begin(), eclIndex.end(), current.begin(),
|
||||
[](double v){ return 1+10.0*v;});
|
||||
std::ranges::transform(eclIndex, current.begin(),
|
||||
[](double v){ return 1+10.0*v;});
|
||||
commAboveBelow.beginReset();
|
||||
for (std::size_t i = 0; i < current.size(); ++i)
|
||||
{
|
||||
@@ -212,8 +211,8 @@ BOOST_AUTO_TEST_CASE(CommunicateAboveBelowSelf1)
|
||||
{
|
||||
std::vector<int> eclIndex = {0};
|
||||
std::vector<double> current(eclIndex.size());
|
||||
std::transform(eclIndex.begin(), eclIndex.end(), current.begin(),
|
||||
[](double v){ return 1+10.0*v;});
|
||||
std::ranges::transform(eclIndex, current.begin(),
|
||||
[](double v){ return 1+10.0*v;});
|
||||
commAboveBelow.beginReset();
|
||||
for (std::size_t i = 0; i < current.size(); ++i)
|
||||
{
|
||||
@@ -297,8 +296,8 @@ BOOST_AUTO_TEST_CASE(CommunicateAboveBelowParallel)
|
||||
{
|
||||
auto globalEclIndex = createGlobalEclIndex(comm);
|
||||
std::vector<double> globalCurrent(globalEclIndex.size());
|
||||
std::transform(globalEclIndex.begin(), globalEclIndex.end(), globalCurrent.begin(),
|
||||
[](double v){ return 1+10.0*v;});
|
||||
std::ranges::transform(globalEclIndex, globalCurrent.begin(),
|
||||
[](double v) { return 1 + 10.0 * v; });
|
||||
|
||||
auto current = populateCommAbove(commAboveBelow, comm, globalEclIndex, globalCurrent);
|
||||
auto above = commAboveBelow.communicateAbove(-10.0, current.data(), current.size());
|
||||
@@ -355,8 +354,8 @@ BOOST_AUTO_TEST_CASE(PartialSumself)
|
||||
Opm::CommunicateAboveBelow<double> commAboveBelow{ comm };
|
||||
std::vector<int> eclIndex = {0, 1, 2, 3, 7 , 8, 10, 11};
|
||||
std::vector<double> current(eclIndex.size());
|
||||
std::transform(eclIndex.begin(), eclIndex.end(), current.begin(),
|
||||
[](double v){ return 1+10.0*v;});
|
||||
std::ranges::transform(eclIndex, current.begin(),
|
||||
[](double v) { return 1 + 10.0 * v; });
|
||||
commAboveBelow.beginReset();
|
||||
for (std::size_t i = 0; i < current.size(); ++i)
|
||||
{
|
||||
@@ -439,20 +438,17 @@ void testGlobalPerfFactoryParallel(int num_component, bool local_consecutive = f
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(std::begin(globalCurrent), std::end(globalCurrent),
|
||||
std::begin(globalCreated), std::end(globalCreated));
|
||||
|
||||
std::transform(std::begin(globalAdd), std::end(globalAdd),
|
||||
std::begin(globalCreated), std::begin(globalCreated),
|
||||
std::plus<double>());
|
||||
std::ranges::transform(globalAdd, globalCreated,
|
||||
std::begin(globalCreated), std::plus<double>());
|
||||
|
||||
auto globalSol = globalCurrent;
|
||||
std::transform(std::begin(globalAdd), std::end(globalAdd),
|
||||
std::begin(globalSol), std::begin(globalSol),
|
||||
std::plus<double>());
|
||||
std::ranges::transform(globalAdd, globalSol,
|
||||
std::begin(globalSol), std::plus<double>());
|
||||
|
||||
auto localSol = localCurrent;
|
||||
|
||||
std::transform(std::begin(localAdd), std::end(localAdd),
|
||||
std::begin(localSol), std::begin(localSol),
|
||||
std::plus<double>());
|
||||
std::ranges::transform(localAdd, localSol,
|
||||
std::begin(localSol), std::plus<double>());
|
||||
factory.copyGlobalToLocal(globalCreated, localCurrent, num_component);
|
||||
|
||||
for (std::size_t i = 0; i < localCurrent.size() / num_component; ++i)
|
||||
|
||||
@@ -36,7 +36,7 @@ struct Column : public std::vector<std::string>
|
||||
return dval;
|
||||
};
|
||||
|
||||
std::transform(this->cbegin(), this->cend(), std::back_inserter(vec), conv_func);
|
||||
std::ranges::transform(*this, std::back_inserter(vec), conv_func);
|
||||
return vec;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ struct Column : public std::vector<std::string>
|
||||
return ival;
|
||||
};
|
||||
|
||||
std::transform(this->cbegin(), this->cend(), std::back_inserter(vec), conv_func);
|
||||
std::ranges::transform(*this, std::back_inserter(vec), conv_func);
|
||||
return vec;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user