mark parameters/variables as const where appropriate

This commit is contained in:
Arne Morten Kvarving 2025-01-22 17:41:25 +01:00
parent 918b6cc594
commit c114def851
30 changed files with 62 additions and 62 deletions

View File

@ -509,8 +509,8 @@ private:
if (!onUpperBoundary_(pos))
return false;
Scalar xInject[] = { 0.25, 0.75 };
Scalar injectLen[] = { 0.1, 0.1 };
const Scalar xInject[] = { 0.25, 0.75 };
const Scalar injectLen[] = { 0.1, 0.1 };
for (unsigned i = 0; i < sizeof(xInject) / sizeof(Scalar); ++i) {
if (xInject[i] - injectLen[i] / 2 < lambda
&& lambda < xInject[i] + injectLen[i] / 2)

View File

@ -373,7 +373,7 @@ protected:
for (unsigned i = 0; i < phaseIdxs.size(); ++i) {
normVelocityCell_[i] = 0;
}
for (auto& velocityInfo : velocityInfos) {
for (const auto& velocityInfo : velocityInfos) {
for (unsigned i = 0; i < phaseIdxs.size(); ++i) {
if (FluidSystem::phaseIsActive(phaseIdxs[i])) {
normVelocityCell_[phaseIdxs[i]] = max( normVelocityCell_[phaseIdxs[i]],

View File

@ -136,9 +136,9 @@ BlackoilAquiferModel<TypeTag>::endTimeStep()
{
using NumAq = AquiferNumerical<TypeTag>;
for (auto& aquifer : this->aquifers) {
for (const auto& aquifer : this->aquifers) {
aquifer->endTimeStep();
NumAq* num = dynamic_cast<NumAq*>(aquifer.get());
const NumAq* num = dynamic_cast<const NumAq*>(aquifer.get());
if (num) {
this->simulator_.vanguard().grid().comm().barrier();
}

View File

@ -81,7 +81,7 @@ void mergeParallelLogFiles(std::string_view output_dir,
enableLoggingFalloutWarning));
}
void handleExtraConvergenceOutput(SimulatorReport& report,
void handleExtraConvergenceOutput(const SimulatorReport& report,
std::string_view option,
std::string_view optionName,
std::string_view output_dir,

View File

@ -36,7 +36,7 @@ void mergeParallelLogFiles(std::string_view output_dir,
std::string_view deck_filename,
bool enableLoggingFalloutWarning);
void handleExtraConvergenceOutput(SimulatorReport& report,
void handleExtraConvergenceOutput(const SimulatorReport& report,
std::string_view option,
std::string_view optionName,
std::string_view output_dir,

View File

@ -216,7 +216,7 @@ configureThpresft_()
thpresftValues_.resize(numFaults, -1.0);
cartElemFaultIdx_.resize(numCartesianElem, -1);
for (std::size_t faultIdx = 0; faultIdx < faults.size(); ++faultIdx) {
auto& fault = faults.getFault(faultIdx);
const auto& fault = faults.getFault(faultIdx);
thpresftValues_[faultIdx] = thpres.getThresholdPressureFault(faultIdx);
for (const FaultFace& face : fault) {
// "face" is a misnomer because the object describes a set of cell

View File

@ -190,7 +190,7 @@ Opm::InterRegFlowMap::getInterRegFlows() const
auto maps = std::vector<data::InterRegFlowMap>{};
maps.reserve(this->regionMaps_.size());
for (auto& regionMap : this->regionMaps_) {
for (const auto& regionMap : this->regionMaps_) {
maps.push_back(regionMap.getInterRegFlows());
}
@ -203,7 +203,7 @@ Opm::InterRegFlowMap::getLocalMaxRegionID() const
auto maxLocalRegionID = std::vector<std::size_t>{};
maxLocalRegionID.reserve(this->regionMaps_.size());
for (auto& regionMap : this->regionMaps_) {
for (const auto& regionMap : this->regionMaps_) {
maxLocalRegionID.push_back(regionMap.getLocalMaxRegionID());
}

View File

@ -711,7 +711,7 @@ public:
if (!problem.model().linearizer().getFlowsInfo().empty()) {
const auto& flowsInf = problem.model().linearizer().getFlowsInfo();
auto flowsInfos = flowsInf[globalDofIdx];
for (auto& flowsInfo : flowsInfos) {
for (const auto& flowsInfo : flowsInfos) {
if (flowsInfo.faceId >= 0) {
if (!this->flows_[flowsInfo.faceId][gasCompIdx].empty()) {
this->flows_[flowsInfo.faceId][gasCompIdx][globalDofIdx]
@ -750,7 +750,7 @@ public:
if (!problem.model().linearizer().getFloresInfo().empty()) {
const auto& floresInf = problem.model().linearizer().getFloresInfo();
auto floresInfos =floresInf[globalDofIdx];
for (auto& floresInfo : floresInfos) {
for (const auto& floresInfo : floresInfos) {
if (floresInfo.faceId >= 0) {
if (!this->flores_[floresInfo.faceId][gasCompIdx].empty()) {
this->flores_[floresInfo.faceId][gasCompIdx][globalDofIdx]

View File

@ -244,7 +244,7 @@ public:
#ifdef RESERVOIR_COUPLING_ENABLED
// NOTE: The argc and argv will be used when launching a slave process
void init(SimulatorTimer &timer, int argc, char** argv)
void init(const SimulatorTimer& timer, int argc, char** argv)
{
auto slave_mode = Parameters::Get<Parameters::Slave>();
if (slave_mode) {
@ -269,7 +269,7 @@ public:
}
}
#else
void init(SimulatorTimer &timer)
void init(const SimulatorTimer& timer)
{
#endif
simulator_.setEpisodeIndex(-1);

View File

@ -616,7 +616,7 @@ protected:
if (elem.partitionType() != Dune::InteriorEntity)
{
// Dirichlet boundary conditions needed for the parallel matrix
for (auto& tr : tbatch) {
for (const auto& tr : tbatch) {
if (tr.numTracer() != 0) {
(*tr.mat)[I][I][0][0] = 1.;
(*tr.mat)[I][I][1][1] = 1.;

View File

@ -61,7 +61,7 @@ void sortRow(int *colIndices, int *data, int left, int right)
// LUMat->nnzValues[ik] = LUMat->nnzValues[ik] - (pivot * LUMat->nnzValues[jk]) in ilu decomposition
// a = a - (b * c)
template<class Scalar>
void blockMultSub(Scalar* a, Scalar* b, Scalar* c, unsigned int block_size)
void blockMultSub(Scalar* a, const Scalar* b, const Scalar* c, unsigned int block_size)
{
for (unsigned int row = 0; row < block_size; row++) {
for (unsigned int col = 0; col < block_size; col++) {
@ -76,7 +76,8 @@ void blockMultSub(Scalar* a, Scalar* b, Scalar* c, unsigned int block_size)
/*Perform a 3x3 matrix-matrix multiplicationj on two blocks*/
template<class Scalar>
void blockMult(Scalar* mat1, Scalar* mat2, Scalar* resMat, unsigned int block_size)
void blockMult(const Scalar* mat1, const Scalar* mat2,
Scalar* resMat, unsigned int block_size)
{
for (unsigned int row = 0; row < block_size; row++) {
for (unsigned int col = 0; col < block_size; col++) {
@ -90,8 +91,8 @@ void blockMult(Scalar* mat1, Scalar* mat2, Scalar* resMat, unsigned int block_si
}
#define INSTANTIATE_TYPE(T) \
template void blockMultSub(T*, T*, T*, unsigned int); \
template void blockMult(T*, T*, T*, unsigned int);
template void blockMultSub(T*, const T*, const T*, unsigned int); \
template void blockMult(const T*, const T*, T*, unsigned int);
INSTANTIATE_TYPE(double)

View File

@ -111,7 +111,8 @@ void sortRow(int* colIndices, int* data, int left, int right);
/// \param[in] c input block
/// \param[in] block_size size of block
template<class Scalar>
void blockMultSub(Scalar* a, Scalar* b, Scalar* c, unsigned int block_size);
void blockMultSub(Scalar* a, const Scalar* b,
const Scalar* c, unsigned int block_size);
/// Perform a matrix-matrix multiplication on two blocks
/// resMat = mat1 * mat2

View File

@ -61,10 +61,10 @@ bool canBeStarted(const int rowIndex,
* "Iterative methods for Sparse Linear Systems" by Yousef Saad in section 11.6.3
*/
void findLevelScheduling(int* CSRColIndices,
int* CSRRowPointers,
int* CSCRowIndices,
int* CSCColPointers,
void findLevelScheduling(const int* CSRColIndices,
const int* CSRRowPointers,
const int* CSCRowIndices,
const int* CSCColPointers,
int Nb,
int* numColors,
int* toOrder,
@ -129,8 +129,8 @@ void findLevelScheduling(int* CSRColIndices,
}
// based on the scipy package from python, scipy/sparse/sparsetools/csr.h on github
void csrPatternToCsc(int* CSRColIndices,
int* CSRRowPointers,
void csrPatternToCsc(const int* CSRColIndices,
const int* CSRRowPointers,
int* CSCRowIndices,
int* CSCColPointers,
int Nb)

View File

@ -46,10 +46,10 @@ bool canBeStarted(const int rowIndex,
/// \param[out] toOrder the reorder pattern that was found, which lists for each index in the original order, to which index in the new order it should be moved
/// \param[out] fromOrder the reorder pattern that was found, which lists for each index in the new order, from which index in the original order it was moved
/// \param[out] rowsPerColor for each color, an array of all rowIndices in that color, this function uses emplace_back() to fill
void findLevelScheduling(int* CSRColIndices,
int* CSRRowPointers,
int* CSCRowIndices,
int* CSCColPointers,
void findLevelScheduling(const int* CSRColIndices,
const int* CSRRowPointers,
const int* CSCRowIndices,
const int* CSCColPointers,
int Nb,
int* numColors,
int* toOrder,
@ -64,8 +64,8 @@ void findLevelScheduling(int* CSRColIndices,
/// \param[inout] CSCRowIndices row indices of the result CSC representation of the pattern
/// \param[inout] CSCColPointers column pointers of the result CSC representation of the pattern
/// \param[in] Nb number of blockrows in the matrix
void csrPatternToCsc(int* CSRColIndices,
int* CSRRowPointers,
void csrPatternToCsc(const int* CSRColIndices,
const int* CSRRowPointers,
int* CSCRowIndices,
int* CSCColPointers,
int Nb);

View File

@ -163,7 +163,7 @@ void amgclSolverBackend<Scalar,block_size>::initialize(int Nb_, int nnzbs)
template<class Scalar, unsigned int block_size>
void amgclSolverBackend<Scalar,block_size>::
convert_sparsity_pattern(int* rows, int* cols)
convert_sparsity_pattern(const int* rows, const int* cols)
{
Timer t;
const unsigned int bs = block_size;
@ -193,7 +193,7 @@ convert_sparsity_pattern(int* rows, int* cols)
template<class Scalar, unsigned int block_size>
void amgclSolverBackend<Scalar,block_size>::
convert_data(Scalar* vals, int* rows)
convert_data(const Scalar* vals, const int* rows)
{
Timer t;
const unsigned int bs = block_size;

View File

@ -105,12 +105,12 @@ private:
/// Convert the BCSR sparsity pattern to a CSR one
/// \param[in] rows array of rowPointers, contains N/dim+1 values
/// \param[in] cols array of columnIndices, contains nnz values
void convert_sparsity_pattern(int *rows, int *cols);
void convert_sparsity_pattern(const int *rows, const int *cols);
/// Convert the BCSR nonzero data to a CSR format
/// \param[in] vals array of nonzeroes, each block is stored row-wise and contiguous, contains nnz values
/// \param[in] rows array of rowPointers, contains N/dim+1 values
void convert_data(Scalar* vals, int* rows);
void convert_data(const Scalar* vals, const int* rows);
/// Solve linear system
/// \param[in] b pointer to b vector

View File

@ -194,7 +194,7 @@ create_preconditioner(BlockedMatrix<Scalar>* mat, BlockedMatrix<Scalar>* jacMat)
{
const unsigned int bs = block_size;
auto *matToDecompose = jacMat ? jacMat : mat;
const auto* matToDecompose = jacMat ? jacMat : mat;
bool use_multithreading = true;
#if HAVE_OPENMP

View File

@ -285,11 +285,11 @@ private:
void buildCommPairIdxs() const
{
auto &ri = this->m_cpuOwnerOverlapCopy.remoteIndices();
const auto& ri = this->m_cpuOwnerOverlapCopy.remoteIndices();
std::vector<int> commpairIndicesCopyOnCPU;
std::vector<int> commpairIndicesOwnerCPU;
for (auto process : ri) {
for (const auto& process : ri) {
m_im[process.first] = std::pair(std::vector<int>(), std::vector<int>());
for (int send = 0; send < 2; ++send) {
auto remoteEnd = send ? process.second.first->end()

View File

@ -16,6 +16,7 @@
#include <dune/common/unused.hh>
#include <dune/common/version.hh>
#include <algorithm>
#include <cstddef>
#include <iostream>
#include <memory>
@ -193,13 +194,8 @@ public:
ParallelInformation pinfo;
std::size_t aggregates = coarsen(renumberer, pinfo, pg, vm,*aggregatesMap_, noAggregates, true);
std::vector<bool>& visited=excluded;
typedef std::vector<bool>::iterator Iterator;
for(Iterator iter= visited.begin(), end=visited.end();
iter != end; ++iter)
*iter=false;
std::fill(excluded.begin(), excluded.end(), false);
matrix_.reset(productBuilder.build(mg, vm,
SequentialInformation(),
*aggregatesMap_,

View File

@ -542,7 +542,7 @@ extern "C" {
if (cells.empty()) { return; }
const auto first = parts[cells.front()];
for (auto& cell : cells) {
for (const auto& cell : cells) {
parts[cell] = first;
}
}

View File

@ -259,7 +259,7 @@ template<class Scalar> class WellContributions;
// add source from wells to the reservoir matrix
void addReservoirSourceTerms(GlobalEqVector& residual,
std::vector<typename SparseMatrixAdapter::MatrixBlock*>& diagMatAddress) const;
const std::vector<typename SparseMatrixAdapter::MatrixBlock*>& diagMatAddress) const;
// called at the beginning of a report step
void beginReportStep(const int time_step);

View File

@ -1906,7 +1906,7 @@ getMaxWellConnections() const
const auto possibleFutureConnectionSetIt = possibleFutureConnections.find(well.name());
if (possibleFutureConnectionSetIt != possibleFutureConnections.end()) {
for (auto& global_index : possibleFutureConnectionSetIt->second) {
for (const auto& global_index : possibleFutureConnectionSetIt->second) {
int compressed_idx = compressedIndexForInterior(global_index);
if (compressed_idx >= 0) { // Ignore connections in inactive/remote cells.
compressed_well_perforations.push_back(compressed_idx);

View File

@ -433,7 +433,7 @@ namespace Opm {
// have proper multi-phase rates proportional to rates at bhp zero.
// This is done only for producers, as injectors will only have a single
// nonzero phase anyway.
for (auto& well : well_container_) {
for (const auto& well : well_container_) {
const bool zero_target = well->stoppedOrZeroRateTarget(simulator_, this->wellState(), local_deferredLogger);
if (well->isProducer() && !zero_target) {
well->updateWellStateRates(simulator_, this->wellState(), local_deferredLogger);
@ -441,7 +441,7 @@ namespace Opm {
}
}
for (auto& well : well_container_) {
for (const auto& well : well_container_) {
if (well->isVFPActive(local_deferredLogger)){
well->setPrevSurfaceRates(this->wellState(), this->prevWellState());
}
@ -478,7 +478,7 @@ namespace Opm {
auto exc_type = ExceptionType::NONE;
// update gpmaint targets
if (this->schedule_[reportStepIdx].has_gpmaint()) {
for (auto& calculator : regionalAveragePressureCalculator_) {
for (const auto& calculator : regionalAveragePressureCalculator_) {
calculator.second->template defineState<ElementContext>(simulator_);
}
const double dt = simulator_.timeStepSize();
@ -1641,7 +1641,7 @@ namespace Opm {
template <typename TypeTag>
void BlackoilWellModel<TypeTag>::
addReservoirSourceTerms(GlobalEqVector& residual,
std::vector<typename SparseMatrixAdapter::MatrixBlock*>& diagMatAddress) const
const std::vector<typename SparseMatrixAdapter::MatrixBlock*>& diagMatAddress) const
{
// NB this loop may write multiple times to the same element
// if a cell is perforated by more than one well, so it should
@ -2022,7 +2022,7 @@ namespace Opm {
// if a well or group change control it affects all wells that are under the same group
for (const auto& well : well_container_) {
// We only want to update wells under group-control here
auto& ws = this->wellState().well(well->indexOfWell());
const auto& ws = this->wellState().well(well->indexOfWell());
if (ws.production_cmode == Well::ProducerCMode::GRUP ||
ws.injection_cmode == Well::InjectorCMode::GRUP)
{

View File

@ -1590,7 +1590,7 @@ template<class Scalar>
void GasLiftSingleWellGeneric<Scalar>::
updateWellStateAlqFixedValue_(const GasLiftWell& well)
{
auto& max_alq_optional = well.max_rate();
const auto& max_alq_optional = well.max_rate();
if (max_alq_optional) {
// According to WLIFTOPT, item 3:
// If item 2 is NO, then item 3 is regarded as the fixed

View File

@ -215,7 +215,7 @@ void
GasLiftSingleWell<TypeTag>::
setAlqMaxRate_(const GasLiftWell& well)
{
auto& max_alq_optional = well.max_rate();
const auto& max_alq_optional = well.max_rate();
if (max_alq_optional) {
// NOTE: To prevent extrapolation of the VFP tables, any value
// entered here must not exceed the largest ALQ value in the well's VFP table.

View File

@ -474,7 +474,7 @@ recalculateGradientAndUpdateData_(GradPairItr& grad_itr,
// only applies to wells in the well_state_map (i.e. wells on this rank)
// the grads and other grads are synchronized later
if(this->stage1_wells_.count(name) > 0) {
GasLiftSingleWell &gs_well = *(this->stage1_wells_.at(name).get());
const GasLiftSingleWell& gs_well = *(this->stage1_wells_.at(name).get());
{
auto grad = calcIncOrDecGrad_(name, gs_well, gr_name_dont_limit, increase);
if (grad) {

View File

@ -121,7 +121,7 @@ public:
// Create a function that calls some function
// for all the individual data items to simplify
// the further code.
auto iterateContainer = [](auto& container, auto& func) {
auto iterateContainer = [](auto& container, const auto& func) {
for (auto& x : container) {
func(x.second);
}

View File

@ -81,7 +81,7 @@ public:
// Now add the cells of the possible future connections
const auto possibleFutureConnectionSetIt = possibleFutureConnections.find(well.name());
if (possibleFutureConnectionSetIt != possibleFutureConnections.end()) {
for (auto& global_index : possibleFutureConnectionSetIt->second) {
for (const auto& global_index : possibleFutureConnectionSetIt->second) {
int compressed_idx = model_.compressedIndexForInterior(global_index);
if (compressed_idx >= 0) { // Ignore connections in inactive/remote cells.
wellCells.push_back(compressed_idx);
@ -126,7 +126,7 @@ public:
}
}
void postSolveDomain(GlobalEqVector& deltaX, const Domain& domain)
void postSolveDomain(const GlobalEqVector& deltaX, const Domain& domain)
{
model_.recoverWellSolutionAndUpdateWellStateDomain(deltaX, domain);
}

View File

@ -476,7 +476,7 @@ namespace Opm
deferred_logger.info(msg);
// also reopen completions
for (auto& completion : this->well_ecl_.getCompletions()) {
for (const auto& completion : this->well_ecl_.getCompletions()) {
if (!welltest_state_temp.completion_is_closed(this->name(), completion.first))
well_test_state.open_completion(this->name(), completion.first);
}

View File

@ -116,7 +116,8 @@ createBridge(const boost::property_tree::ptree& prm, std::unique_ptr<Opm::GpuBri
template <int bz>
Dune::BlockVector<Dune::FieldVector<double, bz>>
testOpenclSolver(Opm::GpuBridge<Matrix<bz>, Vector<bz>, bz>& bridge, Matrix<bz>& matrix, Vector<bz>& rhs)
testOpenclSolver(Opm::GpuBridge<Matrix<bz>, Vector<bz>, bz>& bridge,
const Matrix<bz>& matrix, Vector<bz>& rhs)
{
Dune::InverseOperatorResult result;
Vector<bz> x(rhs.size());
@ -131,7 +132,8 @@ testOpenclSolver(Opm::GpuBridge<Matrix<bz>, Vector<bz>, bz>& bridge, Matrix<bz>&
template <int bz>
Dune::BlockVector<Dune::FieldVector<double, bz>>
testOpenclSolverJacobi(Opm::GpuBridge<Matrix<bz>, Vector<bz>, bz>& bridge, Matrix<bz>& matrix, Vector<bz>& rhs)
testOpenclSolverJacobi(Opm::GpuBridge<Matrix<bz>, Vector<bz>, bz>& bridge,
const Matrix<bz>& matrix, Vector<bz>& rhs)
{
Dune::InverseOperatorResult result;
Vector<bz> x(rhs.size());