use .empty() instead of .size() comparisons

This commit is contained in:
Arne Morten Kvarving
2021-08-04 09:09:46 +02:00
parent 8d40860b0b
commit 08e950686f
6 changed files with 12 additions and 12 deletions

View File

@@ -128,7 +128,7 @@ int checkZeroDiagonal(BridgeMatrix& mat) {
int numZeros = 0;
const int dim = 3; // might be replaced with mat[0][0].N() or BridgeMatrix::block_type::size()
const double zero_replace = 1e-15;
if (diag_indices.size() == 0) {
if (diag_indices.empty()) {
int N = mat.N();
diag_indices.reserve(N);
for (typename BridgeMatrix::iterator r = mat.begin(); r != mat.end(); ++r) {
@@ -169,7 +169,7 @@ void getSparsityPattern(BridgeMatrix& mat, std::vector<int> &h_rows, std::vector
int sum_nnzs = 0;
// convert colIndices and rowPointers
if (h_rows.size() == 0) {
if (h_rows.empty()) {
h_rows.emplace_back(0);
for (typename BridgeMatrix::const_iterator r = mat.begin(); r != mat.end(); ++r) {
int size_row = 0;

View File

@@ -270,7 +270,7 @@ void findLevelScheduling(int *CSRColIndices, int *CSRRowPointers, int *CSCRowInd
std::vector <int> rowsToStart;
// since emplace_back() is used to fill, the vector must be empty
assert(rowsPerColor.size() == 0);
assert(rowsPerColor.empty());
// find starting rows: rows that are independent from all rows that come before them.
for (thisRow = 0; thisRow < Nb; thisRow++) {

View File

@@ -49,7 +49,7 @@ openclSolverBackend<block_size>::openclSolverBackend(int verbosity_, int maxit_,
try {
std::vector<cl::Platform> platforms;
cl::Platform::get(&platforms);
if (platforms.size() == 0) {
if (platforms.empty()) {
OPM_THROW(std::logic_error, "Error openclSolver is selected but no OpenCL platforms are found");
}
out << "Found " << platforms.size() << " OpenCL platforms" << "\n";
@@ -89,7 +89,7 @@ openclSolverBackend<block_size>::openclSolverBackend(int verbosity_, int maxit_,
platforms[platformID].getDevices(CL_DEVICE_TYPE_ALL, &devices);
if (devices.size() == 0){
if (devices.empty()) {
OPM_THROW(std::logic_error, "Error openclSolver is selected but no OpenCL devices are found");
}
out << "Found " << devices.size() << " OpenCL devices" << "\n";

View File

@@ -137,14 +137,14 @@ AdaptiveSimulatorTimer& AdaptiveSimulatorTimer::operator++ ()
/// \brief return max step length used so far
double AdaptiveSimulatorTimer::maxStepLength () const
{
if( steps_.size() == 0 ) return 0.0;
if( steps_.empty() ) return 0.0;
return *(std::max_element( steps_.begin(), steps_.end() ));
}
/// \brief return min step length used so far
double AdaptiveSimulatorTimer::minStepLength () const
{
if( steps_.size() == 0 ) return 0.0;
if( steps_.empty() ) return 0.0;
return *(std::min_element( steps_.begin(), steps_.end() ));
}

View File

@@ -705,11 +705,11 @@ GasLiftStage2::
removeSurplusALQ_(const Group &group,
std::vector<GradPair> &inc_grads, std::vector<GradPair> &dec_grads)
{
if (dec_grads.size() == 0) {
if (dec_grads.empty()) {
displayDebugMessage2B_("no wells to remove ALQ from. Skipping");
return;
}
assert(dec_grads.size() > 0);
assert(!dec_grads.empty());
const auto &gl_group = this->glo_.group(group.name());
const auto &max_glift = gl_group.max_lift_gas();
const auto controls = group.productionControls(this->summary_state_);
@@ -760,7 +760,7 @@ removeSurplusALQ_(const Group &group,
// NOTE: recalculateGradientAndUpdateData_() will remove the current gradient
// from dec_grads if it cannot calculate a new decremental gradient.
// This will invalidate dec_grad_itr and well_name
if (dec_grads.size() == 0) stop_iteration = true;
if (dec_grads.empty()) stop_iteration = true;
++state.it;
}
else {
@@ -907,7 +907,7 @@ std::pair<std::optional<GasLiftStage2::GradPairItr>,
GasLiftStage2::OptimizeState::
getEcoGradients(std::vector<GradPair> &inc_grads, std::vector<GradPair> &dec_grads)
{
if (inc_grads.size() > 0 && dec_grads.size() > 0) {
if (!inc_grads.empty() && !dec_grads.empty()) {
this->parent.sortGradients_(inc_grads);
this->parent.sortGradients_(dec_grads);
// The largest incremental gradient is the last element

View File

@@ -65,7 +65,7 @@ void WellState::base_init(const std::vector<double>& cellPressures,
// Setup wellname -> well index mapping.
const int num_perf_this_well = well_perf_data[w].size();
std::string name = well.name();
assert( name.size() > 0 );
assert( !name.empty() );
mapentry_t& wellMapEntry = wellMap_[name];
wellMapEntry[ 0 ] = w;
wellMapEntry[ 1 ] = connpos;