Merge pull request #5908 from akva2/janitoring_sca_various

Janitoring: address various static analyzer issues
This commit is contained in:
Bård Skaflestad 2025-01-23 11:50:01 +01:00 committed by GitHub
commit 06904dc93f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
30 changed files with 144 additions and 160 deletions

View File

@ -571,7 +571,7 @@ private:
const auto& matParams = this->materialLawParams(context, spaceIdx, timeIdx);
MaterialLaw::capillaryPressures(pC, matParams, fs);
fs.setPressure(liquidPhaseIdx, pl + (pC[liquidPhaseIdx] - pC[liquidPhaseIdx]));
fs.setPressure(liquidPhaseIdx, pl);
fs.setPressure(gasPhaseIdx, pl + (pC[gasPhaseIdx] - pC[liquidPhaseIdx]));
//////

View File

@ -194,14 +194,17 @@ public:
}
// Adding dispersion in the gas phase leads to
// convergence issues and unphysical results.
// convergence issues and unphysical results.
// We disable dispersion in the gas phase for now
// See comment below
if (FluidSystem::gasPhaseIdx == phaseIdx) {
continue;
}
// no dispersion in gas for blackoil models unless gas can contain evaporated water or oil
if ((!FluidSystem::enableVaporizedWater() && !FluidSystem::enableVaporizedOil()) && FluidSystem::gasPhaseIdx == phaseIdx) {
// phase check disabled due to if above, reenable when removing unconditional gas phase disablement
if ((!FluidSystem::enableVaporizedWater() && !FluidSystem::enableVaporizedOil())
/*&& FluidSystem::gasPhaseIdx == phaseIdx*/) {
continue;
}

View File

@ -167,8 +167,8 @@ public:
{ return 1.0 - upstreamWeight(phaseIdx); }
private:
short upstreamScvIdx_[numPhases];
short downstreamScvIdx_[numPhases];
short upstreamScvIdx_[numPhases]{};
short downstreamScvIdx_[numPhases]{};
};
} // namespace Opm

View File

@ -500,10 +500,10 @@ private:
Evaluation pressureDifference_[numPhases];
// the local indices of the interior and exterior degrees of freedom
unsigned short interiorDofIdx_;
unsigned short exteriorDofIdx_;
short upIdx_[numPhases];
short dnIdx_[numPhases];
unsigned short interiorDofIdx_{};
unsigned short exteriorDofIdx_{};
short upIdx_[numPhases]{};
short dnIdx_[numPhases]{};
};
} // namespace Opm

View File

@ -122,7 +122,7 @@ public:
{};
private:
int dofOffset_;
int dofOffset_{};
};
} // namespace Opm

View File

@ -124,10 +124,10 @@ public:
private:
// local indices of the interior and the exterior sub-control-volumes
unsigned short interiorScvIdx_;
unsigned short exteriorScvIdx_;
unsigned short interiorScvIdx_{};
unsigned short exteriorScvIdx_{};
Scalar extrusionFactor_;
Scalar extrusionFactor_{};
};
} // namespace Opm

View File

@ -341,9 +341,9 @@ private:
#if HAVE_DUNE_LOCALFUNCTIONS
static LocalFiniteElementCache feCache_;
const LocalFiniteElement* localFiniteElement_;
std::vector<Dune::FieldVector<Scalar, 1>> p1Value_[maxFap];
DimVector p1Gradient_[maxFap][maxDof];
const LocalFiniteElement* localFiniteElement_{nullptr};
std::vector<Dune::FieldVector<Scalar, 1>> p1Value_[maxFap]{};
DimVector p1Gradient_[maxFap][maxDof]{};
#endif // HAVE_DUNE_LOCALFUNCTIONS
};

View File

