From 1f7532a4b61d6b89076616a49115aa89a1357e79 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Wed, 29 Jul 2026 08:08:33 +0200 Subject: [PATCH 1/7] avoid implicit int/bool conversions --- opm/simulators/flow/Banners.cpp | 2 +- opm/simulators/flow/DamarisWriter.cpp | 2 +- opm/simulators/flow/FlowGenericVanguard.cpp | 6 +++--- opm/simulators/flow/FlowUtils.cpp | 6 +++--- opm/simulators/flow/GenericCpGridVanguard.cpp | 10 +++++++--- opm/simulators/flow/GenericOutputBlackoilModule.cpp | 12 ++++++------ opm/simulators/flow/LogOutputHelper.cpp | 2 +- opm/simulators/flow/Main.cpp | 2 +- 8 files changed, 23 insertions(+), 19 deletions(-) diff --git a/opm/simulators/flow/Banners.cpp b/opm/simulators/flow/Banners.cpp index b164e47eb7..9f81cde585 100644 --- a/opm/simulators/flow/Banners.cpp +++ b/opm/simulators/flow/Banners.cpp @@ -82,7 +82,7 @@ void printPRTHeader(const int nprocs, const int nthreads, ss << ", " << arch.version << " )\n"; ss << "Build time = " << compileTimestamp << "\n"; } - if (user) { + if (user != nullptr) { ss << "User = " << user << std::endl; } ss << "Simulation started on " << tmstr << " hrs\n"; diff --git a/opm/simulators/flow/DamarisWriter.cpp b/opm/simulators/flow/DamarisWriter.cpp index f8fcf770dc..d20276ce7e 100644 --- a/opm/simulators/flow/DamarisWriter.cpp +++ b/opm/simulators/flow/DamarisWriter.cpp @@ -117,7 +117,7 @@ void handleError(const int dam_err, Parallel::Communication comm, const std::string& message) { // Find if some rank has encountered an error. - const int isOk = (dam_err == DAMARIS_OK); + const int isOk = dam_err == DAMARIS_OK ? 1 : 0; const bool error = (comm.sum(isOk) != comm.size()); if (error) { diff --git a/opm/simulators/flow/FlowGenericVanguard.cpp b/opm/simulators/flow/FlowGenericVanguard.cpp index 3b65d7e897..a013cb0726 100644 --- a/opm/simulators/flow/FlowGenericVanguard.cpp +++ b/opm/simulators/flow/FlowGenericVanguard.cpp @@ -370,7 +370,7 @@ void FlowGenericVanguard::init() // Check whether allowing distribute wells makes sense if (enableDistributedWells() ) { - int hasMsWell = false; + int hasMsWell = 0; const auto& comm = FlowGenericVanguard::comm(); if (useMultisegmentWell_) @@ -380,13 +380,13 @@ void FlowGenericVanguard::init() const auto& wells = this->schedule().getWellsatEnd(); hasMsWell = std::ranges::any_of(wells, [](const auto& well) - { return well.isMultiSegment(); }); + { return well.isMultiSegment(); }) ? 1 : 0; } } hasMsWell = comm.max(hasMsWell); - if (hasMsWell) + if (hasMsWell != 0) { if (comm.rank() == 0) { diff --git a/opm/simulators/flow/FlowUtils.cpp b/opm/simulators/flow/FlowUtils.cpp index 19a795e21d..2a8a4c289b 100644 --- a/opm/simulators/flow/FlowUtils.cpp +++ b/opm/simulators/flow/FlowUtils.cpp @@ -136,13 +136,13 @@ void checkAllMPIProcesses() OpmLog::error(fmt::format("Error: Could not test for MPI message (error code : {})", error)); MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); } - if (flag) + if (flag != 0) { --msgs; } } } - if (msgs) { + if (msgs != 0) { // seems like some processes are stuck. Abort just to be save MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); } @@ -166,7 +166,7 @@ void checkAllMPIProcesses() OpmLog::error(fmt::format("Error: Could not test for MPI message (error code : {})", error)); MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); } - if (flag) + if (flag != 0) { completed = true; } diff --git a/opm/simulators/flow/GenericCpGridVanguard.cpp b/opm/simulators/flow/GenericCpGridVanguard.cpp index 6efc2aa226..65f336e087 100644 --- a/opm/simulators/flow/GenericCpGridVanguard.cpp +++ b/opm/simulators/flow/GenericCpGridVanguard.cpp @@ -255,7 +255,9 @@ doLoadBalance_(const Dune::EdgeWeightMethod edgeWeightsMethod, break; } } - if (!well_on_rank[well_idx]) parallelWells.emplace_back(well_name, false); + if (well_on_rank[well_idx] == 0) { + parallelWells.emplace_back(well_name, false); + } ++well_idx; } @@ -269,8 +271,10 @@ doLoadBalance_(const Dune::EdgeWeightMethod edgeWeightsMethod, well_idx = 0; for (const auto& well_name : inactive_well_names) { std::string msg = fmt::format("Well {} is inactive, with perforations on ranks: ", well_name); - for (int i=0; ienableNonWettingHysteresis() && FluidSystem::phaseIsActive(oilPhaseIdx) && FluidSystem::phaseIsActive(waterPhaseIdx)}, - Entry{&sgmax_, "", effectiveHysteresisConfig && + Entry{&sgmax_, "", effectiveHysteresisConfig != nullptr && effectiveHysteresisConfig->enableNonWettingHysteresis() && FluidSystem::phaseIsActive(oilPhaseIdx) && FluidSystem::phaseIsActive(gasPhaseIdx)}, - Entry{&swMax_, "", effectiveHysteresisConfig && + Entry{&swMax_, "", effectiveHysteresisConfig != nullptr && effectiveHysteresisConfig->enableWettingHysteresis() && FluidSystem::phaseIsActive(oilPhaseIdx) && FluidSystem::phaseIsActive(waterPhaseIdx)}, - Entry{&shmax_, "", effectiveHysteresisConfig && + Entry{&shmax_, "", effectiveHysteresisConfig != nullptr && effectiveHysteresisConfig->enableWettingHysteresis() && FluidSystem::phaseIsActive(oilPhaseIdx) && FluidSystem::phaseIsActive(gasPhaseIdx)}, - Entry{&swmin_, "", effectiveHysteresisConfig && + Entry{&swmin_, "", effectiveHysteresisConfig != nullptr && effectiveHysteresisConfig->enablePCHysteresis() && FluidSystem::phaseIsActive(oilPhaseIdx) && FluidSystem::phaseIsActive(waterPhaseIdx)}, - Entry{&somin_, "", effectiveHysteresisConfig && + Entry{&somin_, "", effectiveHysteresisConfig != nullptr && effectiveHysteresisConfig->enablePCHysteresis() && FluidSystem::phaseIsActive(oilPhaseIdx) && FluidSystem::phaseIsActive(gasPhaseIdx)}, diff --git a/opm/simulators/flow/LogOutputHelper.cpp b/opm/simulators/flow/LogOutputHelper.cpp index 7ced7ae3d7..abc2a3bf3b 100644 --- a/opm/simulators/flow/LogOutputHelper.cpp +++ b/opm/simulators/flow/LogOutputHelper.cpp @@ -1438,7 +1438,7 @@ outputRegionFluidInPlace_(std::unordered_map oip, } ss << topEntry("PAV", pav, UnitSystem::measure::pressure) << topEntry("PORV", cip[Inplace::Phase::PoreVolume], UnitSystem::measure::volume); - if (!reg) { + if (reg == 0) { ss << topLabel("Pressure is weighted by hydrocarbon pore volume") << topLabel("Pore volumes are taken at reference conditions"); } diff --git a/opm/simulators/flow/Main.cpp b/opm/simulators/flow/Main.cpp index 275596256b..3d858f6067 100644 --- a/opm/simulators/flow/Main.cpp +++ b/opm/simulators/flow/Main.cpp @@ -234,7 +234,7 @@ void Main::initMPI() maybeRedirectReservoirCouplingSlaveOutput_(); if (test_split_comm_ && FlowGenericVanguard::comm().size() > 1) { int world_rank = FlowGenericVanguard::comm().rank(); - int color = (world_rank == 0); + const int color = world_rank == 0 ? 1 : 0; MPI_Comm new_comm; MPI_Comm_split(FlowGenericVanguard::comm(), color, world_rank, &new_comm); isSimulationRank_ = (world_rank > 0); From f6280f76db38cbc822e8905ab95657c4c0550ba4 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Wed, 29 Jul 2026 08:10:08 +0200 Subject: [PATCH 2/7] avoid implicit signed/unsigned conversions --- flowexperimental/comp/flow_comp.cpp | 2 +- opm/simulators/flow/Banners.cpp | 9 +++-- opm/simulators/flow/Banners.hpp | 3 +- opm/simulators/flow/DamarisWriter.cpp | 22 +++++++---- .../flow/ExtraConvergenceOutputThread.cpp | 39 +++++++++---------- opm/simulators/flow/GenericCpGridVanguard.cpp | 2 +- .../flow/GenericOutputBlackoilModule.cpp | 2 +- opm/simulators/flow/RSTConv.cpp | 8 ++-- opm/simulators/flow/RegionPhasePVAverage.cpp | 6 +-- opm/simulators/flow/RegionPhasePVAverage.hpp | 2 +- .../flow/SimulatorConvergenceOutput.cpp | 4 +- opm/simulators/flow/SimulatorSerializer.cpp | 4 +- opm/simulators/flow/partitionCells.cpp | 2 +- 13 files changed, 59 insertions(+), 46 deletions(-) diff --git a/flowexperimental/comp/flow_comp.cpp b/flowexperimental/comp/flow_comp.cpp index 1a334da446..e8098113b0 100644 --- a/flowexperimental/comp/flow_comp.cpp +++ b/flowexperimental/comp/flow_comp.cpp @@ -96,7 +96,7 @@ main(int argc, char** argv) const auto deck = Opm::Parser {}.parseFile(inputFilename, Opm::ParseContext {}, std::vector {Opm::Ecl::SectionType::RUNSPEC}); const auto runspec = Opm::Runspec(deck); - const auto numComps = runspec.numComps(); + const auto numComps = static_cast(runspec.numComps()); const auto& phases = runspec.phases(); const auto wat = phases.active(Opm::Phase::WATER); diff --git a/opm/simulators/flow/Banners.cpp b/opm/simulators/flow/Banners.cpp index 9f81cde585..d3a6cb5ab7 100644 --- a/opm/simulators/flow/Banners.cpp +++ b/opm/simulators/flow/Banners.cpp @@ -50,7 +50,8 @@ unsigned long long getTotalSystemMemory() namespace Opm { -void printPRTHeader(const int nprocs, const int nthreads, +void printPRTHeader(const std::size_t nprocs, + const std::size_t nthreads, const std::string& parameters, std::string_view moduleVersion, std::string_view compileTimestamp) @@ -97,8 +98,10 @@ void printFlowBanner(int nprocs, int nthreads, std::string_view moduleVersionNam const int lineLen = 70; std::string banner = "This is flow "; banner += moduleVersionName; - const int bannerPreLen = (lineLen - 2 - banner.size())/2; - const int bannerPostLen = bannerPreLen + (lineLen - 2 - banner.size())%2; + const int available = lineLen - 2 - static_cast(banner.size()); + const int pad = std::max(available, 0); + const std::size_t bannerPreLen = pad / 2; + const std::size_t bannerPostLen = pad - bannerPreLen; std::cout << "**********************************************************************\n"; std::cout << "* *\n"; std::cout << "*" << std::string(bannerPreLen, ' ') << banner << std::string(bannerPostLen, ' ') << "*\n"; diff --git a/opm/simulators/flow/Banners.hpp b/opm/simulators/flow/Banners.hpp index 55a1d3374c..48bdf27c59 100644 --- a/opm/simulators/flow/Banners.hpp +++ b/opm/simulators/flow/Banners.hpp @@ -31,7 +31,8 @@ struct SimulatorReport; struct SimulatorReportSingle; // Print an ASCII-art header to the PRT and DEBUG files. -void printPRTHeader(const int nprocs, const int nthreads, +void printPRTHeader(const std::size_t nprocs, + const std::size_t nthreads, const std::string& parameters, std::string_view moduleVersion, std::string_view compileTimestamp); diff --git a/opm/simulators/flow/DamarisWriter.cpp b/opm/simulators/flow/DamarisWriter.cpp index d20276ce7e..37db7133d8 100644 --- a/opm/simulators/flow/DamarisWriter.cpp +++ b/opm/simulators/flow/DamarisWriter.cpp @@ -87,25 +87,33 @@ int setupWritingPars(Parallel::Communication comm, n_elements_global_max += elements_rank_sizes[comm.size() - 1]; // add the last ranks size to the already accumulated offset values if (comm.rank() == 0) { - OpmLog::debug(fmt::format("In setupDamarisWritingPars(): n_elements_global_max = {}", + OpmLog::debug(fmt::format("In setupWritingPars(): n_elements_global_max = {}", n_elements_global_max)); } - // Set the paramater so that the Damaris servers can allocate the correct amount of memory for the variabe + // Set the parameter so that the Damaris servers can allocate the correct amount of memory for the variable. // Damaris parameters only support int data types. This will limit models to be under size of 2^32-1 elements // ToDo: Do we need to check that local ranks are 0 based ? - int dam_err = setParameter("n_elements_local", elements_rank_sizes[comm.rank()]); + const auto localSize = elements_rank_sizes[comm.rank()]; + if (localSize > static_cast(std::numeric_limits::max())) { + OPM_THROW(std::runtime_error, + "setupWritingPars() n_elements_local > std::numeric_limits::max() "); + } + + int dam_err = setParameter("n_elements_local", + static_cast(elements_rank_sizes[comm.rank()])); // Damaris parameters only support int data types. This will limit models to be under size of 2^32-1 elements // ToDo: Do we need to check that n_elements_global_max will fit in a C int type (INT_MAX) - if ( n_elements_global_max <= std::numeric_limits::max() ) { - setParameter("n_elements_total", n_elements_global_max); - } else { + if (n_elements_global_max <= static_cast(std::numeric_limits::max())) { + dam_err = setParameter("n_elements_total", static_cast(n_elements_global_max)); + } + else { if (comm.rank() == 0) { OpmLog::error(fmt::format("The size of the global array ({}) is" "greater than what a Damaris paramater type supports ({}). ", n_elements_global_max, std::numeric_limits::max() )); } - OPM_THROW(std::runtime_error, "setupDamarisWritingPars() n_elements_global_max " + OPM_THROW(std::runtime_error, "setupWritingPars() n_elements_global_max " "> std::numeric_limits::max() " + std::to_string(dam_err)); } diff --git a/opm/simulators/flow/ExtraConvergenceOutputThread.cpp b/opm/simulators/flow/ExtraConvergenceOutputThread.cpp index d43eac9589..be654d5833 100644 --- a/opm/simulators/flow/ExtraConvergenceOutputThread.cpp +++ b/opm/simulators/flow/ExtraConvergenceOutputThread.cpp @@ -72,19 +72,16 @@ namespace { } template - auto maxHeaderSize(const HeaderSequence& headers) + int maxHeaderSize(const HeaderSequence& headers) { - using sz_t = std::remove_cv_t().front().size())>>; - if (headers.empty()) { - return sz_t{0}; + return 0; } - return std::accumulate(headers.begin(), headers.end(), sz_t{1}, + return std::accumulate(headers.begin(), headers.end(), 0, [](const auto m, const auto& header) { - return std::max(m, header.size() + 1); + return std::max(m, static_cast(header.size() + 1)); }); } @@ -98,20 +95,20 @@ namespace { return os.str(); } - std::string::size_type - maxColHeaderSize(const std::string::size_type minColSize, + int + maxColHeaderSize(const int minColSize, const Opm::ConvergenceOutputThread::ComponentToPhaseName& getPhaseName, const std::vector& cols) { return std::accumulate(cols.begin(), cols.end(), minColSize, - [&getPhaseName](const std::string::size_type maxChar, + [&getPhaseName](const int maxChar, const Opm::ConvergenceReport::ReservoirConvergenceMetric& metric) { - return std::max(maxChar, formatMetricColumn(getPhaseName, metric).size() + 1); + return std::max(maxChar, static_cast(formatMetricColumn(getPhaseName, metric).size() + 1)); }); } - std::pair + std::pair writeConvergenceHeader(std::ostream& os, const Opm::ConvergenceOutputThread::ComponentToPhaseName& getPhaseName, const Opm::ConvergenceReportQueue::OutputRequest& firstRequest) @@ -146,7 +143,7 @@ namespace { void writeTimeColumns(std::ostream& os, const Opm::ConvergenceOutputThread::ConvertToTimeUnits& convertTime, - const std::string::size_type firstColSize, + const int firstColSize, const int iter, const Opm::ConvergenceReport& report, const Opm::ConvergenceReportQueue::OutputRequest& request) @@ -160,7 +157,7 @@ namespace { void writeCnvPvSplit(std::ostream& os, const std::vector::size_type expectedNumValues, - const std::string::size_type firstColSize, + const int firstColSize, const Opm::ConvergenceReport& report) { const auto& [splitPv, cellCnt] = report.cnvPvSplit(); @@ -194,7 +191,7 @@ namespace { } void writePenaltyCount(std::ostream& os, - const std::string::size_type firstColSize, + const int firstColSize, const Opm::ConvergenceReport& report) { const auto& penaltyCard = report.getPenaltyCard(); @@ -205,7 +202,7 @@ namespace { } void writeReservoirConvergence(std::ostream& os, - const std::string::size_type colSize, + const int colSize, const Opm::ConvergenceReport& report) { for (const auto& metric : report.reservoirConvergence()) { @@ -214,7 +211,7 @@ namespace { } void writeWellConvergence(std::ostream& os, - const std::string::size_type colSize, + const int colSize, const Opm::ConvergenceReport& report) { os << std::right << std::setw(colSize) @@ -229,8 +226,8 @@ namespace { void writeConvergenceRequest(std::ostream& os, const Opm::ConvergenceOutputThread::ConvertToTimeUnits& convertTime, - const std::string::size_type firstColSize, - const std::string::size_type colSize, + const int firstColSize, + const int colSize, const Opm::ConvergenceReportQueue::OutputRequest& request) { os.setf(std::ios_base::scientific); @@ -283,8 +280,8 @@ private: ComponentToPhaseName getPhaseName_{}; ConvertToTimeUnits convertTime_{}; std::optional infoIter_{}; - std::string::size_type firstColSize_{0}; - std::string::size_type colSize_{0}; + int firstColSize_{0}; + int colSize_{0}; bool haveOutputIterHeader_{false}; bool finalRequestWritten_{false}; diff --git a/opm/simulators/flow/GenericCpGridVanguard.cpp b/opm/simulators/flow/GenericCpGridVanguard.cpp index 65f336e087..b06942e02f 100644 --- a/opm/simulators/flow/GenericCpGridVanguard.cpp +++ b/opm/simulators/flow/GenericCpGridVanguard.cpp @@ -580,7 +580,7 @@ doCreateGrids_(const bool edge_conformal, EclipseState& eclState) removed_cells.resize(size); } - this->grid_->comm().broadcast(removed_cells.data(), size, 0); + this->grid_->comm().broadcast(removed_cells.data(), static_cast(size), 0); } // Inform the aquifer object that we might have removed/deactivated diff --git a/opm/simulators/flow/GenericOutputBlackoilModule.cpp b/opm/simulators/flow/GenericOutputBlackoilModule.cpp index 4dc8b14f8f..1b589a3566 100644 --- a/opm/simulators/flow/GenericOutputBlackoilModule.cpp +++ b/opm/simulators/flow/GenericOutputBlackoilModule.cpp @@ -1221,7 +1221,7 @@ setupExtraBlockData(const std::size_t reportStepNum, for (const auto& wname : sched.well_order()) { const auto& well = sched.wells.get(wname); for (const auto& connection : well.getConnections()) { - if (isCartIdxOnThisRank(connection.global_index())) { + if (isCartIdxOnThisRank(static_cast(connection.global_index()))) { this->extraBlockData_.emplace(std::piecewise_construct, std::forward_as_tuple("BPR", connection.global_index() + 1), diff --git a/opm/simulators/flow/RSTConv.cpp b/opm/simulators/flow/RSTConv.cpp index 90e3e76a0e..9492ceeed5 100644 --- a/opm/simulators/flow/RSTConv.cpp +++ b/opm/simulators/flow/RSTConv.cpp @@ -103,7 +103,7 @@ void RSTConv::prepareConv() void RSTConv::updateNewton(const std::vector& convNewt) { - const std::size_t numGloCells = conv_new_.size(); + const auto numGloCells = conv_new_.size(); if (comm_.size() == 1) { for (std::size_t n = 0; n < numGloCells; ++n) { @@ -113,13 +113,13 @@ void RSTConv::updateNewton(const std::vector& convNewt) } std::vector values(numGloCells, 0); - const std::size_t numLocCells = convNewt.size(); + const auto numLocCells = convNewt.size(); for (std::size_t i = 0; i < numLocCells; ++i) { - values[globalCell_(i)] = convNewt[i]; + values[globalCell_(static_cast(i))] = convNewt[i]; } - comm_.sum(values.data(), numGloCells); + comm_.sum(values.data(), static_cast(numGloCells)); for (std::size_t n = 0; n < numGloCells; ++n) { conv_new_[n] += values[n]; diff --git a/opm/simulators/flow/RegionPhasePVAverage.cpp b/opm/simulators/flow/RegionPhasePVAverage.cpp index 356be125ca..8cf0941da3 100644 --- a/opm/simulators/flow/RegionPhasePVAverage.cpp +++ b/opm/simulators/flow/RegionPhasePVAverage.cpp @@ -66,7 +66,7 @@ namespace { start[rset + 1] += *m; } - comm.max(start.data(), start.size()); + comm.max(start.data(), static_cast(start.size())); std::partial_sum(start.begin(), start.end(), start.begin()); @@ -127,7 +127,7 @@ addCell(const std::size_t activeCell, void Opm::RegionPhasePoreVolAverage::accumulateParallel() { - this->comm_.get().sum(this->x_.data(), this->x_.size()); + this->comm_.get().sum(this->x_.data(), static_cast(this->x_.size())); } double Opm::RegionPhasePoreVolAverage::averageValueWithFallback(const Ix start) const @@ -153,7 +153,7 @@ Opm::RegionPhasePoreVolAverage::fieldStartIx(const unsigned int phase) const Opm::RegionPhasePoreVolAverage::Ix Opm::RegionPhasePoreVolAverage::rsetStartIx(const std::size_t rset, - const int region, + const std::size_t region, const unsigned int phase) const { return this->startIx(this->rsStart_[rset] + region, phase); diff --git a/opm/simulators/flow/RegionPhasePVAverage.hpp b/opm/simulators/flow/RegionPhasePVAverage.hpp index a7a986b630..5cce6a0413 100644 --- a/opm/simulators/flow/RegionPhasePVAverage.hpp +++ b/opm/simulators/flow/RegionPhasePVAverage.hpp @@ -233,7 +233,7 @@ namespace Opm { /// \param[in] phase Phase index for which to compute array offset. /// /// \return Value array offset for region-level averages of \p phase. - Ix rsetStartIx(std::size_t rset, int region, unsigned int phase) const; + Ix rsetStartIx(std::size_t rset, std::size_t region, unsigned int phase) const; /// Compute linearised value array offset for average function /// values of a single phase. diff --git a/opm/simulators/flow/SimulatorConvergenceOutput.cpp b/opm/simulators/flow/SimulatorConvergenceOutput.cpp index 9bf89eaeba..1e3d8100cc 100644 --- a/opm/simulators/flow/SimulatorConvergenceOutput.cpp +++ b/opm/simulators/flow/SimulatorConvergenceOutput.cpp @@ -79,7 +79,9 @@ write(const std::vector& reports) return; } - const auto begin = reports.begin() + this->alreadyReportedSteps_; + using dtype = std::vector::difference_type; + const auto begin = std::next(reports.begin(), + static_cast(this->alreadyReportedSteps_)); const auto end = reports.end(); auto requests = std::vector{}; diff --git a/opm/simulators/flow/SimulatorSerializer.cpp b/opm/simulators/flow/SimulatorSerializer.cpp index 61a63ff789..de5ed14b21 100644 --- a/opm/simulators/flow/SimulatorSerializer.cpp +++ b/opm/simulators/flow/SimulatorSerializer.cpp @@ -239,7 +239,9 @@ void SimulatorSerializer::checkSerializedCmdLine(const std::string& current, } else { only_stored.push_back(difference[i]); } - difference.erase(difference.begin() + i); + using dtype = std::vector::difference_type; + difference.erase(std::next(difference.begin(), + static_cast(i))); } } std::stringstream str; diff --git a/opm/simulators/flow/partitionCells.cpp b/opm/simulators/flow/partitionCells.cpp index 8d4e42e396..6f3744f7f6 100644 --- a/opm/simulators/flow/partitionCells.cpp +++ b/opm/simulators/flow/partitionCells.cpp @@ -364,7 +364,7 @@ void ZoltanPartitioner::connectWells(const Comm auto otherProc = 0; for (const auto& conn : well.getConnections()) { - auto locPos = g2l.find(conn.global_index()); + auto locPos = g2l.find(static_cast(conn.global_index())); if (locPos == g2l.end()) { ++otherProc; continue; From ce9c1921127e0c79d79ba9e4260faa12d97cb45f Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Wed, 29 Jul 2026 08:10:26 +0200 Subject: [PATCH 3/7] use nullptr --- opm/simulators/flow/Banners.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opm/simulators/flow/Banners.cpp b/opm/simulators/flow/Banners.cpp index d3a6cb5ab7..2a2257a7d1 100644 --- a/opm/simulators/flow/Banners.cpp +++ b/opm/simulators/flow/Banners.cpp @@ -60,7 +60,7 @@ void printPRTHeader(const std::size_t nprocs, unsigned num_cpu = std::thread::hardware_concurrency(); struct utsname arch; const char* user = getlogin(); - std::time_t now = std::time(0); + std::time_t now = std::time(nullptr); struct std::tm tstruct; char tmstr[80]; tstruct = *std::localtime(&now); From c1737e051e62727dbccc6dd9badd957f403f0844 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Wed, 29 Jul 2026 08:10:54 +0200 Subject: [PATCH 4/7] avoid c array --- opm/simulators/flow/Banners.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/opm/simulators/flow/Banners.cpp b/opm/simulators/flow/Banners.cpp index 2a2257a7d1..4ff15dc901 100644 --- a/opm/simulators/flow/Banners.cpp +++ b/opm/simulators/flow/Banners.cpp @@ -29,6 +29,7 @@ #include +#include #include #include #include @@ -62,10 +63,10 @@ void printPRTHeader(const std::size_t nprocs, const char* user = getlogin(); std::time_t now = std::time(nullptr); struct std::tm tstruct; - char tmstr[80]; + std::array tmstr; tstruct = *std::localtime(&now); - std::strftime(tmstr, sizeof(tmstr), "%d-%m-%Y at %X", &tstruct); - const double mem_size = getTotalSystemMemory() / megabyte; + std::strftime(tmstr.data(), tmstr.size(), "%d-%m-%Y at %X", &tstruct); + const double mem_size = static_cast(getTotalSystemMemory()) / megabyte; std::ostringstream ss; ss << "\n\n\n"; ss << " ######## # ###### # #\n"; @@ -86,7 +87,7 @@ void printPRTHeader(const std::size_t nprocs, if (user != nullptr) { ss << "User = " << user << std::endl; } - ss << "Simulation started on " << tmstr << " hrs\n"; + ss << "Simulation started on " << tmstr.data() << " hrs\n"; ss << "Using "<< nprocs << " MPI processes with "<< nthreads <<" OMP threads on each \n"; ss << "Parameters used by Flow:\n" << parameters; From 03b94d372a5b2d1e79d28f0679ff59373e8d8948 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Wed, 29 Jul 2026 08:11:06 +0200 Subject: [PATCH 5/7] avoid unncessary copies --- opm/simulators/flow/ExtraConvergenceOutputThread.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opm/simulators/flow/ExtraConvergenceOutputThread.cpp b/opm/simulators/flow/ExtraConvergenceOutputThread.cpp index be654d5833..3282adb090 100644 --- a/opm/simulators/flow/ExtraConvergenceOutputThread.cpp +++ b/opm/simulators/flow/ExtraConvergenceOutputThread.cpp @@ -388,8 +388,8 @@ ConvergenceOutputThread(std::string_view outputDir, ConvergenceReportQueue& queue) : pImpl_ { std::make_unique(outputDir, baseName, - getPhaseName, - convertTime, + std::move(getPhaseName), + std::move(convertTime), config, queue) } {} From 57df9319b215eba7b6e8c3657ad8f8b9ccec55bc Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Wed, 29 Jul 2026 08:11:20 +0200 Subject: [PATCH 6/7] use string member functions --- opm/simulators/flow/FlowGenericVanguard.cpp | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/opm/simulators/flow/FlowGenericVanguard.cpp b/opm/simulators/flow/FlowGenericVanguard.cpp index a013cb0726..2deb7d6a75 100644 --- a/opm/simulators/flow/FlowGenericVanguard.cpp +++ b/opm/simulators/flow/FlowGenericVanguard.cpp @@ -317,21 +317,14 @@ void FlowGenericVanguard::init() // compute the base name of the input file name const char directorySeparator = '/'; - long int i; - for (i = fileName_.size(); i >= 0; -- i) - if (fileName_[i] == directorySeparator) - break; - std::string baseName = fileName_.substr(i + 1, fileName_.size()); + const auto sepPos = fileName_.find_last_of(directorySeparator); + const auto baseName = sepPos != std::string::npos + ? fileName_.substr(sepPos + 1, fileName_.size()) + : fileName_; // remove the extension from the input file - for (i = baseName.size(); i >= 0; -- i) - if (baseName[i] == '.') - break; - std::string rawCaseName; - if (i < 0) - rawCaseName = baseName; - else - rawCaseName = baseName.substr(0, i); + const auto dotPos = baseName.find_last_of('.'); + const auto rawCaseName = dotPos == std::string::npos ? baseName : baseName.substr(0, dotPos); // transform the result to ALL_UPPERCASE caseName_ = rawCaseName; From dee13c52174d25cb404222ee95834ec8a04a5b55 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Wed, 29 Jul 2026 08:11:34 +0200 Subject: [PATCH 7/7] mark method const --- opm/simulators/flow/Main.cpp | 2 +- opm/simulators/flow/Main.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/opm/simulators/flow/Main.cpp b/opm/simulators/flow/Main.cpp index 3d858f6067..95b80928ee 100644 --- a/opm/simulators/flow/Main.cpp +++ b/opm/simulators/flow/Main.cpp @@ -283,7 +283,7 @@ void Main::handleTestSplitCommunicatorCmdLine_() } } -void Main::notifyMasterSlaveInitFailed_() +void Main::notifyMasterSlaveInitFailed_() const { #if HAVE_MPI if (Parameters::Get()) { diff --git a/opm/simulators/flow/Main.hpp b/opm/simulators/flow/Main.hpp index ec47cb6d67..483bd7ff9b 100644 --- a/opm/simulators/flow/Main.hpp +++ b/opm/simulators/flow/Main.hpp @@ -398,7 +398,7 @@ private: // If this process is a reservoir coupling slave, notify the master that // initialization failed so it does not hang waiting for the initial data exchange. - void notifyMasterSlaveInitFailed_(); + void notifyMasterSlaveInitFailed_() const; /// Dispatch to actual simulation functions based on input deck's setup. ///