/* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories LAMMPS development team: developers@lammps.org 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 "pair_lj_cut_full.h" #include "atom.h" #include "comm.h" #include "error.h" #include "force.h" #include "math_const.h" #include "memory.h" #include "neigh_list.h" #include "neighbor.h" #include "update.h" #include #include using namespace LAMMPS_NS; using namespace MathConst; /* ---------------------------------------------------------------------- */ PairLJCutFull::PairLJCutFull(LAMMPS *lmp) : Pair(lmp) { respa_enable = 0; single_enable = 0; writedata = 0; restartinfo = 0; no_virial_fdotr_compute = 1; } /* ---------------------------------------------------------------------- */ PairLJCutFull::~PairLJCutFull() { 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 PairLJCutFull::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; double fxtmp, fytmp, fztmp; int *ilist, *jlist, *numneigh, **firstneigh; evdwl = 0.0; ev_init(eflag, vflag); double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; double *special_lj = force->special_lj; 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]; fxtmp = fytmp = fztmp = 0.0; 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; fxtmp += delx * fpair; fytmp += dely * fpair; fztmp += delz * fpair; if (eflag) { evdwl = r6inv * (lj3[itype][jtype] * r6inv - lj4[itype][jtype]) - offset[itype][jtype]; evdwl *= factor_lj; } if (evflag) ev_tally(i, i, nlocal, 0, 0.5*evdwl, 0.0, 0.5*fpair, delx, dely, delz); } } f[i][0] += fxtmp; f[i][1] += fytmp; f[i][2] += fztmp; } if (vflag_fdotr) virial_fdotr_compute(); } /* ---------------------------------------------------------------------- allocate all arrays ------------------------------------------------------------------------- */ void PairLJCutFull::allocate() { allocated = 1; int n = atom->ntypes + 1; memory->create(setflag, n, n, "pair:setflag"); for (int i = 1; i < n; i++) for (int j = i; j < n; j++) setflag[i][j] = 0; memory->create(cutsq, n, n, "pair:cutsq"); memory->create(cut, n, n, "pair:cut"); memory->create(epsilon, n, n, "pair:epsilon"); memory->create(sigma, n, n, "pair:sigma"); memory->create(lj1, n, n, "pair:lj1"); memory->create(lj2, n, n, "pair:lj2"); memory->create(lj3, n, n, "pair:lj3"); memory->create(lj4, n, n, "pair:lj4"); memory->create(offset, n, n, "pair:offset"); } /* ---------------------------------------------------------------------- global settings ------------------------------------------------------------------------- */ void PairLJCutFull::settings(int narg, char **arg) { if (narg != 1) error->all(FLERR, "Illegal pair_style command"); cut_global = utils::numeric(FLERR, arg[0], false, lmp); // 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 PairLJCutFull::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; utils::bounds(FLERR, arg[0], 1, atom->ntypes, ilo, ihi, error); utils::bounds(FLERR, arg[1], 1, atom->ntypes, jlo, jhi, error); double epsilon_one = utils::numeric(FLERR, arg[2], false, lmp); double sigma_one = utils::numeric(FLERR, arg[3], false, lmp); double cut_one = cut_global; if (narg == 5) cut_one = utils::numeric(FLERR, arg[4], false, lmp); 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 PairLJCutFull::init_style() { neighbor->add_request(this, NeighConst::REQ_FULL); } /* ---------------------------------------------------------------------- init for one type pair i,j and corresponding j,i ------------------------------------------------------------------------- */ double PairLJCutFull::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; epsilon[j][i] = epsilon[i][j]; sigma[j][i] = epsilon[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[i][j]; }