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 Copyright (2003) Sandia Corporation. Under the terms of Contract
8 DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
9 certain rights in this software. This software is distributed under
10 the GNU General Public License.
11
12 See the README file in the top-level LAMMPS directory.
13 ------------------------------------------------------------------------- */
14
15 #include "npair_half_bin_newton_tri.h"
16 #include "neigh_list.h"
17 #include "atom.h"
18 #include "atom_vec.h"
19 #include "molecule.h"
20 #include "domain.h"
21 #include "my_page.h"
22 #include "error.h"
23
24 using namespace LAMMPS_NS;
25
26 /* ---------------------------------------------------------------------- */
27
NPairHalfBinNewtonTri(LAMMPS * lmp)28 NPairHalfBinNewtonTri::NPairHalfBinNewtonTri(LAMMPS *lmp) : NPair(lmp) {}
29
30 /* ----------------------------------------------------------------------
31 binned neighbor list construction with Newton's 3rd law for triclinic
32 each owned atom i checks its own bin and other bins in triclinic stencil
33 every pair stored exactly once by some processor
34 ------------------------------------------------------------------------- */
35
build(NeighList * list)36 void NPairHalfBinNewtonTri::build(NeighList *list)
37 {
38 int i,j,k,n,itype,jtype,ibin,which,imol,iatom,moltemplate;
39 tagint tagprev;
40 double xtmp,ytmp,ztmp,delx,dely,delz,rsq;
41 int *neighptr;
42
43 double **x = atom->x;
44 int *type = atom->type;
45 int *mask = atom->mask;
46 tagint *tag = atom->tag;
47 tagint *molecule = atom->molecule;
48 tagint **special = atom->special;
49 int **nspecial = atom->nspecial;
50 int nlocal = atom->nlocal;
51 if (includegroup) nlocal = atom->nfirst;
52
53 int *molindex = atom->molindex;
54 int *molatom = atom->molatom;
55 Molecule **onemols = atom->avec->onemols;
56 if (molecular == Atom::TEMPLATE) moltemplate = 1;
57 else moltemplate = 0;
58
59 int *ilist = list->ilist;
60 int *numneigh = list->numneigh;
61 int **firstneigh = list->firstneigh;
62 MyPage<int> *ipage = list->ipage;
63
64 int inum = 0;
65 ipage->reset();
66
67 for (i = 0; i < nlocal; i++) {
68 n = 0;
69 neighptr = ipage->vget();
70
71 itype = type[i];
72 xtmp = x[i][0];
73 ytmp = x[i][1];
74 ztmp = x[i][2];
75 if (moltemplate) {
76 imol = molindex[i];
77 iatom = molatom[i];
78 tagprev = tag[i] - iatom - 1;
79 }
80
81 // loop over all atoms in bins in stencil
82 // pairs for atoms j "below" i are excluded
83 // below = lower z or (equal z and lower y) or (equal zy and lower x)
84 // (equal zyx and j <= i)
85 // latter excludes self-self interaction but allows superposed atoms
86
87 ibin = atom2bin[i];
88 for (k = 0; k < nstencil; k++) {
89 for (j = binhead[ibin+stencil[k]]; j >= 0; j = bins[j]) {
90 if (x[j][2] < ztmp) continue;
91 if (x[j][2] == ztmp) {
92 if (x[j][1] < ytmp) continue;
93 if (x[j][1] == ytmp) {
94 if (x[j][0] < xtmp) continue;
95 if (x[j][0] == xtmp && j <= i) continue;
96 }
97 }
98
99 jtype = type[j];
100 if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue;
101
102 delx = xtmp - x[j][0];
103 dely = ytmp - x[j][1];
104 delz = ztmp - x[j][2];
105 rsq = delx*delx + dely*dely + delz*delz;
106
107 if (rsq <= cutneighsq[itype][jtype]) {
108 if (molecular != Atom::ATOMIC) {
109 if (!moltemplate)
110 which = find_special(special[i],nspecial[i],tag[j]);
111 else if (imol >= 0)
112 which = find_special(onemols[imol]->special[iatom],
113 onemols[imol]->nspecial[iatom],
114 tag[j]-tagprev);
115 else which = 0;
116 if (which == 0) neighptr[n++] = j;
117 else if (domain->minimum_image_check(delx,dely,delz))
118 neighptr[n++] = j;
119 else if (which > 0) neighptr[n++] = j ^ (which << SBBITS);
120 } else neighptr[n++] = j;
121 }
122 }
123 }
124
125 ilist[inum++] = i;
126 firstneigh[i] = neighptr;
127 numneigh[i] = n;
128 ipage->vgot(n);
129 if (ipage->status())
130 error->one(FLERR,"Neighbor list overflow, boost neigh_modify one");
131 }
132
133 list->inum = inum;
134 }
135