40 data::Atoms::force_t::atomic_access_slice force_;
58 KOKKOS_INLINE_FUNCTION
63 dist[0] = pos_(idx, 0) - pos_(jdx, 0);
64 dist[1] = pos_(idx, 1) - pos_(jdx, 1);
65 dist[2] = pos_(idx, 2) - pos_(jdx, 2);
69 auto invMassI = 1_r / mass_(idx);
70 auto invMassJ = 1_r / mass_(jdx);
71 auto reducedMass = 1_r / (invMassI + invMassJ);
74 relVel[0] = vel_(idx, 0) - vel_(jdx, 0);
75 relVel[1] = vel_(idx, 1) - vel_(jdx, 1);
76 relVel[2] = vel_(idx, 2) - vel_(jdx, 2);
78 auto factor =
util::dot3(relVel, dist) / distSq * reducedMass;
80 vel_(idx, 0) -= factor * dist[0] * invMassI;
81 vel_(idx, 1) -= factor * dist[1] * invMassI;
82 vel_(idx, 2) -= factor * dist[2] * invMassI;
84 vel_(jdx, 0) += factor * dist[0] * invMassJ;
85 vel_(jdx, 1) += factor * dist[1] * invMassJ;
86 vel_(jdx, 2) += factor * dist[2] * invMassJ;
89 KOKKOS_INLINE_FUNCTION
92 const real_t eqDistance)
const
96 dist[0] = pos_(idx, 0) - pos_(jdx, 0);
97 dist[1] = pos_(idx, 1) - pos_(jdx, 1);
98 dist[2] = pos_(idx, 2) - pos_(jdx, 2);
104 updatedDist[0] = updatedPos_(idx, 0) - updatedPos_(jdx, 0);
105 updatedDist[1] = updatedPos_(idx, 1) - updatedPos_(jdx, 1);
106 updatedDist[2] = updatedPos_(idx, 2) - updatedPos_(jdx, 2);
110 auto invMassI = 1_r / mass_(idx);
111 auto invMassJ = 1_r / mass_(jdx);
118 real_t determinant = b * b - 4_r * a * c;
120 determinant = Kokkos::max(0_r, determinant);
123 auto lambda1 = (-b + std::sqrt(determinant)) / (2_r * a);
124 auto lambda2 = (-b - std::sqrt(determinant)) / (2_r * a);
125 auto lambda = std::abs(lambda1) < std::abs(lambda2) ? lambda1 : lambda2;
129 force_(idx, 0) += lambda * dist[0];
130 force_(idx, 1) += lambda * dist[1];
131 force_(idx, 2) += lambda * dist[2];
133 force_(jdx, 0) -= lambda * dist[0];
134 force_(jdx, 1) -= lambda * dist[1];
135 force_(jdx, 2) -= lambda * dist[2];
138 KOKKOS_INLINE_FUNCTION
141 auto dtfm = dtf_ / mass_(idx);
142 updatedPos_(idx, 0) = pos_(idx, 0) + dtv_ * vel_(idx, 0) + dtfm * force_(idx, 0);
143 updatedPos_(idx, 1) = pos_(idx, 1) + dtv_ * vel_(idx, 1) + dtfm * force_(idx, 1);
144 updatedPos_(idx, 2) = pos_(idx, 2) + dtv_ * vel_(idx, 2) + dtfm * force_(idx, 2);
157 dtf_ = 0.5_r * dt * dt;
165 idx_t atomsPerMolecule_;
168 idx_t numConstraintIterations_;
177 for (
int iteration = 0; iteration < numConstraintIterations_; ++iteration)
179 auto policy = Kokkos::RangePolicy<impl::Shake::UnconstraintUpdate>(
181 Kokkos::parallel_for(
"Shake::UnconstraintUpdate", policy, shake);
188 auto kernel = KOKKOS_LAMBDA(
idx_t moleculeIdx)
190 auto atomsStart = moleculesAtomsOffset(moleculeIdx);
191 auto numAtoms = moleculesNumAtoms(moleculeIdx);
192 for (
idx_t bondIdx = 0; bondIdx < bonds.extent(0); ++bondIdx)
196 "not enough atoms in molecule to satisfy bond");
199 "not enough atoms in molecule to satisfy bond");
201 atomsStart + bonds(bondIdx).jdx,
202 bonds(bondIdx).eqDistance);
206 Kokkos::parallel_for(
207 "MoleculeConstraints::enforcePositionalConstraints", applyBondsPolicy, kernel);
220 auto kernel = KOKKOS_LAMBDA(
idx_t moleculeIdx)
222 auto atomsStart = moleculesAtomsOffset(moleculeIdx);
223 auto numAtoms = moleculesNumAtoms(moleculeIdx);
224 for (
idx_t bondIdx = 0; bondIdx < bonds.extent(0); ++bondIdx)
227 bonds(bondIdx).idx, numAtoms,
"not enough atoms in molecule to satisfy bond");
229 bonds(bondIdx).jdx, numAtoms,
"not enough atoms in molecule to satisfy bond");
231 atomsStart + bonds(bondIdx).jdx,
232 bonds(bondIdx).eqDistance);
235 Kokkos::parallel_for(
236 "MoleculeConstraints::enforceVelocityConstraints", applyBondsPolicy, kernel);
243 Kokkos::resize(bonds_, bonds.extent(0));
244 Kokkos::deep_copy(bonds_, bonds);
248 : atomsPerMolecule_(atomsPerMolecule), numConstraintIterations_(numConstraintIterations)
void enforceVelocityConstraints(data::Molecules &molecules, data::Atoms &atoms, const real_t dt)
Definition Shake.hpp:212
void enforcePositionalConstraints(data::Molecules &molecules, data::Atoms &atoms, const real_t dt)
Definition Shake.hpp:171
MoleculeConstraints(idx_t atomsPerMolecule, idx_t numConstraintIterations)
Definition Shake.hpp:247
void setConstraints(const data::BondView::host_mirror_type &bonds)
Definition Shake.hpp:241
void setConstraints(const data::BondView &bonds)
Definition Shake.hpp:240
SHAKE algorithm (DOI: 10.1016/0021-9991(77)90098-5) RATTLE algorithm (DOI: 10.1016/0021-9991(83)90014...
Definition Shake.hpp:36
KOKKOS_INLINE_FUNCTION void enforceVelocityConstraint(const idx_t idx, const idx_t jdx, const real_t eqDistance) const
Definition Shake.hpp:59
KOKKOS_INLINE_FUNCTION void operator()(UnconstraintUpdate, const idx_t idx) const
Definition Shake.hpp:139
Shake(data::Atoms &atoms, const real_t &dt)
Definition Shake.hpp:147
KOKKOS_INLINE_FUNCTION void enforcePositionalConstraint(const idx_t idx, const idx_t jdx, const real_t eqDistance) const
Definition Shake.hpp:90
Data structure for storing information about atoms on the host and the device.
Definition Atoms.hpp:35
KOKKOS_FORCEINLINE_FUNCTION vel_t getVel() const
Definition Atoms.hpp:65
idx_t numLocalAtoms
Definition Atoms.hpp:120
idx_t numGhostAtoms
Definition Atoms.hpp:121
KOKKOS_FORCEINLINE_FUNCTION pos_t getPos() const
Definition Atoms.hpp:64
typename AtomsT::template member_slice_type< MASS > mass_t
Definition Atoms.hpp:60
KOKKOS_FORCEINLINE_FUNCTION force_t getForce() const
Definition Atoms.hpp:66
typename AtomsT::template member_slice_type< POS > pos_t
Definition Atoms.hpp:56
KOKKOS_FORCEINLINE_FUNCTION charge_t getMass() const
Definition Atoms.hpp:68
typename AtomsT::template member_slice_type< VEL > vel_t
Definition Atoms.hpp:57
Definition Molecules.hpp:29
KOKKOS_FORCEINLINE_FUNCTION atoms_offset_t getAtomsOffset() const
Definition Molecules.hpp:67
KOKKOS_FORCEINLINE_FUNCTION num_atoms_t getNumAtoms() const
Definition Molecules.hpp:68
idx_t numLocalMolecules
Definition Molecules.hpp:120
#define MRMD_DEVICE_ASSERT_GREATER(...)
Definition device.hpp:471
#define MRMD_DEVICE_ASSERT_LESS(...)
Definition device.hpp:472
Kokkos::View< Bond * > BondView
Definition Bond.hpp:30
KOKKOS_INLINE_FUNCTION real_t sqr(const real_t &sqr)
Definition math.hpp:29
void grow(Kokkos::View< T, P... > &view, idx_t size, real_t safetyMargin=1.1_r)
Definition Kokkos_grow.hpp:25
KOKKOS_INLINE_FUNCTION real_t dot3(real_t const *const a, real_t const *const b)
Definition math.hpp:24
Definition BerendsenBarostat.cpp:18
KOKKOS_INLINE_FUNCTION constexpr idx_t idx_c(const T &val)
Definition datatypes.hpp:93
Kokkos::View< real_t *[3]> VectorView
Definition datatypes.hpp:163
int64_t idx_t
Definition datatypes.hpp:91
double real_t
Definition datatypes.hpp:99