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_dpd_energy_kokkos.h"
16 #include "atom_masks.h"
17 #include "atom_kokkos.h"
18 #include "update.h"
19 #include "error.h"
20
21 using namespace LAMMPS_NS;
22 using namespace FixConst;
23
24 /* ---------------------------------------------------------------------- */
25
26 template <typename DeviceType>
FixDPDenergyKokkos(LAMMPS * lmp,int narg,char ** arg)27 FixDPDenergyKokkos<DeviceType>::FixDPDenergyKokkos(LAMMPS *lmp, int narg, char **arg) :
28 FixDPDenergy(lmp, narg, arg)
29 {
30 kokkosable = 1;
31 atomKK = (AtomKokkos *) atom;
32 execution_space = ExecutionSpaceFromDevice<DeviceType>::space;
33 datamask_read = EMPTY_MASK;
34 datamask_modify = EMPTY_MASK;
35 pairDPDEKK = dynamic_cast<decltype(pairDPDEKK)>(pairDPDE);
36 if (!pairDPDEKK)
37 error->all(FLERR,"Must use pair_style dpd/fdt/energy/kk with fix dpd/energy/kk");
38 }
39
40 /* ---------------------------------------------------------------------- */
41
42 template <typename DeviceType>
take_half_step()43 void FixDPDenergyKokkos<DeviceType>::take_half_step()
44 {
45 int nlocal = atom->nlocal;
46 if (igroup == atom->firstgroup) nlocal = atom->nfirst;
47
48 using AT = ArrayTypes<DeviceType>;
49
50 atomKK->sync(execution_space, UCOND_MASK);
51 typename AT::t_efloat_1d uCond = atomKK->k_uCond.view<DeviceType>();
52 atomKK->sync(execution_space, UMECH_MASK);
53 typename AT::t_efloat_1d uMech = atomKK->k_uMech.view<DeviceType>();
54
55 pairDPDEKK->k_duCond.template sync<DeviceType>();
56 typename AT::t_efloat_1d_const duCond = pairDPDEKK->k_duCond.template view<DeviceType>();
57 pairDPDEKK->k_duMech.template sync<DeviceType>();
58 typename AT::t_efloat_1d_const duMech = pairDPDEKK->k_duMech.template view<DeviceType>();
59
60 auto dt = update->dt;
61
62 Kokkos::parallel_for(Kokkos::RangePolicy<DeviceType>(0,nlocal),
63 LAMMPS_LAMBDA(int i) {
64 uCond(i) += 0.5*dt*duCond(i);
65 uMech(i) += 0.5*dt*duMech(i);
66 });
67
68 atomKK->modified(execution_space, UCOND_MASK);
69 atomKK->modified(execution_space, UMECH_MASK);
70 }
71
72 /* ---------------------------------------------------------------------- */
73
74 template <typename DeviceType>
initial_integrate(int)75 void FixDPDenergyKokkos<DeviceType>::initial_integrate(int)
76 {
77 take_half_step();
78 }
79
80 /* ---------------------------------------------------------------------- */
81
82 template <typename DeviceType>
final_integrate()83 void FixDPDenergyKokkos<DeviceType>::final_integrate()
84 {
85 take_half_step();
86 }
87
88 namespace LAMMPS_NS {
89 template class FixDPDenergyKokkos<LMPDeviceType>;
90 #ifdef LMP_KOKKOS_GPU
91 template class FixDPDenergyKokkos<LMPHostType>;
92 #endif
93 }
94