MRMD 0.4.0
Multi Resolution Molecular Dynamics
Loading...
Searching...
No Matches
Atoms.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 <Cabana_Core.hpp>
18
19#include "cmake.hpp"
20#include "constants.hpp"
21#include "datatypes.hpp"
22
23namespace mrmd::data
24{
25namespace impl
26{
33template <class DEVICE_TYPE = DeviceType, bool DEVICE = true>
35{
36public:
37 enum Props
38 {
39 POS = 0,
40 VEL = 1,
41 FORCE = 2,
42 TYPE = 3,
43 MASS = 4,
44 CHARGE = 5,
46 };
47 using DataTypes = Cabana::MemberTypes<real_t[DIMENSIONS],
50 idx_t,
51 real_t,
52 real_t,
53 real_t>;
54 using AtomsT = Cabana::AoSoA<DataTypes, typename DEVICE_TYPE::memory_space, VECTOR_LENGTH>;
55
56 using pos_t = typename AtomsT::template member_slice_type<POS>;
57 using vel_t = typename AtomsT::template member_slice_type<VEL>;
58 using force_t = typename AtomsT::template member_slice_type<FORCE>;
59 using type_t = typename AtomsT::template member_slice_type<TYPE>;
60 using mass_t = typename AtomsT::template member_slice_type<MASS>;
61 using charge_t = typename AtomsT::template member_slice_type<CHARGE>;
62 using relative_mass_t = typename AtomsT::template member_slice_type<RELATIVE_MASS>;
63
71
72 void setForce(const real_t& val) const { Cabana::deep_copy(force, val); }
73
74 void sliceAll()
75 {
76 pos = Cabana::slice<POS>(atoms_);
77 vel = Cabana::slice<VEL>(atoms_);
78 force = Cabana::slice<FORCE>(atoms_);
79 type = Cabana::slice<TYPE>(atoms_);
80 mass = Cabana::slice<MASS>(atoms_);
81 charge = Cabana::slice<CHARGE>(atoms_);
82 relativeMass = Cabana::slice<RELATIVE_MASS>(atoms_);
83 }
84
85 KOKKOS_INLINE_FUNCTION auto size() const { return atoms_.size(); }
86 KOKKOS_INLINE_FUNCTION auto numSoA() const { return atoms_.numSoA(); }
87 KOKKOS_INLINE_FUNCTION auto arraySize(size_t s) const { return atoms_.arraySize(s); }
88
89 void resize(size_t size)
90 {
91 atoms_.resize(size);
92 sliceAll();
93 };
94
95 void permute(LinkedCellList& linkedCellList) const { Cabana::permute(linkedCellList, atoms_); }
96
98 void copy(const idx_t dst, const idx_t src) const
99 {
100 for (auto dim = 0; dim < DIMENSIONS; ++dim)
101 {
102 pos(dst, dim) = pos(src, dim);
103 vel(dst, dim) = vel(src, dim);
104 force(dst, dim) = force(src, dim);
105 }
106 type(dst) = type(src);
107 mass(dst) = mass(src);
108 charge(dst) = charge(src);
109 relativeMass(dst) = relativeMass(src);
110 }
111
117
118 auto& getAoSoA() const { return atoms_; }
119
122
123 explicit GeneralAtoms(const idx_t numAtoms) : atoms_("atoms", numAtoms)
124 {
125 sliceAll();
126 Cabana::deep_copy(pos, 0_r);
127 Cabana::deep_copy(vel, 0_r);
128 Cabana::deep_copy(force, 0_r);
129 Cabana::deep_copy(type, 0);
130 Cabana::deep_copy(mass, 0_r);
131 Cabana::deep_copy(charge, 0_r);
132 Cabana::deep_copy(relativeMass, 0_r);
133 }
134 template <class DEVICE_TYPE_SRC, bool DEVICE_SRC>
136
137private:
138 AtomsT atoms_;
139
140 pos_t pos;
141 vel_t vel;
142 force_t force;
143 type_t type;
144 mass_t mass;
145 charge_t charge;
146 relative_mass_t relativeMass;
147};
148} // namespace impl
149
150template <class DEVICE_TYPE_A, bool DEVICE_A, class DEVICE_TYPE_B, bool DEVICE_B>
153{
154 dst.numLocalAtoms = src.numLocalAtoms;
155 dst.numGhostAtoms = src.numGhostAtoms;
156 dst.resize(src.size());
157 Cabana::deep_copy(dst.getAoSoA(), src.getAoSoA());
158 dst.sliceAll();
159}
160
161namespace impl
162{
163template <class DEVICE_TYPE, bool DEVICE>
164template <class DEVICE_TYPE_SRC, bool DEVICE_SRC>
167 : atoms_("atoms", atoms.size())
168{
169 deep_copy(*this, atoms);
170}
171} // namespace impl
172
178} // namespace mrmd::data
Data structure for storing information about atoms on the host and the device.
Definition Atoms.hpp:35
void sliceAll()
Definition Atoms.hpp:74
typename AtomsT::template member_slice_type< RELATIVE_MASS > relative_mass_t
Definition Atoms.hpp:62
KOKKOS_INLINE_FUNCTION auto arraySize(size_t s) const
Definition Atoms.hpp:87
KOKKOS_INLINE_FUNCTION auto numSoA() const
Definition Atoms.hpp:86
KOKKOS_FORCEINLINE_FUNCTION relative_mass_t getRelativeMass() const
Definition Atoms.hpp:70
KOKKOS_FORCEINLINE_FUNCTION vel_t getVel() const
Definition Atoms.hpp:65
idx_t numLocalAtoms
Definition Atoms.hpp:120
typename AtomsT::template member_slice_type< FORCE > force_t
Definition Atoms.hpp:58
idx_t numGhostAtoms
Definition Atoms.hpp:121
KOKKOS_INLINE_FUNCTION auto size() const
Definition Atoms.hpp:85
Props
Definition Atoms.hpp:38
@ POS
Definition Atoms.hpp:39
@ RELATIVE_MASS
relative mass of the atom in relation to the molecule
Definition Atoms.hpp:45
@ CHARGE
Definition Atoms.hpp:44
@ VEL
Definition Atoms.hpp:40
@ MASS
Definition Atoms.hpp:43
@ TYPE
Definition Atoms.hpp:42
@ FORCE
Definition Atoms.hpp:41
KOKKOS_FORCEINLINE_FUNCTION charge_t getCharge() const
Definition Atoms.hpp:69
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
void removeGhostAtoms()
Definition Atoms.hpp:112
GeneralAtoms(const idx_t numAtoms)
Definition Atoms.hpp:123
typename AtomsT::template member_slice_type< TYPE > type_t
Definition Atoms.hpp:59
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
void resize(size_t size)
Definition Atoms.hpp:89
KOKKOS_FORCEINLINE_FUNCTION charge_t getMass() const
Definition Atoms.hpp:68
KOKKOS_INLINE_FUNCTION void copy(const idx_t dst, const idx_t src) const
Definition Atoms.hpp:98
void permute(LinkedCellList &linkedCellList) const
Definition Atoms.hpp:95
Cabana::AoSoA< DataTypes, typename DEVICE_TYPE::memory_space, VECTOR_LENGTH > AtomsT
Definition Atoms.hpp:54
typename AtomsT::template member_slice_type< VEL > vel_t
Definition Atoms.hpp:57
auto & getAoSoA() const
Definition Atoms.hpp:118
KOKKOS_FORCEINLINE_FUNCTION type_t getType() const
Definition Atoms.hpp:67
void setForce(const real_t &val) const
Definition Atoms.hpp:72
Cabana::MemberTypes< real_t[DIMENSIONS], real_t[DIMENSIONS], real_t[DIMENSIONS], idx_t, real_t, real_t, real_t > DataTypes
Definition Atoms.hpp:53
Definition Array.hpp:18
impl::GeneralAtoms< DeviceType, true > DeviceAtoms
atoms with memory allocated on device
Definition Atoms.hpp:176
void deep_copy(impl::GeneralAtoms< DEVICE_TYPE_A, DEVICE_A > &dst, const impl::GeneralAtoms< DEVICE_TYPE_B, DEVICE_B > &src)
Definition Atoms.hpp:151
static constexpr int DIMENSIONS
number of spatial dimensions
Definition constants.hpp:24
Cabana::LinkedCellList< typename DeviceType::memory_space > LinkedCellList
Definition datatypes.hpp:179
int64_t idx_t
Definition datatypes.hpp:91
double real_t
Definition datatypes.hpp:99
Definition Array.hpp:21