add clang-format support to plugin examples

This commit is contained in:
Axel Kohlmeyer
2021-05-05 23:51:12 -04:00
parent 5fcd0d8b79
commit 49a7bb57de
21 changed files with 376 additions and 326 deletions

View File

@ -19,8 +19,8 @@
#include "atom.h"
#include "comm.h"
#include "memory.h"
#include "error.h"
#include "memory.h"
#include <cstring>
@ -28,11 +28,12 @@ using namespace LAMMPS_NS;
/* ---------------------------------------------------------------------- */
PairZero2::PairZero2(LAMMPS *lmp) : Pair(lmp) {
coeffflag=1;
writedata=1;
single_enable=1;
respa_enable=1;
PairZero2::PairZero2(LAMMPS *lmp) : Pair(lmp)
{
coeffflag = 1;
writedata = 1;
single_enable = 1;
respa_enable = 1;
}
/* ---------------------------------------------------------------------- */
@ -50,15 +51,15 @@ PairZero2::~PairZero2()
void PairZero2::compute(int eflag, int vflag)
{
ev_init(eflag,vflag);
if (vflag_fdotr) virial_fdotr_compute();
ev_init(eflag, vflag);
if (vflag_fdotr) virial_fdotr_compute();
}
/* ---------------------------------------------------------------------- */
void PairZero2::compute_outer(int eflag, int vflag)
{
ev_init(eflag,vflag);
ev_init(eflag, vflag);
}
/* ----------------------------------------------------------------------
@ -70,13 +71,12 @@ void PairZero2::allocate()
allocated = 1;
int n = atom->ntypes;
memory->create(setflag,n+1,n+1,"pair:setflag");
memory->create(setflag, n + 1, n + 1, "pair:setflag");
for (int i = 1; i <= n; i++)
for (int j = i; j <= n; j++)
setflag[i][j] = 0;
for (int j = i; j <= n; j++) setflag[i][j] = 0;
memory->create(cutsq,n+1,n+1,"pair:cutsq");
memory->create(cut,n+1,n+1,"pair:cut");
memory->create(cutsq, n + 1, n + 1, "pair:cutsq");
memory->create(cut, n + 1, n + 1, "pair:cut");
}
/* ----------------------------------------------------------------------
@ -86,21 +86,22 @@ void PairZero2::allocate()
void PairZero2::settings(int narg, char **arg)
{
if ((narg != 1) && (narg != 2))
error->all(FLERR,"Illegal pair_style command");
error->all(FLERR, "Illegal pair_style command");
cut_global = utils::numeric(FLERR,arg[0],false,lmp);
cut_global = utils::numeric(FLERR, arg[0], false, lmp);
if (narg == 2) {
if (strcmp("nocoeff",arg[1]) == 0) coeffflag=0;
else error->all(FLERR,"Illegal pair_style command");
if (strcmp("nocoeff", arg[1]) == 0)
coeffflag = 0;
else
error->all(FLERR, "Illegal pair_style command");
}
// reset cutoffs that have been explicitly set
if (allocated) {
int i,j;
int i, j;
for (i = 1; i <= atom->ntypes; i++)
for (j = i+1; j <= atom->ntypes; j++)
cut[i][j] = cut_global;
for (j = i + 1; j <= atom->ntypes; j++) cut[i][j] = cut_global;
}
}
@ -111,27 +112,28 @@ void PairZero2::settings(int narg, char **arg)
void PairZero2::coeff(int narg, char **arg)
{
if ((narg < 2) || (coeffflag && narg > 3))
error->all(FLERR,"Incorrect args for pair coefficients");
error->all(FLERR, "Incorrect args for pair coefficients");
if (!allocated) allocate();
int ilo,ihi,jlo,jhi;
utils::bounds(FLERR,arg[0],1,atom->ntypes,ilo,ihi,error);
utils::bounds(FLERR,arg[1],1,atom->ntypes,jlo,jhi,error);
int ilo, ihi, jlo, jhi;
utils::bounds(FLERR, arg[0], 1, atom->ntypes, ilo, ihi, error);
utils::bounds(FLERR, arg[1], 1, atom->ntypes, jlo, jhi, error);
double cut_one = cut_global;
if (coeffflag && (narg == 3)) cut_one = utils::numeric(FLERR,arg[2],false,lmp);
if (coeffflag && (narg == 3))
cut_one = utils::numeric(FLERR, arg[2], false, lmp);
int count = 0;
for (int i = ilo; i <= ihi; i++) {
for (int j = MAX(jlo,i); j <= jhi; j++) {
for (int j = MAX(jlo, i); j <= jhi; j++) {
cut[i][j] = cut_one;
setflag[i][j] = 1;
count++;
}
}
if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients");
if (count == 0) error->all(FLERR, "Incorrect args for pair coefficients");
}
/* ----------------------------------------------------------------------
@ -140,9 +142,7 @@ void PairZero2::coeff(int narg, char **arg)
double PairZero2::init_one(int i, int j)
{
if (setflag[i][j] == 0) {
cut[i][j] = mix_distance(cut[i][i],cut[j][j]);
}
if (setflag[i][j] == 0) { cut[i][j] = mix_distance(cut[i][i], cut[j][j]); }
return cut[i][j];
}
@ -155,13 +155,11 @@ void PairZero2::write_restart(FILE *fp)
{
write_restart_settings(fp);
int i,j;
int i, j;
for (i = 1; i <= atom->ntypes; i++)
for (j = i; j <= atom->ntypes; j++) {
fwrite(&setflag[i][j],sizeof(int),1,fp);
if (setflag[i][j]) {
fwrite(&cut[i][j],sizeof(double),1,fp);
}
fwrite(&setflag[i][j], sizeof(int), 1, fp);
if (setflag[i][j]) { fwrite(&cut[i][j], sizeof(double), 1, fp); }
}
}
@ -174,17 +172,20 @@ void PairZero2::read_restart(FILE *fp)
read_restart_settings(fp);
allocate();
int i,j;
int i, j;
int me = comm->me;
for (i = 1; i <= atom->ntypes; i++)
for (j = i; j <= atom->ntypes; j++) {
if (me == 0) utils::sfread(FLERR,&setflag[i][j],sizeof(int),1,fp,nullptr,error);
MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world);
if (me == 0)
utils::sfread(FLERR, &setflag[i][j], sizeof(int), 1, fp, nullptr,
error);
MPI_Bcast(&setflag[i][j], 1, MPI_INT, 0, world);
if (setflag[i][j]) {
if (me == 0) {
utils::sfread(FLERR,&cut[i][j],sizeof(double),1,fp,nullptr,error);
utils::sfread(FLERR, &cut[i][j], sizeof(double), 1, fp, nullptr,
error);
}
MPI_Bcast(&cut[i][j],1,MPI_DOUBLE,0,world);
MPI_Bcast(&cut[i][j], 1, MPI_DOUBLE, 0, world);
}
}
}
@ -195,8 +196,8 @@ void PairZero2::read_restart(FILE *fp)
void PairZero2::write_restart_settings(FILE *fp)
{
fwrite(&cut_global,sizeof(double),1,fp);
fwrite(&coeffflag,sizeof(int),1,fp);
fwrite(&cut_global, sizeof(double), 1, fp);
fwrite(&coeffflag, sizeof(int), 1, fp);
}
/* ----------------------------------------------------------------------
@ -207,11 +208,11 @@ void PairZero2::read_restart_settings(FILE *fp)
{
int me = comm->me;
if (me == 0) {
utils::sfread(FLERR,&cut_global,sizeof(double),1,fp,nullptr,error);
utils::sfread(FLERR,&coeffflag,sizeof(int),1,fp,nullptr,error);
utils::sfread(FLERR, &cut_global, sizeof(double), 1, fp, nullptr, error);
utils::sfread(FLERR, &coeffflag, sizeof(int), 1, fp, nullptr, error);
}
MPI_Bcast(&cut_global,1,MPI_DOUBLE,0,world);
MPI_Bcast(&coeffflag,1,MPI_INT,0,world);
MPI_Bcast(&cut_global, 1, MPI_DOUBLE, 0, world);
MPI_Bcast(&coeffflag, 1, MPI_INT, 0, world);
}
/* ----------------------------------------------------------------------
@ -220,8 +221,7 @@ void PairZero2::read_restart_settings(FILE *fp)
void PairZero2::write_data(FILE *fp)
{
for (int i = 1; i <= atom->ntypes; i++)
fprintf(fp,"%d\n",i);
for (int i = 1; i <= atom->ntypes; i++) fprintf(fp, "%d\n", i);
}
/* ----------------------------------------------------------------------
@ -232,16 +232,15 @@ void PairZero2::write_data_all(FILE *fp)
{
for (int i = 1; i <= atom->ntypes; i++)
for (int j = i; j <= atom->ntypes; j++)
fprintf(fp,"%d %d %g\n",i,j,cut[i][j]);
fprintf(fp, "%d %d %g\n", i, j, cut[i][j]);
}
/* ---------------------------------------------------------------------- */
double PairZero2::single(int /*i*/, int /*j*/, int /* itype */, int /* jtype */,
double /* rsq */, double /*factor_coul*/,
double /* factor_lj */, double &fforce)
double /* rsq */, double /*factor_coul*/,
double /* factor_lj */, double &fforce)
{
fforce = 0.0;
return 0.0;
}