diff --git a/.clang-tidy b/palace/.clang-tidy similarity index 58% rename from .clang-tidy rename to palace/.clang-tidy index e9478297e..25e1d1ced 100644 --- a/.clang-tidy +++ b/palace/.clang-tidy @@ -10,15 +10,27 @@ Checks: > -modernize-use-using, cppcoreguidelines-*, -cppcoreguidelines-avoid-c-arrays, + -cppcoreguidelines-avoid-const-or-ref-data-members, + -cppcoreguidelines-avoid-do-while, -cppcoreguidelines-avoid-magic-numbers, -cppcoreguidelines-init-variables, -cppcoreguidelines-macro-usage, -cppcoreguidelines-non-private-member-variables-in-classes, -cppcoreguidelines-pro-*, + -cppcoreguidelines-special-member-functions, + -cppcoreguidelines-owning-memory, + -cppcoreguidelines-use-default-member-init, + -cppcoreguidelines-narrowing-conversions, bugprone-*, -bugprone-easily-swappable-parameters, -bugprone-reserved-identifier, + -bugprone-implicit-widening-of-multiplication-result, + -bugprone-multi-level-implicit-pointer-conversion, + -bugprone-branch-clone, + -bugprone-narrowing-conversions, readability-*, + -readability-avoid-unconditional-preprocessor-if, + -readability-avoid-nested-conditional-operator, -readability-convert-member-functions-to-static, -readability-else-after-return, -readability-function-cognitive-complexity, @@ -29,10 +41,13 @@ Checks: > -readability-named-parameter, -readability-redundant-*, -readability-string-compare, + -readability-simplify-boolean-expr, performance-*, + -performance-inefficient-string-concatenation, + -performance-unnecessary-value-param, mpi-*, openmp-*' WarningsAsErrors: >- - performance-enum-size -HeaderFilterRegex: 'palace/drivers|palace/fem|palace/linalg|palace/utils' + performance-enum-size +HeaderFilterRegex: "palace/(drivers|fem|linalg|utils)" FormatStyle: 'file' diff --git a/palace/drivers/basesolver.cpp b/palace/drivers/basesolver.cpp index 6cf3f80de..d36666767 100644 --- a/palace/drivers/basesolver.cpp +++ b/palace/drivers/basesolver.cpp @@ -33,7 +33,7 @@ namespace std::string GetPostDir(const std::string &output) { - return (output.length() > 0 && output.back() != '/') ? output + '/' : output; + return (!output.empty() && output.back() != '/') ? output + '/' : output; } std::string GetIterationPostDir(const std::string &output, int step, int width) @@ -118,7 +118,7 @@ BaseSolver::BaseSolver(const IoData &iodata, bool root, int size, int num_thread } // Initialize simulation metadata for this simulation. - if (root && post_dir.length() > 0) + if (root && !post_dir.empty()) { json meta; if (git_tag) @@ -259,7 +259,7 @@ void BaseSolver::SolveEstimateMarkRefine(std::vector> &mes void BaseSolver::SaveMetadata(const FiniteElementSpaceHierarchy &fespaces) const { - if (post_dir.length() == 0) + if (post_dir.empty()) { return; } @@ -284,7 +284,7 @@ void BaseSolver::SaveMetadata(const FiniteElementSpaceHierarchy &fespaces) const template void BaseSolver::SaveMetadata(const SolverType &ksp) const { - if (post_dir.length() == 0) + if (post_dir.empty()) { return; } @@ -299,7 +299,7 @@ void BaseSolver::SaveMetadata(const SolverType &ksp) const void BaseSolver::SaveMetadata(const Timer &timer) const { - if (post_dir.length() == 0) + if (post_dir.empty()) { return; } @@ -355,7 +355,7 @@ void BaseSolver::PostprocessDomains(const PostOperator &post_op, const std::stri { // If domains have been specified for postprocessing, compute the corresponding values // and write out to disk. - if (post_dir.length() == 0) + if (post_dir.empty()) { return; } @@ -434,7 +434,7 @@ void BaseSolver::PostprocessSurfaces(const PostOperator &post_op, const std::str // If surfaces have been specified for postprocessing, compute the corresponding values // and write out to disk. The passed in E_elec is the sum of the E-field and lumped // capacitor energies, and E_mag is the same for the B-field and lumped inductors. - if (post_dir.length() == 0) + if (post_dir.empty()) { return; } @@ -581,13 +581,13 @@ void BaseSolver::PostprocessProbes(const PostOperator &post_op, const std::strin #if defined(MFEM_USE_GSLIB) // If probe locations have been specified for postprocessing, compute the corresponding // field values and write out to disk. - if (post_dir.length() == 0) + if (post_dir.empty()) { return; } // Write the computed field values at probe locations. - if (post_op.GetProbes().size() == 0) + if (post_op.GetProbes().empty()) { return; } @@ -749,7 +749,7 @@ void BaseSolver::PostprocessFields(const PostOperator &post_op, int step, double { // Save the computed fields in parallel in format for viewing with ParaView. BlockTimer bt(Timer::IO); - if (post_dir.length() == 0) + if (post_dir.empty()) { Mpi::Warning(post_op.GetComm(), "No file specified under [\"Problem\"][\"Output\"]!\nSkipping saving of " @@ -765,7 +765,7 @@ void BaseSolver::PostprocessErrorIndicator(const PostOperator &post_op, bool fields) const { // Write the indicator statistics. - if (post_dir.length() == 0) + if (post_dir.empty()) { return; } diff --git a/palace/drivers/drivensolver.cpp b/palace/drivers/drivensolver.cpp index c447b8c24..817e460ea 100644 --- a/palace/drivers/drivensolver.cpp +++ b/palace/drivers/drivensolver.cpp @@ -465,7 +465,7 @@ void DrivenSolver::PostprocessCurrents(const PostOperator &post_op, double omega) const { // Postprocess the frequency domain surface current excitations. - if (post_dir.length() == 0) + if (post_dir.empty()) { return; } @@ -516,7 +516,7 @@ void DrivenSolver::PostprocessPorts(const PostOperator &post_op, { // Postprocess the frequency domain lumped port voltages and currents (complex magnitude // = sqrt(2) * RMS). - if (post_dir.length() == 0) + if (post_dir.empty()) { return; } @@ -725,7 +725,7 @@ void DrivenSolver::PostprocessSParameters(const PostOperator &post_op, } // Print table to file. - if (root && post_dir.length() > 0) + if (root && !post_dir.empty()) { std::string path = post_dir + "port-S.csv"; auto output = OutputFile(path, (step > 0)); diff --git a/palace/drivers/eigensolver.cpp b/palace/drivers/eigensolver.cpp index 8f12cba7e..ed5d84aff 100644 --- a/palace/drivers/eigensolver.cpp +++ b/palace/drivers/eigensolver.cpp @@ -414,7 +414,7 @@ void EigenSolver::PostprocessEigen(int i, std::complex omega, double err } // Print table to file. - if (root && post_dir.length() > 0) + if (root && !post_dir.empty()) { std::string path = post_dir + "eig.csv"; auto output = OutputFile(path, (i > 0)); @@ -447,7 +447,7 @@ void EigenSolver::PostprocessPorts(const PostOperator &post_op, { // Postprocess the frequency domain lumped port voltages and currents (complex magnitude // = sqrt(2) * RMS). - if (post_dir.length() == 0) + if (post_dir.empty()) { return; } @@ -538,7 +538,7 @@ void EigenSolver::PostprocessEPR(const PostOperator &post_op, { // If ports have been specified in the model, compute the corresponding energy- // participation ratios (EPR) and write out to disk. - if (post_dir.length() == 0) + if (post_dir.empty()) { return; } diff --git a/palace/drivers/electrostaticsolver.cpp b/palace/drivers/electrostaticsolver.cpp index a57e13e8d..4eab8d5be 100644 --- a/palace/drivers/electrostaticsolver.cpp +++ b/palace/drivers/electrostaticsolver.cpp @@ -163,7 +163,7 @@ void ElectrostaticSolver::PostprocessTerminals( Cinv.Invert(); // In-place, uses LAPACK (when available) and should be cheap // Only root writes to disk (every process has full matrices). - if (!root || post_dir.length() == 0) + if (!root || post_dir.empty()) { return; } diff --git a/palace/drivers/magnetostaticsolver.cpp b/palace/drivers/magnetostaticsolver.cpp index d8701385f..f0f224690 100644 --- a/palace/drivers/magnetostaticsolver.cpp +++ b/palace/drivers/magnetostaticsolver.cpp @@ -171,7 +171,7 @@ void MagnetostaticSolver::PostprocessTerminals(PostOperator &post_op, Minv.Invert(); // In-place, uses LAPACK (when available) and should be cheap // Only root writes to disk (every process has full matrices). - if (!root || post_dir.length() == 0) + if (!root || post_dir.empty()) { return; } diff --git a/palace/drivers/transientsolver.cpp b/palace/drivers/transientsolver.cpp index 77093c467..edc9eac2b 100644 --- a/palace/drivers/transientsolver.cpp +++ b/palace/drivers/transientsolver.cpp @@ -304,7 +304,7 @@ void TransientSolver::PostprocessCurrents(const PostOperator &post_op, double t, double J_coef) const { // Postprocess the time domain surface current excitations. - if (post_dir.length() == 0) + if (post_dir.empty()) { return; } @@ -355,7 +355,7 @@ void TransientSolver::PostprocessPorts(const PostOperator &post_op, { // Postprocess the time domain lumped port voltages and currents, which can then be used // to compute S- or Z-parameters. - if (post_dir.length() == 0) + if (post_dir.empty()) { return; } diff --git a/palace/fem/fespace.cpp b/palace/fem/fespace.cpp index 3f45893e1..0e9dff579 100644 --- a/palace/fem/fespace.cpp +++ b/palace/fem/fespace.cpp @@ -121,9 +121,8 @@ void FiniteElementSpace::ResetCeedObjects() restr.clear(); interp_restr.clear(); interp_range_restr.clear(); - for (std::size_t i = 0; i < ceed::internal::GetCeedObjects().size(); i++) + for (const auto& ceed : ceed::internal::GetCeedObjects()) { - Ceed ceed = ceed::internal::GetCeedObjects()[i]; basis.emplace(ceed, ceed::GeometryObjectMap()); restr.emplace(ceed, ceed::GeometryObjectMap()); interp_restr.emplace(ceed, ceed::GeometryObjectMap()); diff --git a/palace/fem/fespace.hpp b/palace/fem/fespace.hpp index daa6b1c72..fc2317b08 100644 --- a/palace/fem/fespace.hpp +++ b/palace/fem/fespace.hpp @@ -42,7 +42,7 @@ class FiniteElementSpace { // For interpolation operators and tensor-product elements, we need native (not // lexicographic) ordering. - const mfem::TensorBasisElement *tfe = + const auto *tfe = dynamic_cast(&fe); return (tfe && tfe->GetDofMap().Size() > 0 && fe.GetRangeType() != mfem::FiniteElement::VECTOR); diff --git a/palace/fem/interpolator.cpp b/palace/fem/interpolator.cpp index a24abc25f..224455d61 100644 --- a/palace/fem/interpolator.cpp +++ b/palace/fem/interpolator.cpp @@ -10,6 +10,7 @@ namespace palace { +using std::vector; #if defined(MFEM_USE_GSLIB) InterpolationOperator::InterpolationOperator(const IoData &iodata, mfem::ParMesh &mesh) @@ -103,7 +104,7 @@ std::vector> InterpolationOperator::ProbeField(const GridFu } else { - return std::vector>(vr.begin(), vr.end()); + return {vr.begin(), vr.end()}; } } diff --git a/palace/fem/libceed/ceed.cpp b/palace/fem/libceed/ceed.cpp index 1050f7f1a..74b428a7f 100644 --- a/palace/fem/libceed/ceed.cpp +++ b/palace/fem/libceed/ceed.cpp @@ -12,7 +12,7 @@ namespace palace::ceed namespace internal { -static std::vector ceeds; +static std::vector ceeds; // NOLINT const std::vector &GetCeedObjects() { @@ -37,11 +37,10 @@ void Initialize(const char *resource, const char *jit_source_dir) // Master thread initializes all Ceed objects (ineherently sequential anyway due to shared // resources). - for (std::size_t i = 0; i < internal::ceeds.size(); i++) + for (auto &ceed : internal::ceeds) { - int ierr = CeedInit(resource, &internal::ceeds[i]); + int ierr = CeedInit(resource, &ceed); MFEM_VERIFY(!ierr, "Failed to initialize libCEED with resource " << resource << "!"); - Ceed ceed = internal::ceeds[i]; // Configure error handling (allow errors to be handled by PalaceCeedCallBackend or // PalaceCeedCall). @@ -58,7 +57,7 @@ void Initialize(const char *resource, const char *jit_source_dir) void Finalize() { // Destroy Ceed context(s). - for (std::size_t i = 0; i < internal::ceeds.size(); i++) + for (std::size_t i = 0; i < internal::ceeds.size(); i++) // NOLINT { int ierr = CeedDestroy(&internal::ceeds[i]); MFEM_VERIFY(!ierr, "Failed to finalize libCEED!"); @@ -68,12 +67,12 @@ void Finalize() std::string Print() { - MFEM_VERIFY(internal::GetCeedObjects().size() > 0, + MFEM_VERIFY(!internal::GetCeedObjects().empty(), "libCEED must be initialized before querying the active backend!"); Ceed ceed = internal::GetCeedObjects()[0]; const char *ceed_resource; PalaceCeedCall(ceed, CeedGetResource(ceed, &ceed_resource)); - return std::string(ceed_resource); + return {ceed_resource}; } void InitCeedVector(const mfem::Vector &v, Ceed ceed, CeedVector *cv, bool init) diff --git a/palace/fem/libceed/operator.cpp b/palace/fem/libceed/operator.cpp index 8fdc162bd..ccd87ee32 100644 --- a/palace/fem/libceed/operator.cpp +++ b/palace/fem/libceed/operator.cpp @@ -230,7 +230,7 @@ namespace int CeedInternalCallocArray(size_t n, size_t unit, void *p) { - *(void **)p = calloc(n, unit); + *(void **)p = calloc(n, unit); // NOLINT MFEM_ASSERT(!n || !unit || *(void **)p, "calloc failed to allocate " << n << " members of size " << unit << "!"); return 0; @@ -238,7 +238,7 @@ int CeedInternalCallocArray(size_t n, size_t unit, void *p) int CeedInternalFree(void *p) { - free(*(void **)p); + free(*(void **)p); // NOLINT *(void **)p = nullptr; return 0; } diff --git a/palace/fem/libceed/restriction.cpp b/palace/fem/libceed/restriction.cpp index 130308397..e6a3d6c6e 100644 --- a/palace/fem/libceed/restriction.cpp +++ b/palace/fem/libceed/restriction.cpp @@ -20,7 +20,7 @@ void InitLexicoRestr(const mfem::FiniteElementSpace &fespace, const mfem::FiniteElement &fe = use_bdr ? *fespace.GetBE(indices[0]) : *fespace.GetFE(indices[0]); const int P = fe.GetDof(); - const mfem::TensorBasisElement *tfe = dynamic_cast(&fe); + const auto *tfe = dynamic_cast(&fe); const mfem::Array &dof_map = tfe->GetDofMap(); const CeedInt comp_stride = (fespace.GetVDim() == 1 || fespace.GetOrdering() == mfem::Ordering::byVDIM) @@ -260,7 +260,7 @@ void InitRestriction(const mfem::FiniteElementSpace &fespace, } const mfem::FiniteElement &fe = use_bdr ? *fespace.GetBE(indices[0]) : *fespace.GetFE(indices[0]); - const mfem::TensorBasisElement *tfe = dynamic_cast(&fe); + const auto *tfe = dynamic_cast(&fe); const bool vector = fe.GetRangeType() == mfem::FiniteElement::VECTOR; const bool lexico = (tfe && tfe->GetDofMap().Size() > 0 && !vector && !is_interp); if (lexico) diff --git a/palace/fem/mesh.cpp b/palace/fem/mesh.cpp index 946b8df60..a9fff84f6 100644 --- a/palace/fem/mesh.cpp +++ b/palace/fem/mesh.cpp @@ -121,10 +121,10 @@ auto GetElementIndices(const mfem::ParMesh &mesh, bool use_bdr, int start, int s // Populate the indices arrays for each element geometry. std::unordered_map offsets; std::unordered_map> element_indices; - for (auto it = counts.begin(); it != counts.end(); ++it) + for (const auto &it : counts) { - offsets[it->first] = 0; - element_indices[it->first].resize(it->second); + offsets[it.first] = 0; + element_indices[it.first].resize(it.second); } for (int i = start; i < stop; i++) { @@ -335,9 +335,8 @@ void Mesh::ResetCeedObjects() } } geom_data.clear(); - for (std::size_t i = 0; i < ceed::internal::GetCeedObjects().size(); i++) + for ( const auto &ceed : ceed::internal::GetCeedObjects() ) { - Ceed ceed = ceed::internal::GetCeedObjects()[i]; geom_data.emplace(ceed, ceed::GeometryObjectMap()); } } diff --git a/palace/linalg/arpack.hpp b/palace/linalg/arpack.hpp index 0f37cf944..483b82a67 100644 --- a/palace/linalg/arpack.hpp +++ b/palace/linalg/arpack.hpp @@ -14,10 +14,7 @@ #include "linalg/operator.hpp" #include "linalg/vector.hpp" -namespace palace -{ - -namespace arpack +namespace palace::arpack { // @@ -242,9 +239,7 @@ class ArpackPEPSolver : public ArpackEigenvalueSolver int Solve() override; }; -} // namespace arpack - -} // namespace palace +} // namespace palace::arpack #endif diff --git a/palace/linalg/hypre.cpp b/palace/linalg/hypre.cpp index 1889ad2ea..ae44ab2a9 100644 --- a/palace/linalg/hypre.cpp +++ b/palace/linalg/hypre.cpp @@ -91,7 +91,7 @@ void HypreCSRMatrix::AssembleDiagonal(Vector &diag) const namespace { -static HypreVector X, Y; +static HypreVector X, Y; // NOLINT } // namespace diff --git a/palace/linalg/hypre.hpp b/palace/linalg/hypre.hpp index 18c946049..7755f186c 100644 --- a/palace/linalg/hypre.hpp +++ b/palace/linalg/hypre.hpp @@ -56,7 +56,7 @@ class HypreCSRMatrix : public palace::Operator HypreCSRMatrix(int h, int w, int nnz); HypreCSRMatrix(hypre_CSRMatrix *mat); HypreCSRMatrix(const mfem::SparseMatrix &m); - ~HypreCSRMatrix(); + ~HypreCSRMatrix() override; auto NNZ() const { return hypre_CSRMatrixNumNonzeros(mat); } diff --git a/palace/linalg/rap.cpp b/palace/linalg/rap.cpp index 070358e2f..31fece0fd 100644 --- a/palace/linalg/rap.cpp +++ b/palace/linalg/rap.cpp @@ -111,7 +111,7 @@ mfem::HypreParMatrix &ParOperator::ParallelAssemble(bool skip_zeros) const } else { - mfem::HypreParMatrix *hR = new mfem::HypreParMatrix( + auto *hR = new mfem::HypreParMatrix( test_fespace.GetComm(), test_fespace.GlobalTrueVSize(), test_fespace.GlobalVSize(), test_fespace.Get().GetTrueDofOffsets(), test_fespace.Get().GetDofOffsets(), const_cast(test_fespace.GetRestrictionMatrix())); diff --git a/palace/linalg/solver.cpp b/palace/linalg/solver.cpp index 7ea33e07b..74ac74fd1 100644 --- a/palace/linalg/solver.cpp +++ b/palace/linalg/solver.cpp @@ -33,8 +33,8 @@ void MfemWrapperSolver::SetOperator(const ComplexOperator &op) { // Assemble the real and imaginary parts, then add. // XX TODO: Test complex matrix assembly if coarse solve supports it - const mfem::HypreParMatrix *hAr = dynamic_cast(op.Real()); - const mfem::HypreParMatrix *hAi = dynamic_cast(op.Imag()); + const auto *hAr = dynamic_cast(op.Real()); + const auto *hAi = dynamic_cast(op.Imag()); const ParOperator *PtAPr = nullptr, *PtAPi = nullptr; if (op.Real() && !hAr) { diff --git a/palace/linalg/solver.hpp b/palace/linalg/solver.hpp index 60983314b..031a0feae 100644 --- a/palace/linalg/solver.hpp +++ b/palace/linalg/solver.hpp @@ -34,7 +34,7 @@ class Solver : public OperType public: Solver(bool initial_guess = false) : OperType(), initial_guess(initial_guess) {} - virtual ~Solver() = default; + ~Solver() override = default; // Configure whether or not to use an initial guess when applying the solver. virtual void SetInitialGuess(bool guess) { initial_guess = guess; } diff --git a/palace/main.cpp b/palace/main.cpp index ac3cfebf2..a38c36a88 100644 --- a/palace/main.cpp +++ b/palace/main.cpp @@ -167,7 +167,7 @@ static void PrintPalaceBanner(MPI_Comm comm) static void PrintPalaceInfo(MPI_Comm comm, int np, int nt, int ngpu, mfem::Device &device) { - if (std::strcmp(GetPalaceGitTag(), "UNKNOWN")) + if (std::strcmp(GetPalaceGitTag(), "UNKNOWN") != 0) { Mpi::Print(comm, "Git changeset ID: {}\n", GetPalaceGitTag()); } diff --git a/palace/models/domainpostoperator.hpp b/palace/models/domainpostoperator.hpp index 4745c3be1..f20e2222f 100644 --- a/palace/models/domainpostoperator.hpp +++ b/palace/models/domainpostoperator.hpp @@ -48,7 +48,7 @@ class DomainPostOperator // Get volume integrals for the electric or magnetic field energy in a portion of the // domain. double GetDomainElectricFieldEnergy(int idx, const GridFunction &E) const; - double GetDomainMagneticFieldEnergy(int idx, const GridFunction &E) const; + double GetDomainMagneticFieldEnergy(int idx, const GridFunction &B) const; }; } // namespace palace diff --git a/palace/models/materialoperator.cpp b/palace/models/materialoperator.cpp index 2af6efdd5..87c6884d1 100644 --- a/palace/models/materialoperator.cpp +++ b/palace/models/materialoperator.cpp @@ -298,11 +298,11 @@ mfem::Array MaterialOperator::GetBdrAttributeToMaterial() const bdr_attr_mat = -1; for (const auto &[attr, bdr_attr_map] : mesh.GetCeedBdrAttributes()) { - for (auto it = bdr_attr_map.begin(); it != bdr_attr_map.end(); ++it) + for (const auto &it : bdr_attr_map) { - MFEM_ASSERT(it->second > 0 && it->second <= bdr_attr_mat.Size(), - "Invalid libCEED boundary attribute " << it->second << "!"); - bdr_attr_mat[it->second - 1] = AttrToMat(it->first); + MFEM_ASSERT(it.second > 0 && it.second <= bdr_attr_mat.Size(), + "Invalid libCEED boundary attribute " << it.second << "!"); + bdr_attr_mat[it.second - 1] = AttrToMat(it.first); } } return bdr_attr_mat; diff --git a/palace/models/spaceoperator.cpp b/palace/models/spaceoperator.cpp index 52066cad9..bffedd71a 100644 --- a/palace/models/spaceoperator.cpp +++ b/palace/models/spaceoperator.cpp @@ -667,7 +667,7 @@ auto BuildLevelParOperator(std::unique_ptr &&br, std::unique_ptr auto BuildLevelParOperator(std::unique_ptr &&br, - std::unique_ptr &&bi, + std::unique_ptr &&bi, //NOLINT const FiniteElementSpace &fespace) { MFEM_VERIFY( diff --git a/palace/utils/configfile.cpp b/palace/utils/configfile.cpp index 3386211fc..bcf5107ee 100644 --- a/palace/utils/configfile.cpp +++ b/palace/utils/configfile.cpp @@ -109,12 +109,12 @@ void ParseElementData(json &elem, const std::string &name, bool required, direction = elem.value(name, direction); for (auto &c : direction) { - c = std::tolower(c); + c = std::tolower(c); //NOLINT } - const auto xpos = direction.find("x"); - const auto ypos = direction.find("y"); - const auto zpos = direction.find("z"); - const auto rpos = direction.find("r"); + const auto xpos = direction.find('x'); + const auto ypos = direction.find('y'); + const auto zpos = direction.find('z'); + const auto rpos = direction.find('r'); const bool xfound = xpos != std::string::npos; const bool yfound = ypos != std::string::npos; const bool zfound = zpos != std::string::npos; diff --git a/palace/utils/dorfler.cpp b/palace/utils/dorfler.cpp index bb4e5384c..2688b1c37 100644 --- a/palace/utils/dorfler.cpp +++ b/palace/utils/dorfler.cpp @@ -32,10 +32,10 @@ std::array ComputeDorflerThreshold(MPI_Comm comm, const Vector &e, } // The pivot is the first point which leaves (1-θ) of the total sum after it. - const double local_total = sum.size() > 0 ? sum.back() : 0.0; + const double local_total = sum.empty() ? 0.0 : sum.back(); auto pivot = std::lower_bound(sum.begin(), sum.end(), (1 - fraction) * local_total); auto index = std::distance(sum.begin(), pivot); - double error_threshold = estimates.size() > 0 ? estimates[index] : 0.0; + double error_threshold = estimates.empty() ? 0.0 : estimates[index]; // Compute the number of elements, and amount of error, marked by threshold value e. auto Marked = [&estimates, &sum, &local_total](double e) -> std::pair @@ -85,7 +85,7 @@ std::array ComputeDorflerThreshold(MPI_Comm comm, const Vector &e, Mpi::GlobalSum(3, &error.total, comm); const double max_indicator = [&]() { - double max_indicator = estimates.size() > 0 ? estimates.back() : 0.0; + double max_indicator = estimates.empty() ? 0.0 : estimates.back(); Mpi::GlobalMax(1, &max_indicator, comm); return max_indicator; }(); diff --git a/palace/utils/geodata.cpp b/palace/utils/geodata.cpp index 487ef4c80..29f3fb811 100644 --- a/palace/utils/geodata.cpp +++ b/palace/utils/geodata.cpp @@ -1718,7 +1718,7 @@ std::unique_ptr GetMeshPartitioning(const mfem::Mesh &mesh, int size, { MFEM_VERIFY(size <= mesh.GetNE(), "Mesh partitioning must have parts <= mesh elements (" << size << " vs. " << mesh.GetNE() << ")!"); - if (partition.length() == 0) + if (partition.empty()) { const int part_method = 1; std::unique_ptr partitioning( diff --git a/palace/utils/iodata.cpp b/palace/utils/iodata.cpp index 98a5a2380..c211e58a8 100644 --- a/palace/utils/iodata.cpp +++ b/palace/utils/iodata.cpp @@ -171,7 +171,7 @@ IoData::IoData(const char *filename, bool print) switch (event) { case json::parse_event_t::object_start: - parse_stack.push(std::set()); + parse_stack.emplace(); break; case json::parse_event_t::object_end: parse_stack.pop(); diff --git a/palace/utils/meshio.cpp b/palace/utils/meshio.cpp index 8aa1f6c62..456e238c5 100644 --- a/palace/utils/meshio.cpp +++ b/palace/utils/meshio.cpp @@ -261,7 +261,7 @@ inline std::string ReadStringComsolBinary(std::istream &input) input.read(reinterpret_cast(&n), sizeof(int)); std::vector vstr(n); input.read(reinterpret_cast(vstr.data()), (std::streamsize)(n * sizeof(int))); - return std::string(vstr.begin(), vstr.end()); + return {vstr.begin(), vstr.end()}; } // Nastran has a special floating point format: "-7.-1" instead of "-7.E-01" or "2.3+2" @@ -284,7 +284,7 @@ inline double ConvertDoubleNastran(const std::string &str) { fstr.replace(pos, 1, "E+"); } - else if ((pos = fstr.find('-', 1)) != std::string::npos) + else if ((pos = fstr.find('-', 1)) != std::string::npos) // NOLINT { fstr.replace(pos, 1, "E-"); } @@ -936,7 +936,7 @@ void ConvertMeshNastran(const std::string &filename, std::ostream &buffer, while (true) { auto line = GetLineNastran(input); - if (line.length() > 0) + if (!line.empty()) { if (!line.compare("BEGIN BULK")) { @@ -954,7 +954,7 @@ void ConvertMeshNastran(const std::string &filename, std::ostream &buffer, while (true) { auto line = GetLineNastran(input); - if (line.length() > 0) + if (!line.empty()) { if (!line.compare("ENDDATA")) { @@ -1007,7 +1007,7 @@ void ConvertMeshNastran(const std::string &filename, std::ostream &buffer, ConvertDoubleNastran(line.substr(5 * NASTRAN_CHUNK, NASTRAN_CHUNK))}); } } - else if ((elem_type = ElemTypeNastran(line))) + else if ((elem_type = ElemTypeNastran(line))) // NOLINT { // Prepare to parse the element ID and nodes. const bool free = (line.find_first_of(',') != std::string::npos); diff --git a/palace/utils/timer.hpp b/palace/utils/timer.hpp index e674cbf0e..a9a0c3f6d 100644 --- a/palace/utils/timer.hpp +++ b/palace/utils/timer.hpp @@ -218,7 +218,7 @@ class BlockTimer } // clang-format off Mpi::Print(comm, "{:<{}s}{:{}.{}f}{:{}.{}f}{:{}.{}f}\n", - timer.descriptions[i], h, + timer.descriptions[i], h, //NOLINT data_min[i], w, p, data_max[i], w, p, data_avg[i], w, p); // clang-format on }