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;
if (me == 0) {
fp = fopen(arg[2],"r");
if (fp == NULL) {
if (fp == nullptr) {
printf("ERROR: Could not open LAMMPS input script\n");
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)
// all LAMMPS procs call input->one() on the line
LAMMPS *lmp = NULL;
if (lammps == 1) lmp = new LAMMPS(0,NULL,comm_lammps);
LAMMPS *lmp = nullptr;
if (lammps == 1) lmp = new LAMMPS(0,nullptr,comm_lammps);
int n;
char line[1024];
while (1) {
while (true) {
if (me == 0) {
if (fgets(line,1024,fp) == NULL) n = 0;
if (fgets(line,1024,fp) == nullptr) n = 0;
else n = strlen(line) + 1;
if (n == 0) fclose(fp);
}
@ -101,8 +101,8 @@ int main(int narg, char **arg)
// put coords back into LAMMPS
// run a single step with changed coords
double *x = NULL;
double *v = NULL;
double *x = nullptr;
double *v = nullptr;
if (lammps == 1) {
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
// initial thermo should be same as step 20
int *type = NULL;
int *type = nullptr;
if (lammps == 1) {
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;
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");
}

View File

@ -1076,7 +1076,6 @@ void FixTGNHDrude::couple()
void FixTGNHDrude::remap()
{
int i;
double oldlo,oldhi;
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]);
delete acecimpl->basis_set;
acecimpl->basis_set = new ACECTildeBasisSet(potential_file_name);
double cut = acecimpl->basis_set->cutoffmax;
cutmax = acecimpl->basis_set->cutoffmax;
double cuti;
double radelemall = 0.5;
//# of rank 1, rank > 1 functions
@ -178,7 +175,6 @@ void ComputePACE::init_list(int /*id*/, NeighList *ptr)
void ComputePACE::compute_array()
{
int ntotal = atom->nlocal + atom->nghost;
double **f = atom->f;
invoked_array = update->ntimestep;
// grow pace_peratom array if necessary
@ -208,9 +204,6 @@ void ComputePACE::compute_array()
// invoke full neighbor list (will copy or build if necessary)
neighbor->build_one(list);
SPECIES_TYPE *mus;
NS_TYPE *ns;
LS_TYPE *ls;
const int inum = list->inum;
const int* const ilist = list->ilist;
@ -234,7 +227,6 @@ void ComputePACE::compute_array()
// compute pace derivatives for each atom in group
// use full neighbor list to count atoms less than cutoff
double** const x = atom->x;
const int* const mask = atom->mask;
const int ntypes = atom->ntypes;
@ -251,8 +243,8 @@ void ComputePACE::compute_array()
delete acecimpl->ace;
acecimpl->ace = new ACECTildeEvaluator(*acecimpl->basis_set);
acecimpl->ace->compute_projections = 1;
acecimpl->ace->compute_b_grad = 1;
acecimpl->ace->compute_projections = true;
acecimpl->ace->compute_b_grad = true;
int n_r1, n_rp = 0;
n_r1 = acecimpl->basis_set->total_basis_size_rank1[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 ##### //
// ############################################################################## //
if (nearest_neighbors_mode == true) {
if (nearest_neighbors_mode) {
// ##### 1) : consider full neighbor list in rlist
memory->create(distsq, jnum, "snann/atom:distsq");
memory->create(rlist, jnum, 3, "snann/atom:rlist");
@ -308,7 +308,6 @@ void ComputeSNAAtom::compute_peratom()
for (int jj = 0; jj < jnum; jj++) {
int j = jlist[jj];
j &= NEIGHMASK;
int jtype = type[j];
const double delx = xtmp - x[j][0];
const double dely = ytmp - x[j][1];
@ -614,10 +613,9 @@ double * ComputeSNAAtom::tanh_weights(double * rsq, double rcut, double delta, i
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 rloc=0.;
for (int i=0; i<ncounts; i++)
{
S += w[i];

View File

@ -59,7 +59,7 @@ void NPairBinGhostOmp<HALF>::build(NeighList *list)
#endif
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;
double xtmp, ytmp, ztmp, delx, dely, delz, rsq;
int xbin, ybin, zbin, xbin2, ybin2, zbin2;

View File

@ -34,11 +34,10 @@ using namespace ReaxFF;
/* ---------------------------------------------------------------------- */
ComputeReaxFFAtom::ComputeReaxFFAtom(LAMMPS *lmp, int narg, char **arg) :
Compute(lmp, narg, arg),
abo(nullptr), neighid(nullptr), bondcount(nullptr), reaxff(nullptr)
Compute(lmp, narg, arg), neighid(nullptr), abo(nullptr), bondcount(nullptr), reaxff(nullptr)
{
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");
peratom_flag = 1;

View File

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

View File

@ -709,7 +709,7 @@ void lammps_commands_string(void *handle, const char *str)
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
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 (! (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)
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_flag) {
if (DIM_3D) {
if (! (k > 0 || j > 0 || (j == 0 && i > 0))) continue;
if (k <= 0 && j <= 0 && (j != 0 || i <= 0)) continue;
} 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
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 (! (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);
if (rsq < typesq) {

View File

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

View File

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

View File

@ -38,7 +38,7 @@
StdCapture::StdCapture() : m_oldStdOut(0), m_capturing(false)
{
// 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[WRITE] = 0;
@ -106,7 +106,7 @@ bool StdCapture::EndCapture()
std::string StdCapture::GetChunk()
{
if (!m_capturing) return std::string();
if (!m_capturing) return {};
int bytesRead = 0;
buf[0] = '\0';
@ -120,7 +120,7 @@ std::string StdCapture::GetChunk()
if (bytesRead > 0) {
buf[bytesRead] = '\0';
}
return std::string(buf);
return {buf};
}
std::string StdCapture::GetCapture()

View File

@ -234,7 +234,7 @@ TEST_F(LAMMPS_configuration, style_count)
{
Info info(lmp);
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)

View File

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