convert more styles to use new neighbor list request API, apply clang-format

This commit is contained in:
Axel Kohlmeyer
2022-03-05 21:09:19 -05:00
parent ffb367663d
commit 54e667e491
20 changed files with 1083 additions and 1122 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
@ -18,16 +17,16 @@
#include "pair_coul_wolf.h"
#include <cmath>
#include "atom.h"
#include "comm.h"
#include "error.h"
#include "force.h"
#include "neighbor.h"
#include "neigh_list.h"
#include "math_const.h"
#include "memory.h"
#include "error.h"
#include "neigh_list.h"
#include "neighbor.h"
#include <cmath>
using namespace LAMMPS_NS;
using namespace MathConst;
@ -36,7 +35,7 @@ using namespace MathConst;
PairCoulWolf::PairCoulWolf(LAMMPS *lmp) : Pair(lmp)
{
single_enable = 0; // NOTE: single() method below is not yet correct
single_enable = 0; // NOTE: single() method below is not yet correct
}
/* ---------------------------------------------------------------------- */
@ -55,16 +54,16 @@ PairCoulWolf::~PairCoulWolf()
void PairCoulWolf::compute(int eflag, int vflag)
{
int i,j,ii,jj,inum,jnum;
double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,ecoul,fpair;
double rsq,forcecoul,factor_coul;
int i, j, ii, jj, inum, jnum;
double qtmp, xtmp, ytmp, ztmp, delx, dely, delz, ecoul, fpair;
double rsq, forcecoul, factor_coul;
double prefactor;
double r;
int *ilist,*jlist,*numneigh,**firstneigh;
double erfcc,erfcd,v_sh,dvdrr,e_self,e_shift,f_shift,qisq;
int *ilist, *jlist, *numneigh, **firstneigh;
double erfcc, erfcd, v_sh, dvdrr, e_self, e_shift, f_shift, qisq;
ecoul = 0.0;
ev_init(eflag,vflag);
ev_init(eflag, vflag);
double **x = atom->x;
double **f = atom->f;
@ -77,9 +76,8 @@ void PairCoulWolf::compute(int eflag, int vflag)
// self and shifted coulombic energy
e_self = v_sh = 0.0;
e_shift = erfc(alf*cut_coul)/cut_coul;
f_shift = -(e_shift+ 2.0*alf/MY_PIS * exp(-alf*alf*cut_coul*cut_coul)) /
cut_coul;
e_shift = erfc(alf * cut_coul) / cut_coul;
f_shift = -(e_shift + 2.0 * alf / MY_PIS * exp(-alf * alf * cut_coul * cut_coul)) / cut_coul;
inum = list->inum;
ilist = list->ilist;
@ -97,9 +95,9 @@ void PairCoulWolf::compute(int eflag, int vflag)
jlist = firstneigh[i];
jnum = numneigh[i];
qisq = qtmp*qtmp;
e_self = -(e_shift/2.0 + alf/MY_PIS) * qisq*qqrd2e;
if (evflag) ev_tally(i,i,nlocal,0,0.0,e_self,0.0,0.0,0.0,0.0);
qisq = qtmp * qtmp;
e_self = -(e_shift / 2.0 + alf / MY_PIS) * qisq * qqrd2e;
if (evflag) ev_tally(i, i, nlocal, 0, 0.0, e_self, 0.0, 0.0, 0.0, 0.0);
for (jj = 0; jj < jnum; jj++) {
j = jlist[jj];
@ -109,35 +107,35 @@ void PairCoulWolf::compute(int eflag, int vflag)
delx = xtmp - x[j][0];
dely = ytmp - x[j][1];
delz = ztmp - x[j][2];
rsq = delx*delx + dely*dely + delz*delz;
rsq = delx * delx + dely * dely + delz * delz;
if (rsq < cut_coulsq) {
r = sqrt(rsq);
prefactor = qqrd2e*qtmp*q[j]/r;
erfcc = erfc(alf*r);
erfcd = exp(-alf*alf*r*r);
v_sh = (erfcc - e_shift*r) * prefactor;
dvdrr = (erfcc/rsq + 2.0*alf/MY_PIS * erfcd/r) + f_shift;
forcecoul = dvdrr*rsq*prefactor;
if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor;
prefactor = qqrd2e * qtmp * q[j] / r;
erfcc = erfc(alf * r);
erfcd = exp(-alf * alf * r * r);
v_sh = (erfcc - e_shift * r) * prefactor;
dvdrr = (erfcc / rsq + 2.0 * alf / MY_PIS * erfcd / r) + f_shift;
forcecoul = dvdrr * rsq * prefactor;
if (factor_coul < 1.0) forcecoul -= (1.0 - factor_coul) * prefactor;
fpair = forcecoul / rsq;
f[i][0] += delx*fpair;
f[i][1] += dely*fpair;
f[i][2] += delz*fpair;
f[i][0] += delx * fpair;
f[i][1] += dely * fpair;
f[i][2] += delz * fpair;
if (newton_pair || j < nlocal) {
f[j][0] -= delx*fpair;
f[j][1] -= dely*fpair;
f[j][2] -= delz*fpair;
f[j][0] -= delx * fpair;
f[j][1] -= dely * fpair;
f[j][2] -= delz * fpair;
}
if (eflag) {
ecoul = v_sh;
if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor;
} else ecoul = 0.0;
if (factor_coul < 1.0) ecoul -= (1.0 - factor_coul) * prefactor;
} else
ecoul = 0.0;
if (evflag) ev_tally(i,j,nlocal,newton_pair,
0.0,ecoul,fpair,delx,dely,delz);
if (evflag) ev_tally(i, j, nlocal, newton_pair, 0.0, ecoul, fpair, delx, dely, delz);
}
}
}
@ -154,12 +152,11 @@ void PairCoulWolf::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(cutsq, n + 1, n + 1, "pair:cutsq");
}
/* ----------------------------------------------------------------------
@ -170,10 +167,10 @@ void PairCoulWolf::allocate()
void PairCoulWolf::settings(int narg, char **arg)
{
if (narg != 2) error->all(FLERR,"Illegal pair_style command");
if (narg != 2) error->all(FLERR, "Illegal pair_style command");
alf = utils::numeric(FLERR,arg[0],false,lmp);
cut_coul = utils::numeric(FLERR,arg[1],false,lmp);
alf = utils::numeric(FLERR, arg[0], false, lmp);
cut_coul = utils::numeric(FLERR, arg[1], false, lmp);
}
/* ----------------------------------------------------------------------
@ -182,22 +179,22 @@ void PairCoulWolf::settings(int narg, char **arg)
void PairCoulWolf::coeff(int narg, char **arg)
{
if (narg != 2) error->all(FLERR,"Incorrect args for pair coefficients");
if (narg != 2) 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);
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++) {
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");
}
/* ----------------------------------------------------------------------
@ -206,12 +203,11 @@ void PairCoulWolf::coeff(int narg, char **arg)
void PairCoulWolf::init_style()
{
if (!atom->q_flag)
error->all(FLERR,"Pair coul/wolf requires atom attribute q");
if (!atom->q_flag) error->all(FLERR, "Pair coul/wolf requires atom attribute q");
neighbor->request(this,instance_me);
neighbor->add_request(this, NeighConst::REQ_DEFAULT);
cut_coulsq = cut_coul*cut_coul;
cut_coulsq = cut_coul * cut_coul;
}
/* ----------------------------------------------------------------------
@ -231,10 +227,9 @@ void PairCoulWolf::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);
for (j = i; j <= atom->ntypes; j++) fwrite(&setflag[i][j], sizeof(int), 1, fp);
}
/* ----------------------------------------------------------------------
@ -246,12 +241,12 @@ void PairCoulWolf::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);
}
}
@ -261,10 +256,10 @@ void PairCoulWolf::read_restart(FILE *fp)
void PairCoulWolf::write_restart_settings(FILE *fp)
{
fwrite(&alf,sizeof(double),1,fp);
fwrite(&cut_coul,sizeof(double),1,fp);
fwrite(&offset_flag,sizeof(int),1,fp);
fwrite(&mix_flag,sizeof(int),1,fp);
fwrite(&alf, sizeof(double), 1, fp);
fwrite(&cut_coul, sizeof(double), 1, fp);
fwrite(&offset_flag, sizeof(int), 1, fp);
fwrite(&mix_flag, sizeof(int), 1, fp);
}
/* ----------------------------------------------------------------------
@ -274,15 +269,15 @@ void PairCoulWolf::write_restart_settings(FILE *fp)
void PairCoulWolf::read_restart_settings(FILE *fp)
{
if (comm->me == 0) {
utils::sfread(FLERR,&alf,sizeof(double),1,fp,nullptr,error);
utils::sfread(FLERR,&cut_coul,sizeof(double),1,fp,nullptr,error);
utils::sfread(FLERR,&offset_flag,sizeof(int),1,fp,nullptr,error);
utils::sfread(FLERR,&mix_flag,sizeof(int),1,fp,nullptr,error);
utils::sfread(FLERR, &alf, sizeof(double), 1, fp, nullptr, error);
utils::sfread(FLERR, &cut_coul, sizeof(double), 1, fp, nullptr, error);
utils::sfread(FLERR, &offset_flag, sizeof(int), 1, fp, nullptr, error);
utils::sfread(FLERR, &mix_flag, sizeof(int), 1, fp, nullptr, error);
}
MPI_Bcast(&alf,1,MPI_DOUBLE,0,world);
MPI_Bcast(&cut_coul,1,MPI_DOUBLE,0,world);
MPI_Bcast(&offset_flag,1,MPI_INT,0,world);
MPI_Bcast(&mix_flag,1,MPI_INT,0,world);
MPI_Bcast(&alf, 1, MPI_DOUBLE, 0, world);
MPI_Bcast(&cut_coul, 1, MPI_DOUBLE, 0, world);
MPI_Bcast(&offset_flag, 1, MPI_INT, 0, world);
MPI_Bcast(&mix_flag, 1, MPI_INT, 0, world);
}
/* ----------------------------------------------------------------------
@ -290,32 +285,31 @@ void PairCoulWolf::read_restart_settings(FILE *fp)
------------------------------------------------------------------------- */
double PairCoulWolf::single(int i, int j, int /*itype*/, int /*jtype*/, double rsq,
double factor_coul, double /*factor_lj*/,
double &fforce)
double factor_coul, double /*factor_lj*/, double &fforce)
{
double r,prefactor;
double forcecoul,phicoul;
double e_shift,f_shift,dvdrr,erfcc,erfcd;
double r, prefactor;
double forcecoul, phicoul;
double e_shift, f_shift, dvdrr, erfcc, erfcd;
e_shift = erfc(alf*cut_coul) / cut_coul;
f_shift = -(e_shift+ 2.0*alf/MY_PIS * exp(-alf*alf*cut_coul*cut_coul)) /
cut_coul;
e_shift = erfc(alf * cut_coul) / cut_coul;
f_shift = -(e_shift + 2.0 * alf / MY_PIS * exp(-alf * alf * cut_coul * cut_coul)) / cut_coul;
if (rsq < cut_coulsq) {
r = sqrt(rsq);
prefactor = force->qqrd2e * atom->q[i]*atom->q[j]/r;
erfcc = erfc(alf*r);
erfcd = exp(-alf*alf*r*r);
dvdrr = (erfcc/rsq + 2.0*alf/MY_PIS * erfcd/r) + f_shift;
forcecoul = dvdrr*rsq*prefactor;
if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor;
} else forcecoul = 0.0;
prefactor = force->qqrd2e * atom->q[i] * atom->q[j] / r;
erfcc = erfc(alf * r);
erfcd = exp(-alf * alf * r * r);
dvdrr = (erfcc / rsq + 2.0 * alf / MY_PIS * erfcd / r) + f_shift;
forcecoul = dvdrr * rsq * prefactor;
if (factor_coul < 1.0) forcecoul -= (1.0 - factor_coul) * prefactor;
} else
forcecoul = 0.0;
fforce = forcecoul / rsq;
double eng = 0.0;
if (rsq < cut_coulsq) {
phicoul = prefactor * (erfcc-e_shift*r);
if (factor_coul < 1.0) phicoul -= (1.0-factor_coul)*prefactor;
phicoul = prefactor * (erfcc - e_shift * r);
if (factor_coul < 1.0) phicoul -= (1.0 - factor_coul) * prefactor;
eng += phicoul;
}
return eng;