1 // clang-format off
2 /* ----------------------------------------------------------------------
3 LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
4 https://www.lammps.org/, Sandia National Laboratories
5 Steve Plimpton, sjplimp@sandia.gov
6
7 This software is distributed under the GNU General Public License.
8
9 See the README file in the top-level LAMMPS directory.
10 ------------------------------------------------------------------------- */
11
12 /* ----------------------------------------------------------------------
13 Contributing author: Axel Kohlmeyer (Temple U)
14 ------------------------------------------------------------------------- */
15
16 #include "omp_compat.h"
17 #include "pair_buck_omp.h"
18 #include <cmath>
19 #include "atom.h"
20 #include "comm.h"
21 #include "force.h"
22 #include "neigh_list.h"
23
24
25 #include "suffix.h"
26 using namespace LAMMPS_NS;
27
28 /* ---------------------------------------------------------------------- */
29
PairBuckOMP(LAMMPS * lmp)30 PairBuckOMP::PairBuckOMP(LAMMPS *lmp) :
31 PairBuck(lmp), ThrOMP(lmp, THR_PAIR)
32 {
33 suffix_flag |= Suffix::OMP;
34 respa_enable = 0;
35 }
36
37 /* ---------------------------------------------------------------------- */
38
compute(int eflag,int vflag)39 void PairBuckOMP::compute(int eflag, int vflag)
40 {
41 ev_init(eflag,vflag);
42
43 const int nall = atom->nlocal + atom->nghost;
44 const int nthreads = comm->nthreads;
45 const int inum = list->inum;
46
47 #if defined(_OPENMP)
48 #pragma omp parallel LMP_DEFAULT_NONE LMP_SHARED(eflag,vflag)
49 #endif
50 {
51 int ifrom, ito, tid;
52
53 loop_setup_thr(ifrom, ito, tid, inum, nthreads);
54 ThrData *thr = fix->get_thr(tid);
55 thr->timer(Timer::START);
56 ev_setup_thr(eflag, vflag, nall, eatom, vatom, nullptr, thr);
57
58 if (evflag) {
59 if (eflag) {
60 if (force->newton_pair) eval<1,1,1>(ifrom, ito, thr);
61 else eval<1,1,0>(ifrom, ito, thr);
62 } else {
63 if (force->newton_pair) eval<1,0,1>(ifrom, ito, thr);
64 else eval<1,0,0>(ifrom, ito, thr);
65 }
66 } else {
67 if (force->newton_pair) eval<0,0,1>(ifrom, ito, thr);
68 else eval<0,0,0>(ifrom, ito, thr);
69 }
70
71 thr->timer(Timer::PAIR);
72 reduce_thr(this, eflag, vflag, thr);
73 } // end of omp parallel region
74 }
75
76 template <int EVFLAG, int EFLAG, int NEWTON_PAIR>
eval(int iifrom,int iito,ThrData * const thr)77 void PairBuckOMP::eval(int iifrom, int iito, ThrData * const thr)
78 {
79 int i,j,ii,jj,jnum,itype,jtype;
80 double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair;
81 double rsq,r2inv,r6inv,r,rexp,forcebuck,factor_lj;
82 int *ilist,*jlist,*numneigh,**firstneigh;
83
84 evdwl = 0.0;
85
86 const dbl3_t * _noalias const x = (dbl3_t *) atom->x[0];
87 dbl3_t * _noalias const f = (dbl3_t *) thr->get_f()[0];
88 int *type = atom->type;
89 int nlocal = atom->nlocal;
90 double *special_lj = force->special_lj;
91 double fxtmp,fytmp,fztmp;
92
93 ilist = list->ilist;
94 numneigh = list->numneigh;
95 firstneigh = list->firstneigh;
96
97 // loop over neighbors of my atoms
98
99 for (ii = iifrom; ii < iito; ++ii) {
100
101 i = ilist[ii];
102 xtmp = x[i].x;
103 ytmp = x[i].y;
104 ztmp = x[i].z;
105 itype = type[i];
106 jlist = firstneigh[i];
107 jnum = numneigh[i];
108 fxtmp=fytmp=fztmp=0.0;
109
110 for (jj = 0; jj < jnum; jj++) {
111 j = jlist[jj];
112 factor_lj = special_lj[sbmask(j)];
113 j &= NEIGHMASK;
114
115 delx = xtmp - x[j].x;
116 dely = ytmp - x[j].y;
117 delz = ztmp - x[j].z;
118 rsq = delx*delx + dely*dely + delz*delz;
119 jtype = type[j];
120
121 if (rsq < cutsq[itype][jtype]) {
122 r2inv = 1.0/rsq;
123 r6inv = r2inv*r2inv*r2inv;
124 r = sqrt(rsq);
125 r2inv = 1.0/rsq;
126 r6inv = r2inv*r2inv*r2inv;
127 r = sqrt(rsq);
128 rexp = exp(-r*rhoinv[itype][jtype]);
129 forcebuck = buck1[itype][jtype]*r*rexp - buck2[itype][jtype]*r6inv;
130 fpair = factor_lj*forcebuck*r2inv;
131
132 fxtmp += delx*fpair;
133 fytmp += dely*fpair;
134 fztmp += delz*fpair;
135 if (NEWTON_PAIR || j < nlocal) {
136 f[j].x -= delx*fpair;
137 f[j].y -= dely*fpair;
138 f[j].z -= delz*fpair;
139 }
140
141 if (EFLAG) {
142 evdwl = a[itype][jtype]*rexp - c[itype][jtype]*r6inv -
143 offset[itype][jtype];
144 evdwl *= factor_lj;
145 }
146
147 if (EVFLAG) ev_tally_thr(this, i,j,nlocal,NEWTON_PAIR,
148 evdwl,0.0,fpair,delx,dely,delz,thr);
149 }
150 }
151 f[i].x += fxtmp;
152 f[i].y += fytmp;
153 f[i].z += fztmp;
154 }
155 }
156
157 /* ---------------------------------------------------------------------- */
158
memory_usage()159 double PairBuckOMP::memory_usage()
160 {
161 double bytes = memory_usage_thr();
162 bytes += PairBuck::memory_usage();
163
164 return bytes;
165 }
166