Skip to content

Commit

Permalink
[clang-tidy] Different fixes and change of active checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaraslaut committed Jul 19, 2024
1 parent 5e62b99 commit 6567b13
Show file tree
Hide file tree
Showing 30 changed files with 87 additions and 79 deletions.
19 changes: 17 additions & 2 deletions .clang-tidy → palace/.clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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'
22 changes: 11 additions & 11 deletions palace/drivers/basesolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -259,7 +259,7 @@ void BaseSolver::SolveEstimateMarkRefine(std::vector<std::unique_ptr<Mesh>> &mes

void BaseSolver::SaveMetadata(const FiniteElementSpaceHierarchy &fespaces) const
{
if (post_dir.length() == 0)
if (post_dir.empty())
{
return;
}
Expand All @@ -284,7 +284,7 @@ void BaseSolver::SaveMetadata(const FiniteElementSpaceHierarchy &fespaces) const
template <typename SolverType>
void BaseSolver::SaveMetadata(const SolverType &ksp) const
{
if (post_dir.length() == 0)
if (post_dir.empty())
{
return;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 "
Expand All @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions palace/drivers/drivensolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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));
Expand Down
6 changes: 3 additions & 3 deletions palace/drivers/eigensolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ void EigenSolver::PostprocessEigen(int i, std::complex<double> 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));
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion palace/drivers/electrostaticsolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion palace/drivers/magnetostaticsolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions palace/drivers/transientsolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 1 addition & 2 deletions palace/fem/fespace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CeedBasis>());
restr.emplace(ceed, ceed::GeometryObjectMap<CeedElemRestriction>());
interp_restr.emplace(ceed, ceed::GeometryObjectMap<CeedElemRestriction>());
Expand Down
2 changes: 1 addition & 1 deletion palace/fem/fespace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const mfem::TensorBasisElement *>(&fe);
return (tfe && tfe->GetDofMap().Size() > 0 &&
fe.GetRangeType() != mfem::FiniteElement::VECTOR);
Expand Down
3 changes: 2 additions & 1 deletion palace/fem/interpolator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace palace
{
using std::vector;

#if defined(MFEM_USE_GSLIB)
InterpolationOperator::InterpolationOperator(const IoData &iodata, mfem::ParMesh &mesh)
Expand Down Expand Up @@ -103,7 +104,7 @@ std::vector<std::complex<double>> InterpolationOperator::ProbeField(const GridFu
}
else
{
return std::vector<std::complex<double>>(vr.begin(), vr.end());
return {vr.begin(), vr.end()};
}
}

Expand Down
13 changes: 6 additions & 7 deletions palace/fem/libceed/ceed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace palace::ceed
namespace internal
{

static std::vector<Ceed> ceeds;
static std::vector<Ceed> ceeds; // NOLINT

const std::vector<Ceed> &GetCeedObjects()
{
Expand All @@ -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).
Expand All @@ -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!");
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions palace/fem/libceed/operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,15 @@ 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;
}

int CeedInternalFree(void *p)
{
free(*(void **)p);
free(*(void **)p); // NOLINT
*(void **)p = nullptr;
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions palace/fem/libceed/restriction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const mfem::TensorBasisElement *>(&fe);
const auto *tfe = dynamic_cast<const mfem::TensorBasisElement *>(&fe);
const mfem::Array<int> &dof_map = tfe->GetDofMap();
const CeedInt comp_stride =
(fespace.GetVDim() == 1 || fespace.GetOrdering() == mfem::Ordering::byVDIM)
Expand Down Expand Up @@ -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<const mfem::TensorBasisElement *>(&fe);
const auto *tfe = dynamic_cast<const mfem::TensorBasisElement *>(&fe);
const bool vector = fe.GetRangeType() == mfem::FiniteElement::VECTOR;
const bool lexico = (tfe && tfe->GetDofMap().Size() > 0 && !vector && !is_interp);
if (lexico)
Expand Down
9 changes: 4 additions & 5 deletions palace/fem/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<mfem::Geometry::Type, int> offsets;
std::unordered_map<mfem::Geometry::Type, std::vector<int>> 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++)
{
Expand Down Expand Up @@ -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<ceed::CeedGeomFactorData>());
}
}
Expand Down
9 changes: 2 additions & 7 deletions palace/linalg/arpack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
#include "linalg/operator.hpp"
#include "linalg/vector.hpp"

namespace palace
{

namespace arpack
namespace palace::arpack
{

//
Expand Down Expand Up @@ -242,9 +239,7 @@ class ArpackPEPSolver : public ArpackEigenvalueSolver
int Solve() override;
};

} // namespace arpack

} // namespace palace
} // namespace palace::arpack

#endif

Expand Down
Loading

0 comments on commit 6567b13

Please sign in to comment.