MRMD 0.4.0
Multi Resolution Molecular Dynamics
Loading...
Searching...
No Matches
NoForce.hpp
Go to the documentation of this file.
1// Copyright 2024 Sebastian Eibl
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include "data/Atoms.hpp"
18#include "datatypes.hpp"
19
20namespace mrmd::action
21{
23{
24private:
26 data::Atoms::force_t::atomic_access_slice force_;
28
29 HalfVerletList verletList_;
30
31public:
32 KOKKOS_INLINE_FUNCTION
33 real_t computeForce(const real_t& /*distSqr*/) const { /* TO BE IMPLEMENTED */ return 0_r; }
34
35 KOKKOS_INLINE_FUNCTION
36 void operator()(const idx_t& idx) const
37 {
38 real_t posTmp[3];
39 posTmp[0] = pos_(idx, 0);
40 posTmp[1] = pos_(idx, 1);
41 posTmp[2] = pos_(idx, 2);
42
43 real_t forceTmp[3] = {0_r, 0_r, 0_r};
44
45 const auto numNeighbors = idx_c(HalfNeighborList::numNeighbor(verletList_, idx));
46 for (idx_t n = 0; n < numNeighbors; ++n)
47 {
48 idx_t jdx = idx_c(HalfNeighborList::getNeighbor(verletList_, idx, n));
49 assert(0 <= jdx);
50
51 auto dx = posTmp[0] - pos_(jdx, 0);
52 auto dy = posTmp[1] - pos_(jdx, 1);
53 auto dz = posTmp[2] - pos_(jdx, 2);
54
55 auto distSqr = dx * dx + dy * dy + dz * dz;
56
57 auto force = computeForce(distSqr);
58
59 forceTmp[0] += dx * force;
60 forceTmp[1] += dy * force;
61 forceTmp[2] += dz * force;
62
63 force_(jdx, 0) -= dx * force;
64 force_(jdx, 1) -= dy * force;
65 force_(jdx, 2) -= dz * force;
66 }
67
68 force_(idx, 0) += forceTmp[0];
69 force_(idx, 1) += forceTmp[1];
70 force_(idx, 2) += forceTmp[2];
71 }
72
73 void apply(data::Atoms& atoms, HalfVerletList& verletList);
74
75 NoForce() = default;
76};
77} // namespace mrmd::action
Definition NoForce.hpp:23
KOKKOS_INLINE_FUNCTION real_t computeForce(const real_t &) const
Definition NoForce.hpp:33
KOKKOS_INLINE_FUNCTION void operator()(const idx_t &idx) const
Definition NoForce.hpp:36
void apply(data::Atoms &atoms, HalfVerletList &verletList)
Definition NoForce.cpp:19
Data structure for storing information about atoms on the host and the device.
Definition Atoms.hpp:35
typename AtomsT::template member_slice_type< TYPE > type_t
Definition Atoms.hpp:59
typename AtomsT::template member_slice_type< POS > pos_t
Definition Atoms.hpp:56
Definition BerendsenBarostat.cpp:20
KOKKOS_INLINE_FUNCTION constexpr idx_t idx_c(const T &val)
Definition datatypes.hpp:93
Cabana::VerletList< Kokkos::DefaultExecutionSpace::memory_space, Cabana::HalfNeighborTag, Cabana::VerletLayout2D, Cabana::TeamOpTag > HalfVerletList
Definition datatypes.hpp:187
int64_t idx_t
Definition datatypes.hpp:91
double real_t
Definition datatypes.hpp:99