1
/* ----------------------------------------------------------------------
2
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
3
http://lammps.sandia.gov, Sandia National Laboratories
4
Steve Plimpton, sjplimp@sandia.gov
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.
11
See the README file in the top-level LAMMPS directory.
12
------------------------------------------------------------------------- */
17
#include "fix_langevin_kokkos.h"
18
#include "atom_masks.h"
19
#include "atom_kokkos.h"
26
#include "random_mars.h"
33
using namespace LAMMPS_NS;
34
using namespace FixConst;
37
enum{CONSTANT,EQUAL,ATOM};
38
#define SINERTIA 0.4 // moment of inertia prefactor for sphere
39
#define EINERTIA 0.2 // moment of inertia prefactor for ellipsoid
41
/* ---------------------------------------------------------------------- */
43
template<class DeviceType>
44
FixLangevinKokkos<DeviceType>::FixLangevinKokkos(LAMMPS *lmp, int narg, char **arg) :
45
FixLangevin(lmp, narg, arg),rand_pool(seed + comm->me)
47
atomKK = (AtomKokkos *) atom;
48
int ntypes = atomKK->ntypes;
50
// allocate per-type arrays for force prefactors
51
memory->create_kokkos(k_gfactor1,gfactor1,ntypes+1,"langevin:gfactor1");
52
memory->create_kokkos(k_gfactor2,gfactor2,ntypes+1,"langevin:gfactor2");
53
memory->create_kokkos(k_ratio,ratio,ntypes+1,"langevin:ratio");
54
d_gfactor1 = k_gfactor1.template view<DeviceType>();
55
h_gfactor1 = k_gfactor1.template view<LMPHostType>();
56
d_gfactor2 = k_gfactor2.template view<DeviceType>();
57
h_gfactor2 = k_gfactor2.template view<LMPHostType>();
58
d_ratio = k_ratio.template view<DeviceType>();
59
h_ratio = k_ratio.template view<LMPHostType>();
62
for (int i = 1; i <= ntypes; i++) ratio[i] = 1.0;
63
k_ratio.template modify<LMPHostType>();
67
grow_arrays(atomKK->nmax);
68
atom->add_callback(0);
69
// initialize franprev to zero
70
for (int i = 0; i < atomKK->nlocal; i++) {
75
k_franprev.template modify<LMPHostType>();
78
k_fsumall = tdual_double_1d_3n("langevin:fsumall");
79
h_fsumall = k_fsumall.template view<LMPHostType>();
80
d_fsumall = k_fsumall.template view<DeviceType>();
83
execution_space = ExecutionSpaceFromDevice<DeviceType>::space;
84
datamask_read = V_MASK | F_MASK | MASK_MASK | RMASS_MASK | TYPE_MASK;
85
datamask_modify = F_MASK;
89
/* ---------------------------------------------------------------------- */
91
template<class DeviceType>
92
FixLangevinKokkos<DeviceType>::~FixLangevinKokkos()
94
memory->destroy_kokkos(k_gfactor1,gfactor1);
95
memory->destroy_kokkos(k_gfactor2,gfactor2);
96
memory->destroy_kokkos(k_ratio,ratio);
97
memory->destroy_kokkos(k_flangevin,flangevin);
98
if(gjfflag) memory->destroy_kokkos(k_franprev,franprev);
99
memory->destroy_kokkos(k_tforce,tforce);
102
/* ---------------------------------------------------------------------- */
104
template<class DeviceType>
105
void FixLangevinKokkos<DeviceType>::init()
109
error->all(FLERR,"Fix langevin omega is not yet implemented with kokkos");
111
error->all(FLERR,"Fix langevin angmom is not yet implemented with kokkos");
113
// prefactors are modified in the init
114
k_gfactor1.template modify<LMPHostType>();
115
k_gfactor2.template modify<LMPHostType>();
118
/* ---------------------------------------------------------------------- */
120
template<class DeviceType>
121
void FixLangevinKokkos<DeviceType>::grow_arrays(int nmax)
123
memory->grow_kokkos(k_franprev,franprev,nmax,3,"langevin:franprev");
124
d_franprev = k_franprev.template view<DeviceType>();
125
h_franprev = k_franprev.template view<LMPHostType>();
128
/* ---------------------------------------------------------------------- */
130
template<class DeviceType>
131
void FixLangevinKokkos<DeviceType>::post_force(int vflag)
133
// sync the device views which might have been modified on host
134
atomKK->sync(execution_space,datamask_read);
135
rmass = atomKK->rmass;
136
f = atomKK->k_f.template view<DeviceType>();
137
v = atomKK->k_v.template view<DeviceType>();
138
type = atomKK->k_type.template view<DeviceType>();
139
mask = atomKK->k_mask.template view<DeviceType>();
141
k_gfactor1.template sync<DeviceType>();
142
k_gfactor2.template sync<DeviceType>();
143
k_ratio.template sync<DeviceType>();
144
if(gjfflag) k_franprev.template sync<DeviceType>();
146
boltz = force->boltz;
148
mvv2e = force->mvv2e;
149
ftm2v = force->ftm2v;
150
fran_prop_const = sqrt(24.0*boltz/t_period/dt/mvv2e);
152
compute_target(); // modifies tforce vector, hence sync here
153
k_tforce.template sync<DeviceType>();
155
double fsum[3],fsumall[3];
157
int nlocal = atomKK->nlocal;
160
fsum[0] = fsum[1] = fsum[2] = 0.0;
161
count = group->count(igroup);
163
error->all(FLERR,"Cannot zero Langevin force of 0 atoms");
166
// reallocate flangevin if necessary
168
if (nlocal > maxatom1) {
169
memory->destroy_kokkos(k_flangevin,flangevin);
170
maxatom1 = atomKK->nmax;
171
memory->create_kokkos(k_flangevin,flangevin,maxatom1,3,"langevin:flangevin");
172
d_flangevin = k_flangevin.template view<DeviceType>();
173
h_flangevin = k_flangevin.template view<LMPHostType>();
177
// account for bias velocity
178
if(tbiasflag == BIAS){
179
temperature->compute_scalar();
180
temperature->remove_bias_all(); // modifies velocities
181
// if temeprature compute is kokkosized host-devcie comm won't be needed
182
atomKK->modified(Host,V_MASK);
183
atomKK->sync(execution_space,V_MASK);
186
// compute langevin force in parallel on the device
191
if (tbiasflag == BIAS)
194
FixLangevinKokkosPostForceFunctor<DeviceType,1,1,1,1,1,1> post_functor(this);
195
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
198
FixLangevinKokkosPostForceFunctor<DeviceType,1,1,1,1,1,0> post_functor(this);
199
Kokkos::parallel_for(nlocal,post_functor);
203
FixLangevinKokkosPostForceFunctor<DeviceType,1,1,1,1,0,1> post_functor(this);
204
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
207
FixLangevinKokkosPostForceFunctor<DeviceType,1,1,1,1,0,0> post_functor(this);
208
Kokkos::parallel_for(nlocal,post_functor);
213
FixLangevinKokkosPostForceFunctor<DeviceType,1,1,1,0,1,1> post_functor(this);
214
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
217
FixLangevinKokkosPostForceFunctor<DeviceType,1,1,1,0,1,0> post_functor(this);
218
Kokkos::parallel_for(nlocal,post_functor);
222
FixLangevinKokkosPostForceFunctor<DeviceType,1,1,1,0,0,1> post_functor(this);
223
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
226
FixLangevinKokkosPostForceFunctor<DeviceType,1,1,1,0,0,0> post_functor(this);
227
Kokkos::parallel_for(nlocal,post_functor);
230
if (tbiasflag == BIAS)
233
FixLangevinKokkosPostForceFunctor<DeviceType,1,1,0,1,1,1> post_functor(this);
234
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
237
FixLangevinKokkosPostForceFunctor<DeviceType,1,1,0,1,1,0> post_functor(this);
238
Kokkos::parallel_for(nlocal,post_functor);
242
FixLangevinKokkosPostForceFunctor<DeviceType,1,1,0,1,0,1> post_functor(this);
243
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
246
FixLangevinKokkosPostForceFunctor<DeviceType,1,1,0,1,0,0> post_functor(this);
247
Kokkos::parallel_for(nlocal,post_functor);
252
FixLangevinKokkosPostForceFunctor<DeviceType,1,1,0,0,1,1> post_functor(this);
253
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
256
FixLangevinKokkosPostForceFunctor<DeviceType,1,1,0,0,1,0> post_functor(this);
257
Kokkos::parallel_for(nlocal,post_functor);
261
FixLangevinKokkosPostForceFunctor<DeviceType,1,1,0,0,0,1> post_functor(this);
262
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
265
FixLangevinKokkosPostForceFunctor<DeviceType,1,1,0,0,0,0> post_functor(this);
266
Kokkos::parallel_for(nlocal,post_functor);
270
if (tbiasflag == BIAS)
273
FixLangevinKokkosPostForceFunctor<DeviceType,1,0,1,1,1,1> post_functor(this);
274
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
277
FixLangevinKokkosPostForceFunctor<DeviceType,1,0,1,1,1,0> post_functor(this);
278
Kokkos::parallel_for(nlocal,post_functor);
282
FixLangevinKokkosPostForceFunctor<DeviceType,1,0,1,1,0,1> post_functor(this);
283
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
286
FixLangevinKokkosPostForceFunctor<DeviceType,1,0,1,1,0,0> post_functor(this);
287
Kokkos::parallel_for(nlocal,post_functor);
292
FixLangevinKokkosPostForceFunctor<DeviceType,1,0,1,0,1,1> post_functor(this);
293
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
296
FixLangevinKokkosPostForceFunctor<DeviceType,1,0,1,0,1,0> post_functor(this);
297
Kokkos::parallel_for(nlocal,post_functor);
301
FixLangevinKokkosPostForceFunctor<DeviceType,1,0,1,0,0,1> post_functor(this);
302
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
305
FixLangevinKokkosPostForceFunctor<DeviceType,1,0,1,0,0,0> post_functor(this);
306
Kokkos::parallel_for(nlocal,post_functor);
309
if (tbiasflag == BIAS)
312
FixLangevinKokkosPostForceFunctor<DeviceType,1,0,0,1,1,1> post_functor(this);
313
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
316
FixLangevinKokkosPostForceFunctor<DeviceType,1,0,0,1,1,0> post_functor(this);
317
Kokkos::parallel_for(nlocal,post_functor);
321
FixLangevinKokkosPostForceFunctor<DeviceType,1,0,0,1,0,1> post_functor(this);
322
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
325
FixLangevinKokkosPostForceFunctor<DeviceType,1,0,0,1,0,0> post_functor(this);
326
Kokkos::parallel_for(nlocal,post_functor);
331
FixLangevinKokkosPostForceFunctor<DeviceType,1,0,0,0,1,1> post_functor(this);
332
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
335
FixLangevinKokkosPostForceFunctor<DeviceType,1,0,0,0,1,0> post_functor(this);
336
Kokkos::parallel_for(nlocal,post_functor);
340
FixLangevinKokkosPostForceFunctor<DeviceType,1,0,0,0,0,1> post_functor(this);
341
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
344
FixLangevinKokkosPostForceFunctor<DeviceType,1,0,0,0,0,0> post_functor(this);
345
Kokkos::parallel_for(nlocal,post_functor);
350
if (tbiasflag == BIAS)
353
FixLangevinKokkosPostForceFunctor<DeviceType,0,1,1,1,1,1> post_functor(this);
354
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
357
FixLangevinKokkosPostForceFunctor<DeviceType,0,1,1,1,1,0> post_functor(this);
358
Kokkos::parallel_for(nlocal,post_functor);
362
FixLangevinKokkosPostForceFunctor<DeviceType,0,1,1,1,0,1> post_functor(this);
363
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
366
FixLangevinKokkosPostForceFunctor<DeviceType,0,1,1,1,0,0> post_functor(this);
367
Kokkos::parallel_for(nlocal,post_functor);
372
FixLangevinKokkosPostForceFunctor<DeviceType,0,1,1,0,1,1> post_functor(this);
373
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
376
FixLangevinKokkosPostForceFunctor<DeviceType,0,1,1,0,1,0> post_functor(this);
377
Kokkos::parallel_for(nlocal,post_functor);
381
FixLangevinKokkosPostForceFunctor<DeviceType,0,1,1,0,0,1> post_functor(this);
382
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
385
FixLangevinKokkosPostForceFunctor<DeviceType,0,1,1,0,0,0> post_functor(this);
386
Kokkos::parallel_for(nlocal,post_functor);
389
if (tbiasflag == BIAS)
392
FixLangevinKokkosPostForceFunctor<DeviceType,0,1,0,1,1,1> post_functor(this);
393
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
396
FixLangevinKokkosPostForceFunctor<DeviceType,0,1,0,1,1,0> post_functor(this);
397
Kokkos::parallel_for(nlocal,post_functor);
401
FixLangevinKokkosPostForceFunctor<DeviceType,0,1,0,1,0,1> post_functor(this);
402
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
405
FixLangevinKokkosPostForceFunctor<DeviceType,0,1,0,1,0,0> post_functor(this);
406
Kokkos::parallel_for(nlocal,post_functor);
411
FixLangevinKokkosPostForceFunctor<DeviceType,0,1,0,0,1,1> post_functor(this);
412
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
415
FixLangevinKokkosPostForceFunctor<DeviceType,0,1,0,0,1,0> post_functor(this);
416
Kokkos::parallel_for(nlocal,post_functor);
420
FixLangevinKokkosPostForceFunctor<DeviceType,0,1,0,0,0,1> post_functor(this);
421
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
424
FixLangevinKokkosPostForceFunctor<DeviceType,0,1,0,0,0,0> post_functor(this);
425
Kokkos::parallel_for(nlocal,post_functor);
429
if (tbiasflag == BIAS)
432
FixLangevinKokkosPostForceFunctor<DeviceType,0,0,1,1,1,1> post_functor(this);
433
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
436
FixLangevinKokkosPostForceFunctor<DeviceType,0,0,1,1,1,0> post_functor(this);
437
Kokkos::parallel_for(nlocal,post_functor);
441
FixLangevinKokkosPostForceFunctor<DeviceType,0,0,1,1,0,1> post_functor(this);
442
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
445
FixLangevinKokkosPostForceFunctor<DeviceType,0,0,1,1,0,0> post_functor(this);
446
Kokkos::parallel_for(nlocal,post_functor);
451
FixLangevinKokkosPostForceFunctor<DeviceType,0,0,1,0,1,1> post_functor(this);
452
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
455
FixLangevinKokkosPostForceFunctor<DeviceType,0,0,1,0,1,0> post_functor(this);
456
Kokkos::parallel_for(nlocal,post_functor);
460
FixLangevinKokkosPostForceFunctor<DeviceType,0,0,1,0,0,1> post_functor(this);
461
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
464
FixLangevinKokkosPostForceFunctor<DeviceType,0,0,1,0,0,0> post_functor(this);
465
Kokkos::parallel_for(nlocal,post_functor);
468
if (tbiasflag == BIAS)
471
FixLangevinKokkosPostForceFunctor<DeviceType,0,0,0,1,1,1> post_functor(this);
472
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
475
FixLangevinKokkosPostForceFunctor<DeviceType,0,0,0,1,1,0> post_functor(this);
476
Kokkos::parallel_for(nlocal,post_functor);
480
FixLangevinKokkosPostForceFunctor<DeviceType,0,0,0,1,0,1> post_functor(this);
481
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
484
FixLangevinKokkosPostForceFunctor<DeviceType,0,0,0,1,0,0> post_functor(this);
485
Kokkos::parallel_for(nlocal,post_functor);
490
FixLangevinKokkosPostForceFunctor<DeviceType,0,0,0,0,1,1> post_functor(this);
491
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
494
FixLangevinKokkosPostForceFunctor<DeviceType,0,0,0,0,1,0> post_functor(this);
495
Kokkos::parallel_for(nlocal,post_functor);
499
FixLangevinKokkosPostForceFunctor<DeviceType,0,0,0,0,0,1> post_functor(this);
500
Kokkos::parallel_reduce(nlocal,post_functor,s_fsum);
503
FixLangevinKokkosPostForceFunctor<DeviceType,0,0,0,0,0,0> post_functor(this);
504
Kokkos::parallel_for(nlocal,post_functor);
509
if(tbiasflag == BIAS){
510
temperature->restore_bias_all(); // modifies velocities
511
atomKK->modified(Host,V_MASK);
514
// set modify flags for the views modified in post_force functor
515
if (gjfflag) k_franprev.template modify<DeviceType>();
516
if (tallyflag) k_flangevin.template modify<DeviceType>();
518
// set total force to zero
520
fsum[0] = s_fsum.fx; fsum[1] = s_fsum.fy; fsum[2] = s_fsum.fz;
521
MPI_Allreduce(fsum,fsumall,3,MPI_DOUBLE,MPI_SUM,world);
522
h_fsumall(0) = fsumall[0]/count;
523
h_fsumall(1) = fsumall[1]/count;
524
h_fsumall(2) = fsumall[2]/count;
525
k_fsumall.template modify<LMPHostType>();
526
k_fsumall.template sync<DeviceType>();
527
// set total force zero in parallel on the device
528
FixLangevinKokkosZeroForceFunctor<DeviceType> zero_functor(this);
529
Kokkos::parallel_for(nlocal,zero_functor);
532
// f is modified by both post_force and zero_force functors
533
atomKK->modified(execution_space,datamask_modify);
535
// thermostat omega and angmom
536
// if (oflag) omega_thermostat();
537
// if (ascale) angmom_thermostat();
541
/* ---------------------------------------------------------------------- */
543
template<class DeviceType>
544
template<int Tp_TSTYLEATOM, int Tp_GJF, int Tp_TALLY,
545
int Tp_BIAS, int Tp_RMASS, int Tp_ZERO>
546
KOKKOS_INLINE_FUNCTION
547
FSUM FixLangevinKokkos<DeviceType>::post_force_item(int i) const
550
double fdrag[3],fran[3];
551
double gamma1,gamma2;
553
double tsqrt_t = tsqrt;
555
if (mask[i] & groupbit) {
556
rand_type rand_gen = rand_pool.get_state();
557
if(Tp_TSTYLEATOM) tsqrt_t = sqrt(d_tforce[i]);
559
gamma1 = -rmass[i] / t_period / ftm2v;
560
gamma2 = sqrt(rmass[i]) * fran_prop_const / ftm2v;
561
gamma1 *= 1.0/d_ratio[type[i]];
562
gamma2 *= 1.0/sqrt(d_ratio[type[i]]) * tsqrt_t;
564
gamma1 = d_gfactor1[type[i]];
565
gamma2 = d_gfactor2[type[i]] * tsqrt_t;
568
fran[0] = gamma2 * (rand_gen.drand() - 0.5); //(random->uniform()-0.5);
569
fran[1] = gamma2 * (rand_gen.drand() - 0.5); //(random->uniform()-0.5);
570
fran[2] = gamma2 * (rand_gen.drand() - 0.5); //(random->uniform()-0.5);
573
fdrag[0] = gamma1*v(i,0);
574
fdrag[1] = gamma1*v(i,1);
575
fdrag[2] = gamma1*v(i,2);
576
if (v(i,0) == 0.0) fran[0] = 0.0;
577
if (v(i,1) == 0.0) fran[1] = 0.0;
578
if (v(i,2) == 0.0) fran[2] = 0.0;
580
fdrag[0] = gamma1*v(i,0);
581
fdrag[1] = gamma1*v(i,1);
582
fdrag[2] = gamma1*v(i,2);
586
fswap = 0.5*(fran[0]+d_franprev(i,0));
587
d_franprev(i,0) = fran[0];
589
fswap = 0.5*(fran[1]+d_franprev(i,1));
590
d_franprev(i,1) = fran[1];
592
fswap = 0.5*(fran[2]+d_franprev(i,2));
593
d_franprev(i,2) = fran[2];
607
f(i,0) += fdrag[0] + fran[0];
608
f(i,1) += fdrag[1] + fran[1];
609
f(i,2) += fdrag[2] + fran[2];
612
d_flangevin(i,0) = fdrag[0] + fran[0];
613
d_flangevin(i,1) = fdrag[1] + fran[1];
614
d_flangevin(i,2) = fdrag[2] + fran[2];
622
rand_pool.free_state(rand_gen);
628
/* ---------------------------------------------------------------------- */
630
template<class DeviceType>
631
KOKKOS_INLINE_FUNCTION
632
void FixLangevinKokkos<DeviceType>::zero_force_item(int i) const
634
if (mask[i] & groupbit) {
635
f(i,0) -= d_fsumall[0];
636
f(i,1) -= d_fsumall[1];
637
f(i,2) -= d_fsumall[2];
642
/* ----------------------------------------------------------------------
643
set current t_target and t_sqrt
644
------------------------------------------------------------------------- */
646
template<class DeviceType>
647
void FixLangevinKokkos<DeviceType>::compute_target()
649
atomKK->sync(Host, MASK_MASK);
650
mask = atomKK->k_mask.template view<DeviceType>();
651
int nlocal = atomKK->nlocal;
653
double delta = update->ntimestep - update->beginstep;
654
if (delta != 0.0) delta /= update->endstep - update->beginstep;
656
// if variable temp, evaluate variable, wrap with clear/add
657
// reallocate tforce array if necessary
659
if (tstyle == CONSTANT) {
660
t_target = t_start + delta * (t_stop-t_start);
661
tsqrt = sqrt(t_target);
663
modify->clearstep_compute();
664
if (tstyle == EQUAL) {
665
t_target = input->variable->compute_equal(tvar);
667
error->one(FLERR,"Fix langevin variable returned negative temperature");
668
tsqrt = sqrt(t_target);
670
if (nlocal > maxatom2) {
671
maxatom2 = atom->nmax;
672
memory->destroy_kokkos(k_tforce,tforce);
673
memory->create_kokkos(k_tforce,tforce,maxatom2,"langevin:tforce");
674
d_tforce = k_tforce.template view<DeviceType>();
675
h_tforce = k_tforce.template view<LMPHostType>();
677
input->variable->compute_atom(tvar,igroup,tforce,1,0); // tforce is modified on host
678
k_tforce.template modify<LMPHostType>();
679
for (int i = 0; i < nlocal; i++)
680
if (mask[i] & groupbit)
681
if (h_tforce[i] < 0.0)
683
"Fix langevin variable returned negative temperature");
685
modify->addstep_compute(update->ntimestep + 1);
689
/* ---------------------------------------------------------------------- */
691
template<class DeviceType>
692
void FixLangevinKokkos<DeviceType>::reset_dt()
695
for (int i = 1; i <= atomKK->ntypes; i++) {
696
h_gfactor2[i] = sqrt(atomKK->mass[i]) *
697
sqrt(24.0*force->boltz/t_period/update->dt/force->mvv2e) /
699
h_gfactor2[i] *= 1.0/sqrt(h_ratio[i]);
701
k_gfactor2.template modify<LMPHostType>();
706
/* ---------------------------------------------------------------------- */
708
template<class DeviceType>
709
double FixLangevinKokkos<DeviceType>::compute_scalar()
711
if (!tallyflag || flangevin == NULL) return 0.0;
713
v = atomKK->k_v.template view<DeviceType>();
714
mask = atomKK->k_mask.template view<DeviceType>();
716
// capture the very first energy transfer to thermal reservoir
718
if (update->ntimestep == update->beginstep) {
719
energy_onestep = 0.0;
720
atomKK->sync(execution_space,V_MASK | MASK_MASK);
721
int nlocal = atomKK->nlocal;
722
k_flangevin.template sync<DeviceType>();
723
FixLangevinKokkosTallyEnergyFunctor<DeviceType> scalar_functor(this);
724
Kokkos::parallel_reduce(nlocal,scalar_functor,energy_onestep);
726
energy = 0.5*energy_onestep*update->dt;
729
// convert midstep energy back to previous fullstep energy
730
double energy_me = energy - 0.5*energy_onestep*update->dt;
732
MPI_Allreduce(&energy_me,&energy_all,1,MPI_DOUBLE,MPI_SUM,world);
736
/* ---------------------------------------------------------------------- */
738
template<class DeviceType>
739
KOKKOS_INLINE_FUNCTION
740
double FixLangevinKokkos<DeviceType>::compute_energy_item(int i) const
743
if (mask[i] & groupbit)
744
energy = d_flangevin(i,0)*v(i,0) + d_flangevin(i,1)*v(i,1) +
745
d_flangevin(i,2)*v(i,2);
749
/* ----------------------------------------------------------------------
750
tally energy transfer to thermal reservoir
751
------------------------------------------------------------------------- */
753
template<class DeviceType>
754
void FixLangevinKokkos<DeviceType>::end_of_step()
756
if (!tallyflag) return;
758
v = atomKK->k_v.template view<DeviceType>();
759
mask = atomKK->k_mask.template view<DeviceType>();
761
atomKK->sync(execution_space,V_MASK | MASK_MASK);
762
int nlocal = atomKK->nlocal;
764
energy_onestep = 0.0;
766
k_flangevin.template sync<DeviceType>();
767
FixLangevinKokkosTallyEnergyFunctor<DeviceType> tally_functor(this);
768
Kokkos::parallel_reduce(nlocal,tally_functor,energy_onestep);
771
energy += energy_onestep*update->dt;
774
/* ----------------------------------------------------------------------
775
copy values within local atom-based array
776
------------------------------------------------------------------------- */
778
template<class DeviceType>
779
void FixLangevinKokkos<DeviceType>::copy_arrays(int i, int j, int delflag)
781
for (int m = 0; m < nvalues; m++)
782
h_franprev(j,m) = h_franprev(i,m);
784
k_franprev.template modify<LMPHostType>();
788
/* ---------------------------------------------------------------------- */
790
template<class DeviceType>
791
void FixLangevinKokkos<DeviceType>::cleanup_copy()
807
template class FixLangevinKokkos<LMPDeviceType>;
808
#ifdef KOKKOS_HAVE_CUDA
809
template class FixLangevinKokkos<LMPHostType>;