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 "fix_wall_reflect_kokkos.h"
16 
17 #include "atom_kokkos.h"
18 #include "atom_masks.h"
19 #include "input.h"
20 #include "modify.h"
21 #include "update.h"
22 #include "variable.h"
23 
24 #include <cstring>
25 
26 using namespace LAMMPS_NS;
27 using namespace FixConst;
28 
29 enum{XLO=0,XHI=1,YLO=2,YHI=3,ZLO=4,ZHI=5};
30 enum{NONE=0,EDGE,CONSTANT,VARIABLE};
31 
32 
33 /* ---------------------------------------------------------------------- */
34 
35 template<class DeviceType>
FixWallReflectKokkos(LAMMPS * lmp,int narg,char ** arg)36 FixWallReflectKokkos<DeviceType>::FixWallReflectKokkos(LAMMPS *lmp, int narg, char **arg) :
37   FixWallReflect(lmp, narg, arg)
38 {
39   kokkosable = 1;
40   atomKK = (AtomKokkos *) atom;
41   execution_space = ExecutionSpaceFromDevice<DeviceType>::space;
42   datamask_read = X_MASK | V_MASK | MASK_MASK;
43   datamask_modify = X_MASK | V_MASK;
44 }
45 
46 /* ---------------------------------------------------------------------- */
47 
48 template<class DeviceType>
post_integrate()49 void FixWallReflectKokkos<DeviceType>::post_integrate()
50 {
51   // coord = current position of wall
52   // evaluate variable if necessary, wrap with clear/add
53 
54   atomKK->sync(execution_space,datamask_read);
55   atomKK->modified(execution_space,datamask_modify);
56 
57   x = atomKK->k_x.view<DeviceType>();
58   v = atomKK->k_v.view<DeviceType>();
59   mask = atomKK->k_mask.view<DeviceType>();
60   int nlocal = atom->nlocal;
61 
62 
63   if (varflag) modify->clearstep_compute();
64 
65   for (int m = 0; m < nwall; m++) {
66     if (wallstyle[m] == VARIABLE) {
67       coord = input->variable->compute_equal(varindex[m]);
68       if (wallwhich[m] < YLO) coord *= xscale;
69       else if (wallwhich[m] < ZLO) coord *= yscale;
70       else coord *= zscale;
71     } else coord = coord0[m];
72 
73     dim = wallwhich[m] / 2;
74     side = wallwhich[m] % 2;
75 
76     copymode = 1;
77     Kokkos::parallel_for(Kokkos::RangePolicy<DeviceType, TagFixWallReflectPostIntegrate>(0,nlocal),*this);
78     copymode = 0;
79   }
80 
81   if (varflag) modify->addstep_compute(update->ntimestep + 1);
82 }
83 
84 template<class DeviceType>
85 KOKKOS_INLINE_FUNCTION
operator ()(TagFixWallReflectPostIntegrate,const int & i) const86 void FixWallReflectKokkos<DeviceType>::operator()(TagFixWallReflectPostIntegrate, const int &i) const {
87   if (mask[i] & groupbit) {
88     if (side == 0) {
89       if (x(i,dim) < coord) {
90         x(i,dim) = coord + (coord - x(i,dim));
91         v(i,dim) = -v(i,dim);
92       }
93     } else {
94       if (x(i,dim) > coord) {
95         x(i,dim) = coord - (x(i,dim) - coord);
96         v(i,dim) = -v(i,dim);
97       }
98     }
99   }
100 }
101 
102 /* ---------------------------------------------------------------------- */
103 
104 namespace LAMMPS_NS {
105 template class FixWallReflectKokkos<LMPDeviceType>;
106 #ifdef LMP_KOKKOS_GPU
107 template class FixWallReflectKokkos<LMPHostType>;
108 #endif
109 }
110 
111