apply clang-format

This commit is contained in:
Axel Kohlmeyer
2021-08-17 22:35:05 -04:00
parent 96b563dffc
commit f470964393
7 changed files with 662 additions and 673 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
@ -48,14 +47,14 @@ using namespace InterLayer;
#define PGDELTA 1
static const char cite_ilp[] =
"@Article{Ouyang2018\n"
" author = {W. Ouyang, D. Mandelli, M. Urbakh, and O. Hod},\n"
" title = {Nanoserpents: Graphene Nanoribbon Motion on Two-Dimensional Hexagonal Materials},\n"
" journal = {Nano Letters},\n"
" volume = 18,\n"
" pages = {6009}\n"
" year = 2018,\n"
"}\n\n";
"@Article{Ouyang2018\n"
" author = {W. Ouyang, D. Mandelli, M. Urbakh, and O. Hod},\n"
" title = {Nanoserpents: Graphene Nanoribbon Motion on Two-Dimensional Hexagonal Materials},\n"
" journal = {Nano Letters},\n"
" volume = 18,\n"
" pages = {6009}\n"
" year = 2018,\n"
"}\n\n";
/* ---------------------------------------------------------------------- */
@ -100,8 +99,8 @@ PairILPGrapheneHBN::~PairILPGrapheneHBN()
{
memory->destroy(ILP_numneigh);
memory->sfree(ILP_firstneigh);
delete [] ipage;
delete [] pvector;
delete[] ipage;
delete[] pvector;
memory->destroy(normal);
memory->destroy(dnormal);
memory->destroy(dnormdri);
@ -109,7 +108,6 @@ PairILPGrapheneHBN::~PairILPGrapheneHBN()
if (allocated) {
memory->destroy(setflag);
memory->destroy(cutsq);
memory->destroy(cut);
memory->destroy(offset);
}
@ -125,17 +123,15 @@ PairILPGrapheneHBN::~PairILPGrapheneHBN()
void PairILPGrapheneHBN::allocate()
{
allocated = 1;
int n = atom->ntypes;
int n = atom->ntypes + 1;
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;
memory->create(setflag, n, n, "pair:setflag");
for (int i = 1; i < n; i++)
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(offset,n+1,n+1,"pair:offset");
map = new int[atom->ntypes+1];
memory->create(cutsq, n, n, "pair:cutsq");
memory->create(offset, n, n, "pair:offset");
map = new int[n];
}
/* ----------------------------------------------------------------------
@ -144,12 +140,12 @@ void PairILPGrapheneHBN::allocate()
void PairILPGrapheneHBN::settings(int narg, char **arg)
{
if (narg < 1 || narg > 2) error->all(FLERR,"Illegal pair_style command");
if (strcmp(force->pair_style,"hybrid/overlay")!=0)
error->all(FLERR,"ERROR: requires hybrid/overlay pair_style");
if (narg < 1 || narg > 2) error->all(FLERR, "Illegal pair_style command");
if (strcmp(force->pair_style, "hybrid/overlay") != 0)
error->all(FLERR, "ERROR: requires hybrid/overlay pair_style");
cut_global = utils::numeric(FLERR,arg[0],false,lmp);
if (narg == 2) tap_flag = utils::numeric(FLERR,arg[1],false,lmp);
cut_global = utils::numeric(FLERR, arg[0], false, lmp);
if (narg == 2) tap_flag = utils::numeric(FLERR, arg[1], false, lmp);
}
/* ----------------------------------------------------------------------
@ -160,26 +156,26 @@ void PairILPGrapheneHBN::coeff(int narg, char **arg)
{
if (!allocated) allocate();
map_element2type(narg-3,arg+3);
map_element2type(narg - 3, arg + 3);
read_file(arg[2]);
}
/* ----------------------------------------------------------------------
init for one type pair i,j and corresponding j,i
------------------------------------------------------------------------- */
double PairILPGrapheneHBN::init_one(int i, int j)
{
if (setflag[i][j] == 0) error->all(FLERR,"All pair coeffs are not set");
if (!offset_flag)
error->all(FLERR,"Must use 'pair_modify shift yes' with this pair style");
if (setflag[i][j] == 0) error->all(FLERR, "All pair coeffs are not set");
if (!offset_flag) error->all(FLERR, "Must use 'pair_modify shift yes' with this pair style");
if (offset_flag && (cut_global > 0.0)) {
if (offset_flag && (cut_global > 0.0)) {
int iparam_ij = elem2param[map[i]][map[j]];
Param& p = params[iparam_ij];
offset[i][j] = -p.C6*pow(1.0/cut_global,6)/(1.0 + exp(-p.d*(cut_global/p.seff - 1.0)));
} else offset[i][j] = 0.0;
Param &p = params[iparam_ij];
offset[i][j] =
-p.C6 * pow(1.0 / cut_global, 6) / (1.0 + exp(-p.d * (cut_global / p.seff - 1.0)));
} else
offset[i][j] = 0.0;
offset[j][i] = offset[i][j];
return cut_global;
@ -230,30 +226,30 @@ void PairILPGrapheneHBN::read_file(char *filename)
if (nparams == maxparam) {
maxparam += DELTA;
params = (Param *) memory->srealloc(params,maxparam*sizeof(Param), "pair:params");
params = (Param *) memory->srealloc(params, maxparam * sizeof(Param), "pair:params");
// make certain all addional allocated storage is initialized
// to avoid false positives when checking with valgrind
memset(params + nparams, 0, DELTA*sizeof(Param));
memset(params + nparams, 0, DELTA * sizeof(Param));
}
// load up parameter settings and error check their values
params[nparams].ielement = ielement;
params[nparams].jelement = jelement;
params[nparams].z0 = values.next_double();
params[nparams].alpha = values.next_double();
params[nparams].delta = values.next_double();
params[nparams].epsilon = values.next_double();
params[nparams].C = values.next_double();
params[nparams].d = values.next_double();
params[nparams].sR = values.next_double();
params[nparams].reff = values.next_double();
params[nparams].C6 = values.next_double();
params[nparams].z0 = values.next_double();
params[nparams].alpha = values.next_double();
params[nparams].delta = values.next_double();
params[nparams].epsilon = values.next_double();
params[nparams].C = values.next_double();
params[nparams].d = values.next_double();
params[nparams].sR = values.next_double();
params[nparams].reff = values.next_double();
params[nparams].C6 = values.next_double();
// S provides a convenient scaling of all energies
params[nparams].S = values.next_double();
params[nparams].rcut = values.next_double();
params[nparams].S = values.next_double();
params[nparams].rcut = values.next_double();
} catch (TokenizerException &e) {
error->one(FLERR, e.what());
@ -262,7 +258,7 @@ void PairILPGrapheneHBN::read_file(char *filename)
// energies in meV further scaled by S
// S = 43.3634 meV = 1 kcal/mol
double meV = 1e-3*params[nparams].S;
double meV = 1e-3 * params[nparams].S;
if (unit_convert) meV *= conversion_factor;
params[nparams].C *= meV;
@ -270,8 +266,8 @@ void PairILPGrapheneHBN::read_file(char *filename)
params[nparams].epsilon *= meV;
// precompute some quantities
params[nparams].delta2inv = pow(params[nparams].delta,-2.0);
params[nparams].lambda = params[nparams].alpha/params[nparams].z0;
params[nparams].delta2inv = pow(params[nparams].delta, -2.0);
params[nparams].lambda = params[nparams].alpha / params[nparams].z0;
params[nparams].seff = params[nparams].sR * params[nparams].reff;
nparams++;
@ -281,27 +277,27 @@ void PairILPGrapheneHBN::read_file(char *filename)
MPI_Bcast(&maxparam, 1, MPI_INT, 0, world);
if (comm->me != 0) {
params = (Param *) memory->srealloc(params,maxparam*sizeof(Param), "pair:params");
params = (Param *) memory->srealloc(params, maxparam * sizeof(Param), "pair:params");
}
MPI_Bcast(params, maxparam*sizeof(Param), MPI_BYTE, 0, world);
MPI_Bcast(params, maxparam * sizeof(Param), MPI_BYTE, 0, world);
}
memory->destroy(elem2param);
memory->destroy(cutILPsq);
memory->create(elem2param,nelements,nelements,"pair:elem2param");
memory->create(cutILPsq,nelements,nelements,"pair:cutILPsq");
memory->create(elem2param, nelements, nelements, "pair:elem2param");
memory->create(cutILPsq, nelements, nelements, "pair:cutILPsq");
for (int i = 0; i < nelements; i++) {
for (int j = 0; j < nelements; j++) {
int n = -1;
for (int m = 0; m < nparams; m++) {
if (i == params[m].ielement && j == params[m].jelement) {
if (n >= 0) error->all(FLERR,"ILP Potential file has duplicate entry");
if (n >= 0) error->all(FLERR, "ILP Potential file has duplicate entry");
n = m;
}
}
if (n < 0) error->all(FLERR,"Potential file is missing an entry");
if (n < 0) error->all(FLERR, "Potential file is missing an entry");
elem2param[i][j] = n;
cutILPsq[i][j] = params[n].rcut*params[n].rcut;
cutILPsq[i][j] = params[n].rcut * params[n].rcut;
}
}
}
@ -313,13 +309,13 @@ void PairILPGrapheneHBN::read_file(char *filename)
void PairILPGrapheneHBN::init_style()
{
if (force->newton_pair == 0)
error->all(FLERR,"Pair style ilp/graphene/hbn requires newton pair on");
error->all(FLERR, "Pair style ilp/graphene/hbn requires newton pair on");
if (!atom->molecule_flag)
error->all(FLERR,"Pair style ilp/graphene/hbn requires atom attribute molecule");
error->all(FLERR, "Pair style ilp/graphene/hbn requires atom attribute molecule");
// need a full neighbor list, including neighbors of ghosts
int irequest = neighbor->request(this,instance_me);
int irequest = neighbor->request(this, instance_me);
neighbor->requests[irequest]->half = 0;
neighbor->requests[irequest]->full = 1;
neighbor->requests[irequest]->ghost = 1;
@ -333,21 +329,20 @@ void PairILPGrapheneHBN::init_style()
if (oneatom != neighbor->oneatom) create = 1;
if (create) {
delete [] ipage;
delete[] ipage;
pgsize = neighbor->pgsize;
oneatom = neighbor->oneatom;
int nmypage= comm->nthreads;
int nmypage = comm->nthreads;
ipage = new MyPage<int>[nmypage];
for (int i = 0; i < nmypage; i++)
ipage[i].init(oneatom,pgsize,PGDELTA);
for (int i = 0; i < nmypage; i++) ipage[i].init(oneatom, pgsize, PGDELTA);
}
}
/* ---------------------------------------------------------------------- */
void PairILPGrapheneHBN::compute(int eflag, int vflag)
{
ev_init(eflag,vflag);
ev_init(eflag, vflag);
pvector[0] = pvector[1] = 0.0;
// Build full neighbor list
@ -355,9 +350,9 @@ void PairILPGrapheneHBN::compute(int eflag, int vflag)
// Calculate the normals and its derivatives
calc_normal();
// Calculate the van der Waals force and energy
calc_FvdW(eflag,vflag);
calc_FvdW(eflag, vflag);
// Calculate the repulsive force and energy
calc_FRep(eflag,vflag);
calc_FRep(eflag, vflag);
if (vflag_fdotr) virial_fdotr_compute();
}
@ -368,11 +363,11 @@ void PairILPGrapheneHBN::compute(int eflag, int vflag)
void PairILPGrapheneHBN::calc_FvdW(int eflag, int /* vflag */)
{
int i,j,ii,jj,inum,jnum,itype,jtype;
tagint itag,jtag;
double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair;
double rsq,r,Rcut,r2inv,r6inv,r8inv,Tap,dTap,Vilp,TSvdw,TSvdw2inv,fsum;
int *ilist,*jlist,*numneigh,**firstneigh;
int i, j, ii, jj, inum, jnum, itype, jtype;
tagint itag, jtag;
double xtmp, ytmp, ztmp, delx, dely, delz, evdwl, fpair;
double rsq, r, Rcut, r2inv, r6inv, r8inv, Tap, dTap, Vilp, TSvdw, TSvdw2inv, fsum;
int *ilist, *jlist, *numneigh, **firstneigh;
evdwl = 0.0;
double **x = atom->x;
@ -406,9 +401,9 @@ void PairILPGrapheneHBN::calc_FvdW(int eflag, int /* vflag */)
// two-body interactions from full neighbor list, skip half of them
if (itag > jtag) {
if ((itag+jtag) % 2 == 0) continue;
if ((itag + jtag) % 2 == 0) continue;
} else if (itag < jtag) {
if ((itag+jtag) % 2 == 1) continue;
if ((itag + jtag) % 2 == 1) continue;
} else {
if (x[j][2] < ztmp) continue;
if (x[j][2] == ztmp && x[j][1] < ytmp) continue;
@ -418,43 +413,46 @@ void PairILPGrapheneHBN::calc_FvdW(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;
// only include the interaction between different layers
if (rsq < cutsq[itype][jtype] && atom->molecule[i] != atom->molecule[j]) {
int iparam_ij = elem2param[map[itype]][map[jtype]];
Param& p = params[iparam_ij];
Param &p = params[iparam_ij];
r = sqrt(rsq);
r2inv = 1.0/rsq;
r6inv = r2inv*r2inv*r2inv;
r8inv = r6inv*r2inv;
r2inv = 1.0 / rsq;
r6inv = r2inv * r2inv * r2inv;
r8inv = r6inv * r2inv;
// turn on/off taper function
if (tap_flag) {
Rcut = sqrt(cutsq[itype][jtype]);
Tap = calc_Tap(r,Rcut);
dTap = calc_dTap(r,Rcut);
} else {Tap = 1.0; dTap = 0.0;}
Tap = calc_Tap(r, Rcut);
dTap = calc_dTap(r, Rcut);
} else {
Tap = 1.0;
dTap = 0.0;
}
TSvdw = 1.0 + exp(-p.d*(r/p.seff - 1.0));
TSvdw2inv = pow(TSvdw,-2.0);
Vilp = -p.C6*r6inv/TSvdw;
TSvdw = 1.0 + exp(-p.d * (r / p.seff - 1.0));
TSvdw2inv = pow(TSvdw, -2.0);
Vilp = -p.C6 * r6inv / TSvdw;
// derivatives
fpair = -6.0*p.C6*r8inv/TSvdw + p.C6*p.d/p.seff*(TSvdw-1.0)*TSvdw2inv*r8inv*r;
fsum = fpair*Tap - Vilp*dTap/r;
fpair = -6.0 * p.C6 * r8inv / TSvdw +
p.C6 * p.d / p.seff * (TSvdw - 1.0) * TSvdw2inv * r8inv * r;
fsum = fpair * Tap - Vilp * dTap / r;
f[i][0] += fsum*delx;
f[i][1] += fsum*dely;
f[i][2] += fsum*delz;
f[j][0] -= fsum*delx;
f[j][1] -= fsum*dely;
f[j][2] -= fsum*delz;
f[i][0] += fsum * delx;
f[i][1] += fsum * dely;
f[i][2] += fsum * delz;
f[j][0] -= fsum * delx;
f[j][1] -= fsum * dely;
f[j][2] -= fsum * delz;
if (eflag) pvector[0] += evdwl = Vilp*Tap;
if (evflag) ev_tally(i,j,nlocal,newton_pair,
evdwl,0.0,fsum,delx,dely,delz);
if (eflag) pvector[0] += evdwl = Vilp * Tap;
if (evflag) ev_tally(i, j, nlocal, newton_pair, evdwl, 0.0, fsum, delx, dely, delz);
}
}
}
@ -466,12 +464,12 @@ void PairILPGrapheneHBN::calc_FvdW(int eflag, int /* vflag */)
void PairILPGrapheneHBN::calc_FRep(int eflag, int /* vflag */)
{
int i,j,ii,jj,inum,jnum,itype,jtype,k,kk;
double prodnorm1,fkcx,fkcy,fkcz;
double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair,fpair1;
double rsq,r,Rcut,rhosq1,exp0,exp1,Tap,dTap,Vilp;
double frho1,Erep,fsum,rdsq1;
int *ilist,*jlist,*numneigh,**firstneigh;
int i, j, ii, jj, inum, jnum, itype, jtype, k, kk;
double prodnorm1, fkcx, fkcy, fkcz;
double xtmp, ytmp, ztmp, delx, dely, delz, evdwl, fpair, fpair1;
double rsq, r, Rcut, rhosq1, exp0, exp1, Tap, dTap, Vilp;
double frho1, Erep, fsum, rdsq1;
int *ilist, *jlist, *numneigh, **firstneigh;
int *ILP_neighs_i;
evdwl = 0.0;
@ -511,57 +509,63 @@ void PairILPGrapheneHBN::calc_FRep(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;
// only include the interaction between different layers
if (rsq < cutsq[itype][jtype] && atom->molecule[i] != atom->molecule[j]) {
int iparam_ij = elem2param[map[itype]][map[jtype]];
Param& p = params[iparam_ij];
Param &p = params[iparam_ij];
r = sqrt(rsq);
// turn on/off taper function
if (tap_flag) {
Rcut = sqrt(cutsq[itype][jtype]);
Tap = calc_Tap(r,Rcut);
dTap = calc_dTap(r,Rcut);
} else {Tap = 1.0; dTap = 0.0;}
Tap = calc_Tap(r, Rcut);
dTap = calc_dTap(r, Rcut);
} else {
Tap = 1.0;
dTap = 0.0;
}
// Calculate the transverse distance
prodnorm1 = normal[i][0]*delx + normal[i][1]*dely + normal[i][2]*delz;
rhosq1 = rsq - prodnorm1*prodnorm1; // rho_ij
rdsq1 = rhosq1*p.delta2inv; // (rho_ij/delta)^2
prodnorm1 = normal[i][0] * delx + normal[i][1] * dely + normal[i][2] * delz;
rhosq1 = rsq - prodnorm1 * prodnorm1; // rho_ij
rdsq1 = rhosq1 * p.delta2inv; // (rho_ij/delta)^2
// store exponents
exp0 = exp(-p.lambda*(r-p.z0));
exp0 = exp(-p.lambda * (r - p.z0));
exp1 = exp(-rdsq1);
frho1 = exp1*p.C;
Erep = 0.5*p.epsilon + frho1;
Vilp = exp0*Erep;
frho1 = exp1 * p.C;
Erep = 0.5 * p.epsilon + frho1;
Vilp = exp0 * Erep;
// derivatives
fpair = p.lambda*exp0/r*Erep;
fpair1 = 2.0*exp0*frho1*p.delta2inv;
fpair = p.lambda * exp0 / r * Erep;
fpair1 = 2.0 * exp0 * frho1 * p.delta2inv;
fsum = fpair + fpair1;
// derivatives of the product of rij and ni, the result is a vector
dprodnorm1[0] = dnormdri[0][0][i]*delx + dnormdri[1][0][i]*dely + dnormdri[2][0][i]*delz;
dprodnorm1[1] = dnormdri[0][1][i]*delx + dnormdri[1][1][i]*dely + dnormdri[2][1][i]*delz;
dprodnorm1[2] = dnormdri[0][2][i]*delx + dnormdri[1][2][i]*dely + dnormdri[2][2][i]*delz;
fp1[0] = prodnorm1*normal[i][0]*fpair1;
fp1[1] = prodnorm1*normal[i][1]*fpair1;
fp1[2] = prodnorm1*normal[i][2]*fpair1;
fprod1[0] = prodnorm1*dprodnorm1[0]*fpair1;
fprod1[1] = prodnorm1*dprodnorm1[1]*fpair1;
fprod1[2] = prodnorm1*dprodnorm1[2]*fpair1;
dprodnorm1[0] =
dnormdri[0][0][i] * delx + dnormdri[1][0][i] * dely + dnormdri[2][0][i] * delz;
dprodnorm1[1] =
dnormdri[0][1][i] * delx + dnormdri[1][1][i] * dely + dnormdri[2][1][i] * delz;
dprodnorm1[2] =
dnormdri[0][2][i] * delx + dnormdri[1][2][i] * dely + dnormdri[2][2][i] * delz;
fp1[0] = prodnorm1 * normal[i][0] * fpair1;
fp1[1] = prodnorm1 * normal[i][1] * fpair1;
fp1[2] = prodnorm1 * normal[i][2] * fpair1;
fprod1[0] = prodnorm1 * dprodnorm1[0] * fpair1;
fprod1[1] = prodnorm1 * dprodnorm1[1] * fpair1;
fprod1[2] = prodnorm1 * dprodnorm1[2] * fpair1;
fkcx = (delx*fsum - fp1[0])*Tap - Vilp*dTap*delx/r;
fkcy = (dely*fsum - fp1[1])*Tap - Vilp*dTap*dely/r;
fkcz = (delz*fsum - fp1[2])*Tap - Vilp*dTap*delz/r;
fkcx = (delx * fsum - fp1[0]) * Tap - Vilp * dTap * delx / r;
fkcy = (dely * fsum - fp1[1]) * Tap - Vilp * dTap * dely / r;
fkcz = (delz * fsum - fp1[2]) * Tap - Vilp * dTap * delz / r;
f[i][0] += fkcx - fprod1[0]*Tap;
f[i][1] += fkcy - fprod1[1]*Tap;
f[i][2] += fkcz - fprod1[2]*Tap;
f[i][0] += fkcx - fprod1[0] * Tap;
f[i][1] += fkcy - fprod1[1] * Tap;
f[i][2] += fkcz - fprod1[2] * Tap;
f[j][0] -= fkcx;
f[j][1] -= fkcy;
f[j][2] -= fkcz;
@ -572,26 +576,32 @@ void PairILPGrapheneHBN::calc_FRep(int eflag, int /* vflag */)
k = ILP_neighs_i[kk];
if (k == i) continue;
// derivatives of the product of rij and ni respect to rk, k=0,1,2, where atom k is the neighbors of atom i
dprodnorm1[0] = dnormal[0][0][kk][i]*delx + dnormal[1][0][kk][i]*dely + dnormal[2][0][kk][i]*delz;
dprodnorm1[1] = dnormal[0][1][kk][i]*delx + dnormal[1][1][kk][i]*dely + dnormal[2][1][kk][i]*delz;
dprodnorm1[2] = dnormal[0][2][kk][i]*delx + dnormal[1][2][kk][i]*dely + dnormal[2][2][kk][i]*delz;
fk[0] = (-prodnorm1*dprodnorm1[0]*fpair1)*Tap;
fk[1] = (-prodnorm1*dprodnorm1[1]*fpair1)*Tap;
fk[2] = (-prodnorm1*dprodnorm1[2]*fpair1)*Tap;
dprodnorm1[0] = dnormal[0][0][kk][i] * delx + dnormal[1][0][kk][i] * dely +
dnormal[2][0][kk][i] * delz;
dprodnorm1[1] = dnormal[0][1][kk][i] * delx + dnormal[1][1][kk][i] * dely +
dnormal[2][1][kk][i] * delz;
dprodnorm1[2] = dnormal[0][2][kk][i] * delx + dnormal[1][2][kk][i] * dely +
dnormal[2][2][kk][i] * delz;
fk[0] = (-prodnorm1 * dprodnorm1[0] * fpair1) * Tap;
fk[1] = (-prodnorm1 * dprodnorm1[1] * fpair1) * Tap;
fk[2] = (-prodnorm1 * dprodnorm1[2] * fpair1) * Tap;
f[k][0] += fk[0];
f[k][1] += fk[1];
f[k][2] += fk[2];
delkj[0] = x[k][0] - x[j][0];
delkj[1] = x[k][1] - x[j][1];
delkj[2] = x[k][2] - x[j][2];
if (evflag) ev_tally_xyz(k,j,nlocal,newton_pair,0.0,0.0,fk[0],fk[1],fk[2],delkj[0],delkj[1],delkj[2]);
if (evflag)
ev_tally_xyz(k, j, nlocal, newton_pair, 0.0, 0.0, fk[0], fk[1], fk[2], delkj[0],
delkj[1], delkj[2]);
}
if (eflag) pvector[1] += evdwl = Tap*Vilp;
if (evflag) ev_tally_xyz(i,j,nlocal,newton_pair,evdwl,0.0,fkcx,fkcy,fkcz,delx,dely,delz);
if (eflag) pvector[1] += evdwl = Tap * Vilp;
if (evflag)
ev_tally_xyz(i, j, nlocal, newton_pair, evdwl, 0.0, fkcx, fkcy, fkcz, delx, dely, delz);
}
} // loop over jj
} // loop over ii
} // loop over jj
} // loop over ii
}
/* ----------------------------------------------------------------------
@ -600,9 +610,9 @@ void PairILPGrapheneHBN::calc_FRep(int eflag, int /* vflag */)
void PairILPGrapheneHBN::ILP_neigh()
{
int i,j,ii,jj,n,allnum,jnum,itype,jtype;
double xtmp,ytmp,ztmp,delx,dely,delz,rsq;
int *ilist,*jlist,*numneigh,**firstneigh;
int i, j, ii, jj, n, allnum, jnum, itype, jtype;
double xtmp, ytmp, ztmp, delx, dely, delz, rsq;
int *ilist, *jlist, *numneigh, **firstneigh;
int *neighptr;
double **x = atom->x;
@ -612,8 +622,9 @@ void PairILPGrapheneHBN::ILP_neigh()
maxlocal = atom->nmax;
memory->destroy(ILP_numneigh);
memory->sfree(ILP_firstneigh);
memory->create(ILP_numneigh,maxlocal,"ILPGrapheneHBN:numneigh");
ILP_firstneigh = (int **) memory->smalloc(maxlocal*sizeof(int *),"ILPGrapheneHBN:firstneigh");
memory->create(ILP_numneigh, maxlocal, "ILPGrapheneHBN:numneigh");
ILP_firstneigh =
(int **) memory->smalloc(maxlocal * sizeof(int *), "ILPGrapheneHBN:firstneigh");
}
allnum = list->inum + list->gnum;
@ -646,20 +657,21 @@ void PairILPGrapheneHBN::ILP_neigh()
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 != 0 && rsq < cutILPsq[itype][jtype] && atom->molecule[i] == atom->molecule[j]) {
neighptr[n++] = j;
}
} // loop over jj
} // loop over jj
ILP_firstneigh[i] = neighptr;
ILP_numneigh[i] = n;
if (n > 3) error->one(FLERR,"There are too many neighbors for some atoms, please check your configuration");
if (n > 3)
error->one(FLERR,
"There are too many neighbors for some atoms, please check your configuration");
ipage->vgot(n);
if (ipage->status())
error->one(FLERR,"Neighbor list overflow, boost neigh_modify one");
if (ipage->status()) error->one(FLERR, "Neighbor list overflow, boost neigh_modify one");
}
}
@ -668,12 +680,12 @@ void PairILPGrapheneHBN::ILP_neigh()
------------------------------------------------------------------------- */
void PairILPGrapheneHBN::calc_normal()
{
int i,j,ii,jj,inum,jnum;
int cont,id,ip,m;
double nn,xtp,ytp,ztp,delx,dely,delz,nn2;
int *ilist,*jlist;
double pv12[3],pv31[3],pv23[3],n1[3],dni[3],dnn[3][3],vet[3][3],dpvdri[3][3];
double dn1[3][3][3],dpv12[3][3][3],dpv23[3][3][3],dpv31[3][3][3];
int i, j, ii, jj, inum, jnum;
int cont, id, ip, m;
double nn, xtp, ytp, ztp, delx, dely, delz, nn2;
int *ilist, *jlist;
double pv12[3], pv31[3], pv23[3], n1[3], dni[3], dnn[3][3], vet[3][3], dpvdri[3][3];
double dn1[3][3][3], dpv12[3][3][3], dpv23[3][3][3], dpv31[3][3][3];
double **x = atom->x;
@ -684,9 +696,9 @@ void PairILPGrapheneHBN::calc_normal()
memory->destroy(dnormal);
memory->destroy(dnormdri);
nmax = atom->nmax;
memory->create(normal,nmax,3,"ILPGrapheneHBN:normal");
memory->create(dnormdri,3,3,nmax,"ILPGrapheneHBN:dnormdri");
memory->create(dnormal,3,3,3,nmax,"ILPGrapheneHBN:dnormal");
memory->create(normal, nmax, 3, "ILPGrapheneHBN:normal");
memory->create(dnormdri, 3, 3, nmax, "ILPGrapheneHBN:dnormdri");
memory->create(dnormal, 3, 3, 3, nmax, "ILPGrapheneHBN:dnormal");
}
inum = list->inum;
@ -745,85 +757,78 @@ void PairILPGrapheneHBN::calc_normal()
for (id = 0; id < 3; id++) {
for (ip = 0; ip < 3; ip++) {
dnormdri[id][ip][i] = 0.0;
for (m = 0; m < 3; m++) {
dnormal[id][ip][m][i] = 0.0;
}
for (m = 0; m < 3; m++) { dnormal[id][ip][m][i] = 0.0; }
}
}
}
else if (cont == 2) {
pv12[0] = vet[0][1]*vet[1][2] - vet[1][1]*vet[0][2];
pv12[1] = vet[0][2]*vet[1][0] - vet[1][2]*vet[0][0];
pv12[2] = vet[0][0]*vet[1][1] - vet[1][0]*vet[0][1];
} else if (cont == 2) {
pv12[0] = vet[0][1] * vet[1][2] - vet[1][1] * vet[0][2];
pv12[1] = vet[0][2] * vet[1][0] - vet[1][2] * vet[0][0];
pv12[2] = vet[0][0] * vet[1][1] - vet[1][0] * vet[0][1];
// derivatives of pv12[0] to ri
dpvdri[0][0] = 0.0;
dpvdri[0][1] = vet[0][2]-vet[1][2];
dpvdri[0][2] = vet[1][1]-vet[0][1];
dpvdri[0][1] = vet[0][2] - vet[1][2];
dpvdri[0][2] = vet[1][1] - vet[0][1];
// derivatives of pv12[1] to ri
dpvdri[1][0] = vet[1][2]-vet[0][2];
dpvdri[1][0] = vet[1][2] - vet[0][2];
dpvdri[1][1] = 0.0;
dpvdri[1][2] = vet[0][0]-vet[1][0];
dpvdri[1][2] = vet[0][0] - vet[1][0];
// derivatives of pv12[2] to ri
dpvdri[2][0] = vet[0][1]-vet[1][1];
dpvdri[2][1] = vet[1][0]-vet[0][0];
dpvdri[2][0] = vet[0][1] - vet[1][1];
dpvdri[2][1] = vet[1][0] - vet[0][0];
dpvdri[2][2] = 0.0;
dpv12[0][0][0] = 0.0;
dpv12[0][1][0] = vet[1][2];
dpv12[0][0][0] = 0.0;
dpv12[0][1][0] = vet[1][2];
dpv12[0][2][0] = -vet[1][1];
dpv12[1][0][0] = -vet[1][2];
dpv12[1][1][0] = 0.0;
dpv12[1][2][0] = vet[1][0];
dpv12[2][0][0] = vet[1][1];
dpv12[1][1][0] = 0.0;
dpv12[1][2][0] = vet[1][0];
dpv12[2][0][0] = vet[1][1];
dpv12[2][1][0] = -vet[1][0];
dpv12[2][2][0] = 0.0;
dpv12[2][2][0] = 0.0;
// derivatives respect to the second neighbor, atom l
dpv12[0][0][1] = 0.0;
dpv12[0][0][1] = 0.0;
dpv12[0][1][1] = -vet[0][2];
dpv12[0][2][1] = vet[0][1];
dpv12[1][0][1] = vet[0][2];
dpv12[1][1][1] = 0.0;
dpv12[0][2][1] = vet[0][1];
dpv12[1][0][1] = vet[0][2];
dpv12[1][1][1] = 0.0;
dpv12[1][2][1] = -vet[0][0];
dpv12[2][0][1] = -vet[0][1];
dpv12[2][1][1] = vet[0][0];
dpv12[2][2][1] = 0.0;
dpv12[2][1][1] = vet[0][0];
dpv12[2][2][1] = 0.0;
// derivatives respect to the third neighbor, atom n
// derivatives of pv12 to rn is zero
for (id = 0; id < 3; id++) {
for (ip = 0; ip < 3; ip++) {
dpv12[id][ip][2] = 0.0;
}
for (ip = 0; ip < 3; ip++) { dpv12[id][ip][2] = 0.0; }
}
n1[0] = pv12[0];
n1[1] = pv12[1];
n1[2] = pv12[2];
// the magnitude of the normal vector
nn2 = n1[0]*n1[0] + n1[1]*n1[1] + n1[2]*n1[2];
nn2 = n1[0] * n1[0] + n1[1] * n1[1] + n1[2] * n1[2];
nn = sqrt(nn2);
if (nn == 0) error->one(FLERR,"The magnitude of the normal vector is zero");
if (nn == 0) error->one(FLERR, "The magnitude of the normal vector is zero");
// the unit normal vector
normal[i][0] = n1[0]/nn;
normal[i][1] = n1[1]/nn;
normal[i][2] = n1[2]/nn;
normal[i][0] = n1[0] / nn;
normal[i][1] = n1[1] / nn;
normal[i][2] = n1[2] / nn;
// derivatives of nn, dnn:3x1 vector
dni[0] = (n1[0]*dpvdri[0][0] + n1[1]*dpvdri[1][0] + n1[2]*dpvdri[2][0])/nn;
dni[1] = (n1[0]*dpvdri[0][1] + n1[1]*dpvdri[1][1] + n1[2]*dpvdri[2][1])/nn;
dni[2] = (n1[0]*dpvdri[0][2] + n1[1]*dpvdri[1][2] + n1[2]*dpvdri[2][2])/nn;
dni[0] = (n1[0] * dpvdri[0][0] + n1[1] * dpvdri[1][0] + n1[2] * dpvdri[2][0]) / nn;
dni[1] = (n1[0] * dpvdri[0][1] + n1[1] * dpvdri[1][1] + n1[2] * dpvdri[2][1]) / nn;
dni[2] = (n1[0] * dpvdri[0][2] + n1[1] * dpvdri[1][2] + n1[2] * dpvdri[2][2]) / nn;
// derivatives of unit vector ni respect to ri, the result is 3x3 matrix
for (id = 0; id < 3; id++) {
for (ip = 0; ip < 3; ip++) {
dnormdri[id][ip][i] = dpvdri[id][ip]/nn - n1[id]*dni[ip]/nn2;
dnormdri[id][ip][i] = dpvdri[id][ip] / nn - n1[id] * dni[ip] / nn2;
}
}
// derivatives of non-normalized normal vector, dn1:3x3x3 array
for (id = 0; id < 3; id++) {
for (ip = 0; ip < 3; ip++) {
for (m = 0; m < 3; m++) {
dn1[id][ip][m] = dpv12[id][ip][m];
}
for (m = 0; m < 3; m++) { dn1[id][ip][m] = dpv12[id][ip][m]; }
}
}
// derivatives of nn, dnn:3x3 vector
@ -831,7 +836,7 @@ void PairILPGrapheneHBN::calc_normal()
// r[id][m]: the id's component of atom m
for (m = 0; m < 3; m++) {
for (id = 0; id < 3; id++) {
dnn[id][m] = (n1[0]*dn1[0][id][m] + n1[1]*dn1[1][id][m] + n1[2]*dn1[2][id][m])/nn;
dnn[id][m] = (n1[0] * dn1[0][id][m] + n1[1] * dn1[1][id][m] + n1[2] * dn1[2][id][m]) / nn;
}
}
// dnormal[id][ip][m][i]: the derivative of normal[id] respect to r[ip][m], id,ip=0,1,2
@ -839,131 +844,123 @@ void PairILPGrapheneHBN::calc_normal()
for (m = 0; m < 3; m++) {
for (id = 0; id < 3; id++) {
for (ip = 0; ip < 3; ip++) {
dnormal[id][ip][m][i] = dn1[id][ip][m]/nn - n1[id]*dnn[ip][m]/nn2;
dnormal[id][ip][m][i] = dn1[id][ip][m] / nn - n1[id] * dnn[ip][m] / nn2;
}
}
}
}
//##############################################################################################
//##############################################################################################
else if (cont == 3) {
pv12[0] = vet[0][1]*vet[1][2] - vet[1][1]*vet[0][2];
pv12[1] = vet[0][2]*vet[1][0] - vet[1][2]*vet[0][0];
pv12[2] = vet[0][0]*vet[1][1] - vet[1][0]*vet[0][1];
pv12[0] = vet[0][1] * vet[1][2] - vet[1][1] * vet[0][2];
pv12[1] = vet[0][2] * vet[1][0] - vet[1][2] * vet[0][0];
pv12[2] = vet[0][0] * vet[1][1] - vet[1][0] * vet[0][1];
// derivatives respect to the first neighbor, atom k
dpv12[0][0][0] = 0.0;
dpv12[0][1][0] = vet[1][2];
dpv12[0][0][0] = 0.0;
dpv12[0][1][0] = vet[1][2];
dpv12[0][2][0] = -vet[1][1];
dpv12[1][0][0] = -vet[1][2];
dpv12[1][1][0] = 0.0;
dpv12[1][2][0] = vet[1][0];
dpv12[2][0][0] = vet[1][1];
dpv12[1][1][0] = 0.0;
dpv12[1][2][0] = vet[1][0];
dpv12[2][0][0] = vet[1][1];
dpv12[2][1][0] = -vet[1][0];
dpv12[2][2][0] = 0.0;
dpv12[2][2][0] = 0.0;
// derivatives respect to the second neighbor, atom l
dpv12[0][0][1] = 0.0;
dpv12[0][0][1] = 0.0;
dpv12[0][1][1] = -vet[0][2];
dpv12[0][2][1] = vet[0][1];
dpv12[1][0][1] = vet[0][2];
dpv12[1][1][1] = 0.0;
dpv12[0][2][1] = vet[0][1];
dpv12[1][0][1] = vet[0][2];
dpv12[1][1][1] = 0.0;
dpv12[1][2][1] = -vet[0][0];
dpv12[2][0][1] = -vet[0][1];
dpv12[2][1][1] = vet[0][0];
dpv12[2][2][1] = 0.0;
dpv12[2][1][1] = vet[0][0];
dpv12[2][2][1] = 0.0;
// derivatives respect to the third neighbor, atom n
for (id = 0; id < 3; id++) {
for (ip = 0; ip < 3; ip++) {
dpv12[id][ip][2] = 0.0;
}
for (ip = 0; ip < 3; ip++) { dpv12[id][ip][2] = 0.0; }
}
pv31[0] = vet[2][1]*vet[0][2] - vet[0][1]*vet[2][2];
pv31[1] = vet[2][2]*vet[0][0] - vet[0][2]*vet[2][0];
pv31[2] = vet[2][0]*vet[0][1] - vet[0][0]*vet[2][1];
pv31[0] = vet[2][1] * vet[0][2] - vet[0][1] * vet[2][2];
pv31[1] = vet[2][2] * vet[0][0] - vet[0][2] * vet[2][0];
pv31[2] = vet[2][0] * vet[0][1] - vet[0][0] * vet[2][1];
// derivatives respect to the first neighbor, atom k
dpv31[0][0][0] = 0.0;
dpv31[0][0][0] = 0.0;
dpv31[0][1][0] = -vet[2][2];
dpv31[0][2][0] = vet[2][1];
dpv31[1][0][0] = vet[2][2];
dpv31[1][1][0] = 0.0;
dpv31[0][2][0] = vet[2][1];
dpv31[1][0][0] = vet[2][2];
dpv31[1][1][0] = 0.0;
dpv31[1][2][0] = -vet[2][0];
dpv31[2][0][0] = -vet[2][1];
dpv31[2][1][0] = vet[2][0];
dpv31[2][2][0] = 0.0;
dpv31[2][1][0] = vet[2][0];
dpv31[2][2][0] = 0.0;
// derivatives respect to the third neighbor, atom n
dpv31[0][0][2] = 0.0;
dpv31[0][1][2] = vet[0][2];
dpv31[0][0][2] = 0.0;
dpv31[0][1][2] = vet[0][2];
dpv31[0][2][2] = -vet[0][1];
dpv31[1][0][2] = -vet[0][2];
dpv31[1][1][2] = 0.0;
dpv31[1][2][2] = vet[0][0];
dpv31[2][0][2] = vet[0][1];
dpv31[1][1][2] = 0.0;
dpv31[1][2][2] = vet[0][0];
dpv31[2][0][2] = vet[0][1];
dpv31[2][1][2] = -vet[0][0];
dpv31[2][2][2] = 0.0;
dpv31[2][2][2] = 0.0;
// derivatives respect to the second neighbor, atom l
for (id = 0; id < 3; id++) {
for (ip = 0; ip < 3; ip++) {
dpv31[id][ip][1] = 0.0;
}
for (ip = 0; ip < 3; ip++) { dpv31[id][ip][1] = 0.0; }
}
pv23[0] = vet[1][1]*vet[2][2] - vet[2][1]*vet[1][2];
pv23[1] = vet[1][2]*vet[2][0] - vet[2][2]*vet[1][0];
pv23[2] = vet[1][0]*vet[2][1] - vet[2][0]*vet[1][1];
pv23[0] = vet[1][1] * vet[2][2] - vet[2][1] * vet[1][2];
pv23[1] = vet[1][2] * vet[2][0] - vet[2][2] * vet[1][0];
pv23[2] = vet[1][0] * vet[2][1] - vet[2][0] * vet[1][1];
// derivatives respect to the second neighbor, atom k
for (id = 0; id < 3; id++) {
for (ip = 0; ip < 3; ip++) {
dpv23[id][ip][0] = 0.0;
}
for (ip = 0; ip < 3; ip++) { dpv23[id][ip][0] = 0.0; }
}
// derivatives respect to the second neighbor, atom l
dpv23[0][0][1] = 0.0;
dpv23[0][1][1] = vet[2][2];
dpv23[0][0][1] = 0.0;
dpv23[0][1][1] = vet[2][2];
dpv23[0][2][1] = -vet[2][1];
dpv23[1][0][1] = -vet[2][2];
dpv23[1][1][1] = 0.0;
dpv23[1][2][1] = vet[2][0];
dpv23[2][0][1] = vet[2][1];
dpv23[1][1][1] = 0.0;
dpv23[1][2][1] = vet[2][0];
dpv23[2][0][1] = vet[2][1];
dpv23[2][1][1] = -vet[2][0];
dpv23[2][2][1] = 0.0;
dpv23[2][2][1] = 0.0;
// derivatives respect to the third neighbor, atom n
dpv23[0][0][2] = 0.0;
dpv23[0][0][2] = 0.0;
dpv23[0][1][2] = -vet[1][2];
dpv23[0][2][2] = vet[1][1];
dpv23[1][0][2] = vet[1][2];
dpv23[1][1][2] = 0.0;
dpv23[0][2][2] = vet[1][1];
dpv23[1][0][2] = vet[1][2];
dpv23[1][1][2] = 0.0;
dpv23[1][2][2] = -vet[1][0];
dpv23[2][0][2] = -vet[1][1];
dpv23[2][1][2] = vet[1][0];
dpv23[2][2][2] = 0.0;
dpv23[2][1][2] = vet[1][0];
dpv23[2][2][2] = 0.0;
//############################################################################################
//############################################################################################
// average the normal vectors by using the 3 neighboring planes
n1[0] = (pv12[0] + pv31[0] + pv23[0])/cont;
n1[1] = (pv12[1] + pv31[1] + pv23[1])/cont;
n1[2] = (pv12[2] + pv31[2] + pv23[2])/cont;
n1[0] = (pv12[0] + pv31[0] + pv23[0]) / cont;
n1[1] = (pv12[1] + pv31[1] + pv23[1]) / cont;
n1[2] = (pv12[2] + pv31[2] + pv23[2]) / cont;
// the magnitude of the normal vector
nn2 = n1[0]*n1[0] + n1[1]*n1[1] + n1[2]*n1[2];
nn2 = n1[0] * n1[0] + n1[1] * n1[1] + n1[2] * n1[2];
nn = sqrt(nn2);
if (nn == 0) error->one(FLERR,"The magnitude of the normal vector is zero");
if (nn == 0) error->one(FLERR, "The magnitude of the normal vector is zero");
// the unit normal vector
normal[i][0] = n1[0]/nn;
normal[i][1] = n1[1]/nn;
normal[i][2] = n1[2]/nn;
normal[i][0] = n1[0] / nn;
normal[i][1] = n1[1] / nn;
normal[i][2] = n1[2] / nn;
// for the central atoms, dnormdri is always zero
for (id = 0; id < 3; id++) {
for (ip = 0; ip < 3; ip++) {
dnormdri[id][ip][i] = 0.0;
}
for (ip = 0; ip < 3; ip++) { dnormdri[id][ip][i] = 0.0; }
}
// derivatives of non-normalized normal vector, dn1:3x3x3 array
for (id = 0; id < 3; id++) {
for (ip = 0; ip < 3; ip++) {
for (m = 0; m < 3; m++) {
dn1[id][ip][m] = (dpv12[id][ip][m] + dpv23[id][ip][m] + dpv31[id][ip][m])/cont;
dn1[id][ip][m] = (dpv12[id][ip][m] + dpv23[id][ip][m] + dpv31[id][ip][m]) / cont;
}
}
}
@ -972,7 +969,7 @@ void PairILPGrapheneHBN::calc_normal()
// r[id][m]: the id's component of atom m
for (m = 0; m < 3; m++) {
for (id = 0; id < 3; id++) {
dnn[id][m] = (n1[0]*dn1[0][id][m] + n1[1]*dn1[1][id][m] + n1[2]*dn1[2][id][m])/nn;
dnn[id][m] = (n1[0] * dn1[0][id][m] + n1[1] * dn1[1][id][m] + n1[2] * dn1[2][id][m]) / nn;
}
}
// dnormal[id][ip][m][i]: the derivative of normal[id] respect to r[ip][m], id,ip=0,1,2
@ -980,50 +977,51 @@ void PairILPGrapheneHBN::calc_normal()
for (m = 0; m < 3; m++) {
for (id = 0; id < 3; id++) {
for (ip = 0; ip < 3; ip++) {
dnormal[id][ip][m][i] = dn1[id][ip][m]/nn - n1[id]*dnn[ip][m]/nn2;
dnormal[id][ip][m][i] = dn1[id][ip][m] / nn - n1[id] * dnn[ip][m] / nn2;
}
}
}
}
else {
error->one(FLERR,"There are too many neighbors for calculating normals");
} else {
error->one(FLERR, "There are too many neighbors for calculating normals");
}
//##############################################################################################
//##############################################################################################
}
}
/* ---------------------------------------------------------------------- */
double PairILPGrapheneHBN::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,r2inv,r6inv,r8inv,forcelj,philj,fpair;
double Tap,dTap,Vilp,TSvdw,TSvdw2inv;
double r, r2inv, r6inv, r8inv, forcelj, philj, fpair;
double Tap, dTap, Vilp, TSvdw, TSvdw2inv;
int iparam_ij = elem2param[map[itype]][map[jtype]];
Param& p = params[iparam_ij];
Param &p = params[iparam_ij];
r = sqrt(rsq);
// turn on/off taper function
if (tap_flag) {
Tap = calc_Tap(r,sqrt(cutsq[itype][jtype]));
dTap = calc_dTap(r,sqrt(cutsq[itype][jtype]));
} else {Tap = 1.0; dTap = 0.0;}
Tap = calc_Tap(r, sqrt(cutsq[itype][jtype]));
dTap = calc_dTap(r, sqrt(cutsq[itype][jtype]));
} else {
Tap = 1.0;
dTap = 0.0;
}
r2inv = 1.0/rsq;
r6inv = r2inv*r2inv*r2inv;
r8inv = r2inv*r6inv;
r2inv = 1.0 / rsq;
r6inv = r2inv * r2inv * r2inv;
r8inv = r2inv * r6inv;
TSvdw = 1.0 + exp(-p.d*(r/p.seff - 1.0));
TSvdw2inv = pow(TSvdw,-2.0);
Vilp = -p.C6*r6inv/TSvdw;
TSvdw = 1.0 + exp(-p.d * (r / p.seff - 1.0));
TSvdw2inv = pow(TSvdw, -2.0);
Vilp = -p.C6 * r6inv / TSvdw;
// derivatives
fpair = -6.0*p.C6*r8inv/TSvdw + p.d/p.seff*p.C6*(TSvdw - 1.0)*r6inv*TSvdw2inv/r;
fpair = -6.0 * p.C6 * r8inv / TSvdw + p.d / p.seff * p.C6 * (TSvdw - 1.0) * r6inv * TSvdw2inv / r;
forcelj = fpair;
fforce = factor_lj*(forcelj*Tap - Vilp*dTap/r);
fforce = factor_lj * (forcelj * Tap - Vilp * dTap / r);
philj = Vilp*Tap;
return factor_lj*philj;
philj = Vilp * Tap;
return factor_lj * philj;
}

