1 /* -*- c++ -*- ----------------------------------------------------------
2    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
3    https://www.lammps.org/, Sandia National Laboratories
4    Steve Plimpton, sjplimp@sandia.gov
5 
6    Copyright (2003) Sandia Corporation.  Under the terms of Contract
7    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
8    certain rights in this software.  This software is distributed under
9    the GNU General Public License.
10 
11    See the README file in the top-level LAMMPS directory.
12 ------------------------------------------------------------------------- */
13 
14 #ifdef PAIR_CLASS
15 // clang-format off
16 PairStyle(tersoff/mod/kk,PairTersoffMODKokkos<LMPDeviceType>);
17 PairStyle(tersoff/mod/kk/device,PairTersoffMODKokkos<LMPDeviceType>);
18 PairStyle(tersoff/mod/kk/host,PairTersoffMODKokkos<LMPHostType>);
19 // clang-format on
20 #else
21 
22 // clang-format off
23 #ifndef LMP_PAIR_TERSOFF_MOD_KOKKOS_H
24 #define LMP_PAIR_TERSOFF_MOD_KOKKOS_H
25 
26 #include "pair_kokkos.h"
27 #include "pair_tersoff_mod.h"
28 #include "neigh_list_kokkos.h"
29 
30 namespace LAMMPS_NS {
31 
32 template<int NEIGHFLAG, int EVFLAG>
33 struct TagPairTersoffMODComputeHalf{};
34 
35 template<int NEIGHFLAG, int EVFLAG>
36 struct TagPairTersoffMODComputeFullA{};
37 
38 template<int NEIGHFLAG, int EVFLAG>
39 struct TagPairTersoffMODComputeFullB{};
40 
41 struct TagPairTersoffMODComputeShortNeigh{};
42 
43 template<class DeviceType>
44 class PairTersoffMODKokkos : public PairTersoffMOD {
45  public:
46   enum {EnabledNeighFlags=FULL};
47   enum {COUL_FLAG=0};
48   typedef DeviceType device_type;
49   typedef ArrayTypes<DeviceType> AT;
50   typedef EV_FLOAT value_type;
51 
52   PairTersoffMODKokkos(class LAMMPS *);
53   virtual ~PairTersoffMODKokkos();
54   virtual void compute(int, int);
55   void init_style();
56 
57   template<int NEIGHFLAG, int EVFLAG>
58   KOKKOS_INLINE_FUNCTION
59   void operator()(TagPairTersoffMODComputeHalf<NEIGHFLAG,EVFLAG>, const int&, EV_FLOAT&) const;
60 
61   template<int NEIGHFLAG, int EVFLAG>
62   KOKKOS_INLINE_FUNCTION
63   void operator()(TagPairTersoffMODComputeHalf<NEIGHFLAG,EVFLAG>, const int&) const;
64 
65   template<int NEIGHFLAG, int EVFLAG>
66   KOKKOS_INLINE_FUNCTION
67   void operator()(TagPairTersoffMODComputeFullA<NEIGHFLAG,EVFLAG>, const int&, EV_FLOAT&) const;
68 
69   template<int NEIGHFLAG, int EVFLAG>
70   KOKKOS_INLINE_FUNCTION
71   void operator()(TagPairTersoffMODComputeFullA<NEIGHFLAG,EVFLAG>, const int&) const;
72 
73   template<int NEIGHFLAG, int EVFLAG>
74   KOKKOS_INLINE_FUNCTION
75   void operator()(TagPairTersoffMODComputeFullB<NEIGHFLAG,EVFLAG>, const int&, EV_FLOAT&) const;
76 
77   template<int NEIGHFLAG, int EVFLAG>
78   KOKKOS_INLINE_FUNCTION
79   void operator()(TagPairTersoffMODComputeFullB<NEIGHFLAG,EVFLAG>, const int&) const;
80 
81   KOKKOS_INLINE_FUNCTION
82   void operator()(TagPairTersoffMODComputeShortNeigh, const int&) const;
83 
84   KOKKOS_INLINE_FUNCTION
85   double ters_fc_k(const int &i, const int &j, const int &k, const F_FLOAT &r) const;
86 
87   KOKKOS_INLINE_FUNCTION
88   double ters_dfc(const int &i, const int &j, const int &k, const F_FLOAT &r) const;
89 
90   KOKKOS_INLINE_FUNCTION
91   double ters_fa_k(const int &i, const int &j, const int &k, const F_FLOAT &r) const;
92 
93   KOKKOS_INLINE_FUNCTION
94   double ters_dfa(const int &i, const int &j, const int &k, const F_FLOAT &r) const;
95 
96   KOKKOS_INLINE_FUNCTION
97   double ters_bij_k(const int &i, const int &j, const int &k, const F_FLOAT &bo) const;
98 
99   KOKKOS_INLINE_FUNCTION
100   double ters_dbij(const int &i, const int &j, const int &k, const F_FLOAT &bo) const;
101 
102   KOKKOS_INLINE_FUNCTION
103   double bondorder(const int &i, const int &j, const int &k,
104         const F_FLOAT &rij, const F_FLOAT &dx1, const F_FLOAT &dy1, const F_FLOAT &dz1,
105         const F_FLOAT &rik, const F_FLOAT &dx2, const F_FLOAT &dy2, const F_FLOAT &dz2) const;
106 
107   KOKKOS_INLINE_FUNCTION
108   double ters_gijk(const int &i, const int &j, const int &k, const F_FLOAT &cos) const;
109 
110   KOKKOS_INLINE_FUNCTION
111   double ters_dgijk(const int &i, const int &j, const int &k, const F_FLOAT &cos) const;
112 
113   KOKKOS_INLINE_FUNCTION
114   void ters_dthb(const int &i, const int &j, const int &k, const F_FLOAT &prefactor,
115         const F_FLOAT &rij, const F_FLOAT &dx1, const F_FLOAT &dy1, const F_FLOAT &dz1,
116         const F_FLOAT &rik, const F_FLOAT &dx2, const F_FLOAT &dy2, const F_FLOAT &dz2,
117         F_FLOAT *fi, F_FLOAT *fj, F_FLOAT *fk) const;
118 
119   KOKKOS_INLINE_FUNCTION
120   void ters_dthbj(const int &i, const int &j, const int &k, const F_FLOAT &prefactor,
121         const F_FLOAT &rij, const F_FLOAT &dx1, const F_FLOAT &dy1, const F_FLOAT &dz1,
122         const F_FLOAT &rik, const F_FLOAT &dx2, const F_FLOAT &dy2, const F_FLOAT &dz2,
123         F_FLOAT *fj, F_FLOAT *fk) const;
124 
125   KOKKOS_INLINE_FUNCTION
126   void ters_dthbk(const int &i, const int &j, const int &k, const F_FLOAT &prefactor,
127         const F_FLOAT &rij, const F_FLOAT &dx1, const F_FLOAT &dy1, const F_FLOAT &dz1,
128         const F_FLOAT &rik, const F_FLOAT &dx2, const F_FLOAT &dy2, const F_FLOAT &dz2,
129         F_FLOAT *fk) const;
130 
131   KOKKOS_INLINE_FUNCTION
vec3_dot(const F_FLOAT x[3],const double y[3])132   double vec3_dot(const F_FLOAT x[3], const double y[3]) const {
133     return x[0]*y[0] + x[1]*y[1] + x[2]*y[2];
134   }
135 
136   KOKKOS_INLINE_FUNCTION
vec3_add(const F_FLOAT x[3],const double y[3],double * const z)137   void vec3_add(const F_FLOAT x[3], const double y[3], double * const z) const {
138     z[0] = x[0]+y[0]; z[1] = x[1]+y[1]; z[2] = x[2]+y[2];
139   }
140 
141   KOKKOS_INLINE_FUNCTION
vec3_scale(const F_FLOAT k,const double x[3],double y[3])142   void vec3_scale(const F_FLOAT k, const double x[3], double y[3]) const {
143     y[0] = k*x[0]; y[1] = k*x[1]; y[2] = k*x[2];
144   }
145 
146   KOKKOS_INLINE_FUNCTION
vec3_scaleadd(const F_FLOAT k,const double x[3],const double y[3],double * const z)147   void vec3_scaleadd(const F_FLOAT k, const double x[3], const double y[3], double * const z) const {
148     z[0] = k*x[0]+y[0]; z[1] = k*x[1]+y[1]; z[2] = k*x[2]+y[2];
149   }
150 
151   KOKKOS_INLINE_FUNCTION
152   int sbmask(const int& j) const;
153 
154   struct params_ters{
155     KOKKOS_INLINE_FUNCTION
params_tersparams_ters156     params_ters() {powerm=0;lam3=0;h=0;powern=0;beta=0;lam2=0;bigb=0;bigr=0;bigd=0;
157       lam1=0;biga=0;powern_del=0;cutsq=0;c1=0;c2=0;c3=0;c4=0;c5=0;ca1=0;ca4=0;};
158     KOKKOS_INLINE_FUNCTION
params_tersparams_ters159     params_ters(int /*i*/) {powerm=0;lam3=0;h=0;powern=0;beta=0;lam2=0;bigb=0;bigr=0;bigd=0;
160       lam1=0;biga=0;powern_del=0;cutsq=0;c1=0;c2=0;c3=0;c4=0;c5=0;ca1=0;ca4=0;};
161     F_FLOAT powerm, lam3, h, powern, beta, lam2, bigb, bigr, bigd,
162       lam1, biga, powern_del, cutsq, c1, c2, c3, c4, c5, ca1, ca4;
163   };
164 
165   template<int NEIGHFLAG>
166   KOKKOS_INLINE_FUNCTION
167   void ev_tally(EV_FLOAT &ev, const int &i, const int &j,
168       const F_FLOAT &epair, const F_FLOAT &fpair, const F_FLOAT &delx,
169                   const F_FLOAT &dely, const F_FLOAT &delz) const;
170 
171   template<int NEIGHFLAG>
172   KOKKOS_INLINE_FUNCTION
173   void v_tally3(EV_FLOAT &ev, const int &i, const int &j, const int &k,
174     F_FLOAT *fj, F_FLOAT *fk, F_FLOAT *drij, F_FLOAT *drik) const;
175 
176   KOKKOS_INLINE_FUNCTION
177   void v_tally3_atom(EV_FLOAT &ev, const int &i, const int &j, const int &k,
178     F_FLOAT *fj, F_FLOAT *fk, F_FLOAT *drji, F_FLOAT *drjk) const;
179 
180   void allocate();
181   void setup_params();
182 
183  protected:
184   typedef Kokkos::DualView<int***,DeviceType> tdual_int_3d;
185   Kokkos::DualView<params_ters***,Kokkos::LayoutRight,DeviceType> k_params;
186   typename Kokkos::DualView<params_ters***,
187     Kokkos::LayoutRight,DeviceType>::t_dev_const_um paramskk;
188   // hardwired to space for 12 atom types
189   //params_ters m_params[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1];
190 
191   int inum;
192   typename AT::t_x_array_randomread x;
193   typename AT::t_f_array f;
194   typename AT::t_int_1d_randomread type;
195   typename AT::t_tagint_1d tag;
196 
197   DAT::tdual_efloat_1d k_eatom;
198   DAT::tdual_virial_array k_vatom;
199   typename ArrayTypes<DeviceType>::t_efloat_1d d_eatom;
200   typename ArrayTypes<DeviceType>::t_virial_array d_vatom;
201 
202   int need_dup;
203   Kokkos::Experimental::ScatterView<F_FLOAT*[3], typename DAT::t_f_array::array_layout,typename KKDevice<DeviceType>::value,typename Kokkos::Experimental::ScatterSum,Kokkos::Experimental::ScatterDuplicated> dup_f;
204   Kokkos::Experimental::ScatterView<E_FLOAT*, typename DAT::t_efloat_1d::array_layout,typename KKDevice<DeviceType>::value,typename Kokkos::Experimental::ScatterSum,Kokkos::Experimental::ScatterDuplicated> dup_eatom;
205   Kokkos::Experimental::ScatterView<F_FLOAT*[6], typename DAT::t_virial_array::array_layout,typename KKDevice<DeviceType>::value,typename Kokkos::Experimental::ScatterSum,Kokkos::Experimental::ScatterDuplicated> dup_vatom;
206   Kokkos::Experimental::ScatterView<F_FLOAT*[3], typename DAT::t_f_array::array_layout,typename KKDevice<DeviceType>::value,typename Kokkos::Experimental::ScatterSum,Kokkos::Experimental::ScatterNonDuplicated> ndup_f;
207   Kokkos::Experimental::ScatterView<E_FLOAT*, typename DAT::t_efloat_1d::array_layout,typename KKDevice<DeviceType>::value,typename Kokkos::Experimental::ScatterSum,Kokkos::Experimental::ScatterNonDuplicated> ndup_eatom;
208   Kokkos::Experimental::ScatterView<F_FLOAT*[6], typename DAT::t_virial_array::array_layout,typename KKDevice<DeviceType>::value,typename Kokkos::Experimental::ScatterSum,Kokkos::Experimental::ScatterNonDuplicated> ndup_vatom;
209 
210   typedef Kokkos::DualView<F_FLOAT**[7],Kokkos::LayoutRight,DeviceType> tdual_ffloat_2d_n7;
211   typedef typename tdual_ffloat_2d_n7::t_dev_const_randomread t_ffloat_2d_n7_randomread;
212   typedef typename tdual_ffloat_2d_n7::t_host t_host_ffloat_2d_n7;
213 
214   typename AT::t_neighbors_2d d_neighbors;
215   typename AT::t_int_1d_randomread d_ilist;
216   typename AT::t_int_1d_randomread d_numneigh;
217   //NeighListKokkos<DeviceType> k_list;
218 
219   int neighflag,newton_pair;
220   int nlocal,nall,eflag,vflag;
221 
222   Kokkos::View<int**,DeviceType> d_neighbors_short;
223   Kokkos::View<int*,DeviceType> d_numneigh_short;
224 
225   friend void pair_virial_fdotr_compute<PairTersoffMODKokkos>(PairTersoffMODKokkos*);
226 };
227 
228 }
229 
230 #endif
231 #endif
232 
233 /* ERROR/WARNING messages:
234 
235 E: Cannot (yet) use full neighbor list style with tersoff/mod/kk
236 
237 Self-explanatory.
238 
239 E: Cannot use chosen neighbor list style with tersoff/mod/kk
240 
241 Self-explanatory.
242 
243 */
244