~ubuntu-branches/debian/sid/lammps/sid

« back to all changes in this revision

Viewing changes to src/KOKKOS/domain_kokkos.cpp

  • Committer: Package Import Robot
  • Author(s): Anton Gladky
  • Date: 2015-04-29 23:44:49 UTC
  • mfrom: (5.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20150429234449-mbhy9utku6hp6oq8
Tags: 0~20150313.gitfa668e1-1
Upload into unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ----------------------------------------------------------------------
 
2
   LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
 
3
   http://lammps.sandia.gov, 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
#include "domain_kokkos.h"
 
15
#include "atom_kokkos.h"
 
16
#include "atom_masks.h"
 
17
 
 
18
using namespace LAMMPS_NS;
 
19
 
 
20
/* ---------------------------------------------------------------------- */
 
21
 
 
22
DomainKokkos::DomainKokkos(LAMMPS *lmp) : Domain(lmp) {}
 
23
 
 
24
/* ---------------------------------------------------------------------- */
 
25
 
 
26
void DomainKokkos::init()
 
27
{
 
28
  atomKK = (AtomKokkos *) atom;
 
29
  Domain::init();
 
30
}
 
31
 
 
32
/* ---------------------------------------------------------------------- */
 
33
 
 
34
template<class DeviceType, int PERIODIC, int DEFORM_VREMAP>
 
35
struct DomainPBCFunctor {
 
36
  typedef DeviceType device_type;
 
37
  double lo[3],hi[3],period[3];
 
38
  typename ArrayTypes<DeviceType>::t_x_array x;
 
39
  typename ArrayTypes<DeviceType>::t_v_array v;
 
40
  typename ArrayTypes<DeviceType>::t_int_1d mask;
 
41
  typename ArrayTypes<DeviceType>::t_imageint_1d image;
 
42
  int deform_groupbit;
 
43
  double h_rate[6];
 
44
  int xperiodic,yperiodic,zperiodic;
 
45
 
 
46
  DomainPBCFunctor(double* _lo, double* _hi, double* _period,
 
47
                   DAT::tdual_x_array _x, DAT::tdual_v_array _v,
 
48
                   DAT::tdual_int_1d _mask, DAT::tdual_imageint_1d _image, 
 
49
                   int _deform_groupbit, double* _h_rate,
 
50
                   int _xperiodic, int _yperiodic, int _zperiodic):
 
51
    x(_x.view<DeviceType>()), v(_v.view<DeviceType>()),
 
52
    mask(_mask.view<DeviceType>()), image(_image.view<DeviceType>()),
 
53
    deform_groupbit(_deform_groupbit),
 
54
    xperiodic(_xperiodic), yperiodic(_yperiodic), zperiodic(_zperiodic){
 
55
    lo[0]=_lo[0]; lo[1]=_lo[1]; lo[2]=_lo[2];
 
56
    hi[0]=_hi[0]; hi[1]=_hi[1]; hi[2]=_hi[2];
 
57
    period[0]=_period[0]; period[1]=_period[1]; period[2]=_period[2];
 
58
    h_rate[0]=_h_rate[0]; h_rate[1]=_h_rate[1]; h_rate[2]=_h_rate[2];
 
59
    h_rate[3]=_h_rate[3]; h_rate[4]=_h_rate[4]; h_rate[5]=_h_rate[5];
 
60
  }
 
61
 
 
62
  KOKKOS_INLINE_FUNCTION
 
63
  void operator() (const int &i) const {
 
64
    if (PERIODIC && xperiodic) {
 
65
      if (x(i,0) < lo[0]) {
 
66
        x(i,0) += period[0];
 
67
        if (DEFORM_VREMAP && (mask[i] & deform_groupbit)) v(i,0) += h_rate[0];
 
68
        imageint idim = image[i] & IMGMASK;
 
69
        const int otherdims = image[i] ^ idim;
 
70
        idim--;
 
71
        idim &= IMGMASK;
 
72
        image[i] = otherdims | idim;
 
73
      }
 
74
      if (x(i,0) >= hi[0]) {
 
75
        x(i,0) -= period[0];
 
76
        x(i,0) = MAX(x(i,0),lo[0]);
 
77
        if (DEFORM_VREMAP && (mask[i] & deform_groupbit)) v(i,0) -= h_rate[0];
 
78
        imageint idim = image[i] & IMGMASK;
 
79
        const int otherdims = image[i] ^ idim;
 
80
        idim++;
 
81
        idim &= IMGMASK;
 
82
        image[i] = otherdims | idim;
 
83
      }
 
84
    }
 
85
    
 
86
    if (PERIODIC && yperiodic) {
 
87
      if (x(i,1) < lo[1]) {
 
88
        x(i,1) += period[1];
 
89
        if (DEFORM_VREMAP && (mask[i] & deform_groupbit)) {
 
90
          v(i,0) += h_rate[5];
 
91
          v(i,1) += h_rate[1];
 
92
        }
 
93
        imageint idim = (image[i] >> IMGBITS) & IMGMASK;
 
94
        const imageint otherdims = image[i] ^ (idim << IMGBITS);
 
95
        idim--;
 
96
        idim &= IMGMASK;
 
97
        image[i] = otherdims | (idim << IMGBITS);
 
98
      }
 
99
      if (x(i,1) >= hi[1]) {
 
100
        x(i,1) -= period[1];
 
101
        x(i,1) = MAX(x(i,1),lo[1]);
 
102
        if (DEFORM_VREMAP && (mask[i] & deform_groupbit)) {
 
103
          v(i,0) -= h_rate[5];
 
104
          v(i,1) -= h_rate[1];
 
105
        }
 
106
        imageint idim = (image[i] >> IMGBITS) & IMGMASK;
 
107
        const imageint otherdims = image[i] ^ (idim << IMGBITS);
 
108
        idim++;
 
109
        idim &= IMGMASK;
 
110
        image[i] = otherdims | (idim << IMGBITS);
 
111
      }
 
112
    }
 
113
    
 
114
    if (PERIODIC && zperiodic) {
 
115
      if (x(i,2) < lo[2]) {
 
116
        x(i,2) += period[2];
 
117
        if (DEFORM_VREMAP && (mask[i] & deform_groupbit)) {
 
118
          v(i,0) += h_rate[4];
 
119
          v(i,1) += h_rate[3];
 
120
          v(i,2) += h_rate[2];
 
121
        }
 
122
        imageint idim = image[i] >> IMG2BITS;
 
123
        const imageint otherdims = image[i] ^ (idim << IMG2BITS);
 
124
        idim--;
 
125
        idim &= IMGMASK;
 
126
        image[i] = otherdims | (idim << IMG2BITS);
 
127
      }
 
128
      if (x(i,2) >= hi[2]) {
 
129
        x(i,2) -= period[2];
 
130
        x(i,2) = MAX(x(i,2),lo[2]);
 
131
        if (DEFORM_VREMAP && (mask[i] & deform_groupbit)) {
 
132
          v(i,0) -= h_rate[4];
 
133
          v(i,1) -= h_rate[3];
 
134
          v(i,2) -= h_rate[2];
 
135
        }
 
136
        imageint idim = image[i] >> IMG2BITS;
 
137
        const imageint otherdims = image[i] ^ (idim << IMG2BITS);
 
138
        idim++;
 
139
        idim &= IMGMASK;
 
140
        image[i] = otherdims | (idim << IMG2BITS);
 
141
      }
 
142
    }
 
143
  }
 
144
};
 
145
 
 
146
/* ----------------------------------------------------------------------
 
147
   enforce PBC and modify box image flags for each atom
 
148
   called every reneighboring and by other commands that change atoms
 
149
   resulting coord must satisfy lo <= coord < hi
 
150
   MAX is important since coord - prd < lo can happen when coord = hi
 
151
   if fix deform, remap velocity of fix group atoms by box edge velocities
 
152
   for triclinic, atoms must be in lamda coords (0-1) before pbc is called
 
153
   image = 10 bits for each dimension
 
154
   increment/decrement in wrap-around fashion
 
155
------------------------------------------------------------------------- */
 
156
 
 
157
void DomainKokkos::pbc()
 
158
{
 
159
  double *lo,*hi,*period;
 
160
  int nlocal = atomKK->nlocal;
 
161
 
 
162
  if (triclinic == 0) {
 
163
    lo = boxlo;
 
164
    hi = boxhi;
 
165
    period = prd;
 
166
  } else {
 
167
    lo = boxlo_lamda;
 
168
    hi = boxhi_lamda;
 
169
    period = prd_lamda;
 
170
  }
 
171
 
 
172
  atomKK->sync(Device,X_MASK|V_MASK|MASK_MASK|IMAGE_MASK);
 
173
  atomKK->modified(Device,X_MASK|V_MASK);
 
174
 
 
175
  if (xperiodic || yperiodic || zperiodic) {
 
176
    if (deform_vremap) {
 
177
      DomainPBCFunctor<LMPDeviceType,1,1> 
 
178
        f(lo,hi,period,
 
179
          atomKK->k_x,atomKK->k_v,atomKK->k_mask,atomKK->k_image,
 
180
          deform_groupbit,h_rate,xperiodic,yperiodic,zperiodic);
 
181
      Kokkos::parallel_for(nlocal,f);
 
182
    } else {
 
183
      DomainPBCFunctor<LMPDeviceType,1,0> 
 
184
        f(lo,hi,period,
 
185
          atomKK->k_x,atomKK->k_v,atomKK->k_mask,atomKK->k_image,
 
186
          deform_groupbit,h_rate,xperiodic,yperiodic,zperiodic);
 
187
      Kokkos::parallel_for(nlocal,f);
 
188
    }
 
189
  } else {
 
190
    if (deform_vremap) {
 
191
      DomainPBCFunctor<LMPDeviceType,0,1> 
 
192
        f(lo,hi,period,
 
193
          atomKK->k_x,atomKK->k_v,atomKK->k_mask,atomKK->k_image,
 
194
          deform_groupbit,h_rate,xperiodic,yperiodic,zperiodic);
 
195
      Kokkos::parallel_for(nlocal,f);
 
196
    } else {
 
197
      DomainPBCFunctor<LMPDeviceType,0,0> 
 
198
        f(lo,hi,period,
 
199
          atomKK->k_x,atomKK->k_v,atomKK->k_mask,atomKK->k_image,
 
200
          deform_groupbit,h_rate,xperiodic,yperiodic,zperiodic);
 
201
      Kokkos::parallel_for(nlocal,f);
 
202
    }
 
203
  }
 
204
 
 
205
  LMPDeviceType::fence();
 
206
}
 
207