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

« back to all changes in this revision

Viewing changes to src/KOKKOS/fix_langevin_kokkos.h

  • 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
/* -*- c++ -*- ----------------------------------------------------------
 
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
#ifdef FIX_CLASS
 
15
 
 
16
FixStyle(langevin/kk,FixLangevinKokkos<LMPDeviceType>)
 
17
FixStyle(langevin/kk/device,FixLangevinKokkos<LMPDeviceType>)
 
18
FixStyle(langevin/kk/host,FixLangevinKokkos<LMPHostType>)
 
19
 
 
20
#else
 
21
 
 
22
#ifndef LMP_FIX_LANGEVIN_KOKKOS_H
 
23
#define LMP_FIX_LANGEVIN_KOKKOS_H
 
24
 
 
25
#include "fix_langevin.h"
 
26
#include "kokkos_type.h"
 
27
#include "Kokkos_Random.hpp"
 
28
#include "comm_kokkos.h"
 
29
 
 
30
namespace LAMMPS_NS {
 
31
 
 
32
  struct s_FSUM {
 
33
    double fx, fy, fz;
 
34
    KOKKOS_INLINE_FUNCTION
 
35
    s_FSUM() {
 
36
      fx = fy = fz = 0.0;
 
37
    }
 
38
    KOKKOS_INLINE_FUNCTION
 
39
    s_FSUM& operator+=(const s_FSUM &rhs){
 
40
      fx += rhs.fx;
 
41
      fy += rhs.fy;
 
42
      fz += rhs.fz;
 
43
      return *this;
 
44
    }
 
45
    
 
46
    KOKKOS_INLINE_FUNCTION
 
47
    volatile s_FSUM& operator+=(const volatile s_FSUM &rhs) volatile {
 
48
      fx += rhs.fx;
 
49
      fy += rhs.fy;
 
50
      fz += rhs.fz;
 
51
      return *this;
 
52
    }
 
53
  };
 
54
  typedef s_FSUM FSUM;
 
55
 
 
56
  template<class DeviceType>
 
57
    class FixLangevinKokkos;
 
58
 
 
59
  template<class DeviceType,int Tp_TSTYLEATOM, int Tp_GJF, int Tp_TALLY,
 
60
    int Tp_BIAS, int Tp_RMASS, int Tp_ZERO>
 
61
    class FixLangevinKokkosPostForceFunctor;
 
62
 
 
63
  template<class DeviceType> class FixLangevinKokkosZeroForceFunctor;
 
64
 
 
65
  template<class DeviceType> class FixLangevinKokkosTallyEnergyFunctor;
 
66
 
 
67
  template<class DeviceType>
 
68
    class FixLangevinKokkos : public FixLangevin {
 
69
  public:
 
70
    FixLangevinKokkos(class LAMMPS *, int, char **);
 
71
    ~FixLangevinKokkos();
 
72
 
 
73
    void cleanup_copy();
 
74
    void init();
 
75
    void post_force(int);
 
76
    void reset_dt();
 
77
    void grow_arrays(int);
 
78
    void copy_arrays(int i, int j, int delflag);
 
79
    double compute_scalar();
 
80
    void end_of_step();
 
81
 
 
82
    template<int Tp_TSTYLEATOM, int Tp_GJF, int Tp_TALLY,
 
83
      int Tp_BIAS, int Tp_RMASS, int Tp_ZERO>
 
84
      KOKKOS_INLINE_FUNCTION
 
85
      FSUM post_force_item(int) const;
 
86
 
 
87
    KOKKOS_INLINE_FUNCTION
 
88
      void zero_force_item(int) const;
 
89
 
 
90
    KOKKOS_INLINE_FUNCTION
 
91
      double compute_energy_item(int) const;
 
92
 
 
93
  private:
 
94
    class CommKokkos *commKK;
 
95
    class AtomKokkos *atomKK;
 
96
    double *rmass;
 
97
    typename ArrayTypes<DeviceType>::tdual_double_2d k_franprev;
 
98
    typename ArrayTypes<DeviceType>::t_double_2d d_franprev;
 
99
    HAT::t_double_2d h_franprev;
 
100
 
 
101
    typename ArrayTypes<DeviceType>::tdual_double_2d k_flangevin;
 
102
    typename ArrayTypes<DeviceType>::t_double_2d d_flangevin;
 
103
    HAT::t_double_2d h_flangevin;
 
104
 
 
105
    typename ArrayTypes<DeviceType>::tdual_double_1d k_tforce;
 
106
    typename ArrayTypes<DeviceType>::t_double_1d d_tforce;
 
107
    HAT::t_double_1d h_tforce;
 
108
 
 
109
    typename ArrayTypes<DeviceType>::t_v_array v;
 
110
    typename ArrayTypes<DeviceType>::t_f_array f;
 
111
    typename ArrayTypes<DeviceType>::t_int_1d type;
 
112
    typename ArrayTypes<DeviceType>::t_int_1d mask;
 
113
 
 
114
    typename ArrayTypes<DeviceType>::tdual_double_1d k_gfactor1, k_gfactor2, k_ratio;
 
115
    typename ArrayTypes<DeviceType>::t_double_1d d_gfactor1, d_gfactor2, d_ratio;
 
116
    HAT::t_double_1d h_gfactor1, h_gfactor2, h_ratio;
 
117
 
 
118
    typedef Kokkos::DualView<double[3], DeviceType>
 
119
      tdual_double_1d_3n;
 
120
    tdual_double_1d_3n k_fsumall;
 
121
    typename tdual_double_1d_3n::t_dev d_fsumall;
 
122
    typename tdual_double_1d_3n::t_host h_fsumall;
 
123
 
 
124
    double boltz,dt,mvv2e,ftm2v,fran_prop_const;
 
125
 
 
126
    void compute_target();
 
127
 
 
128
    Kokkos::Random_XorShift64_Pool<DeviceType> rand_pool;
 
129
    typedef typename Kokkos::Random_XorShift64_Pool<DeviceType>::generator_type rand_type;
 
130
 
 
131
  };
 
132
 
 
133
  template <class DeviceType,int Tp_TSTYLEATOM, int Tp_GJF, int Tp_TALLY,
 
134
    int Tp_BIAS, int Tp_RMASS, int Tp_ZERO>
 
135
    struct FixLangevinKokkosPostForceFunctor {
 
136
 
 
137
      typedef DeviceType  device_type;
 
138
      typedef FSUM value_type;
 
139
      FixLangevinKokkos<DeviceType> c;
 
140
 
 
141
    FixLangevinKokkosPostForceFunctor(FixLangevinKokkos<DeviceType>* c_ptr):
 
142
      c(*c_ptr) {}
 
143
      ~FixLangevinKokkosPostForceFunctor(){c.cleanup_copy();}
 
144
 
 
145
      KOKKOS_INLINE_FUNCTION
 
146
      void operator()(const int i) const {
 
147
        c.template post_force_item<Tp_TSTYLEATOM,Tp_GJF, Tp_TALLY,
 
148
          Tp_BIAS,Tp_RMASS,Tp_ZERO>(i);
 
149
      }
 
150
 
 
151
      KOKKOS_INLINE_FUNCTION
 
152
      void operator()(const int i, value_type &fsum) const {
 
153
 
 
154
        fsum += c.template post_force_item<Tp_TSTYLEATOM,Tp_GJF, Tp_TALLY,
 
155
          Tp_BIAS,Tp_RMASS,Tp_ZERO>(i);
 
156
      }
 
157
 
 
158
      KOKKOS_INLINE_FUNCTION
 
159
      static void init(volatile value_type &update) {
 
160
        update.fx = 0.0;
 
161
        update.fy = 0.0;
 
162
        update.fz = 0.0;
 
163
      }
 
164
      KOKKOS_INLINE_FUNCTION
 
165
      static void join(volatile value_type &update,
 
166
                       const volatile value_type &source) {
 
167
        update.fx += source.fx;
 
168
        update.fy += source.fy;
 
169
        update.fz += source.fz;
 
170
      }
 
171
 
 
172
    };
 
173
 
 
174
  template <class DeviceType>
 
175
    struct FixLangevinKokkosZeroForceFunctor {
 
176
      typedef DeviceType  device_type ;
 
177
      FixLangevinKokkos<DeviceType> c;
 
178
 
 
179
    FixLangevinKokkosZeroForceFunctor(FixLangevinKokkos<DeviceType>* c_ptr):
 
180
      c(*c_ptr) {c.cleanup_copy();}
 
181
 
 
182
      KOKKOS_INLINE_FUNCTION
 
183
      void operator()(const int i) const {
 
184
        c.zero_force_item(i);
 
185
      }
 
186
    };
 
187
 
 
188
  template<class DeviceType>
 
189
    struct FixLangevinKokkosTallyEnergyFunctor {
 
190
      typedef DeviceType  device_type ;
 
191
      FixLangevinKokkos<DeviceType> c;
 
192
      typedef double value_type;
 
193
    FixLangevinKokkosTallyEnergyFunctor(FixLangevinKokkos<DeviceType>* c_ptr):
 
194
      c(*c_ptr) {c.cleanup_copy();}
 
195
 
 
196
      KOKKOS_INLINE_FUNCTION
 
197
      void operator()(const int i, value_type &energy) const {
 
198
        energy += c.compute_energy_item(i);
 
199
      }
 
200
      KOKKOS_INLINE_FUNCTION
 
201
      static void init(volatile value_type &update) {
 
202
        update = 0.0;
 
203
      }
 
204
      KOKKOS_INLINE_FUNCTION
 
205
      static void join(volatile value_type &update,
 
206
                       const volatile value_type &source) {
 
207
        update += source;
 
208
      }
 
209
    };
 
210
}
 
211
 
 
212
#endif
 
213
#endif
 
214
 
 
215
/* ERROR/WARNING messages:
 
216
 
 
217
   E: Illegal ... command
 
218
 
 
219
   Self-explanatory.  Check the input script syntax and compare to the
 
220
   documentation for the command.  You can use -echo screen as a
 
221
   command-line option when running LAMMPS to see the offending line.
 
222
 
 
223
   E: Fix langevin period must be > 0.0
 
224
 
 
225
   The time window for temperature relaxation must be > 0
 
226
 
 
227
   E: Fix langevin omega requires atom style sphere
 
228
 
 
229
   Self-explanatory.
 
230
 
 
231
   E: Fix langevin angmom requires atom style ellipsoid
 
232
 
 
233
   Self-explanatory.
 
234
 
 
235
   E: Variable name for fix langevin does not exist
 
236
 
 
237
   Self-explanatory.
 
238
 
 
239
   E: Variable for fix langevin is invalid style
 
240
 
 
241
   It must be an equal-style variable.
 
242
 
 
243
   E: Fix langevin omega requires extended particles
 
244
 
 
245
   One of the particles has radius 0.0.
 
246
 
 
247
   E: Fix langevin angmom requires extended particles
 
248
 
 
249
   This fix option cannot be used with point paritlces.
 
250
 
 
251
   E: Cannot zero Langevin force of 0 atoms
 
252
 
 
253
   The group has zero atoms, so you cannot request its force
 
254
   be zeroed.
 
255
 
 
256
   E: Fix langevin variable returned negative temperature
 
257
 
 
258
   Self-explanatory.
 
259
 
 
260
   E: Could not find fix_modify temperature ID
 
261
 
 
262
   The compute ID for computing temperature does not exist.
 
263
 
 
264
   E: Fix_modify temperature ID does not compute temperature
 
265
 
 
266
   The compute ID assigned to the fix must compute temperature.
 
267
 
 
268
   W: Group for fix_modify temp != fix group
 
269
 
 
270
   The fix_modify command is specifying a temperature computation that
 
271
   computes a temperature on a different group of atoms than the fix
 
272
   itself operates on.  This is probably not what you want to do.
 
273
 
 
274
*/