68 static inline constexpr Tvec
generator(Tscal dr, std::array<i32, dim> coord)
noexcept {
75 = {2 * i + (sycl::abs(j + k) % 2),
76 sycl::sqrt(3.) * (j + (1. / 3.) * (sycl::abs(k) % 2)),
77 2 * sycl::sqrt(6.) * k / 3};
91 std::array<i32, dim> coord_min, std::array<i32, dim> coord_max) {
92 if (coord_max[0] - coord_min[0] < 2) {
96 if ((coord_max[1] + coord_min[1]) % 2 != 0) {
100 if ((coord_max[2] + coord_min[2]) % 2 != 0) {
117 Tscal dr, std::array<i32, dim> coord_min, std::array<i32, dim> coord_max) {
118 Tscal xmin, xmax, ymin, ymax, zmin, zmax;
120 xmin = 2 * coord_min[0];
121 xmax = 2 * coord_max[0];
123 ymin = sycl::sqrt(3.) * coord_min[1];
124 ymax = sycl::sqrt(3.) * coord_max[1];
126 zmin = 2 * sycl::sqrt(6.) * coord_min[2] / 3;
127 zmax = 2 * sycl::sqrt(6.) * coord_max[2] / 3;
131 "x axis count should be greater than 1\n"
132 "y axis count should be even\n"
133 "z axis count should be even");
136 return {Tvec{xmin, ymin, zmin} * dr, Tvec{xmax, ymax, zmax} * dr};
139 static inline constexpr std::pair<std::array<i32, dim>, std::array<i32, dim>>
172 static inline constexpr std::pair<std::array<i32, dim>, std::array<i32, dim>>
174 std::array<i32, dim> coord_min, std::array<i32, dim> coord_max) {
175 std::array<i32, dim> ret_coord_min;
176 std::array<i32, dim> ret_coord_max;
178 ret_coord_min[0] = coord_min[0];
179 ret_coord_min[1] = coord_min[1];
180 ret_coord_min[2] = coord_min[2];
182 ret_coord_max[0] = coord_max[0];
183 ret_coord_max[1] = coord_max[1];
184 ret_coord_max[2] = coord_max[2];
186 if (coord_max[0] - coord_min[0] < 2) {
190 if ((coord_max[1] + coord_min[1]) % 2 != 0) {
194 if ((coord_max[2] + coord_min[2]) % 2 != 0) {
198 return {ret_coord_min, ret_coord_max};
207 std::array<i32, dim> coord_min;
209 std::array<size_t, dim> coord_delta;
216 Iterator(Tscal dr, std::array<i32, dim> coord_min, std::array<i32, dim> coord_max)
217 : dr(dr), coord_min(coord_min), current_idx(0),
219 size_t(coord_max[0] - coord_min[0]),
220 size_t(coord_max[1] - coord_min[1]),
221 size_t(coord_max[2] - coord_min[2]),
225 for (
int ax = 0; ax < dim; ax++) {
226 if (coord_min[ax] == coord_max[ax]) {
231 max_coord = coord_delta[0] * coord_delta[1] * coord_delta[2];
234 inline bool is_done() {
return done; }
244 std::array<i32, 3> current = {
245 coord_min[0] +
i32(current_idx % coord_delta[0]),
246 coord_min[1] +
i32((current_idx / coord_delta[0]) % coord_delta[1]),
247 coord_min[2] +
i32((current_idx / (coord_delta[0] * coord_delta[1]))),
257 if (current_idx >= max_coord) {
264 inline std::vector<Tvec> next_n(
u64 nmax) {
265 std::vector<Tvec> ret{};
266 for (
u64 i = 0; i < nmax; i++) {
271 ret.push_back(next());
273 shamlog_debug_ln(
"Discontinuous iterator",
"next_n final idx", current_idx);
277 inline void skip(
u64 n) {
281 if (current_idx >= max_coord) {
284 shamlog_debug_ln(
"Discontinuous iterator",
"skip final idx", current_idx);
295 std::array<std::vector<size_t>, dim> remapped_indices;
297 std::array<size_t, dim> coord_delta;
305 Tscal dr, std::array<i32, dim> coord_min, std::array<i32, dim> coord_max)
306 : dr(dr), current_idx(0), coord_delta({
307 size_t(coord_max[0] - coord_min[0]),
308 size_t(coord_max[1] - coord_min[1]),
309 size_t(coord_max[2] - coord_min[2]),
313 for (
int ax = 0; ax < dim; ax++) {
314 if (coord_min[ax] == coord_max[ax]) {
319 max_coord = coord_delta[0] * coord_delta[1] * coord_delta[2];
321 for (
int ax = 0; ax < dim; ax++) {
323 while (!it.is_done()) {
324 remapped_indices[ax].push_back(it.next());
329 inline bool is_done() {
return done; }
339 std::array<i32, 3> current = {
340 i32(current_idx % coord_delta[0]),
341 i32((current_idx / coord_delta[0]) % coord_delta[1]),
342 i32((current_idx / (coord_delta[0] * coord_delta[1]))),
345 current[0] = remapped_indices[0][current[0]];
346 current[1] = remapped_indices[1][current[1]];
347 current[2] = remapped_indices[2][current[2]];
356 if (current_idx >= max_coord) {
363 inline std::vector<Tvec> next_n(
u64 nmax) {
364 std::vector<Tvec> ret{};
365 for (
u64 i = 0; i < nmax; i++) {
370 ret.push_back(next());
372 shamlog_debug_ln(
"Discontinuous iterator",
"next_n final idx", current_idx);
376 inline void skip(
u64 n) {
380 if (current_idx >= max_coord) {
383 shamlog_debug_ln(
"Discontinuous iterator",
"skip final idx", current_idx);