diff --git a/src/CORESHELL/pair_lj_cut_coul_long_cs.cpp b/src/CORESHELL/pair_lj_cut_coul_long_cs.cpp index e2ffda148..d418cf20a 100644 --- a/src/CORESHELL/pair_lj_cut_coul_long_cs.cpp +++ b/src/CORESHELL/pair_lj_cut_coul_long_cs.cpp @@ -1,572 +1,572 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- Contributing author: Hendrik Heenen (hendrik.heenen@mytum.de) ------------------------------------------------------------------------- */ #include #include #include #include #include "pair_lj_cut_coul_long_cs.h" #include "atom.h" #include "comm.h" #include "force.h" #include "kspace.h" #include "update.h" #include "integrate.h" #include "respa.h" #include "neighbor.h" #include "neigh_list.h" #include "neigh_request.h" #include "math_const.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; using namespace MathConst; #define EWALD_F 1.12837917 #define EWALD_P 9.95473818e-1 #define B0 -0.1335096380159268 #define B1 -2.57839507e-1 #define B2 -1.37203639e-1 #define B3 -8.88822059e-3 #define B4 -5.80844129e-3 #define B5 1.14652755e-1 #define EPSILON 1.0e-20 #define EPS_EWALD 1.0e-6 #define EPS_EWALD_SQR 1.0e-12 /* ---------------------------------------------------------------------- */ PairLJCutCoulLongCS::PairLJCutCoulLongCS(LAMMPS *lmp) : PairLJCutCoulLong(lmp) { ewaldflag = pppmflag = 1; respa_enable = 1; writedata = 1; ftable = NULL; qdist = 0.0; } /* ---------------------------------------------------------------------- */ void PairLJCutCoulLongCS::compute(int eflag, int vflag) { int i,ii,j,jj,inum,jnum,itype,jtype,itable; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair; double fraction,table; double r,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; double grij,expm2,prefactor,t,erfc,u; int *ilist,*jlist,*numneigh,**firstneigh; double rsq; evdwl = ecoul = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; inum = list->inum; ilist = list->ilist; numneigh = list->numneigh; firstneigh = list->firstneigh; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; if (rsq < cutsq[itype][jtype]) { rsq += EPSILON; // Add Epsilon for case: r = 0; Interaction must be removed by special bond; r2inv = 1.0/rsq; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { r = sqrt(rsq); prefactor = qqrd2e * qtmp*q[j]; if (factor_coul < 1.0) { // When bonded parts are being calculated a minimal distance (EPS_EWALD) // has to be added to the prefactor and erfc in order to make the // used approximation functions for the Ewald correction valid grij = g_ewald * (r+EPS_EWALD); expm2 = exp(-grij*grij); t = 1.0 / (1.0 + EWALD_P*grij); u = 1.0 - t; erfc = t * (1.+u*(B0+u*(B1+u*(B2+u*(B3+u*(B4+u*B5)))))) * expm2; prefactor /= (r+EPS_EWALD); forcecoul = prefactor * (erfc + EWALD_F*grij*expm2 - (1.0-factor_coul)); // Additionally r2inv needs to be accordingly modified since the later // scaling of the overall force shall be consistent r2inv = 1.0/(rsq + EPS_EWALD_SQR); } else { grij = g_ewald * r; expm2 = exp(-grij*grij); t = 1.0 / (1.0 + EWALD_P*grij); u = 1.0 - t; erfc = t * (1.+u*(B0+u*(B1+u*(B2+u*(B3+u*(B4+u*B5)))))) * expm2; prefactor /= r; forcecoul = prefactor * (erfc + EWALD_F*grij*expm2); } } else { union_int_float_t rsq_lookup; rsq_lookup.f = rsq; itable = rsq_lookup.i & ncoulmask; itable >>= ncoulshiftbits; fraction = (rsq_lookup.f - rtable[itable]) * drtable[itable]; table = ftable[itable] + fraction*dftable[itable]; forcecoul = qtmp*q[j] * table; if (factor_coul < 1.0) { table = ctable[itable] + fraction*dctable[itable]; prefactor = qtmp*q[j] * table; forcecoul -= (1.0-factor_coul)*prefactor; } } } else forcecoul = 0.0; if (rsq < cut_ljsq[itype][jtype]) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); } else forcelj = 0.0; fpair = (forcecoul + factor_lj*forcelj) * r2inv; 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; } if (eflag) { if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) ecoul = prefactor*erfc; else { table = etable[itable] + fraction*detable[itable]; ecoul = qtmp*q[j] * table; } if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; } else ecoul = 0.0; if (rsq < cut_ljsq[itype][jtype]) { evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - offset[itype][jtype]; evdwl *= factor_lj; } else evdwl = 0.0; } if (evflag) ev_tally(i,j,nlocal,newton_pair, evdwl,ecoul,fpair,delx,dely,delz); } } } if (vflag_fdotr) virial_fdotr_compute(); } /* ---------------------------------------------------------------------- */ void PairLJCutCoulLongCS::compute_inner() { int i,j,ii,jj,inum,jnum,itype,jtype; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fpair; double rsq,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; double rsw; int *ilist,*jlist,*numneigh,**firstneigh; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; - inum = listinner->inum; - ilist = listinner->ilist; - numneigh = listinner->numneigh; - firstneigh = listinner->firstneigh; + inum = list->inum_inner; + ilist = list->ilist_inner; + numneigh = list->numneigh_inner; + firstneigh = list->firstneigh_inner; double cut_out_on = cut_respa[0]; double cut_out_off = cut_respa[1]; double cut_out_diff = cut_out_off - cut_out_on; double cut_out_on_sq = cut_out_on*cut_out_on; double cut_out_off_sq = cut_out_off*cut_out_off; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq < cut_out_off_sq) { rsq += EPSILON; // Add Epsilon for case: r = 0; Interaction must be removed by special bond; r2inv = 1.0/rsq; forcecoul = qqrd2e * qtmp*q[j]*sqrt(r2inv); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*forcecoul; jtype = type[j]; if (rsq < cut_ljsq[itype][jtype]) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); } else forcelj = 0.0; fpair = (forcecoul + factor_lj*forcelj) * r2inv; if (rsq > cut_out_on_sq) { rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; fpair *= 1.0 + rsw*rsw*(2.0*rsw-3.0); } 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; } } } } } /* ---------------------------------------------------------------------- */ void PairLJCutCoulLongCS::compute_middle() { int i,j,ii,jj,inum,jnum,itype,jtype; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fpair; double rsq,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; double rsw; int *ilist,*jlist,*numneigh,**firstneigh; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; - inum = listmiddle->inum; - ilist = listmiddle->ilist; - numneigh = listmiddle->numneigh; - firstneigh = listmiddle->firstneigh; + inum = list->inum_middle; + ilist = list->ilist_middle; + numneigh = list->numneigh_middle; + firstneigh = list->firstneigh_middle; double cut_in_off = cut_respa[0]; double cut_in_on = cut_respa[1]; double cut_out_on = cut_respa[2]; double cut_out_off = cut_respa[3]; double cut_in_diff = cut_in_on - cut_in_off; double cut_out_diff = cut_out_off - cut_out_on; double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; double cut_out_on_sq = cut_out_on*cut_out_on; double cut_out_off_sq = cut_out_off*cut_out_off; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq < cut_out_off_sq && rsq > cut_in_off_sq) { r2inv = 1.0/rsq; forcecoul = qqrd2e * qtmp*q[j]*sqrt(r2inv); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*forcecoul; jtype = type[j]; if (rsq < cut_ljsq[itype][jtype]) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); } else forcelj = 0.0; fpair = (forcecoul + factor_lj*forcelj) * r2inv; if (rsq < cut_in_on_sq) { rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; fpair *= rsw*rsw*(3.0 - 2.0*rsw); } if (rsq > cut_out_on_sq) { rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; fpair *= 1.0 + rsw*rsw*(2.0*rsw - 3.0); } 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; } } } } } /* ---------------------------------------------------------------------- */ void PairLJCutCoulLongCS::compute_outer(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype,itable; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair; double fraction,table; double r,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; double grij,expm2,prefactor,t,erfc,u; double rsw; int *ilist,*jlist,*numneigh,**firstneigh; double rsq; evdwl = ecoul = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; - inum = listouter->inum; - ilist = listouter->ilist; - numneigh = listouter->numneigh; - firstneigh = listouter->firstneigh; + inum = list->inum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; double cut_in_off = cut_respa[2]; double cut_in_on = cut_respa[3]; double cut_in_diff = cut_in_on - cut_in_off; double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; if (rsq < cutsq[itype][jtype]) { rsq += EPSILON; // Add Epsilon for case: r = 0; Interaction must be removed by special bond; r2inv = 1.0/rsq; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { r = sqrt(rsq); grij = g_ewald * r; expm2 = exp(-grij*grij); t = 1.0 / (1.0 + EWALD_P*grij); u = 1. - t; erfc = t * (1.+u*(B0+u*(B1+u*(B2+u*(B3+u*(B4+u*B5)))))) * expm2; //erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2; prefactor = qqrd2e * qtmp*q[j]/r; forcecoul = prefactor * (erfc + EWALD_F*grij*expm2 - 1.0); if (rsq > cut_in_off_sq) { if (rsq < cut_in_on_sq) { rsw = (r - cut_in_off)/cut_in_diff; forcecoul += prefactor*rsw*rsw*(3.0 - 2.0*rsw); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor*rsw*rsw*(3.0 - 2.0*rsw); } else { forcecoul += prefactor; if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; } } } else { union_int_float_t rsq_lookup; rsq_lookup.f = rsq; itable = rsq_lookup.i & ncoulmask; itable >>= ncoulshiftbits; fraction = (rsq_lookup.f - rtable[itable]) * drtable[itable]; table = ftable[itable] + fraction*dftable[itable]; forcecoul = qtmp*q[j] * table; if (factor_coul < 1.0) { table = ctable[itable] + fraction*dctable[itable]; prefactor = qtmp*q[j] * table; forcecoul -= (1.0-factor_coul)*prefactor; } } } else forcecoul = 0.0; if (rsq < cut_ljsq[itype][jtype] && rsq > cut_in_off_sq) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); if (rsq < cut_in_on_sq) { rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; forcelj *= rsw*rsw*(3.0 - 2.0*rsw); } } else forcelj = 0.0; fpair = (forcecoul + forcelj) * r2inv; 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; } if (eflag) { if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { ecoul = prefactor*erfc; if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; } else { table = etable[itable] + fraction*detable[itable]; ecoul = qtmp*q[j] * table; if (factor_coul < 1.0) { table = ptable[itable] + fraction*dptable[itable]; prefactor = qtmp*q[j] * table; ecoul -= (1.0-factor_coul)*prefactor; } } } else ecoul = 0.0; if (rsq < cut_ljsq[itype][jtype]) { r6inv = r2inv*r2inv*r2inv; evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - offset[itype][jtype]; evdwl *= factor_lj; } else evdwl = 0.0; } if (vflag) { if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { forcecoul = prefactor * (erfc + EWALD_F*grij*expm2); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; } else { table = vtable[itable] + fraction*dvtable[itable]; forcecoul = qtmp*q[j] * table; if (factor_coul < 1.0) { table = ptable[itable] + fraction*dptable[itable]; prefactor = qtmp*q[j] * table; forcecoul -= (1.0-factor_coul)*prefactor; } } } else forcecoul = 0.0; if (rsq <= cut_in_off_sq) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); } else if (rsq <= cut_in_on_sq) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); } fpair = (forcecoul + factor_lj*forcelj) * r2inv; } if (evflag) ev_tally(i,j,nlocal,newton_pair, evdwl,ecoul,fpair,delx,dely,delz); } } } } diff --git a/src/DIPOLE/pair_lj_long_dipole_long.cpp b/src/DIPOLE/pair_lj_long_dipole_long.cpp index b833b250d..c9b2b3f4a 100644 --- a/src/DIPOLE/pair_lj_long_dipole_long.cpp +++ b/src/DIPOLE/pair_lj_long_dipole_long.cpp @@ -1,682 +1,666 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- Contributing author: Pieter J. in 't Veld and Stan Moore (Sandia) ------------------------------------------------------------------------- */ #include #include #include #include #include "math_const.h" #include "math_vector.h" #include "pair_lj_long_dipole_long.h" #include "atom.h" #include "comm.h" #include "neighbor.h" #include "neigh_list.h" #include "neigh_request.h" #include "force.h" #include "kspace.h" #include "update.h" #include "integrate.h" #include "respa.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; using namespace MathConst; #define EWALD_F 1.12837917 #define EWALD_P 0.3275911 #define A1 0.254829592 #define A2 -0.284496736 #define A3 1.421413741 #define A4 -1.453152027 #define A5 1.061405429 // ---------------------------------------------------------------------- PairLJLongDipoleLong::PairLJLongDipoleLong(LAMMPS *lmp) : Pair(lmp) { dispersionflag = ewaldflag = dipoleflag = 1; respa_enable = 0; single_enable = 0; } // ---------------------------------------------------------------------- // global settings // ---------------------------------------------------------------------- void PairLJLongDipoleLong::options(char **arg, int order) { const char *option[] = {"long", "cut", "off", NULL}; int i; if (!*arg) error->all(FLERR,"Illegal pair_style lj/long/dipole/long command"); for (i=0; option[i]&&strcmp(arg[0], option[i]); ++i); switch (i) { default: error->all(FLERR,"Illegal pair_style lj/long/dipole/long command"); case 0: ewald_order |= 1<all(FLERR,"Illegal pair_style command"); ewald_off = 0; ewald_order = 0; options(arg, 6); options(++arg, 3); options(arg, 1); if (!comm->me && ewald_order&(1<<6)) error->warning(FLERR,"Geometric mixing assumed for 1/r^6 coefficients"); if (!comm->me && ewald_order==((1<<3)|(1<<6))) error->warning(FLERR, "Using largest cut-off for lj/long/dipole/long long long"); if (!*(++arg)) error->all(FLERR,"Cut-offs missing in pair_style lj/long/dipole/long"); if (!((ewald_order^ewald_off)&(1<<3))) error->all(FLERR, "Coulombic cut not supported in pair_style lj/long/dipole/long"); cut_lj_global = force->numeric(FLERR,*(arg++)); if (narg == 4 && (ewald_order==74)) error->all(FLERR,"Only one cut-off allowed when requesting all long"); if (narg == 4) cut_coul = force->numeric(FLERR,*(arg++)); else cut_coul = cut_lj_global; if (allocated) { // reset explicit cuts int i,j; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) if (setflag[i][j]) cut_lj[i][j] = cut_lj_global; } } // ---------------------------------------------------------------------- // free all arrays // ---------------------------------------------------------------------- PairLJLongDipoleLong::~PairLJLongDipoleLong() { if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(cut_lj_read); memory->destroy(cut_lj); memory->destroy(cut_ljsq); memory->destroy(epsilon_read); memory->destroy(epsilon); memory->destroy(sigma_read); memory->destroy(sigma); memory->destroy(lj1); memory->destroy(lj2); memory->destroy(lj3); memory->destroy(lj4); memory->destroy(offset); } //if (ftable) free_tables(); } /* ---------------------------------------------------------------------- allocate all arrays ------------------------------------------------------------------------- */ void PairLJLongDipoleLong::allocate() { allocated = 1; int n = atom->ntypes; 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(cutsq,n+1,n+1,"pair:cutsq"); memory->create(cut_lj_read,n+1,n+1,"pair:cut_lj_read"); memory->create(cut_lj,n+1,n+1,"pair:cut_lj"); memory->create(cut_ljsq,n+1,n+1,"pair:cut_ljsq"); memory->create(epsilon_read,n+1,n+1,"pair:epsilon_read"); memory->create(epsilon,n+1,n+1,"pair:epsilon"); memory->create(sigma_read,n+1,n+1,"pair:sigma_read"); memory->create(sigma,n+1,n+1,"pair:sigma"); memory->create(lj1,n+1,n+1,"pair:lj1"); memory->create(lj2,n+1,n+1,"pair:lj2"); memory->create(lj3,n+1,n+1,"pair:lj3"); memory->create(lj4,n+1,n+1,"pair:lj4"); memory->create(offset,n+1,n+1,"pair:offset"); } /* ---------------------------------------------------------------------- extract protected data from object ------------------------------------------------------------------------- */ void *PairLJLongDipoleLong::extract(const char *id, int &dim) { const char *ids[] = { "B", "sigma", "epsilon", "ewald_order", "ewald_cut", "ewald_mix", "cut_coul", "cut_vdwl", NULL}; void *ptrs[] = { lj4, sigma, epsilon, &ewald_order, &cut_coul, &mix_flag, &cut_coul, &cut_lj_global, NULL}; int i; for (i=0; ids[i]&&strcmp(ids[i], id); ++i); if (i <= 2) dim = 2; else dim = 0; return ptrs[i]; } /* ---------------------------------------------------------------------- set coeffs for one or more type pairs ------------------------------------------------------------------------- */ void PairLJLongDipoleLong::coeff(int narg, char **arg) { if (narg < 4 || narg > 5) error->all(FLERR,"Incorrect args for pair coefficients"); if (!allocated) allocate(); int ilo,ihi,jlo,jhi; force->bounds(FLERR,arg[0],atom->ntypes,ilo,ihi); force->bounds(FLERR,arg[1],atom->ntypes,jlo,jhi); double epsilon_one = force->numeric(FLERR,arg[2]); double sigma_one = force->numeric(FLERR,arg[3]); double cut_lj_one = cut_lj_global; if (narg == 5) cut_lj_one = force->numeric(FLERR,arg[4]); int count = 0; for (int i = ilo; i <= ihi; i++) { for (int j = MAX(jlo,i); j <= jhi; j++) { epsilon_read[i][j] = epsilon_one; sigma_read[i][j] = sigma_one; cut_lj_read[i][j] = cut_lj_one; setflag[i][j] = 1; count++; } } if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- init specific to this pair style ------------------------------------------------------------------------- */ void PairLJLongDipoleLong::init_style() { const char *style3[] = {"ewald/disp", NULL}; const char *style6[] = {"ewald/disp", NULL}; int i; if (strcmp(update->unit_style,"electron") == 0) error->all(FLERR,"Cannot (yet) use 'electron' units with dipoles"); // require an atom style with charge defined if (!atom->q_flag && (ewald_order&(1<<1))) error->all(FLERR, "Invoking coulombic in pair style lj/long/dipole/long requires atom attribute q"); if (!atom->mu && (ewald_order&(1<<3))) error->all(FLERR,"Pair lj/long/dipole/long requires atom attributes mu, torque"); if (!atom->torque && (ewald_order&(1<<3))) error->all(FLERR,"Pair lj/long/dipole/long requires atom attributes mu, torque"); neighbor->request(this,instance_me); cut_coulsq = cut_coul * cut_coul; // ensure use of KSpace long-range solver, set g_ewald if (ewald_order&(1<<3)) { // r^-1 kspace if (force->kspace == NULL) error->all(FLERR,"Pair style requires a KSpace style"); for (i=0; style3[i]&&strcmp(force->kspace_style, style3[i]); ++i); if (!style3[i]) error->all(FLERR,"Pair style requires use of kspace_style ewald/disp"); } if (ewald_order&(1<<6)) { // r^-6 kspace if (force->kspace == NULL) error->all(FLERR,"Pair style requires a KSpace style"); for (i=0; style6[i]&&strcmp(force->kspace_style, style6[i]); ++i); if (!style6[i]) error->all(FLERR,"Pair style requires use of kspace_style ewald/disp"); } if (force->kspace) g_ewald = force->kspace->g_ewald; } -/* ---------------------------------------------------------------------- - neighbor callback to inform pair style of neighbor list to use - regular or rRESPA -------------------------------------------------------------------------- */ - -void PairLJLongDipoleLong::init_list(int id, NeighList *ptr) -{ - if (id == 0) list = ptr; - else if (id == 1) listinner = ptr; - else if (id == 2) listmiddle = ptr; - else if (id == 3) listouter = ptr; - - if (id) - error->all(FLERR,"Pair style lj/long/dipole/long does not currently support respa"); -} - /* ---------------------------------------------------------------------- init for one type pair i,j and corresponding j,i ------------------------------------------------------------------------- */ double PairLJLongDipoleLong::init_one(int i, int j) { if ((ewald_order&(1<<6))||(setflag[i][j] == 0)) { epsilon[i][j] = mix_energy(epsilon_read[i][i],epsilon_read[j][j], sigma_read[i][i],sigma_read[j][j]); sigma[i][j] = mix_distance(sigma_read[i][i],sigma_read[j][j]); if (ewald_order&(1<<6)) cut_lj[i][j] = cut_lj_global; else cut_lj[i][j] = mix_distance(cut_lj_read[i][i],cut_lj_read[j][j]); } else { sigma[i][j] = sigma_read[i][j]; epsilon[i][j] = epsilon_read[i][j]; cut_lj[i][j] = cut_lj_read[i][j]; } double cut = MAX(cut_lj[i][j], cut_coul); cutsq[i][j] = cut*cut; cut_ljsq[i][j] = cut_lj[i][j] * cut_lj[i][j]; lj1[i][j] = 48.0 * epsilon[i][j] * pow(sigma[i][j],12.0); lj2[i][j] = 24.0 * epsilon[i][j] * pow(sigma[i][j],6.0); lj3[i][j] = 4.0 * epsilon[i][j] * pow(sigma[i][j],12.0); lj4[i][j] = 4.0 * epsilon[i][j] * pow(sigma[i][j],6.0); // check interior rRESPA cutoff //if (cut_respa && MIN(cut_lj[i][j],cut_coul) < cut_respa[3]) //error->all(FLERR,"Pair cutoff < Respa interior cutoff"); if (offset_flag && (cut_lj[i][j] > 0.0)) { double ratio = sigma[i][j] / cut_lj[i][j]; offset[i][j] = 4.0 * epsilon[i][j] * (pow(ratio,12.0) - pow(ratio,6.0)); } else offset[i][j] = 0.0; cutsq[j][i] = cutsq[i][j]; cut_ljsq[j][i] = cut_ljsq[i][j]; lj1[j][i] = lj1[i][j]; lj2[j][i] = lj2[i][j]; lj3[j][i] = lj3[i][j]; lj4[j][i] = lj4[i][j]; offset[j][i] = offset[i][j]; return cut; } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairLJLongDipoleLong::write_restart(FILE *fp) { write_restart_settings(fp); int i,j; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { fwrite(&setflag[i][j],sizeof(int),1,fp); if (setflag[i][j]) { fwrite(&epsilon_read[i][j],sizeof(double),1,fp); fwrite(&sigma_read[i][j],sizeof(double),1,fp); fwrite(&cut_lj_read[i][j],sizeof(double),1,fp); } } } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairLJLongDipoleLong::read_restart(FILE *fp) { read_restart_settings(fp); allocate(); int i,j; int me = comm->me; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp); MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world); if (setflag[i][j]) { if (me == 0) { fread(&epsilon_read[i][j],sizeof(double),1,fp); fread(&sigma_read[i][j],sizeof(double),1,fp); fread(&cut_lj_read[i][j],sizeof(double),1,fp); } MPI_Bcast(&epsilon_read[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&sigma_read[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&cut_lj_read[i][j],1,MPI_DOUBLE,0,world); } } } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairLJLongDipoleLong::write_restart_settings(FILE *fp) { fwrite(&cut_lj_global,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(&ewald_order,sizeof(int),1,fp); } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairLJLongDipoleLong::read_restart_settings(FILE *fp) { if (comm->me == 0) { fread(&cut_lj_global,sizeof(double),1,fp); fread(&cut_coul,sizeof(double),1,fp); fread(&offset_flag,sizeof(int),1,fp); fread(&mix_flag,sizeof(int),1,fp); fread(&ewald_order,sizeof(int),1,fp); } MPI_Bcast(&cut_lj_global,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(&ewald_order,1,MPI_INT,0,world); } /* ---------------------------------------------------------------------- compute pair interactions ------------------------------------------------------------------------- */ void PairLJLongDipoleLong::compute(int eflag, int vflag) { double evdwl,ecoul,fpair; evdwl = ecoul = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = vflag_fdotr = 0; double **x = atom->x, *x0 = x[0]; double **mu = atom->mu, *mu0 = mu[0], *imu, *jmu; double **tq = atom->torque, *tq0 = tq[0], *tqi; double **f = atom->f, *f0 = f[0], *fi = f0, fx, fy, fz; double *q = atom->q, qi = 0, qj; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; int i, j; int order3 = ewald_order&(1<<3), order6 = ewald_order&(1<<6); int *ineigh, *ineighn, *jneigh, *jneighn, typei, typej, ni; double *cutsqi, *cut_ljsqi, *lj1i, *lj2i, *lj3i, *lj4i, *offseti; double rsq, r2inv, force_coul, force_lj; double g2 = g_ewald*g_ewald, g6 = g2*g2*g2, g8 = g6*g2; double B0, B1, B2, B3, G0, G1, G2, mudi, mudj, muij; vector force_d = VECTOR_NULL, ti = VECTOR_NULL, tj = VECTOR_NULL; vector mui, muj, xi, d; double C1 = 2.0 * g_ewald / MY_PIS; double C2 = 2.0 * g2 * C1; double C3 = 2.0 * g2 * C2; ineighn = (ineigh = list->ilist)+list->inum; for (; ineighfirstneigh[i])+list->numneigh[i]; for (; jneigh= cutsqi[typej = type[j]]) continue; r2inv = 1.0/rsq; if (order3 && (rsq < cut_coulsq)) { // dipole memcpy(muj, jmu = mu0+(j<<2), sizeof(vector)); { // series real space register double r = sqrt(rsq); register double x = g_ewald*r; register double f = exp(-x*x)*qqrd2e; B0 = 1.0/(1.0+EWALD_P*x); // eqn 2.8 B0 *= ((((A5*B0+A4)*B0+A3)*B0+A2)*B0+A1)*f/r; B1 = (B0 + C1 * f) * r2inv; B2 = (3.0*B1 + C2 * f) * r2inv; B3 = (5.0*B2 + C3 * f) * r2inv; mudi = mui[0]*d[0]+mui[1]*d[1]+mui[2]*d[2]; mudj = muj[0]*d[0]+muj[1]*d[1]+muj[2]*d[2]; muij = mui[0]*muj[0]+mui[1]*muj[1]+mui[2]*muj[2]; G0 = qi*(qj = q[j]); // eqn 2.10 G1 = qi*mudj-qj*mudi+muij; G2 = -mudi*mudj; force_coul = G0*B1+G1*B2+G2*B3; mudi *= B2; mudj *= B2; // torque contribs ti[0] = mudj*d[0]+(qj*d[0]-muj[0])*B1; ti[1] = mudj*d[1]+(qj*d[1]-muj[1])*B1; ti[2] = mudj*d[2]+(qj*d[2]-muj[2])*B1; if (newton_pair || j < nlocal) { tj[0] = mudi*d[0]-(qi*d[0]+mui[0])*B1; tj[1] = mudi*d[1]-(qi*d[1]+mui[1])*B1; tj[2] = mudi*d[2]-(qi*d[2]+mui[2])*B1; } if (eflag) ecoul = G0*B0+G1*B1+G2*B2; if (ni > 0) { // adj part, eqn 2.13 force_coul -= (f = qqrd2e*(1.0-special_coul[ni])/r)*( (3.0*G1+15.0*G2*r2inv)*r2inv+G0)*r2inv; if (eflag) ecoul -= f*((G1+3.0*G2*r2inv)*r2inv+G0); B1 -= f*r2inv; } B0 = mudj+qj*B1; B3 = -qi*B1+mudi; // position independent if (ni > 0) B0 -= f*3.0*mudj*r2inv*r2inv/B2; if (ni > 0) B3 -= f*3.0*mudi*r2inv*r2inv/B2; force_d[0] = B0*mui[0]+B3*muj[0]; // force contribs force_d[1] = B0*mui[1]+B3*muj[1]; force_d[2] = B0*mui[2]+B3*muj[2]; if (ni > 0) { ti[0] -= f*(3.0*mudj*r2inv*r2inv*d[0]/B2+(qj*r2inv*d[0]-muj[0]*r2inv)); ti[1] -= f*(3.0*mudj*r2inv*r2inv*d[1]/B2+(qj*r2inv*d[1]-muj[1]*r2inv)); ti[2] -= f*(3.0*mudj*r2inv*r2inv*d[2]/B2+(qj*r2inv*d[2]-muj[2]*r2inv)); if (newton_pair || j < nlocal) { tj[0] -= f*(3.0*mudi*r2inv*r2inv*d[0]/B2-(qi*r2inv*d[0]+mui[0]*r2inv)); tj[1] -= f*(3.0*mudi*r2inv*r2inv*d[1]/B2-(qi*r2inv*d[1]+mui[1]*r2inv)); tj[2] -= f*(3.0*mudi*r2inv*r2inv*d[2]/B2-(qi*r2inv*d[2]+mui[2]*r2inv)); } } } // table real space } else { force_coul = ecoul = 0.0; memset(force_d, 0, 3*sizeof(double)); } if (rsq < cut_ljsqi[typej]) { // lj if (order6) { // long-range lj register double rn = r2inv*r2inv*r2inv; register double x2 = g2*rsq, a2 = 1.0/x2; x2 = a2*exp(-x2)*lj4i[typej]; if (ni < 0) { force_lj = (rn*=rn)*lj1i[typej]-g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq; if (eflag) evdwl = rn*lj3i[typej]-g6*((a2+1.0)*a2+0.5)*x2; } else { // special case register double f = special_lj[ni], t = rn*(1.0-f); force_lj = f*(rn *= rn)*lj1i[typej]- g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq+t*lj2i[typej]; if (eflag) evdwl = f*rn*lj3i[typej]-g6*((a2+1.0)*a2+0.5)*x2+t*lj4i[typej]; } } else { // cut lj register double rn = r2inv*r2inv*r2inv; if (ni < 0) { force_lj = rn*(rn*lj1i[typej]-lj2i[typej]); if (eflag) evdwl = rn*(rn*lj3i[typej]-lj4i[typej])-offseti[typej]; } else { // special case register double f = special_lj[ni]; force_lj = f*rn*(rn*lj1i[typej]-lj2i[typej]); if (eflag) evdwl = f*( rn*(rn*lj3i[typej]-lj4i[typej])-offseti[typej]); } } force_lj *= r2inv; } else force_lj = evdwl = 0.0; fpair = force_coul+force_lj; // force if (newton_pair || j < nlocal) { register double *fj = f0+(j+(j<<1)); fi[0] += fx = d[0]*fpair+force_d[0]; fj[0] -= fx; fi[1] += fy = d[1]*fpair+force_d[1]; fj[1] -= fy; fi[2] += fz = d[2]*fpair+force_d[2]; fj[2] -= fz; tqi[0] += mui[1]*ti[2]-mui[2]*ti[1]; // torque tqi[1] += mui[2]*ti[0]-mui[0]*ti[2]; tqi[2] += mui[0]*ti[1]-mui[1]*ti[0]; register double *tqj = tq0+(j+(j<<1)); tqj[0] += muj[1]*tj[2]-muj[2]*tj[1]; tqj[1] += muj[2]*tj[0]-muj[0]*tj[2]; tqj[2] += muj[0]*tj[1]-muj[1]*tj[0]; } else { fi[0] += fx = d[0]*fpair+force_d[0]; // force fi[1] += fy = d[1]*fpair+force_d[1]; fi[2] += fz = d[2]*fpair+force_d[2]; tqi[0] += mui[1]*ti[2]-mui[2]*ti[1]; // torque tqi[1] += mui[2]*ti[0]-mui[0]*ti[2]; tqi[2] += mui[0]*ti[1]-mui[1]*ti[0]; } if (evflag) ev_tally_xyz(i,j,nlocal,newton_pair, evdwl,ecoul,fx,fy,fz,d[0],d[1],d[2]); } } if (vflag_fdotr) virial_fdotr_compute(); } /* ---------------------------------------------------------------------- */ /* double PairLJLongDipoleLong::single(int i, int j, int itype, int jtype, double rsq, double factor_coul, double factor_lj, double &fforce) { double r6inv, force_coul, force_lj; double g2 = g_ewald*g_ewald, g6 = g2*g2*g2, g8 = g6*g2, *q = atom->q; double eng = 0.0; double r2inv = 1.0/rsq; if ((ewald_order&(1<<3)) && (rsq < cut_coulsq)) { // coulombic double *mui = atom->mu[i], *muj = atom->mu[j]; double *xi = atom->x[i], *xj = atom->x[j]; double qi = q[i], qj = q[j]; double G0, G1, G2, B0, B1, B2, B3, mudi, mudj, muij; vector d = {xi[0]-xj[0], xi[1]-xj[1], xi[2]-xj[2]}; { // series real space register double r = sqrt(rsq); register double x = g_ewald*r; register double f = exp(-x*x)*qqrd2e; B0 = 1.0/(1.0+EWALD_P*x); // eqn 2.8 B0 *= ((((A5*B0+A4)*B0+A3)*B0+A2)*B0+A1)*f/r; B1 = (B0 + C1 * f) * r2inv; B2 = (3.0*B1 + C2 * f) * r2inv; B3 = (5.0*B2 + C3 * f) * r2inv; mudi = mui[0]*d[0]+mui[1]*d[1]+mui[2]*d[2]; mudj = muj[0]*d[0]+muj[1]*d[1]+muj[2]*d[2]; muij = mui[0]*muj[0]+mui[1]*muj[1]+mui[2]*muj[2]; G0 = qi*(qj = q[j]); // eqn 2.10 G1 = qi*mudj-qj*mudi+muij; G2 = -mudi*mudj; force_coul = G0*B1+G1*B2+G2*B3; eng += G0*B0+G1*B1+G2*B2; if (factor_coul < 1.0) { // adj part, eqn 2.13 force_coul -= (f = force->qqrd2e*(1.0-factor_coul)/r)*( (3.0*G1+6.0*muij+15.0*G2*r2inv)*r2inv+G0); eng -= f*((G1+3.0*G2*r2inv)*r2inv+G0); B1 -= f*r2inv; } B0 = mudj*B2-qj*B1; B3 = qi*B1+mudi*B2; // position independent //force_d[0] = B0*mui[0]+B3*muj[0]; // force contributions //force_d[1] = B0*mui[1]+B3*muj[1]; //force_d[2] = B0*mui[2]+B3*muj[2]; } // table real space } else force_coul = 0.0; if (rsq < cut_ljsq[itype][jtype]) { // lennard-jones r6inv = r2inv*r2inv*r2inv; if (ewald_order&0x40) { // long-range register double x2 = g2*rsq, a2 = 1.0/x2, t = r6inv*(1.0-factor_lj); x2 = a2*exp(-x2)*lj4[itype][jtype]; force_lj = factor_lj*(r6inv *= r6inv)*lj1[itype][jtype]- g8*(((6.0*a2+6.0)*a2+3.0)*a2+a2)*x2*rsq+t*lj2[itype][jtype]; eng += factor_lj*r6inv*lj3[itype][jtype]- g6*((a2+1.0)*a2+0.5)*x2+t*lj4[itype][jtype]; } else { // cut force_lj = factor_lj*r6inv*(lj1[itype][jtype]*r6inv-lj2[itype][jtype]); eng += factor_lj*(r6inv*(r6inv*lj3[itype][jtype]- lj4[itype][jtype])-offset[itype][jtype]); } } else force_lj = 0.0; fforce = (force_coul+force_lj)*r2inv; return eng; } */ diff --git a/src/DIPOLE/pair_lj_long_dipole_long.h b/src/DIPOLE/pair_lj_long_dipole_long.h index f9fa10af1..2ace9ca30 100644 --- a/src/DIPOLE/pair_lj_long_dipole_long.h +++ b/src/DIPOLE/pair_lj_long_dipole_long.h @@ -1,126 +1,125 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #ifdef PAIR_CLASS PairStyle(lj/long/dipole/long,PairLJLongDipoleLong) #else #ifndef LMP_PAIR_LJ_LONG_DIPOLE_LONG_H #define LMP_PAIR_LJ_LONG_DIPOLE_LONG_H #include "pair.h" namespace LAMMPS_NS { class PairLJLongDipoleLong : public Pair { public: double cut_coul; PairLJLongDipoleLong(class LAMMPS *); virtual ~PairLJLongDipoleLong(); virtual void compute(int, int); virtual void settings(int, char **); void coeff(int, char **); void init_style(); - void init_list(int, class NeighList *); double init_one(int, int); void write_restart(FILE *); void read_restart(FILE *); void write_restart_settings(FILE *); void read_restart_settings(FILE *); void *extract(const char *, int &); protected: double cut_lj_global; double **cut_lj, **cut_lj_read, **cut_ljsq; double cut_coulsq; double **epsilon_read, **epsilon, **sigma_read, **sigma; double **lj1, **lj2, **lj3, **lj4, **offset; double *cut_respa; double g_ewald; int ewald_order, ewald_off; void options(char **arg, int order); void allocate(); }; } #endif #endif /* ERROR/WARNING messages: E: Illegal ... command Self-explanatory. Check the input script syntax and compare to the documentation for the command. You can use -echo screen as a command-line option when running LAMMPS to see the offending line. W: Geometric mixing assumed for 1/r^6 coefficients Self-explanatory. W: Using largest cut-off for lj/long/dipole/long long long Self-explanatory. E: Cut-offs missing in pair_style lj/long/dipole/long Self-explanatory. E: Coulombic cut not supported in pair_style lj/long/dipole/long Must use long-range Coulombic interactions. E: Only one cut-off allowed when requesting all long Self-explanatory. E: Incorrect args for pair coefficients Self-explanatory. Check the input script or data file. E: Cannot (yet) use 'electron' units with dipoles This feature is not yet supported. E: Invoking coulombic in pair style lj/long/dipole/long requires atom attribute q The atom style defined does not have these attributes. E: Pair lj/long/dipole/long requires atom attributes mu, torque The atom style defined does not have these attributes. E: Pair style requires a KSpace style No kspace style is defined. E: Pair style requires use of kspace_style ewald/disp Self-explanatory. E: Pair style lj/long/dipole/long does not currently support respa This feature is not yet supported. E: Pair cutoff < Respa interior cutoff One or more pairwise cutoffs are too short to use with the specified rRESPA cutoffs. */ diff --git a/src/GRANULAR/pair_gran_hertz_history.cpp b/src/GRANULAR/pair_gran_hertz_history.cpp index e52aac10d..972353162 100644 --- a/src/GRANULAR/pair_gran_hertz_history.cpp +++ b/src/GRANULAR/pair_gran_hertz_history.cpp @@ -1,465 +1,466 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- Contributing authors: Leo Silbert (SNL), Gary Grest (SNL) ------------------------------------------------------------------------- */ #include #include #include #include #include "pair_gran_hertz_history.h" #include "atom.h" #include "update.h" #include "force.h" #include "fix.h" +#include "fix_neigh_history.h" #include "neighbor.h" #include "neigh_list.h" #include "comm.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ PairGranHertzHistory::PairGranHertzHistory(LAMMPS *lmp) : PairGranHookeHistory(lmp) {} /* ---------------------------------------------------------------------- */ void PairGranHertzHistory::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum; double xtmp,ytmp,ztmp,delx,dely,delz,fx,fy,fz; double radi,radj,radsum,rsq,r,rinv,rsqinv; double vr1,vr2,vr3,vnnr,vn1,vn2,vn3,vt1,vt2,vt3; double wr1,wr2,wr3; double vtr1,vtr2,vtr3,vrel; double mi,mj,meff,damp,ccel,tor1,tor2,tor3; double fn,fs,fs1,fs2,fs3; double shrmag,rsht,polyhertz; int *ilist,*jlist,*numneigh,**firstneigh; int *touch,**firsttouch; double *shear,*allshear,**firstshear; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = vflag_fdotr = 0; int shearupdate = 1; if (update->setupflag) shearupdate = 0; // update rigid body info for owned & ghost atoms if using FixRigid masses // body[i] = which body atom I is in, -1 if none // mass_body = mass of each rigid body if (fix_rigid && neighbor->ago == 0) { int tmp; int *body = (int *) fix_rigid->extract("body",tmp); double *mass_body = (double *) fix_rigid->extract("masstotal",tmp); if (atom->nmax > nmax) { memory->destroy(mass_rigid); nmax = atom->nmax; memory->create(mass_rigid,nmax,"pair:mass_rigid"); } int nlocal = atom->nlocal; for (i = 0; i < nlocal; i++) if (body[i] >= 0) mass_rigid[i] = mass_body[body[i]]; else mass_rigid[i] = 0.0; comm->forward_comm_pair(this); } double **x = atom->x; double **v = atom->v; double **f = atom->f; double **omega = atom->omega; double **torque = atom->torque; double *radius = atom->radius; double *rmass = atom->rmass; int *mask = atom->mask; int nlocal = atom->nlocal; int newton_pair = force->newton_pair; inum = list->inum; ilist = list->ilist; numneigh = list->numneigh; firstneigh = list->firstneigh; - firsttouch = list->listhistory->firstneigh; - firstshear = list->listhistory->firstdouble; + firsttouch = fix_history->firstflag; + firstshear = fix_history->firstvalue; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; radi = radius[i]; touch = firsttouch[i]; allshear = firstshear[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; radj = radius[j]; radsum = radi + radj; if (rsq >= radsum*radsum) { // unset non-touching neighbors touch[jj] = 0; shear = &allshear[3*jj]; shear[0] = 0.0; shear[1] = 0.0; shear[2] = 0.0; } else { r = sqrt(rsq); rinv = 1.0/r; rsqinv = 1.0/rsq; // relative translational velocity vr1 = v[i][0] - v[j][0]; vr2 = v[i][1] - v[j][1]; vr3 = v[i][2] - v[j][2]; // normal component vnnr = vr1*delx + vr2*dely + vr3*delz; vn1 = delx*vnnr * rsqinv; vn2 = dely*vnnr * rsqinv; vn3 = delz*vnnr * rsqinv; // tangential component vt1 = vr1 - vn1; vt2 = vr2 - vn2; vt3 = vr3 - vn3; // relative rotational velocity wr1 = (radi*omega[i][0] + radj*omega[j][0]) * rinv; wr2 = (radi*omega[i][1] + radj*omega[j][1]) * rinv; wr3 = (radi*omega[i][2] + radj*omega[j][2]) * rinv; // meff = effective mass of pair of particles // if I or J part of rigid body, use body mass // if I or J is frozen, meff is other particle mi = rmass[i]; mj = rmass[j]; if (fix_rigid) { if (mass_rigid[i] > 0.0) mi = mass_rigid[i]; if (mass_rigid[j] > 0.0) mj = mass_rigid[j]; } meff = mi*mj / (mi+mj); if (mask[i] & freeze_group_bit) meff = mj; if (mask[j] & freeze_group_bit) meff = mi; // normal force = Hertzian contact + normal velocity damping damp = meff*gamman*vnnr*rsqinv; ccel = kn*(radsum-r)*rinv - damp; polyhertz = sqrt((radsum-r)*radi*radj / radsum); ccel *= polyhertz; // relative velocities vtr1 = vt1 - (delz*wr2-dely*wr3); vtr2 = vt2 - (delx*wr3-delz*wr1); vtr3 = vt3 - (dely*wr1-delx*wr2); vrel = vtr1*vtr1 + vtr2*vtr2 + vtr3*vtr3; vrel = sqrt(vrel); // shear history effects touch[jj] = 1; shear = &allshear[3*jj]; if (shearupdate) { shear[0] += vtr1*dt; shear[1] += vtr2*dt; shear[2] += vtr3*dt; } shrmag = sqrt(shear[0]*shear[0] + shear[1]*shear[1] + shear[2]*shear[2]); // rotate shear displacements rsht = shear[0]*delx + shear[1]*dely + shear[2]*delz; rsht *= rsqinv; if (shearupdate) { shear[0] -= rsht*delx; shear[1] -= rsht*dely; shear[2] -= rsht*delz; } // tangential forces = shear + tangential velocity damping fs1 = -polyhertz * (kt*shear[0] + meff*gammat*vtr1); fs2 = -polyhertz * (kt*shear[1] + meff*gammat*vtr2); fs3 = -polyhertz * (kt*shear[2] + meff*gammat*vtr3); // rescale frictional displacements and forces if needed fs = sqrt(fs1*fs1 + fs2*fs2 + fs3*fs3); fn = xmu * fabs(ccel*r); if (fs > fn) { if (shrmag != 0.0) { shear[0] = (fn/fs) * (shear[0] + meff*gammat*vtr1/kt) - meff*gammat*vtr1/kt; shear[1] = (fn/fs) * (shear[1] + meff*gammat*vtr2/kt) - meff*gammat*vtr2/kt; shear[2] = (fn/fs) * (shear[2] + meff*gammat*vtr3/kt) - meff*gammat*vtr3/kt; fs1 *= fn/fs; fs2 *= fn/fs; fs3 *= fn/fs; } else fs1 = fs2 = fs3 = 0.0; } // forces & torques fx = delx*ccel + fs1; fy = dely*ccel + fs2; fz = delz*ccel + fs3; f[i][0] += fx; f[i][1] += fy; f[i][2] += fz; tor1 = rinv * (dely*fs3 - delz*fs2); tor2 = rinv * (delz*fs1 - delx*fs3); tor3 = rinv * (delx*fs2 - dely*fs1); torque[i][0] -= radi*tor1; torque[i][1] -= radi*tor2; torque[i][2] -= radi*tor3; if (newton_pair || j < nlocal) { f[j][0] -= fx; f[j][1] -= fy; f[j][2] -= fz; torque[j][0] -= radj*tor1; torque[j][1] -= radj*tor2; torque[j][2] -= radj*tor3; } if (evflag) ev_tally_xyz(i,j,nlocal,newton_pair, 0.0,0.0,fx,fy,fz,delx,dely,delz); } } } if (vflag_fdotr) virial_fdotr_compute(); } /* ---------------------------------------------------------------------- global settings ------------------------------------------------------------------------- */ void PairGranHertzHistory::settings(int narg, char **arg) { if (narg != 6) error->all(FLERR,"Illegal pair_style command"); kn = force->numeric(FLERR,arg[0]); if (strcmp(arg[1],"NULL") == 0) kt = kn * 2.0/7.0; else kt = force->numeric(FLERR,arg[1]); gamman = force->numeric(FLERR,arg[2]); if (strcmp(arg[3],"NULL") == 0) gammat = 0.5 * gamman; else gammat = force->numeric(FLERR,arg[3]); xmu = force->numeric(FLERR,arg[4]); dampflag = force->inumeric(FLERR,arg[5]); if (dampflag == 0) gammat = 0.0; if (kn < 0.0 || kt < 0.0 || gamman < 0.0 || gammat < 0.0 || xmu < 0.0 || xmu > 10000.0 || dampflag < 0 || dampflag > 1) error->all(FLERR,"Illegal pair_style command"); // convert Kn and Kt from pressure units to force/distance^2 kn /= force->nktv2p; kt /= force->nktv2p; } /* ---------------------------------------------------------------------- */ double PairGranHertzHistory::single(int i, int j, int itype, int jtype, double rsq, double factor_coul, double factor_lj, double &fforce) { double radi,radj,radsum; double r,rinv,rsqinv,delx,dely,delz; double vr1,vr2,vr3,vnnr,vn1,vn2,vn3,vt1,vt2,vt3,wr1,wr2,wr3; double mi,mj,meff,damp,ccel,polyhertz; double vtr1,vtr2,vtr3,vrel,shrmag,rsht; double fs1,fs2,fs3,fs,fn; double *radius = atom->radius; radi = radius[i]; radj = radius[j]; radsum = radi + radj; if (rsq >= radsum*radsum) { fforce = 0.0; for (int m = 0; m < single_extra; m++) svector[m] = 0.0; return 0.0; } r = sqrt(rsq); rinv = 1.0/r; rsqinv = 1.0/rsq; // relative translational velocity double **v = atom->v; vr1 = v[i][0] - v[j][0]; vr2 = v[i][1] - v[j][1]; vr3 = v[i][2] - v[j][2]; // normal component double **x = atom->x; delx = x[i][0] - x[j][0]; dely = x[i][1] - x[j][1]; delz = x[i][2] - x[j][2]; vnnr = vr1*delx + vr2*dely + vr3*delz; vn1 = delx*vnnr * rsqinv; vn2 = dely*vnnr * rsqinv; vn3 = delz*vnnr * rsqinv; // tangential component vt1 = vr1 - vn1; vt2 = vr2 - vn2; vt3 = vr3 - vn3; // relative rotational velocity double **omega = atom->omega; wr1 = (radi*omega[i][0] + radj*omega[j][0]) * rinv; wr2 = (radi*omega[i][1] + radj*omega[j][1]) * rinv; wr3 = (radi*omega[i][2] + radj*omega[j][2]) * rinv; // meff = effective mass of pair of particles // if I or J part of rigid body, use body mass // if I or J is frozen, meff is other particle double *rmass = atom->rmass; int *mask = atom->mask; mi = rmass[i]; mj = rmass[j]; if (fix_rigid) { // NOTE: insure mass_rigid is current for owned+ghost atoms? if (mass_rigid[i] > 0.0) mi = mass_rigid[i]; if (mass_rigid[j] > 0.0) mj = mass_rigid[j]; } meff = mi*mj / (mi+mj); if (mask[i] & freeze_group_bit) meff = mj; if (mask[j] & freeze_group_bit) meff = mi; // normal force = Hertzian contact + normal velocity damping damp = meff*gamman*vnnr*rsqinv; ccel = kn*(radsum-r)*rinv - damp; polyhertz = sqrt((radsum-r)*radi*radj / radsum); ccel *= polyhertz; // relative velocities vtr1 = vt1 - (delz*wr2-dely*wr3); vtr2 = vt2 - (delx*wr3-delz*wr1); vtr3 = vt3 - (dely*wr1-delx*wr2); vrel = vtr1*vtr1 + vtr2*vtr2 + vtr3*vtr3; vrel = sqrt(vrel); // shear history effects // neighprev = index of found neigh on previous call // search entire jnum list of neighbors of I for neighbor J // start from neighprev, since will typically be next neighbor // reset neighprev to 0 as necessary int jnum = list->numneigh[i]; int *jlist = list->firstneigh[i]; - double *allshear = list->listhistory->firstdouble[i]; + double *allshear = fix_history->firstvalue[i]; for (int jj = 0; jj < jnum; jj++) { neighprev++; if (neighprev >= jnum) neighprev = 0; if (jlist[neighprev] == j) break; } double *shear = &allshear[3*neighprev]; shrmag = sqrt(shear[0]*shear[0] + shear[1]*shear[1] + shear[2]*shear[2]); // rotate shear displacements rsht = shear[0]*delx + shear[1]*dely + shear[2]*delz; rsht *= rsqinv; // tangential forces = shear + tangential velocity damping fs1 = -polyhertz * (kt*shear[0] + meff*gammat*vtr1); fs2 = -polyhertz * (kt*shear[1] + meff*gammat*vtr2); fs3 = -polyhertz * (kt*shear[2] + meff*gammat*vtr3); // rescale frictional displacements and forces if needed fs = sqrt(fs1*fs1 + fs2*fs2 + fs3*fs3); fn = xmu * fabs(ccel*r); if (fs > fn) { if (shrmag != 0.0) { fs1 *= fn/fs; fs2 *= fn/fs; fs3 *= fn/fs; fs *= fn/fs; } else fs1 = fs2 = fs3 = fs = 0.0; } // set force and return no energy fforce = ccel; // set single_extra quantities svector[0] = fs1; svector[1] = fs2; svector[2] = fs3; svector[3] = fs; svector[4] = vn1; svector[5] = vn2; svector[6] = vn3; svector[7] = vt1; svector[8] = vt2; svector[9] = vt3; return 0.0; } diff --git a/src/GRANULAR/pair_gran_hooke_history.cpp b/src/GRANULAR/pair_gran_hooke_history.cpp index e9662c9e7..4f120150d 100644 --- a/src/GRANULAR/pair_gran_hooke_history.cpp +++ b/src/GRANULAR/pair_gran_hooke_history.cpp @@ -1,810 +1,781 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- Contributing authors: Leo Silbert (SNL), Gary Grest (SNL) ------------------------------------------------------------------------- */ #include #include #include #include #include "pair_gran_hooke_history.h" #include "atom.h" #include "atom_vec.h" #include "domain.h" #include "force.h" #include "update.h" #include "modify.h" #include "fix.h" -#include "fix_shear_history.h" +#include "fix_neigh_history.h" #include "comm.h" #include "neighbor.h" #include "neigh_list.h" #include "neigh_request.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ PairGranHookeHistory::PairGranHookeHistory(LAMMPS *lmp) : Pair(lmp) { single_enable = 1; no_virial_fdotr_compute = 1; history = 1; fix_history = NULL; single_extra = 10; svector = new double[10]; neighprev = 0; nmax = 0; mass_rigid = NULL; // set comm size needed by this Pair if used with fix rigid comm_forward = 1; } /* ---------------------------------------------------------------------- */ PairGranHookeHistory::~PairGranHookeHistory() { delete [] svector; - if (fix_history) modify->delete_fix("SHEAR_HISTORY"); + if (fix_history) modify->delete_fix("NEIGH_HISTORY"); if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); delete [] onerad_dynamic; delete [] onerad_frozen; delete [] maxrad_dynamic; delete [] maxrad_frozen; } memory->destroy(mass_rigid); } /* ---------------------------------------------------------------------- */ void PairGranHookeHistory::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum; double xtmp,ytmp,ztmp,delx,dely,delz,fx,fy,fz; double radi,radj,radsum,rsq,r,rinv,rsqinv; double vr1,vr2,vr3,vnnr,vn1,vn2,vn3,vt1,vt2,vt3; double wr1,wr2,wr3; double vtr1,vtr2,vtr3,vrel; double mi,mj,meff,damp,ccel,tor1,tor2,tor3; double fn,fs,fs1,fs2,fs3; double shrmag,rsht; int *ilist,*jlist,*numneigh,**firstneigh; int *touch,**firsttouch; double *shear,*allshear,**firstshear; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = vflag_fdotr = 0; int shearupdate = 1; if (update->setupflag) shearupdate = 0; // update rigid body info for owned & ghost atoms if using FixRigid masses // body[i] = which body atom I is in, -1 if none // mass_body = mass of each rigid body if (fix_rigid && neighbor->ago == 0) { int tmp; int *body = (int *) fix_rigid->extract("body",tmp); double *mass_body = (double *) fix_rigid->extract("masstotal",tmp); if (atom->nmax > nmax) { memory->destroy(mass_rigid); nmax = atom->nmax; memory->create(mass_rigid,nmax,"pair:mass_rigid"); } int nlocal = atom->nlocal; for (i = 0; i < nlocal; i++) if (body[i] >= 0) mass_rigid[i] = mass_body[body[i]]; else mass_rigid[i] = 0.0; comm->forward_comm_pair(this); } double **x = atom->x; double **v = atom->v; double **f = atom->f; double **omega = atom->omega; double **torque = atom->torque; double *radius = atom->radius; double *rmass = atom->rmass; int *mask = atom->mask; int nlocal = atom->nlocal; int newton_pair = force->newton_pair; inum = list->inum; ilist = list->ilist; numneigh = list->numneigh; firstneigh = list->firstneigh; - firsttouch = listhistory->firstneigh; - firstshear = listhistory->firstdouble; + firsttouch = fix_history->firstflag; + firstshear = fix_history->firstvalue; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; radi = radius[i]; touch = firsttouch[i]; allshear = firstshear[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; radj = radius[j]; radsum = radi + radj; if (rsq >= radsum*radsum) { // unset non-touching neighbors touch[jj] = 0; shear = &allshear[3*jj]; shear[0] = 0.0; shear[1] = 0.0; shear[2] = 0.0; } else { r = sqrt(rsq); rinv = 1.0/r; rsqinv = 1.0/rsq; // relative translational velocity vr1 = v[i][0] - v[j][0]; vr2 = v[i][1] - v[j][1]; vr3 = v[i][2] - v[j][2]; // normal component vnnr = vr1*delx + vr2*dely + vr3*delz; vn1 = delx*vnnr * rsqinv; vn2 = dely*vnnr * rsqinv; vn3 = delz*vnnr * rsqinv; // tangential component vt1 = vr1 - vn1; vt2 = vr2 - vn2; vt3 = vr3 - vn3; // relative rotational velocity wr1 = (radi*omega[i][0] + radj*omega[j][0]) * rinv; wr2 = (radi*omega[i][1] + radj*omega[j][1]) * rinv; wr3 = (radi*omega[i][2] + radj*omega[j][2]) * rinv; // meff = effective mass of pair of particles // if I or J part of rigid body, use body mass // if I or J is frozen, meff is other particle mi = rmass[i]; mj = rmass[j]; if (fix_rigid) { if (mass_rigid[i] > 0.0) mi = mass_rigid[i]; if (mass_rigid[j] > 0.0) mj = mass_rigid[j]; } meff = mi*mj / (mi+mj); if (mask[i] & freeze_group_bit) meff = mj; if (mask[j] & freeze_group_bit) meff = mi; // normal forces = Hookian contact + normal velocity damping damp = meff*gamman*vnnr*rsqinv; ccel = kn*(radsum-r)*rinv - damp; // relative velocities vtr1 = vt1 - (delz*wr2-dely*wr3); vtr2 = vt2 - (delx*wr3-delz*wr1); vtr3 = vt3 - (dely*wr1-delx*wr2); vrel = vtr1*vtr1 + vtr2*vtr2 + vtr3*vtr3; vrel = sqrt(vrel); // shear history effects touch[jj] = 1; shear = &allshear[3*jj]; if (shearupdate) { shear[0] += vtr1*dt; shear[1] += vtr2*dt; shear[2] += vtr3*dt; } shrmag = sqrt(shear[0]*shear[0] + shear[1]*shear[1] + shear[2]*shear[2]); // rotate shear displacements rsht = shear[0]*delx + shear[1]*dely + shear[2]*delz; rsht *= rsqinv; if (shearupdate) { shear[0] -= rsht*delx; shear[1] -= rsht*dely; shear[2] -= rsht*delz; } // tangential forces = shear + tangential velocity damping fs1 = - (kt*shear[0] + meff*gammat*vtr1); fs2 = - (kt*shear[1] + meff*gammat*vtr2); fs3 = - (kt*shear[2] + meff*gammat*vtr3); // rescale frictional displacements and forces if needed fs = sqrt(fs1*fs1 + fs2*fs2 + fs3*fs3); fn = xmu * fabs(ccel*r); if (fs > fn) { if (shrmag != 0.0) { shear[0] = (fn/fs) * (shear[0] + meff*gammat*vtr1/kt) - meff*gammat*vtr1/kt; shear[1] = (fn/fs) * (shear[1] + meff*gammat*vtr2/kt) - meff*gammat*vtr2/kt; shear[2] = (fn/fs) * (shear[2] + meff*gammat*vtr3/kt) - meff*gammat*vtr3/kt; fs1 *= fn/fs; fs2 *= fn/fs; fs3 *= fn/fs; } else fs1 = fs2 = fs3 = 0.0; } // forces & torques fx = delx*ccel + fs1; fy = dely*ccel + fs2; fz = delz*ccel + fs3; f[i][0] += fx; f[i][1] += fy; f[i][2] += fz; tor1 = rinv * (dely*fs3 - delz*fs2); tor2 = rinv * (delz*fs1 - delx*fs3); tor3 = rinv * (delx*fs2 - dely*fs1); torque[i][0] -= radi*tor1; torque[i][1] -= radi*tor2; torque[i][2] -= radi*tor3; if (newton_pair || j < nlocal) { f[j][0] -= fx; f[j][1] -= fy; f[j][2] -= fz; torque[j][0] -= radj*tor1; torque[j][1] -= radj*tor2; torque[j][2] -= radj*tor3; } if (evflag) ev_tally_xyz(i,j,nlocal,newton_pair, 0.0,0.0,fx,fy,fz,delx,dely,delz); } } } if (vflag_fdotr) virial_fdotr_compute(); } /* ---------------------------------------------------------------------- allocate all arrays ------------------------------------------------------------------------- */ void PairGranHookeHistory::allocate() { allocated = 1; int n = atom->ntypes; 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(cutsq,n+1,n+1,"pair:cutsq"); onerad_dynamic = new double[n+1]; onerad_frozen = new double[n+1]; maxrad_dynamic = new double[n+1]; maxrad_frozen = new double[n+1]; } /* ---------------------------------------------------------------------- global settings ------------------------------------------------------------------------- */ void PairGranHookeHistory::settings(int narg, char **arg) { if (narg != 6) error->all(FLERR,"Illegal pair_style command"); kn = force->numeric(FLERR,arg[0]); if (strcmp(arg[1],"NULL") == 0) kt = kn * 2.0/7.0; else kt = force->numeric(FLERR,arg[1]); gamman = force->numeric(FLERR,arg[2]); if (strcmp(arg[3],"NULL") == 0) gammat = 0.5 * gamman; else gammat = force->numeric(FLERR,arg[3]); xmu = force->numeric(FLERR,arg[4]); dampflag = force->inumeric(FLERR,arg[5]); if (dampflag == 0) gammat = 0.0; if (kn < 0.0 || kt < 0.0 || gamman < 0.0 || gammat < 0.0 || xmu < 0.0 || xmu > 10000.0 || dampflag < 0 || dampflag > 1) error->all(FLERR,"Illegal pair_style command"); } /* ---------------------------------------------------------------------- set coeffs for one or more type pairs ------------------------------------------------------------------------- */ void PairGranHookeHistory::coeff(int narg, char **arg) { if (narg > 2) error->all(FLERR,"Incorrect args for pair coefficients"); if (!allocated) allocate(); int ilo,ihi,jlo,jhi; force->bounds(FLERR,arg[0],atom->ntypes,ilo,ihi); force->bounds(FLERR,arg[1],atom->ntypes,jlo,jhi); int count = 0; for (int i = ilo; i <= ihi; i++) { 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"); } /* ---------------------------------------------------------------------- init specific to this pair style ------------------------------------------------------------------------- */ void PairGranHookeHistory::init_style() { int i; // error and warning checks if (!atom->radius_flag || !atom->rmass_flag) error->all(FLERR,"Pair granular requires atom attributes radius, rmass"); if (comm->ghost_velocity == 0) error->all(FLERR,"Pair granular requires ghost atoms store velocity"); - // need a granular neigh list and optionally a granular history neigh list + // need a granular neigh list int irequest = neighbor->request(this,instance_me); neighbor->requests[irequest]->size = 1; - if (history) { - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 1; - neighbor->requests[irequest]->history = 1; - neighbor->requests[irequest]->dnum = 3; - } + if (history) neighbor->requests[irequest]->history = 1; dt = update->dt; - // if shear history is stored: // if first init, create Fix needed for storing shear history if (history && fix_history == NULL) { char dnumstr[16]; sprintf(dnumstr,"%d",3); char **fixarg = new char*[4]; - fixarg[0] = (char *) "SHEAR_HISTORY"; + fixarg[0] = (char *) "NEIGH_HISTORY"; fixarg[1] = (char *) "all"; - fixarg[2] = (char *) "SHEAR_HISTORY"; + fixarg[2] = (char *) "NEIGH_HISTORY"; fixarg[3] = dnumstr; - modify->add_fix(4,fixarg); + modify->add_fix(4,fixarg,1); delete [] fixarg; - fix_history = (FixShearHistory *) modify->fix[modify->nfix-1]; + fix_history = (FixNeighHistory *) modify->fix[modify->nfix-1]; fix_history->pair = this; - neighbor->requests[irequest]->fix_history = fix_history; } // check for FixFreeze and set freeze_group_bit for (i = 0; i < modify->nfix; i++) if (strcmp(modify->fix[i]->style,"freeze") == 0) break; if (i < modify->nfix) freeze_group_bit = modify->fix[i]->groupbit; else freeze_group_bit = 0; // check for FixRigid so can extract rigid body masses fix_rigid = NULL; for (i = 0; i < modify->nfix; i++) if (modify->fix[i]->rigid_flag) break; if (i < modify->nfix) fix_rigid = modify->fix[i]; // check for FixPour and FixDeposit so can extract particle radii int ipour; for (ipour = 0; ipour < modify->nfix; ipour++) if (strcmp(modify->fix[ipour]->style,"pour") == 0) break; if (ipour == modify->nfix) ipour = -1; int idep; for (idep = 0; idep < modify->nfix; idep++) if (strcmp(modify->fix[idep]->style,"deposit") == 0) break; if (idep == modify->nfix) idep = -1; // set maxrad_dynamic and maxrad_frozen for each type // include future FixPour and FixDeposit particles as dynamic int itype; for (i = 1; i <= atom->ntypes; i++) { onerad_dynamic[i] = onerad_frozen[i] = 0.0; if (ipour >= 0) { itype = i; onerad_dynamic[i] = *((double *) modify->fix[ipour]->extract("radius",itype)); } if (idep >= 0) { itype = i; onerad_dynamic[i] = *((double *) modify->fix[idep]->extract("radius",itype)); } } double *radius = atom->radius; int *mask = atom->mask; int *type = atom->type; int nlocal = atom->nlocal; for (i = 0; i < nlocal; i++) if (mask[i] & freeze_group_bit) onerad_frozen[type[i]] = MAX(onerad_frozen[type[i]],radius[i]); else onerad_dynamic[type[i]] = MAX(onerad_dynamic[type[i]],radius[i]); MPI_Allreduce(&onerad_dynamic[1],&maxrad_dynamic[1],atom->ntypes, MPI_DOUBLE,MPI_MAX,world); MPI_Allreduce(&onerad_frozen[1],&maxrad_frozen[1],atom->ntypes, MPI_DOUBLE,MPI_MAX,world); // set fix which stores history info if (history) { - int ifix = modify->find_fix("SHEAR_HISTORY"); - if (ifix < 0) error->all(FLERR,"Could not find pair fix ID"); - fix_history = (FixShearHistory *) modify->fix[ifix]; + int ifix = modify->find_fix("NEIGH_HISTORY"); + if (ifix < 0) error->all(FLERR,"Could not find pair fix neigh history ID"); + fix_history = (FixNeighHistory *) modify->fix[ifix]; } } -/* ---------------------------------------------------------------------- - neighbor callback to inform pair style of neighbor list to use - optional granular history list -------------------------------------------------------------------------- */ - -void PairGranHookeHistory::init_list(int id, NeighList *ptr) -{ - if (id == 0) list = ptr; - else if (id == 1) listhistory = ptr; -} - /* ---------------------------------------------------------------------- init for one type pair i,j and corresponding j,i ------------------------------------------------------------------------- */ double PairGranHookeHistory::init_one(int i, int j) { if (!allocated) allocate(); // cutoff = sum of max I,J radii for // dynamic/dynamic & dynamic/frozen interactions, but not frozen/frozen double cutoff = maxrad_dynamic[i]+maxrad_dynamic[j]; cutoff = MAX(cutoff,maxrad_frozen[i]+maxrad_dynamic[j]); cutoff = MAX(cutoff,maxrad_dynamic[i]+maxrad_frozen[j]); return cutoff; } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairGranHookeHistory::write_restart(FILE *fp) { write_restart_settings(fp); 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); } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairGranHookeHistory::read_restart(FILE *fp) { read_restart_settings(fp); allocate(); int i,j; int me = comm->me; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp); MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world); } } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairGranHookeHistory::write_restart_settings(FILE *fp) { fwrite(&kn,sizeof(double),1,fp); fwrite(&kt,sizeof(double),1,fp); fwrite(&gamman,sizeof(double),1,fp); fwrite(&gammat,sizeof(double),1,fp); fwrite(&xmu,sizeof(double),1,fp); fwrite(&dampflag,sizeof(int),1,fp); } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairGranHookeHistory::read_restart_settings(FILE *fp) { if (comm->me == 0) { fread(&kn,sizeof(double),1,fp); fread(&kt,sizeof(double),1,fp); fread(&gamman,sizeof(double),1,fp); fread(&gammat,sizeof(double),1,fp); fread(&xmu,sizeof(double),1,fp); fread(&dampflag,sizeof(int),1,fp); } MPI_Bcast(&kn,1,MPI_DOUBLE,0,world); MPI_Bcast(&kt,1,MPI_DOUBLE,0,world); MPI_Bcast(&gamman,1,MPI_DOUBLE,0,world); MPI_Bcast(&gammat,1,MPI_DOUBLE,0,world); MPI_Bcast(&xmu,1,MPI_DOUBLE,0,world); MPI_Bcast(&dampflag,1,MPI_INT,0,world); } /* ---------------------------------------------------------------------- */ void PairGranHookeHistory::reset_dt() { dt = update->dt; } /* ---------------------------------------------------------------------- */ double PairGranHookeHistory::single(int i, int j, int itype, int jtype, double rsq, double factor_coul, double factor_lj, double &fforce) { double radi,radj,radsum; double r,rinv,rsqinv,delx,dely,delz; double vr1,vr2,vr3,vnnr,vn1,vn2,vn3,vt1,vt2,vt3,wr1,wr2,wr3; double mi,mj,meff,damp,ccel; double vtr1,vtr2,vtr3,vrel,shrmag,rsht; double fs1,fs2,fs3,fs,fn; double *radius = atom->radius; radi = radius[i]; radj = radius[j]; radsum = radi + radj; if (rsq >= radsum*radsum) { fforce = 0.0; for (int m = 0; m < single_extra; m++) svector[m] = 0.0; return 0.0; } r = sqrt(rsq); rinv = 1.0/r; rsqinv = 1.0/rsq; // relative translational velocity double **v = atom->v; vr1 = v[i][0] - v[j][0]; vr2 = v[i][1] - v[j][1]; vr3 = v[i][2] - v[j][2]; // normal component double **x = atom->x; delx = x[i][0] - x[j][0]; dely = x[i][1] - x[j][1]; delz = x[i][2] - x[j][2]; vnnr = vr1*delx + vr2*dely + vr3*delz; vn1 = delx*vnnr * rsqinv; vn2 = dely*vnnr * rsqinv; vn3 = delz*vnnr * rsqinv; // tangential component vt1 = vr1 - vn1; vt2 = vr2 - vn2; vt3 = vr3 - vn3; // relative rotational velocity double **omega = atom->omega; wr1 = (radi*omega[i][0] + radj*omega[j][0]) * rinv; wr2 = (radi*omega[i][1] + radj*omega[j][1]) * rinv; wr3 = (radi*omega[i][2] + radj*omega[j][2]) * rinv; // meff = effective mass of pair of particles // if I or J part of rigid body, use body mass // if I or J is frozen, meff is other particle double *rmass = atom->rmass; int *mask = atom->mask; mi = rmass[i]; mj = rmass[j]; if (fix_rigid) { // NOTE: insure mass_rigid is current for owned+ghost atoms? if (mass_rigid[i] > 0.0) mi = mass_rigid[i]; if (mass_rigid[j] > 0.0) mj = mass_rigid[j]; } meff = mi*mj / (mi+mj); if (mask[i] & freeze_group_bit) meff = mj; if (mask[j] & freeze_group_bit) meff = mi; // normal forces = Hookian contact + normal velocity damping damp = meff*gamman*vnnr*rsqinv; ccel = kn*(radsum-r)*rinv - damp; // relative velocities vtr1 = vt1 - (delz*wr2-dely*wr3); vtr2 = vt2 - (delx*wr3-delz*wr1); vtr3 = vt3 - (dely*wr1-delx*wr2); vrel = vtr1*vtr1 + vtr2*vtr2 + vtr3*vtr3; vrel = sqrt(vrel); // shear history effects // neighprev = index of found neigh on previous call // search entire jnum list of neighbors of I for neighbor J // start from neighprev, since will typically be next neighbor // reset neighprev to 0 as necessary int jnum = list->numneigh[i]; int *jlist = list->firstneigh[i]; - double *allshear = list->listhistory->firstdouble[i]; + double *allshear = fix_history->firstvalue[i]; for (int jj = 0; jj < jnum; jj++) { neighprev++; if (neighprev >= jnum) neighprev = 0; if (jlist[neighprev] == j) break; } double *shear = &allshear[3*neighprev]; shrmag = sqrt(shear[0]*shear[0] + shear[1]*shear[1] + shear[2]*shear[2]); // rotate shear displacements rsht = shear[0]*delx + shear[1]*dely + shear[2]*delz; rsht *= rsqinv; // tangential forces = shear + tangential velocity damping fs1 = - (kt*shear[0] + meff*gammat*vtr1); fs2 = - (kt*shear[1] + meff*gammat*vtr2); fs3 = - (kt*shear[2] + meff*gammat*vtr3); // rescale frictional displacements and forces if needed fs = sqrt(fs1*fs1 + fs2*fs2 + fs3*fs3); fn = xmu * fabs(ccel*r); if (fs > fn) { if (shrmag != 0.0) { fs1 *= fn/fs; fs2 *= fn/fs; fs3 *= fn/fs; fs *= fn/fs; } else fs1 = fs2 = fs3 = fs = 0.0; } // set force and return no energy fforce = ccel; // set single_extra quantities svector[0] = fs1; svector[1] = fs2; svector[2] = fs3; svector[3] = fs; svector[4] = vn1; svector[5] = vn2; svector[6] = vn3; svector[7] = vt1; svector[8] = vt2; svector[9] = vt3; return 0.0; } /* ---------------------------------------------------------------------- */ int PairGranHookeHistory::pack_forward_comm(int n, int *list, double *buf, int pbc_flag, int *pbc) { int i,j,m; m = 0; for (i = 0; i < n; i++) { j = list[i]; buf[m++] = mass_rigid[j]; } return m; } /* ---------------------------------------------------------------------- */ void PairGranHookeHistory::unpack_forward_comm(int n, int first, double *buf) { int i,m,last; m = 0; last = first + n; for (i = first; i < last; i++) mass_rigid[i] = buf[m++]; } /* ---------------------------------------------------------------------- memory usage of local atom-based arrays ------------------------------------------------------------------------- */ double PairGranHookeHistory::memory_usage() { double bytes = nmax * sizeof(double); return bytes; } - -/* ---------------------------------------------------------------------- - return ptr to FixShearHistory class - called by Neighbor when setting up neighbor lists -------------------------------------------------------------------------- */ - -void *PairGranHookeHistory::extract(const char *str, int &dim) -{ - if (strcmp(str,"history") == 0) return (void *) fix_history; - return NULL; -} diff --git a/src/GRANULAR/pair_gran_hooke_history.h b/src/GRANULAR/pair_gran_hooke_history.h index afeab9341..f02cccd55 100644 --- a/src/GRANULAR/pair_gran_hooke_history.h +++ b/src/GRANULAR/pair_gran_hooke_history.h @@ -1,105 +1,103 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #ifdef PAIR_CLASS PairStyle(gran/hooke/history,PairGranHookeHistory) #else #ifndef LMP_PAIR_GRAN_HOOKE_HISTORY_H #define LMP_PAIR_GRAN_HOOKE_HISTORY_H #include "pair.h" namespace LAMMPS_NS { class PairGranHookeHistory : public Pair { public: PairGranHookeHistory(class LAMMPS *); virtual ~PairGranHookeHistory(); virtual void compute(int, int); virtual void settings(int, char **); void coeff(int, char **); void init_style(); - void init_list(int, class NeighList *); double init_one(int, int); void write_restart(FILE *); void read_restart(FILE *); void write_restart_settings(FILE *); void read_restart_settings(FILE *); void reset_dt(); virtual double single(int, int, int, int, double, double, double, double &); int pack_forward_comm(int, int *, double *, int, int *); void unpack_forward_comm(int, int, double *); double memory_usage(); - void *extract(const char *, int &); protected: double kn,kt,gamman,gammat,xmu; int dampflag; double dt; int freeze_group_bit; int history; int neighprev; double *onerad_dynamic,*onerad_frozen; double *maxrad_dynamic,*maxrad_frozen; - class FixShearHistory *fix_history; + class FixNeighHistory *fix_history; // storage of rigid body masses for use in granular interactions class Fix *fix_rigid; // ptr to rigid body fix, NULL if none double *mass_rigid; // rigid mass for owned+ghost atoms int nmax; // allocated size of mass_rigid void allocate(); }; } #endif #endif /* ERROR/WARNING messages: E: Illegal ... command Self-explanatory. Check the input script syntax and compare to the documentation for the command. You can use -echo screen as a command-line option when running LAMMPS to see the offending line. E: Incorrect args for pair coefficients Self-explanatory. Check the input script or data file. E: Pair granular requires atom attributes radius, rmass The atom style defined does not have these attributes. E: Pair granular requires ghost atoms store velocity Use the comm_modify vel yes command to enable this. E: Pair granular with shear history requires newton pair off This is a current restriction of the implementation of pair granular styles with history. E: Could not find pair fix ID A fix is created internally by the pair style to store shear history information. You cannot delete it. */ diff --git a/src/KOKKOS/neigh_list_kokkos.cpp b/src/KOKKOS/neigh_list_kokkos.cpp index caf2dfee5..04454e53c 100644 --- a/src/KOKKOS/neigh_list_kokkos.cpp +++ b/src/KOKKOS/neigh_list_kokkos.cpp @@ -1,71 +1,62 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include "neigh_list_kokkos.h" #include "atom.h" #include "memory.h" using namespace LAMMPS_NS; enum{NSQ,BIN,MULTI}; /* ---------------------------------------------------------------------- */ template NeighListKokkos::NeighListKokkos(class LAMMPS *lmp):NeighList(lmp) { _stride = 1; maxneighs = 16; kokkos = 1; maxatoms = 0; execution_space = ExecutionSpaceFromDevice::space; }; /* ---------------------------------------------------------------------- */ template void NeighListKokkos::grow(int nmax) { // skip if this list is already long enough to store nmax atoms if (nmax <= maxatoms) return; maxatoms = nmax; k_ilist = DAT::tdual_int_1d("neighlist:ilist",maxatoms); d_ilist = k_ilist.view(); d_numneigh = typename ArrayTypes::t_int_1d("neighlist:numneigh",maxatoms); d_neighbors = typename ArrayTypes::t_neighbors_2d("neighlist:neighbors", maxatoms,maxneighs); - - memory->sfree(firstneigh); - memory->sfree(firstdouble); - - firstneigh = (int **) memory->smalloc(maxatoms*sizeof(int *), - "neighlist:firstneigh"); - if (dnum) - firstdouble = (double **) memory->smalloc(maxatoms*sizeof(double *), - "neighlist:firstdouble"); } /* ---------------------------------------------------------------------- */ namespace LAMMPS_NS { template class NeighListKokkos; #ifdef KOKKOS_HAVE_CUDA template class NeighListKokkos; #endif } diff --git a/src/KOKKOS/npair_copy_kokkos.cpp b/src/KOKKOS/npair_copy_kokkos.cpp index 6835d8c1b..870281603 100644 --- a/src/KOKKOS/npair_copy_kokkos.cpp +++ b/src/KOKKOS/npair_copy_kokkos.cpp @@ -1,62 +1,59 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include "npair_copy_kokkos.h" #include "neighbor.h" #include "neigh_list_kokkos.h" #include "atom.h" #include "atom_vec.h" #include "molecule.h" #include "domain.h" #include "my_page.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ template NPairCopyKokkos::NPairCopyKokkos(LAMMPS *lmp) : NPair(lmp) {} /* ---------------------------------------------------------------------- create list which is simply a copy of parent list ------------------------------------------------------------------------- */ template void NPairCopyKokkos::build(NeighList *list) { NeighList *listcopy = list->listcopy; list->inum = listcopy->inum; list->gnum = listcopy->gnum; list->ilist = listcopy->ilist; list->numneigh = listcopy->numneigh; - list->firstneigh = listcopy->firstneigh; - list->firstdouble = listcopy->firstdouble; list->ipage = listcopy->ipage; - list->dpage = listcopy->dpage; NeighListKokkos* list_kk = (NeighListKokkos*) list; NeighListKokkos* listcopy_kk = (NeighListKokkos*) list->listcopy; list_kk->d_ilist = listcopy_kk->d_ilist; list_kk->d_numneigh = listcopy_kk->d_numneigh; list_kk->d_neighbors = listcopy_kk->d_neighbors; } namespace LAMMPS_NS { template class NPairCopyKokkos; #ifdef KOKKOS_HAVE_CUDA template class NPairCopyKokkos; #endif } diff --git a/src/KSPACE/pair_buck_long_coul_long.cpp b/src/KSPACE/pair_buck_long_coul_long.cpp index 4cfb9b726..7df8ebac6 100644 --- a/src/KSPACE/pair_buck_long_coul_long.cpp +++ b/src/KSPACE/pair_buck_long_coul_long.cpp @@ -1,1051 +1,1026 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- Contributing author: Pieter J. in 't Veld (SNL) ------------------------------------------------------------------------- */ #include #include #include #include #include "math_vector.h" #include "pair_buck_long_coul_long.h" #include "atom.h" #include "comm.h" #include "neighbor.h" #include "neigh_list.h" #include "neigh_request.h" #include "force.h" #include "kspace.h" #include "update.h" #include "integrate.h" #include "respa.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; #define EWALD_F 1.12837917 #define EWALD_P 0.3275911 #define A1 0.254829592 #define A2 -0.284496736 #define A3 1.421413741 #define A4 -1.453152027 #define A5 1.061405429 /* ---------------------------------------------------------------------- */ PairBuckLongCoulLong::PairBuckLongCoulLong(LAMMPS *lmp) : Pair(lmp) { dispersionflag = ewaldflag = pppmflag = 1; respa_enable = 1; writedata = 1; ftable = NULL; fdisptable = NULL; } /* ---------------------------------------------------------------------- global settings ------------------------------------------------------------------------- */ void PairBuckLongCoulLong::options(char **arg, int order) { const char *option[] = {"long", "cut", "off", NULL}; int i; if (!*arg) error->all(FLERR,"Illegal pair_style buck/long/coul/long command"); for (i=0; option[i]&&strcmp(arg[0], option[i]); ++i); switch (i) { default: error->all(FLERR,"Illegal pair_style buck/long/coul/long command"); case 0: ewald_order |= 1<all(FLERR,"Illegal pair_style command"); ewald_order = 0; ewald_off = 0; options(arg,6); options(++arg,1); if (!comm->me && ewald_order == ((1<<1) | (1<<6))) error->warning(FLERR,"Using largest cutoff for buck/long/coul/long"); if (!*(++arg)) error->all(FLERR,"Cutoffs missing in pair_style buck/long/coul/long"); if (ewald_off & (1<<6)) error->all(FLERR,"LJ6 off not supported in pair_style buck/long/coul/long"); if (!((ewald_order^ewald_off) & (1<<1))) error->all(FLERR, "Coulomb cut not supported in pair_style buck/long/coul/coul"); cut_buck_global = force->numeric(FLERR,*(arg++)); if (narg == 4 && ((ewald_order & 0x42) == 0x42)) error->all(FLERR,"Only one cutoff allowed when requesting all long"); if (narg == 4) cut_coul = force->numeric(FLERR,*arg); else cut_coul = cut_buck_global; if (allocated) { int i,j; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) if (setflag[i][j]) cut_buck[i][j] = cut_buck_global; } } /* ---------------------------------------------------------------------- free all arrays ------------------------------------------------------------------------- */ PairBuckLongCoulLong::~PairBuckLongCoulLong() { if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(cut_buck_read); memory->destroy(cut_buck); memory->destroy(cut_bucksq); memory->destroy(buck_a_read); memory->destroy(buck_a); memory->destroy(buck_c_read); memory->destroy(buck_c); memory->destroy(buck_rho_read); memory->destroy(buck_rho); memory->destroy(buck1); memory->destroy(buck2); memory->destroy(rhoinv); memory->destroy(offset); } if (ftable) free_tables(); if (fdisptable) free_disp_tables(); } /* ---------------------------------------------------------------------- allocate all arrays ------------------------------------------------------------------------- */ void PairBuckLongCoulLong::allocate() { allocated = 1; int n = atom->ntypes; 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(cutsq,n+1,n+1,"pair:cutsq"); memory->create(cut_buck_read,n+1,n+1,"pair:cut_buck_read"); memory->create(cut_buck,n+1,n+1,"pair:cut_buck"); memory->create(cut_bucksq,n+1,n+1,"pair:cut_bucksq"); memory->create(buck_a_read,n+1,n+1,"pair:buck_a_read"); memory->create(buck_a,n+1,n+1,"pair:buck_a"); memory->create(buck_c_read,n+1,n+1,"pair:buck_c_read"); memory->create(buck_c,n+1,n+1,"pair:buck_c"); memory->create(buck_rho_read,n+1,n+1,"pair:buck_rho_read"); memory->create(buck_rho,n+1,n+1,"pair:buck_rho"); memory->create(buck1,n+1,n+1,"pair:buck1"); memory->create(buck2,n+1,n+1,"pair:buck2"); memory->create(rhoinv,n+1,n+1,"pair:rhoinv"); memory->create(offset,n+1,n+1,"pair:offset"); } /* ---------------------------------------------------------------------- extract protected data from object ------------------------------------------------------------------------- */ void *PairBuckLongCoulLong::extract(const char *id, int &dim) { const char *ids[] = { "B", "ewald_order", "ewald_cut", "ewald_mix", "cut_coul", "cut_LJ", NULL}; void *ptrs[] = { buck_c, &ewald_order, &cut_coul, &mix_flag, &cut_coul, &cut_buck_global, NULL}; int i; for (i=0; ids[i]&&strcmp(ids[i], id); ++i); if (i == 0) dim = 2; else dim = 0; return ptrs[i]; } /* ---------------------------------------------------------------------- set coeffs for one or more type pairs ------------------------------------------------------------------------- */ void PairBuckLongCoulLong::coeff(int narg, char **arg) { if (narg < 5 || narg > 6) error->all(FLERR,"Incorrect args for pair coefficients"); if (!allocated) allocate(); int ilo,ihi,jlo,jhi; force->bounds(FLERR,*(arg++),atom->ntypes,ilo,ihi); force->bounds(FLERR,*(arg++),atom->ntypes,jlo,jhi); double buck_a_one = force->numeric(FLERR,*(arg++)); double buck_rho_one = force->numeric(FLERR,*(arg++)); double buck_c_one = force->numeric(FLERR,*(arg++)); double cut_buck_one = cut_buck_global; if (narg == 6) cut_buck_one = force->numeric(FLERR,*(arg++)); int count = 0; for (int i = ilo; i <= ihi; i++) { for (int j = MAX(jlo,i); j <= jhi; j++) { buck_a_read[i][j] = buck_a_one; buck_c_read[i][j] = buck_c_one; buck_rho_read[i][j] = buck_rho_one; cut_buck_read[i][j] = cut_buck_one; setflag[i][j] = 1; count++; } } if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- init specific to this pair style ------------------------------------------------------------------------- */ void PairBuckLongCoulLong::init_style() { // require an atom style with charge defined if (!atom->q_flag && (ewald_order&(1<<1))) error->all(FLERR, - "Invoking coulombic in pair style buck/long/coul/long requires atom attribute q"); + "Invoking coulombic in pair style buck/long/coul/long " + "requires atom attribute q"); // ensure use of KSpace long-range solver, set two g_ewalds if (force->kspace == NULL) error->all(FLERR,"Pair style requires a KSpace style"); if (ewald_order&(1<<1)) g_ewald = force->kspace->g_ewald; if (ewald_order&(1<<6)) g_ewald_6 = force->kspace->g_ewald_6; // set rRESPA cutoffs if (strstr(update->integrate_style,"respa") && ((Respa *) update->integrate)->level_inner >= 0) cut_respa = ((Respa *) update->integrate)->cutoff; else cut_respa = NULL; // setup force tables if (ncoultablebits && (ewald_order&(1<<1))) init_tables(cut_coul,cut_respa); if (ndisptablebits && (ewald_order&(1<<6))) init_tables_disp(cut_buck_global); // request regular or rRESPA neighbor lists if neighrequest_flag != 0 if (force->kspace->neighrequest_flag) { int irequest; + int respa = 0; if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { - int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; + } - if (respa == 0) irequest = neighbor->request(this,instance_me); - else if (respa == 1) { - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 1; - neighbor->requests[irequest]->respainner = 1; - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 3; - neighbor->requests[irequest]->respaouter = 1; - } else { - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 1; - neighbor->requests[irequest]->respainner = 1; - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 2; - neighbor->requests[irequest]->respamiddle = 1; - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 3; - neighbor->requests[irequest]->respaouter = 1; - } + irequest = neighbor->request(this,instance_me); - } else irequest = neighbor->request(this,instance_me); + if (respa >= 1) { + neighbor->requests[irequest]->respaouter = 1; + neighbor->requests[irequest]->respainner = 1; + } + if (respa == 2) neighbor->requests[irequest]->respamiddle = 1; } cut_coulsq = cut_coul * cut_coul; } -/* ---------------------------------------------------------------------- - neighbor callback to inform pair style of neighbor list to use - regular or rRESPA -------------------------------------------------------------------------- */ - -void PairBuckLongCoulLong::init_list(int id, NeighList *ptr) -{ - if (id == 0) list = ptr; - else if (id == 1) listinner = ptr; - else if (id == 2) listmiddle = ptr; - else if (id == 3) listouter = ptr; -} - /* ---------------------------------------------------------------------- init for one type pair i,j and corresponding j,i ------------------------------------------------------------------------- */ double PairBuckLongCoulLong::init_one(int i, int j) { if (setflag[i][j] == 0) error->all(FLERR,"All pair coeffs are not set"); if (ewald_order&(1<<6)) cut_buck[i][j] = cut_buck_global; else cut_buck[i][j] = cut_buck_read[i][j]; buck_a[i][j] = buck_a_read[i][j]; buck_c[i][j] = buck_c_read[i][j]; buck_rho[i][j] = buck_rho_read[i][j]; double cut = MAX(cut_buck[i][j],cut_coul); cutsq[i][j] = cut*cut; cut_bucksq[i][j] = cut_buck[i][j] * cut_buck[i][j]; buck1[i][j] = buck_a[i][j]/buck_rho[i][j]; buck2[i][j] = 6.0*buck_c[i][j]; rhoinv[i][j] = 1.0/buck_rho[i][j]; // check interior rRESPA cutoff if (cut_respa && MIN(cut_buck[i][j],cut_coul) < cut_respa[3]) error->all(FLERR,"Pair cutoff < Respa interior cutoff"); if (offset_flag && (cut_buck[i][j] > 0.0)) { double rexp = exp(-cut_buck[i][j]/buck_rho[i][j]); offset[i][j] = buck_a[i][j]*rexp - buck_c[i][j]/pow(cut_buck[i][j],6.0); } else offset[i][j] = 0.0; cutsq[j][i] = cutsq[i][j]; cut_bucksq[j][i] = cut_bucksq[i][j]; buck_a[j][i] = buck_a[i][j]; buck_c[j][i] = buck_c[i][j]; rhoinv[j][i] = rhoinv[i][j]; buck1[j][i] = buck1[i][j]; buck2[j][i] = buck2[i][j]; offset[j][i] = offset[i][j]; return cut; } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairBuckLongCoulLong::write_restart(FILE *fp) { write_restart_settings(fp); int i,j; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { fwrite(&setflag[i][j],sizeof(int),1,fp); if (setflag[i][j]) { fwrite(&buck_a_read[i][j],sizeof(double),1,fp); fwrite(&buck_rho_read[i][j],sizeof(double),1,fp); fwrite(&buck_c_read[i][j],sizeof(double),1,fp); fwrite(&cut_buck_read[i][j],sizeof(double),1,fp); } } } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairBuckLongCoulLong::read_restart(FILE *fp) { read_restart_settings(fp); allocate(); int i,j; int me = comm->me; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp); MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world); if (setflag[i][j]) { if (me == 0) { fread(&buck_a_read[i][j],sizeof(double),1,fp); fread(&buck_rho_read[i][j],sizeof(double),1,fp); fread(&buck_c_read[i][j],sizeof(double),1,fp); fread(&cut_buck_read[i][j],sizeof(double),1,fp); } MPI_Bcast(&buck_a_read[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&buck_rho_read[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&buck_c_read[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&cut_buck_read[i][j],1,MPI_DOUBLE,0,world); } } } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairBuckLongCoulLong::write_restart_settings(FILE *fp) { fwrite(&cut_buck_global,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(&ncoultablebits,sizeof(int),1,fp); fwrite(&tabinner,sizeof(double),1,fp); fwrite(&ewald_order,sizeof(int),1,fp); } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairBuckLongCoulLong::read_restart_settings(FILE *fp) { if (comm->me == 0) { fread(&cut_buck_global,sizeof(double),1,fp); fread(&cut_coul,sizeof(double),1,fp); fread(&offset_flag,sizeof(int),1,fp); fread(&mix_flag,sizeof(int),1,fp); fread(&ncoultablebits,sizeof(int),1,fp); fread(&tabinner,sizeof(double),1,fp); fread(&ewald_order,sizeof(int),1,fp); } MPI_Bcast(&cut_buck_global,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(&ncoultablebits,1,MPI_INT,0,world); MPI_Bcast(&tabinner,1,MPI_DOUBLE,0,world); MPI_Bcast(&ewald_order,1,MPI_INT,0,world); } /* ---------------------------------------------------------------------- proc 0 writes to data file ------------------------------------------------------------------------- */ void PairBuckLongCoulLong::write_data(FILE *fp) { for (int i = 1; i <= atom->ntypes; i++) fprintf(fp,"%d %g %g %g\n",i, buck_a_read[i][i],buck_rho_read[i][i],buck_c_read[i][i]); } /* ---------------------------------------------------------------------- proc 0 writes all pairs to data file ------------------------------------------------------------------------- */ void PairBuckLongCoulLong::write_data_all(FILE *fp) { for (int i = 1; i <= atom->ntypes; i++) for (int j = i; j <= atom->ntypes; j++) fprintf(fp,"%d %d %g %g %g\n",i,j, buck_a_read[i][j],buck_rho_read[i][j],buck_c_read[i][j]); } /* ---------------------------------------------------------------------- compute pair interactions ------------------------------------------------------------------------- */ void PairBuckLongCoulLong::compute(int eflag, int vflag) { double evdwl,ecoul,fpair; evdwl = ecoul = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = vflag_fdotr = 0; double **x = atom->x, *x0 = x[0]; double **f = atom->f, *f0 = f[0], *fi = f0; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; int i, j, order1 = ewald_order&(1<<1), order6 = ewald_order&(1<<6); int *ineigh, *ineighn, *jneigh, *jneighn, typei, typej, ni; double qi = 0.0, qri = 0.0, *cutsqi, *cut_bucksqi, *buck1i, *buck2i, *buckai, *buckci, *rhoinvi, *offseti; double r, rsq, r2inv, force_coul, force_buck; double g2 = g_ewald_6*g_ewald_6, g6 = g2*g2*g2, g8 = g6*g2; vector xi, d; ineighn = (ineigh = list->ilist)+list->inum; for (; ineighfirstneigh[i])+list->numneigh[i]; for (; jneigh= cutsqi[typej = type[j]]) continue; r2inv = 1.0/rsq; r = sqrt(rsq); if (order1 && (rsq < cut_coulsq)) { // coulombic if (!ncoultablebits || rsq <= tabinnersq) { // series real space register double x = g_ewald*r; register double s = qri*q[j], t = 1.0/(1.0+EWALD_P*x); if (ni == 0) { s *= g_ewald*exp(-x*x); force_coul = (t *= ((((t*A5+A4)*t+A3)*t+A2)*t+A1)*s/x)+EWALD_F*s; if (eflag) ecoul = t; } else { // special case register double f = s*(1.0-special_coul[ni])/r; s *= g_ewald*exp(-x*x); force_coul = (t *= ((((t*A5+A4)*t+A3)*t+A2)*t+A1)*s/x)+EWALD_F*s-f; if (eflag) ecoul = t-f; } } // table real space else { register union_int_float_t t; t.f = rsq; register const int k = (t.i & ncoulmask) >> ncoulshiftbits; register double f = (rsq-rtable[k])*drtable[k], qiqj = qi*q[j]; if (ni == 0) { force_coul = qiqj*(ftable[k]+f*dftable[k]); if (eflag) ecoul = qiqj*(etable[k]+f*detable[k]); } else { // special case t.f = (1.0-special_coul[ni])*(ctable[k]+f*dctable[k]); force_coul = qiqj*(ftable[k]+f*dftable[k]-t.f); if (eflag) ecoul = qiqj*(etable[k]+f*detable[k]-t.f); } } } else force_coul = ecoul = 0.0; if (rsq < cut_bucksqi[typej]) { // buckingham register double rn = r2inv*r2inv*r2inv, expr = exp(-r*rhoinvi[typej]); if (order6) { // long-range if (!ndisptablebits || rsq <= tabinnerdispsq) { register double x2 = g2*rsq, a2 = 1.0/x2; x2 = a2*exp(-x2)*buckci[typej]; if (ni == 0) { force_buck = r*expr*buck1i[typej]-g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq; if (eflag) evdwl = expr*buckai[typej]-g6*((a2+1.0)*a2+0.5)*x2; } else { // special case register double f = special_lj[ni], t = rn*(1.0-f); force_buck = f*r*expr*buck1i[typej]- g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq+t*buck2i[typej]; if (eflag) evdwl = f*expr*buckai[typej] - g6*((a2+1.0)*a2+0.5)*x2+t*buckci[typej]; } } else { //table real space register union_int_float_t disp_t; disp_t.f = rsq; register const int disp_k = (disp_t.i & ndispmask)>>ndispshiftbits; register double f_disp = (rsq-rdisptable[disp_k])*drdisptable[disp_k]; if (ni == 0) { force_buck = r*expr*buck1i[typej]-(fdisptable[disp_k]+f_disp*dfdisptable[disp_k])*buckci[typej]; if (eflag) evdwl = expr*buckai[typej]-(edisptable[disp_k]+f_disp*dedisptable[disp_k])*buckci[typej]; } else { //speial case register double f = special_lj[ni], t = rn*(1.0-f); force_buck = f*r*expr*buck1i[typej] -(fdisptable[disp_k]+f_disp*dfdisptable[disp_k])*buckci[typej] +t*buck2i[typej]; if (eflag) evdwl = f*expr*buckai[typej] -(edisptable[disp_k]+f_disp*dedisptable[disp_k])*buckci[typej]+t*buckci[typej]; } } } else { // cut if (ni == 0) { force_buck = r*expr*buck1i[typej]-rn*buck2i[typej]; if (eflag) evdwl = expr*buckai[typej] - rn*buckci[typej]-offseti[typej]; } else { // special case register double f = special_lj[ni]; force_buck = f*(r*expr*buck1i[typej]-rn*buck2i[typej]); if (eflag) evdwl = f*(expr*buckai[typej]-rn*buckci[typej]-offseti[typej]); } } } else force_buck = evdwl = 0.0; fpair = (force_coul+force_buck)*r2inv; if (newton_pair || j < nlocal) { register double *fj = f0+(j+(j<<1)), f; fi[0] += f = d[0]*fpair; fj[0] -= f; fi[1] += f = d[1]*fpair; fj[1] -= f; fi[2] += f = d[2]*fpair; fj[2] -= f; } else { fi[0] += d[0]*fpair; fi[1] += d[1]*fpair; fi[2] += d[2]*fpair; } if (evflag) ev_tally(i,j,nlocal,newton_pair, evdwl,ecoul,fpair,d[0],d[1],d[2]); } } if (vflag_fdotr) virial_fdotr_compute(); } /* ---------------------------------------------------------------------- */ void PairBuckLongCoulLong::compute_inner() { double r, rsq, r2inv, force_coul = 0.0, force_buck, fpair; int *type = atom->type; int nlocal = atom->nlocal; double *x0 = atom->x[0], *f0 = atom->f[0], *fi = f0, *q = atom->q; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; double cut_out_on = cut_respa[0]; double cut_out_off = cut_respa[1]; double cut_out_diff = cut_out_off - cut_out_on; double cut_out_on_sq = cut_out_on*cut_out_on; double cut_out_off_sq = cut_out_off*cut_out_off; int *ineigh, *ineighn, *jneigh, *jneighn, typei, typej, ni; int i, j, order1 = (ewald_order|(ewald_off^-1))&(1<<1); double qri, *cut_bucksqi, *buck1i, *buck2i, *rhoinvi; vector xi, d; - ineighn = (ineigh = listinner->ilist) + listinner->inum; + ineighn = (ineigh = list->ilist_inner) + list->inum_inner; for (; ineighfirstneigh[i])+listinner->numneigh[i]; + jneighn = (jneigh = list->firstneigh_inner[i])+list->numneigh_inner[i]; for (; jneigh= cut_out_off_sq) continue; r2inv = 1.0/rsq; r = sqrt(rsq); if (order1 && (rsq < cut_coulsq)) // coulombic force_coul = ni == 0 ? qri*q[j]/r : qri*q[j]/r*special_coul[ni]; if (rsq < cut_bucksqi[typej = type[j]]) { // buckingham register double rn = r2inv*r2inv*r2inv, expr = exp(-r*rhoinvi[typej]); force_buck = ni == 0 ? (r*expr*buck1i[typej]-rn*buck2i[typej]) : (r*expr*buck1i[typej]-rn*buck2i[typej])*special_lj[ni]; } else force_buck = 0.0; fpair = (force_coul + force_buck) * r2inv; if (rsq > cut_out_on_sq) { // switching register double rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; fpair *= 1.0 + rsw*rsw*(2.0*rsw-3.0); } if (newton_pair || j < nlocal) { // force update register double *fj = f0+(j+(j<<1)), f; fi[0] += f = d[0]*fpair; fj[0] -= f; fi[1] += f = d[1]*fpair; fj[1] -= f; fi[2] += f = d[2]*fpair; fj[2] -= f; } else { fi[0] += d[0]*fpair; fi[1] += d[1]*fpair; fi[2] += d[2]*fpair; } } } } /* ---------------------------------------------------------------------- */ void PairBuckLongCoulLong::compute_middle() { double r, rsq, r2inv, force_coul = 0.0, force_buck, fpair; int *type = atom->type; int nlocal = atom->nlocal; double *x0 = atom->x[0], *f0 = atom->f[0], *fi = f0, *q = atom->q; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; double cut_in_off = cut_respa[0]; double cut_in_on = cut_respa[1]; double cut_out_on = cut_respa[2]; double cut_out_off = cut_respa[3]; double cut_in_diff = cut_in_on - cut_in_off; double cut_out_diff = cut_out_off - cut_out_on; double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; double cut_out_on_sq = cut_out_on*cut_out_on; double cut_out_off_sq = cut_out_off*cut_out_off; int *ineigh, *ineighn, *jneigh, *jneighn, typei, typej, ni; int i, j, order1 = (ewald_order|(ewald_off^-1))&(1<<1); double qri, *cut_bucksqi, *buck1i, *buck2i, *rhoinvi; vector xi, d; - ineighn = (ineigh = listmiddle->ilist)+listmiddle->inum; + ineighn = (ineigh = list->ilist_middle)+list->inum_middle; for (; ineighfirstneigh[i])+listmiddle->numneigh[i]; + jneighn = (jneigh = list->firstneigh_middle[i])+list->numneigh_middle[i]; for (; jneigh= cut_out_off_sq) continue; if (rsq <= cut_in_off_sq) continue; r2inv = 1.0/rsq; r = sqrt(rsq); if (order1 && (rsq < cut_coulsq)) // coulombic force_coul = ni == 0 ? qri*q[j]/r : qri*q[j]/r*special_coul[ni]; if (rsq < cut_bucksqi[typej = type[j]]) { // buckingham register double rn = r2inv*r2inv*r2inv, expr = exp(-r*rhoinvi[typej]); force_buck = ni == 0 ? (r*expr*buck1i[typej]-rn*buck2i[typej]) : (r*expr*buck1i[typej]-rn*buck2i[typej])*special_lj[ni]; } else force_buck = 0.0; fpair = (force_coul + force_buck) * r2inv; if (rsq < cut_in_on_sq) { // switching register double rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; fpair *= rsw*rsw*(3.0 - 2.0*rsw); } if (rsq > cut_out_on_sq) { register double rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; fpair *= 1.0 + rsw*rsw*(2.0*rsw-3.0); } if (newton_pair || j < nlocal) { // force update register double *fj = f0+(j+(j<<1)), f; fi[0] += f = d[0]*fpair; fj[0] -= f; fi[1] += f = d[1]*fpair; fj[1] -= f; fi[2] += f = d[2]*fpair; fj[2] -= f; } else { fi[0] += d[0]*fpair; fi[1] += d[1]*fpair; fi[2] += d[2]*fpair; } } } } /* ---------------------------------------------------------------------- */ void PairBuckLongCoulLong::compute_outer(int eflag, int vflag) { double evdwl,ecoul,fpair,fvirial; evdwl = ecoul = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = 0; double **x = atom->x, *x0 = x[0]; double **f = atom->f, *f0 = f[0], *fi = f0; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; int i, j, order1 = ewald_order&(1<<1), order6 = ewald_order&(1<<6); int *ineigh, *ineighn, *jneigh, *jneighn, typei, typej, ni, respa_flag; double qi = 0.0, qri = 0.0, *cutsqi, *cut_bucksqi, *buck1i, *buck2i, *buckai, *buckci, *rhoinvi, *offseti; double r, rsq, r2inv, force_coul, force_buck; double g2 = g_ewald_6*g_ewald_6, g6 = g2*g2*g2, g8 = g6*g2; double respa_buck = 0.0, respa_coul = 0.0, frespa = 0.0; vector xi, d; double cut_in_off = cut_respa[2]; double cut_in_on = cut_respa[3]; double cut_in_diff = cut_in_on - cut_in_off; double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; - ineighn = (ineigh = listouter->ilist)+listouter->inum; + ineighn = (ineigh = list->ilist)+list->inum; for (; ineighfirstneigh[i])+listouter->numneigh[i]; + jneighn = (jneigh = list->firstneigh[i])+list->numneigh[i]; for (; jneigh= cutsqi[typej = type[j]]) continue; r2inv = 1.0/rsq; r = sqrt(rsq); frespa = 1.0; //check whether and how to compute respa corrections respa_coul = 0.0; respa_buck = 0.0; respa_flag = rsq < cut_in_on_sq ? 1 : 0; if (respa_flag && (rsq > cut_in_off_sq)) { register double rsw = (r-cut_in_off)/cut_in_diff; frespa = 1-rsw*rsw*(3.0-2.0*rsw); } if (order1 && (rsq < cut_coulsq)) { // coulombic if (!ncoultablebits || rsq <= tabinnersq) { // series real space register double s = qri*q[j]; if (respa_flag) // correct for respa respa_coul = ni == 0 ? frespa*s/r : frespa*s/r*special_coul[ni]; register double x = g_ewald*r, t = 1.0/(1.0+EWALD_P*x); if (ni == 0) { s *= g_ewald*exp(-x*x); force_coul = (t *= ((((t*A5+A4)*t+A3)*t+A2)*t+A1)*s/x)+EWALD_F*s-respa_coul; if (eflag) ecoul = t; } else { // correct for special register double ri = s*(1.0-special_coul[ni])/r; s *= g_ewald*exp(-x*x); force_coul = (t *= ((((t*A5+A4)*t+A3)*t+A2)*t+A1)*s/x)+EWALD_F*s-ri-respa_coul; if (eflag) ecoul = t-ri; } } // table real space else { if (respa_flag) { register double s = qri*q[j]; respa_coul = ni == 0 ? frespa*s/r : frespa*s/r*special_coul[ni]; } register union_int_float_t t; t.f = rsq; register const int k = (t.i & ncoulmask) >> ncoulshiftbits; register double f = (rsq-rtable[k])*drtable[k], qiqj = qi*q[j]; if (ni == 0) { force_coul = qiqj*(ftable[k]+f*dftable[k]); if (eflag) ecoul = qiqj*(etable[k]+f*detable[k]); } else { // correct for special t.f = (1.0-special_coul[ni])*(ctable[k]+f*dctable[k]); force_coul = qiqj*(ftable[k]+f*dftable[k]-t.f); if (eflag) { t.f = (1.0-special_coul[ni])*(ptable[k]+f*dptable[k]); ecoul = qiqj*(etable[k]+f*detable[k]-t.f); } } } } else force_coul = respa_coul = ecoul = 0.0; if (rsq < cut_bucksqi[typej]) { // buckingham register double rn = r2inv*r2inv*r2inv, expr = exp(-r*rhoinvi[typej]); if (respa_flag) respa_buck = ni == 0 ? // correct for respa frespa*(r*expr*buck1i[typej]-rn*buck2i[typej]) : frespa*(r*expr*buck1i[typej]-rn*buck2i[typej])*special_lj[ni]; if (order6) { // long-range form if (!ndisptablebits || rsq <= tabinnerdispsq) { register double x2 = g2*rsq, a2 = 1.0/x2; x2 = a2*exp(-x2)*buckci[typej]; if (ni == 0) { force_buck = r*expr*buck1i[typej]-g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq-respa_buck; if (eflag) evdwl = expr*buckai[typej]-g6*((a2+1.0)*a2+0.5)*x2; } else { // correct for special register double f = special_lj[ni], t = rn*(1.0-f); force_buck = f*r*expr*buck1i[typej]- g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq+t*buck2i[typej]-respa_buck; if (eflag) evdwl = f*expr*buckai[typej] - g6*((a2+1.0)*a2+0.5)*x2+t*buckci[typej]; } } else { // table real space register union_int_float_t disp_t; disp_t.f = rsq; register const int disp_k = (disp_t.i & ndispmask)>>ndispshiftbits; register double f_disp = (rsq-rdisptable[disp_k])*drdisptable[disp_k]; register double rn = r2inv*r2inv*r2inv; if (ni == 0) { force_buck = r*expr*buck1i[typej]-(fdisptable[disp_k]+f_disp*dfdisptable[disp_k])*buckci[typej]-respa_buck; if (eflag) evdwl = expr*buckai[typej]-(edisptable[disp_k]+f_disp*dedisptable[disp_k])*buckci[typej]; } else { //special case register double f = special_lj[ni], t = rn*(1.0-f); force_buck = f*r*expr*buck1i[typej]-(fdisptable[disp_k]+f_disp*dfdisptable[disp_k])*buckci[typej]+t*buck2i[typej]-respa_buck; if (eflag) evdwl = f*expr*buckai[typej]-(edisptable[disp_k]+f_disp*dedisptable[disp_k])*buckci[typej]+t*buckci[typej]; } } } else { // cut form if (ni == 0) { force_buck = r*expr*buck1i[typej]-rn*buck2i[typej]-respa_buck; if (eflag) evdwl = expr*buckai[typej]-rn*buckci[typej]-offseti[typej]; } else { // correct for special register double f = special_lj[ni]; force_buck = f*(r*expr*buck1i[typej]-rn*buck2i[typej])-respa_buck; if (eflag) evdwl = f*(expr*buckai[typej]-rn*buckci[typej]-offseti[typej]); } } } else force_buck = respa_buck = evdwl = 0.0; fpair = (force_coul+force_buck)*r2inv; if (newton_pair || j < nlocal) { register double *fj = f0+(j+(j<<1)), f; fi[0] += f = d[0]*fpair; fj[0] -= f; fi[1] += f = d[1]*fpair; fj[1] -= f; fi[2] += f = d[2]*fpair; fj[2] -= f; } else { fi[0] += d[0]*fpair; fi[1] += d[1]*fpair; fi[2] += d[2]*fpair; } if (evflag) { fvirial = (force_coul + force_buck + respa_coul + respa_buck)*r2inv; ev_tally(i,j,nlocal,newton_pair, evdwl,ecoul,fvirial,d[0],d[1],d[2]); } } } } /* ---------------------------------------------------------------------- */ double PairBuckLongCoulLong::single(int i, int j, int itype, int jtype, double rsq, double factor_coul, double factor_buck, double &fforce) { double f, r, r2inv, r6inv, force_coul, force_buck; double g2 = g_ewald_6*g_ewald_6, g6 = g2*g2*g2, g8 = g6*g2, *q = atom->q; r = sqrt(rsq); r2inv = 1.0/rsq; double eng = 0.0; if ((ewald_order&2) && (rsq < cut_coulsq)) { // coulombic if (!ncoultablebits || rsq <= tabinnersq) { // series real space register double x = g_ewald*r; register double s = force->qqrd2e*q[i]*q[j], t = 1.0/(1.0+EWALD_P*x); f = s*(1.0-factor_coul)/r; s *= g_ewald*exp(-x*x); force_coul = (t *= ((((t*A5+A4)*t+A3)*t+A2)*t+A1)*s/x)+EWALD_F*s-f; eng += t-f; } else { // table real space register union_int_float_t t; t.f = rsq; register const int k = (t.i & ncoulmask) >> ncoulshiftbits; register double f = (rsq-rtable[k])*drtable[k], qiqj = q[i]*q[j]; t.f = (1.0-factor_coul)*(ctable[k]+f*dctable[k]); force_coul = qiqj*(ftable[k]+f*dftable[k]-t.f); eng += qiqj*(etable[k]+f*detable[k]-t.f); } } else force_coul = 0.0; if (rsq < cut_bucksq[itype][jtype]) { // buckingham register double expr = factor_buck*exp(-sqrt(rsq)*rhoinv[itype][jtype]); r6inv = r2inv*r2inv*r2inv; if (ewald_order&64) { // long-range register double x2 = g2*rsq, a2 = 1.0/x2, t = r6inv*(1.0-factor_buck); x2 = a2*exp(-x2)*buck_c[itype][jtype]; force_buck = buck1[itype][jtype]*r*expr- g8*(((6.0*a2+6.0)*a2+3.0)*a2+a2)*x2*rsq+t*buck2[itype][jtype]; eng += buck_a[itype][jtype]*expr- g6*((a2+1.0)*a2+0.5)*x2+t*buck_c[itype][jtype]; } else { // cut force_buck = buck1[itype][jtype]*r*expr-factor_buck*buck_c[itype][jtype]*r6inv; eng += buck_a[itype][jtype]*expr- factor_buck*(buck_c[itype][jtype]*r6inv-offset[itype][jtype]); } } else force_buck = 0.0; fforce = (force_coul+force_buck)*r2inv; return eng; } diff --git a/src/KSPACE/pair_buck_long_coul_long.h b/src/KSPACE/pair_buck_long_coul_long.h index cf752a09b..40fe7c417 100644 --- a/src/KSPACE/pair_buck_long_coul_long.h +++ b/src/KSPACE/pair_buck_long_coul_long.h @@ -1,123 +1,122 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #ifdef PAIR_CLASS PairStyle(buck/long/coul/long,PairBuckLongCoulLong) #else #ifndef LMP_PAIR_BUCK_LONG_COUL_LONG_H #define LMP_PAIR_BUCK_LONG_COUL_LONG_H #include "pair.h" namespace LAMMPS_NS { class PairBuckLongCoulLong : public Pair { public: double cut_coul; PairBuckLongCoulLong(class LAMMPS *); ~PairBuckLongCoulLong(); virtual void compute(int, int); virtual void settings(int, char **); void coeff(int, char **); void init_style(); - void init_list(int, class NeighList *); double init_one(int, int); void write_restart(FILE *); void read_restart(FILE *); void write_restart_settings(FILE *); void read_restart_settings(FILE *); void write_data(FILE *); void write_data_all(FILE *); double single(int, int, int, int, double, double, double, double &); void *extract(const char *, int &); virtual void compute_inner(); virtual void compute_middle(); virtual void compute_outer(int, int); protected: double cut_buck_global; double **cut_buck, **cut_buck_read, **cut_bucksq; double cut_coulsq; double **buck_a_read, **buck_a, **buck_c_read, **buck_c; double **buck1, **buck2, **buck_rho_read, **buck_rho, **rhoinv, **offset; double *cut_respa; double g_ewald; double g_ewald_6; int ewald_order, ewald_off; void options(char **arg, int order); void allocate(); }; } #endif #endif /* ERROR/WARNING messages: E: Illegal ... command Self-explanatory. Check the input script syntax and compare to the documentation for the command. You can use -echo screen as a command-line option when running LAMMPS to see the offending line. W: Using largest cutoff for buck/long/coul/long Self-explanatory. E: Cutoffs missing in pair_style buck/long/coul/long Self-explanatory. E: LJ6 off not supported in pair_style buck/long/coul/long Self-explanatory. E: Coulomb cut not supported in pair_style buck/long/coul/coul Must use long-range Coulombic interactions. E: Only one cutoff allowed when requesting all long Self-explanatory. E: Incorrect args for pair coefficients Self-explanatory. Check the input script or data file. E: Pair style buck/long/coul/long requires atom attribute q The atom style defined does not have this attribute. E: Pair style requires a KSpace style No kspace style is defined. E: All pair coeffs are not set All pair coefficients must be set in the data file or by the pair_coeff command before running a simulation. E: Pair cutoff < Respa interior cutoff One or more pairwise cutoffs are too short to use with the specified rRESPA cutoffs. */ diff --git a/src/KSPACE/pair_lj_charmm_coul_long.cpp b/src/KSPACE/pair_lj_charmm_coul_long.cpp index 7b3fdd4b5..daa493cef 100644 --- a/src/KSPACE/pair_lj_charmm_coul_long.cpp +++ b/src/KSPACE/pair_lj_charmm_coul_long.cpp @@ -1,1027 +1,1001 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- Contributing author: Paul Crozier (SNL) ------------------------------------------------------------------------- */ #include #include #include #include #include "pair_lj_charmm_coul_long.h" #include "atom.h" #include "comm.h" #include "force.h" #include "kspace.h" #include "update.h" #include "integrate.h" #include "respa.h" #include "neighbor.h" #include "neigh_list.h" #include "neigh_request.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; #define EWALD_F 1.12837917 #define EWALD_P 0.3275911 #define A1 0.254829592 #define A2 -0.284496736 #define A3 1.421413741 #define A4 -1.453152027 #define A5 1.061405429 /* ---------------------------------------------------------------------- */ PairLJCharmmCoulLong::PairLJCharmmCoulLong(LAMMPS *lmp) : Pair(lmp) { respa_enable = 1; ewaldflag = pppmflag = 1; ftable = NULL; implicit = 0; mix_flag = ARITHMETIC; writedata = 1; } /* ---------------------------------------------------------------------- */ PairLJCharmmCoulLong::~PairLJCharmmCoulLong() { if (!copymode) { if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(epsilon); memory->destroy(sigma); memory->destroy(eps14); memory->destroy(sigma14); memory->destroy(lj1); memory->destroy(lj2); memory->destroy(lj3); memory->destroy(lj4); memory->destroy(lj14_1); memory->destroy(lj14_2); memory->destroy(lj14_3); memory->destroy(lj14_4); memory->destroy(offset); } if (ftable) free_tables(); } } /* ---------------------------------------------------------------------- */ void PairLJCharmmCoulLong::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype,itable; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair; double fraction,table; double r,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; double grij,expm2,prefactor,t,erfc; double philj,switch1,switch2; int *ilist,*jlist,*numneigh,**firstneigh; double rsq; evdwl = ecoul = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; inum = list->inum; ilist = list->ilist; numneigh = list->numneigh; firstneigh = list->firstneigh; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq < cut_bothsq) { r2inv = 1.0/rsq; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { r = sqrt(rsq); grij = g_ewald * r; expm2 = exp(-grij*grij); t = 1.0 / (1.0 + EWALD_P*grij); erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2; prefactor = qqrd2e * qtmp*q[j]/r; forcecoul = prefactor * (erfc + EWALD_F*grij*expm2); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; } else { union_int_float_t rsq_lookup; rsq_lookup.f = rsq; itable = rsq_lookup.i & ncoulmask; itable >>= ncoulshiftbits; fraction = (rsq_lookup.f - rtable[itable]) * drtable[itable]; table = ftable[itable] + fraction*dftable[itable]; forcecoul = qtmp*q[j] * table; if (factor_coul < 1.0) { table = ctable[itable] + fraction*dctable[itable]; prefactor = qtmp*q[j] * table; forcecoul -= (1.0-factor_coul)*prefactor; } } } else forcecoul = 0.0; if (rsq < cut_ljsq) { r6inv = r2inv*r2inv*r2inv; jtype = type[j]; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) * denom_lj_inv; switch2 = 12.0*rsq * (cut_ljsq-rsq) * (rsq-cut_lj_innersq) * denom_lj_inv; philj = r6inv * (lj3[itype][jtype]*r6inv - lj4[itype][jtype]); forcelj = forcelj*switch1 + philj*switch2; } } else forcelj = 0.0; fpair = (forcecoul + factor_lj*forcelj) * r2inv; 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; } if (eflag) { if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) ecoul = prefactor*erfc; else { table = etable[itable] + fraction*detable[itable]; ecoul = qtmp*q[j] * table; } if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; } else ecoul = 0.0; if (rsq < cut_ljsq) { evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) * denom_lj_inv; evdwl *= switch1; } evdwl *= factor_lj; } else evdwl = 0.0; } if (evflag) ev_tally(i,j,nlocal,newton_pair, evdwl,ecoul,fpair,delx,dely,delz); } } } if (vflag_fdotr) virial_fdotr_compute(); } /* ---------------------------------------------------------------------- */ void PairLJCharmmCoulLong::compute_inner() { int i,j,ii,jj,inum,jnum,itype,jtype; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fpair; double rsq,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; double rsw; int *ilist,*jlist,*numneigh,**firstneigh; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; - inum = listinner->inum; - ilist = listinner->ilist; - numneigh = listinner->numneigh; - firstneigh = listinner->firstneigh; + inum = list->inum_inner; + ilist = list->ilist_inner; + numneigh = list->numneigh_inner; + firstneigh = list->firstneigh_inner; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq < cut_out_off_sq) { r2inv = 1.0/rsq; forcecoul = qqrd2e * qtmp*q[j]*sqrt(r2inv); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*forcecoul; r6inv = r2inv*r2inv*r2inv; jtype = type[j]; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); fpair = (forcecoul + factor_lj*forcelj) * r2inv; if (rsq > cut_out_on_sq) { rsw = (sqrt(rsq) - cut_out_on)*cut_out_diff_inv; fpair *= 1.0 + rsw*rsw*(2.0*rsw-3.0); } 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; } } } } } /* ---------------------------------------------------------------------- */ void PairLJCharmmCoulLong::compute_middle() { int i,j,ii,jj,inum,jnum,itype,jtype; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fpair; double rsq,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; double philj,switch1,switch2; double rsw; int *ilist,*jlist,*numneigh,**firstneigh; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; - inum = listmiddle->inum; - ilist = listmiddle->ilist; - numneigh = listmiddle->numneigh; - firstneigh = listmiddle->firstneigh; + inum = list->inum_middle; + ilist = list->ilist_middle; + numneigh = list->numneigh_middle; + firstneigh = list->firstneigh_middle; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq < cut_out_off_sq && rsq > cut_in_off_sq) { r2inv = 1.0/rsq; forcecoul = qqrd2e * qtmp*q[j]*sqrt(r2inv); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*forcecoul; r6inv = r2inv*r2inv*r2inv; jtype = type[j]; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) * denom_lj_inv; switch2 = 12.0*rsq * (cut_ljsq-rsq) * (rsq-cut_lj_innersq) * denom_lj_inv; philj = r6inv * (lj3[itype][jtype]*r6inv - lj4[itype][jtype]); forcelj = forcelj*switch1 + philj*switch2; } fpair = (forcecoul + factor_lj*forcelj) * r2inv; if (rsq < cut_in_on_sq) { rsw = (sqrt(rsq) - cut_in_off)*cut_in_diff_inv; fpair *= rsw*rsw*(3.0 - 2.0*rsw); } if (rsq > cut_out_on_sq) { rsw = (sqrt(rsq) - cut_out_on)*cut_out_diff_inv; fpair *= 1.0 + rsw*rsw*(2.0*rsw - 3.0); } 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; } } } } } /* ---------------------------------------------------------------------- */ void PairLJCharmmCoulLong::compute_outer(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype,itable; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair; double fraction,table; double r,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; double grij,expm2,prefactor,t,erfc; double philj,switch1,switch2; double rsw; int *ilist,*jlist,*numneigh,**firstneigh; double rsq; evdwl = ecoul = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; - inum = listouter->inum; - ilist = listouter->ilist; - numneigh = listouter->numneigh; - firstneigh = listouter->firstneigh; + inum = list->inum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; if (rsq < cut_bothsq) { r2inv = 1.0/rsq; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { r = sqrt(rsq); grij = g_ewald * r; expm2 = exp(-grij*grij); t = 1.0 / (1.0 + EWALD_P*grij); erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2; prefactor = qqrd2e * qtmp*q[j]/r; forcecoul = prefactor * (erfc + EWALD_F*grij*expm2 - 1.0); if (rsq > cut_in_off_sq) { if (rsq < cut_in_on_sq) { rsw = (r - cut_in_off)/cut_in_diff; forcecoul += prefactor*rsw*rsw*(3.0 - 2.0*rsw); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor*rsw*rsw*(3.0 - 2.0*rsw); } else { forcecoul += prefactor; if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; } } } else { union_int_float_t rsq_lookup; rsq_lookup.f = rsq; itable = rsq_lookup.i & ncoulmask; itable >>= ncoulshiftbits; fraction = (rsq_lookup.f - rtable[itable]) * drtable[itable]; table = ftable[itable] + fraction*dftable[itable]; forcecoul = qtmp*q[j] * table; if (factor_coul < 1.0) { table = ctable[itable] + fraction*dctable[itable]; prefactor = qtmp*q[j] * table; forcecoul -= (1.0-factor_coul)*prefactor; } } } else forcecoul = 0.0; if (rsq < cut_ljsq && rsq > cut_in_off_sq) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) * denom_lj_inv; switch2 = 12.0*rsq * (cut_ljsq-rsq) * (rsq-cut_lj_innersq) * denom_lj_inv; philj = r6inv * (lj3[itype][jtype]*r6inv - lj4[itype][jtype]); forcelj = forcelj*switch1 + philj*switch2; } if (rsq < cut_in_on_sq) { rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; forcelj *= rsw*rsw*(3.0 - 2.0*rsw); } } else forcelj = 0.0; fpair = (forcecoul + forcelj) * r2inv; 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; } if (eflag) { if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { ecoul = prefactor*erfc; if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; } else { table = etable[itable] + fraction*detable[itable]; ecoul = qtmp*q[j] * table; if (factor_coul < 1.0) { table = ptable[itable] + fraction*dptable[itable]; prefactor = qtmp*q[j] * table; ecoul -= (1.0-factor_coul)*prefactor; } } } else ecoul = 0.0; if (rsq < cut_ljsq) { r6inv = r2inv*r2inv*r2inv; evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) * denom_lj_inv; evdwl *= switch1; } evdwl *= factor_lj; } else evdwl = 0.0; } if (vflag) { if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { forcecoul = prefactor * (erfc + EWALD_F*grij*expm2); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; } else { table = vtable[itable] + fraction*dvtable[itable]; forcecoul = qtmp*q[j] * table; if (factor_coul < 1.0) { table = ptable[itable] + fraction*dptable[itable]; prefactor = qtmp*q[j] * table; forcecoul -= (1.0-factor_coul)*prefactor; } } } else forcecoul = 0.0; if (rsq <= cut_in_off_sq) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) * denom_lj_inv; switch2 = 12.0*rsq * (cut_ljsq-rsq) * (rsq-cut_lj_innersq) * denom_lj_inv; philj = r6inv * (lj3[itype][jtype]*r6inv - lj4[itype][jtype]); forcelj = forcelj*switch1 + philj*switch2; } } else if (rsq <= cut_in_on_sq) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) * denom_lj_inv; switch2 = 12.0*rsq * (cut_ljsq-rsq) * (rsq-cut_lj_innersq) * denom_lj_inv; philj = r6inv * (lj3[itype][jtype]*r6inv - lj4[itype][jtype]); forcelj = forcelj*switch1 + philj*switch2; } } fpair = (forcecoul + factor_lj*forcelj) * r2inv; } if (evflag) ev_tally(i,j,nlocal,newton_pair, evdwl,ecoul,fpair,delx,dely,delz); } } } } /* ---------------------------------------------------------------------- allocate all arrays ------------------------------------------------------------------------- */ void PairLJCharmmCoulLong::allocate() { allocated = 1; int n = atom->ntypes; 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(cutsq,n+1,n+1,"pair:cutsq"); memory->create(epsilon,n+1,n+1,"pair:epsilon"); memory->create(sigma,n+1,n+1,"pair:sigma"); memory->create(eps14,n+1,n+1,"pair:eps14"); memory->create(sigma14,n+1,n+1,"pair:sigma14"); memory->create(lj1,n+1,n+1,"pair:lj1"); memory->create(lj2,n+1,n+1,"pair:lj2"); memory->create(lj3,n+1,n+1,"pair:lj3"); memory->create(lj4,n+1,n+1,"pair:lj4"); memory->create(lj14_1,n+1,n+1,"pair:lj14_1"); memory->create(lj14_2,n+1,n+1,"pair:lj14_2"); memory->create(lj14_3,n+1,n+1,"pair:lj14_3"); memory->create(lj14_4,n+1,n+1,"pair:lj14_4"); memory->create(offset,n+1,n+1,"pair:offset"); } /* ---------------------------------------------------------------------- global settings unlike other pair styles, there are no individual pair settings that these override ------------------------------------------------------------------------- */ void PairLJCharmmCoulLong::settings(int narg, char **arg) { if (narg != 2 && narg != 3) error->all(FLERR,"Illegal pair_style command"); cut_lj_inner = force->numeric(FLERR,arg[0]); cut_lj = force->numeric(FLERR,arg[1]); if (narg == 2) cut_coul = cut_lj; else cut_coul = force->numeric(FLERR,arg[2]); } /* ---------------------------------------------------------------------- set coeffs for one or more type pairs ------------------------------------------------------------------------- */ void PairLJCharmmCoulLong::coeff(int narg, char **arg) { if (narg != 4 && narg != 6) error->all(FLERR,"Illegal pair_coeff command"); if (!allocated) allocate(); int ilo,ihi,jlo,jhi; force->bounds(FLERR,arg[0],atom->ntypes,ilo,ihi); force->bounds(FLERR,arg[1],atom->ntypes,jlo,jhi); double epsilon_one = force->numeric(FLERR,arg[2]); double sigma_one = force->numeric(FLERR,arg[3]); double eps14_one = epsilon_one; double sigma14_one = sigma_one; if (narg == 6) { eps14_one = force->numeric(FLERR,arg[4]); sigma14_one = force->numeric(FLERR,arg[5]); } int count = 0; for (int i = ilo; i <= ihi; i++) { for (int j = MAX(jlo,i); j <= jhi; j++) { epsilon[i][j] = epsilon_one; sigma[i][j] = sigma_one; eps14[i][j] = eps14_one; sigma14[i][j] = sigma14_one; setflag[i][j] = 1; count++; } } if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- init specific to this pair style ------------------------------------------------------------------------- */ void PairLJCharmmCoulLong::init_style() { if (!atom->q_flag) error->all(FLERR, "Pair style lj/charmm/coul/long requires atom attribute q"); - // request regular or rRESPA neighbor lists + // request regular or rRESPA neighbor list int irequest; + int respa = 0; if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { - int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; + } - if (respa == 0) irequest = neighbor->request(this,instance_me); - else if (respa == 1) { - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 1; - neighbor->requests[irequest]->respainner = 1; - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 3; - neighbor->requests[irequest]->respaouter = 1; - } else { - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 1; - neighbor->requests[irequest]->respainner = 1; - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 2; - neighbor->requests[irequest]->respamiddle = 1; - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 3; - neighbor->requests[irequest]->respaouter = 1; - } + irequest = neighbor->request(this,instance_me); - } else irequest = neighbor->request(this,instance_me); + if (respa >= 1) { + neighbor->requests[irequest]->respaouter = 1; + neighbor->requests[irequest]->respainner = 1; + } + if (respa == 2) neighbor->requests[irequest]->respamiddle = 1; // require cut_lj_inner < cut_lj if (cut_lj_inner >= cut_lj) error->all(FLERR,"Pair inner cutoff >= Pair outer cutoff"); cut_lj_innersq = cut_lj_inner * cut_lj_inner; cut_ljsq = cut_lj * cut_lj; cut_coulsq = cut_coul * cut_coul; cut_bothsq = MAX(cut_ljsq,cut_coulsq); denom_lj = ( (cut_ljsq-cut_lj_innersq) * (cut_ljsq-cut_lj_innersq) * (cut_ljsq-cut_lj_innersq) ); denom_lj_inv = 1.0 / denom_lj; // set & error check interior rRESPA cutoffs if (strstr(update->integrate_style,"respa") && ((Respa *) update->integrate)->level_inner >= 0) { cut_respa = ((Respa *) update->integrate)->cutoff; cut_in_off = cut_respa[0]; cut_in_on = cut_respa[1]; cut_out_on = cut_respa[2]; cut_out_off = cut_respa[3]; cut_in_diff = cut_in_on - cut_in_off; cut_out_diff = cut_out_off - cut_out_on; cut_in_diff_inv = 1.0 / (cut_in_diff); cut_out_diff_inv = 1.0 / (cut_out_diff); cut_in_off_sq = cut_in_off*cut_in_off; cut_in_on_sq = cut_in_on*cut_in_on; cut_out_on_sq = cut_out_on*cut_out_on; cut_out_off_sq = cut_out_off*cut_out_off; if (MIN(cut_lj,cut_coul) < cut_respa[3]) error->all(FLERR,"Pair cutoff < Respa interior cutoff"); if (cut_lj_inner < cut_respa[1]) error->all(FLERR,"Pair inner cutoff < Respa interior cutoff"); } else cut_respa = NULL; // insure use of KSpace long-range solver, set g_ewald if (force->kspace == NULL) error->all(FLERR,"Pair style requires a KSpace style"); g_ewald = force->kspace->g_ewald; // setup force tables if (ncoultablebits) init_tables(cut_coul,cut_respa); } -/* ---------------------------------------------------------------------- - neighbor callback to inform pair style of neighbor list to use - regular or rRESPA -------------------------------------------------------------------------- */ - -void PairLJCharmmCoulLong::init_list(int id, NeighList *ptr) -{ - if (id == 0) list = ptr; - else if (id == 1) listinner = ptr; - else if (id == 2) listmiddle = ptr; - else if (id == 3) listouter = ptr; -} - /* ---------------------------------------------------------------------- init for one type pair i,j and corresponding j,i ------------------------------------------------------------------------- */ double PairLJCharmmCoulLong::init_one(int i, int j) { if (setflag[i][j] == 0) { epsilon[i][j] = mix_energy(epsilon[i][i],epsilon[j][j], sigma[i][i],sigma[j][j]); sigma[i][j] = mix_distance(sigma[i][i],sigma[j][j]); eps14[i][j] = mix_energy(eps14[i][i],eps14[j][j], sigma14[i][i],sigma14[j][j]); sigma14[i][j] = mix_distance(sigma14[i][i],sigma14[j][j]); } double cut = MAX(cut_lj,cut_coul); lj1[i][j] = 48.0 * epsilon[i][j] * pow(sigma[i][j],12.0); lj2[i][j] = 24.0 * epsilon[i][j] * pow(sigma[i][j],6.0); lj3[i][j] = 4.0 * epsilon[i][j] * pow(sigma[i][j],12.0); lj4[i][j] = 4.0 * epsilon[i][j] * pow(sigma[i][j],6.0); lj14_1[i][j] = 48.0 * eps14[i][j] * pow(sigma14[i][j],12.0); lj14_2[i][j] = 24.0 * eps14[i][j] * pow(sigma14[i][j],6.0); lj14_3[i][j] = 4.0 * eps14[i][j] * pow(sigma14[i][j],12.0); lj14_4[i][j] = 4.0 * eps14[i][j] * pow(sigma14[i][j],6.0); lj1[j][i] = lj1[i][j]; lj2[j][i] = lj2[i][j]; lj3[j][i] = lj3[i][j]; lj4[j][i] = lj4[i][j]; lj14_1[j][i] = lj14_1[i][j]; lj14_2[j][i] = lj14_2[i][j]; lj14_3[j][i] = lj14_3[i][j]; lj14_4[j][i] = lj14_4[i][j]; return cut; } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairLJCharmmCoulLong::write_restart(FILE *fp) { write_restart_settings(fp); int i,j; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { fwrite(&setflag[i][j],sizeof(int),1,fp); if (setflag[i][j]) { fwrite(&epsilon[i][j],sizeof(double),1,fp); fwrite(&sigma[i][j],sizeof(double),1,fp); fwrite(&eps14[i][j],sizeof(double),1,fp); fwrite(&sigma14[i][j],sizeof(double),1,fp); } } } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairLJCharmmCoulLong::read_restart(FILE *fp) { read_restart_settings(fp); allocate(); int i,j; int me = comm->me; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp); MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world); if (setflag[i][j]) { if (me == 0) { fread(&epsilon[i][j],sizeof(double),1,fp); fread(&sigma[i][j],sizeof(double),1,fp); fread(&eps14[i][j],sizeof(double),1,fp); fread(&sigma14[i][j],sizeof(double),1,fp); } MPI_Bcast(&epsilon[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&sigma[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&eps14[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&sigma14[i][j],1,MPI_DOUBLE,0,world); } } } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairLJCharmmCoulLong::write_restart_settings(FILE *fp) { fwrite(&cut_lj_inner,sizeof(double),1,fp); fwrite(&cut_lj,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(&ncoultablebits,sizeof(int),1,fp); fwrite(&tabinner,sizeof(double),1,fp); } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairLJCharmmCoulLong::read_restart_settings(FILE *fp) { if (comm->me == 0) { fread(&cut_lj_inner,sizeof(double),1,fp); fread(&cut_lj,sizeof(double),1,fp); fread(&cut_coul,sizeof(double),1,fp); fread(&offset_flag,sizeof(int),1,fp); fread(&mix_flag,sizeof(int),1,fp); fread(&ncoultablebits,sizeof(int),1,fp); fread(&tabinner,sizeof(double),1,fp); } MPI_Bcast(&cut_lj_inner,1,MPI_DOUBLE,0,world); MPI_Bcast(&cut_lj,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(&ncoultablebits,1,MPI_INT,0,world); MPI_Bcast(&tabinner,1,MPI_DOUBLE,0,world); } /* ---------------------------------------------------------------------- proc 0 writes to data file ------------------------------------------------------------------------- */ void PairLJCharmmCoulLong::write_data(FILE *fp) { for (int i = 1; i <= atom->ntypes; i++) fprintf(fp,"%d %g %g %g %g\n", i,epsilon[i][i],sigma[i][i],eps14[i][i],sigma14[i][i]); } /* ---------------------------------------------------------------------- proc 0 writes all pairs to data file ------------------------------------------------------------------------- */ void PairLJCharmmCoulLong::write_data_all(FILE *fp) { for (int i = 1; i <= atom->ntypes; i++) for (int j = i; j <= atom->ntypes; j++) fprintf(fp,"%d %d %g %g %g %g\n",i,j, epsilon[i][j],sigma[i][j],eps14[i][j],sigma14[i][j]); } /* ---------------------------------------------------------------------- */ double PairLJCharmmCoulLong::single(int i, int j, int itype, int jtype, double rsq, double factor_coul, double factor_lj, double &fforce) { double r2inv,r6inv,r,grij,expm2,t,erfc,prefactor; double switch1,switch2,fraction,table,forcecoul,forcelj,phicoul,philj; int itable; r2inv = 1.0/rsq; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { r = sqrt(rsq); grij = g_ewald * r; expm2 = exp(-grij*grij); t = 1.0 / (1.0 + EWALD_P*grij); erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2; prefactor = force->qqrd2e * atom->q[i]*atom->q[j]/r; forcecoul = prefactor * (erfc + EWALD_F*grij*expm2); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; } else { union_int_float_t rsq_lookup; rsq_lookup.f = rsq; itable = rsq_lookup.i & ncoulmask; itable >>= ncoulshiftbits; fraction = (rsq_lookup.f - rtable[itable]) * drtable[itable]; table = ftable[itable] + fraction*dftable[itable]; forcecoul = atom->q[i]*atom->q[j] * table; if (factor_coul < 1.0) { table = ctable[itable] + fraction*dctable[itable]; prefactor = atom->q[i]*atom->q[j] * table; forcecoul -= (1.0-factor_coul)*prefactor; } } } else forcecoul = 0.0; if (rsq < cut_ljsq) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) * denom_lj_inv; switch2 = 12.0*rsq * (cut_ljsq-rsq) * (rsq-cut_lj_innersq) * denom_lj_inv; philj = r6inv * (lj3[itype][jtype]*r6inv - lj4[itype][jtype]); forcelj = forcelj*switch1 + philj*switch2; } } else forcelj = 0.0; fforce = (forcecoul + factor_lj*forcelj) * r2inv; double eng = 0.0; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) phicoul = prefactor*erfc; else { table = etable[itable] + fraction*detable[itable]; phicoul = atom->q[i]*atom->q[j] * table; } if (factor_coul < 1.0) phicoul -= (1.0-factor_coul)*prefactor; eng += phicoul; } if (rsq < cut_ljsq) { philj = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) * denom_lj_inv; philj *= switch1; } eng += factor_lj*philj; } return eng; } /* ---------------------------------------------------------------------- */ void *PairLJCharmmCoulLong::extract(const char *str, int &dim) { dim = 2; if (strcmp(str,"lj14_1") == 0) return (void *) lj14_1; if (strcmp(str,"lj14_2") == 0) return (void *) lj14_2; if (strcmp(str,"lj14_3") == 0) return (void *) lj14_3; if (strcmp(str,"lj14_4") == 0) return (void *) lj14_4; dim = 0; if (strcmp(str,"implicit") == 0) return (void *) &implicit; if (strcmp(str,"cut_coul") == 0) return (void *) &cut_coul; return NULL; } diff --git a/src/KSPACE/pair_lj_charmm_coul_long.h b/src/KSPACE/pair_lj_charmm_coul_long.h index 1544f3bc1..95c6d0d1c 100644 --- a/src/KSPACE/pair_lj_charmm_coul_long.h +++ b/src/KSPACE/pair_lj_charmm_coul_long.h @@ -1,110 +1,109 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #ifdef PAIR_CLASS PairStyle(lj/charmm/coul/long,PairLJCharmmCoulLong) #else #ifndef LMP_PAIR_LJ_CHARMM_COUL_LONG_H #define LMP_PAIR_LJ_CHARMM_COUL_LONG_H #include "pair.h" namespace LAMMPS_NS { class PairLJCharmmCoulLong : public Pair { public: PairLJCharmmCoulLong(class LAMMPS *); virtual ~PairLJCharmmCoulLong(); virtual void compute(int, int); virtual void settings(int, char **); void coeff(int, char **); virtual void init_style(); - void init_list(int, class NeighList *); virtual double init_one(int, int); void write_restart(FILE *); void read_restart(FILE *); void write_restart_settings(FILE *); void read_restart_settings(FILE *); void write_data(FILE *); void write_data_all(FILE *); virtual double single(int, int, int, int, double, double, double, double &); void compute_inner(); void compute_middle(); virtual void compute_outer(int, int); virtual void *extract(const char *, int &); protected: int implicit; double cut_lj_inner,cut_lj; double cut_lj_innersq,cut_ljsq; double cut_coul,cut_coulsq; double cut_bothsq; double cut_in_off, cut_in_on, cut_out_off, cut_out_on; double cut_in_diff, cut_out_diff; double cut_in_diff_inv, cut_out_diff_inv; double cut_in_off_sq, cut_in_on_sq, cut_out_off_sq, cut_out_on_sq; double denom_lj, denom_lj_inv; double **epsilon,**sigma,**eps14,**sigma14; double **lj1,**lj2,**lj3,**lj4,**offset; double **lj14_1,**lj14_2,**lj14_3,**lj14_4; double *cut_respa; double g_ewald; virtual void allocate(); }; } #endif #endif /* ERROR/WARNING messages: E: Illegal ... command Self-explanatory. Check the input script syntax and compare to the documentation for the command. You can use -echo screen as a command-line option when running LAMMPS to see the offending line. E: Incorrect args for pair coefficients Self-explanatory. Check the input script or data file. E: Pair style lj/charmm/coul/long requires atom attribute q The atom style defined does not have these attributes. E: Pair inner cutoff >= Pair outer cutoff The specified cutoffs for the pair style are inconsistent. E: Pair cutoff < Respa interior cutoff One or more pairwise cutoffs are too short to use with the specified rRESPA cutoffs. E: Pair inner cutoff < Respa interior cutoff One or more pairwise cutoffs are too short to use with the specified rRESPA cutoffs. E: Pair style requires a KSpace style No kspace style is defined. */ diff --git a/src/KSPACE/pair_lj_charmm_coul_msm.cpp b/src/KSPACE/pair_lj_charmm_coul_msm.cpp index 76c9ef0cc..00617c0bf 100644 --- a/src/KSPACE/pair_lj_charmm_coul_msm.cpp +++ b/src/KSPACE/pair_lj_charmm_coul_msm.cpp @@ -1,551 +1,551 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- Contributing authors: Paul Crozier (SNL), Stan Moore (SNL) ------------------------------------------------------------------------- */ #include #include #include #include #include "pair_lj_charmm_coul_msm.h" #include "atom.h" #include "comm.h" #include "force.h" #include "kspace.h" #include "update.h" #include "integrate.h" #include "respa.h" #include "neighbor.h" #include "neigh_list.h" #include "neigh_request.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ PairLJCharmmCoulMSM::PairLJCharmmCoulMSM(LAMMPS *lmp) : PairLJCharmmCoulLong(lmp) { ewaldflag = pppmflag = 0; msmflag = 1; nmax = 0; ftmp = NULL; } /* ---------------------------------------------------------------------- */ PairLJCharmmCoulMSM::~PairLJCharmmCoulMSM() { if (ftmp) memory->destroy(ftmp); } /* ---------------------------------------------------------------------- */ void PairLJCharmmCoulMSM::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype,itable; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair,fcoul; double fraction,table; double r,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; double egamma,fgamma,prefactor; double philj,switch1,switch2; int *ilist,*jlist,*numneigh,**firstneigh; double rsq; int eflag_old = eflag; if (force->kspace->scalar_pressure_flag && vflag) { if (vflag > 2) error->all(FLERR,"Must use 'kspace_modify pressure/scalar no' " "to obtain per-atom virial with kspace_style MSM"); if (atom->nmax > nmax) { if (ftmp) memory->destroy(ftmp); nmax = atom->nmax; memory->create(ftmp,nmax,3,"pair:ftmp"); } memset(&ftmp[0][0],0,nmax*3*sizeof(double)); // must switch on global energy computation if not already on if (eflag == 0 || eflag == 2) { eflag++; } } evdwl = ecoul = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; inum = list->inum; ilist = list->ilist; numneigh = list->numneigh; firstneigh = list->firstneigh; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq < cut_bothsq) { r2inv = 1.0/rsq; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { r = sqrt(rsq); prefactor = qqrd2e * qtmp*q[j]/r; egamma = 1.0 - (r/cut_coul)*force->kspace->gamma(r/cut_coul); fgamma = 1.0 + (rsq/cut_coulsq)*force->kspace->dgamma(r/cut_coul); forcecoul = prefactor * fgamma; if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; } else { union_int_float_t rsq_lookup; rsq_lookup.f = rsq; itable = rsq_lookup.i & ncoulmask; itable >>= ncoulshiftbits; fraction = (rsq_lookup.f - rtable[itable]) * drtable[itable]; table = ftable[itable] + fraction*dftable[itable]; forcecoul = qtmp*q[j] * table; if (factor_coul < 1.0) { table = ctable[itable] + fraction*dctable[itable]; prefactor = qtmp*q[j] * table; forcecoul -= (1.0-factor_coul)*prefactor; } } } else forcecoul = 0.0; if (rsq < cut_ljsq) { r6inv = r2inv*r2inv*r2inv; jtype = type[j]; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) * denom_lj_inv; switch2 = 12.0*rsq * (cut_ljsq-rsq) * (rsq-cut_lj_innersq) * denom_lj_inv; philj = r6inv * (lj3[itype][jtype]*r6inv - lj4[itype][jtype]); forcelj = forcelj*switch1 + philj*switch2; } } else forcelj = 0.0; if (!(force->kspace->scalar_pressure_flag && vflag)) { fpair = (forcecoul + factor_lj*forcelj) * r2inv; 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; } } else { // separate LJ and Coulombic forces fpair = (factor_lj*forcelj) * r2inv; 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; } fcoul = (forcecoul) * r2inv; ftmp[i][0] += delx*fcoul; ftmp[i][1] += dely*fcoul; ftmp[i][2] += delz*fcoul; if (newton_pair || j < nlocal) { ftmp[j][0] -= delx*fcoul; ftmp[j][1] -= dely*fcoul; ftmp[j][2] -= delz*fcoul; } } if (eflag) { if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) ecoul = prefactor*egamma; else { table = etable[itable] + fraction*detable[itable]; ecoul = qtmp*q[j] * table; } if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; } else ecoul = 0.0; if (eflag_old && rsq < cut_ljsq) { evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) * denom_lj_inv; evdwl *= switch1; } evdwl *= factor_lj; } else evdwl = 0.0; } if (evflag) ev_tally(i,j,nlocal,newton_pair, evdwl,ecoul,fpair,delx,dely,delz); } } } if (vflag_fdotr) virial_fdotr_compute(); if (force->kspace->scalar_pressure_flag && vflag) { for (i = 0; i < 3; i++) virial[i] += force->pair->eng_coul/3.0; for (int i = 0; i < nmax; i++) { f[i][0] += ftmp[i][0]; f[i][1] += ftmp[i][1]; f[i][2] += ftmp[i][2]; } } } /* ---------------------------------------------------------------------- */ void PairLJCharmmCoulMSM::compute_outer(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype,itable; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair; double fraction,table; double r,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; double egamma,fgamma,prefactor; double philj,switch1,switch2; double rsw; int *ilist,*jlist,*numneigh,**firstneigh; double rsq; if (force->kspace->scalar_pressure_flag) error->all(FLERR,"Must use 'kspace_modify pressure/scalar no' " "for rRESPA with kspace_style MSM"); evdwl = ecoul = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; - inum = listouter->inum; - ilist = listouter->ilist; - numneigh = listouter->numneigh; - firstneigh = listouter->firstneigh; + inum = list->inum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; double cut_in_off = cut_respa[2]; double cut_in_on = cut_respa[3]; double cut_in_diff = cut_in_on - cut_in_off; double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; if (rsq < cut_bothsq) { r2inv = 1.0/rsq; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { r = sqrt(rsq); prefactor = qqrd2e * qtmp*q[j]/r; egamma = 1.0 - (r/cut_coul)*force->kspace->gamma(r/cut_coul); fgamma = 1.0 + (rsq/cut_coulsq)*force->kspace->dgamma(r/cut_coul); forcecoul = prefactor * (fgamma - 1.0); if (rsq > cut_in_off_sq) { if (rsq < cut_in_on_sq) { rsw = (r - cut_in_off)/cut_in_diff; forcecoul += prefactor*rsw*rsw*(3.0 - 2.0*rsw); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor*rsw*rsw*(3.0 - 2.0*rsw); } else { forcecoul += prefactor; if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; } } } else { union_int_float_t rsq_lookup; rsq_lookup.f = rsq; itable = rsq_lookup.i & ncoulmask; itable >>= ncoulshiftbits; fraction = (rsq_lookup.f - rtable[itable]) * drtable[itable]; table = ftable[itable] + fraction*dftable[itable]; forcecoul = qtmp*q[j] * table; if (factor_coul < 1.0) { table = ctable[itable] + fraction*dctable[itable]; prefactor = qtmp*q[j] * table; forcecoul -= (1.0-factor_coul)*prefactor; } } } else forcecoul = 0.0; if (rsq < cut_ljsq && rsq > cut_in_off_sq) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) * denom_lj_inv; switch2 = 12.0*rsq * (cut_ljsq-rsq) * (rsq-cut_lj_innersq) * denom_lj_inv; philj = r6inv * (lj3[itype][jtype]*r6inv - lj4[itype][jtype]); forcelj = forcelj*switch1 + philj*switch2; } if (rsq < cut_in_on_sq) { rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; forcelj *= rsw*rsw*(3.0 - 2.0*rsw); } } else forcelj = 0.0; fpair = (forcecoul + forcelj) * r2inv; 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; } if (eflag) { if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { ecoul = prefactor*egamma; if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; } else { table = etable[itable] + fraction*detable[itable]; ecoul = qtmp*q[j] * table; if (factor_coul < 1.0) { table = ptable[itable] + fraction*dptable[itable]; prefactor = qtmp*q[j] * table; ecoul -= (1.0-factor_coul)*prefactor; } } } else ecoul = 0.0; if (rsq < cut_ljsq) { r6inv = r2inv*r2inv*r2inv; evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) * denom_lj_inv; evdwl *= switch1; } evdwl *= factor_lj; } else evdwl = 0.0; } if (vflag) { if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { forcecoul = prefactor * fgamma; if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; } else { table = vtable[itable] + fraction*dvtable[itable]; forcecoul = qtmp*q[j] * table; if (factor_coul < 1.0) { table = ptable[itable] + fraction*dptable[itable]; prefactor = qtmp*q[j] * table; forcecoul -= (1.0-factor_coul)*prefactor; } } } else forcecoul = 0.0; if (rsq <= cut_in_off_sq) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) * denom_lj_inv; switch2 = 12.0*rsq * (cut_ljsq-rsq) * (rsq-cut_lj_innersq) * denom_lj_inv; philj = r6inv * (lj3[itype][jtype]*r6inv - lj4[itype][jtype]); forcelj = forcelj*switch1 + philj*switch2; } } else if (rsq <= cut_in_on_sq) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) * denom_lj_inv; switch2 = 12.0*rsq * (cut_ljsq-rsq) * (rsq-cut_lj_innersq) * denom_lj_inv; philj = r6inv * (lj3[itype][jtype]*r6inv - lj4[itype][jtype]); forcelj = forcelj*switch1 + philj*switch2; } } fpair = (forcecoul + factor_lj*forcelj) * r2inv; } if (evflag) ev_tally(i,j,nlocal,newton_pair, evdwl,ecoul,fpair,delx,dely,delz); } } } } /* ---------------------------------------------------------------------- */ double PairLJCharmmCoulMSM::single(int i, int j, int itype, int jtype, double rsq, double factor_coul, double factor_lj, double &fforce) { double r2inv,r6inv,r,egamma,fgamma,prefactor; double switch1,switch2,fraction,table,forcecoul,forcelj,phicoul,philj; int itable; r2inv = 1.0/rsq; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { r = sqrt(rsq); egamma = 1.0 - (r/cut_coul)*force->kspace->gamma(r/cut_coul); fgamma = 1.0 + (rsq/cut_coulsq)*force->kspace->dgamma(r/cut_coul); prefactor = force->qqrd2e * atom->q[i]*atom->q[j]/r; forcecoul = prefactor * fgamma; if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; } else { union_int_float_t rsq_lookup; rsq_lookup.f = rsq; itable = rsq_lookup.i & ncoulmask; itable >>= ncoulshiftbits; fraction = (rsq_lookup.f - rtable[itable]) * drtable[itable]; table = ftable[itable] + fraction*dftable[itable]; forcecoul = atom->q[i]*atom->q[j] * table; if (factor_coul < 1.0) { table = ctable[itable] + fraction*dctable[itable]; prefactor = atom->q[i]*atom->q[j] * table; forcecoul -= (1.0-factor_coul)*prefactor; } } } else forcecoul = 0.0; if (rsq < cut_ljsq) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) * denom_lj_inv; switch2 = 12.0*rsq * (cut_ljsq-rsq) * (rsq-cut_lj_innersq) * denom_lj_inv; philj = r6inv * (lj3[itype][jtype]*r6inv - lj4[itype][jtype]); forcelj = forcelj*switch1 + philj*switch2; } } else forcelj = 0.0; fforce = (forcecoul + factor_lj*forcelj) * r2inv; double eng = 0.0; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) phicoul = prefactor*egamma; else { table = etable[itable] + fraction*detable[itable]; phicoul = atom->q[i]*atom->q[j] * table; } if (factor_coul < 1.0) phicoul -= (1.0-factor_coul)*prefactor; eng += phicoul; } if (rsq < cut_ljsq) { philj = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) * denom_lj_inv; philj *= switch1; } eng += factor_lj*philj; } return eng; } /* ---------------------------------------------------------------------- */ void *PairLJCharmmCoulMSM::extract(const char *str, int &dim) { dim = 2; if (strcmp(str,"lj14_1") == 0) return (void *) lj14_1; if (strcmp(str,"lj14_2") == 0) return (void *) lj14_2; if (strcmp(str,"lj14_3") == 0) return (void *) lj14_3; if (strcmp(str,"lj14_4") == 0) return (void *) lj14_4; dim = 0; if (strcmp(str,"implicit") == 0) return (void *) &implicit; if (strcmp(str,"cut_coul") == 0) return (void *) &cut_coul; return NULL; } diff --git a/src/KSPACE/pair_lj_charmmfsw_coul_long.cpp b/src/KSPACE/pair_lj_charmmfsw_coul_long.cpp index 30d8ab64b..859f42176 100644 --- a/src/KSPACE/pair_lj_charmmfsw_coul_long.cpp +++ b/src/KSPACE/pair_lj_charmmfsw_coul_long.cpp @@ -1,1097 +1,1084 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- Contributing author: Paul Crozier (SNL) The lj-fsw sections (force-switched) were provided by Robert Meissner and Lucio Colombi Ciacchi of Bremen University, Bremen, Germany, with additional assistance from Robert A. Latour, Clemson University ------------------------------------------------------------------------- */ #include #include #include #include #include "pair_lj_charmmfsw_coul_long.h" #include "atom.h" #include "update.h" #include "comm.h" #include "force.h" #include "kspace.h" #include "update.h" #include "integrate.h" #include "respa.h" #include "neighbor.h" #include "neigh_list.h" #include "neigh_request.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; #define EWALD_F 1.12837917 #define EWALD_P 0.3275911 #define A1 0.254829592 #define A2 -0.284496736 #define A3 1.421413741 #define A4 -1.453152027 #define A5 1.061405429 /* ---------------------------------------------------------------------- */ PairLJCharmmfswCoulLong::PairLJCharmmfswCoulLong(LAMMPS *lmp) : Pair(lmp) { respa_enable = 1; ewaldflag = pppmflag = 1; ftable = NULL; implicit = 0; mix_flag = ARITHMETIC; writedata = 1; // short-range/long-range flag accessed by DihedralCharmmfsw dihedflag = 1; // switch qqr2e from LAMMPS value to CHARMM value if (strcmp(update->unit_style,"real") == 0) { if ((comm->me == 0) && (force->qqr2e != force->qqr2e_charmm_real)) error->message(FLERR,"Switching to CHARMM coulomb energy" " conversion constant"); force->qqr2e = force->qqr2e_charmm_real; } } /* ---------------------------------------------------------------------- */ PairLJCharmmfswCoulLong::~PairLJCharmmfswCoulLong() { if (!copymode) { if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(epsilon); memory->destroy(sigma); memory->destroy(eps14); memory->destroy(sigma14); memory->destroy(lj1); memory->destroy(lj2); memory->destroy(lj3); memory->destroy(lj4); memory->destroy(lj14_1); memory->destroy(lj14_2); memory->destroy(lj14_3); memory->destroy(lj14_4); } if (ftable) free_tables(); } // switch qqr2e back from CHARMM value to LAMMPS value if (update && strcmp(update->unit_style,"real") == 0) { if ((comm->me == 0) && (force->qqr2e == force->qqr2e_charmm_real)) error->message(FLERR,"Restoring original LAMMPS coulomb energy" " conversion constant"); force->qqr2e = force->qqr2e_lammps_real; } } /* ---------------------------------------------------------------------- */ void PairLJCharmmfswCoulLong::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype,itable; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,evdwl12,evdwl6,ecoul,fpair; double fraction,table; double r,rinv,r2inv,r3inv,r6inv,rsq,forcecoul,forcelj,factor_coul,factor_lj; double grij,expm2,prefactor,t,erfc; double switch1; int *ilist,*jlist,*numneigh,**firstneigh; evdwl = ecoul = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; inum = list->inum; ilist = list->ilist; numneigh = list->numneigh; firstneigh = list->firstneigh; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq < cut_bothsq) { r2inv = 1.0/rsq; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { r = sqrt(rsq); grij = g_ewald * r; expm2 = exp(-grij*grij); t = 1.0 / (1.0 + EWALD_P*grij); erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2; prefactor = qqrd2e * qtmp*q[j]/r; forcecoul = prefactor * (erfc + EWALD_F*grij*expm2); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; } else { union_int_float_t rsq_lookup; rsq_lookup.f = rsq; itable = rsq_lookup.i & ncoulmask; itable >>= ncoulshiftbits; fraction = (rsq_lookup.f - rtable[itable]) * drtable[itable]; table = ftable[itable] + fraction*dftable[itable]; forcecoul = qtmp*q[j] * table; if (factor_coul < 1.0) { table = ctable[itable] + fraction*dctable[itable]; prefactor = qtmp*q[j] * table; forcecoul -= (1.0-factor_coul)*prefactor; } } } else forcecoul = 0.0; if (rsq < cut_ljsq) { r6inv = r2inv*r2inv*r2inv; jtype = type[j]; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) / denom_lj; forcelj = forcelj*switch1; } } else forcelj = 0.0; fpair = (forcecoul + factor_lj*forcelj) * r2inv; 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; } if (eflag) { if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) ecoul = prefactor*erfc; else { table = etable[itable] + fraction*detable[itable]; ecoul = qtmp*q[j] * table; } if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; } else ecoul = 0.0; if (rsq < cut_ljsq) { if (rsq > cut_lj_innersq) { r = sqrt(rsq); rinv = 1.0/r; r3inv = rinv*rinv*rinv; evdwl12 = lj3[itype][jtype]*cut_lj6*denom_lj12 * (r6inv - cut_lj6inv)*(r6inv - cut_lj6inv); evdwl6 = -lj4[itype][jtype]*cut_lj3*denom_lj6 * (r3inv - cut_lj3inv)*(r3inv - cut_lj3inv);; evdwl = evdwl12 + evdwl6; } else { evdwl12 = r6inv*lj3[itype][jtype]*r6inv - lj3[itype][jtype]*cut_lj_inner6inv*cut_lj6inv; evdwl6 = -lj4[itype][jtype]*r6inv + lj4[itype][jtype]*cut_lj_inner3inv*cut_lj3inv; evdwl = evdwl12 + evdwl6; } evdwl *= factor_lj; } else evdwl = 0.0; } if (evflag) ev_tally(i,j,nlocal,newton_pair, evdwl,ecoul,fpair,delx,dely,delz); } } } if (vflag_fdotr) virial_fdotr_compute(); } /* ---------------------------------------------------------------------- */ void PairLJCharmmfswCoulLong::compute_inner() { int i,j,ii,jj,inum,jnum,itype,jtype; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fpair; double rsq,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; double rsw; int *ilist,*jlist,*numneigh,**firstneigh; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; - inum = listinner->inum; - ilist = listinner->ilist; - numneigh = listinner->numneigh; - firstneigh = listinner->firstneigh; + inum = list->inum_inner; + ilist = list->ilist_inner; + numneigh = list->numneigh_inner; + firstneigh = list->firstneigh_inner; double cut_out_on = cut_respa[0]; double cut_out_off = cut_respa[1]; double cut_out_diff = cut_out_off - cut_out_on; double cut_out_on_sq = cut_out_on*cut_out_on; double cut_out_off_sq = cut_out_off*cut_out_off; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq < cut_out_off_sq) { r2inv = 1.0/rsq; forcecoul = qqrd2e * qtmp*q[j]*sqrt(r2inv); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*forcecoul; r6inv = r2inv*r2inv*r2inv; jtype = type[j]; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); fpair = (forcecoul + factor_lj*forcelj) * r2inv; if (rsq > cut_out_on_sq) { rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; fpair *= 1.0 + rsw*rsw*(2.0*rsw-3.0); } 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; } } } } } /* ---------------------------------------------------------------------- */ void PairLJCharmmfswCoulLong::compute_middle() { int i,j,ii,jj,inum,jnum,itype,jtype; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fpair; double rsq,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; double switch1; double rsw; int *ilist,*jlist,*numneigh,**firstneigh; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; - inum = listmiddle->inum; - ilist = listmiddle->ilist; - numneigh = listmiddle->numneigh; - firstneigh = listmiddle->firstneigh; + inum = list->inum_middle; + ilist = list->ilist_middle; + numneigh = list->numneigh_middle; + firstneigh = list->firstneigh_middle; double cut_in_off = cut_respa[0]; double cut_in_on = cut_respa[1]; double cut_out_on = cut_respa[2]; double cut_out_off = cut_respa[3]; double cut_in_diff = cut_in_on - cut_in_off; double cut_out_diff = cut_out_off - cut_out_on; double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; double cut_out_on_sq = cut_out_on*cut_out_on; double cut_out_off_sq = cut_out_off*cut_out_off; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq < cut_out_off_sq && rsq > cut_in_off_sq) { r2inv = 1.0/rsq; forcecoul = qqrd2e * qtmp*q[j]*sqrt(r2inv); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*forcecoul; r6inv = r2inv*r2inv*r2inv; jtype = type[j]; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) / denom_lj; forcelj = forcelj*switch1; } fpair = (forcecoul + factor_lj*forcelj) * r2inv; if (rsq < cut_in_on_sq) { rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; fpair *= rsw*rsw*(3.0 - 2.0*rsw); } if (rsq > cut_out_on_sq) { rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; fpair *= 1.0 + rsw*rsw*(2.0*rsw - 3.0); } 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; } } } } } /* ---------------------------------------------------------------------- */ void PairLJCharmmfswCoulLong::compute_outer(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype,itable; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,evdwl6,evdwl12,ecoul,fpair; double fraction,table; double r,rinv,r2inv,r3inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; double grij,expm2,prefactor,t,erfc; double switch1; double rsw; int *ilist,*jlist,*numneigh,**firstneigh; double rsq; evdwl = ecoul = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; - inum = listouter->inum; - ilist = listouter->ilist; - numneigh = listouter->numneigh; - firstneigh = listouter->firstneigh; + inum = list->inum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; double cut_in_off = cut_respa[2]; double cut_in_on = cut_respa[3]; double cut_in_diff = cut_in_on - cut_in_off; double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; if (rsq < cut_bothsq) { r2inv = 1.0/rsq; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { r = sqrt(rsq); grij = g_ewald * r; expm2 = exp(-grij*grij); t = 1.0 / (1.0 + EWALD_P*grij); erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2; prefactor = qqrd2e * qtmp*q[j]/r; forcecoul = prefactor * (erfc + EWALD_F*grij*expm2 - 1.0); if (rsq > cut_in_off_sq) { if (rsq < cut_in_on_sq) { rsw = (r - cut_in_off)/cut_in_diff; forcecoul += prefactor*rsw*rsw*(3.0 - 2.0*rsw); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor*rsw*rsw*(3.0 - 2.0*rsw); } else { forcecoul += prefactor; if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; } } } else { union_int_float_t rsq_lookup; rsq_lookup.f = rsq; itable = rsq_lookup.i & ncoulmask; itable >>= ncoulshiftbits; fraction = (rsq_lookup.f - rtable[itable]) * drtable[itable]; table = ftable[itable] + fraction*dftable[itable]; forcecoul = qtmp*q[j] * table; if (factor_coul < 1.0) { table = ctable[itable] + fraction*dctable[itable]; prefactor = qtmp*q[j] * table; forcecoul -= (1.0-factor_coul)*prefactor; } } } else forcecoul = 0.0; if (rsq < cut_ljsq && rsq > cut_in_off_sq) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) / denom_lj; forcelj = forcelj*switch1; } if (rsq < cut_in_on_sq) { rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; forcelj *= rsw*rsw*(3.0 - 2.0*rsw); } } else forcelj = 0.0; fpair = (forcecoul + forcelj) * r2inv; 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; } if (eflag) { if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { ecoul = prefactor*erfc; if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; } else { table = etable[itable] + fraction*detable[itable]; ecoul = qtmp*q[j] * table; if (factor_coul < 1.0) { table = ptable[itable] + fraction*dptable[itable]; prefactor = qtmp*q[j] * table; ecoul -= (1.0-factor_coul)*prefactor; } } } else ecoul = 0.0; if (rsq < cut_ljsq) { r6inv = r2inv*r2inv*r2inv; evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]); if (rsq > cut_lj_innersq) { rinv = 1.0/r; r3inv = rinv*rinv*rinv; evdwl12 = lj3[itype][jtype]*cut_lj6*denom_lj12 * (r6inv - cut_lj6inv)*(r6inv - cut_lj6inv); evdwl6 = -lj4[itype][jtype]*cut_lj3*denom_lj6 * (r3inv - cut_lj3inv)*(r3inv - cut_lj3inv);; evdwl = evdwl12 + evdwl6; } else { evdwl12 = r6inv*lj3[itype][jtype]*r6inv - lj3[itype][jtype]*cut_lj_inner6inv*cut_lj6inv; evdwl6 = -lj4[itype][jtype]*r6inv + lj4[itype][jtype]*cut_lj_inner3inv*cut_lj3inv; evdwl = evdwl12 + evdwl6; } evdwl *= factor_lj; } else evdwl = 0.0; } if (vflag) { if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { forcecoul = prefactor * (erfc + EWALD_F*grij*expm2); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; } else { table = vtable[itable] + fraction*dvtable[itable]; forcecoul = qtmp*q[j] * table; if (factor_coul < 1.0) { table = ptable[itable] + fraction*dptable[itable]; prefactor = qtmp*q[j] * table; forcecoul -= (1.0-factor_coul)*prefactor; } } } else forcecoul = 0.0; if (rsq <= cut_in_off_sq) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) / denom_lj; forcelj = forcelj*switch1; } } else if (rsq <= cut_in_on_sq) { forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) / denom_lj; forcelj = forcelj*switch1; } } fpair = (forcecoul + factor_lj*forcelj) * r2inv; } if (evflag) ev_tally(i,j,nlocal,newton_pair, evdwl,ecoul,fpair,delx,dely,delz); } } } } /* ---------------------------------------------------------------------- allocate all arrays ------------------------------------------------------------------------- */ void PairLJCharmmfswCoulLong::allocate() { allocated = 1; int n = atom->ntypes; 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(cutsq,n+1,n+1,"pair:cutsq"); memory->create(epsilon,n+1,n+1,"pair:epsilon"); memory->create(sigma,n+1,n+1,"pair:sigma"); memory->create(eps14,n+1,n+1,"pair:eps14"); memory->create(sigma14,n+1,n+1,"pair:sigma14"); memory->create(lj1,n+1,n+1,"pair:lj1"); memory->create(lj2,n+1,n+1,"pair:lj2"); memory->create(lj3,n+1,n+1,"pair:lj3"); memory->create(lj4,n+1,n+1,"pair:lj4"); memory->create(lj14_1,n+1,n+1,"pair:lj14_1"); memory->create(lj14_2,n+1,n+1,"pair:lj14_2"); memory->create(lj14_3,n+1,n+1,"pair:lj14_3"); memory->create(lj14_4,n+1,n+1,"pair:lj14_4"); } /* ---------------------------------------------------------------------- global settings unlike other pair styles, there are no individual pair settings that these override ------------------------------------------------------------------------- */ void PairLJCharmmfswCoulLong::settings(int narg, char **arg) { if (narg != 2 && narg != 3) error->all(FLERR,"Illegal pair_style command"); cut_lj_inner = force->numeric(FLERR,arg[0]); cut_lj = force->numeric(FLERR,arg[1]); if (narg == 2) cut_coul = cut_lj; else cut_coul = force->numeric(FLERR,arg[2]); } /* ---------------------------------------------------------------------- set coeffs for one or more type pairs ------------------------------------------------------------------------- */ void PairLJCharmmfswCoulLong::coeff(int narg, char **arg) { if (narg != 4 && narg != 6) error->all(FLERR,"Illegal pair_coeff command"); if (!allocated) allocate(); int ilo,ihi,jlo,jhi; force->bounds(FLERR,arg[0],atom->ntypes,ilo,ihi); force->bounds(FLERR,arg[1],atom->ntypes,jlo,jhi); double epsilon_one = force->numeric(FLERR,arg[2]); double sigma_one = force->numeric(FLERR,arg[3]); double eps14_one = epsilon_one; double sigma14_one = sigma_one; if (narg == 6) { eps14_one = force->numeric(FLERR,arg[4]); sigma14_one = force->numeric(FLERR,arg[5]); } int count = 0; for (int i = ilo; i <= ihi; i++) { for (int j = MAX(jlo,i); j <= jhi; j++) { epsilon[i][j] = epsilon_one; sigma[i][j] = sigma_one; eps14[i][j] = eps14_one; sigma14[i][j] = sigma14_one; setflag[i][j] = 1; count++; } } if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- init specific to this pair style ------------------------------------------------------------------------- */ void PairLJCharmmfswCoulLong::init_style() { if (!atom->q_flag) error->all(FLERR, "Pair style lj/charmmfsw/coul/long requires atom attribute q"); // request regular or rRESPA neighbor lists int irequest; if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; if (respa == 0) irequest = neighbor->request(this,instance_me); else if (respa == 1) { irequest = neighbor->request(this,instance_me); neighbor->requests[irequest]->id = 1; neighbor->requests[irequest]->half = 0; neighbor->requests[irequest]->respainner = 1; irequest = neighbor->request(this,instance_me); neighbor->requests[irequest]->id = 3; neighbor->requests[irequest]->half = 0; neighbor->requests[irequest]->respaouter = 1; } else { irequest = neighbor->request(this,instance_me); neighbor->requests[irequest]->id = 1; neighbor->requests[irequest]->half = 0; neighbor->requests[irequest]->respainner = 1; irequest = neighbor->request(this,instance_me); neighbor->requests[irequest]->id = 2; neighbor->requests[irequest]->half = 0; neighbor->requests[irequest]->respamiddle = 1; irequest = neighbor->request(this,instance_me); neighbor->requests[irequest]->id = 3; neighbor->requests[irequest]->half = 0; neighbor->requests[irequest]->respaouter = 1; } } else irequest = neighbor->request(this,instance_me); // require cut_lj_inner < cut_lj if (cut_lj_inner >= cut_lj) error->all(FLERR,"Pair inner cutoff >= Pair outer cutoff"); cut_lj_innersq = cut_lj_inner * cut_lj_inner; cut_ljsq = cut_lj * cut_lj; cut_ljinv = 1.0/cut_lj; cut_lj_innerinv = 1.0/cut_lj_inner; cut_lj3 = cut_lj * cut_lj * cut_lj; cut_lj3inv = cut_ljinv * cut_ljinv * cut_ljinv; cut_lj_inner3inv = cut_lj_innerinv * cut_lj_innerinv * cut_lj_innerinv; cut_lj_inner3 = cut_lj_inner * cut_lj_inner * cut_lj_inner; cut_lj6 = cut_ljsq * cut_ljsq * cut_ljsq; cut_lj6inv = cut_lj3inv * cut_lj3inv; cut_lj_inner6inv = cut_lj_inner3inv * cut_lj_inner3inv; cut_lj_inner6 = cut_lj_innersq * cut_lj_innersq * cut_lj_innersq; cut_coulsq = cut_coul * cut_coul; cut_bothsq = MAX(cut_ljsq,cut_coulsq); denom_lj = (cut_ljsq-cut_lj_innersq) * (cut_ljsq-cut_lj_innersq) * (cut_ljsq-cut_lj_innersq); denom_lj12 = 1.0/(cut_lj6 - cut_lj_inner6); denom_lj6 = 1.0/(cut_lj3 - cut_lj_inner3); // set & error check interior rRESPA cutoffs if (strstr(update->integrate_style,"respa") && ((Respa *) update->integrate)->level_inner >= 0) { cut_respa = ((Respa *) update->integrate)->cutoff; if (MIN(cut_lj,cut_coul) < cut_respa[3]) error->all(FLERR,"Pair cutoff < Respa interior cutoff"); if (cut_lj_inner < cut_respa[1]) error->all(FLERR,"Pair inner cutoff < Respa interior cutoff"); } else cut_respa = NULL; // insure use of KSpace long-range solver, set g_ewald if (force->kspace == NULL) error->all(FLERR,"Pair style requires a KSpace style"); g_ewald = force->kspace->g_ewald; // setup force tables if (ncoultablebits) init_tables(cut_coul,cut_respa); } -/* ---------------------------------------------------------------------- - neighbor callback to inform pair style of neighbor list to use - regular or rRESPA -------------------------------------------------------------------------- */ - -void PairLJCharmmfswCoulLong::init_list(int id, NeighList *ptr) -{ - if (id == 0) list = ptr; - else if (id == 1) listinner = ptr; - else if (id == 2) listmiddle = ptr; - else if (id == 3) listouter = ptr; -} - /* ---------------------------------------------------------------------- init for one type pair i,j and corresponding j,i ------------------------------------------------------------------------- */ double PairLJCharmmfswCoulLong::init_one(int i, int j) { if (setflag[i][j] == 0) { epsilon[i][j] = mix_energy(epsilon[i][i],epsilon[j][j], sigma[i][i],sigma[j][j]); sigma[i][j] = mix_distance(sigma[i][i],sigma[j][j]); eps14[i][j] = mix_energy(eps14[i][i],eps14[j][j], sigma14[i][i],sigma14[j][j]); sigma14[i][j] = mix_distance(sigma14[i][i],sigma14[j][j]); } double cut = MAX(cut_lj,cut_coul); lj1[i][j] = 48.0 * epsilon[i][j] * pow(sigma[i][j],12.0); lj2[i][j] = 24.0 * epsilon[i][j] * pow(sigma[i][j],6.0); lj3[i][j] = 4.0 * epsilon[i][j] * pow(sigma[i][j],12.0); lj4[i][j] = 4.0 * epsilon[i][j] * pow(sigma[i][j],6.0); lj14_1[i][j] = 48.0 * eps14[i][j] * pow(sigma14[i][j],12.0); lj14_2[i][j] = 24.0 * eps14[i][j] * pow(sigma14[i][j],6.0); lj14_3[i][j] = 4.0 * eps14[i][j] * pow(sigma14[i][j],12.0); lj14_4[i][j] = 4.0 * eps14[i][j] * pow(sigma14[i][j],6.0); lj1[j][i] = lj1[i][j]; lj2[j][i] = lj2[i][j]; lj3[j][i] = lj3[i][j]; lj4[j][i] = lj4[i][j]; lj14_1[j][i] = lj14_1[i][j]; lj14_2[j][i] = lj14_2[i][j]; lj14_3[j][i] = lj14_3[i][j]; lj14_4[j][i] = lj14_4[i][j]; return cut; } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairLJCharmmfswCoulLong::write_restart(FILE *fp) { write_restart_settings(fp); int i,j; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { fwrite(&setflag[i][j],sizeof(int),1,fp); if (setflag[i][j]) { fwrite(&epsilon[i][j],sizeof(double),1,fp); fwrite(&sigma[i][j],sizeof(double),1,fp); fwrite(&eps14[i][j],sizeof(double),1,fp); fwrite(&sigma14[i][j],sizeof(double),1,fp); } } } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairLJCharmmfswCoulLong::read_restart(FILE *fp) { read_restart_settings(fp); allocate(); int i,j; int me = comm->me; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp); MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world); if (setflag[i][j]) { if (me == 0) { fread(&epsilon[i][j],sizeof(double),1,fp); fread(&sigma[i][j],sizeof(double),1,fp); fread(&eps14[i][j],sizeof(double),1,fp); fread(&sigma14[i][j],sizeof(double),1,fp); } MPI_Bcast(&epsilon[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&sigma[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&eps14[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&sigma14[i][j],1,MPI_DOUBLE,0,world); } } } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairLJCharmmfswCoulLong::write_restart_settings(FILE *fp) { fwrite(&cut_lj_inner,sizeof(double),1,fp); fwrite(&cut_lj,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(&ncoultablebits,sizeof(int),1,fp); fwrite(&tabinner,sizeof(double),1,fp); } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairLJCharmmfswCoulLong::read_restart_settings(FILE *fp) { if (comm->me == 0) { fread(&cut_lj_inner,sizeof(double),1,fp); fread(&cut_lj,sizeof(double),1,fp); fread(&cut_coul,sizeof(double),1,fp); fread(&offset_flag,sizeof(int),1,fp); fread(&mix_flag,sizeof(int),1,fp); fread(&ncoultablebits,sizeof(int),1,fp); fread(&tabinner,sizeof(double),1,fp); } MPI_Bcast(&cut_lj_inner,1,MPI_DOUBLE,0,world); MPI_Bcast(&cut_lj,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(&ncoultablebits,1,MPI_INT,0,world); MPI_Bcast(&tabinner,1,MPI_DOUBLE,0,world); } /* ---------------------------------------------------------------------- proc 0 writes to data file ------------------------------------------------------------------------- */ void PairLJCharmmfswCoulLong::write_data(FILE *fp) { for (int i = 1; i <= atom->ntypes; i++) fprintf(fp,"%d %g %g %g %g\n", i,epsilon[i][i],sigma[i][i],eps14[i][i],sigma14[i][i]); } /* ---------------------------------------------------------------------- proc 0 writes all pairs to data file ------------------------------------------------------------------------- */ void PairLJCharmmfswCoulLong::write_data_all(FILE *fp) { for (int i = 1; i <= atom->ntypes; i++) for (int j = i; j <= atom->ntypes; j++) fprintf(fp,"%d %d %g %g %g %g\n",i,j, epsilon[i][j],sigma[i][j],eps14[i][j],sigma14[i][j]); } /* ---------------------------------------------------------------------- */ double PairLJCharmmfswCoulLong::single(int i, int j, int itype, int jtype, double rsq, double factor_coul, double factor_lj, double &fforce) { double r,rinv,r2inv,r3inv,r6inv,grij,expm2,t,erfc,prefactor; double switch1,fraction,table,forcecoul,forcelj,phicoul,philj,philj12,philj6; int itable; r = sqrt(rsq); rinv = 1.0/r; r2inv = 1.0/rsq; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { r = sqrt(rsq); grij = g_ewald * r; expm2 = exp(-grij*grij); t = 1.0 / (1.0 + EWALD_P*grij); erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2; prefactor = force->qqrd2e * atom->q[i]*atom->q[j]/r; forcecoul = prefactor * (erfc + EWALD_F*grij*expm2); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; } else { union_int_float_t rsq_lookup; rsq_lookup.f = rsq; itable = rsq_lookup.i & ncoulmask; itable >>= ncoulshiftbits; fraction = (rsq_lookup.f - rtable[itable]) * drtable[itable]; table = ftable[itable] + fraction*dftable[itable]; forcecoul = atom->q[i]*atom->q[j] * table; if (factor_coul < 1.0) { table = ctable[itable] + fraction*dctable[itable]; prefactor = atom->q[i]*atom->q[j] * table; forcecoul -= (1.0-factor_coul)*prefactor; } } } else forcecoul = 0.0; if (rsq < cut_ljsq) { r3inv = rinv*rinv*rinv; r6inv = r3inv*r3inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) / denom_lj; forcelj = forcelj*switch1; } } else forcelj = 0.0; fforce = (forcecoul + factor_lj*forcelj) * r2inv; double eng = 0.0; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) phicoul = prefactor*erfc; else { table = etable[itable] + fraction*detable[itable]; phicoul = atom->q[i]*atom->q[j] * table; } if (factor_coul < 1.0) phicoul -= (1.0-factor_coul)*prefactor; eng += phicoul; } if (rsq < cut_ljsq) { if (rsq > cut_lj_innersq) { philj12 = lj3[itype][jtype]*cut_lj6*denom_lj12 * (r6inv - cut_lj6inv)*(r6inv - cut_lj6inv); philj6 = -lj4[itype][jtype]*cut_lj3*denom_lj6 * (r3inv - cut_lj3inv)*(r3inv - cut_lj3inv);; philj = philj12 + philj6; } else { philj12 = r6inv*lj3[itype][jtype]*r6inv - lj3[itype][jtype]*cut_lj_inner6inv*cut_lj6inv; philj6 = -lj4[itype][jtype]*r6inv + lj4[itype][jtype]*cut_lj_inner3inv*cut_lj3inv; philj = philj12 + philj6; } eng += factor_lj*philj; } return eng; } /* ---------------------------------------------------------------------- */ void *PairLJCharmmfswCoulLong::extract(const char *str, int &dim) { dim = 2; if (strcmp(str,"lj14_1") == 0) return (void *) lj14_1; if (strcmp(str,"lj14_2") == 0) return (void *) lj14_2; if (strcmp(str,"lj14_3") == 0) return (void *) lj14_3; if (strcmp(str,"lj14_4") == 0) return (void *) lj14_4; dim = 0; if (strcmp(str,"implicit") == 0) return (void *) &implicit; // info extracted by dihedral_charmmfsw if (strcmp(str,"cut_coul") == 0) return (void *) &cut_coul; if (strcmp(str,"cut_lj_inner") == 0) return (void *) &cut_lj_inner; if (strcmp(str,"cut_lj") == 0) return (void *) &cut_lj; if (strcmp(str,"dihedflag") == 0) return (void *) &dihedflag; return NULL; } diff --git a/src/KSPACE/pair_lj_charmmfsw_coul_long.h b/src/KSPACE/pair_lj_charmmfsw_coul_long.h index 650a908e4..135b82ea7 100644 --- a/src/KSPACE/pair_lj_charmmfsw_coul_long.h +++ b/src/KSPACE/pair_lj_charmmfsw_coul_long.h @@ -1,110 +1,109 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #ifdef PAIR_CLASS PairStyle(lj/charmmfsw/coul/long,PairLJCharmmfswCoulLong) #else #ifndef LMP_PAIR_LJ_CHARMMFSW_COUL_LONG_H #define LMP_PAIR_LJ_CHARMMFSW_COUL_LONG_H #include "pair.h" namespace LAMMPS_NS { class PairLJCharmmfswCoulLong : public Pair { public: PairLJCharmmfswCoulLong(class LAMMPS *); virtual ~PairLJCharmmfswCoulLong(); virtual void compute(int, int); virtual void settings(int, char **); void coeff(int, char **); virtual void init_style(); - void init_list(int, class NeighList *); virtual double init_one(int, int); void write_restart(FILE *); void read_restart(FILE *); void write_restart_settings(FILE *); void read_restart_settings(FILE *); void write_data(FILE *); void write_data_all(FILE *); virtual double single(int, int, int, int, double, double, double, double &); void compute_inner(); void compute_middle(); virtual void compute_outer(int, int); virtual void *extract(const char *, int &); protected: int implicit; int dihedflag; double cut_lj_inner,cut_lj,cut_ljinv,cut_lj_innerinv; double cut_lj_innersq,cut_ljsq; double cut_lj3inv,cut_lj_inner3inv,cut_lj3,cut_lj_inner3; double cut_lj6inv,cut_lj_inner6inv,cut_lj6,cut_lj_inner6; double cut_coul,cut_coulsq; double cut_bothsq; double denom_lj,denom_lj12,denom_lj6; double **epsilon,**sigma,**eps14,**sigma14; double **lj1,**lj2,**lj3,**lj4,**offset; double **lj14_1,**lj14_2,**lj14_3,**lj14_4; double *cut_respa; double g_ewald; virtual void allocate(); }; } #endif #endif /* ERROR/WARNING messages: E: Illegal ... command Self-explanatory. Check the input script syntax and compare to the documentation for the command. You can use -echo screen as a command-line option when running LAMMPS to see the offending line. E: Incorrect args for pair coefficients Self-explanatory. Check the input script or data file. E: Pair style lj/charmmfsw/coul/long requires atom attribute q The atom style defined does not have these attributes. E: Pair inner cutoff >= Pair outer cutoff The specified cutoffs for the pair style are inconsistent. E: Pair cutoff < Respa interior cutoff One or more pairwise cutoffs are too short to use with the specified rRESPA cutoffs. E: Pair inner cutoff < Respa interior cutoff One or more pairwise cutoffs are too short to use with the specified rRESPA cutoffs. E: Pair style requires a KSpace style No kspace style is defined. */ diff --git a/src/KSPACE/pair_lj_cut_coul_long.cpp b/src/KSPACE/pair_lj_cut_coul_long.cpp index f8be9fdb7..3096df2b0 100644 --- a/src/KSPACE/pair_lj_cut_coul_long.cpp +++ b/src/KSPACE/pair_lj_cut_coul_long.cpp @@ -1,978 +1,952 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- Contributing author: Paul Crozier (SNL) ------------------------------------------------------------------------- */ #include #include #include #include #include "pair_lj_cut_coul_long.h" #include "atom.h" #include "comm.h" #include "force.h" #include "kspace.h" #include "update.h" #include "integrate.h" #include "respa.h" #include "neighbor.h" #include "neigh_list.h" #include "neigh_request.h" #include "math_const.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; using namespace MathConst; #define EWALD_F 1.12837917 #define EWALD_P 0.3275911 #define A1 0.254829592 #define A2 -0.284496736 #define A3 1.421413741 #define A4 -1.453152027 #define A5 1.061405429 /* ---------------------------------------------------------------------- */ PairLJCutCoulLong::PairLJCutCoulLong(LAMMPS *lmp) : Pair(lmp) { ewaldflag = pppmflag = 1; respa_enable = 1; writedata = 1; ftable = NULL; qdist = 0.0; } /* ---------------------------------------------------------------------- */ PairLJCutCoulLong::~PairLJCutCoulLong() { if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(cut_lj); memory->destroy(cut_ljsq); memory->destroy(epsilon); memory->destroy(sigma); memory->destroy(lj1); memory->destroy(lj2); memory->destroy(lj3); memory->destroy(lj4); memory->destroy(offset); } if (ftable) free_tables(); } /* ---------------------------------------------------------------------- */ void PairLJCutCoulLong::compute(int eflag, int vflag) { int i,ii,j,jj,inum,jnum,itype,jtype,itable; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair; double fraction,table; double r,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; double grij,expm2,prefactor,t,erfc; int *ilist,*jlist,*numneigh,**firstneigh; double rsq; evdwl = ecoul = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; inum = list->inum; ilist = list->ilist; numneigh = list->numneigh; firstneigh = list->firstneigh; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; if (rsq < cutsq[itype][jtype]) { r2inv = 1.0/rsq; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { r = sqrt(rsq); grij = g_ewald * r; expm2 = exp(-grij*grij); t = 1.0 / (1.0 + EWALD_P*grij); erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2; prefactor = qqrd2e * qtmp*q[j]/r; forcecoul = prefactor * (erfc + EWALD_F*grij*expm2); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; } else { union_int_float_t rsq_lookup; rsq_lookup.f = rsq; itable = rsq_lookup.i & ncoulmask; itable >>= ncoulshiftbits; fraction = (rsq_lookup.f - rtable[itable]) * drtable[itable]; table = ftable[itable] + fraction*dftable[itable]; forcecoul = qtmp*q[j] * table; if (factor_coul < 1.0) { table = ctable[itable] + fraction*dctable[itable]; prefactor = qtmp*q[j] * table; forcecoul -= (1.0-factor_coul)*prefactor; } } } else forcecoul = 0.0; if (rsq < cut_ljsq[itype][jtype]) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); } else forcelj = 0.0; fpair = (forcecoul + factor_lj*forcelj) * r2inv; 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; } if (eflag) { if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) ecoul = prefactor*erfc; else { table = etable[itable] + fraction*detable[itable]; ecoul = qtmp*q[j] * table; } if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; } else ecoul = 0.0; if (rsq < cut_ljsq[itype][jtype]) { evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - offset[itype][jtype]; evdwl *= factor_lj; } else evdwl = 0.0; } if (evflag) ev_tally(i,j,nlocal,newton_pair, evdwl,ecoul,fpair,delx,dely,delz); } } } if (vflag_fdotr) virial_fdotr_compute(); } /* ---------------------------------------------------------------------- */ void PairLJCutCoulLong::compute_inner() { int i,j,ii,jj,inum,jnum,itype,jtype; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fpair; double rsq,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; double rsw; int *ilist,*jlist,*numneigh,**firstneigh; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; - inum = listinner->inum; - ilist = listinner->ilist; - numneigh = listinner->numneigh; - firstneigh = listinner->firstneigh; + inum = list->inum_inner; + ilist = list->ilist_inner; + numneigh = list->numneigh_inner; + firstneigh = list->firstneigh_inner; double cut_out_on = cut_respa[0]; double cut_out_off = cut_respa[1]; double cut_out_diff = cut_out_off - cut_out_on; double cut_out_on_sq = cut_out_on*cut_out_on; double cut_out_off_sq = cut_out_off*cut_out_off; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq < cut_out_off_sq) { r2inv = 1.0/rsq; forcecoul = qqrd2e * qtmp*q[j]*sqrt(r2inv); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*forcecoul; jtype = type[j]; if (rsq < cut_ljsq[itype][jtype]) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); } else forcelj = 0.0; fpair = (forcecoul + factor_lj*forcelj) * r2inv; if (rsq > cut_out_on_sq) { rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; fpair *= 1.0 + rsw*rsw*(2.0*rsw-3.0); } 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; } } } } } /* ---------------------------------------------------------------------- */ void PairLJCutCoulLong::compute_middle() { int i,j,ii,jj,inum,jnum,itype,jtype; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fpair; double rsq,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; double rsw; int *ilist,*jlist,*numneigh,**firstneigh; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; - inum = listmiddle->inum; - ilist = listmiddle->ilist; - numneigh = listmiddle->numneigh; - firstneigh = listmiddle->firstneigh; + inum = list->inum_middle; + ilist = list->ilist_middle; + numneigh = list->numneigh_middle; + firstneigh = list->firstneigh_middle; double cut_in_off = cut_respa[0]; double cut_in_on = cut_respa[1]; double cut_out_on = cut_respa[2]; double cut_out_off = cut_respa[3]; double cut_in_diff = cut_in_on - cut_in_off; double cut_out_diff = cut_out_off - cut_out_on; double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; double cut_out_on_sq = cut_out_on*cut_out_on; double cut_out_off_sq = cut_out_off*cut_out_off; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq < cut_out_off_sq && rsq > cut_in_off_sq) { r2inv = 1.0/rsq; forcecoul = qqrd2e * qtmp*q[j]*sqrt(r2inv); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*forcecoul; jtype = type[j]; if (rsq < cut_ljsq[itype][jtype]) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); } else forcelj = 0.0; fpair = (forcecoul + factor_lj*forcelj) * r2inv; if (rsq < cut_in_on_sq) { rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; fpair *= rsw*rsw*(3.0 - 2.0*rsw); } if (rsq > cut_out_on_sq) { rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; fpair *= 1.0 + rsw*rsw*(2.0*rsw - 3.0); } 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; } } } } } /* ---------------------------------------------------------------------- */ void PairLJCutCoulLong::compute_outer(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype,itable; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair; double fraction,table; double r,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; double grij,expm2,prefactor,t,erfc; double rsw; int *ilist,*jlist,*numneigh,**firstneigh; double rsq; evdwl = ecoul = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; - inum = listouter->inum; - ilist = listouter->ilist; - numneigh = listouter->numneigh; - firstneigh = listouter->firstneigh; + inum = list->inum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; double cut_in_off = cut_respa[2]; double cut_in_on = cut_respa[3]; double cut_in_diff = cut_in_on - cut_in_off; double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; if (rsq < cutsq[itype][jtype]) { r2inv = 1.0/rsq; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { r = sqrt(rsq); grij = g_ewald * r; expm2 = exp(-grij*grij); t = 1.0 / (1.0 + EWALD_P*grij); erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2; prefactor = qqrd2e * qtmp*q[j]/r; forcecoul = prefactor * (erfc + EWALD_F*grij*expm2 - 1.0); if (rsq > cut_in_off_sq) { if (rsq < cut_in_on_sq) { rsw = (r - cut_in_off)/cut_in_diff; forcecoul += prefactor*rsw*rsw*(3.0 - 2.0*rsw); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor*rsw*rsw*(3.0 - 2.0*rsw); } else { forcecoul += prefactor; if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; } } } else { union_int_float_t rsq_lookup; rsq_lookup.f = rsq; itable = rsq_lookup.i & ncoulmask; itable >>= ncoulshiftbits; fraction = (rsq_lookup.f - rtable[itable]) * drtable[itable]; table = ftable[itable] + fraction*dftable[itable]; forcecoul = qtmp*q[j] * table; if (factor_coul < 1.0) { table = ctable[itable] + fraction*dctable[itable]; prefactor = qtmp*q[j] * table; forcecoul -= (1.0-factor_coul)*prefactor; } } } else forcecoul = 0.0; if (rsq < cut_ljsq[itype][jtype] && rsq > cut_in_off_sq) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); if (rsq < cut_in_on_sq) { rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; forcelj *= rsw*rsw*(3.0 - 2.0*rsw); } } else forcelj = 0.0; fpair = (forcecoul + forcelj) * r2inv; 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; } if (eflag) { if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { ecoul = prefactor*erfc; if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; } else { table = etable[itable] + fraction*detable[itable]; ecoul = qtmp*q[j] * table; if (factor_coul < 1.0) { table = ptable[itable] + fraction*dptable[itable]; prefactor = qtmp*q[j] * table; ecoul -= (1.0-factor_coul)*prefactor; } } } else ecoul = 0.0; if (rsq < cut_ljsq[itype][jtype]) { r6inv = r2inv*r2inv*r2inv; evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - offset[itype][jtype]; evdwl *= factor_lj; } else evdwl = 0.0; } if (vflag) { if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { forcecoul = prefactor * (erfc + EWALD_F*grij*expm2); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; } else { table = vtable[itable] + fraction*dvtable[itable]; forcecoul = qtmp*q[j] * table; if (factor_coul < 1.0) { table = ptable[itable] + fraction*dptable[itable]; prefactor = qtmp*q[j] * table; forcecoul -= (1.0-factor_coul)*prefactor; } } } else forcecoul = 0.0; if (rsq <= cut_in_off_sq) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); } else if (rsq <= cut_in_on_sq) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); } fpair = (forcecoul + factor_lj*forcelj) * r2inv; } if (evflag) ev_tally(i,j,nlocal,newton_pair, evdwl,ecoul,fpair,delx,dely,delz); } } } } /* ---------------------------------------------------------------------- allocate all arrays ------------------------------------------------------------------------- */ void PairLJCutCoulLong::allocate() { allocated = 1; int n = atom->ntypes; 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(cutsq,n+1,n+1,"pair:cutsq"); memory->create(cut_lj,n+1,n+1,"pair:cut_lj"); memory->create(cut_ljsq,n+1,n+1,"pair:cut_ljsq"); memory->create(epsilon,n+1,n+1,"pair:epsilon"); memory->create(sigma,n+1,n+1,"pair:sigma"); memory->create(lj1,n+1,n+1,"pair:lj1"); memory->create(lj2,n+1,n+1,"pair:lj2"); memory->create(lj3,n+1,n+1,"pair:lj3"); memory->create(lj4,n+1,n+1,"pair:lj4"); memory->create(offset,n+1,n+1,"pair:offset"); } /* ---------------------------------------------------------------------- global settings ------------------------------------------------------------------------- */ void PairLJCutCoulLong::settings(int narg, char **arg) { if (narg < 1 || narg > 2) error->all(FLERR,"Illegal pair_style command"); cut_lj_global = force->numeric(FLERR,arg[0]); if (narg == 1) cut_coul = cut_lj_global; else cut_coul = force->numeric(FLERR,arg[1]); // reset cutoffs that have been explicitly set if (allocated) { int i,j; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) if (setflag[i][j]) cut_lj[i][j] = cut_lj_global; } } /* ---------------------------------------------------------------------- set coeffs for one or more type pairs ------------------------------------------------------------------------- */ void PairLJCutCoulLong::coeff(int narg, char **arg) { if (narg < 4 || narg > 5) error->all(FLERR,"Incorrect args for pair coefficients"); if (!allocated) allocate(); int ilo,ihi,jlo,jhi; force->bounds(FLERR,arg[0],atom->ntypes,ilo,ihi); force->bounds(FLERR,arg[1],atom->ntypes,jlo,jhi); double epsilon_one = force->numeric(FLERR,arg[2]); double sigma_one = force->numeric(FLERR,arg[3]); double cut_lj_one = cut_lj_global; if (narg == 5) cut_lj_one = force->numeric(FLERR,arg[4]); int count = 0; for (int i = ilo; i <= ihi; i++) { for (int j = MAX(jlo,i); j <= jhi; j++) { epsilon[i][j] = epsilon_one; sigma[i][j] = sigma_one; cut_lj[i][j] = cut_lj_one; setflag[i][j] = 1; count++; } } if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- init specific to this pair style ------------------------------------------------------------------------- */ void PairLJCutCoulLong::init_style() { if (!atom->q_flag) error->all(FLERR,"Pair style lj/cut/coul/long requires atom attribute q"); - // request regular or rRESPA neighbor lists + // request regular or rRESPA neighbor list int irequest; + int respa = 0; if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { - int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; + } - if (respa == 0) irequest = neighbor->request(this,instance_me); - else if (respa == 1) { - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 1; - neighbor->requests[irequest]->respainner = 1; - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 3; - neighbor->requests[irequest]->respaouter = 1; - } else { - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 1; - neighbor->requests[irequest]->respainner = 1; - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 2; - neighbor->requests[irequest]->respamiddle = 1; - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 3; - neighbor->requests[irequest]->respaouter = 1; - } + irequest = neighbor->request(this,instance_me); - } else irequest = neighbor->request(this,instance_me); + if (respa >= 1) { + neighbor->requests[irequest]->respaouter = 1; + neighbor->requests[irequest]->respainner = 1; + } + if (respa == 2) neighbor->requests[irequest]->respamiddle = 1; cut_coulsq = cut_coul * cut_coul; // set rRESPA cutoffs if (strstr(update->integrate_style,"respa") && ((Respa *) update->integrate)->level_inner >= 0) cut_respa = ((Respa *) update->integrate)->cutoff; else cut_respa = NULL; // insure use of KSpace long-range solver, set g_ewald if (force->kspace == NULL) error->all(FLERR,"Pair style requires a KSpace style"); g_ewald = force->kspace->g_ewald; // setup force tables if (ncoultablebits) init_tables(cut_coul,cut_respa); } -/* ---------------------------------------------------------------------- - neighbor callback to inform pair style of neighbor list to use - regular or rRESPA -------------------------------------------------------------------------- */ - -void PairLJCutCoulLong::init_list(int id, NeighList *ptr) -{ - if (id == 0) list = ptr; - else if (id == 1) listinner = ptr; - else if (id == 2) listmiddle = ptr; - else if (id == 3) listouter = ptr; -} - /* ---------------------------------------------------------------------- init for one type pair i,j and corresponding j,i ------------------------------------------------------------------------- */ double PairLJCutCoulLong::init_one(int i, int j) { if (setflag[i][j] == 0) { epsilon[i][j] = mix_energy(epsilon[i][i],epsilon[j][j], sigma[i][i],sigma[j][j]); sigma[i][j] = mix_distance(sigma[i][i],sigma[j][j]); cut_lj[i][j] = mix_distance(cut_lj[i][i],cut_lj[j][j]); } // include TIP4P qdist in full cutoff, qdist = 0.0 if not TIP4P double cut = MAX(cut_lj[i][j],cut_coul+2.0*qdist); cut_ljsq[i][j] = cut_lj[i][j] * cut_lj[i][j]; lj1[i][j] = 48.0 * epsilon[i][j] * pow(sigma[i][j],12.0); lj2[i][j] = 24.0 * epsilon[i][j] * pow(sigma[i][j],6.0); lj3[i][j] = 4.0 * epsilon[i][j] * pow(sigma[i][j],12.0); lj4[i][j] = 4.0 * epsilon[i][j] * pow(sigma[i][j],6.0); if (offset_flag && (cut_lj[i][j] > 0.0)) { double ratio = sigma[i][j] / cut_lj[i][j]; offset[i][j] = 4.0 * epsilon[i][j] * (pow(ratio,12.0) - pow(ratio,6.0)); } else offset[i][j] = 0.0; cut_ljsq[j][i] = cut_ljsq[i][j]; lj1[j][i] = lj1[i][j]; lj2[j][i] = lj2[i][j]; lj3[j][i] = lj3[i][j]; lj4[j][i] = lj4[i][j]; offset[j][i] = offset[i][j]; // check interior rRESPA cutoff if (cut_respa && MIN(cut_lj[i][j],cut_coul) < cut_respa[3]) error->all(FLERR,"Pair cutoff < Respa interior cutoff"); // compute I,J contribution to long-range tail correction // count total # of atoms of type I and J via Allreduce if (tail_flag) { int *type = atom->type; int nlocal = atom->nlocal; double count[2],all[2]; count[0] = count[1] = 0.0; for (int k = 0; k < nlocal; k++) { if (type[k] == i) count[0] += 1.0; if (type[k] == j) count[1] += 1.0; } MPI_Allreduce(count,all,2,MPI_DOUBLE,MPI_SUM,world); double sig2 = sigma[i][j]*sigma[i][j]; double sig6 = sig2*sig2*sig2; double rc3 = cut_lj[i][j]*cut_lj[i][j]*cut_lj[i][j]; double rc6 = rc3*rc3; double rc9 = rc3*rc6; etail_ij = 8.0*MY_PI*all[0]*all[1]*epsilon[i][j] * sig6 * (sig6 - 3.0*rc6) / (9.0*rc9); ptail_ij = 16.0*MY_PI*all[0]*all[1]*epsilon[i][j] * sig6 * (2.0*sig6 - 3.0*rc6) / (9.0*rc9); } return cut; } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairLJCutCoulLong::write_restart(FILE *fp) { write_restart_settings(fp); int i,j; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { fwrite(&setflag[i][j],sizeof(int),1,fp); if (setflag[i][j]) { fwrite(&epsilon[i][j],sizeof(double),1,fp); fwrite(&sigma[i][j],sizeof(double),1,fp); fwrite(&cut_lj[i][j],sizeof(double),1,fp); } } } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairLJCutCoulLong::read_restart(FILE *fp) { read_restart_settings(fp); allocate(); int i,j; int me = comm->me; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp); MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world); if (setflag[i][j]) { if (me == 0) { fread(&epsilon[i][j],sizeof(double),1,fp); fread(&sigma[i][j],sizeof(double),1,fp); fread(&cut_lj[i][j],sizeof(double),1,fp); } MPI_Bcast(&epsilon[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&sigma[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&cut_lj[i][j],1,MPI_DOUBLE,0,world); } } } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairLJCutCoulLong::write_restart_settings(FILE *fp) { fwrite(&cut_lj_global,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(&tail_flag,sizeof(int),1,fp); fwrite(&ncoultablebits,sizeof(int),1,fp); fwrite(&tabinner,sizeof(double),1,fp); } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairLJCutCoulLong::read_restart_settings(FILE *fp) { if (comm->me == 0) { fread(&cut_lj_global,sizeof(double),1,fp); fread(&cut_coul,sizeof(double),1,fp); fread(&offset_flag,sizeof(int),1,fp); fread(&mix_flag,sizeof(int),1,fp); fread(&tail_flag,sizeof(int),1,fp); fread(&ncoultablebits,sizeof(int),1,fp); fread(&tabinner,sizeof(double),1,fp); } MPI_Bcast(&cut_lj_global,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(&tail_flag,1,MPI_INT,0,world); MPI_Bcast(&ncoultablebits,1,MPI_INT,0,world); MPI_Bcast(&tabinner,1,MPI_DOUBLE,0,world); } /* ---------------------------------------------------------------------- proc 0 writes to data file ------------------------------------------------------------------------- */ void PairLJCutCoulLong::write_data(FILE *fp) { for (int i = 1; i <= atom->ntypes; i++) fprintf(fp,"%d %g %g\n",i,epsilon[i][i],sigma[i][i]); } /* ---------------------------------------------------------------------- proc 0 writes all pairs to data file ------------------------------------------------------------------------- */ void PairLJCutCoulLong::write_data_all(FILE *fp) { for (int i = 1; i <= atom->ntypes; i++) for (int j = i; j <= atom->ntypes; j++) fprintf(fp,"%d %d %g %g %g\n",i,j,epsilon[i][j],sigma[i][j],cut_lj[i][j]); } /* ---------------------------------------------------------------------- */ double PairLJCutCoulLong::single(int i, int j, int itype, int jtype, double rsq, double factor_coul, double factor_lj, double &fforce) { double r2inv,r6inv,r,grij,expm2,t,erfc,prefactor; double fraction,table,forcecoul,forcelj,phicoul,philj; int itable; r2inv = 1.0/rsq; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { r = sqrt(rsq); grij = g_ewald * r; expm2 = exp(-grij*grij); t = 1.0 / (1.0 + EWALD_P*grij); erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2; prefactor = force->qqrd2e * atom->q[i]*atom->q[j]/r; forcecoul = prefactor * (erfc + EWALD_F*grij*expm2); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; } else { union_int_float_t rsq_lookup_single; rsq_lookup_single.f = rsq; itable = rsq_lookup_single.i & ncoulmask; itable >>= ncoulshiftbits; fraction = (rsq_lookup_single.f - rtable[itable]) * drtable[itable]; table = ftable[itable] + fraction*dftable[itable]; forcecoul = atom->q[i]*atom->q[j] * table; if (factor_coul < 1.0) { table = ctable[itable] + fraction*dctable[itable]; prefactor = atom->q[i]*atom->q[j] * table; forcecoul -= (1.0-factor_coul)*prefactor; } } } else forcecoul = 0.0; if (rsq < cut_ljsq[itype][jtype]) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); } else forcelj = 0.0; fforce = (forcecoul + factor_lj*forcelj) * r2inv; double eng = 0.0; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) phicoul = prefactor*erfc; else { table = etable[itable] + fraction*detable[itable]; phicoul = atom->q[i]*atom->q[j] * table; } if (factor_coul < 1.0) phicoul -= (1.0-factor_coul)*prefactor; eng += phicoul; } if (rsq < cut_ljsq[itype][jtype]) { philj = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - offset[itype][jtype]; eng += factor_lj*philj; } return eng; } /* ---------------------------------------------------------------------- */ void *PairLJCutCoulLong::extract(const char *str, int &dim) { dim = 0; if (strcmp(str,"cut_coul") == 0) return (void *) &cut_coul; dim = 2; if (strcmp(str,"epsilon") == 0) return (void *) epsilon; if (strcmp(str,"sigma") == 0) return (void *) sigma; return NULL; } diff --git a/src/KSPACE/pair_lj_cut_coul_long.h b/src/KSPACE/pair_lj_cut_coul_long.h index 886542d07..e6f97c088 100644 --- a/src/KSPACE/pair_lj_cut_coul_long.h +++ b/src/KSPACE/pair_lj_cut_coul_long.h @@ -1,94 +1,93 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #ifdef PAIR_CLASS PairStyle(lj/cut/coul/long,PairLJCutCoulLong) #else #ifndef LMP_PAIR_LJ_CUT_COUL_LONG_H #define LMP_PAIR_LJ_CUT_COUL_LONG_H #include "pair.h" namespace LAMMPS_NS { class PairLJCutCoulLong : public Pair { public: PairLJCutCoulLong(class LAMMPS *); virtual ~PairLJCutCoulLong(); virtual void compute(int, int); virtual void settings(int, char **); void coeff(int, char **); virtual void init_style(); - void init_list(int, class NeighList *); virtual double init_one(int, int); void write_restart(FILE *); void read_restart(FILE *); virtual void write_restart_settings(FILE *); virtual void read_restart_settings(FILE *); void write_data(FILE *); void write_data_all(FILE *); virtual double single(int, int, int, int, double, double, double, double &); void compute_inner(); void compute_middle(); virtual void compute_outer(int, int); virtual void *extract(const char *, int &); protected: double cut_lj_global; double **cut_lj,**cut_ljsq; double cut_coul,cut_coulsq; double **epsilon,**sigma; double **lj1,**lj2,**lj3,**lj4,**offset; double *cut_respa; double qdist; // TIP4P distance from O site to negative charge double g_ewald; virtual void allocate(); }; } #endif #endif /* ERROR/WARNING messages: E: Illegal ... command Self-explanatory. Check the input script syntax and compare to the documentation for the command. You can use -echo screen as a command-line option when running LAMMPS to see the offending line. E: Incorrect args for pair coefficients Self-explanatory. Check the input script or data file. E: Pair style lj/cut/coul/long requires atom attribute q The atom style defined does not have this attribute. E: Pair style requires a KSpace style No kspace style is defined. E: Pair cutoff < Respa interior cutoff One or more pairwise cutoffs are too short to use with the specified rRESPA cutoffs. */ diff --git a/src/KSPACE/pair_lj_cut_coul_msm.cpp b/src/KSPACE/pair_lj_cut_coul_msm.cpp index e3b3f58fc..9f901db9f 100644 --- a/src/KSPACE/pair_lj_cut_coul_msm.cpp +++ b/src/KSPACE/pair_lj_cut_coul_msm.cpp @@ -1,494 +1,494 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- Contributing authors: Stan Moore (SNL), Paul Crozier (SNL) ------------------------------------------------------------------------- */ #include #include #include #include #include "pair_lj_cut_coul_msm.h" #include "atom.h" #include "comm.h" #include "force.h" #include "kspace.h" #include "update.h" #include "integrate.h" #include "respa.h" #include "neighbor.h" #include "neigh_list.h" #include "neigh_request.h" #include "math_const.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; using namespace MathConst; /* ---------------------------------------------------------------------- */ PairLJCutCoulMSM::PairLJCutCoulMSM(LAMMPS *lmp) : PairLJCutCoulLong(lmp) { ewaldflag = pppmflag = 0; msmflag = 1; nmax = 0; ftmp = NULL; } /* ---------------------------------------------------------------------- */ PairLJCutCoulMSM::~PairLJCutCoulMSM() { if (ftmp) memory->destroy(ftmp); } /* ---------------------------------------------------------------------- */ void PairLJCutCoulMSM::compute(int eflag, int vflag) { int i,ii,j,jj,inum,jnum,itype,jtype,itable; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair,fcoul; double fraction,table; double r,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; double egamma,fgamma,prefactor; int *ilist,*jlist,*numneigh,**firstneigh; double rsq; int eflag_old = eflag; if (force->kspace->scalar_pressure_flag && vflag) { if (vflag > 2) error->all(FLERR,"Must use 'kspace_modify pressure/scalar no' " "to obtain per-atom virial with kspace_style MSM"); if (atom->nmax > nmax) { if (ftmp) memory->destroy(ftmp); nmax = atom->nmax; memory->create(ftmp,nmax,3,"pair:ftmp"); } memset(&ftmp[0][0],0,nmax*3*sizeof(double)); // must switch on global energy computation if not already on if (eflag == 0 || eflag == 2) { eflag++; } } evdwl = ecoul = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; inum = list->inum; ilist = list->ilist; numneigh = list->numneigh; firstneigh = list->firstneigh; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; if (rsq < cutsq[itype][jtype]) { r2inv = 1.0/rsq; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { r = sqrt(rsq); prefactor = qqrd2e * qtmp*q[j]/r; egamma = 1.0 - (r/cut_coul)*force->kspace->gamma(r/cut_coul); fgamma = 1.0 + (rsq/cut_coulsq)*force->kspace->dgamma(r/cut_coul); forcecoul = prefactor * fgamma; if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; } else { union_int_float_t rsq_lookup; rsq_lookup.f = rsq; itable = rsq_lookup.i & ncoulmask; itable >>= ncoulshiftbits; fraction = (rsq_lookup.f - rtable[itable]) * drtable[itable]; table = ftable[itable] + fraction*dftable[itable]; forcecoul = qtmp*q[j] * table; if (factor_coul < 1.0) { table = ctable[itable] + fraction*dctable[itable]; prefactor = qtmp*q[j] * table; forcecoul -= (1.0-factor_coul)*prefactor; } } } else forcecoul = 0.0; if (rsq < cut_ljsq[itype][jtype]) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); } else forcelj = 0.0; if (!(force->kspace->scalar_pressure_flag && vflag)) { fpair = (forcecoul + factor_lj*forcelj) * r2inv; 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; } } else { // separate LJ and Coulombic forces fpair = (factor_lj*forcelj) * r2inv; 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; } fcoul = (forcecoul) * r2inv; ftmp[i][0] += delx*fcoul; ftmp[i][1] += dely*fcoul; ftmp[i][2] += delz*fcoul; if (newton_pair || j < nlocal) { ftmp[j][0] -= delx*fcoul; ftmp[j][1] -= dely*fcoul; ftmp[j][2] -= delz*fcoul; } } if (eflag) { if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) ecoul = prefactor*egamma; else { table = etable[itable] + fraction*detable[itable]; ecoul = qtmp*q[j] * table; } if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; } else ecoul = 0.0; if (eflag_old && rsq < cut_ljsq[itype][jtype]) { evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - offset[itype][jtype]; evdwl *= factor_lj; } else evdwl = 0.0; } if (evflag) ev_tally(i,j,nlocal,newton_pair, evdwl,ecoul,fpair,delx,dely,delz); } } } if (vflag_fdotr) virial_fdotr_compute(); if (force->kspace->scalar_pressure_flag && vflag) { for (i = 0; i < 3; i++) virial[i] += force->pair->eng_coul/3.0; for (int i = 0; i < nmax; i++) { f[i][0] += ftmp[i][0]; f[i][1] += ftmp[i][1]; f[i][2] += ftmp[i][2]; } } } /* ---------------------------------------------------------------------- */ void PairLJCutCoulMSM::compute_outer(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype,itable; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair; double fraction,table; double r,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; double egamma,fgamma,prefactor; double rsw; int *ilist,*jlist,*numneigh,**firstneigh; double rsq; if (force->kspace->scalar_pressure_flag) error->all(FLERR,"Must use 'kspace_modify pressure/scalar no' " "for rRESPA with kspace_style MSM"); evdwl = ecoul = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; - inum = listouter->inum; - ilist = listouter->ilist; - numneigh = listouter->numneigh; - firstneigh = listouter->firstneigh; + inum = list->inum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; double cut_in_off = cut_respa[2]; double cut_in_on = cut_respa[3]; double cut_in_diff = cut_in_on - cut_in_off; double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; if (rsq < cutsq[itype][jtype]) { r2inv = 1.0/rsq; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { r = sqrt(rsq); prefactor = qqrd2e * qtmp*q[j]/r; egamma = 1.0 - (r/cut_coul)*force->kspace->gamma(r/cut_coul); fgamma = 1.0 + (rsq/cut_coulsq)*force->kspace->dgamma(r/cut_coul); forcecoul = prefactor * (fgamma - 1.0); if (rsq > cut_in_off_sq) { if (rsq < cut_in_on_sq) { rsw = (r - cut_in_off)/cut_in_diff; forcecoul += prefactor*rsw*rsw*(3.0 - 2.0*rsw); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor*rsw*rsw*(3.0 - 2.0*rsw); } else { forcecoul += prefactor; if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; } } } else { union_int_float_t rsq_lookup; rsq_lookup.f = rsq; itable = rsq_lookup.i & ncoulmask; itable >>= ncoulshiftbits; fraction = (rsq_lookup.f - rtable[itable]) * drtable[itable]; table = ftable[itable] + fraction*dftable[itable]; forcecoul = qtmp*q[j] * table; if (factor_coul < 1.0) { table = ctable[itable] + fraction*dctable[itable]; prefactor = qtmp*q[j] * table; forcecoul -= (1.0-factor_coul)*prefactor; } } } else forcecoul = 0.0; if (rsq < cut_ljsq[itype][jtype] && rsq > cut_in_off_sq) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); if (rsq < cut_in_on_sq) { rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; forcelj *= rsw*rsw*(3.0 - 2.0*rsw); } } else forcelj = 0.0; fpair = (forcecoul + forcelj) * r2inv; 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; } if (eflag) { if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { ecoul = prefactor*egamma; if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; } else { table = etable[itable] + fraction*detable[itable]; ecoul = qtmp*q[j] * table; if (factor_coul < 1.0) { table = ptable[itable] + fraction*dptable[itable]; prefactor = qtmp*q[j] * table; ecoul -= (1.0-factor_coul)*prefactor; } } } else ecoul = 0.0; if (rsq < cut_ljsq[itype][jtype]) { r6inv = r2inv*r2inv*r2inv; evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - offset[itype][jtype]; evdwl *= factor_lj; } else evdwl = 0.0; } if (vflag) { if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { forcecoul = prefactor * fgamma; if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; } else { table = vtable[itable] + fraction*dvtable[itable]; forcecoul = qtmp*q[j] * table; if (factor_coul < 1.0) { table = ptable[itable] + fraction*dptable[itable]; prefactor = qtmp*q[j] * table; forcecoul -= (1.0-factor_coul)*prefactor; } } } else forcecoul = 0.0; if (rsq <= cut_in_off_sq) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); } else if (rsq <= cut_in_on_sq) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); } fpair = (forcecoul + factor_lj*forcelj) * r2inv; } if (evflag) ev_tally(i,j,nlocal,newton_pair, evdwl,ecoul,fpair,delx,dely,delz); } } } } /* ---------------------------------------------------------------------- */ double PairLJCutCoulMSM::single(int i, int j, int itype, int jtype, double rsq, double factor_coul, double factor_lj, double &fforce) { double r2inv,r6inv,r,egamma,fgamma,prefactor; double fraction,table,forcecoul,forcelj,phicoul,philj; int itable; r2inv = 1.0/rsq; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { r = sqrt(rsq); prefactor = force->qqrd2e * atom->q[i]*atom->q[j]/r; egamma = 1.0 - (r/cut_coul)*force->kspace->gamma(r/cut_coul); fgamma = 1.0 + (rsq/cut_coulsq)*force->kspace->dgamma(r/cut_coul); forcecoul = prefactor * fgamma; if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; } else { union_int_float_t rsq_lookup_single; rsq_lookup_single.f = rsq; itable = rsq_lookup_single.i & ncoulmask; itable >>= ncoulshiftbits; fraction = (rsq_lookup_single.f - rtable[itable]) * drtable[itable]; table = ftable[itable] + fraction*dftable[itable]; forcecoul = atom->q[i]*atom->q[j] * table; if (factor_coul < 1.0) { table = ctable[itable] + fraction*dctable[itable]; prefactor = atom->q[i]*atom->q[j] * table; forcecoul -= (1.0-factor_coul)*prefactor; } } } else forcecoul = 0.0; if (rsq < cut_ljsq[itype][jtype]) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); } else forcelj = 0.0; fforce = (forcecoul + factor_lj*forcelj) * r2inv; double eng = 0.0; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) phicoul = prefactor*egamma; else { table = etable[itable] + fraction*detable[itable]; phicoul = atom->q[i]*atom->q[j] * table; } if (factor_coul < 1.0) phicoul -= (1.0-factor_coul)*prefactor; eng += phicoul; } if (rsq < cut_ljsq[itype][jtype]) { philj = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - offset[itype][jtype]; eng += factor_lj*philj; } return eng; } /* ---------------------------------------------------------------------- */ void *PairLJCutCoulMSM::extract(const char *str, int &dim) { dim = 0; if (strcmp(str,"cut_coul") == 0) return (void *) &cut_coul; dim = 2; if (strcmp(str,"epsilon") == 0) return (void *) epsilon; if (strcmp(str,"sigma") == 0) return (void *) sigma; return NULL; } diff --git a/src/KSPACE/pair_lj_long_coul_long.cpp b/src/KSPACE/pair_lj_long_coul_long.cpp index 7c6adfcb4..61b69011f 100644 --- a/src/KSPACE/pair_lj_long_coul_long.cpp +++ b/src/KSPACE/pair_lj_long_coul_long.cpp @@ -1,1039 +1,1013 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- Contributing author: Pieter J. in 't Veld (SNL) Tabulation for long-range dispersion added by Wayne Mitchell (Loyola University New Orleans) ------------------------------------------------------------------------- */ #include #include #include #include #include "math_vector.h" #include "pair_lj_long_coul_long.h" #include "atom.h" #include "comm.h" #include "neighbor.h" #include "neigh_list.h" #include "neigh_request.h" #include "force.h" #include "kspace.h" #include "update.h" #include "integrate.h" #include "respa.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; #define EWALD_F 1.12837917 #define EWALD_P 0.3275911 #define A1 0.254829592 #define A2 -0.284496736 #define A3 1.421413741 #define A4 -1.453152027 #define A5 1.061405429 /* ---------------------------------------------------------------------- */ PairLJLongCoulLong::PairLJLongCoulLong(LAMMPS *lmp) : Pair(lmp) { dispersionflag = ewaldflag = pppmflag = 1; respa_enable = 1; writedata = 1; ftable = NULL; fdisptable = NULL; qdist = 0.0; } /* ---------------------------------------------------------------------- global settings ------------------------------------------------------------------------- */ void PairLJLongCoulLong::options(char **arg, int order) { const char *option[] = {"long", "cut", "off", NULL}; int i; if (!*arg) error->all(FLERR,"Illegal pair_style lj/long/coul/long command"); for (i=0; option[i]&&strcmp(arg[0], option[i]); ++i); switch (i) { default: error->all(FLERR,"Illegal pair_style lj/long/coul/long command"); case 0: ewald_order |= 1<all(FLERR,"Illegal pair_style command"); ewald_order = 0; ewald_off = 0; options(arg,6); options(++arg,1); if (!comm->me && ewald_order == ((1<<1) | (1<<6))) error->warning(FLERR,"Using largest cutoff for lj/long/coul/long"); if (!*(++arg)) error->all(FLERR,"Cutoffs missing in pair_style lj/long/coul/long"); if (!((ewald_order^ewald_off) & (1<<1))) error->all(FLERR, "Coulomb cut not supported in pair_style lj/long/coul/long"); cut_lj_global = force->numeric(FLERR,*(arg++)); if (narg == 4 && ((ewald_order & 0x42) == 0x42)) error->all(FLERR,"Only one cutoff allowed when requesting all long"); if (narg == 4) cut_coul = force->numeric(FLERR,*arg); else cut_coul = cut_lj_global; if (allocated) { int i,j; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) if (setflag[i][j]) cut_lj[i][j] = cut_lj_global; } } /* ---------------------------------------------------------------------- free all arrays ------------------------------------------------------------------------- */ PairLJLongCoulLong::~PairLJLongCoulLong() { if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(cut_lj_read); memory->destroy(cut_lj); memory->destroy(cut_ljsq); memory->destroy(epsilon_read); memory->destroy(epsilon); memory->destroy(sigma_read); memory->destroy(sigma); memory->destroy(lj1); memory->destroy(lj2); memory->destroy(lj3); memory->destroy(lj4); memory->destroy(offset); } if (ftable) free_tables(); if (fdisptable) free_disp_tables(); } /* ---------------------------------------------------------------------- allocate all arrays ------------------------------------------------------------------------- */ void PairLJLongCoulLong::allocate() { allocated = 1; int n = atom->ntypes; 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(cutsq,n+1,n+1,"pair:cutsq"); memory->create(cut_lj_read,n+1,n+1,"pair:cut_lj_read"); memory->create(cut_lj,n+1,n+1,"pair:cut_lj"); memory->create(cut_ljsq,n+1,n+1,"pair:cut_ljsq"); memory->create(epsilon_read,n+1,n+1,"pair:epsilon_read"); memory->create(epsilon,n+1,n+1,"pair:epsilon"); memory->create(sigma_read,n+1,n+1,"pair:sigma_read"); memory->create(sigma,n+1,n+1,"pair:sigma"); memory->create(lj1,n+1,n+1,"pair:lj1"); memory->create(lj2,n+1,n+1,"pair:lj2"); memory->create(lj3,n+1,n+1,"pair:lj3"); memory->create(lj4,n+1,n+1,"pair:lj4"); memory->create(offset,n+1,n+1,"pair:offset"); } /* ---------------------------------------------------------------------- extract protected data from object ------------------------------------------------------------------------- */ void *PairLJLongCoulLong::extract(const char *id, int &dim) { const char *ids[] = { "B", "sigma", "epsilon", "ewald_order", "ewald_cut", "ewald_mix", "cut_coul", "cut_LJ", NULL}; void *ptrs[] = { lj4, sigma, epsilon, &ewald_order, &cut_coul, &mix_flag, &cut_coul, &cut_lj_global, NULL}; int i; for (i=0; ids[i]&&strcmp(ids[i], id); ++i); if (i <= 2) dim = 2; else dim = 0; return ptrs[i]; } /* ---------------------------------------------------------------------- set coeffs for one or more type pairs ------------------------------------------------------------------------- */ void PairLJLongCoulLong::coeff(int narg, char **arg) { if (narg < 4 || narg > 5) error->all(FLERR,"Incorrect args for pair coefficients"); if (!allocated) allocate(); int ilo,ihi,jlo,jhi; force->bounds(FLERR,arg[0],atom->ntypes,ilo,ihi); force->bounds(FLERR,arg[1],atom->ntypes,jlo,jhi); double epsilon_one = force->numeric(FLERR,arg[2]); double sigma_one = force->numeric(FLERR,arg[3]); double cut_lj_one = cut_lj_global; if (narg == 5) cut_lj_one = force->numeric(FLERR,arg[4]); int count = 0; for (int i = ilo; i <= ihi; i++) { for (int j = MAX(jlo,i); j <= jhi; j++) { epsilon_read[i][j] = epsilon_one; sigma_read[i][j] = sigma_one; cut_lj_read[i][j] = cut_lj_one; setflag[i][j] = 1; count++; } } if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- init specific to this pair style ------------------------------------------------------------------------- */ void PairLJLongCoulLong::init_style() { // require an atom style with charge defined if (!atom->q_flag && (ewald_order&(1<<1))) error->all(FLERR, "Invoking coulombic in pair style lj/long/coul/long requires atom attribute q"); // ensure use of KSpace long-range solver, set two g_ewalds if (force->kspace == NULL) error->all(FLERR,"Pair style requires a KSpace style"); if (ewald_order&(1<<1)) g_ewald = force->kspace->g_ewald; if (ewald_order&(1<<6)) g_ewald_6 = force->kspace->g_ewald_6; // set rRESPA cutoffs if (strstr(update->integrate_style,"respa") && ((Respa *) update->integrate)->level_inner >= 0) cut_respa = ((Respa *) update->integrate)->cutoff; else cut_respa = NULL; // setup force tables if (ncoultablebits && (ewald_order&(1<<1))) init_tables(cut_coul,cut_respa); if (ndisptablebits && (ewald_order&(1<<6))) init_tables_disp(cut_lj_global); // request regular or rRESPA neighbor lists if neighrequest_flag != 0 if (force->kspace->neighrequest_flag) { int irequest; - + int respa = 0; + if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { - int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; - - if (respa == 0) irequest = neighbor->request(this,instance_me); - else if (respa == 1) { - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 1; - neighbor->requests[irequest]->respainner = 1; - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 3; - neighbor->requests[irequest]->respaouter = 1; - } else { - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 1; - neighbor->requests[irequest]->respainner = 1; - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 2; - neighbor->requests[irequest]->respamiddle = 1; - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 3; - neighbor->requests[irequest]->respaouter = 1; - } - - } else irequest = neighbor->request(this,instance_me); + } + + irequest = neighbor->request(this,instance_me); + + if (respa >= 1) { + neighbor->requests[irequest]->respaouter = 1; + neighbor->requests[irequest]->respainner = 1; + } + if (respa == 2) neighbor->requests[irequest]->respamiddle = 1; } cut_coulsq = cut_coul * cut_coul; } -/* ---------------------------------------------------------------------- - neighbor callback to inform pair style of neighbor list to use - regular or rRESPA -------------------------------------------------------------------------- */ - -void PairLJLongCoulLong::init_list(int id, NeighList *ptr) -{ - if (id == 0) list = ptr; - else if (id == 1) listinner = ptr; - else if (id == 2) listmiddle = ptr; - else if (id == 3) listouter = ptr; -} - /* ---------------------------------------------------------------------- init for one type pair i,j and corresponding j,i ------------------------------------------------------------------------- */ double PairLJLongCoulLong::init_one(int i, int j) { if (setflag[i][j] == 0) { epsilon[i][j] = mix_energy(epsilon_read[i][i],epsilon_read[j][j], sigma_read[i][i],sigma_read[j][j]); sigma[i][j] = mix_distance(sigma_read[i][i],sigma_read[j][j]); if (ewald_order&(1<<6)) cut_lj[i][j] = cut_lj_global; else cut_lj[i][j] = mix_distance(cut_lj_read[i][i],cut_lj_read[j][j]); } else { sigma[i][j] = sigma_read[i][j]; epsilon[i][j] = epsilon_read[i][j]; cut_lj[i][j] = cut_lj_read[i][j]; } double cut = MAX(cut_lj[i][j], cut_coul + 2.0*qdist); cutsq[i][j] = cut*cut; cut_ljsq[i][j] = cut_lj[i][j] * cut_lj[i][j]; lj1[i][j] = 48.0 * epsilon[i][j] * pow(sigma[i][j],12.0); lj2[i][j] = 24.0 * epsilon[i][j] * pow(sigma[i][j],6.0); lj3[i][j] = 4.0 * epsilon[i][j] * pow(sigma[i][j],12.0); lj4[i][j] = 4.0 * epsilon[i][j] * pow(sigma[i][j],6.0); // check interior rRESPA cutoff if (cut_respa && MIN(cut_lj[i][j],cut_coul) < cut_respa[3]) error->all(FLERR,"Pair cutoff < Respa interior cutoff"); if (offset_flag && (cut_lj[i][j] > 0.0)) { double ratio = sigma[i][j] / cut_lj[i][j]; offset[i][j] = 4.0 * epsilon[i][j] * (pow(ratio,12.0) - pow(ratio,6.0)); } else offset[i][j] = 0.0; cutsq[j][i] = cutsq[i][j]; cut_ljsq[j][i] = cut_ljsq[i][j]; lj1[j][i] = lj1[i][j]; lj2[j][i] = lj2[i][j]; lj3[j][i] = lj3[i][j]; lj4[j][i] = lj4[i][j]; offset[j][i] = offset[i][j]; return cut; } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairLJLongCoulLong::write_restart(FILE *fp) { write_restart_settings(fp); int i,j; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { fwrite(&setflag[i][j],sizeof(int),1,fp); if (setflag[i][j]) { fwrite(&epsilon_read[i][j],sizeof(double),1,fp); fwrite(&sigma_read[i][j],sizeof(double),1,fp); fwrite(&cut_lj_read[i][j],sizeof(double),1,fp); } } } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairLJLongCoulLong::read_restart(FILE *fp) { read_restart_settings(fp); allocate(); int i,j; int me = comm->me; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp); MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world); if (setflag[i][j]) { if (me == 0) { fread(&epsilon_read[i][j],sizeof(double),1,fp); fread(&sigma_read[i][j],sizeof(double),1,fp); fread(&cut_lj_read[i][j],sizeof(double),1,fp); } MPI_Bcast(&epsilon_read[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&sigma_read[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&cut_lj_read[i][j],1,MPI_DOUBLE,0,world); } } } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairLJLongCoulLong::write_restart_settings(FILE *fp) { fwrite(&cut_lj_global,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(&ncoultablebits,sizeof(int),1,fp); fwrite(&tabinner,sizeof(double),1,fp); fwrite(&ewald_order,sizeof(int),1,fp); } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairLJLongCoulLong::read_restart_settings(FILE *fp) { if (comm->me == 0) { fread(&cut_lj_global,sizeof(double),1,fp); fread(&cut_coul,sizeof(double),1,fp); fread(&offset_flag,sizeof(int),1,fp); fread(&mix_flag,sizeof(int),1,fp); fread(&ncoultablebits,sizeof(int),1,fp); fread(&tabinner,sizeof(double),1,fp); fread(&ewald_order,sizeof(int),1,fp); } MPI_Bcast(&cut_lj_global,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(&ncoultablebits,1,MPI_INT,0,world); MPI_Bcast(&tabinner,1,MPI_DOUBLE,0,world); MPI_Bcast(&ewald_order,1,MPI_INT,0,world); } /* ---------------------------------------------------------------------- proc 0 writes to data file ------------------------------------------------------------------------- */ void PairLJLongCoulLong::write_data(FILE *fp) { for (int i = 1; i <= atom->ntypes; i++) fprintf(fp,"%d %g %g\n",i,epsilon_read[i][i],sigma_read[i][i]); } /* ---------------------------------------------------------------------- proc 0 writes all pairs to data file ------------------------------------------------------------------------- */ void PairLJLongCoulLong::write_data_all(FILE *fp) { for (int i = 1; i <= atom->ntypes; i++) for (int j = i; j <= atom->ntypes; j++) fprintf(fp,"%d %d %g %g %g\n",i,j, epsilon_read[i][j],sigma_read[i][j],cut_lj_read[i][j]); } /* ---------------------------------------------------------------------- compute pair interactions ------------------------------------------------------------------------- */ void PairLJLongCoulLong::compute(int eflag, int vflag) { double evdwl,ecoul,fpair; evdwl = ecoul = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = vflag_fdotr = 0; double **x = atom->x, *x0 = x[0]; double **f = atom->f, *f0 = f[0], *fi = f0; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; int i, j, order1 = ewald_order&(1<<1), order6 = ewald_order&(1<<6); int *ineigh, *ineighn, *jneigh, *jneighn, typei, typej, ni; double qi = 0.0, qri = 0.0; double *cutsqi, *cut_ljsqi, *lj1i, *lj2i, *lj3i, *lj4i, *offseti; double rsq, r2inv, force_coul, force_lj; double g2 = g_ewald_6*g_ewald_6, g6 = g2*g2*g2, g8 = g6*g2; vector xi, d; ineighn = (ineigh = list->ilist)+list->inum; for (; ineighfirstneigh[i])+list->numneigh[i]; for (; jneigh= cutsqi[typej = type[j]]) continue; r2inv = 1.0/rsq; if (order1 && (rsq < cut_coulsq)) { // coulombic if (!ncoultablebits || rsq <= tabinnersq) { // series real space register double r = sqrt(rsq), x = g_ewald*r; register double s = qri*q[j], t = 1.0/(1.0+EWALD_P*x); if (ni == 0) { s *= g_ewald*exp(-x*x); force_coul = (t *= ((((t*A5+A4)*t+A3)*t+A2)*t+A1)*s/x)+EWALD_F*s; if (eflag) ecoul = t; } else { // special case r = s*(1.0-special_coul[ni])/r; s *= g_ewald*exp(-x*x); force_coul = (t *= ((((t*A5+A4)*t+A3)*t+A2)*t+A1)*s/x)+EWALD_F*s-r; if (eflag) ecoul = t-r; } } // table real space else { register union_int_float_t t; t.f = rsq; register const int k = (t.i & ncoulmask)>>ncoulshiftbits; register double f = (rsq-rtable[k])*drtable[k], qiqj = qi*q[j]; if (ni == 0) { force_coul = qiqj*(ftable[k]+f*dftable[k]); if (eflag) ecoul = qiqj*(etable[k]+f*detable[k]); } else { // special case t.f = (1.0-special_coul[ni])*(ctable[k]+f*dctable[k]); force_coul = qiqj*(ftable[k]+f*dftable[k]-t.f); if (eflag) ecoul = qiqj*(etable[k]+f*detable[k]-t.f); } } } else force_coul = ecoul = 0.0; if (rsq < cut_ljsqi[typej]) { // lj if (order6) { // long-range lj if(!ndisptablebits || rsq <= tabinnerdispsq) { // series real space register double rn = r2inv*r2inv*r2inv; register double x2 = g2*rsq, a2 = 1.0/x2; x2 = a2*exp(-x2)*lj4i[typej]; if (ni == 0) { force_lj = (rn*=rn)*lj1i[typej]-g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq; if (eflag) evdwl = rn*lj3i[typej]-g6*((a2+1.0)*a2+0.5)*x2; } else { // special case register double f = special_lj[ni], t = rn*(1.0-f); force_lj = f*(rn *= rn)*lj1i[typej]- g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq+t*lj2i[typej]; if (eflag) evdwl = f*rn*lj3i[typej]-g6*((a2+1.0)*a2+0.5)*x2+t*lj4i[typej]; } } else { // table real space register union_int_float_t disp_t; disp_t.f = rsq; register const int disp_k = (disp_t.i & ndispmask)>>ndispshiftbits; register double f_disp = (rsq-rdisptable[disp_k])*drdisptable[disp_k]; register double rn = r2inv*r2inv*r2inv; if (ni == 0) { force_lj = (rn*=rn)*lj1i[typej]-(fdisptable[disp_k]+f_disp*dfdisptable[disp_k])*lj4i[typej]; if (eflag) evdwl = rn*lj3i[typej]-(edisptable[disp_k]+f_disp*dedisptable[disp_k])*lj4i[typej]; } else { // special case register double f = special_lj[ni], t = rn*(1.0-f); force_lj = f*(rn *= rn)*lj1i[typej]-(fdisptable[disp_k]+f_disp*dfdisptable[disp_k])*lj4i[typej]+t*lj2i[typej]; if (eflag) evdwl = f*rn*lj3i[typej]-(edisptable[disp_k]+f_disp*dedisptable[disp_k])*lj4i[typej]+t*lj4i[typej]; } } } else { // cut lj register double rn = r2inv*r2inv*r2inv; if (ni == 0) { force_lj = rn*(rn*lj1i[typej]-lj2i[typej]); if (eflag) evdwl = rn*(rn*lj3i[typej]-lj4i[typej])-offseti[typej]; } else { // special case register double f = special_lj[ni]; force_lj = f*rn*(rn*lj1i[typej]-lj2i[typej]); if (eflag) evdwl = f * (rn*(rn*lj3i[typej]-lj4i[typej])-offseti[typej]); } } } else force_lj = evdwl = 0.0; fpair = (force_coul+force_lj)*r2inv; if (newton_pair || j < nlocal) { register double *fj = f0+(j+(j<<1)), f; fi[0] += f = d[0]*fpair; fj[0] -= f; fi[1] += f = d[1]*fpair; fj[1] -= f; fi[2] += f = d[2]*fpair; fj[2] -= f; } else { fi[0] += d[0]*fpair; fi[1] += d[1]*fpair; fi[2] += d[2]*fpair; } if (evflag) ev_tally(i,j,nlocal,newton_pair, evdwl,ecoul,fpair,d[0],d[1],d[2]); } } if (vflag_fdotr) virial_fdotr_compute(); } /* ---------------------------------------------------------------------- */ void PairLJLongCoulLong::compute_inner() { double rsq, r2inv, force_coul = 0.0, force_lj, fpair; int *type = atom->type; int nlocal = atom->nlocal; double *x0 = atom->x[0], *f0 = atom->f[0], *fi = f0, *q = atom->q; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; double cut_out_on = cut_respa[0]; double cut_out_off = cut_respa[1]; double cut_out_diff = cut_out_off - cut_out_on; double cut_out_on_sq = cut_out_on*cut_out_on; double cut_out_off_sq = cut_out_off*cut_out_off; int *ineigh, *ineighn, *jneigh, *jneighn, typei, typej, ni; int i, j, order1 = (ewald_order|(ewald_off^-1))&(1<<1); double qri, *cut_ljsqi, *lj1i, *lj2i; vector xi, d; - ineighn = (ineigh = listinner->ilist)+listinner->inum; + ineighn = (ineigh = list->ilist_inner)+list->inum_inner; for (; ineighfirstneigh[i])+listinner->numneigh[i]; + jneighn = (jneigh = list->firstneigh_inner[i])+list->numneigh_inner[i]; for (; jneigh= cut_out_off_sq) continue; r2inv = 1.0/rsq; if (order1 && (rsq < cut_coulsq)) { // coulombic qri = qqrd2e*q[i]; force_coul = ni == 0 ? qri*q[j]*sqrt(r2inv) : qri*q[j]*sqrt(r2inv)*special_coul[ni]; } if (rsq < cut_ljsqi[typej = type[j]]) { // lennard-jones register double rn = r2inv*r2inv*r2inv; force_lj = ni == 0 ? rn*(rn*lj1i[typej]-lj2i[typej]) : rn*(rn*lj1i[typej]-lj2i[typej])*special_lj[ni]; } else force_lj = 0.0; fpair = (force_coul + force_lj) * r2inv; if (rsq > cut_out_on_sq) { // switching register double rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; fpair *= 1.0 + rsw*rsw*(2.0*rsw-3.0); } if (newton_pair || j < nlocal) { // force update register double *fj = f0+(j+(j<<1)), f; fi[0] += f = d[0]*fpair; fj[0] -= f; fi[1] += f = d[1]*fpair; fj[1] -= f; fi[2] += f = d[2]*fpair; fj[2] -= f; } else { fi[0] += d[0]*fpair; fi[1] += d[1]*fpair; fi[2] += d[2]*fpair; } } } } /* ---------------------------------------------------------------------- */ void PairLJLongCoulLong::compute_middle() { double rsq, r2inv, force_coul = 0.0, force_lj, fpair; int *type = atom->type; int nlocal = atom->nlocal; double *x0 = atom->x[0], *f0 = atom->f[0], *fi = f0, *q = atom->q; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; double cut_in_off = cut_respa[0]; double cut_in_on = cut_respa[1]; double cut_out_on = cut_respa[2]; double cut_out_off = cut_respa[3]; double cut_in_diff = cut_in_on - cut_in_off; double cut_out_diff = cut_out_off - cut_out_on; double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; double cut_out_on_sq = cut_out_on*cut_out_on; double cut_out_off_sq = cut_out_off*cut_out_off; int *ineigh, *ineighn, *jneigh, *jneighn, typei, typej, ni; int i, j, order1 = (ewald_order|(ewald_off^-1))&(1<<1); double qri, *cut_ljsqi, *lj1i, *lj2i; vector xi, d; - ineighn = (ineigh = listmiddle->ilist)+listmiddle->inum; + ineighn = (ineigh = list->ilist_middle)+list->inum_middle; for (; ineighfirstneigh[i])+listmiddle->numneigh[i]; + jneighn = (jneigh = list->firstneigh_middle[i])+list->numneigh_middle[i]; for (; jneigh= cut_out_off_sq) continue; if (rsq <= cut_in_off_sq) continue; r2inv = 1.0/rsq; if (order1 && (rsq < cut_coulsq)) // coulombic force_coul = ni == 0 ? qri*q[j]*sqrt(r2inv) : qri*q[j]*sqrt(r2inv)*special_coul[ni]; if (rsq < cut_ljsqi[typej = type[j]]) { // lennard-jones register double rn = r2inv*r2inv*r2inv; force_lj = ni == 0 ? rn*(rn*lj1i[typej]-lj2i[typej]) : rn*(rn*lj1i[typej]-lj2i[typej])*special_lj[ni]; } else force_lj = 0.0; fpair = (force_coul + force_lj) * r2inv; if (rsq < cut_in_on_sq) { // switching register double rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; fpair *= rsw*rsw*(3.0 - 2.0*rsw); } if (rsq > cut_out_on_sq) { register double rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; fpair *= 1.0 + rsw*rsw*(2.0*rsw-3.0); } if (newton_pair || j < nlocal) { // force update register double *fj = f0+(j+(j<<1)), f; fi[0] += f = d[0]*fpair; fj[0] -= f; fi[1] += f = d[1]*fpair; fj[1] -= f; fi[2] += f = d[2]*fpair; fj[2] -= f; } else { fi[0] += d[0]*fpair; fi[1] += d[1]*fpair; fi[2] += d[2]*fpair; } } } } /* ---------------------------------------------------------------------- */ void PairLJLongCoulLong::compute_outer(int eflag, int vflag) { double evdwl,ecoul,fvirial,fpair; evdwl = ecoul = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = 0; double **x = atom->x, *x0 = x[0]; double **f = atom->f, *f0 = f[0], *fi = f0; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; int i, j, order1 = ewald_order&(1<<1), order6 = ewald_order&(1<<6); int *ineigh, *ineighn, *jneigh, *jneighn, typei, typej, ni, respa_flag; double qi = 0.0, qri = 0.0; double *cutsqi, *cut_ljsqi, *lj1i, *lj2i, *lj3i, *lj4i, *offseti; double rsq, r2inv, force_coul, force_lj; double g2 = g_ewald_6*g_ewald_6, g6 = g2*g2*g2, g8 = g6*g2; double respa_lj = 0.0, respa_coul = 0.0, frespa = 0.0; vector xi, d; double cut_in_off = cut_respa[2]; double cut_in_on = cut_respa[3]; double cut_in_diff = cut_in_on - cut_in_off; double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; - ineighn = (ineigh = listouter->ilist)+listouter->inum; + ineighn = (ineigh = list->ilist)+list->inum; for (; ineighfirstneigh[i])+listouter->numneigh[i]; + jneighn = (jneigh = list->firstneigh[i])+list->numneigh[i]; for (; jneigh= cutsqi[typej = type[j]]) continue; r2inv = 1.0/rsq; frespa = 1.0; // check whether and how to compute respa corrections respa_coul = 0; respa_lj = 0; respa_flag = rsq < cut_in_on_sq ? 1 : 0; if (respa_flag && (rsq > cut_in_off_sq)) { register double rsw = (sqrt(rsq)-cut_in_off)/cut_in_diff; frespa = 1-rsw*rsw*(3.0-2.0*rsw); } if (order1 && (rsq < cut_coulsq)) { // coulombic if (!ncoultablebits || rsq <= tabinnersq) { // series real space register double r = sqrt(rsq), s = qri*q[j]; if (respa_flag) // correct for respa respa_coul = ni == 0 ? frespa*s/r : frespa*s/r*special_coul[ni]; register double x = g_ewald*r, t = 1.0/(1.0+EWALD_P*x); if (ni == 0) { s *= g_ewald*exp(-x*x); force_coul = (t *= ((((t*A5+A4)*t+A3)*t+A2)*t+A1)*s/x)+EWALD_F*s-respa_coul; if (eflag) ecoul = t; } else { // correct for special r = s*(1.0-special_coul[ni])/r; s *= g_ewald*exp(-x*x); force_coul = (t *= ((((t*A5+A4)*t+A3)*t+A2)*t+A1)*s/x)+EWALD_F*s-r-respa_coul; if (eflag) ecoul = t-r; } } // table real space else { if (respa_flag) { register double r = sqrt(rsq), s = qri*q[j]; respa_coul = ni == 0 ? frespa*s/r : frespa*s/r*special_coul[ni]; } register union_int_float_t t; t.f = rsq; register const int k = (t.i & ncoulmask) >> ncoulshiftbits; register double f = (rsq-rtable[k])*drtable[k], qiqj = qi*q[j]; if (ni == 0) { force_coul = qiqj*(ftable[k]+f*dftable[k]); if (eflag) ecoul = qiqj*(etable[k]+f*detable[k]); } else { // correct for special t.f = (1.0-special_coul[ni])*(ctable[k]+f*dctable[k]); force_coul = qiqj*(ftable[k]+f*dftable[k]-t.f); if (eflag) { t.f = (1.0-special_coul[ni])*(ptable[k]+f*dptable[k]); ecoul = qiqj*(etable[k]+f*detable[k]-t.f); } } } } else force_coul = respa_coul = ecoul = 0.0; if (rsq < cut_ljsqi[typej]) { // lennard-jones register double rn = r2inv*r2inv*r2inv; if (respa_flag) respa_lj = ni == 0 ? // correct for respa frespa*rn*(rn*lj1i[typej]-lj2i[typej]) : frespa*rn*(rn*lj1i[typej]-lj2i[typej])*special_lj[ni]; if (order6) { // long-range form if (!ndisptablebits || rsq <= tabinnerdispsq) { register double x2 = g2*rsq, a2 = 1.0/x2; x2 = a2*exp(-x2)*lj4i[typej]; if (ni == 0) { force_lj = (rn*=rn)*lj1i[typej]-g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq-respa_lj; if (eflag) evdwl = rn*lj3i[typej]-g6*((a2+1.0)*a2+0.5)*x2; } else { // correct for special register double f = special_lj[ni], t = rn*(1.0-f); force_lj = f*(rn *= rn)*lj1i[typej]- g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq+t*lj2i[typej]-respa_lj; if (eflag) evdwl = f*rn*lj3i[typej]-g6*((a2+1.0)*a2+0.5)*x2+t*lj4i[typej]; } } else { // table real space register union_int_float_t disp_t; disp_t.f = rsq; register const int disp_k = (disp_t.i & ndispmask)>>ndispshiftbits; register double f_disp = (rsq-rdisptable[disp_k])*drdisptable[disp_k]; register double rn = r2inv*r2inv*r2inv; if (ni == 0) { force_lj = (rn*=rn)*lj1i[typej]-(fdisptable[disp_k]+f_disp*dfdisptable[disp_k])*lj4i[typej]-respa_lj; if (eflag) evdwl = rn*lj3i[typej]-(edisptable[disp_k]+f_disp*dedisptable[disp_k])*lj4i[typej]; } else { // special case register double f = special_lj[ni], t = rn*(1.0-f); force_lj = f*(rn *= rn)*lj1i[typej]-(fdisptable[disp_k]+f_disp*dfdisptable[disp_k])*lj4i[typej]+t*lj2i[typej]-respa_lj; if (eflag) evdwl = f*rn*lj3i[typej]-(edisptable[disp_k]+f_disp*dedisptable[disp_k])*lj4i[typej]+t*lj4i[typej]; } } } else { // cut form if (ni == 0) { force_lj = rn*(rn*lj1i[typej]-lj2i[typej])-respa_lj; if (eflag) evdwl = rn*(rn*lj3i[typej]-lj4i[typej])-offseti[typej]; } else { // correct for special register double f = special_lj[ni]; force_lj = f*rn*(rn*lj1i[typej]-lj2i[typej])-respa_lj; if (eflag) evdwl = f*(rn*(rn*lj3i[typej]-lj4i[typej])-offseti[typej]); } } } else force_lj = respa_lj = evdwl = 0.0; fpair = (force_coul+force_lj)*r2inv; if (newton_pair || j < nlocal) { register double *fj = f0+(j+(j<<1)), f; fi[0] += f = d[0]*fpair; fj[0] -= f; fi[1] += f = d[1]*fpair; fj[1] -= f; fi[2] += f = d[2]*fpair; fj[2] -= f; } else { fi[0] += d[0]*fpair; fi[1] += d[1]*fpair; fi[2] += d[2]*fpair; } if (evflag) { fvirial = (force_coul + force_lj + respa_coul + respa_lj)*r2inv; ev_tally(i,j,nlocal,newton_pair, evdwl,ecoul,fvirial,d[0],d[1],d[2]); } } } } /* ---------------------------------------------------------------------- */ double PairLJLongCoulLong::single(int i, int j, int itype, int jtype, double rsq, double factor_coul, double factor_lj, double &fforce) { double r2inv, r6inv, force_coul, force_lj; double g2 = g_ewald_6*g_ewald_6, g6 = g2*g2*g2, g8 = g6*g2, *q = atom->q; double eng = 0.0; r2inv = 1.0/rsq; if ((ewald_order&2) && (rsq < cut_coulsq)) { // coulombic if (!ncoultablebits || rsq <= tabinnersq) { // series real space register double r = sqrt(rsq), x = g_ewald*r; register double s = force->qqrd2e*q[i]*q[j], t = 1.0/(1.0+EWALD_P*x); r = s*(1.0-factor_coul)/r; s *= g_ewald*exp(-x*x); force_coul = (t *= ((((t*A5+A4)*t+A3)*t+A2)*t+A1)*s/x)+EWALD_F*s-r; eng += t-r; } else { // table real space register union_int_float_t t; t.f = rsq; register const int k = (t.i & ncoulmask) >> ncoulshiftbits; register double f = (rsq-rtable[k])*drtable[k], qiqj = q[i]*q[j]; t.f = (1.0-factor_coul)*(ctable[k]+f*dctable[k]); force_coul = qiqj*(ftable[k]+f*dftable[k]-t.f); eng += qiqj*(etable[k]+f*detable[k]-t.f); } } else force_coul = 0.0; if (rsq < cut_ljsq[itype][jtype]) { // lennard-jones r6inv = r2inv*r2inv*r2inv; if (ewald_order&64) { // long-range register double x2 = g2*rsq, a2 = 1.0/x2, t = r6inv*(1.0-factor_lj); x2 = a2*exp(-x2)*lj4[itype][jtype]; force_lj = factor_lj*(r6inv *= r6inv)*lj1[itype][jtype]- g8*(((6.0*a2+6.0)*a2+3.0)*a2+a2)*x2*rsq+t*lj2[itype][jtype]; eng += factor_lj*r6inv*lj3[itype][jtype]- g6*((a2+1.0)*a2+0.5)*x2+t*lj4[itype][jtype]; } else { // cut force_lj = factor_lj*r6inv*(lj1[itype][jtype]*r6inv-lj2[itype][jtype]); eng += factor_lj*(r6inv*(r6inv*lj3[itype][jtype]- lj4[itype][jtype])-offset[itype][jtype]); } } else force_lj = 0.0; fforce = (force_coul+force_lj)*r2inv; return eng; } diff --git a/src/KSPACE/pair_lj_long_coul_long.h b/src/KSPACE/pair_lj_long_coul_long.h index 22704c79f..f11c81e28 100644 --- a/src/KSPACE/pair_lj_long_coul_long.h +++ b/src/KSPACE/pair_lj_long_coul_long.h @@ -1,114 +1,113 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #ifdef PAIR_CLASS PairStyle(lj/long/coul/long,PairLJLongCoulLong) #else #ifndef LMP_PAIR_LJ_LONG_COUL_LONG_H #define LMP_PAIR_LJ_LONG_COUL_LONG_H #include "pair.h" namespace LAMMPS_NS { class PairLJLongCoulLong : public Pair { public: double cut_coul; PairLJLongCoulLong(class LAMMPS *); virtual ~PairLJLongCoulLong(); virtual void compute(int, int); virtual void settings(int, char **); void coeff(int, char **); void init_style(); - void init_list(int, class NeighList *); double init_one(int, int); void write_restart(FILE *); void read_restart(FILE *); void write_restart_settings(FILE *); void read_restart_settings(FILE *); void write_data(FILE *); void write_data_all(FILE *); double single(int, int, int, int, double, double, double, double &); void *extract(const char *, int &); virtual void compute_inner(); virtual void compute_middle(); virtual void compute_outer(int, int); protected: double cut_lj_global; double **cut_lj, **cut_lj_read, **cut_ljsq; double cut_coulsq; double **epsilon_read, **epsilon, **sigma_read, **sigma; double **lj1, **lj2, **lj3, **lj4, **offset; double *cut_respa; double qdist; double g_ewald; double g_ewald_6; int ewald_order, ewald_off; void options(char **arg, int order); void allocate(); }; } #endif #endif /* ERROR/WARNING messages: E: Illegal ... command Self-explanatory. Check the input script syntax and compare to the documentation for the command. You can use -echo screen as a command-line option when running LAMMPS to see the offending line. W: Using largest cutoff for lj/long/coul/long Self-explanatory. E: Cutoffs missing in pair_style lj/long/coul/long Self-explanatory. E: Coulomb cut not supported in pair_style lj/long/coul/long Must use long-range Coulombic interactions. E: Only one cutoff allowed when requesting all long Self-explanatory. E: Incorrect args for pair coefficients Self-explanatory. Check the input script or data file. E: Invoking coulombic in pair style lj/coul requires atom attribute q The atom style defined does not have this attribute. E: Pair style requires a KSpace style No kspace style is defined. E: Pair cutoff < Respa interior cutoff One or more pairwise cutoffs are too short to use with the specified rRESPA cutoffs. */ diff --git a/src/KSPACE/pair_lj_long_tip4p_long.cpp b/src/KSPACE/pair_lj_long_tip4p_long.cpp index 1dc1ca1cb..1b0eb12e2 100644 --- a/src/KSPACE/pair_lj_long_tip4p_long.cpp +++ b/src/KSPACE/pair_lj_long_tip4p_long.cpp @@ -1,1641 +1,1641 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- Contributing authors: Amalie Frischknecht and Ahmed Ismail (SNL) Rolf Isele-Holder (Aachen University) ------------------------------------------------------------------------- */ #include #include #include #include #include "pair_lj_long_tip4p_long.h" #include "angle.h" #include "atom.h" #include "bond.h" #include "comm.h" #include "domain.h" #include "force.h" #include "kspace.h" #include "update.h" #include "respa.h" #include "neighbor.h" #include "neigh_list.h" #include "neigh_request.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; #define EWALD_F 1.12837917 #define EWALD_P 0.3275911 #define A1 0.254829592 #define A2 -0.284496736 #define A3 1.421413741 #define A4 -1.453152027 #define A5 1.061405429 /* ---------------------------------------------------------------------- */ PairLJLongTIP4PLong::PairLJLongTIP4PLong(LAMMPS *lmp) : PairLJLongCoulLong(lmp) { dispersionflag = tip4pflag = 1; single_enable = 0; respa_enable = 1; nmax = 0; hneigh = NULL; newsite = NULL; // TIP4P cannot compute virial as F dot r // due to find_M() finding bonded H atoms which are not near O atom no_virial_fdotr_compute = 1; } /* ---------------------------------------------------------------------- */ PairLJLongTIP4PLong::~PairLJLongTIP4PLong() { memory->destroy(hneigh); memory->destroy(newsite); } /* ---------------------------------------------------------------------- */ void PairLJLongTIP4PLong::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype,itable; int n,vlist[6]; int key; int iH1,iH2,jH1,jH2; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul; double fraction,table; double r,r2inv,forcecoul,forcelj,cforce; double factor_coul; double grij,expm2,prefactor,t,erfc; double fO[3],fH[3],fd[3],v[6]; double *x1,*x2,*xH1,*xH2; int *ilist,*jlist,*numneigh,**firstneigh; double rsq; evdwl = ecoul = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = vflag_fdotr = 0; // reallocate hneigh & newsite if necessary // initialize hneigh[0] to -1 on steps when reneighboring occurred // initialize hneigh[2] to 0 every step int nlocal = atom->nlocal; int nall = nlocal + atom->nghost; if (atom->nmax > nmax) { nmax = atom->nmax; memory->destroy(hneigh); memory->create(hneigh,nmax,3,"pair:hneigh"); memory->destroy(newsite); memory->create(newsite,nmax,3,"pair:newsite"); } if (neighbor->ago == 0) for (i = 0; i < nall; i++) hneigh[i][0] = -1; for (i = 0; i < nall; i++) hneigh[i][2] = 0; double **f = atom->f; double **x = atom->x; double *q = atom->q; tagint *tag = atom->tag; int *type = atom->type; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; double cut_coulsqplus = (cut_coul+2.0*qdist)*(cut_coul+2.0*qdist); int order1 = ewald_order&(1<<1), order6 = ewald_order&(1<<6); int ni; double *lj1i, *lj2i, *lj3i, *lj4i, *offseti; double g2 = g_ewald_6*g_ewald_6, g6 = g2*g2*g2, g8 = g6*g2; inum = list->inum; ilist = list->ilist; numneigh = list->numneigh; firstneigh = list->firstneigh; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; if (itype == typeO) { if (hneigh[i][0] < 0) { iH1 = atom->map(tag[i] + 1); iH2 = atom->map(tag[i] + 2); if (iH1 == -1 || iH2 == -1) error->one(FLERR,"TIP4P hydrogen is missing"); if (atom->type[iH1] != typeH || atom->type[iH2] != typeH) error->one(FLERR,"TIP4P hydrogen has incorrect atom type"); // set iH1,iH2 to closest image to O iH1 = domain->closest_image(i,iH1); iH2 = domain->closest_image(i,iH2); compute_newsite(x[i],x[iH1],x[iH2],newsite[i]); hneigh[i][0] = iH1; hneigh[i][1] = iH2; hneigh[i][2] = 1; } else { iH1 = hneigh[i][0]; iH2 = hneigh[i][1]; if (hneigh[i][2] == 0) { hneigh[i][2] = 1; compute_newsite(x[i],x[iH1],x[iH2],newsite[i]); } } x1 = newsite[i]; } else x1 = x[i]; jlist = firstneigh[i]; jnum = numneigh[i]; offseti = offset[itype]; lj1i = lj1[itype]; lj2i = lj2[itype]; lj3i = lj3[itype]; lj4i = lj4[itype]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; ni = sbmask(j); factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; if (rsq < cut_ljsq[itype][jtype]) { // lj r2inv = 1.0/rsq; if (order6) { // long-range lj if (!ndisptablebits || rsq <= tabinnerdispsq) { register double rn = r2inv*r2inv*r2inv; register double x2 = g2*rsq, a2 = 1.0/x2; x2 = a2*exp(-x2)*lj4i[jtype]; if (ni == 0) { forcelj = (rn*=rn)*lj1i[jtype]-g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq; if (eflag) evdwl = rn*lj3i[jtype]-g6*((a2+1.0)*a2+0.5)*x2; } else { // special case register double f = special_lj[ni], t = rn*(1.0-f); forcelj = f*(rn *= rn)*lj1i[jtype]- g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq+t*lj2i[jtype]; if (eflag) evdwl = f*rn*lj3i[jtype]-g6*((a2+1.0)*a2+0.5)*x2+t*lj4i[jtype]; } } else { // table real space register union_int_float_t disp_t; disp_t.f = rsq; register const int disp_k = (disp_t.i & ndispmask)>>ndispshiftbits; register double f_disp = (rsq-rdisptable[disp_k])*drdisptable[disp_k]; register double rn = r2inv*r2inv*r2inv; if (ni == 0) { forcelj = (rn*=rn)*lj1i[jtype]-(fdisptable[disp_k]+f_disp*dfdisptable[disp_k])*lj4i[jtype]; if (eflag) evdwl = rn*lj3i[jtype]-(edisptable[disp_k]+f_disp*dedisptable[disp_k])*lj4i[jtype]; } else { // special case register double f = special_lj[ni], t = rn*(1.0-f); forcelj = f*(rn *= rn)*lj1i[jtype]-(fdisptable[disp_k]+f_disp*dfdisptable[disp_k])*lj4i[jtype]+t*lj2i[jtype]; if (eflag) evdwl = f*rn*lj3i[jtype]-(edisptable[disp_k]+f_disp*dedisptable[disp_k])*lj4i[jtype]+t*lj4i[jtype]; } } } else { // cut lj register double rn = r2inv*r2inv*r2inv; if (ni == 0) { forcelj = rn*(rn*lj1i[jtype]-lj2i[jtype]); if (eflag) evdwl = rn*(rn*lj3i[jtype]-lj4i[jtype])-offseti[jtype]; } else { // special case register double f = special_lj[ni]; forcelj = f*rn*(rn*lj1i[jtype]-lj2i[jtype]); if (eflag) evdwl = f * (rn*(rn*lj3i[jtype]-lj4i[jtype])-offseti[jtype]); } } forcelj *= r2inv; f[i][0] += delx*forcelj; f[i][1] += dely*forcelj; f[i][2] += delz*forcelj; f[j][0] -= delx*forcelj; f[j][1] -= dely*forcelj; f[j][2] -= delz*forcelj; if (evflag) ev_tally(i,j,nlocal,newton_pair, evdwl,0.0,forcelj,delx,dely,delz); } // adjust rsq and delxyz for off-site O charge(s) // ADDITIONAL REQEUST REQUIRED HERE!!!!! if (rsq < cut_coulsqplus) { if (itype == typeO || jtype == typeO) { if (jtype == typeO) { if (hneigh[j][0] < 0) { jH1 = atom->map(tag[j] + 1); jH2 = atom->map(tag[j] + 2); if (jH1 == -1 || jH2 == -1) error->one(FLERR,"TIP4P hydrogen is missing"); if (atom->type[jH1] != typeH || atom->type[jH2] != typeH) error->one(FLERR,"TIP4P hydrogen has incorrect atom type"); // set jH1,jH2 to closest image to O jH1 = domain->closest_image(j,jH1); jH2 = domain->closest_image(j,jH2); compute_newsite(x[j],x[jH1],x[jH2],newsite[j]); hneigh[j][0] = jH1; hneigh[j][1] = jH2; hneigh[j][2] = 1; } else { jH1 = hneigh[j][0]; jH2 = hneigh[j][1]; if (hneigh[j][2] == 0) { hneigh[j][2] = 1; compute_newsite(x[j],x[jH1],x[jH2],newsite[j]); } } x2 = newsite[j]; } else x2 = x[j]; delx = x1[0] - x2[0]; dely = x1[1] - x2[1]; delz = x1[2] - x2[2]; rsq = delx*delx + dely*dely + delz*delz; } // test current rsq against cutoff and compute Coulombic force if (rsq < cut_coulsq && order1) { r2inv = 1.0 / rsq; if (!ncoultablebits || rsq <= tabinnersq) { r = sqrt(rsq); grij = g_ewald * r; expm2 = exp(-grij*grij); t = 1.0 / (1.0 + EWALD_P*grij); erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2; prefactor = qqrd2e * qtmp*q[j]/r; forcecoul = prefactor * (erfc + EWALD_F*grij*expm2); if (factor_coul < 1.0) { forcecoul -= (1.0-factor_coul)*prefactor; } } else { union_int_float_t rsq_lookup; rsq_lookup.f = rsq; itable = rsq_lookup.i & ncoulmask; itable >>= ncoulshiftbits; fraction = (rsq_lookup.f - rtable[itable]) * drtable[itable]; table = ftable[itable] + fraction*dftable[itable]; forcecoul = qtmp*q[j] * table; if (factor_coul < 1.0) { table = ctable[itable] + fraction*dctable[itable]; prefactor = qtmp*q[j] * table; forcecoul -= (1.0-factor_coul)*prefactor; } } cforce = forcecoul * r2inv; //if (evflag) ev_tally(i,j,nlocal,newton_pair, // evdwl,0.0,cforce,delx,dely,delz); // if i,j are not O atoms, force is applied directly // if i or j are O atoms, force is on fictitious atom & partitioned // force partitioning due to Feenstra, J Comp Chem, 20, 786 (1999) // f_f = fictitious force, fO = f_f (1 - 2 alpha), fH = alpha f_f // preserves total force and torque on water molecule // virial = sum(r x F) where each water's atoms are near xi and xj // vlist stores 2,4,6 atoms whose forces contribute to virial n = 0; key = 0; if (itype != typeO) { f[i][0] += delx * cforce; f[i][1] += dely * cforce; f[i][2] += delz * cforce; if (vflag) { v[0] = x[i][0] * delx * cforce; v[1] = x[i][1] * dely * cforce; v[2] = x[i][2] * delz * cforce; v[3] = x[i][0] * dely * cforce; v[4] = x[i][0] * delz * cforce; v[5] = x[i][1] * delz * cforce; } vlist[n++] = i; } else { key += 1; fd[0] = delx*cforce; fd[1] = dely*cforce; fd[2] = delz*cforce; fO[0] = fd[0]*(1 - alpha); fO[1] = fd[1]*(1 - alpha); fO[2] = fd[2]*(1 - alpha); fH[0] = 0.5 * alpha * fd[0]; fH[1] = 0.5 * alpha * fd[1]; fH[2] = 0.5 * alpha * fd[2]; f[i][0] += fO[0]; f[i][1] += fO[1]; f[i][2] += fO[2]; f[iH1][0] += fH[0]; f[iH1][1] += fH[1]; f[iH1][2] += fH[2]; f[iH2][0] += fH[0]; f[iH2][1] += fH[1]; f[iH2][2] += fH[2]; if (vflag) { xH1 = x[iH1]; xH2 = x[iH2]; v[0] = x[i][0]*fO[0] + xH1[0]*fH[0] + xH2[0]*fH[0]; v[1] = x[i][1]*fO[1] + xH1[1]*fH[1] + xH2[1]*fH[1]; v[2] = x[i][2]*fO[2] + xH1[2]*fH[2] + xH2[2]*fH[2]; v[3] = x[i][0]*fO[1] + xH1[0]*fH[1] + xH2[0]*fH[1]; v[4] = x[i][0]*fO[2] + xH1[0]*fH[2] + xH2[0]*fH[2]; v[5] = x[i][1]*fO[2] + xH1[1]*fH[2] + xH2[1]*fH[2]; } vlist[n++] = i; vlist[n++] = iH1; vlist[n++] = iH2; } if (jtype != typeO) { f[j][0] -= delx * cforce; f[j][1] -= dely * cforce; f[j][2] -= delz * cforce; if (vflag) { v[0] -= x[j][0] * delx * cforce; v[1] -= x[j][1] * dely * cforce; v[2] -= x[j][2] * delz * cforce; v[3] -= x[j][0] * dely * cforce; v[4] -= x[j][0] * delz * cforce; v[5] -= x[j][1] * delz * cforce; } vlist[n++] = j; } else { key += 2; fd[0] = -delx*cforce; fd[1] = -dely*cforce; fd[2] = -delz*cforce; fO[0] = fd[0]*(1 - alpha); fO[1] = fd[1]*(1 - alpha); fO[2] = fd[2]*(1 - alpha); fH[0] = 0.5 * alpha * fd[0]; fH[1] = 0.5 * alpha * fd[1]; fH[2] = 0.5 * alpha * fd[2]; f[j][0] += fO[0]; f[j][1] += fO[1]; f[j][2] += fO[2]; f[jH1][0] += fH[0]; f[jH1][1] += fH[1]; f[jH1][2] += fH[2]; f[jH2][0] += fH[0]; f[jH2][1] += fH[1]; f[jH2][2] += fH[2]; if (vflag) { xH1 = x[jH1]; xH2 = x[jH2]; v[0] += x[j][0]*fO[0] + xH1[0]*fH[0] + xH2[0]*fH[0]; v[1] += x[j][1]*fO[1] + xH1[1]*fH[1] + xH2[1]*fH[1]; v[2] += x[j][2]*fO[2] + xH1[2]*fH[2] + xH2[2]*fH[2]; v[3] += x[j][0]*fO[1] + xH1[0]*fH[1] + xH2[0]*fH[1]; v[4] += x[j][0]*fO[2] + xH1[0]*fH[2] + xH2[0]*fH[2]; v[5] += x[j][1]*fO[2] + xH1[1]*fH[2] + xH2[1]*fH[2]; } vlist[n++] = j; vlist[n++] = jH1; vlist[n++] = jH2; } if (eflag) { if (!ncoultablebits || rsq <= tabinnersq) ecoul = prefactor*erfc; else { table = etable[itable] + fraction*detable[itable]; ecoul = qtmp*q[j] * table; } if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; } else ecoul = 0.0; if (evflag) ev_tally_tip4p(key,vlist,v,ecoul,alpha); } } } } } /* --------------------------------------------------------------------- */ void PairLJLongTIP4PLong::compute_inner() { int i,j,ii,jj,inum,jnum,itype,jtype; int iH1,iH2,jH1,jH2; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz; double r2inv,forcecoul,forcelj,cforce; double fO[3],fH[3],fd[3]; double *x1,*x2; int *ilist,*jlist,*numneigh,**firstneigh; double rsq, qri; double cut_out_on = cut_respa[0]; double cut_out_off = cut_respa[1]; double cut_out_diff = cut_out_off - cut_out_on; double cut_out_on_sq = cut_out_on*cut_out_on; double cut_out_off_sq = cut_out_off*cut_out_off; // reallocate hneigh & newsite if necessary // initialize hneigh[0] to -1 on steps when reneighboring occurred // initialize hneigh[2] to 0 every step int nlocal = atom->nlocal; int nall = nlocal + atom->nghost; // atom->nmax > nmax will occur during setup if (atom->nmax > nmax) { nmax = atom->nmax; memory->destroy(hneigh); memory->create(hneigh,nmax,3,"pair:hneigh"); memory->destroy(newsite); memory->create(newsite,nmax,3,"pair:newsite"); } if (neighbor->ago == 0) for (i = 0; i < nall; i++) hneigh[i][0] = -1; for (i = 0; i < nall; i++) hneigh[i][2] = 0; double **f = atom->f; double **x = atom->x; double *q = atom->q; tagint *tag = atom->tag; int *type = atom->type; double *special_coul = force->special_coul; double *special_lj = force->special_lj; double qqrd2e = force->qqrd2e; double cut_coulsqplus = (cut_coul+2.0*qdist)*(cut_coul+2.0*qdist); int order1 = ewald_order&(1<<1); int ni; double *lj1i, *lj2i; - inum = listinner->inum; - ilist = listinner->ilist; - numneigh = listinner->numneigh; - firstneigh = listinner->firstneigh; + inum = list->inum_inner; + ilist = list->ilist_inner; + numneigh = list->numneigh_inner; + firstneigh = list->firstneigh_inner; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; if (itype == typeO && order1) { if (hneigh[i][0] < 0) { iH1 = atom->map(tag[i] + 1); iH2 = atom->map(tag[i] + 2); if (iH1 == -1 || iH2 == -1) error->one(FLERR,"TIP4P hydrogen is missing"); if (atom->type[iH1] != typeH || atom->type[iH2] != typeH) error->one(FLERR,"TIP4P hydrogen has incorrect atom type"); // set iH1,iH2 to closest image to O iH1 = domain->closest_image(i,iH1); iH2 = domain->closest_image(i,iH2); compute_newsite(x[i],x[iH1],x[iH2],newsite[i]); hneigh[i][0] = iH1; hneigh[i][1] = iH2; hneigh[i][2] = 1; } else { iH1 = hneigh[i][0]; iH2 = hneigh[i][1]; if (hneigh[i][2] == 0) { hneigh[i][2] = 1; compute_newsite(x[i],x[iH1],x[iH2],newsite[i]); } } x1 = newsite[i]; } else x1 = x[i]; jlist = firstneigh[i]; jnum = numneigh[i]; lj1i = lj1[itype]; lj2i = lj2[itype]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; ni = sbmask(j); j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; if (rsq < cut_ljsq[itype][jtype] && rsq < cut_out_off_sq ) { // lj r2inv = 1.0/rsq; register double rn = r2inv*r2inv*r2inv; if (ni == 0) forcelj = rn*(rn*lj1i[jtype]-lj2i[jtype]); else { // special case register double f = special_lj[ni]; forcelj = f*rn*(rn*lj1i[jtype]-lj2i[jtype]); } if (rsq > cut_out_on_sq) { // switching register double rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; forcelj *= 1.0 + rsw*rsw*(2.0*rsw-3.0); } forcelj *= r2inv; f[i][0] += delx*forcelj; f[i][1] += dely*forcelj; f[i][2] += delz*forcelj; f[j][0] -= delx*forcelj; f[j][1] -= dely*forcelj; f[j][2] -= delz*forcelj; } // adjust rsq and delxyz for off-site O charge(s) // ADDITIONAL REQEUST REQUIRED HERE!!!!! if (rsq < cut_coulsqplus && order1) { if (itype == typeO || jtype == typeO) { if (jtype == typeO) { if (hneigh[j][0] < 0) { jH1 = atom->map(tag[j] + 1); jH2 = atom->map(tag[j] + 2); if (jH1 == -1 || jH2 == -1) error->one(FLERR,"TIP4P hydrogen is missing"); if (atom->type[jH1] != typeH || atom->type[jH2] != typeH) error->one(FLERR,"TIP4P hydrogen has incorrect atom type"); // set jH1,jH2 to closest image to O jH1 = domain->closest_image(j,jH1); jH2 = domain->closest_image(j,jH2); compute_newsite(x[j],x[jH1],x[jH2],newsite[j]); hneigh[j][0] = jH1; hneigh[j][1] = jH2; hneigh[j][2] = 1; } else { jH1 = hneigh[j][0]; jH2 = hneigh[j][1]; if (hneigh[j][2] == 0) { hneigh[j][2] = 1; compute_newsite(x[j],x[jH1],x[jH2],newsite[j]); } } x2 = newsite[j]; } else x2 = x[j]; delx = x1[0] - x2[0]; dely = x1[1] - x2[1]; delz = x1[2] - x2[2]; rsq = delx*delx + dely*dely + delz*delz; } // test current rsq against cutoff and compute Coulombic force if (rsq < cut_coulsq && rsq < cut_out_off_sq) { r2inv = 1.0 / rsq; qri = qqrd2e*qtmp; if (ni == 0) forcecoul = qri*q[j]*sqrt(r2inv); else { forcecoul = qri*q[j]*sqrt(r2inv)*special_coul[ni]; } if (rsq > cut_out_on_sq) { // switching register double rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; forcecoul *= 1.0 + rsw*rsw*(2.0*rsw-3.0); } cforce = forcecoul * r2inv; //if (evflag) ev_tally(i,j,nlocal,newton_pair, // evdwl,0.0,cforce,delx,dely,delz); // if i,j are not O atoms, force is applied directly // if i or j are O atoms, force is on fictitious atom & partitioned // force partitioning due to Feenstra, J Comp Chem, 20, 786 (1999) // f_f = fictitious force, fO = f_f (1 - 2 alpha), fH = alpha f_f // preserves total force and torque on water molecule // virial = sum(r x F) where each water's atoms are near xi and xj // vlist stores 2,4,6 atoms whose forces contribute to virial if (itype != typeO) { f[i][0] += delx * cforce; f[i][1] += dely * cforce; f[i][2] += delz * cforce; } else { fd[0] = delx*cforce; fd[1] = dely*cforce; fd[2] = delz*cforce; fO[0] = fd[0]*(1 - alpha); fO[1] = fd[1]*(1 - alpha); fO[2] = fd[2]*(1 - alpha); fH[0] = 0.5 * alpha * fd[0]; fH[1] = 0.5 * alpha * fd[1]; fH[2] = 0.5 * alpha * fd[2]; f[i][0] += fO[0]; f[i][1] += fO[1]; f[i][2] += fO[2]; f[iH1][0] += fH[0]; f[iH1][1] += fH[1]; f[iH1][2] += fH[2]; f[iH2][0] += fH[0]; f[iH2][1] += fH[1]; f[iH2][2] += fH[2]; } if (jtype != typeO) { f[j][0] -= delx * cforce; f[j][1] -= dely * cforce; f[j][2] -= delz * cforce; } else { fd[0] = -delx*cforce; fd[1] = -dely*cforce; fd[2] = -delz*cforce; fO[0] = fd[0]*(1 - alpha); fO[1] = fd[1]*(1 - alpha); fO[2] = fd[2]*(1 - alpha); fH[0] = 0.5 * alpha * fd[0]; fH[1] = 0.5 * alpha * fd[1]; fH[2] = 0.5 * alpha * fd[2]; f[j][0] += fO[0]; f[j][1] += fO[1]; f[j][2] += fO[2]; f[jH1][0] += fH[0]; f[jH1][1] += fH[1]; f[jH1][2] += fH[2]; f[jH2][0] += fH[0]; f[jH2][1] += fH[1]; f[jH2][2] += fH[2]; } } } } } } /* --------------------------------------------------------------------- */ void PairLJLongTIP4PLong::compute_middle() { int i,j,ii,jj,inum,jnum,itype,jtype; int iH1,iH2,jH1,jH2; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz; double r2inv,forcecoul,forcelj,cforce; double fO[3],fH[3],fd[3]; double *x1,*x2; int *ilist,*jlist,*numneigh,**firstneigh; double rsq,qri; double cut_in_off = cut_respa[0]; double cut_in_on = cut_respa[1]; double cut_out_on = cut_respa[2]; double cut_out_off = cut_respa[3]; double cut_in_diff = cut_in_on - cut_in_off; double cut_out_diff = cut_out_off - cut_out_on; double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; double cut_out_on_sq = cut_out_on*cut_out_on; double cut_out_off_sq = cut_out_off*cut_out_off; // reallocate hneigh & newsite if necessary // initialize hneigh[0] to -1 on steps when reneighboring occurred // initialize hneigh[2] to 0 every step double **f = atom->f; double **x = atom->x; double *q = atom->q; tagint *tag = atom->tag; int *type = atom->type; double *special_coul = force->special_coul; double *special_lj = force->special_lj; double qqrd2e = force->qqrd2e; double cut_coulsqplus = (cut_coul+2.0*qdist)*(cut_coul+2.0*qdist); int order1 = ewald_order&(1<<1); int ni; double *lj1i, *lj2i; - inum = listmiddle->inum; - ilist = listmiddle->ilist; - numneigh = listmiddle->numneigh; - firstneigh = listmiddle->firstneigh; + inum = list->inum_middle; + ilist = list->ilist_middle; + numneigh = list->numneigh_middle; + firstneigh = list->firstneigh_middle; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; if (itype == typeO && order1) { if (hneigh[i][0] < 0) { iH1 = atom->map(tag[i] + 1); iH2 = atom->map(tag[i] + 2); if (iH1 == -1 || iH2 == -1) error->one(FLERR,"TIP4P hydrogen is missing"); if (atom->type[iH1] != typeH || atom->type[iH2] != typeH) error->one(FLERR,"TIP4P hydrogen has incorrect atom type"); // set iH1,iH2 to closest image to O iH1 = domain->closest_image(i,iH1); iH2 = domain->closest_image(i,iH2); compute_newsite(x[i],x[iH1],x[iH2],newsite[i]); hneigh[i][0] = iH1; hneigh[i][1] = iH2; hneigh[i][2] = 1; } else { iH1 = hneigh[i][0]; iH2 = hneigh[i][1]; if (hneigh[i][2] == 0) { hneigh[i][2] = 1; compute_newsite(x[i],x[iH1],x[iH2],newsite[i]); } } x1 = newsite[i]; } else x1 = x[i]; jlist = firstneigh[i]; jnum = numneigh[i]; lj1i = lj1[itype]; lj2i = lj2[itype]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; ni = sbmask(j); j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; if (rsq < cut_ljsq[itype][jtype] && rsq >= cut_in_off_sq && rsq <= cut_out_off_sq ) { // lj r2inv = 1.0/rsq; register double rn = r2inv*r2inv*r2inv; if (ni == 0) forcelj = rn*(rn*lj1i[jtype]-lj2i[jtype]); else { // special case register double f = special_lj[ni]; forcelj = f*rn*(rn*lj1i[jtype]-lj2i[jtype]); } if (rsq < cut_in_on_sq) { // switching register double rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; forcelj *= rsw*rsw*(3.0 - 2.0*rsw); } if (rsq > cut_out_on_sq) { register double rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; forcelj *= 1.0 + rsw*rsw*(2.0*rsw-3.0); } forcelj *= r2inv; f[i][0] += delx*forcelj; f[i][1] += dely*forcelj; f[i][2] += delz*forcelj; f[j][0] -= delx*forcelj; f[j][1] -= dely*forcelj; f[j][2] -= delz*forcelj; } // adjust rsq and delxyz for off-site O charge(s) // ADDITIONAL REQEUST REQUIRED HERE!!!!! if (rsq < cut_coulsqplus && order1) { if (itype == typeO || jtype == typeO) { if (jtype == typeO) { if (hneigh[j][0] < 0) { jH1 = atom->map(tag[j] + 1); jH2 = atom->map(tag[j] + 2); if (jH1 == -1 || jH2 == -1) error->one(FLERR,"TIP4P hydrogen is missing"); if (atom->type[jH1] != typeH || atom->type[jH2] != typeH) error->one(FLERR,"TIP4P hydrogen has incorrect atom type"); // set jH1,jH2 to closest image to O jH1 = domain->closest_image(j,jH1); jH2 = domain->closest_image(j,jH2); compute_newsite(x[j],x[jH1],x[jH2],newsite[j]); hneigh[j][0] = jH1; hneigh[j][1] = jH2; hneigh[j][2] = 1; } else { jH1 = hneigh[j][0]; jH2 = hneigh[j][1]; if (hneigh[j][2] == 0) { hneigh[j][2] = 1; compute_newsite(x[j],x[jH1],x[jH2],newsite[j]); } } x2 = newsite[j]; } else x2 = x[j]; delx = x1[0] - x2[0]; dely = x1[1] - x2[1]; delz = x1[2] - x2[2]; rsq = delx*delx + dely*dely + delz*delz; } // test current rsq against cutoff and compute Coulombic force if (rsq < cut_coulsq && rsq >= cut_in_off_sq && rsq <= cut_out_off_sq) { r2inv = 1.0 / rsq; qri = qqrd2e*qtmp; if (ni == 0) forcecoul = qri*q[j]*sqrt(r2inv); else { forcecoul = qri*q[j]*sqrt(r2inv)*special_coul[ni]; } if (rsq < cut_in_on_sq) { // switching register double rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; forcecoul *= rsw*rsw*(3.0 - 2.0*rsw); } if (rsq > cut_out_on_sq) { register double rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; forcecoul *= 1.0 + rsw*rsw*(2.0*rsw-3.0); } cforce = forcecoul * r2inv; //if (evflag) ev_tally(i,j,nlocal,newton_pair, // evdwl,0.0,cforce,delx,dely,delz); // if i,j are not O atoms, force is applied directly // if i or j are O atoms, force is on fictitious atom & partitioned // force partitioning due to Feenstra, J Comp Chem, 20, 786 (1999) // f_f = fictitious force, fO = f_f (1 - 2 alpha), fH = alpha f_f // preserves total force and torque on water molecule // virial = sum(r x F) where each water's atoms are near xi and xj // vlist stores 2,4,6 atoms whose forces contribute to virial if (itype != typeO) { f[i][0] += delx * cforce; f[i][1] += dely * cforce; f[i][2] += delz * cforce; } else { fd[0] = delx*cforce; fd[1] = dely*cforce; fd[2] = delz*cforce; fO[0] = fd[0]*(1 - alpha); fO[1] = fd[1]*(1 - alpha); fO[2] = fd[2]*(1 - alpha); fH[0] = 0.5 * alpha * fd[0]; fH[1] = 0.5 * alpha * fd[1]; fH[2] = 0.5 * alpha * fd[2]; f[i][0] += fO[0]; f[i][1] += fO[1]; f[i][2] += fO[2]; f[iH1][0] += fH[0]; f[iH1][1] += fH[1]; f[iH1][2] += fH[2]; f[iH2][0] += fH[0]; f[iH2][1] += fH[1]; f[iH2][2] += fH[2]; } if (jtype != typeO) { f[j][0] -= delx * cforce; f[j][1] -= dely * cforce; f[j][2] -= delz * cforce; } else { fd[0] = -delx*cforce; fd[1] = -dely*cforce; fd[2] = -delz*cforce; fO[0] = fd[0]*(1 - alpha); fO[1] = fd[1]*(1 - alpha); fO[2] = fd[2]*(1 - alpha); fH[0] = 0.5 * alpha * fd[0]; fH[1] = 0.5 * alpha * fd[1]; fH[2] = 0.5 * alpha * fd[2]; f[j][0] += fO[0]; f[j][1] += fO[1]; f[j][2] += fO[2]; f[jH1][0] += fH[0]; f[jH1][1] += fH[1]; f[jH1][2] += fH[2]; f[jH2][0] += fH[0]; f[jH2][1] += fH[1]; f[jH2][2] += fH[2]; } } } } } } /* --------------------------------------------------------------------- */ void PairLJLongTIP4PLong::compute_outer(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; int n,vlist[6]; int key; int iH1,iH2,jH1,jH2; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul; double r2inv,forcecoul,forcelj,cforce, respa_coul, respa_lj, frespa,fvirial; double fO[3],fH[3],fd[3],v[6]; double *x1,*x2,*xH1,*xH2; int *ilist,*jlist,*numneigh,**firstneigh; double rsq,qri; int respa_flag; evdwl = ecoul = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = vflag_fdotr = 0; // reallocate hneigh & newsite if necessary // initialize hneigh[0] to -1 on steps when reneighboring occurred // initialize hneigh[2] to 0 every step int nlocal = atom->nlocal; int nall = nlocal + atom->nghost; if (atom->nmax > nmax) { nmax = atom->nmax; memory->destroy(hneigh); memory->create(hneigh,nmax,3,"pair:hneigh"); memory->destroy(newsite); memory->create(newsite,nmax,3,"pair:newsite"); } if (neighbor->ago == 0) { for (i = 0; i < nall; i++) hneigh[i][0] = -1; for (i = 0; i < nall; i++) hneigh[i][2] = 0; } double **f = atom->f; double **x = atom->x; double *q = atom->q; tagint *tag = atom->tag; int *type = atom->type; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; double cut_coulsqplus = (cut_coul+2.0*qdist)*(cut_coul+2.0*qdist); int order1 = ewald_order&(1<<1), order6 = ewald_order&(1<<6); int ni; double *lj1i, *lj2i, *lj3i, *lj4i, *offseti; double g2 = g_ewald_6*g_ewald_6, g6 = g2*g2*g2, g8 = g6*g2; double cut_in_off = cut_respa[2]; double cut_in_on = cut_respa[3]; double cut_in_diff = cut_in_on - cut_in_off; double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; - inum = listouter->inum; - ilist = listouter->ilist; - numneigh = listouter->numneigh; - firstneigh = listouter->firstneigh; + inum = list->inum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; qri = qtmp*qqrd2e; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; if (itype == typeO) { if (hneigh[i][0] < 0) { iH1 = atom->map(tag[i] + 1); iH2 = atom->map(tag[i] + 2); if (iH1 == -1 || iH2 == -1) error->one(FLERR,"TIP4P hydrogen is missing"); if (atom->type[iH1] != typeH || atom->type[iH2] != typeH) error->one(FLERR,"TIP4P hydrogen has incorrect atom type"); // set iH1,iH2 to closest image to O iH1 = domain->closest_image(i,iH1); iH2 = domain->closest_image(i,iH2); compute_newsite(x[i],x[iH1],x[iH2],newsite[i]); hneigh[i][0] = iH1; hneigh[i][1] = iH2; hneigh[i][2] = 1; } else { iH1 = hneigh[i][0]; iH2 = hneigh[i][1]; if (hneigh[i][2] == 0) { hneigh[i][2] = 1; compute_newsite(x[i],x[iH1],x[iH2],newsite[i]); } } x1 = newsite[i]; } else x1 = x[i]; jlist = firstneigh[i]; jnum = numneigh[i]; offseti = offset[itype]; lj1i = lj1[itype]; lj2i = lj2[itype]; lj3i = lj3[itype]; lj4i = lj4[itype]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; ni = sbmask(j); j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; respa_coul = 0; respa_lj = 0; if (rsq < cut_ljsq[itype][jtype]) { // lj frespa = 1.0; // check whether and how to compute respa corrections respa_flag = rsq < cut_in_on_sq ? 1 : 0; if (respa_flag && (rsq > cut_in_off_sq)) { register double rsw = (sqrt(rsq)-cut_in_off)/cut_in_diff; frespa = 1-rsw*rsw*(3.0-2.0*rsw); } r2inv = 1.0/rsq; register double rn = r2inv*r2inv*r2inv; if (respa_flag) respa_lj = ni == 0 ? // correct for respa frespa*rn*(rn*lj1i[jtype]-lj2i[jtype]) : frespa*rn*(rn*lj1i[jtype]-lj2i[jtype])*special_lj[ni]; if (order6) { // long-range form if (!ndisptablebits || rsq <= tabinnerdispsq) { register double x2 = g2*rsq, a2 = 1.0/x2; x2 = a2*exp(-x2)*lj4i[jtype]; if (ni == 0) { forcelj = (rn*=rn)*lj1i[jtype]-g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq-respa_lj; if (eflag) evdwl = rn*lj3i[jtype]-g6*((a2+1.0)*a2+0.5)*x2; } else { // correct for special register double f = special_lj[ni], t = rn*(1.0-f); forcelj = f*(rn *= rn)*lj1i[jtype]- g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq+t*lj2i[jtype]-respa_lj; if (eflag) evdwl = f*rn*lj3i[jtype]-g6*((a2+1.0)*a2+0.5)*x2+t*lj4i[jtype]; } } else { // table real space register union_int_float_t disp_t; disp_t.f = rsq; register const int disp_k = (disp_t.i & ndispmask)>>ndispshiftbits; register double f_disp = (rsq-rdisptable[disp_k])*drdisptable[disp_k]; if (ni == 0) { forcelj = (rn*=rn)*lj1i[jtype]-(fdisptable[disp_k]+f_disp*dfdisptable[disp_k])*lj4i[jtype]-respa_lj; if (eflag) evdwl = rn*lj3i[jtype]-(edisptable[disp_k]+f_disp*dedisptable[disp_k])*lj4i[jtype]; } else { // special case register double f = special_lj[ni], t = rn*(1.0-f); forcelj = f*(rn *= rn)*lj1i[jtype]-(fdisptable[disp_k]+f_disp*dfdisptable[disp_k])*lj4i[jtype]+t*lj2i[jtype]-respa_lj; if (eflag) evdwl = f*rn*lj3i[jtype]-(edisptable[disp_k]+f_disp*dedisptable[disp_k])*lj4i[jtype]+t*lj4i[jtype]; } } } else { // cut form if (ni == 0) { forcelj = rn*(rn*lj1i[jtype]-lj2i[jtype])-respa_lj; if (eflag) evdwl = rn*(rn*lj3i[jtype]-lj4i[jtype])-offseti[jtype]; } else { // correct for special register double f = special_lj[ni]; forcelj = f*rn*(rn*lj1i[jtype]-lj2i[jtype])-respa_lj; if (eflag) evdwl = f*(rn*(rn*lj3i[jtype]-lj4i[jtype])-offseti[jtype]); } } forcelj *= r2inv; f[i][0] += delx*forcelj; f[i][1] += dely*forcelj; f[i][2] += delz*forcelj; f[j][0] -= delx*forcelj; f[j][1] -= dely*forcelj; f[j][2] -= delz*forcelj; if (evflag) { fvirial = forcelj + respa_lj*r2inv; ev_tally(i,j,nlocal,newton_pair, evdwl,0.0,fvirial,delx,dely,delz); } } // adjust rsq and delxyz for off-site O charge(s) // ADDITIONAL REQEUST REQUIRED HERE!!!!! if (rsq < cut_coulsqplus) { if (itype == typeO || jtype == typeO) { if (jtype == typeO) { if (hneigh[j][0] < 0) { jH1 = atom->map(tag[j] + 1); jH2 = atom->map(tag[j] + 2); if (jH1 == -1 || jH2 == -1) error->one(FLERR,"TIP4P hydrogen is missing"); if (atom->type[jH1] != typeH || atom->type[jH2] != typeH) error->one(FLERR,"TIP4P hydrogen has incorrect atom type"); // set jH1,jH2 to closest image to O jH1 = domain->closest_image(j,jH1); jH2 = domain->closest_image(j,jH2); compute_newsite(x[j],x[jH1],x[jH2],newsite[j]); hneigh[j][0] = jH1; hneigh[j][1] = jH2; hneigh[j][2] = 1; } else { jH1 = hneigh[j][0]; jH2 = hneigh[j][1]; if (hneigh[j][2] == 0) { hneigh[j][2] = 1; compute_newsite(x[j],x[jH1],x[jH2],newsite[j]); } } x2 = newsite[j]; } else x2 = x[j]; delx = x1[0] - x2[0]; dely = x1[1] - x2[1]; delz = x1[2] - x2[2]; rsq = delx*delx + dely*dely + delz*delz; } // test current rsq against cutoff and compute Coulombic force if ((rsq < cut_coulsq) && order1) { frespa = 1.0; // check whether and how to compute respa corrections respa_flag = rsq < cut_in_on_sq ? 1 : 0; if (respa_flag && (rsq > cut_in_off_sq)) { register double rsw = (sqrt(rsq)-cut_in_off)/cut_in_diff; frespa = 1-rsw*rsw*(3.0-2.0*rsw); } r2inv = 1.0 / rsq; if (!ncoultablebits || rsq <= tabinnersq) { // series real space register double r = sqrt(rsq), s = qri*q[j]; if (respa_flag) // correct for respa respa_coul = ni == 0 ? frespa*s/r : frespa*s/r*special_coul[ni]; register double x = g_ewald*r, t = 1.0/(1.0+EWALD_P*x); if (ni == 0) { s *= g_ewald*exp(-x*x); forcecoul = (t *= ((((t*A5+A4)*t+A3)*t+A2)*t+A1)*s/x)+EWALD_F*s-respa_coul; if (eflag) ecoul = t; } else { // correct for special r = s*(1.0-special_coul[ni])/r; s *= g_ewald*exp(-x*x); forcecoul = (t *= ((((t*A5+A4)*t+A3)*t+A2)*t+A1)*s/x)+EWALD_F*s-r-respa_coul; if (eflag) ecoul = t-r; } } // table real space else { if (respa_flag) { register double r = sqrt(rsq), s = qri*q[j]; respa_coul = ni == 0 ? frespa*s/r : frespa*s/r*special_coul[ni]; } register union_int_float_t t; t.f = rsq; register const int k = (t.i & ncoulmask) >> ncoulshiftbits; register double f = (t.f-rtable[k])*drtable[k], qiqj = qtmp*q[j]; if (ni == 0) { forcecoul = qiqj*(ftable[k]+f*dftable[k]); if (eflag) ecoul = qiqj*(etable[k]+f*detable[k]); } else { // correct for special t.f = (1.0-special_coul[ni])*(ctable[k]+f*dctable[k]); forcecoul = qiqj*(ftable[k]+f*dftable[k]-t.f); if (eflag) { t.f = (1.0-special_coul[ni])*(ptable[k]+f*dptable[k]); ecoul = qiqj*(etable[k]+f*detable[k]-t.f); } } } cforce = forcecoul * r2inv; fvirial = (forcecoul + respa_coul) * r2inv; // if i,j are not O atoms, force is applied directly // if i or j are O atoms, force is on fictitious atom & partitioned // force partitioning due to Feenstra, J Comp Chem, 20, 786 (1999) // f_f = fictitious force, fO = f_f (1 - 2 alpha), fH = alpha f_f // preserves total force and torque on water molecule // virial = sum(r x F) where each water's atoms are near xi and xj // vlist stores 2,4,6 atoms whose forces contribute to virial n = 0; key = 0; if (itype != typeO) { f[i][0] += delx * cforce; f[i][1] += dely * cforce; f[i][2] += delz * cforce; if (vflag) { v[0] = x[i][0] * delx * fvirial; v[1] = x[i][1] * dely * fvirial; v[2] = x[i][2] * delz * fvirial; v[3] = x[i][0] * dely * fvirial; v[4] = x[i][0] * delz * fvirial; v[5] = x[i][1] * delz * fvirial; } vlist[n++] = i; } else { key += 1; fd[0] = delx*cforce; fd[1] = dely*cforce; fd[2] = delz*cforce; fO[0] = fd[0]*(1 - alpha); fO[1] = fd[1]*(1 - alpha); fO[2] = fd[2]*(1 - alpha); fH[0] = 0.5 * alpha * fd[0]; fH[1] = 0.5 * alpha * fd[1]; fH[2] = 0.5 * alpha * fd[2]; f[i][0] += fO[0]; f[i][1] += fO[1]; f[i][2] += fO[2]; f[iH1][0] += fH[0]; f[iH1][1] += fH[1]; f[iH1][2] += fH[2]; f[iH2][0] += fH[0]; f[iH2][1] += fH[1]; f[iH2][2] += fH[2]; if (vflag) { fd[0] = delx*fvirial; fd[1] = dely*fvirial; fd[2] = delz*fvirial; fO[0] = fd[0]*(1 - alpha); fO[1] = fd[1]*(1 - alpha); fO[2] = fd[2]*(1 - alpha); fH[0] = 0.5 * alpha * fd[0]; fH[1] = 0.5 * alpha * fd[1]; fH[2] = 0.5 * alpha * fd[2]; xH1 = x[iH1]; xH2 = x[iH2]; v[0] = x[i][0]*fO[0] + xH1[0]*fH[0] + xH2[0]*fH[0]; v[1] = x[i][1]*fO[1] + xH1[1]*fH[1] + xH2[1]*fH[1]; v[2] = x[i][2]*fO[2] + xH1[2]*fH[2] + xH2[2]*fH[2]; v[3] = x[i][0]*fO[1] + xH1[0]*fH[1] + xH2[0]*fH[1]; v[4] = x[i][0]*fO[2] + xH1[0]*fH[2] + xH2[0]*fH[2]; v[5] = x[i][1]*fO[2] + xH1[1]*fH[2] + xH2[1]*fH[2]; } vlist[n++] = i; vlist[n++] = iH1; vlist[n++] = iH2; } if (jtype != typeO) { f[j][0] -= delx * cforce; f[j][1] -= dely * cforce; f[j][2] -= delz * cforce; if (vflag) { v[0] -= x[j][0] * delx * fvirial; v[1] -= x[j][1] * dely * fvirial; v[2] -= x[j][2] * delz * fvirial; v[3] -= x[j][0] * dely * fvirial; v[4] -= x[j][0] * delz * fvirial; v[5] -= x[j][1] * delz * fvirial; } vlist[n++] = j; } else { key += 2; fd[0] = -delx*cforce; fd[1] = -dely*cforce; fd[2] = -delz*cforce; fO[0] = fd[0]*(1 - alpha); fO[1] = fd[1]*(1 - alpha); fO[2] = fd[2]*(1 - alpha); fH[0] = 0.5 * alpha * fd[0]; fH[1] = 0.5 * alpha * fd[1]; fH[2] = 0.5 * alpha * fd[2]; f[j][0] += fO[0]; f[j][1] += fO[1]; f[j][2] += fO[2]; f[jH1][0] += fH[0]; f[jH1][1] += fH[1]; f[jH1][2] += fH[2]; f[jH2][0] += fH[0]; f[jH2][1] += fH[1]; f[jH2][2] += fH[2]; if (vflag) { fd[0] = -delx*fvirial; fd[1] = -dely*fvirial; fd[2] = -delz*fvirial; fO[0] = fd[0]*(1 - alpha); fO[1] = fd[1]*(1 - alpha); fO[2] = fd[2]*(1 - alpha); fH[0] = 0.5 * alpha * fd[0]; fH[1] = 0.5 * alpha * fd[1]; fH[2] = 0.5 * alpha * fd[2]; xH1 = x[jH1]; xH2 = x[jH2]; v[0] += x[j][0]*fO[0] + xH1[0]*fH[0] + xH2[0]*fH[0]; v[1] += x[j][1]*fO[1] + xH1[1]*fH[1] + xH2[1]*fH[1]; v[2] += x[j][2]*fO[2] + xH1[2]*fH[2] + xH2[2]*fH[2]; v[3] += x[j][0]*fO[1] + xH1[0]*fH[1] + xH2[0]*fH[1]; v[4] += x[j][0]*fO[2] + xH1[0]*fH[2] + xH2[0]*fH[2]; v[5] += x[j][1]*fO[2] + xH1[1]*fH[2] + xH2[1]*fH[2]; } vlist[n++] = j; vlist[n++] = jH1; vlist[n++] = jH2; } if (evflag) ev_tally_tip4p(key,vlist,v,ecoul,alpha); } } } } } /* ---------------------------------------------------------------------- global settings ------------------------------------------------------------------------- */ void PairLJLongTIP4PLong::settings(int narg, char **arg) { if (narg < 8 || narg > 9) error->all(FLERR,"Illegal pair_style command"); ewald_off = 0; ewald_order = 0; options(arg, 6); options(++arg, 1); if (!comm->me && ewald_order&(1<<6)) error->warning(FLERR,"Mixing forced for lj coefficients"); if (!comm->me && ewald_order==((1<<1)|(1<<6))) error->warning(FLERR, "Using largest cutoff for pair_style lj/long/tip4p/long"); if (!((ewald_order^ewald_off)&(1<<1))) error->all(FLERR, "Coulomb cut not supported in pair_style lj/long/tip4p/long"); typeO = force->inumeric(FLERR,arg[1]); typeH = force->inumeric(FLERR,arg[2]); typeB = force->inumeric(FLERR,arg[3]); typeA = force->inumeric(FLERR,arg[4]); qdist = force->numeric(FLERR,arg[5]); cut_lj_global = force->numeric(FLERR,arg[6]); if (narg == 8) cut_coul = cut_lj_global; else cut_coul = force->numeric(FLERR,arg[7]); // reset cutoffs that have been explicitly set if (allocated) { int i,j; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) if (setflag[i][j]) cut_lj[i][j] = cut_lj_global; } } /* ---------------------------------------------------------------------- init specific to this pair style ------------------------------------------------------------------------- */ void PairLJLongTIP4PLong::init_style() { if (atom->tag_enable == 0) error->all(FLERR,"Pair style lj/long/tip4p/long requires atom IDs"); if (!force->newton_pair) error->all(FLERR,"Pair style lj/long/tip4p/long requires newton pair on"); if (!atom->q_flag) error->all(FLERR,"Pair style lj/long/tip4p/long requires atom attribute q"); if (force->bond == NULL) error->all(FLERR,"Must use a bond style with TIP4P potential"); if (force->angle == NULL) error->all(FLERR,"Must use an angle style with TIP4P potential"); PairLJLongCoulLong::init_style(); // set alpha parameter double theta = force->angle->equilibrium_angle(typeA); double blen = force->bond->equilibrium_distance(typeB); alpha = qdist / (cos(0.5*theta) * blen); } /* ---------------------------------------------------------------------- init for one type pair i,j and corresponding j,i ------------------------------------------------------------------------- */ double PairLJLongTIP4PLong::init_one(int i, int j) { double cut = PairLJLongCoulLong::init_one(i,j); // check that LJ epsilon = 0.0 for water H // set LJ cutoff to 0.0 for any interaction involving water H // so LJ term isn't calculated in compute() if ((i == typeH && epsilon[i][i] != 0.0)) error->all(FLERR,"Water H epsilon must be 0.0 for " "pair style lj/long/tip4p/long"); if (i == typeH || j == typeH) cut_ljsq[j][i] = cut_ljsq[i][j] = 0.0; return cut; } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairLJLongTIP4PLong::write_restart_settings(FILE *fp) { fwrite(&typeO,sizeof(int),1,fp); fwrite(&typeH,sizeof(int),1,fp); fwrite(&typeB,sizeof(int),1,fp); fwrite(&typeA,sizeof(int),1,fp); fwrite(&qdist,sizeof(double),1,fp); fwrite(&cut_lj_global,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(&ncoultablebits,sizeof(int),1,fp); fwrite(&tabinner,sizeof(double),1,fp); } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairLJLongTIP4PLong::read_restart_settings(FILE *fp) { if (comm->me == 0) { fread(&typeO,sizeof(int),1,fp); fread(&typeH,sizeof(int),1,fp); fread(&typeB,sizeof(int),1,fp); fread(&typeA,sizeof(int),1,fp); fread(&qdist,sizeof(double),1,fp); fread(&cut_lj_global,sizeof(double),1,fp); fread(&cut_coul,sizeof(double),1,fp); fread(&offset_flag,sizeof(int),1,fp); fread(&mix_flag,sizeof(int),1,fp); fread(&ncoultablebits,sizeof(int),1,fp); fread(&tabinner,sizeof(double),1,fp); } MPI_Bcast(&typeO,1,MPI_INT,0,world); MPI_Bcast(&typeH,1,MPI_INT,0,world); MPI_Bcast(&typeB,1,MPI_INT,0,world); MPI_Bcast(&typeA,1,MPI_INT,0,world); MPI_Bcast(&qdist,1,MPI_DOUBLE,0,world); MPI_Bcast(&cut_lj_global,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(&ncoultablebits,1,MPI_INT,0,world); MPI_Bcast(&tabinner,1,MPI_DOUBLE,0,world); } /* ---------------------------------------------------------------------- compute position xM of fictitious charge site for O atom and 2 H atoms return it as xM ------------------------------------------------------------------------- */ void PairLJLongTIP4PLong::compute_newsite(double *xO, double *xH1, double *xH2, double *xM) { double delx1 = xH1[0] - xO[0]; double dely1 = xH1[1] - xO[1]; double delz1 = xH1[2] - xO[2]; double delx2 = xH2[0] - xO[0]; double dely2 = xH2[1] - xO[1]; double delz2 = xH2[2] - xO[2]; xM[0] = xO[0] + alpha * 0.5 * (delx1 + delx2); xM[1] = xO[1] + alpha * 0.5 * (dely1 + dely2); xM[2] = xO[2] + alpha * 0.5 * (delz1 + delz2); } /* ---------------------------------------------------------------------- */ void *PairLJLongTIP4PLong::extract(const char *str, int &dim) { dim = 0; if (strcmp(str,"qdist") == 0) return (void *) &qdist; if (strcmp(str,"typeO") == 0) return (void *) &typeO; if (strcmp(str,"typeH") == 0) return (void *) &typeH; if (strcmp(str,"typeA") == 0) return (void *) &typeA; if (strcmp(str,"typeB") == 0) return (void *) &typeB; if (strcmp(str,"cut_coul") == 0) return (void *) &cut_coul; const char *ids[] = { "B", "sigma", "epsilon", "ewald_order", "ewald_cut", "cut_coul", "ewald_mix", "cut_LJ", NULL}; void *ptrs[] = { lj4, sigma, epsilon, &ewald_order, &cut_coul, &cut_coul, &mix_flag, &cut_lj_global, NULL}; int i; i=0; while (ids[i] != NULL) { if (i <=2) dim = 2; else dim = 0; if (strcmp(ids[i],str) == 0) return ptrs[i]; ++i; } return NULL; } /* ---------------------------------------------------------------------- memory usage of hneigh ------------------------------------------------------------------------- */ double PairLJLongTIP4PLong::memory_usage() { double bytes = maxeatom * sizeof(double); bytes += maxvatom*6 * sizeof(double); bytes += 2 * nmax * sizeof(double); return bytes; } diff --git a/src/OPT/pair_lj_long_coul_long_opt.cpp b/src/OPT/pair_lj_long_coul_long_opt.cpp index 9004e5c93..678d2d8bc 100644 --- a/src/OPT/pair_lj_long_coul_long_opt.cpp +++ b/src/OPT/pair_lj_long_coul_long_opt.cpp @@ -1,880 +1,880 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- OPT version: Wayne Mitchell (Loyola University New Orleans) ------------------------------------------------------------------------- */ #include #include "pair_lj_long_coul_long_opt.h" #include "atom.h" #include "force.h" #include "neigh_list.h" #include "math_vector.h" using namespace LAMMPS_NS; #define EWALD_F 1.12837917 #define EWALD_P 0.3275911 #define A1 0.254829592 #define A2 -0.284496736 #define A3 1.421413741 #define A4 -1.453152027 #define A5 1.061405429 /* ---------------------------------------------------------------------- */ PairLJLongCoulLongOpt::PairLJLongCoulLongOpt(LAMMPS *lmp) : PairLJLongCoulLong(lmp) { respa_enable = 1; } /* ---------------------------------------------------------------------- */ void PairLJLongCoulLongOpt::compute(int eflag, int vflag) { if (eflag || vflag) ev_setup(eflag,vflag); else evflag = vflag_fdotr = 0; int order1 = ewald_order&(1<<1), order6 = ewald_order&(1<<6); if (order6) { if (order1) { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) return eval<1,1,1,0,0,1,1>(); else return eval<1,1,0,0,0,1,1>(); } else { if (force->newton_pair) return eval<1,0,1,0,0,1,1>(); else return eval<1,0,0,0,0,1,1>(); } } else { if (force->newton_pair) return eval<0,0,1,0,0,1,1>(); else return eval<0,0,0,0,0,1,1>(); } } else { if (evflag) { if (eflag) { if (force->newton_pair) return eval<1,1,1,1,0,1,1>(); else return eval<1,1,0,1,0,1,1>(); } else { if (force->newton_pair) return eval<1,0,1,1,0,1,1>(); else return eval<1,0,0,1,0,1,1>(); } } else { if (force->newton_pair) return eval<0,0,1,1,0,1,1>(); else return eval<0,0,0,1,0,1,1>(); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) return eval<1,1,1,0,1,1,1>(); else return eval<1,1,0,0,1,1,1>(); } else { if (force->newton_pair) return eval<1,0,1,0,1,1,1>(); else return eval<1,0,0,0,1,1,1>(); } } else { if (force->newton_pair) return eval<0,0,1,0,1,1,1>(); else return eval<0,0,0,0,1,1,1>(); } } else { if (evflag) { if (eflag) { if (force->newton_pair) return eval<1,1,1,1,1,1,1>(); else return eval<1,1,0,1,1,1,1>(); } else { if (force->newton_pair) return eval<1,0,1,1,1,1,1>(); else return eval<1,0,0,1,1,1,1>(); } } else { if (force->newton_pair) return eval<0,0,1,1,1,1,1>(); else return eval<0,0,0,1,1,1,1>(); } } } } else { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) return eval<1,1,1,0,0,0,1>(); else return eval<1,1,0,0,0,0,1>(); } else { if (force->newton_pair) return eval<1,0,1,0,0,0,1>(); else return eval<1,0,0,0,0,0,1>(); } } else { if (force->newton_pair) return eval<0,0,1,0,0,0,1>(); else return eval<0,0,0,0,0,0,1>(); } } else { if (evflag) { if (eflag) { if (force->newton_pair) return eval<1,1,1,1,0,0,1>(); else return eval<1,1,0,1,0,0,1>(); } else { if (force->newton_pair) return eval<1,0,1,1,0,0,1>(); else return eval<1,0,0,1,0,0,1>(); } } else { if (force->newton_pair) return eval<0,0,1,1,0,0,1>(); else return eval<0,0,0,1,0,0,1>(); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) return eval<1,1,1,0,1,0,1>(); else return eval<1,1,0,0,1,0,1>(); } else { if (force->newton_pair) return eval<1,0,1,0,1,0,1>(); else return eval<1,0,0,0,1,0,1>(); } } else { if (force->newton_pair) return eval<0,0,1,0,1,0,1>(); else return eval<0,0,0,0,1,0,1>(); } } else { if (evflag) { if (eflag) { if (force->newton_pair) return eval<1,1,1,1,1,0,1>(); else return eval<1,1,0,1,1,0,1>(); } else { if (force->newton_pair) return eval<1,0,1,1,1,0,1>(); else return eval<1,0,0,1,1,0,1>(); } } else { if (force->newton_pair) return eval<0,0,1,1,1,0,1>(); else return eval<0,0,0,1,1,0,1>(); } } } } } else { if (order1) { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) return eval<1,1,1,0,0,1,0>(); else return eval<1,1,0,0,0,1,0>(); } else { if (force->newton_pair) return eval<1,0,1,0,0,1,0>(); else return eval<1,0,0,0,0,1,0>(); } } else { if (force->newton_pair) return eval<0,0,1,0,0,1,0>(); else return eval<0,0,0,0,0,1,0>(); } } else { if (evflag) { if (eflag) { if (force->newton_pair) return eval<1,1,1,1,0,1,0>(); else return eval<1,1,0,1,0,1,0>(); } else { if (force->newton_pair) return eval<1,0,1,1,0,1,0>(); else return eval<1,0,0,1,0,1,0>(); } } else { if (force->newton_pair) return eval<0,0,1,1,0,1,0>(); else return eval<0,0,0,1,0,1,0>(); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) return eval<1,1,1,0,1,1,0>(); else return eval<1,1,0,0,1,1,0>(); } else { if (force->newton_pair) return eval<1,0,1,0,1,1,0>(); else return eval<1,0,0,0,1,1,0>(); } } else { if (force->newton_pair) return eval<0,0,1,0,1,1,0>(); else return eval<0,0,0,0,1,1,0>(); } } else { if (evflag) { if (eflag) { if (force->newton_pair) return eval<1,1,1,1,1,1,0>(); else return eval<1,1,0,1,1,1,0>(); } else { if (force->newton_pair) return eval<1,0,1,1,1,1,0>(); else return eval<1,0,0,1,1,1,0>(); } } else { if (force->newton_pair) return eval<0,0,1,1,1,1,0>(); else return eval<0,0,0,1,1,1,0>(); } } } } else { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) return eval<1,1,1,0,0,0,0>(); else return eval<1,1,0,0,0,0,0>(); } else { if (force->newton_pair) return eval<1,0,1,0,0,0,0>(); else return eval<1,0,0,0,0,0,0>(); } } else { if (force->newton_pair) return eval<0,0,1,0,0,0,0>(); else return eval<0,0,0,0,0,0,0>(); } } else { if (evflag) { if (eflag) { if (force->newton_pair) return eval<1,1,1,1,0,0,0>(); else return eval<1,1,0,1,0,0,0>(); } else { if (force->newton_pair) return eval<1,0,1,1,0,0,0>(); else return eval<1,0,0,1,0,0,0>(); } } else { if (force->newton_pair) return eval<0,0,1,1,0,0,0>(); else return eval<0,0,0,1,0,0,0>(); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) return eval<1,1,1,0,1,0,0>(); else return eval<1,1,0,0,1,0,0>(); } else { if (force->newton_pair) return eval<1,0,1,0,1,0,0>(); else return eval<1,0,0,0,1,0,0>(); } } else { if (force->newton_pair) return eval<0,0,1,0,1,0,0>(); else return eval<0,0,0,0,1,0,0>(); } } else { if (evflag) { if (eflag) { if (force->newton_pair) return eval<1,1,1,1,1,0,0>(); else return eval<1,1,0,1,1,0,0>(); } else { if (force->newton_pair) return eval<1,0,1,1,1,0,0>(); else return eval<1,0,0,1,1,0,0>(); } } else { if (force->newton_pair) return eval<0,0,1,1,1,0,0>(); else return eval<0,0,0,1,1,0,0>(); } } } } } } void PairLJLongCoulLongOpt::compute_outer(int eflag, int vflag) { if (eflag || vflag) ev_setup(eflag,vflag); else evflag = vflag_fdotr = 0; int order1 = ewald_order&(1<<1), order6 = ewald_order&(1<<6); if (order6) { if (order1) { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) return eval_outer<1,1,1,0,0,1,1>(); else return eval_outer<1,1,0,0,0,1,1>(); } else { if (force->newton_pair) return eval_outer<1,0,1,0,0,1,1>(); else return eval_outer<1,0,0,0,0,1,1>(); } } else { if (force->newton_pair) return eval_outer<0,0,1,0,0,1,1>(); else return eval_outer<0,0,0,0,0,1,1>(); } } else { if (evflag) { if (eflag) { if (force->newton_pair) return eval_outer<1,1,1,1,0,1,1>(); else return eval_outer<1,1,0,1,0,1,1>(); } else { if (force->newton_pair) return eval_outer<1,0,1,1,0,1,1>(); else return eval_outer<1,0,0,1,0,1,1>(); } } else { if (force->newton_pair) return eval_outer<0,0,1,1,0,1,1>(); else return eval_outer<0,0,0,1,0,1,1>(); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) return eval_outer<1,1,1,0,1,1,1>(); else return eval_outer<1,1,0,0,1,1,1>(); } else { if (force->newton_pair) return eval_outer<1,0,1,0,1,1,1>(); else return eval_outer<1,0,0,0,1,1,1>(); } } else { if (force->newton_pair) return eval_outer<0,0,1,0,1,1,1>(); else return eval_outer<0,0,0,0,1,1,1>(); } } else { if (evflag) { if (eflag) { if (force->newton_pair) return eval_outer<1,1,1,1,1,1,1>(); else return eval_outer<1,1,0,1,1,1,1>(); } else { if (force->newton_pair) return eval_outer<1,0,1,1,1,1,1>(); else return eval_outer<1,0,0,1,1,1,1>(); } } else { if (force->newton_pair) return eval_outer<0,0,1,1,1,1,1>(); else return eval_outer<0,0,0,1,1,1,1>(); } } } } else { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) return eval_outer<1,1,1,0,0,0,1>(); else return eval_outer<1,1,0,0,0,0,1>(); } else { if (force->newton_pair) return eval_outer<1,0,1,0,0,0,1>(); else return eval_outer<1,0,0,0,0,0,1>(); } } else { if (force->newton_pair) return eval_outer<0,0,1,0,0,0,1>(); else return eval_outer<0,0,0,0,0,0,1>(); } } else { if (evflag) { if (eflag) { if (force->newton_pair) return eval_outer<1,1,1,1,0,0,1>(); else return eval_outer<1,1,0,1,0,0,1>(); } else { if (force->newton_pair) return eval_outer<1,0,1,1,0,0,1>(); else return eval_outer<1,0,0,1,0,0,1>(); } } else { if (force->newton_pair) return eval_outer<0,0,1,1,0,0,1>(); else return eval_outer<0,0,0,1,0,0,1>(); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) return eval_outer<1,1,1,0,1,0,1>(); else return eval_outer<1,1,0,0,1,0,1>(); } else { if (force->newton_pair) return eval_outer<1,0,1,0,1,0,1>(); else return eval_outer<1,0,0,0,1,0,1>(); } } else { if (force->newton_pair) return eval_outer<0,0,1,0,1,0,1>(); else return eval_outer<0,0,0,0,1,0,1>(); } } else { if (evflag) { if (eflag) { if (force->newton_pair) return eval_outer<1,1,1,1,1,0,1>(); else return eval_outer<1,1,0,1,1,0,1>(); } else { if (force->newton_pair) return eval_outer<1,0,1,1,1,0,1>(); else return eval_outer<1,0,0,1,1,0,1>(); } } else { if (force->newton_pair) return eval_outer<0,0,1,1,1,0,1>(); else return eval_outer<0,0,0,1,1,0,1>(); } } } } } else { if (order1) { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) return eval_outer<1,1,1,0,0,1,0>(); else return eval_outer<1,1,0,0,0,1,0>(); } else { if (force->newton_pair) return eval_outer<1,0,1,0,0,1,0>(); else return eval_outer<1,0,0,0,0,1,0>(); } } else { if (force->newton_pair) return eval_outer<0,0,1,0,0,1,0>(); else return eval_outer<0,0,0,0,0,1,0>(); } } else { if (evflag) { if (eflag) { if (force->newton_pair) return eval_outer<1,1,1,1,0,1,0>(); else return eval_outer<1,1,0,1,0,1,0>(); } else { if (force->newton_pair) return eval_outer<1,0,1,1,0,1,0>(); else return eval_outer<1,0,0,1,0,1,0>(); } } else { if (force->newton_pair) return eval_outer<0,0,1,1,0,1,0>(); else return eval_outer<0,0,0,1,0,1,0>(); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) return eval_outer<1,1,1,0,1,1,0>(); else return eval_outer<1,1,0,0,1,1,0>(); } else { if (force->newton_pair) return eval_outer<1,0,1,0,1,1,0>(); else return eval_outer<1,0,0,0,1,1,0>(); } } else { if (force->newton_pair) return eval_outer<0,0,1,0,1,1,0>(); else return eval_outer<0,0,0,0,1,1,0>(); } } else { if (evflag) { if (eflag) { if (force->newton_pair) return eval_outer<1,1,1,1,1,1,0>(); else return eval_outer<1,1,0,1,1,1,0>(); } else { if (force->newton_pair) return eval_outer<1,0,1,1,1,1,0>(); else return eval_outer<1,0,0,1,1,1,0>(); } } else { if (force->newton_pair) return eval_outer<0,0,1,1,1,1,0>(); else return eval_outer<0,0,0,1,1,1,0>(); } } } } else { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) return eval_outer<1,1,1,0,0,0,0>(); else return eval_outer<1,1,0,0,0,0,0>(); } else { if (force->newton_pair) return eval_outer<1,0,1,0,0,0,0>(); else return eval_outer<1,0,0,0,0,0,0>(); } } else { if (force->newton_pair) return eval_outer<0,0,1,0,0,0,0>(); else return eval_outer<0,0,0,0,0,0,0>(); } } else { if (evflag) { if (eflag) { if (force->newton_pair) return eval_outer<1,1,1,1,0,0,0>(); else return eval_outer<1,1,0,1,0,0,0>(); } else { if (force->newton_pair) return eval_outer<1,0,1,1,0,0,0>(); else return eval_outer<1,0,0,1,0,0,0>(); } } else { if (force->newton_pair) return eval_outer<0,0,1,1,0,0,0>(); else return eval_outer<0,0,0,1,0,0,0>(); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) return eval_outer<1,1,1,0,1,0,0>(); else return eval_outer<1,1,0,0,1,0,0>(); } else { if (force->newton_pair) return eval_outer<1,0,1,0,1,0,0>(); else return eval_outer<1,0,0,0,1,0,0>(); } } else { if (force->newton_pair) return eval_outer<0,0,1,0,1,0,0>(); else return eval_outer<0,0,0,0,1,0,0>(); } } else { if (evflag) { if (eflag) { if (force->newton_pair) return eval_outer<1,1,1,1,1,0,0>(); else return eval_outer<1,1,0,1,1,0,0>(); } else { if (force->newton_pair) return eval_outer<1,0,1,1,1,0,0>(); else return eval_outer<1,0,0,1,1,0,0>(); } } else { if (force->newton_pair) return eval_outer<0,0,1,1,1,0,0>(); else return eval_outer<0,0,0,1,1,0,0>(); } } } } } } template < const int EVFLAG, const int EFLAG, const int NEWTON_PAIR, const int CTABLE, const int LJTABLE, const int ORDER1, const int ORDER6 > void PairLJLongCoulLongOpt::eval() { double evdwl,ecoul,fpair; evdwl = ecoul = 0.0; double **x = atom->x, *x0 = x[0]; double **f = atom->f, *f0 = f[0], *fi = f0; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; double qqrd2e = force->qqrd2e; int i, j; int *ineigh, *ineighn, *jneigh, *jneighn, typei, typej, ni; double qi = 0.0, qri = 0.0; double *cutsqi, *cut_ljsqi, *lj1i, *lj2i, *lj3i, *lj4i, *offseti; double rsq, r2inv, force_coul, force_lj; double g2 = g_ewald_6*g_ewald_6, g6 = g2*g2*g2, g8 = g6*g2; vector xi, d; ineighn = (ineigh = list->ilist)+list->inum; for (; ineighfirstneigh[i])+list->numneigh[i]; for (; jneigh= cutsqi[typej = type[j]]) continue; r2inv = 1.0/rsq; if (ORDER1 && (rsq < cut_coulsq)) { // coulombic if (!CTABLE || rsq <= tabinnersq) { // series real space register double r = sqrt(rsq), x = g_ewald*r; register double s = qri*q[j], t = 1.0/(1.0+EWALD_P*x); if (ni == 0) { s *= g_ewald*exp(-x*x); force_coul = (t *= ((((t*A5+A4)*t+A3)*t+A2)*t+A1)*s/x)+EWALD_F*s; if (EFLAG) ecoul = t; } else { // special case r = s*(1.0-special_coul[ni])/r; s *= g_ewald*exp(-x*x); force_coul = (t *= ((((t*A5+A4)*t+A3)*t+A2)*t+A1)*s/x)+EWALD_F*s-r; if (EFLAG) ecoul = t-r; } } // table real space else { register union_int_float_t t; t.f = rsq; register const int k = (t.i & ncoulmask)>>ncoulshiftbits; register double f = (rsq-rtable[k])*drtable[k], qiqj = qi*q[j]; if (ni == 0) { force_coul = qiqj*(ftable[k]+f*dftable[k]); if (EFLAG) ecoul = qiqj*(etable[k]+f*detable[k]); } else { // special case t.f = (1.0-special_coul[ni])*(ctable[k]+f*dctable[k]); force_coul = qiqj*(ftable[k]+f*dftable[k]-t.f); if (EFLAG) ecoul = qiqj*(etable[k]+f*detable[k]-t.f); } } } else force_coul = ecoul = 0.0; if (rsq < cut_ljsqi[typej]) { // lj if (ORDER6) { // long-range lj if(!LJTABLE || rsq <= tabinnerdispsq) { // series real space register double rn = r2inv*r2inv*r2inv; register double x2 = g2*rsq, a2 = 1.0/x2; x2 = a2*exp(-x2)*lj4i[typej]; if (ni == 0) { force_lj = (rn*=rn)*lj1i[typej]-g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq; if (EFLAG) evdwl = rn*lj3i[typej]-g6*((a2+1.0)*a2+0.5)*x2; } else { // special case register double f = special_lj[ni], t = rn*(1.0-f); force_lj = f*(rn *= rn)*lj1i[typej]- g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq+t*lj2i[typej]; if (EFLAG) evdwl = f*rn*lj3i[typej]-g6*((a2+1.0)*a2+0.5)*x2+t*lj4i[typej]; } } else { // table real space register union_int_float_t disp_t; disp_t.f = rsq; register const int disp_k = (disp_t.i & ndispmask)>>ndispshiftbits; register double f_disp = (rsq-rdisptable[disp_k])*drdisptable[disp_k]; register double rn = r2inv*r2inv*r2inv; if (ni == 0) { force_lj = (rn*=rn)*lj1i[typej]-(fdisptable[disp_k]+f_disp*dfdisptable[disp_k])*lj4i[typej]; if (EFLAG) evdwl = rn*lj3i[typej]-(edisptable[disp_k]+f_disp*dedisptable[disp_k])*lj4i[typej]; } else { // special case register double f = special_lj[ni], t = rn*(1.0-f); force_lj = f*(rn *= rn)*lj1i[typej]-(fdisptable[disp_k]+f_disp*dfdisptable[disp_k])*lj4i[typej]+t*lj2i[typej]; if (EFLAG) evdwl = f*rn*lj3i[typej]-(edisptable[disp_k]+f_disp*dedisptable[disp_k])*lj4i[typej]+t*lj4i[typej]; } } } else { // cut lj register double rn = r2inv*r2inv*r2inv; if (ni == 0) { force_lj = rn*(rn*lj1i[typej]-lj2i[typej]); if (EFLAG) evdwl = rn*(rn*lj3i[typej]-lj4i[typej])-offseti[typej]; } else { // special case register double f = special_lj[ni]; force_lj = f*rn*(rn*lj1i[typej]-lj2i[typej]); if (EFLAG) evdwl = f * (rn*(rn*lj3i[typej]-lj4i[typej])-offseti[typej]); } } } else force_lj = evdwl = 0.0; fpair = (force_coul+force_lj)*r2inv; if (NEWTON_PAIR || j < nlocal) { register double *fj = f0+(j+(j<<1)), f; fi[0] += f = d[0]*fpair; fj[0] -= f; fi[1] += f = d[1]*fpair; fj[1] -= f; fi[2] += f = d[2]*fpair; fj[2] -= f; } else { fi[0] += d[0]*fpair; fi[1] += d[1]*fpair; fi[2] += d[2]*fpair; } if (EVFLAG) ev_tally(i,j,nlocal,NEWTON_PAIR, evdwl,ecoul,fpair,d[0],d[1],d[2]); } } if (vflag_fdotr) virial_fdotr_compute(); } /* ---------------------------------------------------------------------- */ template < const int EVFLAG, const int EFLAG, const int NEWTON_PAIR, const int CTABLE, const int LJTABLE, const int ORDER1, const int ORDER6 > void PairLJLongCoulLongOpt::eval_outer() { double evdwl,ecoul,fvirial,fpair; evdwl = ecoul = 0.0; double **x = atom->x, *x0 = x[0]; double **f = atom->f, *f0 = f[0], *fi = f0; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; int i, j; int *ineigh, *ineighn, *jneigh, *jneighn, typei, typej, ni, respa_flag; double qi = 0.0, qri = 0.0; double *cutsqi, *cut_ljsqi, *lj1i, *lj2i, *lj3i, *lj4i, *offseti; double rsq, r2inv, force_coul, force_lj; double g2 = g_ewald_6*g_ewald_6, g6 = g2*g2*g2, g8 = g6*g2; double respa_lj = 0.0, respa_coul = 0.0, frespa = 0.0; vector xi, d; double cut_in_off = cut_respa[2]; double cut_in_on = cut_respa[3]; double cut_in_diff = cut_in_on - cut_in_off; double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; - ineighn = (ineigh = listouter->ilist)+listouter->inum; + ineighn = (ineigh = list->ilist)+list->inum; for (; ineighfirstneigh[i])+listouter->numneigh[i]; + jneighn = (jneigh = list->firstneigh[i])+list->numneigh[i]; for (; jneigh= cutsqi[typej = type[j]]) continue; r2inv = 1.0/rsq; frespa = 1.0; // check whether and how to compute respa corrections respa_coul = 0; respa_lj = 0; respa_flag = rsq < cut_in_on_sq ? 1 : 0; if (respa_flag && (rsq > cut_in_off_sq)) { register double rsw = (sqrt(rsq)-cut_in_off)/cut_in_diff; frespa = 1-rsw*rsw*(3.0-2.0*rsw); } if (ORDER1 && (rsq < cut_coulsq)) { // coulombic if (!CTABLE || rsq <= tabinnersq) { // series real space register double r = sqrt(rsq), s = qri*q[j]; if (respa_flag) // correct for respa respa_coul = ni == 0 ? frespa*s/r : frespa*s/r*special_coul[ni]; register double x = g_ewald*r, t = 1.0/(1.0+EWALD_P*x); if (ni == 0) { s *= g_ewald*exp(-x*x); force_coul = (t *= ((((t*A5+A4)*t+A3)*t+A2)*t+A1)*s/x)+EWALD_F*s-respa_coul; if (EFLAG) ecoul = t; } else { // correct for special r = s*(1.0-special_coul[ni])/r; s *= g_ewald*exp(-x*x); force_coul = (t *= ((((t*A5+A4)*t+A3)*t+A2)*t+A1)*s/x)+EWALD_F*s-r-respa_coul; if (EFLAG) ecoul = t-r; } } // table real space else { if (respa_flag) { register double r = sqrt(rsq), s = qri*q[j]; respa_coul = ni == 0 ? frespa*s/r : frespa*s/r*special_coul[ni]; } register union_int_float_t t; t.f = rsq; register const int k = (t.i & ncoulmask) >> ncoulshiftbits; register double f = (rsq-rtable[k])*drtable[k], qiqj = qi*q[j]; if (ni == 0) { force_coul = qiqj*(ftable[k]+f*dftable[k]); if (EFLAG) ecoul = qiqj*(etable[k]+f*detable[k]); } else { // correct for special t.f = (1.0-special_coul[ni])*(ctable[k]+f*dctable[k]); force_coul = qiqj*(ftable[k]+f*dftable[k]-t.f); if (EFLAG) { t.f = (1.0-special_coul[ni])*(ptable[k]+f*dptable[k]); ecoul = qiqj*(etable[k]+f*detable[k]-t.f); } } } } else force_coul = respa_coul = ecoul = 0.0; if (rsq < cut_ljsqi[typej]) { // lennard-jones register double rn = r2inv*r2inv*r2inv; if (respa_flag) respa_lj = ni == 0 ? // correct for respa frespa*rn*(rn*lj1i[typej]-lj2i[typej]) : frespa*rn*(rn*lj1i[typej]-lj2i[typej])*special_lj[ni]; if (ORDER6) { // long-range form if (!LJTABLE || rsq <= tabinnerdispsq) { register double x2 = g2*rsq, a2 = 1.0/x2; x2 = a2*exp(-x2)*lj4i[typej]; if (ni == 0) { force_lj = (rn*=rn)*lj1i[typej]-g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq-respa_lj; if (EFLAG) evdwl = rn*lj3i[typej]-g6*((a2+1.0)*a2+0.5)*x2; } else { // correct for special register double f = special_lj[ni], t = rn*(1.0-f); force_lj = f*(rn *= rn)*lj1i[typej]- g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq+t*lj2i[typej]-respa_lj; if (EFLAG) evdwl = f*rn*lj3i[typej]-g6*((a2+1.0)*a2+0.5)*x2+t*lj4i[typej]; } } else { // table real space register union_int_float_t disp_t; disp_t.f = rsq; register const int disp_k = (disp_t.i & ndispmask)>>ndispshiftbits; register double f_disp = (rsq-rdisptable[disp_k])*drdisptable[disp_k]; register double rn = r2inv*r2inv*r2inv; if (ni == 0) { force_lj = (rn*=rn)*lj1i[typej]-(fdisptable[disp_k]+f_disp*dfdisptable[disp_k])*lj4i[typej]-respa_lj; if (EFLAG) evdwl = rn*lj3i[typej]-(edisptable[disp_k]+f_disp*dedisptable[disp_k])*lj4i[typej]; } else { // special case register double f = special_lj[ni], t = rn*(1.0-f); force_lj = f*(rn *= rn)*lj1i[typej]-(fdisptable[disp_k]+f_disp*dfdisptable[disp_k])*lj4i[typej]+t*lj2i[typej]-respa_lj; if (EFLAG) evdwl = f*rn*lj3i[typej]-(edisptable[disp_k]+f_disp*dedisptable[disp_k])*lj4i[typej]+t*lj4i[typej]; } } } else { // cut form if (ni == 0) { force_lj = rn*(rn*lj1i[typej]-lj2i[typej])-respa_lj; if (EFLAG) evdwl = rn*(rn*lj3i[typej]-lj4i[typej])-offseti[typej]; } else { // correct for special register double f = special_lj[ni]; force_lj = f*rn*(rn*lj1i[typej]-lj2i[typej])-respa_lj; if (EFLAG) evdwl = f*(rn*(rn*lj3i[typej]-lj4i[typej])-offseti[typej]); } } } else force_lj = respa_lj = evdwl = 0.0; fpair = (force_coul+force_lj)*r2inv; if (NEWTON_PAIR || j < nlocal) { register double *fj = f0+(j+(j<<1)), f; fi[0] += f = d[0]*fpair; fj[0] -= f; fi[1] += f = d[1]*fpair; fj[1] -= f; fi[2] += f = d[2]*fpair; fj[2] -= f; } else { fi[0] += d[0]*fpair; fi[1] += d[1]*fpair; fi[2] += d[2]*fpair; } if (EVFLAG) { fvirial = (force_coul + force_lj + respa_coul + respa_lj)*r2inv; ev_tally(i,j,nlocal,newton_pair, evdwl,ecoul,fvirial,d[0],d[1],d[2]); } } } } diff --git a/src/Purge.list b/src/Purge.list index 7ccdf3afd..312994fdb 100644 --- a/src/Purge.list +++ b/src/Purge.list @@ -1,479 +1,482 @@ # auto-generated style files style_angle.h style_atom.h style_bond.h style_command.h style_compute.h style_dihedral.h style_dump.h style_fix.h style_improper.h style_integrate.h style_kspace.h style_minimize.h style_pair.h style_region.h style_neigh_bin.h style_neigh_pair.h style_neigh_stencil.h +# deleted on 11 October 2017 +fix_shear_history_omp.cpp +fix_shear_history_omp.h # deleted on 5 September 2017 npair_halffull_newton_ssa.cpp npair_halffull_newton_ssa.h # deleted on 6 June 2017 pair_lj_sf.cpp pair_lj_sf.h pair_lj_sf_omp.cpp pair_lj_sf_omp.h # deleted on 4 May 2017 dump_custom_vtk.cpp dump_custom_vtk.h dump_nc.cpp dump_nc.h dump_nc_mpiio.cpp dump_nc_mpiio.h pair_reax_c.cpp pair_reax_c.h fix_reax_c.cpp fix_reax_c.h fix_reax_c_bonds.cpp fix_reax_c_bonds.h fix_reax_c_species.cpp fix_reax_c_species.h pair_reax_c_kokkos.cpp pair_reax_c_kokkos.h fix_reax_c_bonds_kokkos.cpp fix_reax_c_bonds_kokkos.h fix_reax_c_species_kokkos.cpp fix_reax_c_species_kokkos.h # deleted on 19 April 2017 vmdplugin.h molfile_plugin.h # deleted on 13 April 2017 dihedral_charmmfsh.cpp dihedral_charmmfsh.h # deleted on ## XXX 2016 accelerator_intel.h neigh_bond.cpp neigh_bond.h neigh_derive.cpp neigh_derive.h neigh_full.cpp neigh_full.h neigh_gran.cpp neigh_gran.h neigh_half_bin.cpp neigh_half_bin.h neigh_half_multi.cpp neigh_half_multi.h neigh_half_nsq.cpp neigh_half_nsq.h neigh_respa.cpp neigh_respa.h neigh_shardlow.cpp neigh_shardlow.h neigh_stencil.cpp neigh_half_bin_intel.cpp neigh_full_kokkos.h neighbor_omp.h neigh_derive_omp.cpp neigh_full_omp.cpp neigh_gran_omp.cpp neigh_half_bin_omp.cpp neigh_half_multi_omp.cpp neigh_half_nsq_omp.cpp neigh_respa_omp.cpp # deleted on 20 Sep 2016 fix_ti_rs.cpp fix_ti_rs.h # deleted on 31 May 2016 fix_ave_spatial_sphere.cpp fix_ave_spatial_sphere.h atom_vec_angle_cuda.cpp atom_vec_angle_cuda.h atom_vec_atomic_cuda.cpp atom_vec_atomic_cuda.h atom_vec_charge_cuda.cpp atom_vec_charge_cuda.h atom_vec_full_cuda.cpp atom_vec_full_cuda.h comm_cuda.cpp comm_cuda.h compute_pe_cuda.cpp compute_pe_cuda.h compute_pressure_cuda.cpp compute_pressure_cuda.h compute_temp_cuda.cpp compute_temp_cuda.h compute_temp_partial_cuda.cpp compute_temp_partial_cuda.h cuda.cpp cuda_data.h cuda_modify_flags.h cuda_neigh_list.cpp cuda_neigh_list.h domain_cuda.cpp domain_cuda.h fft3d_cuda.cpp fft3d_cuda.h fft3d_wrap_cuda.cpp fft3d_wrap_cuda.h fix_addforce_cuda.cpp fix_addforce_cuda.h fix_aveforce_cuda.cpp fix_aveforce_cuda.h fix_enforce2d_cuda.cpp fix_enforce2d_cuda.h fix_freeze_cuda.cpp fix_freeze_cuda.h fix_gravity_cuda.cpp fix_gravity_cuda.h fix_nh_cuda.cpp fix_nh_cuda.h fix_npt_cuda.cpp fix_npt_cuda.h fix_nve_cuda.cpp fix_nve_cuda.h fix_nvt_cuda.cpp fix_nvt_cuda.h fix_set_force_cuda.cpp fix_set_force_cuda.h fix_shake_cuda.cpp fix_shake_cuda.h fix_temp_berendsen_cuda.cpp fix_temp_berendsen_cuda.h fix_temp_rescale_cuda.cpp fix_temp_rescale_cuda.h fix_temp_rescale_limit_cuda.cpp fix_temp_rescale_limit_cuda.h fix_viscous_cuda.cpp fix_viscous_cuda.h modify_cuda.cpp modify_cuda.h neighbor_cuda.cpp neighbor_cuda.h neigh_full_cuda.cpp pair_born_coul_long_cuda.cpp pair_born_coul_long_cuda.h pair_buck_coul_cut_cuda.cpp pair_buck_coul_cut_cuda.h pair_buck_coul_long_cuda.cpp pair_buck_coul_long_cuda.h pair_buck_cuda.cpp pair_buck_cuda.h pair_eam_alloy_cuda.cpp pair_eam_alloy_cuda.h pair_eam_cuda.cpp pair_eam_cuda.h pair_eam_fs_cuda.cpp pair_eam_fs_cuda.h pair_gran_hooke_cuda.cpp pair_gran_hooke_cuda.h pair_lj96_cut_cuda.cpp pair_lj96_cut_cuda.h pair_lj_charmm_coul_charmm_cuda.cpp pair_lj_charmm_coul_charmm_cuda.h pair_lj_charmm_coul_charmm_implicit_cuda.cpp pair_lj_charmm_coul_charmm_implicit_cuda.h pair_lj_charmm_coul_long_cuda.cpp pair_lj_charmm_coul_long_cuda.h pair_lj_class2_coul_cut_cuda.cpp pair_lj_class2_coul_cut_cuda.h pair_lj_class2_coul_long_cuda.cpp pair_lj_class2_coul_long_cuda.h pair_lj_class2_cuda.cpp pair_lj_class2_cuda.h pair_lj_cut_coul_cut_cuda.cpp pair_lj_cut_coul_cut_cuda.h pair_lj_cut_coul_debye_cuda.cpp pair_lj_cut_coul_debye_cuda.h pair_lj_cut_coul_long_cuda.cpp pair_lj_cut_coul_long_cuda.h pair_lj_cut_cuda.cpp pair_lj_cut_cuda.h pair_lj_cut_experimental_cuda.cpp pair_lj_cut_experimental_cuda.h pair_lj_expand_cuda.cpp pair_lj_expand_cuda.h pair_lj_gromacs_coul_gromacs_cuda.cpp pair_lj_gromacs_coul_gromacs_cuda.h pair_lj_gromacs_cuda.cpp pair_lj_gromacs_cuda.h pair_lj_sdk_coul_long_cuda.cpp pair_lj_sdk_coul_long_cuda.h pair_lj_sdk_cuda.cpp pair_lj_sdk_cuda.h pair_lj_smooth_cuda.cpp pair_lj_smooth_cuda.h pair_morse_cuda.cpp pair_morse_cuda.h pair_sw_cuda.cpp pair_sw_cuda.h pair_tersoff_cuda.cpp pair_tersoff_cuda.h pair_tersoff_zbl_cuda.cpp pair_tersoff_zbl_cuda.h pppm_cuda.cpp pppm_cuda.h pppm_old.cpp pppm_old.h user_cuda.h verlet_cuda.cpp verlet_cuda.h # deleted on 11 May 2016 pair_dpd_conservative.cpp pair_dpd_conservative.h # deleted on 21 Mar 2016 verlet_intel.cpp verlet_intel.h verlet_split_intel.cpp verlet_split_intel.h # deleted on 15 Jan 2016 pair_line_lj_omp.cpp pair_line_lj_omp.h pair_tri_lj_omp.cpp pair_tri_lj_omp.h # deleted on 13 May 14 commgrid.cpp commgrid.h # deleted on 5 May 14 reaxc_basic_comm.cpp reaxc_basic_comm.h # deleted on 15 Apr 14 pppm_old.cpp pppm_old.h # deleted on Thu Jun 6 15:19:12 2013 +0000 pair_dipole_cut.h pair_dipole_cut.cpp pair_dipole_cut_gpu.h pair_dipole_cut_gpu.cpp pair_dipole_cut_omp.h pair_dipole_cut_omp.cpp pair_dipole_sf.h pair_dipole_sf.cpp pair_dipole_sf_omp.h pair_dipole_sf_omp.cpp pair_dipole_sf_gpu.h pair_dipole_sf_gpu.cpp # deleted on Wed May 8 15:24:36 2013 +0000 fix_species.cpp fix_species.h # deleted on Fri Oct 19 15:27:15 2012 +0000 pair_lj_charmm_coul_long_proxy_omp.cpp pair_lj_charmm_coul_long_proxy_omp.h pair_lj_class2_coul_long_proxy_omp.cpp pair_lj_class2_coul_long_proxy_omp.h pair_lj_cut_coul_long_proxy_omp.cpp pair_lj_cut_coul_long_proxy_omp.h pair_lj_cut_tip4p_long_proxy_omp.cpp pair_lj_cut_tip4p_long_proxy_omp.h pppm_proxy.cpp pppm_proxy.h pppm_tip4p_proxy.cpp pppm_tip4p_proxy.h # deleted on Wed Oct 3 15:17:27 2012 +0000 pair_lj_cut_coul_long_proxy_tip4p_omp.cpp pair_lj_cut_coul_long_proxy_tip4p_omp.h # deleted on Wed Oct 3 15:06:24 2012 +0000 pair_lj_cut_coul_long_tip4p_opt.cpp pair_lj_cut_coul_long_tip4p_opt.h # deleted on Wed Oct 3 14:53:43 2012 +0000 pair_lj_charmm_coul_long_proxy_omp.cpp pair_lj_charmm_coul_long_proxy_omp.h pair_lj_class2_coul_long_proxy_omp.cpp pair_lj_class2_coul_long_proxy_omp.h pair_lj_cut_coul_long_proxy_omp.cpp pair_lj_cut_coul_long_proxy_omp.h pair_lj_cut_coul_long_tip4p_omp.cpp pair_lj_cut_coul_long_tip4p_omp.h # deleted on Wed Oct 3 14:50:44 2012 +0000 pair_buck_disp_coul_long_omp.cpp pair_buck_disp_coul_long_omp.h pair_lj_disp_coul_long_omp.cpp pair_lj_disp_coul_long_omp.h # deleted on Wed Oct 3 14:46:42 2012 +0000 pair_lj_cut_coul_long_tip4p.cpp pair_lj_cut_coul_long_tip4p.h # deleted on Wed Oct 3 14:46:23 2012 +0000 pair_buck_disp_coul_long.cpp pair_buck_disp_coul_long.h pair_lj_disp_coul_long.cpp pair_lj_disp_coul_long.h pair_lj_disp_coul_long_tip4p.cpp pair_lj_disp_coul_long_tip4p.h # deleted on Tue Oct 2 22:50:58 2012 +0000 pair_buck_coul_omp.cpp pair_buck_coul_omp.h pair_lj_coul_omp.cpp pair_lj_coul_omp.h # deleted on Tue Oct 2 20:12:27 2012 +0000 pair_lj_charmm_coul_pppm_omp.cpp pair_lj_charmm_coul_pppm_omp.h pair_lj_class2_coul_pppm_omp.cpp pair_lj_class2_coul_pppm_omp.h pair_lj_cut_coul_pppm_omp.cpp pair_lj_cut_coul_pppm_omp.h pair_lj_cut_coul_pppm_tip4p_omp.cpp pair_lj_cut_coul_pppm_tip4p_omp.h # deleted on Tue Oct 2 19:59:40 2012 +0000 pair_buck_coul_omp.cpp pair_buck_coul_omp.h pair_lj_coul_omp.cpp pair_lj_coul_omp.h pair_lj_cut_coul_long_tip4p_omp.cpp pair_lj_cut_coul_long_tip4p_omp.h pppm_proxy.cpp pppm_proxy.h pppm_tip4p_proxy.cpp pppm_tip4p_proxy.h # deleted on Tue Oct 2 19:58:21 2012 +0000 pair_lj_cut_coul_pppm_omp.cpp pair_lj_cut_coul_pppm_omp.h pair_lj_cut_coul_pppm_tip4p_omp.cpp pair_lj_cut_coul_pppm_tip4p_omp.h # deleted on Tue Oct 2 19:58:03 2012 +0000 pair_lj_charmm_coul_pppm_omp.cpp pair_lj_charmm_coul_pppm_omp.h pair_lj_class2_coul_pppm_omp.cpp pair_lj_class2_coul_pppm_omp.h # deleted on Tue Oct 2 16:36:24 2012 +0000 ewald_n.cpp ewald_n.h pair_buck_coul.cpp pair_buck_coul.h pair_lj_coul.cpp pair_lj_coul.h # deleted on Wed Jul 25 15:17:24 2012 +0000 pair_lj_sdk_coul_cut_cuda.cpp pair_lj_sdk_coul_cut_cuda.h pair_lj_sdk_coul_debye_cuda.cpp pair_lj_sdk_coul_debye_cuda.h # deleted on Tue Jul 24 14:55:49 2012 +0000 pair_cg_cmm_coul_cut_cuda.cpp pair_cg_cmm_coul_cut_cuda.h pair_cg_cmm_coul_debye_cuda.cpp pair_cg_cmm_coul_debye_cuda.h pair_cg_cmm_coul_long_cuda.cpp pair_cg_cmm_coul_long_cuda.h pair_cg_cmm_cuda.cpp pair_cg_cmm_cuda.h # deleted on Sat Dec 31 20:27:05 2011 -0500 ewald_cg.cpp ewald_cg.h # deleted on Sat Dec 31 20:01:21 2011 -0500 dihedral_omp.cpp dihedral_omp.h pair_cg_cmm_omp.cpp pair_cg_cmm_omp.h pair_lj_cut_coul_long_tip4p_omp.cpp pair_lj_cut_coul_long_tip4p_omp.h pair_omp.cpp pair_omp.h # deleted on Thu Dec 8 23:13:51 2011 +0000 pair_cg_cmm_coul_long_gpu.cpp pair_cg_cmm_coul_long_gpu.h pair_cg_cmm_gpu.cpp pair_cg_cmm_gpu.h # deleted on Mon Nov 7 19:32:59 2011 -0500 pair_cg_cmm_coul_long_gpu.cpp pair_cg_cmm_coul_long_gpu.h pair_cg_cmm_gpu.cpp pair_cg_cmm_gpu.h # deleted on Tue Oct 25 23:04:03 2011 -0400 lj_sdk_common.cpp # deleted on Fri Oct 7 08:55:40 2011 -0400 pair_hybrid_overlay_omp.cpp pair_hybrid_overlay_omp.h # deleted on Fri Oct 7 08:54:38 2011 -0400 angle_hybrid_omp.cpp angle_hybrid_omp.h bond_hybrid_omp.cpp bond_hybrid_omp.h dihedral_hybrid_omp.cpp dihedral_hybrid_omp.h improper_hybrid_omp.cpp improper_hybrid_omp.h pair_hybrid_omp.cpp pair_hybrid_omp.h # deleted on Mon Aug 22 13:48:15 2011 -0400 omp_thr.cpp omp_thr.h # deleted on Mon Aug 8 22:56:28 2011 +0000 dihedral_cosineshiftexp.cpp dihedral_cosineshiftexp.h # deleted on Mon Aug 8 22:55:20 2011 +0000 angle_cosineshift.cpp angle_cosineshift.h angle_cosineshiftexp.cpp angle_cosineshiftexp.h # deleted on Mon Aug 8 19:25:08 2011 +0000 pppm_gpu_double.cpp pppm_gpu_double.h pppm_gpu_single.cpp pppm_gpu_single.h # deleted on Fri Apr 15 20:57:03 2011 -0400 pair_lj_charmm_coul_long_gpu2.cpp pair_lj_charmm_coul_long_gpu2.h # deleted on Wed Apr 13 21:40:14 2011 +0000 atom_vec_colloid.cpp atom_vec_colloid.h atom_vec_granular.cpp atom_vec_granular.h # deleted on Fri Nov 19 12:53:07 2010 -0500 fix_pour_omp.cpp fix_pour_omp.h # deleted on Thu Jun 17 01:34:38 2010 +0000 compute_vsum.cpp compute_vsum.h # deleted on Mon Jun 14 11:06:46 2010 -0400 pair_buck_coul_omp.cpp pair_buck_coul_omp.h pair_lj_coul_omp.cpp pair_lj_coul_omp.h # deleted on Thu Jun 10 15:39:08 2010 -0400 pair_buck_coul_omp.cpp pair_buck_coul_omp.h # deleted on Tue Jun 8 15:42:51 2010 -0400 pair_buck_coul_omp.cpp pair_buck_coul_omp.h # deleted on Thu Dec 17 23:52:31 2009 +0000 dump_bond.cpp dump_bond.h # deleted on Mon Nov 9 18:20:20 2009 +0000 style_dpd.h # deleted on Mon Jun 22 21:11:31 2009 +0000 fix_write_reax_bonds.cpp fix_write_reax_bonds.h # deleted on Thu Jan 8 16:53:09 2009 +0000 pair_gran_hertzian.cpp pair_gran_hertzian.h pair_gran_history.cpp pair_gran_history.h pair_gran_no_history.cpp pair_gran_no_history.h # deleted on Mon Mar 17 23:24:44 2008 +0000 compute_temp_dipole.cpp compute_temp_dipole.h fix_nve_dipole.cpp fix_nve_dipole.h # deleted on Mon Mar 17 23:23:24 2008 +0000 fix_nve_gran.cpp fix_nve_gran.h # deleted on Fri Nov 30 21:49:20 2007 +0000 fix_gran_diag.cpp fix_gran_diag.h atom_angle.cpp atom_angle.h atom_bond.cpp atom_bond.h atom_full.cpp atom_full.h atom_molecular.cpp atom_molecular.h # deleted on Tue Jan 30 00:22:05 2007 +0000 atom_dpd.cpp atom_dpd.h atom_granular.cpp atom_granular.h # deleted on Wed Dec 13 00:34:21 2006 +0000 fix_insert.cpp fix_insert.h diff --git a/src/USER-DRUDE/pair_lj_cut_thole_long.cpp b/src/USER-DRUDE/pair_lj_cut_thole_long.cpp index ee9c0744d..4163a816a 100644 --- a/src/USER-DRUDE/pair_lj_cut_thole_long.cpp +++ b/src/USER-DRUDE/pair_lj_cut_thole_long.cpp @@ -1,705 +1,692 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- Contributing author: Paul Crozier (SNL) ------------------------------------------------------------------------- */ #include #include #include #include #include "pair_lj_cut_thole_long.h" #include "atom.h" #include "comm.h" #include "force.h" #include "kspace.h" #include "update.h" #include "integrate.h" #include "neighbor.h" #include "neigh_list.h" #include "neigh_request.h" #include "math_const.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; using namespace MathConst; #define EWALD_F 1.12837917 #define EWALD_P 9.95473818e-1 #define B0 -0.1335096380159268 #define B1 -2.57839507e-1 #define B2 -1.37203639e-1 #define B3 -8.88822059e-3 #define B4 -5.80844129e-3 #define B5 1.14652755e-1 /* ---------------------------------------------------------------------- */ PairLJCutTholeLong::PairLJCutTholeLong(LAMMPS *lmp) : Pair(lmp) { ewaldflag = pppmflag = 1; writedata = 1; ftable = NULL; qdist = 0.0; fix_drude = NULL; } /* ---------------------------------------------------------------------- */ PairLJCutTholeLong::~PairLJCutTholeLong() { if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(polar); memory->destroy(thole); memory->destroy(ascreen); memory->destroy(cut_lj); memory->destroy(cut_ljsq); memory->destroy(scale); memory->destroy(epsilon); memory->destroy(sigma); memory->destroy(lj1); memory->destroy(lj2); memory->destroy(lj3); memory->destroy(lj4); memory->destroy(offset); } if (ftable) free_tables(); } /* ---------------------------------------------------------------------- */ void PairLJCutTholeLong::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype,itable; double qi,qj,xtmp,ytmp,ztmp,delx,dely,delz,ecoul,fpair,evdwl; double r,rsq,r2inv,forcecoul,factor_coul,forcelj,factor_lj,r6inv; double fraction,table; double grij,expm2,prefactor,t,erfc,u; int *ilist,*jlist,*numneigh,**firstneigh; double factor_f,factor_e; int di,dj; double dqi,dqj,dcoul,asr,exp_asr; int di_closest; evdwl = ecoul = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; int *drudetype = fix_drude->drudetype; tagint *drudeid = fix_drude->drudeid; inum = list->inum; ilist = list->ilist; numneigh = list->numneigh; firstneigh = list->firstneigh; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qi = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; if (drudetype[type[i]] != NOPOL_TYPE){ di = atom->map(drudeid[i]); if (di < 0) error->all(FLERR, "Drude partner not found"); di_closest = domain->closest_image(i, di); if (drudetype[type[i]] == CORE_TYPE) dqi = -q[di]; else dqi = qi; } for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; if (rsq < cutsq[itype][jtype]) { r2inv = 1.0/rsq; if (rsq < cut_coulsq) { qj = q[j]; r = sqrt(rsq); if (!ncoultablebits || rsq <= tabinnersq) { grij = g_ewald * r; expm2 = exp(-grij*grij); t = 1.0 / (1.0 + EWALD_P*grij); u = 1. - t; erfc = t * (1.+u*(B0+u*(B1+u*(B2+u*(B3+u*(B4+u*B5)))))) * expm2; prefactor = qqrd2e * qi*qj/r; forcecoul = prefactor * (erfc + EWALD_F*grij*expm2); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; } else { union_int_float_t rsq_lookup; rsq_lookup.f = rsq; itable = rsq_lookup.i & ncoulmask; itable >>= ncoulshiftbits; fraction = (rsq_lookup.f - rtable[itable]) * drtable[itable]; table = ftable[itable] + fraction*dftable[itable]; forcecoul = qi*qj * table; if (factor_coul < 1.0) { table = ctable[itable] + fraction*dctable[itable]; prefactor = qi*qj * table; forcecoul -= (1.0-factor_coul)*prefactor; } } if (drudetype[type[i]] != NOPOL_TYPE && drudetype[type[j]] != NOPOL_TYPE){ if (j != di_closest){ if (drudetype[type[j]] == CORE_TYPE){ dj = atom->map(drudeid[j]); dqj = -q[dj]; } else dqj = qj; asr = ascreen[type[i]][type[j]] * r; exp_asr = exp(-asr); dcoul = qqrd2e * dqi * dqj / r; factor_f = 0.5*(2. + (exp_asr * (-2. - asr * (2. + asr)))) - factor_coul; if (eflag) factor_e = 0.5*(2. - (exp_asr * (2. + asr))) - factor_coul; forcecoul += factor_f * dcoul; } } } else forcecoul = 0.0; if (rsq < cut_ljsq[itype][jtype]) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); } else forcelj = 0.0; fpair = (forcecoul + factor_lj*forcelj) * r2inv; 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; } if (eflag) { if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) ecoul = prefactor*erfc; else { table = etable[itable] + fraction*detable[itable]; ecoul = qi*qj * table; } if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; if (drudetype[type[i]] != NOPOL_TYPE && drudetype[type[j]] != NOPOL_TYPE && j != di_closest){ ecoul += factor_e * dcoul; } } else ecoul = 0.0; if (rsq < cut_ljsq[itype][jtype]) { evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - offset[itype][jtype]; evdwl *= factor_lj; } else evdwl = 0.0; } if (evflag) ev_tally(i,j,nlocal,newton_pair, evdwl,ecoul,fpair,delx,dely,delz); } } } if (vflag_fdotr) virial_fdotr_compute(); } /* ---------------------------------------------------------------------- allocate all arrays ------------------------------------------------------------------------- */ void PairLJCutTholeLong::allocate() { allocated = 1; int n = atom->ntypes; 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(cutsq,n+1,n+1,"pair:cutsq"); memory->create(cut_lj,n+1,n+1,"pair:cut_lj"); memory->create(cut_ljsq,n+1,n+1,"pair:cut_ljsq"); memory->create(scale,n+1,n+1,"pair:scale"); memory->create(ascreen,n+1,n+1,"pair:ascreen"); memory->create(thole,n+1,n+1,"pair:thole"); memory->create(polar,n+1,n+1,"pair:polar"); memory->create(epsilon,n+1,n+1,"pair:epsilon"); memory->create(sigma,n+1,n+1,"pair:sigma"); memory->create(lj1,n+1,n+1,"pair:lj1"); memory->create(lj2,n+1,n+1,"pair:lj2"); memory->create(lj3,n+1,n+1,"pair:lj3"); memory->create(lj4,n+1,n+1,"pair:lj4"); memory->create(offset,n+1,n+1,"pair:offset"); } /* ---------------------------------------------------------------------- global settings ------------------------------------------------------------------------- */ void PairLJCutTholeLong::settings(int narg, char **arg) { if (narg < 2 || narg > 3) error->all(FLERR,"Illegal pair_style command"); thole_global = force->numeric(FLERR,arg[0]); cut_lj_global = force->numeric(FLERR,arg[1]); if (narg == 2) cut_coul = cut_lj_global; else cut_coul = force->numeric(FLERR,arg[2]); // reset cutoffs that have been explicitly set if (allocated) { int i,j; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) if (setflag[i][j]) { thole[i][j] = thole_global; cut_lj[i][j] = cut_lj_global; } } } /* ---------------------------------------------------------------------- set coeffs for one or more type pairs ------------------------------------------------------------------------- */ void PairLJCutTholeLong::coeff(int narg, char **arg) { if (narg < 5 || narg > 7) error->all(FLERR,"Incorrect args for pair coefficients"); if (!allocated) allocate(); int ilo,ihi,jlo,jhi; force->bounds(FLERR,arg[0],atom->ntypes,ilo,ihi); force->bounds(FLERR,arg[1],atom->ntypes,jlo,jhi); double epsilon_one = force->numeric(FLERR,arg[2]); double sigma_one = force->numeric(FLERR,arg[3]); double polar_one = force->numeric(FLERR,arg[4]); double thole_one = thole_global; if (narg >=6) thole_one = force->numeric(FLERR,arg[5]); double cut_lj_one = cut_lj_global; if (narg == 7) cut_lj_one = force->numeric(FLERR,arg[6]); int count = 0; for (int i = ilo; i <= ihi; i++) { for (int j = MAX(jlo,i); j <= jhi; j++) { epsilon[i][j] = epsilon_one; sigma[i][j] = sigma_one; polar[i][j] = polar_one; thole[i][j] = thole_one; ascreen[i][j] = thole[i][j] / pow(polar[i][j], 1./3.); cut_lj[i][j] = cut_lj_one; scale[i][j] = 1.0; setflag[i][j] = 1; count++; } } if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- init specific to this pair style ------------------------------------------------------------------------- */ void PairLJCutTholeLong::init_style() { if (!atom->q_flag) error->all(FLERR,"Pair style lj/cut/thole/long requires atom attribute q"); int ifix; for (ifix = 0; ifix < modify->nfix; ifix++) if (strcmp(modify->fix[ifix]->style,"drude") == 0) break; if (ifix == modify->nfix) error->all(FLERR, "Pair style lj/cut/thole/long requires fix drude"); fix_drude = (FixDrude *) modify->fix[ifix]; int irequest = neighbor->request(this,instance_me); cut_coulsq = cut_coul * cut_coul; // set rRESPA cutoffs cut_respa = NULL; // insure use of KSpace long-range solver, set g_ewald if (force->kspace == NULL) error->all(FLERR,"Pair style requires a KSpace style"); g_ewald = force->kspace->g_ewald; // setup force tables if (ncoultablebits) init_tables(cut_coul,cut_respa); } -/* ---------------------------------------------------------------------- - neighbor callback to inform pair style of neighbor list to use - regular or rRESPA -------------------------------------------------------------------------- */ - -void PairLJCutTholeLong::init_list(int id, NeighList *ptr) -{ - if (id == 0) list = ptr; - else if (id == 1) listinner = ptr; - else if (id == 2) listmiddle = ptr; - else if (id == 3) listouter = ptr; -} - /* ---------------------------------------------------------------------- init for one type pair i,j and corresponding j,i ------------------------------------------------------------------------- */ double PairLJCutTholeLong::init_one(int i, int j) { if (setflag[i][j] == 0) { epsilon[i][j] = mix_energy(epsilon[i][i],epsilon[j][j], sigma[i][i],sigma[j][j]); sigma[i][j] = mix_distance(sigma[i][i],sigma[j][j]); cut_lj[i][j] = mix_distance(cut_lj[i][i],cut_lj[j][j]); polar[i][j] = sqrt(polar[i][i] * polar[j][j]); thole[i][j] = 0.5 * (thole[i][i] + thole[j][j]); ascreen[i][j] = thole[i][j] / pow(polar[i][j], 1./3.); } // include TIP4P qdist in full cutoff, qdist = 0.0 if not TIP4P double cut = MAX(cut_lj[i][j],cut_coul+2.0*qdist); cut_ljsq[i][j] = cut_lj[i][j] * cut_lj[i][j]; lj1[i][j] = 48.0 * epsilon[i][j] * pow(sigma[i][j],12.0); lj2[i][j] = 24.0 * epsilon[i][j] * pow(sigma[i][j],6.0); lj3[i][j] = 4.0 * epsilon[i][j] * pow(sigma[i][j],12.0); lj4[i][j] = 4.0 * epsilon[i][j] * pow(sigma[i][j],6.0); if (offset_flag && (cut_lj[i][j] > 0.0)) { double ratio = sigma[i][j] / cut_lj[i][j]; offset[i][j] = 4.0 * epsilon[i][j] * (pow(ratio,12.0) - pow(ratio,6.0)); } else offset[i][j] = 0.0; cut_ljsq[j][i] = cut_ljsq[i][j]; lj1[j][i] = lj1[i][j]; lj2[j][i] = lj2[i][j]; lj3[j][i] = lj3[i][j]; lj4[j][i] = lj4[i][j]; offset[j][i] = offset[i][j]; polar[j][i] = polar[i][j]; thole[j][i] = thole[i][j]; ascreen[j][i] = ascreen[i][j]; scale[j][i] = scale[i][j]; // check interior rRESPA cutoff if (cut_respa && MIN(cut_lj[i][j],cut_coul) < cut_respa[3]) error->all(FLERR,"Pair cutoff < Respa interior cutoff"); // compute I,J contribution to long-range tail correction // count total # of atoms of type I and J via Allreduce if (tail_flag) { int *type = atom->type; int nlocal = atom->nlocal; double count[2],all[2]; count[0] = count[1] = 0.0; for (int k = 0; k < nlocal; k++) { if (type[k] == i) count[0] += 1.0; if (type[k] == j) count[1] += 1.0; } MPI_Allreduce(count,all,2,MPI_DOUBLE,MPI_SUM,world); double sig2 = sigma[i][j]*sigma[i][j]; double sig6 = sig2*sig2*sig2; double rc3 = cut_lj[i][j]*cut_lj[i][j]*cut_lj[i][j]; double rc6 = rc3*rc3; double rc9 = rc3*rc6; etail_ij = 8.0*MY_PI*all[0]*all[1]*epsilon[i][j] * sig6 * (sig6 - 3.0*rc6) / (9.0*rc9); ptail_ij = 16.0*MY_PI*all[0]*all[1]*epsilon[i][j] * sig6 * (2.0*sig6 - 3.0*rc6) / (9.0*rc9); } return cut; } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairLJCutTholeLong::write_restart(FILE *fp) { write_restart_settings(fp); int i,j; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { fwrite(&setflag[i][j],sizeof(int),1,fp); if (setflag[i][j]) { fwrite(&epsilon[i][j],sizeof(double),1,fp); fwrite(&sigma[i][j],sizeof(double),1,fp); fwrite(&polar[i][j],sizeof(double),1,fp); fwrite(&thole[i][j],sizeof(double),1,fp); fwrite(&cut_lj[i][j],sizeof(double),1,fp); } } } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairLJCutTholeLong::read_restart(FILE *fp) { read_restart_settings(fp); allocate(); int i,j; int me = comm->me; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp); MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world); if (setflag[i][j]) { if (me == 0) { fread(&epsilon[i][j],sizeof(double),1,fp); fread(&sigma[i][j],sizeof(double),1,fp); fread(&polar[i][j],sizeof(double),1,fp); fread(&thole[i][j],sizeof(double),1,fp); ascreen[i][j] = thole[i][j] / pow(polar[i][j], 1./3.); fread(&cut_lj[i][j],sizeof(double),1,fp); } MPI_Bcast(&epsilon[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&sigma[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&polar[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&thole[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&ascreen[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&cut_lj[i][j],1,MPI_DOUBLE,0,world); } } } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairLJCutTholeLong::write_restart_settings(FILE *fp) { fwrite(&cut_lj_global,sizeof(double),1,fp); fwrite(&cut_coul,sizeof(double),1,fp); fwrite(&thole_global,sizeof(double),1,fp); fwrite(&cut_global,sizeof(double),1,fp); fwrite(&offset_flag,sizeof(int),1,fp); fwrite(&mix_flag,sizeof(int),1,fp); fwrite(&tail_flag,sizeof(int),1,fp); fwrite(&ncoultablebits,sizeof(int),1,fp); fwrite(&tabinner,sizeof(double),1,fp); } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairLJCutTholeLong::read_restart_settings(FILE *fp) { if (comm->me == 0) { fread(&cut_lj_global,sizeof(double),1,fp); fread(&cut_coul,sizeof(double),1,fp); fread(&thole_global,sizeof(double),1,fp); fread(&cut_global,sizeof(double),1,fp); fread(&offset_flag,sizeof(int),1,fp); fread(&mix_flag,sizeof(int),1,fp); fread(&tail_flag,sizeof(int),1,fp); fread(&ncoultablebits,sizeof(int),1,fp); fread(&tabinner,sizeof(double),1,fp); } MPI_Bcast(&cut_lj_global,1,MPI_DOUBLE,0,world); MPI_Bcast(&cut_coul,1,MPI_DOUBLE,0,world); MPI_Bcast(&thole_global,1,MPI_DOUBLE,0,world); MPI_Bcast(&cut_global,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(&tail_flag,1,MPI_INT,0,world); MPI_Bcast(&ncoultablebits,1,MPI_INT,0,world); MPI_Bcast(&tabinner,1,MPI_DOUBLE,0,world); } /* ---------------------------------------------------------------------- proc 0 writes to data file ------------------------------------------------------------------------- */ void PairLJCutTholeLong::write_data(FILE *fp) { for (int i = 1; i <= atom->ntypes; i++) fprintf(fp,"%d %g %g %g %g\n",i,epsilon[i][i],sigma[i][i],polar[i][i],thole[i][i]); } /* ---------------------------------------------------------------------- proc 0 writes all pairs to data file ------------------------------------------------------------------------- */ void PairLJCutTholeLong::write_data_all(FILE *fp) { for (int i = 1; i <= atom->ntypes; i++) for (int j = i; j <= atom->ntypes; j++) fprintf(fp,"%d %d %g %g %g %g %g\n",i,j,epsilon[i][j],sigma[i][j],polar[i][j],thole[i][j],cut_lj[i][j]); } /* ---------------------------------------------------------------------- */ double PairLJCutTholeLong::single(int i, int j, int itype, int jtype, double rsq, double factor_coul, double factor_lj, double &fforce) { double r2inv,r6inv,r,grij,expm2,t,erfc,prefactor,u; double fraction,table,forcecoul,forcelj,phicoul,philj; int itable; double factor_f,factor_e; double dqi,dqj,dcoul,asr,exp_asr; int di, dj, di_closest; int *drudetype = fix_drude->drudetype; tagint *drudeid = fix_drude->drudeid; int *type = atom->type; r2inv = 1.0/rsq; if (rsq < cut_coulsq) { r = sqrt(rsq); if (!ncoultablebits || rsq <= tabinnersq) { grij = g_ewald * r; expm2 = exp(-grij*grij); t = 1.0 / (1.0 + EWALD_P*grij); u = 1. - t; erfc = t * (1.+u*(B0+u*(B1+u*(B2+u*(B3+u*(B4+u*B5)))))) * expm2; prefactor = force->qqrd2e * atom->q[i]*atom->q[j]/r; forcecoul = prefactor * (erfc + EWALD_F*grij*expm2); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; } else { union_int_float_t rsq_lookup_single; rsq_lookup_single.f = rsq; itable = rsq_lookup_single.i & ncoulmask; itable >>= ncoulshiftbits; fraction = (rsq_lookup_single.f - rtable[itable]) * drtable[itable]; table = ftable[itable] + fraction*dftable[itable]; forcecoul = atom->q[i]*atom->q[j] * table; if (factor_coul < 1.0) { table = ctable[itable] + fraction*dctable[itable]; prefactor = atom->q[i]*atom->q[j] * table; forcecoul -= (1.0-factor_coul)*prefactor; } } if (drudetype[type[i]] != NOPOL_TYPE && drudetype[type[j]] != NOPOL_TYPE) { di = atom->map(drudeid[i]); di_closest = domain->closest_image(i, di); if (j != di_closest){ if (drudetype[i] == CORE_TYPE) dqi = -atom->q[di]; else if (drudetype[i] == DRUDE_TYPE) dqi = atom->q[i]; else dqi = 0.0; if (drudetype[j] == CORE_TYPE) { dj = atom->map(drudeid[j]); dqj = -atom->q[dj]; } else if (drudetype[j] == DRUDE_TYPE) dqj = atom->q[j]; else dqj = 0.0; asr = ascreen[itype][jtype] * r; exp_asr = exp(-asr); dcoul = force->qqrd2e * dqi * dqj / r; factor_f = 0.5*(2. + (exp_asr * (-2. - asr * (2. + asr)))) - factor_coul; forcecoul += factor_f * dcoul; factor_e = 0.5*(2. - (exp_asr * (2. + asr))) - factor_coul; } } } else forcecoul = 0.0; if (rsq < cut_ljsq[itype][jtype]) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); } else forcelj = 0.0; fforce = (forcecoul + factor_lj*forcelj) * r2inv; double eng = 0.0; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) phicoul = prefactor*erfc; else { table = etable[itable] + fraction*detable[itable]; phicoul = atom->q[i]*atom->q[j] * table; } if (factor_coul < 1.0) phicoul -= (1.0-factor_coul)*prefactor; if (drudetype[type[i]] != NOPOL_TYPE && drudetype[type[j]] != NOPOL_TYPE && di_closest != j) phicoul += factor_e * dcoul; eng += phicoul; } if (rsq < cut_ljsq[itype][jtype]) { philj = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - offset[itype][jtype]; eng += factor_lj*philj; } return eng; } /* ---------------------------------------------------------------------- */ void *PairLJCutTholeLong::extract(const char *str, int &dim) { dim = 0; if (strcmp(str,"cut_coul") == 0) return (void *) &cut_coul; dim = 6; if (strcmp(str,"epsilon") == 0) return (void *) epsilon; if (strcmp(str,"sigma") == 0) return (void *) sigma; if (strcmp(str,"scale") == 0) return (void *) scale; if (strcmp(str,"polar") == 0) return (void *) polar; if (strcmp(str,"thole") == 0) return (void *) thole; if (strcmp(str,"ascreen") == 0) return (void *) ascreen; return NULL; } diff --git a/src/USER-DRUDE/pair_lj_cut_thole_long.h b/src/USER-DRUDE/pair_lj_cut_thole_long.h index 894042f6c..27a917c73 100644 --- a/src/USER-DRUDE/pair_lj_cut_thole_long.h +++ b/src/USER-DRUDE/pair_lj_cut_thole_long.h @@ -1,97 +1,96 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #ifdef PAIR_CLASS PairStyle(lj/cut/thole/long,PairLJCutTholeLong) #else #ifndef LMP_PAIR_LJ_CUT_THOLE_LONG_H #define LMP_PAIR_LJ_CUT_THOLE_LONG_H #include "pair.h" #include "fix_drude.h" namespace LAMMPS_NS { class PairLJCutTholeLong : public Pair { public: PairLJCutTholeLong(class LAMMPS *); virtual ~PairLJCutTholeLong(); virtual void compute(int, int); virtual void settings(int, char **); void coeff(int, char **); virtual void init_style(); - void init_list(int, class NeighList *); virtual double init_one(int, int); void write_restart(FILE *); void read_restart(FILE *); virtual void write_restart_settings(FILE *); virtual void read_restart_settings(FILE *); void write_data(FILE *); void write_data_all(FILE *); virtual double single(int, int, int, int, double, double, double, double &); virtual void *extract(const char *, int &); protected: double cut_lj_global; double **cut_lj,**cut_ljsq; double cut_coul,cut_coulsq; double **epsilon,**sigma; double **lj1,**lj2,**lj3,**lj4,**offset; double *cut_respa; double qdist; // TIP4P distance from O site to negative charge double g_ewald; double thole_global; double cut_global; double **cut,**scale; double **polar,**thole,**ascreen; FixDrude *fix_drude; virtual void allocate(); }; } #endif #endif /* ERROR/WARNING messages: E: Illegal ... command Self-explanatory. Check the input script syntax and compare to the documentation for the command. You can use -echo screen as a command-line option when running LAMMPS to see the offending line. E: Incorrect args for pair coefficients Self-explanatory. Check the input script or data file. E: Pair style lj/cut/coul/long requires atom attribute q The atom style defined does not have this attribute. E: Pair style requires a KSpace style No kspace style is defined. E: Pair cutoff < Respa interior cutoff One or more pairwise cutoffs are too short to use with the specified rRESPA cutoffs. */ diff --git a/src/USER-FEP/pair_lj_charmm_coul_long_soft.cpp b/src/USER-FEP/pair_lj_charmm_coul_long_soft.cpp index d8bfd698b..06285a58d 100644 --- a/src/USER-FEP/pair_lj_charmm_coul_long_soft.cpp +++ b/src/USER-FEP/pair_lj_charmm_coul_long_soft.cpp @@ -1,1028 +1,1015 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- Contributing author: Paul Crozier (SNL) Soft-core version: Agilio Padua (Univ Blaise Pascal & CNRS) ------------------------------------------------------------------------- */ #include #include #include #include #include "pair_lj_charmm_coul_long_soft.h" #include "atom.h" #include "comm.h" #include "force.h" #include "kspace.h" #include "update.h" #include "integrate.h" #include "respa.h" #include "neighbor.h" #include "neigh_list.h" #include "neigh_request.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; #define EWALD_F 1.12837917 #define EWALD_P 0.3275911 #define A1 0.254829592 #define A2 -0.284496736 #define A3 1.421413741 #define A4 -1.453152027 #define A5 1.061405429 /* ---------------------------------------------------------------------- */ PairLJCharmmCoulLongSoft::PairLJCharmmCoulLongSoft(LAMMPS *lmp) : Pair(lmp) { respa_enable = 1; ewaldflag = pppmflag = 1; implicit = 0; mix_flag = ARITHMETIC; writedata = 1; } /* ---------------------------------------------------------------------- */ PairLJCharmmCoulLongSoft::~PairLJCharmmCoulLongSoft() { if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(epsilon); memory->destroy(sigma); memory->destroy(lambda); memory->destroy(eps14); memory->destroy(sigma14); memory->destroy(lj1); memory->destroy(lj2); memory->destroy(lj3); memory->destroy(lj4); memory->destroy(lj14_1); memory->destroy(lj14_2); memory->destroy(lj14_3); memory->destroy(lj14_4); } } /* ---------------------------------------------------------------------- */ void PairLJCharmmCoulLongSoft::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair; double r,rsq,forcecoul,forcelj,factor_coul,factor_lj; double grij,expm2,prefactor,t,erfc; double philj,switch1,switch2; double denc, denlj, r4sig6; int *ilist,*jlist,*numneigh,**firstneigh; evdwl = ecoul = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; inum = list->inum; ilist = list->ilist; numneigh = list->numneigh; firstneigh = list->firstneigh; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; if (rsq < cut_bothsq) { if (rsq < cut_coulsq) { r = sqrt(rsq); grij = g_ewald * r; expm2 = exp(-grij*grij); t = 1.0 / (1.0 + EWALD_P*grij); erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2; denc = sqrt(lj4[itype][jtype] + rsq); prefactor = qqrd2e * lj1[itype][jtype] * qtmp*q[j] / (denc*denc*denc); forcecoul = prefactor * (erfc + EWALD_F*grij*expm2); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; } else forcecoul = 0.0; if (rsq < cut_ljsq) { r4sig6 = rsq*rsq / lj2[itype][jtype]; denlj = lj3[itype][jtype] + rsq*r4sig6; forcelj = lj1[itype][jtype] * epsilon[itype][jtype] * (48.0*r4sig6/(denlj*denlj*denlj) - 24.0*r4sig6/(denlj*denlj)); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) / denom_lj; switch2 = 12.0 * (cut_ljsq-rsq) * (rsq-cut_lj_innersq) / denom_lj; philj = lj1[itype][jtype] * 4.0 * epsilon[itype][jtype] * (1.0/(denlj*denlj) - 1.0/denlj); forcelj = forcelj*switch1 + philj*switch2; } } else forcelj = 0.0; fpair = forcecoul + factor_lj*forcelj; 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; } if (eflag) { if (rsq < cut_coulsq) { prefactor = qqrd2e * lj1[itype][jtype] * qtmp*q[j] / denc; ecoul = prefactor*erfc; if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; } else ecoul = 0.0; if (rsq < cut_ljsq) { evdwl = lj1[itype][jtype] * 4.0 * epsilon[itype][jtype] * (1.0/(denlj*denlj) - 1.0/denlj); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) / denom_lj; evdwl *= switch1; } evdwl *= factor_lj; } else evdwl = 0.0; } if (evflag) ev_tally(i,j,nlocal,newton_pair, evdwl,ecoul,fpair,delx,dely,delz); } } } if (vflag_fdotr) virial_fdotr_compute(); } /* ---------------------------------------------------------------------- */ void PairLJCharmmCoulLongSoft::compute_inner() { int i,j,ii,jj,inum,jnum,itype,jtype; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fpair; double rsq,forcecoul,forcelj,factor_coul,factor_lj; double rsw; double denc, denlj, r4sig6; int *ilist,*jlist,*numneigh,**firstneigh; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; - inum = listinner->inum; - ilist = listinner->ilist; - numneigh = listinner->numneigh; - firstneigh = listinner->firstneigh; + inum = list->inum_inner; + ilist = list->ilist_inner; + numneigh = list->numneigh_inner; + firstneigh = list->firstneigh_inner; double cut_out_on = cut_respa[0]; double cut_out_off = cut_respa[1]; double cut_out_diff = cut_out_off - cut_out_on; double cut_out_on_sq = cut_out_on*cut_out_on; double cut_out_off_sq = cut_out_off*cut_out_off; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq < cut_out_off_sq) { jtype = type[j]; denc = sqrt(lj4[itype][jtype] + rsq); forcecoul = qqrd2e * lj1[itype][jtype] * qtmp*q[j] / (denc*denc*denc); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*forcecoul; r4sig6 = rsq*rsq / lj2[itype][jtype]; denlj = lj3[itype][jtype] + rsq*r4sig6; forcelj = lj1[itype][jtype] * epsilon[itype][jtype] * (48.0*r4sig6/(denlj*denlj*denlj) - 24.0*r4sig6/(denlj*denlj)); fpair = forcecoul + factor_lj*forcelj; if (rsq > cut_out_on_sq) { rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; fpair *= 1.0 + rsw*rsw*(2.0*rsw-3.0); } 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; } } } } } /* ---------------------------------------------------------------------- */ void PairLJCharmmCoulLongSoft::compute_middle() { int i,j,ii,jj,inum,jnum,itype,jtype; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fpair; double rsq,forcecoul,forcelj,factor_coul,factor_lj; double philj,switch1,switch2; double rsw; double denc, denlj, r4sig6; int *ilist,*jlist,*numneigh,**firstneigh; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; - inum = listmiddle->inum; - ilist = listmiddle->ilist; - numneigh = listmiddle->numneigh; - firstneigh = listmiddle->firstneigh; + inum = list->inum_middle; + ilist = list->ilist_middle; + numneigh = list->numneigh_middle; + firstneigh = list->firstneigh_middle; double cut_in_off = cut_respa[0]; double cut_in_on = cut_respa[1]; double cut_out_on = cut_respa[2]; double cut_out_off = cut_respa[3]; double cut_in_diff = cut_in_on - cut_in_off; double cut_out_diff = cut_out_off - cut_out_on; double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; double cut_out_on_sq = cut_out_on*cut_out_on; double cut_out_off_sq = cut_out_off*cut_out_off; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq < cut_out_off_sq && rsq > cut_in_off_sq) { jtype = type[j]; denc = sqrt(lj4[itype][jtype] + rsq); forcecoul = qqrd2e * lj1[itype][jtype] * qtmp*q[j] / (denc*denc*denc); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*forcecoul; r4sig6 = rsq*rsq / lj2[itype][jtype]; denlj = lj3[itype][jtype] + rsq*r4sig6; forcelj = lj1[itype][jtype] * epsilon[itype][jtype] * (48.0*r4sig6/(denlj*denlj*denlj) - 24.0*r4sig6/(denlj*denlj)); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) / denom_lj; switch2 = 12.0 * (cut_ljsq-rsq) * (rsq-cut_lj_innersq) / denom_lj; philj = lj1[itype][jtype] * 4.0 * epsilon[itype][jtype] * (1.0/(denlj*denlj) - 1.0/denlj); forcelj = forcelj*switch1 + philj*switch2; } fpair = forcecoul + factor_lj*forcelj; if (rsq < cut_in_on_sq) { rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; fpair *= rsw*rsw*(3.0 - 2.0*rsw); } if (rsq > cut_out_on_sq) { rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; fpair *= 1.0 + rsw*rsw*(2.0*rsw - 3.0); } 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; } } } } } /* ---------------------------------------------------------------------- */ void PairLJCharmmCoulLongSoft::compute_outer(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair; double r,rsq,forcecoul,forcelj,factor_coul,factor_lj; double grij,expm2,fprefactor,eprefactor,t,erfc; double philj,switch1,switch2; double rsw; double denc, denlj, r4sig6; int *ilist,*jlist,*numneigh,**firstneigh; evdwl = ecoul = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; - inum = listouter->inum; - ilist = listouter->ilist; - numneigh = listouter->numneigh; - firstneigh = listouter->firstneigh; + inum = list->inum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; double cut_in_off = cut_respa[2]; double cut_in_on = cut_respa[3]; double cut_in_diff = cut_in_on - cut_in_off; double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq < cut_bothsq) { jtype = type[j]; if (rsq < cut_coulsq) { r = sqrt(rsq); grij = g_ewald * r; expm2 = exp(-grij*grij); t = 1.0 / (1.0 + EWALD_P*grij); erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2; denc = sqrt(lj4[itype][jtype] + rsq); fprefactor = qqrd2e * lj1[itype][jtype] * qtmp*q[j] / (denc*denc*denc); forcecoul = fprefactor * (erfc + EWALD_F*grij*expm2 - 1.0); if (rsq > cut_in_off_sq) { if (rsq < cut_in_on_sq) { rsw = (r - cut_in_off)/cut_in_diff; forcecoul += fprefactor*rsw*rsw*(3.0 - 2.0*rsw); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*fprefactor*rsw*rsw*(3.0 - 2.0*rsw); } else { forcecoul += fprefactor; if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*fprefactor; } } } else forcecoul = 0.0; if (rsq < cut_ljsq && rsq > cut_in_off_sq) { r4sig6 = rsq*rsq / lj2[itype][jtype]; denlj = lj3[itype][jtype] + rsq*r4sig6; forcelj = lj1[itype][jtype] * epsilon[itype][jtype] * (48.0*r4sig6/(denlj*denlj*denlj) - 24.0*r4sig6/(denlj*denlj)); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) / denom_lj; switch2 = 12.0 * (cut_ljsq-rsq) * (rsq-cut_lj_innersq) / denom_lj; philj = lj1[itype][jtype] * 4.0 * epsilon[itype][jtype] * (1.0/(denlj*denlj) - 1.0/denlj); forcelj = forcelj*switch1 + philj*switch2; } if (rsq < cut_in_on_sq) { rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; forcelj *= rsw*rsw*(3.0 - 2.0*rsw); } } else forcelj = 0.0; fpair = forcecoul + forcelj; 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; } if (eflag) { if (rsq < cut_coulsq) { eprefactor = qqrd2e * lj1[itype][jtype] * qtmp*q[j] / denc; ecoul = eprefactor*erfc; if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*eprefactor; } else ecoul = 0.0; if (rsq < cut_ljsq) { r4sig6 = rsq*rsq / lj2[itype][jtype]; denlj = lj3[itype][jtype] + rsq*r4sig6; evdwl = lj1[itype][jtype] * 4.0 * epsilon[itype][jtype] * (1.0/(denlj*denlj) - 1.0/denlj); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) / denom_lj; evdwl *= switch1; } evdwl *= factor_lj; } else evdwl = 0.0; } if (vflag) { if (rsq < cut_coulsq) { forcecoul = fprefactor * (erfc + EWALD_F*grij*expm2); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*fprefactor; } else forcecoul = 0.0; if (rsq <= cut_in_off_sq) { r4sig6 = rsq*rsq / lj2[itype][jtype]; denlj = lj3[itype][jtype] + rsq*r4sig6; forcelj = lj1[itype][jtype] * epsilon[itype][jtype] * (48.0*r4sig6/(denlj*denlj*denlj) - 24.0*r4sig6/(denlj*denlj)); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) / denom_lj; switch2 = 12.0 * (cut_ljsq-rsq) * (rsq-cut_lj_innersq) / denom_lj; philj = lj1[itype][jtype] * 4.0 * epsilon[itype][jtype] * (1.0/(denlj*denlj) - 1.0/denlj); forcelj = forcelj*switch1 + philj*switch2; } } else if (rsq <= cut_in_on_sq) { r4sig6 = rsq*rsq / lj2[itype][jtype]; denlj = lj3[itype][jtype] + rsq*r4sig6; forcelj = lj1[itype][jtype] * epsilon[itype][jtype] * (48.0*r4sig6/(denlj*denlj*denlj) - 24.0*r4sig6/(denlj*denlj)); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) / denom_lj; switch2 = 12.0 * (cut_ljsq-rsq) * (rsq-cut_lj_innersq) / denom_lj; philj = lj1[itype][jtype] * 4.0 * epsilon[itype][jtype] * (1.0/(denlj*denlj) - 1.0/denlj); forcelj = forcelj*switch1 + philj*switch2; } } fpair = forcecoul + factor_lj*forcelj; } if (evflag) ev_tally(i,j,nlocal,newton_pair, evdwl,ecoul,fpair,delx,dely,delz); } } } } /* ---------------------------------------------------------------------- allocate all arrays ------------------------------------------------------------------------- */ void PairLJCharmmCoulLongSoft::allocate() { allocated = 1; int n = atom->ntypes; 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(cutsq,n+1,n+1,"pair:cutsq"); memory->create(epsilon,n+1,n+1,"pair:epsilon"); memory->create(sigma,n+1,n+1,"pair:sigma"); memory->create(lambda,n+1,n+1,"pair:lambda"); memory->create(eps14,n+1,n+1,"pair:eps14"); memory->create(sigma14,n+1,n+1,"pair:sigma14"); memory->create(lj1,n+1,n+1,"pair:lj1"); memory->create(lj2,n+1,n+1,"pair:lj2"); memory->create(lj3,n+1,n+1,"pair:lj3"); memory->create(lj4,n+1,n+1,"pair:lj4"); memory->create(lj14_1,n+1,n+1,"pair:lj14_1"); memory->create(lj14_2,n+1,n+1,"pair:lj14_2"); memory->create(lj14_3,n+1,n+1,"pair:lj14_3"); memory->create(lj14_4,n+1,n+1,"pair:lj14_4"); } /* ---------------------------------------------------------------------- global settings unlike other pair styles, there are no individual pair settings that these override ------------------------------------------------------------------------- */ void PairLJCharmmCoulLongSoft::settings(int narg, char **arg) { if (narg != 5 && narg != 6) error->all(FLERR,"Illegal pair_style command"); nlambda = force->numeric(FLERR,arg[0]); alphalj = force->numeric(FLERR,arg[1]); alphac = force->numeric(FLERR,arg[2]); cut_lj_inner = force->numeric(FLERR,arg[3]); cut_lj = force->numeric(FLERR,arg[4]); if (narg == 5) cut_coul = cut_lj; else cut_coul = force->numeric(FLERR,arg[5]); } /* ---------------------------------------------------------------------- set coeffs for one or more type pairs ------------------------------------------------------------------------- */ void PairLJCharmmCoulLongSoft::coeff(int narg, char **arg) { if (narg != 5 && narg != 7) error->all(FLERR,"Illegal pair_coeff command"); if (!allocated) allocate(); int ilo,ihi,jlo,jhi; force->bounds(FLERR,arg[0],atom->ntypes,ilo,ihi); force->bounds(FLERR,arg[1],atom->ntypes,jlo,jhi); double epsilon_one = force->numeric(FLERR,arg[2]); double sigma_one = force->numeric(FLERR,arg[3]); double lambda_one = force->numeric(FLERR,arg[4]); double eps14_one = epsilon_one; double sigma14_one = sigma_one; if (narg == 7) { eps14_one = force->numeric(FLERR,arg[5]); sigma14_one = force->numeric(FLERR,arg[6]); } int count = 0; for (int i = ilo; i <= ihi; i++) { for (int j = MAX(jlo,i); j <= jhi; j++) { epsilon[i][j] = epsilon_one; sigma[i][j] = sigma_one; lambda[i][j] = lambda_one; eps14[i][j] = eps14_one; sigma14[i][j] = sigma14_one; setflag[i][j] = 1; count++; } } if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- init specific to this pair style ------------------------------------------------------------------------- */ void PairLJCharmmCoulLongSoft::init_style() { if (!atom->q_flag) error->all(FLERR, "Pair style lj/charmm/coul/long/soft requires atom attribute q"); // request regular or rRESPA neighbor lists int irequest; if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; if (respa == 0) irequest = neighbor->request(this,instance_me); else if (respa == 1) { irequest = neighbor->request(this,instance_me); neighbor->requests[irequest]->id = 1; neighbor->requests[irequest]->half = 0; neighbor->requests[irequest]->respainner = 1; irequest = neighbor->request(this,instance_me); neighbor->requests[irequest]->id = 3; neighbor->requests[irequest]->half = 0; neighbor->requests[irequest]->respaouter = 1; } else { irequest = neighbor->request(this,instance_me); neighbor->requests[irequest]->id = 1; neighbor->requests[irequest]->half = 0; neighbor->requests[irequest]->respainner = 1; irequest = neighbor->request(this,instance_me); neighbor->requests[irequest]->id = 2; neighbor->requests[irequest]->half = 0; neighbor->requests[irequest]->respamiddle = 1; irequest = neighbor->request(this,instance_me); neighbor->requests[irequest]->id = 3; neighbor->requests[irequest]->half = 0; neighbor->requests[irequest]->respaouter = 1; } } else irequest = neighbor->request(this,instance_me); // require cut_lj_inner < cut_lj if (cut_lj_inner >= cut_lj) error->all(FLERR,"Pair inner cutoff >= Pair outer cutoff"); cut_lj_innersq = cut_lj_inner * cut_lj_inner; cut_ljsq = cut_lj * cut_lj; cut_coulsq = cut_coul * cut_coul; cut_bothsq = MAX(cut_ljsq,cut_coulsq); denom_lj = (cut_ljsq-cut_lj_innersq) * (cut_ljsq-cut_lj_innersq) * (cut_ljsq-cut_lj_innersq); // set & error check interior rRESPA cutoffs if (strstr(update->integrate_style,"respa") && ((Respa *) update->integrate)->level_inner >= 0) { cut_respa = ((Respa *) update->integrate)->cutoff; if (MIN(cut_lj,cut_coul) < cut_respa[3]) error->all(FLERR,"Pair cutoff < Respa interior cutoff"); if (cut_lj_inner < cut_respa[1]) error->all(FLERR,"Pair inner cutoff < Respa interior cutoff"); } else cut_respa = NULL; // insure use of KSpace long-range solver, set g_ewald if (force->kspace == NULL) error->all(FLERR,"Pair style requires a KSpace style"); g_ewald = force->kspace->g_ewald; } -/* ---------------------------------------------------------------------- - neighbor callback to inform pair style of neighbor list to use - regular or rRESPA -------------------------------------------------------------------------- */ - -void PairLJCharmmCoulLongSoft::init_list(int id, NeighList *ptr) -{ - if (id == 0) list = ptr; - else if (id == 1) listinner = ptr; - else if (id == 2) listmiddle = ptr; - else if (id == 3) listouter = ptr; -} - /* ---------------------------------------------------------------------- init for one type pair i,j and corresponding j,i ------------------------------------------------------------------------- */ double PairLJCharmmCoulLongSoft::init_one(int i, int j) { if (setflag[i][j] == 0) { epsilon[i][j] = mix_energy(epsilon[i][i],epsilon[j][j], sigma[i][i],sigma[j][j]); sigma[i][j] = mix_distance(sigma[i][i],sigma[j][j]); if (lambda[i][i] != lambda[j][j]) error->all(FLERR,"Pair lj/charmm/coul/long/soft different lambda values in mix"); lambda[i][j] = lambda[i][i]; eps14[i][j] = mix_energy(eps14[i][i],eps14[j][j], sigma14[i][i],sigma14[j][j]); sigma14[i][j] = mix_distance(sigma14[i][i],sigma14[j][j]); } double cut = MAX(cut_lj,cut_coul); lj1[i][j] = pow(lambda[i][j], nlambda); lj2[i][j] = pow(sigma[i][j], 6.0); lj3[i][j] = alphalj * (1.0 - lambda[i][j])*(1.0 - lambda[i][j]); lj4[i][j] = alphac * (1.0 - lambda[i][j])*(1.0 - lambda[i][j]); // 1-4 interactions unaffected (they're part of the dihedral term) lj14_1[i][j] = 48.0 * eps14[i][j] * pow(sigma14[i][j],12.0); lj14_2[i][j] = 24.0 * eps14[i][j] * pow(sigma14[i][j],6.0); lj14_3[i][j] = 4.0 * eps14[i][j] * pow(sigma14[i][j],12.0); lj14_4[i][j] = 4.0 * eps14[i][j] * pow(sigma14[i][j],6.0); epsilon[j][i] = epsilon[i][j]; sigma[j][i] = sigma[i][j]; lambda[j][i] = lambda[i][j]; lj1[j][i] = lj1[i][j]; lj2[j][i] = lj2[i][j]; lj3[j][i] = lj3[i][j]; lj4[j][i] = lj4[i][j]; lj14_1[j][i] = lj14_1[i][j]; lj14_2[j][i] = lj14_2[i][j]; lj14_3[j][i] = lj14_3[i][j]; lj14_4[j][i] = lj14_4[i][j]; return cut; } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairLJCharmmCoulLongSoft::write_restart(FILE *fp) { write_restart_settings(fp); int i,j; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { fwrite(&setflag[i][j],sizeof(int),1,fp); if (setflag[i][j]) { fwrite(&epsilon[i][j],sizeof(double),1,fp); fwrite(&sigma[i][j],sizeof(double),1,fp); fwrite(&lambda[i][j],sizeof(double),1,fp); fwrite(&eps14[i][j],sizeof(double),1,fp); fwrite(&sigma14[i][j],sizeof(double),1,fp); } } } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairLJCharmmCoulLongSoft::read_restart(FILE *fp) { read_restart_settings(fp); allocate(); int i,j; int me = comm->me; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp); MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world); if (setflag[i][j]) { if (me == 0) { fread(&epsilon[i][j],sizeof(double),1,fp); fread(&sigma[i][j],sizeof(double),1,fp); fread(&lambda[i][j],sizeof(double),1,fp); fread(&eps14[i][j],sizeof(double),1,fp); fread(&sigma14[i][j],sizeof(double),1,fp); } MPI_Bcast(&epsilon[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&sigma[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&lambda[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&eps14[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&sigma14[i][j],1,MPI_DOUBLE,0,world); } } } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairLJCharmmCoulLongSoft::write_restart_settings(FILE *fp) { fwrite(&nlambda,sizeof(double),1,fp); fwrite(&alphalj,sizeof(double),1,fp); fwrite(&alphac,sizeof(double),1,fp); fwrite(&cut_lj_inner,sizeof(double),1,fp); fwrite(&cut_lj,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); } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairLJCharmmCoulLongSoft::read_restart_settings(FILE *fp) { if (comm->me == 0) { fread(&nlambda,sizeof(double),1,fp); fread(&alphalj,sizeof(double),1,fp); fread(&alphac,sizeof(double),1,fp); fread(&cut_lj_inner,sizeof(double),1,fp); fread(&cut_lj,sizeof(double),1,fp); fread(&cut_coul,sizeof(double),1,fp); fread(&offset_flag,sizeof(int),1,fp); fread(&mix_flag,sizeof(int),1,fp); } MPI_Bcast(&nlambda,1,MPI_DOUBLE,0,world); MPI_Bcast(&alphalj,1,MPI_DOUBLE,0,world); MPI_Bcast(&alphac,1,MPI_DOUBLE,0,world); MPI_Bcast(&cut_lj_inner,1,MPI_DOUBLE,0,world); MPI_Bcast(&cut_lj,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); } /* ---------------------------------------------------------------------- proc 0 writes to data file ------------------------------------------------------------------------- */ void PairLJCharmmCoulLongSoft::write_data(FILE *fp) { for (int i = 1; i <= atom->ntypes; i++) fprintf(fp,"%d %g %g %g %g %g\n",i,epsilon[i][i],sigma[i][i], lambda[i][i],eps14[i][i],sigma14[i][i]); } /* ---------------------------------------------------------------------- proc 0 writes all pairs to data file ------------------------------------------------------------------------- */ void PairLJCharmmCoulLongSoft::write_data_all(FILE *fp) { for (int i = 1; i <= atom->ntypes; i++) for (int j = i; j <= atom->ntypes; j++) fprintf(fp,"%d %d %g %g %g %g %g\n",i,j,epsilon[i][j],sigma[i][j], lambda[i][j],eps14[i][j],sigma14[i][j]); } /* ---------------------------------------------------------------------- */ double PairLJCharmmCoulLongSoft::single(int i, int j, int itype, int jtype, double rsq, double factor_coul, double factor_lj, double &fforce) { double r,grij,expm2,t,erfc,prefactor; double switch1,switch2,forcecoul,forcelj,phicoul,philj; double denc, denlj, r4sig6; if (rsq < cut_coulsq) { r = sqrt(rsq); grij = g_ewald * r; expm2 = exp(-grij*grij); t = 1.0 / (1.0 + EWALD_P*grij); erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2; denc = sqrt(lj4[itype][jtype] + rsq); prefactor = force->qqrd2e * lj1[itype][jtype] * atom->q[i]*atom->q[j] / (denc*denc*denc); forcecoul = prefactor * (erfc + EWALD_F*grij*expm2); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; } else forcecoul = 0.0; if (rsq < cut_ljsq) { r4sig6 = rsq*rsq / lj2[itype][jtype]; denlj = lj3[itype][jtype] + rsq*r4sig6; forcelj = lj1[itype][jtype] * epsilon[itype][jtype] * (48.0*r4sig6/(denlj*denlj*denlj) - 24.0*r4sig6/(denlj*denlj)); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) / denom_lj; switch2 = 12.0 * (cut_ljsq-rsq) * (rsq-cut_lj_innersq) / denom_lj; philj = lj1[itype][jtype] * 4.0 * epsilon[itype][jtype] * (1.0/(denlj*denlj) - 1.0/denlj); forcelj = forcelj*switch1 + philj*switch2; } } else forcelj = 0.0; fforce = forcecoul + factor_lj*forcelj; double eng = 0.0; if (rsq < cut_coulsq) { prefactor = force->qqrd2e * lj1[itype][jtype] * atom->q[i]*atom->q[j] / denc; phicoul = prefactor*erfc; if (factor_coul < 1.0) phicoul -= (1.0-factor_coul)*prefactor; eng += phicoul; } if (rsq < cut_ljsq) { philj = lj1[itype][jtype] * 4.0 * epsilon[itype][jtype] * (1.0/(denlj*denlj) - 1.0/denlj); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) / denom_lj; philj *= switch1; } eng += factor_lj*philj; } return eng; } /* ---------------------------------------------------------------------- */ void *PairLJCharmmCoulLongSoft::extract(const char *str, int &dim) { dim = 2; if (strcmp(str,"lj14_1") == 0) return (void *) lj14_1; if (strcmp(str,"lj14_2") == 0) return (void *) lj14_2; if (strcmp(str,"lj14_3") == 0) return (void *) lj14_3; if (strcmp(str,"lj14_4") == 0) return (void *) lj14_4; if (strcmp(str,"epsilon") == 0) return (void *) epsilon; if (strcmp(str,"sigma") == 0) return (void *) sigma; if (strcmp(str,"lambda") == 0) return (void *) lambda; dim = 0; if (strcmp(str,"implicit") == 0) return (void *) &implicit; if (strcmp(str,"cut_coul") == 0) return (void *) &cut_coul; return NULL; } diff --git a/src/USER-FEP/pair_lj_charmm_coul_long_soft.h b/src/USER-FEP/pair_lj_charmm_coul_long_soft.h index 7e52ec54b..252c9f66f 100644 --- a/src/USER-FEP/pair_lj_charmm_coul_long_soft.h +++ b/src/USER-FEP/pair_lj_charmm_coul_long_soft.h @@ -1,107 +1,106 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #ifdef PAIR_CLASS PairStyle(lj/charmm/coul/long/soft,PairLJCharmmCoulLongSoft) #else #ifndef LMP_PAIR_LJ_CHARMM_COUL_LONG_SOFT_H #define LMP_PAIR_LJ_CHARMM_COUL_LONG_SOFT_H #include "pair.h" namespace LAMMPS_NS { class PairLJCharmmCoulLongSoft : public Pair { public: PairLJCharmmCoulLongSoft(class LAMMPS *); virtual ~PairLJCharmmCoulLongSoft(); virtual void compute(int, int); void settings(int, char **); void coeff(int, char **); void init_style(); - void init_list(int, class NeighList *); double init_one(int, int); void write_restart(FILE *); void read_restart(FILE *); void write_restart_settings(FILE *); void read_restart_settings(FILE *); void write_data(FILE *); void write_data_all(FILE *); virtual double single(int, int, int, int, double, double, double, double &); void compute_inner(); void compute_middle(); virtual void compute_outer(int, int); virtual void *extract(const char *, int &); protected: int implicit; double cut_lj_inner,cut_lj; double cut_lj_innersq,cut_ljsq; double cut_coul,cut_coulsq; double cut_bothsq; double denom_lj; double **epsilon,**sigma,**eps14,**sigma14,**lambda; double nlambda, alphalj, alphac; double **lj1,**lj2,**lj3,**lj4,**offset; double **lj14_1,**lj14_2,**lj14_3,**lj14_4; double *cut_respa; double g_ewald; void allocate(); }; } #endif #endif /* ERROR/WARNING messages: E: Illegal ... command Self-explanatory. Check the input script syntax and compare to the documentation for the command. You can use -echo screen as a command-line option when running LAMMPS to see the offending line. E: Incorrect args for pair coefficients Self-explanatory. Check the input script or data file. E: Pair style lj/charmm/coul/long/soft requires atom attribute q The atom style defined does not have these attributes. E: Pair inner cutoff >= Pair outer cutoff The specified cutoffs for the pair style are inconsistent. E: Pair cutoff < Respa interior cutoff One or more pairwise cutoffs are too short to use with the specified rRESPA cutoffs. E: Pair inner cutoff < Respa interior cutoff One or more pairwise cutoffs are too short to use with the specified rRESPA cutoffs. E: Pair style requires a KSpace style No kspace style is defined. */ diff --git a/src/USER-FEP/pair_lj_cut_coul_long_soft.cpp b/src/USER-FEP/pair_lj_cut_coul_long_soft.cpp index f7c4084fe..7be2ebabe 100644 --- a/src/USER-FEP/pair_lj_cut_coul_long_soft.cpp +++ b/src/USER-FEP/pair_lj_cut_coul_long_soft.cpp @@ -1,961 +1,948 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- Contributing author: Paul Crozier (SNL) Soft-core version: Agilio Padua (Univ Blaise Pascal & CNRS) ------------------------------------------------------------------------- */ #include #include #include #include #include "pair_lj_cut_coul_long_soft.h" #include "atom.h" #include "comm.h" #include "force.h" #include "kspace.h" #include "update.h" #include "integrate.h" #include "respa.h" #include "neighbor.h" #include "neigh_list.h" #include "neigh_request.h" #include "math_const.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; using namespace MathConst; #define EWALD_F 1.12837917 #define EWALD_P 0.3275911 #define A1 0.254829592 #define A2 -0.284496736 #define A3 1.421413741 #define A4 -1.453152027 #define A5 1.061405429 /* ---------------------------------------------------------------------- */ PairLJCutCoulLongSoft::PairLJCutCoulLongSoft(LAMMPS *lmp) : Pair(lmp) { ewaldflag = pppmflag = 1; respa_enable = 1; writedata = 1; qdist = 0.0; } /* ---------------------------------------------------------------------- */ PairLJCutCoulLongSoft::~PairLJCutCoulLongSoft() { if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(cut_lj); memory->destroy(cut_ljsq); memory->destroy(epsilon); memory->destroy(sigma); memory->destroy(lambda); memory->destroy(lj1); memory->destroy(lj2); memory->destroy(lj3); memory->destroy(lj4); memory->destroy(offset); } } /* ---------------------------------------------------------------------- */ void PairLJCutCoulLongSoft::compute(int eflag, int vflag) { int i,ii,j,jj,inum,jnum,itype,jtype; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair; double r,rsq,forcecoul,forcelj,factor_coul,factor_lj; double grij,expm2,prefactor,t,erfc; double denc, denlj, r4sig6; int *ilist,*jlist,*numneigh,**firstneigh; evdwl = ecoul = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; inum = list->inum; ilist = list->ilist; numneigh = list->numneigh; firstneigh = list->firstneigh; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; if (rsq < cutsq[itype][jtype]) { if (rsq < cut_coulsq) { r = sqrt(rsq); grij = g_ewald * r; expm2 = exp(-grij*grij); t = 1.0 / (1.0 + EWALD_P*grij); erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2; denc = sqrt(lj4[itype][jtype] + rsq); prefactor = qqrd2e * lj1[itype][jtype] * qtmp*q[j] / (denc*denc*denc); forcecoul = prefactor * (erfc + EWALD_F*grij*expm2); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; } else forcecoul = 0.0; if (rsq < cut_ljsq[itype][jtype]) { r4sig6 = rsq*rsq / lj2[itype][jtype]; denlj = lj3[itype][jtype] + rsq*r4sig6; forcelj = lj1[itype][jtype] * epsilon[itype][jtype] * (48.0*r4sig6/(denlj*denlj*denlj) - 24.0*r4sig6/(denlj*denlj)); } else forcelj = 0.0; fpair = forcecoul + factor_lj*forcelj; 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; } if (eflag) { if (rsq < cut_coulsq) { prefactor = qqrd2e * lj1[itype][jtype] * qtmp*q[j] / denc; ecoul = prefactor*erfc; if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; } else ecoul = 0.0; if (rsq < cut_ljsq[itype][jtype]) { evdwl = lj1[itype][jtype] * 4.0 * epsilon[itype][jtype] * (1.0/(denlj*denlj) - 1.0/denlj) - offset[itype][jtype]; evdwl *= factor_lj; } else evdwl = 0.0; } if (evflag) ev_tally(i,j,nlocal,newton_pair, evdwl,ecoul,fpair,delx,dely,delz); } } } if (vflag_fdotr) virial_fdotr_compute(); } /* ---------------------------------------------------------------------- */ void PairLJCutCoulLongSoft::compute_inner() { int i,j,ii,jj,inum,jnum,itype,jtype; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fpair; double rsq,forcecoul,forcelj,factor_coul,factor_lj; double rsw; double denc, denlj, r4sig6; int *ilist,*jlist,*numneigh,**firstneigh; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; - inum = listinner->inum; - ilist = listinner->ilist; - numneigh = listinner->numneigh; - firstneigh = listinner->firstneigh; + inum = list->inum_inner; + ilist = list->ilist_inner; + numneigh = list->numneigh_inner; + firstneigh = list->firstneigh_inner; double cut_out_on = cut_respa[0]; double cut_out_off = cut_respa[1]; double cut_out_diff = cut_out_off - cut_out_on; double cut_out_on_sq = cut_out_on*cut_out_on; double cut_out_off_sq = cut_out_off*cut_out_off; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq < cut_out_off_sq) { jtype = type[j]; denc = sqrt(lj4[itype][jtype] + rsq); forcecoul = qqrd2e * lj1[itype][jtype] * qtmp*q[j] / (denc*denc*denc); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*forcecoul; if (rsq < cut_ljsq[itype][jtype]) { r4sig6 = rsq*rsq / lj2[itype][jtype]; denlj = lj3[itype][jtype] + rsq*r4sig6; forcelj = lj1[itype][jtype] * epsilon[itype][jtype] * (48.0*r4sig6/(denlj*denlj*denlj) - 24.0*r4sig6/(denlj*denlj)); } else forcelj = 0.0; fpair = forcecoul + factor_lj*forcelj; if (rsq > cut_out_on_sq) { rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; fpair *= 1.0 + rsw*rsw*(2.0*rsw-3.0); } 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; } } } } } /* ---------------------------------------------------------------------- */ void PairLJCutCoulLongSoft::compute_middle() { int i,j,ii,jj,inum,jnum,itype,jtype; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fpair; double rsq,forcecoul,forcelj,factor_coul,factor_lj; double rsw; double denc, denlj, r4sig6; int *ilist,*jlist,*numneigh,**firstneigh; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; - inum = listmiddle->inum; - ilist = listmiddle->ilist; - numneigh = listmiddle->numneigh; - firstneigh = listmiddle->firstneigh; + inum = list->inum_middle; + ilist = list->ilist_middle; + numneigh = list->numneigh_middle; + firstneigh = list->firstneigh_middle; double cut_in_off = cut_respa[0]; double cut_in_on = cut_respa[1]; double cut_out_on = cut_respa[2]; double cut_out_off = cut_respa[3]; double cut_in_diff = cut_in_on - cut_in_off; double cut_out_diff = cut_out_off - cut_out_on; double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; double cut_out_on_sq = cut_out_on*cut_out_on; double cut_out_off_sq = cut_out_off*cut_out_off; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq < cut_out_off_sq && rsq > cut_in_off_sq) { jtype = type[j]; denc = sqrt(lj4[itype][jtype] + rsq); forcecoul = qqrd2e * lj1[itype][jtype] * qtmp*q[j] / (denc*denc*denc); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*forcecoul; if (rsq < cut_ljsq[itype][jtype]) { r4sig6 = rsq*rsq / lj2[itype][jtype]; denlj = lj3[itype][jtype] + rsq*r4sig6; forcelj = lj1[itype][jtype] * epsilon[itype][jtype] * (48.0*r4sig6/(denlj*denlj*denlj) - 24.0*r4sig6/(denlj*denlj)); } else forcelj = 0.0; fpair = forcecoul + factor_lj*forcelj; if (rsq < cut_in_on_sq) { rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; fpair *= rsw*rsw*(3.0 - 2.0*rsw); } if (rsq > cut_out_on_sq) { rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; fpair *= 1.0 + rsw*rsw*(2.0*rsw - 3.0); } 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; } } } } } /* ---------------------------------------------------------------------- */ void PairLJCutCoulLongSoft::compute_outer(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair; double r,rsq,forcecoul,forcelj,factor_coul,factor_lj; double grij,expm2,fprefactor,eprefactor,t,erfc; double rsw; double denc, denlj, r4sig6; int *ilist,*jlist,*numneigh,**firstneigh; evdwl = ecoul = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; - inum = listouter->inum; - ilist = listouter->ilist; - numneigh = listouter->numneigh; - firstneigh = listouter->firstneigh; + inum = list->inum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; double cut_in_off = cut_respa[2]; double cut_in_on = cut_respa[3]; double cut_in_diff = cut_in_on - cut_in_off; double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; if (rsq < cutsq[itype][jtype]) { if (rsq < cut_coulsq) { r = sqrt(rsq); grij = g_ewald * r; expm2 = exp(-grij*grij); t = 1.0 / (1.0 + EWALD_P*grij); erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2; denc = sqrt(lj4[itype][jtype] + rsq); fprefactor = qqrd2e * lj1[itype][jtype] * qtmp*q[j] / (denc*denc*denc); forcecoul = fprefactor * (erfc + EWALD_F*grij*expm2 - 1.0); if (rsq > cut_in_off_sq) { if (rsq < cut_in_on_sq) { rsw = (r - cut_in_off)/cut_in_diff; forcecoul += fprefactor*rsw*rsw*(3.0 - 2.0*rsw); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*fprefactor*rsw*rsw*(3.0 - 2.0*rsw); } else { forcecoul += fprefactor; if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*fprefactor; } } } else forcecoul = 0.0; if (rsq < cut_ljsq[itype][jtype] && rsq > cut_in_off_sq) { r4sig6 = rsq*rsq / lj2[itype][jtype]; denlj = lj3[itype][jtype] + rsq*r4sig6; forcelj = lj1[itype][jtype] * epsilon[itype][jtype] * (48.0*r4sig6/(denlj*denlj*denlj) - 24.0*r4sig6/(denlj*denlj)); if (rsq < cut_in_on_sq) { rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; forcelj *= rsw*rsw*(3.0 - 2.0*rsw); } } else forcelj = 0.0; fpair = forcecoul + forcelj; 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; } if (eflag) { if (rsq < cut_coulsq) { eprefactor = qqrd2e * lj1[itype][jtype] * qtmp*q[j] / denc; ecoul = eprefactor*erfc; if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*eprefactor; } else ecoul = 0.0; if (rsq < cut_ljsq[itype][jtype]) { r4sig6 = rsq*rsq / lj2[itype][jtype]; denlj = lj3[itype][jtype] + rsq*r4sig6; evdwl = lj1[itype][jtype] * 4.0 * epsilon[itype][jtype] * (1.0/(denlj*denlj) - 1.0/denlj) - offset[itype][jtype]; evdwl *= factor_lj; } else evdwl = 0.0; } if (vflag) { if (rsq < cut_coulsq) { forcecoul = fprefactor * (erfc + EWALD_F*grij*expm2); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*fprefactor; } else forcecoul = 0.0; if (rsq <= cut_in_off_sq) { r4sig6 = rsq*rsq / lj2[itype][jtype]; denlj = lj3[itype][jtype] + rsq*r4sig6; forcelj = lj1[itype][jtype] * epsilon[itype][jtype] * (48.0*r4sig6/(denlj*denlj*denlj) - 24.0*r4sig6/(denlj*denlj)); } else if (rsq < cut_in_on_sq) { r4sig6 = rsq*rsq / lj2[itype][jtype]; denlj = lj3[itype][jtype] + rsq*r4sig6; forcelj = lj1[itype][jtype] * epsilon[itype][jtype] * (48.0*r4sig6/(denlj*denlj*denlj) - 24.0*r4sig6/(denlj*denlj)); } fpair = forcecoul + factor_lj*forcelj; } if (evflag) ev_tally(i,j,nlocal,newton_pair, evdwl,ecoul,fpair,delx,dely,delz); } } } } /* ---------------------------------------------------------------------- allocate all arrays ------------------------------------------------------------------------- */ void PairLJCutCoulLongSoft::allocate() { allocated = 1; int n = atom->ntypes; 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(cutsq,n+1,n+1,"pair:cutsq"); memory->create(cut_lj,n+1,n+1,"pair:cut_lj"); memory->create(cut_ljsq,n+1,n+1,"pair:cut_ljsq"); memory->create(epsilon,n+1,n+1,"pair:epsilon"); memory->create(sigma,n+1,n+1,"pair:sigma"); memory->create(lambda,n+1,n+1,"pair:lambda"); memory->create(lj1,n+1,n+1,"pair:lj1"); memory->create(lj2,n+1,n+1,"pair:lj2"); memory->create(lj3,n+1,n+1,"pair:lj3"); memory->create(lj4,n+1,n+1,"pair:lj4"); memory->create(offset,n+1,n+1,"pair:offset"); } /* ---------------------------------------------------------------------- global settings ------------------------------------------------------------------------- */ void PairLJCutCoulLongSoft::settings(int narg, char **arg) { if (narg < 4 || narg > 5) error->all(FLERR,"Illegal pair_style command"); nlambda = force->numeric(FLERR,arg[0]); alphalj = force->numeric(FLERR,arg[1]); alphac = force->numeric(FLERR,arg[2]); cut_lj_global = force->numeric(FLERR,arg[3]); if (narg == 4) cut_coul = cut_lj_global; else cut_coul = force->numeric(FLERR,arg[4]); // reset cutoffs that have been explicitly set if (allocated) { int i,j; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) if (setflag[i][j]) cut_lj[i][j] = cut_lj_global; } } /* ---------------------------------------------------------------------- set coeffs for one or more type pairs ------------------------------------------------------------------------- */ void PairLJCutCoulLongSoft::coeff(int narg, char **arg) { if (narg < 5 || narg > 6) error->all(FLERR,"Incorrect args for pair coefficients"); if (!allocated) allocate(); int ilo,ihi,jlo,jhi; force->bounds(FLERR,arg[0],atom->ntypes,ilo,ihi); force->bounds(FLERR,arg[1],atom->ntypes,jlo,jhi); double epsilon_one = force->numeric(FLERR,arg[2]); double sigma_one = force->numeric(FLERR,arg[3]); double lambda_one = force->numeric(FLERR,arg[4]); if (sigma_one <= 0.0) error->all(FLERR,"Incorrect args for pair coefficients"); double cut_lj_one = cut_lj_global; if (narg == 6) cut_lj_one = force->numeric(FLERR,arg[5]); int count = 0; for (int i = ilo; i <= ihi; i++) { for (int j = MAX(jlo,i); j <= jhi; j++) { epsilon[i][j] = epsilon_one; sigma[i][j] = sigma_one; lambda[i][j] = lambda_one; cut_lj[i][j] = cut_lj_one; setflag[i][j] = 1; count++; } } if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- init specific to this pair style ------------------------------------------------------------------------- */ void PairLJCutCoulLongSoft::init_style() { if (!atom->q_flag) error->all(FLERR,"Pair style lj/cut/coul/long/soft requires atom attribute q"); // request regular or rRESPA neighbor lists int irequest; if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; if (respa == 0) irequest = neighbor->request(this,instance_me); else if (respa == 1) { irequest = neighbor->request(this,instance_me); neighbor->requests[irequest]->id = 1; neighbor->requests[irequest]->half = 0; neighbor->requests[irequest]->respainner = 1; irequest = neighbor->request(this,instance_me); neighbor->requests[irequest]->id = 3; neighbor->requests[irequest]->half = 0; neighbor->requests[irequest]->respaouter = 1; } else { irequest = neighbor->request(this,instance_me); neighbor->requests[irequest]->id = 1; neighbor->requests[irequest]->half = 0; neighbor->requests[irequest]->respainner = 1; irequest = neighbor->request(this,instance_me); neighbor->requests[irequest]->id = 2; neighbor->requests[irequest]->half = 0; neighbor->requests[irequest]->respamiddle = 1; irequest = neighbor->request(this,instance_me); neighbor->requests[irequest]->id = 3; neighbor->requests[irequest]->half = 0; neighbor->requests[irequest]->respaouter = 1; } } else irequest = neighbor->request(this,instance_me); cut_coulsq = cut_coul * cut_coul; // set rRESPA cutoffs if (strstr(update->integrate_style,"respa") && ((Respa *) update->integrate)->level_inner >= 0) cut_respa = ((Respa *) update->integrate)->cutoff; else cut_respa = NULL; // insure use of KSpace long-range solver, set g_ewald if (force->kspace == NULL) error->all(FLERR,"Pair style requires a KSpace style"); g_ewald = force->kspace->g_ewald; } -/* ---------------------------------------------------------------------- - neighbor callback to inform pair style of neighbor list to use - regular or rRESPA -------------------------------------------------------------------------- */ - -void PairLJCutCoulLongSoft::init_list(int id, NeighList *ptr) -{ - if (id == 0) list = ptr; - else if (id == 1) listinner = ptr; - else if (id == 2) listmiddle = ptr; - else if (id == 3) listouter = ptr; -} - /* ---------------------------------------------------------------------- init for one type pair i,j and corresponding j,i ------------------------------------------------------------------------- */ double PairLJCutCoulLongSoft::init_one(int i, int j) { if (setflag[i][j] == 0) { epsilon[i][j] = mix_energy(epsilon[i][i],epsilon[j][j], sigma[i][i],sigma[j][j]); sigma[i][j] = mix_distance(sigma[i][i],sigma[j][j]); if (lambda[i][i] != lambda[j][j]) error->all(FLERR,"Pair lj/cut/coul/long/soft different lambda values in mix"); lambda[i][j] = lambda[i][i]; cut_lj[i][j] = mix_distance(cut_lj[i][i],cut_lj[j][j]); } // include TIP4P qdist in full cutoff, qdist = 0.0 if not TIP4P double cut = MAX(cut_lj[i][j],cut_coul+2.0*qdist); cut_ljsq[i][j] = cut_lj[i][j] * cut_lj[i][j]; lj1[i][j] = pow(lambda[i][j], nlambda); lj2[i][j] = pow(sigma[i][j], 6.0); lj3[i][j] = alphalj * (1.0 - lambda[i][j])*(1.0 - lambda[i][j]); lj4[i][j] = alphac * (1.0 - lambda[i][j])*(1.0 - lambda[i][j]); if (offset_flag && (cut_lj[i][j] > 0.0)) { double denlj = lj3[i][j] + pow(cut_lj[i][j] / sigma[i][j], 6.0); offset[i][j] = lj1[i][j] * 4.0 * epsilon[i][j] * (1.0/(denlj*denlj) - 1.0/denlj); } else offset[i][j] = 0.0; epsilon[j][i] = epsilon[i][j]; sigma[j][i] = sigma[i][j]; lambda[j][i] = lambda[i][j]; cut_ljsq[j][i] = cut_ljsq[i][j]; lj1[j][i] = lj1[i][j]; lj2[j][i] = lj2[i][j]; lj3[j][i] = lj3[i][j]; lj4[j][i] = lj4[i][j]; offset[j][i] = offset[i][j]; // check interior rRESPA cutoff if (cut_respa && MIN(cut_lj[i][j],cut_coul) < cut_respa[3]) error->all(FLERR,"Pair cutoff < Respa interior cutoff"); // compute I,J contribution to long-range tail correction // count total # of atoms of type I and J via Allreduce if (tail_flag) { int *type = atom->type; int nlocal = atom->nlocal; double count[2],all[2]; count[0] = count[1] = 0.0; for (int k = 0; k < nlocal; k++) { if (type[k] == i) count[0] += 1.0; if (type[k] == j) count[1] += 1.0; } MPI_Allreduce(count,all,2,MPI_DOUBLE,MPI_SUM,world); double sig2 = sigma[i][j]*sigma[i][j]; double sig6 = sig2*sig2*sig2; double rc3 = cut_lj[i][j]*cut_lj[i][j]*cut_lj[i][j]; double rc6 = rc3*rc3; double rc9 = rc3*rc6; etail_ij = 8.0*MY_PI*all[0]*all[1]* lj1[i][j] * epsilon[i][j] * sig6 * (sig6 - 3.0*rc6) / (9.0*rc9); ptail_ij = 16.0*MY_PI*all[0]*all[1]* lj1[i][j] * epsilon[i][j] * sig6 * (2.0*sig6 - 3.0*rc6) / (9.0*rc9); } return cut; } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairLJCutCoulLongSoft::write_restart(FILE *fp) { write_restart_settings(fp); int i,j; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { fwrite(&setflag[i][j],sizeof(int),1,fp); if (setflag[i][j]) { fwrite(&epsilon[i][j],sizeof(double),1,fp); fwrite(&sigma[i][j],sizeof(double),1,fp); fwrite(&lambda[i][j],sizeof(double),1,fp); fwrite(&cut_lj[i][j],sizeof(double),1,fp); } } } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairLJCutCoulLongSoft::read_restart(FILE *fp) { read_restart_settings(fp); allocate(); int i,j; int me = comm->me; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp); MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world); if (setflag[i][j]) { if (me == 0) { fread(&epsilon[i][j],sizeof(double),1,fp); fread(&sigma[i][j],sizeof(double),1,fp); fread(&lambda[i][j],sizeof(double),1,fp); fread(&cut_lj[i][j],sizeof(double),1,fp); } MPI_Bcast(&epsilon[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&sigma[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&lambda[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&cut_lj[i][j],1,MPI_DOUBLE,0,world); } } } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairLJCutCoulLongSoft::write_restart_settings(FILE *fp) { fwrite(&nlambda,sizeof(double),1,fp); fwrite(&alphalj,sizeof(double),1,fp); fwrite(&alphac,sizeof(double),1,fp); fwrite(&cut_lj_global,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(&tail_flag,sizeof(int),1,fp); } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairLJCutCoulLongSoft::read_restart_settings(FILE *fp) { if (comm->me == 0) { fread(&nlambda,sizeof(double),1,fp); fread(&alphalj,sizeof(double),1,fp); fread(&alphac,sizeof(double),1,fp); fread(&cut_lj_global,sizeof(double),1,fp); fread(&cut_coul,sizeof(double),1,fp); fread(&offset_flag,sizeof(int),1,fp); fread(&mix_flag,sizeof(int),1,fp); fread(&tail_flag,sizeof(int),1,fp); } MPI_Bcast(&nlambda,1,MPI_DOUBLE,0,world); MPI_Bcast(&alphalj,1,MPI_DOUBLE,0,world); MPI_Bcast(&alphac,1,MPI_DOUBLE,0,world); MPI_Bcast(&cut_lj_global,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(&tail_flag,1,MPI_INT,0,world); } /* ---------------------------------------------------------------------- proc 0 writes to data file ------------------------------------------------------------------------- */ void PairLJCutCoulLongSoft::write_data(FILE *fp) { for (int i = 1; i <= atom->ntypes; i++) fprintf(fp,"%d %g %g %g\n",i,epsilon[i][i],sigma[i][i],lambda[i][i]); } /* ---------------------------------------------------------------------- proc 0 writes all pairs to data file ------------------------------------------------------------------------- */ void PairLJCutCoulLongSoft::write_data_all(FILE *fp) { for (int i = 1; i <= atom->ntypes; i++) for (int j = i; j <= atom->ntypes; j++) fprintf(fp,"%d %d %g %g %g %g\n",i,j,epsilon[i][j],sigma[i][j], lambda[i][j],cut_lj[i][j]); } /* ---------------------------------------------------------------------- */ double PairLJCutCoulLongSoft::single(int i, int j, int itype, int jtype, double rsq, double factor_coul, double factor_lj, double &fforce) { double r,grij,expm2,t,erfc,prefactor; double forcecoul,forcelj,phicoul,philj; double denc, denlj, r4sig6; if (rsq < cut_coulsq) { r = sqrt(rsq); grij = g_ewald * r; expm2 = exp(-grij*grij); t = 1.0 / (1.0 + EWALD_P*grij); erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2; denc = sqrt(lj4[itype][jtype] + rsq); prefactor = force->qqrd2e * lj1[itype][jtype] * atom->q[i]*atom->q[j] / (denc*denc*denc); forcecoul = prefactor * (erfc + EWALD_F*grij*expm2); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; } else forcecoul = 0.0; if (rsq < cut_ljsq[itype][jtype]) { r4sig6 = rsq*rsq / lj2[itype][jtype]; denlj = lj3[itype][jtype] + rsq*r4sig6; forcelj = lj1[itype][jtype] * epsilon[itype][jtype] * (48.0*r4sig6/(denlj*denlj*denlj) - 24.0*r4sig6/(denlj*denlj)); } else forcelj = 0.0; fforce = forcecoul + factor_lj*forcelj; double eng = 0.0; if (rsq < cut_coulsq) { prefactor = force->qqrd2e * lj1[itype][jtype] * atom->q[i]*atom->q[j] / denc; phicoul = prefactor*erfc; if (factor_coul < 1.0) phicoul -= (1.0-factor_coul)*prefactor; eng += phicoul; } if (rsq < cut_ljsq[itype][jtype]) { philj = lj1[itype][jtype] * 4.0 * epsilon[itype][jtype] * (1.0/(denlj*denlj) - 1.0/denlj) - offset[itype][jtype]; eng += factor_lj*philj; } return eng; } /* ---------------------------------------------------------------------- */ void *PairLJCutCoulLongSoft::extract(const char *str, int &dim) { dim = 0; if (strcmp(str,"cut_coul") == 0) return (void *) &cut_coul; dim = 2; if (strcmp(str,"epsilon") == 0) return (void *) epsilon; if (strcmp(str,"sigma") == 0) return (void *) sigma; if (strcmp(str,"lambda") == 0) return (void *) lambda; return NULL; } diff --git a/src/USER-FEP/pair_lj_cut_coul_long_soft.h b/src/USER-FEP/pair_lj_cut_coul_long_soft.h index a03be3814..d49d1c864 100644 --- a/src/USER-FEP/pair_lj_cut_coul_long_soft.h +++ b/src/USER-FEP/pair_lj_cut_coul_long_soft.h @@ -1,94 +1,93 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #ifdef PAIR_CLASS PairStyle(lj/cut/coul/long/soft,PairLJCutCoulLongSoft) #else #ifndef LMP_PAIR_LJ_CUT_COUL_LONG_SOFT_H #define LMP_PAIR_LJ_CUT_COUL_LONG_SOFT_H #include "pair.h" namespace LAMMPS_NS { class PairLJCutCoulLongSoft : public Pair { public: PairLJCutCoulLongSoft(class LAMMPS *); virtual ~PairLJCutCoulLongSoft(); virtual void compute(int, int); virtual void settings(int, char **); void coeff(int, char **); virtual void init_style(); - void init_list(int, class NeighList *); virtual double init_one(int, int); void write_restart(FILE *); void read_restart(FILE *); virtual void write_restart_settings(FILE *); virtual void read_restart_settings(FILE *); void write_data(FILE *); void write_data_all(FILE *); virtual double single(int, int, int, int, double, double, double, double &); virtual void *extract(const char *, int &); void compute_inner(); void compute_middle(); virtual void compute_outer(int, int); protected: double cut_lj_global; double **cut_lj,**cut_ljsq; double cut_coul,cut_coulsq; double **epsilon,**sigma, **lambda; double nlambda, alphalj, alphac; double **lj1,**lj2,**lj3,**lj4,**offset; double *cut_respa; double qdist; // TIP4P distance O to negative charge (compatibility of cutoffs) double g_ewald; void allocate(); }; } #endif #endif /* ERROR/WARNING messages: E: Illegal ... command Self-explanatory. Check the input script syntax and compare to the documentation for the command. You can use -echo screen as a command-line option when running LAMMPS to see the offending line. E: Incorrect args for pair coefficients Self-explanatory. Check the input script or data file. E: Pair style lj/cut/coul/long requires atom attribute q The atom style defined does not have this attribute. E: Pair style requires a KSpace style No kspace style is defined. E: Pair cutoff < Respa interior cutoff One or more pairwise cutoffs are too short to use with the specified rRESPA cutoffs. */ diff --git a/src/USER-FEP/pair_lj_cut_soft.cpp b/src/USER-FEP/pair_lj_cut_soft.cpp index 8b6280a61..9ae108fa3 100644 --- a/src/USER-FEP/pair_lj_cut_soft.cpp +++ b/src/USER-FEP/pair_lj_cut_soft.cpp @@ -1,783 +1,770 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- Contributing author: Paul Crozier (SNL) Soft-core version: Agilio Padua (Univ Blaise Pascal & CNRS) ------------------------------------------------------------------------- */ #include #include #include #include #include "pair_lj_cut_soft.h" #include "atom.h" #include "comm.h" #include "force.h" #include "neighbor.h" #include "neigh_list.h" #include "neigh_request.h" #include "update.h" #include "integrate.h" #include "respa.h" #include "math_const.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; using namespace MathConst; /* ---------------------------------------------------------------------- */ PairLJCutSoft::PairLJCutSoft(LAMMPS *lmp) : Pair(lmp) { respa_enable = 1; writedata = 1; allocated = 0; } /* ---------------------------------------------------------------------- */ PairLJCutSoft::~PairLJCutSoft() { if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(cut); memory->destroy(epsilon); memory->destroy(sigma); memory->destroy(lambda); memory->destroy(lj1); memory->destroy(lj2); memory->destroy(lj3); memory->destroy(offset); allocated=0; } } /* ---------------------------------------------------------------------- */ void PairLJCutSoft::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; double rsq,forcelj,factor_lj; double denlj, r4sig6; int *ilist,*jlist,*numneigh,**firstneigh; evdwl = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; inum = list->inum; ilist = list->ilist; numneigh = list->numneigh; firstneigh = list->firstneigh; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; if (rsq < cutsq[itype][jtype]) { r4sig6 = rsq*rsq / lj2[itype][jtype]; denlj = lj3[itype][jtype] + rsq*r4sig6; forcelj = lj1[itype][jtype] * epsilon[itype][jtype] * (48.0*r4sig6/(denlj*denlj*denlj) - 24.0*r4sig6/(denlj*denlj)); fpair = factor_lj*forcelj; 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; } if (eflag) { evdwl = lj1[itype][jtype] * 4.0 * epsilon[itype][jtype] * (1.0/(denlj*denlj) - 1.0/denlj) - offset[itype][jtype]; evdwl *= factor_lj; } if (evflag) ev_tally(i,j,nlocal,newton_pair, evdwl,0.0,fpair,delx,dely,delz); } } } if (vflag_fdotr) virial_fdotr_compute(); } /* ---------------------------------------------------------------------- */ void PairLJCutSoft::compute_inner() { int i,j,ii,jj,inum,jnum,itype,jtype; double xtmp,ytmp,ztmp,delx,dely,delz,fpair; double rsq,forcelj,factor_lj,rsw; double denlj, r4sig6; int *ilist,*jlist,*numneigh,**firstneigh; double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; - inum = listinner->inum; - ilist = listinner->ilist; - numneigh = listinner->numneigh; - firstneigh = listinner->firstneigh; + inum = list->inum_inner; + ilist = list->ilist_inner; + numneigh = list->numneigh_inner; + firstneigh = list->firstneigh_inner; double cut_out_on = cut_respa[0]; double cut_out_off = cut_respa[1]; double cut_out_diff = cut_out_off - cut_out_on; double cut_out_on_sq = cut_out_on*cut_out_on; double cut_out_off_sq = cut_out_off*cut_out_off; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq < cut_out_off_sq) { jtype = type[j]; r4sig6 = rsq*rsq / lj2[itype][jtype]; denlj = lj3[itype][jtype] + rsq*r4sig6; forcelj = lj1[itype][jtype] * epsilon[itype][jtype] * (48.0*r4sig6/(denlj*denlj*denlj) - 24.0*r4sig6/(denlj*denlj)); fpair = factor_lj*forcelj; if (rsq > cut_out_on_sq) { rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; fpair *= 1.0 - rsw*rsw*(3.0 - 2.0*rsw); } 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; } } } } } /* ---------------------------------------------------------------------- */ void PairLJCutSoft::compute_middle() { int i,j,ii,jj,inum,jnum,itype,jtype; double xtmp,ytmp,ztmp,delx,dely,delz,fpair; double rsq,forcelj,factor_lj,rsw; double denlj, r4sig6; int *ilist,*jlist,*numneigh,**firstneigh; double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; - inum = listmiddle->inum; - ilist = listmiddle->ilist; - numneigh = listmiddle->numneigh; - firstneigh = listmiddle->firstneigh; + inum = list->inum_middle; + ilist = list->ilist_middle; + numneigh = list->numneigh_middle; + firstneigh = list->firstneigh_middle; double cut_in_off = cut_respa[0]; double cut_in_on = cut_respa[1]; double cut_out_on = cut_respa[2]; double cut_out_off = cut_respa[3]; double cut_in_diff = cut_in_on - cut_in_off; double cut_out_diff = cut_out_off - cut_out_on; double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; double cut_out_on_sq = cut_out_on*cut_out_on; double cut_out_off_sq = cut_out_off*cut_out_off; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq < cut_out_off_sq && rsq > cut_in_off_sq) { jtype = type[j]; r4sig6 = rsq*rsq / lj2[itype][jtype]; denlj = lj3[itype][jtype] + rsq*r4sig6; forcelj = lj1[itype][jtype] * epsilon[itype][jtype] * (48.0*r4sig6/(denlj*denlj*denlj) - 24.0*r4sig6/(denlj*denlj)); fpair = factor_lj*forcelj; if (rsq < cut_in_on_sq) { rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; fpair *= rsw*rsw*(3.0 - 2.0*rsw); } if (rsq > cut_out_on_sq) { rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; fpair *= 1.0 + rsw*rsw*(2.0*rsw - 3.0); } 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; } } } } } /* ---------------------------------------------------------------------- */ void PairLJCutSoft::compute_outer(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; double rsq,forcelj,factor_lj,rsw; double denlj, r4sig6; int *ilist,*jlist,*numneigh,**firstneigh; evdwl = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = 0; double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; - inum = listouter->inum; - ilist = listouter->ilist; - numneigh = listouter->numneigh; - firstneigh = listouter->firstneigh; + inum = list->inum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; double cut_in_off = cut_respa[2]; double cut_in_on = cut_respa[3]; double cut_in_diff = cut_in_on - cut_in_off; double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; if (rsq < cutsq[itype][jtype]) { if (rsq > cut_in_off_sq) { r4sig6 = rsq*rsq / lj2[itype][jtype]; denlj = lj3[itype][jtype] + rsq*r4sig6; forcelj = lj1[itype][jtype] * epsilon[itype][jtype] * (48.0*r4sig6/(denlj*denlj*denlj) - 24.0*r4sig6/(denlj*denlj)); fpair = factor_lj*forcelj; if (rsq < cut_in_on_sq) { rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; fpair *= rsw*rsw*(3.0 - 2.0*rsw); } 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; } } if (eflag) { r4sig6 = rsq*rsq / lj2[itype][jtype]; denlj = lj3[itype][jtype] + rsq*r4sig6; evdwl = lj1[itype][jtype] * 4.0 * epsilon[itype][jtype] * (1.0/(denlj*denlj) - 1.0/denlj) - offset[itype][jtype]; evdwl *= factor_lj; } if (vflag) { if (rsq <= cut_in_off_sq) { r4sig6 = rsq*rsq / lj2[itype][jtype]; denlj = lj3[itype][jtype] + rsq*r4sig6; forcelj = lj1[itype][jtype] * epsilon[itype][jtype] * (48.0*r4sig6/(denlj*denlj*denlj) - 24.0*r4sig6/(denlj*denlj)); fpair = factor_lj*forcelj; } else if (rsq < cut_in_on_sq) fpair = factor_lj*forcelj; } if (evflag) ev_tally(i,j,nlocal,newton_pair, evdwl,0.0,fpair,delx,dely,delz); } } } } /* ---------------------------------------------------------------------- allocate all arrays ------------------------------------------------------------------------- */ void PairLJCutSoft::allocate() { allocated = 1; int n = atom->ntypes; 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(cutsq,n+1,n+1,"pair:cutsq"); memory->create(cut,n+1,n+1,"pair:cut"); memory->create(epsilon,n+1,n+1,"pair:epsilon"); memory->create(sigma,n+1,n+1,"pair:sigma"); memory->create(lambda,n+1,n+1,"pair:lambda"); memory->create(lj1,n+1,n+1,"pair:lj1"); memory->create(lj2,n+1,n+1,"pair:lj2"); memory->create(lj3,n+1,n+1,"pair:lj3"); memory->create(offset,n+1,n+1,"pair:offset"); } /* ---------------------------------------------------------------------- global settings ------------------------------------------------------------------------- */ void PairLJCutSoft::settings(int narg, char **arg) { if (narg != 3) error->all(FLERR,"Illegal pair_style command"); nlambda = force->numeric(FLERR,arg[0]); alphalj = force->numeric(FLERR,arg[1]); cut_global = force->numeric(FLERR,arg[2]); // reset cutoffs that have been explicitly set if (allocated) { int i,j; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) if (setflag[i][j]) cut[i][j] = cut_global; } } /* ---------------------------------------------------------------------- set coeffs for one or more type pairs ------------------------------------------------------------------------- */ void PairLJCutSoft::coeff(int narg, char **arg) { if (narg < 5 || narg > 6) error->all(FLERR,"Incorrect args for pair coefficients"); if (!allocated) allocate(); int ilo,ihi,jlo,jhi; force->bounds(FLERR,arg[0],atom->ntypes,ilo,ihi); force->bounds(FLERR,arg[1],atom->ntypes,jlo,jhi); double epsilon_one = force->numeric(FLERR,arg[2]); double sigma_one = force->numeric(FLERR,arg[3]); double lambda_one = force->numeric(FLERR,arg[4]); if (sigma_one <= 0.0) error->all(FLERR,"Incorrect args for pair coefficients"); double cut_one = cut_global; if (narg == 6) cut_one = force->numeric(FLERR,arg[5]); int count = 0; for (int i = ilo; i <= ihi; i++) { for (int j = MAX(jlo,i); j <= jhi; j++) { epsilon[i][j] = epsilon_one; sigma[i][j] = sigma_one; lambda[i][j] = lambda_one; cut[i][j] = cut_one; setflag[i][j] = 1; count++; } } if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- init specific to this pair style ------------------------------------------------------------------------- */ void PairLJCutSoft::init_style() { // request regular or rRESPA neighbor lists int irequest; if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; if (respa == 0) irequest = neighbor->request(this,instance_me); else if (respa == 1) { irequest = neighbor->request(this,instance_me); neighbor->requests[irequest]->id = 1; neighbor->requests[irequest]->half = 0; neighbor->requests[irequest]->respainner = 1; irequest = neighbor->request(this,instance_me); neighbor->requests[irequest]->id = 3; neighbor->requests[irequest]->half = 0; neighbor->requests[irequest]->respaouter = 1; } else { irequest = neighbor->request(this,instance_me); neighbor->requests[irequest]->id = 1; neighbor->requests[irequest]->half = 0; neighbor->requests[irequest]->respainner = 1; irequest = neighbor->request(this,instance_me); neighbor->requests[irequest]->id = 2; neighbor->requests[irequest]->half = 0; neighbor->requests[irequest]->respamiddle = 1; irequest = neighbor->request(this,instance_me); neighbor->requests[irequest]->id = 3; neighbor->requests[irequest]->half = 0; neighbor->requests[irequest]->respaouter = 1; } } else irequest = neighbor->request(this,instance_me); // set rRESPA cutoffs if (strstr(update->integrate_style,"respa") && ((Respa *) update->integrate)->level_inner >= 0) cut_respa = ((Respa *) update->integrate)->cutoff; else cut_respa = NULL; } -/* ---------------------------------------------------------------------- - neighbor callback to inform pair style of neighbor list to use - regular or rRESPA -------------------------------------------------------------------------- */ - -void PairLJCutSoft::init_list(int id, NeighList *ptr) -{ - if (id == 0) list = ptr; - else if (id == 1) listinner = ptr; - else if (id == 2) listmiddle = ptr; - else if (id == 3) listouter = ptr; -} - /* ---------------------------------------------------------------------- init for one type pair i,j and corresponding j,i ------------------------------------------------------------------------- */ double PairLJCutSoft::init_one(int i, int j) { if (setflag[i][j] == 0) { epsilon[i][j] = mix_energy(epsilon[i][i],epsilon[j][j], sigma[i][i],sigma[j][j]); sigma[i][j] = mix_distance(sigma[i][i],sigma[j][j]); cut[i][j] = mix_distance(cut[i][i],cut[j][j]); } lj1[i][j] = pow(lambda[i][j], nlambda); lj2[i][j] = pow(sigma[i][j], 6.0); lj3[i][j] = alphalj * (1.0 - lambda[i][j])*(1.0 - lambda[i][j]); if (offset_flag && (cut[i][j] > 0.0)) { double denlj = lj3[i][j] + pow(cut[i][j] / sigma[i][j], 6.0); offset[i][j] = lj1[i][j] * 4.0 * epsilon[i][j] * (1.0/(denlj*denlj) - 1.0/denlj); } else offset[i][j] = 0.0; epsilon[j][i] = epsilon[i][j]; sigma[j][i] = sigma[i][j]; lambda[j][i] = lambda[i][j]; lj1[j][i] = lj1[i][j]; lj2[j][i] = lj2[i][j]; lj3[j][i] = lj3[i][j]; offset[j][i] = offset[i][j]; // check interior rRESPA cutoff if (cut_respa && cut[i][j] < cut_respa[3]) error->all(FLERR,"Pair cutoff < Respa interior cutoff"); // compute I,J contribution to long-range tail correction // count total # of atoms of type I and J via Allreduce if (tail_flag) { int *type = atom->type; int nlocal = atom->nlocal; double count[2],all[2]; count[0] = count[1] = 0.0; for (int k = 0; k < nlocal; k++) { if (type[k] == i) count[0] += 1.0; if (type[k] == j) count[1] += 1.0; } MPI_Allreduce(count,all,2,MPI_DOUBLE,MPI_SUM,world); double sig2 = sigma[i][j]*sigma[i][j]; double sig6 = sig2*sig2*sig2; double rc3 = cut[i][j]*cut[i][j]*cut[i][j]; double rc6 = rc3*rc3; double rc9 = rc3*rc6; etail_ij = 8.0*MY_PI*all[0]*all[1]* lj1[i][j] * epsilon[i][j] * sig6 * (sig6 - 3.0*rc6) / (9.0*rc9); ptail_ij = 16.0*MY_PI*all[0]*all[1]* lj1[i][j] * epsilon[i][j] * sig6 * (2.0*sig6 - 3.0*rc6) / (9.0*rc9); } return cut[i][j]; } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairLJCutSoft::write_restart(FILE *fp) { write_restart_settings(fp); int i,j; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { fwrite(&setflag[i][j],sizeof(int),1,fp); if (setflag[i][j]) { fwrite(&epsilon[i][j],sizeof(double),1,fp); fwrite(&sigma[i][j],sizeof(double),1,fp); fwrite(&lambda[i][j],sizeof(double),1,fp); fwrite(&cut[i][j],sizeof(double),1,fp); } } } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairLJCutSoft::read_restart(FILE *fp) { read_restart_settings(fp); allocate(); int i,j; int me = comm->me; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp); MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world); if (setflag[i][j]) { if (me == 0) { fread(&epsilon[i][j],sizeof(double),1,fp); fread(&sigma[i][j],sizeof(double),1,fp); fread(&lambda[i][j],sizeof(double),1,fp); fread(&cut[i][j],sizeof(double),1,fp); } MPI_Bcast(&epsilon[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&sigma[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&lambda[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&cut[i][j],1,MPI_DOUBLE,0,world); } } } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairLJCutSoft::write_restart_settings(FILE *fp) { fwrite(&nlambda,sizeof(double),1,fp); fwrite(&alphalj,sizeof(double),1,fp); fwrite(&cut_global,sizeof(double),1,fp); fwrite(&offset_flag,sizeof(int),1,fp); fwrite(&mix_flag,sizeof(int),1,fp); fwrite(&tail_flag,sizeof(int),1,fp); } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairLJCutSoft::read_restart_settings(FILE *fp) { int me = comm->me; if (me == 0) { fread(&nlambda,sizeof(double),1,fp); fread(&alphalj,sizeof(double),1,fp); fread(&cut_global,sizeof(double),1,fp); fread(&offset_flag,sizeof(int),1,fp); fread(&mix_flag,sizeof(int),1,fp); fread(&tail_flag,sizeof(int),1,fp); } MPI_Bcast(&nlambda,1,MPI_DOUBLE,0,world); MPI_Bcast(&alphalj,1,MPI_DOUBLE,0,world); MPI_Bcast(&cut_global,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(&tail_flag,1,MPI_INT,0,world); } /* ---------------------------------------------------------------------- proc 0 writes to data file ------------------------------------------------------------------------- */ void PairLJCutSoft::write_data(FILE *fp) { for (int i = 1; i <= atom->ntypes; i++) fprintf(fp,"%d %g %g %g\n",i,epsilon[i][i],sigma[i][i],lambda[i][i]); } /* ---------------------------------------------------------------------- proc 0 writes all pairs to data file ------------------------------------------------------------------------- */ void PairLJCutSoft::write_data_all(FILE *fp) { for (int i = 1; i <= atom->ntypes; i++) for (int j = i; j <= atom->ntypes; j++) fprintf(fp,"%d %d %g %g %g %g\n",i,j,epsilon[i][j],sigma[i][j], lambda[i][j],cut[i][j]); } /* ---------------------------------------------------------------------- */ double PairLJCutSoft::single(int i, int j, int itype, int jtype, double rsq, double factor_coul, double factor_lj, double &fforce) { double forcelj,philj; double r4sig6, denlj; if (rsq < cutsq[itype][jtype]) { r4sig6 = rsq*rsq / lj2[itype][jtype]; denlj = lj3[itype][jtype] + rsq*r4sig6; forcelj = lj1[itype][jtype] * epsilon[itype][jtype] * (48.0*r4sig6/(denlj*denlj*denlj) - 24.0*r4sig6/(denlj*denlj)); } else forcelj = 0.0; fforce = factor_lj*forcelj; if (rsq < cutsq[itype][jtype]) { philj = lj1[itype][jtype] * 4.0 * epsilon[itype][jtype] * (1.0/(denlj*denlj) - 1.0/denlj) - offset[itype][jtype]; } else philj = 0.0; return factor_lj*philj; } /* ---------------------------------------------------------------------- */ void *PairLJCutSoft::extract(const char *str, int &dim) { dim = 2; if (strcmp(str,"epsilon") == 0) return (void *) epsilon; if (strcmp(str,"sigma") == 0) return (void *) sigma; if (strcmp(str,"lambda") == 0) return (void *) lambda; return NULL; } diff --git a/src/USER-FEP/pair_lj_cut_soft.h b/src/USER-FEP/pair_lj_cut_soft.h index 50ce685e5..46202d78a 100644 --- a/src/USER-FEP/pair_lj_cut_soft.h +++ b/src/USER-FEP/pair_lj_cut_soft.h @@ -1,87 +1,86 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #ifdef PAIR_CLASS PairStyle(lj/cut/soft,PairLJCutSoft) #else #ifndef LMP_PAIR_LJ_CUT_SOFT_H #define LMP_PAIR_LJ_CUT_SOFT_H #include "pair.h" namespace LAMMPS_NS { class PairLJCutSoft : public Pair { public: PairLJCutSoft(class LAMMPS *); virtual ~PairLJCutSoft(); virtual void compute(int, int); virtual void settings(int, char **); void coeff(int, char **); virtual void init_style(); - void init_list(int, class NeighList *); virtual double init_one(int, int); void write_restart(FILE *); void read_restart(FILE *); virtual void write_restart_settings(FILE *); virtual void read_restart_settings(FILE *); void write_data(FILE *); void write_data_all(FILE *); virtual double single(int, int, int, int, double, double, double, double &); void *extract(const char *, int &); void compute_inner(); void compute_middle(); void compute_outer(int, int); protected: double cut_global; double **cut; double **epsilon,**sigma, **lambda; double nlambda, alphalj; double **lj1,**lj2,**lj3,**offset; double *cut_respa; void allocate(); }; } #endif #endif /* ERROR/WARNING messages: E: Illegal ... command Self-explanatory. Check the input script syntax and compare to the documentation for the command. You can use -echo screen as a command-line option when running LAMMPS to see the offending line. E: Incorrect args for pair coefficients Self-explanatory. Check the input script or data file. E: Pair cutoff < Respa interior cutoff One or more pairwise cutoffs are too short to use with the specified rRESPA cutoffs. E: Pair lj/cut/soft different lambda values in mix The value of lambda has to be the same for I J pairs. */ diff --git a/src/USER-OMP/fix_shear_history_omp.cpp b/src/USER-OMP/fix_neigh_history_omp.cpp similarity index 61% rename from src/USER-OMP/fix_shear_history_omp.cpp rename to src/USER-OMP/fix_neigh_history_omp.cpp index 4180e0af4..05b8fa41b 100644 --- a/src/USER-OMP/fix_shear_history_omp.cpp +++ b/src/USER-OMP/fix_neigh_history_omp.cpp @@ -1,170 +1,191 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include #include -#include "fix_shear_history_omp.h" +#include "fix_neigh_history_omp.h" #include "atom.h" #include "comm.h" #include "neighbor.h" #include "neigh_list.h" #include "force.h" #include "pair.h" #include "update.h" #include "modify.h" #include "error.h" #if defined(_OPENMP) #include #endif using namespace LAMMPS_NS; using namespace FixConst; + +FixNeighHistoryOMP::FixNeighHistoryOMP(class LAMMPS *lmp,int narg,char **argv) + : FixNeighHistory(lmp,narg,argv) { + + if (onesided) + error->all(FLERR,"tri/lj and line/lj are not supported by USER-OMP"); + if (!newton_pair) + error->all(FLERR,"Newton off for granular is not supported by USER-OMP"); +} + + /* ---------------------------------------------------------------------- - copy shear partner info from neighbor lists to per-atom arrays - so it can be exchanged with those atoms + copy partner info from neighbor data structs (NDS) to atom arrays + should be called whenever NDS store current history info + and need to transfer the info to owned atoms + e.g. when atoms migrate to new procs, new neigh list built, or between runs + when atoms may be added or deleted (NDS becomes out-of-date) + the next post_neighbor() will put this info back into new NDS + called during run before atom exchanges, including for restart files + called at end of run via post_run() + do not call during setup of run (setup_pre_exchange) + b/c there is no guarantee of a current NDS (even on continued run) + if run command does a 2nd run with pre = no, then no neigh list + will be built, but old neigh list will still have the info + + the USER-OMP version only supports newton on ------------------------------------------------------------------------- */ -void FixShearHistoryOMP::pre_exchange() +void FixNeighHistoryOMP::pre_exchange() { const int nthreads = comm->nthreads; - maxtouch = 0; + maxpartner = 0; #if defined(_OPENMP) #pragma omp parallel default(none) #endif { #if defined(_OPENMP) const int tid = omp_get_thread_num(); #else const int tid = 0; #endif int i,j,ii,jj,m,n,inum,jnum; int *ilist,*jlist,*numneigh,**firstneigh; - int *touch,**firsttouch; - double *shear,*shearj,*allshear,**firstshear; + int *allflags,**firstflag; + double *allvalues,*onevalues,*jvalues; - MyPage &ipg = ipage[tid]; - MyPage &dpg = dpage[tid]; + MyPage &ipg = ipage_atom[tid]; + MyPage &dpg = dpage_atom[tid]; ipg.reset(); dpg.reset(); // 1st loop over neighbor list - // calculate nparter for each owned atom + // calculate npartner for each owned atom tagint *tag = atom->tag; NeighList *list = pair->list; inum = list->inum; ilist = list->ilist; numneigh = list->numneigh; firstneigh = list->firstneigh; - firsttouch = list->listhistory->firstneigh; - firstshear = list->listhistory->firstdouble; int nlocal_neigh = 0; if (inum) nlocal_neigh = ilist[inum-1] + 1; // each thread works on a fixed chunk of local and ghost atoms. const int ldelta = 1 + nlocal_neigh/nthreads; const int lfrom = tid*ldelta; const int lmax = lfrom +ldelta; const int lto = (lmax > nlocal_neigh) ? nlocal_neigh : lmax; // zero npartners for all current atoms and // clear page data structures for this thread for (i = lfrom; i < lto; i++) npartner[i] = 0; for (ii = 0; ii < inum; ii++) { i = ilist[ii]; jlist = firstneigh[i]; jnum = numneigh[i]; - touch = firsttouch[i]; + allflags = firstflag[i]; for (jj = 0; jj < jnum; jj++) { - if (touch[jj]) { + if (allflags[jj]) { if ((i >= lfrom) && (i < lto)) npartner[i]++; j = jlist[jj]; j &= NEIGHMASK; if ((j >= lfrom) && (j < lto)) npartner[j]++; } } } // get page chunks to store atom IDs and shear history for my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; if ((i >= lfrom) && (i < lto)) { n = npartner[i]; partner[i] = ipg.get(n); - shearpartner[i] = dpg.get(dnum*n); - if (partner[i] == NULL || shearpartner[i] == NULL) - error->one(FLERR,"Shear history overflow, boost neigh_modify one"); + valuepartner[i] = dpg.get(dnum*n); + if (partner[i] == NULL || valuepartner[i] == NULL) + error->one(FLERR,"Neighbor history overflow, boost neigh_modify one"); } } // 2nd loop over neighbor list - // store atom IDs and shear history for my atoms - // re-zero npartner to use as counter for all my atoms + // store partner IDs and values for owned+ghost atoms + // re-zero npartner to use as counter for (i = lfrom; i < lto; i++) npartner[i] = 0; for (ii = 0; ii < inum; ii++) { i = ilist[ii]; jlist = firstneigh[i]; - allshear = firstshear[i]; jnum = numneigh[i]; - touch = firsttouch[i]; + allflags = firstflag[i]; + allvalues = firstvalue[i]; for (jj = 0; jj < jnum; jj++) { - if (touch[jj]) { - shear = &allshear[3*jj]; + if (allflags[jj]) { + onevalues = &allvalues[3*jj]; j = jlist[jj]; j &= NEIGHMASK; if ((i >= lfrom) && (i < lto)) { m = npartner[i]++; partner[i][m] = tag[j]; - memcpy(&shearpartner[i][dnum*m],shear,dnumbytes); + memcpy(&valuepartner[i][dnum*m],onevalues,dnumbytes); } if ((j >= lfrom) && (j < lto)) { m = npartner[j]++; partner[j][m] = tag[i]; - shearj = &shearpartner[j][dnum*m]; - for (n = 0; n < dnum; n++) shearj[n] = -shear[n]; + jvalues = &valuepartner[j][dnum*m]; + for (n = 0; n < dnum; n++) jvalues[n] = -onevalues[n]; } } } } - // set maxtouch = max # of partners of any owned atom - maxtouch = m = 0; + // set maxpartner = max # of partners of any owned atom + maxpartner = m = 0; for (i = lfrom; i < lto; i++) m = MAX(m,npartner[i]); #if defined(_OPENMP) #pragma omp critical #endif - maxtouch = MAX(m,maxtouch); + maxpartner = MAX(m,maxpartner); } } diff --git a/src/USER-OMP/fix_shear_history_omp.h b/src/USER-OMP/fix_neigh_history_omp.h similarity index 70% rename from src/USER-OMP/fix_shear_history_omp.h rename to src/USER-OMP/fix_neigh_history_omp.h index 95281b2af..83472391a 100644 --- a/src/USER-OMP/fix_shear_history_omp.h +++ b/src/USER-OMP/fix_neigh_history_omp.h @@ -1,38 +1,37 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #ifdef FIX_CLASS -FixStyle(SHEAR_HISTORY/omp,FixShearHistoryOMP) +FixStyle(NEIGH_HISTORY/omp,FixNeighHistoryOMP) #else -#ifndef LMP_FIX_SHEAR_HISTORY_OMP_H -#define LMP_FIX_SHEAR_HISTORY_OMP_H +#ifndef LMP_FIX_NEIGH_HISTORY_OMP_H +#define LMP_FIX_NEIGH_HISTORY_OMP_H -#include "fix_shear_history.h" +#include "fix_neigh_history.h" namespace LAMMPS_NS { -class FixShearHistoryOMP : public FixShearHistory { +class FixNeighHistoryOMP : public FixNeighHistory { public: - FixShearHistoryOMP(class LAMMPS *lmp, int narg, char **argv) - : FixShearHistory(lmp,narg,argv) {}; + FixNeighHistoryOMP(class LAMMPS *lmp, int narg, char **argv); virtual void pre_exchange(); }; } #endif #endif diff --git a/src/USER-OMP/npair_half_respa_bin_newtoff_omp.cpp b/src/USER-OMP/npair_half_respa_bin_newtoff_omp.cpp index 45add8709..f094691b7 100644 --- a/src/USER-OMP/npair_half_respa_bin_newtoff_omp.cpp +++ b/src/USER-OMP/npair_half_respa_bin_newtoff_omp.cpp @@ -1,204 +1,202 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include "npair_half_respa_bin_newtoff_omp.h" #include "npair_omp.h" #include "neighbor.h" #include "neigh_list.h" #include "atom.h" #include "atom_vec.h" #include "molecule.h" #include "domain.h" #include "my_page.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ NPairHalfRespaBinNewtoffOmp::NPairHalfRespaBinNewtoffOmp(LAMMPS *lmp) : NPair(lmp) {} /* ---------------------------------------------------------------------- multiple respa lists binned neighbor list construction with partial Newton's 3rd law each owned atom i checks own bin and surrounding bins in non-Newton stencil pair stored once if i,j are both owned and i < j pair stored by me if j is ghost (also stored by proc owning j) ------------------------------------------------------------------------- */ void NPairHalfRespaBinNewtoffOmp::build(NeighList *list) { const int nlocal = (includegroup) ? atom->nfirst : atom->nlocal; const int molecular = atom->molecular; const int moltemplate = (molecular == 2) ? 1 : 0; NPAIR_OMP_INIT; - NeighList *listinner = list->listinner; - NeighList *listmiddle = list->listmiddle; const int respamiddle = list->respamiddle; #if defined(_OPENMP) -#pragma omp parallel default(none) shared(list,listinner,listmiddle) +#pragma omp parallel default(none) shared(list) #endif NPAIR_OMP_SETUP(nlocal); int i,j,k,n,itype,jtype,ibin,n_inner,n_middle,imol,iatom; tagint tagprev; double xtmp,ytmp,ztmp,delx,dely,delz,rsq; int *neighptr,*neighptr_inner,*neighptr_middle; // loop over each atom, storing neighbors double **x = atom->x; int *type = atom->type; int *mask = atom->mask; tagint *tag = atom->tag; tagint *molecule = atom->molecule; tagint **special = atom->special; int **nspecial = atom->nspecial; int *molindex = atom->molindex; int *molatom = atom->molatom; Molecule **onemols = atom->avec->onemols; int *ilist = list->ilist; int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; - int *ilist_inner = listinner->ilist; - int *numneigh_inner = listinner->numneigh; - int **firstneigh_inner = listinner->firstneigh; + int *ilist_inner = list->ilist_inner; + int *numneigh_inner = list->numneigh_inner; + int **firstneigh_inner = list->firstneigh_inner; int *ilist_middle,*numneigh_middle,**firstneigh_middle; if (respamiddle) { - ilist_middle = listmiddle->ilist; - numneigh_middle = listmiddle->numneigh; - firstneigh_middle = listmiddle->firstneigh; + ilist_middle = list->ilist_middle; + numneigh_middle = list->numneigh_middle; + firstneigh_middle = list->firstneigh_middle; } // each thread has its own page allocator MyPage &ipage = list->ipage[tid]; - MyPage &ipage_inner = listinner->ipage[tid]; + MyPage &ipage_inner = list->ipage_inner[tid]; ipage.reset(); ipage_inner.reset(); MyPage *ipage_middle; if (respamiddle) { - ipage_middle = listmiddle->ipage + tid; + ipage_middle = list->ipage_middle + tid; ipage_middle->reset(); } int which = 0; int minchange = 0; for (i = ifrom; i < ito; i++) { n = n_inner = 0; neighptr = ipage.vget(); neighptr_inner = ipage_inner.vget(); if (respamiddle) { n_middle = 0; neighptr_middle = ipage_middle->vget(); } itype = type[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; ibin = atom2bin[i]; if (moltemplate) { imol = molindex[i]; iatom = molatom[i]; tagprev = tag[i] - iatom - 1; } // loop over all atoms in surrounding bins in stencil including self // only store pair if i < j // stores own/own pairs only once // stores own/ghost pairs on both procs for (k = 0; k < nstencil; k++) { for (j = binhead[ibin+stencil[k]]; j >= 0; j = bins[j]) { if (j <= i) continue; jtype = type[j]; if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq <= cutneighsq[itype][jtype]) { if (molecular) { if (!moltemplate) which = find_special(special[i],nspecial[i],tag[j]); else if (imol >=0) which = find_special(onemols[imol]->special[iatom], onemols[imol]->nspecial[iatom], tag[j]-tagprev); else which = 0; if (which == 0) neighptr[n++] = j; else if ((minchange = domain->minimum_image_check(delx,dely,delz))) neighptr[n++] = j; else if (which > 0) neighptr[n++] = j ^ (which << SBBITS); } else neighptr[n++] = j; if (rsq < cut_inner_sq) { if (which == 0) neighptr_inner[n_inner++] = j; else if (minchange) neighptr_inner[n_inner++] = j; else if (which > 0) neighptr_inner[n_inner++] = j ^ (which << SBBITS); } if (respamiddle && rsq < cut_middle_sq && rsq > cut_middle_inside_sq) { if (which == 0) neighptr_middle[n_middle++] = j; else if (minchange) neighptr_middle[n_middle++] = j; else if (which > 0) neighptr_middle[n_middle++] = j ^ (which << SBBITS); } } } } ilist[i] = i; firstneigh[i] = neighptr; numneigh[i] = n; ipage.vgot(n); if (ipage.status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); ilist_inner[i] = i; firstneigh_inner[i] = neighptr_inner; numneigh_inner[i] = n_inner; ipage.vgot(n_inner); if (ipage_inner.status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); if (respamiddle) { ilist_middle[i] = i; firstneigh_middle[i] = neighptr_middle; numneigh_middle[i] = n_middle; ipage_middle->vgot(n_middle); if (ipage_middle->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); } } NPAIR_OMP_CLOSE; list->inum = nlocal; - listinner->inum = nlocal; - if (respamiddle) listmiddle->inum = nlocal; + list->inum_inner = nlocal; + if (respamiddle) list->inum_middle = nlocal; } diff --git a/src/USER-OMP/npair_half_respa_bin_newton_omp.cpp b/src/USER-OMP/npair_half_respa_bin_newton_omp.cpp index ee6b9b750..de7ef5f7d 100644 --- a/src/USER-OMP/npair_half_respa_bin_newton_omp.cpp +++ b/src/USER-OMP/npair_half_respa_bin_newton_omp.cpp @@ -1,250 +1,248 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include "npair_half_respa_bin_newton_omp.h" #include "neighbor.h" #include "npair_omp.h" #include "neigh_list.h" #include "atom.h" #include "atom_vec.h" #include "molecule.h" #include "domain.h" #include "my_page.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ NPairHalfRespaBinNewtonOmp::NPairHalfRespaBinNewtonOmp(LAMMPS *lmp) : NPair(lmp) {} /* ---------------------------------------------------------------------- multiple respa lists binned neighbor list construction with full Newton's 3rd law each owned atom i checks its own bin and other bins in Newton stencil every pair stored exactly once by some processor ------------------------------------------------------------------------- */ void NPairHalfRespaBinNewtonOmp::build(NeighList *list) { const int nlocal = (includegroup) ? atom->nfirst : atom->nlocal; const int molecular = atom->molecular; const int moltemplate = (molecular == 2) ? 1 : 0; NPAIR_OMP_INIT; - NeighList *listinner = list->listinner; - NeighList *listmiddle = list->listmiddle; const int respamiddle = list->respamiddle; #if defined(_OPENMP) -#pragma omp parallel default(none) shared(list,listinner,listmiddle) +#pragma omp parallel default(none) shared(list) #endif NPAIR_OMP_SETUP(nlocal); int i,j,k,n,itype,jtype,ibin,n_inner,n_middle,imol,iatom; tagint tagprev; double xtmp,ytmp,ztmp,delx,dely,delz,rsq; int *neighptr,*neighptr_inner,*neighptr_middle; // loop over each atom, storing neighbors double **x = atom->x; int *type = atom->type; int *mask = atom->mask; tagint *tag = atom->tag; tagint *molecule = atom->molecule; tagint **special = atom->special; int **nspecial = atom->nspecial; int *molindex = atom->molindex; int *molatom = atom->molatom; Molecule **onemols = atom->avec->onemols; int *ilist = list->ilist; int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; - int *ilist_inner = listinner->ilist; - int *numneigh_inner = listinner->numneigh; - int **firstneigh_inner = listinner->firstneigh; + int *ilist_inner = list->ilist_inner; + int *numneigh_inner = list->numneigh_inner; + int **firstneigh_inner = list->firstneigh_inner; int *ilist_middle,*numneigh_middle,**firstneigh_middle; if (respamiddle) { - ilist_middle = listmiddle->ilist; - numneigh_middle = listmiddle->numneigh; - firstneigh_middle = listmiddle->firstneigh; + ilist_middle = list->ilist_middle; + numneigh_middle = list->numneigh_middle; + firstneigh_middle = list->firstneigh_middle; } // each thread has its own page allocator MyPage &ipage = list->ipage[tid]; - MyPage &ipage_inner = listinner->ipage[tid]; + MyPage &ipage_inner = list->ipage_inner[tid]; ipage.reset(); ipage_inner.reset(); MyPage *ipage_middle; if (respamiddle) { - ipage_middle = listmiddle->ipage + tid; + ipage_middle = list->ipage_middle + tid; ipage_middle->reset(); } int which = 0; int minchange = 0; for (i = ifrom; i < ito; i++) { n = n_inner = 0; neighptr = ipage.vget(); neighptr_inner = ipage_inner.vget(); if (respamiddle) { n_middle = 0; neighptr_middle = ipage_middle->vget(); } itype = type[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; if (moltemplate) { imol = molindex[i]; iatom = molatom[i]; tagprev = tag[i] - iatom - 1; } // loop over rest of atoms in i's bin, ghosts are at end of linked list // if j is owned atom, store it, since j is beyond i in linked list // if j is ghost, only store if j coords are "above and to the right" of i for (j = bins[i]; j >= 0; j = bins[j]) { if (j >= nlocal) { if (x[j][2] < ztmp) continue; if (x[j][2] == ztmp) { if (x[j][1] < ytmp) continue; if (x[j][1] == ytmp && x[j][0] < xtmp) continue; } } jtype = type[j]; if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq <= cutneighsq[itype][jtype]) { if (molecular) { if (!moltemplate) which = find_special(special[i],nspecial[i],tag[j]); else if (imol >=0) which = find_special(onemols[imol]->special[iatom], onemols[imol]->nspecial[iatom], tag[j]-tagprev); else which = 0; if (which == 0) neighptr[n++] = j; else if ((minchange = domain->minimum_image_check(delx,dely,delz))) neighptr[n++] = j; else if (which > 0) neighptr[n++] = j ^ (which << SBBITS); } else neighptr[n++] = j; if (rsq < cut_inner_sq) { if (which == 0) neighptr_inner[n_inner++] = j; else if (minchange) neighptr_inner[n_inner++] = j; else if (which > 0) neighptr_inner[n_inner++] = j ^ (which << SBBITS); } if (respamiddle && rsq < cut_middle_sq && rsq > cut_middle_inside_sq) { if (which == 0) neighptr_middle[n_middle++] = j; else if (minchange) neighptr_middle[n_middle++] = j; else if (which > 0) neighptr_middle[n_middle++] = j ^ (which << SBBITS); } } } // loop over all atoms in other bins in stencil, store every pair ibin = atom2bin[i]; for (k = 0; k < nstencil; k++) { for (j = binhead[ibin+stencil[k]]; j >= 0; j = bins[j]) { jtype = type[j]; if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq <= cutneighsq[itype][jtype]) { if (molecular) { if (!moltemplate) which = find_special(special[i],nspecial[i],tag[j]); else if (imol >=0) which = find_special(onemols[imol]->special[iatom], onemols[imol]->nspecial[iatom], tag[j]-tagprev); else which = 0; if (which == 0) neighptr[n++] = j; else if ((minchange = domain->minimum_image_check(delx,dely,delz))) neighptr[n++] = j; else if (which > 0) neighptr[n++] = j ^ (which << SBBITS); } else neighptr[n++] = j; if (rsq < cut_inner_sq) { if (which == 0) neighptr_inner[n_inner++] = j; else if (minchange) neighptr_inner[n_inner++] = j; else if (which > 0) neighptr_inner[n_inner++] = j ^ (which << SBBITS); } if (respamiddle && rsq < cut_middle_sq && rsq > cut_middle_inside_sq) { if (which == 0) neighptr_middle[n_middle++] = j; else if (minchange) neighptr_middle[n_middle++] = j; else if (which > 0) neighptr_middle[n_middle++] = j ^ (which << SBBITS); } } } } ilist[i] = i; firstneigh[i] = neighptr; numneigh[i] = n; ipage.vgot(n); if (ipage.status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); ilist_inner[i] = i; firstneigh_inner[i] = neighptr_inner; numneigh_inner[i] = n_inner; ipage.vgot(n_inner); if (ipage_inner.status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); if (respamiddle) { ilist_middle[i] = i; firstneigh_middle[i] = neighptr_middle; numneigh_middle[i] = n_middle; ipage_middle->vgot(n_middle); if (ipage_middle->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); } } NPAIR_OMP_CLOSE; list->inum = nlocal; - listinner->inum = nlocal; - if (respamiddle) listmiddle->inum = nlocal; + list->inum_inner = nlocal; + if (respamiddle) list->inum_middle = nlocal; } diff --git a/src/USER-OMP/npair_half_respa_bin_newton_tri_omp.cpp b/src/USER-OMP/npair_half_respa_bin_newton_tri_omp.cpp index fbb512ba6..f20d101bc 100644 --- a/src/USER-OMP/npair_half_respa_bin_newton_tri_omp.cpp +++ b/src/USER-OMP/npair_half_respa_bin_newton_tri_omp.cpp @@ -1,211 +1,209 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include "npair_half_respa_bin_newton_tri_omp.h" #include "npair_omp.h" #include "neighbor.h" #include "neigh_list.h" #include "atom.h" #include "atom_vec.h" #include "molecule.h" #include "domain.h" #include "my_page.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ NPairHalfRespaBinNewtonTriOmp::NPairHalfRespaBinNewtonTriOmp(LAMMPS *lmp) : NPair(lmp) {} /* ---------------------------------------------------------------------- multiple respa lists binned neighbor list construction with Newton's 3rd law for triclinic each owned atom i checks its own bin and other bins in triclinic stencil every pair stored exactly once by some processor ------------------------------------------------------------------------- */ void NPairHalfRespaBinNewtonTriOmp::build(NeighList *list) { const int nlocal = (includegroup) ? atom->nfirst : atom->nlocal; const int molecular = atom->molecular; const int moltemplate = (molecular == 2) ? 1 : 0; NPAIR_OMP_INIT; - NeighList *listinner = list->listinner; - NeighList *listmiddle = list->listmiddle; const int respamiddle = list->respamiddle; #if defined(_OPENMP) -#pragma omp parallel default(none) shared(list,listinner,listmiddle) +#pragma omp parallel default(none) shared(list) #endif NPAIR_OMP_SETUP(nlocal); int i,j,k,n,itype,jtype,ibin,n_inner,n_middle,imol,iatom; tagint tagprev; double xtmp,ytmp,ztmp,delx,dely,delz,rsq; int *neighptr,*neighptr_inner,*neighptr_middle; // loop over each atom, storing neighbors double **x = atom->x; int *type = atom->type; int *mask = atom->mask; tagint *tag = atom->tag; tagint *molecule = atom->molecule; tagint **special = atom->special; int **nspecial = atom->nspecial; int *molindex = atom->molindex; int *molatom = atom->molatom; Molecule **onemols = atom->avec->onemols; int *ilist = list->ilist; int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; - int *ilist_inner = listinner->ilist; - int *numneigh_inner = listinner->numneigh; - int **firstneigh_inner = listinner->firstneigh; + int *ilist_inner = list->ilist_inner; + int *numneigh_inner = list->numneigh_inner; + int **firstneigh_inner = list->firstneigh_inner; int *ilist_middle,*numneigh_middle,**firstneigh_middle; if (respamiddle) { - ilist_middle = listmiddle->ilist; - numneigh_middle = listmiddle->numneigh; - firstneigh_middle = listmiddle->firstneigh; + ilist_middle = list->ilist_middle; + numneigh_middle = list->numneigh_middle; + firstneigh_middle = list->firstneigh_middle; } // each thread has its own page allocator MyPage &ipage = list->ipage[tid]; - MyPage &ipage_inner = listinner->ipage[tid]; + MyPage &ipage_inner = list->ipage_inner[tid]; ipage.reset(); ipage_inner.reset(); MyPage *ipage_middle; if (respamiddle) { - ipage_middle = listmiddle->ipage + tid; + ipage_middle = list->ipage_middle + tid; ipage_middle->reset(); } int which = 0; int minchange = 0; for (i = ifrom; i < ito; i++) { n = n_inner = 0; neighptr = ipage.vget(); neighptr_inner = ipage_inner.vget(); if (respamiddle) { n_middle = 0; neighptr_middle = ipage_middle->vget(); } itype = type[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; if (moltemplate) { imol = molindex[i]; iatom = molatom[i]; tagprev = tag[i] - iatom - 1; } // loop over all atoms in bins in stencil // pairs for atoms j "below" i are excluded // below = lower z or (equal z and lower y) or (equal zy and lower x) // (equal zyx and j <= i) // latter excludes self-self interaction but allows superposed atoms ibin = atom2bin[i]; for (k = 0; k < nstencil; k++) { for (j = binhead[ibin+stencil[k]]; j >= 0; j = bins[j]) { if (x[j][2] < ztmp) continue; if (x[j][2] == ztmp) { if (x[j][1] < ytmp) continue; if (x[j][1] == ytmp) { if (x[j][0] < xtmp) continue; if (x[j][0] == xtmp && j <= i) continue; } } jtype = type[j]; if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq <= cutneighsq[itype][jtype]) { if (molecular) { if (!moltemplate) which = find_special(special[i],nspecial[i],tag[j]); else if (imol >=0) which = find_special(onemols[imol]->special[iatom], onemols[imol]->nspecial[iatom], tag[j]-tagprev); else which = 0; if (which == 0) neighptr[n++] = j; else if ((minchange = domain->minimum_image_check(delx,dely,delz))) neighptr[n++] = j; else if (which > 0) neighptr[n++] = j ^ (which << SBBITS); } else neighptr[n++] = j; if (rsq < cut_inner_sq) { if (which == 0) neighptr_inner[n_inner++] = j; else if (minchange) neighptr_inner[n_inner++] = j; else if (which > 0) neighptr_inner[n_inner++] = j ^ (which << SBBITS); } if (respamiddle && rsq < cut_middle_sq && rsq > cut_middle_inside_sq) { if (which == 0) neighptr_middle[n_middle++] = j; else if (minchange) neighptr_middle[n_middle++] = j; else if (which > 0) neighptr_middle[n_middle++] = j ^ (which << SBBITS); } } } } ilist[i] = i; firstneigh[i] = neighptr; numneigh[i] = n; ipage.vgot(n); if (ipage.status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); ilist_inner[i] = i; firstneigh_inner[i] = neighptr_inner; numneigh_inner[i] = n_inner; ipage_inner.vgot(n_inner); if (ipage_inner.status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); if (respamiddle) { ilist_middle[i] = i; firstneigh_middle[i] = neighptr_middle; numneigh_middle[i] = n_middle; ipage_middle->vgot(n_middle); if (ipage_middle->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); } } NPAIR_OMP_CLOSE; list->inum = nlocal; - listinner->inum = nlocal; - if (respamiddle) listmiddle->inum = nlocal; + list->inum_inner = nlocal; + if (respamiddle) list->inum_middle = nlocal; } diff --git a/src/USER-OMP/npair_half_respa_nsq_newtoff_omp.cpp b/src/USER-OMP/npair_half_respa_nsq_newtoff_omp.cpp index 5ee71beba..0f726cdd7 100644 --- a/src/USER-OMP/npair_half_respa_nsq_newtoff_omp.cpp +++ b/src/USER-OMP/npair_half_respa_nsq_newtoff_omp.cpp @@ -1,198 +1,196 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include "npair_half_respa_nsq_newtoff_omp.h" #include "npair_omp.h" #include "neighbor.h" #include "neigh_list.h" #include "atom.h" #include "atom_vec.h" #include "group.h" #include "molecule.h" #include "domain.h" #include "my_page.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ NPairHalfRespaNsqNewtoffOmp::NPairHalfRespaNsqNewtoffOmp(LAMMPS *lmp) : NPair(lmp) {} /* ---------------------------------------------------------------------- multiple respa lists N^2 / 2 search for neighbor pairs with partial Newton's 3rd law pair added to list if atoms i and j are both owned and i < j pair added if j is ghost (also stored by proc owning j) ------------------------------------------------------------------------- */ void NPairHalfRespaNsqNewtoffOmp::build(NeighList *list) { const int nlocal = (includegroup) ? atom->nfirst : atom->nlocal; const int bitmask = (includegroup) ? group->bitmask[includegroup] : 0; const int molecular = atom->molecular; const int moltemplate = (molecular == 2) ? 1 : 0; NPAIR_OMP_INIT; - NeighList *listinner = list->listinner; - NeighList *listmiddle = list->listmiddle; const int respamiddle = list->respamiddle; #if defined(_OPENMP) -#pragma omp parallel default(none) shared(list,listinner,listmiddle) +#pragma omp parallel default(none) shared(list) #endif NPAIR_OMP_SETUP(nlocal); int i,j,n,itype,jtype,n_inner,n_middle,imol,iatom; tagint tagprev; double xtmp,ytmp,ztmp,delx,dely,delz,rsq; int *neighptr,*neighptr_inner,*neighptr_middle; // loop over each atom, storing neighbors double **x = atom->x; int *type = atom->type; int *mask = atom->mask; tagint *tag = atom->tag; tagint *molecule = atom->molecule; tagint **special = atom->special; int **nspecial = atom->nspecial; int *molindex = atom->molindex; int *molatom = atom->molatom; Molecule **onemols = atom->avec->onemols; int nall = atom->nlocal + atom->nghost; int *ilist = list->ilist; int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; - int *ilist_inner = listinner->ilist; - int *numneigh_inner = listinner->numneigh; - int **firstneigh_inner = listinner->firstneigh; + int *ilist_inner = list->ilist_inner; + int *numneigh_inner = list->numneigh_inner; + int **firstneigh_inner = list->firstneigh_inner; int *ilist_middle,*numneigh_middle,**firstneigh_middle; if (respamiddle) { - ilist_middle = listmiddle->ilist; - numneigh_middle = listmiddle->numneigh; - firstneigh_middle = listmiddle->firstneigh; + ilist_middle = list->ilist_middle; + numneigh_middle = list->numneigh_middle; + firstneigh_middle = list->firstneigh_middle; } // each thread has its own page allocator MyPage &ipage = list->ipage[tid]; - MyPage &ipage_inner = listinner->ipage[tid]; + MyPage &ipage_inner = list->ipage_inner[tid]; ipage.reset(); ipage_inner.reset(); MyPage *ipage_middle; if (respamiddle) { - ipage_middle = listmiddle->ipage + tid; + ipage_middle = list->ipage_middle + tid; ipage_middle->reset(); } int which = 0; int minchange = 0; for (i = ifrom; i < ito; i++) { n = n_inner = 0; neighptr = ipage.vget(); neighptr_inner = ipage_inner.vget(); if (respamiddle) { n_middle = 0; neighptr_middle = ipage_middle->vget(); } itype = type[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; if (moltemplate) { imol = molindex[i]; iatom = molatom[i]; tagprev = tag[i] - iatom - 1; } // loop over remaining atoms, owned and ghost for (j = i+1; j < nall; j++) { if (includegroup && !(mask[j] & bitmask)) continue; jtype = type[j]; if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq <= cutneighsq[itype][jtype]) { if (molecular) { if (!moltemplate) which = find_special(special[i],nspecial[i],tag[j]); else if (imol >=0) which = find_special(onemols[imol]->special[iatom], onemols[imol]->nspecial[iatom], tag[j]-tagprev); else which = 0; if (which == 0) neighptr[n++] = j; else if ((minchange = domain->minimum_image_check(delx,dely,delz))) neighptr[n++] = j; else if (which > 0) neighptr[n++] = j ^ (which << SBBITS); } else neighptr[n++] = j; if (rsq < cut_inner_sq) { if (which == 0) neighptr_inner[n_inner++] = j; else if (minchange) neighptr_inner[n_inner++] = j; else if (which > 0) neighptr_inner[n_inner++] = j ^ (which << SBBITS); } if (respamiddle && rsq < cut_middle_sq && rsq > cut_middle_inside_sq) { if (which == 0) neighptr_middle[n_middle++] = j; else if (minchange) neighptr_middle[n_middle++] = j; else if (which > 0) neighptr_middle[n_middle++] = j ^ (which << SBBITS); } } } ilist[i] = i; firstneigh[i] = neighptr; numneigh[i] = n; ipage.vgot(n); if (ipage.status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); ilist_inner[i] = i; firstneigh_inner[i] = neighptr_inner; numneigh_inner[i] = n_inner; ipage.vgot(n_inner); if (ipage_inner.status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); if (respamiddle) { ilist_middle[i] = i; firstneigh_middle[i] = neighptr_middle; numneigh_middle[i] = n_middle; ipage_middle->vgot(n_middle); if (ipage_middle->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); } } NPAIR_OMP_CLOSE; list->inum = nlocal; - listinner->inum = nlocal; - if (respamiddle) listmiddle->inum = nlocal; + list->inum_inner = nlocal; + if (respamiddle) list->inum_middle = nlocal; } diff --git a/src/USER-OMP/npair_half_respa_nsq_newton_omp.cpp b/src/USER-OMP/npair_half_respa_nsq_newton_omp.cpp index 89cff732c..2783e1255 100644 --- a/src/USER-OMP/npair_half_respa_nsq_newton_omp.cpp +++ b/src/USER-OMP/npair_half_respa_nsq_newton_omp.cpp @@ -1,217 +1,215 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include "npair_half_respa_nsq_newton_omp.h" #include "npair_omp.h" #include "neighbor.h" #include "neigh_list.h" #include "atom.h" #include "atom_vec.h" #include "group.h" #include "molecule.h" #include "domain.h" #include "my_page.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ NPairHalfRespaNsqNewtonOmp::NPairHalfRespaNsqNewtonOmp(LAMMPS *lmp) : NPair(lmp) {} /* ---------------------------------------------------------------------- multiple respa lists N^2 / 2 search for neighbor pairs with full Newton's 3rd law pair added to list if atoms i and j are both owned and i < j if j is ghost only me or other proc adds pair decision based on itag,jtag tests ------------------------------------------------------------------------- */ void NPairHalfRespaNsqNewtonOmp::build(NeighList *list) { const int nlocal = (includegroup) ? atom->nfirst : atom->nlocal; const int bitmask = (includegroup) ? group->bitmask[includegroup] : 0; const int molecular = atom->molecular; const int moltemplate = (molecular == 2) ? 1 : 0; NPAIR_OMP_INIT; - NeighList *listinner = list->listinner; - NeighList *listmiddle = list->listmiddle; const int respamiddle = list->respamiddle; #if defined(_OPENMP) -#pragma omp parallel default(none) shared(list,listinner,listmiddle) +#pragma omp parallel default(none) shared(list) #endif NPAIR_OMP_SETUP(nlocal); int i,j,n,itype,jtype,itag,jtag,n_inner,n_middle,imol,iatom; tagint tagprev; double xtmp,ytmp,ztmp,delx,dely,delz,rsq; int *neighptr,*neighptr_inner,*neighptr_middle; // loop over each atom, storing neighbors double **x = atom->x; int *type = atom->type; int *mask = atom->mask; tagint *tag = atom->tag; tagint *molecule = atom->molecule; tagint **special = atom->special; int **nspecial = atom->nspecial; int *molindex = atom->molindex; int *molatom = atom->molatom; Molecule **onemols = atom->avec->onemols; int nall = atom->nlocal + atom->nghost; int *ilist = list->ilist; int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; - int *ilist_inner = listinner->ilist; - int *numneigh_inner = listinner->numneigh; - int **firstneigh_inner = listinner->firstneigh; + int *ilist_inner = list->ilist_inner; + int *numneigh_inner = list->numneigh_inner; + int **firstneigh_inner = list->firstneigh_inner; int *ilist_middle,*numneigh_middle,**firstneigh_middle; if (respamiddle) { - ilist_middle = listmiddle->ilist; - numneigh_middle = listmiddle->numneigh; - firstneigh_middle = listmiddle->firstneigh; + ilist_middle = list->ilist_middle; + numneigh_middle = list->numneigh_middle; + firstneigh_middle = list->firstneigh_middle; } // each thread has its own page allocator MyPage &ipage = list->ipage[tid]; - MyPage &ipage_inner = listinner->ipage[tid]; + MyPage &ipage_inner = list->ipage_inner[tid]; ipage.reset(); ipage_inner.reset(); MyPage *ipage_middle; if (respamiddle) { - ipage_middle = listmiddle->ipage + tid; + ipage_middle = list->ipage_middle + tid; ipage_middle->reset(); } int which = 0; int minchange = 0; for (i = ifrom; i < ito; i++) { n = n_inner = 0; neighptr = ipage.vget(); neighptr_inner = ipage_inner.vget(); if (respamiddle) { n_middle = 0; neighptr_middle = ipage_middle->vget(); } itag = tag[i]; itype = type[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; if (moltemplate) { imol = molindex[i]; iatom = molatom[i]; tagprev = tag[i] - iatom - 1; } // loop over remaining atoms, owned and ghost for (j = i+1; j < nall; j++) { if (includegroup && !(mask[j] & bitmask)) continue; if (j >= nlocal) { jtag = tag[j]; if (itag > jtag) { if ((itag+jtag) % 2 == 0) continue; } else if (itag < jtag) { if ((itag+jtag) % 2 == 1) continue; } else { if (x[j][2] < ztmp) continue; if (x[j][2] == ztmp) { if (x[j][1] < ytmp) continue; if (x[j][1] == ytmp && x[j][0] < xtmp) continue; } } } jtype = type[j]; if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq <= cutneighsq[itype][jtype]) { if (molecular) { if (!moltemplate) which = find_special(special[i],nspecial[i],tag[j]); else if (imol >=0) which = find_special(onemols[imol]->special[iatom], onemols[imol]->nspecial[iatom], tag[j]-tagprev); else which = 0; if (which == 0) neighptr[n++] = j; else if ((minchange = domain->minimum_image_check(delx,dely,delz))) neighptr[n++] = j; else if (which > 0) neighptr[n++] = j ^ (which << SBBITS); } else neighptr[n++] = j; if (rsq < cut_inner_sq) { if (which == 0) neighptr_inner[n_inner++] = j; else if (minchange) neighptr_inner[n_inner++] = j; else if (which > 0) neighptr_inner[n_inner++] = j ^ (which << SBBITS); } if (respamiddle && rsq < cut_middle_sq && rsq > cut_middle_inside_sq) { if (which == 0) neighptr_middle[n_middle++] = j; else if (minchange) neighptr_middle[n_middle++] = j; else if (which > 0) neighptr_middle[n_middle++] = j ^ (which << SBBITS); } } } ilist[i] = i; firstneigh[i] = neighptr; numneigh[i] = n; ipage.vgot(n); if (ipage.status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); ilist_inner[i] = i; firstneigh_inner[i] = neighptr_inner; numneigh_inner[i] = n_inner; ipage.vgot(n_inner); if (ipage_inner.status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); if (respamiddle) { ilist_middle[i] = i; firstneigh_middle[i] = neighptr_middle; numneigh_middle[i] = n_middle; ipage_middle->vgot(n_middle); if (ipage_middle->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); } } NPAIR_OMP_CLOSE; list->inum = nlocal; - listinner->inum = nlocal; - if (respamiddle) listmiddle->inum = nlocal; + list->inum_inner = nlocal; + if (respamiddle) list->inum_middle = nlocal; } diff --git a/src/USER-OMP/npair_half_size_bin_newtoff_omp.cpp b/src/USER-OMP/npair_half_size_bin_newtoff_omp.cpp index 120658b71..6a1cb46ea 100644 --- a/src/USER-OMP/npair_half_size_bin_newtoff_omp.cpp +++ b/src/USER-OMP/npair_half_size_bin_newtoff_omp.cpp @@ -1,179 +1,120 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include #include "npair_half_size_bin_newtoff_omp.h" #include "npair_omp.h" #include "neighbor.h" #include "neigh_list.h" #include "atom.h" #include "atom_vec.h" -#include "molecule.h" -#include "domain.h" -#include "fix_shear_history.h" #include "my_page.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ NPairHalfSizeBinNewtoffOmp::NPairHalfSizeBinNewtoffOmp(LAMMPS *lmp) : NPair(lmp) {} /* ---------------------------------------------------------------------- size particles binned neighbor list construction with partial Newton's 3rd law - shear history must be accounted for when a neighbor pair is added each owned atom i checks own bin and surrounding bins in non-Newton stencil pair stored once if i,j are both owned and i < j pair stored by me if j is ghost (also stored by proc owning j) ------------------------------------------------------------------------- */ void NPairHalfSizeBinNewtoffOmp::build(NeighList *list) { const int nlocal = (includegroup) ? atom->nfirst : atom->nlocal; - - FixShearHistory * const fix_history = (FixShearHistory *) list->fix_history; - NeighList * listhistory = list->listhistory; + const int history = list->history; + const int mask_history = 3 << SBBITS; NPAIR_OMP_INIT; #if defined(_OPENMP) -#pragma omp parallel default(none) shared(list,listhistory) +#pragma omp parallel default(none) shared(list) #endif NPAIR_OMP_SETUP(nlocal); - int i,j,k,m,n,nn,ibin,dnum,dnumbytes; + int i,j,k,m,n,nn,ibin; double xtmp,ytmp,ztmp,delx,dely,delz,rsq; double radi,radsum,cutsq; - int *neighptr,*touchptr; - double *shearptr; - MyPage *ipage_touch; - MyPage *dpage_shear; - - int *npartner; - tagint **partner; - double **shearpartner; - int **firsttouch; - double **firstshear; + int *neighptr; // loop over each atom, storing neighbors double **x = atom->x; double *radius = atom->radius; tagint *tag = atom->tag; int *type = atom->type; int *mask = atom->mask; tagint *molecule = atom->molecule; int *ilist = list->ilist; int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; // each thread has its own page allocator MyPage &ipage = list->ipage[tid]; ipage.reset(); - if (fix_history) { - npartner = fix_history->npartner; - partner = fix_history->partner; - shearpartner = fix_history->shearpartner; - firsttouch = listhistory->firstneigh; - firstshear = listhistory->firstdouble; - ipage_touch = listhistory->ipage+tid; - dpage_shear = listhistory->dpage+tid; - dnum = listhistory->dnum; - dnumbytes = dnum * sizeof(double); - ipage_touch->reset(); - dpage_shear->reset(); - } - for (i = ifrom; i < ito; i++) { n = 0; neighptr = ipage.vget(); - if (fix_history) { - nn = 0; - touchptr = ipage_touch->vget(); - shearptr = dpage_shear->vget(); - } xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; radi = radius[i]; ibin = atom2bin[i]; // loop over all atoms in surrounding bins in stencil including self // only store pair if i < j // stores own/own pairs only once // stores own/ghost pairs on both procs for (k = 0; k < nstencil; k++) { for (j = binhead[ibin+stencil[k]]; j >= 0; j = bins[j]) { if (j <= i) continue; if (exclude && exclusion(i,j,type[i],type[j],mask,molecule)) continue; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; radsum = radi + radius[j]; cutsq = (radsum+skin) * (radsum+skin); if (rsq <= cutsq) { - neighptr[n] = j; - - if (fix_history) { - if (rsq < radsum*radsum) { - for (m = 0; m < npartner[i]; m++) - if (partner[i][m] == tag[j]) break; - if (m < npartner[i]) { - touchptr[n] = 1; - memcpy(&shearptr[nn],&shearpartner[i][dnum*m],dnumbytes); - nn += dnum; - } else { - touchptr[n] = 0; - memcpy(&shearptr[nn],zeroes,dnumbytes); - nn += dnum; - } - } else { - touchptr[n] = 0; - memcpy(&shearptr[nn],zeroes,dnumbytes); - nn += dnum; - } - } - - n++; + if (history && rsq < radsum*radsum) + neighptr[n++] = j ^ mask_history; + else + neighptr[n++] = j; } } } ilist[i] = i; firstneigh[i] = neighptr; numneigh[i] = n; ipage.vgot(n); if (ipage.status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); - - if (fix_history) { - firsttouch[i] = touchptr; - firstshear[i] = shearptr; - ipage_touch->vgot(n); - dpage_shear->vgot(nn); - } } NPAIR_OMP_CLOSE; list->inum = nlocal; } diff --git a/src/USER-OMP/npair_half_size_bin_newton_omp.cpp b/src/USER-OMP/npair_half_size_bin_newton_omp.cpp index cf0c6d20f..d8e1e6da4 100644 --- a/src/USER-OMP/npair_half_size_bin_newton_omp.cpp +++ b/src/USER-OMP/npair_half_size_bin_newton_omp.cpp @@ -1,227 +1,143 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include #include "npair_half_size_bin_newton_omp.h" #include "npair_omp.h" #include "neighbor.h" #include "neigh_list.h" #include "atom.h" #include "atom_vec.h" -#include "molecule.h" -#include "domain.h" -#include "fix_shear_history.h" #include "my_page.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ NPairHalfSizeBinNewtonOmp::NPairHalfSizeBinNewtonOmp(LAMMPS *lmp) : NPair(lmp) {} /* ---------------------------------------------------------------------- size particles binned neighbor list construction with full Newton's 3rd law - shear history must be accounted for when a neighbor pair is added each owned atom i checks its own bin and other bins in Newton stencil every pair stored exactly once by some processor ------------------------------------------------------------------------- */ void NPairHalfSizeBinNewtonOmp::build(NeighList *list) { const int nlocal = (includegroup) ? atom->nfirst : atom->nlocal; - - FixShearHistory * const fix_history = (FixShearHistory *) list->fix_history; - NeighList * listhistory = list->listhistory; - if (fix_history) { - fix_history->nlocal_neigh = nlocal; - fix_history->nall_neigh = nlocal + atom->nghost; - } + const int history = list->history; + const int mask_history = 3 << SBBITS; NPAIR_OMP_INIT; #if defined(_OPENMP) -#pragma omp parallel default(none) shared(list,listhistory) +#pragma omp parallel default(none) shared(list) #endif NPAIR_OMP_SETUP(nlocal); - int i,j,k,m,n,nn,ibin,dnum,dnumbytes; + int i,j,k,m,n,nn,ibin; double xtmp,ytmp,ztmp,delx,dely,delz,rsq; double radi,radsum,cutsq; - int *neighptr,*touchptr; - double *shearptr; - MyPage *ipage_touch; - MyPage *dpage_shear; - - int *npartner; - tagint **partner; - double **shearpartner; - int **firsttouch; - double **firstshear; - - // loop over each atom, storing neighbors + int *neighptr; double **x = atom->x; double *radius = atom->radius; tagint *tag = atom->tag; int *type = atom->type; int *mask = atom->mask; tagint *molecule = atom->molecule; int *ilist = list->ilist; int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; // each thread has its own page allocator MyPage &ipage = list->ipage[tid]; ipage.reset(); - if (fix_history) { - npartner = fix_history->npartner; - partner = fix_history->partner; - shearpartner = fix_history->shearpartner; - firsttouch = listhistory->firstneigh; - firstshear = listhistory->firstdouble; - ipage_touch = listhistory->ipage+tid; - dpage_shear = listhistory->dpage+tid; - dnum = listhistory->dnum; - dnumbytes = dnum * sizeof(double); - ipage_touch->reset(); - dpage_shear->reset(); - } - for (i = ifrom; i < ito; i++) { n = 0; neighptr = ipage.vget(); - if (fix_history) { - nn = 0; - touchptr = ipage_touch->vget(); - shearptr = dpage_shear->vget(); - } xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; radi = radius[i]; // loop over rest of atoms in i's bin, ghosts are at end of linked list // if j is owned atom, store it, since j is beyond i in linked list // if j is ghost, only store if j coords are "above and to the right" of i for (j = bins[i]; j >= 0; j = bins[j]) { if (j >= nlocal) { if (x[j][2] < ztmp) continue; if (x[j][2] == ztmp) { if (x[j][1] < ytmp) continue; if (x[j][1] == ytmp && x[j][0] < xtmp) continue; } } if (exclude && exclusion(i,j,type[i],type[j],mask,molecule)) continue; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; radsum = radi + radius[j]; cutsq = (radsum+skin) * (radsum+skin); if (rsq <= cutsq) { - neighptr[n] = j; - - if (fix_history) { - if (rsq < radsum*radsum) { - for (m = 0; m < npartner[i]; m++) - if (partner[i][m] == tag[j]) break; - if (m < npartner[i]) { - touchptr[n] = 1; - memcpy(&shearptr[nn],&shearpartner[i][dnum*m],dnumbytes); - nn += dnum; - } else { - touchptr[n] = 0; - memcpy(&shearptr[nn],zeroes,dnumbytes); - nn += dnum; - } - } else { - touchptr[n] = 0; - memcpy(&shearptr[nn],zeroes,dnumbytes); - nn += dnum; - } - } - - n++; + if (history && rsq < radsum*radsum) + neighptr[n++] = j ^ mask_history; + else + neighptr[n++] = j; } } // loop over all atoms in other bins in stencil, store every pair ibin = atom2bin[i]; for (k = 0; k < nstencil; k++) { for (j = binhead[ibin+stencil[k]]; j >= 0; j = bins[j]) { if (exclude && exclusion(i,j,type[i],type[j],mask,molecule)) continue; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; radsum = radi + radius[j]; cutsq = (radsum+skin) * (radsum+skin); if (rsq <= cutsq) { - neighptr[n] = j; - - if (fix_history) { - if (rsq < radsum*radsum) { - for (m = 0; m < npartner[i]; m++) - if (partner[i][m] == tag[j]) break; - if (m < npartner[i]) { - touchptr[n] = 1; - memcpy(&shearptr[nn],&shearpartner[i][dnum*m],dnumbytes); - nn += dnum; - } else { - touchptr[n] = 0; - memcpy(&shearptr[nn],zeroes,dnumbytes); - nn += dnum; - } - } else { - touchptr[n] = 0; - memcpy(&shearptr[nn],zeroes,dnumbytes); - nn += dnum; - } - } - - n++; + if (history && rsq < radsum*radsum) + neighptr[n++] = j ^ mask_history; + else + neighptr[n++] = j; } } } ilist[i] = i; firstneigh[i] = neighptr; numneigh[i] = n; ipage.vgot(n); if (ipage.status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); - - if (fix_history) { - firsttouch[i] = touchptr; - firstshear[i] = shearptr; - ipage_touch->vgot(n); - dpage_shear->vgot(nn); - } } NPAIR_OMP_CLOSE; list->inum = nlocal; } diff --git a/src/USER-OMP/npair_half_size_bin_newton_tri_omp.cpp b/src/USER-OMP/npair_half_size_bin_newton_tri_omp.cpp index da04eebd1..b02bfa345 100644 --- a/src/USER-OMP/npair_half_size_bin_newton_tri_omp.cpp +++ b/src/USER-OMP/npair_half_size_bin_newton_tri_omp.cpp @@ -1,121 +1,125 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include "npair_half_size_bin_newton_tri_omp.h" #include "npair_omp.h" #include "neighbor.h" #include "neigh_list.h" #include "atom.h" #include "atom_vec.h" -#include "molecule.h" -#include "domain.h" #include "my_page.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ NPairHalfSizeBinNewtonTriOmp::NPairHalfSizeBinNewtonTriOmp(LAMMPS *lmp) : NPair(lmp) {} /* ---------------------------------------------------------------------- size particles binned neighbor list construction with Newton's 3rd law for triclinic - no shear history is allowed for this option each owned atom i checks its own bin and other bins in triclinic stencil every pair stored exactly once by some processor ------------------------------------------------------------------------- */ void NPairHalfSizeBinNewtonTriOmp::build(NeighList *list) { const int nlocal = (includegroup) ? atom->nfirst : atom->nlocal; + const int history = list->history; + const int mask_history = 3 << SBBITS; NPAIR_OMP_INIT; #if defined(_OPENMP) #pragma omp parallel default(none) shared(list) #endif NPAIR_OMP_SETUP(nlocal); int i,j,k,n,ibin; double xtmp,ytmp,ztmp,delx,dely,delz,rsq; double radi,radsum,cutsq; int *neighptr; // loop over each atom, storing neighbors double **x = atom->x; double *radius = atom->radius; int *type = atom->type; int *mask = atom->mask; tagint *molecule = atom->molecule; int *ilist = list->ilist; int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; // each thread has its own page allocator MyPage &ipage = list->ipage[tid]; ipage.reset(); for (i = ifrom; i < ito; i++) { n = 0; neighptr = ipage.vget(); xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; radi = radius[i]; // loop over all atoms in bins in stencil // pairs for atoms j "below" i are excluded // below = lower z or (equal z and lower y) or (equal zy and lower x) // (equal zyx and j <= i) // latter excludes self-self interaction but allows superposed atoms ibin = atom2bin[i]; for (k = 0; k < nstencil; k++) { for (j = binhead[ibin+stencil[k]]; j >= 0; j = bins[j]) { if (x[j][2] < ztmp) continue; if (x[j][2] == ztmp) { if (x[j][1] < ytmp) continue; if (x[j][1] == ytmp) { if (x[j][0] < xtmp) continue; if (x[j][0] == xtmp && j <= i) continue; } } if (exclude && exclusion(i,j,type[i],type[j],mask,molecule)) continue; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; radsum = radi + radius[j]; cutsq = (radsum+skin) * (radsum+skin); - if (rsq <= cutsq) neighptr[n++] = j; + if (rsq <= cutsq) { + if (history && rsq < radsum*radsum) + neighptr[n++] = j ^ mask_history; + else + neighptr[n++] = j; + } } } ilist[i] = i; firstneigh[i] = neighptr; numneigh[i] = n; ipage.vgot(n); if (ipage.status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); } NPAIR_OMP_CLOSE; list->inum = nlocal; } diff --git a/src/USER-OMP/npair_half_size_nsq_newtoff_omp.cpp b/src/USER-OMP/npair_half_size_nsq_newtoff_omp.cpp index f898ec382..3c7b6b118 100644 --- a/src/USER-OMP/npair_half_size_nsq_newtoff_omp.cpp +++ b/src/USER-OMP/npair_half_size_nsq_newtoff_omp.cpp @@ -1,177 +1,115 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include #include "npair_half_size_nsq_newtoff_omp.h" #include "npair_omp.h" #include "neighbor.h" #include "neigh_list.h" #include "atom.h" #include "atom_vec.h" #include "group.h" -#include "molecule.h" -#include "domain.h" -#include "fix_shear_history.h" #include "my_page.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ NPairHalfSizeNsqNewtoffOmp::NPairHalfSizeNsqNewtoffOmp(LAMMPS *lmp) : NPair(lmp) {} /* ---------------------------------------------------------------------- size particles N^2 / 2 search for neighbor pairs with partial Newton's 3rd law shear history must be accounted for when a neighbor pair is added pair added to list if atoms i and j are both owned and i < j pair added if j is ghost (also stored by proc owning j) ------------------------------------------------------------------------- */ void NPairHalfSizeNsqNewtoffOmp::build(NeighList *list) { const int nlocal = (includegroup) ? atom->nfirst : atom->nlocal; const int bitmask = (includegroup) ? group->bitmask[includegroup] : 0; - - FixShearHistory * const fix_history = (FixShearHistory *) list->fix_history; - NeighList * listhistory = list->listhistory; - if (fix_history) { - fix_history->nlocal_neigh = nlocal; - fix_history->nall_neigh = nlocal + atom->nghost; - } + const int history = list->history; + const int mask_history = 3 << SBBITS; NPAIR_OMP_INIT; #if defined(_OPENMP) -#pragma omp parallel default(none) shared(list,listhistory) +#pragma omp parallel default(none) shared(list) #endif NPAIR_OMP_SETUP(nlocal); - int i,j,m,n,nn,dnum,dnumbytes; + int i,j,m,n,nn; double xtmp,ytmp,ztmp,delx,dely,delz,rsq; double radi,radsum,cutsq; - int *neighptr,*touchptr; - double *shearptr; - - int *npartner; - tagint **partner; - double **shearpartner; - int **firsttouch; - double **firstshear; - MyPage *ipage_touch; - MyPage *dpage_shear; + int *neighptr; double **x = atom->x; double *radius = atom->radius; tagint *tag = atom->tag; int *type = atom->type; int *mask = atom->mask; tagint *molecule = atom->molecule; int nall = atom->nlocal + atom->nghost; int *ilist = list->ilist; int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; // each thread has its own page allocator MyPage &ipage = list->ipage[tid]; ipage.reset(); - if (fix_history) { - npartner = fix_history->npartner; - partner = fix_history->partner; - shearpartner = fix_history->shearpartner; - firsttouch = listhistory->firstneigh; - firstshear = listhistory->firstdouble; - ipage_touch = listhistory->ipage+tid; - dpage_shear = listhistory->dpage+tid; - dnum = listhistory->dnum; - dnumbytes = dnum * sizeof(double); - ipage_touch->reset(); - dpage_shear->reset(); - } - for (i = ifrom; i < ito; i++) { n = 0; neighptr = ipage.vget(); - if (fix_history) { - nn = 0; - touchptr = ipage_touch->vget(); - shearptr = dpage_shear->vget(); - } xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; radi = radius[i]; // loop over remaining atoms, owned and ghost for (j = i+1; j < nall; j++) { if (includegroup && !(mask[j] & bitmask)) continue; if (exclude && exclusion(i,j,type[i],type[j],mask,molecule)) continue; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; radsum = radi + radius[j]; cutsq = (radsum+skin) * (radsum+skin); if (rsq <= cutsq) { - neighptr[n] = j; - - if (fix_history) { - if (rsq < radsum*radsum) { - for (m = 0; m < npartner[i]; m++) - if (partner[i][m] == tag[j]) break; - if (m < npartner[i]) { - touchptr[n] = 1; - memcpy(&shearptr[nn],&shearpartner[i][dnum*m],dnumbytes); - nn += dnum; - } else { - touchptr[n] = 0; - memcpy(&shearptr[nn],zeroes,dnumbytes); - nn += dnum; - } - } else { - touchptr[n] = 0; - memcpy(&shearptr[nn],zeroes,dnumbytes); - nn += dnum; - } - } - - n++; + if (history && rsq < radsum*radsum) + neighptr[n++] = j ^ mask_history; + else + neighptr[n++] = j; } } ilist[i] = i; firstneigh[i] = neighptr; numneigh[i] = n; ipage.vgot(n); if (ipage.status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); - - if (fix_history) { - firsttouch[i] = touchptr; - firstshear[i] = shearptr; - ipage_touch->vgot(n); - dpage_shear->vgot(nn); - } } NPAIR_OMP_CLOSE; list->inum = nlocal; } diff --git a/src/USER-OMP/npair_half_size_nsq_newton_omp.cpp b/src/USER-OMP/npair_half_size_nsq_newton_omp.cpp index a7caac372..37a4181af 100644 --- a/src/USER-OMP/npair_half_size_nsq_newton_omp.cpp +++ b/src/USER-OMP/npair_half_size_nsq_newton_omp.cpp @@ -1,195 +1,134 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include #include "npair_half_size_nsq_newton_omp.h" #include "npair_omp.h" #include "neighbor.h" #include "neigh_list.h" #include "atom.h" #include "atom_vec.h" #include "group.h" -#include "molecule.h" -#include "domain.h" -#include "fix_shear_history.h" #include "my_page.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ NPairHalfSizeNsqNewtonOmp::NPairHalfSizeNsqNewtonOmp(LAMMPS *lmp) : NPair(lmp) {} /* ---------------------------------------------------------------------- size particles N^2 / 2 search for neighbor pairs with full Newton's 3rd law shear history must be accounted for when a neighbor pair is added pair added to list if atoms i and j are both owned and i < j if j is ghost only me or other proc adds pair decision based on itag,jtag tests ------------------------------------------------------------------------- */ void NPairHalfSizeNsqNewtonOmp::build(NeighList *list) { const int nlocal = (includegroup) ? atom->nfirst : atom->nlocal; const int bitmask = (includegroup) ? group->bitmask[includegroup] : 0;; - - FixShearHistory * const fix_history = (FixShearHistory *) list->fix_history; - NeighList * listhistory = list->listhistory; - if (fix_history) { - fix_history->nlocal_neigh = nlocal; - fix_history->nall_neigh = nlocal+atom->nghost; - } + const int history = list->history; + const int mask_history = 3 << SBBITS; NPAIR_OMP_INIT; #if defined(_OPENMP) -#pragma omp parallel default(none) shared(list,listhistory) +#pragma omp parallel default(none) shared(list) #endif NPAIR_OMP_SETUP(nlocal); - int i,j,m,n,nn,itag,jtag,dnum,dnumbytes; + int i,j,m,n,nn,itag,jtag; double xtmp,ytmp,ztmp,delx,dely,delz,rsq; double radi,radsum,cutsq; - int *neighptr,*touchptr; - double *shearptr; - - int *npartner; - tagint **partner; - double **shearpartner; - int **firsttouch; - double **firstshear; - MyPage *ipage_touch; - MyPage *dpage_shear; + int *neighptr; double **x = atom->x; double *radius = atom->radius; tagint *tag = atom->tag; int *type = atom->type; int *mask = atom->mask; tagint *molecule = atom->molecule; int nall = atom->nlocal + atom->nghost; int *ilist = list->ilist; int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; // each thread has its own page allocator MyPage &ipage = list->ipage[tid]; ipage.reset(); - if (fix_history) { - npartner = fix_history->npartner; - partner = fix_history->partner; - shearpartner = fix_history->shearpartner; - firsttouch = listhistory->firstneigh; - firstshear = listhistory->firstdouble; - ipage_touch = listhistory->ipage+tid; - dpage_shear = listhistory->dpage+tid; - dnum = listhistory->dnum; - dnumbytes = dnum * sizeof(double); - ipage_touch->reset(); - dpage_shear->reset(); - } - for (i = ifrom; i < ito; i++) { n = 0; neighptr = ipage.vget(); - if (fix_history) { - nn = 0; - touchptr = ipage_touch->vget(); - shearptr = dpage_shear->vget(); - } itag = tag[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; radi = radius[i]; // loop over remaining atoms, owned and ghost for (j = i+1; j < nall; j++) { if (includegroup && !(mask[j] & bitmask)) continue; if (j >= nlocal) { jtag = tag[j]; if (itag > jtag) { if ((itag+jtag) % 2 == 0) continue; } else if (itag < jtag) { if ((itag+jtag) % 2 == 1) continue; } else { if (x[j][2] < ztmp) continue; if (x[j][2] == ztmp) { if (x[j][1] < ytmp) continue; if (x[j][1] == ytmp && x[j][0] < xtmp) continue; } } } if (exclude && exclusion(i,j,type[i],type[j],mask,molecule)) continue; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; radsum = radi + radius[j]; cutsq = (radsum+skin) * (radsum+skin); if (rsq <= cutsq) { - neighptr[n] = j; - - if (fix_history) { - if (rsq < radsum*radsum) { - for (m = 0; m < npartner[i]; m++) - if (partner[i][m] == tag[j]) break; - if (m < npartner[i]) { - touchptr[n] = 1; - memcpy(&shearptr[nn],&shearpartner[i][dnum*m],dnumbytes); - nn += dnum; - } else { - touchptr[n] = 0; - memcpy(&shearptr[nn],zeroes,dnumbytes); - nn += dnum; - } - } else { - touchptr[n] = 0; - memcpy(&shearptr[nn],zeroes,dnumbytes); - nn += dnum; - } - } - - n++; + if (history && rsq < radsum*radsum) + neighptr[n++] = j ^ mask_history; + else + neighptr[n++] = j; } } ilist[i] = i; firstneigh[i] = neighptr; numneigh[i] = n; ipage.vgot(n); if (ipage.status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); - if (fix_history) { - firsttouch[i] = touchptr; - firstshear[i] = shearptr; - ipage_touch->vgot(n); - dpage_shear->vgot(nn); - } } NPAIR_OMP_CLOSE; list->inum = nlocal; } diff --git a/src/USER-OMP/pair_buck_long_coul_long_omp.cpp b/src/USER-OMP/pair_buck_long_coul_long_omp.cpp index 87f9e2e32..f99637240 100644 --- a/src/USER-OMP/pair_buck_long_coul_long_omp.cpp +++ b/src/USER-OMP/pair_buck_long_coul_long_omp.cpp @@ -1,1183 +1,1183 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include #include "math_vector.h" #include "pair_buck_long_coul_long_omp.h" #include "atom.h" #include "comm.h" #include "neighbor.h" #include "neigh_list.h" #include "force.h" #include "suffix.h" using namespace LAMMPS_NS; #define EWALD_F 1.12837917 #define EWALD_P 0.3275911 #define A1 0.254829592 #define A2 -0.284496736 #define A3 1.421413741 #define A4 -1.453152027 #define A5 1.061405429 /* ---------------------------------------------------------------------- */ PairBuckLongCoulLongOMP::PairBuckLongCoulLongOMP(LAMMPS *lmp) : PairBuckLongCoulLong(lmp), ThrOMP(lmp, THR_PAIR) { suffix_flag |= Suffix::OMP; respa_enable = 1; cut_respa = NULL; } /* ---------------------------------------------------------------------- */ void PairBuckLongCoulLongOMP::compute(int eflag, int vflag) { if (eflag || vflag) { ev_setup(eflag,vflag); } else evflag = vflag_fdotr = 0; const int order1 = ewald_order&(1<<1); const int order6 = ewald_order&(1<<6); const int nall = atom->nlocal + atom->nghost; const int nthreads = comm->nthreads; const int inum = list->inum; #if defined(_OPENMP) #pragma omp parallel default(none) shared(eflag,vflag) #endif { int ifrom, ito, tid; loop_setup_thr(ifrom, ito, tid, inum, nthreads); ThrData *thr = fix->get_thr(tid); thr->timer(Timer::START); ev_setup_thr(eflag, vflag, nall, eatom, vatom, thr); if (order6) { if (order1) { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,0,0,1,1>(ifrom, ito, thr); else eval<1,1,0,0,0,1,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,0,0,1,1>(ifrom, ito, thr); else eval<1,0,0,0,0,1,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,0,0,1,1>(ifrom, ito, thr); else eval<0,0,0,0,0,1,1>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,1,0,1,1>(ifrom, ito, thr); else eval<1,1,0,1,0,1,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,1,0,1,1>(ifrom, ito, thr); else eval<1,0,0,1,0,1,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,1,0,1,1>(ifrom, ito, thr); else eval<0,0,0,1,0,1,1>(ifrom, ito, thr); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,0,1,1,1>(ifrom, ito, thr); else eval<1,1,0,0,1,1,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,0,1,1,1>(ifrom, ito, thr); else eval<1,0,0,0,1,1,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,0,1,1,1>(ifrom, ito, thr); else eval<0,0,0,0,1,1,1>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,1,1,1,1>(ifrom, ito, thr); else eval<1,1,0,1,1,1,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,1,1,1,1>(ifrom, ito, thr); else eval<1,0,0,1,1,1,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,1,1,1,1>(ifrom, ito, thr); else eval<0,0,0,1,1,1,1>(ifrom, ito, thr); } } } } else { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,0,0,0,1>(ifrom, ito, thr); else eval<1,1,0,0,0,0,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,0,0,0,1>(ifrom, ito, thr); else eval<1,0,0,0,0,0,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,0,0,0,1>(ifrom, ito, thr); else eval<0,0,0,0,0,0,1>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,1,0,0,1>(ifrom, ito, thr); else eval<1,1,0,1,0,0,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,1,0,0,1>(ifrom, ito, thr); else eval<1,0,0,1,0,0,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,1,0,0,1>(ifrom, ito, thr); else eval<0,0,0,1,0,0,1>(ifrom, ito, thr); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,0,1,0,1>(ifrom, ito, thr); else eval<1,1,0,0,1,0,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,0,1,0,1>(ifrom, ito, thr); else eval<1,0,0,0,1,0,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,0,1,0,1>(ifrom, ito, thr); else eval<0,0,0,0,1,0,1>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,1,1,0,1>(ifrom, ito, thr); else eval<1,1,0,1,1,0,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,1,1,0,1>(ifrom, ito, thr); else eval<1,0,0,1,1,0,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,1,1,0,1>(ifrom, ito, thr); else eval<0,0,0,1,1,0,1>(ifrom, ito, thr); } } } } } else { if (order1) { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,0,0,1,0>(ifrom, ito, thr); else eval<1,1,0,0,0,1,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,0,0,1,0>(ifrom, ito, thr); else eval<1,0,0,0,0,1,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,0,0,1,0>(ifrom, ito, thr); else eval<0,0,0,0,0,1,0>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,1,0,1,0>(ifrom, ito, thr); else eval<1,1,0,1,0,1,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,1,0,1,0>(ifrom, ito, thr); else eval<1,0,0,1,0,1,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,1,0,1,0>(ifrom, ito, thr); else eval<0,0,0,1,0,1,0>(ifrom, ito, thr); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,0,1,1,0>(ifrom, ito, thr); else eval<1,1,0,0,1,1,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,0,1,1,0>(ifrom, ito, thr); else eval<1,0,0,0,1,1,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,0,1,1,0>(ifrom, ito, thr); else eval<0,0,0,0,1,1,0>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,1,1,1,0>(ifrom, ito, thr); else eval<1,1,0,1,1,1,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,1,1,1,0>(ifrom, ito, thr); else eval<1,0,0,1,1,1,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,1,1,1,0>(ifrom, ito, thr); else eval<0,0,0,1,1,1,0>(ifrom, ito, thr); } } } } else { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,0,0,0,0>(ifrom, ito, thr); else eval<1,1,0,0,0,0,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,0,0,0,0>(ifrom, ito, thr); else eval<1,0,0,0,0,0,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,0,0,0,0>(ifrom, ito, thr); else eval<0,0,0,0,0,0,0>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,1,0,0,0>(ifrom, ito, thr); else eval<1,1,0,1,0,0,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,1,0,0,0>(ifrom, ito, thr); else eval<1,0,0,1,0,0,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,1,0,0,0>(ifrom, ito, thr); else eval<0,0,0,1,0,0,0>(ifrom, ito, thr); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,0,1,0,0>(ifrom, ito, thr); else eval<1,1,0,0,1,0,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,0,1,0,0>(ifrom, ito, thr); else eval<1,0,0,0,1,0,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,0,1,0,0>(ifrom, ito, thr); else eval<0,0,0,0,1,0,0>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,1,1,0,0>(ifrom, ito, thr); else eval<1,1,0,1,1,0,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,1,1,0,0>(ifrom, ito, thr); else eval<1,0,0,1,1,0,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,1,1,0,0>(ifrom, ito, thr); else eval<0,0,0,1,1,0,0>(ifrom, ito, thr); } } } } } thr->timer(Timer::PAIR); reduce_thr(this, eflag, vflag, thr); } // end of omp parallel region } /* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */ void PairBuckLongCoulLongOMP::compute_inner() { const int nall = atom->nlocal + atom->nghost; const int nthreads = comm->nthreads; - const int inum = listinner->inum; + const int inum = list->inum_inner; #if defined(_OPENMP) #pragma omp parallel default(none) #endif { int ifrom, ito, tid; loop_setup_thr(ifrom, ito, tid, inum, nthreads); ThrData *thr = fix->get_thr(tid); thr->timer(Timer::START); ev_setup_thr(0, 0, nall, 0, 0, thr); eval_inner(ifrom, ito, thr); thr->timer(Timer::PAIR); } // end of omp parallel region } /* ---------------------------------------------------------------------- */ void PairBuckLongCoulLongOMP::compute_middle() { const int nall = atom->nlocal + atom->nghost; const int nthreads = comm->nthreads; - const int inum = listmiddle->inum; + const int inum = list->inum_middle; #if defined(_OPENMP) #pragma omp parallel default(none) #endif { int ifrom, ito, tid; loop_setup_thr(ifrom, ito, tid, inum, nthreads); ThrData *thr = fix->get_thr(tid); thr->timer(Timer::START); ev_setup_thr(0, 0, nall, 0, 0, thr); eval_middle(ifrom, ito, thr); thr->timer(Timer::PAIR); } // end of omp parallel region } /* ---------------------------------------------------------------------- */ void PairBuckLongCoulLongOMP::compute_outer(int eflag, int vflag) { if (eflag || vflag) { ev_setup(eflag,vflag); } else evflag = vflag_fdotr = 0; const int order1 = ewald_order&(1<<1); const int order6 = ewald_order&(1<<6); const int nall = atom->nlocal + atom->nghost; const int nthreads = comm->nthreads; - const int inum = listouter->inum; + const int inum = list->inum; #if defined(_OPENMP) #pragma omp parallel default(none) shared(eflag,vflag) #endif { int ifrom, ito, tid; loop_setup_thr(ifrom, ito, tid, inum, nthreads); ThrData *thr = fix->get_thr(tid); thr->timer(Timer::START); ev_setup_thr(eflag, vflag, nall, eatom, vatom, thr); if (order6) { if (order1) { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,0,0,1,1>(ifrom, ito, thr); else eval_outer<1,1,0,0,0,1,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,0,0,1,1>(ifrom, ito, thr); else eval_outer<1,0,0,0,0,1,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,0,0,1,1>(ifrom, ito, thr); else eval_outer<0,0,0,0,0,1,1>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,1,0,1,1>(ifrom, ito, thr); else eval_outer<1,1,0,1,0,1,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,1,0,1,1>(ifrom, ito, thr); else eval_outer<1,0,0,1,0,1,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,1,0,1,1>(ifrom, ito, thr); else eval_outer<0,0,0,1,0,1,1>(ifrom, ito, thr); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,0,1,1,1>(ifrom, ito, thr); else eval_outer<1,1,0,0,1,1,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,0,1,1,1>(ifrom, ito, thr); else eval_outer<1,0,0,0,1,1,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,0,1,1,1>(ifrom, ito, thr); else eval_outer<0,0,0,0,1,1,1>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,1,1,1,1>(ifrom, ito, thr); else eval_outer<1,1,0,1,1,1,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,1,1,1,1>(ifrom, ito, thr); else eval_outer<1,0,0,1,1,1,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,1,1,1,1>(ifrom, ito, thr); else eval_outer<0,0,0,1,1,1,1>(ifrom, ito, thr); } } } } else { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,0,0,0,1>(ifrom, ito, thr); else eval_outer<1,1,0,0,0,0,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,0,0,0,1>(ifrom, ito, thr); else eval_outer<1,0,0,0,0,0,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,0,0,0,1>(ifrom, ito, thr); else eval_outer<0,0,0,0,0,0,1>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,1,0,0,1>(ifrom, ito, thr); else eval_outer<1,1,0,1,0,0,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,1,0,0,1>(ifrom, ito, thr); else eval_outer<1,0,0,1,0,0,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,1,0,0,1>(ifrom, ito, thr); else eval_outer<0,0,0,1,0,0,1>(ifrom, ito, thr); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,0,1,0,1>(ifrom, ito, thr); else eval_outer<1,1,0,0,1,0,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,0,1,0,1>(ifrom, ito, thr); else eval_outer<1,0,0,0,1,0,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,0,1,0,1>(ifrom, ito, thr); else eval_outer<0,0,0,0,1,0,1>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,1,1,0,1>(ifrom, ito, thr); else eval_outer<1,1,0,1,1,0,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,1,1,0,1>(ifrom, ito, thr); else eval_outer<1,0,0,1,1,0,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,1,1,0,1>(ifrom, ito, thr); else eval_outer<0,0,0,1,1,0,1>(ifrom, ito, thr); } } } } } else { if (order1) { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,0,0,1,0>(ifrom, ito, thr); else eval_outer<1,1,0,0,0,1,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,0,0,1,0>(ifrom, ito, thr); else eval_outer<1,0,0,0,0,1,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,0,0,1,0>(ifrom, ito, thr); else eval_outer<0,0,0,0,0,1,0>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,1,0,1,0>(ifrom, ito, thr); else eval_outer<1,1,0,1,0,1,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,1,0,1,0>(ifrom, ito, thr); else eval_outer<1,0,0,1,0,1,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,1,0,1,0>(ifrom, ito, thr); else eval_outer<0,0,0,1,0,1,0>(ifrom, ito, thr); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,0,1,1,0>(ifrom, ito, thr); else eval_outer<1,1,0,0,1,1,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,0,1,1,0>(ifrom, ito, thr); else eval_outer<1,0,0,0,1,1,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,0,1,1,0>(ifrom, ito, thr); else eval_outer<0,0,0,0,1,1,0>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,1,1,1,0>(ifrom, ito, thr); else eval_outer<1,1,0,1,1,1,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,1,1,1,0>(ifrom, ito, thr); else eval_outer<1,0,0,1,1,1,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,1,1,1,0>(ifrom, ito, thr); else eval_outer<0,0,0,1,1,1,0>(ifrom, ito, thr); } } } } else { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,0,0,0,0>(ifrom, ito, thr); else eval_outer<1,1,0,0,0,0,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,0,0,0,0>(ifrom, ito, thr); else eval_outer<1,0,0,0,0,0,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,0,0,0,0>(ifrom, ito, thr); else eval_outer<0,0,0,0,0,0,0>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,1,0,0,0>(ifrom, ito, thr); else eval_outer<1,1,0,1,0,0,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,1,0,0,0>(ifrom, ito, thr); else eval_outer<1,0,0,1,0,0,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,1,0,0,0>(ifrom, ito, thr); else eval_outer<0,0,0,1,0,0,0>(ifrom, ito, thr); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,0,1,0,0>(ifrom, ito, thr); else eval_outer<1,1,0,0,1,0,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,0,1,0,0>(ifrom, ito, thr); else eval_outer<1,0,0,0,1,0,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,0,1,0,0>(ifrom, ito, thr); else eval_outer<0,0,0,0,1,0,0>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,1,1,0,0>(ifrom, ito, thr); else eval_outer<1,1,0,1,1,0,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,1,1,0,0>(ifrom, ito, thr); else eval_outer<1,0,0,1,1,0,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,1,1,0,0>(ifrom, ito, thr); else eval_outer<0,0,0,1,1,0,0>(ifrom, ito, thr); } } } } } thr->timer(Timer::PAIR); reduce_thr(this, eflag, vflag, thr); } // end of omp parallel region } /* ---------------------------------------------------------------------- */ template < const int EVFLAG, const int EFLAG, const int NEWTON_PAIR, const int CTABLE, const int DISPTABLE, const int ORDER1, const int ORDER6 > void PairBuckLongCoulLongOMP::eval(int iifrom, int iito, ThrData * const thr) { double evdwl,ecoul,fpair; evdwl = ecoul = 0.0; const double * const * const x = atom->x; double * const * const f = thr->get_f(); const double * const q = atom->q; const int * const type = atom->type; const int nlocal = atom->nlocal; const double * const special_coul = force->special_coul; const double * const special_lj = force->special_lj; const double qqrd2e = force->qqrd2e; const double *x0 = x[0]; double *f0 = f[0], *fi = f0; int *ilist = list->ilist; // loop over neighbors of my atoms int i, ii, j; int *jneigh, *jneighn, typei, typej, ni; double qi = 0.0, qri = 0.0, *cutsqi, *cut_bucksqi, *buck1i, *buck2i, *buckai, *buckci, *rhoinvi, *offseti; double r, rsq, r2inv, force_coul, force_buck; double g2 = g_ewald_6*g_ewald_6, g6 = g2*g2*g2, g8 = g6*g2; vector xi, d; for (ii = iifrom; ii < iito; ++ii) { // loop over my atoms i = ilist[ii]; fi=f0+3*i; if (ORDER1) qri = (qi = q[i])*qqrd2e; // initialize constants offseti = offset[typei = type[i]]; buck1i = buck1[typei]; buck2i = buck2[typei]; buckai = buck_a[typei]; buckci = buck_c[typei], rhoinvi = rhoinv[typei]; cutsqi = cutsq[typei]; cut_bucksqi = cut_bucksq[typei]; memcpy(xi, x0+(i+(i<<1)), sizeof(vector)); jneighn = (jneigh = list->firstneigh[i])+list->numneigh[i]; for (; jneigh= cutsqi[typej = type[j]]) continue; r2inv = 1.0/rsq; r = sqrt(rsq); if (ORDER1 && (rsq < cut_coulsq)) { // coulombic if (!CTABLE || rsq <= tabinnersq) { // series real space register double x = g_ewald*r; register double s = qri*q[j], t = 1.0/(1.0+EWALD_P*x); if (ni == 0) { s *= g_ewald*exp(-x*x); force_coul = (t *= ((((t*A5+A4)*t+A3)*t+A2)*t+A1)*s/x)+EWALD_F*s; if (EFLAG) ecoul = t; } else { // special case register double f = s*(1.0-special_coul[ni])/r; s *= g_ewald*exp(-x*x); force_coul = (t *= ((((t*A5+A4)*t+A3)*t+A2)*t+A1)*s/x)+EWALD_F*s-f; if (EFLAG) ecoul = t-f; } } // table real space else { register union_int_float_t t; t.f = rsq; register const int k = (t.i & ncoulmask) >> ncoulshiftbits; register double f = (rsq-rtable[k])*drtable[k], qiqj = qi*q[j]; if (ni == 0) { force_coul = qiqj*(ftable[k]+f*dftable[k]); if (EFLAG) ecoul = qiqj*(etable[k]+f*detable[k]); } else { // special case t.f = (1.0-special_coul[ni])*(ctable[k]+f*dctable[k]); force_coul = qiqj*(ftable[k]+f*dftable[k]-t.f); if (EFLAG) ecoul = qiqj*(etable[k]+f*detable[k]-t.f); } } } else force_coul = ecoul = 0.0; if (rsq < cut_bucksqi[typej]) { // buckingham register double rn = r2inv*r2inv*r2inv, expr = exp(-r*rhoinvi[typej]); if (ORDER6) { // long-range if (!DISPTABLE || rsq <= tabinnerdispsq) { register double x2 = g2*rsq, a2 = 1.0/x2; x2 = a2*exp(-x2)*buckci[typej]; if (ni == 0) { force_buck = r*expr*buck1i[typej]-g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq; if (EFLAG) evdwl = expr*buckai[typej]-g6*((a2+1.0)*a2+0.5)*x2; } else { // special case register double f = special_lj[ni], t = rn*(1.0-f); force_buck = f*r*expr*buck1i[typej]- g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq+t*buck2i[typej]; if (EFLAG) evdwl = f*expr*buckai[typej] - g6*((a2+1.0)*a2+0.5)*x2+t*buckci[typej]; } } else { //table real space register union_int_float_t disp_t; disp_t.f = rsq; register const int disp_k = (disp_t.i & ndispmask)>>ndispshiftbits; register double f_disp = (rsq-rdisptable[disp_k])*drdisptable[disp_k]; if (ni == 0) { force_buck = r*expr*buck1i[typej]-(fdisptable[disp_k]+f_disp*dfdisptable[disp_k])*buckci[typej]; if (EFLAG) evdwl = expr*buckai[typej]-(edisptable[disp_k]+f_disp*dedisptable[disp_k])*buckci[typej]; } else { //speial case register double f = special_lj[ni], t = rn*(1.0-f); force_buck = f*r*expr*buck1i[typej] -(fdisptable[disp_k]+f_disp*dfdisptable[disp_k])*buckci[typej] +t*buck2i[typej]; if (EFLAG) evdwl = f*expr*buckai[typej] -(edisptable[disp_k]+f_disp*dedisptable[disp_k])*buckci[typej]+t*buckci[typej]; } } } else { // cut if (ni == 0) { force_buck = r*expr*buck1i[typej]-rn*buck2i[typej]; if (EFLAG) evdwl = expr*buckai[typej] - rn*buckci[typej]-offseti[typej]; } else { // special case register double f = special_lj[ni]; force_buck = f*(r*expr*buck1i[typej]-rn*buck2i[typej]); if (EFLAG) evdwl = f*(expr*buckai[typej]-rn*buckci[typej]-offseti[typej]); } } } else force_buck = evdwl = 0.0; fpair = (force_coul+force_buck)*r2inv; if (NEWTON_PAIR || j < nlocal) { register double *fj = f0+(j+(j<<1)), f; fi[0] += f = d[0]*fpair; fj[0] -= f; fi[1] += f = d[1]*fpair; fj[1] -= f; fi[2] += f = d[2]*fpair; fj[2] -= f; } else { fi[0] += d[0]*fpair; fi[1] += d[1]*fpair; fi[2] += d[2]*fpair; } if (EVFLAG) ev_tally_thr(this,i,j,nlocal,NEWTON_PAIR, evdwl,ecoul,fpair,d[0],d[1],d[2],thr); } } } /* ---------------------------------------------------------------------- */ void PairBuckLongCoulLongOMP::eval_inner(int iifrom, int iito, ThrData * const thr) { double r, rsq, r2inv, force_coul = 0.0, force_buck, fpair; const double * const * const x = atom->x; double * const * const f = thr->get_f(); const double * const q = atom->q; const int * const type = atom->type; const int nlocal = atom->nlocal; const double * const special_coul = force->special_coul; const double * const special_lj = force->special_lj; const double qqrd2e = force->qqrd2e; const double *x0 = x[0]; double *f0 = f[0], *fi = 0; - int *ilist = listinner->ilist; + int *ilist = list->ilist_inner; const int newton_pair = force->newton_pair; const double cut_out_on = cut_respa[0]; const double cut_out_off = cut_respa[1]; const double cut_out_diff = cut_out_off - cut_out_on; const double cut_out_on_sq = cut_out_on*cut_out_on; const double cut_out_off_sq = cut_out_off*cut_out_off; int *jneigh, *jneighn, typei, typej, ni; const int order1 = (ewald_order|(ewald_off^-1))&(1<<1); int i, j, ii; double qri, *cut_bucksqi, *buck1i, *buck2i, *rhoinvi; vector xi, d; for (ii = iifrom; ii < iito; ++ii) { // loop over my atoms i = ilist[ii]; fi = f0+3*i; if (order1) qri = qqrd2e*q[i]; memcpy(xi, x0+(i+(i<<1)), sizeof(vector)); cut_bucksqi = cut_bucksq[typei = type[i]]; buck1i = buck1[typei]; buck2i = buck2[typei]; rhoinvi = rhoinv[typei]; - jneighn = (jneigh = listinner->firstneigh[i])+listinner->numneigh[i]; + jneighn = (jneigh = list->firstneigh_inner[i])+list->numneigh_inner[i]; for (; jneigh= cut_out_off_sq) continue; r2inv = 1.0/rsq; r = sqrt(rsq); if (order1 && (rsq < cut_coulsq)) // coulombic force_coul = ni == 0 ? qri*q[j]/r : qri*q[j]/r*special_coul[ni]; if (rsq < cut_bucksqi[typej = type[j]]) { // buckingham register double rn = r2inv*r2inv*r2inv, expr = exp(-r*rhoinvi[typej]); force_buck = ni == 0 ? (r*expr*buck1i[typej]-rn*buck2i[typej]) : (r*expr*buck1i[typej]-rn*buck2i[typej])*special_lj[ni]; } else force_buck = 0.0; fpair = (force_coul + force_buck) * r2inv; if (rsq > cut_out_on_sq) { // switching register double rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; fpair *= 1.0 + rsw*rsw*(2.0*rsw-3.0); } if (newton_pair || j < nlocal) { // force update register double *fj = f0+(j+(j<<1)), f; fi[0] += f = d[0]*fpair; fj[0] -= f; fi[1] += f = d[1]*fpair; fj[1] -= f; fi[2] += f = d[2]*fpair; fj[2] -= f; } else { fi[0] += d[0]*fpair; fi[1] += d[1]*fpair; fi[2] += d[2]*fpair; } } } } /* ---------------------------------------------------------------------- */ void PairBuckLongCoulLongOMP::eval_middle(int iifrom, int iito, ThrData * const thr) { double r, rsq, r2inv, force_coul = 0.0, force_buck, fpair; const double * const * const x = atom->x; double * const * const f = thr->get_f(); const double * const q = atom->q; const int * const type = atom->type; const int nlocal = atom->nlocal; const double * const special_coul = force->special_coul; const double * const special_lj = force->special_lj; const double qqrd2e = force->qqrd2e; const double *x0 = x[0]; double *f0 = f[0], *fi = 0; - int *ilist = listmiddle->ilist; + int *ilist = list->ilist_middle; const int newton_pair = force->newton_pair; const double cut_in_off = cut_respa[0]; const double cut_in_on = cut_respa[1]; const double cut_out_on = cut_respa[2]; const double cut_out_off = cut_respa[3]; const double cut_in_diff = cut_in_on - cut_in_off; const double cut_out_diff = cut_out_off - cut_out_on; const double cut_in_off_sq = cut_in_off*cut_in_off; const double cut_in_on_sq = cut_in_on*cut_in_on; const double cut_out_on_sq = cut_out_on*cut_out_on; const double cut_out_off_sq = cut_out_off*cut_out_off; int *jneigh, *jneighn, typei, typej, ni; const int order1 = (ewald_order|(ewald_off^-1))&(1<<1); int i, j, ii; double qri, *cut_bucksqi, *buck1i, *buck2i, *rhoinvi; vector xi, d; for (ii = iifrom; ii < iito; ++ii) { // loop over my atoms i = ilist[ii]; fi = f0+3*i; if (order1) qri = qqrd2e*q[i]; memcpy(xi, x0+(i+(i<<1)), sizeof(vector)); cut_bucksqi = cut_bucksq[typei = type[i]]; buck1i = buck1[typei]; buck2i = buck2[typei]; rhoinvi = rhoinv[typei]; - jneighn = (jneigh = listmiddle->firstneigh[i])+listmiddle->numneigh[i]; + jneighn = (jneigh = list->firstneigh_middle[i])+list->numneigh_middle[i]; for (; jneigh= cut_out_off_sq) continue; if (rsq <= cut_in_off_sq) continue; r2inv = 1.0/rsq; r = sqrt(rsq); if (order1 && (rsq < cut_coulsq)) // coulombic force_coul = ni == 0 ? qri*q[j]/r : qri*q[j]/r*special_coul[ni]; if (rsq < cut_bucksqi[typej = type[j]]) { // buckingham register double rn = r2inv*r2inv*r2inv, expr = exp(-r*rhoinvi[typej]); force_buck = ni == 0 ? (r*expr*buck1i[typej]-rn*buck2i[typej]) : (r*expr*buck1i[typej]-rn*buck2i[typej])*special_lj[ni]; } else force_buck = 0.0; fpair = (force_coul + force_buck) * r2inv; if (rsq < cut_in_on_sq) { // switching register double rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; fpair *= rsw*rsw*(3.0 - 2.0*rsw); } if (rsq > cut_out_on_sq) { register double rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; fpair *= 1.0 + rsw*rsw*(2.0*rsw-3.0); } if (newton_pair || j < nlocal) { // force update register double *fj = f0+(j+(j<<1)), f; fi[0] += f = d[0]*fpair; fj[0] -= f; fi[1] += f = d[1]*fpair; fj[1] -= f; fi[2] += f = d[2]*fpair; fj[2] -= f; } else { fi[0] += d[0]*fpair; fi[1] += d[1]*fpair; fi[2] += d[2]*fpair; } } } } /* ---------------------------------------------------------------------- */ template < const int EVFLAG, const int EFLAG, const int NEWTON_PAIR, const int CTABLE, const int DISPTABLE, const int ORDER1, const int ORDER6 > void PairBuckLongCoulLongOMP::eval_outer(int iiform, int iito, ThrData * const thr) { double evdwl,ecoul,fpair,fvirial; evdwl = ecoul = 0.0; const double * const * const x = atom->x; double * const * const f = thr->get_f(); const double * const q = atom->q; const int * const type = atom->type; const int nlocal = atom->nlocal; const double * const special_coul = force->special_coul; const double * const special_lj = force->special_lj; const double qqrd2e = force->qqrd2e; const double *x0 = x[0]; double *f0 = f[0], *fi = f0; - int *ilist = listouter->ilist; + int *ilist = list->ilist; int i, j, ii; int *jneigh, *jneighn, typei, typej, ni, respa_flag; double qi = 0.0, qri = 0.0; double *cutsqi, *cut_bucksqi, *buck1i, *buck2i, *buckai, *buckci, *rhoinvi, *offseti; double r, rsq, r2inv, force_coul, force_buck; double g2 = g_ewald_6*g_ewald_6, g6 = g2*g2*g2, g8 = g6*g2; double respa_buck = 0.0, respa_coul = 0.0, frespa = 0.0; vector xi, d; const double cut_in_off = cut_respa[2]; const double cut_in_on = cut_respa[3]; const double cut_in_diff = cut_in_on - cut_in_off; const double cut_in_off_sq = cut_in_off*cut_in_off; const double cut_in_on_sq = cut_in_on*cut_in_on; for (ii = iiform; ii < iito; ++ii) { // loop over my atoms i = ilist[ii]; fi = f0+3*i; if (ORDER1) qri = (qi = q[i])*qqrd2e; // initialize constants offseti = offset[typei = type[i]]; buck1i = buck1[typei]; buck2i = buck2[typei]; buckai = buck_a[typei]; buckci = buck_c[typei]; rhoinvi = rhoinv[typei]; cutsqi = cutsq[typei]; cut_bucksqi = cut_bucksq[typei]; memcpy(xi, x0+(i+(i<<1)), sizeof(vector)); - jneighn = (jneigh = listouter->firstneigh[i])+listouter->numneigh[i]; + jneighn = (jneigh = list->firstneigh[i])+list->numneigh[i]; for (; jneigh= cutsqi[typej = type[j]]) continue; r2inv = 1.0/rsq; r = sqrt(rsq); frespa = 1.0; //check whether and how to compute respa corrections respa_coul = 0.0; respa_buck = 0.0; respa_flag = rsq < cut_in_on_sq ? 1 : 0; if (respa_flag && (rsq > cut_in_off_sq)) { register double rsw = (r-cut_in_off)/cut_in_diff; frespa = 1-rsw*rsw*(3.0-2.0*rsw); } if (ORDER1 && (rsq < cut_coulsq)) { // coulombic if (!CTABLE || rsq <= tabinnersq) { // series real space register double s = qri*q[j]; if (respa_flag) // correct for respa respa_coul = ni == 0 ? frespa*s/r : frespa*s/r*special_coul[ni]; register double x = g_ewald*r, t = 1.0/(1.0+EWALD_P*x); if (ni == 0) { s *= g_ewald*exp(-x*x); force_coul = (t *= ((((t*A5+A4)*t+A3)*t+A2)*t+A1)*s/x)+EWALD_F*s-respa_coul; if (EFLAG) ecoul = t; } else { // correct for special register double ri = s*(1.0-special_coul[ni])/r; s *= g_ewald*exp(-x*x); force_coul = (t *= ((((t*A5+A4)*t+A3)*t+A2)*t+A1)*s/x)+EWALD_F*s-ri-respa_coul; if (EFLAG) ecoul = t-ri; } } // table real space else { if (respa_flag) { register double s = qri*q[j]; respa_coul = ni == 0 ? frespa*s/r : frespa*s/r*special_coul[ni]; } register union_int_float_t t; t.f = rsq; register const int k = (t.i & ncoulmask) >> ncoulshiftbits; register double f = (rsq-rtable[k])*drtable[k], qiqj = qi*q[j]; if (ni == 0) { force_coul = qiqj*(ftable[k]+f*dftable[k]); if (EFLAG) ecoul = qiqj*(etable[k]+f*detable[k]); } else { // correct for special t.f = (1.0-special_coul[ni])*(ctable[k]+f*dctable[k]); force_coul = qiqj*(ftable[k]+f*dftable[k]-t.f); if (EFLAG) { t.f = (1.0-special_coul[ni])*(ptable[k]+f*dptable[k]); ecoul = qiqj*(etable[k]+f*detable[k]-t.f); } } } } else force_coul = respa_coul = ecoul = 0.0; if (rsq < cut_bucksqi[typej]) { // buckingham register double rn = r2inv*r2inv*r2inv, expr = exp(-r*rhoinvi[typej]); if (respa_flag) respa_buck = ni == 0 ? // correct for respa frespa*(r*expr*buck1i[typej]-rn*buck2i[typej]) : frespa*(r*expr*buck1i[typej]-rn*buck2i[typej])*special_lj[ni]; if (ORDER6) { // long-range form if (!DISPTABLE || rsq <= tabinnerdispsq) { register double x2 = g2*rsq, a2 = 1.0/x2; x2 = a2*exp(-x2)*buckci[typej]; if (ni == 0) { force_buck = r*expr*buck1i[typej]-g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq-respa_buck; if (EFLAG) evdwl = expr*buckai[typej]-g6*((a2+1.0)*a2+0.5)*x2; } else { // correct for special register double f = special_lj[ni], t = rn*(1.0-f); force_buck = f*r*expr*buck1i[typej]- g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq+t*buck2i[typej]-respa_buck; if (EFLAG) evdwl = f*expr*buckai[typej] - g6*((a2+1.0)*a2+0.5)*x2+t*buckci[typej]; } } else { // table real space register union_int_float_t disp_t; disp_t.f = rsq; register const int disp_k = (disp_t.i & ndispmask)>>ndispshiftbits; register double f_disp = (rsq-rdisptable[disp_k])*drdisptable[disp_k]; register double rn = r2inv*r2inv*r2inv; if (ni == 0) { force_buck = r*expr*buck1i[typej]-(fdisptable[disp_k]+f_disp*dfdisptable[disp_k])*buckci[typej]-respa_buck; if (EFLAG) evdwl = expr*buckai[typej]-(edisptable[disp_k]+f_disp*dedisptable[disp_k])*buckci[typej]; } else { //special case register double f = special_lj[ni], t = rn*(1.0-f); force_buck = f*r*expr*buck1i[typej]-(fdisptable[disp_k]+f_disp*dfdisptable[disp_k])*buckci[typej]+t*buck2i[typej]-respa_buck; if (EFLAG) evdwl = f*expr*buckai[typej]-(edisptable[disp_k]+f_disp*dedisptable[disp_k])*buckci[typej]+t*buckci[typej]; } } } else { // cut form if (ni == 0) { force_buck = r*expr*buck1i[typej]-rn*buck2i[typej]-respa_buck; if (EFLAG) evdwl = expr*buckai[typej]-rn*buckci[typej]-offseti[typej]; } else { // correct for special register double f = special_lj[ni]; force_buck = f*(r*expr*buck1i[typej]-rn*buck2i[typej])-respa_buck; if (EFLAG) evdwl = f*(expr*buckai[typej]-rn*buckci[typej]-offseti[typej]); } } } else force_buck = respa_buck = evdwl = 0.0; fpair = (force_coul+force_buck)*r2inv; if (NEWTON_PAIR || j < nlocal) { register double *fj = f0+(j+(j<<1)), f; fi[0] += f = d[0]*fpair; fj[0] -= f; fi[1] += f = d[1]*fpair; fj[1] -= f; fi[2] += f = d[2]*fpair; fj[2] -= f; } else { fi[0] += d[0]*fpair; fi[1] += d[1]*fpair; fi[2] += d[2]*fpair; } if (EVFLAG) { fvirial = (force_coul + force_buck + respa_coul + respa_buck)*r2inv; ev_tally_thr(this,i,j,nlocal,NEWTON_PAIR, evdwl,ecoul,fvirial,d[0],d[1],d[2],thr); } } } } diff --git a/src/USER-OMP/pair_gran_hertz_history_omp.cpp b/src/USER-OMP/pair_gran_hertz_history_omp.cpp index ac40e29ed..046b71a73 100644 --- a/src/USER-OMP/pair_gran_hertz_history_omp.cpp +++ b/src/USER-OMP/pair_gran_hertz_history_omp.cpp @@ -1,330 +1,331 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- Contributing author: Axel Kohlmeyer (Temple U) ------------------------------------------------------------------------- */ #include #include "pair_gran_hertz_history_omp.h" +#include "fix_neigh_history.h" #include "atom.h" #include "comm.h" #include "fix.h" #include "force.h" #include "memory.h" #include "neighbor.h" #include "neigh_list.h" #include "update.h" #include "suffix.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ PairGranHertzHistoryOMP::PairGranHertzHistoryOMP(LAMMPS *lmp) : PairGranHertzHistory(lmp), ThrOMP(lmp, THR_PAIR) { suffix_flag |= Suffix::OMP; respa_enable = 0; } /* ---------------------------------------------------------------------- */ void PairGranHertzHistoryOMP::compute(int eflag, int vflag) { if (eflag || vflag) { ev_setup(eflag,vflag); } else evflag = vflag_fdotr = 0; const int nall = atom->nlocal + atom->nghost; const int nthreads = comm->nthreads; const int inum = list->inum; const int shearupdate = (update->setupflag) ? 0 : 1; // update rigid body info for owned & ghost atoms if using FixRigid masses // body[i] = which body atom I is in, -1 if none // mass_body = mass of each rigid body if (fix_rigid && neighbor->ago == 0) { int tmp; int *body = (int *) fix_rigid->extract("body",tmp); double *mass_body = (double *) fix_rigid->extract("masstotal",tmp); if (atom->nmax > nmax) { memory->destroy(mass_rigid); nmax = atom->nmax; memory->create(mass_rigid,nmax,"pair:mass_rigid"); } int nlocal = atom->nlocal; for (int i = 0; i < nlocal; i++) if (body[i] >= 0) mass_rigid[i] = mass_body[body[i]]; else mass_rigid[i] = 0.0; comm->forward_comm_pair(this); } #if defined(_OPENMP) #pragma omp parallel default(none) shared(eflag,vflag) #endif { int ifrom, ito, tid; loop_setup_thr(ifrom, ito, tid, inum, nthreads); ThrData *thr = fix->get_thr(tid); thr->timer(Timer::START); ev_setup_thr(eflag, vflag, nall, eatom, vatom, thr); if (evflag) { if (shearupdate) { if (force->newton_pair) eval<1,1,1>(ifrom, ito, thr); else eval<1,1,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1>(ifrom, ito, thr); else eval<1,0,0>(ifrom, ito, thr); } } else { if (shearupdate) { if (force->newton_pair) eval<0,1,1>(ifrom, ito, thr); else eval<0,1,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval<0,0,1>(ifrom, ito, thr); else eval<0,0,0>(ifrom, ito, thr); } } thr->timer(Timer::PAIR); reduce_thr(this, eflag, vflag, thr); } // end of omp parallel region } template void PairGranHertzHistoryOMP::eval(int iifrom, int iito, ThrData * const thr) { int i,j,ii,jj,jnum; double xtmp,ytmp,ztmp,delx,dely,delz,fx,fy,fz; double radi,radj,radsum,rsq,r,rinv,rsqinv; double vr1,vr2,vr3,vnnr,vn1,vn2,vn3,vt1,vt2,vt3; double wr1,wr2,wr3; double vtr1,vtr2,vtr3,vrel; double mi,mj,meff,damp,ccel,tor1,tor2,tor3; double fn,fs,fs1,fs2,fs3; double shrmag,rsht,polyhertz; int *ilist,*jlist,*numneigh,**firstneigh; int *touch,**firsttouch; double *shear,*allshear,**firstshear; const double * const * const x = atom->x; const double * const * const v = atom->v; const double * const * const omega = atom->omega; const double * const radius = atom->radius; const double * const rmass = atom->rmass; double * const * const f = thr->get_f(); double * const * const torque = thr->get_torque(); const int * const mask = atom->mask; const int nlocal = atom->nlocal; double fxtmp,fytmp,fztmp; double t1tmp,t2tmp,t3tmp; ilist = list->ilist; numneigh = list->numneigh; firstneigh = list->firstneigh; - firsttouch = list->listhistory->firstneigh; - firstshear = list->listhistory->firstdouble; + firsttouch = fix_history->firstflag; + firstshear = fix_history->firstvalue; // loop over neighbors of my atoms for (ii = iifrom; ii < iito; ++ii) { i = ilist[ii]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; radi = radius[i]; touch = firsttouch[i]; allshear = firstshear[i]; jlist = firstneigh[i]; jnum = numneigh[i]; fxtmp=fytmp=fztmp=t1tmp=t2tmp=t3tmp=0.0; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; radj = radius[j]; radsum = radi + radj; if (rsq >= radsum*radsum) { // unset non-touching neighbors touch[jj] = 0; shear = &allshear[3*jj]; shear[0] = 0.0; shear[1] = 0.0; shear[2] = 0.0; } else { r = sqrt(rsq); rinv = 1.0/r; rsqinv = 1.0/rsq; // relative translational velocity vr1 = v[i][0] - v[j][0]; vr2 = v[i][1] - v[j][1]; vr3 = v[i][2] - v[j][2]; // normal component vnnr = vr1*delx + vr2*dely + vr3*delz; vn1 = delx*vnnr * rsqinv; vn2 = dely*vnnr * rsqinv; vn3 = delz*vnnr * rsqinv; // tangential component vt1 = vr1 - vn1; vt2 = vr2 - vn2; vt3 = vr3 - vn3; // relative rotational velocity wr1 = (radi*omega[i][0] + radj*omega[j][0]) * rinv; wr2 = (radi*omega[i][1] + radj*omega[j][1]) * rinv; wr3 = (radi*omega[i][2] + radj*omega[j][2]) * rinv; // meff = effective mass of pair of particles // if I or J part of rigid body, use body mass // if I or J is frozen, meff is other particle mi = rmass[i]; mj = rmass[j]; if (fix_rigid) { if (mass_rigid[i] > 0.0) mi = mass_rigid[i]; if (mass_rigid[j] > 0.0) mj = mass_rigid[j]; } meff = mi*mj / (mi+mj); if (mask[i] & freeze_group_bit) meff = mj; if (mask[j] & freeze_group_bit) meff = mi; // normal force = Hertzian contact + normal velocity damping damp = meff*gamman*vnnr*rsqinv; ccel = kn*(radsum-r)*rinv - damp; polyhertz = sqrt((radsum-r)*radi*radj / radsum); ccel *= polyhertz; // relative velocities vtr1 = vt1 - (delz*wr2-dely*wr3); vtr2 = vt2 - (delx*wr3-delz*wr1); vtr3 = vt3 - (dely*wr1-delx*wr2); vrel = vtr1*vtr1 + vtr2*vtr2 + vtr3*vtr3; vrel = sqrt(vrel); // shear history effects touch[jj] = 1; shear = &allshear[3*jj]; if (SHEARUPDATE) { shear[0] += vtr1*dt; shear[1] += vtr2*dt; shear[2] += vtr3*dt; } shrmag = sqrt(shear[0]*shear[0] + shear[1]*shear[1] + shear[2]*shear[2]); // rotate shear displacements rsht = shear[0]*delx + shear[1]*dely + shear[2]*delz; rsht *= rsqinv; if (SHEARUPDATE) { shear[0] -= rsht*delx; shear[1] -= rsht*dely; shear[2] -= rsht*delz; } // tangential forces = shear + tangential velocity damping fs1 = -polyhertz * (kt*shear[0] + meff*gammat*vtr1); fs2 = -polyhertz * (kt*shear[1] + meff*gammat*vtr2); fs3 = -polyhertz * (kt*shear[2] + meff*gammat*vtr3); // rescale frictional displacements and forces if needed fs = sqrt(fs1*fs1 + fs2*fs2 + fs3*fs3); fn = xmu * fabs(ccel*r); if (fs > fn) { if (shrmag != 0.0) { const double fnfs = fn/fs; const double mgkt = meff*gammat/kt; shear[0] = fnfs * (shear[0] + mgkt*vtr1) - mgkt*vtr1; shear[1] = fnfs * (shear[1] + mgkt*vtr2) - mgkt*vtr2; shear[2] = fnfs * (shear[2] + mgkt*vtr3) - mgkt*vtr3; fs1 *= fnfs; fs2 *= fnfs; fs3 *= fnfs; } else fs1 = fs2 = fs3 = 0.0; } // forces & torques fx = delx*ccel + fs1; fy = dely*ccel + fs2; fz = delz*ccel + fs3; fxtmp += fx; fytmp += fy; fztmp += fz; tor1 = rinv * (dely*fs3 - delz*fs2); tor2 = rinv * (delz*fs1 - delx*fs3); tor3 = rinv * (delx*fs2 - dely*fs1); t1tmp -= radi*tor1; t2tmp -= radi*tor2; t3tmp -= radi*tor3; if (NEWTON_PAIR || j < nlocal) { f[j][0] -= fx; f[j][1] -= fy; f[j][2] -= fz; torque[j][0] -= radj*tor1; torque[j][1] -= radj*tor2; torque[j][2] -= radj*tor3; } if (EVFLAG) ev_tally_xyz_thr(this,i,j,nlocal,NEWTON_PAIR, 0.0,0.0,fx,fy,fz,delx,dely,delz,thr); } } f[i][0] += fxtmp; f[i][1] += fytmp; f[i][2] += fztmp; torque[i][0] += t1tmp; torque[i][1] += t2tmp; torque[i][2] += t3tmp; } } /* ---------------------------------------------------------------------- */ double PairGranHertzHistoryOMP::memory_usage() { double bytes = memory_usage_thr(); bytes += PairGranHertzHistory::memory_usage(); return bytes; } diff --git a/src/USER-OMP/pair_gran_hooke_history_omp.cpp b/src/USER-OMP/pair_gran_hooke_history_omp.cpp index e507a63f7..2e7d55aff 100644 --- a/src/USER-OMP/pair_gran_hooke_history_omp.cpp +++ b/src/USER-OMP/pair_gran_hooke_history_omp.cpp @@ -1,331 +1,332 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- Contributing author: Axel Kohlmeyer (Temple U) ------------------------------------------------------------------------- */ #include #include "pair_gran_hooke_history_omp.h" +#include "fix_neigh_history.h" #include "atom.h" #include "comm.h" #include "fix.h" #include "force.h" #include "memory.h" #include "neighbor.h" #include "neigh_list.h" #include "update.h" #include #include "suffix.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ PairGranHookeHistoryOMP::PairGranHookeHistoryOMP(LAMMPS *lmp) : PairGranHookeHistory(lmp), ThrOMP(lmp, THR_PAIR) { suffix_flag |= Suffix::OMP; respa_enable = 0; } /* ---------------------------------------------------------------------- */ void PairGranHookeHistoryOMP::compute(int eflag, int vflag) { if (eflag || vflag) { ev_setup(eflag,vflag); } else evflag = vflag_fdotr = 0; const int shearupdate = (update->setupflag) ? 0 : 1; // update rigid body info for owned & ghost atoms if using FixRigid masses // body[i] = which body atom I is in, -1 if none // mass_body = mass of each rigid body if (fix_rigid && neighbor->ago == 0) { int tmp; int *body = (int *) fix_rigid->extract("body",tmp); double *mass_body = (double *) fix_rigid->extract("masstotal",tmp); if (atom->nmax > nmax) { memory->destroy(mass_rigid); nmax = atom->nmax; memory->create(mass_rigid,nmax,"pair:mass_rigid"); } int nlocal = atom->nlocal; for (int i = 0; i < nlocal; i++) if (body[i] >= 0) mass_rigid[i] = mass_body[body[i]]; else mass_rigid[i] = 0.0; comm->forward_comm_pair(this); } const int nall = atom->nlocal + atom->nghost; const int nthreads = comm->nthreads; const int inum = list->inum; #if defined(_OPENMP) #pragma omp parallel default(none) shared(eflag,vflag) #endif { int ifrom, ito, tid; loop_setup_thr(ifrom, ito, tid, inum, nthreads); ThrData *thr = fix->get_thr(tid); thr->timer(Timer::START); ev_setup_thr(eflag, vflag, nall, eatom, vatom, thr); if (evflag) { if (shearupdate) { if (force->newton_pair) eval<1,1,1>(ifrom, ito, thr); else eval<1,1,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1>(ifrom, ito, thr); else eval<1,0,0>(ifrom, ito, thr); } } else { if (shearupdate) { if (force->newton_pair) eval<0,1,1>(ifrom, ito, thr); else eval<0,1,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval<0,0,1>(ifrom, ito, thr); else eval<0,0,0>(ifrom, ito, thr); } } thr->timer(Timer::PAIR); reduce_thr(this, eflag, vflag, thr); } // end of omp parallel region } template void PairGranHookeHistoryOMP::eval(int iifrom, int iito, ThrData * const thr) { int i,j,ii,jj,jnum; double xtmp,ytmp,ztmp,delx,dely,delz,fx,fy,fz; double myshear[3]; double radi,radj,radsum,rsq,r,rinv,rsqinv; double vr1,vr2,vr3,vnnr,vn1,vn2,vn3,vt1,vt2,vt3; double wr1,wr2,wr3; double vtr1,vtr2,vtr3,vrel; double mi,mj,meff,damp,ccel,tor1,tor2,tor3; double fn,fs,fs1,fs2,fs3; double shrmag,rsht; int *ilist,*jlist,*numneigh,**firstneigh; int *touch,**firsttouch; double *allshear,**firstshear; const double * const * const x = atom->x; const double * const * const v = atom->v; const double * const * const omega = atom->omega; const double * const radius = atom->radius; const double * const rmass = atom->rmass; double * const * const f = thr->get_f(); double * const * const torque = thr->get_torque(); const int * const mask = atom->mask; const int nlocal = atom->nlocal; double fxtmp,fytmp,fztmp; double t1tmp,t2tmp,t3tmp; ilist = list->ilist; numneigh = list->numneigh; firstneigh = list->firstneigh; - firsttouch = listhistory->firstneigh; - firstshear = listhistory->firstdouble; + firsttouch = fix_history->firstflag; + firstshear = fix_history->firstvalue; // loop over neighbors of my atoms for (ii = iifrom; ii < iito; ++ii) { i = ilist[ii]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; radi = radius[i]; touch = firsttouch[i]; allshear = firstshear[i]; jlist = firstneigh[i]; jnum = numneigh[i]; fxtmp=fytmp=fztmp=t1tmp=t2tmp=t3tmp=0.0; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; radj = radius[j]; radsum = radi + radj; if (rsq >= radsum*radsum) { // unset non-touching neighbors touch[jj] = 0; myshear[0] = 0.0; myshear[1] = 0.0; myshear[2] = 0.0; } else { r = sqrt(rsq); rinv = 1.0/r; rsqinv = 1.0/rsq; // relative translational velocity vr1 = v[i][0] - v[j][0]; vr2 = v[i][1] - v[j][1]; vr3 = v[i][2] - v[j][2]; // normal component vnnr = vr1*delx + vr2*dely + vr3*delz; vn1 = delx*vnnr * rsqinv; vn2 = dely*vnnr * rsqinv; vn3 = delz*vnnr * rsqinv; // tangential component vt1 = vr1 - vn1; vt2 = vr2 - vn2; vt3 = vr3 - vn3; // relative rotational velocity wr1 = (radi*omega[i][0] + radj*omega[j][0]) * rinv; wr2 = (radi*omega[i][1] + radj*omega[j][1]) * rinv; wr3 = (radi*omega[i][2] + radj*omega[j][2]) * rinv; // meff = effective mass of pair of particles // if I or J part of rigid body, use body mass // if I or J is frozen, meff is other particle mi = rmass[i]; mj = rmass[j]; if (fix_rigid) { if (mass_rigid[i] > 0.0) mi = mass_rigid[i]; if (mass_rigid[j] > 0.0) mj = mass_rigid[j]; } meff = mi*mj / (mi+mj); if (mask[i] & freeze_group_bit) meff = mj; if (mask[j] & freeze_group_bit) meff = mi; // normal forces = Hookian contact + normal velocity damping damp = meff*gamman*vnnr*rsqinv; ccel = kn*(radsum-r)*rinv - damp; // relative velocities vtr1 = vt1 - (delz*wr2-dely*wr3); vtr2 = vt2 - (delx*wr3-delz*wr1); vtr3 = vt3 - (dely*wr1-delx*wr2); vrel = vtr1*vtr1 + vtr2*vtr2 + vtr3*vtr3; vrel = sqrt(vrel); // shear history effects touch[jj] = 1; memcpy(myshear,allshear + 3*jj, 3*sizeof(double)); if (SHEARUPDATE) { myshear[0] += vtr1*dt; myshear[1] += vtr2*dt; myshear[2] += vtr3*dt; } shrmag = sqrt(myshear[0]*myshear[0] + myshear[1]*myshear[1] + myshear[2]*myshear[2]); // rotate shear displacements rsht = myshear[0]*delx + myshear[1]*dely + myshear[2]*delz; rsht *= rsqinv; if (SHEARUPDATE) { myshear[0] -= rsht*delx; myshear[1] -= rsht*dely; myshear[2] -= rsht*delz; } // tangential forces = shear + tangential velocity damping fs1 = - (kt*myshear[0] + meff*gammat*vtr1); fs2 = - (kt*myshear[1] + meff*gammat*vtr2); fs3 = - (kt*myshear[2] + meff*gammat*vtr3); // rescale frictional displacements and forces if needed fs = sqrt(fs1*fs1 + fs2*fs2 + fs3*fs3); fn = xmu * fabs(ccel*r); if (fs > fn) { if (shrmag != 0.0) { const double fnfs = fn/fs; const double mgkt = meff*gammat/kt; myshear[0] = fnfs * (myshear[0] + mgkt*vtr1) - mgkt*vtr1; myshear[1] = fnfs * (myshear[1] + mgkt*vtr2) - mgkt*vtr2; myshear[2] = fnfs * (myshear[2] + mgkt*vtr3) - mgkt*vtr3; fs1 *= fnfs; fs2 *= fnfs; fs3 *= fnfs; } else fs1 = fs2 = fs3 = 0.0; } // forces & torques fx = delx*ccel + fs1; fy = dely*ccel + fs2; fz = delz*ccel + fs3; fxtmp += fx; fytmp += fy; fztmp += fz; tor1 = rinv * (dely*fs3 - delz*fs2); tor2 = rinv * (delz*fs1 - delx*fs3); tor3 = rinv * (delx*fs2 - dely*fs1); t1tmp -= radi*tor1; t2tmp -= radi*tor2; t3tmp -= radi*tor3; if (NEWTON_PAIR || j < nlocal) { f[j][0] -= fx; f[j][1] -= fy; f[j][2] -= fz; torque[j][0] -= radj*tor1; torque[j][1] -= radj*tor2; torque[j][2] -= radj*tor3; } if (EVFLAG) ev_tally_xyz_thr(this,i,j,nlocal,NEWTON_PAIR, 0.0,0.0,fx,fy,fz,delx,dely,delz,thr); } memcpy(allshear + 3*jj, myshear, 3*sizeof(double)); } f[i][0] += fxtmp; f[i][1] += fytmp; f[i][2] += fztmp; torque[i][0] += t1tmp; torque[i][1] += t2tmp; torque[i][2] += t3tmp; } } /* ---------------------------------------------------------------------- */ double PairGranHookeHistoryOMP::memory_usage() { double bytes = memory_usage_thr(); bytes += PairGranHookeHistory::memory_usage(); return bytes; } diff --git a/src/USER-OMP/pair_lj_long_coul_long_omp.cpp b/src/USER-OMP/pair_lj_long_coul_long_omp.cpp index 28d4f229c..c0c87e748 100644 --- a/src/USER-OMP/pair_lj_long_coul_long_omp.cpp +++ b/src/USER-OMP/pair_lj_long_coul_long_omp.cpp @@ -1,1182 +1,1182 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- Contributing author: Axel Kohlmeyer (Temple U) ------------------------------------------------------------------------- */ #include #include "pair_lj_long_coul_long_omp.h" #include "atom.h" #include "comm.h" #include "math_vector.h" #include "force.h" #include "neighbor.h" #include "neigh_list.h" #include "suffix.h" using namespace LAMMPS_NS; #define EWALD_F 1.12837917 #define EWALD_P 0.3275911 #define A1 0.254829592 #define A2 -0.284496736 #define A3 1.421413741 #define A4 -1.453152027 #define A5 1.061405429 /* ---------------------------------------------------------------------- */ PairLJLongCoulLongOMP::PairLJLongCoulLongOMP(LAMMPS *lmp) : PairLJLongCoulLong(lmp), ThrOMP(lmp, THR_PAIR) { suffix_flag |= Suffix::OMP; respa_enable = 1; cut_respa = NULL; } /* ---------------------------------------------------------------------- */ void PairLJLongCoulLongOMP::compute(int eflag, int vflag) { if (eflag || vflag) { ev_setup(eflag,vflag); } else evflag = vflag_fdotr = 0; const int order1 = ewald_order&(1<<1); const int order6 = ewald_order&(1<<6); const int nall = atom->nlocal + atom->nghost; const int nthreads = comm->nthreads; const int inum = list->inum; #if defined(_OPENMP) #pragma omp parallel default(none) shared(eflag,vflag) #endif { int ifrom, ito, tid; loop_setup_thr(ifrom, ito, tid, inum, nthreads); ThrData *thr = fix->get_thr(tid); thr->timer(Timer::START); ev_setup_thr(eflag, vflag, nall, eatom, vatom, thr); if (order6) { if (order1) { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,0,0,1,1>(ifrom, ito, thr); else eval<1,1,0,0,0,1,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,0,0,1,1>(ifrom, ito, thr); else eval<1,0,0,0,0,1,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,0,0,1,1>(ifrom, ito, thr); else eval<0,0,0,0,0,1,1>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,1,0,1,1>(ifrom, ito, thr); else eval<1,1,0,1,0,1,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,1,0,1,1>(ifrom, ito, thr); else eval<1,0,0,1,0,1,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,1,0,1,1>(ifrom, ito, thr); else eval<0,0,0,1,0,1,1>(ifrom, ito, thr); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,0,1,1,1>(ifrom, ito, thr); else eval<1,1,0,0,1,1,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,0,1,1,1>(ifrom, ito, thr); else eval<1,0,0,0,1,1,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,0,1,1,1>(ifrom, ito, thr); else eval<0,0,0,0,1,1,1>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,1,1,1,1>(ifrom, ito, thr); else eval<1,1,0,1,1,1,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,1,1,1,1>(ifrom, ito, thr); else eval<1,0,0,1,1,1,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,1,1,1,1>(ifrom, ito, thr); else eval<0,0,0,1,1,1,1>(ifrom, ito, thr); } } } } else { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,0,0,0,1>(ifrom, ito, thr); else eval<1,1,0,0,0,0,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,0,0,0,1>(ifrom, ito, thr); else eval<1,0,0,0,0,0,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,0,0,0,1>(ifrom, ito, thr); else eval<0,0,0,0,0,0,1>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,1,0,0,1>(ifrom, ito, thr); else eval<1,1,0,1,0,0,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,1,0,0,1>(ifrom, ito, thr); else eval<1,0,0,1,0,0,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,1,0,0,1>(ifrom, ito, thr); else eval<0,0,0,1,0,0,1>(ifrom, ito, thr); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,0,1,0,1>(ifrom, ito, thr); else eval<1,1,0,0,1,0,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,0,1,0,1>(ifrom, ito, thr); else eval<1,0,0,0,1,0,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,0,1,0,1>(ifrom, ito, thr); else eval<0,0,0,0,1,0,1>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,1,1,0,1>(ifrom, ito, thr); else eval<1,1,0,1,1,0,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,1,1,0,1>(ifrom, ito, thr); else eval<1,0,0,1,1,0,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,1,1,0,1>(ifrom, ito, thr); else eval<0,0,0,1,1,0,1>(ifrom, ito, thr); } } } } } else { if (order1) { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,0,0,1,0>(ifrom, ito, thr); else eval<1,1,0,0,0,1,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,0,0,1,0>(ifrom, ito, thr); else eval<1,0,0,0,0,1,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,0,0,1,0>(ifrom, ito, thr); else eval<0,0,0,0,0,1,0>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,1,0,1,0>(ifrom, ito, thr); else eval<1,1,0,1,0,1,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,1,0,1,0>(ifrom, ito, thr); else eval<1,0,0,1,0,1,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,1,0,1,0>(ifrom, ito, thr); else eval<0,0,0,1,0,1,0>(ifrom, ito, thr); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,0,1,1,0>(ifrom, ito, thr); else eval<1,1,0,0,1,1,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,0,1,1,0>(ifrom, ito, thr); else eval<1,0,0,0,1,1,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,0,1,1,0>(ifrom, ito, thr); else eval<0,0,0,0,1,1,0>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,1,1,1,0>(ifrom, ito, thr); else eval<1,1,0,1,1,1,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,1,1,1,0>(ifrom, ito, thr); else eval<1,0,0,1,1,1,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,1,1,1,0>(ifrom, ito, thr); else eval<0,0,0,1,1,1,0>(ifrom, ito, thr); } } } } else { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,0,0,0,0>(ifrom, ito, thr); else eval<1,1,0,0,0,0,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,0,0,0,0>(ifrom, ito, thr); else eval<1,0,0,0,0,0,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,0,0,0,0>(ifrom, ito, thr); else eval<0,0,0,0,0,0,0>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,1,0,0,0>(ifrom, ito, thr); else eval<1,1,0,1,0,0,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,1,0,0,0>(ifrom, ito, thr); else eval<1,0,0,1,0,0,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,1,0,0,0>(ifrom, ito, thr); else eval<0,0,0,1,0,0,0>(ifrom, ito, thr); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,0,1,0,0>(ifrom, ito, thr); else eval<1,1,0,0,1,0,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,0,1,0,0>(ifrom, ito, thr); else eval<1,0,0,0,1,0,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,0,1,0,0>(ifrom, ito, thr); else eval<0,0,0,0,1,0,0>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,1,1,0,0>(ifrom, ito, thr); else eval<1,1,0,1,1,0,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,1,1,0,0>(ifrom, ito, thr); else eval<1,0,0,1,1,0,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,1,1,0,0>(ifrom, ito, thr); else eval<0,0,0,1,1,0,0>(ifrom, ito, thr); } } } } } thr->timer(Timer::PAIR); reduce_thr(this, eflag, vflag, thr); } // end of omp parallel region } /* ---------------------------------------------------------------------- */ void PairLJLongCoulLongOMP::compute_inner() { const int nall = atom->nlocal + atom->nghost; const int nthreads = comm->nthreads; - const int inum = listinner->inum; + const int inum = list->inum_inner; #if defined(_OPENMP) #pragma omp parallel default(none) #endif { int ifrom, ito, tid; loop_setup_thr(ifrom, ito, tid, inum, nthreads); ThrData *thr = fix->get_thr(tid); thr->timer(Timer::START); ev_setup_thr(0, 0, nall, 0, 0, thr); eval_inner(ifrom, ito, thr); thr->timer(Timer::PAIR); } // end of omp parallel region } /* ---------------------------------------------------------------------- */ void PairLJLongCoulLongOMP::compute_middle() { const int nall = atom->nlocal + atom->nghost; const int nthreads = comm->nthreads; - const int inum = listmiddle->inum; + const int inum = list->inum_middle; #if defined(_OPENMP) #pragma omp parallel default(none) #endif { int ifrom, ito, tid; loop_setup_thr(ifrom, ito, tid, inum, nthreads); ThrData *thr = fix->get_thr(tid); thr->timer(Timer::START); ev_setup_thr(0, 0, nall, 0, 0, thr); eval_middle(ifrom, ito, thr); thr->timer(Timer::PAIR); } // end of omp parallel region } /* ---------------------------------------------------------------------- */ void PairLJLongCoulLongOMP::compute_outer(int eflag, int vflag) { if (eflag || vflag) { ev_setup(eflag,vflag); } else evflag = vflag_fdotr = 0; const int order1 = ewald_order&(1<<1); const int order6 = ewald_order&(1<<6); const int nall = atom->nlocal + atom->nghost; const int nthreads = comm->nthreads; - const int inum = listouter->inum; + const int inum = list->inum; #if defined(_OPENMP) #pragma omp parallel default(none) shared(eflag,vflag) #endif { int ifrom, ito, tid; loop_setup_thr(ifrom, ito, tid, inum, nthreads); ThrData *thr = fix->get_thr(tid); thr->timer(Timer::START); ev_setup_thr(eflag, vflag, nall, eatom, vatom, thr); if (order6) { if (order1) { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,0,0,1,1>(ifrom, ito, thr); else eval_outer<1,1,0,0,0,1,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,0,0,1,1>(ifrom, ito, thr); else eval_outer<1,0,0,0,0,1,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,0,0,1,1>(ifrom, ito, thr); else eval_outer<0,0,0,0,0,1,1>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,1,0,1,1>(ifrom, ito, thr); else eval_outer<1,1,0,1,0,1,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,1,0,1,1>(ifrom, ito, thr); else eval_outer<1,0,0,1,0,1,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,1,0,1,1>(ifrom, ito, thr); else eval_outer<0,0,0,1,0,1,1>(ifrom, ito, thr); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,0,1,1,1>(ifrom, ito, thr); else eval_outer<1,1,0,0,1,1,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,0,1,1,1>(ifrom, ito, thr); else eval_outer<1,0,0,0,1,1,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,0,1,1,1>(ifrom, ito, thr); else eval_outer<0,0,0,0,1,1,1>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,1,1,1,1>(ifrom, ito, thr); else eval_outer<1,1,0,1,1,1,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,1,1,1,1>(ifrom, ito, thr); else eval_outer<1,0,0,1,1,1,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,1,1,1,1>(ifrom, ito, thr); else eval_outer<0,0,0,1,1,1,1>(ifrom, ito, thr); } } } } else { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,0,0,0,1>(ifrom, ito, thr); else eval_outer<1,1,0,0,0,0,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,0,0,0,1>(ifrom, ito, thr); else eval_outer<1,0,0,0,0,0,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,0,0,0,1>(ifrom, ito, thr); else eval_outer<0,0,0,0,0,0,1>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,1,0,0,1>(ifrom, ito, thr); else eval_outer<1,1,0,1,0,0,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,1,0,0,1>(ifrom, ito, thr); else eval_outer<1,0,0,1,0,0,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,1,0,0,1>(ifrom, ito, thr); else eval_outer<0,0,0,1,0,0,1>(ifrom, ito, thr); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,0,1,0,1>(ifrom, ito, thr); else eval_outer<1,1,0,0,1,0,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,0,1,0,1>(ifrom, ito, thr); else eval_outer<1,0,0,0,1,0,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,0,1,0,1>(ifrom, ito, thr); else eval_outer<0,0,0,0,1,0,1>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,1,1,0,1>(ifrom, ito, thr); else eval_outer<1,1,0,1,1,0,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,1,1,0,1>(ifrom, ito, thr); else eval_outer<1,0,0,1,1,0,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,1,1,0,1>(ifrom, ito, thr); else eval_outer<0,0,0,1,1,0,1>(ifrom, ito, thr); } } } } } else { if (order1) { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,0,0,1,0>(ifrom, ito, thr); else eval_outer<1,1,0,0,0,1,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,0,0,1,0>(ifrom, ito, thr); else eval_outer<1,0,0,0,0,1,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,0,0,1,0>(ifrom, ito, thr); else eval_outer<0,0,0,0,0,1,0>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,1,0,1,0>(ifrom, ito, thr); else eval_outer<1,1,0,1,0,1,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,1,0,1,0>(ifrom, ito, thr); else eval_outer<1,0,0,1,0,1,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,1,0,1,0>(ifrom, ito, thr); else eval_outer<0,0,0,1,0,1,0>(ifrom, ito, thr); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,0,1,1,0>(ifrom, ito, thr); else eval_outer<1,1,0,0,1,1,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,0,1,1,0>(ifrom, ito, thr); else eval_outer<1,0,0,0,1,1,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,0,1,1,0>(ifrom, ito, thr); else eval_outer<0,0,0,0,1,1,0>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,1,1,1,0>(ifrom, ito, thr); else eval_outer<1,1,0,1,1,1,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,1,1,1,0>(ifrom, ito, thr); else eval_outer<1,0,0,1,1,1,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,1,1,1,0>(ifrom, ito, thr); else eval_outer<0,0,0,1,1,1,0>(ifrom, ito, thr); } } } } else { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,0,0,0,0>(ifrom, ito, thr); else eval_outer<1,1,0,0,0,0,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,0,0,0,0>(ifrom, ito, thr); else eval_outer<1,0,0,0,0,0,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,0,0,0,0>(ifrom, ito, thr); else eval_outer<0,0,0,0,0,0,0>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,1,0,0,0>(ifrom, ito, thr); else eval_outer<1,1,0,1,0,0,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,1,0,0,0>(ifrom, ito, thr); else eval_outer<1,0,0,1,0,0,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,1,0,0,0>(ifrom, ito, thr); else eval_outer<0,0,0,1,0,0,0>(ifrom, ito, thr); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,0,1,0,0>(ifrom, ito, thr); else eval_outer<1,1,0,0,1,0,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,0,1,0,0>(ifrom, ito, thr); else eval_outer<1,0,0,0,1,0,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,0,1,0,0>(ifrom, ito, thr); else eval_outer<0,0,0,0,1,0,0>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,1,1,0,0>(ifrom, ito, thr); else eval_outer<1,1,0,1,1,0,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,1,1,0,0>(ifrom, ito, thr); else eval_outer<1,0,0,1,1,0,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,1,1,0,0>(ifrom, ito, thr); else eval_outer<0,0,0,1,1,0,0>(ifrom, ito, thr); } } } } } thr->timer(Timer::PAIR); reduce_thr(this, eflag, vflag, thr); } // end of omp parallel region } /* ---------------------------------------------------------------------- */ template < const int EVFLAG, const int EFLAG, const int NEWTON_PAIR, const int CTABLE, const int LJTABLE, const int ORDER1, const int ORDER6 > void PairLJLongCoulLongOMP::eval(int iifrom, int iito, ThrData * const thr) { double evdwl,ecoul,fpair; evdwl = ecoul = 0.0; const double * const * const x = atom->x; double * const * const f = thr->get_f(); const double * const q = atom->q; const int * const type = atom->type; const int nlocal = atom->nlocal; const double * const special_coul = force->special_coul; const double * const special_lj = force->special_lj; const double qqrd2e = force->qqrd2e; const double *x0 = x[0]; double *f0 = f[0], *fi = f0; int *ilist = list->ilist; // loop over neighbors of my atoms int i, ii, j; int *jneigh, *jneighn, typei, typej, ni; double qi, qri, *cutsqi, *cut_ljsqi, *lj1i, *lj2i, *lj3i, *lj4i, *offseti; double rsq, r2inv, force_coul, force_lj; double g2 = g_ewald_6*g_ewald_6, g6 = g2*g2*g2, g8 = g6*g2; vector xi, d; for (ii = iifrom; ii < iito; ++ii) { // loop over my atoms i = ilist[ii]; fi = f0+3*i; if (ORDER1) qri = (qi = q[i])*qqrd2e; // initialize constants offseti = offset[typei = type[i]]; lj1i = lj1[typei]; lj2i = lj2[typei]; lj3i = lj3[typei]; lj4i = lj4[typei]; cutsqi = cutsq[typei]; cut_ljsqi = cut_ljsq[typei]; memcpy(xi, x0+(i+(i<<1)), sizeof(vector)); jneighn = (jneigh = list->firstneigh[i])+list->numneigh[i]; for (; jneigh= cutsqi[typej = type[j]]) continue; r2inv = 1.0/rsq; if (ORDER1 && (rsq < cut_coulsq)) { // coulombic if (!CTABLE || rsq <= tabinnersq) { // series real space register double r = sqrt(rsq), x = g_ewald*r; register double s = qri*q[j], t = 1.0/(1.0+EWALD_P*x); if (ni == 0) { s *= g_ewald*exp(-x*x); force_coul = (t *= ((((t*A5+A4)*t+A3)*t+A2)*t+A1)*s/x)+EWALD_F*s; if (EFLAG) ecoul = t; } else { // special case r = s*(1.0-special_coul[ni])/r; s *= g_ewald*exp(-x*x); force_coul = (t *= ((((t*A5+A4)*t+A3)*t+A2)*t+A1)*s/x)+EWALD_F*s-r; if (EFLAG) ecoul = t-r; } } // table real space else { register union_int_float_t t; t.f = rsq; register const int k = (t.i & ncoulmask)>>ncoulshiftbits; register double f = (rsq-rtable[k])*drtable[k], qiqj = qi*q[j]; if (ni == 0) { force_coul = qiqj*(ftable[k]+f*dftable[k]); if (EFLAG) ecoul = qiqj*(etable[k]+f*detable[k]); } else { // special case t.f = (1.0-special_coul[ni])*(ctable[k]+f*dctable[k]); force_coul = qiqj*(ftable[k]+f*dftable[k]-t.f); if (EFLAG) ecoul = qiqj*(etable[k]+f*detable[k]-t.f); } } } else force_coul = ecoul = 0.0; if (rsq < cut_ljsqi[typej]) { // lj if (ORDER6) { // long-range lj if(!LJTABLE || rsq <= tabinnerdispsq) { //series real space register double rn = r2inv*r2inv*r2inv; register double x2 = g2*rsq, a2 = 1.0/x2; x2 = a2*exp(-x2)*lj4i[typej]; if (ni == 0) { force_lj = (rn*=rn)*lj1i[typej]-g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq; if (EFLAG) evdwl = rn*lj3i[typej]-g6*((a2+1.0)*a2+0.5)*x2; } else { // special case register double f = special_lj[ni], t = rn*(1.0-f); force_lj = f*(rn *= rn)*lj1i[typej]- g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq+t*lj2i[typej]; if (EFLAG) evdwl = f*rn*lj3i[typej]-g6*((a2+1.0)*a2+0.5)*x2+t*lj4i[typej]; } } else { // table real space register union_int_float_t disp_t; disp_t.f = rsq; register const int disp_k = (disp_t.i & ndispmask)>>ndispshiftbits; register double f_disp = (rsq-rdisptable[disp_k])*drdisptable[disp_k]; register double rn = r2inv*r2inv*r2inv; if (ni == 0) { force_lj = (rn*=rn)*lj1i[typej]-(fdisptable[disp_k]+f_disp*dfdisptable[disp_k])*lj4i[typej]; if (EFLAG) evdwl = rn*lj3i[typej]-(edisptable[disp_k]+f_disp*dedisptable[disp_k])*lj4i[typej]; } else { // special case register double f = special_lj[ni], t = rn*(1.0-f); force_lj = f*(rn *= rn)*lj1i[typej]-(fdisptable[disp_k]+f_disp*dfdisptable[disp_k])*lj4i[typej]+t*lj2i[typej]; if (EFLAG) evdwl = f*rn*lj3i[typej]-(edisptable[disp_k]+f_disp*dedisptable[disp_k])*lj4i[typej]+t*lj4i[typej]; } } } else { // cut lj register double rn = r2inv*r2inv*r2inv; if (ni == 0) { force_lj = rn*(rn*lj1i[typej]-lj2i[typej]); if (EFLAG) evdwl = rn*(rn*lj3i[typej]-lj4i[typej])-offseti[typej]; } else { // special case register double f = special_lj[ni]; force_lj = f*rn*(rn*lj1i[typej]-lj2i[typej]); if (EFLAG) evdwl = f * (rn*(rn*lj3i[typej]-lj4i[typej])-offseti[typej]); } } } else force_lj = evdwl = 0.0; fpair = (force_coul+force_lj)*r2inv; if (NEWTON_PAIR || j < nlocal) { register double *fj = f0+(j+(j<<1)), f; fi[0] += f = d[0]*fpair; fj[0] -= f; fi[1] += f = d[1]*fpair; fj[1] -= f; fi[2] += f = d[2]*fpair; fj[2] -= f; } else { fi[0] += d[0]*fpair; fi[1] += d[1]*fpair; fi[2] += d[2]*fpair; } if (EVFLAG) ev_tally_thr(this,i,j,nlocal,NEWTON_PAIR, evdwl,ecoul,fpair,d[0],d[1],d[2],thr); } } } /* ---------------------------------------------------------------------- */ void PairLJLongCoulLongOMP::eval_inner(int iifrom, int iito, ThrData * const thr) { double rsq, r2inv, force_coul = 0.0, force_lj, fpair; const double * const * const x = atom->x; double * const * const f = thr->get_f(); const double * const q = atom->q; const int * const type = atom->type; const int nlocal = atom->nlocal; const double * const special_coul = force->special_coul; const double * const special_lj = force->special_lj; const double qqrd2e = force->qqrd2e; const double *x0 = x[0]; double *f0 = f[0], *fi = 0; - int *ilist = listinner->ilist; + int *ilist = list->ilist_inner; const int newton_pair = force->newton_pair; const double cut_out_on = cut_respa[0]; const double cut_out_off = cut_respa[1]; const double cut_out_diff = cut_out_off - cut_out_on; const double cut_out_on_sq = cut_out_on*cut_out_on; const double cut_out_off_sq = cut_out_off*cut_out_off; int *jneigh, *jneighn, typei, typej, ni; const int order1 = (ewald_order|(ewald_off^-1))&(1<<1); int i, j, ii; double qri, *cut_ljsqi, *lj1i, *lj2i; vector xi, d; for (ii = iifrom; ii < iito; ++ii) { // loop over my atoms i = ilist[ii]; fi = f0+3*i; memcpy(xi, x0+(i+(i<<1)), sizeof(vector)); cut_ljsqi = cut_ljsq[typei = type[i]]; lj1i = lj1[typei]; lj2i = lj2[typei]; - jneighn = (jneigh = listinner->firstneigh[i])+listinner->numneigh[i]; + jneighn = (jneigh = list->firstneigh_inner[i])+list->numneigh_inner[i]; for (; jneigh= cut_out_off_sq) continue; r2inv = 1.0/rsq; if (order1 && (rsq < cut_coulsq)) { // coulombic qri = qqrd2e*q[i]; force_coul = ni == 0 ? qri*q[j]*sqrt(r2inv) : qri*q[j]*sqrt(r2inv)*special_coul[ni]; } if (rsq < cut_ljsqi[typej = type[j]]) { // lennard-jones register double rn = r2inv*r2inv*r2inv; force_lj = ni == 0 ? rn*(rn*lj1i[typej]-lj2i[typej]) : rn*(rn*lj1i[typej]-lj2i[typej])*special_lj[ni]; } else force_lj = 0.0; fpair = (force_coul + force_lj) * r2inv; if (rsq > cut_out_on_sq) { // switching register double rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; fpair *= 1.0 + rsw*rsw*(2.0*rsw-3.0); } if (newton_pair || j < nlocal) { // force update register double *fj = f0+(j+(j<<1)), f; fi[0] += f = d[0]*fpair; fj[0] -= f; fi[1] += f = d[1]*fpair; fj[1] -= f; fi[2] += f = d[2]*fpair; fj[2] -= f; } else { fi[0] += d[0]*fpair; fi[1] += d[1]*fpair; fi[2] += d[2]*fpair; } } } } /* ---------------------------------------------------------------------- */ void PairLJLongCoulLongOMP::eval_middle(int iifrom, int iito, ThrData * const thr) { double rsq, r2inv, force_coul = 0.0, force_lj, fpair; const double * const * const x = atom->x; double * const * const f = thr->get_f(); const double * const q = atom->q; const int * const type = atom->type; const int nlocal = atom->nlocal; const double * const special_coul = force->special_coul; const double * const special_lj = force->special_lj; const double qqrd2e = force->qqrd2e; const double *x0 = x[0]; double *f0 = f[0], *fi = 0; - int *ilist = listmiddle->ilist; + int *ilist = list->ilist_middle; const int newton_pair = force->newton_pair; const double cut_in_off = cut_respa[0]; const double cut_in_on = cut_respa[1]; const double cut_out_on = cut_respa[2]; const double cut_out_off = cut_respa[3]; const double cut_in_diff = cut_in_on - cut_in_off; const double cut_out_diff = cut_out_off - cut_out_on; const double cut_in_off_sq = cut_in_off*cut_in_off; const double cut_in_on_sq = cut_in_on*cut_in_on; const double cut_out_on_sq = cut_out_on*cut_out_on; const double cut_out_off_sq = cut_out_off*cut_out_off; int *jneigh, *jneighn, typei, typej, ni; const int order1 = (ewald_order|(ewald_off^-1))&(1<<1); int i, j, ii; double qri, *cut_ljsqi, *lj1i, *lj2i; vector xi, d; for (ii = iifrom; ii < iito; ++ii) { // loop over my atoms i = ilist[ii]; fi = f0+3*i; if (order1) qri = qqrd2e*q[i]; memcpy(xi, x0+(i+(i<<1)), sizeof(vector)); cut_ljsqi = cut_ljsq[typei = type[i]]; lj1i = lj1[typei]; lj2i = lj2[typei]; - jneighn = (jneigh = listmiddle->firstneigh[i])+listmiddle->numneigh[i]; + jneighn = (jneigh = list->firstneigh_middle[i])+list->numneigh_middle[i]; for (; jneigh= cut_out_off_sq) continue; if (rsq <= cut_in_off_sq) continue; r2inv = 1.0/rsq; if (order1 && (rsq < cut_coulsq)) // coulombic force_coul = ni == 0 ? qri*q[j]*sqrt(r2inv) : qri*q[j]*sqrt(r2inv)*special_coul[ni]; if (rsq < cut_ljsqi[typej = type[j]]) { // lennard-jones register double rn = r2inv*r2inv*r2inv; force_lj = ni == 0 ? rn*(rn*lj1i[typej]-lj2i[typej]) : rn*(rn*lj1i[typej]-lj2i[typej])*special_lj[ni]; } else force_lj = 0.0; fpair = (force_coul + force_lj) * r2inv; if (rsq < cut_in_on_sq) { // switching register double rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; fpair *= rsw*rsw*(3.0 - 2.0*rsw); } if (rsq > cut_out_on_sq) { register double rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; fpair *= 1.0 + rsw*rsw*(2.0*rsw-3.0); } if (newton_pair || j < nlocal) { // force update register double *fj = f0+(j+(j<<1)), f; fi[0] += f = d[0]*fpair; fj[0] -= f; fi[1] += f = d[1]*fpair; fj[1] -= f; fi[2] += f = d[2]*fpair; fj[2] -= f; } else { fi[0] += d[0]*fpair; fi[1] += d[1]*fpair; fi[2] += d[2]*fpair; } } } } /* ---------------------------------------------------------------------- */ template < const int EVFLAG, const int EFLAG, const int NEWTON_PAIR, const int CTABLE, const int LJTABLE, const int ORDER1, const int ORDER6 > void PairLJLongCoulLongOMP::eval_outer(int iiform, int iito, ThrData * const thr) { double evdwl,ecoul,fvirial,fpair; evdwl = ecoul = 0.0; const double * const * const x = atom->x; double * const * const f = thr->get_f(); const double * const q = atom->q; const int * const type = atom->type; const int nlocal = atom->nlocal; const double * const special_coul = force->special_coul; const double * const special_lj = force->special_lj; const double qqrd2e = force->qqrd2e; const double *x0 = x[0]; double *f0 = f[0], *fi = f0; - int *ilist = listouter->ilist; + int *ilist = list->ilist; int i, j, ii; int *jneigh, *jneighn, typei, typej, ni, respa_flag; double qi = 0.0, qri = 0.0; double *cutsqi, *cut_ljsqi, *lj1i, *lj2i, *lj3i, *lj4i, *offseti; double rsq, r2inv, force_coul, force_lj; double g2 = g_ewald_6*g_ewald_6, g6 = g2*g2*g2, g8 = g6*g2; double respa_lj = 0.0, respa_coul = 0.0, frespa = 0.0; vector xi, d; const double cut_in_off = cut_respa[2]; const double cut_in_on = cut_respa[3]; const double cut_in_diff = cut_in_on - cut_in_off; const double cut_in_off_sq = cut_in_off*cut_in_off; const double cut_in_on_sq = cut_in_on*cut_in_on; //ineighn = (ineigh = list->ilist)+list->inum; for (ii = iiform; ii < iito; ++ii) { // loop over my atoms i = ilist[ii]; fi = f0+3*i; if (ORDER1) qri = (qi = q[i])*qqrd2e; // initialize constants offseti = offset[typei = type[i]]; lj1i = lj1[typei]; lj2i = lj2[typei]; lj3i = lj3[typei]; lj4i = lj4[typei]; cutsqi = cutsq[typei]; cut_ljsqi = cut_ljsq[typei]; memcpy(xi, x0+(i+(i<<1)), sizeof(vector)); - jneighn = (jneigh = listouter->firstneigh[i])+listouter->numneigh[i]; + jneighn = (jneigh = list->firstneigh[i])+list->numneigh[i]; for (; jneigh= cutsqi[typej = type[j]]) continue; r2inv = 1.0/rsq; frespa = 1.0; // check whether and how to compute respa corrections respa_coul = 0; respa_lj = 0; respa_flag = rsq < cut_in_on_sq ? 1 : 0; if (respa_flag && (rsq > cut_in_off_sq)) { register double rsw = (sqrt(rsq)-cut_in_off)/cut_in_diff; frespa = 1-rsw*rsw*(3.0-2.0*rsw); } if (ORDER1 && (rsq < cut_coulsq)) { // coulombic if (!CTABLE || rsq <= tabinnersq) { // series real space register double r = sqrt(rsq), s = qri*q[j]; if (respa_flag) // correct for respa respa_coul = ni == 0 ? frespa*s/r : frespa*s/r*special_coul[ni]; register double x = g_ewald*r, t = 1.0/(1.0+EWALD_P*x); if (ni == 0) { s *= g_ewald*exp(-x*x); force_coul = (t *= ((((t*A5+A4)*t+A3)*t+A2)*t+A1)*s/x)+EWALD_F*s-respa_coul; if (EFLAG) ecoul = t; } else { // correct for special r = s*(1.0-special_coul[ni])/r; s *= g_ewald*exp(-x*x); force_coul = (t *= ((((t*A5+A4)*t+A3)*t+A2)*t+A1)*s/x)+EWALD_F*s-r-respa_coul; if (EFLAG) ecoul = t-r; } } // table real space else { if (respa_flag) { register double r = sqrt(rsq), s = qri*q[j]; respa_coul = ni == 0 ? frespa*s/r : frespa*s/r*special_coul[ni]; } register union_int_float_t t; t.f = rsq; register const int k = (t.i & ncoulmask) >> ncoulshiftbits; register double f = (rsq-rtable[k])*drtable[k], qiqj = qi*q[j]; if (ni == 0) { force_coul = qiqj*(ftable[k]+f*dftable[k]); if (EFLAG) ecoul = qiqj*(etable[k]+f*detable[k]); } else { // correct for special t.f = (1.0-special_coul[ni])*(ctable[k]+f*dctable[k]); force_coul = qiqj*(ftable[k]+f*dftable[k]-t.f); if (EFLAG) { t.f = (1.0-special_coul[ni])*(ptable[k]+f*dptable[k]); ecoul = qiqj*(etable[k]+f*detable[k]-t.f); } } } } else force_coul = respa_coul = ecoul = 0.0; if (rsq < cut_ljsqi[typej]) { // lennard-jones register double rn = r2inv*r2inv*r2inv; if (respa_flag) respa_lj = ni == 0 ? // correct for respa frespa*rn*(rn*lj1i[typej]-lj2i[typej]) : frespa*rn*(rn*lj1i[typej]-lj2i[typej])*special_lj[ni]; if (ORDER6) { // long-range form if (!LJTABLE || rsq <= tabinnerdispsq) { register double x2 = g2*rsq, a2 = 1.0/x2; x2 = a2*exp(-x2)*lj4i[typej]; if (ni == 0) { force_lj = (rn*=rn)*lj1i[typej]-g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq-respa_lj; if (EFLAG) evdwl = rn*lj3i[typej]-g6*((a2+1.0)*a2+0.5)*x2; } else { // correct for special register double f = special_lj[ni], t = rn*(1.0-f); force_lj = f*(rn *= rn)*lj1i[typej]- g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq+t*lj2i[typej]-respa_lj; if (EFLAG) evdwl = f*rn*lj3i[typej]-g6*((a2+1.0)*a2+0.5)*x2+t*lj4i[typej]; } } else { // table real space register union_int_float_t disp_t; disp_t.f = rsq; register const int disp_k = (disp_t.i & ndispmask)>>ndispshiftbits; register double f_disp = (rsq-rdisptable[disp_k])*drdisptable[disp_k]; register double rn = r2inv*r2inv*r2inv; if (ni == 0) { force_lj = (rn*=rn)*lj1i[typej]-(fdisptable[disp_k]+f_disp*dfdisptable[disp_k])*lj4i[typej]-respa_lj; if (EFLAG) evdwl = rn*lj3i[typej]-(edisptable[disp_k]+f_disp*dedisptable[disp_k])*lj4i[typej]; } else { // special case register double f = special_lj[ni], t = rn*(1.0-f); force_lj = f*(rn *= rn)*lj1i[typej]-(fdisptable[disp_k]+f_disp*dfdisptable[disp_k])*lj4i[typej]+t*lj2i[typej]-respa_lj; if (EFLAG) evdwl = f*rn*lj3i[typej]-(edisptable[disp_k]+f_disp*dedisptable[disp_k])*lj4i[typej]+t*lj4i[typej]; } } } else { // cut form if (ni == 0) { force_lj = rn*(rn*lj1i[typej]-lj2i[typej])-respa_lj; if (EFLAG) evdwl = rn*(rn*lj3i[typej]-lj4i[typej])-offseti[typej]; } else { // correct for special register double f = special_lj[ni]; force_lj = f*rn*(rn*lj1i[typej]-lj2i[typej])-respa_lj; if (EFLAG) evdwl = f*(rn*(rn*lj3i[typej]-lj4i[typej])-offseti[typej]); } } } else force_lj = respa_lj = evdwl = 0.0; fpair = (force_coul+force_lj)*r2inv; if (NEWTON_PAIR || j < nlocal) { register double *fj = f0+(j+(j<<1)), f; fi[0] += f = d[0]*fpair; fj[0] -= f; fi[1] += f = d[1]*fpair; fj[1] -= f; fi[2] += f = d[2]*fpair; fj[2] -= f; } else { fi[0] += d[0]*fpair; fi[1] += d[1]*fpair; fi[2] += d[2]*fpair; } if (EVFLAG) { fvirial = (force_coul + force_lj + respa_coul + respa_lj)*r2inv; ev_tally_thr(this,i,j,nlocal,NEWTON_PAIR, evdwl,ecoul,fvirial,d[0],d[1],d[2],thr); } } } } /* ---------------------------------------------------------------------- */ double PairLJLongCoulLongOMP::memory_usage() { double bytes = memory_usage_thr(); bytes += PairLJLongCoulLong::memory_usage(); return bytes; } diff --git a/src/USER-OMP/pair_lj_long_tip4p_long_omp.cpp b/src/USER-OMP/pair_lj_long_tip4p_long_omp.cpp index 1c8f60d7d..c6490b082 100644 --- a/src/USER-OMP/pair_lj_long_tip4p_long_omp.cpp +++ b/src/USER-OMP/pair_lj_long_tip4p_long_omp.cpp @@ -1,2076 +1,2076 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- Contributing author: Axel Kohlmeyer (Temple U) ------------------------------------------------------------------------- */ #include #include "pair_lj_long_tip4p_long_omp.h" #include "atom.h" #include "domain.h" #include "comm.h" #include "math_vector.h" #include "force.h" #include "neighbor.h" #include "error.h" #include "memory.h" #include "neigh_list.h" #include "suffix.h" using namespace LAMMPS_NS; #define EWALD_F 1.12837917 #define EWALD_P 0.3275911 #define A1 0.254829592 #define A2 -0.284496736 #define A3 1.421413741 #define A4 -1.453152027 #define A5 1.061405429 /* ---------------------------------------------------------------------- */ PairLJLongTIP4PLongOMP::PairLJLongTIP4PLongOMP(LAMMPS *lmp) : PairLJLongTIP4PLong(lmp), ThrOMP(lmp, THR_PAIR) { suffix_flag |= Suffix::OMP; respa_enable = 1; cut_respa = NULL; newsite_thr = NULL; hneigh_thr = NULL; tip4pflag = dispersionflag = 1; no_virial_fdotr_compute = 1; single_enable = 0; nmax = 0; } /* ---------------------------------------------------------------------- */ PairLJLongTIP4PLongOMP::~PairLJLongTIP4PLongOMP() { memory->destroy(hneigh_thr); memory->destroy(newsite_thr); } /* ---------------------------------------------------------------------- */ void PairLJLongTIP4PLongOMP::compute(int eflag, int vflag) { if (eflag || vflag) { ev_setup(eflag,vflag); } else evflag = vflag_fdotr = 0; // reallocate hneigh_thr & newsite_thr if necessary // initialize hneigh_thr[0] to -1 on steps when reneighboring occured // initialize hneigh_thr[2] to 0 every step const int nlocal = atom->nlocal; const int nall = nlocal + atom->nghost; if (atom->nmax > nmax) { nmax = atom->nmax; memory->destroy(hneigh_thr); memory->create(hneigh_thr,nmax,"pair:hneigh_thr"); memory->destroy(newsite_thr); memory->create(newsite_thr,nmax,"pair:newsite_thr"); } int i; // tag entire list as completely invalid after a neighbor // list update, since that can change the order of atoms. if (neighbor->ago == 0) for (i = 0; i < nall; i++) hneigh_thr[i].a = -1; // indicate that the coordinates for the M point need to // be updated. this needs to be done in every step. for (i = 0; i < nall; i++) hneigh_thr[i].t = 0; const int order1 = ewald_order&(1<<1); const int order6 = ewald_order&(1<<6); const int nthreads = comm->nthreads; const int inum = list->inum; #if defined(_OPENMP) #pragma omp parallel default(none) shared(eflag,vflag) #endif { int ifrom, ito, tid; loop_setup_thr(ifrom, ito, tid, inum, nthreads); ThrData *thr = fix->get_thr(tid); thr->timer(Timer::START); ev_setup_thr(eflag, vflag, nall, eatom, vatom, thr); if (order6) { if (order1) { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,0,0,1,1>(ifrom, ito, thr); else eval<1,1,0,0,0,1,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,0,0,1,1>(ifrom, ito, thr); else eval<1,0,0,0,0,1,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,0,0,1,1>(ifrom, ito, thr); else eval<0,0,0,0,0,1,1>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,1,0,1,1>(ifrom, ito, thr); else eval<1,1,0,1,0,1,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,1,0,1,1>(ifrom, ito, thr); else eval<1,0,0,1,0,1,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,1,0,1,1>(ifrom, ito, thr); else eval<0,0,0,1,0,1,1>(ifrom, ito, thr); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,0,1,1,1>(ifrom, ito, thr); else eval<1,1,0,0,1,1,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,0,1,1,1>(ifrom, ito, thr); else eval<1,0,0,0,1,1,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,0,1,1,1>(ifrom, ito, thr); else eval<0,0,0,0,1,1,1>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,1,1,1,1>(ifrom, ito, thr); else eval<1,1,0,1,1,1,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,1,1,1,1>(ifrom, ito, thr); else eval<1,0,0,1,1,1,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,1,1,1,1>(ifrom, ito, thr); else eval<0,0,0,1,1,1,1>(ifrom, ito, thr); } } } } else { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,0,0,0,1>(ifrom, ito, thr); else eval<1,1,0,0,0,0,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,0,0,0,1>(ifrom, ito, thr); else eval<1,0,0,0,0,0,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,0,0,0,1>(ifrom, ito, thr); else eval<0,0,0,0,0,0,1>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,1,0,0,1>(ifrom, ito, thr); else eval<1,1,0,1,0,0,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,1,0,0,1>(ifrom, ito, thr); else eval<1,0,0,1,0,0,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,1,0,0,1>(ifrom, ito, thr); else eval<0,0,0,1,0,0,1>(ifrom, ito, thr); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,0,1,0,1>(ifrom, ito, thr); else eval<1,1,0,0,1,0,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,0,1,0,1>(ifrom, ito, thr); else eval<1,0,0,0,1,0,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,0,1,0,1>(ifrom, ito, thr); else eval<0,0,0,0,1,0,1>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,1,1,0,1>(ifrom, ito, thr); else eval<1,1,0,1,1,0,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,1,1,0,1>(ifrom, ito, thr); else eval<1,0,0,1,1,0,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,1,1,0,1>(ifrom, ito, thr); else eval<0,0,0,1,1,0,1>(ifrom, ito, thr); } } } } } else { if (order1) { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,0,0,1,0>(ifrom, ito, thr); else eval<1,1,0,0,0,1,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,0,0,1,0>(ifrom, ito, thr); else eval<1,0,0,0,0,1,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,0,0,1,0>(ifrom, ito, thr); else eval<0,0,0,0,0,1,0>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,1,0,1,0>(ifrom, ito, thr); else eval<1,1,0,1,0,1,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,1,0,1,0>(ifrom, ito, thr); else eval<1,0,0,1,0,1,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,1,0,1,0>(ifrom, ito, thr); else eval<0,0,0,1,0,1,0>(ifrom, ito, thr); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,0,1,1,0>(ifrom, ito, thr); else eval<1,1,0,0,1,1,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,0,1,1,0>(ifrom, ito, thr); else eval<1,0,0,0,1,1,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,0,1,1,0>(ifrom, ito, thr); else eval<0,0,0,0,1,1,0>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,1,1,1,0>(ifrom, ito, thr); else eval<1,1,0,1,1,1,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,1,1,1,0>(ifrom, ito, thr); else eval<1,0,0,1,1,1,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,1,1,1,0>(ifrom, ito, thr); else eval<0,0,0,1,1,1,0>(ifrom, ito, thr); } } } } else { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,0,0,0,0>(ifrom, ito, thr); else eval<1,1,0,0,0,0,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,0,0,0,0>(ifrom, ito, thr); else eval<1,0,0,0,0,0,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,0,0,0,0>(ifrom, ito, thr); else eval<0,0,0,0,0,0,0>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,1,0,0,0>(ifrom, ito, thr); else eval<1,1,0,1,0,0,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,1,0,0,0>(ifrom, ito, thr); else eval<1,0,0,1,0,0,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,1,0,0,0>(ifrom, ito, thr); else eval<0,0,0,1,0,0,0>(ifrom, ito, thr); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,0,1,0,0>(ifrom, ito, thr); else eval<1,1,0,0,1,0,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,0,1,0,0>(ifrom, ito, thr); else eval<1,0,0,0,1,0,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,0,1,0,0>(ifrom, ito, thr); else eval<0,0,0,0,1,0,0>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval<1,1,1,1,1,0,0>(ifrom, ito, thr); else eval<1,1,0,1,1,0,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval<1,0,1,1,1,0,0>(ifrom, ito, thr); else eval<1,0,0,1,1,0,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval<0,0,1,1,1,0,0>(ifrom, ito, thr); else eval<0,0,0,1,1,0,0>(ifrom, ito, thr); } } } } } thr->timer(Timer::PAIR); reduce_thr(this, eflag, vflag, thr); } // end of omp parallel region } /* ---------------------------------------------------------------------- */ void PairLJLongTIP4PLongOMP::compute_inner() { // reallocate hneigh_thr & newsite_thr if necessary // initialize hneigh_thr[0] to -1 on steps when reneighboring occured // initialize hneigh_thr[2] to 0 every step const int nall = atom->nlocal + atom->nghost; if (atom->nmax > nmax) { nmax = atom->nmax; memory->destroy(hneigh_thr); memory->create(hneigh_thr,nmax,"pair:hneigh_thr"); memory->destroy(newsite_thr); memory->create(newsite_thr,nmax,"pair:newsite_thr"); } int i; // tag entire list as completely invalid after a neighbor // list update, since that can change the order of atoms. if (neighbor->ago == 0) for (i = 0; i < nall; i++) hneigh_thr[i].a = -1; // indicate that the coordinates for the M point need to // be updated. this needs to be done in every step. for (i = 0; i < nall; i++) hneigh_thr[i].t = 0; const int nthreads = comm->nthreads; - const int inum = listinner->inum; + const int inum = list->inum_inner; #if defined(_OPENMP) #pragma omp parallel default(none) #endif { int ifrom, ito, tid; loop_setup_thr(ifrom, ito, tid, inum, nthreads); ThrData *thr = fix->get_thr(tid); thr->timer(Timer::START); ev_setup_thr(0, 0, nall, 0, 0, thr); eval_inner(ifrom, ito, thr); thr->timer(Timer::PAIR); } // end of omp parallel region } /* ---------------------------------------------------------------------- */ void PairLJLongTIP4PLongOMP::compute_middle() { const int nall = atom->nlocal + atom->nghost; const int nthreads = comm->nthreads; - const int inum = listmiddle->inum; + const int inum = list->inum_middle; #if defined(_OPENMP) #pragma omp parallel default(none) #endif { int ifrom, ito, tid; loop_setup_thr(ifrom, ito, tid, inum, nthreads); ThrData *thr = fix->get_thr(tid); thr->timer(Timer::START); ev_setup_thr(0, 0, nall, 0, 0, thr); eval_middle(ifrom, ito, thr); thr->timer(Timer::PAIR); } // end of omp parallel region } /* ---------------------------------------------------------------------- */ void PairLJLongTIP4PLongOMP::compute_outer(int eflag, int vflag) { if (eflag || vflag) { ev_setup(eflag,vflag); } else evflag = vflag_fdotr = 0; const int order1 = ewald_order&(1<<1); const int order6 = ewald_order&(1<<6); const int nall = atom->nlocal + atom->nghost; // reallocate hneigh_thr & newsite_thr if necessary // initialize hneigh_thr[0] to -1 on steps when reneighboring occured // initialize hneigh_thr[2] to 0 every step if (atom->nmax > nmax) { nmax = atom->nmax; memory->destroy(hneigh_thr); memory->create(hneigh_thr,nmax,"pair:hneigh_thr"); memory->destroy(newsite_thr); memory->create(newsite_thr,nmax,"pair:newsite_thr"); } int i; // tag entire list as completely invalid after a neighbor // list update, since that can change the order of atoms. if (neighbor->ago == 0) { for (i = 0; i < nall; i++) hneigh_thr[i].a = -1; // indicate that the coordinates for the M point need to // be updated. this needs to be done only if neighbor list // has been updated in compute_outer for (i = 0; i < nall; i++) hneigh_thr[i].t = 0; } const int nthreads = comm->nthreads; - const int inum = listouter->inum; + const int inum = list->inum; #if defined(_OPENMP) #pragma omp parallel default(none) shared(eflag,vflag) #endif { int ifrom, ito, tid; loop_setup_thr(ifrom, ito, tid, inum, nthreads); ThrData *thr = fix->get_thr(tid); thr->timer(Timer::START); ev_setup_thr(eflag, vflag, nall, eatom, vatom, thr); if (order6) { if (order1) { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,0,0,1,1>(ifrom, ito, thr); else eval_outer<1,1,0,0,0,1,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,0,0,1,1>(ifrom, ito, thr); else eval_outer<1,0,0,0,0,1,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,0,0,1,1>(ifrom, ito, thr); else eval_outer<0,0,0,0,0,1,1>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,1,0,1,1>(ifrom, ito, thr); else eval_outer<1,1,0,1,0,1,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,1,0,1,1>(ifrom, ito, thr); else eval_outer<1,0,0,1,0,1,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,1,0,1,1>(ifrom, ito, thr); else eval_outer<0,0,0,1,0,1,1>(ifrom, ito, thr); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,0,1,1,1>(ifrom, ito, thr); else eval_outer<1,1,0,0,1,1,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,0,1,1,1>(ifrom, ito, thr); else eval_outer<1,0,0,0,1,1,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,0,1,1,1>(ifrom, ito, thr); else eval_outer<0,0,0,0,1,1,1>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,1,1,1,1>(ifrom, ito, thr); else eval_outer<1,1,0,1,1,1,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,1,1,1,1>(ifrom, ito, thr); else eval_outer<1,0,0,1,1,1,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,1,1,1,1>(ifrom, ito, thr); else eval_outer<0,0,0,1,1,1,1>(ifrom, ito, thr); } } } } else { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,0,0,0,1>(ifrom, ito, thr); else eval_outer<1,1,0,0,0,0,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,0,0,0,1>(ifrom, ito, thr); else eval_outer<1,0,0,0,0,0,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,0,0,0,1>(ifrom, ito, thr); else eval_outer<0,0,0,0,0,0,1>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,1,0,0,1>(ifrom, ito, thr); else eval_outer<1,1,0,1,0,0,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,1,0,0,1>(ifrom, ito, thr); else eval_outer<1,0,0,1,0,0,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,1,0,0,1>(ifrom, ito, thr); else eval_outer<0,0,0,1,0,0,1>(ifrom, ito, thr); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,0,1,0,1>(ifrom, ito, thr); else eval_outer<1,1,0,0,1,0,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,0,1,0,1>(ifrom, ito, thr); else eval_outer<1,0,0,0,1,0,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,0,1,0,1>(ifrom, ito, thr); else eval_outer<0,0,0,0,1,0,1>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,1,1,0,1>(ifrom, ito, thr); else eval_outer<1,1,0,1,1,0,1>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,1,1,0,1>(ifrom, ito, thr); else eval_outer<1,0,0,1,1,0,1>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,1,1,0,1>(ifrom, ito, thr); else eval_outer<0,0,0,1,1,0,1>(ifrom, ito, thr); } } } } } else { if (order1) { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,0,0,1,0>(ifrom, ito, thr); else eval_outer<1,1,0,0,0,1,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,0,0,1,0>(ifrom, ito, thr); else eval_outer<1,0,0,0,0,1,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,0,0,1,0>(ifrom, ito, thr); else eval_outer<0,0,0,0,0,1,0>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,1,0,1,0>(ifrom, ito, thr); else eval_outer<1,1,0,1,0,1,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,1,0,1,0>(ifrom, ito, thr); else eval_outer<1,0,0,1,0,1,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,1,0,1,0>(ifrom, ito, thr); else eval_outer<0,0,0,1,0,1,0>(ifrom, ito, thr); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,0,1,1,0>(ifrom, ito, thr); else eval_outer<1,1,0,0,1,1,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,0,1,1,0>(ifrom, ito, thr); else eval_outer<1,0,0,0,1,1,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,0,1,1,0>(ifrom, ito, thr); else eval_outer<0,0,0,0,1,1,0>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,1,1,1,0>(ifrom, ito, thr); else eval_outer<1,1,0,1,1,1,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,1,1,1,0>(ifrom, ito, thr); else eval_outer<1,0,0,1,1,1,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,1,1,1,0>(ifrom, ito, thr); else eval_outer<0,0,0,1,1,1,0>(ifrom, ito, thr); } } } } else { if (!ndisptablebits) { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,0,0,0,0>(ifrom, ito, thr); else eval_outer<1,1,0,0,0,0,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,0,0,0,0>(ifrom, ito, thr); else eval_outer<1,0,0,0,0,0,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,0,0,0,0>(ifrom, ito, thr); else eval_outer<0,0,0,0,0,0,0>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,1,0,0,0>(ifrom, ito, thr); else eval_outer<1,1,0,1,0,0,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,1,0,0,0>(ifrom, ito, thr); else eval_outer<1,0,0,1,0,0,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,1,0,0,0>(ifrom, ito, thr); else eval_outer<0,0,0,1,0,0,0>(ifrom, ito, thr); } } } else { if (!ncoultablebits) { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,0,1,0,0>(ifrom, ito, thr); else eval_outer<1,1,0,0,1,0,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,0,1,0,0>(ifrom, ito, thr); else eval_outer<1,0,0,0,1,0,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,0,1,0,0>(ifrom, ito, thr); else eval_outer<0,0,0,0,1,0,0>(ifrom, ito, thr); } } else { if (evflag) { if (eflag) { if (force->newton_pair) eval_outer<1,1,1,1,1,0,0>(ifrom, ito, thr); else eval_outer<1,1,0,1,1,0,0>(ifrom, ito, thr); } else { if (force->newton_pair) eval_outer<1,0,1,1,1,0,0>(ifrom, ito, thr); else eval_outer<1,0,0,1,1,0,0>(ifrom, ito, thr); } } else { if (force->newton_pair) eval_outer<0,0,1,1,1,0,0>(ifrom, ito, thr); else eval_outer<0,0,0,1,1,0,0>(ifrom, ito, thr); } } } } } thr->timer(Timer::PAIR); reduce_thr(this, eflag, vflag, thr); } // end of omp parallel region } /* ---------------------------------------------------------------------- */ template < const int EVFLAG, const int EFLAG, const int NEWTON_PAIR, const int CTABLE, const int LJTABLE, const int ORDER1, const int ORDER6 > void PairLJLongTIP4PLongOMP::eval(int iifrom, int iito, ThrData * const thr) { const dbl3_t * _noalias const x = (dbl3_t *) atom->x[0]; dbl3_t * _noalias const f = (dbl3_t *) thr->get_f()[0]; const double * _noalias const q = atom->q; const int * _noalias const type = atom->type; const tagint * _noalias const tag = atom->tag; const int nlocal = atom->nlocal; const double * _noalias const special_coul = force->special_coul; const double * _noalias const special_lj = force->special_lj; const double qqrd2e = force->qqrd2e; const double cut_coulsqplus = (cut_coul+2.0*qdist)*(cut_coul+2.0*qdist); const int vflag = vflag_global || vflag_atom; int i,j,ii,jj,jnum,itype,jtype,itable; int n,vlist[6]; int key; int iH1,iH2,jH1,jH2; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fxtmp,fytmp,fztmp,evdwl,ecoul; double fraction,table; double r,r2inv,forcecoul,forcelj,cforce; double factor_coul; double grij,expm2,prefactor,t,erfc; double fOx,fOy,fOz,fHx,fHy,fHz,fdx,fdy,fdz,v[6]; dbl3_t x1,x2,xH1,xH2; int *ilist,*jlist,*numneigh,**firstneigh; double rsq; evdwl = ecoul = 0.0; int ni; double *lj1i, *lj2i, *lj3i, *lj4i, *offseti; double g2 = g_ewald_6*g_ewald_6, g6 = g2*g2*g2, g8 = g6*g2; ilist = list->ilist; numneigh = list->numneigh; firstneigh = list->firstneigh; // loop over neighbors of my atoms for (ii = iifrom; ii < iito; ++ii) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i].x; ytmp = x[i].y; ztmp = x[i].z; itype = type[i]; if (itype == typeO) { if (hneigh_thr[i].a < 0) { iH1 = atom->map(tag[i] + 1); iH2 = atom->map(tag[i] + 2); if (iH1 == -1 || iH2 == -1) error->one(FLERR,"TIP4P hydrogen is missing"); if (type[iH1] != typeH || type[iH2] != typeH) error->one(FLERR,"TIP4P hydrogen has incorrect atom type"); // set iH1,iH2 to closest image to O iH1 = domain->closest_image(i,iH1); iH2 = domain->closest_image(i,iH2); compute_newsite_thr(x[i],x[iH1],x[iH2],newsite_thr[i]); hneigh_thr[i].t = 1; hneigh_thr[i].b = iH2; hneigh_thr[i].a = iH1; } else { iH1 = hneigh_thr[i].a; iH2 = hneigh_thr[i].b; if (hneigh_thr[i].t == 0) { compute_newsite_thr(x[i],x[iH1],x[iH2],newsite_thr[i]); hneigh_thr[i].t = 1; } } x1 = newsite_thr[i]; } else x1 = x[i]; jlist = firstneigh[i]; jnum = numneigh[i]; fxtmp=fytmp=fztmp=0.0; offseti = offset[itype]; lj1i = lj1[itype]; lj2i = lj2[itype]; lj3i = lj3[itype]; lj4i = lj4[itype]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; ni = sbmask(j); factor_coul = special_coul[ni]; j &= NEIGHMASK; delx = xtmp - x[j].x; dely = ytmp - x[j].y; delz = ztmp - x[j].z; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; if (rsq < cut_ljsq[itype][jtype]) { // lj r2inv = 1.0/rsq; if (ORDER6) { // long-range lj if (!LJTABLE || rsq <= tabinnerdispsq) { register double rn = r2inv*r2inv*r2inv; register double x2 = g2*rsq, a2 = 1.0/x2; x2 = a2*exp(-x2)*lj4i[jtype]; if (ni == 0) { forcelj = (rn*=rn)*lj1i[jtype]-g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq; if (EFLAG) evdwl = rn*lj3i[jtype]-g6*((a2+1.0)*a2+0.5)*x2; } else { // special case register double f = special_lj[ni], t = rn*(1.0-f); forcelj = f*(rn *= rn)*lj1i[jtype]- g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq+t*lj2i[jtype]; if (EFLAG) evdwl = f*rn*lj3i[jtype]-g6*((a2+1.0)*a2+0.5)*x2+t*lj4i[jtype]; } } else { // table real space register union_int_float_t disp_t; disp_t.f = rsq; register const int disp_k = (disp_t.i & ndispmask)>>ndispshiftbits; register double f_disp = (rsq-rdisptable[disp_k])*drdisptable[disp_k]; register double rn = r2inv*r2inv*r2inv; if (ni == 0) { forcelj = (rn*=rn)*lj1i[jtype]-(fdisptable[disp_k]+f_disp*dfdisptable[disp_k])*lj4i[jtype]; if (EFLAG) evdwl = rn*lj3i[jtype]-(edisptable[disp_k]+f_disp*dedisptable[disp_k])*lj4i[jtype]; } else { // special case register double f = special_lj[ni], t = rn*(1.0-f); forcelj = f*(rn *= rn)*lj1i[jtype]-(fdisptable[disp_k]+f_disp*dfdisptable[disp_k])*lj4i[jtype]+t*lj2i[jtype]; if (EFLAG) evdwl = f*rn*lj3i[jtype]-(edisptable[disp_k]+f_disp*dedisptable[disp_k])*lj4i[jtype]+t*lj4i[jtype]; } } } else { // cut lj register double rn = r2inv*r2inv*r2inv; if (ni == 0) { forcelj = rn*(rn*lj1i[jtype]-lj2i[jtype]); if (EFLAG) evdwl = rn*(rn*lj3i[jtype]-lj4i[jtype])-offseti[jtype]; } else { // special case register double f = special_lj[ni]; forcelj = f*rn*(rn*lj1i[jtype]-lj2i[jtype]); if (EFLAG) evdwl = f * (rn*(rn*lj3i[jtype]-lj4i[jtype])-offseti[jtype]); } } forcelj *= r2inv; fxtmp += delx*forcelj; fytmp += dely*forcelj; fztmp += delz*forcelj; f[j].x -= delx*forcelj; f[j].y -= dely*forcelj; f[j].z -= delz*forcelj; if (EVFLAG) ev_tally_thr(this,i,j,nlocal, /* newton_pair = */ 1, evdwl,0.0,forcelj,delx,dely,delz,thr); } // adjust rsq and delxyz for off-site O charge(s) // ADDITIONAL REQEUST REQUIRED HERE!!!!! if (rsq < cut_coulsqplus) { if (itype == typeO || jtype == typeO) { if (jtype == typeO) { if (hneigh_thr[j].a < 0) { jH1 = atom->map(tag[j] + 1); jH2 = atom->map(tag[j] + 2); if (jH1 == -1 || jH2 == -1) error->one(FLERR,"TIP4P hydrogen is missing"); if (type[jH1] != typeH || type[jH2] != typeH) error->one(FLERR,"TIP4P hydrogen has incorrect atom type"); // set jH1,jH2 to closest image to O jH1 = domain->closest_image(j,jH1); jH2 = domain->closest_image(j,jH2); compute_newsite_thr(x[j],x[jH1],x[jH2],newsite_thr[j]); hneigh_thr[j].t = 1; hneigh_thr[j].b = jH2; hneigh_thr[j].a = jH1; } else { jH1 = hneigh_thr[j].a; jH2 = hneigh_thr[j].b; if (hneigh_thr[j].t == 0) { compute_newsite_thr(x[j],x[jH1],x[jH2],newsite_thr[j]); hneigh_thr[j].t = 1; } } x2 = newsite_thr[j]; } else x2 = x[j]; delx = x1.x - x2.x; dely = x1.y - x2.y; delz = x1.z - x2.z; rsq = delx*delx + dely*dely + delz*delz; } // test current rsq against cutoff and compute Coulombic force if (rsq < cut_coulsq && ORDER1) { r2inv = 1.0 / rsq; if (!CTABLE || rsq <= tabinnersq) { r = sqrt(rsq); grij = g_ewald * r; expm2 = exp(-grij*grij); t = 1.0 / (1.0 + EWALD_P*grij); erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2; prefactor = qqrd2e * qtmp*q[j]/r; forcecoul = prefactor * (erfc + EWALD_F*grij*expm2); if (factor_coul < 1.0) { forcecoul -= (1.0-factor_coul)*prefactor; } } else { union_int_float_t rsq_lookup; rsq_lookup.f = rsq; itable = rsq_lookup.i & ncoulmask; itable >>= ncoulshiftbits; fraction = (rsq_lookup.f - rtable[itable]) * drtable[itable]; table = ftable[itable] + fraction*dftable[itable]; forcecoul = qtmp*q[j] * table; if (factor_coul < 1.0) { table = ctable[itable] + fraction*dctable[itable]; prefactor = qtmp*q[j] * table; forcecoul -= (1.0-factor_coul)*prefactor; } } cforce = forcecoul * r2inv; //if (evflag) ev_tally(i,j,nlocal,newton_pair, // evdwl,0.0,cforce,delx,dely,delz); // if i,j are not O atoms, force is applied directly // if i or j are O atoms, force is on fictitious atom & partitioned // force partitioning due to Feenstra, J Comp Chem, 20, 786 (1999) // f_f = fictitious force, fO = f_f (1 - 2 alpha), fH = alpha f_f // preserves total force and torque on water molecule // virial = sum(r x F) where each water's atoms are near xi and xj // vlist stores 2,4,6 atoms whose forces contribute to virial if (EVFLAG && vflag) { n = 0; key = 0; } if (itype != typeO) { fxtmp += delx * cforce; fytmp += dely * cforce; fztmp += delz * cforce; if (EVFLAG && vflag) { v[0] = x[i].x * delx * cforce; v[1] = x[i].y * dely * cforce; v[2] = x[i].z * delz * cforce; v[3] = x[i].x * dely * cforce; v[4] = x[i].x * delz * cforce; v[5] = x[i].y * delz * cforce; vlist[n++] = i; } } else { if (EVFLAG && vflag) key++; fdx = delx*cforce; fdy = dely*cforce; fdz = delz*cforce; fOx = fdx*(1 - alpha); fOy = fdy*(1 - alpha); fOz = fdz*(1 - alpha); fHx = 0.5 * alpha * fdx; fHy = 0.5 * alpha * fdy; fHz = 0.5 * alpha * fdz; fxtmp += fOx; fytmp += fOy; fztmp += fOz; f[iH1].x += fHx; f[iH1].y += fHy; f[iH1].z += fHz; f[iH2].x += fHx; f[iH2].y += fHy; f[iH2].z += fHz; if (EVFLAG && vflag) { xH1 = x[iH1]; xH2 = x[iH2]; v[0] = x[i].x*fOx + xH1.x*fHx + xH2.x*fHx; v[1] = x[i].y*fOy + xH1.y*fHy + xH2.y*fHy; v[2] = x[i].z*fOz + xH1.z*fHz + xH2.z*fHz; v[3] = x[i].x*fOy + xH1.x*fHy + xH2.x*fHy; v[4] = x[i].x*fOz + xH1.x*fHz + xH2.x*fHz; v[5] = x[i].y*fOz + xH1.y*fHz + xH2.y*fHz; vlist[n++] = i; vlist[n++] = iH1; vlist[n++] = iH2; } } if (jtype != typeO) { f[j].x -= delx * cforce; f[j].y -= dely * cforce; f[j].z -= delz * cforce; if (EVFLAG && vflag) { v[0] -= x[j].x * delx * cforce; v[1] -= x[j].y * dely * cforce; v[2] -= x[j].z * delz * cforce; v[3] -= x[j].x * dely * cforce; v[4] -= x[j].x * delz * cforce; v[5] -= x[j].y * delz * cforce; vlist[n++] = j; } } else { if (EVFLAG && vflag) key += 2; fdx = -delx*cforce; fdy = -dely*cforce; fdz = -delz*cforce; fOx = fdx*(1 - alpha); fOy = fdy*(1 - alpha); fOz = fdz*(1 - alpha); fHx = 0.5 * alpha * fdx; fHy = 0.5 * alpha * fdy; fHz = 0.5 * alpha * fdz; f[j].x += fOx; f[j].y += fOy; f[j].z += fOz; f[jH1].x += fHx; f[jH1].y += fHy; f[jH1].z += fHz; f[jH2].x += fHx; f[jH2].y += fHy; f[jH2].z += fHz; if (EVFLAG && vflag) { xH1 = x[jH1]; xH2 = x[jH2]; v[0] += x[j].x*fOx + xH1.x*fHx + xH2.x*fHx; v[1] += x[j].y*fOy + xH1.y*fHy + xH2.y*fHy; v[2] += x[j].z*fOz + xH1.z*fHz + xH2.z*fHz; v[3] += x[j].x*fOy + xH1.x*fHy + xH2.x*fHy; v[4] += x[j].x*fOz + xH1.x*fHz + xH2.x*fHz; v[5] += x[j].y*fOz + xH1.y*fHz + xH2.y*fHz; vlist[n++] = j; vlist[n++] = jH1; vlist[n++] = jH2; } } if (EFLAG) { if (!CTABLE || rsq <= tabinnersq) ecoul = prefactor*erfc; else { table = etable[itable] + fraction*detable[itable]; ecoul = qtmp*q[j] * table; } if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; } else ecoul = 0.0; if (EVFLAG) ev_tally_list_thr(this,key,vlist,v,ecoul,alpha,thr); } } } f[i].x += fxtmp; f[i].y += fytmp; f[i].z += fztmp; } } /* ---------------------------------------------------------------------- */ void PairLJLongTIP4PLongOMP::eval_inner(int iifrom, int iito, ThrData * const thr) { double rsq, r2inv, forcecoul = 0.0, forcelj, cforce; const dbl3_t * _noalias const x = (dbl3_t *) atom->x[0]; dbl3_t * _noalias const f = (dbl3_t *) thr->get_f()[0]; const double * _noalias const q = atom->q; const int * _noalias const type = atom->type; const tagint * _noalias const tag = atom->tag; const double * _noalias const special_coul = force->special_coul; const double * _noalias const special_lj = force->special_lj; const double qqrd2e = force->qqrd2e; const double cut_coulsqplus = (cut_coul+2.0*qdist)*(cut_coul+2.0*qdist); const double cut_out_on = cut_respa[0]; const double cut_out_off = cut_respa[1]; const double cut_out_diff = cut_out_off - cut_out_on; const double cut_out_on_sq = cut_out_on*cut_out_on; const double cut_out_off_sq = cut_out_off*cut_out_off; int ni; const int order1 = (ewald_order|(ewald_off^-1))&(1<<1); double qri; int i,j,ii,jj,jnum,itype,jtype; int iH1,iH2,jH1,jH2; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fxtmp,fytmp,fztmp; double fOx,fOy,fOz,fHx,fHy,fHz,fdx,fdy,fdz; dbl3_t x1,x2; int *ilist,*jlist,*numneigh,**firstneigh; double *lj1i, *lj2i; - ilist = listinner->ilist; - numneigh = listinner->numneigh; - firstneigh = listinner->firstneigh; + ilist = list->ilist_inner; + numneigh = list->numneigh_inner; + firstneigh = list->firstneigh_inner; // loop over neighbors of my atoms for (ii = iifrom; ii < iito; ++ii) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i].x; ytmp = x[i].y; ztmp = x[i].z; itype = type[i]; // if atom I = water O, set x1 = offset charge site // else x1 = x of atom I // NOTE: to make this part thread safe, we need to // make sure that the hneigh_thr[][] entries only get // updated, when all data is in place. worst case, // some calculation is repeated, but since the results // will be the same, there is no race condition. if (itype == typeO) { if (hneigh_thr[i].a < 0) { iH1 = atom->map(tag[i] + 1); iH2 = atom->map(tag[i] + 2); if (iH1 == -1 || iH2 == -1) error->one(FLERR,"TIP4P hydrogen is missing"); if (type[iH1] != typeH || type[iH2] != typeH) error->one(FLERR,"TIP4P hydrogen has incorrect atom type"); // set iH1,iH2 to index of closest image to O iH1 = domain->closest_image(i,iH1); iH2 = domain->closest_image(i,iH2); compute_newsite_thr(x[i],x[iH1],x[iH2],newsite_thr[i]); hneigh_thr[i].t = 1; hneigh_thr[i].b = iH2; hneigh_thr[i].a = iH1; } else { iH1 = hneigh_thr[i].a; iH2 = hneigh_thr[i].b; if (hneigh_thr[i].t == 0) { compute_newsite_thr(x[i],x[iH1],x[iH2],newsite_thr[i]); hneigh_thr[i].t = 1; } } x1 = newsite_thr[i]; } else x1 = x[i]; jlist = firstneigh[i]; jnum = numneigh[i]; lj1i = lj1[itype]; lj2i = lj2[itype]; fxtmp=fytmp=fztmp=0.0; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; ni = sbmask(j); j &= NEIGHMASK; delx = xtmp - x[j].x; dely = ytmp - x[j].y; delz = ztmp - x[j].z; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; if (rsq < cut_ljsq[itype][jtype] && rsq < cut_out_off_sq ) { // lj r2inv = 1.0/rsq; register double rn = r2inv*r2inv*r2inv; if (ni == 0) forcelj = rn*(rn*lj1i[jtype]-lj2i[jtype]); else { // special case register double f = special_lj[ni]; forcelj = f*rn*(rn*lj1i[jtype]-lj2i[jtype]); } if (rsq > cut_out_on_sq) { // switching register double rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; forcelj *= 1.0 + rsw*rsw*(2.0*rsw-3.0); } forcelj *= r2inv; fxtmp += delx*forcelj; fytmp += dely*forcelj; fztmp += delz*forcelj; f[j].x -= delx*forcelj; f[j].y -= dely*forcelj; f[j].z -= delz*forcelj; } // adjust rsq and delxyz for off-site O charge(s) // ADDITIONAL REQEUST REQUIRED HERE!!!!! if (rsq < cut_coulsqplus && order1) { if (itype == typeO || jtype == typeO) { if (jtype == typeO) { if (hneigh_thr[j].a < 0) { jH1 = atom->map(tag[j] + 1); jH2 = atom->map(tag[j] + 2); if (jH1 == -1 || jH2 == -1) error->one(FLERR,"TIP4P hydrogen is missing"); if (type[jH1] != typeH || type[jH2] != typeH) error->one(FLERR,"TIP4P hydrogen has incorrect atom type"); // set jH1,jH2 to closest image to O jH1 = domain->closest_image(j,jH1); jH2 = domain->closest_image(j,jH2); compute_newsite_thr(x[j],x[jH1],x[jH2],newsite_thr[j]); hneigh_thr[j].t = 1; hneigh_thr[j].b = jH2; hneigh_thr[j].a = jH1; } else { jH1 = hneigh_thr[j].a; jH2 = hneigh_thr[j].b; if (hneigh_thr[j].t == 0) { compute_newsite_thr(x[j],x[jH1],x[jH2],newsite_thr[j]); hneigh_thr[j].t = 1; } } x2 = newsite_thr[j]; } else x2 = x[j]; delx = x1.x - x2.x; dely = x1.y - x2.y; delz = x1.z - x2.z; rsq = delx*delx + dely*dely + delz*delz; } // test current rsq against cutoff and compute Coulombic force if (rsq < cut_coulsq && rsq < cut_out_off_sq) { r2inv = 1.0 / rsq; qri = qqrd2e*qtmp; if (ni == 0) forcecoul = qri*q[j]*sqrt(r2inv); else { forcecoul = qri*q[j]*sqrt(r2inv)*special_coul[ni]; } if (rsq > cut_out_on_sq) { // switching register double rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; forcecoul *= 1.0 + rsw*rsw*(2.0*rsw-3.0); } cforce = forcecoul * r2inv; //if (evflag) ev_tally(i,j,nlocal,newton_pair, // evdwl,0.0,cforce,delx,dely,delz); // if i,j are not O atoms, force is applied directly // if i or j are O atoms, force is on fictitious atom & partitioned // force partitioning due to Feenstra, J Comp Chem, 20, 786 (1999) // f_f = fictitious force, fO = f_f (1 - 2 alpha), fH = alpha f_f // preserves total force and torque on water molecule // virial = sum(r x F) where each water's atoms are near xi and xj // vlist stores 2,4,6 atoms whose forces contribute to virial if (itype != typeO) { fxtmp += delx * cforce; fytmp += dely * cforce; fztmp += delz * cforce; } else { fdx = delx*cforce; fdy = dely*cforce; fdz = delz*cforce; fOx = fdx*(1 - alpha); fOy = fdy*(1 - alpha); fOz = fdz*(1 - alpha); fHx = 0.5 * alpha * fdx; fHy = 0.5 * alpha * fdy; fHz = 0.5 * alpha * fdz; fxtmp += fOx; fytmp += fOy; fztmp += fOz; f[iH1].x += fHx; f[iH1].y += fHy; f[iH1].z += fHz; f[iH2].x += fHx; f[iH2].y += fHy; f[iH2].z += fHz; } if (jtype != typeO) { f[j].x -= delx * cforce; f[j].y -= dely * cforce; f[j].z -= delz * cforce; } else { fdx = -delx*cforce; fdy = -dely*cforce; fdz = -delz*cforce; fOx = fdx*(1 - alpha); fOy = fdy*(1 - alpha); fOz = fdz*(1 - alpha); fHx = 0.5 * alpha * fdx; fHy = 0.5 * alpha * fdy; fHz = 0.5 * alpha * fdz; f[j].x += fOx; f[j].y += fOy; f[j].z += fOz; f[jH1].x += fHx; f[jH1].y += fHy; f[jH1].z += fHz; f[jH2].x += fHx; f[jH2].y += fHy; f[jH2].z += fHz; } } } } f[i].x += fxtmp; f[i].y += fytmp; f[i].z += fztmp; } } /* ---------------------------------------------------------------------- */ void PairLJLongTIP4PLongOMP::eval_middle(int iifrom, int iito, ThrData * const thr) { double rsq, r2inv, forcecoul,forcelj, cforce; const dbl3_t * _noalias const x = (dbl3_t *) atom->x[0]; dbl3_t * _noalias const f = (dbl3_t *) thr->get_f()[0]; const double * _noalias const q = atom->q; const int * _noalias const type = atom->type; const tagint * _noalias const tag = atom->tag; const double * _noalias const special_coul = force->special_coul; const double * _noalias const special_lj = force->special_lj; const double qqrd2e = force->qqrd2e; const double cut_coulsqplus = (cut_coul+2.0*qdist)*(cut_coul+2.0*qdist); const int order1 = (ewald_order|(ewald_off^-1))&(1<<1); const double cut_in_off = cut_respa[0]; const double cut_in_on = cut_respa[1]; const double cut_out_on = cut_respa[2]; const double cut_out_off = cut_respa[3]; const double cut_in_diff = cut_in_on - cut_in_off; const double cut_out_diff = cut_out_off - cut_out_on; const double cut_in_off_sq = cut_in_off*cut_in_off; const double cut_in_on_sq = cut_in_on*cut_in_on; const double cut_out_on_sq = cut_out_on*cut_out_on; const double cut_out_off_sq = cut_out_off*cut_out_off; int i,j,ii,jj,jnum,itype,jtype; int iH1,iH2,jH1,jH2; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fxtmp,fytmp,fztmp; double fOx,fOy,fOz,fHx,fHy,fHz,fdx,fdy,fdz; dbl3_t x1,x2; int *ilist,*jlist,*numneigh,**firstneigh; double qri; int ni; double *lj1i, *lj2i; - ilist = listmiddle->ilist; - numneigh = listmiddle->numneigh; - firstneigh = listmiddle->firstneigh; + ilist = list->ilist_middle; + numneigh = list->numneigh_middle; + firstneigh = list->firstneigh_middle; // loop over neighbors of my atoms for (ii = iifrom; ii < iito; ++ii) { i = ilist[ii]; qtmp = q[i]; xtmp = x[i].x; ytmp = x[i].y; ztmp = x[i].z; itype = type[i]; if (itype == typeO) { if (hneigh_thr[i].a < 0) { iH1 = atom->map(tag[i] + 1); iH2 = atom->map(tag[i] + 2); if (iH1 == -1 || iH2 == -1) error->one(FLERR,"TIP4P hydrogen is missing"); if (type[iH1] != typeH || type[iH2] != typeH) error->one(FLERR,"TIP4P hydrogen has incorrect atom type"); // set iH1,iH2 to index of closest image to O iH1 = domain->closest_image(i,iH1); iH2 = domain->closest_image(i,iH2); compute_newsite_thr(x[i],x[iH1],x[iH2],newsite_thr[i]); hneigh_thr[i].t = 1; hneigh_thr[i].b = iH2; hneigh_thr[i].a = iH1; } else { iH1 = hneigh_thr[i].a; iH2 = hneigh_thr[i].b; if (hneigh_thr[i].t == 0) { compute_newsite_thr(x[i],x[iH1],x[iH2],newsite_thr[i]); hneigh_thr[i].t = 1; } } x1 = newsite_thr[i]; } else x1 = x[i]; jlist = firstneigh[i]; jnum = numneigh[i]; lj1i = lj1[itype]; lj2i = lj2[itype]; fxtmp = fytmp = fztmp = 0.0; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; ni = sbmask(j); j &= NEIGHMASK; delx = xtmp - x[j].x; dely = ytmp - x[j].y; delz = ztmp - x[j].z; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; if (rsq < cut_ljsq[itype][jtype] && rsq >= cut_in_off_sq && rsq <= cut_out_off_sq ) { // lj r2inv = 1.0/rsq; register double rn = r2inv*r2inv*r2inv; if (ni == 0) forcelj = rn*(rn*lj1i[jtype]-lj2i[jtype]); else { // special case register double f = special_lj[ni]; forcelj = f*rn*(rn*lj1i[jtype]-lj2i[jtype]); } if (rsq < cut_in_on_sq) { // switching register double rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; forcelj *= rsw*rsw*(3.0 - 2.0*rsw); } if (rsq > cut_out_on_sq) { register double rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; forcelj *= 1.0 + rsw*rsw*(2.0*rsw-3.0); } forcelj *= r2inv; fxtmp += delx*forcelj; fytmp += dely*forcelj; fztmp += delz*forcelj; f[j].x -= delx*forcelj; f[j].y -= dely*forcelj; f[j].z -= delz*forcelj; } // adjust rsq and delxyz for off-site O charge(s) // ADDITIONAL REQEUST REQUIRED HERE!!!!! if (rsq < cut_coulsqplus && order1) { if (itype == typeO || jtype == typeO) { if (jtype == typeO) { if (hneigh_thr[j].a < 0) { jH1 = atom->map(tag[j] + 1); jH2 = atom->map(tag[j] + 2); if (jH1 == -1 || jH2 == -1) error->one(FLERR,"TIP4P hydrogen is missing"); if (type[jH1] != typeH || type[jH2] != typeH) error->one(FLERR,"TIP4P hydrogen has incorrect atom type"); // set jH1,jH2 to closest image to O jH1 = domain->closest_image(j,jH1); jH2 = domain->closest_image(j,jH2); compute_newsite_thr(x[j],x[jH1],x[jH2],newsite_thr[j]); hneigh_thr[j].t = 1; hneigh_thr[j].b = jH2; hneigh_thr[j].a = jH1; } else { jH1 = hneigh_thr[j].a; jH2 = hneigh_thr[j].b; if (hneigh_thr[j].t == 0) { compute_newsite_thr(x[j],x[jH1],x[jH2],newsite_thr[j]); hneigh_thr[j].t = 1; } } x2 = newsite_thr[j]; } else x2 = x[j]; delx = x1.x - x2.x; dely = x1.y - x2.y; delz = x1.z - x2.z; rsq = delx*delx + dely*dely + delz*delz; } // test current rsq against cutoff and compute Coulombic force if (rsq < cut_coulsq && rsq >= cut_in_off_sq && rsq <= cut_out_off_sq) { r2inv = 1.0 / rsq; qri = qqrd2e*qtmp; if (ni == 0) forcecoul = qri*q[j]*sqrt(r2inv); else { forcecoul = qri*q[j]*sqrt(r2inv)*special_coul[ni]; } if (rsq < cut_in_on_sq) { // switching register double rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; forcecoul *= rsw*rsw*(3.0 - 2.0*rsw); } if (rsq > cut_out_on_sq) { register double rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; forcecoul *= 1.0 + rsw*rsw*(2.0*rsw-3.0); } cforce = forcecoul * r2inv; //if (evflag) ev_tally(i,j,nlocal,newton_pair, // evdwl,0.0,cforce,delx,dely,delz); // if i,j are not O atoms, force is applied directly // if i or j are O atoms, force is on fictitious atom & partitioned // force partitioning due to Feenstra, J Comp Chem, 20, 786 (1999) // f_f = fictitious force, fO = f_f (1 - 2 alpha), fH = alpha f_f // preserves total force and torque on water molecule // virial = sum(r x F) where each water's atoms are near xi and xj // vlist stores 2,4,6 atoms whose forces contribute to virial if (itype != typeO) { fxtmp += delx * cforce; fytmp += dely * cforce; fztmp += delz * cforce; } else { fdx = delx*cforce; fdy = dely*cforce; fdz = delz*cforce; fOx = fdx*(1 - alpha); fOy = fdy*(1 - alpha); fOz = fdz*(1 - alpha); fHx = 0.5 * alpha * fdx; fHy = 0.5 * alpha * fdy; fHz = 0.5 * alpha * fdz; fxtmp += fOx; fytmp += fOy; fztmp += fOz; f[iH1].x += fHx; f[iH1].y += fHy; f[iH1].z += fHz; f[iH2].x += fHx; f[iH2].y += fHy; f[iH2].z += fHz; } if (jtype != typeO) { f[j].x -= delx * cforce; f[j].y -= dely * cforce; f[j].z -= delz * cforce; } else { fdx = -delx*cforce; fdy = -dely*cforce; fdz = -delz*cforce; fOx = fdx*(1 - alpha); fOy = fdy*(1 - alpha); fOz = fdz*(1 - alpha); fHx = 0.5 * alpha * fdx; fHy = 0.5 * alpha * fdy; fHz = 0.5 * alpha * fdz; f[j].x += fOx; f[j].y += fOy; f[j].z += fOz; f[jH1].x += fHx; f[jH1].y += fHy; f[jH1].z += fHz; f[jH2].x += fHx; f[jH2].y += fHy; f[jH2].z += fHz; } } } } f[i].x += fxtmp; f[i].y += fytmp; f[i].z += fztmp; } } /* ---------------------------------------------------------------------- */ template < const int EVFLAG, const int EFLAG, const int NEWTON_PAIR, const int CTABLE, const int LJTABLE, const int ORDER1, const int ORDER6 > void PairLJLongTIP4PLongOMP::eval_outer(int iifrom, int iito, ThrData * const thr) { double evdwl,ecoul,fvirial; evdwl = ecoul = 0.0; double qtmp,xtmp,ytmp,ztmp,delx,dely,delz; double r2inv,forcecoul,forcelj,cforce, respa_coul, respa_lj, frespa; double fdx,fdy,fdz,fOx,fOy,fOz,fHx,fHy,fHz; double v[6]; dbl3_t x1,x2,xH1,xH2; const dbl3_t * _noalias const x = (dbl3_t *) atom->x[0]; dbl3_t * _noalias const f = (dbl3_t *) thr->get_f()[0]; const double * _noalias const q = atom->q; const int * _noalias const type = atom->type; const tagint * _noalias const tag = atom->tag; const int nlocal = atom->nlocal; const double * _noalias const special_coul = force->special_coul; const double * _noalias const special_lj = force->special_lj; const double qqrd2e = force->qqrd2e; const double cut_coulsqplus = (cut_coul+2.0*qdist)*(cut_coul+2.0*qdist); const int vflag = vflag_atom || vflag_global; int i,j,ii,jj,jnum,itype,jtype; int n,vlist[6]; int key; int iH1,iH2,jH1,jH2; int *ilist,*jlist,*numneigh,**firstneigh; double rsq,qri; int respa_flag; int ni; double *lj1i, *lj2i, *lj3i, *lj4i, *offseti; double g2 = g_ewald_6*g_ewald_6, g6 = g2*g2*g2, g8 = g6*g2; const double cut_in_off = cut_respa[2]; const double cut_in_on = cut_respa[3]; const double cut_in_diff = cut_in_on - cut_in_off; const double cut_in_off_sq = cut_in_off*cut_in_off; const double cut_in_on_sq = cut_in_on*cut_in_on; double fxtmp,fytmp,fztmp; - ilist = listouter->ilist; - numneigh = listouter->numneigh; - firstneigh = listouter->firstneigh; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; // loop over neighbors of my atoms for (ii = iifrom; ii < iito; ++ii) { i = ilist[ii]; qtmp = q[i]; qri = qtmp*qqrd2e; xtmp = x[i].x; ytmp = x[i].y; ztmp = x[i].z; itype = type[i]; if (itype == typeO) { if (hneigh_thr[i].a < 0) { iH1 = atom->map(tag[i] + 1); iH2 = atom->map(tag[i] + 2); if (iH1 == -1 || iH2 == -1) error->one(FLERR,"TIP4P hydrogen is missing"); if (type[iH1] != typeH || type[iH2] != typeH) error->one(FLERR,"TIP4P hydrogen has incorrect atom type"); // set iH1,iH2 to closest image to O iH1 = domain->closest_image(i,iH1); iH2 = domain->closest_image(i,iH2); hneigh_thr[i].t = 1; hneigh_thr[i].b = iH2; hneigh_thr[i].a = iH1; compute_newsite_thr(x[i],x[iH1],x[iH2],newsite_thr[i]); } else { iH1 = hneigh_thr[i].a; iH2 = hneigh_thr[i].b; if (hneigh_thr[i].t == 0) { compute_newsite_thr(x[i],x[iH1],x[iH2],newsite_thr[i]); hneigh_thr[i].t = 1; } } x1 = newsite_thr[i]; } else x1 = x[i]; jlist = firstneigh[i]; jnum = numneigh[i]; offseti = offset[itype]; lj1i = lj1[itype]; lj2i = lj2[itype]; lj3i = lj3[itype]; lj4i = lj4[itype]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; ni = sbmask(j); j &= NEIGHMASK; delx = xtmp - x[j].x; dely = ytmp - x[j].y; delz = ztmp - x[j].z; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; respa_coul = 0; respa_lj = 0; if (rsq < cut_ljsq[itype][jtype]) { // lj frespa = 1.0; // check whether and how to compute respa corrections respa_flag = rsq < cut_in_on_sq ? 1 : 0; if (respa_flag && (rsq > cut_in_off_sq)) { register double rsw = (sqrt(rsq)-cut_in_off)/cut_in_diff; frespa = 1-rsw*rsw*(3.0-2.0*rsw); } r2inv = 1.0/rsq; register double rn = r2inv*r2inv*r2inv; if (respa_flag) respa_lj = ni == 0 ? // correct for respa frespa*rn*(rn*lj1i[jtype]-lj2i[jtype]) : frespa*rn*(rn*lj1i[jtype]-lj2i[jtype])*special_lj[ni]; if (ORDER6) { // long-range form if (!ndisptablebits || rsq <= tabinnerdispsq) { register double x2 = g2*rsq, a2 = 1.0/x2; x2 = a2*exp(-x2)*lj4i[jtype]; if (ni == 0) { forcelj = (rn*=rn)*lj1i[jtype]-g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq-respa_lj; if (EFLAG) evdwl = rn*lj3i[jtype]-g6*((a2+1.0)*a2+0.5)*x2; } else { // correct for special register double f = special_lj[ni], t = rn*(1.0-f); forcelj = f*(rn *= rn)*lj1i[jtype]- g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq+t*lj2i[jtype]-respa_lj; if (EFLAG) evdwl = f*rn*lj3i[jtype]-g6*((a2+1.0)*a2+0.5)*x2+t*lj4i[jtype]; } } else { // table real space register union_int_float_t disp_t; disp_t.f = rsq; register const int disp_k = (disp_t.i & ndispmask)>>ndispshiftbits; register double f_disp = (rsq-rdisptable[disp_k])*drdisptable[disp_k]; if (ni == 0) { forcelj = (rn*=rn)*lj1i[jtype]-(fdisptable[disp_k]+f_disp*dfdisptable[disp_k])*lj4i[jtype]-respa_lj; if (EFLAG) evdwl = rn*lj3i[jtype]-(edisptable[disp_k]+f_disp*dedisptable[disp_k])*lj4i[jtype]; } else { // special case register double f = special_lj[ni], t = rn*(1.0-f); forcelj = f*(rn *= rn)*lj1i[jtype]-(fdisptable[disp_k]+f_disp*dfdisptable[disp_k])*lj4i[jtype]+t*lj2i[jtype]-respa_lj; if (EFLAG) evdwl = f*rn*lj3i[jtype]-(edisptable[disp_k]+f_disp*dedisptable[disp_k])*lj4i[jtype]+t*lj4i[jtype]; } } } else { // cut form if (ni == 0) { forcelj = rn*(rn*lj1i[jtype]-lj2i[jtype])-respa_lj; if (EFLAG) evdwl = rn*(rn*lj3i[jtype]-lj4i[jtype])-offseti[jtype]; } else { // correct for special register double f = special_lj[ni]; forcelj = f*rn*(rn*lj1i[jtype]-lj2i[jtype])-respa_lj; if (EFLAG) evdwl = f*(rn*(rn*lj3i[jtype]-lj4i[jtype])-offseti[jtype]); } } forcelj *= r2inv; fxtmp += delx*forcelj; fytmp += dely*forcelj; fztmp += delz*forcelj; f[j].x -= delx*forcelj; f[j].y -= dely*forcelj; f[j].z -= delz*forcelj; if (EVFLAG) { fvirial = forcelj + respa_lj*r2inv; ev_tally_thr(this,i,j,nlocal,/*newton_pair = */ 1, evdwl,0.0,fvirial,delx,dely,delz, thr); } } // adjust rsq and delxyz for off-site O charge(s) // ADDITIONAL REQEUST REQUIRED HERE!!!!! if (rsq < cut_coulsqplus) { if (itype == typeO || jtype == typeO) { if (jtype == typeO) { if (hneigh_thr[j].a < 0) { jH1 = atom->map(tag[j] + 1); jH2 = atom->map(tag[j] + 2); if (jH1 == -1 || jH2 == -1) error->one(FLERR,"TIP4P hydrogen is missing"); if (type[jH1] != typeH || type[jH2] != typeH) error->one(FLERR,"TIP4P hydrogen has incorrect atom type"); // set jH1,jH2 to closest image to O jH1 = domain->closest_image(j,jH1); jH2 = domain->closest_image(j,jH2); compute_newsite_thr(x[j],x[jH1],x[jH2],newsite_thr[j]); hneigh_thr[j].t = 1; hneigh_thr[j].b = jH2; hneigh_thr[j].a = jH1; } else { jH1 = hneigh_thr[j].a; jH2 = hneigh_thr[j].b; if (hneigh_thr[j].t == 0) { compute_newsite_thr(x[j],x[jH1],x[jH2],newsite_thr[j]); hneigh_thr[j].t = 1; } } x2 = newsite_thr[j]; } else x2 = x[j]; delx = x1.x - x2.x; dely = x1.y - x2.y; delz = x1.z - x2.z; rsq = delx*delx + dely*dely + delz*delz; } // test current rsq against cutoff and compute Coulombic force if ((rsq < cut_coulsq) && ORDER1) { frespa = 1.0; // check whether and how to compute respa corrections respa_flag = rsq < cut_in_on_sq ? 1 : 0; if (respa_flag && (rsq > cut_in_off_sq)) { register double rsw = (sqrt(rsq)-cut_in_off)/cut_in_diff; frespa = 1-rsw*rsw*(3.0-2.0*rsw); } r2inv = 1.0 / rsq; if (!CTABLE || rsq <= tabinnersq) { // series real space register double r = sqrt(rsq), s = qri*q[j]; if (respa_flag) // correct for respa respa_coul = ni == 0 ? frespa*s/r : frespa*s/r*special_coul[ni]; register double x = g_ewald*r, t = 1.0/(1.0+EWALD_P*x); if (ni == 0) { s *= g_ewald*exp(-x*x); forcecoul = (t *= ((((t*A5+A4)*t+A3)*t+A2)*t+A1)*s/x)+EWALD_F*s-respa_coul; if (EFLAG) ecoul = t; } else { // correct for special r = s*(1.0-special_coul[ni])/r; s *= g_ewald*exp(-x*x); forcecoul = (t *= ((((t*A5+A4)*t+A3)*t+A2)*t+A1)*s/x)+EWALD_F*s-r-respa_coul; if (EFLAG) ecoul = t-r; } } // table real space else { if (respa_flag) { register double r = sqrt(rsq), s = qri*q[j]; respa_coul = ni == 0 ? frespa*s/r : frespa*s/r*special_coul[ni]; } register union_int_float_t t; t.f = rsq; register const int k = (t.i & ncoulmask) >> ncoulshiftbits; register double f = (t.f-rtable[k])*drtable[k], qiqj = qtmp*q[j]; if (ni == 0) { forcecoul = qiqj*(ftable[k]+f*dftable[k]); if (EFLAG) ecoul = qiqj*(etable[k]+f*detable[k]); } else { // correct for special t.f = (1.0-special_coul[ni])*(ctable[k]+f*dctable[k]); forcecoul = qiqj*(ftable[k]+f*dftable[k]-t.f); if (EFLAG) { t.f = (1.0-special_coul[ni])*(ptable[k]+f*dptable[k]); ecoul = qiqj*(etable[k]+f*detable[k]-t.f); } } } cforce = forcecoul * r2inv; fvirial = (forcecoul + respa_coul) * r2inv; // if i,j are not O atoms, force is applied directly // if i or j are O atoms, force is on fictitious atom & partitioned // force partitioning due to Feenstra, J Comp Chem, 20, 786 (1999) // f_f = fictitious force, fO = f_f (1 - 2 alpha), fH = alpha f_f // preserves total force and torque on water molecule // virial = sum(r x F) where each water's atoms are near xi and xj // vlist stores 2,4,6 atoms whose forces contribute to virial if (EVFLAG && vflag) { n = 0; key = 0; } if (itype != typeO) { fxtmp += delx * cforce; fytmp += dely * cforce; fztmp += delz * cforce; if (EVFLAG && vflag) { v[0] = x[i].x * delx * fvirial; v[1] = x[i].y * dely * fvirial; v[2] = x[i].z * delz * fvirial; v[3] = x[i].x * dely * fvirial; v[4] = x[i].x * delz * fvirial; v[5] = x[i].y * delz * fvirial; vlist[n++] = i; } } else { if (EVFLAG && vflag) key += 1; fdx = delx*cforce; fdy = dely*cforce; fdz = delz*cforce; fOx = fdx*(1 - alpha); fOy = fdy*(1 - alpha); fOz = fdz*(1 - alpha); fHx = 0.5*alpha * fdx; fHy = 0.5*alpha * fdy; fHz = 0.5*alpha * fdz; fxtmp += fOx; fytmp += fOy; fztmp += fOz; f[iH1].x += fHx; f[iH1].y += fHy; f[iH1].z += fHz; f[iH2].x += fHx; f[iH2].y += fHy; f[iH2].z += fHz; if (EVFLAG && vflag) { xH1 = x[iH1]; xH2 = x[iH2]; fdx = delx*fvirial; fdy = dely*fvirial; fdz = delz*fvirial; fOx = fdx*(1 - alpha); fOy = fdy*(1 - alpha); fOz = fdz*(1 - alpha); fHx = 0.5 * alpha * fdx; fHy = 0.5 * alpha * fdy; fHz = 0.5 * alpha * fdz; v[0] = x[i].x*fOx + xH1.x*fHx + xH2.x*fHx; v[1] = x[i].y*fOy + xH1.y*fHy + xH2.y*fHy; v[2] = x[i].z*fOz + xH1.z*fHz + xH2.z*fHz; v[3] = x[i].x*fOy + xH1.x*fHy + xH2.x*fHy; v[4] = x[i].x*fOz + xH1.x*fHz + xH2.x*fHz; v[5] = x[i].y*fOz + xH1.y*fHz + xH2.y*fHz; vlist[n++] = i; vlist[n++] = iH1; vlist[n++] = iH2; } } if (jtype != typeO) { f[j].x -= delx * cforce; f[j].y -= dely * cforce; f[j].z -= delz * cforce; if (EVFLAG && vflag) { v[0] -= x[j].x * delx * fvirial; v[1] -= x[j].y * dely * fvirial; v[2] -= x[j].z * delz * fvirial; v[3] -= x[j].x * dely * fvirial; v[4] -= x[j].x * delz * fvirial; v[5] -= x[j].y * delz * fvirial; vlist[n++] = j; } } else { if (EVFLAG && vflag) key += 2; fdx = -delx*cforce; fdy = -dely*cforce; fdz = -delz*cforce; fOx = fdx*(1 - alpha); fOy = fdy*(1 - alpha); fOz = fdz*(1 - alpha); fHx = 0.5 * alpha * fdx; fHy = 0.5 * alpha * fdy; fHz = 0.5 * alpha * fdz; f[j].x += fOx; f[j].y += fOy; f[j].z += fOz; f[jH1].x += fHx; f[jH1].y += fHy; f[jH1].z += fHz; f[jH2].x += fHx; f[jH2].y += fHy; f[jH2].z += fHz; if (EVFLAG && vflag) { xH1 = x[jH1]; xH2 = x[jH2]; fdx = -delx*fvirial; fdy = -dely*fvirial; fdz = -delz*fvirial; fOx = fdx*(1 - alpha); fOy = fdy*(1 - alpha); fOz = fdz*(1 - alpha); fHx = 0.5 * alpha * fdx; fHy = 0.5 * alpha * fdy; fHz = 0.5 * alpha * fdz; v[0] += x[j].x*fOx + xH1.x*fHx + xH2.x*fHx; v[1] += x[j].y*fOy + xH1.y*fHy + xH2.y*fHy; v[2] += x[j].z*fOz + xH1.z*fHz + xH2.z*fHz; v[3] += x[j].x*fOy + xH1.x*fHy + xH2.x*fHy; v[4] += x[j].x*fOz + xH1.x*fHz + xH2.x*fHz; v[5] += x[j].y*fOz + xH1.y*fHz + xH2.y*fHz; vlist[n++] = j; vlist[n++] = jH1; vlist[n++] = jH2; } } if (EVFLAG) ev_tally_list_thr(this,key,vlist,v,ecoul,alpha,thr); } } } f[i].x += fxtmp; f[i].y += fytmp; f[i].z += fztmp; } } /* ---------------------------------------------------------------------- compute position xM of fictitious charge site for O atom and 2 H atoms return it as xM ------------------------------------------------------------------------- */ void PairLJLongTIP4PLongOMP::compute_newsite_thr(const dbl3_t &xO, const dbl3_t &xH1, const dbl3_t &xH2, dbl3_t &xM) const { double delx1 = xH1.x - xO.x; double dely1 = xH1.y - xO.y; double delz1 = xH1.z - xO.z; double delx2 = xH2.x - xO.x; double dely2 = xH2.y - xO.y; double delz2 = xH2.z - xO.z; const double prefac = alpha * 0.5; xM.x = xO.x + prefac * (delx1 + delx2); xM.y = xO.y + prefac * (dely1 + dely2); xM.z = xO.z + prefac * (delz1 + delz2); } /* ---------------------------------------------------------------------- */ double PairLJLongTIP4PLongOMP::memory_usage() { double bytes = memory_usage_thr(); bytes += PairLJLongTIP4PLong::memory_usage(); return bytes; } diff --git a/src/USER-OMP/respa_omp.cpp b/src/USER-OMP/respa_omp.cpp index 738538a20..aa4aa65a4 100644 --- a/src/USER-OMP/respa_omp.cpp +++ b/src/USER-OMP/respa_omp.cpp @@ -1,423 +1,429 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- Contributing authors: Mark Stevens (SNL), Paul Crozier (SNL) ------------------------------------------------------------------------- */ #include #include #include "respa_omp.h" #include "neighbor.h" #include "domain.h" #include "comm.h" #include "atom.h" #include "force.h" #include "pair.h" #include "bond.h" #include "angle.h" #include "dihedral.h" #include "improper.h" #include "kspace.h" #include "output.h" #include "update.h" #include "modify.h" #include "compute.h" #include "fix_respa.h" #include "timer.h" #include "memory.h" #include "error.h" #if defined(_OPENMP) #include #endif using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ RespaOMP::RespaOMP(LAMMPS *lmp, int narg, char **arg) : Respa(lmp, narg, arg),ThrOMP(lmp, THR_INTGR) { } /* ---------------------------------------------------------------------- initialization before run ------------------------------------------------------------------------- */ void RespaOMP::init() { Respa::init(); if (atom->torque) error->all(FLERR,"Extended particles are not supported by respa/omp\n"); } /* ---------------------------------------------------------------------- setup before run ------------------------------------------------------------------------- */ void RespaOMP::setup() { if (comm->me == 0 && screen) { fprintf(screen,"Setting up r-RESPA/omp run ...\n"); fprintf(screen," Unit style : %s\n", update->unit_style); fprintf(screen," Current step : " BIGINT_FORMAT "\n", update->ntimestep); fprintf(screen," Time steps :"); for (int ilevel=0; ilevel < nlevels; ++ilevel) fprintf(screen," %d:%g",ilevel+1, step[ilevel]); fprintf(screen,"\n r-RESPA fixes :"); for (int l=0; l < modify->n_post_force_respa; ++l) { Fix *f = modify->fix[modify->list_post_force_respa[l]]; if (f->respa_level >= 0) fprintf(screen," %d:%s[%s]", MIN(f->respa_level+1,nlevels),f->style,f->id); } fprintf(screen,"\n"); timer->print_timeout(screen); } update->setupflag = 1; // setup domain, communication and neighboring // acquire ghosts // build neighbor lists atom->setup(); modify->setup_pre_exchange(); if (triclinic) domain->x2lamda(atom->nlocal); domain->pbc(); domain->reset_box(); comm->setup(); if (neighbor->style) neighbor->setup_bins(); comm->exchange(); if (atom->sortfreq > 0) atom->sort(); comm->borders(); if (triclinic) domain->lamda2x(atom->nlocal+atom->nghost); domain->image_check(); domain->box_too_small_check(); modify->setup_pre_neighbor(); neighbor->build(); + modify->setup_post_neighbor(); neighbor->ncalls = 0; // compute all forces ev_set(update->ntimestep); for (int ilevel = 0; ilevel < nlevels; ilevel++) { force_clear(newton[ilevel]); modify->setup_pre_force_respa(vflag,ilevel); if (nhybrid_styles > 0) { set_compute_flags(ilevel); force->pair->compute(eflag,vflag); } if (level_pair == ilevel && pair_compute_flag) force->pair->compute(eflag,vflag); if (level_inner == ilevel && pair_compute_flag) force->pair->compute_inner(); if (level_middle == ilevel && pair_compute_flag) force->pair->compute_middle(); if (level_outer == ilevel && pair_compute_flag) force->pair->compute_outer(eflag,vflag); if (level_bond == ilevel && force->bond) force->bond->compute(eflag,vflag); if (level_angle == ilevel && force->angle) force->angle->compute(eflag,vflag); if (level_dihedral == ilevel && force->dihedral) force->dihedral->compute(eflag,vflag); if (level_improper == ilevel && force->improper) force->improper->compute(eflag,vflag); if (level_kspace == ilevel && force->kspace) { force->kspace->setup(); if (kspace_compute_flag) force->kspace->compute(eflag,vflag); } // reduce forces from per-thread arrays, if needed if (!fix->get_reduced()) { const int nall = atom->nlocal + atom->nghost; const int nthreads = comm->nthreads; #if defined(_OPENMP) #pragma omp parallel default(none) #endif { #if defined(_OPENMP) int tid = omp_get_thread_num(); #else int tid = 0; #endif data_reduce_thr(atom->f[0], nall, nthreads, 3, tid); } fix->did_reduce(); } modify->pre_reverse(eflag,vflag); if (newton[ilevel]) comm->reverse_comm(); copy_f_flevel(ilevel); } sum_flevel_f(); modify->setup(vflag); output->setup(); update->setupflag = 0; } /* ---------------------------------------------------------------------- setup without output flag = 0 = just force calculation flag = 1 = reneighbor and force calculation ------------------------------------------------------------------------- */ void RespaOMP::setup_minimal(int flag) { update->setupflag = 1; // setup domain, communication and neighboring // acquire ghosts // build neighbor lists if (flag) { modify->setup_pre_exchange(); if (triclinic) domain->x2lamda(atom->nlocal); domain->pbc(); domain->reset_box(); comm->setup(); if (neighbor->style) neighbor->setup_bins(); comm->exchange(); comm->borders(); if (triclinic) domain->lamda2x(atom->nlocal+atom->nghost); domain->image_check(); domain->box_too_small_check(); modify->setup_pre_neighbor(); neighbor->build(); + modify->setup_post_neighbor(); neighbor->ncalls = 0; } // compute all forces ev_set(update->ntimestep); for (int ilevel = 0; ilevel < nlevels; ilevel++) { force_clear(newton[ilevel]); modify->setup_pre_force_respa(vflag,ilevel); if (nhybrid_styles > 0) { set_compute_flags(ilevel); force->pair->compute(eflag,vflag); } if (level_pair == ilevel && pair_compute_flag) force->pair->compute(eflag,vflag); if (level_inner == ilevel && pair_compute_flag) force->pair->compute_inner(); if (level_middle == ilevel && pair_compute_flag) force->pair->compute_middle(); if (level_outer == ilevel && pair_compute_flag) force->pair->compute_outer(eflag,vflag); if (level_bond == ilevel && force->bond) force->bond->compute(eflag,vflag); if (level_angle == ilevel && force->angle) force->angle->compute(eflag,vflag); if (level_dihedral == ilevel && force->dihedral) force->dihedral->compute(eflag,vflag); if (level_improper == ilevel && force->improper) force->improper->compute(eflag,vflag); if (level_kspace == ilevel && force->kspace) { force->kspace->setup(); if (kspace_compute_flag) force->kspace->compute(eflag,vflag); } // reduce forces from per-thread arrays, if needed if (!fix->get_reduced()) { const int nall = atom->nlocal + atom->nghost; const int nthreads = comm->nthreads; #if defined(_OPENMP) #pragma omp parallel default(none) #endif { #if defined(_OPENMP) int tid = omp_get_thread_num(); #else int tid = 0; #endif data_reduce_thr(atom->f[0], nall, nthreads, 3, tid); } fix->did_reduce(); } modify->pre_reverse(eflag,vflag); if (newton[ilevel]) comm->reverse_comm(); copy_f_flevel(ilevel); } sum_flevel_f(); modify->setup(vflag); update->setupflag = 0; } /* ---------------------------------------------------------------------- */ void RespaOMP::recurse(int ilevel) { copy_flevel_f(ilevel); for (int iloop = 0; iloop < loop[ilevel]; iloop++) { timer->stamp(); modify->initial_integrate_respa(vflag,ilevel,iloop); if (modify->n_post_integrate_respa) modify->post_integrate_respa(ilevel,iloop); timer->stamp(Timer::MODIFY); // at outermost level, check on rebuilding neighbor list // at innermost level, communicate // at middle levels, do nothing if (ilevel == nlevels-1) { int nflag = neighbor->decide(); if (nflag) { if (modify->n_pre_exchange) { timer->stamp(); modify->pre_exchange(); timer->stamp(Timer::MODIFY); } if (triclinic) domain->x2lamda(atom->nlocal); domain->pbc(); if (domain->box_change) { domain->reset_box(); comm->setup(); if (neighbor->style) neighbor->setup_bins(); } timer->stamp(); comm->exchange(); if (atom->sortfreq > 0 && update->ntimestep >= atom->nextsort) atom->sort(); comm->borders(); if (triclinic) domain->lamda2x(atom->nlocal+atom->nghost); timer->stamp(Timer::COMM); if (modify->n_pre_neighbor) { modify->pre_neighbor(); timer->stamp(Timer::MODIFY); } neighbor->build(); timer->stamp(Timer::NEIGH); + if (modify->n_post_neighbor) { + modify->post_neighbor(); + timer->stamp(Timer::MODIFY); + } } else if (ilevel == 0) { timer->stamp(); comm->forward_comm(); timer->stamp(Timer::COMM); } } else if (ilevel == 0) { timer->stamp(); comm->forward_comm(); timer->stamp(Timer::COMM); } // rRESPA recursion thru all levels // this used to be before neigh list build, // which prevented per-atom energy/stress being tallied correctly // b/c atoms migrated to new procs between short/long force calls // now they migrate at very start of rRESPA timestep, before all forces if (ilevel) recurse(ilevel-1); // force computations // important that ordering is same as Verlet // so that any order dependencies are the same // when potentials are invoked at same level force_clear(newton[ilevel]); if (modify->n_pre_force_respa) { timer->stamp(); modify->pre_force_respa(vflag,ilevel,iloop); timer->stamp(Timer::MODIFY); } timer->stamp(); if (nhybrid_styles > 0) { set_compute_flags(ilevel); force->pair->compute(eflag,vflag); timer->stamp(Timer::PAIR); } if (level_pair == ilevel && pair_compute_flag) { force->pair->compute(eflag,vflag); timer->stamp(Timer::PAIR); } if (level_inner == ilevel && pair_compute_flag) { force->pair->compute_inner(); timer->stamp(Timer::PAIR); } if (level_middle == ilevel && pair_compute_flag) { force->pair->compute_middle(); timer->stamp(Timer::PAIR); } if (level_outer == ilevel && pair_compute_flag) { force->pair->compute_outer(eflag,vflag); timer->stamp(Timer::PAIR); } if (level_bond == ilevel && force->bond) { force->bond->compute(eflag,vflag); timer->stamp(Timer::BOND); } if (level_angle == ilevel && force->angle) { force->angle->compute(eflag,vflag); timer->stamp(Timer::BOND); } if (level_dihedral == ilevel && force->dihedral) { force->dihedral->compute(eflag,vflag); timer->stamp(Timer::BOND); } if (level_improper == ilevel && force->improper) { force->improper->compute(eflag,vflag); timer->stamp(Timer::BOND); } if (level_kspace == ilevel && kspace_compute_flag) { force->kspace->compute(eflag,vflag); timer->stamp(Timer::KSPACE); } // reduce forces from per-thread arrays, if needed if (!fix->get_reduced()) { const int nall = atom->nlocal + atom->nghost; const int nthreads = comm->nthreads; #if defined(_OPENMP) #pragma omp parallel default(none) #endif { #if defined(_OPENMP) int tid = omp_get_thread_num(); #else int tid = 0; #endif data_reduce_thr(atom->f[0], nall, nthreads, 3, tid); } fix->did_reduce(); } if (modify->n_pre_reverse) { modify->pre_reverse(eflag,vflag); timer->stamp(Timer::MODIFY); } if (newton[ilevel]) { comm->reverse_comm(); timer->stamp(Timer::COMM); } timer->stamp(); if (modify->n_post_force_respa) modify->post_force_respa(vflag,ilevel,iloop); modify->final_integrate_respa(ilevel,iloop); timer->stamp(Timer::MODIFY); } copy_f_flevel(ilevel); } diff --git a/src/fix.h b/src/fix.h index 3f3289530..21dfc955a 100644 --- a/src/fix.h +++ b/src/fix.h @@ -1,288 +1,293 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #ifndef LMP_FIX_H #define LMP_FIX_H #include "pointers.h" namespace LAMMPS_NS { class Fix : protected Pointers { public: static int instance_total; // # of Fix classes ever instantiated char *id,*style; int igroup,groupbit; int restart_global; // 1 if Fix saves global state, 0 if not int restart_peratom; // 1 if Fix saves peratom state, 0 if not int restart_file; // 1 if Fix writes own restart file, 0 if not int force_reneighbor; // 1 if Fix forces reneighboring, 0 if not int box_change_size; // 1 if Fix changes box size, 0 if not int box_change_shape; // 1 if Fix changes box shape, 0 if not int box_change_domain; // 1 if Fix changes proc sub-domains, 0 if not bigint next_reneighbor; // next timestep to force a reneighboring int thermo_energy; // 1 if fix_modify enabled ThEng, 0 if not int thermo_virial; // 1 if fix_modify enabled ThVir, 0 if not int nevery; // how often to call an end_of_step fix int rigid_flag; // 1 if Fix integrates rigid bodies, 0 if not int peatom_flag; // 1 if Fix contributes per-atom eng, 0 if not int virial_flag; // 1 if Fix contributes to virial, 0 if not int no_change_box; // 1 if cannot swap ortho <-> triclinic int time_integrate; // 1 if fix performs time integration, 0 if no int time_depend; // 1 if requires continuous timestepping int create_attribute; // 1 if fix stores attributes that need // setting when a new atom is created int restart_pbc; // 1 if fix moves atoms (except integrate) // so write_restart must remap to PBC int wd_header; // # of header values fix writes to data file int wd_section; // # of sections fix writes to data file int dynamic_group_allow; // 1 if can be used with dynamic group, else 0 int dof_flag; // 1 if has dof() method (not min_dof()) int special_alter_flag; // 1 if has special_alter() meth for spec lists int enforce2d_flag; // 1 if has enforce2d method int respa_level_support; // 1 if fix supports fix_modify respa int respa_level; // which respa level to apply fix (1-Nrespa) int scalar_flag; // 0/1 if compute_scalar() function exists int vector_flag; // 0/1 if compute_vector() function exists int array_flag; // 0/1 if compute_array() function exists int size_vector; // length of global vector int size_array_rows; // rows in global array int size_array_cols; // columns in global array int size_vector_variable; // 1 if vec length is unknown in advance int size_array_rows_variable; // 1 if array rows is unknown in advance int global_freq; // frequency s/v data is available at int peratom_flag; // 0/1 if per-atom data is stored int size_peratom_cols; // 0 = vector, N = columns in peratom array int peratom_freq; // frequency per-atom data is available at int local_flag; // 0/1 if local data is stored int size_local_rows; // rows in local vector or array int size_local_cols; // 0 = vector, N = columns in local array int local_freq; // frequency local data is available at int extscalar; // 0/1 if global scalar is intensive/extensive int extvector; // 0/1/-1 if global vector is all int/ext/extlist int *extlist; // list of 0/1 int/ext for each vec component int extarray; // 0/1 if global array is intensive/extensive double *vector_atom; // computed per-atom vector double **array_atom; // computed per-atom array double *vector_local; // computed local vector double **array_local; // computed local array int comm_forward; // size of forward communication (0 if none) int comm_reverse; // size of reverse communication (0 if none) int comm_border; // size of border communication (0 if none) double virial[6]; // accumulated virial double *eatom,**vatom; // accumulated per-atom energy/virial int restart_reset; // 1 if restart just re-initialized fix // KOKKOS host/device flag and data masks int kokkosable; // 1 if Kokkos fix ExecutionSpace execution_space; unsigned int datamask_read,datamask_modify; Fix(class LAMMPS *, int, char **); virtual ~Fix(); void modify_params(int, char **); virtual int setmask() = 0; virtual void post_constructor() {} virtual void init() {} virtual void init_list(int, class NeighList *) {} virtual void setup(int) {} virtual void setup_pre_exchange() {} virtual void setup_pre_neighbor() {} + virtual void setup_post_neighbor() {} virtual void setup_pre_force(int) {} virtual void setup_pre_reverse(int, int) {} virtual void min_setup(int) {} virtual void initial_integrate(int) {} virtual void post_integrate() {} virtual void pre_exchange() {} virtual void pre_neighbor() {} + virtual void post_neighbor() {} virtual void pre_force(int) {} virtual void pre_reverse(int,int) {} virtual void post_force(int) {} virtual void final_integrate() {} virtual void end_of_step() {} virtual void post_run() {} virtual void write_restart(FILE *) {} virtual void write_restart_file(char *) {} virtual void restart(char *) {} virtual void grow_arrays(int) {} virtual void copy_arrays(int, int, int) {} virtual void set_arrays(int) {} virtual void update_arrays(int, int) {} virtual void set_molecule(int, tagint, int, double *, double *, double *) {} virtual void clear_bonus() {} virtual int pack_border(int, int *, double *) {return 0;} virtual int unpack_border(int, int, double *) {return 0;} virtual int pack_exchange(int, double *) {return 0;} virtual int unpack_exchange(int, double *) {return 0;} virtual int pack_restart(int, double *) {return 0;} virtual void unpack_restart(int, int) {} virtual int size_restart(int) {return 0;} virtual int maxsize_restart() {return 0;} virtual void setup_pre_force_respa(int, int) {} virtual void initial_integrate_respa(int, int, int) {} virtual void post_integrate_respa(int, int) {} virtual void pre_force_respa(int, int, int) {} virtual void post_force_respa(int, int, int) {} virtual void final_integrate_respa(int, int) {} virtual void min_pre_exchange() {} virtual void min_pre_neighbor() {} + virtual void min_post_neighbor() {} virtual void min_pre_force(int) {} virtual void min_pre_reverse(int,int) {} virtual void min_post_force(int) {} virtual double min_energy(double *) {return 0.0;} virtual void min_store() {} virtual void min_clearstore() {} virtual void min_pushstore() {} virtual void min_popstore() {} virtual int min_reset_ref() {return 0;} virtual void min_step(double, double *) {} virtual double max_alpha(double *) {return 0.0;} virtual int min_dof() {return 0;} virtual int pack_forward_comm(int, int *, double *, int, int *) {return 0;} virtual void unpack_forward_comm(int, int, double *) {} virtual int pack_reverse_comm_size(int, int) {return 0;} virtual int pack_reverse_comm(int, int, double *) {return 0;} virtual void unpack_reverse_comm(int, int *, double *) {} virtual double compute_scalar() {return 0.0;} virtual double compute_vector(int) {return 0.0;} virtual double compute_array(int,int) {return 0.0;} virtual int dof(int) {return 0;} virtual void deform(int) {} virtual void reset_target(double) {} virtual void reset_dt() {} virtual void enforce2d() {} virtual void read_data_header(char *) {} virtual void read_data_section(char *, int, char *, tagint) {} virtual bigint read_data_skip_lines(char *) {return 0;} virtual void write_data_header(FILE *, int) {} virtual void write_data_section_size(int, int &, int &) {} virtual void write_data_section_pack(int, double **) {} virtual void write_data_section_keyword(int, FILE *) {} virtual void write_data_section(int, FILE *, int, double **, int) {} virtual void zero_momentum() {} virtual void zero_rotation() {} virtual void rebuild_special() {} virtual int image(int *&, double **&) {return 0;} virtual int modify_param(int, char **) {return 0;} virtual void *extract(const char *, int &) {return NULL;} virtual double memory_usage() {return 0.0;} protected: int instance_me; // which Fix class instantiation I am int evflag; int eflag_either,eflag_global,eflag_atom; int vflag_either,vflag_global,vflag_atom; int maxeatom,maxvatom; int copymode; // if set, do not deallocate during destruction // required when classes are used as functors by Kokkos int dynamic; // recount atoms for temperature computes void ev_setup(int, int); void ev_tally(int, int *, double, double, double *); void v_setup(int); void v_tally(int, int *, double, double *); void v_tally(int, double *); void v_tally(int, int, double); // union data struct for packing 32-bit and 64-bit ints into double bufs // see atom_vec.h for documentation union ubuf { double d; int64_t i; ubuf(double arg) : d(arg) {} ubuf(int64_t arg) : i(arg) {} ubuf(int arg) : i(arg) {} }; }; namespace FixConst { static const int INITIAL_INTEGRATE = 1<<0; static const int POST_INTEGRATE = 1<<1; static const int PRE_EXCHANGE = 1<<2; static const int PRE_NEIGHBOR = 1<<3; - static const int PRE_FORCE = 1<<4; - static const int PRE_REVERSE = 1<<5; - static const int POST_FORCE = 1<<6; - static const int FINAL_INTEGRATE = 1<<7; - static const int END_OF_STEP = 1<<8; - static const int POST_RUN = 1<<9; - static const int THERMO_ENERGY = 1<<10; - static const int INITIAL_INTEGRATE_RESPA = 1<<11; - static const int POST_INTEGRATE_RESPA = 1<<12; - static const int PRE_FORCE_RESPA = 1<<13; - static const int POST_FORCE_RESPA = 1<<14; - static const int FINAL_INTEGRATE_RESPA = 1<<15; - static const int MIN_PRE_EXCHANGE = 1<<16; - static const int MIN_PRE_NEIGHBOR = 1<<17; - static const int MIN_PRE_FORCE = 1<<18; - static const int MIN_PRE_REVERSE = 1<<19; - static const int MIN_POST_FORCE = 1<<20; - static const int MIN_ENERGY = 1<<21; - static const int FIX_CONST_LAST = 1<<22; + static const int POST_NEIGHBOR = 1<<4; + static const int PRE_FORCE = 1<<5; + static const int PRE_REVERSE = 1<<6; + static const int POST_FORCE = 1<<7; + static const int FINAL_INTEGRATE = 1<<8; + static const int END_OF_STEP = 1<<9; + static const int POST_RUN = 1<<10; + static const int THERMO_ENERGY = 1<<11; + static const int INITIAL_INTEGRATE_RESPA = 1<<12; + static const int POST_INTEGRATE_RESPA = 1<<13; + static const int PRE_FORCE_RESPA = 1<<14; + static const int POST_FORCE_RESPA = 1<<15; + static const int FINAL_INTEGRATE_RESPA = 1<<16; + static const int MIN_PRE_EXCHANGE = 1<<17; + static const int MIN_PRE_NEIGHBOR = 1<<18; + static const int MIN_POST_NEIGHBOR = 1<<19; + static const int MIN_PRE_FORCE = 1<<20; + static const int MIN_PRE_REVERSE = 1<<21; + static const int MIN_POST_FORCE = 1<<22; + static const int MIN_ENERGY = 1<<23; + static const int FIX_CONST_LAST = 1<<24; } } #endif /* ERROR/WARNING messages: E: Fix ID must be alphanumeric or underscore characters Self-explanatory. E: Could not find fix group ID A group ID used in the fix command does not exist. E: Illegal ... command Self-explanatory. Check the input script syntax and compare to the documentation for the command. You can use -echo screen as a command-line option when running LAMMPS to see the offending line. */ diff --git a/src/fix_shear_history.cpp b/src/fix_neigh_history.cpp similarity index 55% rename from src/fix_shear_history.cpp rename to src/fix_neigh_history.cpp index 17e78830f..de94fbece 100644 --- a/src/fix_shear_history.cpp +++ b/src/fix_neigh_history.cpp @@ -1,764 +1,896 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include #include #include -#include "fix_shear_history.h" +#include "fix_neigh_history.h" #include "atom.h" #include "comm.h" #include "neighbor.h" #include "neigh_list.h" #include "force.h" #include "pair.h" #include "update.h" #include "modify.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; using namespace FixConst; enum{DEFAULT,NPARTNER,PERPARTNER}; /* ---------------------------------------------------------------------- */ -FixShearHistory::FixShearHistory(LAMMPS *lmp, int narg, char **arg) : +FixNeighHistory::FixNeighHistory(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), - npartner(NULL), partner(NULL), shearpartner(NULL), pair(NULL), - ipage(NULL), dpage(NULL) + npartner(NULL), partner(NULL), valuepartner(NULL), pair(NULL), + ipage_atom(NULL), dpage_atom(NULL), ipage_neigh(NULL), dpage_neigh(NULL) { - if (narg != 4) error->all(FLERR,"Illegal fix SHEAR_HISTORY command"); + if (narg != 4) error->all(FLERR,"Illegal fix NEIGH_HISTORY command"); restart_peratom = 1; create_attribute = 1; newton_pair = force->newton_pair; dnum = force->inumeric(FLERR,arg[3]); dnumbytes = dnum * sizeof(double); + zeroes = new double[dnum]; + for (int i = 0; i < dnum; i++) zeroes[i] = 0.0; + onesided = 0; - if (strcmp(id,"LINE_SHEAR_HISTORY") == 0) onesided = 1; - if (strcmp(id,"TRI_SHEAR_HISTORY") == 0) onesided = 1; + if (strcmp(id,"LINE_NEIGH_HISTORY") == 0) onesided = 1; + if (strcmp(id,"TRI_NEIGH_HISTORY") == 0) onesided = 1; if (newton_pair) comm_reverse = 1; // just for single npartner value // variable-size history communicated via // reverse_comm_fix_variable() // perform initial allocation of atom-based arrays // register with atom class grow_arrays(atom->nmax); atom->add_callback(0); atom->add_callback(1); pgsize = oneatom = 0; + // other per-atom vectors + + firstflag = NULL; + firstvalue = NULL; + maxatom = 0; + + // per-atom and per-neighbor data structs + + ipage_atom = NULL; + dpage_atom = NULL; + ipage_neigh = NULL; + dpage_neigh = NULL; + // initialize npartner to 0 so neighbor list creation is OK the 1st time int nlocal = atom->nlocal; for (int i = 0; i < nlocal; i++) npartner[i] = 0; - maxtouch = 0; + maxpartner = 0; nlocal_neigh = nall_neigh = 0; commflag = DEFAULT; } /* ---------------------------------------------------------------------- */ -FixShearHistory::~FixShearHistory() +FixNeighHistory::~FixNeighHistory() { // unregister this fix so atom class doesn't invoke it any more atom->delete_callback(id,0); atom->delete_callback(id,1); // delete locally stored arrays + delete [] zeroes; + + memory->sfree(firstflag); + memory->sfree(firstvalue); + memory->destroy(npartner); memory->sfree(partner); - memory->sfree(shearpartner); + memory->sfree(valuepartner); + + delete [] ipage_atom; + delete [] dpage_atom; + delete [] ipage_neigh; + delete [] dpage_neigh; // to better detect use-after-delete errors + firstflag = NULL; + firstvalue = NULL; + pair = NULL; npartner = NULL; partner = NULL; - shearpartner = NULL; - - delete [] ipage; - delete [] dpage; + valuepartner = NULL; } /* ---------------------------------------------------------------------- */ -int FixShearHistory::setmask() +int FixNeighHistory::setmask() { int mask = 0; mask |= PRE_EXCHANGE; mask |= MIN_PRE_EXCHANGE; + mask |= POST_NEIGHBOR; + mask |= MIN_POST_NEIGHBOR; return mask; } /* ---------------------------------------------------------------------- */ -void FixShearHistory::init() +void FixNeighHistory::init() { if (atom->tag_enable == 0) - error->all(FLERR,"Granular shear history requires atoms have IDs"); + error->all(FLERR,"Neighbor history requires atoms have IDs"); allocate_pages(); } /* ---------------------------------------------------------------------- create pages if first time or if neighbor pgsize/oneatom has changed - note that latter could cause shear history info to be discarded + note that latter could cause neighbor history info to be discarded ------------------------------------------------------------------------- */ -void FixShearHistory::allocate_pages() +void FixNeighHistory::allocate_pages() { int create = 0; - if (ipage == NULL) create = 1; + if (ipage_atom == NULL) create = 1; if (pgsize != neighbor->pgsize) create = 1; if (oneatom != neighbor->oneatom) create = 1; if (create) { - delete [] ipage; - delete [] dpage; + delete [] ipage_atom; + delete [] dpage_atom; + delete [] ipage_neigh; + delete [] dpage_neigh; pgsize = neighbor->pgsize; oneatom = neighbor->oneatom; int nmypage = comm->nthreads; - ipage = new MyPage[nmypage]; - dpage = new MyPage[nmypage]; + ipage_atom = new MyPage[nmypage]; + dpage_atom = new MyPage[nmypage]; + ipage_neigh = new MyPage[nmypage]; + dpage_neigh = new MyPage[nmypage]; for (int i = 0; i < nmypage; i++) { - ipage[i].init(oneatom,pgsize); - dpage[i].init(dnum*oneatom,dnum*pgsize); + ipage_atom[i].init(oneatom,pgsize); + dpage_atom[i].init(dnum*oneatom,dnum*pgsize); + ipage_neigh[i].init(oneatom,pgsize); + dpage_neigh[i].init(dnum*oneatom,dnum*pgsize); } } } +/* ---------------------------------------------------------------------- */ + +void FixNeighHistory::setup_post_neighbor() +{ + post_neighbor(); +} + /* ---------------------------------------------------------------------- - copy shear partner info from neighbor lists to atom arrays - should be called whenever neighbor list stores current history info - and need to store the info with owned atoms - e.g. so atoms can migrate to new procs or between runs - when atoms may be added or deleted (neighbor list becomes out-of-date) - the next granular neigh list build will put this info back into neigh list + copy partner info from neighbor data structs (NDS) to atom arrays + should be called whenever NDS store current history info + and need to transfer the info to owned atoms + e.g. when atoms migrate to new procs, new neigh list built, or between runs + when atoms may be added or deleted (NDS becomes out-of-date) + the next post_neighbor() will put this info back into new NDS called during run before atom exchanges, including for restart files called at end of run via post_run() do not call during setup of run (setup_pre_exchange) - b/c there is no guarantee of a current neigh list (even on continued run) + b/c there is no guarantee of a current NDS (even on continued run) if run command does a 2nd run with pre = no, then no neigh list will be built, but old neigh list will still have the info onesided and newton on and newton off versions ------------------------------------------------------------------------- */ -void FixShearHistory::pre_exchange() +void FixNeighHistory::pre_exchange() { if (onesided) pre_exchange_onesided(); else if (newton_pair) pre_exchange_newton(); else pre_exchange_no_newton(); } /* ---------------------------------------------------------------------- onesided version for sphere contact with line/tri particles neighbor list has I = sphere, J = line/tri only store history info with spheres ------------------------------------------------------------------------- */ -void FixShearHistory::pre_exchange_onesided() +void FixNeighHistory::pre_exchange_onesided() { int i,j,ii,jj,m,n,inum,jnum; int *ilist,*jlist,*numneigh,**firstneigh; - int *touch,**firsttouch; - double *shear,*allshear,**firstshear; + int *allflags; + double *allvalues,*onevalues; // NOTE: all operations until very end are with nlocal_neigh <= current nlocal // b/c previous neigh list was built with nlocal_neigh // nlocal can be larger if other fixes added atoms at this pre_exchange() - // zero npartner for owned atoms - // clear 2 page data structures - - for (i = 0; i < nlocal_neigh; i++) npartner[i] = 0; + // clear two paged data structures - ipage->reset(); - dpage->reset(); + ipage_atom->reset(); + dpage_atom->reset(); // 1st loop over neighbor list, I = sphere, J = tri // only calculate npartner for owned spheres + for (i = 0; i < nlocal_neigh; i++) npartner[i] = 0; + tagint *tag = atom->tag; NeighList *list = pair->list; inum = list->inum; ilist = list->ilist; numneigh = list->numneigh; firstneigh = list->firstneigh; - firsttouch = list->listhistory->firstneigh; - firstshear = list->listhistory->firstdouble; for (ii = 0; ii < inum; ii++) { i = ilist[ii]; jlist = firstneigh[i]; jnum = numneigh[i]; - touch = firsttouch[i]; + allflags = firstflag[i]; for (jj = 0; jj < jnum; jj++) - if (touch[jj]) npartner[i]++; + if (allflags[jj]) npartner[i]++; } - // get page chunks to store atom IDs and shear history for owned atoms + // get page chunks to store partner IDs and values for owned atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; n = npartner[i]; - partner[i] = ipage->get(n); - shearpartner[i] = dpage->get(dnum*n); - if (partner[i] == NULL || shearpartner[i] == NULL) - error->one(FLERR,"Shear history overflow, boost neigh_modify one"); + partner[i] = ipage_atom->get(n); + valuepartner[i] = dpage_atom->get(dnum*n); + if (partner[i] == NULL || valuepartner[i] == NULL) + error->one(FLERR,"Neighbor history overflow, boost neigh_modify one"); } // 2nd loop over neighbor list, I = sphere, J = tri - // store atom IDs and shear history for owned spheres + // store partner IDs and values for owned+ghost atoms // re-zero npartner to use as counter for (i = 0; i < nlocal_neigh; i++) npartner[i] = 0; for (ii = 0; ii < inum; ii++) { i = ilist[ii]; jlist = firstneigh[i]; - allshear = firstshear[i]; jnum = numneigh[i]; - touch = firsttouch[i]; + allflags = firstflag[i]; + allvalues = firstvalue[i]; for (jj = 0; jj < jnum; jj++) { - if (touch[jj]) { - shear = &allshear[dnum*jj]; + if (allflags[jj]) { + onevalues = &allvalues[dnum*jj]; j = jlist[jj]; j &= NEIGHMASK; m = npartner[i]++; partner[i][m] = tag[j]; - memcpy(&shearpartner[i][dnum*m],shear,dnumbytes); + memcpy(&valuepartner[i][dnum*m],onevalues,dnumbytes); } } } - // set maxtouch = max # of partners of any owned atom + // set maxpartner = max # of partners of any owned atom // bump up comm->maxexchange_fix if necessary - maxtouch = 0; - for (i = 0; i < nlocal_neigh; i++) maxtouch = MAX(maxtouch,npartner[i]); - comm->maxexchange_fix = MAX(comm->maxexchange_fix,(dnum+1)*maxtouch+1); + maxpartner = 0; + for (i = 0; i < nlocal_neigh; i++) maxpartner = MAX(maxpartner,npartner[i]); + comm->maxexchange_fix = MAX(comm->maxexchange_fix,(dnum+1)*maxpartner+1); // zero npartner values from previous nlocal_neigh to current nlocal int nlocal = atom->nlocal; for (i = nlocal_neigh; i < nlocal; i++) npartner[i] = 0; } /* ---------------------------------------------------------------------- - newton on version, for sphere/sphere contacts - performs reverse comm to acquire shear partner info from ghost atoms + newton ON version + performs reverse comm to acquire partner values from ghost atoms ------------------------------------------------------------------------- */ -void FixShearHistory::pre_exchange_newton() +void FixNeighHistory::pre_exchange_newton() { int i,j,ii,jj,m,n,inum,jnum; int *ilist,*jlist,*numneigh,**firstneigh; - int *touch,**firsttouch; - double *shear,*shearj,*allshear,**firstshear; + int *allflags; + double *allvalues,*onevalues,*jvalues; // NOTE: all operations until very end are with // nlocal_neigh <= current nlocal and nall_neigh - // b/c previous neigh list was built with nlocal_neigh,nghost_neigh + // b/c previous neigh list was built with nlocal_neigh & nghost_neigh // nlocal can be larger if other fixes added atoms at this pre_exchange() - // zero npartner for owned+ghost atoms - // clear 2 page data structures - - for (i = 0; i < nall_neigh; i++) npartner[i] = 0; + // clear two paged data structures - ipage->reset(); - dpage->reset(); + ipage_atom->reset(); + dpage_atom->reset(); // 1st loop over neighbor list // calculate npartner for owned+ghost atoms + for (i = 0; i < nall_neigh; i++) npartner[i] = 0; + tagint *tag = atom->tag; NeighList *list = pair->list; inum = list->inum; ilist = list->ilist; numneigh = list->numneigh; firstneigh = list->firstneigh; - firsttouch = list->listhistory->firstneigh; - firstshear = list->listhistory->firstdouble; for (ii = 0; ii < inum; ii++) { i = ilist[ii]; jlist = firstneigh[i]; jnum = numneigh[i]; - touch = firsttouch[i]; + allflags = firstflag[i]; for (jj = 0; jj < jnum; jj++) { - if (touch[jj]) { + if (allflags[jj]) { npartner[i]++; j = jlist[jj]; j &= NEIGHMASK; npartner[j]++; } } } // perform reverse comm to augment owned npartner counts with ghost counts commflag = NPARTNER; comm->reverse_comm_fix(this,0); - // get page chunks to store atom IDs and shear history for owned+ghost atoms + // get page chunks to store partner IDs and values for owned+ghost atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; n = npartner[i]; - partner[i] = ipage->get(n); - shearpartner[i] = dpage->get(dnum*n); - if (partner[i] == NULL || shearpartner[i] == NULL) { - error->one(FLERR,"Shear history overflow, boost neigh_modify one"); + partner[i] = ipage_atom->get(n); + valuepartner[i] = dpage_atom->get(dnum*n); + if (partner[i] == NULL || valuepartner[i] == NULL) { + error->one(FLERR,"Neighbor history overflow, boost neigh_modify one"); } } for (i = nlocal_neigh; i < nall_neigh; i++) { n = npartner[i]; - partner[i] = ipage->get(n); - shearpartner[i] = dpage->get(dnum*n); - if (partner[i] == NULL || shearpartner[i] == NULL) { - error->one(FLERR,"Shear history overflow, boost neigh_modify one"); + partner[i] = ipage_atom->get(n); + valuepartner[i] = dpage_atom->get(dnum*n); + if (partner[i] == NULL || valuepartner[i] == NULL) { + error->one(FLERR,"Neighbor history overflow, boost neigh_modify one"); } } // 2nd loop over neighbor list - // store atom IDs and shear history for owned+ghost atoms + // store partner IDs and values for owned+ghost atoms // re-zero npartner to use as counter for (i = 0; i < nall_neigh; i++) npartner[i] = 0; for (ii = 0; ii < inum; ii++) { i = ilist[ii]; jlist = firstneigh[i]; - allshear = firstshear[i]; jnum = numneigh[i]; - touch = firsttouch[i]; + allflags = firstflag[i]; + allvalues = firstvalue[i]; for (jj = 0; jj < jnum; jj++) { - if (touch[jj]) { - shear = &allshear[dnum*jj]; + if (allflags[jj]) { + onevalues = &allvalues[dnum*jj]; j = jlist[jj]; j &= NEIGHMASK; m = npartner[i]++; partner[i][m] = tag[j]; - memcpy(&shearpartner[i][dnum*m],shear,dnumbytes); + memcpy(&valuepartner[i][dnum*m],onevalues,dnumbytes); m = npartner[j]++; partner[j][m] = tag[i]; - shearj = &shearpartner[j][dnum*m]; - for (n = 0; n < dnum; n++) shearj[n] = -shear[n]; + jvalues = &valuepartner[j][dnum*m]; + for (n = 0; n < dnum; n++) jvalues[n] = -onevalues[n]; } } } // perform reverse comm to augment - // owned atom partner/shearpartner with ghost info + // owned atom partner/valuepartner with ghost info // use variable variant b/c size of packed data can be arbitrarily large // if many touching neighbors for large particle commflag = PERPARTNER; comm->reverse_comm_fix_variable(this); - // set maxtouch = max # of partners of any owned atom + // set maxpartner = max # of partners of any owned atom // bump up comm->maxexchange_fix if necessary - maxtouch = 0; - for (i = 0; i < nlocal_neigh; i++) maxtouch = MAX(maxtouch,npartner[i]); - comm->maxexchange_fix = MAX(comm->maxexchange_fix,(dnum+1)*maxtouch+1); + maxpartner = 0; + for (i = 0; i < nlocal_neigh; i++) maxpartner = MAX(maxpartner,npartner[i]); + comm->maxexchange_fix = MAX(comm->maxexchange_fix,4*maxpartner+1); // zero npartner values from previous nlocal_neigh to current nlocal int nlocal = atom->nlocal; for (i = nlocal_neigh; i < nlocal; i++) npartner[i] = 0; } /* ---------------------------------------------------------------------- - newton off version, for sphere/sphere contacts - newton OFF works with smaller vectors that don't include ghost info + newton OFF version + do not need partner values from ghost atoms + assume J values are negative of I values ------------------------------------------------------------------------- */ -void FixShearHistory::pre_exchange_no_newton() +void FixNeighHistory::pre_exchange_no_newton() { int i,j,ii,jj,m,n,inum,jnum; int *ilist,*jlist,*numneigh,**firstneigh; - int *touch,**firsttouch; - double *shear,*shearj,*allshear,**firstshear; + int *allflags; + double *allvalues,*onevalues,*jvalues; // NOTE: all operations until very end are with nlocal_neigh <= current nlocal // b/c previous neigh list was built with nlocal_neigh // nlocal can be larger if other fixes added atoms at this pre_exchange() - // zero npartner for owned atoms - // clear 2 page data structures - - for (i = 0; i < nlocal_neigh; i++) npartner[i] = 0; + // clear two paged data structures - ipage->reset(); - dpage->reset(); + ipage_atom->reset(); + dpage_atom->reset(); // 1st loop over neighbor list // calculate npartner for owned atoms + for (i = 0; i < nlocal_neigh; i++) npartner[i] = 0; + tagint *tag = atom->tag; NeighList *list = pair->list; inum = list->inum; ilist = list->ilist; numneigh = list->numneigh; firstneigh = list->firstneigh; - firsttouch = list->listhistory->firstneigh; - firstshear = list->listhistory->firstdouble; for (ii = 0; ii < inum; ii++) { i = ilist[ii]; jlist = firstneigh[i]; jnum = numneigh[i]; - touch = firsttouch[i]; + allflags = firstflag[i]; for (jj = 0; jj < jnum; jj++) { - if (touch[jj]) { + if (allflags[jj]) { npartner[i]++; j = jlist[jj]; j &= NEIGHMASK; if (j < nlocal_neigh) npartner[j]++; } } } - // get page chunks to store atom IDs and shear history for owned atoms + // get page chunks to store partner IDs and values for owned atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; n = npartner[i]; - partner[i] = ipage->get(n); - shearpartner[i] = dpage->get(dnum*n); - if (partner[i] == NULL || shearpartner[i] == NULL) - error->one(FLERR,"Shear history overflow, boost neigh_modify one"); + partner[i] = ipage_atom->get(n); + valuepartner[i] = dpage_atom->get(dnum*n); + if (partner[i] == NULL || valuepartner[i] == NULL) + error->one(FLERR,"Neighbor history overflow, boost neigh_modify one"); } // 2nd loop over neighbor list - // store atom IDs and shear history for owned atoms + // store partner IDs and values for owned+ghost atoms // re-zero npartner to use as counter for (i = 0; i < nlocal_neigh; i++) npartner[i] = 0; for (ii = 0; ii < inum; ii++) { i = ilist[ii]; jlist = firstneigh[i]; - allshear = firstshear[i]; jnum = numneigh[i]; - touch = firsttouch[i]; + allflags = firstflag[i]; + allvalues = firstvalue[i]; for (jj = 0; jj < jnum; jj++) { - if (touch[jj]) { - shear = &allshear[dnum*jj]; + if (allflags[jj]) { + onevalues = &allvalues[dnum*jj]; j = jlist[jj]; j &= NEIGHMASK; m = npartner[i]++; partner[i][m] = tag[j]; - memcpy(&shearpartner[i][dnum*m],shear,dnumbytes); + memcpy(&valuepartner[i][dnum*m],onevalues,dnumbytes); if (j < nlocal_neigh) { m = npartner[j]++; partner[j][m] = tag[i]; - shearj = &shearpartner[j][dnum*m]; - for (n = 0; n < dnum; n++) shearj[n] = -shear[n]; + jvalues = &valuepartner[j][dnum*m]; + for (n = 0; n < dnum; n++) jvalues[n] = -onevalues[n]; } } } } - // set maxtouch = max # of partners of any owned atom + // set maxpartner = max # of partners of any owned atom // bump up comm->maxexchange_fix if necessary - maxtouch = 0; - for (i = 0; i < nlocal_neigh; i++) maxtouch = MAX(maxtouch,npartner[i]); - comm->maxexchange_fix = MAX(comm->maxexchange_fix,(dnum+1)*maxtouch+1); + maxpartner = 0; + for (i = 0; i < nlocal_neigh; i++) maxpartner = MAX(maxpartner,npartner[i]); + comm->maxexchange_fix = MAX(comm->maxexchange_fix,(dnum+1)*maxpartner+1); // zero npartner values from previous nlocal_neigh to current nlocal int nlocal = atom->nlocal; for (i = nlocal_neigh; i < nlocal; i++) npartner[i] = 0; } /* ---------------------------------------------------------------------- */ -void FixShearHistory::min_pre_exchange() +void FixNeighHistory::min_pre_exchange() { pre_exchange(); } +/* ---------------------------------------------------------------------- + called after neighbor list is build + recover history info stored temporarily in per-atom partner lists + and store afresh in per-neighbor firstflag and firstvalue lists +------------------------------------------------------------------------- */ + +void FixNeighHistory::post_neighbor() +{ + int i,j,m,ii,jj,nn,np,inum,jnum,rflag; + tagint jtag; + double xtmp,ytmp,ztmp,delx,dely,delz; + double radi,rsq,radsum; + int *ilist,*jlist,*numneigh,**firstneigh; + int *allflags; + double *allvalues; + + // store atom counts used for new neighbor list which was just built + + int nlocal = atom->nlocal; + int nall = nlocal + atom->nghost; + nlocal_neigh = nlocal; + nall_neigh = nall; + + // realloc firstflag and firstvalue if needed + + if (maxatom < nlocal) { + memory->sfree(firstflag); + memory->sfree(firstvalue); + maxatom = nall; + firstflag = (int **) + memory->smalloc(maxatom*sizeof(int *),"neighbor_history:firstflag"); + firstvalue = (double **) + memory->smalloc(maxatom*sizeof(double *),"neighbor_history:firstvalue"); + } + + // loop over newly built neighbor list + // repopulate entire per-neighbor data structs + // whether with old-neigh partner info or zeroes + + ipage_neigh->reset(); + dpage_neigh->reset(); + + tagint *tag = atom->tag; + NeighList *list = pair->list; + inum = list->inum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; + + for (ii = 0; ii < inum; ii++) { + i = ilist[ii]; + jlist = firstneigh[i]; + jnum = numneigh[i]; + firstflag[i] = allflags = ipage_neigh->get(jnum); + firstvalue[i] = allvalues = dpage_neigh->get(jnum*dnum); + np = npartner[i]; + nn = 0; + + for (jj = 0; jj < jnum; jj++) { + j = jlist[jj]; + rflag = sbmask(j); + j &= NEIGHMASK; + jlist[jj] = j; + + // rflag = 1 if r < radsum in npair_size() method + // preserve neigh history info if tag[j] is in old-neigh partner list + // this test could be more geometrically precise for two sphere/line/tri + + if (rflag) { + jtag = tag[j]; + for (m = 0; m < np; m++) + if (partner[i][m] == jtag) break; + if (m < np) { + allflags[jj] = 1; + memcpy(&allvalues[nn],&valuepartner[i][dnum*m],dnumbytes); + } else { + allflags[jj] = 0; + memcpy(&allvalues[nn],zeroes,dnumbytes); + } + } else { + allflags[jj] = 0; + memcpy(&allvalues[nn],zeroes,dnumbytes); + } + nn += dnum; + } + } +} + +/* ---------------------------------------------------------------------- */ + +void FixNeighHistory::min_post_neighbor() +{ + post_neighbor(); +} + /* ---------------------------------------------------------------------- */ -void FixShearHistory::post_run() +void FixNeighHistory::post_run() { pre_exchange(); } /* ---------------------------------------------------------------------- memory usage of local atom-based arrays ------------------------------------------------------------------------- */ -double FixShearHistory::memory_usage() +double FixNeighHistory::memory_usage() { int nmax = atom->nmax; - double bytes = nmax * sizeof(int); - bytes += nmax * sizeof(tagint *); - bytes += nmax * sizeof(double *); + double bytes = nmax * sizeof(int); // npartner + bytes += nmax * sizeof(tagint *); // partner + bytes += nmax * sizeof(double *); // valuepartner + bytes += maxatom * sizeof(int *); // firstflag + bytes += maxatom * sizeof(double *); // firstvalue int nmypage = comm->nthreads; for (int i = 0; i < nmypage; i++) { - bytes += ipage[i].size(); - bytes += dpage[i].size(); + bytes += ipage_atom[i].size(); + bytes += dpage_atom[i].size(); + bytes += ipage_neigh[i].size(); + bytes += dpage_neigh[i].size(); } return bytes; } /* ---------------------------------------------------------------------- allocate local atom-based arrays ------------------------------------------------------------------------- */ -void FixShearHistory::grow_arrays(int nmax) +void FixNeighHistory::grow_arrays(int nmax) { - memory->grow(npartner,nmax,"shear_history:npartner"); + memory->grow(npartner,nmax,"neighbor_history:npartner"); partner = (tagint **) memory->srealloc(partner,nmax*sizeof(tagint *), - "shear_history:partner"); - shearpartner = (double **) memory->srealloc(shearpartner, + "neighbor_history:partner"); + valuepartner = (double **) memory->srealloc(valuepartner, nmax*sizeof(double *), - "shear_history:shearpartner"); + "neighbor_history:valuepartner"); } /* ---------------------------------------------------------------------- copy values within local atom-based arrays ------------------------------------------------------------------------- */ -void FixShearHistory::copy_arrays(int i, int j, int delflag) +void FixNeighHistory::copy_arrays(int i, int j, int delflag) { - // just copy pointers for partner and shearpartner - // b/c can't overwrite chunk allocation inside ipage,dpage + // just copy pointers for partner and valuepartner + // b/c can't overwrite chunk allocation inside ipage_atom,dpage_atom // incoming atoms in unpack_exchange just grab new chunks // so are orphaning chunks for migrating atoms - // OK, b/c will reset ipage,dpage on next reneighboring + // OK, b/c will reset ipage_atom,dpage_atom on next reneighboring npartner[j] = npartner[i]; partner[j] = partner[i]; - shearpartner[j] = shearpartner[i]; + valuepartner[j] = valuepartner[i]; } /* ---------------------------------------------------------------------- initialize one atom's array values, called when atom is created ------------------------------------------------------------------------- */ -void FixShearHistory::set_arrays(int i) +void FixNeighHistory::set_arrays(int i) { npartner[i] = 0; } /* ---------------------------------------------------------------------- only called by Comm::reverse_comm_fix_variable for PERPARTNER mode ------------------------------------------------------------------------- */ -int FixShearHistory::pack_reverse_comm_size(int n, int first) +int FixNeighHistory::pack_reverse_comm_size(int n, int first) { int i,last; int m = 0; last = first + n; for (i = first; i < last; i++) - m += 1 + (dnum+1)*npartner[i]; + m += 1 + 4*npartner[i]; return m; } /* ---------------------------------------------------------------------- two modes: NPARTNER and PERPARTNER ------------------------------------------------------------------------- */ -int FixShearHistory::pack_reverse_comm(int n, int first, double *buf) +int FixNeighHistory::pack_reverse_comm(int n, int first, double *buf) { int i,k,last; int m = 0; last = first + n; if (commflag == NPARTNER) { for (i = first; i < last; i++) { buf[m++] = npartner[i]; } } else if (commflag == PERPARTNER) { for (i = first; i < last; i++) { buf[m++] = npartner[i]; for (k = 0; k < npartner[i]; k++) { buf[m++] = partner[i][k]; - memcpy(&buf[m],&shearpartner[i][dnum*k],dnumbytes); + memcpy(&buf[m],&valuepartner[i][dnum*k],dnumbytes); m += dnum; } } - } else error->all(FLERR,"Unsupported comm mode in shear history"); + } else error->all(FLERR,"Unsupported comm mode in neighbor history"); return m; } /* ---------------------------------------------------------------------- two modes: NPARTNER and PERPARTNER ------------------------------------------------------------------------- */ -void FixShearHistory::unpack_reverse_comm(int n, int *list, double *buf) +void FixNeighHistory::unpack_reverse_comm(int n, int *list, double *buf) { int i,j,k,kk,ncount; int m = 0; if (commflag == NPARTNER) { for (i = 0; i < n; i++) { j = list[i]; npartner[j] += static_cast (buf[m++]); } } else if (commflag == PERPARTNER) { for (i = 0; i < n; i++) { j = list[i]; ncount = static_cast (buf[m++]); for (k = 0; k < ncount; k++) { kk = npartner[j]++; partner[j][kk] = static_cast (buf[m++]); - memcpy(&shearpartner[j][dnum*kk],&buf[m],dnumbytes); + memcpy(&valuepartner[j][dnum*kk],&buf[m],dnumbytes); m += dnum; } } - } else error->all(FLERR,"Unsupported comm mode in shear history"); + } else error->all(FLERR,"Unsupported comm mode in neighbor history"); } /* ---------------------------------------------------------------------- pack values in local atom-based arrays for exchange with another proc ------------------------------------------------------------------------- */ -int FixShearHistory::pack_exchange(int i, double *buf) +int FixNeighHistory::pack_exchange(int i, double *buf) { // NOTE: how do I know comm buf is big enough if extreme # of touching neighs // Comm::BUFEXTRA may need to be increased int m = 0; buf[m++] = npartner[i]; for (int n = 0; n < npartner[i]; n++) { buf[m++] = partner[i][n]; - memcpy(&buf[m],&shearpartner[i][dnum*n],dnumbytes); + memcpy(&buf[m],&valuepartner[i][dnum*n],dnumbytes); m += dnum; } return m; } /* ---------------------------------------------------------------------- unpack values in local atom-based arrays from exchange with another proc ------------------------------------------------------------------------- */ -int FixShearHistory::unpack_exchange(int nlocal, double *buf) +int FixNeighHistory::unpack_exchange(int nlocal, double *buf) { - // allocate new chunks from ipage,dpage for incoming values + // allocate new chunks from ipage_atom,dpage_atom for incoming values int m = 0; npartner[nlocal] = static_cast (buf[m++]); - maxtouch = MAX(maxtouch,npartner[nlocal]); - partner[nlocal] = ipage->get(npartner[nlocal]); - shearpartner[nlocal] = dpage->get(dnum*npartner[nlocal]); + maxpartner = MAX(maxpartner,npartner[nlocal]); + partner[nlocal] = ipage_atom->get(npartner[nlocal]); + valuepartner[nlocal] = dpage_atom->get(dnum*npartner[nlocal]); for (int n = 0; n < npartner[nlocal]; n++) { partner[nlocal][n] = static_cast (buf[m++]); - memcpy(&shearpartner[nlocal][dnum*n],&buf[m],dnumbytes); + memcpy(&valuepartner[nlocal][dnum*n],&buf[m],dnumbytes); m += dnum; } return m; } /* ---------------------------------------------------------------------- pack values in local atom-based arrays for restart file ------------------------------------------------------------------------- */ -int FixShearHistory::pack_restart(int i, double *buf) +int FixNeighHistory::pack_restart(int i, double *buf) { int m = 1; buf[m++] = npartner[i]; for (int n = 0; n < npartner[i]; n++) { buf[m++] = partner[i][n]; - memcpy(&buf[m],&shearpartner[i][dnum*n],dnumbytes); + memcpy(&buf[m],&valuepartner[i][dnum*n],dnumbytes); m += dnum; } buf[0] = m; return m; } /* ---------------------------------------------------------------------- unpack values from atom->extra array to restart the fix ------------------------------------------------------------------------- */ -void FixShearHistory::unpack_restart(int nlocal, int nth) +void FixNeighHistory::unpack_restart(int nlocal, int nth) { - // ipage = NULL if being called from granular pair style init() + // ipage_atom = NULL if being called from granular pair style init() - if (ipage == NULL) allocate_pages(); + if (ipage_atom == NULL) allocate_pages(); // skip to Nth set of extra values double **extra = atom->extra; int m = 0; for (int i = 0; i < nth; i++) m += static_cast (extra[nlocal][m]); m++; - // allocate new chunks from ipage,dpage for incoming values + // allocate new chunks from ipage_atom,dpage_atom for incoming values npartner[nlocal] = static_cast (extra[nlocal][m++]); - maxtouch = MAX(maxtouch,npartner[nlocal]); - partner[nlocal] = ipage->get(npartner[nlocal]); - shearpartner[nlocal] = dpage->get(dnum*npartner[nlocal]); + maxpartner = MAX(maxpartner,npartner[nlocal]); + partner[nlocal] = ipage_atom->get(npartner[nlocal]); + valuepartner[nlocal] = dpage_atom->get(dnum*npartner[nlocal]); for (int n = 0; n < npartner[nlocal]; n++) { partner[nlocal][n] = static_cast (extra[nlocal][m++]); - memcpy(&shearpartner[nlocal][dnum*n],&extra[nlocal][m],dnumbytes); + memcpy(&valuepartner[nlocal][dnum*n],&extra[nlocal][m],dnumbytes); m += dnum; } } /* ---------------------------------------------------------------------- maxsize of any atom's restart data ------------------------------------------------------------------------- */ -int FixShearHistory::maxsize_restart() +int FixNeighHistory::maxsize_restart() { - // maxtouch_all = max # of touching partners across all procs + // maxpartner_all = max # of touching partners across all procs - int maxtouch_all; - MPI_Allreduce(&maxtouch,&maxtouch_all,1,MPI_INT,MPI_MAX,world); - return (dnum+1)*maxtouch_all + 2; + int maxpartner_all; + MPI_Allreduce(&maxpartner,&maxpartner_all,1,MPI_INT,MPI_MAX,world); + return (dnum+1)*maxpartner_all + 2; } /* ---------------------------------------------------------------------- size of atom nlocal's restart data ------------------------------------------------------------------------- */ -int FixShearHistory::size_restart(int nlocal) +int FixNeighHistory::size_restart(int nlocal) { return (dnum+1)*npartner[nlocal] + 2; } diff --git a/src/fix_shear_history.h b/src/fix_neigh_history.h similarity index 62% rename from src/fix_shear_history.h rename to src/fix_neigh_history.h index 00f219f03..64cc11efe 100644 --- a/src/fix_shear_history.h +++ b/src/fix_neigh_history.h @@ -1,101 +1,118 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #ifdef FIX_CLASS -FixStyle(SHEAR_HISTORY,FixShearHistory) +FixStyle(NEIGH_HISTORY,FixNeighHistory) #else -#ifndef LMP_FIX_SHEAR_HISTORY_H -#define LMP_FIX_SHEAR_HISTORY_H +#ifndef LMP_FIX_NEIGH_HISTORY_H +#define LMP_FIX_NEIGH_HISTORY_H #include "fix.h" #include "my_page.h" namespace LAMMPS_NS { -class FixShearHistory : public Fix { - //friend class Neighbor; - //friend class PairGranHookeHistory; - friend class PairLineGranHookeHistory; - friend class PairTriGranHookeHistory; - +class FixNeighHistory : public Fix { public: int nlocal_neigh; // nlocal at last time neigh list was built int nall_neigh; // ditto for nlocal+nghost - int *npartner; // # of touching partners of each atom - tagint **partner; // global atom IDs for the partners - double **shearpartner; // shear values with the partner - class Pair *pair; // ptr to pair style that uses shear history + int **firstflag; // ptr to each atom's neighbor flsg + double **firstvalue; // ptr to each atom's values + class Pair *pair; // ptr to pair style that uses neighbor history - FixShearHistory(class LAMMPS *, int, char **); - ~FixShearHistory(); + FixNeighHistory(class LAMMPS *, int, char **); + ~FixNeighHistory(); int setmask(); void init(); + void setup_post_neighbor(); virtual void pre_exchange(); void min_pre_exchange(); + void post_neighbor(); + void min_post_neighbor(); void post_run(); double memory_usage(); void grow_arrays(int); void copy_arrays(int, int, int); void set_arrays(int); int pack_reverse_comm_size(int, int); int pack_reverse_comm(int, int, double *); void unpack_reverse_comm(int, int *, double *); int pack_exchange(int, double *); int unpack_exchange(int, double *); int pack_restart(int, double *); void unpack_restart(int, int); int size_restart(int); int maxsize_restart(); protected: int newton_pair; // same as force setting - int dnum,dnumbytes; // dnum = # of shear history values + int dnum,dnumbytes; // dnum = # of values per neighbor int onesided; // 1 for line/tri history, else 0 - int maxtouch; // max # of touching partners for my atoms + int maxatom; // max size of firstflag and firstvalue int commflag; // mode of reverse comm to get ghost info + double *zeroes; + + // per-atom data structures + // partners = flagged neighbors of an atom + + int *npartner; // # of partners of each atom + tagint **partner; // global atom IDs for the partners + double **valuepartner; // values for the partners + int maxpartner; // max # of partners for any of my atoms + + // per-atom data structs pointed to by partner & valuepartner int pgsize,oneatom; // copy of settings in Neighbor - MyPage *ipage; // pages of partner atom IDs - MyPage *dpage; // pages of shear history with partners + MyPage *ipage_atom; // pages of partner atom IDs + MyPage *dpage_atom; // pages of partner values + + // per-neighbor data structs pointed to by firstflag & firstvalue + + MyPage *ipage_neigh; // pages of local atom indices + MyPage *dpage_neigh; // pages of partner values void pre_exchange_onesided(); void pre_exchange_newton(); void pre_exchange_no_newton(); void allocate_pages(); + + inline int sbmask(int j) const { + return j >> SBBITS & 3; + } }; } #endif #endif /* ERROR/WARNING messages: E: Pair style granular with history requires atoms have IDs Atoms in the simulation do not have IDs, so history effects cannot be tracked by the granular pair potential. E: Shear history overflow, boost neigh_modify one There are too many neighbors of a single atom. Use the neigh_modify command to increase the max number of neighbors allowed for one atom. You may also want to boost the page size. */ diff --git a/src/min.cpp b/src/min.cpp index af23629ca..653cac71e 100644 --- a/src/min.cpp +++ b/src/min.cpp @@ -1,828 +1,833 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- Contributing author: Aidan Thompson (SNL) improved CG and backtrack ls, added quadratic ls Sources: Numerical Recipes frprmn routine "Conjugate Gradient Method Without the Agonizing Pain" by JR Shewchuk, http://www-2.cs.cmu.edu/~jrs/jrspapers.html#cg ------------------------------------------------------------------------- */ #include #include #include #include "min.h" #include "atom.h" #include "atom_vec.h" #include "domain.h" #include "comm.h" #include "update.h" #include "modify.h" #include "fix_minimize.h" #include "compute.h" #include "neighbor.h" #include "force.h" #include "pair.h" #include "bond.h" #include "angle.h" #include "dihedral.h" #include "improper.h" #include "kspace.h" #include "output.h" #include "thermo.h" #include "timer.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ Min::Min(LAMMPS *lmp) : Pointers(lmp) { dmax = 0.1; searchflag = 0; linestyle = 1; elist_global = elist_atom = NULL; vlist_global = vlist_atom = NULL; nextra_global = 0; fextra = NULL; nextra_atom = 0; xextra_atom = fextra_atom = NULL; extra_peratom = extra_nlen = NULL; extra_max = NULL; requestor = NULL; external_force_clear = 0; } /* ---------------------------------------------------------------------- */ Min::~Min() { delete [] elist_global; delete [] elist_atom; delete [] vlist_global; delete [] vlist_atom; delete [] fextra; memory->sfree(xextra_atom); memory->sfree(fextra_atom); memory->destroy(extra_peratom); memory->destroy(extra_nlen); memory->destroy(extra_max); memory->sfree(requestor); } /* ---------------------------------------------------------------------- */ void Min::init() { // create fix needed for storing atom-based quantities // will delete it at end of run char **fixarg = new char*[3]; fixarg[0] = (char *) "MINIMIZE"; fixarg[1] = (char *) "all"; fixarg[2] = (char *) "MINIMIZE"; modify->add_fix(3,fixarg); delete [] fixarg; fix_minimize = (FixMinimize *) modify->fix[modify->nfix-1]; // clear out extra global and per-atom dof // will receive requests for new per-atom dof during pair init() // can then add vectors to fix_minimize in setup() nextra_global = 0; delete [] fextra; fextra = NULL; nextra_atom = 0; memory->sfree(xextra_atom); memory->sfree(fextra_atom); memory->destroy(extra_peratom); memory->destroy(extra_nlen); memory->destroy(extra_max); memory->sfree(requestor); xextra_atom = fextra_atom = NULL; extra_peratom = extra_nlen = NULL; extra_max = NULL; requestor = NULL; // virial_style: // 1 if computed explicitly by pair->compute via sum over pair interactions // 2 if computed implicitly by pair->virial_compute via sum over ghost atoms if (force->newton_pair) virial_style = 2; else virial_style = 1; // setup lists of computes for global and per-atom PE and pressure ev_setup(); // detect if fix omp is present for clearing force arrays int ifix = modify->find_fix("package_omp"); if (ifix >= 0) external_force_clear = 1; // set flags for arrays to clear in force_clear() torqueflag = extraflag = 0; if (atom->torque_flag) torqueflag = 1; if (atom->avec->forceclearflag) extraflag = 1; // allow pair and Kspace compute() to be turned off via modify flags if (force->pair && force->pair->compute_flag) pair_compute_flag = 1; else pair_compute_flag = 0; if (force->kspace && force->kspace->compute_flag) kspace_compute_flag = 1; else kspace_compute_flag = 0; // orthogonal vs triclinic simulation box triclinic = domain->triclinic; // reset reneighboring criteria if necessary neigh_every = neighbor->every; neigh_delay = neighbor->delay; neigh_dist_check = neighbor->dist_check; if (neigh_every != 1 || neigh_delay != 0 || neigh_dist_check != 1) { if (comm->me == 0) error->warning(FLERR, "Using 'neigh_modify every 1 delay 0 check" " yes' setting during minimization"); } neighbor->every = 1; neighbor->delay = 0; neighbor->dist_check = 1; niter = neval = 0; } /* ---------------------------------------------------------------------- setup before run ------------------------------------------------------------------------- */ void Min::setup(int flag) { if (comm->me == 0 && screen) { fprintf(screen,"Setting up %s style minimization ...\n", update->minimize_style); if (flag) { fprintf(screen," Unit style : %s\n", update->unit_style); fprintf(screen," Current step : " BIGINT_FORMAT "\n", update->ntimestep); timer->print_timeout(screen); } } update->setupflag = 1; // setup extra global dof due to fixes // cannot be done in init() b/c update init() is before modify init() nextra_global = modify->min_dof(); if (nextra_global) { fextra = new double[nextra_global]; if (comm->me == 0 && screen) fprintf(screen,"WARNING: Energy due to %d extra global DOFs will" " be included in minimizer energies\n",nextra_global); } // compute for potential energy int id = modify->find_compute("thermo_pe"); if (id < 0) error->all(FLERR,"Minimization could not find thermo_pe compute"); pe_compute = modify->compute[id]; // style-specific setup does two tasks // setup extra global dof vectors // setup extra per-atom dof vectors due to requests from Pair classes // cannot be done in init() b/c update init() is before modify/pair init() setup_style(); // ndoftotal = total dof for entire minimization problem // dof for atoms, extra per-atom, extra global bigint ndofme = 3 * static_cast(atom->nlocal); for (int m = 0; m < nextra_atom; m++) ndofme += extra_peratom[m]*atom->nlocal; MPI_Allreduce(&ndofme,&ndoftotal,1,MPI_LMP_BIGINT,MPI_SUM,world); ndoftotal += nextra_global; // setup domain, communication and neighboring // acquire ghosts // build neighbor lists atom->setup(); modify->setup_pre_exchange(); if (triclinic) domain->x2lamda(atom->nlocal); domain->pbc(); domain->reset_box(); comm->setup(); if (neighbor->style) neighbor->setup_bins(); comm->exchange(); if (atom->sortfreq > 0) atom->sort(); comm->borders(); if (triclinic) domain->lamda2x(atom->nlocal+atom->nghost); domain->image_check(); domain->box_too_small_check(); modify->setup_pre_neighbor(); neighbor->build(); + modify->setup_post_neighbor(); neighbor->ncalls = 0; // remove these restriction eventually if (searchflag == 0) { if (nextra_global) error->all(FLERR, "Cannot use a damped dynamics min style with fix box/relax"); if (nextra_atom) error->all(FLERR, "Cannot use a damped dynamics min style with per-atom DOF"); } if (strcmp(update->minimize_style,"hftn") == 0) { if (nextra_global) error->all(FLERR, "Cannot use hftn min style with fix box/relax"); if (nextra_atom) error->all(FLERR, "Cannot use hftn min style with per-atom DOF"); } // atoms may have migrated in comm->exchange() reset_vectors(); // compute all forces force->setup(); ev_set(update->ntimestep); force_clear(); modify->setup_pre_force(vflag); if (pair_compute_flag) force->pair->compute(eflag,vflag); else if (force->pair) force->pair->compute_dummy(eflag,vflag); if (atom->molecular) { if (force->bond) force->bond->compute(eflag,vflag); if (force->angle) force->angle->compute(eflag,vflag); if (force->dihedral) force->dihedral->compute(eflag,vflag); if (force->improper) force->improper->compute(eflag,vflag); } if (force->kspace) { force->kspace->setup(); if (kspace_compute_flag) force->kspace->compute(eflag,vflag); else force->kspace->compute_dummy(eflag,vflag); } modify->setup_pre_reverse(eflag,vflag); if (force->newton) comm->reverse_comm(); // update per-atom minimization variables stored by pair styles if (nextra_atom) for (int m = 0; m < nextra_atom; m++) requestor[m]->min_xf_get(m); modify->setup(vflag); output->setup(flag); update->setupflag = 0; // stats for initial thermo output ecurrent = pe_compute->compute_scalar(); if (nextra_global) ecurrent += modify->min_energy(fextra); if (output->thermo->normflag) ecurrent /= atom->natoms; einitial = ecurrent; fnorm2_init = sqrt(fnorm_sqr()); fnorminf_init = fnorm_inf(); } /* ---------------------------------------------------------------------- setup without output or one-time post-init setup flag = 0 = just force calculation flag = 1 = reneighbor and force calculation ------------------------------------------------------------------------- */ void Min::setup_minimal(int flag) { update->setupflag = 1; // setup domain, communication and neighboring // acquire ghosts // build neighbor lists if (flag) { modify->setup_pre_exchange(); if (triclinic) domain->x2lamda(atom->nlocal); domain->pbc(); domain->reset_box(); comm->setup(); if (neighbor->style) neighbor->setup_bins(); comm->exchange(); comm->borders(); if (triclinic) domain->lamda2x(atom->nlocal+atom->nghost); domain->image_check(); domain->box_too_small_check(); modify->setup_pre_neighbor(); neighbor->build(); + modify->setup_post_neighbor(); neighbor->ncalls = 0; } // atoms may have migrated in comm->exchange() reset_vectors(); // compute all forces ev_set(update->ntimestep); force_clear(); modify->setup_pre_force(vflag); if (pair_compute_flag) force->pair->compute(eflag,vflag); else if (force->pair) force->pair->compute_dummy(eflag,vflag); if (atom->molecular) { if (force->bond) force->bond->compute(eflag,vflag); if (force->angle) force->angle->compute(eflag,vflag); if (force->dihedral) force->dihedral->compute(eflag,vflag); if (force->improper) force->improper->compute(eflag,vflag); } if (force->kspace) { force->kspace->setup(); if (kspace_compute_flag) force->kspace->compute(eflag,vflag); else force->kspace->compute_dummy(eflag,vflag); } modify->setup_pre_reverse(eflag,vflag); if (force->newton) comm->reverse_comm(); // update per-atom minimization variables stored by pair styles if (nextra_atom) for (int m = 0; m < nextra_atom; m++) requestor[m]->min_xf_get(m); modify->setup(vflag); update->setupflag = 0; // stats for Finish to print ecurrent = pe_compute->compute_scalar(); if (nextra_global) ecurrent += modify->min_energy(fextra); if (output->thermo->normflag) ecurrent /= atom->natoms; einitial = ecurrent; fnorm2_init = sqrt(fnorm_sqr()); fnorminf_init = fnorm_inf(); } /* ---------------------------------------------------------------------- perform minimization, calling iterate() for N steps ------------------------------------------------------------------------- */ void Min::run(int n) { // minimizer iterations stop_condition = iterate(n); stopstr = stopstrings(stop_condition); // if early exit from iterate loop: // set update->nsteps to niter for Finish stats to print // set output->next values to this timestep // call energy_force() to insure vflag is set when forces computed // output->write does final output for thermo, dump, restart files // add ntimestep to all computes that store invocation times // since are hardwiring call to thermo/dumps and computes may not be ready if (stop_condition != MAXITER) { update->nsteps = niter; if (update->restrict_output == 0) { for (int idump = 0; idump < output->ndump; idump++) output->next_dump[idump] = update->ntimestep; output->next_dump_any = update->ntimestep; if (output->restart_flag) { output->next_restart = update->ntimestep; if (output->restart_every_single) output->next_restart_single = update->ntimestep; if (output->restart_every_double) output->next_restart_double = update->ntimestep; } } output->next_thermo = update->ntimestep; modify->addstep_compute_all(update->ntimestep); ecurrent = energy_force(0); output->write(update->ntimestep); } } /* ---------------------------------------------------------------------- */ void Min::cleanup() { modify->post_run(); // stats for Finish to print efinal = ecurrent; fnorm2_final = sqrt(fnorm_sqr()); fnorminf_final = fnorm_inf(); // reset reneighboring criteria neighbor->every = neigh_every; neighbor->delay = neigh_delay; neighbor->dist_check = neigh_dist_check; // delete fix at end of run, so its atom arrays won't persist modify->delete_fix("MINIMIZE"); domain->box_too_small_check(); } /* ---------------------------------------------------------------------- evaluate potential energy and forces may migrate atoms due to reneighboring return new energy, which should include nextra_global dof return negative gradient stored in atom->f return negative gradient for nextra_global dof in fextra ------------------------------------------------------------------------- */ double Min::energy_force(int resetflag) { // check for reneighboring // always communicate since minimizer moved atoms int nflag = neighbor->decide(); if (nflag == 0) { timer->stamp(); comm->forward_comm(); timer->stamp(Timer::COMM); } else { if (modify->n_min_pre_exchange) { timer->stamp(); modify->min_pre_exchange(); timer->stamp(Timer::MODIFY); } if (triclinic) domain->x2lamda(atom->nlocal); domain->pbc(); if (domain->box_change) { domain->reset_box(); comm->setup(); if (neighbor->style) neighbor->setup_bins(); } timer->stamp(); comm->exchange(); if (atom->sortfreq > 0 && update->ntimestep >= atom->nextsort) atom->sort(); comm->borders(); if (triclinic) domain->lamda2x(atom->nlocal+atom->nghost); timer->stamp(Timer::COMM); if (modify->n_min_pre_neighbor) { - timer->stamp(); modify->min_pre_neighbor(); timer->stamp(Timer::MODIFY); } neighbor->build(); timer->stamp(Timer::NEIGH); + if (modify->n_min_post_neighbor) { + modify->min_post_neighbor(); + timer->stamp(Timer::MODIFY); + } } ev_set(update->ntimestep); force_clear(); timer->stamp(); if (modify->n_min_pre_force) { modify->min_pre_force(vflag); timer->stamp(Timer::MODIFY); } if (pair_compute_flag) { force->pair->compute(eflag,vflag); timer->stamp(Timer::PAIR); } if (atom->molecular) { if (force->bond) force->bond->compute(eflag,vflag); if (force->angle) force->angle->compute(eflag,vflag); if (force->dihedral) force->dihedral->compute(eflag,vflag); if (force->improper) force->improper->compute(eflag,vflag); timer->stamp(Timer::BOND); } if (kspace_compute_flag) { force->kspace->compute(eflag,vflag); timer->stamp(Timer::KSPACE); } if (modify->n_min_pre_reverse) { modify->min_pre_reverse(eflag,vflag); timer->stamp(Timer::MODIFY); } if (force->newton) { comm->reverse_comm(); timer->stamp(Timer::COMM); } // update per-atom minimization variables stored by pair styles if (nextra_atom) for (int m = 0; m < nextra_atom; m++) requestor[m]->min_xf_get(m); // fixes that affect minimization if (modify->n_min_post_force) { timer->stamp(); modify->min_post_force(vflag); timer->stamp(Timer::MODIFY); } // compute potential energy of system // normalize if thermo PE does double energy = pe_compute->compute_scalar(); if (nextra_global) energy += modify->min_energy(fextra); if (output->thermo->normflag) energy /= atom->natoms; // if reneighbored, atoms migrated // if resetflag = 1, update x0 of atoms crossing PBC // reset vectors used by lo-level minimizer if (nflag) { if (resetflag) fix_minimize->reset_coords(); reset_vectors(); } return energy; } /* ---------------------------------------------------------------------- clear force on own & ghost atoms clear other arrays as needed ------------------------------------------------------------------------- */ void Min::force_clear() { if (external_force_clear) return; // clear global force array // if either newton flag is set, also include ghosts size_t nbytes = sizeof(double) * atom->nlocal; if (force->newton) nbytes += sizeof(double) * atom->nghost; if (nbytes) { memset(&atom->f[0][0],0,3*nbytes); if (torqueflag) memset(&atom->torque[0][0],0,3*nbytes); if (extraflag) atom->avec->force_clear(0,nbytes); } } /* ---------------------------------------------------------------------- pair style makes request to add a per-atom variables to minimization requestor stores callback to pair class to invoke during min to get current variable and forces on it and to update the variable return flag that pair can use if it registers multiple variables ------------------------------------------------------------------------- */ int Min::request(Pair *pair, int peratom, double maxvalue) { int n = nextra_atom + 1; xextra_atom = (double **) memory->srealloc(xextra_atom,n*sizeof(double *), "min:xextra_atom"); fextra_atom = (double **) memory->srealloc(fextra_atom,n*sizeof(double *), "min:fextra_atom"); memory->grow(extra_peratom,n,"min:extra_peratom"); memory->grow(extra_nlen,n,"min:extra_nlen"); memory->grow(extra_max,n,"min:extra_max"); requestor = (Pair **) memory->srealloc(requestor,n*sizeof(Pair *), "min:requestor"); requestor[nextra_atom] = pair; extra_peratom[nextra_atom] = peratom; extra_max[nextra_atom] = maxvalue; nextra_atom++; return nextra_atom-1; } /* ---------------------------------------------------------------------- */ void Min::modify_params(int narg, char **arg) { if (narg == 0) error->all(FLERR,"Illegal min_modify command"); int iarg = 0; while (iarg < narg) { if (strcmp(arg[iarg],"dmax") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal min_modify command"); dmax = force->numeric(FLERR,arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"line") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal min_modify command"); if (strcmp(arg[iarg+1],"backtrack") == 0) linestyle = 0; else if (strcmp(arg[iarg+1],"quadratic") == 0) linestyle = 1; else if (strcmp(arg[iarg+1],"forcezero") == 0) linestyle = 2; else error->all(FLERR,"Illegal min_modify command"); iarg += 2; } else error->all(FLERR,"Illegal min_modify command"); } } /* ---------------------------------------------------------------------- setup lists of computes for global and per-atom PE and pressure ------------------------------------------------------------------------- */ void Min::ev_setup() { delete [] elist_global; delete [] elist_atom; delete [] vlist_global; delete [] vlist_atom; elist_global = elist_atom = NULL; vlist_global = vlist_atom = NULL; nelist_global = nelist_atom = 0; nvlist_global = nvlist_atom = 0; for (int i = 0; i < modify->ncompute; i++) { if (modify->compute[i]->peflag) nelist_global++; if (modify->compute[i]->peatomflag) nelist_atom++; if (modify->compute[i]->pressflag) nvlist_global++; if (modify->compute[i]->pressatomflag) nvlist_atom++; } if (nelist_global) elist_global = new Compute*[nelist_global]; if (nelist_atom) elist_atom = new Compute*[nelist_atom]; if (nvlist_global) vlist_global = new Compute*[nvlist_global]; if (nvlist_atom) vlist_atom = new Compute*[nvlist_atom]; nelist_global = nelist_atom = 0; nvlist_global = nvlist_atom = 0; for (int i = 0; i < modify->ncompute; i++) { if (modify->compute[i]->peflag) elist_global[nelist_global++] = modify->compute[i]; if (modify->compute[i]->peatomflag) elist_atom[nelist_atom++] = modify->compute[i]; if (modify->compute[i]->pressflag) vlist_global[nvlist_global++] = modify->compute[i]; if (modify->compute[i]->pressatomflag) vlist_atom[nvlist_atom++] = modify->compute[i]; } } /* ---------------------------------------------------------------------- set eflag,vflag for current iteration invoke matchstep() on all timestep-dependent computes to clear their arrays eflag/vflag based on computes that need info on this ntimestep always set eflag_global = 1, since need energy every iteration eflag = 0 = no energy computation eflag = 1 = global energy only eflag = 2 = per-atom energy only eflag = 3 = both global and per-atom energy vflag = 0 = no virial computation (pressure) vflag = 1 = global virial with pair portion via sum of pairwise interactions vflag = 2 = global virial with pair portion via F dot r including ghosts vflag = 4 = per-atom virial only vflag = 5 or 6 = both global and per-atom virial ------------------------------------------------------------------------- */ void Min::ev_set(bigint ntimestep) { int i,flag; int eflag_global = 1; for (i = 0; i < nelist_global; i++) elist_global[i]->matchstep(ntimestep); flag = 0; int eflag_atom = 0; for (i = 0; i < nelist_atom; i++) if (elist_atom[i]->matchstep(ntimestep)) flag = 1; if (flag) eflag_atom = 2; if (eflag_global) update->eflag_global = update->ntimestep; if (eflag_atom) update->eflag_atom = update->ntimestep; eflag = eflag_global + eflag_atom; flag = 0; int vflag_global = 0; for (i = 0; i < nvlist_global; i++) if (vlist_global[i]->matchstep(ntimestep)) flag = 1; if (flag) vflag_global = virial_style; flag = 0; int vflag_atom = 0; for (i = 0; i < nvlist_atom; i++) if (vlist_atom[i]->matchstep(ntimestep)) flag = 1; if (flag) vflag_atom = 4; if (vflag_global) update->vflag_global = update->ntimestep; if (vflag_atom) update->vflag_atom = update->ntimestep; vflag = vflag_global + vflag_atom; } /* ---------------------------------------------------------------------- compute and return ||force||_2^2 ------------------------------------------------------------------------- */ double Min::fnorm_sqr() { int i,n; double *fatom; double local_norm2_sqr = 0.0; for (i = 0; i < nvec; i++) local_norm2_sqr += fvec[i]*fvec[i]; if (nextra_atom) { for (int m = 0; m < nextra_atom; m++) { fatom = fextra_atom[m]; n = extra_nlen[m]; for (i = 0; i < n; i++) local_norm2_sqr += fatom[i]*fatom[i]; } } double norm2_sqr = 0.0; MPI_Allreduce(&local_norm2_sqr,&norm2_sqr,1,MPI_DOUBLE,MPI_SUM,world); if (nextra_global) for (i = 0; i < nextra_global; i++) norm2_sqr += fextra[i]*fextra[i]; return norm2_sqr; } /* ---------------------------------------------------------------------- compute and return ||force||_inf ------------------------------------------------------------------------- */ double Min::fnorm_inf() { int i,n; double *fatom; double local_norm_inf = 0.0; for (i = 0; i < nvec; i++) local_norm_inf = MAX(fabs(fvec[i]),local_norm_inf); if (nextra_atom) { for (int m = 0; m < nextra_atom; m++) { fatom = fextra_atom[m]; n = extra_nlen[m]; for (i = 0; i < n; i++) local_norm_inf = MAX(fabs(fatom[i]),local_norm_inf); } } double norm_inf = 0.0; MPI_Allreduce(&local_norm_inf,&norm_inf,1,MPI_DOUBLE,MPI_MAX,world); if (nextra_global) for (i = 0; i < nextra_global; i++) norm_inf = MAX(fabs(fextra[i]),norm_inf); return norm_inf; } /* ---------------------------------------------------------------------- possible stop conditions ------------------------------------------------------------------------- */ char *Min::stopstrings(int n) { const char *strings[] = {"max iterations", "max force evaluations", "energy tolerance", "force tolerance", "search direction is not downhill", "linesearch alpha is zero", "forces are zero", "quadratic factors are zero", "trust region too small", "HFTN minimizer error", "walltime limit reached"}; return (char *) strings[n]; } diff --git a/src/modify.cpp b/src/modify.cpp index 04137f110..64970f2cf 100644 --- a/src/modify.cpp +++ b/src/modify.cpp @@ -1,1596 +1,1635 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include #include #include "modify.h" #include "style_compute.h" #include "style_fix.h" #include "atom.h" #include "comm.h" #include "fix.h" #include "compute.h" #include "group.h" #include "update.h" #include "domain.h" #include "region.h" #include "input.h" #include "variable.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; using namespace FixConst; #define DELTA 4 #define BIG 1.0e20 #define NEXCEPT 7 // change when add to exceptions in add_fix() /* ---------------------------------------------------------------------- */ Modify::Modify(LAMMPS *lmp) : Pointers(lmp) { nfix = maxfix = 0; n_initial_integrate = n_post_integrate = 0; - n_pre_exchange = n_pre_neighbor = 0; + n_pre_exchange = n_pre_neighbor = n_post_neighbor = 0; n_pre_force = n_pre_reverse = n_post_force = 0; n_final_integrate = n_end_of_step = n_thermo_energy = 0; n_thermo_energy_atom = 0; n_initial_integrate_respa = n_post_integrate_respa = 0; n_pre_force_respa = n_post_force_respa = n_final_integrate_respa = 0; n_min_pre_exchange = n_min_pre_force = n_min_pre_reverse = 0; n_min_post_force = n_min_energy = 0; fix = NULL; fmask = NULL; list_initial_integrate = list_post_integrate = NULL; - list_pre_exchange = list_pre_neighbor = NULL; + list_pre_exchange = list_pre_neighbor = list_post_neighbor = NULL; list_pre_force = list_pre_reverse = list_post_force = NULL; list_final_integrate = list_end_of_step = NULL; list_thermo_energy = list_thermo_energy_atom = NULL; list_initial_integrate_respa = list_post_integrate_respa = NULL; list_pre_force_respa = list_post_force_respa = NULL; list_final_integrate_respa = NULL; - list_min_pre_exchange = list_min_pre_neighbor = NULL; + list_min_pre_exchange = list_min_pre_neighbor = list_min_post_neighbor = NULL; list_min_pre_force = list_min_pre_reverse = list_min_post_force = NULL; list_min_energy = NULL; end_of_step_every = NULL; list_timeflag = NULL; nfix_restart_global = 0; id_restart_global = style_restart_global = NULL; state_restart_global = NULL; used_restart_global = NULL; nfix_restart_peratom = 0; id_restart_peratom = style_restart_peratom = NULL; index_restart_peratom = used_restart_peratom = NULL; ncompute = maxcompute = 0; compute = NULL; // fill map with fixes listed in style_fix.h fix_map = new FixCreatorMap(); #define FIX_CLASS #define FixStyle(key,Class) \ (*fix_map)[#key] = &fix_creator; #include "style_fix.h" #undef FixStyle #undef FIX_CLASS // fill map with computes listed in style_compute.h compute_map = new ComputeCreatorMap(); #define COMPUTE_CLASS #define ComputeStyle(key,Class) \ (*compute_map)[#key] = &compute_creator; #include "style_compute.h" #undef ComputeStyle #undef COMPUTE_CLASS } /* ---------------------------------------------------------------------- */ Modify::~Modify() { // delete all fixes // do it via delete_fix() so callbacks in Atom are also updated correctly while (nfix) delete_fix(0); memory->sfree(fix); memory->destroy(fmask); // delete all computes for (int i = 0; i < ncompute; i++) delete compute[i]; memory->sfree(compute); delete [] list_initial_integrate; delete [] list_post_integrate; delete [] list_pre_exchange; delete [] list_pre_neighbor; + delete [] list_post_neighbor; delete [] list_pre_force; delete [] list_pre_reverse; delete [] list_post_force; delete [] list_final_integrate; delete [] list_end_of_step; delete [] list_thermo_energy; delete [] list_thermo_energy_atom; delete [] list_initial_integrate_respa; delete [] list_post_integrate_respa; delete [] list_pre_force_respa; delete [] list_post_force_respa; delete [] list_final_integrate_respa; delete [] list_min_pre_exchange; delete [] list_min_pre_neighbor; + delete [] list_min_post_neighbor; delete [] list_min_pre_force; delete [] list_min_pre_reverse; delete [] list_min_post_force; delete [] list_min_energy; delete [] end_of_step_every; delete [] list_timeflag; restart_deallocate(0); delete compute_map; delete fix_map; } /* ---------------------------------------------------------------------- initialize all fixes and computes ------------------------------------------------------------------------- */ void Modify::init() { int i,j; // delete storage of restart info since it is not valid after 1st run restart_deallocate(1); // create lists of fixes to call at each stage of run list_init(INITIAL_INTEGRATE,n_initial_integrate,list_initial_integrate); list_init(POST_INTEGRATE,n_post_integrate,list_post_integrate); list_init(PRE_EXCHANGE,n_pre_exchange,list_pre_exchange); list_init(PRE_NEIGHBOR,n_pre_neighbor,list_pre_neighbor); + list_init(POST_NEIGHBOR,n_post_neighbor,list_post_neighbor); list_init(PRE_FORCE,n_pre_force,list_pre_force); list_init(PRE_REVERSE,n_pre_reverse,list_pre_reverse); list_init(POST_FORCE,n_post_force,list_post_force); list_init(FINAL_INTEGRATE,n_final_integrate,list_final_integrate); list_init_end_of_step(END_OF_STEP,n_end_of_step,list_end_of_step); list_init_thermo_energy(THERMO_ENERGY,n_thermo_energy,list_thermo_energy); list_init_thermo_energy_atom(n_thermo_energy_atom,list_thermo_energy_atom); list_init(INITIAL_INTEGRATE_RESPA, n_initial_integrate_respa,list_initial_integrate_respa); list_init(POST_INTEGRATE_RESPA, n_post_integrate_respa,list_post_integrate_respa); list_init(POST_FORCE_RESPA, n_post_force_respa,list_post_force_respa); list_init(PRE_FORCE_RESPA, n_pre_force_respa,list_pre_force_respa); list_init(FINAL_INTEGRATE_RESPA, n_final_integrate_respa,list_final_integrate_respa); list_init(MIN_PRE_EXCHANGE,n_min_pre_exchange,list_min_pre_exchange); list_init(MIN_PRE_NEIGHBOR,n_min_pre_neighbor,list_min_pre_neighbor); + list_init(MIN_POST_NEIGHBOR,n_min_post_neighbor,list_min_post_neighbor); list_init(MIN_PRE_FORCE,n_min_pre_force,list_min_pre_force); list_init(MIN_PRE_REVERSE,n_min_pre_reverse,list_min_pre_reverse); list_init(MIN_POST_FORCE,n_min_post_force,list_min_post_force); list_init(MIN_ENERGY,n_min_energy,list_min_energy); // init each fix // not sure if now needs to come before compute init // used to b/c temperature computes called fix->dof() in their init, // and fix rigid required its own init before its dof() could be called, // but computes now do their DOF in setup() for (i = 0; i < nfix; i++) fix[i]->init(); // set global flag if any fix has its restart_pbc flag set restart_pbc_any = 0; for (i = 0; i < nfix; i++) if (fix[i]->restart_pbc) restart_pbc_any = 1; // create list of computes that store invocation times list_init_compute(); // init each compute // set invoked_scalar,vector,etc to -1 to force new run to re-compute them // add initial timestep to all computes that store invocation times // since any of them may be invoked by initial thermo // do not clear out invocation times stored within a compute, // b/c some may be holdovers from previous run, like for ave fixes for (i = 0; i < ncompute; i++) { compute[i]->init(); compute[i]->invoked_scalar = -1; compute[i]->invoked_vector = -1; compute[i]->invoked_array = -1; compute[i]->invoked_peratom = -1; compute[i]->invoked_local = -1; } addstep_compute_all(update->ntimestep); // error if any fix or compute is using a dynamic group when not allowed for (i = 0; i < nfix; i++) if (!fix[i]->dynamic_group_allow && group->dynamic[fix[i]->igroup]) { char str[128]; sprintf(str,"Fix %s does not allow use of dynamic group",fix[i]->id); error->all(FLERR,str); } for (i = 0; i < ncompute; i++) if (!compute[i]->dynamic_group_allow && group->dynamic[compute[i]->igroup]) { char str[128]; sprintf(str,"Compute %s does not allow use of dynamic group",fix[i]->id); error->all(FLERR,str); } // warn if any particle is time integrated more than once int nlocal = atom->nlocal; int *mask = atom->mask; int *flag = new int[nlocal]; for (i = 0; i < nlocal; i++) flag[i] = 0; int groupbit; for (i = 0; i < nfix; i++) { if (fix[i]->time_integrate == 0) continue; groupbit = fix[i]->groupbit; for (j = 0; j < nlocal; j++) if (mask[j] & groupbit) flag[j]++; } int check = 0; for (i = 0; i < nlocal; i++) if (flag[i] > 1) check = 1; delete [] flag; int checkall; MPI_Allreduce(&check,&checkall,1,MPI_INT,MPI_SUM,world); if (comm->me == 0 && checkall) error->warning(FLERR, "One or more atoms are time integrated more than once"); } /* ---------------------------------------------------------------------- setup for run, calls setup() of all fixes and computes called from Verlet, RESPA, Min ------------------------------------------------------------------------- */ void Modify::setup(int vflag) { // compute setup needs to come before fix setup // b/c NH fixes need DOF of temperature computes // fix group setup() is special case since populates a dynamic group // needs to be done before temperature compute setup for (int i = 0; i < nfix; i++) if (strcmp(fix[i]->style,"GROUP") == 0) fix[i]->setup(vflag); for (int i = 0; i < ncompute; i++) compute[i]->setup(); if (update->whichflag == 1) for (int i = 0; i < nfix; i++) fix[i]->setup(vflag); else if (update->whichflag == 2) for (int i = 0; i < nfix; i++) fix[i]->min_setup(vflag); } /* ---------------------------------------------------------------------- setup pre_exchange call, only for fixes that define pre_exchange called from Verlet, RESPA, Min, and WriteRestart with whichflag = 0 ------------------------------------------------------------------------- */ void Modify::setup_pre_exchange() { if (update->whichflag <= 1) for (int i = 0; i < n_pre_exchange; i++) fix[list_pre_exchange[i]]->setup_pre_exchange(); else if (update->whichflag == 2) for (int i = 0; i < n_min_pre_exchange; i++) fix[list_min_pre_exchange[i]]->setup_pre_exchange(); } /* ---------------------------------------------------------------------- setup pre_neighbor call, only for fixes that define pre_neighbor called from Verlet, RESPA ------------------------------------------------------------------------- */ void Modify::setup_pre_neighbor() { if (update->whichflag == 1) for (int i = 0; i < n_pre_neighbor; i++) fix[list_pre_neighbor[i]]->setup_pre_neighbor(); else if (update->whichflag == 2) for (int i = 0; i < n_min_pre_neighbor; i++) fix[list_min_pre_neighbor[i]]->setup_pre_neighbor(); } +/* ---------------------------------------------------------------------- + setup post_neighbor call, only for fixes that define post_neighbor + called from Verlet, RESPA +------------------------------------------------------------------------- */ + +void Modify::setup_post_neighbor() +{ + if (update->whichflag == 1) + for (int i = 0; i < n_post_neighbor; i++) + fix[list_post_neighbor[i]]->setup_post_neighbor(); + else if (update->whichflag == 2) + for (int i = 0; i < n_min_post_neighbor; i++) + fix[list_min_post_neighbor[i]]->setup_post_neighbor(); +} + /* ---------------------------------------------------------------------- setup pre_force call, only for fixes that define pre_force called from Verlet, RESPA, Min ------------------------------------------------------------------------- */ void Modify::setup_pre_force(int vflag) { if (update->whichflag == 1) for (int i = 0; i < n_pre_force; i++) fix[list_pre_force[i]]->setup_pre_force(vflag); else if (update->whichflag == 2) for (int i = 0; i < n_min_pre_force; i++) fix[list_min_pre_force[i]]->setup_pre_force(vflag); } /* ---------------------------------------------------------------------- setup pre_reverse call, only for fixes that define pre_reverse called from Verlet, RESPA, Min ------------------------------------------------------------------------- */ void Modify::setup_pre_reverse(int eflag, int vflag) { if (update->whichflag == 1) for (int i = 0; i < n_pre_reverse; i++) fix[list_pre_reverse[i]]->setup_pre_reverse(eflag,vflag); else if (update->whichflag == 2) for (int i = 0; i < n_min_pre_reverse; i++) fix[list_min_pre_reverse[i]]->setup_pre_reverse(eflag,vflag); } /* ---------------------------------------------------------------------- 1st half of integrate call, only for relevant fixes ------------------------------------------------------------------------- */ void Modify::initial_integrate(int vflag) { for (int i = 0; i < n_initial_integrate; i++) fix[list_initial_integrate[i]]->initial_integrate(vflag); } /* ---------------------------------------------------------------------- post_integrate call, only for relevant fixes ------------------------------------------------------------------------- */ void Modify::post_integrate() { for (int i = 0; i < n_post_integrate; i++) fix[list_post_integrate[i]]->post_integrate(); } /* ---------------------------------------------------------------------- pre_exchange call, only for relevant fixes ------------------------------------------------------------------------- */ void Modify::pre_exchange() { for (int i = 0; i < n_pre_exchange; i++) fix[list_pre_exchange[i]]->pre_exchange(); } /* ---------------------------------------------------------------------- pre_neighbor call, only for relevant fixes ------------------------------------------------------------------------- */ void Modify::pre_neighbor() { for (int i = 0; i < n_pre_neighbor; i++) fix[list_pre_neighbor[i]]->pre_neighbor(); } +/* ---------------------------------------------------------------------- + post_neighbor call, only for relevant fixes +------------------------------------------------------------------------- */ + +void Modify::post_neighbor() +{ + for (int i = 0; i < n_post_neighbor; i++) + fix[list_post_neighbor[i]]->post_neighbor(); +} + /* ---------------------------------------------------------------------- pre_force call, only for relevant fixes ------------------------------------------------------------------------- */ void Modify::pre_force(int vflag) { for (int i = 0; i < n_pre_force; i++) fix[list_pre_force[i]]->pre_force(vflag); } /* ---------------------------------------------------------------------- pre_reverse call, only for relevant fixes ------------------------------------------------------------------------- */ void Modify::pre_reverse(int eflag, int vflag) { for (int i = 0; i < n_pre_reverse; i++) fix[list_pre_reverse[i]]->pre_reverse(eflag,vflag); } /* ---------------------------------------------------------------------- post_force call, only for relevant fixes ------------------------------------------------------------------------- */ void Modify::post_force(int vflag) { for (int i = 0; i < n_post_force; i++) fix[list_post_force[i]]->post_force(vflag); } /* ---------------------------------------------------------------------- 2nd half of integrate call, only for relevant fixes ------------------------------------------------------------------------- */ void Modify::final_integrate() { for (int i = 0; i < n_final_integrate; i++) fix[list_final_integrate[i]]->final_integrate(); } /* ---------------------------------------------------------------------- end-of-timestep call, only for relevant fixes only call fix->end_of_step() on timesteps that are multiples of nevery ------------------------------------------------------------------------- */ void Modify::end_of_step() { for (int i = 0; i < n_end_of_step; i++) if (update->ntimestep % end_of_step_every[i] == 0) fix[list_end_of_step[i]]->end_of_step(); } /* ---------------------------------------------------------------------- thermo energy call, only for relevant fixes called by Thermo class compute_scalar() is fix call to return energy ------------------------------------------------------------------------- */ double Modify::thermo_energy() { double energy = 0.0; for (int i = 0; i < n_thermo_energy; i++) energy += fix[list_thermo_energy[i]]->compute_scalar(); return energy; } /* ---------------------------------------------------------------------- per-atom thermo energy call, only for relevant fixes called by compute pe/atom ------------------------------------------------------------------------- */ void Modify::thermo_energy_atom(int nlocal, double *energy) { int i,j; double *eatom; for (i = 0; i < n_thermo_energy_atom; i++) { eatom = fix[list_thermo_energy_atom[i]]->eatom; if (!eatom) continue; for (j = 0; j < nlocal; j++) energy[j] += eatom[j]; } } /* ---------------------------------------------------------------------- post_run call ------------------------------------------------------------------------- */ void Modify::post_run() { for (int i = 0; i < nfix; i++) fix[i]->post_run(); } /* ---------------------------------------------------------------------- create_attribute call invoked when an atom is added to system during a run necessary so that fixes and computes that store per-atom state can initialize that state for the new atom N computes can store per-atom state via a fix like fix STORE compute has the create_attribute flag, not fix STORE ------------------------------------------------------------------------- */ void Modify::create_attribute(int n) { for (int i = 0; i < nfix; i++) if (fix[i]->create_attribute) fix[i]->set_arrays(n); for (int i = 0; i < ncompute; i++) if (compute[i]->create_attribute) compute[i]->set_arrays(n); input->variable->set_arrays(n); } /* ---------------------------------------------------------------------- setup rRESPA pre_force call, only for relevant fixes ------------------------------------------------------------------------- */ void Modify::setup_pre_force_respa(int vflag, int ilevel) { for (int i = 0; i < n_pre_force_respa; i++) fix[list_pre_force_respa[i]]->setup_pre_force_respa(vflag,ilevel); } /* ---------------------------------------------------------------------- 1st half of rRESPA integrate call, only for relevant fixes ------------------------------------------------------------------------- */ void Modify::initial_integrate_respa(int vflag, int ilevel, int iloop) { for (int i = 0; i < n_initial_integrate_respa; i++) fix[list_initial_integrate_respa[i]]-> initial_integrate_respa(vflag,ilevel,iloop); } /* ---------------------------------------------------------------------- rRESPA post_integrate call, only for relevant fixes ------------------------------------------------------------------------- */ void Modify::post_integrate_respa(int ilevel, int iloop) { for (int i = 0; i < n_post_integrate_respa; i++) fix[list_post_integrate_respa[i]]->post_integrate_respa(ilevel,iloop); } /* ---------------------------------------------------------------------- rRESPA pre_force call, only for relevant fixes ------------------------------------------------------------------------- */ void Modify::pre_force_respa(int vflag, int ilevel, int iloop) { for (int i = 0; i < n_pre_force_respa; i++) fix[list_pre_force_respa[i]]->pre_force_respa(vflag,ilevel,iloop); } /* ---------------------------------------------------------------------- rRESPA post_force call, only for relevant fixes ------------------------------------------------------------------------- */ void Modify::post_force_respa(int vflag, int ilevel, int iloop) { for (int i = 0; i < n_post_force_respa; i++) fix[list_post_force_respa[i]]->post_force_respa(vflag,ilevel,iloop); } /* ---------------------------------------------------------------------- 2nd half of rRESPA integrate call, only for relevant fixes ------------------------------------------------------------------------- */ void Modify::final_integrate_respa(int ilevel, int iloop) { for (int i = 0; i < n_final_integrate_respa; i++) fix[list_final_integrate_respa[i]]->final_integrate_respa(ilevel,iloop); } /* ---------------------------------------------------------------------- minimizer pre-exchange call, only for relevant fixes ------------------------------------------------------------------------- */ void Modify::min_pre_exchange() { for (int i = 0; i < n_min_pre_exchange; i++) fix[list_min_pre_exchange[i]]->min_pre_exchange(); } /* ---------------------------------------------------------------------- minimizer pre-neighbor call, only for relevant fixes ------------------------------------------------------------------------- */ void Modify::min_pre_neighbor() { for (int i = 0; i < n_min_pre_neighbor; i++) fix[list_min_pre_neighbor[i]]->min_pre_neighbor(); } +/* ---------------------------------------------------------------------- + minimizer post-neighbor call, only for relevant fixes +------------------------------------------------------------------------- */ + +void Modify::min_post_neighbor() +{ + for (int i = 0; i < n_min_post_neighbor; i++) + fix[list_min_post_neighbor[i]]->min_post_neighbor(); +} + /* ---------------------------------------------------------------------- minimizer pre-force call, only for relevant fixes ------------------------------------------------------------------------- */ void Modify::min_pre_force(int vflag) { for (int i = 0; i < n_min_pre_force; i++) fix[list_min_pre_force[i]]->min_pre_force(vflag); } /* ---------------------------------------------------------------------- minimizer pre-reverse call, only for relevant fixes ------------------------------------------------------------------------- */ void Modify::min_pre_reverse(int eflag, int vflag) { for (int i = 0; i < n_min_pre_reverse; i++) fix[list_min_pre_reverse[i]]->min_pre_reverse(eflag,vflag); } /* ---------------------------------------------------------------------- minimizer force adjustment call, only for relevant fixes ------------------------------------------------------------------------- */ void Modify::min_post_force(int vflag) { for (int i = 0; i < n_min_post_force; i++) fix[list_min_post_force[i]]->min_post_force(vflag); } /* ---------------------------------------------------------------------- minimizer energy/force evaluation, only for relevant fixes return energy and forces on extra degrees of freedom ------------------------------------------------------------------------- */ double Modify::min_energy(double *fextra) { int ifix,index; index = 0; double eng = 0.0; for (int i = 0; i < n_min_energy; i++) { ifix = list_min_energy[i]; eng += fix[ifix]->min_energy(&fextra[index]); index += fix[ifix]->min_dof(); } return eng; } /* ---------------------------------------------------------------------- store current state of extra minimizer dof, only for relevant fixes ------------------------------------------------------------------------- */ void Modify::min_store() { for (int i = 0; i < n_min_energy; i++) fix[list_min_energy[i]]->min_store(); } /* ---------------------------------------------------------------------- manage state of extra minimizer dof on a stack, only for relevant fixes ------------------------------------------------------------------------- */ void Modify::min_clearstore() { for (int i = 0; i < n_min_energy; i++) fix[list_min_energy[i]]->min_clearstore(); } void Modify::min_pushstore() { for (int i = 0; i < n_min_energy; i++) fix[list_min_energy[i]]->min_pushstore(); } void Modify::min_popstore() { for (int i = 0; i < n_min_energy; i++) fix[list_min_energy[i]]->min_popstore(); } /* ---------------------------------------------------------------------- displace extra minimizer dof along vector hextra, only for relevant fixes ------------------------------------------------------------------------- */ void Modify::min_step(double alpha, double *hextra) { int ifix,index; index = 0; for (int i = 0; i < n_min_energy; i++) { ifix = list_min_energy[i]; fix[ifix]->min_step(alpha,&hextra[index]); index += fix[ifix]->min_dof(); } } /* ---------------------------------------------------------------------- compute max allowed step size along vector hextra, only for relevant fixes ------------------------------------------------------------------------- */ double Modify::max_alpha(double *hextra) { int ifix,index; double alpha = BIG; index = 0; for (int i = 0; i < n_min_energy; i++) { ifix = list_min_energy[i]; double alpha_one = fix[ifix]->max_alpha(&hextra[index]); alpha = MIN(alpha,alpha_one); index += fix[ifix]->min_dof(); } return alpha; } /* ---------------------------------------------------------------------- extract extra minimizer dof, only for relevant fixes ------------------------------------------------------------------------- */ int Modify::min_dof() { int ndof = 0; for (int i = 0; i < n_min_energy; i++) ndof += fix[list_min_energy[i]]->min_dof(); return ndof; } /* ---------------------------------------------------------------------- reset minimizer reference state of fix, only for relevant fixes ------------------------------------------------------------------------- */ int Modify::min_reset_ref() { int itmp,itmpall; itmpall = 0; for (int i = 0; i < n_min_energy; i++) { itmp = fix[list_min_energy[i]]->min_reset_ref(); if (itmp) itmpall = 1; } return itmpall; } /* ---------------------------------------------------------------------- add a new fix or replace one with same ID ------------------------------------------------------------------------- */ void Modify::add_fix(int narg, char **arg, int trysuffix) { if (narg < 3) error->all(FLERR,"Illegal fix command"); // cannot define fix before box exists unless style is in exception list // don't like this way of checking for exceptions by adding fixes to list, // but can't think of better way // too late if instantiate fix, then check flag set in fix constructor, // since some fixes access domain settings in their constructor // MUST change NEXCEPT above when add new fix to this list const char *exceptions[NEXCEPT] = {"GPU","OMP","INTEL","property/atom","cmap","cmap3","rx"}; if (domain->box_exist == 0) { int m; for (m = 0; m < NEXCEPT; m++) if (strcmp(arg[2],exceptions[m]) == 0) break; if (m == NEXCEPT) error->all(FLERR,"Fix command before simulation box is defined"); } // check group ID int igroup = group->find(arg[1]); if (igroup == -1) error->all(FLERR,"Could not find fix group ID"); // if fix ID exists: // set newflag = 0 so create new fix in same location in fix list // error if new style does not match old style // since can't replace it (all when-to-invoke ptrs would be invalid) // warn if new group != old group // delete old fix, but do not call update_callback(), // since will replace this fix and thus other fix locs will not change // set ptr to NULL in case new fix scans list of fixes, // e.g. scan will occur in add_callback() if called by new fix // if fix ID does not exist: // set newflag = 1 so create new fix // extend fix and fmask lists as necessary int ifix,newflag; for (ifix = 0; ifix < nfix; ifix++) if (strcmp(arg[0],fix[ifix]->id) == 0) break; if (ifix < nfix) { newflag = 0; int match = 0; if (strcmp(arg[2],fix[ifix]->style) == 0) match = 1; if (!match && trysuffix && lmp->suffix_enable) { char estyle[256]; if (lmp->suffix) { sprintf(estyle,"%s/%s",arg[2],lmp->suffix); if (strcmp(estyle,fix[ifix]->style) == 0) match = 1; } if (lmp->suffix2) { sprintf(estyle,"%s/%s",arg[2],lmp->suffix2); if (strcmp(estyle,fix[ifix]->style) == 0) match = 1; } } if (!match) error->all(FLERR, "Replacing a fix, but new style != old style"); if (fix[ifix]->igroup != igroup && comm->me == 0) error->warning(FLERR,"Replacing a fix, but new group != old group"); delete fix[ifix]; fix[ifix] = NULL; } else { newflag = 1; if (nfix == maxfix) { maxfix += DELTA; fix = (Fix **) memory->srealloc(fix,maxfix*sizeof(Fix *),"modify:fix"); memory->grow(fmask,maxfix,"modify:fmask"); } } // create the Fix // try first with suffix appended fix[ifix] = NULL; if (trysuffix && lmp->suffix_enable) { if (lmp->suffix) { int n = strlen(arg[2])+strlen(lmp->suffix)+2; char *estyle = new char[n]; sprintf(estyle,"%s/%s",arg[2],lmp->suffix); if (fix_map->find(estyle) != fix_map->end()) { FixCreator fix_creator = (*fix_map)[estyle]; fix[ifix] = fix_creator(lmp,narg,arg); delete[] fix[ifix]->style; fix[ifix]->style = estyle; } else delete[] estyle; } if (fix[ifix] == NULL && lmp->suffix2) { int n = strlen(arg[2])+strlen(lmp->suffix2)+2; char *estyle = new char[n]; sprintf(estyle,"%s/%s",arg[2],lmp->suffix2); if (fix_map->find(estyle) != fix_map->end()) { FixCreator fix_creator = (*fix_map)[estyle]; fix[ifix] = fix_creator(lmp,narg,arg); delete[] fix[ifix]->style; fix[ifix]->style = estyle; } else delete[] estyle; } } if (fix[ifix] == NULL && fix_map->find(arg[2]) != fix_map->end()) { FixCreator fix_creator = (*fix_map)[arg[2]]; fix[ifix] = fix_creator(lmp,narg,arg); } if (fix[ifix] == NULL) { char str[128]; sprintf(str,"Unknown fix style %s",arg[2]); error->all(FLERR,str); } // check if Fix is in restart_global list // if yes, pass state info to the Fix so it can reset itself for (int i = 0; i < nfix_restart_global; i++) if (strcmp(id_restart_global[i],fix[ifix]->id) == 0 && strcmp(style_restart_global[i],fix[ifix]->style) == 0) { fix[ifix]->restart(state_restart_global[i]); used_restart_global[i] = 1; if (comm->me == 0) { if (screen) fprintf(screen,"Resetting global fix info from restart file:\n"); if (logfile) fprintf(logfile,"Resetting global fix info from restart file:\n"); if (screen) fprintf(screen," fix style: %s, fix ID: %s\n", fix[ifix]->style,fix[ifix]->id); if (logfile) fprintf(logfile," fix style: %s, fix ID: %s\n", fix[ifix]->style,fix[ifix]->id); } } // check if Fix is in restart_peratom list // if yes, loop over atoms so they can extract info from atom->extra array for (int i = 0; i < nfix_restart_peratom; i++) if (strcmp(id_restart_peratom[i],fix[ifix]->id) == 0 && strcmp(style_restart_peratom[i],fix[ifix]->style) == 0) { used_restart_peratom[i] = 1; for (int j = 0; j < atom->nlocal; j++) fix[ifix]->unpack_restart(j,index_restart_peratom[i]); fix[ifix]->restart_reset = 1; if (comm->me == 0) { if (screen) fprintf(screen,"Resetting peratom fix info from restart file:\n"); if (logfile) fprintf(logfile,"Resetting peratom fix info from restart file:\n"); if (screen) fprintf(screen," fix style: %s, fix ID: %s\n", fix[ifix]->style,fix[ifix]->id); if (logfile) fprintf(logfile," fix style: %s, fix ID: %s\n", fix[ifix]->style,fix[ifix]->id); } } // increment nfix (if new) // set fix mask values // post_constructor() allows new fix to create other fixes // nfix increment comes first so that recursive call to add_fix within // post_constructor() will see updated nfix if (newflag) nfix++; fmask[ifix] = fix[ifix]->setmask(); fix[ifix]->post_constructor(); } /* ---------------------------------------------------------------------- one instance per fix in style_fix.h ------------------------------------------------------------------------- */ template Fix *Modify::fix_creator(LAMMPS *lmp, int narg, char **arg) { return new T(lmp,narg,arg); } /* ---------------------------------------------------------------------- modify a Fix's parameters ------------------------------------------------------------------------- */ void Modify::modify_fix(int narg, char **arg) { if (narg < 2) error->all(FLERR,"Illegal fix_modify command"); // lookup Fix ID int ifix; for (ifix = 0; ifix < nfix; ifix++) if (strcmp(arg[0],fix[ifix]->id) == 0) break; if (ifix == nfix) error->all(FLERR,"Could not find fix_modify ID"); fix[ifix]->modify_params(narg-1,&arg[1]); } /* ---------------------------------------------------------------------- delete a Fix from list of Fixes Atom class must update indices in its list of callbacks to fixes ------------------------------------------------------------------------- */ void Modify::delete_fix(const char *id) { int ifix = find_fix(id); if (ifix < 0) error->all(FLERR,"Could not find fix ID to delete"); delete_fix(ifix); } void Modify::delete_fix(int ifix) { if (fix[ifix]) delete fix[ifix]; atom->update_callback(ifix); // move other Fixes and fmask down in list one slot for (int i = ifix+1; i < nfix; i++) fix[i-1] = fix[i]; for (int i = ifix+1; i < nfix; i++) fmask[i-1] = fmask[i]; nfix--; } /* ---------------------------------------------------------------------- find a fix by ID return index of fix or -1 if not found ------------------------------------------------------------------------- */ int Modify::find_fix(const char *id) { if (id == NULL) return -1; int ifix; for (ifix = 0; ifix < nfix; ifix++) if (strcmp(id,fix[ifix]->id) == 0) break; if (ifix == nfix) return -1; return ifix; } /* ---------------------------------------------------------------------- find a fix by style return index of fix or -1 if not found ------------------------------------------------------------------------- */ int Modify::find_fix_by_style(const char *style) { int ifix; for (ifix = 0; ifix < nfix; ifix++) if (strcmp(style,fix[ifix]->style) == 0) break; if (ifix == nfix) return -1; return ifix; } /* ---------------------------------------------------------------------- check for fix associated with package name in compiled list return 1 if found else 0 used to determine whether LAMMPS was built with GPU, USER-INTEL, USER-OMP packages, which have their own fixes ------------------------------------------------------------------------- */ int Modify::check_package(const char *package_fix_name) { if (fix_map->find(package_fix_name) == fix_map->end()) return 0; return 1; } /* ---------------------------------------------------------------------- check if the group indicated by groupbit overlaps with any currently existing rigid fixes. return 1 in this case otherwise 0 ------------------------------------------------------------------------- */ int Modify::check_rigid_group_overlap(int groupbit) { const int * const mask = atom->mask; const int nlocal = atom->nlocal; int dim; int n = 0; for (int ifix = 0; ifix < nfix; ifix++) { if (strncmp("rigid",fix[ifix]->style,5) == 0) { const int * const body = (const int *)fix[ifix]->extract("body",dim); if ((body == NULL) || (dim != 1)) break; for (int i=0; (i < nlocal) && (n == 0); ++i) if ((mask[i] & groupbit) && (body[i] >= 0)) ++n; } } int n_all = 0; MPI_Allreduce(&n,&n_all,1,MPI_INT,MPI_SUM,world); if (n_all > 0) return 1; return 0; } /* ---------------------------------------------------------------------- check if the atoms in the group indicated by groupbit _and_ region indicated by regionid overlap with any currently existing rigid fixes. return 1 in this case, otherwise 0 ------------------------------------------------------------------------- */ int Modify::check_rigid_region_overlap(int groupbit, Region *reg) { const int * const mask = atom->mask; const double * const * const x = atom->x; const int nlocal = atom->nlocal; int dim; int n = 0; reg->prematch(); for (int ifix = 0; ifix < nfix; ifix++) { if (strncmp("rigid",fix[ifix]->style,5) == 0) { const int * const body = (const int *)fix[ifix]->extract("body",dim); if ((body == NULL) || (dim != 1)) break; for (int i=0; (i < nlocal) && (n == 0); ++i) if ((mask[i] & groupbit) && (body[i] >= 0) && reg->match(x[i][0],x[i][1],x[i][2])) ++n; } } int n_all = 0; MPI_Allreduce(&n,&n_all,1,MPI_INT,MPI_SUM,world); if (n_all > 0) return 1; return 0; } /* ---------------------------------------------------------------------- check if the atoms in the selection list (length atom->nlocal, content: 1 if atom is contained, 0 if not) overlap with currently existing rigid fixes. return 1 in this case otherwise 0 ------------------------------------------------------------------------- */ int Modify::check_rigid_list_overlap(int *select) { const int nlocal = atom->nlocal; int dim; int n = 0; for (int ifix = 0; ifix < nfix; ifix++) { if (strncmp("rigid",fix[ifix]->style,5) == 0) { const int * const body = (const int *)fix[ifix]->extract("body",dim); if ((body == NULL) || (dim != 1)) break; for (int i=0; (i < nlocal) && (n == 0); ++i) if ((body[i] >= 0) && select[i]) ++n; } } int n_all = 0; MPI_Allreduce(&n,&n_all,1,MPI_INT,MPI_SUM,world); if (n_all > 0) return 1; return 0; } /* ---------------------------------------------------------------------- add a new compute ------------------------------------------------------------------------- */ void Modify::add_compute(int narg, char **arg, int trysuffix) { if (narg < 3) error->all(FLERR,"Illegal compute command"); // error check for (int icompute = 0; icompute < ncompute; icompute++) if (strcmp(arg[0],compute[icompute]->id) == 0) error->all(FLERR,"Reuse of compute ID"); // extend Compute list if necessary if (ncompute == maxcompute) { maxcompute += DELTA; compute = (Compute **) memory->srealloc(compute,maxcompute*sizeof(Compute *),"modify:compute"); } // create the Compute // try first with suffix appended compute[ncompute] = NULL; if (trysuffix && lmp->suffix_enable) { if (lmp->suffix) { int n = strlen(arg[2])+strlen(lmp->suffix)+2; char *estyle = new char[n]; sprintf(estyle,"%s/%s",arg[2],lmp->suffix); if (compute_map->find(estyle) != compute_map->end()) { ComputeCreator compute_creator = (*compute_map)[estyle]; compute[ncompute] = compute_creator(lmp,narg,arg); delete[] compute[ncompute]->style; compute[ncompute]->style = estyle; } else delete[] estyle; } if (compute[ncompute] == NULL && lmp->suffix2) { int n = strlen(arg[2])+strlen(lmp->suffix2)+2; char *estyle = new char[n]; sprintf(estyle,"%s/%s",arg[2],lmp->suffix2); if (compute_map->find(estyle) != compute_map->end()) { ComputeCreator compute_creator = (*compute_map)[estyle]; compute[ncompute] = compute_creator(lmp,narg,arg); delete[] compute[ncompute]->style; compute[ncompute]->style = estyle; } else delete[] estyle; } } if (compute[ncompute] == NULL && compute_map->find(arg[2]) != compute_map->end()) { ComputeCreator compute_creator = (*compute_map)[arg[2]]; compute[ncompute] = compute_creator(lmp,narg,arg); } if (compute[ncompute] == NULL) { char str[128]; sprintf(str,"Unknown compute style %s",arg[2]); error->all(FLERR,str); } ncompute++; } /* ---------------------------------------------------------------------- one instance per compute in style_compute.h ------------------------------------------------------------------------- */ template Compute *Modify::compute_creator(LAMMPS *lmp, int narg, char **arg) { return new T(lmp,narg,arg); } /* ---------------------------------------------------------------------- modify a Compute's parameters ------------------------------------------------------------------------- */ void Modify::modify_compute(int narg, char **arg) { if (narg < 2) error->all(FLERR,"Illegal compute_modify command"); // lookup Compute ID int icompute; for (icompute = 0; icompute < ncompute; icompute++) if (strcmp(arg[0],compute[icompute]->id) == 0) break; if (icompute == ncompute) error->all(FLERR,"Could not find compute_modify ID"); compute[icompute]->modify_params(narg-1,&arg[1]); } /* ---------------------------------------------------------------------- delete a Compute from list of Computes ------------------------------------------------------------------------- */ void Modify::delete_compute(const char *id) { int icompute = find_compute(id); if (icompute < 0) error->all(FLERR,"Could not find compute ID to delete"); delete compute[icompute]; // move other Computes down in list one slot for (int i = icompute+1; i < ncompute; i++) compute[i-1] = compute[i]; ncompute--; } /* ---------------------------------------------------------------------- find a compute by ID return index of compute or -1 if not found ------------------------------------------------------------------------- */ int Modify::find_compute(const char *id) { if(id==NULL) return -1; int icompute; for (icompute = 0; icompute < ncompute; icompute++) if (strcmp(id,compute[icompute]->id) == 0) break; if (icompute == ncompute) return -1; return icompute; } /* ---------------------------------------------------------------------- clear invoked flag of all computes called everywhere that computes are used, before computes are invoked invoked flag used to avoid re-invoking same compute multiple times and to flag computes that store invocation times as having been invoked ------------------------------------------------------------------------- */ void Modify::clearstep_compute() { for (int icompute = 0; icompute < ncompute; icompute++) compute[icompute]->invoked_flag = 0; } /* ---------------------------------------------------------------------- loop over computes that store invocation times if its invoked flag set on this timestep, schedule next invocation called everywhere that computes are used, after computes are invoked ------------------------------------------------------------------------- */ void Modify::addstep_compute(bigint newstep) { for (int icompute = 0; icompute < n_timeflag; icompute++) if (compute[list_timeflag[icompute]]->invoked_flag) compute[list_timeflag[icompute]]->addstep(newstep); } /* ---------------------------------------------------------------------- loop over all computes schedule next invocation for those that store invocation times called when not sure what computes will be needed on newstep do not loop only over n_timeflag, since may not be set yet ------------------------------------------------------------------------- */ void Modify::addstep_compute_all(bigint newstep) { for (int icompute = 0; icompute < ncompute; icompute++) if (compute[icompute]->timeflag) compute[icompute]->addstep(newstep); } /* ---------------------------------------------------------------------- write to restart file for all Fixes with restart info (1) fixes that have global state (2) fixes that store per-atom quantities ------------------------------------------------------------------------- */ void Modify::write_restart(FILE *fp) { int me = comm->me; int count = 0; for (int i = 0; i < nfix; i++) if (fix[i]->restart_global) count++; if (me == 0) fwrite(&count,sizeof(int),1,fp); int n; for (int i = 0; i < nfix; i++) if (fix[i]->restart_global) { if (me == 0) { n = strlen(fix[i]->id) + 1; fwrite(&n,sizeof(int),1,fp); fwrite(fix[i]->id,sizeof(char),n,fp); n = strlen(fix[i]->style) + 1; fwrite(&n,sizeof(int),1,fp); fwrite(fix[i]->style,sizeof(char),n,fp); } fix[i]->write_restart(fp); } count = 0; for (int i = 0; i < nfix; i++) if (fix[i]->restart_peratom) count++; if (me == 0) fwrite(&count,sizeof(int),1,fp); for (int i = 0; i < nfix; i++) if (fix[i]->restart_peratom) { int maxsize_restart = fix[i]->maxsize_restart(); if (me == 0) { n = strlen(fix[i]->id) + 1; fwrite(&n,sizeof(int),1,fp); fwrite(fix[i]->id,sizeof(char),n,fp); n = strlen(fix[i]->style) + 1; fwrite(&n,sizeof(int),1,fp); fwrite(fix[i]->style,sizeof(char),n,fp); fwrite(&maxsize_restart,sizeof(int),1,fp); } } } /* ---------------------------------------------------------------------- read in restart file data on all previously defined Fixes with restart info (1) fixes that have global state (2) fixes that store per-atom quantities return maxsize of extra info that will be stored with any atom ------------------------------------------------------------------------- */ int Modify::read_restart(FILE *fp) { // nfix_restart_global = # of restart entries with global state info int me = comm->me; if (me == 0) fread(&nfix_restart_global,sizeof(int),1,fp); MPI_Bcast(&nfix_restart_global,1,MPI_INT,0,world); // allocate space for each entry if (nfix_restart_global) { id_restart_global = new char*[nfix_restart_global]; style_restart_global = new char*[nfix_restart_global]; state_restart_global = new char*[nfix_restart_global]; used_restart_global = new int[nfix_restart_global]; } // read each entry and Bcast to all procs // each entry has id string, style string, chunk of state data int n; for (int i = 0; i < nfix_restart_global; i++) { if (me == 0) fread(&n,sizeof(int),1,fp); MPI_Bcast(&n,1,MPI_INT,0,world); id_restart_global[i] = new char[n]; if (me == 0) fread(id_restart_global[i],sizeof(char),n,fp); MPI_Bcast(id_restart_global[i],n,MPI_CHAR,0,world); if (me == 0) fread(&n,sizeof(int),1,fp); MPI_Bcast(&n,1,MPI_INT,0,world); style_restart_global[i] = new char[n]; if (me == 0) fread(style_restart_global[i],sizeof(char),n,fp); MPI_Bcast(style_restart_global[i],n,MPI_CHAR,0,world); if (me == 0) fread(&n,sizeof(int),1,fp); MPI_Bcast(&n,1,MPI_INT,0,world); state_restart_global[i] = new char[n]; if (me == 0) fread(state_restart_global[i],sizeof(char),n,fp); MPI_Bcast(state_restart_global[i],n,MPI_CHAR,0,world); used_restart_global[i] = 0; } // nfix_restart_peratom = # of restart entries with peratom info int maxsize = 0; if (me == 0) fread(&nfix_restart_peratom,sizeof(int),1,fp); MPI_Bcast(&nfix_restart_peratom,1,MPI_INT,0,world); // allocate space for each entry if (nfix_restart_peratom) { id_restart_peratom = new char*[nfix_restart_peratom]; style_restart_peratom = new char*[nfix_restart_peratom]; index_restart_peratom = new int[nfix_restart_peratom]; used_restart_peratom = new int[nfix_restart_peratom]; } // read each entry and Bcast to all procs // each entry has id string, style string, maxsize of one atom's data // set index = which set of extra data this fix represents for (int i = 0; i < nfix_restart_peratom; i++) { if (me == 0) fread(&n,sizeof(int),1,fp); MPI_Bcast(&n,1,MPI_INT,0,world); id_restart_peratom[i] = new char[n]; if (me == 0) fread(id_restart_peratom[i],sizeof(char),n,fp); MPI_Bcast(id_restart_peratom[i],n,MPI_CHAR,0,world); if (me == 0) fread(&n,sizeof(int),1,fp); MPI_Bcast(&n,1,MPI_INT,0,world); style_restart_peratom[i] = new char[n]; if (me == 0) fread(style_restart_peratom[i],sizeof(char),n,fp); MPI_Bcast(style_restart_peratom[i],n,MPI_CHAR,0,world); if (me == 0) fread(&n,sizeof(int),1,fp); MPI_Bcast(&n,1,MPI_INT,0,world); maxsize += n; index_restart_peratom[i] = i; used_restart_peratom[i] = 0; } return maxsize; } /* ---------------------------------------------------------------------- delete all lists of restart file Fix info if flag set, print list of restart file info not assigned to new fixes ------------------------------------------------------------------------- */ void Modify::restart_deallocate(int flag) { if (nfix_restart_global) { if (flag && comm->me == 0) { int i; for (i = 0; i < nfix_restart_global; i++) if (used_restart_global[i] == 0) break; if (i == nfix_restart_global) { if (screen) fprintf(screen,"All restart file global fix info " "was re-assigned\n"); if (logfile) fprintf(logfile,"All restart file global fix info " "was re-assigned\n"); } else { if (screen) fprintf(screen,"Unused restart file global fix info:\n"); if (logfile) fprintf(logfile,"Unused restart file global fix info:\n"); for (i = 0; i < nfix_restart_global; i++) { if (used_restart_global[i]) continue; if (screen) fprintf(screen," fix style: %s, fix ID: %s\n", style_restart_global[i],id_restart_global[i]); if (logfile) fprintf(logfile," fix style: %s, fix ID: %s\n", style_restart_global[i],id_restart_global[i]); } } } for (int i = 0; i < nfix_restart_global; i++) { delete [] id_restart_global[i]; delete [] style_restart_global[i]; delete [] state_restart_global[i]; } delete [] id_restart_global; delete [] style_restart_global; delete [] state_restart_global; delete [] used_restart_global; } if (nfix_restart_peratom) { if (flag && comm->me == 0) { int i; for (i = 0; i < nfix_restart_peratom; i++) if (used_restart_peratom[i] == 0) break; if (i == nfix_restart_peratom) { if (screen) fprintf(screen,"All restart file peratom fix info " "was re-assigned\n"); if (logfile) fprintf(logfile,"All restart file peratom fix info " "was re-assigned\n"); } else { if (screen) fprintf(screen,"Unused restart file peratom fix info:\n"); if (logfile) fprintf(logfile,"Unused restart file peratom fix info:\n"); for (i = 0; i < nfix_restart_peratom; i++) { if (used_restart_peratom[i]) continue; if (screen) fprintf(screen," fix style: %s, fix ID: %s\n", style_restart_peratom[i],id_restart_peratom[i]); if (logfile) fprintf(logfile," fix style: %s, fix ID: %s\n", style_restart_peratom[i],id_restart_peratom[i]); } } } for (int i = 0; i < nfix_restart_peratom; i++) { delete [] id_restart_peratom[i]; delete [] style_restart_peratom[i]; } delete [] id_restart_peratom; delete [] style_restart_peratom; delete [] index_restart_peratom; delete [] used_restart_peratom; } nfix_restart_global = nfix_restart_peratom = 0; } /* ---------------------------------------------------------------------- create list of fix indices for fixes which match mask ------------------------------------------------------------------------- */ void Modify::list_init(int mask, int &n, int *&list) { delete [] list; n = 0; for (int i = 0; i < nfix; i++) if (fmask[i] & mask) n++; list = new int[n]; n = 0; for (int i = 0; i < nfix; i++) if (fmask[i] & mask) list[n++] = i; } /* ---------------------------------------------------------------------- create list of fix indices for end_of_step fixes also create end_of_step_every[] ------------------------------------------------------------------------- */ void Modify::list_init_end_of_step(int mask, int &n, int *&list) { delete [] list; delete [] end_of_step_every; n = 0; for (int i = 0; i < nfix; i++) if (fmask[i] & mask) n++; list = new int[n]; end_of_step_every = new int[n]; n = 0; for (int i = 0; i < nfix; i++) if (fmask[i] & mask) { list[n] = i; end_of_step_every[n++] = fix[i]->nevery; } } /* ---------------------------------------------------------------------- create list of fix indices for thermo energy fixes only added to list if fix has THERMO_ENERGY mask set, and its thermo_energy flag was set via fix_modify ------------------------------------------------------------------------- */ void Modify::list_init_thermo_energy(int mask, int &n, int *&list) { delete [] list; n = 0; for (int i = 0; i < nfix; i++) if (fmask[i] & mask && fix[i]->thermo_energy) n++; list = new int[n]; n = 0; for (int i = 0; i < nfix; i++) if (fmask[i] & mask && fix[i]->thermo_energy) list[n++] = i; } /* ---------------------------------------------------------------------- create list of fix indices for peratom thermo energy fixes only added to list if fix has its peatom_flag set, and its thermo_energy flag was set via fix_modify ------------------------------------------------------------------------- */ void Modify::list_init_thermo_energy_atom(int &n, int *&list) { delete [] list; n = 0; for (int i = 0; i < nfix; i++) if (fix[i]->peatom_flag && fix[i]->thermo_energy) n++; list = new int[n]; n = 0; for (int i = 0; i < nfix; i++) if (fix[i]->peatom_flag && fix[i]->thermo_energy) list[n++] = i; } /* ---------------------------------------------------------------------- create list of compute indices for computes which store invocation times ------------------------------------------------------------------------- */ void Modify::list_init_compute() { delete [] list_timeflag; n_timeflag = 0; for (int i = 0; i < ncompute; i++) if (compute[i]->timeflag) n_timeflag++; list_timeflag = new int[n_timeflag]; n_timeflag = 0; for (int i = 0; i < ncompute; i++) if (compute[i]->timeflag) list_timeflag[n_timeflag++] = i; } /* ---------------------------------------------------------------------- return # of bytes of allocated memory from all fixes ------------------------------------------------------------------------- */ bigint Modify::memory_usage() { bigint bytes = 0; for (int i = 0; i < nfix; i++) bytes += static_cast (fix[i]->memory_usage()); for (int i = 0; i < ncompute; i++) bytes += static_cast (compute[i]->memory_usage()); return bytes; } diff --git a/src/modify.h b/src/modify.h index 4ec61f6d5..3e20df5aa 100644 --- a/src/modify.h +++ b/src/modify.h @@ -1,251 +1,255 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #ifndef LMP_MODIFY_H #define LMP_MODIFY_H #include #include "pointers.h" #include #include namespace LAMMPS_NS { class Modify : protected Pointers { friend class Info; friend class FixSRP; friend class Respa; friend class RespaOMP; public: int nfix,maxfix; - int n_initial_integrate,n_post_integrate,n_pre_exchange,n_pre_neighbor; + int n_initial_integrate,n_post_integrate,n_pre_exchange; + int n_pre_neighbor,n_post_neighbor; int n_pre_force,n_pre_reverse,n_post_force; int n_final_integrate,n_end_of_step,n_thermo_energy,n_thermo_energy_atom; int n_initial_integrate_respa,n_post_integrate_respa; int n_pre_force_respa,n_post_force_respa,n_final_integrate_respa; - int n_min_pre_exchange,n_min_pre_neighbor; + int n_min_pre_exchange,n_min_pre_neighbor,n_min_post_neighbor; int n_min_pre_force,n_min_pre_reverse,n_min_post_force,n_min_energy; int restart_pbc_any; // 1 if any fix sets restart_pbc int nfix_restart_global; // stored fix global info from restart file int nfix_restart_peratom; // stored fix peratom info from restart file class Fix **fix; // list of fixes int *fmask; // bit mask for when each fix is applied int ncompute,maxcompute; // list of computes class Compute **compute; Modify(class LAMMPS *); virtual ~Modify(); virtual void init(); virtual void setup(int); virtual void setup_pre_exchange(); virtual void setup_pre_neighbor(); + virtual void setup_post_neighbor(); virtual void setup_pre_force(int); virtual void setup_pre_reverse(int, int); virtual void initial_integrate(int); virtual void post_integrate(); virtual void pre_exchange(); virtual void pre_neighbor(); + virtual void post_neighbor(); virtual void pre_force(int); virtual void pre_reverse(int,int); virtual void post_force(int); virtual void final_integrate(); virtual void end_of_step(); virtual double thermo_energy(); virtual void thermo_energy_atom(int, double *); virtual void post_run(); virtual void create_attribute(int); virtual void setup_pre_force_respa(int, int); virtual void initial_integrate_respa(int, int, int); virtual void post_integrate_respa(int, int); virtual void pre_force_respa(int, int, int); virtual void post_force_respa(int, int, int); virtual void final_integrate_respa(int, int); virtual void min_pre_exchange(); virtual void min_pre_neighbor(); + virtual void min_post_neighbor(); virtual void min_pre_force(int); virtual void min_pre_reverse(int,int); virtual void min_post_force(int); virtual double min_energy(double *); virtual void min_store(); virtual void min_step(double, double *); virtual void min_clearstore(); virtual void min_pushstore(); virtual void min_popstore(); virtual double max_alpha(double *); virtual int min_dof(); virtual int min_reset_ref(); void add_fix(int, char **, int trysuffix=1); void modify_fix(int, char **); void delete_fix(const char *); void delete_fix(int); int find_fix(const char *); int find_fix_by_style(const char *); int check_package(const char *); int check_rigid_group_overlap(int); int check_rigid_region_overlap(int, class Region *); int check_rigid_list_overlap(int *); void add_compute(int, char **, int trysuffix=1); void modify_compute(int, char **); void delete_compute(const char *); int find_compute(const char *); void clearstep_compute(); void addstep_compute(bigint); void addstep_compute_all(bigint); void write_restart(FILE *); int read_restart(FILE *); void restart_deallocate(int); bigint memory_usage(); protected: // lists of fixes to apply at different stages of timestep int *list_initial_integrate,*list_post_integrate; - int *list_pre_exchange,*list_pre_neighbor; + int *list_pre_exchange,*list_pre_neighbor,*list_post_neighbor; int *list_pre_force,*list_pre_reverse,*list_post_force; int *list_final_integrate,*list_end_of_step,*list_thermo_energy; int *list_thermo_energy_atom; int *list_initial_integrate_respa,*list_post_integrate_respa; int *list_pre_force_respa,*list_post_force_respa; int *list_final_integrate_respa; - int *list_min_pre_exchange,*list_min_pre_neighbor; + int *list_min_pre_exchange,*list_min_pre_neighbor,*list_min_post_neighbor; int *list_min_pre_force,*list_min_pre_reverse,*list_min_post_force; int *list_min_energy; int *end_of_step_every; int n_timeflag; // list of computes that store time invocation int *list_timeflag; char **id_restart_global; // stored fix global info char **style_restart_global; // from read-in restart file char **state_restart_global; int *used_restart_global; char **id_restart_peratom; // stored fix peratom info char **style_restart_peratom; // from read-in restart file int *index_restart_peratom; int *used_restart_peratom; int index_permanent; // fix/compute index returned to library call void list_init(int, int &, int *&); void list_init_end_of_step(int, int &, int *&); void list_init_thermo_energy(int, int &, int *&); void list_init_thermo_energy_atom(int &, int *&); void list_init_dofflag(int &, int *&); void list_init_compute(); public: typedef Compute *(*ComputeCreator)(LAMMPS *, int, char **); typedef std::map ComputeCreatorMap; ComputeCreatorMap *compute_map; typedef Fix *(*FixCreator)(LAMMPS *, int, char **); typedef std::map FixCreatorMap; FixCreatorMap *fix_map; protected: template static Compute *compute_creator(LAMMPS *, int, char **); template static Fix *fix_creator(LAMMPS *, int, char **); }; } #endif /* ERROR/WARNING messages: E: Fix %s does not allow use of dynamic group Dynamic groups have not yet been enabled for this fix. E: Compute %s does not allow use of dynamic group Dynamic groups have not yet been enabled for this compute. W: One or more atoms are time integrated more than once This is probably an error since you typically do not want to advance the positions or velocities of an atom more than once per timestep. E: Illegal ... command Self-explanatory. Check the input script syntax and compare to the documentation for the command. You can use -echo screen as a command-line option when running LAMMPS to see the offending line. E: Fix command before simulation box is defined The fix command cannot be used before a read_data, read_restart, or create_box command. E: Could not find fix group ID A group ID used in the fix command does not exist. E: Replacing a fix, but new style != old style A fix ID can be used a 2nd time, but only if the style matches the previous fix. In this case it is assumed you with to reset a fix's parameters. This error may mean you are mistakenly re-using a fix ID when you do not intend to. W: Replacing a fix, but new group != old group The ID and style of a fix match for a fix you are changing with a fix command, but the new group you are specifying does not match the old group. E: Unknown fix style The choice of fix style is unknown. E: Could not find fix_modify ID A fix ID used in the fix_modify command does not exist. E: Could not find fix ID to delete Self-explanatory. E: Reuse of compute ID A compute ID cannot be used twice. E: Unknown compute style The choice of compute style is unknown. E: Could not find compute_modify ID Self-explanatory. E: Could not find compute ID to delete Self-explanatory. */ diff --git a/src/neigh_list.cpp b/src/neigh_list.cpp index dde544a69..934b9f7d9 100644 --- a/src/neigh_list.cpp +++ b/src/neigh_list.cpp @@ -1,303 +1,330 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include "neigh_list.h" #include "atom.h" #include "comm.h" #include "update.h" #include "pair.h" #include "neighbor.h" #include "neigh_request.h" #include "my_page.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; #define PGDELTA 1 enum{NSQ,BIN,MULTI}; // also in Neighbor /* ---------------------------------------------------------------------- */ NeighList::NeighList(LAMMPS *lmp) : Pointers(lmp) { // initializations maxatom = 0; inum = gnum = 0; ilist = NULL; numneigh = NULL; firstneigh = NULL; - firstdouble = NULL; // defaults, but may be reset by post_constructor() occasional = 0; ghost = 0; ssa = 0; + history = 0; + respaouter = 0; + respamiddle = 0; + respainner = 0; copy = 0; copymode = 0; - dnum = 0; // ptrs iskip = NULL; ijskip = NULL; listcopy = NULL; listskip = NULL; listfull = NULL; - listhistory = NULL; - fix_history = NULL; - - respamiddle = 0; - listinner = NULL; - listmiddle = NULL; - fix_bond = NULL; ipage = NULL; - dpage = NULL; + + // extra rRESPA lists + + inum_inner = gnum_inner = 0; + ilist_inner = NULL; + numneigh_inner = NULL; + firstneigh_inner = NULL; + + inum_middle = gnum_middle = 0; + ilist_middle = NULL; + numneigh_middle = NULL; + firstneigh_middle = NULL; + + ipage_inner = NULL; + ipage_middle = NULL; // Kokkos package kokkos = 0; execution_space = Host; // USER-DPD package for (int i = 0; i < 8; i++) AIRct_ssa[i] = 0; np = NULL; } /* ---------------------------------------------------------------------- */ NeighList::~NeighList() { if (copymode) return; if (!copy) { memory->destroy(ilist); memory->destroy(numneigh); memory->sfree(firstneigh); - memory->sfree(firstdouble); - delete [] ipage; - delete [] dpage; + } + + if (respainner) { + memory->destroy(ilist_inner); + memory->destroy(numneigh_inner); + memory->sfree(firstneigh_inner); + delete [] ipage_inner; + } + + if (respamiddle) { + memory->destroy(ilist_middle); + memory->destroy(numneigh_middle); + memory->sfree(firstneigh_middle); + delete [] ipage_middle; } delete [] iskip; memory->destroy(ijskip); } /* ---------------------------------------------------------------------- adjust settings to match corresponding NeighRequest cannot do this in constructor b/c not all NeighLists are allocated yet copy -> set listcopy for list to copy from skip -> set listskip for list to skip from, create copy of itype,ijtype halffull -> set listfull for full list to derive from - history -> set LH and FH ptrs in partner list that uses the history info - respaouter -> set listinner/listmiddle for other rRESPA lists + respaouter -> set all 3 outer/middle/inner flags bond -> set fix_bond to Fix that made the request ------------------------------------------------------------------------- */ void NeighList::post_constructor(NeighRequest *nq) { // copy request settings used by list itself occasional = nq->occasional; ghost = nq->ghost; ssa = nq->ssa; + history = nq->history; + respaouter = nq->respaouter; + respamiddle = nq->respamiddle; + respainner = nq->respainner; copy = nq->copy; - dnum = nq->dnum; if (nq->copy) listcopy = neighbor->lists[nq->copylist]; if (nq->skip) { listskip = neighbor->lists[nq->skiplist]; int ntypes = atom->ntypes; iskip = new int[ntypes+1]; memory->create(ijskip,ntypes+1,ntypes+1,"neigh_list:ijskip"); int i,j; for (i = 1; i <= ntypes; i++) iskip[i] = nq->iskip[i]; for (i = 1; i <= ntypes; i++) for (j = 1; j <= ntypes; j++) ijskip[i][j] = nq->ijskip[i][j]; } if (nq->halffull) listfull = neighbor->lists[nq->halffulllist]; - if (nq->history) { - neighbor->lists[nq->historylist]->listhistory = this; - int tmp; - neighbor->lists[nq->historylist]->fix_history = - (Fix *) ((Pair *) nq->requestor)->extract("history",tmp); - } - - if (nq->respaouter) { - if (nq->respamiddlelist < 0) { - respamiddle = 0; - listinner = neighbor->lists[nq->respainnerlist]; - } else { - respamiddle = 1; - listmiddle = neighbor->lists[nq->respamiddlelist]; - listinner = neighbor->lists[nq->respainnerlist]; - } - } - if (nq->bond) fix_bond = (Fix *) nq->requestor; } /* ---------------------------------------------------------------------- */ void NeighList::setup_pages(int pgsize_caller, int oneatom_caller) { pgsize = pgsize_caller; oneatom = oneatom_caller; int nmypage = comm->nthreads; ipage = new MyPage[nmypage]; for (int i = 0; i < nmypage; i++) ipage[i].init(oneatom,pgsize,PGDELTA); - if (dnum) { - dpage = new MyPage[nmypage]; + if (respainner) { + ipage_inner = new MyPage[nmypage]; for (int i = 0; i < nmypage; i++) - dpage[i].init(dnum*oneatom,dnum*pgsize,PGDELTA); - } else dpage = NULL; + ipage_inner[i].init(oneatom,pgsize,PGDELTA); + } + + if (respamiddle) { + ipage_middle = new MyPage[nmypage]; + for (int i = 0; i < nmypage; i++) + ipage_middle[i].init(oneatom,pgsize,PGDELTA); + } } /* ---------------------------------------------------------------------- grow per-atom data to allow for nlocal/nall atoms - for parent lists: - also trigger grow in child list(s) which are not built themselves - history calls grow() in listhistory - respaouter calls grow() in respainner, respamiddle triggered by neighbor list build not called if a copy list ------------------------------------------------------------------------- */ void NeighList::grow(int nlocal, int nall) { - // trigger grow() in children before possible return - - if (listhistory) listhistory->grow(nlocal,nall); - if (listinner) listinner->grow(nlocal,nall); - if (listmiddle) listmiddle->grow(nlocal,nall); - // skip if data structs are already big enough + if (ssa) { if ((nlocal * 3) + nall <= maxatom) return; } else if (ghost) { if (nall <= maxatom) return; } else { if (nlocal <= maxatom) return; } if (ssa) maxatom = (nlocal * 3) + nall; else maxatom = atom->nmax; memory->destroy(ilist); memory->destroy(numneigh); memory->sfree(firstneigh); memory->create(ilist,maxatom,"neighlist:ilist"); memory->create(numneigh,maxatom,"neighlist:numneigh"); firstneigh = (int **) memory->smalloc(maxatom*sizeof(int *), "neighlist:firstneigh"); - if (dnum) { - memory->sfree(firstdouble); - firstdouble = (double **) memory->smalloc(maxatom*sizeof(double *), - "neighlist:firstdouble"); + + if (respainner) { + memory->destroy(ilist_inner); + memory->destroy(numneigh_inner); + memory->sfree(firstneigh_inner); + memory->create(ilist_inner,maxatom,"neighlist:ilist_inner"); + memory->create(numneigh_inner,maxatom,"neighlist:numneigh_inner"); + firstneigh_inner = (int **) memory->smalloc(maxatom*sizeof(int *), + "neighlist:firstneigh_inner"); + } + + if (respamiddle) { + memory->destroy(ilist_middle); + memory->destroy(numneigh_middle); + memory->sfree(firstneigh_middle); + memory->create(ilist_middle,maxatom,"neighlist:ilist_middle"); + memory->create(numneigh_middle,maxatom,"neighlist:numneigh_middle"); + firstneigh_middle = (int **) memory->smalloc(maxatom*sizeof(int *), + "neighlist:firstneigh_middle"); } } /* ---------------------------------------------------------------------- print attributes of this list and associated request ------------------------------------------------------------------------- */ void NeighList::print_attributes() { if (comm->me != 0) return; NeighRequest *rq = neighbor->requests[index]; printf("Neighbor list/request %d:\n",index); printf(" %p = requestor ptr (instance %d id %d)\n", rq->requestor,rq->requestor_instance,rq->id); printf(" %d = pair\n",rq->pair); printf(" %d = fix\n",rq->fix); printf(" %d = compute\n",rq->compute); printf(" %d = command\n",rq->command); printf(" %d = neigh\n",rq->neigh); printf("\n"); printf(" %d = half\n",rq->half); printf(" %d = full\n",rq->full); printf("\n"); printf(" %d = occasional\n",occasional); printf(" %d = newton\n",rq->newton); printf(" %d = ghost flag\n",ghost); printf(" %d = size\n",rq->size); printf(" %d = history\n",rq->history); printf(" %d = granonesided\n",rq->granonesided); - printf(" %d = respainner\n",rq->respainner); - printf(" %d = respamiddle\n",rq->respamiddle); printf(" %d = respaouter\n",rq->respaouter); + printf(" %d = respamiddle\n",rq->respamiddle); + printf(" %d = respainner\n",rq->respainner); printf(" %d = bond\n",rq->bond); printf(" %d = omp\n",rq->omp); printf(" %d = intel\n",rq->intel); printf(" %d = kokkos host\n",rq->kokkos_host); printf(" %d = kokkos device\n",rq->kokkos_device); printf(" %d = ssa flag\n",ssa); - printf(" %d = dnum\n",dnum); printf("\n"); printf(" %d = skip flag\n",rq->skip); printf(" %d = off2on\n",rq->off2on); printf(" %d = copy flag\n",rq->copy); printf(" %d = half/full\n",rq->halffull); - printf(" %d = history/partner\n",rq->history_partner); printf("\n"); } /* ---------------------------------------------------------------------- return # of bytes of allocated memory if growflag = 0, maxatom & maxpage will also be 0 if stencilflag = 0, maxstencil * maxstencil_multi will also be 0 ------------------------------------------------------------------------- */ bigint NeighList::memory_usage() { bigint bytes = 0; bytes += memory->usage(ilist,maxatom); bytes += memory->usage(numneigh,maxatom); bytes += maxatom * sizeof(int *); int nmypage = comm->nthreads; if (ipage) { for (int i = 0; i < nmypage; i++) bytes += ipage[i].size(); } - if (dnum && dpage) { - for (int i = 0; i < nmypage; i++) { - bytes += maxatom * sizeof(double *); - bytes += dpage[i].size(); + if (respainner) { + bytes += memory->usage(ilist_inner,maxatom); + bytes += memory->usage(numneigh_inner,maxatom); + bytes += maxatom * sizeof(int *); + if (ipage_inner) { + for (int i = 0; i < nmypage; i++) + bytes += ipage_inner[i].size(); + } + } + + if (respamiddle) { + bytes += memory->usage(ilist_middle,maxatom); + bytes += memory->usage(numneigh_middle,maxatom); + bytes += maxatom * sizeof(int *); + if (ipage_middle) { + for (int i = 0; i < nmypage; i++) + bytes += ipage_middle[i].size(); } } return bytes; } diff --git a/src/neigh_list.h b/src/neigh_list.h index 4010a6885..d633ba839 100644 --- a/src/neigh_list.h +++ b/src/neigh_list.h @@ -1,101 +1,112 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #ifndef LMP_NEIGH_LIST_H #define LMP_NEIGH_LIST_H #include "pointers.h" #include "my_page.h" namespace LAMMPS_NS { class NeighList : protected Pointers { public: int index; // index of which neigh list this is // also indexes the request it came from // and the npair list of NPair classes int bin_method; // 0 if no binning, else 1-N index into binnames int stencil_method; // 0 if no stencil, else 1-N index into stencilnames int pair_method; // 0 if no pair, else 1-N index into pairnames // settings from NeighRequest int occasional; // 0 if build every reneighbor, 1 if not int ghost; // 1 if list stores neighbors of ghosts int ssa; // 1 if list stores Shardlow data - int copy; // 1 if this list is (host) copied from another list + int history; // 1 if there is neigh history (FixNeighHist) + int respaouter; // 1 if list is a rRespa outer list + int respamiddle; // 1 if there is also a rRespa middle list + int respainner; // 1 if there is also a rRespa inner list + int copy; // 1 if this list is copied from another list int copymode; // 1 if this is a Kokkos on-device copy - int dnum; // # of doubles per neighbor, 0 if none // data structs to store neighbor pairs I,J and associated values int inum; // # of I atoms neighbors are stored for int gnum; // # of ghost atoms neighbors are stored for int *ilist; // local indices of I atoms int *numneigh; // # of J neighbors for each I atom int **firstneigh; // ptr to 1st J int value of each I atom - double **firstdouble; // ptr to 1st J double value of each I atom int maxatom; // size of allocated per-atom arrays int pgsize; // size of each page int oneatom; // max size for one atom MyPage *ipage; // pages of neighbor indices - MyPage *dpage; // pages of neighbor doubles, if dnum > 0 + + // data structs to store rRESPA neighbor pairs I,J and associated values + + int inum_inner; // # of I atoms neighbors are stored for + int gnum_inner; // # of ghost atoms neighbors are stored for + int *ilist_inner; // local indices of I atoms + int *numneigh_inner; // # of J neighbors for each I atom + int **firstneigh_inner; // ptr to 1st J int value of each I atom + + int inum_middle; // # of I atoms neighbors are stored for + int gnum_middle; // # of ghost atoms neighbors are stored for + int *ilist_middle; // local indices of I atoms + int *numneigh_middle; // # of J neighbors for each I atom + int **firstneigh_middle; // ptr to 1st J int value of each I atom + + MyPage *ipage_inner; // pages of neighbor indices for inner + MyPage *ipage_middle; // pages of neighbor indices for middle // atom types to skip when building list // copied info from corresponding request into realloced vec/array int *iskip; // iskip[i] = 1 if atoms of type I are not in list int **ijskip; // ijskip[i][j] = 1 if pairs of type I,J are not in list // settings and pointers for related neighbor lists and fixes NeighList *listcopy; // me = copy list, point to list I copy from NeighList *listskip; // me = skip list, point to list I skip from NeighList *listfull; // me = half list, point to full I derive from - NeighList *listhistory; // list storing neigh history - class Fix *fix_history; // fix that stores history info - - int respamiddle; // 1 if this respaouter has middle list - NeighList *listinner; // me = respaouter, point to respainner - NeighList *listmiddle; // me = respaouter, point to respamiddle - class Fix *fix_bond; // fix that stores bond info // Kokkos package int kokkos; // 1 if list stores Kokkos data ExecutionSpace execution_space; // USER-DPD package and Shardlow Splitting Algorithm (SSA) support int AIRct_ssa[8]; // count of how many atoms in each AIR class NPair *np; // ptr to NPair instance I depend on // methods NeighList(class LAMMPS *); virtual ~NeighList(); void post_constructor(class NeighRequest *); void setup_pages(int, int); // setup page data structures void grow(int,int); // grow all data structs void print_attributes(); // debug routine int get_maxlocal() {return maxatom;} bigint memory_usage(); }; } #endif diff --git a/src/neigh_request.cpp b/src/neigh_request.cpp index 8d720e766..6325eec56 100644 --- a/src/neigh_request.cpp +++ b/src/neigh_request.cpp @@ -1,252 +1,241 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include "neigh_request.h" #include "atom.h" #include "memory.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ NeighRequest::NeighRequest(LAMMPS *lmp) : Pointers(lmp) { // default ID = 0 id = 0; // class user of list: default is pair request // only one is set to 1 pair = 1; fix = compute = command = neigh = 0; // kind of list: default is half neighbor list // only one is set to 1 half = 1; full = 0; // attribute flags, mutiple can be set to 1 // default is every reneighboring, not occasional // default is use newton_pair setting in force // default is no neighbors of ghosts // default is use cutoffs, not size of particles - // default is no additional neighbor history info + // default is no associated neighbor history info in FixNeighHistory // default is no one-sided sphere/surface interactions (when size = 1) // default is neighbors of atoms, not bonds // default is no multilevel rRESPA neighbors // default is no OpenMP multi-threaded neighbor list build // default is no Intel-specific neighbor list build // default is no Kokkos neighbor list build // default is no Shardlow Splitting Algorithm (SSA) neighbor list build // default is no list-specific cutoff // default is no storage of auxiliary floating point values occasional = 0; newton = 0; ghost = 0; size = 0; history = 0; granonesided = 0; respainner = respamiddle = respaouter = 0; bond = 0; omp = 0; intel = 0; kokkos_host = kokkos_device = 0; ssa = 0; cut = 0; cutoff = 0.0; - dnum = 0; - // skip info, default is no skipping skip = 0; iskip = NULL; ijskip = NULL; // only set when command = 1; command_style = NULL; // info set by Neighbor class when morphing original requests skiplist = -1; off2on = 0; copy = 0; copylist = -1; halffull = 0; halffulllist = -1; - history_partner = 0; - historylist = -1; - respaouterlist = -1; - respamiddlelist = -1; - respainnerlist = -1; unique = 0; // internal settings index_bin = index_stencil = index_pair = -1; } /* ---------------------------------------------------------------------- */ NeighRequest::~NeighRequest() { delete [] iskip; memory->destroy(ijskip); } /* ---------------------------------------------------------------------- compare this request to other request identical means requestor identity and all params it sets are the same do not check other params that Neighbor can change after requests are made return 1 if identical, 0 if not ------------------------------------------------------------------------- */ int NeighRequest::identical(NeighRequest *other) { int same = 1; // check for match of requestor_instance and instance counter // prevents an old fix from being unfix/refix in same memory location // stored in requestor, and thus appearing old, when really new // only needed for classes with persistent neigh lists: Pair, Fix, Compute if (requestor != other->requestor) same = 0; if (requestor_instance != other->requestor_instance) same = 0; if (id != other->id) same = 0; // only compare settings made by requestors // not settings made later by Neighbor class if (pair != other->pair) same = 0; if (fix != other->fix) same = 0; if (compute != other->compute) same = 0; if (command != other->command) same = 0; if (neigh != other->neigh) same = 0; if (half != other->half) same = 0; if (full != other->full) same = 0; if (occasional != other->occasional) same = 0; if (newton != other->newton) same = 0; if (ghost != other->ghost) same = 0; if (size != other->size) same = 0; if (history != other->history) same = 0; if (granonesided != other->granonesided) same = 0; if (respainner != other->respainner) same = 0; if (respamiddle != other->respamiddle) same = 0; if (respaouter != other->respaouter) same = 0; if (bond != other->bond) same = 0; if (omp != other->omp) same = 0; if (intel != other->intel) same = 0; if (kokkos_host != other->kokkos_host) same = 0; if (kokkos_device != other->kokkos_device) same = 0; if (ssa != other->ssa) same = 0; if (copy != other->copy) same = 0; if (cutoff != other->cutoff) same = 0; - if (dnum != other->dnum) same = 0; - if (skip != other->skip) same = 0; if (skip) same = same_skip(other); return same; } /* ---------------------------------------------------------------------- compare same info for two requests that have skip = 1 return 1 if identical, 0 if not ------------------------------------------------------------------------- */ int NeighRequest::same_skip(NeighRequest *other) { int i,j; int ntypes = atom->ntypes; int same = 1; for (i = 1; i <= ntypes; i++) if (iskip[i] != other->iskip[i]) same = 0; for (i = 1; i <= ntypes; i++) for (j = 1; j <= ntypes; j++) if (ijskip[i][j] != other->ijskip[i][j]) same = 0; return same; } /* ---------------------------------------------------------------------- set params in this request to those of other request copy same fields that are checked in identical() purpose is to allow comparison of new requests to old requests skipflag = 1 to copy skip vector/array ------------------------------------------------------------------------- */ void NeighRequest::copy_request(NeighRequest *other, int skipflag) { requestor = other->requestor; requestor_instance = other->requestor_instance; id = other->id; pair = other->pair; fix = other->fix; compute = other->compute; command = other->command; half = other->half; full = other->full; occasional = other->occasional; newton = other->newton; ghost = other->ghost; size = other->size; history = other->history; granonesided = other->granonesided; respainner = other->respainner; respamiddle = other->respamiddle; respaouter = other->respaouter; bond = other->bond; omp = other->omp; intel = other->intel; kokkos_host = other->kokkos_host; kokkos_device = other->kokkos_device; ssa = other->ssa; cut = other->cut; cutoff = other->cutoff; - dnum = other->dnum; - iskip = NULL; ijskip = NULL; if (!skipflag) return; int i,j; int ntypes = atom->ntypes; if (other->iskip) { iskip = new int[ntypes+1]; for (i = 1; i <= ntypes; i++) iskip[i] = other->iskip[i]; } if (other->ijskip) { memory->create(ijskip,ntypes+1,ntypes+1,"neigh_request:ijskip"); for (i = 1; i <= ntypes; i++) for (j = 1; j <= ntypes; j++) ijskip[i][j] = other->ijskip[i][j]; } } diff --git a/src/neigh_request.h b/src/neigh_request.h index 70f7783a7..16e6f1a8c 100644 --- a/src/neigh_request.h +++ b/src/neigh_request.h @@ -1,138 +1,124 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #ifndef LMP_NEIGH_REQUEST_H #define LMP_NEIGH_REQUEST_H #include "pointers.h" namespace LAMMPS_NS { class NeighRequest : protected Pointers { public: int index; // index of which neigh request this is void *requestor; // class that made request int requestor_instance; // instance of that class (only Fix, Compute, Pair) int id; // ID of request as stored by requestor // used to track multiple requests from one class // ----------------------------- // flags set by requesting class for attributes of neighor list they need // all must be set appropriately, all have defaults // ----------------------------- // which class style requests the list // one flag is 1, others are 0 int pair; // pair is set by default int fix; int compute; int command; int neigh; // half/full setting, determines which neighbors appear in list // one flag is 1, other is 0 int half; // half neigh list (set by default) int full; // full neigh list // attribute flags, all are 0 by default int occasional; // how often list is built // 0 if needed every reneighboring during run // 1 if only occasionally needed by a fix, compute, etc int newton; // which owned/ghost pairs appear in list // 0 if use force::newton_pair setting // 1 if override with pair newton on // 2 if override with pair newton off int ghost; // 1 if includes ghost atom neighbors int size; // 1 if pair cutoff set by particle radius - int history; // 1 if stores neighbor history info + int history; // 1 if there is also neigh history info (FixNeighHist) int granonesided; // 1 if one-sided granular list for // sphere/surf interactions - int respainner; // 1 if a rRESPA inner list - int respamiddle; // 1 if a rRESPA middle list - int respaouter; // 1 if a rRESPA outer list + int respainner; // 1 if need a rRESPA inner list + int respamiddle; // 1 if need a rRESPA middle list + int respaouter; // 1 if need a rRESPA outer list int bond; // 1 if store bond neighbors instead of atom neighs int omp; // set by USER-OMP package int intel; // set by USER-INTEL package int kokkos_host; // set by KOKKOS package int kokkos_device; int ssa; // set by USER-DPD package, for Shardlow lists int cut; // 1 if use a non-standard cutoff length double cutoff; // special cutoff distance for this list - int dnum; // # of extra floating point values stored in list - // flags set by pair hybrid int skip; // 1 if this list skips atom types from another list int *iskip; // iskip[i] if atoms of type I are not in list int **ijskip; // ijskip[i][j] if pairs of type I,J are not in list // command_style only set if command = 1 // allows print_pair_info() to access command name const char *command_style; // ----------------------------- // flags set by Neighbor class to morph original requests // ----------------------------- int skiplist; // index of list to skip from int off2on; // 1 if this is newton on list, but skips from off list int copy; // 1 if this list copied from another list int copylist; // index of list to copy from int halffull; // 1 if half list computed from another full list int halffulllist; // index of full list to derive half from - int history_partner; // 1 if this list partners with a history list - int historylist; // index of the associated history list - // for history = 1, index of the non-history partner - - int respaouterlist; // index of respaouter/middle/inner lists - int respamiddlelist; // which this rREPSA list is associated with - int respainnerlist; // each rRESPA style list points at the others - int unique; // 1 if this list requires its own // NStencil, Nbin class - because of requestor cutoff - // pointer to FSH class, set by requestor class (not by Neighbor) - - class FixShearHistory *fix_history; // fix that stores per-atom history info - // ----------------------------- // internal settings made by Neighbor class // ----------------------------- int index_bin; // index of NBin class assigned to this request int index_stencil; // index of NStencil class assigned to this request int index_pair; // index of NPair class assigned to this request // methods NeighRequest(class LAMMPS *); ~NeighRequest(); void archive(); int identical(NeighRequest *); int same_skip(NeighRequest *); void copy_request(NeighRequest *, int); }; } #endif diff --git a/src/neighbor.cpp b/src/neighbor.cpp index a460be006..cc2e5d6d1 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -1,2466 +1,2400 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- Contributing author (triclinic and multi-neigh) : Pieter in 't Veld (SNL) ------------------------------------------------------------------------- */ #include #include #include #include #include "neighbor.h" #include "neigh_list.h" #include "neigh_request.h" #include "nbin.h" #include "nstencil.h" #include "npair.h" #include "ntopo.h" #include "style_nbin.h" #include "style_nstencil.h" #include "style_npair.h" #include "style_ntopo.h" #include "atom.h" #include "atom_vec.h" #include "comm.h" #include "force.h" #include "pair.h" #include "domain.h" #include "group.h" #include "modify.h" #include "fix.h" #include "compute.h" #include "update.h" #include "respa.h" #include "output.h" #include "citeme.h" #include "memory.h" #include "error.h" #include using namespace LAMMPS_NS; using namespace NeighConst; #define RQDELTA 1 #define EXDELTA 1 #define BIG 1.0e20 enum{NSQ,BIN,MULTI}; // also in NBin, NeighList, NStencil enum{NONE,ALL,PARTIAL,TEMPLATE}; static const char cite_neigh_multi[] = "neighbor multi command:\n\n" "@Article{Intveld08,\n" " author = {P.{\\,}J.~in{\\,}'t~Veld and S.{\\,}J.~Plimpton" " and G.{\\,}S.~Grest},\n" " title = {Accurate and Efficient Methods for Modeling Colloidal\n" " Mixtures in an Explicit Solvent using Molecular Dynamics},\n" " journal = {Comp.~Phys.~Comm.},\n" " year = 2008,\n" " volume = 179,\n" " pages = {320--329}\n" "}\n\n"; //#define NEIGH_LIST_DEBUG 1 /* ---------------------------------------------------------------------- */ Neighbor::Neighbor(LAMMPS *lmp) : Pointers(lmp), pairclass(NULL), pairnames(NULL), pairmasks(NULL) { MPI_Comm_rank(world,&me); MPI_Comm_size(world,&nprocs); firsttime = 1; style = BIN; every = 1; delay = 10; dist_check = 1; pgsize = 100000; oneatom = 2000; binsizeflag = 0; build_once = 0; cluster_check = 0; ago = -1; cutneighmax = 0.0; cutneighsq = NULL; cutneighghostsq = NULL; cuttype = NULL; cuttypesq = NULL; fixchecklist = NULL; // pairwise neighbor lists and associated data structs nlist = 0; lists = NULL; nbin = 0; neigh_bin = NULL; nstencil = 0; neigh_stencil = NULL; neigh_pair = NULL; nstencil_perpetual = 0; slist = NULL; npair_perpetual = 0; plist = NULL; nrequest = maxrequest = 0; requests = NULL; old_nrequest = 0; old_requests = NULL; old_style = style; old_triclinic = 0; old_pgsize = pgsize; old_oneatom = oneatom; - zeroes = NULL; - binclass = NULL; binnames = NULL; binmasks = NULL; stencilclass = NULL; stencilnames = NULL; stencilmasks = NULL; // topology lists bondwhich = anglewhich = dihedralwhich = improperwhich = NONE; neigh_bond = NULL; neigh_angle = NULL; neigh_dihedral = NULL; neigh_improper = NULL; // coords at last neighboring maxhold = 0; xhold = NULL; lastcall = -1; last_setup_bins = -1; // pair exclusion list info includegroup = 0; nex_type = maxex_type = 0; ex1_type = ex2_type = NULL; ex_type = NULL; nex_group = maxex_group = 0; ex1_group = ex2_group = ex1_bit = ex2_bit = NULL; nex_mol = maxex_mol = 0; ex_mol_group = ex_mol_bit = ex_mol_intra = NULL; // Kokkos setting copymode = 0; } /* ---------------------------------------------------------------------- */ Neighbor::~Neighbor() { if (copymode) return; memory->destroy(cutneighsq); memory->destroy(cutneighghostsq); delete [] cuttype; delete [] cuttypesq; delete [] fixchecklist; for (int i = 0; i < nlist; i++) delete lists[i]; for (int i = 0; i < nbin; i++) delete neigh_bin[i]; for (int i = 0; i < nstencil; i++) delete neigh_stencil[i]; for (int i = 0; i < nlist; i++) delete neigh_pair[i]; delete [] lists; delete [] neigh_bin; delete [] neigh_stencil; delete [] neigh_pair; delete [] slist; delete [] plist; for (int i = 0; i < nrequest; i++) if (requests[i]) delete requests[i]; memory->sfree(requests); for (int i = 0; i < old_nrequest; i++) if (old_requests[i]) delete old_requests[i]; memory->sfree(old_requests); - delete [] zeroes; - delete [] binclass; delete [] binnames; delete [] binmasks; delete [] stencilclass; delete [] stencilnames; delete [] stencilmasks; delete [] pairclass; delete [] pairnames; delete [] pairmasks; delete neigh_bond; delete neigh_angle; delete neigh_dihedral; delete neigh_improper; memory->destroy(xhold); memory->destroy(ex1_type); memory->destroy(ex2_type); memory->destroy(ex_type); memory->destroy(ex1_group); memory->destroy(ex2_group); delete [] ex1_bit; delete [] ex2_bit; memory->destroy(ex_mol_group); delete [] ex_mol_bit; memory->destroy(ex_mol_intra); } /* ---------------------------------------------------------------------- */ void Neighbor::init() { int i,j,n; ncalls = ndanger = 0; dimension = domain->dimension; triclinic = domain->triclinic; newton_pair = force->newton_pair; // error check if (delay > 0 && (delay % every) != 0) error->all(FLERR,"Neighbor delay must be 0 or multiple of every setting"); if (pgsize < 10*oneatom) error->all(FLERR,"Neighbor page size must be >= 10x the one atom setting"); // ------------------------------------------------------------------ // settings // bbox lo/hi ptrs = bounding box of entire domain, stored by Domain if (triclinic == 0) { bboxlo = domain->boxlo; bboxhi = domain->boxhi; } else { bboxlo = domain->boxlo_bound; bboxhi = domain->boxhi_bound; } // set neighbor cutoffs (force cutoff + skin) // trigger determines when atoms migrate and neighbor lists are rebuilt // needs to be non-zero for migration distance check // even if pair = NULL and no neighbor lists are used // cutneigh = force cutoff + skin if cutforce > 0, else cutneigh = 0 // cutneighghost = pair cutghost if it requests it, else same as cutneigh triggersq = 0.25*skin*skin; boxcheck = 0; if (domain->box_change && (domain->xperiodic || domain->yperiodic || (dimension == 3 && domain->zperiodic))) boxcheck = 1; n = atom->ntypes; if (cutneighsq == NULL) { if (lmp->kokkos) init_cutneighsq_kokkos(n); else memory->create(cutneighsq,n+1,n+1,"neigh:cutneighsq"); memory->create(cutneighghostsq,n+1,n+1,"neigh:cutneighghostsq"); cuttype = new double[n+1]; cuttypesq = new double[n+1]; } double cutoff,delta,cut; cutneighmin = BIG; cutneighmax = 0.0; for (i = 1; i <= n; i++) { cuttype[i] = cuttypesq[i] = 0.0; for (j = 1; j <= n; j++) { if (force->pair) cutoff = sqrt(force->pair->cutsq[i][j]); else cutoff = 0.0; if (cutoff > 0.0) delta = skin; else delta = 0.0; cut = cutoff + delta; cutneighsq[i][j] = cut*cut; cuttype[i] = MAX(cuttype[i],cut); cuttypesq[i] = MAX(cuttypesq[i],cut*cut); cutneighmin = MIN(cutneighmin,cut); cutneighmax = MAX(cutneighmax,cut); if (force->pair && force->pair->ghostneigh) { cut = force->pair->cutghost[i][j] + skin; cutneighghostsq[i][j] = cut*cut; } else cutneighghostsq[i][j] = cut*cut; } } cutneighmaxsq = cutneighmax * cutneighmax; // rRESPA cutoffs int respa = 0; if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; } if (respa) { double *cut_respa = ((Respa *) update->integrate)->cutoff; cut_inner_sq = (cut_respa[1] + skin) * (cut_respa[1] + skin); cut_middle_sq = (cut_respa[3] + skin) * (cut_respa[3] + skin); cut_middle_inside_sq = (cut_respa[0] - skin) * (cut_respa[0] - skin); if (cut_respa[0]-skin < 0) cut_middle_inside_sq = 0.0; } // fixchecklist = other classes that can induce reneighboring in decide() restart_check = 0; if (output->restart_flag) restart_check = 1; delete [] fixchecklist; fixchecklist = NULL; fixchecklist = new int[modify->nfix]; fix_check = 0; for (i = 0; i < modify->nfix; i++) if (modify->fix[i]->force_reneighbor) fixchecklist[fix_check++] = i; must_check = 0; if (restart_check || fix_check) must_check = 1; // set special_flag for 1-2, 1-3, 1-4 neighbors // flag[0] is not used, flag[1] = 1-2, flag[2] = 1-3, flag[3] = 1-4 // flag = 0 if both LJ/Coulomb special values are 0.0 // flag = 1 if both LJ/Coulomb special values are 1.0 // flag = 2 otherwise or if KSpace solver is enabled // pairwise portion of KSpace solver uses all 1-2,1-3,1-4 neighbors // or selected Coulomb-approixmation pair styles require it if (force->special_lj[1] == 0.0 && force->special_coul[1] == 0.0) special_flag[1] = 0; else if (force->special_lj[1] == 1.0 && force->special_coul[1] == 1.0) special_flag[1] = 1; else special_flag[1] = 2; if (force->special_lj[2] == 0.0 && force->special_coul[2] == 0.0) special_flag[2] = 0; else if (force->special_lj[2] == 1.0 && force->special_coul[2] == 1.0) special_flag[2] = 1; else special_flag[2] = 2; if (force->special_lj[3] == 0.0 && force->special_coul[3] == 0.0) special_flag[3] = 0; else if (force->special_lj[3] == 1.0 && force->special_coul[3] == 1.0) special_flag[3] = 1; else special_flag[3] = 2; if (force->kspace || force->pair_match("coul/wolf",0) || force->pair_match("coul/dsf",0) || force->pair_match("thole",0)) special_flag[1] = special_flag[2] = special_flag[3] = 2; // maxwt = max multiplicative factor on atom indices stored in neigh list maxwt = 0; if (special_flag[1] == 2) maxwt = 2; if (special_flag[2] == 2) maxwt = 3; if (special_flag[3] == 2) maxwt = 4; // ------------------------------------------------------------------ // xhold array // free if not needed for this run if (dist_check == 0) { memory->destroy(xhold); maxhold = 0; xhold = NULL; } // first time allocation if (dist_check) { if (maxhold == 0) { maxhold = atom->nmax; memory->create(xhold,maxhold,3,"neigh:xhold"); } } // ------------------------------------------------------------------ // exclusion lists // depend on type, group, molecule settings from neigh_modify // warn if exclusions used with KSpace solver n = atom->ntypes; if (nex_type == 0 && nex_group == 0 && nex_mol == 0) exclude = 0; else exclude = 1; if (nex_type) { if (lmp->kokkos) init_ex_type_kokkos(n); else { memory->destroy(ex_type); memory->create(ex_type,n+1,n+1,"neigh:ex_type"); } for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) ex_type[i][j] = 0; for (i = 0; i < nex_type; i++) { if (ex1_type[i] <= 0 || ex1_type[i] > n || ex2_type[i] <= 0 || ex2_type[i] > n) error->all(FLERR,"Invalid atom type in neighbor exclusion list"); ex_type[ex1_type[i]][ex2_type[i]] = 1; ex_type[ex2_type[i]][ex1_type[i]] = 1; } } if (nex_group) { if (lmp->kokkos) init_ex_bit_kokkos(); else { delete [] ex1_bit; delete [] ex2_bit; ex1_bit = new int[nex_group]; ex2_bit = new int[nex_group]; } for (i = 0; i < nex_group; i++) { ex1_bit[i] = group->bitmask[ex1_group[i]]; ex2_bit[i] = group->bitmask[ex2_group[i]]; } } if (nex_mol) { if (lmp->kokkos) init_ex_mol_bit_kokkos(); else { delete [] ex_mol_bit; ex_mol_bit = new int[nex_mol]; } for (i = 0; i < nex_mol; i++) ex_mol_bit[i] = group->bitmask[ex_mol_group[i]]; } if (exclude && force->kspace && me == 0) error->warning(FLERR,"Neighbor exclusions used with KSpace solver " "may give inconsistent Coulombic energies"); // ------------------------------------------------------------------ // create pairwise lists // one-time call to init_styles() to scan style files and setup // init_pair() creates auxiliary classes: NBin, NStencil, NPair if (firsttime) init_styles(); firsttime = 0; int same = init_pair(); // invoke copy_neighbor_info() in Bin,Stencil,Pair classes // copied once per run in case any cutoff, exclusion, special info changed for (i = 0; i < nbin; i++) neigh_bin[i]->copy_neighbor_info(); for (i = 0; i < nstencil; i++) neigh_stencil[i]->copy_neighbor_info(); for (i = 0; i < nlist; i++) if (neigh_pair[i]) neigh_pair[i]->copy_neighbor_info(); if (!same && comm->me == 0) print_pairwise_info(); // can now delete requests so next run can make new ones // print_pairwise_info() made use of requests // set of NeighLists now stores all needed info for (int i = 0; i < nrequest; i++) { delete requests[i]; requests[i] = NULL; } nrequest = 0; // ------------------------------------------------------------------ // create topology lists // instantiated topo styles can change from run to run init_topology(); } /* ---------------------------------------------------------------------- create and initialize lists of Nbin, Nstencil, NPair classes lists have info on all classes in 3 style*.h files cannot do this in constructor, b/c too early to instantiate classes ------------------------------------------------------------------------- */ void Neighbor::init_styles() { // extract info from NBin classes listed in style_nbin.h nbclass = 0; #define NBIN_CLASS #define NBinStyle(key,Class,bitmasks) nbclass++; #include "style_nbin.h" #undef NBinStyle #undef NBIN_CLASS binclass = new BinCreator[nbclass]; binnames = new char*[nbclass]; binmasks = new int[nbclass]; nbclass = 0; #define NBIN_CLASS #define NBinStyle(key,Class,bitmasks) \ binnames[nbclass] = (char *) #key; \ binclass[nbclass] = &bin_creator; \ binmasks[nbclass++] = bitmasks; #include "style_nbin.h" #undef NBinStyle #undef NBIN_CLASS // extract info from NStencil classes listed in style_nstencil.h nsclass = 0; #define NSTENCIL_CLASS #define NStencilStyle(key,Class,bitmasks) nsclass++; #include "style_nstencil.h" #undef NStencilStyle #undef NSTENCIL_CLASS stencilclass = new StencilCreator[nsclass]; stencilnames = new char*[nsclass]; stencilmasks = new int[nsclass]; nsclass = 0; #define NSTENCIL_CLASS #define NStencilStyle(key,Class,bitmasks) \ stencilnames[nsclass] = (char *) #key; \ stencilclass[nsclass] = &stencil_creator; \ stencilmasks[nsclass++] = bitmasks; #include "style_nstencil.h" #undef NStencilStyle #undef NSTENCIL_CLASS // extract info from NPair classes listed in style_npair.h npclass = 0; #define NPAIR_CLASS #define NPairStyle(key,Class,bitmasks) npclass++; #include "style_npair.h" #undef NPairStyle #undef NPAIR_CLASS pairclass = new PairCreator[npclass]; pairnames = new char*[npclass]; pairmasks = new int[npclass]; npclass = 0; #define NPAIR_CLASS #define NPairStyle(key,Class,bitmasks) \ pairnames[npclass] = (char *) #key; \ pairclass[npclass] = &pair_creator; \ pairmasks[npclass++] = bitmasks; #include "style_npair.h" #undef NPairStyle #undef NPAIR_CLASS } /* ---------------------------------------------------------------------- create and initialize NPair classes ------------------------------------------------------------------------- */ int Neighbor::init_pair() { int i,j,k,m; // test if pairwise lists need to be re-created // no need to re-create if: // neigh style, triclinic, pgsize, oneatom have not changed // current requests = old requests // so just return: // delete requests so next run can make new ones // current set of NeighLists already stores all needed info // requests are compared via identical() before: // any requests are morphed using logic below // any requests are added below, e.g. as parents of pair hybrid skip lists // copy them via requests_new2old() BEFORE any changes made to requests // necessary b/c morphs can change requestor settings (see comment below) int same = 1; if (style != old_style) same = 0; if (triclinic != old_triclinic) same = 0; if (pgsize != old_pgsize) same = 0; if (oneatom != old_oneatom) same = 0; if (nrequest != old_nrequest) same = 0; else for (i = 0; i < nrequest; i++) if (requests[i]->identical(old_requests[i]) == 0) same = 0; #ifdef NEIGH_LIST_DEBUG if (comm->me == 0) printf("SAME flag %d\n",same); #endif if (same) return same; requests_new2old(); // delete old lists since creating new ones for (i = 0; i < nlist; i++) delete lists[i]; for (i = 0; i < nbin; i++) delete neigh_bin[i]; for (i = 0; i < nstencil; i++) delete neigh_stencil[i]; for (i = 0; i < nlist; i++) delete neigh_pair[i]; delete [] lists; delete [] neigh_bin; delete [] neigh_stencil; delete [] neigh_pair; // error check on requests // do not allow occasional, ghost, bin list // b/c it still uses variant of coord2bin() in NPair() method // instead of atom2bin, this could cause error b/c stoms have // moved out of proc domain by time occasional list is built // solution would be to use a different NBin variant // that used Npair::coord2bin(x,ix,iy,iz) (then delete it from NPair) // and stored the ix,iy,iz values for all atoms (including ghosts) // at time of binning when neighbor lists are rebuilt, // similar to what vanilla Nbin::coord2atom() does now in atom2bin if (style == BIN) { for (i = 0; i < nrequest; i++) if (requests[i]->occasional && requests[i]->ghost) error->all(FLERR,"Cannot request an occasional binned neighbor list " "with ghost info"); } // morph requests in various ways // purpose is to avoid duplicate or inefficient builds // may add new requests if a needed request to derive from does not exist // methods: - // (1) other = point history and rRESPA lists at their partner lists + // (1) unique = create unique lists if cutoff is explicitly set // (2) skip = create any new non-skip lists needed by pair hybrid skip lists // (3) granular = adjust parent and skip lists for granular onesided usage // (4) h/f = pair up any matching half/full lists // (5) copy = convert as many lists as possible to copy lists // order of morph methods matters: - // (1) before (2), b/c (2) needs to know history partner pairings - // (2) after (1), b/c (2) may also need to create new history lists // (3) after (2), b/c it adjusts lists created by (2) // (4) after (2) and (3), // b/c (2) may create new full lists, (3) may change them // (5) last, after all lists are finalized, so all possible copies found int nrequest_original = nrequest; - morph_other(); + morph_unique(); morph_skip(); morph_granular(); // this method can change flags set by requestor morph_halffull(); morph_copy(); // create new lists, one per request including added requests // wait to allocate initial pages until copy lists are detected // NOTE: can I allocate now, instead of down below? nlist = nrequest; lists = new NeighList*[nrequest]; neigh_bin = new NBin*[nrequest]; neigh_stencil = new NStencil*[nrequest]; neigh_pair = new NPair*[nrequest]; // allocate new lists // pass list ptr back to requestor (except for Command class) // only for original requests, not ones added by Neighbor class for (i = 0; i < nrequest; i++) { if (requests[i]->kokkos_host || requests[i]->kokkos_device) create_kokkos_list(i); else lists[i] = new NeighList(lmp); lists[i]->index = i; if (requests[i]->pair && i < nrequest_original) { Pair *pair = (Pair *) requests[i]->requestor; pair->init_list(requests[i]->id,lists[i]); } else if (requests[i]->fix && i < nrequest_original) { Fix *fix = (Fix *) requests[i]->requestor; fix->init_list(requests[i]->id,lists[i]); } else if (requests[i]->compute && i < nrequest_original) { Compute *compute = (Compute *) requests[i]->requestor; compute->init_list(requests[i]->id,lists[i]); } } // invoke post_constructor() for all lists // copies info from requests to lists, sets ptrs to related lists for (i = 0; i < nrequest; i++) lists[i]->post_constructor(requests[i]); // assign Bin,Stencil,Pair style to each list int flag; for (i = 0; i < nrequest; i++) { flag = choose_bin(requests[i]); lists[i]->bin_method = flag; if (flag < 0) error->all(FLERR,"Requested neighbor bin option does not exist"); flag = choose_stencil(requests[i]); lists[i]->stencil_method = flag; if (flag < 0) error->all(FLERR,"Requested neighbor stencil method does not exist"); flag = choose_pair(requests[i]); lists[i]->pair_method = flag; if (flag < 0) error->all(FLERR,"Requested neighbor pair method does not exist"); } // instantiate unique Bin,Stencil classes in neigh_bin & neigh_stencil vecs // unique = only one of its style, or request unique flag set (custom cutoff) nbin = 0; for (i = 0; i < nrequest; i++) { requests[i]->index_bin = -1; flag = lists[i]->bin_method; if (flag == 0) continue; for (j = 0; j < nbin; j++) if (neigh_bin[j]->istyle == flag) break; if (j < nbin && !requests[i]->unique) { requests[i]->index_bin = j; continue; } BinCreator bin_creator = binclass[flag-1]; neigh_bin[nbin] = bin_creator(lmp); neigh_bin[nbin]->post_constructor(requests[i]); neigh_bin[nbin]->istyle = flag; requests[i]->index_bin = nbin; nbin++; } nstencil = 0; for (i = 0; i < nrequest; i++) { requests[i]->index_stencil = -1; flag = lists[i]->stencil_method; if (flag == 0) continue; for (j = 0; j < nstencil; j++) if (neigh_stencil[j]->istyle == flag) break; if (j < nstencil && !requests[i]->unique) { requests[i]->index_stencil = j; continue; } StencilCreator stencil_creator = stencilclass[flag-1]; neigh_stencil[nstencil] = stencil_creator(lmp); neigh_stencil[nstencil]->post_constructor(requests[i]); neigh_stencil[nstencil]->istyle = flag; if (lists[i]->bin_method > 0) { neigh_stencil[nstencil]->nb = neigh_bin[requests[i]->index_bin]; if (neigh_stencil[nstencil]->nb == NULL) error->all(FLERR,"Could not assign bin method to neighbor stencil"); } requests[i]->index_stencil = nstencil; nstencil++; } // instantiate one Pair class per list in neigh_pair vec for (i = 0; i < nrequest; i++) { requests[i]->index_pair = -1; flag = lists[i]->pair_method; if (flag == 0) { neigh_pair[i] = NULL; continue; } PairCreator pair_creator = pairclass[flag-1]; lists[i]->np = neigh_pair[i] = pair_creator(lmp); neigh_pair[i]->post_constructor(requests[i]); neigh_pair[i]->istyle = flag; if (lists[i]->bin_method > 0) { neigh_pair[i]->nb = neigh_bin[requests[i]->index_bin]; if (neigh_pair[i]->nb == NULL) error->all(FLERR,"Could not assign bin method to neighbor pair"); } if (lists[i]->stencil_method > 0) { neigh_pair[i]->ns = neigh_stencil[requests[i]->index_stencil]; if (neigh_pair[i]->ns == NULL) error->all(FLERR,"Could not assign stencil method to neighbor pair"); } requests[i]->index_pair = i; } // allocate initial pages for each list, except if copy flag set - // allocate dnum vector of zeroes if set - int dnummax = 0; for (i = 0; i < nlist; i++) { if (lists[i]->copy) continue; lists[i]->setup_pages(pgsize,oneatom); - dnummax = MAX(dnummax,lists[i]->dnum); - } - - if (dnummax) { - delete [] zeroes; - zeroes = new double[dnummax]; - for (i = 0; i < dnummax; i++) zeroes[i] = 0.0; } // first-time allocation of per-atom data for lists that are built and store - // lists that are not built: granhistory, respa inner/middle (no neigh_pair) // lists that do not store: copy // use atom->nmax for both grow() args // i.e. grow first time to expanded size to avoid future reallocs // also Kokkos list initialization int maxatom = atom->nmax; for (i = 0; i < nlist; i++) if (neigh_pair[i] && !lists[i]->copy) lists[i]->grow(maxatom,maxatom); // plist = indices of perpetual NPair classes // perpetual = non-occasional, re-built at every reneighboring // slist = indices of perpetual NStencil classes // perpetual = used by any perpetual NPair class delete [] slist; delete [] plist; nstencil_perpetual = npair_perpetual = 0; slist = new int[nstencil]; plist = new int[nlist]; for (i = 0; i < nlist; i++) { if (lists[i]->occasional == 0 && lists[i]->pair_method) plist[npair_perpetual++] = i; } for (i = 0; i < nstencil; i++) { flag = 0; for (j = 0; j < npair_perpetual; j++) if (lists[plist[j]]->stencil_method == neigh_stencil[i]->istyle) flag = 1; if (flag) slist[nstencil_perpetual++] = i; } // reorder plist vector if necessary // relevant for lists that are derived from a parent list: // half-full,copy,skip // the child index must appear in plist after the parent index // swap two indices within plist when dependency is mis-ordered // start double loop check again whenever a swap is made // done when entire double loop test results in no swaps NeighList *ptr; int done = 0; while (!done) { done = 1; for (i = 0; i < npair_perpetual; i++) { for (k = 0; k < 3; k++) { ptr = NULL; if (k == 0) ptr = lists[plist[i]]->listcopy; if (k == 1) ptr = lists[plist[i]]->listskip; if (k == 2) ptr = lists[plist[i]]->listfull; if (ptr == NULL) continue; for (m = 0; m < nrequest; m++) if (ptr == lists[m]) break; for (j = 0; j < npair_perpetual; j++) if (m == plist[j]) break; if (j < i) continue; int tmp = plist[i]; // swap I,J indices plist[i] = plist[j]; plist[j] = tmp; done = 0; break; } if (!done) break; } } // debug output #ifdef NEIGH_LIST_DEBUG for (i = 0; i < nrequest; i++) lists[i]->print_attributes(); #endif return same; } /* ---------------------------------------------------------------------- scan NeighRequests to set additional flags - only for history, respaouter, custom cutoff lists + only for custom cutoff lists ------------------------------------------------------------------------- */ -void Neighbor::morph_other() +void Neighbor::morph_unique() { NeighRequest *irq; for (int i = 0; i < nrequest; i++) { irq = requests[i]; - // if history, point this list and partner list at each other - - if (irq->history) { - irq->historylist = i-1; - requests[i-1]->history_partner = 1; - requests[i-1]->historylist = i; - } - - // if respaouter, point all associated rRESPA lists at each other - - if (irq->respaouter) { - if (requests[i-1]->respainner) { - irq->respainnerlist = i-1; - requests[i-1]->respaouterlist = i; - } else { - irq->respamiddlelist = i-1; - requests[i-1]->respaouterlist = i; - requests[i-1]->respainnerlist = i-1; - irq->respainnerlist = i-2; - requests[i-2]->respaouterlist = i; - requests[i-2]->respamiddlelist = i-1; - } - } - // if cut flag set by requestor, set unique flag // this forces Pair,Stencil,Bin styles to be instantiated separately if (irq->cut) irq->unique = 1; } } /* ---------------------------------------------------------------------- scan NeighRequests to process all skip lists look for a matching non-skip list if one exists, point at it via skiplist else make new parent via copy_request() and point at it ------------------------------------------------------------------------- */ void Neighbor::morph_skip() { int i,j,inewton,jnewton; NeighRequest *irq,*jrq,*nrq; for (i = 0; i < nrequest; i++) { irq = requests[i]; // only processing skip lists if (!irq->skip) continue; // these lists are created other ways, no need for skipping // halffull list and its full parent may both skip, // but are checked to insure matching skip info - if (irq->history) continue; - if (irq->respainner || irq->respamiddle) continue; if (irq->halffull) continue; if (irq->copy) continue; // check all other lists for (j = 0; j < nrequest; j++) { if (i == j) continue; jrq = requests[j]; // can only skip from a perpetual non-skip list if (jrq->occasional) continue; if (jrq->skip) continue; // both lists must be half, or both full if (irq->half != jrq->half) continue; if (irq->full != jrq->full) continue; // both lists must be newton on, or both newton off // IJ newton = 1 for newton on, 2 for newton off inewton = irq->newton; if (inewton == 0) inewton = force->newton_pair ? 1 : 2; jnewton = jrq->newton; if (jnewton == 0) jnewton = force->newton_pair ? 1 : 2; if (inewton != jnewton) continue; // these flags must be same, // else 2 lists do not store same pairs // or their data structures are different // this includes custom cutoff set by requestor - // no need to check respaouter b/c it stores same pairs - // no need to check dnum b/c only set for history // NOTE: need check for 2 Kokkos flags? if (irq->ghost != jrq->ghost) continue; if (irq->size != jrq->size) continue; + if (irq->history != jrq->history) continue; if (irq->bond != jrq->bond) continue; if (irq->omp != jrq->omp) continue; if (irq->intel != jrq->intel) continue; if (irq->kokkos_host != jrq->kokkos_host) continue; if (irq->kokkos_device != jrq->kokkos_device) continue; if (irq->ssa != jrq->ssa) continue; if (irq->cut != jrq->cut) continue; if (irq->cutoff != jrq->cutoff) continue; // 2 lists are a match break; } // if matching list exists, point to it // else create a new identical list except non-skip // for new list, set neigh = 1, skip = 0, no skip vec/array, // copy unique flag (since copy_request() will not do it) - // note: parents of skip lists do not have associated history list - // b/c child skip lists store their own history info + // note: parents of skip lists do not have associated history + // b/c child skip lists have the associated history if (j < nrequest) irq->skiplist = j; else { int newrequest = request(this,-1); irq->skiplist = newrequest; nrq = requests[newrequest]; nrq->copy_request(irq,0); nrq->pair = nrq->fix = nrq->compute = nrq->command = 0; nrq->neigh = 1; nrq->skip = 0; if (irq->unique) nrq->unique = 1; } } } /* ---------------------------------------------------------------------- scan NeighRequests just added by morph_skip for hybrid granular adjust newton/oneside parent settings if children require onesided skipping also set children off2on flag if parent becomes a newton off list this is needed because line/gran and tri/gran pair styles require onesided neigh lists and system newton on, but parent list must be newton off to enable the onesided skipping ------------------------------------------------------------------------- */ void Neighbor::morph_granular() { int i,j; NeighRequest *irq,*jrq; for (i = 0; i < nrequest; i++) { irq = requests[i]; // only examine NeighRequests added by morph_skip() // only those with size attribute for granular systems if (!irq->neigh) continue; if (!irq->size) continue; // check children of this list int onesided = -1; for (j = 0; j < nrequest; j++) { jrq = requests[j]; // only consider JRQ pair, size lists that skip from Irq list if (!jrq->pair) continue; if (!jrq->size) continue; if (!jrq->skip || jrq->skiplist != i) continue; // onesided = -1 if no children // onesided = 0/1 = child granonesided value if same for all children // onesided = 2 if children have different granonesided values if (onesided < 0) onesided = jrq->granonesided; else if (onesided != jrq->granonesided) onesided = 2; if (onesided == 2) break; } - // if onesided = 2, parent has children with both granonesided = 0/1 // force parent newton off (newton = 2) to enable onesided skip by child // set parent granonesided = 0, so it stores all neighs in usual manner // set off2on = 1 for all children, since they expect newton on lists // this is b/c granonesided only set by line/gran and tri/gran which // both require system newton on if (onesided == 2) { irq->newton = 2; irq->granonesided = 0; for (j = 0; j < nrequest; j++) { jrq = requests[j]; // only consider JRQ pair, size lists that skip from Irq list if (!jrq->pair) continue; if (!jrq->size) continue; if (!jrq->skip || jrq->skiplist != i) continue; jrq->off2on = 1; } } } } /* ---------------------------------------------------------------------- scan NeighRequests for possible half lists to derive from full lists if 2 requests match, set half list to derive from full list ------------------------------------------------------------------------- */ void Neighbor::morph_halffull() { int i,j; NeighRequest *irq,*jrq; for (i = 0; i < nrequest; i++) { irq = requests[i]; // only processing half lists if (!irq->half) continue; // Kokkos doesn't yet support half from full if (irq->kokkos_host) continue; if (irq->kokkos_device) continue; // these lists are created other ways, no need for halffull // do want to process skip lists - if (irq->history) continue; - if (irq->respainner || irq->respamiddle) continue; if (irq->copy) continue; // check all other lists for (j = 0; j < nrequest; j++) { if (i == j) continue; jrq = requests[j]; // can only derive from a perpetual full list // newton setting of derived list does not matter if (jrq->occasional) continue; if (!jrq->full) continue; // these flags must be same, // else 2 lists do not store same pairs // or their data structures are different // this includes custom cutoff set by requestor - // no need to check respaouter b/c it stores same pairs - // no need to check dnum b/c only set for history if (irq->ghost != jrq->ghost) continue; if (irq->size != jrq->size) continue; + if (irq->history != jrq->history) continue; if (irq->bond != jrq->bond) continue; if (irq->omp != jrq->omp) continue; if (irq->intel != jrq->intel) continue; if (irq->kokkos_host != jrq->kokkos_host) continue; if (irq->kokkos_device != jrq->kokkos_device) continue; if (irq->ssa != jrq->ssa) continue; if (irq->cut != jrq->cut) continue; if (irq->cutoff != jrq->cutoff) continue; // skip flag must be same // if both are skip lists, skip info must match if (irq->skip != jrq->skip) continue; if (irq->skip && irq->same_skip(jrq) == 0) continue; // 2 lists are a match break; } // if matching list exists, point to it if (j < nrequest) { irq->halffull = 1; irq->halffulllist = j; } } } /* ---------------------------------------------------------------------- scan NeighRequests for possible copies if 2 requests match, turn one into a copy of the other ------------------------------------------------------------------------- */ void Neighbor::morph_copy() { int i,j,inewton,jnewton; NeighRequest *irq,*jrq; for (i = 0; i < nrequest; i++) { irq = requests[i]; // this list is already a copy list due to another morph method if (irq->copy) continue; - // these lists are created other ways, no need to copy - // skip lists are eligible to become a copy list - - if (irq->history) continue; - if (irq->respainner || irq->respamiddle) continue; - // check all other lists for (j = 0; j < nrequest; j++) { if (i == j) continue; jrq = requests[j]; // other list is already copied from this one if (jrq->copy && jrq->copylist == i) continue; // other list (jrq) to copy from must be perpetual // list that becomes a copy list (irq) can be perpetual or occasional // if both lists are perpetual, require j < i // to prevent circular dependence with 3 or more copies of a list if (jrq->occasional) continue; if (!irq->occasional && j > i) continue; // both lists must be half, or both full if (irq->half != jrq->half) continue; if (irq->full != jrq->full) continue; // both lists must be newton on, or both newton off // IJ newton = 1 for newton on, 2 for newton off inewton = irq->newton; if (inewton == 0) inewton = force->newton_pair ? 1 : 2; jnewton = jrq->newton; if (jnewton == 0) jnewton = force->newton_pair ? 1 : 2; if (inewton != jnewton) continue; // ok for non-ghost list to copy from ghost list, but not vice versa if (irq->ghost && !jrq->ghost) continue; - // do not copy from a history list or a respa middle/inner list + // do not copy from a list with respa middle/inner + // b/c its outer list will not be complete - if (jrq->history) continue; if (jrq->respamiddle) continue; if (jrq->respainner) continue; // these flags must be same, // else 2 lists do not store same pairs // or their data structures are different // this includes custom cutoff set by requestor - // no need to check respaouter b/c it stores same pairs // no need to check omp b/c it stores same pairs - // no need to check dnum b/c only set for history // NOTE: need check for 2 Kokkos flags? if (irq->size != jrq->size) continue; + if (irq->history != jrq->history) continue; if (irq->bond != jrq->bond) continue; if (irq->intel != jrq->intel) continue; if (irq->kokkos_host != jrq->kokkos_host) continue; if (irq->kokkos_device != jrq->kokkos_device) continue; if (irq->ssa != jrq->ssa) continue; if (irq->cut != jrq->cut) continue; if (irq->cutoff != jrq->cutoff) continue; // skip flag must be same // if both are skip lists, skip info must match if (irq->skip != jrq->skip) continue; if (irq->skip && irq->same_skip(jrq) == 0) continue; // 2 lists are a match break; } // turn list I into a copy of list J // do not copy a list from another copy list, but from its parent list if (j < nrequest) { irq->copy = 1; if (jrq->copy) irq->copylist = jrq->copylist; else irq->copylist = j; } } } /* ---------------------------------------------------------------------- create and initialize NTopo classes ------------------------------------------------------------------------- */ void Neighbor::init_topology() { int i,m; if (!atom->molecular) return; // set flags that determine which topology neighbor classes to use // these settings could change from run to run, depending on fixes defined // bonds,etc can only be broken for atom->molecular = 1, not 2 // SHAKE sets bonds and angles negative // gcmc sets all bonds, angles, etc negative // bond_quartic sets bonds to 0 // delete_bonds sets all interactions negative int bond_off = 0; int angle_off = 0; for (i = 0; i < modify->nfix; i++) if ((strcmp(modify->fix[i]->style,"shake") == 0) || (strcmp(modify->fix[i]->style,"rattle") == 0)) bond_off = angle_off = 1; if (force->bond && force->bond_match("quartic")) bond_off = 1; if (atom->avec->bonds_allow && atom->molecular == 1) { for (i = 0; i < atom->nlocal; i++) { if (bond_off) break; for (m = 0; m < atom->num_bond[i]; m++) if (atom->bond_type[i][m] <= 0) bond_off = 1; } } if (atom->avec->angles_allow && atom->molecular == 1) { for (i = 0; i < atom->nlocal; i++) { if (angle_off) break; for (m = 0; m < atom->num_angle[i]; m++) if (atom->angle_type[i][m] <= 0) angle_off = 1; } } int dihedral_off = 0; if (atom->avec->dihedrals_allow && atom->molecular == 1) { for (i = 0; i < atom->nlocal; i++) { if (dihedral_off) break; for (m = 0; m < atom->num_dihedral[i]; m++) if (atom->dihedral_type[i][m] <= 0) dihedral_off = 1; } } int improper_off = 0; if (atom->avec->impropers_allow && atom->molecular == 1) { for (i = 0; i < atom->nlocal; i++) { if (improper_off) break; for (m = 0; m < atom->num_improper[i]; m++) if (atom->improper_type[i][m] <= 0) improper_off = 1; } } for (i = 0; i < modify->nfix; i++) if ((strcmp(modify->fix[i]->style,"gcmc") == 0)) bond_off = angle_off = dihedral_off = improper_off = 1; // sync on/off settings across all procs int onoff = bond_off; MPI_Allreduce(&onoff,&bond_off,1,MPI_INT,MPI_MAX,world); onoff = angle_off; MPI_Allreduce(&onoff,&angle_off,1,MPI_INT,MPI_MAX,world); onoff = dihedral_off; MPI_Allreduce(&onoff,&dihedral_off,1,MPI_INT,MPI_MAX,world); onoff = improper_off; MPI_Allreduce(&onoff,&improper_off,1,MPI_INT,MPI_MAX,world); // instantiate NTopo classes if (atom->avec->bonds_allow) { int old_bondwhich = bondwhich; if (atom->molecular == 2) bondwhich = TEMPLATE; else if (bond_off) bondwhich = PARTIAL; else bondwhich = ALL; if (!neigh_bond || bondwhich != old_bondwhich) { delete neigh_bond; if (bondwhich == ALL) neigh_bond = new NTopoBondAll(lmp); else if (bondwhich == PARTIAL) neigh_bond = new NTopoBondPartial(lmp); else if (bondwhich == TEMPLATE) neigh_bond = new NTopoBondTemplate(lmp); } } if (atom->avec->angles_allow) { int old_anglewhich = anglewhich; if (atom->molecular == 2) anglewhich = TEMPLATE; else if (angle_off) anglewhich = PARTIAL; else anglewhich = ALL; if (!neigh_angle || anglewhich != old_anglewhich) { delete neigh_angle; if (anglewhich == ALL) neigh_angle = new NTopoAngleAll(lmp); else if (anglewhich == PARTIAL) neigh_angle = new NTopoAnglePartial(lmp); else if (anglewhich == TEMPLATE) neigh_angle = new NTopoAngleTemplate(lmp); } } if (atom->avec->dihedrals_allow) { int old_dihedralwhich = dihedralwhich; if (atom->molecular == 2) dihedralwhich = TEMPLATE; else if (dihedral_off) dihedralwhich = PARTIAL; else dihedralwhich = ALL; if (!neigh_dihedral || dihedralwhich != old_dihedralwhich) { delete neigh_dihedral; if (dihedralwhich == ALL) neigh_dihedral = new NTopoDihedralAll(lmp); else if (dihedralwhich == PARTIAL) neigh_dihedral = new NTopoDihedralPartial(lmp); else if (dihedralwhich == TEMPLATE) neigh_dihedral = new NTopoDihedralTemplate(lmp); } } if (atom->avec->impropers_allow) { int old_improperwhich = improperwhich; if (atom->molecular == 2) improperwhich = TEMPLATE; else if (improper_off) improperwhich = PARTIAL; else improperwhich = ALL; if (!neigh_improper || improperwhich != old_improperwhich) { delete neigh_improper; if (improperwhich == ALL) neigh_improper = new NTopoImproperAll(lmp); else if (improperwhich == PARTIAL) neigh_improper = new NTopoImproperPartial(lmp); else if (improperwhich == TEMPLATE) neigh_improper = new NTopoImproperTemplate(lmp); } } } /* ---------------------------------------------------------------------- output summary of pairwise neighbor list info only called by proc 0 ------------------------------------------------------------------------- */ void Neighbor::print_pairwise_info() { int i,m; char str[128]; NeighRequest *rq; FILE *out; const double cutghost = MAX(cutneighmax,comm->cutghostuser); double binsize, bbox[3]; bbox[0] = bboxhi[0]-bboxlo[0]; bbox[1] = bboxhi[1]-bboxlo[1]; bbox[2] = bboxhi[2]-bboxlo[2]; if (binsizeflag) binsize = binsize_user; else if (style == BIN) binsize = 0.5*cutneighmax; else binsize = 0.5*cutneighmin; if (binsize == 0.0) binsize = bbox[0]; int nperpetual = 0; int noccasional = 0; int nextra = 0; for (i = 0; i < nlist; i++) { if (lists[i]->pair_method == 0) nextra++; else if (lists[i]->occasional) noccasional++; else nperpetual++; } for (m = 0; m < 2; m++) { if (m == 0) out = screen; else out = logfile; if (out) { fprintf(out,"Neighbor list info ...\n"); fprintf(out," update every %d steps, delay %d steps, check %s\n", every,delay,dist_check ? "yes" : "no"); fprintf(out," max neighbors/atom: %d, page size: %d\n", oneatom, pgsize); fprintf(out," master list distance cutoff = %g\n",cutneighmax); fprintf(out," ghost atom cutoff = %g\n",cutghost); if (style != NSQ) fprintf(out," binsize = %g, bins = %g %g %g\n",binsize, ceil(bbox[0]/binsize), ceil(bbox[1]/binsize), ceil(bbox[2]/binsize)); fprintf(out," %d neighbor lists, " "perpetual/occasional/extra = %d %d %d\n", nlist,nperpetual,noccasional,nextra); for (i = 0; i < nlist; i++) { rq = requests[i]; if (rq->pair) { char *pname = force->pair_match_ptr((Pair *) rq->requestor); sprintf(str," (%d) pair %s",i+1,pname); } else if (rq->fix) { sprintf(str," (%d) fix %s",i+1,((Fix *) rq->requestor)->style); } else if (rq->compute) { sprintf(str," (%d) compute %s",i+1, ((Compute *) rq->requestor)->style); } else if (rq->command) { sprintf(str," (%d) command %s",i+1,rq->command_style); } else if (rq->neigh) { sprintf(str," (%d) neighbor class addition",i+1); } fprintf(out,"%s",str); if (rq->occasional) fprintf(out,", occasional"); else fprintf(out,", perpetual"); // order these to get single output of most relevant - if (rq->history) - fprintf(out,", history for (%d)",rq->historylist+1); - else if (rq->copy) + if (rq->copy) fprintf(out,", copy from (%d)",rq->copylist+1); else if (rq->halffull) fprintf(out,", half/full from (%d)",rq->halffulllist+1); else if (rq->skip) fprintf(out,", skip from (%d)",rq->skiplist+1); fprintf(out,"\n"); // list of neigh list attributes fprintf(out," attributes: "); if (rq->half) fprintf(out,"half"); else if (rq->full) fprintf(out,"full"); if (rq->newton == 0) { if (force->newton_pair) fprintf(out,", newton on"); else fprintf(out,", newton off"); } else if (rq->newton == 1) fprintf(out,", newton on"); else if (rq->newton == 2) fprintf(out,", newton off"); if (rq->ghost) fprintf(out,", ghost"); if (rq->size) fprintf(out,", size"); if (rq->history) fprintf(out,", history"); if (rq->granonesided) fprintf(out,", onesided"); - if (rq->respainner) fprintf(out,", respa outer"); - if (rq->respamiddle) fprintf(out,", respa middle"); - if (rq->respaouter) fprintf(out,", respa inner"); + if (rq->respamiddle) fprintf(out,", respa outer/middle/inner"); + else if (rq->respainner) fprintf(out,", respa outer/inner"); if (rq->bond) fprintf(out,", bond"); if (rq->omp) fprintf(out,", omp"); if (rq->intel) fprintf(out,", intel"); if (rq->kokkos_device) fprintf(out,", kokkos_device"); if (rq->kokkos_host) fprintf(out,", kokkos_host"); if (rq->ssa) fprintf(out,", ssa"); if (rq->cut) fprintf(out,", cut %g",rq->cutoff); if (rq->off2on) fprintf(out,", off2on"); fprintf(out,"\n"); fprintf(out," "); if (lists[i]->pair_method == 0) fprintf(out,"pair build: none\n"); else fprintf(out,"pair build: %s\n",pairnames[lists[i]->pair_method-1]); fprintf(out," "); if (lists[i]->stencil_method == 0) fprintf(out,"stencil: none\n"); else fprintf(out,"stencil: %s\n", stencilnames[lists[i]->stencil_method-1]); fprintf(out," "); if (lists[i]->bin_method == 0) fprintf(out,"bin: none\n"); else fprintf(out,"bin: %s\n",binnames[lists[i]->bin_method-1]); } /* fprintf(out," %d stencil methods\n",nstencil); for (i = 0; i < nstencil; i++) fprintf(out," (%d) %s\n", i+1,stencilnames[neigh_stencil[i]->istyle-1]); fprintf(out," %d bin methods\n",nbin); for (i = 0; i < nbin; i++) fprintf(out," (%d) %s\n",i+1,binnames[neigh_bin[i]->istyle-1]); */ } } } /* ---------------------------------------------------------------------- make copy of current requests and Neighbor params used to compare to when next run occurs ------------------------------------------------------------------------- */ void Neighbor::requests_new2old() { for (int i = 0; i < old_nrequest; i++) delete old_requests[i]; memory->sfree(old_requests); old_nrequest = nrequest; old_requests = (NeighRequest **) memory->smalloc(old_nrequest*sizeof(NeighRequest *), "neighbor:old_requests"); for (int i = 0; i < old_nrequest; i++) { old_requests[i] = new NeighRequest(lmp); old_requests[i]->copy_request(requests[i],1); } old_style = style; old_triclinic = triclinic; old_pgsize = pgsize; old_oneatom = oneatom; } /* ---------------------------------------------------------------------- find and return request made by classptr if not found or classpt = NULL, return NULL ------------------------------------------------------------------------- */ NeighRequest *Neighbor::find_request(void *classptr) { if (classptr == NULL) return NULL; for (int i = 0; i < nrequest; i++) if (requests[i]->requestor == classptr) return requests[i]; return NULL; } /* ---------------------------------------------------------------------- assign NBin class to a NeighList use neigh request settings to build mask match mask to list of masks of known Nbin classes return index+1 of match in list of masks return 0 for no binning return -1 if no match ------------------------------------------------------------------------- */ int Neighbor::choose_bin(NeighRequest *rq) { // no binning needed if (style == NSQ) return 0; if (rq->skip || rq->copy || rq->halffull) return 0; - if (rq->history) return 0; - if (rq->respainner || rq->respamiddle) return 0; // use request settings to match exactly one NBin class mask // checks are bitwise using NeighConst bit masks int mask; for (int i = 0; i < nbclass; i++) { mask = binmasks[i]; // require match of these request flags and mask bits // (!A != !B) is effectively a logical xor if (!rq->intel != !(mask & NB_INTEL)) continue; if (!rq->ssa != !(mask & NB_SSA)) continue; if (!rq->kokkos_device != !(mask & NB_KOKKOS_DEVICE)) continue; if (!rq->kokkos_host != !(mask & NB_KOKKOS_HOST)) continue; return i+1; } // error return if matched none return -1; } /* ---------------------------------------------------------------------- assign NStencil class to a NeighList use neigh request settings to build mask match mask to list of masks of known NStencil classes return index+1 of match in list of masks return 0 for no binning return -1 if no match ------------------------------------------------------------------------- */ int Neighbor::choose_stencil(NeighRequest *rq) { // no stencil creation needed if (style == NSQ) return 0; if (rq->skip || rq->copy || rq->halffull) return 0; - if (rq->history) return 0; - if (rq->respainner || rq->respamiddle) return 0; // convert newton request to newtflag = on or off int newtflag; if (rq->newton == 0 && newton_pair) newtflag = 1; else if (rq->newton == 0 && !newton_pair) newtflag = 0; else if (rq->newton == 1) newtflag = 1; else if (rq->newton == 2) newtflag = 0; //printf("STENCIL RQ FLAGS: hff %d %d n %d g %d s %d newtflag %d\n", // rq->half,rq->full,rq->newton,rq->ghost,rq->ssa, // newtflag); // use request and system settings to match exactly one NStencil class mask // checks are bitwise using NeighConst bit masks int mask; for (int i = 0; i < nsclass; i++) { mask = stencilmasks[i]; //printf("III %d: half %d full %d newton %d newtoff %d ghost %d ssa %d\n", // i,mask & NS_HALF,mask & NS_FULL,mask & NS_NEWTON, // mask & NS_NEWTOFF,mask & NS_GHOST,mask & NS_SSA); // exactly one of half or full is set and must match if (rq->half) { if (!(mask & NS_HALF)) continue; } else if (rq->full) { if (!(mask & NS_FULL)) continue; } // newtflag is on or off and must match if (newtflag) { if (!(mask & NS_NEWTON)) continue; } else if (!newtflag) { if (!(mask & NS_NEWTOFF)) continue; } // require match of these request flags and mask bits // (!A != !B) is effectively a logical xor if (!rq->ghost != !(mask & NS_GHOST)) continue; if (!rq->ssa != !(mask & NS_SSA)) continue; // neighbor style is BIN or MULTI and must match if (style == BIN) { if (!(mask & NS_BIN)) continue; } else if (style == MULTI) { if (!(mask & NS_MULTI)) continue; } // dimension is 2 or 3 and must match if (dimension == 2) { if (!(mask & NS_2D)) continue; } else if (dimension == 3) { if (!(mask & NS_3D)) continue; } // domain triclinic flag is on or off and must match if (triclinic) { if (!(mask & NS_TRI)) continue; } else if (!triclinic) { if (!(mask & NS_ORTHO)) continue; } return i+1; } // error return if matched none return -1; } /* ---------------------------------------------------------------------- assign NPair class to a NeighList use neigh request settings to build mask match mask to list of masks of known NPair classes return index+1 of match in list of masks return 0 for no binning return -1 if no match ------------------------------------------------------------------------- */ int Neighbor::choose_pair(NeighRequest *rq) { - // no neighbor list build performed - - if (rq->history) return 0; - if (rq->respainner || rq->respamiddle) return 0; - // error check for includegroup with ghost neighbor request if (includegroup && rq->ghost) error->all(FLERR,"Neighbor include group not allowed with ghost neighbors"); // convert newton request to newtflag = on or off int newtflag; if (rq->newton == 0 && newton_pair) newtflag = 1; else if (rq->newton == 0 && !newton_pair) newtflag = 0; else if (rq->newton == 1) newtflag = 1; else if (rq->newton == 2) newtflag = 0; int molecular = atom->molecular; //printf("PAIR RQ FLAGS: hf %d %d n %d g %d sz %d gos %d r %d b %d o %d i %d " // "kk %d %d ss %d dn %d sk %d cp %d hf %d oo %d\n", // rq->half,rq->full,rq->newton,rq->ghost,rq->size, // rq->granonesided,rq->respaouter,rq->bond,rq->omp,rq->intel, // rq->kokkos_host,rq->kokkos_device,rq->ssa,rq->dnum, // rq->skip,rq->copy,rq->halffull,rq->off2on); // use request and system settings to match exactly one NPair class mask // checks are bitwise using NeighConst bit masks int mask; for (int i = 0; i < npclass; i++) { mask = pairmasks[i]; //printf(" PAIR NAMES i %d %d name %s mask %d\n",i,nrequest, // pairnames[i],pairmasks[i]); // if copy request, no further checks needed, just return or continue // Kokkos device/host flags must also match in order to copy if (rq->copy) { if (!(mask & NP_COPY)) continue; if (!rq->kokkos_device != !(mask & NP_KOKKOS_DEVICE)) continue; if (!rq->kokkos_host != !(mask & NP_KOKKOS_HOST)) continue; return i+1; } // exactly one of half or full is set and must match if (rq->half) { if (!(mask & NP_HALF)) continue; } else if (rq->full) { if (!(mask & NP_FULL)) continue; } // newtflag is on or off and must match if (newtflag) { if (!(mask & NP_NEWTON)) continue; } else if (!newtflag) { if (!(mask & NP_NEWTOFF)) continue; } // if molecular on, do not match ATOMONLY (b/c a MOLONLY Npair exists) // if molecular off, do not match MOLONLY (b/c an ATOMONLY Npair exists) if (molecular) { if (mask & NP_ATOMONLY) continue; } else if (!molecular) { if (mask & NP_MOLONLY) continue; } // require match of these request flags and mask bits // (!A != !B) is effectively a logical xor if (!rq->ghost != !(mask & NP_GHOST)) continue; if (!rq->size != !(mask & NP_SIZE)) continue; if (!rq->respaouter != !(mask & NP_RESPA)) continue; if (!rq->granonesided != !(mask & NP_ONESIDE)) continue; if (!rq->respaouter != !(mask & NP_RESPA)) continue; if (!rq->bond != !(mask & NP_BOND)) continue; if (!rq->omp != !(mask & NP_OMP)) continue; if (!rq->intel != !(mask & NP_INTEL)) continue; if (!rq->kokkos_device != !(mask & NP_KOKKOS_DEVICE)) continue; if (!rq->kokkos_host != !(mask & NP_KOKKOS_HOST)) continue; if (!rq->ssa != !(mask & NP_SSA)) continue; if (!rq->skip != !(mask & NP_SKIP)) continue; if (!rq->halffull != !(mask & NP_HALF_FULL)) continue; if (!rq->off2on != !(mask & NP_OFF2ON)) continue; // neighbor style is one of NSQ,BIN,MULTI and must match if (style == NSQ) { if (!(mask & NP_NSQ)) continue; } else if (style == BIN) { if (!(mask & NP_BIN)) continue; } else if (style == MULTI) { if (!(mask & NP_MULTI)) continue; } // domain triclinic flag is on or off and must match if (triclinic) { if (!(mask & NP_TRI)) continue; } else if (!triclinic) { if (!(mask & NP_ORTHO)) continue; } return i+1; } // error return if matched none return -1; } /* ---------------------------------------------------------------------- called by other classes to request a pairwise neighbor list ------------------------------------------------------------------------- */ int Neighbor::request(void *requestor, int instance) { if (nrequest == maxrequest) { maxrequest += RQDELTA; requests = (NeighRequest **) memory->srealloc(requests,maxrequest*sizeof(NeighRequest *), "neighbor:requests"); } requests[nrequest] = new NeighRequest(lmp); requests[nrequest]->index = nrequest; requests[nrequest]->requestor = requestor; requests[nrequest]->requestor_instance = instance; nrequest++; return nrequest-1; } /* ---------------------------------------------------------------------- one instance per entry in style_neigh_bin.h ------------------------------------------------------------------------- */ template NBin *Neighbor::bin_creator(LAMMPS *lmp) { return new T(lmp); } /* ---------------------------------------------------------------------- one instance per entry in style_neigh_stencil.h ------------------------------------------------------------------------- */ template NStencil *Neighbor::stencil_creator(LAMMPS *lmp) { return new T(lmp); } /* ---------------------------------------------------------------------- one instance per entry in style_neigh_pair.h ------------------------------------------------------------------------- */ template NPair *Neighbor::pair_creator(LAMMPS *lmp) { return new T(lmp); } /* ---------------------------------------------------------------------- setup neighbor binning and neighbor stencils called before run and every reneighbor if box size/shape changes only operates on perpetual lists build_one() operates on occasional lists ------------------------------------------------------------------------- */ void Neighbor::setup_bins() { // invoke setup_bins() for all NBin // actual binning is performed in build() for (int i = 0; i < nbin; i++) neigh_bin[i]->setup_bins(style); // invoke create_setup() and create() for all perpetual NStencil // same ops performed for occasional lists in build_one() for (int i = 0; i < nstencil_perpetual; i++) { neigh_stencil[slist[i]]->create_setup(); neigh_stencil[slist[i]]->create(); } last_setup_bins = update->ntimestep; } /* ---------------------------------------------------------------------- */ int Neighbor::decide() { if (must_check) { bigint n = update->ntimestep; if (restart_check && n == output->next_restart) return 1; for (int i = 0; i < fix_check; i++) if (n == modify->fix[fixchecklist[i]]->next_reneighbor) return 1; } ago++; if (ago >= delay && ago % every == 0) { if (build_once) return 0; if (dist_check == 0) return 1; return check_distance(); } else return 0; } /* ---------------------------------------------------------------------- if any atom moved trigger distance (half of neighbor skin) return 1 shrink trigger distance if box size has changed conservative shrink procedure: compute distance each of 8 corners of box has moved since last reneighbor reduce skin distance by sum of 2 largest of the 8 values new trigger = 1/2 of reduced skin distance for orthogonal box, only need 2 lo/hi corners for triclinic, need all 8 corners since deformations can displace all 8 ------------------------------------------------------------------------- */ int Neighbor::check_distance() { double delx,dely,delz,rsq; double delta,deltasq,delta1,delta2; if (boxcheck) { if (triclinic == 0) { delx = bboxlo[0] - boxlo_hold[0]; dely = bboxlo[1] - boxlo_hold[1]; delz = bboxlo[2] - boxlo_hold[2]; delta1 = sqrt(delx*delx + dely*dely + delz*delz); delx = bboxhi[0] - boxhi_hold[0]; dely = bboxhi[1] - boxhi_hold[1]; delz = bboxhi[2] - boxhi_hold[2]; delta2 = sqrt(delx*delx + dely*dely + delz*delz); delta = 0.5 * (skin - (delta1+delta2)); deltasq = delta*delta; } else { domain->box_corners(); delta1 = delta2 = 0.0; for (int i = 0; i < 8; i++) { delx = corners[i][0] - corners_hold[i][0]; dely = corners[i][1] - corners_hold[i][1]; delz = corners[i][2] - corners_hold[i][2]; delta = sqrt(delx*delx + dely*dely + delz*delz); if (delta > delta1) delta1 = delta; else if (delta > delta2) delta2 = delta; } delta = 0.5 * (skin - (delta1+delta2)); deltasq = delta*delta; } } else deltasq = triggersq; double **x = atom->x; int nlocal = atom->nlocal; if (includegroup) nlocal = atom->nfirst; int flag = 0; for (int i = 0; i < nlocal; i++) { delx = x[i][0] - xhold[i][0]; dely = x[i][1] - xhold[i][1]; delz = x[i][2] - xhold[i][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq > deltasq) flag = 1; } int flagall; MPI_Allreduce(&flag,&flagall,1,MPI_INT,MPI_MAX,world); if (flagall && ago == MAX(every,delay)) ndanger++; return flagall; } /* ---------------------------------------------------------------------- build perpetual neighbor lists called at setup and every few timesteps during run or minimization topology lists also built if topoflag = 1 (Kokkos calls with topoflag=0) ------------------------------------------------------------------------- */ void Neighbor::build(int topoflag) { int i,m; ago = 0; ncalls++; lastcall = update->ntimestep; int nlocal = atom->nlocal; int nall = nlocal + atom->nghost; // check that using special bond flags will not overflow neigh lists if (nall > NEIGHMASK) error->one(FLERR,"Too many local+ghost atoms for neighbor list"); // store current atom positions and box size if needed if (dist_check) { double **x = atom->x; if (includegroup) nlocal = atom->nfirst; if (atom->nmax > maxhold) { maxhold = atom->nmax; memory->destroy(xhold); memory->create(xhold,maxhold,3,"neigh:xhold"); } for (i = 0; i < nlocal; i++) { xhold[i][0] = x[i][0]; xhold[i][1] = x[i][1]; xhold[i][2] = x[i][2]; } if (boxcheck) { if (triclinic == 0) { boxlo_hold[0] = bboxlo[0]; boxlo_hold[1] = bboxlo[1]; boxlo_hold[2] = bboxlo[2]; boxhi_hold[0] = bboxhi[0]; boxhi_hold[1] = bboxhi[1]; boxhi_hold[2] = bboxhi[2]; } else { domain->box_corners(); corners = domain->corners; for (i = 0; i < 8; i++) { corners_hold[i][0] = corners[i][0]; corners_hold[i][1] = corners[i][1]; corners_hold[i][2] = corners[i][2]; } } } } // bin atoms for all NBin instances // not just NBin associated with perpetual lists, also occasional lists // b/c cannot wait to bin occasional lists in build_one() call // if bin then, atoms may have moved outside of proc domain & bin extent, // leading to errors or even a crash if (style != NSQ) { for (int i = 0; i < nbin; i++) { neigh_bin[i]->bin_atoms_setup(nall); neigh_bin[i]->bin_atoms(); } } // build pairwise lists for all perpetual NPair/NeighList // grow() with nlocal/nall args so that only realloc if have to for (i = 0; i < npair_perpetual; i++) { m = plist[i]; if (!lists[m]->copy) lists[m]->grow(nlocal,nall); neigh_pair[m]->build_setup(); neigh_pair[m]->build(lists[m]); } // build topology lists for bonds/angles/etc if (atom->molecular && topoflag) build_topology(); } /* ---------------------------------------------------------------------- build topology neighbor lists: bond, angle, dihedral, improper copy their list info back to Neighbor for access by bond/angle/etc classes ------------------------------------------------------------------------- */ void Neighbor::build_topology() { if (force->bond) { neigh_bond->build(); nbondlist = neigh_bond->nbondlist; bondlist = neigh_bond->bondlist; } if (force->angle) { neigh_angle->build(); nanglelist = neigh_angle->nanglelist; anglelist = neigh_angle->anglelist; } if (force->dihedral) { neigh_dihedral->build(); ndihedrallist = neigh_dihedral->ndihedrallist; dihedrallist = neigh_dihedral->dihedrallist; } if (force->improper) { neigh_improper->build(); nimproperlist = neigh_improper->nimproperlist; improperlist = neigh_improper->improperlist; } } /* ---------------------------------------------------------------------- build a single occasional pairwise neighbor list indexed by I called by other classes ------------------------------------------------------------------------- */ void Neighbor::build_one(class NeighList *mylist, int preflag) { // check if list structure is initialized if (mylist == NULL) error->all(FLERR,"Trying to build an occasional neighbor list " "before initialization completed"); // build_one() should never be invoked on a perpetual list if (!mylist->occasional) error->all(FLERR,"Neighbor build one invoked on perpetual list"); // no need to build if already built since last re-neighbor // preflag is set by fix bond/create and fix bond/swap // b/c they invoke build_one() on same step neigh list is re-built, // but before re-build, so need to use ">" instead of ">=" NPair *np = neigh_pair[mylist->index]; if (preflag) { if (np->last_build > lastcall) return; } else { if (np->last_build >= lastcall) return; } // if this is copy list and parent is occasional list, // or this is halffull and parent is occasional list, // insure parent is current if (mylist->listcopy && mylist->listcopy->occasional) build_one(mylist->listcopy,preflag); if (mylist->listfull && mylist->listfull->occasional) build_one(mylist->listfull,preflag); // create stencil if hasn't been created since last setup_bins() call NStencil *ns = np->ns; if (ns && ns->last_stencil < last_setup_bins) { ns->create_setup(); ns->create(); } // build the list if (!mylist->copy) mylist->grow(atom->nlocal,atom->nlocal+atom->nghost); np->build_setup(); np->build(mylist); } /* ---------------------------------------------------------------------- set neighbor style and skin distance ------------------------------------------------------------------------- */ void Neighbor::set(int narg, char **arg) { if (narg != 2) error->all(FLERR,"Illegal neighbor command"); skin = force->numeric(FLERR,arg[0]); if (skin < 0.0) error->all(FLERR,"Illegal neighbor command"); if (strcmp(arg[1],"nsq") == 0) style = NSQ; else if (strcmp(arg[1],"bin") == 0) style = BIN; else if (strcmp(arg[1],"multi") == 0) style = MULTI; else error->all(FLERR,"Illegal neighbor command"); if (style == MULTI && lmp->citeme) lmp->citeme->add(cite_neigh_multi); } /* ---------------------------------------------------------------------- reset timestamps in all NeignBin, NStencil, NPair classes so that neighbor lists will rebuild properly with timestep change ditto for lastcall and last_setup_bins ------------------------------------------------------------------------- */ void Neighbor::reset_timestep(bigint ntimestep) { for (int i = 0; i < nbin; i++) neigh_bin[i]->last_bin = -1; for (int i = 0; i < nstencil; i++) neigh_stencil[i]->last_stencil = -1; for (int i = 0; i < nlist; i++) { if (!neigh_pair[i]) continue; neigh_pair[i]->last_build = -1; } lastcall = -1; last_setup_bins = -1; } /* ---------------------------------------------------------------------- modify parameters of the pair-wise neighbor build ------------------------------------------------------------------------- */ void Neighbor::modify_params(int narg, char **arg) { int iarg = 0; while (iarg < narg) { if (strcmp(arg[iarg],"every") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal neigh_modify command"); every = force->inumeric(FLERR,arg[iarg+1]); if (every <= 0) error->all(FLERR,"Illegal neigh_modify command"); iarg += 2; } else if (strcmp(arg[iarg],"delay") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal neigh_modify command"); delay = force->inumeric(FLERR,arg[iarg+1]); if (delay < 0) error->all(FLERR,"Illegal neigh_modify command"); iarg += 2; } else if (strcmp(arg[iarg],"check") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal neigh_modify command"); if (strcmp(arg[iarg+1],"yes") == 0) dist_check = 1; else if (strcmp(arg[iarg+1],"no") == 0) dist_check = 0; else error->all(FLERR,"Illegal neigh_modify command"); iarg += 2; } else if (strcmp(arg[iarg],"once") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal neigh_modify command"); if (strcmp(arg[iarg+1],"yes") == 0) build_once = 1; else if (strcmp(arg[iarg+1],"no") == 0) build_once = 0; else error->all(FLERR,"Illegal neigh_modify command"); iarg += 2; } else if (strcmp(arg[iarg],"page") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal neigh_modify command"); old_pgsize = pgsize; pgsize = force->inumeric(FLERR,arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"one") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal neigh_modify command"); old_oneatom = oneatom; oneatom = force->inumeric(FLERR,arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"binsize") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal neigh_modify command"); binsize_user = force->numeric(FLERR,arg[iarg+1]); if (binsize_user <= 0.0) binsizeflag = 0; else binsizeflag = 1; iarg += 2; } else if (strcmp(arg[iarg],"cluster") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal neigh_modify command"); if (strcmp(arg[iarg+1],"yes") == 0) cluster_check = 1; else if (strcmp(arg[iarg+1],"no") == 0) cluster_check = 0; else error->all(FLERR,"Illegal neigh_modify command"); iarg += 2; } else if (strcmp(arg[iarg],"include") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal neigh_modify command"); includegroup = group->find(arg[iarg+1]); if (includegroup < 0) error->all(FLERR,"Invalid group ID in neigh_modify command"); if (includegroup && (atom->firstgroupname == NULL || strcmp(arg[iarg+1],atom->firstgroupname) != 0)) error->all(FLERR, "Neigh_modify include group != atom_modify first group"); iarg += 2; } else if (strcmp(arg[iarg],"exclude") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal neigh_modify command"); if (strcmp(arg[iarg+1],"type") == 0) { if (iarg+4 > narg) error->all(FLERR,"Illegal neigh_modify command"); if (nex_type == maxex_type) { maxex_type += EXDELTA; memory->grow(ex1_type,maxex_type,"neigh:ex1_type"); memory->grow(ex2_type,maxex_type,"neigh:ex2_type"); } ex1_type[nex_type] = force->inumeric(FLERR,arg[iarg+2]); ex2_type[nex_type] = force->inumeric(FLERR,arg[iarg+3]); nex_type++; iarg += 4; } else if (strcmp(arg[iarg+1],"group") == 0) { if (iarg+4 > narg) error->all(FLERR,"Illegal neigh_modify command"); if (nex_group == maxex_group) { maxex_group += EXDELTA; memory->grow(ex1_group,maxex_group,"neigh:ex1_group"); memory->grow(ex2_group,maxex_group,"neigh:ex2_group"); } ex1_group[nex_group] = group->find(arg[iarg+2]); ex2_group[nex_group] = group->find(arg[iarg+3]); if (ex1_group[nex_group] == -1 || ex2_group[nex_group] == -1) error->all(FLERR,"Invalid group ID in neigh_modify command"); nex_group++; iarg += 4; } else if (strcmp(arg[iarg+1],"molecule/inter") == 0 || strcmp(arg[iarg+1],"molecule/intra") == 0) { if (iarg+3 > narg) error->all(FLERR,"Illegal neigh_modify command"); if (atom->molecule_flag == 0) error->all(FLERR,"Neigh_modify exclude molecule " "requires atom attribute molecule"); if (nex_mol == maxex_mol) { maxex_mol += EXDELTA; memory->grow(ex_mol_group,maxex_mol,"neigh:ex_mol_group"); if (lmp->kokkos) grow_ex_mol_intra_kokkos(); else memory->grow(ex_mol_intra,maxex_mol,"neigh:ex_mol_intra"); } ex_mol_group[nex_mol] = group->find(arg[iarg+2]); if (ex_mol_group[nex_mol] == -1) error->all(FLERR,"Invalid group ID in neigh_modify command"); if (strcmp(arg[iarg+1],"molecule/intra") == 0) ex_mol_intra[nex_mol] = 1; else ex_mol_intra[nex_mol] = 0; nex_mol++; iarg += 3; } else if (strcmp(arg[iarg+1],"none") == 0) { nex_type = nex_group = nex_mol = 0; iarg += 2; } else error->all(FLERR,"Illegal neigh_modify command"); } else error->all(FLERR,"Illegal neigh_modify command"); } } /* ---------------------------------------------------------------------- remove the first group-group exclusion matching group1, group2 ------------------------------------------------------------------------- */ void Neighbor::exclusion_group_group_delete(int group1, int group2) { int m, mlast; for (m = 0; m < nex_group; m++) if (ex1_group[m] == group1 && ex2_group[m] == group2 ) break; mlast = m; if (mlast == nex_group) error->all(FLERR,"Unable to find group-group exclusion"); for (m = mlast+1; m < nex_group; m++) { ex1_group[m-1] = ex1_group[m]; ex2_group[m-1] = ex2_group[m]; ex1_bit[m-1] = ex1_bit[m]; ex2_bit[m-1] = ex2_bit[m]; } nex_group--; } /* ---------------------------------------------------------------------- return the value of exclude - used to check compatibility with GPU ------------------------------------------------------------------------- */ int Neighbor::exclude_setting() { return exclude; } /* ---------------------------------------------------------------------- return # of bytes of allocated memory ------------------------------------------------------------------------- */ bigint Neighbor::memory_usage() { bigint bytes = 0; bytes += memory->usage(xhold,maxhold,3); for (int i = 0; i < nlist; i++) if (lists[i]) bytes += lists[i]->memory_usage(); for (int i = 0; i < nstencil; i++) bytes += neigh_stencil[i]->memory_usage(); for (int i = 0; i < nbin; i++) bytes += neigh_bin[i]->memory_usage(); if (neigh_bond) bytes += neigh_bond->memory_usage(); if (neigh_angle) bytes += neigh_angle->memory_usage(); if (neigh_dihedral) bytes += neigh_dihedral->memory_usage(); if (neigh_improper) bytes += neigh_improper->memory_usage(); return bytes; } diff --git a/src/neighbor.h b/src/neighbor.h index 64bced229..9244bc575 100644 --- a/src/neighbor.h +++ b/src/neighbor.h @@ -1,375 +1,374 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #ifndef LMP_NEIGHBOR_H #define LMP_NEIGHBOR_H #include "pointers.h" #include namespace LAMMPS_NS { class Neighbor : protected Pointers { public: int style; // 0,1,2 = nsq, bin, multi int every; // build every this many steps int delay; // delay build for this many steps int dist_check; // 0 = always build, 1 = only if 1/2 dist int ago; // how many steps ago neighboring occurred int pgsize; // size of neighbor page int oneatom; // max # of neighbors for one atom int includegroup; // only build pairwise lists for this group int build_once; // 1 if only build lists once per run double skin; // skin distance double cutneighmin; // min neighbor cutoff for all type pairs double cutneighmax; // max neighbor cutoff for all type pairs double cutneighmaxsq; // cutneighmax squared double **cutneighsq; // neighbor cutneigh sq for each type pair double **cutneighghostsq; // cutneigh sq for each ghost type pair double *cuttype; // for each type, max neigh cut w/ others double *cuttypesq; // cuttype squared double cut_inner_sq; // outer cutoff for inner neighbor list double cut_middle_sq; // outer cutoff for middle neighbor list double cut_middle_inside_sq; // inner cutoff for middle neighbor list int binsizeflag; // user-chosen bin size double binsize_user; // set externally by some accelerator pkgs bigint ncalls; // # of times build has been called bigint ndanger; // # of dangerous builds bigint lastcall; // timestep of last neighbor::build() call // geometry and static info, used by other Neigh classes double *bboxlo,*bboxhi; // ptrs to full domain bounding box // different for orthog vs triclinic - double *zeroes; // vector of zeroes for shear history init // exclusion info, used by NeighPair int exclude; // 0 if no type/group exclusions, 1 if yes int nex_type; // # of entries in type exclusion list int *ex1_type,*ex2_type; // pairs of types to exclude int **ex_type; // 2d array of excluded type pairs int nex_group; // # of entries in group exclusion list int *ex1_group,*ex2_group; // pairs of group #'s to exclude int *ex1_bit,*ex2_bit; // pairs of group bits to exclude int nex_mol; // # of entries in molecule exclusion list int *ex_mol_group; // molecule group #'s to exclude int *ex_mol_bit; // molecule group bits to exclude int *ex_mol_intra; // 0 = exclude if in 2 molecules (inter) // 1 = exclude if in same molecule (intra) // special info, used by NeighPair int special_flag[4]; // flags for 1-2, 1-3, 1-4 neighbors // cluster setting, used by NeighTopo int cluster_check; // 1 if check bond/angle/etc satisfies minimg // pairwise neighbor lists and corresponding requests int nlist; // # of pairwise neighbor lists int nrequest; // # of requests, same as nlist int old_nrequest; // # of requests for previous run class NeighList **lists; class NeighRequest **requests; // from Pair,Fix,Compute,Command classes class NeighRequest **old_requests; // copy of requests to compare to // data from topology neighbor lists int nbondlist; // list of bonds to compute int **bondlist; int nanglelist; // list of angles to compute int **anglelist; int ndihedrallist; // list of dihedrals to compute int **dihedrallist; int nimproperlist; // list of impropers to compute int **improperlist; // public methods Neighbor(class LAMMPS *); virtual ~Neighbor(); virtual void init(); int request(void *, int instance=0); int decide(); // decide whether to build or not virtual int check_distance(); // check max distance moved since last build void setup_bins(); // setup bins based on box and cutoff virtual void build(int topoflag=1); // build all perpetual neighbor lists virtual void build_topology(); // pairwise topology neighbor lists void build_one(class NeighList *list, int preflag=0); // create a one-time pairwise neigh list void set(int, char **); // set neighbor style and skin distance void reset_timestep(bigint); // reset of timestep counter void modify_params(int, char**); // modify params that control builds void exclusion_group_group_delete(int, int); // rm a group-group exclusion int exclude_setting(); // return exclude value to accelerator pkg class NeighRequest *find_request(void *); // find a neighbor request bigint memory_usage(); protected: int me,nprocs; int firsttime; // flag for calling init_styles() only once int dimension; // 2/3 for 2d/3d int triclinic; // 0 if domain is orthog, 1 if triclinic int newton_pair; // 0 if newton off for pairwise, 1 if on int must_check; // 1 if must check other classes to reneigh int restart_check; // 1 if restart enabled, 0 if no int fix_check; // # of fixes that induce reneigh int *fixchecklist; // which fixes to check bigint last_setup_bins; // step of last neighbor::setup_bins() call double triggersq; // trigger = build when atom moves this dist double **xhold; // atom coords at last neighbor build int maxhold; // size of xhold array int boxcheck; // 1 if need to store box size double boxlo_hold[3],boxhi_hold[3]; // box size at last neighbor build double corners_hold[8][3]; // box corners at last neighbor build double (*corners)[3]; // ptr to 8 corners of triclinic box double inner[2],middle[2]; // rRESPA cutoffs for extra lists int old_style,old_triclinic; // previous run info int old_pgsize,old_oneatom; // used to avoid re-creating neigh lists int nstencil_perpetual; // # of perpetual NeighStencil classes int npair_perpetual; // #x of perpetual NeighPair classes int *slist; // indices of them in neigh_stencil int *plist; // indices of them in neigh_pair int maxex_type; // max # in exclusion type list int maxex_group; // max # in exclusion group list int maxex_mol; // max # in exclusion molecule list int maxatom; // max size of atom-based NeighList arrays int maxrequest; // max size of NeighRequest list int maxwt; // max weighting factor applied + 1 // info for other Neigh classes: NBin,NStencil,NPair,NTopo int nbin,nstencil; int nbclass,nsclass,npclass; int bondwhich,anglewhich,dihedralwhich,improperwhich; typedef class NBin *(*BinCreator)(class LAMMPS *); BinCreator *binclass; char **binnames; int *binmasks; class NBin **neigh_bin; typedef class NStencil *(*StencilCreator)(class LAMMPS *); StencilCreator *stencilclass; char **stencilnames; int *stencilmasks; class NStencil **neigh_stencil; typedef class NPair *(*PairCreator)(class LAMMPS *); PairCreator *pairclass; char **pairnames; int *pairmasks; class NPair **neigh_pair; class NTopo *neigh_bond; class NTopo *neigh_angle; class NTopo *neigh_dihedral; class NTopo *neigh_improper; // internal methods // including creator methods for Nbin,Nstencil,Npair instances void init_styles(); int init_pair(); virtual void init_topology(); - void morph_other(); + void morph_unique(); void morph_skip(); void morph_granular(); void morph_halffull(); void morph_copy(); void print_pairwise_info(); void requests_new2old(); int choose_bin(class NeighRequest *); int choose_stencil(class NeighRequest *); int choose_pair(class NeighRequest *); template static NBin *bin_creator(class LAMMPS *); template static NStencil *stencil_creator(class LAMMPS *); template static NPair *pair_creator(class LAMMPS *); // dummy functions provided by NeighborKokkos, called in init() // otherwise NeighborKokkos would have to overwrite init() int copymode; virtual void init_cutneighsq_kokkos(int) {} virtual void create_kokkos_list(int) {} virtual void init_ex_type_kokkos(int) {} virtual void init_ex_bit_kokkos() {} virtual void init_ex_mol_bit_kokkos() {} virtual void grow_ex_mol_intra_kokkos() {} }; namespace NeighConst { static const int NB_INTEL = 1<<0; static const int NB_KOKKOS_DEVICE = 1<<1; static const int NB_KOKKOS_HOST = 1<<2; static const int NB_SSA = 1<<3; static const int NS_BIN = 1<<0; static const int NS_MULTI = 1<<1; static const int NS_HALF = 1<<2; static const int NS_FULL = 1<<3; static const int NS_2D = 1<<4; static const int NS_3D = 1<<5; static const int NS_NEWTON = 1<<6; static const int NS_NEWTOFF = 1<<7; static const int NS_ORTHO = 1<<8; static const int NS_TRI = 1<<9; static const int NS_GHOST = 1<<10; static const int NS_SSA = 1<<11; static const int NP_NSQ = 1<<0; static const int NP_BIN = 1<<1; static const int NP_MULTI = 1<<2; static const int NP_HALF = 1<<3; static const int NP_FULL = 1<<4; static const int NP_ORTHO = 1<<5; static const int NP_TRI = 1<<6; static const int NP_ATOMONLY = 1<<7; static const int NP_MOLONLY = 1<<8; static const int NP_NEWTON = 1<<9; static const int NP_NEWTOFF = 1<<10; static const int NP_GHOST = 1<<11; static const int NP_SIZE = 1<<12; static const int NP_ONESIDE = 1<<13; static const int NP_RESPA = 1<<14; static const int NP_BOND = 1<<15; static const int NP_OMP = 1<<16; static const int NP_INTEL = 1<<17; static const int NP_KOKKOS_DEVICE = 1<<18; static const int NP_KOKKOS_HOST = 1<<19; static const int NP_SSA = 1<<20; static const int NP_COPY = 1<<21; static const int NP_SKIP = 1<<22; static const int NP_HALF_FULL = 1<<23; static const int NP_OFF2ON = 1<<24; } } #endif /* ERROR/WARNING messages: E: Neighbor delay must be 0 or multiple of every setting The delay and every parameters set via the neigh_modify command are inconsistent. If the delay setting is non-zero, then it must be a multiple of the every setting. E: Neighbor page size must be >= 10x the one atom setting This is required to prevent wasting too much memory. E: Invalid atom type in neighbor exclusion list Atom types must range from 1 to Ntypes inclusive. W: Neighbor exclusions used with KSpace solver may give inconsistent Coulombic energies This is because excluding specific pair interactions also excludes them from long-range interactions which may not be the desired effect. The special_bonds command handles this consistently by insuring excluded (or weighted) 1-2, 1-3, 1-4 interactions are treated consistently by both the short-range pair style and the long-range solver. This is not done for exclusions of charged atom pairs via the neigh_modify exclude command. E: Neighbor include group not allowed with ghost neighbors This is a current restriction within LAMMPS. E: Neighbor multi not yet enabled for ghost neighbors This is a current restriction within LAMMPS. E: Neighbor multi not yet enabled for granular Self-explanatory. E: Neighbor multi not yet enabled for rRESPA Self-explanatory. E: Too many local+ghost atoms for neighbor list The number of nlocal + nghost atoms on a processor is limited by the size of a 32-bit integer with 2 bits removed for masking 1-2, 1-3, 1-4 neighbors. E: Trying to build an occasional neighbor list before initialization completed This is not allowed. Source code caller needs to be modified. E: Domain too large for neighbor bins The domain has become extremely large so that neighbor bins cannot be used. Most likely, one or more atoms have been blown out of the simulation box to a great distance. E: Cannot use neighbor bins - box size << cutoff Too many neighbor bins will be created. This typically happens when the simulation box is very small in some dimension, compared to the neighbor cutoff. Use the "nsq" style instead of "bin" style. E: Too many neighbor bins This is likely due to an immense simulation box that has blown up to a large size. E: Illegal ... command Self-explanatory. Check the input script syntax and compare to the documentation for the command. You can use -echo screen as a command-line option when running LAMMPS to see the offending line. E: Invalid group ID in neigh_modify command A group ID used in the neigh_modify command does not exist. E: Neigh_modify include group != atom_modify first group Self-explanatory. E: Neigh_modify exclude molecule requires atom attribute molecule Self-explanatory. */ diff --git a/src/npair.cpp b/src/npair.cpp index 9fbb4d219..dd3a73926 100644 --- a/src/npair.cpp +++ b/src/npair.cpp @@ -1,240 +1,239 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include #include "npair.h" #include "neighbor.h" #include "neigh_request.h" #include "nbin.h" #include "nstencil.h" #include "atom.h" #include "update.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ NPair::NPair(LAMMPS *lmp) : Pointers(lmp), nb(NULL), ns(NULL), bins(NULL), stencil(NULL) { last_build = -1; mycutneighsq = NULL; molecular = atom->molecular; } /* ---------------------------------------------------------------------- */ NPair::~NPair() { memory->destroy(mycutneighsq); } /* ---------------------------------------------------------------------- */ void NPair::post_constructor(NeighRequest *nrq) { cutoff_custom = 0.0; if (nrq->cut) cutoff_custom = nrq->cutoff; } /* ---------------------------------------------------------------------- copy needed info from Neighbor class to this build class done once per run ------------------------------------------------------------------------- */ void NPair::copy_neighbor_info() { // general params includegroup = neighbor->includegroup; exclude = neighbor->exclude; skin = neighbor->skin; cutneighsq = neighbor->cutneighsq; cutneighghostsq = neighbor->cutneighghostsq; cut_inner_sq = neighbor->cut_inner_sq; cut_middle_sq = neighbor->cut_middle_sq; cut_middle_inside_sq = neighbor->cut_middle_inside_sq; - zeroes = neighbor->zeroes; bboxlo = neighbor->bboxlo; bboxhi = neighbor->bboxhi; // exclusion info nex_type = neighbor->nex_type; ex1_type = neighbor->ex1_type; ex2_type = neighbor->ex2_type; ex_type = neighbor->ex_type; nex_group = neighbor->nex_group; ex1_group = neighbor->ex1_group; ex2_group = neighbor->ex2_group; ex1_bit = neighbor->ex1_bit; ex2_bit = neighbor->ex2_bit; nex_mol = neighbor->nex_mol; ex_mol_group = neighbor->ex_mol_group; ex_mol_bit = neighbor->ex_mol_bit; ex_mol_intra = neighbor->ex_mol_intra; // special info special_flag = neighbor->special_flag; // overwrite per-type Neighbor cutoffs with custom value set by requestor // only works for style = BIN (checked by Neighbor class) if (cutoff_custom > 0.0) { memory->destroy(mycutneighsq); int n = atom->ntypes; memory->create(mycutneighsq,n+1,n+1,"npair:cutneighsq"); int i,j; for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) mycutneighsq[i][j] = cutoff_custom * cutoff_custom; cutneighsq = mycutneighsq; } } /* ---------------------------------------------------------------------- copy info from NBin class to this build class ------------------------------------------------------------------------- */ void NPair::copy_bin_info() { nbinx = nb->nbinx; nbiny = nb->nbiny; nbinz = nb->nbinz; mbins = nb->mbins; mbinx = nb->mbinx; mbiny = nb->mbiny; mbinz = nb->mbinz; mbinxlo = nb->mbinxlo; mbinylo = nb->mbinylo; mbinzlo = nb->mbinzlo; bininvx = nb->bininvx; bininvy = nb->bininvy; bininvz = nb->bininvz; atom2bin = nb->atom2bin; bins = nb->bins; binhead = nb->binhead; } /* ---------------------------------------------------------------------- copy info from NStencil class to this build class ------------------------------------------------------------------------- */ void NPair::copy_stencil_info() { nstencil = ns->nstencil; stencil = ns->stencil; stencilxyz = ns->stencilxyz; nstencil_multi = ns->nstencil_multi; stencil_multi = ns->stencil_multi; distsq_multi = ns->distsq_multi; } /* ---------------------------------------------------------------------- copy info from NBin and NStencil classes to this build class ------------------------------------------------------------------------- */ void NPair::build_setup() { if (nb) copy_bin_info(); if (ns) copy_stencil_info(); // set here, since build_setup() always called before build() last_build = update->ntimestep; } /* ---------------------------------------------------------------------- test if atom pair i,j is excluded from neighbor list due to type, group, molecule settings from neigh_modify command return 1 if should be excluded, 0 if included ------------------------------------------------------------------------- */ int NPair::exclusion(int i, int j, int itype, int jtype, int *mask, tagint *molecule) const { int m; if (nex_type && ex_type[itype][jtype]) return 1; if (nex_group) { for (m = 0; m < nex_group; m++) { if (mask[i] & ex1_bit[m] && mask[j] & ex2_bit[m]) return 1; if (mask[i] & ex2_bit[m] && mask[j] & ex1_bit[m]) return 1; } } if (nex_mol) { for (m = 0; m < nex_mol; m++) // intra-chain: exclude i-j pair if in same molecule // inter-chain: exclude i-j pair if in different molecules if (ex_mol_intra[m]) { if (mask[i] & ex_mol_bit[m] && mask[j] & ex_mol_bit[m] && molecule[i] == molecule[j]) return 1; } else { if (mask[i] & ex_mol_bit[m] && mask[j] & ex_mol_bit[m] && molecule[i] != molecule[j]) return 1; } } return 0; } /* ---------------------------------------------------------------------- same as coord2bin in Nbin, but also return ix,iy,iz offsets in each dim used by some of the ghost neighbor lists ------------------------------------------------------------------------- */ int NPair::coord2bin(double *x, int &ix, int &iy, int &iz) { if (!ISFINITE(x[0]) || !ISFINITE(x[1]) || !ISFINITE(x[2])) error->one(FLERR,"Non-numeric positions - simulation unstable"); if (x[0] >= bboxhi[0]) ix = static_cast ((x[0]-bboxhi[0])*bininvx) + nbinx; else if (x[0] >= bboxlo[0]) { ix = static_cast ((x[0]-bboxlo[0])*bininvx); ix = MIN(ix,nbinx-1); } else ix = static_cast ((x[0]-bboxlo[0])*bininvx) - 1; if (x[1] >= bboxhi[1]) iy = static_cast ((x[1]-bboxhi[1])*bininvy) + nbiny; else if (x[1] >= bboxlo[1]) { iy = static_cast ((x[1]-bboxlo[1])*bininvy); iy = MIN(iy,nbiny-1); } else iy = static_cast ((x[1]-bboxlo[1])*bininvy) - 1; if (x[2] >= bboxhi[2]) iz = static_cast ((x[2]-bboxhi[2])*bininvz) + nbinz; else if (x[2] >= bboxlo[2]) { iz = static_cast ((x[2]-bboxlo[2])*bininvz); iz = MIN(iz,nbinz-1); } else iz = static_cast ((x[2]-bboxlo[2])*bininvz) - 1; ix -= mbinxlo; iy -= mbinylo; iz -= mbinzlo; return iz*mbiny*mbinx + iy*mbinx + ix; } diff --git a/src/npair.h b/src/npair.h index 6941b8616..289a1348d 100644 --- a/src/npair.h +++ b/src/npair.h @@ -1,146 +1,145 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #ifndef LMP_NPAIR_H #define LMP_NPAIR_H #include "pointers.h" namespace LAMMPS_NS { class NPair : protected Pointers { public: int istyle; // 1-N index into pairnames class NBin *nb; // ptr to NBin instance I depend on class NStencil *ns; // ptr to NStencil instance I depend on bigint last_build; // last timestep build performed double cutoff_custom; // cutoff set by requestor NPair(class LAMMPS *); virtual ~NPair(); void post_constructor(class NeighRequest *); virtual void copy_neighbor_info(); void build_setup(); virtual void build(class NeighList *) = 0; protected: double **mycutneighsq; // per-type cutoffs when user specified // data from Neighbor class int includegroup; int exclude; double skin; double **cutneighsq; double **cutneighghostsq; double cut_inner_sq; double cut_middle_sq; double cut_middle_inside_sq; - double *zeroes; double *bboxlo,*bboxhi; // exclusion data from Neighbor class int nex_type; // # of entries in type exclusion list int *ex1_type,*ex2_type; // pairs of types to exclude int **ex_type; // 2d array of excluded type pairs int nex_group; // # of entries in group exclusion list int *ex1_group,*ex2_group; // pairs of group #'s to exclude int *ex1_bit,*ex2_bit; // pairs of group bits to exclude int nex_mol; // # of entries in molecule exclusion list int *ex_mol_bit; // molecule group bits to exclude int *ex_mol_group; // molecule group #'s to exclude int *ex_mol_intra; // 0 = exclude if in 2 molecules (inter) // 1 = exclude if in same molecule (intra) // special data from Neighbor class int *special_flag; // data from NBin class int nbinx,nbiny,nbinz; int mbins; int mbinx,mbiny,mbinz; int mbinxlo,mbinylo,mbinzlo; double bininvx,bininvy,bininvz; int *atom2bin,*bins; int *binhead; // data from NStencil class int nstencil; int *stencil; int **stencilxyz; int *nstencil_multi; int **stencil_multi; double **distsq_multi; // data common to all NPair variants int molecular; // methods for all NPair variants virtual void copy_bin_info(); virtual void copy_stencil_info(); int exclusion(int, int, int, int, int *, tagint *) const; // test for pair exclusion int coord2bin(double *); // mapping atom coord to a bin int coord2bin(double *, int &, int &, int&); // ditto // find_special: determine if atom j is in special list of atom i // if it is not, return 0 // if it is and special flag is 0 (both coeffs are 0.0), return -1 // if it is and special flag is 1 (both coeffs are 1.0), return 0 // if it is and special flag is 2 (otherwise), return 1,2,3 // for which level of neighbor it is (and which coeff it maps to) inline int find_special(const tagint *list, const int *nspecial, const tagint tag) const { const int n1 = nspecial[0]; const int n2 = nspecial[1]; const int n3 = nspecial[2]; for (int i = 0; i < n3; i++) { if (list[i] == tag) { if (i < n1) { if (special_flag[1] == 0) return -1; else if (special_flag[1] == 1) return 0; else return 1; } else if (i < n2) { if (special_flag[2] == 0) return -1; else if (special_flag[2] == 1) return 0; else return 2; } else { if (special_flag[3] == 0) return -1; else if (special_flag[3] == 1) return 0; else return 3; } } } return 0; }; }; } #endif /* ERROR/WARNING messages: */ diff --git a/src/npair_copy.cpp b/src/npair_copy.cpp index 1799d48fe..9426d22ed 100644 --- a/src/npair_copy.cpp +++ b/src/npair_copy.cpp @@ -1,46 +1,44 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include "npair_copy.h" #include "neighbor.h" #include "neigh_list.h" #include "atom.h" #include "atom_vec.h" #include "molecule.h" #include "domain.h" #include "my_page.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ NPairCopy::NPairCopy(LAMMPS *lmp) : NPair(lmp) {} /* ---------------------------------------------------------------------- create list which is simply a copy of parent list ------------------------------------------------------------------------- */ void NPairCopy::build(NeighList *list) { NeighList *listcopy = list->listcopy; list->inum = listcopy->inum; list->gnum = listcopy->gnum; list->ilist = listcopy->ilist; list->numneigh = listcopy->numneigh; list->firstneigh = listcopy->firstneigh; - list->firstdouble = listcopy->firstdouble; list->ipage = listcopy->ipage; - list->dpage = listcopy->dpage; } diff --git a/src/npair_half_respa_bin_newtoff.cpp b/src/npair_half_respa_bin_newtoff.cpp index 11246b4af..0145771f4 100644 --- a/src/npair_half_respa_bin_newtoff.cpp +++ b/src/npair_half_respa_bin_newtoff.cpp @@ -1,190 +1,187 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include "npair_half_respa_bin_newtoff.h" #include "neighbor.h" #include "neigh_list.h" #include "atom.h" #include "atom_vec.h" #include "molecule.h" #include "domain.h" #include "my_page.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ NPairHalfRespaBinNewtoff::NPairHalfRespaBinNewtoff(LAMMPS *lmp) : NPair(lmp) {} /* ---------------------------------------------------------------------- multiple respa lists binned neighbor list construction with partial Newton's 3rd law each owned atom i checks own bin and surrounding bins in non-Newton stencil pair stored once if i,j are both owned and i < j pair stored by me if j is ghost (also stored by proc owning j) ------------------------------------------------------------------------- */ void NPairHalfRespaBinNewtoff::build(NeighList *list) { int i,j,k,n,itype,jtype,ibin,n_inner,n_middle,imol,iatom,moltemplate; tagint tagprev; double xtmp,ytmp,ztmp,delx,dely,delz,rsq; int *neighptr,*neighptr_inner,*neighptr_middle; double **x = atom->x; int *type = atom->type; int *mask = atom->mask; tagint *tag = atom->tag; tagint *molecule = atom->molecule; tagint **special = atom->special; int **nspecial = atom->nspecial; int nlocal = atom->nlocal; if (includegroup) nlocal = atom->nfirst; int *molindex = atom->molindex; int *molatom = atom->molatom; Molecule **onemols = atom->avec->onemols; if (molecular == 2) moltemplate = 1; else moltemplate = 0; int *ilist = list->ilist; int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; MyPage *ipage = list->ipage; - NeighList *listinner = list->listinner; - int *ilist_inner = listinner->ilist; - int *numneigh_inner = listinner->numneigh; - int **firstneigh_inner = listinner->firstneigh; - MyPage *ipage_inner = listinner->ipage; + int *ilist_inner = list->ilist_inner; + int *numneigh_inner = list->numneigh_inner; + int **firstneigh_inner = list->firstneigh_inner; + MyPage *ipage_inner = list->ipage_inner; - NeighList *listmiddle; int *ilist_middle,*numneigh_middle,**firstneigh_middle; MyPage *ipage_middle; int respamiddle = list->respamiddle; if (respamiddle) { - listmiddle = list->listmiddle; - ilist_middle = listmiddle->ilist; - numneigh_middle = listmiddle->numneigh; - firstneigh_middle = listmiddle->firstneigh; - ipage_middle = listmiddle->ipage; + ilist_middle = list->ilist_middle; + numneigh_middle = list->numneigh_middle; + firstneigh_middle = list->firstneigh_middle; + ipage_middle = list->ipage_middle; } int inum = 0; int which = 0; int minchange = 0; ipage->reset(); ipage_inner->reset(); if (respamiddle) ipage_middle->reset(); for (i = 0; i < nlocal; i++) { n = n_inner = 0; neighptr = ipage->vget(); neighptr_inner = ipage_inner->vget(); if (respamiddle) { n_middle = 0; neighptr_middle = ipage_middle->vget(); } itype = type[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; ibin = atom2bin[i]; if (moltemplate) { imol = molindex[i]; iatom = molatom[i]; tagprev = tag[i] - iatom - 1; } // loop over all atoms in surrounding bins in stencil including self // only store pair if i < j // stores own/own pairs only once // stores own/ghost pairs on both procs for (k = 0; k < nstencil; k++) { for (j = binhead[ibin+stencil[k]]; j >= 0; j = bins[j]) { if (j <= i) continue; jtype = type[j]; if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq <= cutneighsq[itype][jtype]) { if (molecular) { if (!moltemplate) which = find_special(special[i],nspecial[i],tag[j]); else if (imol >= 0) which = find_special(onemols[imol]->special[iatom], onemols[imol]->nspecial[iatom], tag[j]-tagprev); else which = 0; if (which == 0) neighptr[n++] = j; else if ((minchange = domain->minimum_image_check(delx,dely,delz))) neighptr[n++] = j; else if (which > 0) neighptr[n++] = j ^ (which << SBBITS); } else neighptr[n++] = j; if (rsq < cut_inner_sq) { if (which == 0) neighptr_inner[n_inner++] = j; else if (minchange) neighptr_inner[n_inner++] = j; else if (which > 0) neighptr_inner[n_inner++] = j ^ (which << SBBITS); } if (respamiddle && rsq < cut_middle_sq && rsq > cut_middle_inside_sq) { if (which == 0) neighptr_middle[n_middle++] = j; else if (minchange) neighptr_middle[n_middle++] = j; else if (which > 0) neighptr_middle[n_middle++] = j ^ (which << SBBITS); } } } } ilist[inum] = i; firstneigh[i] = neighptr; numneigh[i] = n; ipage->vgot(n); if (ipage->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); ilist_inner[inum] = i; firstneigh_inner[i] = neighptr_inner; numneigh_inner[i] = n_inner; ipage_inner->vgot(n_inner); if (ipage_inner->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); if (respamiddle) { ilist_middle[inum] = i; firstneigh_middle[i] = neighptr_middle; numneigh_middle[i] = n_middle; ipage_middle->vgot(n_middle); if (ipage_middle->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); } inum++; } list->inum = inum; - listinner->inum = inum; - if (respamiddle) listmiddle->inum = inum; + list->inum_inner = inum; + if (respamiddle) list->inum_middle = inum; } diff --git a/src/npair_half_respa_bin_newton.cpp b/src/npair_half_respa_bin_newton.cpp index db7667803..72a613204 100644 --- a/src/npair_half_respa_bin_newton.cpp +++ b/src/npair_half_respa_bin_newton.cpp @@ -1,236 +1,233 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include "npair_half_respa_bin_newton.h" #include "neighbor.h" #include "neigh_list.h" #include "atom.h" #include "atom_vec.h" #include "molecule.h" #include "domain.h" #include "my_page.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ NPairHalfRespaBinNewton::NPairHalfRespaBinNewton(LAMMPS *lmp) : NPair(lmp) {} /* ---------------------------------------------------------------------- multiple respa lists binned neighbor list construction with full Newton's 3rd law each owned atom i checks its own bin and other bins in Newton stencil every pair stored exactly once by some processor ------------------------------------------------------------------------- */ void NPairHalfRespaBinNewton::build(NeighList *list) { int i,j,k,n,itype,jtype,ibin,n_inner,n_middle,imol,iatom,moltemplate; tagint tagprev; double xtmp,ytmp,ztmp,delx,dely,delz,rsq; int *neighptr,*neighptr_inner,*neighptr_middle; double **x = atom->x; int *type = atom->type; int *mask = atom->mask; tagint *tag = atom->tag; tagint *molecule = atom->molecule; tagint **special = atom->special; int **nspecial = atom->nspecial; int nlocal = atom->nlocal; if (includegroup) nlocal = atom->nfirst; int *molindex = atom->molindex; int *molatom = atom->molatom; Molecule **onemols = atom->avec->onemols; if (molecular == 2) moltemplate = 1; else moltemplate = 0; int *ilist = list->ilist; int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; MyPage *ipage = list->ipage; - NeighList *listinner = list->listinner; - int *ilist_inner = listinner->ilist; - int *numneigh_inner = listinner->numneigh; - int **firstneigh_inner = listinner->firstneigh; - MyPage *ipage_inner = listinner->ipage; + int *ilist_inner = list->ilist_inner; + int *numneigh_inner = list->numneigh_inner; + int **firstneigh_inner = list->firstneigh_inner; + MyPage *ipage_inner = list->ipage_inner; - NeighList *listmiddle; int *ilist_middle,*numneigh_middle,**firstneigh_middle; MyPage *ipage_middle; int respamiddle = list->respamiddle; if (respamiddle) { - listmiddle = list->listmiddle; - ilist_middle = listmiddle->ilist; - numneigh_middle = listmiddle->numneigh; - firstneigh_middle = listmiddle->firstneigh; - ipage_middle = listmiddle->ipage; + ilist_middle = list->ilist_middle; + numneigh_middle = list->numneigh_middle; + firstneigh_middle = list->firstneigh_middle; + ipage_middle = list->ipage_middle; } int inum = 0; int which = 0; int minchange = 0; ipage->reset(); ipage_inner->reset(); if (respamiddle) ipage_middle->reset(); for (i = 0; i < nlocal; i++) { n = n_inner = 0; neighptr = ipage->vget(); neighptr_inner = ipage_inner->vget(); if (respamiddle) { n_middle = 0; neighptr_middle = ipage_middle->vget(); } itype = type[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; if (moltemplate) { imol = molindex[i]; iatom = molatom[i]; tagprev = tag[i] - iatom - 1; } // loop over rest of atoms in i's bin, ghosts are at end of linked list // if j is owned atom, store it, since j is beyond i in linked list // if j is ghost, only store if j coords are "above and to the right" of i for (j = bins[i]; j >= 0; j = bins[j]) { if (j >= nlocal) { if (x[j][2] < ztmp) continue; if (x[j][2] == ztmp) { if (x[j][1] < ytmp) continue; if (x[j][1] == ytmp && x[j][0] < xtmp) continue; } } jtype = type[j]; if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq <= cutneighsq[itype][jtype]) { if (molecular) { if (!moltemplate) which = find_special(special[i],nspecial[i],tag[j]); else if (imol >= 0) which = find_special(onemols[imol]->special[iatom], onemols[imol]->nspecial[iatom], tag[j]-tagprev); else which = 0; if (which == 0) neighptr[n++] = j; else if ((minchange = domain->minimum_image_check(delx,dely,delz))) neighptr[n++] = j; else if (which > 0) neighptr[n++] = j ^ (which << SBBITS); } else neighptr[n++] = j; if (rsq < cut_inner_sq) { if (which == 0) neighptr_inner[n_inner++] = j; else if (minchange) neighptr_inner[n_inner++] = j; else if (which > 0) neighptr_inner[n_inner++] = j ^ (which << SBBITS); } if (respamiddle && rsq < cut_middle_sq && rsq > cut_middle_inside_sq) { if (which == 0) neighptr_middle[n_middle++] = j; else if (minchange) neighptr_middle[n_middle++] = j; else if (which > 0) neighptr_middle[n_middle++] = j ^ (which << SBBITS); } } } // loop over all atoms in other bins in stencil, store every pair ibin = atom2bin[i]; for (k = 0; k < nstencil; k++) { for (j = binhead[ibin+stencil[k]]; j >= 0; j = bins[j]) { jtype = type[j]; if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq <= cutneighsq[itype][jtype]) { if (molecular) { if (!moltemplate) which = find_special(special[i],nspecial[i],tag[j]); else if (imol >= 0) which = find_special(onemols[imol]->special[iatom], onemols[imol]->nspecial[iatom], tag[j]-tagprev); else which = 0; if (which == 0) neighptr[n++] = j; else if ((minchange = domain->minimum_image_check(delx,dely,delz))) neighptr[n++] = j; else if (which > 0) neighptr[n++] = j ^ (which << SBBITS); } else neighptr[n++] = j; if (rsq < cut_inner_sq) { if (which == 0) neighptr_inner[n_inner++] = j; else if (minchange) neighptr_inner[n_inner++] = j; else if (which > 0) neighptr_inner[n_inner++] = j ^ (which << SBBITS); } if (respamiddle && rsq < cut_middle_sq && rsq > cut_middle_inside_sq) { if (which == 0) neighptr_middle[n_middle++] = j; else if (minchange) neighptr_middle[n_middle++] = j; else if (which > 0) neighptr_middle[n_middle++] = j ^ (which << SBBITS); } } } } ilist[inum] = i; firstneigh[i] = neighptr; numneigh[i] = n; ipage->vgot(n); if (ipage->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); ilist_inner[inum] = i; firstneigh_inner[i] = neighptr_inner; numneigh_inner[i] = n_inner; ipage_inner->vgot(n_inner); if (ipage_inner->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); if (respamiddle) { ilist_middle[inum] = i; firstneigh_middle[i] = neighptr_middle; numneigh_middle[i] = n_middle; ipage_middle->vgot(n_middle); if (ipage_middle->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); } inum++; } list->inum = inum; - listinner->inum = inum; - if (respamiddle) listmiddle->inum = inum; + list->inum_inner = inum; + if (respamiddle) list->inum_middle = inum; } diff --git a/src/npair_half_respa_bin_newton_tri.cpp b/src/npair_half_respa_bin_newton_tri.cpp index 4ec6685e1..add1cf6e5 100644 --- a/src/npair_half_respa_bin_newton_tri.cpp +++ b/src/npair_half_respa_bin_newton_tri.cpp @@ -1,198 +1,195 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include "npair_half_respa_bin_newton_tri.h" #include "neighbor.h" #include "neigh_list.h" #include "atom.h" #include "atom_vec.h" #include "molecule.h" #include "domain.h" #include "my_page.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ NPairHalfRespaBinNewtonTri::NPairHalfRespaBinNewtonTri(LAMMPS *lmp) : NPair(lmp) {} /* ---------------------------------------------------------------------- multiple respa lists binned neighbor list construction with Newton's 3rd law for triclinic each owned atom i checks its own bin and other bins in triclinic stencil every pair stored exactly once by some processor ------------------------------------------------------------------------- */ void NPairHalfRespaBinNewtonTri::build(NeighList *list) { int i,j,k,n,itype,jtype,ibin,n_inner,n_middle,imol,iatom,moltemplate; tagint tagprev; double xtmp,ytmp,ztmp,delx,dely,delz,rsq; int *neighptr,*neighptr_inner,*neighptr_middle; double **x = atom->x; int *type = atom->type; int *mask = atom->mask; tagint *tag = atom->tag; tagint *molecule = atom->molecule; tagint **special = atom->special; int **nspecial = atom->nspecial; int nlocal = atom->nlocal; if (includegroup) nlocal = atom->nfirst; int *molindex = atom->molindex; int *molatom = atom->molatom; Molecule **onemols = atom->avec->onemols; if (molecular == 2) moltemplate = 1; else moltemplate = 0; int *ilist = list->ilist; int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; MyPage *ipage = list->ipage; - NeighList *listinner = list->listinner; - int *ilist_inner = listinner->ilist; - int *numneigh_inner = listinner->numneigh; - int **firstneigh_inner = listinner->firstneigh; - MyPage *ipage_inner = listinner->ipage; + int *ilist_inner = list->ilist_inner; + int *numneigh_inner = list->numneigh_inner; + int **firstneigh_inner = list->firstneigh_inner; + MyPage *ipage_inner = list->ipage_inner; - NeighList *listmiddle; int *ilist_middle,*numneigh_middle,**firstneigh_middle; MyPage *ipage_middle; int respamiddle = list->respamiddle; if (respamiddle) { - listmiddle = list->listmiddle; - ilist_middle = listmiddle->ilist; - numneigh_middle = listmiddle->numneigh; - firstneigh_middle = listmiddle->firstneigh; - ipage_middle = listmiddle->ipage; + ilist_middle = list->ilist_middle; + numneigh_middle = list->numneigh_middle; + firstneigh_middle = list->firstneigh_middle; + ipage_middle = list->ipage_middle; } int inum = 0; int which = 0; int minchange = 0; ipage->reset(); ipage_inner->reset(); if (respamiddle) ipage_middle->reset(); for (i = 0; i < nlocal; i++) { n = n_inner = 0; neighptr = ipage->vget(); neighptr_inner = ipage_inner->vget(); if (respamiddle) { n_middle = 0; neighptr_middle = ipage_middle->vget(); } itype = type[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; if (moltemplate) { imol = molindex[i]; iatom = molatom[i]; tagprev = tag[i] - iatom - 1; } // loop over all atoms in bins in stencil // pairs for atoms j "below" i are excluded // below = lower z or (equal z and lower y) or (equal zy and lower x) // (equal zyx and j <= i) // latter excludes self-self interaction but allows superposed atoms ibin = atom2bin[i]; for (k = 0; k < nstencil; k++) { for (j = binhead[ibin+stencil[k]]; j >= 0; j = bins[j]) { if (x[j][2] < ztmp) continue; if (x[j][2] == ztmp) { if (x[j][1] < ytmp) continue; if (x[j][1] == ytmp) { if (x[j][0] < xtmp) continue; if (x[j][0] == xtmp && j <= i) continue; } } jtype = type[j]; if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq <= cutneighsq[itype][jtype]) { if (molecular) { if (!moltemplate) which = find_special(special[i],nspecial[i],tag[j]); else if (imol >= 0) which = find_special(onemols[imol]->special[iatom], onemols[imol]->nspecial[iatom], tag[j]-tagprev); else which = 0; if (which == 0) neighptr[n++] = j; else if ((minchange = domain->minimum_image_check(delx,dely,delz))) neighptr[n++] = j; else if (which > 0) neighptr[n++] = j ^ (which << SBBITS); } else neighptr[n++] = j; if (rsq < cut_inner_sq) { if (which == 0) neighptr_inner[n_inner++] = j; else if (minchange) neighptr_inner[n_inner++] = j; else if (which > 0) neighptr_inner[n_inner++] = j ^ (which << SBBITS); } if (respamiddle && rsq < cut_middle_sq && rsq > cut_middle_inside_sq) { if (which == 0) neighptr_middle[n_middle++] = j; else if (minchange) neighptr_middle[n_middle++] = j; else if (which > 0) neighptr_middle[n_middle++] = j ^ (which << SBBITS); } } } } ilist[inum] = i; firstneigh[i] = neighptr; numneigh[i] = n; ipage->vgot(n); if (ipage->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); ilist_inner[inum] = i; firstneigh_inner[i] = neighptr_inner; numneigh_inner[i] = n_inner; ipage_inner->vgot(n_inner); if (ipage_inner->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); if (respamiddle) { ilist_middle[inum] = i; firstneigh_middle[i] = neighptr_middle; numneigh_middle[i] = n_middle; ipage_middle->vgot(n_middle); if (ipage_middle->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); } inum++; } list->inum = inum; - listinner->inum = inum; - if (respamiddle) listmiddle->inum = inum; + list->inum_inner = inum; + if (respamiddle) list->inum_middle = inum; } diff --git a/src/npair_half_respa_nsq_newtoff.cpp b/src/npair_half_respa_nsq_newtoff.cpp index 1bb203438..c0e932f0a 100644 --- a/src/npair_half_respa_nsq_newtoff.cpp +++ b/src/npair_half_respa_nsq_newtoff.cpp @@ -1,185 +1,182 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include "npair_half_respa_nsq_newtoff.h" #include "neighbor.h" #include "neigh_list.h" #include "atom.h" #include "atom_vec.h" #include "group.h" #include "molecule.h" #include "domain.h" #include "my_page.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ NPairHalfRespaNsqNewtoff::NPairHalfRespaNsqNewtoff(LAMMPS *lmp) : NPair(lmp) {} /* ---------------------------------------------------------------------- multiple respa lists N^2 / 2 search for neighbor pairs with partial Newton's 3rd law pair added to list if atoms i and j are both owned and i < j pair added if j is ghost (also stored by proc owning j) ------------------------------------------------------------------------- */ void NPairHalfRespaNsqNewtoff::build(NeighList *list) { int i,j,n,itype,jtype,n_inner,n_middle,bitmask,imol,iatom,moltemplate; tagint tagprev; double xtmp,ytmp,ztmp,delx,dely,delz,rsq; int *neighptr,*neighptr_inner,*neighptr_middle; double **x = atom->x; int *type = atom->type; int *mask = atom->mask; tagint *tag = atom->tag; tagint *molecule = atom->molecule; tagint **special = atom->special; int **nspecial = atom->nspecial; int nlocal = atom->nlocal; int nall = nlocal + atom->nghost; if (includegroup) { nlocal = atom->nfirst; bitmask = group->bitmask[includegroup]; } int *molindex = atom->molindex; int *molatom = atom->molatom; Molecule **onemols = atom->avec->onemols; if (molecular == 2) moltemplate = 1; else moltemplate = 0; int *ilist = list->ilist; int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; MyPage *ipage = list->ipage; - NeighList *listinner = list->listinner; - int *ilist_inner = listinner->ilist; - int *numneigh_inner = listinner->numneigh; - int **firstneigh_inner = listinner->firstneigh; - MyPage *ipage_inner = listinner->ipage; + int *ilist_inner = list->ilist_inner; + int *numneigh_inner = list->numneigh_inner; + int **firstneigh_inner = list->firstneigh_inner; + MyPage *ipage_inner = list->ipage_inner; - NeighList *listmiddle; int *ilist_middle,*numneigh_middle,**firstneigh_middle; MyPage *ipage_middle; int respamiddle = list->respamiddle; if (respamiddle) { - listmiddle = list->listmiddle; - ilist_middle = listmiddle->ilist; - numneigh_middle = listmiddle->numneigh; - firstneigh_middle = listmiddle->firstneigh; - ipage_middle = listmiddle->ipage; + ilist_middle = list->ilist_middle; + numneigh_middle = list->numneigh_middle; + firstneigh_middle = list->firstneigh_middle; + ipage_middle = list->ipage_middle; } int inum = 0; int which = 0; int minchange = 0; ipage->reset(); ipage_inner->reset(); if (respamiddle) ipage_middle->reset(); for (i = 0; i < nlocal; i++) { n = n_inner = 0; neighptr = ipage->vget(); neighptr_inner = ipage_inner->vget(); if (respamiddle) { n_middle = 0; neighptr_middle = ipage_middle->vget(); } itype = type[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; if (moltemplate) { imol = molindex[i]; iatom = molatom[i]; tagprev = tag[i] - iatom - 1; } // loop over remaining atoms, owned and ghost for (j = i+1; j < nall; j++) { if (includegroup && !(mask[j] & bitmask)) continue; jtype = type[j]; if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq <= cutneighsq[itype][jtype]) { if (molecular) { if (!moltemplate) which = find_special(special[i],nspecial[i],tag[j]); else if (imol >= 0) which = find_special(onemols[imol]->special[iatom], onemols[imol]->nspecial[iatom], tag[j]-tagprev); else which = 0; if (which == 0) neighptr[n++] = j; else if ((minchange = domain->minimum_image_check(delx,dely,delz))) neighptr[n++] = j; else if (which > 0) neighptr[n++] = j ^ (which << SBBITS); } else neighptr[n++] = j; if (rsq < cut_inner_sq) { if (which == 0) neighptr_inner[n_inner++] = j; else if (minchange) neighptr_inner[n_inner++] = j; else if (which > 0) neighptr_inner[n_inner++] = j ^ (which << SBBITS); } if (respamiddle && rsq < cut_middle_sq && rsq > cut_middle_inside_sq) { if (which == 0) neighptr_middle[n_middle++] = j; else if (minchange) neighptr_middle[n_middle++] = j; else if (which > 0) neighptr_middle[n_middle++] = j ^ (which << SBBITS); } } } ilist[inum] = i; firstneigh[i] = neighptr; numneigh[i] = n; ipage->vgot(n); if (ipage->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); ilist_inner[inum] = i; firstneigh_inner[i] = neighptr_inner; numneigh_inner[i] = n_inner; ipage_inner->vgot(n_inner); if (ipage_inner->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); if (respamiddle) { ilist_middle[inum] = i; firstneigh_middle[i] = neighptr_middle; numneigh_middle[i] = n_middle; ipage_middle->vgot(n_middle); if (ipage_middle->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); } inum++; } list->inum = inum; - listinner->inum = inum; - if (respamiddle) listmiddle->inum = inum; + list->inum_inner = inum; + if (respamiddle) list->inum_middle = inum; } diff --git a/src/npair_half_respa_nsq_newton.cpp b/src/npair_half_respa_nsq_newton.cpp index 9aacc702c..f7d161896 100644 --- a/src/npair_half_respa_nsq_newton.cpp +++ b/src/npair_half_respa_nsq_newton.cpp @@ -1,205 +1,202 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include "npair_half_respa_nsq_newton.h" #include "neighbor.h" #include "neigh_list.h" #include "atom.h" #include "atom_vec.h" #include "group.h" #include "molecule.h" #include "domain.h" #include "my_page.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ NPairHalfRespaNsqNewton::NPairHalfRespaNsqNewton(LAMMPS *lmp) : NPair(lmp) {} /* ---------------------------------------------------------------------- multiple respa lists N^2 / 2 search for neighbor pairs with full Newton's 3rd law pair added to list if atoms i and j are both owned and i < j if j is ghost only me or other proc adds pair decision based on itag,jtag tests ------------------------------------------------------------------------- */ void NPairHalfRespaNsqNewton::build(NeighList *list) { int i,j,n,itype,jtype,itag,jtag,n_inner,n_middle,bitmask; int imol,iatom,moltemplate; tagint tagprev; double xtmp,ytmp,ztmp,delx,dely,delz,rsq; int *neighptr,*neighptr_inner,*neighptr_middle; double **x = atom->x; int *type = atom->type; int *mask = atom->mask; tagint *tag = atom->tag; tagint *molecule = atom->molecule; tagint **special = atom->special; int **nspecial = atom->nspecial; int nlocal = atom->nlocal; int nall = nlocal + atom->nghost; if (includegroup) { nlocal = atom->nfirst; bitmask = group->bitmask[includegroup]; } int *molindex = atom->molindex; int *molatom = atom->molatom; Molecule **onemols = atom->avec->onemols; if (molecular == 2) moltemplate = 1; else moltemplate = 0; int *ilist = list->ilist; int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; MyPage *ipage = list->ipage; - NeighList *listinner = list->listinner; - int *ilist_inner = listinner->ilist; - int *numneigh_inner = listinner->numneigh; - int **firstneigh_inner = listinner->firstneigh; - MyPage *ipage_inner = listinner->ipage; + int *ilist_inner = list->ilist_inner; + int *numneigh_inner = list->numneigh_inner; + int **firstneigh_inner = list->firstneigh_inner; + MyPage *ipage_inner = list->ipage_inner; - NeighList *listmiddle; int *ilist_middle,*numneigh_middle,**firstneigh_middle; MyPage *ipage_middle; int respamiddle = list->respamiddle; if (respamiddle) { - listmiddle = list->listmiddle; - ilist_middle = listmiddle->ilist; - numneigh_middle = listmiddle->numneigh; - firstneigh_middle = listmiddle->firstneigh; - ipage_middle = listmiddle->ipage; + ilist_middle = list->ilist_middle; + numneigh_middle = list->numneigh_middle; + firstneigh_middle = list->firstneigh_middle; + ipage_middle = list->ipage_middle; } int inum = 0; int which = 0; int minchange = 0; ipage->reset(); ipage_inner->reset(); if (respamiddle) ipage_middle->reset(); for (i = 0; i < nlocal; i++) { n = n_inner = 0; neighptr = ipage->vget(); neighptr_inner = ipage_inner->vget(); if (respamiddle) { n_middle = 0; neighptr_middle = ipage_middle->vget(); } itag = tag[i]; itype = type[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; if (moltemplate) { imol = molindex[i]; iatom = molatom[i]; tagprev = tag[i] - iatom - 1; } // loop over remaining atoms, owned and ghost for (j = i+1; j < nall; j++) { if (includegroup && !(mask[j] & bitmask)) continue; if (j >= nlocal) { jtag = tag[j]; if (itag > jtag) { if ((itag+jtag) % 2 == 0) continue; } else if (itag < jtag) { if ((itag+jtag) % 2 == 1) continue; } else { if (x[j][2] < ztmp) continue; if (x[j][2] == ztmp) { if (x[j][1] < ytmp) continue; if (x[j][1] == ytmp && x[j][0] < xtmp) continue; } } } jtype = type[j]; if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq <= cutneighsq[itype][jtype]) { if (molecular) { if (!moltemplate) which = find_special(special[i],nspecial[i],tag[j]); else if (imol >= 0) which = find_special(onemols[imol]->special[iatom], onemols[imol]->nspecial[iatom], tag[j]-tagprev); else which = 0; if (which == 0) neighptr[n++] = j; else if ((minchange = domain->minimum_image_check(delx,dely,delz))) neighptr[n++] = j; else if (which > 0) neighptr[n++] = j ^ (which << SBBITS); } else neighptr[n++] = j; if (rsq < cut_inner_sq) { if (which == 0) neighptr_inner[n_inner++] = j; else if (minchange) neighptr_inner[n_inner++] = j; else if (which > 0) neighptr_inner[n_inner++] = j ^ (which << SBBITS); } if (respamiddle && rsq < cut_middle_sq && rsq > cut_middle_inside_sq) { if (which == 0) neighptr_middle[n_middle++] = j; else if (minchange) neighptr_middle[n_middle++] = j; else if (which > 0) neighptr_middle[n_middle++] = j ^ (which << SBBITS); } } } ilist[inum] = i; firstneigh[i] = neighptr; numneigh[i] = n; ipage->vgot(n); if (ipage->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); ilist_inner[inum] = i; firstneigh_inner[i] = neighptr_inner; numneigh_inner[i] = n_inner; ipage_inner->vgot(n_inner); if (ipage_inner->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); if (respamiddle) { ilist_middle[inum] = i; firstneigh_middle[i] = neighptr_middle; numneigh_middle[i] = n_middle; ipage_middle->vgot(n_middle); if (ipage_middle->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); } inum++; } list->inum = inum; - listinner->inum = inum; - if (respamiddle) listmiddle->inum = inum; + list->inum_inner = inum; + if (respamiddle) list->inum_middle = inum; } diff --git a/src/npair_half_size_bin_newtoff.cpp b/src/npair_half_size_bin_newtoff.cpp index 571b2484e..cf608b5d5 100644 --- a/src/npair_half_size_bin_newtoff.cpp +++ b/src/npair_half_size_bin_newtoff.cpp @@ -1,171 +1,109 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include #include "npair_half_size_bin_newtoff.h" #include "neighbor.h" #include "neigh_list.h" #include "atom.h" #include "atom_vec.h" -#include "molecule.h" -#include "domain.h" -#include "fix_shear_history.h" #include "my_page.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ NPairHalfSizeBinNewtoff::NPairHalfSizeBinNewtoff(LAMMPS *lmp) : NPair(lmp) {} /* ---------------------------------------------------------------------- size particles binned neighbor list construction with partial Newton's 3rd law - shear history must be accounted for when a neighbor pair is added each owned atom i checks own bin and surrounding bins in non-Newton stencil pair stored once if i,j are both owned and i < j pair stored by me if j is ghost (also stored by proc owning j) ------------------------------------------------------------------------- */ void NPairHalfSizeBinNewtoff::build(NeighList *list) { - int i,j,k,m,n,nn,ibin,dnum,dnumbytes; + int i,j,k,m,n,nn,ibin; double xtmp,ytmp,ztmp,delx,dely,delz,rsq; double radi,radsum,cutsq; - int *neighptr,*touchptr; - double *shearptr; - - int *npartner; - tagint **partner; - double **shearpartner; - int **firsttouch; - double **firstshear; - MyPage *ipage_touch; - MyPage *dpage_shear; - NeighList *listhistory; + int *neighptr; double **x = atom->x; double *radius = atom->radius; tagint *tag = atom->tag; int *type = atom->type; int *mask = atom->mask; tagint *molecule = atom->molecule; int nlocal = atom->nlocal; if (includegroup) nlocal = atom->nfirst; + int history = list->history; int *ilist = list->ilist; int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; MyPage *ipage = list->ipage; - FixShearHistory *fix_history = (FixShearHistory *) list->fix_history; - if (fix_history) { - fix_history->nlocal_neigh = nlocal; - fix_history->nall_neigh = nlocal + atom->nghost; - npartner = fix_history->npartner; - partner = fix_history->partner; - shearpartner = fix_history->shearpartner; - listhistory = list->listhistory; - firsttouch = listhistory->firstneigh; - firstshear = listhistory->firstdouble; - ipage_touch = listhistory->ipage; - dpage_shear = listhistory->dpage; - dnum = listhistory->dnum; - dnumbytes = dnum * sizeof(double); - } + int mask_history = 3 << SBBITS; int inum = 0; ipage->reset(); - if (fix_history) { - ipage_touch->reset(); - dpage_shear->reset(); - } for (i = 0; i < nlocal; i++) { n = 0; neighptr = ipage->vget(); - if (fix_history) { - nn = 0; - touchptr = ipage_touch->vget(); - shearptr = dpage_shear->vget(); - } xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; radi = radius[i]; ibin = atom2bin[i]; // loop over all atoms in surrounding bins in stencil including self // only store pair if i < j // stores own/own pairs only once // stores own/ghost pairs on both procs for (k = 0; k < nstencil; k++) { for (j = binhead[ibin+stencil[k]]; j >= 0; j = bins[j]) { if (j <= i) continue; if (exclude && exclusion(i,j,type[i],type[j],mask,molecule)) continue; - + delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; radsum = radi + radius[j]; cutsq = (radsum+skin) * (radsum+skin); - + if (rsq <= cutsq) { - neighptr[n] = j; - - if (fix_history) { - if (rsq < radsum*radsum) { - for (m = 0; m < npartner[i]; m++) - if (partner[i][m] == tag[j]) break; - if (m < npartner[i]) { - touchptr[n] = 1; - memcpy(&shearptr[nn],&shearpartner[i][dnum*m],dnumbytes); - nn += dnum; - } else { - touchptr[n] = 0; - memcpy(&shearptr[nn],zeroes,dnumbytes); - nn += dnum; - } - } else { - touchptr[n] = 0; - memcpy(&shearptr[nn],zeroes,dnumbytes); - nn += dnum; - } - } - - n++; + if (history && rsq < radsum*radsum) + neighptr[n++] = j ^ mask_history; + else + neighptr[n++] = j; } } } ilist[inum++] = i; firstneigh[i] = neighptr; numneigh[i] = n; ipage->vgot(n); if (ipage->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); - - if (fix_history) { - firsttouch[i] = touchptr; - firstshear[i] = shearptr; - ipage_touch->vgot(n); - dpage_shear->vgot(nn); - } } list->inum = inum; } diff --git a/src/npair_half_size_bin_newton.cpp b/src/npair_half_size_bin_newton.cpp index 4f4ecccb1..662bf91d6 100644 --- a/src/npair_half_size_bin_newton.cpp +++ b/src/npair_half_size_bin_newton.cpp @@ -1,215 +1,134 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include #include "npair_half_size_bin_newton.h" #include "neighbor.h" #include "neigh_list.h" #include "atom.h" #include "atom_vec.h" -#include "molecule.h" -#include "domain.h" -#include "fix_shear_history.h" #include "my_page.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ NPairHalfSizeBinNewton::NPairHalfSizeBinNewton(LAMMPS *lmp) : NPair(lmp) {} /* ---------------------------------------------------------------------- size particles binned neighbor list construction with full Newton's 3rd law - shear history must be accounted for when a neighbor pair is added each owned atom i checks its own bin and other bins in Newton stencil every pair stored exactly once by some processor ------------------------------------------------------------------------- */ void NPairHalfSizeBinNewton::build(NeighList *list) { - int i,j,k,m,n,nn,ibin,dnum,dnumbytes; + int i,j,k,m,n,nn,ibin; double xtmp,ytmp,ztmp,delx,dely,delz,rsq; double radi,radsum,cutsq; - int *neighptr,*touchptr; - double *shearptr; - - int *npartner; - tagint **partner; - double **shearpartner; - int **firsttouch; - double **firstshear; - MyPage *ipage_touch; - MyPage *dpage_shear; - NeighList *listhistory; + int *neighptr; double **x = atom->x; double *radius = atom->radius; tagint *tag = atom->tag; int *type = atom->type; int *mask = atom->mask; tagint *molecule = atom->molecule; int nlocal = atom->nlocal; if (includegroup) nlocal = atom->nfirst; + int history = list->history; int *ilist = list->ilist; int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; MyPage *ipage = list->ipage; - FixShearHistory *fix_history = (FixShearHistory *) list->fix_history; - if (fix_history) { - fix_history->nlocal_neigh = nlocal; - fix_history->nall_neigh = nlocal + atom->nghost; - npartner = fix_history->npartner; - partner = fix_history->partner; - shearpartner = fix_history->shearpartner; - listhistory = list->listhistory; - firsttouch = listhistory->firstneigh; - firstshear = listhistory->firstdouble; - ipage_touch = listhistory->ipage; - dpage_shear = listhistory->dpage; - dnum = listhistory->dnum; - dnumbytes = dnum * sizeof(double); - } + int mask_history = 3 << SBBITS; int inum = 0; ipage->reset(); - if (fix_history) { - ipage_touch->reset(); - dpage_shear->reset(); - } for (i = 0; i < nlocal; i++) { n = 0; neighptr = ipage->vget(); - if (fix_history) { - nn = 0; - touchptr = ipage_touch->vget(); - shearptr = dpage_shear->vget(); - } xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; radi = radius[i]; // loop over rest of atoms in i's bin, ghosts are at end of linked list // if j is owned atom, store it, since j is beyond i in linked list // if j is ghost, only store if j coords are "above and to the right" of i for (j = bins[i]; j >= 0; j = bins[j]) { if (j >= nlocal) { if (x[j][2] < ztmp) continue; if (x[j][2] == ztmp) { if (x[j][1] < ytmp) continue; if (x[j][1] == ytmp && x[j][0] < xtmp) continue; } } if (exclude && exclusion(i,j,type[i],type[j],mask,molecule)) continue; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; radsum = radi + radius[j]; cutsq = (radsum+skin) * (radsum+skin); if (rsq <= cutsq) { - neighptr[n] = j; - - if (fix_history) { - if (rsq < radsum*radsum) { - for (m = 0; m < npartner[i]; m++) - if (partner[i][m] == tag[j]) break; - if (m < npartner[i]) { - touchptr[n] = 1; - memcpy(&shearptr[nn],&shearpartner[i][dnum*m],dnumbytes); - nn += dnum; - } else { - touchptr[n] = 0; - memcpy(&shearptr[nn],zeroes,dnumbytes); - nn += dnum; - } - } else { - touchptr[n] = 0; - memcpy(&shearptr[nn],zeroes,dnumbytes); - nn += dnum; - } - } - - n++; + if (history && rsq < radsum*radsum) + neighptr[n++] = j ^ mask_history; + else + neighptr[n++] = j; } } // loop over all atoms in other bins in stencil, store every pair ibin = atom2bin[i]; for (k = 0; k < nstencil; k++) { for (j = binhead[ibin+stencil[k]]; j >= 0; j = bins[j]) { if (exclude && exclusion(i,j,type[i],type[j],mask,molecule)) continue; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; radsum = radi + radius[j]; cutsq = (radsum+skin) * (radsum+skin); if (rsq <= cutsq) { - neighptr[n] = j; - - if (fix_history) { - if (rsq < radsum*radsum) { - for (m = 0; m < npartner[i]; m++) - if (partner[i][m] == tag[j]) break; - if (m < npartner[i]) { - touchptr[n] = 1; - memcpy(&shearptr[nn],&shearpartner[i][dnum*m],dnumbytes); - nn += dnum; - } else { - touchptr[n] = 0; - memcpy(&shearptr[nn],zeroes,dnumbytes); - nn += dnum; - } - } else { - touchptr[n] = 0; - memcpy(&shearptr[nn],zeroes,dnumbytes); - nn += dnum; - } - } - - n++; + if (history && rsq < radsum*radsum) + neighptr[n++] = j ^ mask_history; + else + neighptr[n++] = j; } } } ilist[inum++] = i; firstneigh[i] = neighptr; numneigh[i] = n; ipage->vgot(n); if (ipage->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); - - if (fix_history) { - firsttouch[i] = touchptr; - firstshear[i] = shearptr; - ipage_touch->vgot(n); - dpage_shear->vgot(nn); - } } list->inum = inum; } diff --git a/src/npair_half_size_bin_newton_tri.cpp b/src/npair_half_size_bin_newton_tri.cpp index 559eb09a7..e70c07228 100644 --- a/src/npair_half_size_bin_newton_tri.cpp +++ b/src/npair_half_size_bin_newton_tri.cpp @@ -1,180 +1,118 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include #include "npair_half_size_bin_newton_tri.h" #include "neighbor.h" #include "neigh_list.h" #include "atom.h" #include "atom_vec.h" -#include "molecule.h" -#include "domain.h" -#include "fix_shear_history.h" #include "my_page.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ NPairHalfSizeBinNewtonTri::NPairHalfSizeBinNewtonTri(LAMMPS *lmp) : NPair(lmp) {} /* ---------------------------------------------------------------------- size particles binned neighbor list construction with Newton's 3rd law for triclinic - shear history must be accounted for when a neighbor pair is added each owned atom i checks its own bin and other bins in triclinic stencil every pair stored exactly once by some processor ------------------------------------------------------------------------- */ void NPairHalfSizeBinNewtonTri::build(NeighList *list) { - int i,j,k,m,n,nn,ibin,dnum,dnumbytes; + int i,j,k,m,n,nn,ibin; double xtmp,ytmp,ztmp,delx,dely,delz,rsq; double radi,radsum,cutsq; - int *neighptr,*touchptr; - double *shearptr; - - int *npartner; - tagint **partner; - double **shearpartner; - int **firsttouch; - double **firstshear; - MyPage *ipage_touch; - MyPage *dpage_shear; - NeighList *listhistory; + int *neighptr; double **x = atom->x; double *radius = atom->radius; tagint *tag = atom->tag; int *type = atom->type; int *mask = atom->mask; tagint *molecule = atom->molecule; int nlocal = atom->nlocal; if (includegroup) nlocal = atom->nfirst; + int history = list->history; int *ilist = list->ilist; int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; MyPage *ipage = list->ipage; - FixShearHistory *fix_history = (FixShearHistory *) list->fix_history; - if (fix_history) { - fix_history->nlocal_neigh = nlocal; - fix_history->nall_neigh = nlocal + atom->nghost; - npartner = fix_history->npartner; - partner = fix_history->partner; - shearpartner = fix_history->shearpartner; - listhistory = list->listhistory; - firsttouch = listhistory->firstneigh; - firstshear = listhistory->firstdouble; - ipage_touch = listhistory->ipage; - dpage_shear = listhistory->dpage; - dnum = listhistory->dnum; - dnumbytes = dnum * sizeof(double); - } + int mask_history = 3 << SBBITS; int inum = 0; ipage->reset(); - if (fix_history) { - ipage_touch->reset(); - dpage_shear->reset(); - } for (i = 0; i < nlocal; i++) { n = 0; neighptr = ipage->vget(); - if (fix_history) { - nn = 0; - touchptr = ipage_touch->vget(); - shearptr = dpage_shear->vget(); - } xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; radi = radius[i]; // loop over all atoms in bins in stencil // pairs for atoms j "below" i are excluded // below = lower z or (equal z and lower y) or (equal zy and lower x) // (equal zyx and j <= i) // latter excludes self-self interaction but allows superposed atoms ibin = atom2bin[i]; for (k = 0; k < nstencil; k++) { for (j = binhead[ibin+stencil[k]]; j >= 0; j = bins[j]) { if (x[j][2] < ztmp) continue; if (x[j][2] == ztmp) { if (x[j][1] < ytmp) continue; if (x[j][1] == ytmp) { if (x[j][0] < xtmp) continue; if (x[j][0] == xtmp && j <= i) continue; } } if (exclude && exclusion(i,j,type[i],type[j],mask,molecule)) continue; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; radsum = radi + radius[j]; cutsq = (radsum+skin) * (radsum+skin); if (rsq <= cutsq) { - neighptr[n++] = j; - - if (fix_history) { - if (rsq < radsum*radsum) { - for (m = 0; m < npartner[i]; m++) - if (partner[i][m] == tag[j]) break; - if (m < npartner[i]) { - touchptr[n] = 1; - memcpy(&shearptr[nn],&shearpartner[i][dnum*m],dnumbytes); - nn += dnum; - } else { - touchptr[n] = 0; - memcpy(&shearptr[nn],zeroes,dnumbytes); - nn += dnum; - } - } else { - touchptr[n] = 0; - memcpy(&shearptr[nn],zeroes,dnumbytes); - nn += dnum; - } - } - - n++; + if (history && rsq < radsum*radsum) + neighptr[n++] = j ^ mask_history; + else + neighptr[n++] = j; } } } ilist[inum++] = i; firstneigh[i] = neighptr; numneigh[i] = n; ipage->vgot(n); if (ipage->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); - - if (fix_history) { - firsttouch[i] = touchptr; - firstshear[i] = shearptr; - ipage_touch->vgot(n); - dpage_shear->vgot(nn); - } } list->inum = inum; } diff --git a/src/npair_half_size_nsq_newtoff.cpp b/src/npair_half_size_nsq_newtoff.cpp index 56630a9dc..e6f5cba65 100644 --- a/src/npair_half_size_nsq_newtoff.cpp +++ b/src/npair_half_size_nsq_newtoff.cpp @@ -1,169 +1,107 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include #include "npair_half_size_nsq_newtoff.h" #include "neighbor.h" #include "neigh_list.h" #include "atom.h" #include "atom_vec.h" #include "group.h" -#include "molecule.h" -#include "domain.h" -#include "fix_shear_history.h" #include "my_page.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ NPairHalfSizeNsqNewtoff::NPairHalfSizeNsqNewtoff(LAMMPS *lmp) : NPair(lmp) {} /* ---------------------------------------------------------------------- size particles N^2 / 2 search for neighbor pairs with partial Newton's 3rd law - shear history must be accounted for when a neighbor pair is added pair added to list if atoms i and j are both owned and i < j pair added if j is ghost (also stored by proc owning j) ------------------------------------------------------------------------- */ void NPairHalfSizeNsqNewtoff::build(NeighList *list) { - int i,j,m,n,nn,bitmask,dnum,dnumbytes; + int i,j,m,n,nn,bitmask; double xtmp,ytmp,ztmp,delx,dely,delz,rsq; double radi,radsum,cutsq; - int *neighptr,*touchptr; - double *shearptr; - - int *npartner; - tagint **partner; - double **shearpartner; - int **firsttouch; - double **firstshear; - MyPage *ipage_touch; - MyPage *dpage_shear; - NeighList *listhistory; + int *neighptr; double **x = atom->x; double *radius = atom->radius; tagint *tag = atom->tag; int *type = atom->type; int *mask = atom->mask; tagint *molecule = atom->molecule; int nlocal = atom->nlocal; int nall = nlocal + atom->nghost; if (includegroup) { nlocal = atom->nfirst; bitmask = group->bitmask[includegroup]; } + int history = list->history; int *ilist = list->ilist; int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; MyPage *ipage = list->ipage; - FixShearHistory *fix_history = (FixShearHistory *) list->fix_history; - if (fix_history) { - fix_history->nlocal_neigh = nlocal; - fix_history->nall_neigh = nall; - npartner = fix_history->npartner; - partner = fix_history->partner; - shearpartner = fix_history->shearpartner; - listhistory = list->listhistory; - firsttouch = listhistory->firstneigh; - firstshear = listhistory->firstdouble; - ipage_touch = listhistory->ipage; - dpage_shear = listhistory->dpage; - dnum = listhistory->dnum; - dnumbytes = dnum * sizeof(double); - } + int mask_history = 3 << SBBITS; int inum = 0; ipage->reset(); - if (fix_history) { - ipage_touch->reset(); - dpage_shear->reset(); - } for (i = 0; i < nlocal; i++) { n = 0; neighptr = ipage->vget(); - if (fix_history) { - nn = 0; - touchptr = ipage_touch->vget(); - shearptr = dpage_shear->vget(); - } xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; radi = radius[i]; // loop over remaining atoms, owned and ghost for (j = i+1; j < nall; j++) { if (includegroup && !(mask[j] & bitmask)) continue; if (exclude && exclusion(i,j,type[i],type[j],mask,molecule)) continue; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; radsum = radi + radius[j]; cutsq = (radsum+skin) * (radsum+skin); if (rsq <= cutsq) { - neighptr[n] = j; - - if (fix_history) { - if (rsq < radsum*radsum) { - for (m = 0; m < npartner[i]; m++) - if (partner[i][m] == tag[j]) break; - if (m < npartner[i]) { - touchptr[n] = 1; - memcpy(&shearptr[nn],&shearpartner[i][dnum*m],dnumbytes); - nn += dnum; - } else { - touchptr[n] = 0; - memcpy(&shearptr[nn],zeroes,dnumbytes); - nn += dnum; - } - } else { - touchptr[n] = 0; - memcpy(&shearptr[nn],zeroes,dnumbytes); - nn += dnum; - } - } - - n++; + if (history && rsq < radsum*radsum) + neighptr[n++] = j ^ mask_history; + else + neighptr[n++] = j; } } ilist[inum++] = i; firstneigh[i] = neighptr; numneigh[i] = n; ipage->vgot(n); if (ipage->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); - - if (fix_history) { - firsttouch[i] = touchptr; - firstshear[i] = shearptr; - ipage_touch->vgot(n); - dpage_shear->vgot(nn); - } } list->inum = inum; } diff --git a/src/npair_half_size_nsq_newton.cpp b/src/npair_half_size_nsq_newton.cpp index 177685b9f..78811170c 100644 --- a/src/npair_half_size_nsq_newton.cpp +++ b/src/npair_half_size_nsq_newton.cpp @@ -1,187 +1,125 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include #include "npair_half_size_nsq_newton.h" #include "neighbor.h" #include "neigh_list.h" #include "atom.h" #include "atom_vec.h" #include "group.h" -#include "molecule.h" -#include "domain.h" -#include "fix_shear_history.h" #include "my_page.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ NPairHalfSizeNsqNewton::NPairHalfSizeNsqNewton(LAMMPS *lmp) : NPair(lmp) {} /* ---------------------------------------------------------------------- size particles N^2 / 2 search for neighbor pairs with full Newton's 3rd law - shear history must be accounted for when a neighbor pair is added pair added to list if atoms i and j are both owned and i < j if j is ghost only me or other proc adds pair decision based on itag,jtag tests ------------------------------------------------------------------------- */ void NPairHalfSizeNsqNewton::build(NeighList *list) { - int i,j,m,n,nn,itag,jtag,bitmask,dnum,dnumbytes; + int i,j,m,n,nn,itag,jtag,bitmask; double xtmp,ytmp,ztmp,delx,dely,delz,rsq; double radi,radsum,cutsq; - int *neighptr,*touchptr; - double *shearptr; - - int *npartner; - tagint **partner; - double **shearpartner; - int **firsttouch; - double **firstshear; - MyPage *ipage_touch; - MyPage *dpage_shear; - NeighList *listhistory; + int *neighptr; double **x = atom->x; double *radius = atom->radius; tagint *tag = atom->tag; int *type = atom->type; int *mask = atom->mask; tagint *molecule = atom->molecule; int nlocal = atom->nlocal; int nall = nlocal + atom->nghost; if (includegroup) { nlocal = atom->nfirst; bitmask = group->bitmask[includegroup]; } + int history = list->history; int *ilist = list->ilist; int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; MyPage *ipage = list->ipage; - FixShearHistory *fix_history = (FixShearHistory *) list->fix_history; - if (fix_history) { - fix_history->nlocal_neigh = nlocal; - fix_history->nall_neigh = nall; - npartner = fix_history->npartner; - partner = fix_history->partner; - shearpartner = fix_history->shearpartner; - listhistory = list->listhistory; - firsttouch = listhistory->firstneigh; - firstshear = listhistory->firstdouble; - ipage_touch = listhistory->ipage; - dpage_shear = listhistory->dpage; - dnum = listhistory->dnum; - dnumbytes = dnum * sizeof(double); - } + int mask_history = 3 << SBBITS; int inum = 0; ipage->reset(); - if (fix_history) { - ipage_touch->reset(); - dpage_shear->reset(); - } for (i = 0; i < nlocal; i++) { n = 0; neighptr = ipage->vget(); - if (fix_history) { - nn = 0; - touchptr = ipage_touch->vget(); - shearptr = dpage_shear->vget(); - } itag = tag[i]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; radi = radius[i]; // loop over remaining atoms, owned and ghost for (j = i+1; j < nall; j++) { if (includegroup && !(mask[j] & bitmask)) continue; if (j >= nlocal) { jtag = tag[j]; if (itag > jtag) { if ((itag+jtag) % 2 == 0) continue; } else if (itag < jtag) { if ((itag+jtag) % 2 == 1) continue; } else { if (x[j][2] < ztmp) continue; if (x[j][2] == ztmp) { if (x[j][1] < ytmp) continue; if (x[j][1] == ytmp && x[j][0] < xtmp) continue; } } } if (exclude && exclusion(i,j,type[i],type[j],mask,molecule)) continue; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; radsum = radi + radius[j]; cutsq = (radsum+skin) * (radsum+skin); if (rsq <= cutsq) { - neighptr[n] = j; - - if (fix_history) { - if (rsq < radsum*radsum) { - for (m = 0; m < npartner[i]; m++) - if (partner[i][m] == tag[j]) break; - if (m < npartner[i]) { - touchptr[n] = 1; - memcpy(&shearptr[nn],&shearpartner[i][dnum*m],dnumbytes); - nn += dnum; - } else { - touchptr[n] = 0; - memcpy(&shearptr[nn],zeroes,dnumbytes); - nn += dnum; - } - } else { - touchptr[n] = 0; - memcpy(&shearptr[nn],zeroes,dnumbytes); - nn += dnum; - } - } - - n++; + if (history && rsq < radsum*radsum) + neighptr[n++] = j ^ mask_history; + else + neighptr[n++] = j; } } ilist[inum++] = i; firstneigh[i] = neighptr; numneigh[i] = n; ipage->vgot(n); if (ipage->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); - - if (fix_history) { - firsttouch[i] = touchptr; - firstshear[i] = shearptr; - ipage_touch->vgot(n); - dpage_shear->vgot(nn); - } } list->inum = inum; } diff --git a/src/npair_skip_respa.cpp b/src/npair_skip_respa.cpp index 31420b32d..1d4eda535 100644 --- a/src/npair_skip_respa.cpp +++ b/src/npair_skip_respa.cpp @@ -1,169 +1,165 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include "npair_skip_respa.h" #include "neighbor.h" #include "neigh_list.h" #include "atom.h" #include "atom_vec.h" #include "molecule.h" #include "domain.h" #include "my_page.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ NPairSkipRespa::NPairSkipRespa(LAMMPS *lmp) : NPair(lmp) {} /* ---------------------------------------------------------------------- build skip list for subset of types from parent list iskip and ijskip flag which atom types and type pairs to skip this is for respa lists, copy the inner/middle values from parent ------------------------------------------------------------------------- */ void NPairSkipRespa::build(NeighList *list) { int i,j,ii,jj,n,itype,jnum,joriginal,n_inner,n_middle; int *neighptr,*jlist,*neighptr_inner,*neighptr_middle; int *type = atom->type; int *ilist = list->ilist; int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; MyPage *ipage = list->ipage; int *ilist_skip = list->listskip->ilist; int *numneigh_skip = list->listskip->numneigh; int **firstneigh_skip = list->listskip->firstneigh; int inum_skip = list->listskip->inum; int *iskip = list->iskip; int **ijskip = list->ijskip; - NeighList *listinner = list->listinner; - int *ilist_inner = listinner->ilist; - int *numneigh_inner = listinner->numneigh; - int **firstneigh_inner = listinner->firstneigh; - MyPage *ipage_inner = listinner->ipage; + int *ilist_inner = list->ilist_inner; + int *numneigh_inner = list->numneigh_inner; + int **firstneigh_inner = list->firstneigh_inner; + MyPage *ipage_inner = list->ipage_inner; + int *numneigh_inner_skip = list->listskip->numneigh_inner; + int **firstneigh_inner_skip = list->listskip->firstneigh_inner; - int *numneigh_inner_skip = list->listskip->listinner->numneigh; - int **firstneigh_inner_skip = list->listskip->listinner->firstneigh; - - NeighList *listmiddle; int *ilist_middle,*numneigh_middle,**firstneigh_middle; MyPage *ipage_middle; int *numneigh_middle_skip,**firstneigh_middle_skip; int respamiddle = list->respamiddle; if (respamiddle) { - listmiddle = list->listmiddle; - ilist_middle = listmiddle->ilist; - numneigh_middle = listmiddle->numneigh; - firstneigh_middle = listmiddle->firstneigh; - ipage_middle = listmiddle->ipage; - numneigh_middle_skip = list->listskip->listmiddle->numneigh; - firstneigh_middle_skip = list->listskip->listmiddle->firstneigh; + ilist_middle = list->ilist_middle; + numneigh_middle = list->numneigh_middle; + firstneigh_middle = list->firstneigh_middle; + ipage_middle = list->ipage_middle; + numneigh_middle_skip = list->listskip->numneigh_middle; + firstneigh_middle_skip = list->listskip->firstneigh_middle; } int inum = 0; ipage->reset(); ipage_inner->reset(); if (respamiddle) ipage_middle->reset(); // loop over atoms in other list // skip I atom entirely if iskip is set for type[I] // skip I,J pair if ijskip is set for type[I],type[J] for (ii = 0; ii < inum_skip; ii++) { i = ilist_skip[ii]; itype = type[i]; if (iskip[itype]) continue; n = n_inner = 0; neighptr = ipage->vget(); neighptr_inner = ipage_inner->vget(); if (respamiddle) { n_middle = 0; neighptr_middle = ipage_middle->vget(); } // loop over parent outer rRESPA list jlist = firstneigh_skip[i]; jnum = numneigh_skip[i]; for (jj = 0; jj < jnum; jj++) { joriginal = jlist[jj]; j = joriginal & NEIGHMASK; if (ijskip[itype][type[j]]) continue; neighptr[n++] = joriginal; } // loop over parent inner rRESPA list jlist = firstneigh_inner_skip[i]; jnum = numneigh_inner_skip[i]; for (jj = 0; jj < jnum; jj++) { joriginal = jlist[jj]; j = joriginal & NEIGHMASK; if (ijskip[itype][type[j]]) continue; neighptr_inner[n_inner++] = joriginal; } // loop over parent middle rRESPA list if (respamiddle) { jlist = firstneigh_middle_skip[i]; jnum = numneigh_middle_skip[i]; for (jj = 0; jj < jnum; jj++) { joriginal = jlist[jj]; j = joriginal & NEIGHMASK; if (ijskip[itype][type[j]]) continue; neighptr_middle[n_middle++] = joriginal; } } ilist[inum] = i; firstneigh[i] = neighptr; numneigh[i] = n; ipage->vgot(n); if (ipage->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); ilist_inner[inum] = i; firstneigh_inner[i] = neighptr_inner; numneigh_inner[i] = n_inner; ipage_inner->vgot(n); if (ipage_inner->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); if (respamiddle) { ilist_middle[inum] = i; firstneigh_middle[i] = neighptr_middle; numneigh_middle[i] = n_middle; ipage_middle->vgot(n); if (ipage_middle->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); } inum++; } list->inum = inum; - listinner->inum = inum; - if (respamiddle) listmiddle->inum = inum; + list->inum_inner = inum; + if (respamiddle) list->inum_middle = inum; } diff --git a/src/npair_skip_size.cpp b/src/npair_skip_size.cpp index e8d19dedc..075387f5b 100644 --- a/src/npair_skip_size.cpp +++ b/src/npair_skip_size.cpp @@ -1,161 +1,93 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include #include "npair_skip_size.h" #include "neighbor.h" #include "neigh_list.h" #include "atom.h" #include "atom_vec.h" -#include "molecule.h" -#include "domain.h" -#include "fix_shear_history.h" #include "my_page.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ NPairSkipSize::NPairSkipSize(LAMMPS *lmp) : NPair(lmp) {} /* ---------------------------------------------------------------------- build skip list for subset of types from parent list iskip and ijskip flag which atom types and type pairs to skip - if list requests it, preserve shear history via fix shear/history ------------------------------------------------------------------------- */ void NPairSkipSize::build(NeighList *list) { int i,j,ii,jj,m,n,nn,itype,jnum,joriginal,dnum,dnumbytes; tagint jtag; - int *neighptr,*jlist,*touchptr; - double *shearptr; - - int *npartner; - tagint **partner; - double **shearpartner; - int **firsttouch; - double **firstshear; - MyPage *ipage_touch; - MyPage *dpage_shear; - NeighList *listhistory; + int *neighptr,*jlist; tagint *tag = atom->tag; int *type = atom->type; int nlocal = atom->nlocal; int *ilist = list->ilist; int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; MyPage *ipage = list->ipage; int *ilist_skip = list->listskip->ilist; int *numneigh_skip = list->listskip->numneigh; int **firstneigh_skip = list->listskip->firstneigh; int inum_skip = list->listskip->inum; int *iskip = list->iskip; int **ijskip = list->ijskip; - FixShearHistory *fix_history = (FixShearHistory *) list->fix_history; - if (fix_history) { - fix_history->nlocal_neigh = nlocal; - fix_history->nall_neigh = nlocal + atom->nghost; - npartner = fix_history->npartner; - partner = fix_history->partner; - shearpartner = fix_history->shearpartner; - listhistory = list->listhistory; - firsttouch = listhistory->firstneigh; - firstshear = listhistory->firstdouble; - ipage_touch = listhistory->ipage; - dpage_shear = listhistory->dpage; - dnum = listhistory->dnum; - dnumbytes = dnum * sizeof(double); - } - int inum = 0; ipage->reset(); - if (fix_history) { - ipage_touch->reset(); - dpage_shear->reset(); - } // loop over atoms in other list // skip I atom entirely if iskip is set for type[I] // skip I,J pair if ijskip is set for type[I],type[J] for (ii = 0; ii < inum_skip; ii++) { i = ilist_skip[ii]; itype = type[i]; if (iskip[itype]) continue; n = 0; neighptr = ipage->vget(); - if (fix_history) { - nn = 0; - touchptr = ipage_touch->vget(); - shearptr = dpage_shear->vget(); - } - // loop over parent non-skip size list and optionally its history info + // loop over parent non-skip size list jlist = firstneigh_skip[i]; jnum = numneigh_skip[i]; for (jj = 0; jj < jnum; jj++) { joriginal = jlist[jj]; j = joriginal & NEIGHMASK; if (ijskip[itype][type[j]]) continue; - neighptr[n] = joriginal; - - // no numeric test for current touch - // just use FSH partner list to infer it - // would require distance calculation for spheres - // more complex calculation for surfs - - if (fix_history) { - jtag = tag[j]; - for (m = 0; m < npartner[i]; m++) - if (partner[i][m] == jtag) break; - if (m < npartner[i]) { - touchptr[n] = 1; - memcpy(&shearptr[nn],&shearpartner[i][dnum*m],dnumbytes); - nn += dnum; - } else { - touchptr[n] = 0; - memcpy(&shearptr[nn],zeroes,dnumbytes); - nn += dnum; - } - } - - n++; + neighptr[n++] = joriginal; } ilist[inum++] = i; firstneigh[i] = neighptr; numneigh[i] = n; ipage->vgot(n); if (ipage->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); - - if (fix_history) { - firsttouch[i] = touchptr; - firstshear[i] = shearptr; - ipage_touch->vgot(n); - dpage_shear->vgot(nn); - } } list->inum = inum; } diff --git a/src/npair_skip_size_off2on.cpp b/src/npair_skip_size_off2on.cpp index da9dd5704..92eae285d 100644 --- a/src/npair_skip_size_off2on.cpp +++ b/src/npair_skip_size_off2on.cpp @@ -1,168 +1,101 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include #include "npair_skip_size_off2on.h" #include "neighbor.h" #include "neigh_list.h" #include "atom.h" #include "atom_vec.h" -#include "molecule.h" -#include "domain.h" -#include "fix_shear_history.h" #include "my_page.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ NPairSkipSizeOff2on::NPairSkipSizeOff2on(LAMMPS *lmp) : NPair(lmp) {} /* ---------------------------------------------------------------------- build skip list for subset of types from parent list iskip and ijskip flag which atom types and type pairs to skip parent non-skip list used newton off, this skip list is newton on - if list requests it, preserve shear history via fix shear/history ------------------------------------------------------------------------- */ void NPairSkipSizeOff2on::build(NeighList *list) { int i,j,ii,jj,m,n,nn,itype,jnum,joriginal,dnum,dnumbytes; tagint itag,jtag; - int *neighptr,*jlist,*touchptr; - double *shearptr; - - int *npartner; - tagint **partner; - double **shearpartner; - int **firsttouch; - double **firstshear; - MyPage *ipage_touch; - MyPage *dpage_shear; - NeighList *listhistory; + int *neighptr,*jlist; tagint *tag = atom->tag; int *type = atom->type; int nlocal = atom->nlocal; int *ilist = list->ilist; int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; MyPage *ipage = list->ipage; int *ilist_skip = list->listskip->ilist; int *numneigh_skip = list->listskip->numneigh; int **firstneigh_skip = list->listskip->firstneigh; int inum_skip = list->listskip->inum; int *iskip = list->iskip; int **ijskip = list->ijskip; - FixShearHistory *fix_history = (FixShearHistory *) list->fix_history; - if (fix_history) { - fix_history->nlocal_neigh = nlocal; - fix_history->nall_neigh = nlocal + atom->nghost; - npartner = fix_history->npartner; - partner = fix_history->partner; - shearpartner = fix_history->shearpartner; - listhistory = list->listhistory; - firsttouch = listhistory->firstneigh; - firstshear = listhistory->firstdouble; - ipage_touch = listhistory->ipage; - dpage_shear = listhistory->dpage; - dnum = listhistory->dnum; - dnumbytes = dnum * sizeof(double); - } - int inum = 0; ipage->reset(); - if (fix_history) { - ipage_touch->reset(); - dpage_shear->reset(); - } // loop over atoms in other list // skip I atom entirely if iskip is set for type[I] // skip I,J pair if ijskip is set for type[I],type[J] for (ii = 0; ii < inum_skip; ii++) { i = ilist_skip[ii]; itype = type[i]; if (iskip[itype]) continue; itag = tag[i]; n = 0; neighptr = ipage->vget(); - if (fix_history) { - nn = 0; - touchptr = ipage_touch->vget(); - shearptr = dpage_shear->vget(); - } // loop over parent non-skip size list and optionally its history info jlist = firstneigh_skip[i]; jnum = numneigh_skip[i]; for (jj = 0; jj < jnum; jj++) { joriginal = jlist[jj]; j = joriginal & NEIGHMASK; if (ijskip[itype][type[j]]) continue; // only keep I,J when J = ghost if Itag < Jtag jtag = tag[j]; if (j >= nlocal && jtag < itag) continue; - neighptr[n] = joriginal; - - // no numeric test for current touch - // just use FSH partner list to infer it - // would require distance calculation for spheres - // more complex calculation for surfs - - if (fix_history) { - for (m = 0; m < npartner[i]; m++) - if (partner[i][m] == jtag) break; - if (m < npartner[i]) { - touchptr[n] = 1; - memcpy(&shearptr[nn],&shearpartner[i][dnum*m],dnumbytes); - nn += dnum; - } else { - touchptr[n] = 0; - memcpy(&shearptr[nn],zeroes,dnumbytes); - nn += dnum; - } - } - - n++; + neighptr[n++] = joriginal; } ilist[inum++] = i; firstneigh[i] = neighptr; numneigh[i] = n; ipage->vgot(n); if (ipage->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); - - if (fix_history) { - firsttouch[i] = touchptr; - firstshear[i] = shearptr; - ipage_touch->vgot(n); - dpage_shear->vgot(nn); - } } list->inum = inum; } diff --git a/src/npair_skip_size_off2on_oneside.cpp b/src/npair_skip_size_off2on_oneside.cpp index 7377feec5..f2fca7b12 100644 --- a/src/npair_skip_size_off2on_oneside.cpp +++ b/src/npair_skip_size_off2on_oneside.cpp @@ -1,223 +1,166 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include #include "npair_skip_size_off2on_oneside.h" #include "neighbor.h" #include "neigh_list.h" #include "atom.h" #include "atom_vec.h" -#include "molecule.h" #include "domain.h" -#include "fix_shear_history.h" #include "my_page.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ NPairSkipSizeOff2onOneside::NPairSkipSizeOff2onOneside(LAMMPS *lmp) : NPair(lmp) {} /* ---------------------------------------------------------------------- build skip list for subset of types from parent list iskip and ijskip flag which atom types and type pairs to skip parent non-skip list used newton off and was not onesided, this skip list is newton on and onesided - if list requests it, preserve shear history via fix shear/history ------------------------------------------------------------------------- */ void NPairSkipSizeOff2onOneside::build(NeighList *list) { int i,j,ii,jj,m,n,nn,itype,jnum,joriginal,flip,dnum,dnumbytes,tmp; tagint jtag; int *surf,*jlist; - int *npartner; - tagint **partner; - double **shearpartner; - int **firsttouch; - double **firstshear; - MyPage *ipage_touch; - MyPage *dpage_shear; - NeighList *listhistory; - tagint *tag = atom->tag; int *type = atom->type; int nlocal = atom->nlocal; int *ilist = list->ilist; int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; MyPage *ipage = list->ipage; int *ilist_skip = list->listskip->ilist; int *numneigh_skip = list->listskip->numneigh; int **firstneigh_skip = list->listskip->firstneigh; int inum_skip = list->listskip->inum; int *iskip = list->iskip; int **ijskip = list->ijskip; if (domain->dimension == 2) surf = atom->line; else surf = atom->tri; - FixShearHistory *fix_history = (FixShearHistory *) list->fix_history; - if (fix_history) { - fix_history->nlocal_neigh = nlocal; - fix_history->nall_neigh = nlocal + atom->nghost; - npartner = fix_history->npartner; - partner = fix_history->partner; - shearpartner = fix_history->shearpartner; - listhistory = list->listhistory; - firsttouch = listhistory->firstneigh; - firstshear = listhistory->firstdouble; - ipage_touch = listhistory->ipage; - dpage_shear = listhistory->dpage; - dnum = listhistory->dnum; - dnumbytes = dnum * sizeof(double); - } - int inum = 0; ipage->reset(); - if (fix_history) { - ipage_touch->reset(); - dpage_shear->reset(); - } // two loops over parent list required, one to count, one to store // because onesided constraint means pair I,J may be stored with I or J // so don't know in advance how much space to alloc for each atom's neighs // first loop over atoms in other list to count neighbors // skip I atom entirely if iskip is set for type[I] // skip I,J pair if ijskip is set for type[I],type[J] for (i = 0; i < nlocal; i++) numneigh[i] = 0; for (ii = 0; ii < inum_skip; ii++) { i = ilist_skip[ii]; itype = type[i]; if (iskip[itype]) continue; n = 0; // loop over parent non-skip size list jlist = firstneigh_skip[i]; jnum = numneigh_skip[i]; for (jj = 0; jj < jnum; jj++) { joriginal = jlist[jj]; j = joriginal & NEIGHMASK; if (ijskip[itype][type[j]]) continue; // flip I,J if necessary to satisfy onesided constraint // do not keep if I is now ghost if (surf[i] >= 0) { if (j >= nlocal) continue; tmp = i; i = j; j = tmp; flip = 1; } else flip = 0; numneigh[i]++; if (flip) i = j; } } - // allocate all per-atom neigh list chunks, including history + // allocate all per-atom neigh list chunks for (i = 0; i < nlocal; i++) { if (numneigh[i] == 0) continue; n = numneigh[i]; firstneigh[i] = ipage->get(n); if (ipage->status()) error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); - if (fix_history) { - firsttouch[i] = ipage_touch->get(n); - firstshear[i] = dpage_shear->get(dnum*n); - } } // second loop over atoms in other list to store neighbors // skip I atom entirely if iskip is set for type[I] // skip I,J pair if ijskip is set for type[I],type[J] for (i = 0; i < nlocal; i++) numneigh[i] = 0; for (ii = 0; ii < inum_skip; ii++) { i = ilist_skip[ii]; itype = type[i]; if (iskip[itype]) continue; // loop over parent non-skip size list and optionally its history info jlist = firstneigh_skip[i]; jnum = numneigh_skip[i]; for (jj = 0; jj < jnum; jj++) { joriginal = jlist[jj]; j = joriginal & NEIGHMASK; if (ijskip[itype][type[j]]) continue; // flip I,J if necessary to satisfy onesided constraint // do not keep if I is now ghost if (surf[i] >= 0) { if (j >= nlocal) continue; tmp = i; i = j; j = tmp; flip = 1; } else flip = 0; // store j in neigh list, not joriginal, like other neigh methods // OK, b/c there is no special list flagging for surfs firstneigh[i][numneigh[i]] = j; - - // no numeric test for current touch - // just use FSH partner list to infer it - // would require complex calculation for surfs - - if (fix_history) { - jtag = tag[j]; - n = numneigh[i]; - nn = dnum*n; - for (m = 0; m < npartner[i]; m++) - if (partner[i][m] == jtag) break; - if (m < npartner[i]) { - firsttouch[i][n] = 1; - memcpy(&firstshear[i][nn],&shearpartner[i][dnum*m],dnumbytes); - } else { - firsttouch[i][n] = 0; - memcpy(&firstshear[i][nn],zeroes,dnumbytes); - } - } - numneigh[i]++; if (flip) i = j; } // only add atom I to ilist if it has neighbors - // fix shear/history allows for this in pre_exchange_onesided() if (numneigh[i]) ilist[inum++] = i; } list->inum = inum; } diff --git a/src/pair.h b/src/pair.h index 0f7b0f85b..eb71e8822 100644 --- a/src/pair.h +++ b/src/pair.h @@ -1,364 +1,360 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #ifndef LMP_PAIR_H #define LMP_PAIR_H #include "pointers.h" #include "accelerator_kokkos.h" namespace LAMMPS_NS { class Pair : protected Pointers { friend class AngleSDK; friend class AngleSDKOMP; friend class BondQuartic; friend class BondQuarticOMP; friend class DihedralCharmm; friend class DihedralCharmmOMP; friend class FixGPU; friend class FixOMP; friend class ThrOMP; friend class Info; public: static int instance_total; // # of Pair classes ever instantiated double eng_vdwl,eng_coul; // accumulated energies double virial[6]; // accumulated virial double *eatom,**vatom; // accumulated per-atom energy/virial double cutforce; // max cutoff for all atom pairs double **cutsq; // cutoff sq for each atom pair int **setflag; // 0/1 = whether each i,j has been set int comm_forward; // size of forward communication (0 if none) int comm_reverse; // size of reverse communication (0 if none) int comm_reverse_off; // size of reverse comm even if newton off int single_enable; // 1 if single() routine exists int restartinfo; // 1 if pair style writes restart info int respa_enable; // 1 if inner/middle/outer rRESPA routines int one_coeff; // 1 if allows only one coeff * * call int manybody_flag; // 1 if a manybody potential int no_virial_fdotr_compute; // 1 if does not invoke virial_fdotr_compute() int writedata; // 1 if writes coeffs to data file int ghostneigh; // 1 if pair style needs neighbors of ghosts double **cutghost; // cutoff for each ghost pair int ewaldflag; // 1 if compatible with Ewald solver int pppmflag; // 1 if compatible with PPPM solver int msmflag; // 1 if compatible with MSM solver int dispersionflag; // 1 if compatible with LJ/dispersion solver int tip4pflag; // 1 if compatible with TIP4P solver int dipoleflag; // 1 if compatible with dipole solver int reinitflag; // 1 if compatible with fix adapt and alike int tail_flag; // pair_modify flag for LJ tail correction double etail,ptail; // energy/pressure tail corrections double etail_ij,ptail_ij; int evflag; // energy,virial settings int eflag_either,eflag_global,eflag_atom; int vflag_either,vflag_global,vflag_atom; int ncoultablebits; // size of Coulomb table, accessed by KSpace int ndisptablebits; // size of dispersion table double tabinnersq; double tabinnerdispsq; double *rtable,*drtable,*ftable,*dftable,*ctable,*dctable; double *etable,*detable,*ptable,*dptable,*vtable,*dvtable; double *rdisptable, *drdisptable, *fdisptable, *dfdisptable; double *edisptable, *dedisptable; int ncoulshiftbits,ncoulmask; int ndispshiftbits, ndispmask; int nextra; // # of extra quantities pair style calculates double *pvector; // vector of extra pair quantities int single_extra; // number of extra single values calculated double *svector; // vector of extra single quantities class NeighList *list; // standard neighbor list used by most pairs class NeighList *listhalf; // half list used by some pairs class NeighList *listfull; // full list used by some pairs - class NeighList *listhistory; // neighbor history list used by some pairs - class NeighList *listinner; // rRESPA lists used by some pairs - class NeighList *listmiddle; - class NeighList *listouter; int allocated; // 0/1 = whether arrays are allocated // public so external driver can check int compute_flag; // 0 if skip compute() // KOKKOS host/device flag and data masks ExecutionSpace execution_space; unsigned int datamask_read,datamask_modify; Pair(class LAMMPS *); virtual ~Pair(); // top-level Pair methods void init(); virtual void reinit(); virtual void setup() {} double mix_energy(double, double, double, double); double mix_distance(double, double); void write_file(int, char **); void init_bitmap(double, double, int, int &, int &, int &, int &); virtual void modify_params(int, char **); void compute_dummy(int, int); // need to be public, so can be called by pair_style reaxc void v_tally(int, double *, double *); void ev_tally(int, int, int, int, double, double, double, double, double, double); void ev_tally3(int, int, int, double, double, double *, double *, double *, double *); void v_tally3(int, int, int, double *, double *, double *, double *); void v_tally4(int, int, int, int, double *, double *, double *, double *, double *, double *); void ev_tally_xyz(int, int, int, int, double, double, double, double, double, double, double, double); // general child-class methods virtual void compute(int, int) = 0; virtual void compute_inner() {} virtual void compute_middle() {} virtual void compute_outer(int, int) {} virtual double single(int, int, int, int, double, double, double, double& fforce) { fforce = 0.0; return 0.0; } virtual void settings(int, char **) = 0; virtual void coeff(int, char **) = 0; virtual void init_style(); virtual void init_list(int, class NeighList *); virtual double init_one(int, int) {return 0.0;} virtual void init_tables(double, double *); virtual void init_tables_disp(double); virtual void free_tables(); virtual void free_disp_tables(); virtual void write_restart(FILE *) {} virtual void read_restart(FILE *) {} virtual void write_restart_settings(FILE *) {} virtual void read_restart_settings(FILE *) {} virtual void write_data(FILE *) {} virtual void write_data_all(FILE *) {} virtual int pack_forward_comm(int, int *, double *, int, int *) {return 0;} virtual void unpack_forward_comm(int, int, double *) {} virtual int pack_forward_comm_kokkos(int, DAT::tdual_int_2d, int, DAT::tdual_xfloat_1d &, int, int *) {return 0;}; virtual void unpack_forward_comm_kokkos(int, int, DAT::tdual_xfloat_1d &) {} virtual int pack_reverse_comm(int, int, double *) {return 0;} virtual void unpack_reverse_comm(int, int *, double *) {} virtual double memory_usage(); void set_copymode(int value) {copymode = value;} // specific child-class methods for certain Pair styles virtual void *extract(const char *, int &) {return NULL;} virtual void swap_eam(double *, double **) {} virtual void reset_dt() {} virtual void min_xf_pointers(int, double **, double **) {} virtual void min_xf_get(int) {} virtual void min_x_set(int) {} // management of callbacks to be run from ev_tally() protected: int num_tally_compute; class Compute **list_tally_compute; public: virtual void add_tally_callback(class Compute *); virtual void del_tally_callback(class Compute *); protected: int instance_me; // which Pair class instantiation I am enum{GEOMETRIC,ARITHMETIC,SIXTHPOWER}; // mixing options int special_lj[4]; // copied from force->special_lj for Kokkos int suffix_flag; // suffix compatibility flag // pair_modify settings int offset_flag,mix_flag; // flags for offset and mixing double tabinner; // inner cutoff for Coulomb table double tabinner_disp; // inner cutoff for dispersion table public: // custom data type for accessing Coulomb tables typedef union {int i; float f;} union_int_float_t; protected: int vflag_fdotr; int maxeatom,maxvatom; int copymode; // if set, do not deallocate during destruction // required when classes are used as functors by Kokkos virtual void ev_setup(int, int, int alloc = 1); void ev_unset(); void ev_tally_full(int, double, double, double, double, double, double); void ev_tally_xyz_full(int, double, double, double, double, double, double, double, double); void ev_tally4(int, int, int, int, double, double *, double *, double *, double *, double *, double *); void ev_tally_tip4p(int, int *, double *, double, double); void v_tally2(int, int, double, double *); void v_tally_tensor(int, int, int, int, double, double, double, double, double, double); void virial_fdotr_compute(); // union data struct for packing 32-bit and 64-bit ints into double bufs // see atom_vec.h for documentation union ubuf { double d; int64_t i; ubuf(double arg) : d(arg) {} ubuf(int64_t arg) : i(arg) {} ubuf(int arg) : i(arg) {} }; inline int sbmask(int j) const { return j >> SBBITS & 3; } }; } #endif /* ERROR/WARNING messages: E: Illegal ... command Self-explanatory. Check the input script syntax and compare to the documentation for the command. You can use -echo screen as a command-line option when running LAMMPS to see the offending line. E: Too many total bits for bitmapped lookup table Table size specified via pair_modify command is too large. Note that a value of N generates a 2^N size table. E: Cannot have both pair_modify shift and tail set to yes These 2 options are contradictory. E: Cannot use pair tail corrections with 2d simulations The correction factors are only currently defined for 3d systems. W: Using pair tail corrections with nonperiodic system This is probably a bogus thing to do, since tail corrections are computed by integrating the density of a periodic system out to infinity. W: Using pair tail corrections with pair_modify compute no The tail corrections will thus not be computed. W: Using pair potential shift with pair_modify compute no The shift effects will thus not be computed. W: Using a manybody potential with bonds/angles/dihedrals and special_bond exclusions This is likely not what you want to do. The exclusion settings will eliminate neighbors in the neighbor list, which the manybody potential needs to calculated its terms correctly. E: All pair coeffs are not set All pair coefficients must be set in the data file or by the pair_coeff command before running a simulation. E: Fix adapt interface to this pair style not supported New coding for the pair style would need to be done. E: Pair style requires a KSpace style No kspace style is defined. E: Cannot yet use compute tally with Kokkos This feature is not yet supported. E: Pair style does not support pair_write The pair style does not have a single() function, so it can not be invoked by pair write. E: Invalid atom types in pair_write command Atom types must range from 1 to Ntypes inclusive. E: Invalid style in pair_write command Self-explanatory. Check the input script. E: Invalid cutoffs in pair_write command Inner cutoff must be larger than 0.0 and less than outer cutoff. E: Cannot open pair_write file The specified output file for pair energies and forces cannot be opened. Check that the path and name are correct. E: Bitmapped lookup tables require int/float be same size Cannot use pair tables on this machine, because of word sizes. Use the pair_modify command with table 0 instead. W: Table inner cutoff >= outer cutoff You specified an inner cutoff for a Coulombic table that is longer than the global cutoff. Probably not what you wanted. E: Too many exponent bits for lookup table Table size specified via pair_modify command does not work with your machine's floating point representation. E: Too many mantissa bits for lookup table Table size specified via pair_modify command does not work with your machine's floating point representation. E: Too few bits for lookup table Table size specified via pair_modify command does not work with your machine's floating point representation. */ diff --git a/src/pair_lj96_cut.cpp b/src/pair_lj96_cut.cpp index 83fc5bcdd..842b918fe 100644 --- a/src/pair_lj96_cut.cpp +++ b/src/pair_lj96_cut.cpp @@ -1,722 +1,696 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- Contributing author: Chuanfu Luo (luochuanfu@gmail.com) ------------------------------------------------------------------------- */ #include #include #include #include #include "pair_lj96_cut.h" #include "atom.h" #include "comm.h" #include "force.h" #include "neighbor.h" #include "neigh_list.h" #include "neigh_request.h" #include "update.h" #include "integrate.h" #include "respa.h" #include "math_const.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; using namespace MathConst; /* ---------------------------------------------------------------------- */ PairLJ96Cut::PairLJ96Cut(LAMMPS *lmp) : Pair(lmp) { respa_enable = 1; writedata = 1; } /* ---------------------------------------------------------------------- */ PairLJ96Cut::~PairLJ96Cut() { if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(cut); memory->destroy(epsilon); memory->destroy(sigma); memory->destroy(lj1); memory->destroy(lj2); memory->destroy(lj3); memory->destroy(lj4); memory->destroy(offset); } } /* ---------------------------------------------------------------------- */ void PairLJ96Cut::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; double rsq,r2inv,r3inv,r6inv,forcelj,factor_lj; int *ilist,*jlist,*numneigh,**firstneigh; evdwl = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; inum = list->inum; ilist = list->ilist; numneigh = list->numneigh; firstneigh = list->firstneigh; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; if (rsq < cutsq[itype][jtype]) { r2inv = 1.0/rsq; r6inv = r2inv*r2inv*r2inv; r3inv = sqrt(r6inv); forcelj = r6inv * (lj1[itype][jtype]*r3inv - lj2[itype][jtype]); fpair = factor_lj*forcelj*r2inv; 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; } if (eflag) { evdwl = r6inv*(lj3[itype][jtype]*r3inv-lj4[itype][jtype]) - offset[itype][jtype]; evdwl *= factor_lj; } if (evflag) ev_tally(i,j,nlocal,newton_pair, evdwl,0.0,fpair,delx,dely,delz); } } } if (vflag_fdotr) virial_fdotr_compute(); } /* ---------------------------------------------------------------------- */ void PairLJ96Cut::compute_inner() { int i,j,ii,jj,inum,jnum,itype,jtype; double xtmp,ytmp,ztmp,delx,dely,delz,fpair; double rsq,r2inv,r3inv,r6inv,forcelj,factor_lj,rsw; int *ilist,*jlist,*numneigh,**firstneigh; double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; - inum = listinner->inum; - ilist = listinner->ilist; - numneigh = listinner->numneigh; - firstneigh = listinner->firstneigh; + inum = list->inum_inner; + ilist = list->ilist_inner; + numneigh = list->numneigh_inner; + firstneigh = list->firstneigh_inner; double cut_out_on = cut_respa[0]; double cut_out_off = cut_respa[1]; double cut_out_diff = cut_out_off - cut_out_on; double cut_out_on_sq = cut_out_on*cut_out_on; double cut_out_off_sq = cut_out_off*cut_out_off; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq < cut_out_off_sq) { r2inv = 1.0/rsq; r6inv = r2inv*r2inv*r2inv; r3inv = sqrt(r6inv); jtype = type[j]; forcelj = r6inv * (lj1[itype][jtype]*r3inv - lj2[itype][jtype]); fpair = factor_lj*forcelj*r2inv; if (rsq > cut_out_on_sq) { rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; fpair *= 1.0 - rsw*rsw*(3.0 - 2.0*rsw); } 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; } } } } } /* ---------------------------------------------------------------------- */ void PairLJ96Cut::compute_middle() { int i,j,ii,jj,inum,jnum,itype,jtype; double xtmp,ytmp,ztmp,delx,dely,delz,fpair; double rsq,r2inv,r3inv,r6inv,forcelj,factor_lj,rsw; int *ilist,*jlist,*numneigh,**firstneigh; double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; - inum = listmiddle->inum; - ilist = listmiddle->ilist; - numneigh = listmiddle->numneigh; - firstneigh = listmiddle->firstneigh; + inum = list->inum_middle; + ilist = list->ilist_middle; + numneigh = list->numneigh_middle; + firstneigh = list->firstneigh_middle; double cut_in_off = cut_respa[0]; double cut_in_on = cut_respa[1]; double cut_out_on = cut_respa[2]; double cut_out_off = cut_respa[3]; double cut_in_diff = cut_in_on - cut_in_off; double cut_out_diff = cut_out_off - cut_out_on; double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; double cut_out_on_sq = cut_out_on*cut_out_on; double cut_out_off_sq = cut_out_off*cut_out_off; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq < cut_out_off_sq && rsq > cut_in_off_sq) { r2inv = 1.0/rsq; r6inv = r2inv*r2inv*r2inv; r3inv = sqrt(r6inv); jtype = type[j]; forcelj = r6inv * (lj1[itype][jtype]*r3inv - lj2[itype][jtype]); fpair = factor_lj*forcelj*r2inv; if (rsq < cut_in_on_sq) { rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; fpair *= rsw*rsw*(3.0 - 2.0*rsw); } if (rsq > cut_out_on_sq) { rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; fpair *= 1.0 + rsw*rsw*(2.0*rsw - 3.0); } 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; } } } } } /* ---------------------------------------------------------------------- */ void PairLJ96Cut::compute_outer(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; double rsq,r2inv,r3inv,r6inv,forcelj,factor_lj,rsw; int *ilist,*jlist,*numneigh,**firstneigh; evdwl = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = 0; double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; - inum = listouter->inum; - ilist = listouter->ilist; - numneigh = listouter->numneigh; - firstneigh = listouter->firstneigh; + inum = list->inum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; double cut_in_off = cut_respa[2]; double cut_in_on = cut_respa[3]; double cut_in_diff = cut_in_on - cut_in_off; double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; if (rsq < cutsq[itype][jtype]) { if (rsq > cut_in_off_sq) { r2inv = 1.0/rsq; r6inv = r2inv*r2inv*r2inv; r3inv = sqrt(r6inv); forcelj = r6inv * (lj1[itype][jtype]*r3inv - lj2[itype][jtype]); fpair = factor_lj*forcelj*r2inv; if (rsq < cut_in_on_sq) { rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; fpair *= rsw*rsw*(3.0 - 2.0*rsw); } 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; } } if (eflag) { r2inv = 1.0/rsq; r6inv = r2inv*r2inv*r2inv; r3inv = sqrt(r6inv); evdwl = r6inv*(lj3[itype][jtype]*r3inv-lj4[itype][jtype]) - offset[itype][jtype]; evdwl *= factor_lj; } if (vflag) { if (rsq <= cut_in_off_sq) { r2inv = 1.0/rsq; r6inv = r2inv*r2inv*r2inv; r3inv = sqrt(r6inv); forcelj = r6inv * (lj1[itype][jtype]*r3inv - lj2[itype][jtype]); fpair = factor_lj*forcelj*r2inv; } else if (rsq < cut_in_on_sq) fpair = factor_lj*forcelj*r2inv; } if (evflag) ev_tally(i,j,nlocal,newton_pair, evdwl,0.0,fpair,delx,dely,delz); } } } } /* ---------------------------------------------------------------------- allocate all arrays ------------------------------------------------------------------------- */ void PairLJ96Cut::allocate() { allocated = 1; int n = atom->ntypes; 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(cutsq,n+1,n+1,"pair:cutsq"); memory->create(cut,n+1,n+1,"pair:cut"); memory->create(epsilon,n+1,n+1,"pair:epsilon"); memory->create(sigma,n+1,n+1,"pair:sigma"); memory->create(lj1,n+1,n+1,"pair:lj1"); memory->create(lj2,n+1,n+1,"pair:lj2"); memory->create(lj3,n+1,n+1,"pair:lj3"); memory->create(lj4,n+1,n+1,"pair:lj4"); memory->create(offset,n+1,n+1,"pair:offset"); } /* ---------------------------------------------------------------------- global settings ------------------------------------------------------------------------- */ void PairLJ96Cut::settings(int narg, char **arg) { if (narg != 1) error->all(FLERR,"Illegal pair_style command"); cut_global = force->numeric(FLERR,arg[0]); // reset cutoffs that have been explicitly set if (allocated) { int i,j; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) if (setflag[i][j]) cut[i][j] = cut_global; } } /* ---------------------------------------------------------------------- set coeffs for one or more type pairs ------------------------------------------------------------------------- */ void PairLJ96Cut::coeff(int narg, char **arg) { if (narg < 4 || narg > 5) error->all(FLERR,"Incorrect args for pair coefficients"); if (!allocated) allocate(); int ilo,ihi,jlo,jhi; force->bounds(FLERR,arg[0],atom->ntypes,ilo,ihi); force->bounds(FLERR,arg[1],atom->ntypes,jlo,jhi); double epsilon_one = force->numeric(FLERR,arg[2]); double sigma_one = force->numeric(FLERR,arg[3]); double cut_one = cut_global; if (narg == 5) cut_one = force->numeric(FLERR,arg[4]); int count = 0; for (int i = ilo; i <= ihi; i++) { for (int j = MAX(jlo,i); j <= jhi; j++) { epsilon[i][j] = epsilon_one; sigma[i][j] = sigma_one; cut[i][j] = cut_one; setflag[i][j] = 1; count++; } } if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- init specific to this pair style ------------------------------------------------------------------------- */ void PairLJ96Cut::init_style() { - // request regular or rRESPA neighbor lists + // request regular or rRESPA neighbor list int irequest; + int respa = 0; if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { - int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; + } - if (respa == 0) irequest = neighbor->request(this,instance_me); - else if (respa == 1) { - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 1; - neighbor->requests[irequest]->respainner = 1; - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 3; - neighbor->requests[irequest]->respaouter = 1; - } else { - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 1; - neighbor->requests[irequest]->respainner = 1; - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 2; - neighbor->requests[irequest]->respamiddle = 1; - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 3; - neighbor->requests[irequest]->respaouter = 1; - } + irequest = neighbor->request(this,instance_me); - } else irequest = neighbor->request(this,instance_me); + if (respa >= 1) { + neighbor->requests[irequest]->respaouter = 1; + neighbor->requests[irequest]->respainner = 1; + } + if (respa == 2) neighbor->requests[irequest]->respamiddle = 1; // set rRESPA cutoffs if (strstr(update->integrate_style,"respa") && ((Respa *) update->integrate)->level_inner >= 0) cut_respa = ((Respa *) update->integrate)->cutoff; else cut_respa = NULL; } -/* ---------------------------------------------------------------------- - neighbor callback to inform pair style of neighbor list to use - regular or rRESPA -------------------------------------------------------------------------- */ - -void PairLJ96Cut::init_list(int id, NeighList *ptr) -{ - if (id == 0) list = ptr; - else if (id == 1) listinner = ptr; - else if (id == 2) listmiddle = ptr; - else if (id == 3) listouter = ptr; -} - /* ---------------------------------------------------------------------- init for one type pair i,j and corresponding j,i ------------------------------------------------------------------------- */ double PairLJ96Cut::init_one(int i, int j) { if (setflag[i][j] == 0) { epsilon[i][j] = mix_energy(epsilon[i][i],epsilon[j][j], sigma[i][i],sigma[j][j]); sigma[i][j] = mix_distance(sigma[i][i],sigma[j][j]); cut[i][j] = mix_distance(cut[i][i],cut[j][j]); } lj1[i][j] = 36.0 * epsilon[i][j] * pow(sigma[i][j],9.0); lj2[i][j] = 24.0 * epsilon[i][j] * pow(sigma[i][j],6.0); lj3[i][j] = 4.0 * epsilon[i][j] * pow(sigma[i][j],9.0); lj4[i][j] = 4.0 * epsilon[i][j] * pow(sigma[i][j],6.0); if (offset_flag && (cut[i][j] > 0.0)) { double ratio = sigma[i][j] / cut[i][j]; offset[i][j] = 4.0 * epsilon[i][j] * (pow(ratio,9.0) - pow(ratio,6.0)); } else offset[i][j] = 0.0; lj1[j][i] = lj1[i][j]; lj2[j][i] = lj2[i][j]; lj3[j][i] = lj3[i][j]; lj4[j][i] = lj4[i][j]; offset[j][i] = offset[i][j]; // check interior rRESPA cutoff if (cut_respa && cut[i][j] < cut_respa[3]) error->all(FLERR,"Pair cutoff < Respa interior cutoff"); // compute I,J contribution to long-range tail correction // count total # of atoms of type I and J via Allreduce if (tail_flag) { int *type = atom->type; int nlocal = atom->nlocal; double count[2],all[2]; count[0] = count[1] = 0.0; for (int k = 0; k < nlocal; k++) { if (type[k] == i) count[0] += 1.0; if (type[k] == j) count[1] += 1.0; } MPI_Allreduce(count,all,2,MPI_DOUBLE,MPI_SUM,world); double sig3 = sigma[i][j]*sigma[i][j]*sigma[i][j]; double sig6 = sig3*sig3; double rc3 = cut[i][j]*cut[i][j]*cut[i][j]; double rc6 = rc3*rc3; etail_ij = 8.0*MY_PI*all[0]*all[1]*epsilon[i][j] * sig6 * (sig3 - 2.0*rc3) / (6.0*rc6); ptail_ij = 8.0*MY_PI*all[0]*all[1]*epsilon[i][j] * sig6 * (3.0*sig3 - 4.0*rc3) / (6.0*rc6); } return cut[i][j]; } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairLJ96Cut::write_restart(FILE *fp) { write_restart_settings(fp); int i,j; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { fwrite(&setflag[i][j],sizeof(int),1,fp); if (setflag[i][j]) { fwrite(&epsilon[i][j],sizeof(double),1,fp); fwrite(&sigma[i][j],sizeof(double),1,fp); fwrite(&cut[i][j],sizeof(double),1,fp); } } } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairLJ96Cut::read_restart(FILE *fp) { read_restart_settings(fp); allocate(); int i,j; int me = comm->me; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp); MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world); if (setflag[i][j]) { if (me == 0) { fread(&epsilon[i][j],sizeof(double),1,fp); fread(&sigma[i][j],sizeof(double),1,fp); fread(&cut[i][j],sizeof(double),1,fp); } MPI_Bcast(&epsilon[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&sigma[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&cut[i][j],1,MPI_DOUBLE,0,world); } } } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairLJ96Cut::write_restart_settings(FILE *fp) { fwrite(&cut_global,sizeof(double),1,fp); fwrite(&offset_flag,sizeof(int),1,fp); fwrite(&mix_flag,sizeof(int),1,fp); fwrite(&tail_flag,sizeof(int),1,fp); } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairLJ96Cut::read_restart_settings(FILE *fp) { int me = comm->me; if (me == 0) { fread(&cut_global,sizeof(double),1,fp); fread(&offset_flag,sizeof(int),1,fp); fread(&mix_flag,sizeof(int),1,fp); fread(&tail_flag,sizeof(int),1,fp); } MPI_Bcast(&cut_global,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(&tail_flag,1,MPI_INT,0,world); } /* ---------------------------------------------------------------------- proc 0 writes to data file ------------------------------------------------------------------------- */ void PairLJ96Cut::write_data(FILE *fp) { for (int i = 1; i <= atom->ntypes; i++) fprintf(fp,"%d %g %g\n",i,epsilon[i][i],sigma[i][i]); } /* ---------------------------------------------------------------------- proc 0 writes all pairs to data file ------------------------------------------------------------------------- */ void PairLJ96Cut::write_data_all(FILE *fp) { for (int i = 1; i <= atom->ntypes; i++) for (int j = i; j <= atom->ntypes; j++) fprintf(fp,"%d %d %g %g %g\n",i,j,epsilon[i][j],sigma[i][j],cut[i][j]); } /* ---------------------------------------------------------------------- */ double PairLJ96Cut::single(int i, int j, int itype, int jtype, double rsq, double factor_coul, double factor_lj, double &fforce) { double r2inv,r3inv,r6inv,forcelj,philj; r2inv = 1.0/rsq; r6inv = r2inv*r2inv*r2inv; r3inv = sqrt(r6inv); forcelj = r6inv * (lj1[itype][jtype]*r3inv - lj2[itype][jtype]); fforce = factor_lj*forcelj*r2inv; philj = r6inv*(lj3[itype][jtype]*r3inv-lj4[itype][jtype]) - offset[itype][jtype]; return factor_lj*philj; } diff --git a/src/pair_lj96_cut.h b/src/pair_lj96_cut.h index 6b677c642..4d6df0212 100644 --- a/src/pair_lj96_cut.h +++ b/src/pair_lj96_cut.h @@ -1,82 +1,81 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #ifdef PAIR_CLASS PairStyle(lj96/cut,PairLJ96Cut) #else #ifndef LMP_PAIR_LJ96_CUT_H #define LMP_PAIR_LJ96_CUT_H #include "pair.h" namespace LAMMPS_NS { class PairLJ96Cut : public Pair { public: PairLJ96Cut(class LAMMPS *); virtual ~PairLJ96Cut(); virtual void compute(int, int); void settings(int, char **); void coeff(int, char **); void init_style(); - void init_list(int, class NeighList *); double init_one(int, int); void write_restart(FILE *); void read_restart(FILE *); void write_restart_settings(FILE *); void read_restart_settings(FILE *); void write_data(FILE *); void write_data_all(FILE *); double single(int, int, int, int, double, double, double, double &); void compute_inner(); void compute_middle(); void compute_outer(int, int); protected: double cut_global; double **cut; double **epsilon,**sigma; double **lj1,**lj2,**lj3,**lj4,**offset; double *cut_respa; void allocate(); }; } #endif #endif /* ERROR/WARNING messages: E: Illegal ... command Self-explanatory. Check the input script syntax and compare to the documentation for the command. You can use -echo screen as a command-line option when running LAMMPS to see the offending line. E: Incorrect args for pair coefficients Self-explanatory. Check the input script or data file. E: Pair cutoff < Respa interior cutoff One or more pairwise cutoffs are too short to use with the specified rRESPA cutoffs. */ diff --git a/src/pair_lj_cut.cpp b/src/pair_lj_cut.cpp index 7f838061f..215fabecb 100644 --- a/src/pair_lj_cut.cpp +++ b/src/pair_lj_cut.cpp @@ -1,725 +1,699 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- Contributing author: Paul Crozier (SNL) ------------------------------------------------------------------------- */ #include #include #include #include #include "pair_lj_cut.h" #include "atom.h" #include "comm.h" #include "force.h" #include "neighbor.h" #include "neigh_list.h" #include "neigh_request.h" #include "update.h" #include "integrate.h" #include "respa.h" #include "math_const.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; using namespace MathConst; /* ---------------------------------------------------------------------- */ PairLJCut::PairLJCut(LAMMPS *lmp) : Pair(lmp) { respa_enable = 1; writedata = 1; } /* ---------------------------------------------------------------------- */ PairLJCut::~PairLJCut() { if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(cut); memory->destroy(epsilon); memory->destroy(sigma); memory->destroy(lj1); memory->destroy(lj2); memory->destroy(lj3); memory->destroy(lj4); memory->destroy(offset); } } /* ---------------------------------------------------------------------- */ void PairLJCut::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; double rsq,r2inv,r6inv,forcelj,factor_lj; int *ilist,*jlist,*numneigh,**firstneigh; evdwl = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; inum = list->inum; ilist = list->ilist; numneigh = list->numneigh; firstneigh = list->firstneigh; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; if (rsq < cutsq[itype][jtype]) { r2inv = 1.0/rsq; r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); fpair = factor_lj*forcelj*r2inv; 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; } if (eflag) { evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - offset[itype][jtype]; evdwl *= factor_lj; } if (evflag) ev_tally(i,j,nlocal,newton_pair, evdwl,0.0,fpair,delx,dely,delz); } } } if (vflag_fdotr) virial_fdotr_compute(); } /* ---------------------------------------------------------------------- */ void PairLJCut::compute_inner() { int i,j,ii,jj,inum,jnum,itype,jtype; double xtmp,ytmp,ztmp,delx,dely,delz,fpair; double rsq,r2inv,r6inv,forcelj,factor_lj,rsw; int *ilist,*jlist,*numneigh,**firstneigh; double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; - inum = listinner->inum; - ilist = listinner->ilist; - numneigh = listinner->numneigh; - firstneigh = listinner->firstneigh; + inum = list->inum_inner; + ilist = list->ilist_inner; + numneigh = list->numneigh_inner; + firstneigh = list->firstneigh_inner; double cut_out_on = cut_respa[0]; double cut_out_off = cut_respa[1]; double cut_out_diff = cut_out_off - cut_out_on; double cut_out_on_sq = cut_out_on*cut_out_on; double cut_out_off_sq = cut_out_off*cut_out_off; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq < cut_out_off_sq) { r2inv = 1.0/rsq; r6inv = r2inv*r2inv*r2inv; jtype = type[j]; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); fpair = factor_lj*forcelj*r2inv; if (rsq > cut_out_on_sq) { rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; fpair *= 1.0 - rsw*rsw*(3.0 - 2.0*rsw); } 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; } } } } } /* ---------------------------------------------------------------------- */ void PairLJCut::compute_middle() { int i,j,ii,jj,inum,jnum,itype,jtype; double xtmp,ytmp,ztmp,delx,dely,delz,fpair; double rsq,r2inv,r6inv,forcelj,factor_lj,rsw; int *ilist,*jlist,*numneigh,**firstneigh; double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; - inum = listmiddle->inum; - ilist = listmiddle->ilist; - numneigh = listmiddle->numneigh; - firstneigh = listmiddle->firstneigh; + inum = list->inum_middle; + ilist = list->ilist_middle; + numneigh = list->numneigh_middle; + firstneigh = list->firstneigh_middle; double cut_in_off = cut_respa[0]; double cut_in_on = cut_respa[1]; double cut_out_on = cut_respa[2]; double cut_out_off = cut_respa[3]; double cut_in_diff = cut_in_on - cut_in_off; double cut_out_diff = cut_out_off - cut_out_on; double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; double cut_out_on_sq = cut_out_on*cut_out_on; double cut_out_off_sq = cut_out_off*cut_out_off; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq < cut_out_off_sq && rsq > cut_in_off_sq) { r2inv = 1.0/rsq; r6inv = r2inv*r2inv*r2inv; jtype = type[j]; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); fpair = factor_lj*forcelj*r2inv; if (rsq < cut_in_on_sq) { rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; fpair *= rsw*rsw*(3.0 - 2.0*rsw); } if (rsq > cut_out_on_sq) { rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; fpair *= 1.0 + rsw*rsw*(2.0*rsw - 3.0); } 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; } } } } } /* ---------------------------------------------------------------------- */ void PairLJCut::compute_outer(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; double rsq,r2inv,r6inv,forcelj,factor_lj,rsw; int *ilist,*jlist,*numneigh,**firstneigh; evdwl = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = 0; double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; - inum = listouter->inum; - ilist = listouter->ilist; - numneigh = listouter->numneigh; - firstneigh = listouter->firstneigh; + inum = list->inum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; double cut_in_off = cut_respa[2]; double cut_in_on = cut_respa[3]; double cut_in_diff = cut_in_on - cut_in_off; double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_lj = special_lj[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; if (rsq < cutsq[itype][jtype]) { if (rsq > cut_in_off_sq) { r2inv = 1.0/rsq; r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); fpair = factor_lj*forcelj*r2inv; if (rsq < cut_in_on_sq) { rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; fpair *= rsw*rsw*(3.0 - 2.0*rsw); } 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; } } if (eflag) { r2inv = 1.0/rsq; r6inv = r2inv*r2inv*r2inv; evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - offset[itype][jtype]; evdwl *= factor_lj; } if (vflag) { if (rsq <= cut_in_off_sq) { r2inv = 1.0/rsq; r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); fpair = factor_lj*forcelj*r2inv; } else if (rsq < cut_in_on_sq) fpair = factor_lj*forcelj*r2inv; } if (evflag) ev_tally(i,j,nlocal,newton_pair, evdwl,0.0,fpair,delx,dely,delz); } } } } /* ---------------------------------------------------------------------- allocate all arrays ------------------------------------------------------------------------- */ void PairLJCut::allocate() { allocated = 1; int n = atom->ntypes; 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(cutsq,n+1,n+1,"pair:cutsq"); memory->create(cut,n+1,n+1,"pair:cut"); memory->create(epsilon,n+1,n+1,"pair:epsilon"); memory->create(sigma,n+1,n+1,"pair:sigma"); memory->create(lj1,n+1,n+1,"pair:lj1"); memory->create(lj2,n+1,n+1,"pair:lj2"); memory->create(lj3,n+1,n+1,"pair:lj3"); memory->create(lj4,n+1,n+1,"pair:lj4"); memory->create(offset,n+1,n+1,"pair:offset"); } /* ---------------------------------------------------------------------- global settings ------------------------------------------------------------------------- */ void PairLJCut::settings(int narg, char **arg) { if (narg != 1) error->all(FLERR,"Illegal pair_style command"); cut_global = force->numeric(FLERR,arg[0]); // reset cutoffs that have been explicitly set if (allocated) { int i,j; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) if (setflag[i][j]) cut[i][j] = cut_global; } } /* ---------------------------------------------------------------------- set coeffs for one or more type pairs ------------------------------------------------------------------------- */ void PairLJCut::coeff(int narg, char **arg) { if (narg < 4 || narg > 5) error->all(FLERR,"Incorrect args for pair coefficients"); if (!allocated) allocate(); int ilo,ihi,jlo,jhi; force->bounds(FLERR,arg[0],atom->ntypes,ilo,ihi); force->bounds(FLERR,arg[1],atom->ntypes,jlo,jhi); double epsilon_one = force->numeric(FLERR,arg[2]); double sigma_one = force->numeric(FLERR,arg[3]); double cut_one = cut_global; if (narg == 5) cut_one = force->numeric(FLERR,arg[4]); int count = 0; for (int i = ilo; i <= ihi; i++) { for (int j = MAX(jlo,i); j <= jhi; j++) { epsilon[i][j] = epsilon_one; sigma[i][j] = sigma_one; cut[i][j] = cut_one; setflag[i][j] = 1; count++; } } if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- init specific to this pair style ------------------------------------------------------------------------- */ void PairLJCut::init_style() { - // request regular or rRESPA neighbor lists + // request regular or rRESPA neighbor list int irequest; + int respa = 0; if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { - int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; + } - if (respa == 0) irequest = neighbor->request(this,instance_me); - else if (respa == 1) { - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 1; - neighbor->requests[irequest]->respainner = 1; - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 3; - neighbor->requests[irequest]->respaouter = 1; - } else { - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 1; - neighbor->requests[irequest]->respainner = 1; - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 2; - neighbor->requests[irequest]->respamiddle = 1; - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 3; - neighbor->requests[irequest]->respaouter = 1; - } + irequest = neighbor->request(this,instance_me); - } else irequest = neighbor->request(this,instance_me); + if (respa >= 1) { + neighbor->requests[irequest]->respaouter = 1; + neighbor->requests[irequest]->respainner = 1; + } + if (respa == 2) neighbor->requests[irequest]->respamiddle = 1; // set rRESPA cutoffs if (strstr(update->integrate_style,"respa") && ((Respa *) update->integrate)->level_inner >= 0) cut_respa = ((Respa *) update->integrate)->cutoff; else cut_respa = NULL; } -/* ---------------------------------------------------------------------- - neighbor callback to inform pair style of neighbor list to use - regular or rRESPA -------------------------------------------------------------------------- */ - -void PairLJCut::init_list(int id, NeighList *ptr) -{ - if (id == 0) list = ptr; - else if (id == 1) listinner = ptr; - else if (id == 2) listmiddle = ptr; - else if (id == 3) listouter = ptr; -} - /* ---------------------------------------------------------------------- init for one type pair i,j and corresponding j,i ------------------------------------------------------------------------- */ double PairLJCut::init_one(int i, int j) { if (setflag[i][j] == 0) { epsilon[i][j] = mix_energy(epsilon[i][i],epsilon[j][j], sigma[i][i],sigma[j][j]); sigma[i][j] = mix_distance(sigma[i][i],sigma[j][j]); cut[i][j] = mix_distance(cut[i][i],cut[j][j]); } lj1[i][j] = 48.0 * epsilon[i][j] * pow(sigma[i][j],12.0); lj2[i][j] = 24.0 * epsilon[i][j] * pow(sigma[i][j],6.0); lj3[i][j] = 4.0 * epsilon[i][j] * pow(sigma[i][j],12.0); lj4[i][j] = 4.0 * epsilon[i][j] * pow(sigma[i][j],6.0); if (offset_flag && (cut[i][j] > 0.0)) { double ratio = sigma[i][j] / cut[i][j]; offset[i][j] = 4.0 * epsilon[i][j] * (pow(ratio,12.0) - pow(ratio,6.0)); } else offset[i][j] = 0.0; lj1[j][i] = lj1[i][j]; lj2[j][i] = lj2[i][j]; lj3[j][i] = lj3[i][j]; lj4[j][i] = lj4[i][j]; offset[j][i] = offset[i][j]; // check interior rRESPA cutoff if (cut_respa && cut[i][j] < cut_respa[3]) error->all(FLERR,"Pair cutoff < Respa interior cutoff"); // compute I,J contribution to long-range tail correction // count total # of atoms of type I and J via Allreduce if (tail_flag) { int *type = atom->type; int nlocal = atom->nlocal; double count[2],all[2]; count[0] = count[1] = 0.0; for (int k = 0; k < nlocal; k++) { if (type[k] == i) count[0] += 1.0; if (type[k] == j) count[1] += 1.0; } MPI_Allreduce(count,all,2,MPI_DOUBLE,MPI_SUM,world); double sig2 = sigma[i][j]*sigma[i][j]; double sig6 = sig2*sig2*sig2; double rc3 = cut[i][j]*cut[i][j]*cut[i][j]; double rc6 = rc3*rc3; double rc9 = rc3*rc6; etail_ij = 8.0*MY_PI*all[0]*all[1]*epsilon[i][j] * sig6 * (sig6 - 3.0*rc6) / (9.0*rc9); ptail_ij = 16.0*MY_PI*all[0]*all[1]*epsilon[i][j] * sig6 * (2.0*sig6 - 3.0*rc6) / (9.0*rc9); } return cut[i][j]; } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairLJCut::write_restart(FILE *fp) { write_restart_settings(fp); int i,j; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { fwrite(&setflag[i][j],sizeof(int),1,fp); if (setflag[i][j]) { fwrite(&epsilon[i][j],sizeof(double),1,fp); fwrite(&sigma[i][j],sizeof(double),1,fp); fwrite(&cut[i][j],sizeof(double),1,fp); } } } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairLJCut::read_restart(FILE *fp) { read_restart_settings(fp); allocate(); int i,j; int me = comm->me; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp); MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world); if (setflag[i][j]) { if (me == 0) { fread(&epsilon[i][j],sizeof(double),1,fp); fread(&sigma[i][j],sizeof(double),1,fp); fread(&cut[i][j],sizeof(double),1,fp); } MPI_Bcast(&epsilon[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&sigma[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&cut[i][j],1,MPI_DOUBLE,0,world); } } } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairLJCut::write_restart_settings(FILE *fp) { fwrite(&cut_global,sizeof(double),1,fp); fwrite(&offset_flag,sizeof(int),1,fp); fwrite(&mix_flag,sizeof(int),1,fp); fwrite(&tail_flag,sizeof(int),1,fp); } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairLJCut::read_restart_settings(FILE *fp) { int me = comm->me; if (me == 0) { fread(&cut_global,sizeof(double),1,fp); fread(&offset_flag,sizeof(int),1,fp); fread(&mix_flag,sizeof(int),1,fp); fread(&tail_flag,sizeof(int),1,fp); } MPI_Bcast(&cut_global,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(&tail_flag,1,MPI_INT,0,world); } /* ---------------------------------------------------------------------- proc 0 writes to data file ------------------------------------------------------------------------- */ void PairLJCut::write_data(FILE *fp) { for (int i = 1; i <= atom->ntypes; i++) fprintf(fp,"%d %g %g\n",i,epsilon[i][i],sigma[i][i]); } /* ---------------------------------------------------------------------- proc 0 writes all pairs to data file ------------------------------------------------------------------------- */ void PairLJCut::write_data_all(FILE *fp) { for (int i = 1; i <= atom->ntypes; i++) for (int j = i; j <= atom->ntypes; j++) fprintf(fp,"%d %d %g %g %g\n",i,j,epsilon[i][j],sigma[i][j],cut[i][j]); } /* ---------------------------------------------------------------------- */ double PairLJCut::single(int i, int j, int itype, int jtype, double rsq, double factor_coul, double factor_lj, double &fforce) { double r2inv,r6inv,forcelj,philj; r2inv = 1.0/rsq; r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); fforce = factor_lj*forcelj*r2inv; philj = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - offset[itype][jtype]; return factor_lj*philj; } /* ---------------------------------------------------------------------- */ void *PairLJCut::extract(const char *str, int &dim) { dim = 2; if (strcmp(str,"epsilon") == 0) return (void *) epsilon; if (strcmp(str,"sigma") == 0) return (void *) sigma; return NULL; } diff --git a/src/pair_lj_cut.h b/src/pair_lj_cut.h index 43eeda09c..3724685db 100644 --- a/src/pair_lj_cut.h +++ b/src/pair_lj_cut.h @@ -1,82 +1,81 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #ifdef PAIR_CLASS PairStyle(lj/cut,PairLJCut) #else #ifndef LMP_PAIR_LJ_CUT_H #define LMP_PAIR_LJ_CUT_H #include "pair.h" namespace LAMMPS_NS { class PairLJCut : public Pair { public: PairLJCut(class LAMMPS *); virtual ~PairLJCut(); virtual void compute(int, int); void settings(int, char **); void coeff(int, char **); void init_style(); - void init_list(int, class NeighList *); double init_one(int, int); void write_restart(FILE *); void read_restart(FILE *); void write_restart_settings(FILE *); void read_restart_settings(FILE *); void write_data(FILE *); void write_data_all(FILE *); double single(int, int, int, int, double, double, double, double &); void *extract(const char *, int &); void compute_inner(); void compute_middle(); void compute_outer(int, int); protected: double cut_global; double **cut; double **epsilon,**sigma; double **lj1,**lj2,**lj3,**lj4,**offset; double *cut_respa; virtual void allocate(); }; } #endif #endif /* ERROR/WARNING messages: E: Illegal ... command Self-explanatory. Check the input script syntax and compare to the documentation for the command. You can use -echo screen as a command-line option when running LAMMPS to see the offending line. E: Incorrect args for pair coefficients Self-explanatory. Check the input script or data file. E: Pair cutoff < Respa interior cutoff One or more pairwise cutoffs are too short to use with the specified rRESPA cutoffs. */ diff --git a/src/pair_mie_cut.cpp b/src/pair_mie_cut.cpp index 320f21248..04f8de8d7 100644 --- a/src/pair_mie_cut.cpp +++ b/src/pair_mie_cut.cpp @@ -1,738 +1,712 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- Contributing author: Cassiano Aimoli (aimoli@gmail.com) ------------------------------------------------------------------------- */ #include #include #include #include #include "pair_mie_cut.h" #include "atom.h" #include "comm.h" #include "force.h" #include "neighbor.h" #include "neigh_list.h" #include "neigh_request.h" #include "update.h" #include "integrate.h" #include "respa.h" #include "math_const.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; using namespace MathConst; /* ---------------------------------------------------------------------- */ PairMIECut::PairMIECut(LAMMPS *lmp) : Pair(lmp) { respa_enable = 1; } /* ---------------------------------------------------------------------- */ PairMIECut::~PairMIECut() { if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(cut); memory->destroy(epsilon); memory->destroy(sigma); memory->destroy(gamR); memory->destroy(gamA); memory->destroy(Cmie); memory->destroy(mie1); memory->destroy(mie2); memory->destroy(mie3); memory->destroy(mie4); memory->destroy(offset); } } /* ---------------------------------------------------------------------- */ void PairMIECut::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; double rsq,r2inv,rgamR,rgamA,forcemie,factor_mie; int *ilist,*jlist,*numneigh,**firstneigh; evdwl = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; double *special_mie = force->special_lj; int newton_pair = force->newton_pair; inum = list->inum; ilist = list->ilist; numneigh = list->numneigh; firstneigh = list->firstneigh; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_mie = special_mie[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; if (rsq < cutsq[itype][jtype]) { r2inv = 1.0/rsq; rgamA = pow(r2inv,(gamA[itype][jtype]/2.0)); rgamR = pow(r2inv,(gamR[itype][jtype]/2.0)); forcemie = (mie1[itype][jtype]*rgamR - mie2[itype][jtype]*rgamA); fpair = factor_mie*forcemie*r2inv; 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; } if (eflag) { evdwl = (mie3[itype][jtype]*rgamR - mie4[itype][jtype]*rgamA) - offset[itype][jtype]; evdwl *= factor_mie; } if (evflag) ev_tally(i,j,nlocal,newton_pair, evdwl,0.0,fpair,delx,dely,delz); } } } if (vflag_fdotr) virial_fdotr_compute(); } /* ---------------------------------------------------------------------- */ void PairMIECut::compute_inner() { int i,j,ii,jj,inum,jnum,itype,jtype; double xtmp,ytmp,ztmp,delx,dely,delz,fpair; double rsq,r2inv,rgamR,rgamA,forcemie,factor_mie,rsw; int *ilist,*jlist,*numneigh,**firstneigh; double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; double *special_mie = force->special_lj; int newton_pair = force->newton_pair; - inum = listinner->inum; - ilist = listinner->ilist; - numneigh = listinner->numneigh; - firstneigh = listinner->firstneigh; + inum = list->inum_inner; + ilist = list->ilist_inner; + numneigh = list->numneigh_inner; + firstneigh = list->firstneigh_inner; double cut_out_on = cut_respa[0]; double cut_out_off = cut_respa[1]; double cut_out_diff = cut_out_off - cut_out_on; double cut_out_on_sq = cut_out_on*cut_out_on; double cut_out_off_sq = cut_out_off*cut_out_off; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_mie = special_mie[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq < cut_out_off_sq) { jtype = type[j]; r2inv = 1.0/rsq; rgamA = pow(r2inv,(gamA[itype][jtype]/2.0)); rgamR = pow(r2inv,(gamR[itype][jtype]/2.0)); forcemie = (mie1[itype][jtype]*rgamR - mie2[itype][jtype]*rgamA); fpair = factor_mie*forcemie*r2inv; if (rsq > cut_out_on_sq) { rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; fpair *= 1.0 - rsw*rsw*(3.0 - 2.0*rsw); } 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; } } } } } /* ---------------------------------------------------------------------- */ void PairMIECut::compute_middle() { int i,j,ii,jj,inum,jnum,itype,jtype; double xtmp,ytmp,ztmp,delx,dely,delz,fpair; double rsq,r2inv,rgamR,rgamA,forcemie,factor_mie,rsw; int *ilist,*jlist,*numneigh,**firstneigh; double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; double *special_mie = force->special_lj; int newton_pair = force->newton_pair; - inum = listmiddle->inum; - ilist = listmiddle->ilist; - numneigh = listmiddle->numneigh; - firstneigh = listmiddle->firstneigh; + inum = list->inum_middle; + ilist = list->ilist_middle; + numneigh = list->numneigh_middle; + firstneigh = list->firstneigh_middle; double cut_in_off = cut_respa[0]; double cut_in_on = cut_respa[1]; double cut_out_on = cut_respa[2]; double cut_out_off = cut_respa[3]; double cut_in_diff = cut_in_on - cut_in_off; double cut_out_diff = cut_out_off - cut_out_on; double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; double cut_out_on_sq = cut_out_on*cut_out_on; double cut_out_off_sq = cut_out_off*cut_out_off; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_mie = special_mie[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; if (rsq < cut_out_off_sq && rsq > cut_in_off_sq) { jtype = type[j]; r2inv = 1.0/rsq; rgamA = pow(r2inv,(gamA[itype][jtype]/2.0)); rgamR = pow(r2inv,(gamR[itype][jtype]/2.0)); forcemie = (mie1[itype][jtype]*rgamR - mie2[itype][jtype]*rgamA); fpair = factor_mie*forcemie*r2inv; if (rsq < cut_in_on_sq) { rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; fpair *= rsw*rsw*(3.0 - 2.0*rsw); } if (rsq > cut_out_on_sq) { rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; fpair *= 1.0 + rsw*rsw*(2.0*rsw - 3.0); } 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; } } } } } /* ---------------------------------------------------------------------- */ void PairMIECut::compute_outer(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; double rsq,r2inv,rgamR,rgamA,forcemie,factor_mie,rsw; int *ilist,*jlist,*numneigh,**firstneigh; evdwl = 0.0; if (eflag || vflag) ev_setup(eflag,vflag); else evflag = 0; double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; double *special_mie = force->special_lj; int newton_pair = force->newton_pair; - inum = listouter->inum; - ilist = listouter->ilist; - numneigh = listouter->numneigh; - firstneigh = listouter->firstneigh; + inum = list->inum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; double cut_in_off = cut_respa[2]; double cut_in_on = cut_respa[3]; double cut_in_diff = cut_in_on - cut_in_off; double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; // loop over neighbors of my atoms for (ii = 0; ii < inum; ii++) { i = ilist[ii]; xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; factor_mie = special_mie[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; jtype = type[j]; if (rsq < cutsq[itype][jtype]) { if (rsq > cut_in_off_sq) { r2inv = 1.0/rsq; rgamA = pow(r2inv,(gamA[itype][jtype]/2.0)); rgamR = pow(r2inv,(gamR[itype][jtype]/2.0)); forcemie = (mie1[itype][jtype]*rgamR - mie2[itype][jtype]*rgamA); fpair = factor_mie*forcemie*r2inv; if (rsq < cut_in_on_sq) { rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; fpair *= rsw*rsw*(3.0 - 2.0*rsw); } 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; } } if (eflag) { r2inv = 1.0/rsq; rgamA = pow(r2inv,(gamA[itype][jtype]/2.0)); rgamR = pow(r2inv,(gamR[itype][jtype]/2.0)); evdwl = (mie3[itype][jtype]*rgamR - mie4[itype][jtype]*rgamA) - offset[itype][jtype]; evdwl *= factor_mie; } if (vflag) { if (rsq <= cut_in_off_sq) { r2inv = 1.0/rsq; rgamA = pow(r2inv,(gamA[itype][jtype]/2.0)); rgamR = pow(r2inv,(gamR[itype][jtype]/2.0)); forcemie = (mie1[itype][jtype]*rgamR - mie2[itype][jtype]*rgamA); fpair = factor_mie*forcemie*r2inv; } else if (rsq < cut_in_on_sq) fpair = factor_mie*forcemie*r2inv; } if (evflag) ev_tally(i,j,nlocal,newton_pair, evdwl,0.0,fpair,delx,dely,delz); } } } } /* ---------------------------------------------------------------------- allocate all arrays ------------------------------------------------------------------------- */ void PairMIECut::allocate() { allocated = 1; int n = atom->ntypes; 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(cutsq,n+1,n+1,"pair:cutsq"); memory->create(cut,n+1,n+1,"pair:cut"); memory->create(epsilon,n+1,n+1,"pair:epsilon"); memory->create(sigma,n+1,n+1,"pair:sigma"); memory->create(gamR,n+1,n+1,"pair:gamR"); memory->create(gamA,n+1,n+1,"pair:gamA"); memory->create(Cmie,n+1,n+1,"pair:Cmie"); memory->create(mie1,n+1,n+1,"pair:mie1"); memory->create(mie2,n+1,n+1,"pair:mie2"); memory->create(mie3,n+1,n+1,"pair:mie3"); memory->create(mie4,n+1,n+1,"pair:mie4"); memory->create(offset,n+1,n+1,"pair:offset"); } /* ---------------------------------------------------------------------- global settings ------------------------------------------------------------------------- */ void PairMIECut::settings(int narg, char **arg) { if (narg != 1) error->all(FLERR,"Illegal pair_style command"); cut_global = force->numeric(FLERR,arg[0]); // reset cutoffs that have been explicitly set if (allocated) { int i,j; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) if (setflag[i][j]) cut[i][j] = cut_global; } } /* ---------------------------------------------------------------------- set coeffs for one or more type pairs ------------------------------------------------------------------------- */ void PairMIECut::coeff(int narg, char **arg) { if (narg < 6 || narg > 7) error->all(FLERR,"Incorrect args for pair coefficients"); if (!allocated) allocate(); int ilo,ihi,jlo,jhi; force->bounds(FLERR,arg[0],atom->ntypes,ilo,ihi); force->bounds(FLERR,arg[1],atom->ntypes,jlo,jhi); double epsilon_one = force->numeric(FLERR,arg[2]); double sigma_one = force->numeric(FLERR,arg[3]); double gamR_one = force->numeric(FLERR,arg[4]); double gamA_one = force->numeric(FLERR,arg[5]); double cut_one = cut_global; if (narg == 7) cut_one = force->numeric(FLERR,arg[6]); int count = 0; for (int i = ilo; i <= ihi; i++) { for (int j = MAX(jlo,i); j <= jhi; j++) { epsilon[i][j] = epsilon_one; sigma[i][j] = sigma_one; gamR[i][j] = gamR_one; gamA[i][j] = gamA_one; cut[i][j] = cut_one; setflag[i][j] = 1; count++; } } if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- init specific to this pair style ------------------------------------------------------------------------- */ void PairMIECut::init_style() { - // request regular or rRESPA neighbor lists + // request regular or rRESPA neighbor list int irequest; + int respa = 0; if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { - int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; + } - if (respa == 0) irequest = neighbor->request(this,instance_me); - else if (respa == 1) { - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 1; - neighbor->requests[irequest]->respainner = 1; - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 3; - neighbor->requests[irequest]->respaouter = 1; - } else { - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 1; - neighbor->requests[irequest]->respainner = 1; - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 2; - neighbor->requests[irequest]->respamiddle = 1; - irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->id = 3; - neighbor->requests[irequest]->respaouter = 1; - } + irequest = neighbor->request(this,instance_me); - } else irequest = neighbor->request(this,instance_me); + if (respa >= 1) { + neighbor->requests[irequest]->respaouter = 1; + neighbor->requests[irequest]->respainner = 1; + } + if (respa == 2) neighbor->requests[irequest]->respamiddle = 1; // set rRESPA cutoffs if (strstr(update->integrate_style,"respa") && ((Respa *) update->integrate)->level_inner >= 0) cut_respa = ((Respa *) update->integrate)->cutoff; else cut_respa = NULL; } -/* ---------------------------------------------------------------------- - neighbor callback to inform pair style of neighbor list to use - regular or rRESPA -------------------------------------------------------------------------- */ - -void PairMIECut::init_list(int id, NeighList *ptr) -{ - if (id == 0) list = ptr; - else if (id == 1) listinner = ptr; - else if (id == 2) listmiddle = ptr; - else if (id == 3) listouter = ptr; -} - /* ---------------------------------------------------------------------- init for one type pair i,j and corresponding j,i ------------------------------------------------------------------------- */ double PairMIECut::init_one(int i, int j) { if (setflag[i][j] == 0) { epsilon[i][j] = mix_energy(epsilon[i][i],epsilon[j][j], sigma[i][i],sigma[j][j]); sigma[i][j] = mix_distance(sigma[i][i],sigma[j][j]); gamR[i][j] = mix_distance(gamR[i][i],gamR[j][j]); gamA[i][j] = mix_distance(gamA[i][i],gamA[j][j]); cut[i][j] = mix_distance(cut[i][i],cut[j][j]); } gamA[j][i] = gamA[i][j]; gamR[j][i] = gamR[i][j]; Cmie[i][j] = (gamR[i][j]/(gamR[i][j]-gamA[i][j]) * pow((gamR[i][j]/gamA[i][j]), (gamA[i][j]/(gamR[i][j]-gamA[i][j])))); mie1[i][j] = Cmie[i][j] * gamR[i][j]* epsilon[i][j] * pow(sigma[i][j],gamR[i][j]); mie2[i][j] = Cmie[i][j] * gamA[i][j] * epsilon[i][j] * pow(sigma[i][j],gamA[i][j]); mie3[i][j] = Cmie[i][j] * epsilon[i][j] * pow(sigma[i][j],gamR[i][j]); mie4[i][j] = Cmie[i][j] * epsilon[i][j] * pow(sigma[i][j],gamA[i][j]); if (offset_flag && (cut[i][j] > 0.0)) { double ratio = sigma[i][j] / cut[i][j]; offset[i][j] = Cmie[i][j] * epsilon[i][j] * (pow(ratio,gamR[i][j]) - pow(ratio,gamA[i][j])); } else offset[i][j] = 0.0; mie1[j][i] = mie1[i][j]; mie2[j][i] = mie2[i][j]; mie3[j][i] = mie3[i][j]; mie4[j][i] = mie4[i][j]; offset[j][i] = offset[i][j]; // check interior rRESPA cutoff if (cut_respa && cut[i][j] < cut_respa[3]) error->all(FLERR,"Pair cutoff < Respa interior cutoff"); // compute I,J contribution to long-range tail correction // count total # of atoms of type I and J via Allreduce if (tail_flag) { int *type = atom->type; int nlocal = atom->nlocal; double count[2],all[2]; count[0] = count[1] = 0.0; for (int k = 0; k < nlocal; k++) { if (type[k] == i) count[0] += 1.0; if (type[k] == j) count[1] += 1.0; } MPI_Allreduce(count,all,2,MPI_DOUBLE,MPI_SUM,world); double siggamA = pow(sigma[i][j],gamA[i][j]); double siggamR = pow(sigma[i][j],gamR[i][j]); double rcgamA = pow(cut[i][j],(gamA[i][j]-3.0)); double rcgamR = pow(cut[i][j],(gamR[i][j]-3.0)); etail_ij = Cmie[i][j]*2.0*MY_PI*all[0]*all[1]*epsilon[i][j]* (siggamR/((gamR[i][j]-3.0)*rcgamR)-siggamA/((gamA[i][j]-3.0)*rcgamA)); ptail_ij = Cmie[i][j]*2.0*MY_PI*all[0]*all[1]*epsilon[i][j]/3.0* ((gamR[i][j]/(gamR[i][j]-3.0))*siggamR/rcgamR- (gamA[i][j]/(gamA[i][j]-3.0))*siggamA/rcgamA); } return cut[i][j]; } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairMIECut::write_restart(FILE *fp) { write_restart_settings(fp); int i,j; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { fwrite(&setflag[i][j],sizeof(int),1,fp); if (setflag[i][j]) { fwrite(&epsilon[i][j],sizeof(double),1,fp); fwrite(&sigma[i][j],sizeof(double),1,fp); fwrite(&gamR[i][j],sizeof(double),1,fp); fwrite(&gamA[i][j],sizeof(double),1,fp); fwrite(&cut[i][j],sizeof(double),1,fp); } } } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairMIECut::read_restart(FILE *fp) { read_restart_settings(fp); allocate(); int i,j; int me = comm->me; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp); MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world); if (setflag[i][j]) { if (me == 0) { fread(&epsilon[i][j],sizeof(double),1,fp); fread(&sigma[i][j],sizeof(double),1,fp); fread(&gamR[i][j],sizeof(double),1,fp); fread(&gamA[i][j],sizeof(double),1,fp); fread(&cut[i][j],sizeof(double),1,fp); } MPI_Bcast(&epsilon[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&sigma[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&gamR[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&gamA[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&cut[i][j],1,MPI_DOUBLE,0,world); } } } /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ void PairMIECut::write_restart_settings(FILE *fp) { fwrite(&cut_global,sizeof(double),1,fp); fwrite(&offset_flag,sizeof(int),1,fp); fwrite(&mix_flag,sizeof(int),1,fp); fwrite(&tail_flag,sizeof(int),1,fp); } /* ---------------------------------------------------------------------- proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ void PairMIECut::read_restart_settings(FILE *fp) { int me = comm->me; if (me == 0) { fread(&cut_global,sizeof(double),1,fp); fread(&offset_flag,sizeof(int),1,fp); fread(&mix_flag,sizeof(int),1,fp); fread(&tail_flag,sizeof(int),1,fp); } MPI_Bcast(&cut_global,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(&tail_flag,1,MPI_INT,0,world); } /* ---------------------------------------------------------------------- */ double PairMIECut::single(int i, int j, int itype, int jtype, double rsq, double factor_coul, double factor_mie, double &fforce) { double r2inv,rgamR,rgamA,forcemie,phimie; r2inv = 1.0/rsq; rgamA = pow(r2inv,(gamA[itype][jtype]/2.0)); rgamR = pow(r2inv,(gamR[itype][jtype]/2.0)); forcemie = (mie1[itype][jtype]*rgamR - mie2[itype][jtype]*rgamA); fforce = factor_mie*forcemie*r2inv; phimie = (mie3[itype][jtype]*rgamR - mie4[itype][jtype]*rgamA) - offset[itype][jtype]; return factor_mie*phimie; } /* ---------------------------------------------------------------------- */ void *PairMIECut::extract(const char *str, int &dim) { dim = 2; if (strcmp(str,"epsilon") == 0) return (void *) epsilon; if (strcmp(str,"sigma") == 0) return (void *) sigma; if (strcmp(str,"gamR") == 0) return (void *) gamR; if (strcmp(str,"gamA") == 0) return (void *) gamA; return NULL; } diff --git a/src/pair_mie_cut.h b/src/pair_mie_cut.h index 2a0a29843..9e12438d1 100644 --- a/src/pair_mie_cut.h +++ b/src/pair_mie_cut.h @@ -1,81 +1,80 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #ifdef PAIR_CLASS PairStyle(mie/cut,PairMIECut) #else #ifndef LMP_PAIR_MIE_CUT_H #define LMP_PAIR_MIE_CUT_H #include "pair.h" namespace LAMMPS_NS { class PairMIECut : public Pair { public: PairMIECut(class LAMMPS *); virtual ~PairMIECut(); virtual void compute(int, int); void settings(int, char **); void coeff(int, char **); void init_style(); - void init_list(int, class NeighList *); double init_one(int, int); void write_restart(FILE *); void read_restart(FILE *); void write_restart_settings(FILE *); void read_restart_settings(FILE *); double single(int, int, int, int, double, double, double, double &); void *extract(const char *, int &); void compute_inner(); void compute_middle(); void compute_outer(int, int); protected: double cut_global; double **cut; double **epsilon,**sigma; double **gamR,**gamA,**Cmie; double **mie1,**mie2,**mie3,**mie4,**offset; double *cut_respa; void allocate(); }; } #endif #endif /* ERROR/WARNING messages: E: Illegal ... command Self-explanatory. Check the input script syntax and compare to the documentation for the command. You can use -echo screen as a command-line option when running LAMMPS to see the offending line. E: Incorrect args for pair coefficients Self-explanatory. Check the input script or data file. E: Pair cutoff < Respa interior cutoff One or more pairwise cutoffs are too short to use with the specified rRESPA cutoffs. */ diff --git a/src/respa.cpp b/src/respa.cpp index 5d51ff64e..23cd94183 100644 --- a/src/respa.cpp +++ b/src/respa.cpp @@ -1,878 +1,885 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- Contributing authors: Mark Stevens (SNL), Paul Crozier (SNL) ------------------------------------------------------------------------- */ #include #include #include "respa.h" #include "neighbor.h" #include "atom.h" #include "atom_vec.h" #include "domain.h" #include "comm.h" #include "force.h" #include "pair.h" #include "bond.h" #include "angle.h" #include "dihedral.h" #include "improper.h" #include "kspace.h" #include "output.h" #include "update.h" #include "modify.h" #include "compute.h" #include "fix_respa.h" #include "timer.h" #include "memory.h" #include "error.h" #include "pair_hybrid.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ Respa::Respa(LAMMPS *lmp, int narg, char **arg) : Integrate(lmp, narg, arg), step(NULL), loop(NULL), hybrid_level(NULL), hybrid_compute(NULL), newton(NULL), fix_respa(NULL) { nhybrid_styles = 0; if (narg < 1) error->all(FLERR,"Illegal run_style respa command"); nlevels = force->inumeric(FLERR,arg[0]); if (nlevels < 1) error->all(FLERR,"Respa levels must be >= 1"); if (narg < nlevels) error->all(FLERR,"Illegal run_style respa command"); loop = new int[nlevels]; for (int iarg = 1; iarg < nlevels; iarg++) { loop[iarg-1] = force->inumeric(FLERR,arg[iarg]); if (loop[iarg-1] <= 0) error->all(FLERR,"Illegal run_style respa command"); } loop[nlevels-1] = 1; // set level at which each force is computed // argument settings override defaults level_bond = level_angle = level_dihedral = level_improper = -1; level_pair = level_kspace = -1; level_inner = level_middle = level_outer = -1; // defaults for hybrid pair styles nhybrid_styles = 0; tally_global = 1; pair_compute = 1; int iarg = nlevels; while (iarg < narg) { if (strcmp(arg[iarg],"bond") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal run_style respa command"); level_bond = force->inumeric(FLERR,arg[iarg+1]) - 1; iarg += 2; } else if (strcmp(arg[iarg],"angle") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal run_style respa command"); level_angle = force->inumeric(FLERR,arg[iarg+1]) - 1; iarg += 2; } else if (strcmp(arg[iarg],"dihedral") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal run_style respa command"); level_dihedral = force->inumeric(FLERR,arg[iarg+1]) - 1; iarg += 2; } else if (strcmp(arg[iarg],"improper") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal run_style respa command"); level_improper = force->inumeric(FLERR,arg[iarg+1]) - 1; iarg += 2; } else if (strcmp(arg[iarg],"pair") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal run_style respa command"); level_pair = force->inumeric(FLERR,arg[iarg+1]) - 1; iarg += 2; } else if (strcmp(arg[iarg],"inner") == 0) { if (iarg+4 > narg) error->all(FLERR,"Illegal run_style respa command"); level_inner = force->inumeric(FLERR,arg[iarg+1]) - 1; cutoff[0] = force->numeric(FLERR,arg[iarg+2]); cutoff[1] = force->numeric(FLERR,arg[iarg+3]); iarg += 4; } else if (strcmp(arg[iarg],"middle") == 0) { if (iarg+4 > narg) error->all(FLERR,"Illegal run_style respa command"); level_middle = force->inumeric(FLERR,arg[iarg+1]) - 1; cutoff[2] = force->numeric(FLERR,arg[iarg+2]); cutoff[3] = force->numeric(FLERR,arg[iarg+3]); iarg += 4; } else if (strcmp(arg[iarg],"outer") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal run_style respa command"); level_outer = force->inumeric(FLERR,arg[iarg+1]) - 1; iarg += 2; } else if (strcmp(arg[iarg],"kspace") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal run_style respa command"); level_kspace = force->inumeric(FLERR,arg[iarg+1]) - 1; iarg += 2; } else if (strcmp(arg[iarg],"hybrid") == 0) { // the hybrid keyword requires a hybrid pair style if (!strstr(force->pair_style,"hybrid")) error->all(FLERR,"Illegal run_style respa command"); PairHybrid *hybrid = (PairHybrid *) force->pair; nhybrid_styles = hybrid->nstyles; // each hybrid sub-style needs to be assigned to a respa level if (iarg+nhybrid_styles > narg) error->all(FLERR,"Illegal run_style respa command"); hybrid_level = new int[nhybrid_styles]; hybrid_compute = new int[nhybrid_styles]; for (int i=0; i < nhybrid_styles; ++i) { ++iarg; hybrid_level[i] = force->inumeric(FLERR,arg[iarg])-1; } ++iarg; } else error->all(FLERR,"Illegal run_style respa command"); } // cannot specify both pair and inner/middle/outer if (level_pair >= 0 && (level_inner >= 0 || level_middle >= 0 || level_outer >= 0)) error->all(FLERR,"Cannot set both respa pair and inner/middle/outer"); // if either inner and outer is specified, then both must be if ((level_inner >= 0 && level_outer == -1) || (level_outer >= 0 && level_inner == -1)) error->all(FLERR,"Must set both respa inner and outer"); // middle cannot be set without inner/outer if (level_middle >= 0 && level_inner == -1) error->all(FLERR,"Cannot set respa middle without inner/outer"); // cannot combine hybrid with any of pair/inner/middle/outer if ((nhybrid_styles > 0) && (level_pair >= 0 || level_inner >= 0 || level_middle >= 0 || level_outer >= 0)) error->all(FLERR,"Cannot set respa hybrid and " "any of pair/inner/middle/outer"); // set defaults if user did not specify level // bond to innermost level // angle same as bond, dihedral same as angle, improper same as dihedral // pair to outermost level if no inner/middle/outer // inner/middle/outer have no defaults // kspace same as pair or outer if (level_bond == -1) level_bond = 0; if (level_angle == -1) level_angle = level_bond; if (level_dihedral == -1) level_dihedral = level_angle; if (level_improper == -1) level_improper = level_dihedral; if (level_pair == -1 && level_inner == -1 && nhybrid_styles < 1) level_pair = nlevels-1; if (level_kspace == -1 && level_pair >= 0) level_kspace = level_pair; if (level_kspace == -1 && level_pair == -1) { if (nhybrid_styles < 1) { level_kspace = level_outer; } else { int max_hybrid_level = -1; for (int i=0; i < nhybrid_styles; ++i) { if (max_hybrid_level < hybrid_level[i]) max_hybrid_level = hybrid_level[i]; } level_kspace = max_hybrid_level; } } // print respa levels if (comm->me == 0) { if (screen) { fprintf(screen,"Respa levels:\n"); for (int i = 0; i < nlevels; i++) { fprintf(screen," %d =",i+1); if (level_bond == i) fprintf(screen," bond"); if (level_angle == i) fprintf(screen," angle"); if (level_dihedral == i) fprintf(screen," dihedral"); if (level_improper == i) fprintf(screen," improper"); if (level_pair == i) fprintf(screen," pair"); if (level_inner == i) fprintf(screen," pair-inner"); if (level_middle == i) fprintf(screen," pair-middle"); if (level_outer == i) fprintf(screen," pair-outer"); for (int j=0;jall(FLERR,"Invalid order of forces within respa levels"); if (level_pair >= 0) { if (level_pair < level_improper || level_kspace < level_pair) error->all(FLERR,"Invalid order of forces within respa levels"); } if (level_pair == -1 && level_middle == -1 && nhybrid_styles < 1) { if (level_inner < level_improper || level_outer < level_inner || level_kspace < level_outer) error->all(FLERR,"Invalid order of forces within respa levels"); } if (level_pair == -1 && level_middle >= 0) { if (level_inner < level_improper || level_middle < level_inner || level_outer < level_inner || level_kspace < level_outer) error->all(FLERR,"Invalid order of forces within respa levels"); } // warn if any levels are devoid of forces int flag = 0; for (int i = 0; i < nlevels; i++) if (level_bond != i && level_angle != i && level_dihedral != i && level_improper != i && level_pair != i && level_inner != i && level_middle != i && level_outer != i && level_kspace != i) flag = 1; if (flag && comm->me == 0) error->warning(FLERR,"One or more respa levels compute no forces"); // check cutoff consistency if inner/middle/outer are enabled if (level_inner >= 0 && cutoff[1] < cutoff[0]) error->all(FLERR,"Respa inner cutoffs are invalid"); if (level_middle >= 0 && (cutoff[3] < cutoff[2] || cutoff[2] < cutoff[1])) error->all(FLERR,"Respa middle cutoffs are invalid"); // set outer pair of cutoffs to inner pair if middle is not enabled if (level_inner >= 0 && level_middle < 0) { cutoff[2] = cutoff[0]; cutoff[3] = cutoff[1]; } // ensure that pair->compute() is run properly // when the hybrid keyword is not used if (nhybrid_styles < 1) { pair_compute = 1; tally_global = 1; } // allocate other needed arrays newton = new int[nlevels]; step = new double[nlevels]; } /* ---------------------------------------------------------------------- */ Respa::~Respa() { delete [] loop; delete [] newton; delete [] step; if (nhybrid_styles > 0) { delete [] hybrid_level; delete [] hybrid_compute; } } /* ---------------------------------------------------------------------- initialization before run ------------------------------------------------------------------------- */ void Respa::init() { Integrate::init(); // warn if no fixes if (modify->nfix == 0 && comm->me == 0) error->warning(FLERR,"No fixes defined, atoms won't move"); // create fix needed for storing atom-based respa level forces // will delete it at end of run char **fixarg = new char*[5]; fixarg[0] = (char *) "RESPA"; fixarg[1] = (char *) "all"; fixarg[2] = (char *) "RESPA"; fixarg[3] = new char[8]; sprintf(fixarg[3],"%d",nlevels); // if supported, we also store torques on a per-level basis if (atom->torque_flag) { fixarg[4] = (char *) "torque"; modify->add_fix(5,fixarg); } else { modify->add_fix(4,fixarg); } delete [] fixarg[3]; delete [] fixarg; fix_respa = (FixRespa *) modify->fix[modify->nfix-1]; // insure respa inner/middle/outer is using Pair class that supports it if (level_inner >= 0) if (force->pair && force->pair->respa_enable == 0) error->all(FLERR,"Pair style does not support rRESPA inner/middle/outer"); // virial_style = 1 (explicit) since never computed implicitly like Verlet virial_style = 1; // setup lists of computes for global and per-atom PE and pressure ev_setup(); // detect if fix omp is present and will clear force arrays int ifix = modify->find_fix("package_omp"); if (ifix >= 0) external_force_clear = 1; // set flags for arrays to clear in force_clear() torqueflag = extraflag = 0; if (atom->torque_flag) torqueflag = 1; if (atom->avec->forceclearflag) extraflag = 1; // step[] = timestep for each level step[nlevels-1] = update->dt; for (int ilevel = nlevels-2; ilevel >= 0; ilevel--) step[ilevel] = step[ilevel+1]/loop[ilevel]; // set newton flag for each level for (int ilevel = 0; ilevel < nlevels; ilevel++) { newton[ilevel] = 0; if (force->newton_bond) { if (level_bond == ilevel || level_angle == ilevel || level_dihedral == ilevel || level_improper == ilevel) newton[ilevel] = 1; } if (force->newton_pair) { if (level_pair == ilevel || level_inner == ilevel || level_middle == ilevel || level_outer == ilevel) newton[ilevel] = 1; if (nhybrid_styles > 0) { set_compute_flags(ilevel); if (pair_compute) newton[ilevel] = 1; } } } // orthogonal vs triclinic simulation box triclinic = domain->triclinic; } /* ---------------------------------------------------------------------- setup before run ------------------------------------------------------------------------- */ void Respa::setup(int flag) { if (comm->me == 0 && screen) { fprintf(screen,"Setting up r-RESPA run ...\n"); if (flag) { fprintf(screen," Unit style : %s\n", update->unit_style); fprintf(screen," Current step : " BIGINT_FORMAT "\n", update->ntimestep); fprintf(screen," Time steps :"); for (int ilevel=0; ilevel < nlevels; ++ilevel) fprintf(screen," %d:%g",ilevel+1, step[ilevel]); fprintf(screen,"\n r-RESPA fixes :"); for (int l=0; l < modify->n_post_force_respa; ++l) { Fix *f = modify->fix[modify->list_post_force_respa[l]]; if (f->respa_level >= 0) fprintf(screen," %d:%s[%s]", MIN(f->respa_level+1,nlevels),f->style,f->id); } fprintf(screen,"\n"); timer->print_timeout(screen); } } update->setupflag = 1; // setup domain, communication and neighboring // acquire ghosts // build neighbor lists atom->setup(); modify->setup_pre_exchange(); if (triclinic) domain->x2lamda(atom->nlocal); domain->pbc(); domain->reset_box(); comm->setup(); if (neighbor->style) neighbor->setup_bins(); comm->exchange(); if (atom->sortfreq > 0) atom->sort(); comm->borders(); if (triclinic) domain->lamda2x(atom->nlocal+atom->nghost); domain->image_check(); domain->box_too_small_check(); modify->setup_pre_neighbor(); neighbor->build(); + modify->setup_post_neighbor(); neighbor->ncalls = 0; // compute all forces force->setup(); ev_set(update->ntimestep); for (int ilevel = 0; ilevel < nlevels; ilevel++) { force_clear(newton[ilevel]); modify->setup_pre_force_respa(vflag,ilevel); if (nhybrid_styles > 0) { set_compute_flags(ilevel); force->pair->compute(eflag,vflag); } if (level_pair == ilevel && pair_compute_flag) force->pair->compute(eflag,vflag); if (level_inner == ilevel && pair_compute_flag) force->pair->compute_inner(); if (level_middle == ilevel && pair_compute_flag) force->pair->compute_middle(); if (level_outer == ilevel && pair_compute_flag) force->pair->compute_outer(eflag,vflag); if (level_bond == ilevel && force->bond) force->bond->compute(eflag,vflag); if (level_angle == ilevel && force->angle) force->angle->compute(eflag,vflag); if (level_dihedral == ilevel && force->dihedral) force->dihedral->compute(eflag,vflag); if (level_improper == ilevel && force->improper) force->improper->compute(eflag,vflag); if (level_kspace == ilevel && force->kspace) { force->kspace->setup(); if (kspace_compute_flag) force->kspace->compute(eflag,vflag); } modify->setup_pre_reverse(eflag,vflag); if (newton[ilevel]) comm->reverse_comm(); copy_f_flevel(ilevel); } sum_flevel_f(); modify->setup(vflag); output->setup(flag); update->setupflag = 0; } /* ---------------------------------------------------------------------- setup without output flag = 0 = just force calculation flag = 1 = reneighbor and force calculation ------------------------------------------------------------------------- */ void Respa::setup_minimal(int flag) { update->setupflag = 1; // setup domain, communication and neighboring // acquire ghosts // build neighbor lists if (flag) { modify->setup_pre_exchange(); if (triclinic) domain->x2lamda(atom->nlocal); domain->pbc(); domain->reset_box(); comm->setup(); if (neighbor->style) neighbor->setup_bins(); comm->exchange(); comm->borders(); if (triclinic) domain->lamda2x(atom->nlocal+atom->nghost); domain->image_check(); domain->box_too_small_check(); modify->setup_pre_neighbor(); neighbor->build(); + modify->setup_post_neighbor(); neighbor->ncalls = 0; } // compute all forces ev_set(update->ntimestep); for (int ilevel = 0; ilevel < nlevels; ilevel++) { force_clear(newton[ilevel]); modify->setup_pre_force_respa(vflag,ilevel); if (nhybrid_styles > 0) { set_compute_flags(ilevel); force->pair->compute(eflag,vflag); } if (level_pair == ilevel && pair_compute_flag) force->pair->compute(eflag,vflag); if (level_inner == ilevel && pair_compute_flag) force->pair->compute_inner(); if (level_middle == ilevel && pair_compute_flag) force->pair->compute_middle(); if (level_outer == ilevel && pair_compute_flag) force->pair->compute_outer(eflag,vflag); if (level_bond == ilevel && force->bond) force->bond->compute(eflag,vflag); if (level_angle == ilevel && force->angle) force->angle->compute(eflag,vflag); if (level_dihedral == ilevel && force->dihedral) force->dihedral->compute(eflag,vflag); if (level_improper == ilevel && force->improper) force->improper->compute(eflag,vflag); if (level_kspace == ilevel && force->kspace) { force->kspace->setup(); if (kspace_compute_flag) force->kspace->compute(eflag,vflag); } modify->setup_pre_reverse(eflag,vflag); if (newton[ilevel]) comm->reverse_comm(); copy_f_flevel(ilevel); } sum_flevel_f(); modify->setup(vflag); update->setupflag = 0; } /* ---------------------------------------------------------------------- run for N steps ------------------------------------------------------------------------- */ void Respa::run(int n) { bigint ntimestep; for (int i = 0; i < n; i++) { if (timer->check_timeout(i)) { update->nsteps = i; break; } ntimestep = ++update->ntimestep; ev_set(ntimestep); recurse(nlevels-1); // needed in case end_of_step() or output() use total force sum_flevel_f(); if (modify->n_end_of_step) { timer->stamp(); modify->end_of_step(); timer->stamp(Timer::MODIFY); } if (ntimestep == output->next) { timer->stamp(); output->write(update->ntimestep); timer->stamp(Timer::OUTPUT); } } } /* ---------------------------------------------------------------------- delete rRESPA fix at end of run, so its atom arrays won't persist ------------------------------------------------------------------------- */ void Respa::cleanup() { modify->post_run(); modify->delete_fix("RESPA"); domain->box_too_small_check(); update->update_time(); } /* ---------------------------------------------------------------------- */ void Respa::reset_dt() { step[nlevels-1] = update->dt; for (int ilevel = nlevels-2; ilevel >= 0; ilevel--) step[ilevel] = step[ilevel+1]/loop[ilevel]; } /* ---------------------------------------------------------------------- */ void Respa::recurse(int ilevel) { copy_flevel_f(ilevel); for (int iloop = 0; iloop < loop[ilevel]; iloop++) { timer->stamp(); modify->initial_integrate_respa(vflag,ilevel,iloop); if (modify->n_post_integrate_respa) modify->post_integrate_respa(ilevel,iloop); timer->stamp(Timer::MODIFY); // at outermost level, check on rebuilding neighbor list // at innermost level, communicate // at middle levels, do nothing if (ilevel == nlevels-1) { int nflag = neighbor->decide(); if (nflag) { if (modify->n_pre_exchange) { timer->stamp(); modify->pre_exchange(); timer->stamp(Timer::MODIFY); } if (triclinic) domain->x2lamda(atom->nlocal); domain->pbc(); if (domain->box_change) { domain->reset_box(); comm->setup(); if (neighbor->style) neighbor->setup_bins(); } timer->stamp(); comm->exchange(); if (atom->sortfreq > 0 && update->ntimestep >= atom->nextsort) atom->sort(); comm->borders(); if (triclinic) domain->lamda2x(atom->nlocal+atom->nghost); timer->stamp(Timer::COMM); if (modify->n_pre_neighbor) { modify->pre_neighbor(); timer->stamp(Timer::MODIFY); } neighbor->build(); timer->stamp(Timer::NEIGH); + if (modify->n_post_neighbor) { + modify->post_neighbor(); + timer->stamp(Timer::MODIFY); + } + } else if (ilevel == 0) { timer->stamp(); comm->forward_comm(); timer->stamp(Timer::COMM); } } else if (ilevel == 0) { timer->stamp(); comm->forward_comm(); timer->stamp(Timer::COMM); } // rRESPA recursion thru all levels // this used to be before neigh list build, // which prevented per-atom energy/stress being tallied correctly // b/c atoms migrated to new procs between short/long force calls // now they migrate at very start of rRESPA timestep, before all forces if (ilevel) recurse(ilevel-1); // force computations // important that ordering is same as Verlet // so that any order dependencies are the same // when potentials are invoked at same level force_clear(newton[ilevel]); if (modify->n_pre_force_respa) { timer->stamp(); modify->pre_force_respa(vflag,ilevel,iloop); timer->stamp(Timer::MODIFY); } timer->stamp(); if (nhybrid_styles > 0) { set_compute_flags(ilevel); force->pair->compute(eflag,vflag); timer->stamp(Timer::PAIR); } if (level_pair == ilevel && pair_compute_flag) { force->pair->compute(eflag,vflag); timer->stamp(Timer::PAIR); } if (level_inner == ilevel && pair_compute_flag) { force->pair->compute_inner(); timer->stamp(Timer::PAIR); } if (level_middle == ilevel && pair_compute_flag) { force->pair->compute_middle(); timer->stamp(Timer::PAIR); } if (level_outer == ilevel && pair_compute_flag) { force->pair->compute_outer(eflag,vflag); timer->stamp(Timer::PAIR); } if (level_bond == ilevel && force->bond) { force->bond->compute(eflag,vflag); timer->stamp(Timer::BOND); } if (level_angle == ilevel && force->angle) { force->angle->compute(eflag,vflag); timer->stamp(Timer::BOND); } if (level_dihedral == ilevel && force->dihedral) { force->dihedral->compute(eflag,vflag); timer->stamp(Timer::BOND); } if (level_improper == ilevel && force->improper) { force->improper->compute(eflag,vflag); timer->stamp(Timer::BOND); } if (level_kspace == ilevel && kspace_compute_flag) { force->kspace->compute(eflag,vflag); timer->stamp(Timer::KSPACE); } if (modify->n_pre_reverse) { modify->pre_reverse(eflag,vflag); timer->stamp(Timer::MODIFY); } if (newton[ilevel]) { comm->reverse_comm(); timer->stamp(Timer::COMM); } timer->stamp(); if (modify->n_post_force_respa) modify->post_force_respa(vflag,ilevel,iloop); modify->final_integrate_respa(ilevel,iloop); timer->stamp(Timer::MODIFY); } copy_f_flevel(ilevel); } /* ---------------------------------------------------------------------- clear force on own & ghost atoms clear other arrays as needed ------------------------------------------------------------------------- */ void Respa::force_clear(int newtonflag) { if (external_force_clear) return; // clear global force array // if either newton flag is set, also include ghosts size_t nbytes = sizeof(double) * atom->nlocal; if (force->newton) nbytes += sizeof(double) * atom->nghost; if (nbytes) { memset(&atom->f[0][0],0,3*nbytes); if (torqueflag) memset(&atom->torque[0][0],0,3*nbytes); if (extraflag) atom->avec->force_clear(0,nbytes); } } /* ---------------------------------------------------------------------- copy force components from atom->f to FixRespa->f_level ------------------------------------------------------------------------- */ void Respa::copy_f_flevel(int ilevel) { double ***f_level = fix_respa->f_level; double **f = atom->f; double ***t_level = fix_respa->t_level; double **t = atom->torque; int n = atom->nlocal; for (int i = 0; i < n; i++) { f_level[i][ilevel][0] = f[i][0]; f_level[i][ilevel][1] = f[i][1]; f_level[i][ilevel][2] = f[i][2]; if (fix_respa->store_torque) { t_level[i][ilevel][0] = t[i][0]; t_level[i][ilevel][1] = t[i][1]; t_level[i][ilevel][2] = t[i][2]; } } } /* ---------------------------------------------------------------------- copy force components from FixRespa->f_level to atom->f ------------------------------------------------------------------------- */ void Respa::copy_flevel_f(int ilevel) { double ***f_level = fix_respa->f_level; double **f = atom->f; double ***t_level = fix_respa->t_level; double **t = atom->torque; int n = atom->nlocal; for (int i = 0; i < n; i++) { f[i][0] = f_level[i][ilevel][0]; f[i][1] = f_level[i][ilevel][1]; f[i][2] = f_level[i][ilevel][2]; if (fix_respa->store_torque) { t[i][0] = t_level[i][ilevel][0]; t[i][1] = t_level[i][ilevel][1]; t[i][2] = t_level[i][ilevel][2]; } } } /* ---------------------------------------------------------------------- sum all force components from FixRespa->f_level to create full atom->f ------------------------------------------------------------------------- */ void Respa::sum_flevel_f() { copy_flevel_f(0); double ***f_level = fix_respa->f_level; double **f = atom->f; double ***t_level = fix_respa->t_level; double **t = atom->torque; int n = atom->nlocal; for (int ilevel = 1; ilevel < nlevels; ilevel++) { for (int i = 0; i < n; i++) { f[i][0] += f_level[i][ilevel][0]; f[i][1] += f_level[i][ilevel][1]; f[i][2] += f_level[i][ilevel][2]; if (fix_respa->store_torque) { t[i][0] += t_level[i][ilevel][0]; t[i][1] += t_level[i][ilevel][1]; t[i][2] += t_level[i][ilevel][2]; } } } } /*----------------------------------------------------------------------- set flags for when some hybrid forces should be computed ------------------------------------------------------------------------- */ void Respa::set_compute_flags(int ilevel) { if (nhybrid_styles < 1) return; pair_compute = 0; for (int i=0; i #include "verlet.h" #include "neighbor.h" #include "domain.h" #include "comm.h" #include "atom.h" #include "atom_vec.h" #include "force.h" #include "pair.h" #include "bond.h" #include "angle.h" #include "dihedral.h" #include "improper.h" #include "kspace.h" #include "output.h" #include "update.h" #include "modify.h" #include "compute.h" #include "fix.h" #include "timer.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ Verlet::Verlet(LAMMPS *lmp, int narg, char **arg) : Integrate(lmp, narg, arg) {} /* ---------------------------------------------------------------------- initialization before run ------------------------------------------------------------------------- */ void Verlet::init() { Integrate::init(); // warn if no fixes if (modify->nfix == 0 && comm->me == 0) error->warning(FLERR,"No fixes defined, atoms won't move"); // virial_style: // 1 if computed explicitly by pair->compute via sum over pair interactions // 2 if computed implicitly by pair->virial_fdotr_compute via sum over ghosts if (force->newton_pair) virial_style = 2; else virial_style = 1; // setup lists of computes for global and per-atom PE and pressure ev_setup(); // detect if fix omp is present for clearing force arrays int ifix = modify->find_fix("package_omp"); if (ifix >= 0) external_force_clear = 1; // set flags for arrays to clear in force_clear() torqueflag = extraflag = 0; if (atom->torque_flag) torqueflag = 1; if (atom->avec->forceclearflag) extraflag = 1; // orthogonal vs triclinic simulation box triclinic = domain->triclinic; } /* ---------------------------------------------------------------------- setup before run ------------------------------------------------------------------------- */ void Verlet::setup(int flag) { if (comm->me == 0 && screen) { fprintf(screen,"Setting up Verlet run ...\n"); if (flag) { - fprintf(screen," Unit style : %s\n", update->unit_style); - fprintf(screen," Current step : " BIGINT_FORMAT "\n", - update->ntimestep); - fprintf(screen," Time step : %g\n", update->dt); + fprintf(screen," Unit style : %s\n",update->unit_style); + fprintf(screen," Current step : " BIGINT_FORMAT "\n",update->ntimestep); + fprintf(screen," Time step : %g\n",update->dt); timer->print_timeout(screen); } } if (lmp->kokkos) error->all(FLERR,"KOKKOS package requires run_style verlet/kk"); update->setupflag = 1; // setup domain, communication and neighboring // acquire ghosts // build neighbor lists atom->setup(); modify->setup_pre_exchange(); if (triclinic) domain->x2lamda(atom->nlocal); domain->pbc(); domain->reset_box(); comm->setup(); if (neighbor->style) neighbor->setup_bins(); comm->exchange(); if (atom->sortfreq > 0) atom->sort(); comm->borders(); if (triclinic) domain->lamda2x(atom->nlocal+atom->nghost); domain->image_check(); domain->box_too_small_check(); modify->setup_pre_neighbor(); neighbor->build(); + modify->setup_post_neighbor(); neighbor->ncalls = 0; // compute all forces force->setup(); ev_set(update->ntimestep); force_clear(); modify->setup_pre_force(vflag); if (pair_compute_flag) force->pair->compute(eflag,vflag); else if (force->pair) force->pair->compute_dummy(eflag,vflag); if (atom->molecular) { if (force->bond) force->bond->compute(eflag,vflag); if (force->angle) force->angle->compute(eflag,vflag); if (force->dihedral) force->dihedral->compute(eflag,vflag); if (force->improper) force->improper->compute(eflag,vflag); } if (force->kspace) { force->kspace->setup(); if (kspace_compute_flag) force->kspace->compute(eflag,vflag); else force->kspace->compute_dummy(eflag,vflag); } modify->setup_pre_reverse(eflag,vflag); if (force->newton) comm->reverse_comm(); modify->setup(vflag); output->setup(flag); update->setupflag = 0; } /* ---------------------------------------------------------------------- setup without output flag = 0 = just force calculation flag = 1 = reneighbor and force calculation ------------------------------------------------------------------------- */ void Verlet::setup_minimal(int flag) { update->setupflag = 1; // setup domain, communication and neighboring // acquire ghosts // build neighbor lists if (flag) { modify->setup_pre_exchange(); if (triclinic) domain->x2lamda(atom->nlocal); domain->pbc(); domain->reset_box(); comm->setup(); if (neighbor->style) neighbor->setup_bins(); comm->exchange(); comm->borders(); if (triclinic) domain->lamda2x(atom->nlocal+atom->nghost); domain->image_check(); domain->box_too_small_check(); modify->setup_pre_neighbor(); neighbor->build(); + modify->setup_post_neighbor(); neighbor->ncalls = 0; } // compute all forces ev_set(update->ntimestep); force_clear(); modify->setup_pre_force(vflag); if (pair_compute_flag) force->pair->compute(eflag,vflag); else if (force->pair) force->pair->compute_dummy(eflag,vflag); if (atom->molecular) { if (force->bond) force->bond->compute(eflag,vflag); if (force->angle) force->angle->compute(eflag,vflag); if (force->dihedral) force->dihedral->compute(eflag,vflag); if (force->improper) force->improper->compute(eflag,vflag); } if (force->kspace) { force->kspace->setup(); if (kspace_compute_flag) force->kspace->compute(eflag,vflag); else force->kspace->compute_dummy(eflag,vflag); } modify->setup_pre_reverse(eflag,vflag); if (force->newton) comm->reverse_comm(); modify->setup(vflag); update->setupflag = 0; } /* ---------------------------------------------------------------------- run for N steps ------------------------------------------------------------------------- */ void Verlet::run(int n) { bigint ntimestep; int nflag,sortflag; int n_post_integrate = modify->n_post_integrate; int n_pre_exchange = modify->n_pre_exchange; int n_pre_neighbor = modify->n_pre_neighbor; + int n_post_neighbor = modify->n_post_neighbor; int n_pre_force = modify->n_pre_force; int n_pre_reverse = modify->n_pre_reverse; int n_post_force = modify->n_post_force; int n_end_of_step = modify->n_end_of_step; if (atom->sortfreq > 0) sortflag = 1; else sortflag = 0; for (int i = 0; i < n; i++) { if (timer->check_timeout(i)) { update->nsteps = i; break; } ntimestep = ++update->ntimestep; ev_set(ntimestep); // initial time integration timer->stamp(); modify->initial_integrate(vflag); if (n_post_integrate) modify->post_integrate(); timer->stamp(Timer::MODIFY); // regular communication vs neighbor list rebuild nflag = neighbor->decide(); if (nflag == 0) { timer->stamp(); comm->forward_comm(); timer->stamp(Timer::COMM); } else { if (n_pre_exchange) { timer->stamp(); modify->pre_exchange(); timer->stamp(Timer::MODIFY); } if (triclinic) domain->x2lamda(atom->nlocal); domain->pbc(); if (domain->box_change) { domain->reset_box(); comm->setup(); if (neighbor->style) neighbor->setup_bins(); } timer->stamp(); comm->exchange(); if (sortflag && ntimestep >= atom->nextsort) atom->sort(); comm->borders(); if (triclinic) domain->lamda2x(atom->nlocal+atom->nghost); timer->stamp(Timer::COMM); if (n_pre_neighbor) { modify->pre_neighbor(); timer->stamp(Timer::MODIFY); } neighbor->build(); timer->stamp(Timer::NEIGH); + if (n_post_neighbor) { + modify->post_neighbor(); + timer->stamp(Timer::MODIFY); + } } // force computations // important for pair to come before bonded contributions // since some bonded potentials tally pairwise energy/virial // and Pair:ev_tally() needs to be called before any tallying force_clear(); timer->stamp(); if (n_pre_force) { modify->pre_force(vflag); timer->stamp(Timer::MODIFY); } if (pair_compute_flag) { force->pair->compute(eflag,vflag); timer->stamp(Timer::PAIR); } if (atom->molecular) { if (force->bond) force->bond->compute(eflag,vflag); if (force->angle) force->angle->compute(eflag,vflag); if (force->dihedral) force->dihedral->compute(eflag,vflag); if (force->improper) force->improper->compute(eflag,vflag); timer->stamp(Timer::BOND); } if (kspace_compute_flag) { force->kspace->compute(eflag,vflag); timer->stamp(Timer::KSPACE); } if (n_pre_reverse) { modify->pre_reverse(eflag,vflag); timer->stamp(Timer::MODIFY); } // reverse communication of forces if (force->newton) { comm->reverse_comm(); timer->stamp(Timer::COMM); } // force modifications, final time integration, diagnostics if (n_post_force) modify->post_force(vflag); modify->final_integrate(); if (n_end_of_step) modify->end_of_step(); timer->stamp(Timer::MODIFY); // all output if (ntimestep == output->next) { timer->stamp(); output->write(ntimestep); timer->stamp(Timer::OUTPUT); } } } /* ---------------------------------------------------------------------- */ void Verlet::cleanup() { modify->post_run(); domain->box_too_small_check(); update->update_time(); } /* ---------------------------------------------------------------------- clear force on own & ghost atoms clear other arrays as needed ------------------------------------------------------------------------- */ void Verlet::force_clear() { size_t nbytes; if (external_force_clear) return; // clear force on all particles // if either newton flag is set, also include ghosts // when using threads always clear all forces. int nlocal = atom->nlocal; if (neighbor->includegroup == 0) { nbytes = sizeof(double) * nlocal; if (force->newton) nbytes += sizeof(double) * atom->nghost; if (nbytes) { memset(&atom->f[0][0],0,3*nbytes); if (torqueflag) memset(&atom->torque[0][0],0,3*nbytes); if (extraflag) atom->avec->force_clear(0,nbytes); } // neighbor includegroup flag is set // clear force only on initial nfirst particles // if either newton flag is set, also include ghosts } else { nbytes = sizeof(double) * atom->nfirst; if (nbytes) { memset(&atom->f[0][0],0,3*nbytes); if (torqueflag) memset(&atom->torque[0][0],0,3*nbytes); if (extraflag) atom->avec->force_clear(0,nbytes); } if (force->newton) { nbytes = sizeof(double) * atom->nghost; if (nbytes) { memset(&atom->f[nlocal][0],0,3*nbytes); if (torqueflag) memset(&atom->torque[nlocal][0],0,3*nbytes); if (extraflag) atom->avec->force_clear(nlocal,nbytes); } } } }