enable and apply clang-format to a whole bunch of small .cpp files in src/

This commit is contained in:
Axel Kohlmeyer
2023-03-25 09:59:25 -04:00
parent 22a1cf935e
commit 8cd34af4f0
38 changed files with 604 additions and 645 deletions

View File

@ -1,4 +1,3 @@
// clang-format off
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
@ -24,15 +23,14 @@
using namespace LAMMPS_NS;
enum{EPAIR,EVDWL,ECOUL};
enum { EPAIR, EVDWL, ECOUL };
/* ---------------------------------------------------------------------- */
ComputePair::ComputePair(LAMMPS *lmp, int narg, char **arg) :
Compute(lmp, narg, arg),
pstyle(nullptr), pair(nullptr), one(nullptr)
Compute(lmp, narg, arg), pstyle(nullptr), pair(nullptr), one(nullptr)
{
if (narg < 4) error->all(FLERR,"Illegal compute pair command");
if (narg < 4) error->all(FLERR, "Illegal compute pair command");
scalar_flag = 1;
extscalar = 1;
@ -41,8 +39,9 @@ ComputePair::ComputePair(LAMMPS *lmp, int narg, char **arg) :
// copy with suffix so we can later chop it off, if needed
if (lmp->suffix)
pstyle = utils::strdup(fmt::format("{}/{}",arg[3],lmp->suffix));
else pstyle = utils::strdup(arg[3]);
pstyle = utils::strdup(fmt::format("{}/{}", arg[3], lmp->suffix));
else
pstyle = utils::strdup(arg[3]);
int iarg = 4;
nsub = 0;
@ -50,31 +49,33 @@ ComputePair::ComputePair(LAMMPS *lmp, int narg, char **arg) :
if (narg > iarg) {
if (isdigit(arg[iarg][0])) {
nsub = utils::inumeric(FLERR,arg[iarg],false,lmp);
nsub = utils::inumeric(FLERR, arg[iarg], false, lmp);
++iarg;
if (nsub <= 0)
error->all(FLERR,"Illegal compute pair command");
if (nsub <= 0) error->all(FLERR, "Illegal compute pair command");
}
}
if (narg > iarg) {
if (strcmp(arg[iarg],"epair") == 0) evalue = EPAIR;
else if (strcmp(arg[iarg],"evdwl") == 0) evalue = EVDWL;
else if (strcmp(arg[iarg],"ecoul") == 0) evalue = ECOUL;
else error->all(FLERR, "Illegal compute pair command");
if (narg > iarg) {
if (strcmp(arg[iarg], "epair") == 0)
evalue = EPAIR;
else if (strcmp(arg[iarg], "evdwl") == 0)
evalue = EVDWL;
else if (strcmp(arg[iarg], "ecoul") == 0)
evalue = ECOUL;
else
error->all(FLERR, "Illegal compute pair command");
++iarg;
}
// check if pair style with and without suffix exists
pair = force->pair_match(pstyle,1,nsub);
pair = force->pair_match(pstyle, 1, nsub);
if (!pair && lmp->suffix) {
pstyle[strlen(pstyle) - strlen(lmp->suffix) - 1] = '\0';
pair = force->pair_match(pstyle,1,nsub);
pair = force->pair_match(pstyle, 1, nsub);
}
if (!pair)
error->all(FLERR,"Unrecognized pair style in compute pair command");
if (!pair) error->all(FLERR, "Unrecognized pair style in compute pair command");
npair = pair->nextra;
if (npair) {
@ -83,7 +84,8 @@ ComputePair::ComputePair(LAMMPS *lmp, int narg, char **arg) :
extvector = 1;
one = new double[npair];
vector = new double[npair];
} else one = vector = nullptr;
} else
one = vector = nullptr;
}
/* ---------------------------------------------------------------------- */
@ -101,9 +103,8 @@ void ComputePair::init()
{
// recheck for pair style in case it has been deleted
pair = force->pair_match(pstyle,1,nsub);
if (!pair)
error->all(FLERR,"Unrecognized pair style in compute pair command");
pair = force->pair_match(pstyle, 1, nsub);
if (!pair) error->all(FLERR, "Unrecognized pair style in compute pair command");
}
/* ---------------------------------------------------------------------- */
@ -112,14 +113,17 @@ double ComputePair::compute_scalar()
{
invoked_scalar = update->ntimestep;
if (update->eflag_global != invoked_scalar)
error->all(FLERR,"Energy was not tallied on needed timestep");
error->all(FLERR, "Energy was not tallied on needed timestep");
double eng;
if (evalue == EPAIR) eng = pair->eng_vdwl + pair->eng_coul;
else if (evalue == EVDWL) eng = pair->eng_vdwl;
else if (evalue == ECOUL) eng = pair->eng_coul;
if (evalue == EPAIR)
eng = pair->eng_vdwl + pair->eng_coul;
else if (evalue == EVDWL)
eng = pair->eng_vdwl;
else if (evalue == ECOUL)
eng = pair->eng_coul;
MPI_Allreduce(&eng,&scalar,1,MPI_DOUBLE,MPI_SUM,world);
MPI_Allreduce(&eng, &scalar, 1, MPI_DOUBLE, MPI_SUM, world);
return scalar;
}
@ -129,9 +133,8 @@ void ComputePair::compute_vector()
{
invoked_vector = update->ntimestep;
if (update->eflag_global != invoked_vector)
error->all(FLERR,"Energy was not tallied on needed timestep");
error->all(FLERR, "Energy was not tallied on needed timestep");
for (int i = 0; i < npair; i++)
one[i] = pair->pvector[i];
MPI_Allreduce(one,vector,npair,MPI_DOUBLE,MPI_SUM,world);
for (int i = 0; i < npair; i++) one[i] = pair->pvector[i];
MPI_Allreduce(one, vector, npair, MPI_DOUBLE, MPI_SUM, world);
}