improvements from clang-tidy

This commit is contained in:
Axel Kohlmeyer
2023-12-19 23:37:07 -05:00
parent 3237c30117
commit dedbd8f6db
16 changed files with 33 additions and 46 deletions

View File

@ -67,7 +67,7 @@ int main(int narg, char **arg)
FILE *fp; FILE *fp;
if (me == 0) { if (me == 0) {
fp = fopen(arg[2],"r"); fp = fopen(arg[2],"r");
if (fp == NULL) { if (fp == nullptr) {
printf("ERROR: Could not open LAMMPS input script\n"); printf("ERROR: Could not open LAMMPS input script\n");
MPI_Abort(MPI_COMM_WORLD,1); MPI_Abort(MPI_COMM_WORLD,1);
} }
@ -78,14 +78,14 @@ int main(int narg, char **arg)
// (could just send it to proc 0 of comm_lammps and let it Bcast) // (could just send it to proc 0 of comm_lammps and let it Bcast)
// all LAMMPS procs call input->one() on the line // all LAMMPS procs call input->one() on the line
LAMMPS *lmp = NULL; LAMMPS *lmp = nullptr;
if (lammps == 1) lmp = new LAMMPS(0,NULL,comm_lammps); if (lammps == 1) lmp = new LAMMPS(0,nullptr,comm_lammps);
int n; int n;
char line[1024]; char line[1024];
while (1) { while (true) {
if (me == 0) { if (me == 0) {
if (fgets(line,1024,fp) == NULL) n = 0; if (fgets(line,1024,fp) == nullptr) n = 0;
else n = strlen(line) + 1; else n = strlen(line) + 1;
if (n == 0) fclose(fp); if (n == 0) fclose(fp);
} }
@ -101,8 +101,8 @@ int main(int narg, char **arg)
// put coords back into LAMMPS // put coords back into LAMMPS
// run a single step with changed coords // run a single step with changed coords
double *x = NULL; double *x = nullptr;
double *v = NULL; double *v = nullptr;
if (lammps == 1) { if (lammps == 1) {
lmp->input->one("run 10"); lmp->input->one("run 10");
@ -147,7 +147,7 @@ int main(int narg, char **arg)
// create_atoms() to create new ones with old coords, vels // create_atoms() to create new ones with old coords, vels
// initial thermo should be same as step 20 // initial thermo should be same as step 20
int *type = NULL; int *type = nullptr;
if (lammps == 1) { if (lammps == 1) {
int natoms = static_cast<int> (lmp->atom->natoms); int natoms = static_cast<int> (lmp->atom->natoms);
@ -155,7 +155,7 @@ int main(int narg, char **arg)
for (int i = 0; i < natoms; i++) type[i] = 1; for (int i = 0; i < natoms; i++) type[i] = 1;
lmp->input->one("delete_atoms group all"); lmp->input->one("delete_atoms group all");
lammps_create_atoms(lmp,natoms,NULL,type,x,v,NULL,0); lammps_create_atoms(lmp,natoms,nullptr,type,x,v,nullptr,0);
lmp->input->one("run 10"); lmp->input->one("run 10");
} }

View File

@ -1076,7 +1076,6 @@ void FixTGNHDrude::couple()
void FixTGNHDrude::remap() void FixTGNHDrude::remap()
{ {
int i;
double oldlo,oldhi; double oldlo,oldhi;
double expfac; double expfac;

View File

@ -73,10 +73,7 @@ ComputePACE::ComputePACE(LAMMPS *lmp, int narg, char **arg) :
auto potential_file_name = utils::get_potential_file_path(arg[3]); auto potential_file_name = utils::get_potential_file_path(arg[3]);
delete acecimpl->basis_set; delete acecimpl->basis_set;
acecimpl->basis_set = new ACECTildeBasisSet(potential_file_name); acecimpl->basis_set = new ACECTildeBasisSet(potential_file_name);
double cut = acecimpl->basis_set->cutoffmax;
cutmax = acecimpl->basis_set->cutoffmax; cutmax = acecimpl->basis_set->cutoffmax;
double cuti;
double radelemall = 0.5;
//# of rank 1, rank > 1 functions //# of rank 1, rank > 1 functions
@ -178,7 +175,6 @@ void ComputePACE::init_list(int /*id*/, NeighList *ptr)
void ComputePACE::compute_array() void ComputePACE::compute_array()
{ {
int ntotal = atom->nlocal + atom->nghost; int ntotal = atom->nlocal + atom->nghost;
double **f = atom->f;
invoked_array = update->ntimestep; invoked_array = update->ntimestep;
// grow pace_peratom array if necessary // grow pace_peratom array if necessary
@ -208,9 +204,6 @@ void ComputePACE::compute_array()
// invoke full neighbor list (will copy or build if necessary) // invoke full neighbor list (will copy or build if necessary)
neighbor->build_one(list); neighbor->build_one(list);
SPECIES_TYPE *mus;
NS_TYPE *ns;
LS_TYPE *ls;
const int inum = list->inum; const int inum = list->inum;
const int* const ilist = list->ilist; const int* const ilist = list->ilist;
@ -234,7 +227,6 @@ void ComputePACE::compute_array()
// compute pace derivatives for each atom in group // compute pace derivatives for each atom in group
// use full neighbor list to count atoms less than cutoff // use full neighbor list to count atoms less than cutoff
double** const x = atom->x;
const int* const mask = atom->mask; const int* const mask = atom->mask;
const int ntypes = atom->ntypes; const int ntypes = atom->ntypes;
@ -251,8 +243,8 @@ void ComputePACE::compute_array()
delete acecimpl->ace; delete acecimpl->ace;
acecimpl->ace = new ACECTildeEvaluator(*acecimpl->basis_set); acecimpl->ace = new ACECTildeEvaluator(*acecimpl->basis_set);
acecimpl->ace->compute_projections = 1; acecimpl->ace->compute_projections = true;
acecimpl->ace->compute_b_grad = 1; acecimpl->ace->compute_b_grad = true;
int n_r1, n_rp = 0; int n_r1, n_rp = 0;
n_r1 = acecimpl->basis_set->total_basis_size_rank1[0]; n_r1 = acecimpl->basis_set->total_basis_size_rank1[0];
n_rp = acecimpl->basis_set->total_basis_size[0]; n_rp = acecimpl->basis_set->total_basis_size[0];

View File

@ -299,7 +299,7 @@ void ComputeSNAAtom::compute_peratom()
// ############################################################################## // // ############################################################################## //
// ##### Start of section for computing bispectrum on nnn nearest neighbors ##### // // ##### Start of section for computing bispectrum on nnn nearest neighbors ##### //
// ############################################################################## // // ############################################################################## //
if (nearest_neighbors_mode == true) { if (nearest_neighbors_mode) {
// ##### 1) : consider full neighbor list in rlist // ##### 1) : consider full neighbor list in rlist
memory->create(distsq, jnum, "snann/atom:distsq"); memory->create(distsq, jnum, "snann/atom:distsq");
memory->create(rlist, jnum, 3, "snann/atom:rlist"); memory->create(rlist, jnum, 3, "snann/atom:rlist");
@ -308,7 +308,6 @@ void ComputeSNAAtom::compute_peratom()
for (int jj = 0; jj < jnum; jj++) { for (int jj = 0; jj < jnum; jj++) {
int j = jlist[jj]; int j = jlist[jj];
j &= NEIGHMASK; j &= NEIGHMASK;
int jtype = type[j];
const double delx = xtmp - x[j][0]; const double delx = xtmp - x[j][0];
const double dely = ytmp - x[j][1]; const double dely = ytmp - x[j][1];
@ -614,10 +613,9 @@ double * ComputeSNAAtom::tanh_weights(double * rsq, double rcut, double delta, i
return w; return w;
} }
double ComputeSNAAtom::sum_weights(double * rsq, double * w, int ncounts) double ComputeSNAAtom::sum_weights(double * /*rsq*/, double * w, int ncounts)
{ {
double S=0.; double S=0.;
double rloc=0.;
for (int i=0; i<ncounts; i++) for (int i=0; i<ncounts; i++)
{ {
S += w[i]; S += w[i];

View File

@ -59,7 +59,7 @@ void NPairBinGhostOmp<HALF>::build(NeighList *list)
#endif #endif
NPAIR_OMP_SETUP(nall); NPAIR_OMP_SETUP(nall);
int i, j, k, n, itype, jtype, ibin, bin_start, which, imol, iatom; int i, j, k, n, itype, jtype, ibin, which, imol, iatom;
tagint tagprev; tagint tagprev;
double xtmp, ytmp, ztmp, delx, dely, delz, rsq; double xtmp, ytmp, ztmp, delx, dely, delz, rsq;
int xbin, ybin, zbin, xbin2, ybin2, zbin2; int xbin, ybin, zbin, xbin2, ybin2, zbin2;

View File

@ -34,8 +34,7 @@ using namespace ReaxFF;
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
ComputeReaxFFAtom::ComputeReaxFFAtom(LAMMPS *lmp, int narg, char **arg) : ComputeReaxFFAtom::ComputeReaxFFAtom(LAMMPS *lmp, int narg, char **arg) :
Compute(lmp, narg, arg), Compute(lmp, narg, arg), neighid(nullptr), abo(nullptr), bondcount(nullptr), reaxff(nullptr)
abo(nullptr), neighid(nullptr), bondcount(nullptr), reaxff(nullptr)
{ {
if (atom->tag_consecutive() == 0) if (atom->tag_consecutive() == 0)
error->all(FLERR, "Atom IDs must be consecutive for compute reaxff/atom"); error->all(FLERR, "Atom IDs must be consecutive for compute reaxff/atom");

View File

@ -219,7 +219,6 @@ void FixRigidNHSmall::init()
} }
} }
int icompute;
if (tcomputeflag) { if (tcomputeflag) {
temperature = modify->get_compute_by_id(id_temp); temperature = modify->get_compute_by_id(id_temp);
if (!temperature) if (!temperature)

View File

@ -709,7 +709,7 @@ void lammps_commands_string(void *handle, const char *str)
break; break;
} }
lmp->input->one(cmd.c_str()); lmp->input->one(cmd);
} }
} }
} }

View File

@ -55,9 +55,9 @@ void NStencilBin<HALF, DIM_3D, TRI>::create()
// Now only include "upper right" bins for half and ortho stencils // Now only include "upper right" bins for half and ortho stencils
if (HALF && (!DIM_3D) && (!TRI)) if (HALF && (!DIM_3D) && (!TRI))
if (! (j > 0 || (j == 0 && i > 0))) continue; if (j <= 0 && (j != 0 || i <= 0)) continue;
if (HALF && DIM_3D && (!TRI)) if (HALF && DIM_3D && (!TRI))
if (! (k > 0 || j > 0 || (j == 0 && i > 0))) continue; if (k <= 0 && j <= 0 && (j != 0 || i <= 0)) continue;
if (bin_distance(i, j, k) < cutneighmaxsq) if (bin_distance(i, j, k) < cutneighmaxsq)
stencil[nstencil++] = k * mbiny * mbinx + j * mbinx + i; stencil[nstencil++] = k * mbiny * mbinx + j * mbinx + i;

View File

@ -115,9 +115,9 @@ void NStencilMulti<HALF, DIM_3D, TRI>::create()
if (HALF && (!TRI)) { if (HALF && (!TRI)) {
if (half_flag) { if (half_flag) {
if (DIM_3D) { if (DIM_3D) {
if (! (k > 0 || j > 0 || (j == 0 && i > 0))) continue; if (k <= 0 && j <= 0 && (j != 0 || i <= 0)) continue;
} else { } else {
if (! (j > 0 || (j == 0 && i > 0))) continue; if (j <= 0 && (j != 0 || i <= 0)) continue;
} }
} }
} }

View File

@ -65,9 +65,9 @@ void NStencilMultiOld<HALF, DIM_3D, TRI>::create()
// Now only include "upper right" bins for half and ortho stencils // Now only include "upper right" bins for half and ortho stencils
if (HALF && (!DIM_3D) && (!TRI)) if (HALF && (!DIM_3D) && (!TRI))
if (! (j > 0 || (j == 0 && i > 0))) continue; if (j <= 0 && (j != 0 || i <= 0)) continue;
if (HALF && DIM_3D && (!TRI)) if (HALF && DIM_3D && (!TRI))
if (! (k > 0 || j > 0 || (j == 0 && i > 0))) continue; if (k <= 0 && j <= 0 && (j != 0 || i <= 0)) continue;
rsq = bin_distance(i, j, k); rsq = bin_distance(i, j, k);
if (rsq < typesq) { if (rsq < typesq) {

View File

@ -36,7 +36,7 @@ int main(int argc, char *argv[])
LammpsGui w(nullptr, infile); LammpsGui w(nullptr, infile);
w.show(); w.show();
return a.exec(); return QApplication::exec();
} }
// Local Variables: // Local Variables:

View File

@ -177,7 +177,7 @@ void Preferences::accept()
msg.exec(); msg.exec();
const char *path = mystrdup(QCoreApplication::applicationFilePath()); const char *path = mystrdup(QCoreApplication::applicationFilePath());
const char *arg0 = mystrdup(QCoreApplication::arguments().at(0)); const char *arg0 = mystrdup(QCoreApplication::arguments().at(0));
execl(path, arg0, (char *)NULL); execl(path, arg0, (char *)nullptr);
} }
// reformatting settings // reformatting settings

View File

@ -38,7 +38,7 @@
StdCapture::StdCapture() : m_oldStdOut(0), m_capturing(false) StdCapture::StdCapture() : m_oldStdOut(0), m_capturing(false)
{ {
// make stdout unbuffered so that we don't need to flush the stream // make stdout unbuffered so that we don't need to flush the stream
setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stdout, nullptr, _IONBF, 0);
m_pipe[READ] = 0; m_pipe[READ] = 0;
m_pipe[WRITE] = 0; m_pipe[WRITE] = 0;
@ -106,7 +106,7 @@ bool StdCapture::EndCapture()
std::string StdCapture::GetChunk() std::string StdCapture::GetChunk()
{ {
if (!m_capturing) return std::string(); if (!m_capturing) return {};
int bytesRead = 0; int bytesRead = 0;
buf[0] = '\0'; buf[0] = '\0';
@ -120,7 +120,7 @@ std::string StdCapture::GetChunk()
if (bytesRead > 0) { if (bytesRead > 0) {
buf[bytesRead] = '\0'; buf[bytesRead] = '\0';
} }
return std::string(buf); return {buf};
} }
std::string StdCapture::GetCapture() std::string StdCapture::GetCapture()

View File

@ -234,7 +234,7 @@ TEST_F(LAMMPS_configuration, style_count)
{ {
Info info(lmp); Info info(lmp);
for (const auto &c : style_category) for (const auto &c : style_category)
EXPECT_EQ(f_lammps_style_count(c.c_str()), info.get_available_styles(c.c_str()).size()); EXPECT_EQ(f_lammps_style_count(c.c_str()), info.get_available_styles(c).size());
}; };
TEST_F(LAMMPS_configuration, style_name) TEST_F(LAMMPS_configuration, style_name)

View File

@ -129,9 +129,9 @@ TEST(LeptonCustomFunction, zbl)
*/ */
class ExampleFunction : public Lepton::CustomFunction { class ExampleFunction : public Lepton::CustomFunction {
int getNumArguments() const { return 2; } int getNumArguments() const override { return 2; }
double evaluate(const double *arguments) const { return 2.0 * arguments[0] * arguments[1]; } double evaluate(const double *arguments) const override { return 2.0 * arguments[0] * arguments[1]; }
double evaluateDerivative(const double *arguments, const int *derivOrder) const double evaluateDerivative(const double *arguments, const int *derivOrder) const override
{ {
if (derivOrder[0] == 1) { if (derivOrder[0] == 1) {
if (derivOrder[1] == 0) if (derivOrder[1] == 0)
@ -142,7 +142,7 @@ class ExampleFunction : public Lepton::CustomFunction {
if (derivOrder[1] == 1 && derivOrder[0] == 0) return 2.0 * arguments[0]; if (derivOrder[1] == 1 && derivOrder[0] == 0) return 2.0 * arguments[0];
return 0.0; return 0.0;
} }
Lepton::CustomFunction *clone() const { return new ExampleFunction(); } Lepton::CustomFunction *clone() const override { return new ExampleFunction(); }
}; };
/** /**