ls1-MarDyn
ls1-MarDyn molecular dynamics code
ConcatenatedSites.h
1
6#ifndef CONCATENATEDSITES_H
7#define CONCATENATEDSITES_H
8
9#include "AlignedArrayTriplet.h"
10#include "utils/mardyn_assert.h"
11#include "../particleContainer/adapter/vectorization/SIMD_TYPES.h"
12#include <array>
13
14namespace ConcSites {
18 enum class CoordinateType {
19 X, Y, Z
20 };
21
25 enum class SiteType {
26 LJC, CHARGE, DIPOLE, QUADRUPOLE
27 };
28} /*namespace ConcSites*/
29
36template<typename T>
38public:
39
40 /*
41 * \brief Constructor
42 */
43 ConcatenatedSites(size_t ljc_num = 0, size_t charges_num = 0,
44 size_t dipoles_num = 0, size_t quadrupoles_num = 0) {
45 resize(ljc_num, charges_num, dipoles_num, quadrupoles_num);
46 }
47
56 T* returnPointer = nullptr;
57
58 switch (coord) {
59 case ConcSites::CoordinateType::X:
60 returnPointer = _data.xBegin();
61 break;
62 case ConcSites::CoordinateType::Y:
63 returnPointer = _data.yBegin();
64 break;
65 case ConcSites::CoordinateType::Z:
66 returnPointer = _data.zBegin();
67 break;
68 }
69
70 mardyn_assert(returnPointer != nullptr);
71
72 switch (st) {
73 case ConcSites::SiteType::QUADRUPOLE:
74 returnPointer += AlignedArray<T>::_round_up(_dipoles_num); // fallthrough
75 /* no break */
76 case ConcSites::SiteType::DIPOLE:
77 returnPointer += AlignedArray<T>::_round_up(_charges_num); // fallthrough
78 /* no break */
79 case ConcSites::SiteType::CHARGE:
80 returnPointer += AlignedArray<T>::_round_up(_ljc_num);
81 /* no break */
82 case ConcSites::SiteType::LJC:
83 /* no break */ ; /* ; needed to compile here */
84 }
85
86 return returnPointer;
87 }
88
89 vcp_inline const T* getBeginPointer (ConcSites::SiteType st, ConcSites::CoordinateType coord) const {
90 const T* returnPointer = nullptr;
91 size_t offset = 0;
92
93 switch (st) {
94 case ConcSites::SiteType::QUADRUPOLE:
95 offset += AlignedArray<T>::_round_up(_dipoles_num); // fallthrough
96 /* no break */
97 case ConcSites::SiteType::DIPOLE:
98 offset += AlignedArray<T>::_round_up(_charges_num); // fallthrough
99 /* no break */
100 case ConcSites::SiteType::CHARGE:
101 offset += AlignedArray<T>::_round_up(_ljc_num);
102 /* no break */
103 case ConcSites::SiteType::LJC:
104 /* no break */ ; /* ; needed to compile here */
105 }
106
107 switch (coord) {
108 case ConcSites::CoordinateType::X:
109 returnPointer = _data.xBegin() + offset;
110 break;
111 case ConcSites::CoordinateType::Y:
112 returnPointer = _data.yBegin() + offset;
113 break;
114 case ConcSites::CoordinateType::Z:
115 returnPointer = _data.zBegin() + offset;
116 break;
117 }
118
119 mardyn_assert(returnPointer != nullptr);
120
121 return returnPointer;
122 }
123
127 vcp_inline std::array<T, 3> getTriplet(ConcSites::SiteType st, size_t index) const {
128 std::array<T, 3> retArray;
129 retArray[0] = getBeginPointer(st, ConcSites::CoordinateType::X)[index];
130 retArray[1] = getBeginPointer(st, ConcSites::CoordinateType::Y)[index];
131 retArray[2] = getBeginPointer(st, ConcSites::CoordinateType::Z)[index];
132 return retArray;
133 }
134
138 vcp_inline void setTriplet(std::array<T, 3> values, ConcSites::SiteType st, size_t index) {
139 getBeginPointer(st, ConcSites::CoordinateType::X)[index] = values[0];
140 getBeginPointer(st, ConcSites::CoordinateType::Y)[index] = values[1];
141 getBeginPointer(st, ConcSites::CoordinateType::Z)[index] = values[2];
142 }
143
151 void resize(size_t ljc_num, size_t charges_num, size_t dipoles_num, size_t quadrupoles_num) {
152 _ljc_num = ljc_num;
153 _charges_num = charges_num;
154 _dipoles_num = dipoles_num;
155 _quadrupoles_num = quadrupoles_num;
156
157 size_t num_centers =
159 + AlignedArray<T>::_round_up(_charges_num)
160 + AlignedArray<T>::_round_up(_dipoles_num)
161 + AlignedArray<T>::_round_up(_quadrupoles_num);
162
163 _data.resize_zero_shrink(num_centers);
164 setPaddingToZero(_data);
165 }
166
171 size_t get_dynamic_memory() const { return _data.get_dynamic_memory(); }
172
173private:
174
176
177// Is there a better solution than keeping them duplicated here and in CellDataSoA.h?
178// But need them unless getBeginPointer shall be moved to CellDataSoA.h
179// Sizes are duplicated in CellDataSoA, but there's no pretty way around this.
180 size_t _ljc_num;
181 size_t _charges_num;
182 size_t _dipoles_num;
183 size_t _quadrupoles_num;
184
185 /*
186 * \brief Set the unused memory to zero
187 */
188 void setPaddingToZero(AlignedArray<T>& t) const {
189 size_t ljc_size = t._round_up(_ljc_num);
190 size_t charges_size = t._round_up(_charges_num);
191 size_t dipoles_size = t._round_up(_dipoles_num);
192
193 t.zero(_ljc_num);
194 t.zero(ljc_size + _charges_num);
195 t.zero(ljc_size + charges_size + _dipoles_num);
196 t.zero(ljc_size + charges_size + dipoles_size + _quadrupoles_num);
197 }
198
199};
200
201#endif /* CONCATENATEDSITES_H */
Definition: AlignedArrayTriplet.h:15
An aligned array.
Definition: AlignedArray.h:75
Class to manage the storage of ljc-, charge-, dipole- and quadrupole-data in one single AlignedArrayT...
Definition: ConcatenatedSites.h:37
void resize(size_t ljc_num, size_t charges_num, size_t dipoles_num, size_t quadrupoles_num)
Resize the ConcatenatedSites to have enough space for the given number of elements.
Definition: ConcatenatedSites.h:151
vcp_inline void setTriplet(std::array< T, 3 > values, ConcSites::SiteType st, size_t index)
Set the value triplet X,Y,Z of ConcSites::SiteType st at position index to given values.
Definition: ConcatenatedSites.h:138
vcp_inline T * getBeginPointer(ConcSites::SiteType st, ConcSites::CoordinateType coord)
Get a Pointer to the beginning of the specified data.
Definition: ConcatenatedSites.h:55
vcp_inline std::array< T, 3 > getTriplet(ConcSites::SiteType st, size_t index) const
Get the value triplet X,Y,Z of ConcSites::SiteType st at position index.
Definition: ConcatenatedSites.h:127
size_t get_dynamic_memory() const
Get the size of currently occupied memory.
Definition: ConcatenatedSites.h:171
Definition: ConcatenatedSites.h:14
SiteType
Specify which of the 4 data-categories is needed.
Definition: ConcatenatedSites.h:25
CoordinateType
What coordinate would you like to have?
Definition: ConcatenatedSites.h:18