@ -839,7 +839,12 @@ public:
numVertices = e.subEntities(/*codim=*/dim);
numEdges = e.subEntities(/*codim=*/dim-1);
numFaces = (dim<3)?0:e.subEntities(/*codim=*/1);
if constexpr (dim == 3) {
numFaces = e.subEntities(/*codim=*/1);
}
else {
numFaces = 0;
}
numBoundarySegments_ = 0; // TODO: really required here(?)
@ -913,13 +918,13 @@ public:
// cases which don't apply.
LocalPosition ipLocal_;
DimVector diffVec;
if (dim==1) {
if constexpr (dim == 1) {
subContVolFace[k].ipLocal_ = 0.5;
subContVolFace[k].normal_ = 1.0;
subContVolFace[k].area_ = 1.0;
ipLocal_ = subContVolFace[k].ipLocal_;
}
else if (dim==2) {
else if constexpr (dim == 2) {
ipLocal_ = referenceElement.position(static_cast<int>(k), dim-1) + elementLocal;
ipLocal_ *= 0.5;
subContVolFace[k].ipLocal_ = ipLocal_;
@ -937,7 +942,7 @@ public:
subContVolFace[k].area_ = subContVolFace[k].normal_.two_norm();
subContVolFace[k].normal_ /= subContVolFace[k].area_;
}
else if (dim==3) {
else if constexpr (dim == 3) {
unsigned leftFace;
unsigned rightFace;
getFaceIndices(numVertices, k, leftFace, rightFace);
@ -973,17 +978,17 @@ public:
unsigned bfIdx = numBoundarySegments_;
++numBoundarySegments_;
if (dim == 1) {
if constexpr (dim == 1) {
boundaryFace_[bfIdx].ipLocal_ = referenceElement.position(static_cast<int>(vertInElement), dim);
boundaryFace_[bfIdx].area_ = 1.0;
}
else if (dim == 2) {
else if constexpr (dim == 2) {
boundaryFace_[bfIdx].ipLocal_ = referenceElement.position(static_cast<int>(vertInElement), dim)
+ referenceElement.position(static_cast<int>(face), 1);
boundaryFace_[bfIdx].ipLocal_ *= 0.5;
boundaryFace_[bfIdx].area_ = 0.5 * intersection.geometry().volume();
}
else if (dim == 3) {
else if constexpr (dim == 3) {
unsigned leftEdge;
unsigned rightEdge;
getEdgeIndices(numVertices, face, vertInElement, leftEdge, rightEdge);
@ -1113,12 +1118,12 @@ private:
#endif
void fillSubContVolData_()
{
if (dim == 1) {
if constexpr (dim == 1) {
// 1D
subContVol[0].volume_ = 0.5*elementVolume;
subContVol[1].volume_ = 0.5*elementVolume;
}
else if (dim == 2) {
else if constexpr (dim == 2) {
switch (numVertices) {
case 3: // 2D, triangle
subContVol[0].volume_ = elementVolume/3;
@ -1152,7 +1157,7 @@ private:
+", numVertices = "+std::to_string(numVertices));
}
}
else if (dim == 3) {
else if constexpr (dim == 3) {
switch (numVertices) {
case 4: // 3D, tetrahedron
for (unsigned k = 0; k < numVertices; k++)

View File

@ -231,17 +231,11 @@ public:
fluidState_.setCompressFactor(1, Z_V);
// Print saturation
if (flashVerbosity >= 5) {
std::cout << "So = " << So <<std::endl;
std::cout << "Sg = " << Sg <<std::endl;
}
// Print saturation
if (flashVerbosity >= 5) {
std::cout << "So = " << So <<std::endl;
std::cout << "Sg = " << Sg <<std::endl;
std::cout << "Z_L = " << Z_L <<std::endl;
std::cout << "Z_V = " << Z_V <<std::endl;
if (flashVerbosity >= 5) {
std::cout << "So = " << So << std::endl;
std::cout << "Sg = " << Sg << std::endl;
std::cout << "Z_L = " << Z_L << std::endl;
std::cout << "Z_V = " << Z_V << std::endl;
}
/////////////

View File

@ -581,13 +581,13 @@ public:
using FsToolbox = Opm::MathToolbox<typename FluidState::Scalar>;
for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
bool oldPhasePresent = (oldPhasePresence& (1 << phaseIdx)) > 0;
bool oldPhasePresent = (oldPhasePresence & (1 << phaseIdx)) > 0;
bool newPhasePresent = newPv.phaseIsPresent(phaseIdx);
if (oldPhasePresent == newPhasePresent)
continue;
const auto& pos = elemCtx.pos(dofIdx, /*timeIdx=*/0);
if (oldPhasePresent && !newPhasePresent) {
if (oldPhasePresent) {
std::cout << "'" << FluidSystem::phaseName(phaseIdx)
<< "' phase disappears at position " << pos
<< ". saturation=" << fs.saturation(phaseIdx)

View File

@ -1098,7 +1098,7 @@ localIdxToGlobalIdx(unsigned localIdx) const
throw std::logic_error("index map is not created on this rank");
}
if (localIdx > this->localIdxToGlobalIdx_.size()) {
if (localIdx >= this->localIdxToGlobalIdx_.size()) {
throw std::logic_error("local index is outside map range");
}

View File

@ -309,7 +309,7 @@ public:
if (this->sub_step_report_.max_linear_iterations != 0) {
miscSummaryData["NLINSMAX"] = this->sub_step_report_.max_linear_iterations;
}
if (this->simulation_report_.success.total_newton_iterations != 0) {
if (this->simulation_report_.success.total_linear_iterations != 0) {
miscSummaryData["MSUMLINS"] = this->simulation_report_.success.total_linear_iterations;
}
if (this->simulation_report_.success.total_newton_iterations != 0) {

View File

@ -337,9 +337,6 @@ public:
std::ostringstream ss;
timer.report(ss);
OpmLog::debug(ss.str());
}
if (terminalOutput_) {
details::outputReportStep(timer);
}

View File

@ -61,10 +61,10 @@ namespace details {
std::uint64_t isId(std::uint32_t elemIdx1, std::uint32_t elemIdx2)
{
std::uint32_t elemAIdx = std::min(elemIdx1, elemIdx2);
std::uint64_t elemBIdx = std::max(elemIdx1, elemIdx2);
const std::uint32_t elemAIdx = std::min(elemIdx1, elemIdx2);
const std::uint64_t elemBIdx = std::max(elemIdx1, elemIdx2);
return (elemBIdx<<elemIdxShift) + elemAIdx;
return (elemBIdx << elemIdxShift) + elemAIdx;
}
std::pair<std::uint32_t, std::uint32_t> isIdReverse(const std::uint64_t& id)
@ -72,15 +72,15 @@ namespace details {
// Assigning an unsigned integer to a narrower type discards the most significant bits.
// See "The C programming language", section A.6.2.
// NOTE that the ordering of element A and B may have changed
std::uint32_t elemAIdx = id;
std::uint32_t elemBIdx = (id - elemAIdx) >> elemIdxShift;
const std::uint32_t elemAIdx = static_cast<uint32_t>(id);
const std::uint32_t elemBIdx = (id - elemAIdx) >> elemIdxShift;
return std::make_pair(elemAIdx, elemBIdx);
}
std::uint64_t directionalIsId(std::uint32_t elemIdx1, std::uint32_t elemIdx2)
{
return (std::uint64_t(elemIdx1)<<elemIdxShift) + elemIdx2;
return (std::uint64_t(elemIdx1) << elemIdxShift) + elemIdx2;
}
}

View File

@ -319,7 +319,7 @@ private:
}
HYPRE_IJMatrixAssemble(A_hypre_);
HYPRE_IJMatrixGetObject(A_hypre_, (void**)&parcsr_A_);
HYPRE_IJMatrixGetObject(A_hypre_, reinterpret_cast<void**>(&parcsr_A_));
}
/**
@ -350,8 +350,8 @@ private:
HYPRE_IJVectorAssemble(x_hypre_);
HYPRE_IJVectorAssemble(b_hypre_);
HYPRE_IJVectorGetObject(x_hypre_, (void**)&par_x_);
HYPRE_IJVectorGetObject(b_hypre_, (void**)&par_b_);
HYPRE_IJVectorGetObject(x_hypre_, reinterpret_cast<void**>(&par_x_));
HYPRE_IJVectorGetObject(b_hypre_, reinterpret_cast<void**>(&par_b_));
}
/**

View File

@ -978,7 +978,7 @@ void ChowPatelIlu<block_size>::gpu_decomposition(
OPM_THROW(std::logic_error, oss.str());
} catch (const std::logic_error& error) {
// rethrow exception by OPM_THROW in the try{}
throw error;
throw;
}
}

View File

@ -341,16 +341,16 @@ create_preconditioner(BlockedMatrix<Scalar>* mat)
}
template<class Scalar, unsigned int block_size>
void openclBISAI<Scalar,block_size>::apply(const cl::Buffer& x, cl::Buffer& y)
void openclBISAI<Scalar,block_size>::apply(const cl::Buffer& y, cl::Buffer& x)
{
const unsigned int bs = block_size;
OpenclKernels<Scalar>::spmv(d_invLvals, d_rowIndices, d_colPointers,
x, d_invL_x, Nb, bs, true, true); // application of isaiL is a simple spmv with addition
y, d_invL_x, Nb, bs, true, true); // application of isaiL is a simple spmv with addition
// (to compensate for the unitary diagonal that is not
// included in isaiL, for simplicity)
OpenclKernels<Scalar>::spmv(d_invUvals, d_rowIndices, d_colPointers,
d_invL_x, y, Nb, bs); // application of isaiU is a simple spmv
d_invL_x, x, Nb, bs); // application of isaiU is a simple spmv
}
#define INSTANTIATE_TYPE(T) \

View File

@ -219,7 +219,7 @@ openclSolverBackend(int verbosity_,
OPM_THROW(std::logic_error, oss.str());
} catch (const std::logic_error& error) {
// rethrow exception by OPM_THROW in the try{}, without this, a segfault occurs
throw error;
throw;
}
}
@ -479,7 +479,7 @@ initialize(std::shared_ptr<BlockedMatrix<Scalar>> matrix,
OPM_THROW(std::logic_error, oss.str());
} catch (const std::logic_error& error) {
// rethrow exception by OPM_THROW in the try{}, without this, a segfault occurs
throw error;
throw;
}
initialized = true;
@ -649,7 +649,7 @@ solve_system(WellContributions<Scalar>& wellContribs, GpuResult& res)
OPM_THROW(std::logic_error, oss.str());
} catch (const std::logic_error& error) {
// rethrow exception by OPM_THROW in the try{}, without this, a segfault occurs
throw error;
throw;
}
if (verbosity > 2) {

View File

@ -70,7 +70,7 @@ namespace Opm::Satfunc::PhaseChecks::Gas {
private:
/// Minimum gas saturation.
Scalar sgl_;
Scalar sgl_{};
/// Run check against a set of saturation function end-points.
///
@ -124,7 +124,7 @@ namespace Opm::Satfunc::PhaseChecks::Gas {
private:
/// Maximum gas saturation.
Scalar sgu_;
Scalar sgu_{};
/// Run check against a set of saturation function end-points.
///
@ -182,13 +182,13 @@ namespace Opm::Satfunc::PhaseChecks::Gas {
private:
/// Minimum gas saturation.
Scalar sgl_;
Scalar sgl_{};
/// Critical gas saturation.
Scalar sgcr_;
Scalar sgcr_{};
/// Maximum gas saturation.
Scalar sgu_;
Scalar sgu_{};
/// Run check against a set of saturation function end-points.
///

View File

@ -70,7 +70,7 @@ namespace Opm::Satfunc::PhaseChecks::Oil {
private:
/// Critical oil saturation in gas/oil system.
Scalar sogcr_;
Scalar sogcr_{};
/// Run check against a set of saturation function end-points.
///
@ -128,10 +128,10 @@ namespace Opm::Satfunc::PhaseChecks::Oil {
private:
/// Minimum (connate) water saturation in gas/oil system.
Scalar swl_;
Scalar swl_{};
/// Maximum gas saturation in gas/oil system.
Scalar sgu_;
Scalar sgu_{};
/// Run check against a set of saturation function end-points.
///
@ -192,13 +192,13 @@ namespace Opm::Satfunc::PhaseChecks::Oil {
private:
/// Minimum water saturation.
Scalar swl_;
Scalar swl_{};
/// Minimum gas saturation.
Scalar sgl_;
Scalar sgl_{};
/// Critical oil saturation in gas/oil system.
Scalar sogcr_;
Scalar sogcr_{};
/// Run check against a set of saturation function end-points.
///
@ -259,13 +259,13 @@ namespace Opm::Satfunc::PhaseChecks::Oil {
private:
/// Minimum water saturation.
Scalar swl_;
Scalar swl_{};
/// Critical gas saturation.
Scalar sgcr_;
Scalar sgcr_{};
/// Critical oil saturation in gas/oil system
Scalar sogcr_;
Scalar sogcr_{};
/// Run check against a set of saturation function end-points.
///
@ -321,7 +321,7 @@ namespace Opm::Satfunc::PhaseChecks::Oil {
private:
/// Critical oil saturation in oil/water system.
Scalar sowcr_;
Scalar sowcr_{};
/// Run check against a set of saturation function end-points.
///
@ -379,10 +379,10 @@ namespace Opm::Satfunc::PhaseChecks::Oil {
private:
/// Minimum gas saturation. Typically zero.
Scalar sgl_;
Scalar sgl_{};
/// Minimum (connate) saturation.
Scalar swu_;
Scalar swu_{};
/// Run check against a set of saturation function end-points.
///
@ -443,13 +443,13 @@ namespace Opm::Satfunc::PhaseChecks::Oil {
private:
/// Minimum (connate) water saturation.
Scalar swl_;
Scalar swl_{};
/// Minimum gas saturation. Typically zero.
Scalar sgl_;
Scalar sgl_{};
/// Critical oil saturation in oil/water system.
Scalar sowcr_;
Scalar sowcr_{};
/// Run check against a set of saturation function end-points.
///
@ -510,13 +510,13 @@ namespace Opm::Satfunc::PhaseChecks::Oil {
private:
/// Minimum gas saturation. Typically zero.
Scalar sgl_;
Scalar sgl_{};
/// Critical water saturation.
Scalar swcr_;
Scalar swcr_{};
/// Critical oil saturation in oil/water system.
Scalar sowcr_;
Scalar sowcr_{};
/// Run check against a set of saturation function end-points.
///

View File

@ -77,10 +77,10 @@ namespace Opm {
NoFamily
};
SaturationFunctionFamily satFamily_;
SaturationFunctionFamily satFamily_{NoFamily};
std::vector<EclEpsScalingPointsInfo<double> > unscaledEpsInfo_;
std::vector<EclEpsScalingPointsInfo<double> > scaledEpsInfo_;
std::vector<EclEpsScalingPointsInfo<double> > unscaledEpsInfo_{};
std::vector<EclEpsScalingPointsInfo<double> > scaledEpsInfo_{};
///Check the phase that used.

View File

@ -82,16 +82,16 @@ namespace Opm::Satfunc::PhaseChecks::ThreePointHorizontal {
private:
/// Minimum (connate) water saturation.
Scalar swl_;
Scalar swl_{};
/// Critical oil saturation in two-phase gas/oil system.
Scalar sogcr_;
Scalar sogcr_{};
/// Critical gas saturation.
Scalar sgcr_;
Scalar sgcr_{};
/// Maximum gas saturation.
Scalar sgu_;
Scalar sgu_{};
/// Run check against a set of saturation function end-points.
///
@ -157,16 +157,16 @@ namespace Opm::Satfunc::PhaseChecks::ThreePointHorizontal {
private:
/// Minimum gas saturation.
Scalar sgl_;
Scalar sgl_{};
/// Critical oil saturation in two-phase oil/water system.
Scalar sowcr_;
Scalar sowcr_{};
/// Critical water saturation.
Scalar swcr_;
Scalar swcr_{};
/// Maximum water saturation.
Scalar swu_;
Scalar swu_{};
/// Run check against a set of saturation function end-points.
///

View File

@ -70,7 +70,7 @@ namespace Opm::Satfunc::PhaseChecks::Water {
private:
/// Minimum (connate) water saturation.
Scalar swl_;
Scalar swl_{};
/// Run check against a set of saturation function end-points.
///
@ -124,7 +124,7 @@ namespace Opm::Satfunc::PhaseChecks::Water {
private:
/// Maximum water saturation.
Scalar swu_;
Scalar swu_{};
/// Run check against a set of saturation function end-points.
///
@ -182,13 +182,13 @@ namespace Opm::Satfunc::PhaseChecks::Water {
private:
/// Minimum (connate) water saturation.
Scalar swl_;
Scalar swl_{};
/// Critical water saturation.
Scalar swcr_;
Scalar swcr_{};
/// Maximum water saturation.
Scalar swu_;
Scalar swu_{};
/// Run check against a set of saturation function end-points.
///

View File

@ -253,9 +253,7 @@ initFromRestartFile(const RestartValue& restartValues,
config.model().target(),
restartValues.wells,
this->guideRate_);
}
if (config.has_model()) {
BlackoilWellModelRestart(*this).
loadRestartGuideRates(report_step,
config,

View File

@ -1852,9 +1852,8 @@ namespace Opm {
if (this->terminal_output_) {
global_deferredLogger.logMessages();
}
// Log debug messages for NaN or too large residuals.
if (this->terminal_output_) {
// Log debug messages for NaN or too large residuals.
for (const auto& f : report.wellFailures()) {
if (f.severity() == ConvergenceReport::Severity::NotANumber) {
OpmLog::debug("NaN residual found with phase " + std::to_string(f.phase()) + " for well " + f.wellName());

View File

@ -1048,11 +1048,10 @@ GasLiftSingleWellGeneric<Scalar>::
increaseALQtoPositiveOilRate_(Scalar alq,
const LimitedRates& orig_rates) const
{
bool stop_iteration = false;
Scalar temp_alq = alq;
// use the copy constructor to only copy the rates
BasicRates rates = orig_rates;
while (!stop_iteration) {
while (true) {
temp_alq += this->increment_;
if (temp_alq > this->max_alq_)
break;
@ -1078,10 +1077,9 @@ increaseALQtoMinALQ_(const Scalar orig_alq,
assert(min_alq >= 0);
assert(orig_alq < min_alq);
assert(min_alq < this->max_alq_);
bool stop_iteration = false;
Scalar alq = orig_alq;
LimitedRates rates = orig_rates;
while (!stop_iteration) {
while (true) {
Scalar temp_alq = alq + this->increment_;
alq = temp_alq;
@ -1175,11 +1173,10 @@ GasLiftSingleWellGeneric<Scalar>::
reduceALQtoGroupAlqLimits_(const Scalar orig_alq,
const LimitedRates& orig_rates) const
{
bool stop_this_iteration = false;
Scalar alq = orig_alq;
BasicRates rates {orig_rates};
Scalar temp_alq = orig_alq;
while (!stop_this_iteration) {
while (true) {
if (temp_alq == 0)
break;
temp_alq -= this->increment_;
@ -1268,8 +1265,7 @@ reduceALQtoWellTarget_(const Scalar orig_alq,
Scalar alq = orig_alq;
Scalar temp_alq = alq;
std::optional<LimitedRates> new_rates;
bool stop_iteration = false;
while (!stop_iteration) {
while (true) {
if (temp_alq == 0)
break;
temp_alq -= this->increment_;

View File

@ -412,8 +412,8 @@ protected:
Scalar delta_alq) const;
LimitedRates
updateRatesToGroupLimits_(const BasicRates& rates,
const LimitedRates& new_rates,
updateRatesToGroupLimits_(const BasicRates& old_rates,
const LimitedRates& rates,
const std::string& gr_name = "") const;
void updateWellStateAlqFixedValue_(const GasLiftWell& well);

View File

@ -1656,32 +1656,28 @@ namespace Opm
// if we fail to solve eqs, we reset status/operability before leaving
const auto well_status_orig = this->wellStatus_;
const auto operability_orig = this->operability_status_;
auto well_status_cur = well_status_orig;
// don't allow opening wells that are stopped from schedule or has a stopped well state
const bool allow_open = this->well_ecl_.getStatus() == WellStatus::OPEN &&
well_state.well(this->index_of_well_).status == WellStatus::OPEN;
// don't allow switcing for wells under zero rate target or requested fixed status and control
const bool allow_switching = !this->wellUnderZeroRateTarget(simulator, well_state, deferred_logger) &&
(!fixed_control || !fixed_status) && allow_open;
bool changed = false;
bool final_check = false;
// well needs to be set operable or else solving/updating of re-opened wells is skipped
this->operability_status_.resetOperability();
this->operability_status_.solvable = true;
for (; it < max_iter_number; ++it, ++debug_cost_counter_) {
its_since_last_switch++;
++its_since_last_switch;
if (allow_switching && its_since_last_switch >= min_its_after_switch){
const Scalar wqTotal = this->primary_variables_.getWQTotal().value();
changed = this->updateWellControlAndStatusLocalIteration(simulator, well_state, group_state,
inj_controls, prod_controls, wqTotal,
deferred_logger, fixed_control, fixed_status);
if (changed){
bool changed = this->updateWellControlAndStatusLocalIteration(simulator, well_state, group_state,
inj_controls, prod_controls, wqTotal,
deferred_logger, fixed_control,
fixed_status);
if (changed) {
its_since_last_switch = 0;
switch_count++;
if (well_status_cur != this->wellStatus_) {
well_status_cur = this->wellStatus_;
}
++switch_count;
}
if (!changed && final_check) {
break;
@ -1690,7 +1686,8 @@ namespace Opm
}
}
assembleWellEqWithoutIteration(simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
assembleWellEqWithoutIteration(simulator, dt, inj_controls, prod_controls,
well_state, group_state, deferred_logger);
const BVectorWell dx_well = this->linSys_.solve();

View File

@ -171,10 +171,9 @@ findThpFromBhpIteratively(const std::function<Scalar(const Scalar, const Scalar)
auto pressure_loss = getVfpBhpAdjustment(bhp + dp, thp_limit);
auto thp = thp_func(bhp, pressure_loss);
const Scalar tolerance = 1e-5 * unit::barsa;
bool do_iterate = true;
int it = 1;
int max_iterations = 50;
while (do_iterate) {
while (true) {
if (it > max_iterations) {
break;
}

View File

@ -919,48 +919,44 @@ template<class Scalar>
void WellState<Scalar>::communicateGroupRates(const Parallel::Communication& comm)
{
// Compute the size of the data.
std::size_t sz = 0;
for (const auto& [_, owner_rates] : this->well_rates) {
(void)_;
const auto& [__, rates] = owner_rates;
(void)__;
sz += rates.size();
}
std::size_t sz = std::accumulate(this->well_rates.begin(), this->well_rates.end(), std::size_t{0},
[](const std::size_t acc, const auto& rates)
{ return acc + rates.second.second.size(); });
sz += this->alq_state.pack_size();
// Make a vector and collect all data into it.
std::vector<Scalar> data(sz);
std::size_t pos = 0;
for (const auto& [_, owner_rates] : this->well_rates) {
(void)_;
const auto& [owner, rates] = owner_rates;
for (const auto& value : rates) {
if (owner)
data[pos++] = value;
else
data[pos++] = 0;
}
auto pos = data.begin();
std::for_each(this->well_rates.begin(), this->well_rates.end(),
[&pos](const auto& input)
{
const auto& [owner, rates] = input.second;
if (owner) {
std::copy(rates.begin(), rates.end(), pos);
}
pos += rates.size();
});
if (pos != data.end()) {
pos += this->alq_state.pack_data(&(*pos));
}
if (!data.empty() && pos != sz) {
pos += this->alq_state.pack_data(&data[pos]);
}
assert(pos == sz);
assert(pos == data.end());
// Communicate it with a single sum() call.
comm.sum(data.data(), data.size());
pos = 0;
for (auto& [_, owner_rates] : this->well_rates) {
(void)_;
auto& [__, rates] = owner_rates;
(void)__;
for (auto& value : rates)
value = data[pos++];
pos = data.begin();
std::for_each(this->well_rates.begin(), this->well_rates.end(),
[&pos](auto& input)
{
auto& rates = input.second.second;
std::copy(pos, pos + rates.size(), rates.begin());
pos += rates.size();
});
if (pos != data.end()) {
pos += this->alq_state.unpack_data(&(*pos));
}
if (!data.empty() && pos != sz) {
pos += this->alq_state.unpack_data(&data[pos]);
}
assert(pos == sz);
assert(pos == data.end());
}
template<class Scalar>