replace std::fill with std::ranges::fill where appropriate

the c++-20 constrained algorithm is safer and code is more readable
This commit is contained in:
Arne Morten Kvarving committed 2026-02-23 10:23:45 +01:00
1 parent 4b2a574727
commit f00ab30268
21 files changed
+56 -61

No files matched your search

+1 -1
View File
@@ -553,7 +553,7 @@ prepareStoringSolutionUpdate()
solUpd_[globalElemIdx] = simulator_.model().solution(/*timeIdx=*/0)[globalElemIdx];
// Ensure each element is zero
std::fill(solUpd_[globalElemIdx].begin(), solUpd_[globalElemIdx].end(), 0.0);
std::ranges::fill(solUpd_[globalElemIdx], 0.0);
}
}
+1 -1
View File
@@ -82,7 +82,7 @@ bool RSTConv::hasConv() const
void RSTConv::prepareConv()
{
std::fill(conv_new_.begin(), conv_new_.end(), 1);
std::ranges::fill(conv_new_, 1);
}
void RSTConv::updateNewton(const std::vector<int>& convNewt)
+1 -1
View File
@@ -110,7 +110,7 @@ value(std::string_view rset, const Phase& p, const Region& r) const
void Opm::RegionPhasePoreVolAverage::prepareAccumulation()
{
std::fill(this->x_.begin(), this->x_.end(), 0.0);
std::ranges::fill(this->x_, 0.0);
}
void Opm::RegionPhasePoreVolAverage::
+1 -1
View File
@@ -150,7 +150,7 @@ colorVerticesWelshPowell(const Graph& graph)
// Overwrite degree with color
auto& colors = degrees;
std::fill(colors.begin(), colors.end(), -1);
std::ranges::fill(colors, -1);
int color = 0;
std::vector<std::size_t> verticesPerColor;
+1 -1
View File
@@ -222,7 +222,7 @@ void milun_decomposition(const M& A, int n, MILU_VARIANT milu, M& ILU,
{
auto& newRow = ILU[ordering[iter.index()]];
// reset stored generation
std::fill(newRow.begin(), newRow.end(), 0);
std::ranges::fill(newRow, 0);
// copy row.
for(auto col = iter->begin(), cend = iter->end(); col != cend; ++col)
@@ -275,7 +275,7 @@ analyzeAggregateMaps()
typename DuneAmg::AggregatesMap *map = *mapIter;
Rmatrices.emplace_back(level_sizes[level+1], level_sizes[level], level_sizes[level]);
std::fill(Rmatrices.back().nnzValues.begin(), Rmatrices.back().nnzValues.end(), 1.0);
std::ranges::fill(Rmatrices.back().nnzValues, 1.0);
// get indices for each row of P and R
std::vector<std::vector<unsigned> > indicesR(level_sizes[level+1]);
@@ -84,8 +84,8 @@ void MultisegmentWellContribution<Scalar>::apply(Scalar* h_x, Scalar* h_y)
{
OPM_TIMEBLOCK(apply);
// reset z1 and z2
std::fill(z1.begin(), z1.end(), 0.0);
std::fill(z2.begin(), z2.end(), 0.0);
std::ranges::fill(z1, 0.0);
std::ranges::fill(z2, 0.0);
// z1 = B * x
for (unsigned int row = 0; row < Mb; ++row) {
@@ -312,7 +312,7 @@ solve_system(Scalar* b, GpuResult& res)
print(solve);
// reset x vector
std::fill(x.begin(), x.end(), 0.0);
std::ranges::fill(x, 0.0);
std::vector<Scalar> b_(b, b + N);
@@ -337,7 +337,7 @@ solve_system(Scalar* b, GpuResult& res)
print(solve);
// reset x vector
std::fill(x.begin(), x.end(), 0.0);
std::ranges::fill(x, 0.0);
// create blocked vectors
auto b_ptr = reinterpret_cast<dvec_type*>(b);
@@ -293,9 +293,7 @@ buildStructure(ViolationSample& violation)
violation.checkValues.resize(this->startCheckValues_.back());
if constexpr (std::numeric_limits<Scalar>::has_quiet_NaN) {
std::fill(violation.checkValues.begin(),
violation.checkValues.end(),
std::numeric_limits<Scalar>::quiet_NaN());
std::ranges::fill(violation.checkValues, std::numeric_limits<Scalar>::quiet_NaN());
}
}
@@ -910,11 +910,11 @@ void
MultisegmentWellSegments<FluidSystem, Indices>::
PhaseCalcResult::clear()
{
std::fill(b.begin(), b.end(), 0.0);
std::fill(mix.begin(), mix.end(), 0.0);
std::fill(mix_s.begin(), mix_s.end(), 0.0);
std::fill(phase_viscosities.begin(), phase_viscosities.end(), 0.0);
std::fill(phase_densities.begin(), phase_densities.end(), 0.0);
std::ranges::fill(b, 0.0);
std::ranges::fill(mix, 0.0);
std::ranges::fill(mix_s, 0.0);
std::ranges::fill(phase_viscosities, 0.0);
std::ranges::fill(phase_densities, 0.0);
vol_ratio = 0.0;
}
@@ -1305,8 +1305,8 @@ namespace Opm
// TODO: not handling solvent related here for now
// initialize all the values to be zero to begin with
std::fill(this->ipr_a_.begin(), this->ipr_a_.end(), 0.);
std::fill(this->ipr_b_.begin(), this->ipr_b_.end(), 0.);
std::ranges::fill(this->ipr_a_, 0.0);
std::ranges::fill(this->ipr_b_, 0.0);
const int nseg = this->numberOfSegments();
std::vector<Scalar> seg_dp(nseg, 0.0);
@@ -1434,8 +1434,8 @@ namespace Opm
*/
}
std::fill(ws.implicit_ipr_a.begin(), ws.implicit_ipr_a.end(), 0.);
std::fill(ws.implicit_ipr_b.begin(), ws.implicit_ipr_b.end(), 0.);
std::ranges::fill(ws.implicit_ipr_a, 0.0);
std::ranges::fill(ws.implicit_ipr_b, 0.0);
//WellState well_state_copy = well_state;
auto inj_controls = Well::InjectionControls(0);
auto prod_controls = Well::ProductionControls(0);
+7 -7
View File
@@ -98,12 +98,12 @@ void SingleWellState<Scalar, IndexTraits>::shut()
this->bhp = 0;
this->thp = 0;
this->status = Well::Status::SHUT;
std::fill(this->surface_rates.begin(), this->surface_rates.end(), 0);
std::fill(this->prev_surface_rates.begin(), this->prev_surface_rates.end(), 0);
std::fill(this->reservoir_rates.begin(), this->reservoir_rates.end(), 0);
std::fill(this->productivity_index.begin(), this->productivity_index.end(), 0);
std::fill(this->implicit_ipr_a.begin(), this->implicit_ipr_a.end(), 0);
std::fill(this->implicit_ipr_b.begin(), this->implicit_ipr_b.end(), 0);
std::ranges::fill(this->surface_rates, 0);
std::ranges::fill(this->prev_surface_rates, 0);
std::ranges::fill(this->reservoir_rates, 0);
std::ranges::fill(this->productivity_index, 0);
std::ranges::fill(this->implicit_ipr_a, 0);
std::ranges::fill(this->implicit_ipr_b, 0);
auto& connpi = this->perf_data.prod_index;
connpi.assign(connpi.size(), 0);
@@ -261,7 +261,7 @@ update_producer_targets(const Well& ecl_well, const SummaryState& st)
return;
}
std::fill(this->surface_rates.begin(), this->surface_rates.end(), 0.0);
std::ranges::fill(this->surface_rates, 0.0);
switch (prod_controls.cmode) {
case Well::ProducerCMode::ORAT:
assert(pu.phaseIsActive(oilPhaseIdx));
@@ -405,7 +405,7 @@ initialiseConnectionMixture(const int num_quantities,
componentMixture[num_quantities - 1] = Scalar{1};
}
else {
std::fill(componentMixture.begin(), componentMixture.end(), Scalar{0});
std::ranges::fill(componentMixture, Scalar{0});
// No flow => use fractions defined at well level for componentMixture.
if ( (this->well_.isInjector() || (perf == 0)) && preferredPhaseIdx.has_value()) {
+4 -4
View File
@@ -835,8 +835,8 @@ namespace Opm
// TODO: not handling solvent related here for now
// initialize all the values to be zero to begin with
std::fill(this->ipr_a_.begin(), this->ipr_a_.end(), 0.);
std::fill(this->ipr_b_.begin(), this->ipr_b_.end(), 0.);
std::ranges::fill(this->ipr_a_, 0.0);
std::ranges::fill(this->ipr_b_, 0.0);
for (int perf = 0; perf < this->number_of_local_perforations_; ++perf) {
std::vector<Scalar> mob(this->num_conservation_quantities_, 0.0);
@@ -955,8 +955,8 @@ namespace Opm
*/
}
std::fill(ws.implicit_ipr_a.begin(), ws.implicit_ipr_a.end(), 0.);
std::fill(ws.implicit_ipr_b.begin(), ws.implicit_ipr_b.end(), 0.);
std::ranges::fill(ws.implicit_ipr_a, 0.0);
std::ranges::fill(ws.implicit_ipr_b, 0.0);
auto inj_controls = Well::InjectionControls(0);
auto prod_controls = Well::ProductionControls(0);
@@ -244,8 +244,9 @@ protected:
Well::InjectionControls& inj_controls,
Well::ProductionControls& prod_controls) const;
void resetDampening() {
std::fill(this->inj_multiplier_damp_factor_.begin(), this->inj_multiplier_damp_factor_.end(), 1.0);
void resetDampening()
{
std::ranges::fill(this->inj_multiplier_damp_factor_, 1.0);
}
// definition of the struct OperabilityStatus