View File

@ -62,7 +62,6 @@ class PairILPGrapheneHBN : public Pair {
double cut_global;
double cut_normal;
double **cut;
double **cutILPsq; // mapping the cutoff from element pairs to parameters
double **offset;
double **normal;

View File

@ -1,4 +1,3 @@
// clang-format off
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
@ -48,14 +47,14 @@ using namespace InterLayer;
#define PGDELTA 1
static const char cite_kc[] =
"@Article{Ouyang2018\n"
" author = {W. Ouyang, D. Mandelli, M. Urbakh, and O. Hod},\n"
" title = {Nanoserpents: Graphene Nanoribbon Motion on Two-Dimensional Hexagonal Materials},\n"
" journal = {Nano Letters},\n"
" volume = 18,\n"
" pages = {6009}\n"
" year = 2018,\n"
"}\n\n";
"@Article{Ouyang2018\n"
" author = {W. Ouyang, D. Mandelli, M. Urbakh, and O. Hod},\n"
" title = {Nanoserpents: Graphene Nanoribbon Motion on Two-Dimensional Hexagonal Materials},\n"
" journal = {Nano Letters},\n"
" volume = 18,\n"
" pages = {6009}\n"
" year = 2018,\n"
"}\n\n";
/* ---------------------------------------------------------------------- */
@ -100,8 +99,8 @@ PairKolmogorovCrespiFull::~PairKolmogorovCrespiFull()
{
memory->destroy(KC_numneigh);
memory->sfree(KC_firstneigh);
delete [] ipage;
delete [] pvector;
delete[] ipage;
delete[] pvector;
memory->destroy(normal);
memory->destroy(dnormal);
memory->destroy(dnormdri);
@ -109,7 +108,6 @@ PairKolmogorovCrespiFull::~PairKolmogorovCrespiFull()
if (allocated) {
memory->destroy(setflag);
memory->destroy(cutsq);
memory->destroy(cut);
memory->destroy(offset);
}
@ -125,17 +123,15 @@ PairKolmogorovCrespiFull::~PairKolmogorovCrespiFull()
void PairKolmogorovCrespiFull::allocate()
{
allocated = 1;
int n = atom->ntypes;
int n = atom->ntypes + 1;
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;
memory->create(setflag, n, n, "pair:setflag");
for (int i = 1; i < n; i++)
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(offset,n+1,n+1,"pair:offset");
map = new int[atom->ntypes+1];
memory->create(cutsq, n, n, "pair:cutsq");
memory->create(offset, n, n, "pair:offset");
map = new int[n];
}
/* ----------------------------------------------------------------------
@ -144,12 +140,12 @@ void PairKolmogorovCrespiFull::allocate()
void PairKolmogorovCrespiFull::settings(int narg, char **arg)
{
if (narg < 1 || narg > 2) error->all(FLERR,"Illegal pair_style command");
if (strcmp(force->pair_style,"hybrid/overlay")!=0)
error->all(FLERR,"ERROR: requires hybrid/overlay pair_style");
if (narg < 1 || narg > 2) error->all(FLERR, "Illegal pair_style command");
if (strcmp(force->pair_style, "hybrid/overlay") != 0)
error->all(FLERR, "ERROR: requires hybrid/overlay pair_style");
cut_global = utils::numeric(FLERR,arg[0],false,lmp);
if (narg == 2) tap_flag = utils::numeric(FLERR,arg[1],false,lmp);
cut_global = utils::numeric(FLERR, arg[0], false, lmp);
if (narg == 2) tap_flag = utils::numeric(FLERR, arg[1], false, lmp);
}
/* ----------------------------------------------------------------------
@ -159,26 +155,25 @@ void PairKolmogorovCrespiFull::settings(int narg, char **arg)
void PairKolmogorovCrespiFull::coeff(int narg, char **arg)
{
if (!allocated) allocate();
map_element2type(narg-3,arg+3);
map_element2type(narg - 3, arg + 3);
read_file(arg[2]);
}
/* ----------------------------------------------------------------------
init for one type pair i,j and corresponding j,i
------------------------------------------------------------------------- */
double PairKolmogorovCrespiFull::init_one(int i, int j)
{
if (setflag[i][j] == 0) error->all(FLERR,"All pair coeffs are not set");
if (!offset_flag)
error->all(FLERR,"Must use 'pair_modify shift yes' with this pair style");
if (setflag[i][j] == 0) error->all(FLERR, "All pair coeffs are not set");
if (!offset_flag) error->all(FLERR, "Must use 'pair_modify shift yes' with this pair style");
if (offset_flag && (cut_global > 0.0)) {
int iparam_ij = elem2param[map[i]][map[j]];
Param& p = params[iparam_ij];
offset[i][j] = -p.A*pow(p.z0/cut_global,6);
} else offset[i][j] = 0.0;
Param &p = params[iparam_ij];
offset[i][j] = -p.A * pow(p.z0 / cut_global, 6);
} else
offset[i][j] = 0.0;
offset[j][i] = offset[i][j];
return cut_global;
@ -229,29 +224,29 @@ void PairKolmogorovCrespiFull::read_file(char *filename)
if (nparams == maxparam) {
maxparam += DELTA;
params = (Param *) memory->srealloc(params,maxparam*sizeof(Param), "pair:params");
params = (Param *) memory->srealloc(params, maxparam * sizeof(Param), "pair:params");
// make certain all addional allocated storage is initialized
// to avoid false positives when checking with valgrind
memset(params + nparams, 0, DELTA*sizeof(Param));
memset(params + nparams, 0, DELTA * sizeof(Param));
}
// load up parameter settings and error check their values
params[nparams].ielement = ielement;
params[nparams].jelement = jelement;
params[nparams].z0 = values.next_double();
params[nparams].C0 = values.next_double();
params[nparams].C2 = values.next_double();
params[nparams].C4 = values.next_double();
params[nparams].C = values.next_double();
params[nparams].delta = values.next_double();
params[nparams].lambda = values.next_double();
params[nparams].A = values.next_double();
params[nparams].z0 = values.next_double();
params[nparams].C0 = values.next_double();
params[nparams].C2 = values.next_double();
params[nparams].C4 = values.next_double();
params[nparams].C = values.next_double();
params[nparams].delta = values.next_double();
params[nparams].lambda = values.next_double();
params[nparams].A = values.next_double();
// S provides a convenient scaling of all energies
params[nparams].S = values.next_double();
params[nparams].rcut = values.next_double();
params[nparams].S = values.next_double();
params[nparams].rcut = values.next_double();
} catch (TokenizerException &e) {
error->one(FLERR, e.what());
@ -259,7 +254,7 @@ void PairKolmogorovCrespiFull::read_file(char *filename)
// energies in meV further scaled by S
double meV = 1.0e-3*params[nparams].S;
double meV = 1.0e-3 * params[nparams].S;
if (unit_convert) meV *= conversion_factor;
params[nparams].C *= meV;
@ -269,8 +264,8 @@ void PairKolmogorovCrespiFull::read_file(char *filename)
params[nparams].C4 *= meV;
// precompute some quantities
params[nparams].delta2inv = pow(params[nparams].delta,-2);
params[nparams].z06 = pow(params[nparams].z0,6);
params[nparams].delta2inv = pow(params[nparams].delta, -2);
params[nparams].z06 = pow(params[nparams].z0, 6);
nparams++;
}
@ -279,28 +274,28 @@ void PairKolmogorovCrespiFull::read_file(char *filename)
MPI_Bcast(&maxparam, 1, MPI_INT, 0, world);
if (comm->me != 0) {
params = (Param *) memory->srealloc(params,maxparam*sizeof(Param), "pair:params");
params = (Param *) memory->srealloc(params, maxparam * sizeof(Param), "pair:params");
}
MPI_Bcast(params, maxparam*sizeof(Param), MPI_BYTE, 0, world);
MPI_Bcast(params, maxparam * sizeof(Param), MPI_BYTE, 0, world);
}
memory->destroy(elem2param);
memory->destroy(cutKCsq);
memory->create(elem2param,nelements,nelements,"pair:elem2param");
memory->create(cutKCsq,nelements,nelements,"pair:cutKCsq");
memory->create(elem2param, nelements, nelements, "pair:elem2param");
memory->create(cutKCsq, nelements, nelements, "pair:cutKCsq");
for (int i = 0; i < nelements; i++) {
for (int j = 0; j < nelements; j++) {
int n = -1;
for (int m = 0; m < nparams; m++) {
if (i == params[m].ielement && j == params[m].jelement) {
if (n >= 0) error->all(FLERR,"KC Potential file has duplicate entry");
if (n >= 0) error->all(FLERR, "KC Potential file has duplicate entry");
n = m;
}
}
if (n < 0) error->all(FLERR,"Potential file is missing an entry");
if (n < 0) error->all(FLERR, "Potential file is missing an entry");
elem2param[i][j] = n;
cutKCsq[i][j] = params[n].rcut*params[n].rcut;
cutKCsq[i][j] = params[n].rcut * params[n].rcut;
}
}
}
@ -312,13 +307,13 @@ void PairKolmogorovCrespiFull::read_file(char *filename)
void PairKolmogorovCrespiFull::init_style()
{
if (force->newton_pair == 0)
error->all(FLERR,"Pair style kolmolgorov/crespi/full requires newton pair on");
error->all(FLERR, "Pair style kolmolgorov/crespi/full requires newton pair on");
if (!atom->molecule_flag)
error->all(FLERR,"Pair style kolmolgorov/crespi/full requires atom attribute molecule");
error->all(FLERR, "Pair style kolmolgorov/crespi/full requires atom attribute molecule");
// need a full neighbor list, including neighbors of ghosts
int irequest = neighbor->request(this,instance_me);
int irequest = neighbor->request(this, instance_me);
neighbor->requests[irequest]->half = 0;
neighbor->requests[irequest]->full = 1;
neighbor->requests[irequest]->ghost = 1;
@ -332,14 +327,13 @@ void PairKolmogorovCrespiFull::init_style()
if (oneatom != neighbor->oneatom) create = 1;
if (create) {
delete [] ipage;
delete[] ipage;
pgsize = neighbor->pgsize;
oneatom = neighbor->oneatom;
int nmypage= comm->nthreads;
int nmypage = comm->nthreads;
ipage = new MyPage<int>[nmypage];
for (int i = 0; i < nmypage; i++)
ipage[i].init(oneatom,pgsize,PGDELTA);
for (int i = 0; i < nmypage; i++) ipage[i].init(oneatom, pgsize, PGDELTA);
}
}
@ -347,7 +341,7 @@ void PairKolmogorovCrespiFull::init_style()
void PairKolmogorovCrespiFull::compute(int eflag, int vflag)
{
ev_init(eflag,vflag);
ev_init(eflag, vflag);
pvector[0] = pvector[1] = 0.0;
// Build full neighbor list
@ -355,9 +349,9 @@ void PairKolmogorovCrespiFull::compute(int eflag, int vflag)
// Calculate the normals and its derivatives
calc_normal();
// Calculate the van der Waals force and energy
calc_FvdW(eflag,vflag);
calc_FvdW(eflag, vflag);
// Calculate the repulsive force and energy
calc_FRep(eflag,vflag);
calc_FRep(eflag, vflag);
if (vflag_fdotr) virial_fdotr_compute();
}
@ -368,11 +362,11 @@ void PairKolmogorovCrespiFull::compute(int eflag, int vflag)
void PairKolmogorovCrespiFull::calc_FvdW(int eflag, int /* vflag */)
{
int i,j,ii,jj,inum,jnum,itype,jtype;
tagint itag,jtag;
double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair;
double rsq,r,Rcut,r2inv,r6inv,r8inv,Tap,dTap,Vkc,fsum;
int *ilist,*jlist,*numneigh,**firstneigh;
int i, j, ii, jj, inum, jnum, itype, jtype;
tagint itag, jtag;
double xtmp, ytmp, ztmp, delx, dely, delz, evdwl, fpair;
double rsq, r, Rcut, r2inv, r6inv, r8inv, Tap, dTap, Vkc, fsum;
int *ilist, *jlist, *numneigh, **firstneigh;
evdwl = 0.0;
double **x = atom->x;
@ -406,9 +400,9 @@ void PairKolmogorovCrespiFull::calc_FvdW(int eflag, int /* vflag */)
// two-body interactions from full neighbor list, skip half of them
if (itag > jtag) {
if ((itag+jtag) % 2 == 0) continue;
if ((itag + jtag) % 2 == 0) continue;
} else if (itag < jtag) {
if ((itag+jtag) % 2 == 1) continue;
if ((itag + jtag) % 2 == 1) continue;
} else {
if (x[j][2] < ztmp) continue;
if (x[j][2] == ztmp && x[j][1] < ytmp) continue;
@ -418,41 +412,43 @@ void PairKolmogorovCrespiFull::calc_FvdW(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;
// only include the interaction between different layers
if (rsq < cutsq[itype][jtype] && atom->molecule[i] != atom->molecule[j]) {
int iparam_ij = elem2param[map[itype]][map[jtype]];
Param& p = params[iparam_ij];
Param &p = params[iparam_ij];
r = sqrt(rsq);
r2inv = 1.0/rsq;
r6inv = r2inv*r2inv*r2inv;
r8inv = r6inv*r2inv;
r2inv = 1.0 / rsq;
r6inv = r2inv * r2inv * r2inv;
r8inv = r6inv * r2inv;
// turn on/off taper function
if (tap_flag) {
Rcut = sqrt(cutsq[itype][jtype]);
Tap = calc_Tap(r,Rcut);
dTap = calc_dTap(r,Rcut);
} else {Tap = 1.0; dTap = 0.0;}
Tap = calc_Tap(r, Rcut);
dTap = calc_dTap(r, Rcut);
} else {
Tap = 1.0;
dTap = 0.0;
}
Vkc = -p.A*p.z06*r6inv;
Vkc = -p.A * p.z06 * r6inv;
// derivatives
fpair = -6.0*p.A*p.z06*r8inv;
fsum = fpair*Tap - Vkc*dTap/r;
fpair = -6.0 * p.A * p.z06 * r8inv;
fsum = fpair * Tap - Vkc * dTap / r;
f[i][0] += fsum*delx;
f[i][1] += fsum*dely;
f[i][2] += fsum*delz;
f[j][0] -= fsum*delx;
f[j][1] -= fsum*dely;
f[j][2] -= fsum*delz;
f[i][0] += fsum * delx;
f[i][1] += fsum * dely;
f[i][2] += fsum * delz;
f[j][0] -= fsum * delx;
f[j][1] -= fsum * dely;
f[j][2] -= fsum * delz;
if (eflag) pvector[0] += evdwl = Vkc*Tap;
if (evflag) ev_tally(i,j,nlocal,newton_pair,
evdwl,0.0,fsum,delx,dely,delz);
if (eflag) pvector[0] += evdwl = Vkc * Tap;
if (evflag) ev_tally(i, j, nlocal, newton_pair, evdwl, 0.0, fsum, delx, dely, delz);
}
}
}
@ -464,12 +460,12 @@ void PairKolmogorovCrespiFull::calc_FvdW(int eflag, int /* vflag */)
void PairKolmogorovCrespiFull::calc_FRep(int eflag, int /* vflag */)
{
int i,j,ii,jj,inum,jnum,itype,jtype,k,kk;
double prodnorm1,fkcx,fkcy,fkcz;
double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair,fpair1;
double rsq,r,rhosq1,exp0,exp1,Tap,dTap,Vkc;
double frho_ij,sumC1,sumC11,sumCff,fsum,rho_ij;
int *ilist,*jlist,*numneigh,**firstneigh;
int i, j, ii, jj, inum, jnum, itype, jtype, k, kk;
double prodnorm1, fkcx, fkcy, fkcz;
double xtmp, ytmp, ztmp, delx, dely, delz, evdwl, fpair, fpair1;
double rsq, r, rhosq1, exp0, exp1, Tap, dTap, Vkc;
double frho_ij, sumC1, sumC11, sumCff, fsum, rho_ij;
int *ilist, *jlist, *numneigh, **firstneigh;
int *KC_neighs_i;
evdwl = 0.0;
@ -509,58 +505,64 @@ void PairKolmogorovCrespiFull::calc_FRep(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;
// only include the interaction between different layers
if (rsq < cutsq[itype][jtype] && atom->molecule[i] != atom->molecule[j]) {
int iparam_ij = elem2param[map[itype]][map[jtype]];
Param& p = params[iparam_ij];
Param &p = params[iparam_ij];
r = sqrt(rsq);
// turn on/off taper function
if (tap_flag) {
Tap = calc_Tap(r,sqrt(cutsq[itype][jtype]));
dTap = calc_dTap(r,sqrt(cutsq[itype][jtype]));
} else {Tap = 1.0; dTap = 0.0;}
Tap = calc_Tap(r, sqrt(cutsq[itype][jtype]));
dTap = calc_dTap(r, sqrt(cutsq[itype][jtype]));
} else {
Tap = 1.0;
dTap = 0.0;
}
// Calculate the transverse distance
prodnorm1 = normal[i][0]*delx + normal[i][1]*dely + normal[i][2]*delz;
rhosq1 = rsq - prodnorm1*prodnorm1; // rho_ij
rho_ij = rhosq1*p.delta2inv; // (rho_ij/delta)^2
prodnorm1 = normal[i][0] * delx + normal[i][1] * dely + normal[i][2] * delz;
rhosq1 = rsq - prodnorm1 * prodnorm1; // rho_ij
rho_ij = rhosq1 * p.delta2inv; // (rho_ij/delta)^2
// store exponents
exp0 = exp(-p.lambda*(r-p.z0));
exp0 = exp(-p.lambda * (r - p.z0));
exp1 = exp(-rho_ij);
sumC1 = p.C0 + p.C2*rho_ij + p.C4*rho_ij*rho_ij;
sumC11 = (p.C2 + 2.0*p.C4*rho_ij)*p.delta2inv;
frho_ij = exp1*sumC1;
sumCff = 0.5*p.C + frho_ij;
Vkc = exp0*sumCff;
sumC1 = p.C0 + p.C2 * rho_ij + p.C4 * rho_ij * rho_ij;
sumC11 = (p.C2 + 2.0 * p.C4 * rho_ij) * p.delta2inv;
frho_ij = exp1 * sumC1;
sumCff = 0.5 * p.C + frho_ij;
Vkc = exp0 * sumCff;
// derivatives
fpair = p.lambda*exp0/r*sumCff;
fpair1 = 2.0*exp0*exp1*(p.delta2inv*sumC1 - sumC11);
fpair = p.lambda * exp0 / r * sumCff;
fpair1 = 2.0 * exp0 * exp1 * (p.delta2inv * sumC1 - sumC11);
fsum = fpair + fpair1;
// derivatives of the product of rij and ni, the result is a vector
dprodnorm1[0] = dnormdri[0][0][i]*delx + dnormdri[1][0][i]*dely + dnormdri[2][0][i]*delz;
dprodnorm1[1] = dnormdri[0][1][i]*delx + dnormdri[1][1][i]*dely + dnormdri[2][1][i]*delz;
dprodnorm1[2] = dnormdri[0][2][i]*delx + dnormdri[1][2][i]*dely + dnormdri[2][2][i]*delz;
fp1[0] = prodnorm1*normal[i][0]*fpair1;
fp1[1] = prodnorm1*normal[i][1]*fpair1;
fp1[2] = prodnorm1*normal[i][2]*fpair1;
fprod1[0] = prodnorm1*dprodnorm1[0]*fpair1;
fprod1[1] = prodnorm1*dprodnorm1[1]*fpair1;
fprod1[2] = prodnorm1*dprodnorm1[2]*fpair1;
fkcx = (delx*fsum - fp1[0])*Tap - Vkc*dTap*delx/r;
fkcy = (dely*fsum - fp1[1])*Tap - Vkc*dTap*dely/r;
fkcz = (delz*fsum - fp1[2])*Tap - Vkc*dTap*delz/r;
dprodnorm1[0] =
dnormdri[0][0][i] * delx + dnormdri[1][0][i] * dely + dnormdri[2][0][i] * delz;
dprodnorm1[1] =
dnormdri[0][1][i] * delx + dnormdri[1][1][i] * dely + dnormdri[2][1][i] * delz;
dprodnorm1[2] =
dnormdri[0][2][i] * delx + dnormdri[1][2][i] * dely + dnormdri[2][2][i] * delz;
fp1[0] = prodnorm1 * normal[i][0] * fpair1;
fp1[1] = prodnorm1 * normal[i][1] * fpair1;
fp1[2] = prodnorm1 * normal[i][2] * fpair1;
fprod1[0] = prodnorm1 * dprodnorm1[0] * fpair1;
fprod1[1] = prodnorm1 * dprodnorm1[1] * fpair1;
fprod1[2] = prodnorm1 * dprodnorm1[2] * fpair1;
fkcx = (delx * fsum - fp1[0]) * Tap - Vkc * dTap * delx / r;
fkcy = (dely * fsum - fp1[1]) * Tap - Vkc * dTap * dely / r;
fkcz = (delz * fsum - fp1[2]) * Tap - Vkc * dTap * delz / r;
f[i][0] += fkcx - fprod1[0]*Tap;
f[i][1] += fkcy - fprod1[1]*Tap;
f[i][2] += fkcz - fprod1[2]*Tap;
f[i][0] += fkcx - fprod1[0] * Tap;
f[i][1] += fkcy - fprod1[1] * Tap;
f[i][2] += fkcz - fprod1[2] * Tap;
f[j][0] -= fkcx;
f[j][1] -= fkcy;
f[j][2] -= fkcz;
@ -571,29 +573,37 @@ void PairKolmogorovCrespiFull::calc_FRep(int eflag, int /* vflag */)
k = KC_neighs_i[kk];
if (k == i) continue;
// derivatives of the product of rij and ni respect to rk, k=0,1,2, where atom k is the neighbors of atom i
dprodnorm1[0] = dnormal[0][0][kk][i]*delx + dnormal[1][0][kk][i]*dely + dnormal[2][0][kk][i]*delz;
dprodnorm1[1] = dnormal[0][1][kk][i]*delx + dnormal[1][1][kk][i]*dely + dnormal[2][1][kk][i]*delz;
dprodnorm1[2] = dnormal[0][2][kk][i]*delx + dnormal[1][2][kk][i]*dely + dnormal[2][2][kk][i]*delz;
fk[0] = (-prodnorm1*dprodnorm1[0]*fpair1)*Tap;
fk[1] = (-prodnorm1*dprodnorm1[1]*fpair1)*Tap;
fk[2] = (-prodnorm1*dprodnorm1[2]*fpair1)*Tap;
dprodnorm1[0] = dnormal[0][0][kk][i] * delx + dnormal[1][0][kk][i] * dely +
dnormal[2][0][kk][i] * delz;
dprodnorm1[1] = dnormal[0][1][kk][i] * delx + dnormal[1][1][kk][i] * dely +
dnormal[2][1][kk][i] * delz;
dprodnorm1[2] = dnormal[0][2][kk][i] * delx + dnormal[1][2][kk][i] * dely +
dnormal[2][2][kk][i] * delz;
fk[0] = (-prodnorm1 * dprodnorm1[0] * fpair1) * Tap;
fk[1] = (-prodnorm1 * dprodnorm1[1] * fpair1) * Tap;
fk[2] = (-prodnorm1 * dprodnorm1[2] * fpair1) * Tap;
f[k][0] += fk[0];
f[k][1] += fk[1];
f[k][2] += fk[2];
delkj[0] = x[k][0] - x[j][0];
delkj[1] = x[k][1] - x[j][1];
delkj[2] = x[k][2] - x[j][2];
if (evflag) ev_tally_xyz(k,j,nlocal,newton_pair,0.0,0.0,fk[0],fk[1],fk[2],delkj[0],delkj[1],delkj[2]);
if (evflag)
ev_tally_xyz(k, j, nlocal, newton_pair, 0.0, 0.0, fk[0], fk[1], fk[2], delkj[0],
delkj[1], delkj[2]);
}
if (eflag) {
if (tap_flag) pvector[1] += evdwl = Tap*Vkc;
else pvector[1] += evdwl = Vkc - offset[itype][jtype];
if (tap_flag)
pvector[1] += evdwl = Tap * Vkc;
else
pvector[1] += evdwl = Vkc - offset[itype][jtype];
}
if (evflag) ev_tally_xyz(i,j,nlocal,newton_pair,evdwl,0.0,fkcx,fkcy,fkcz,delx,dely,delz);
if (evflag)
ev_tally_xyz(i, j, nlocal, newton_pair, evdwl, 0.0, fkcx, fkcy, fkcz, delx, dely, delz);
}
} // loop over jj
} // loop over ii
} // loop over jj
} // loop over ii
}
/* ----------------------------------------------------------------------
@ -602,9 +612,9 @@ void PairKolmogorovCrespiFull::calc_FRep(int eflag, int /* vflag */)
void PairKolmogorovCrespiFull::KC_neigh()
{
int i,j,ii,jj,n,allnum,jnum,itype,jtype;
double xtmp,ytmp,ztmp,delx,dely,delz,rsq;
int *ilist,*jlist,*numneigh,**firstneigh;
int i, j, ii, jj, n, allnum, jnum, itype, jtype;
double xtmp, ytmp, ztmp, delx, dely, delz, rsq;
int *ilist, *jlist, *numneigh, **firstneigh;
int *neighptr;
double **x = atom->x;
@ -614,9 +624,9 @@ void PairKolmogorovCrespiFull::KC_neigh()
maxlocal = atom->nmax;
memory->destroy(KC_numneigh);
memory->sfree(KC_firstneigh);
memory->create(KC_numneigh,maxlocal,"KolmogorovCrespiFull:numneigh");
KC_firstneigh = (int **) memory->smalloc(maxlocal*sizeof(int *),
"KolmogorovCrespiFull:firstneigh");
memory->create(KC_numneigh, maxlocal, "KolmogorovCrespiFull:numneigh");
KC_firstneigh =
(int **) memory->smalloc(maxlocal * sizeof(int *), "KolmogorovCrespiFull:firstneigh");
}
allnum = list->inum + list->gnum;
@ -649,7 +659,7 @@ void PairKolmogorovCrespiFull::KC_neigh()
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 != 0 && rsq < cutKCsq[itype][jtype] && atom->molecule[i] == atom->molecule[j]) {
neighptr[n++] = j;
@ -658,11 +668,12 @@ void PairKolmogorovCrespiFull::KC_neigh()
KC_firstneigh[i] = neighptr;
KC_numneigh[i] = n;
if (n > 3) error->one(FLERR,"There are too many neighbors for some atoms, please check your configuration");
if (n > 3)
error->one(FLERR,
"There are too many neighbors for some atoms, please check your configuration");
ipage->vgot(n);
if (ipage->status())
error->one(FLERR,"Neighbor list overflow, boost neigh_modify one");
if (ipage->status()) error->one(FLERR, "Neighbor list overflow, boost neigh_modify one");
}
}
@ -671,12 +682,12 @@ void PairKolmogorovCrespiFull::KC_neigh()
------------------------------------------------------------------------- */
void PairKolmogorovCrespiFull::calc_normal()
{
int i,j,ii,jj,inum,jnum;
int cont,id,ip,m;
double nn,xtp,ytp,ztp,delx,dely,delz,nn2;
int *ilist,*jlist;
double pv12[3],pv31[3],pv23[3],n1[3],dni[3],dnn[3][3],vet[3][3],dpvdri[3][3];
double dn1[3][3][3],dpv12[3][3][3],dpv23[3][3][3],dpv31[3][3][3];
int i, j, ii, jj, inum, jnum;
int cont, id, ip, m;
double nn, xtp, ytp, ztp, delx, dely, delz, nn2;
int *ilist, *jlist;
double pv12[3], pv31[3], pv23[3], n1[3], dni[3], dnn[3][3], vet[3][3], dpvdri[3][3];
double dn1[3][3][3], dpv12[3][3][3], dpv23[3][3][3], dpv31[3][3][3];
double **x = atom->x;
@ -687,9 +698,9 @@ void PairKolmogorovCrespiFull::calc_normal()
memory->destroy(dnormal);
memory->destroy(dnormdri);
nmax = atom->nmax;
memory->create(normal,nmax,3,"KolmogorovCrespiFull:normal");
memory->create(dnormdri,3,3,nmax,"KolmogorovCrespiFull:dnormdri");
memory->create(dnormal,3,3,3,nmax,"KolmogorovCrespiFull:dnormal");
memory->create(normal, nmax, 3, "KolmogorovCrespiFull:normal");
memory->create(dnormdri, 3, 3, nmax, "KolmogorovCrespiFull:dnormdri");
memory->create(dnormal, 3, 3, 3, nmax, "KolmogorovCrespiFull:dnormal");
}
inum = list->inum;
@ -749,84 +760,77 @@ void PairKolmogorovCrespiFull::calc_normal()
for (id = 0; id < 3; id++) {
for (ip = 0; ip < 3; ip++) {
dnormdri[id][ip][i] = 0.0;
for (m = 0; m < 3; m++) {
dnormal[id][ip][m][i] = 0.0;
}
for (m = 0; m < 3; m++) { dnormal[id][ip][m][i] = 0.0; }
}
}
}
else if (cont == 2) {
} else if (cont == 2) {
// for the atoms at the edge who has only two neighbor atoms
pv12[0] = vet[0][1]*vet[1][2] - vet[1][1]*vet[0][2];
pv12[1] = vet[0][2]*vet[1][0] - vet[1][2]*vet[0][0];
pv12[2] = vet[0][0]*vet[1][1] - vet[1][0]*vet[0][1];
pv12[0] = vet[0][1] * vet[1][2] - vet[1][1] * vet[0][2];
pv12[1] = vet[0][2] * vet[1][0] - vet[1][2] * vet[0][0];
pv12[2] = vet[0][0] * vet[1][1] - vet[1][0] * vet[0][1];
dpvdri[0][0] = 0.0;
dpvdri[0][1] = vet[0][2]-vet[1][2];
dpvdri[0][2] = vet[1][1]-vet[0][1];
dpvdri[1][0] = vet[1][2]-vet[0][2];
dpvdri[0][1] = vet[0][2] - vet[1][2];
dpvdri[0][2] = vet[1][1] - vet[0][1];
dpvdri[1][0] = vet[1][2] - vet[0][2];
dpvdri[1][1] = 0.0;
dpvdri[1][2] = vet[0][0]-vet[1][0];
dpvdri[2][0] = vet[0][1]-vet[1][1];
dpvdri[2][1] = vet[1][0]-vet[0][0];
dpvdri[1][2] = vet[0][0] - vet[1][0];
dpvdri[2][0] = vet[0][1] - vet[1][1];
dpvdri[2][1] = vet[1][0] - vet[0][0];
dpvdri[2][2] = 0.0;
// derivatives respect to the first neighbor, atom k
dpv12[0][0][0] = 0.0;
dpv12[0][1][0] = vet[1][2];
dpv12[0][0][0] = 0.0;
dpv12[0][1][0] = vet[1][2];
dpv12[0][2][0] = -vet[1][1];
dpv12[1][0][0] = -vet[1][2];
dpv12[1][1][0] = 0.0;
dpv12[1][2][0] = vet[1][0];
dpv12[2][0][0] = vet[1][1];
dpv12[1][1][0] = 0.0;
dpv12[1][2][0] = vet[1][0];
dpv12[2][0][0] = vet[1][1];
dpv12[2][1][0] = -vet[1][0];
dpv12[2][2][0] = 0.0;
dpv12[2][2][0] = 0.0;
// derivatives respect to the second neighbor, atom l
dpv12[0][0][1] = 0.0;
dpv12[0][0][1] = 0.0;
dpv12[0][1][1] = -vet[0][2];
dpv12[0][2][1] = vet[0][1];
dpv12[1][0][1] = vet[0][2];
dpv12[1][1][1] = 0.0;
dpv12[0][2][1] = vet[0][1];
dpv12[1][0][1] = vet[0][2];
dpv12[1][1][1] = 0.0;
dpv12[1][2][1] = -vet[0][0];
dpv12[2][0][1] = -vet[0][1];
dpv12[2][1][1] = vet[0][0];
dpv12[2][2][1] = 0.0;
dpv12[2][1][1] = vet[0][0];
dpv12[2][2][1] = 0.0;
// derivatives respect to the third neighbor, atom n
for (id = 0; id < 3; id++) {
for (ip = 0; ip < 3; ip++) {
dpv12[id][ip][2] = 0.0;
}
for (ip = 0; ip < 3; ip++) { dpv12[id][ip][2] = 0.0; }
}
n1[0] = pv12[0];
n1[1] = pv12[1];
n1[2] = pv12[2];
// the magnitude of the normal vector
nn2 = n1[0]*n1[0] + n1[1]*n1[1] + n1[2]*n1[2];
nn2 = n1[0] * n1[0] + n1[1] * n1[1] + n1[2] * n1[2];
nn = sqrt(nn2);
if (nn == 0) error->one(FLERR,"The magnitude of the normal vector is zero");
if (nn == 0) error->one(FLERR, "The magnitude of the normal vector is zero");
// the unit normal vector
normal[i][0] = n1[0]/nn;
normal[i][1] = n1[1]/nn;
normal[i][2] = n1[2]/nn;
normal[i][0] = n1[0] / nn;
normal[i][1] = n1[1] / nn;
normal[i][2] = n1[2] / nn;
// derivatives of nn, dnn:3x1 vector
dni[0] = (n1[0]*dpvdri[0][0] + n1[1]*dpvdri[1][0] + n1[2]*dpvdri[2][0])/nn;
dni[1] = (n1[0]*dpvdri[0][1] + n1[1]*dpvdri[1][1] + n1[2]*dpvdri[2][1])/nn;
dni[2] = (n1[0]*dpvdri[0][2] + n1[1]*dpvdri[1][2] + n1[2]*dpvdri[2][2])/nn;
dni[0] = (n1[0] * dpvdri[0][0] + n1[1] * dpvdri[1][0] + n1[2] * dpvdri[2][0]) / nn;
dni[1] = (n1[0] * dpvdri[0][1] + n1[1] * dpvdri[1][1] + n1[2] * dpvdri[2][1]) / nn;
dni[2] = (n1[0] * dpvdri[0][2] + n1[1] * dpvdri[1][2] + n1[2] * dpvdri[2][2]) / nn;
// derivatives of unit vector ni respect to ri, the result is 3x3 matrix
for (id = 0; id < 3; id++) {
for (ip = 0; ip < 3; ip++) {
dnormdri[id][ip][i] = dpvdri[id][ip]/nn - n1[id]*dni[ip]/nn2;
dnormdri[id][ip][i] = dpvdri[id][ip] / nn - n1[id] * dni[ip] / nn2;
}
}
// derivatives of non-normalized normal vector, dn1:3x3x3 array
for (id = 0; id < 3; id++) {
for (ip = 0; ip < 3; ip++) {
for (m = 0; m < 3; m++) {
dn1[id][ip][m] = dpv12[id][ip][m];
}
for (m = 0; m < 3; m++) { dn1[id][ip][m] = dpv12[id][ip][m]; }
}
}
// derivatives of nn, dnn:3x3 vector
@ -834,7 +838,7 @@ void PairKolmogorovCrespiFull::calc_normal()
// r[id][m]: the id's component of atom m
for (m = 0; m < 3; m++) {
for (id = 0; id < 3; id++) {
dnn[id][m] = (n1[0]*dn1[0][id][m] + n1[1]*dn1[1][id][m] + n1[2]*dn1[2][id][m])/nn;
dnn[id][m] = (n1[0] * dn1[0][id][m] + n1[1] * dn1[1][id][m] + n1[2] * dn1[2][id][m]) / nn;
}
}
// dnormal[id][ip][m][i]: the derivative of normal[id] respect to r[ip][m], id,ip=0,1,2
@ -842,135 +846,127 @@ void PairKolmogorovCrespiFull::calc_normal()
for (m = 0; m < 3; m++) {
for (id = 0; id < 3; id++) {
for (ip = 0; ip < 3; ip++) {
dnormal[id][ip][m][i] = dn1[id][ip][m]/nn - n1[id]*dnn[ip][m]/nn2;
dnormal[id][ip][m][i] = dn1[id][ip][m] / nn - n1[id] * dnn[ip][m] / nn2;
}
}
}
}
//##############################################################################################
//##############################################################################################
else if (cont == 3) {
// for the atoms at the edge who has only two neighbor atoms
pv12[0] = vet[0][1]*vet[1][2] - vet[1][1]*vet[0][2];
pv12[1] = vet[0][2]*vet[1][0] - vet[1][2]*vet[0][0];
pv12[2] = vet[0][0]*vet[1][1] - vet[1][0]*vet[0][1];
pv12[0] = vet[0][1] * vet[1][2] - vet[1][1] * vet[0][2];
pv12[1] = vet[0][2] * vet[1][0] - vet[1][2] * vet[0][0];
pv12[2] = vet[0][0] * vet[1][1] - vet[1][0] * vet[0][1];
// derivatives respect to the first neighbor, atom k
dpv12[0][0][0] = 0.0;
dpv12[0][1][0] = vet[1][2];
dpv12[0][0][0] = 0.0;
dpv12[0][1][0] = vet[1][2];
dpv12[0][2][0] = -vet[1][1];
dpv12[1][0][0] = -vet[1][2];
dpv12[1][1][0] = 0.0;
dpv12[1][2][0] = vet[1][0];
dpv12[2][0][0] = vet[1][1];
dpv12[1][1][0] = 0.0;
dpv12[1][2][0] = vet[1][0];
dpv12[2][0][0] = vet[1][1];
dpv12[2][1][0] = -vet[1][0];
dpv12[2][2][0] = 0.0;
dpv12[2][2][0] = 0.0;
// derivatives respect to the second neighbor, atom l
dpv12[0][0][1] = 0.0;
dpv12[0][0][1] = 0.0;
dpv12[0][1][1] = -vet[0][2];
dpv12[0][2][1] = vet[0][1];
dpv12[1][0][1] = vet[0][2];
dpv12[1][1][1] = 0.0;
dpv12[0][2][1] = vet[0][1];
dpv12[1][0][1] = vet[0][2];
dpv12[1][1][1] = 0.0;
dpv12[1][2][1] = -vet[0][0];
dpv12[2][0][1] = -vet[0][1];
dpv12[2][1][1] = vet[0][0];
dpv12[2][2][1] = 0.0;
dpv12[2][1][1] = vet[0][0];
dpv12[2][2][1] = 0.0;
// derivatives respect to the third neighbor, atom n
for (id = 0; id < 3; id++) {
for (ip = 0; ip < 3; ip++) {
dpv12[id][ip][2] = 0.0;
}
for (ip = 0; ip < 3; ip++) { dpv12[id][ip][2] = 0.0; }
}
pv31[0] = vet[2][1]*vet[0][2] - vet[0][1]*vet[2][2];
pv31[1] = vet[2][2]*vet[0][0] - vet[0][2]*vet[2][0];
pv31[2] = vet[2][0]*vet[0][1] - vet[0][0]*vet[2][1];
pv31[0] = vet[2][1] * vet[0][2] - vet[0][1] * vet[2][2];
pv31[1] = vet[2][2] * vet[0][0] - vet[0][2] * vet[2][0];
pv31[2] = vet[2][0] * vet[0][1] - vet[0][0] * vet[2][1];
// derivatives respect to the first neighbor, atom k
dpv31[0][0][0] = 0.0;
dpv31[0][0][0] = 0.0;
dpv31[0][1][0] = -vet[2][2];
dpv31[0][2][0] = vet[2][1];
dpv31[1][0][0] = vet[2][2];
dpv31[1][1][0] = 0.0;
dpv31[0][2][0] = vet[2][1];
dpv31[1][0][0] = vet[2][2];
dpv31[1][1][0] = 0.0;
dpv31[1][2][0] = -vet[2][0];
dpv31[2][0][0] = -vet[2][1];
dpv31[2][1][0] = vet[2][0];
dpv31[2][2][0] = 0.0;
dpv31[2][1][0] = vet[2][0];
dpv31[2][2][0] = 0.0;
// derivatives respect to the third neighbor, atom n
dpv31[0][0][2] = 0.0;
dpv31[0][1][2] = vet[0][2];
dpv31[0][0][2] = 0.0;
dpv31[0][1][2] = vet[0][2];
dpv31[0][2][2] = -vet[0][1];
// derivatives of pv13[1] to rn
dpv31[1][0][2] = -vet[0][2];
dpv31[1][1][2] = 0.0;
dpv31[1][2][2] = vet[0][0];
dpv31[1][1][2] = 0.0;
dpv31[1][2][2] = vet[0][0];
// derivatives of pv13[2] to rn
dpv31[2][0][2] = vet[0][1];
dpv31[2][0][2] = vet[0][1];
dpv31[2][1][2] = -vet[0][0];
dpv31[2][2][2] = 0.0;
dpv31[2][2][2] = 0.0;
// derivatives respect to the second neighbor, atom l
for (id = 0; id < 3; id++) {
for (ip = 0; ip < 3; ip++) {
dpv31[id][ip][1] = 0.0;
}
for (ip = 0; ip < 3; ip++) { dpv31[id][ip][1] = 0.0; }
}
pv23[0] = vet[1][1]*vet[2][2] - vet[2][1]*vet[1][2];
pv23[1] = vet[1][2]*vet[2][0] - vet[2][2]*vet[1][0];
pv23[2] = vet[1][0]*vet[2][1] - vet[2][0]*vet[1][1];
pv23[0] = vet[1][1] * vet[2][2] - vet[2][1] * vet[1][2];
pv23[1] = vet[1][2] * vet[2][0] - vet[2][2] * vet[1][0];
pv23[2] = vet[1][0] * vet[2][1] - vet[2][0] * vet[1][1];
// derivatives respect to the second neighbor, atom k
for (id = 0; id < 3; id++) {
for (ip = 0; ip < 3; ip++) {
dpv23[id][ip][0] = 0.0;
}
for (ip = 0; ip < 3; ip++) { dpv23[id][ip][0] = 0.0; }
}
// derivatives respect to the second neighbor, atom l
dpv23[0][0][1] = 0.0;
dpv23[0][1][1] = vet[2][2];
dpv23[0][0][1] = 0.0;
dpv23[0][1][1] = vet[2][2];
dpv23[0][2][1] = -vet[2][1];
dpv23[1][0][1] = -vet[2][2];
dpv23[1][1][1] = 0.0;
dpv23[1][2][1] = vet[2][0];
dpv23[2][0][1] = vet[2][1];
dpv23[1][1][1] = 0.0;
dpv23[1][2][1] = vet[2][0];
dpv23[2][0][1] = vet[2][1];
dpv23[2][1][1] = -vet[2][0];
dpv23[2][2][1] = 0.0;
dpv23[2][2][1] = 0.0;
// derivatives respect to the third neighbor, atom n
dpv23[0][0][2] = 0.0;
dpv23[0][0][2] = 0.0;
dpv23[0][1][2] = -vet[1][2];
dpv23[0][2][2] = vet[1][1];
dpv23[1][0][2] = vet[1][2];
dpv23[1][1][2] = 0.0;
dpv23[0][2][2] = vet[1][1];
dpv23[1][0][2] = vet[1][2];
dpv23[1][1][2] = 0.0;
dpv23[1][2][2] = -vet[1][0];
dpv23[2][0][2] = -vet[1][1];
dpv23[2][1][2] = vet[1][0];
dpv23[2][2][2] = 0.0;
dpv23[2][1][2] = vet[1][0];
dpv23[2][2][2] = 0.0;
//############################################################################################
//############################################################################################
// average the normal vectors by using the 3 neighboring planes
n1[0] = (pv12[0] + pv31[0] + pv23[0])/cont;
n1[1] = (pv12[1] + pv31[1] + pv23[1])/cont;
n1[2] = (pv12[2] + pv31[2] + pv23[2])/cont;
n1[0] = (pv12[0] + pv31[0] + pv23[0]) / cont;
n1[1] = (pv12[1] + pv31[1] + pv23[1]) / cont;
n1[2] = (pv12[2] + pv31[2] + pv23[2]) / cont;
// the magnitude of the normal vector
nn2 = n1[0]*n1[0] + n1[1]*n1[1] + n1[2]*n1[2];
nn2 = n1[0] * n1[0] + n1[1] * n1[1] + n1[2] * n1[2];
nn = sqrt(nn2);
if (nn == 0) error->one(FLERR,"The magnitude of the normal vector is zero");
if (nn == 0) error->one(FLERR, "The magnitude of the normal vector is zero");
// the unit normal vector
normal[i][0] = n1[0]/nn;
normal[i][1] = n1[1]/nn;
normal[i][2] = n1[2]/nn;
normal[i][0] = n1[0] / nn;
normal[i][1] = n1[1] / nn;
normal[i][2] = n1[2] / nn;
// for the central atoms, dnormdri is always zero
for (id = 0; id < 3; id++) {
for (ip = 0; ip < 3; ip++) {
dnormdri[id][ip][i] = 0.0;
}
} // end of derivatives of normals respect to atom i
for (ip = 0; ip < 3; ip++) { dnormdri[id][ip][i] = 0.0; }
} // end of derivatives of normals respect to atom i
// derivatives of non-normalized normal vector, dn1:3x3x3 array
for (id = 0; id < 3; id++) {
for (ip = 0; ip < 3; ip++) {
for (m = 0; m < 3; m++) {
dn1[id][ip][m] = (dpv12[id][ip][m] + dpv23[id][ip][m] + dpv31[id][ip][m])/cont;
dn1[id][ip][m] = (dpv12[id][ip][m] + dpv23[id][ip][m] + dpv31[id][ip][m]) / cont;
}
}
}
@ -979,7 +975,7 @@ void PairKolmogorovCrespiFull::calc_normal()
// r[id][m]: the id's component of atom m
for (m = 0; m < 3; m++) {
for (id = 0; id < 3; id++) {
dnn[id][m] = (n1[0]*dn1[0][id][m] + n1[1]*dn1[1][id][m] + n1[2]*dn1[2][id][m])/nn;
dnn[id][m] = (n1[0] * dn1[0][id][m] + n1[1] * dn1[1][id][m] + n1[2] * dn1[2][id][m]) / nn;
}
}
// dnormal[id][ip][m][i]: the derivative of normal[id] respect to r[ip][m], id,ip=0,1,2
@ -987,49 +983,52 @@ void PairKolmogorovCrespiFull::calc_normal()
for (m = 0; m < 3; m++) {
for (id = 0; id < 3; id++) {
for (ip = 0; ip < 3; ip++) {
dnormal[id][ip][m][i] = dn1[id][ip][m]/nn - n1[id]*dnn[ip][m]/nn2;
dnormal[id][ip][m][i] = dn1[id][ip][m] / nn - n1[id] * dnn[ip][m] / nn2;
}
}
}
}
else {
error->one(FLERR,"There are too many neighbors for calculating normals");
} else {
error->one(FLERR, "There are too many neighbors for calculating normals");
}
//##############################################################################################
//##############################################################################################
}
}
/* ---------------------------------------------------------------------- */
double PairKolmogorovCrespiFull::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,r2inv,r6inv,r8inv,forcelj,philj;
double Tap,dTap,Vkc,fpair;
double r, r2inv, r6inv, r8inv, forcelj, philj;
double Tap, dTap, Vkc, fpair;
int iparam_ij = elem2param[map[itype]][map[jtype]];
Param& p = params[iparam_ij];
Param &p = params[iparam_ij];
r = sqrt(rsq);
// turn on/off taper function
if (tap_flag) {
Tap = calc_Tap(r,sqrt(cutsq[itype][jtype]));
dTap = calc_dTap(r,sqrt(cutsq[itype][jtype]));
} else {Tap = 1.0; dTap = 0.0;}
Tap = calc_Tap(r, sqrt(cutsq[itype][jtype]));
dTap = calc_dTap(r, sqrt(cutsq[itype][jtype]));
} else {
Tap = 1.0;
dTap = 0.0;
}
r2inv = 1.0/rsq;
r6inv = r2inv*r2inv*r2inv;
r8inv = r2inv*r6inv;
r2inv = 1.0 / rsq;
r6inv = r2inv * r2inv * r2inv;
r8inv = r2inv * r6inv;
Vkc = -p.A*p.z06*r6inv;
Vkc = -p.A * p.z06 * r6inv;
// derivatives
fpair = -6.0*p.A*p.z06*r8inv;
fpair = -6.0 * p.A * p.z06 * r8inv;
forcelj = fpair;
fforce = factor_lj*(forcelj*Tap - Vkc*dTap/r);
fforce = factor_lj * (forcelj * Tap - Vkc * dTap / r);
if (tap_flag) philj = Vkc*Tap;
else philj = Vkc - offset[itype][jtype];
return factor_lj*philj;
if (tap_flag)
philj = Vkc * Tap;
else
philj = Vkc - offset[itype][jtype];
return factor_lj * philj;
}

