26namespace mrmd::action::impl
34 Energy(
const Energy& rhs) =
default;
36 KOKKOS_INLINE_FUNCTION
37 Energy& operator+=(
const Energy& src)
40 coulomb += src.coulomb;
49struct reduction_identity<
mrmd::action::impl::Energy>
51 KOKKOS_FORCEINLINE_FUNCTION
static mrmd::action::impl::Energy sum()
53 return mrmd::action::impl::Energy();
72 impl::CappedLennardJonesPotential LJ_;
73 impl::Coulomb coulomb_;
77 data::Molecules::force_t::atomic_access_slice moleculesForce_;
85 data::Atoms::force_t::atomic_access_slice atomsForce_;
97 bool isDriftCompensationSamplingRun_ =
false;
101 idx_t runCounter_ = 0;
103 data::BondView::host_mirror_type bonds_;
152 impl::Energy& sumEnergy)
const
154 const auto numNeighbors =
idx_c(HalfNeighborList::numNeighbor(verletList_,
alpha));
155 for (
idx_t n = 0; n < numNeighbors; ++n)
158 const idx_t beta =
idx_c(HalfNeighborList::getNeighbor(verletList_,
alpha, n));
162 const auto startAtomsAlpha = moleculesAtomsOffset_(
alpha);
164 const auto endAtomsAlpha = startAtomsAlpha + moleculesNumAtoms_(
alpha);
165 assert(0 <= startAtomsAlpha);
166 assert(startAtomsAlpha < endAtomsAlpha);
169 const auto startAtomsBeta = moleculesAtomsOffset_(beta);
171 const auto endAtomsBeta = startAtomsBeta + moleculesNumAtoms_(beta);
172 assert(0 <= startAtomsBeta);
173 assert(startAtomsBeta < endAtomsBeta);
177 posTmp[0] = atomsPos_(startAtomsAlpha, 0);
178 posTmp[1] = atomsPos_(startAtomsAlpha, 1);
179 posTmp[2] = atomsPos_(startAtomsAlpha, 2);
182 dx[0] = posTmp[0] - atomsPos_(startAtomsBeta, 0);
183 dx[1] = posTmp[1] - atomsPos_(startAtomsBeta, 1);
184 dx[2] = posTmp[2] - atomsPos_(startAtomsBeta, 2);
188 if (distSqr < rcSqr_)
190 auto forceAndVirial = LJ_.computeForceAndEnergy(distSqr, 0);
191 sumEnergy.LJ += forceAndVirial.energy;
193 atomsForce_(startAtomsBeta, 0) -= dx[0] * forceAndVirial.forceFactor;
194 atomsForce_(startAtomsBeta, 1) -= dx[1] * forceAndVirial.forceFactor;
195 atomsForce_(startAtomsBeta, 2) -= dx[2] * forceAndVirial.forceFactor;
197 atomsForce_(startAtomsAlpha, 0) += dx[0] * forceAndVirial.forceFactor;
198 atomsForce_(startAtomsAlpha, 1) += dx[1] * forceAndVirial.forceFactor;
199 atomsForce_(startAtomsAlpha, 2) += dx[2] * forceAndVirial.forceFactor;
203 for (
idx_t idx = startAtomsAlpha; idx < endAtomsAlpha; ++idx)
206 posTmp[0] = atomsPos_(idx, 0);
207 posTmp[1] = atomsPos_(idx, 1);
208 posTmp[2] = atomsPos_(idx, 2);
210 auto q1 = atomsCharge_(idx);
213 real_t forceTmpIdx[3] = {0_r, 0_r, 0_r};
215 for (
idx_t jdx = startAtomsBeta; jdx < endAtomsBeta; ++jdx)
217 auto q2 = atomsCharge_(jdx);
220 dx[0] = posTmp[0] - atomsPos_(jdx, 0);
221 dx[1] = posTmp[1] - atomsPos_(jdx, 1);
222 dx[2] = posTmp[2] - atomsPos_(jdx, 2);
226 if (distSqr > rcSqr_)
continue;
228 auto ffactor = coulomb_.computeForce(distSqr, q1, q2);
229 sumEnergy.coulomb += coulomb_.computeEnergy(distSqr, q1, q2);
231 forceTmpIdx[0] += dx[0] * ffactor;
232 forceTmpIdx[1] += dx[1] * ffactor;
233 forceTmpIdx[2] += dx[2] * ffactor;
235 atomsForce_(jdx, 0) -= dx[0] * ffactor;
236 atomsForce_(jdx, 1) -= dx[1] * ffactor;
237 atomsForce_(jdx, 2) -= dx[2] * ffactor;
240 atomsForce_(idx, 0) += forceTmpIdx[0];
241 atomsForce_(idx, 1) += forceTmpIdx[1];
242 atomsForce_(idx, 2) += forceTmpIdx[2];
263 moleculesPos_ = molecules.
getPos();
264 moleculesForce_ = molecules.
getForce();
265 moleculesLambda_ = molecules.
getLambda();
270 atomsPos_ = atoms.
getPos();
273 verletList_ = verletList;
279 auto energy = impl::Energy();
280 auto policy = Kokkos::RangePolicy<CalcInteractions>(0, molecules.
numLocalMolecules);
281 Kokkos::parallel_reduce(
282 "SPC::applyForces", policy, *
this, Kokkos::Sum<impl::Energy>(energy));
303 const auto startAtomsAlpha = moleculesAtomsOffset_(
alpha);
304 assert(0 <= startAtomsAlpha);
306 auto idxO = startAtomsAlpha;
307 auto idxH0 = startAtomsAlpha + 1;
308 auto idxH1 = startAtomsAlpha + 2;
313 dx[0] = atomsPos_(idxO, 0) - atomsPos_(idxH0, 0);
314 dx[1] = atomsPos_(idxO, 1) - atomsPos_(idxH0, 1);
315 dx[2] = atomsPos_(idxO, 2) - atomsPos_(idxH0, 2);
319 dx[0] = atomsPos_(idxO, 0) - atomsPos_(idxH1, 0);
320 dx[1] = atomsPos_(idxO, 1) - atomsPos_(idxH1, 1);
321 dx[2] = atomsPos_(idxO, 2) - atomsPos_(idxH1, 2);
325 dx[0] = atomsPos_(idxH0, 0) - atomsPos_(idxH1, 0);
326 dx[1] = atomsPos_(idxH0, 1) - atomsPos_(idxH1, 1);
327 dx[2] = atomsPos_(idxH0, 2) - atomsPos_(idxH1, 2);
334 const real_t& harmonicPreFactor)
336 moleculesPos_ = molecules.
getPos();
337 moleculesForce_ = molecules.
getForce();
338 moleculesLambda_ = molecules.
getLambda();
343 atomsPos_ = atoms.
getPos();
348 auto policy = Kokkos::RangePolicy<BondEnergy>(
350 Kokkos::parallel_reduce(
"SPC::calcHarmonicPotential", policy, *
this, energy);
High-level interface for the application of SHAKE/RATTLE position and velocity constraints to given m...
Definition Shake.hpp:170
void enforceVelocityConstraints(data::Molecules &molecules, data::Atoms &atoms, const real_t dt)
Definition Shake.hpp:219
void enforcePositionalConstraints(data::Molecules &molecules, data::Atoms &atoms, const real_t dt)
Definition Shake.hpp:178
void setConstraints(const data::BondView &bonds)
Definition Shake.hpp:247
static constexpr idx_t COMPENSATION_ENERGY_SAMPLING_INTERVAL
Definition SPC.hpp:132
SPC()
Definition SPC.hpp:357
static constexpr real_t massH
unit: g/mol
Definition SPC.hpp:115
static constexpr real_t rc
unit: nm
Definition SPC.hpp:122
void applyForces(data::Molecules &molecules, HalfVerletList &verletList, data::Atoms &atoms)
Definition SPC.hpp:261
void enforceVelocityConstraints(data::Molecules &molecules, data::Atoms &atoms, real_t dt)
Definition SPC.hpp:254
auto getEnergyLJ() const
Definition SPC.hpp:109
auto getEnergyCoulomb() const
Definition SPC.hpp:110
static constexpr real_t chargeH
Definition SPC.hpp:116
const real_t eqDistanceHH
Definition SPC.hpp:130
real_t sumEnergyLJ_
Definition SPC.hpp:106
static constexpr idx_t COMPENSATION_ENERGY_UPDATE_INTERVAL
Definition SPC.hpp:133
KOKKOS_INLINE_FUNCTION void operator()(CalcInteractions, const idx_t &alpha, impl::Energy &sumEnergy) const
Loop over molecules.
Definition SPC.hpp:150
void enforcePositionalConstraints(data::Molecules &molecules, data::Atoms &atoms, real_t dt)
Definition SPC.hpp:247
real_t calcBondEnergy(data::Molecules &molecules, data::Atoms &atoms, const real_t &harmonicPreFactor)
Definition SPC.hpp:332
static constexpr real_t sigma
unit: nm
Definition SPC.hpp:120
static constexpr real_t angleHOH
unit: radians
Definition SPC.hpp:129
static constexpr real_t chargeO
Definition SPC.hpp:113
static constexpr real_t epsilon
unit: kJ / mol
Definition SPC.hpp:121
static constexpr real_t massO
unit: g/mol
Definition SPC.hpp:112
const auto & getMeanCompensationEnergy() const
Definition SPC.hpp:135
static constexpr real_t alpha
unit: 1/nm
Definition SPC.hpp:125
static constexpr real_t eqDistanceHO
unit: nm, equilibirum distance between hydrogen and oxygen
Definition SPC.hpp:128
real_t sumEnergyCoulomb_
Definition SPC.hpp:107
KOKKOS_INLINE_FUNCTION void operator()(BondEnergy, const idx_t &alpha, real_t &sumEnergy) const
Definition SPC.hpp:300
idx_t numLocalAtoms
Definition Atoms.hpp:120
idx_t numGhostAtoms
Definition Atoms.hpp:121
KOKKOS_FORCEINLINE_FUNCTION charge_t getCharge() const
Definition Atoms.hpp:69
KOKKOS_FORCEINLINE_FUNCTION pos_t getPos() const
Definition Atoms.hpp:64
KOKKOS_FORCEINLINE_FUNCTION force_t getForce() const
Definition Atoms.hpp:66
typename AtomsT::template member_slice_type< CHARGE > charge_t
Definition Atoms.hpp:61
typename AtomsT::template member_slice_type< POS > pos_t
Definition Atoms.hpp:56
typename MoleculesT::template member_slice_type< GRAD_LAMBDA > grad_lambda_t
Definition Molecules.hpp:54
KOKKOS_FORCEINLINE_FUNCTION atoms_offset_t getAtomsOffset() const
Definition Molecules.hpp:67
KOKKOS_FORCEINLINE_FUNCTION num_atoms_t getNumAtoms() const
Definition Molecules.hpp:68
typename MoleculesT::template member_slice_type< MODULATED_LAMBDA > modulated_lambda_t
Definition Molecules.hpp:53
KOKKOS_FORCEINLINE_FUNCTION force_t getForce() const
Definition Molecules.hpp:59
KOKKOS_FORCEINLINE_FUNCTION pos_t getPos() const
Definition Molecules.hpp:58
typename MoleculesT::template member_slice_type< LAMBDA > lambda_t
Definition Molecules.hpp:52
KOKKOS_FORCEINLINE_FUNCTION modulated_lambda_t getModulatedLambda() const
Definition Molecules.hpp:62
typename MoleculesT::template member_slice_type< NUM_ATOMS > num_atoms_t
Definition Molecules.hpp:56
idx_t numGhostMolecules
Definition Molecules.hpp:121
KOKKOS_FORCEINLINE_FUNCTION lambda_t getLambda() const
Definition Molecules.hpp:61
typename MoleculesT::template member_slice_type< ATOMS_OFFSET > atoms_offset_t
Definition Molecules.hpp:55
idx_t numLocalMolecules
Definition Molecules.hpp:120
KOKKOS_FORCEINLINE_FUNCTION grad_lambda_t getGradLambda() const
Definition Molecules.hpp:66
typename MoleculesT::template member_slice_type< POS > pos_t
Definition Molecules.hpp:50
DeviceMolecules Molecules
Definition Molecules.hpp:176
DeviceAtoms Atoms
Definition Atoms.hpp:177
KOKKOS_INLINE_FUNCTION constexpr real_t degToRad(const real_t &grd)
converts degree to radians
Definition angle.hpp:28
KOKKOS_INLINE_FUNCTION real_t sqr(const real_t &sqr)
Definition math.hpp:29
KOKKOS_INLINE_FUNCTION real_t dot3(real_t const *const a, real_t const *const b)
Definition math.hpp:24
Top-level namespace of MRMD.
Cabana::VerletList< Kokkos::DefaultExecutionSpace::memory_space, Cabana::HalfNeighborTag, Cabana::VerletLayout2D, Cabana::TeamOpTag > HalfVerletList
Definition datatypes.hpp:184
KOKKOS_INLINE_FUNCTION constexpr idx_t idx_c(const T &val)
Definition datatypes.hpp:93
int64_t idx_t
Definition datatypes.hpp:91
Kokkos::Experimental::ScatterView< real_t * > ScalarScatterView
Definition datatypes.hpp:160
double real_t
Definition datatypes.hpp:99
KOKKOS_INLINE_FUNCTION constexpr real_t real_c(T t)
Definition datatypes.hpp:114
Definition Histogram.hpp:26