View File

@ -17,8 +17,8 @@ PairStyle(kolmogorov/crespi/full,PairKolmogorovCrespiFull);
// clang-format on
#else
#ifndef LMP_PAIR_KolmogorovCrespi_FULL_H
#define LMP_PAIR_KolmogorovCrespi_FULL_H
#ifndef LMP_PAIR_KOLMOGOROV_CRESPI_FULL_H
#define LMP_PAIR_KOLMOGOROV_CRESPI_FULL_H
#include "pair.h"
@ -39,10 +39,10 @@ class PairKolmogorovCrespiFull : public Pair {
void calc_FRep(int, int);
void calc_FvdW(int, int);
double single(int, int, int, int, double, double, double, double &);
static constexpr int NPARAMS_PER_LINE = 12;
protected:
int me;
int maxlocal; // size of numneigh, firstneigh arrays
int pgsize; // size of neighbor page
int oneatom; // max # of neighbors for one atom
@ -61,7 +61,6 @@ class PairKolmogorovCrespiFull : public Pair {
double cut_global;
double cut_normal;
double **cut;
double **cutKCsq;
double **offset;
double **normal;

View File

@ -1,4 +1,3 @@
// clang-format off
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
@ -79,14 +78,14 @@ PairKolmogorovCrespiZ::~PairKolmogorovCrespiZ()
void PairKolmogorovCrespiZ::compute(int eflag, int vflag)
{
int i,j,ii,jj,inum,jnum,itype,jtype;
double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair, fpair1;
double rsq,r,rhosq,exp1,exp2,r6,r8;
double frho,sumC,sumC2,sumCff,fsum,rdsq;
int *ilist,*jlist,*numneigh,**firstneigh;
int i, j, ii, jj, inum, jnum, itype, jtype;
double xtmp, ytmp, ztmp, delx, dely, delz, evdwl, fpair, fpair1;
double rsq, r, rhosq, exp1, exp2, r6, r8;
double frho, sumC, sumC2, sumCff, fsum, rdsq;
int *ilist, *jlist, *numneigh, **firstneigh;
evdwl = 0.0;
ev_init(eflag,vflag);
ev_init(eflag, vflag);
double **x = atom->x;
double **f = atom->f;
@ -117,51 +116,49 @@ void PairKolmogorovCrespiZ::compute(int eflag, int vflag)
dely = ytmp - x[j][1];
delz = ztmp - x[j][2];
// rho^2 = r^2 - (n,r) = r^2 - z^2
rhosq = delx*delx + dely*dely;
rsq = rhosq + delz*delz;
rhosq = delx * delx + dely * dely;
rsq = rhosq + delz * delz;
if (rsq < cutsq[itype][jtype]) {
int iparam_ij = elem2param[map[itype]][map[jtype]];
Param& p = params[iparam_ij];
Param &p = params[iparam_ij];
r = sqrt(rsq);
r6 = rsq*rsq*rsq;
r8 = r6*rsq;
rdsq = rhosq*p.delta2inv; // (rho/delta)^2
r6 = rsq * rsq * rsq;
r8 = r6 * rsq;
rdsq = rhosq * p.delta2inv; // (rho/delta)^2
// store exponents
exp1 = exp(-p.lambda*(r-p.z0));
exp1 = exp(-p.lambda * (r - p.z0));
exp2 = exp(-rdsq);
// note that f(rho_ij) equals f(rho_ji) as normals are all along z
sumC = p.C0+p.C2*rdsq+p.C4*rdsq*rdsq;
sumC2 = (2*p.C2+4*p.C4*rdsq)*p.delta2inv;
frho = exp2*sumC;
sumCff = p.C + 2*frho;
sumC = p.C0 + p.C2 * rdsq + p.C4 * rdsq * rdsq;
sumC2 = (2 * p.C2 + 4 * p.C4 * rdsq) * p.delta2inv;
frho = exp2 * sumC;
sumCff = p.C + 2 * frho;
// derivatives
fpair = -6.0*p.A*p.z06/r8+p.lambda*exp1/r*sumCff;
fpair1 = exp1*exp2*(4.0*p.delta2inv*sumC-2.0*sumC2);
fpair = -6.0 * p.A * p.z06 / r8 + p.lambda * exp1 / r * sumCff;
fpair1 = exp1 * exp2 * (4.0 * p.delta2inv * sumC - 2.0 * sumC2);
fsum = fpair + fpair1;
f[i][0] += delx*fsum;
f[i][1] += dely*fsum;
f[i][0] += delx * fsum;
f[i][1] += dely * fsum;
// fi_z does not contain contributions from df/dr
// because rho_ij does not depend on z_i or z_j
f[i][2] += delz*fpair;
f[i][2] += delz * fpair;
if (newton_pair || j < nlocal) {
f[j][0] -= delx*fsum;
f[j][1] -= dely*fsum;
f[j][2] -= delz*fpair;
f[j][0] -= delx * fsum;
f[j][1] -= dely * fsum;
f[j][2] -= delz * fpair;
}
if (eflag) {
evdwl = -p.A*p.z06/r6+ exp1*sumCff - offset[itype][jtype];
}
if (eflag) { evdwl = -p.A * p.z06 / r6 + exp1 * sumCff - offset[itype][jtype]; }
if (evflag) {
ev_tally_xyz(i,j,nlocal,newton_pair,evdwl,0,fsum,fsum,fpair,delx,dely,delz);
ev_tally_xyz(i, j, nlocal, newton_pair, evdwl, 0, fsum, fsum, fpair, delx, dely, delz);
}
}
}
@ -177,15 +174,14 @@ void PairKolmogorovCrespiZ::compute(int eflag, int vflag)
void PairKolmogorovCrespiZ::allocate()
{
allocated = 1;
int n = atom->ntypes+1;
int n = atom->ntypes + 1;
memory->create(setflag,n,n,"pair:setflag");
memory->create(setflag, n, n, "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,n,"pair:cutsq");
memory->create(offset,n,n,"pair:offset");
memory->create(cutsq, n, n, "pair:cutsq");
memory->create(offset, n, n, "pair:offset");
map = new int[n];
}
@ -195,11 +191,11 @@ void PairKolmogorovCrespiZ::allocate()
void PairKolmogorovCrespiZ::settings(int narg, char **arg)
{
if (narg != 1) error->all(FLERR,"Illegal pair_style command");
if (strcmp(force->pair_style,"hybrid/overlay")!=0)
error->all(FLERR,"ERROR: requires hybrid/overlay pair_style");
if (narg != 1) error->all(FLERR, "Illegal pair_style command");
if (strcmp(force->pair_style, "hybrid/overlay") != 0)
error->all(FLERR, "ERROR: requires hybrid/overlay pair_style");
cut_global = utils::numeric(FLERR,arg[0],false,lmp);
cut_global = utils::numeric(FLERR, arg[0], false, lmp);
}
/* ----------------------------------------------------------------------
@ -210,44 +206,43 @@ void PairKolmogorovCrespiZ::coeff(int narg, char **arg)
{
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);
map_element2type(narg-3,arg+3,false);
map_element2type(narg - 3, arg + 3, false);
read_file(arg[2]);
// set setflag only for i,j pairs where both are mapped to elements
int count = 0;
for (int i = ilo; i <= ihi; i++) {
for (int j = MAX(jlo,i); j <= jhi; j++) {
if ((map[i] >=0) && (map[j] >= 0)) {
for (int j = MAX(jlo, i); j <= jhi; j++) {
if ((map[i] >= 0) && (map[j] >= 0)) {
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");
}
/* ----------------------------------------------------------------------
init for one type pair i,j and corresponding j,i
------------------------------------------------------------------------- */
double PairKolmogorovCrespiZ::init_one(int i, int j)
{
if (setflag[i][j] == 0) error->all(FLERR,"All pair coeffs are not set");
if (!offset_flag)
error->all(FLERR,"Must use 'pair_modify shift yes' with this pair style");
if (setflag[i][j] == 0) error->all(FLERR, "All pair coeffs are not set");
if (!offset_flag) error->all(FLERR, "Must use 'pair_modify shift yes' with this pair style");
if (offset_flag && (cut_global > 0.0)) {
int iparam_ij = elem2param[map[i]][map[j]];
Param& p = params[iparam_ij];
offset[i][j] = -p.A*pow(p.z0/cut_global,6);
} else offset[i][j] = 0.0;
Param &p = params[iparam_ij];
offset[i][j] = -p.A * pow(p.z0 / cut_global, 6);
} else
offset[i][j] = 0.0;
offset[j][i] = offset[i][j];
return cut_global;
@ -298,28 +293,28 @@ void PairKolmogorovCrespiZ::read_file(char *filename)
if (nparams == maxparam) {
maxparam += DELTA;
params = (Param *) memory->srealloc(params,maxparam*sizeof(Param), "pair:params");
params = (Param *) memory->srealloc(params, maxparam * sizeof(Param), "pair:params");
// make certain all addional allocated storage is initialized
// to avoid false positives when checking with valgrind
memset(params + nparams, 0, DELTA*sizeof(Param));
memset(params + nparams, 0, DELTA * sizeof(Param));
}
// load up parameter settings and error check their values
params[nparams].ielement = ielement;
params[nparams].jelement = jelement;
params[nparams].z0 = values.next_double();
params[nparams].C0 = values.next_double();
params[nparams].C2 = values.next_double();
params[nparams].C4 = values.next_double();
params[nparams].C = values.next_double();
params[nparams].delta = values.next_double();
params[nparams].z0 = values.next_double();
params[nparams].C0 = values.next_double();
params[nparams].C2 = values.next_double();
params[nparams].C4 = values.next_double();
params[nparams].C = values.next_double();
params[nparams].delta = values.next_double();
params[nparams].lambda = values.next_double();
params[nparams].A = values.next_double();
params[nparams].A = values.next_double();
// S provides a convenient scaling of all energies
params[nparams].S = values.next_double();
params[nparams].S = values.next_double();
} catch (TokenizerException &e) {
error->one(FLERR, e.what());
@ -328,7 +323,7 @@ void PairKolmogorovCrespiZ::read_file(char *filename)
// energies in meV further scaled by S
// S = 43.3634 meV = 1 kcal/mol
double meV = 1e-3*params[nparams].S;
double meV = 1e-3 * params[nparams].S;
if (unit_convert) meV *= conversion_factor;
params[nparams].C *= meV;
@ -338,35 +333,35 @@ void PairKolmogorovCrespiZ::read_file(char *filename)
params[nparams].C4 *= meV;
// precompute some quantities
params[nparams].delta2inv = pow(params[nparams].delta,-2);
params[nparams].z06 = pow(params[nparams].z0,6);
params[nparams].delta2inv = pow(params[nparams].delta, -2);
params[nparams].z06 = pow(params[nparams].z0, 6);
nparams++;
if (nparams >= pow(atom->ntypes,3)) break;
if (nparams >= pow(atom->ntypes, 3)) break;
}
MPI_Bcast(&nparams, 1, MPI_INT, 0, world);
MPI_Bcast(&maxparam, 1, MPI_INT, 0, world);
if (comm->me != 0) {
params = (Param *) memory->srealloc(params,maxparam*sizeof(Param), "pair:params");
params = (Param *) memory->srealloc(params, maxparam * sizeof(Param), "pair:params");
}
MPI_Bcast(params, maxparam*sizeof(Param), MPI_BYTE, 0, world);
MPI_Bcast(params, maxparam * sizeof(Param), MPI_BYTE, 0, world);
}
memory->destroy(elem2param);
memory->create(elem2param,nelements,nelements,"pair:elem2param");
memory->create(elem2param, nelements, nelements, "pair:elem2param");
for (int i = 0; i < nelements; i++) {
for (int j = 0; j < nelements; j++) {
int n = -1;
for (int m = 0; m < nparams; m++) {
if (i == params[m].ielement && j == params[m].jelement) {
if (n >= 0) error->all(FLERR,"Potential file has duplicate entry");
if (n >= 0) error->all(FLERR, "Potential file has duplicate entry");
n = m;
}
}
if (n < 0) error->all(FLERR,"Potential file is missing an entry");
if (n < 0) error->all(FLERR, "Potential file is missing an entry");
elem2param[i][j] = n;
}
}

View File

@ -36,7 +36,7 @@ class PairKolmogorovCrespiZ : public Pair {
static constexpr int NPARAMS_PER_LINE = 11;
protected:
protected:
struct Param {
double z0, C0, C2, C4, C, delta, lambda, A, S;
double delta2inv, z06;

View File

@ -252,7 +252,6 @@ double PairLebedevaZ::init_one(int i, int j)
void PairLebedevaZ::read_file(char *filename)
{
int params_per_line = 12;
memory->sfree(params);
params = nullptr;
nparams = maxparam = 0;