HILA
Loading...
Searching...
No Matches
site_index.h
1#ifndef SITEINDEX_H
2#define SITEINDEX_H
3
4#include "coordinates.h"
5#include "lattice.h"
6
7
8/**
9 * @brief Running index for locating sites on the lattice
10 *
11 * The index is computed as x + nx*(y + ny*(z + nz*t) (in 4d)
12 * Used sometimes instead of CoordinateVector, smaller storage.
13 * Can be directly accessed by .value
14 *
15 */
16
17class SiteIndex {
18 public:
19 size_t value;
20
21 // std incantation for field types
22 using base_type = size_t;
23 using argument_type = size_t;
24
25 SiteIndex() = default;
26 SiteIndex(const SiteIndex &s) = default;
27 SiteIndex(size_t v) : value(v) {}
28
29 ~SiteIndex() = default;
30
31 /**
32 * @brief Construct from CoordinateVector
33 *
34 * Assumes cv is a valid lattice coordinate, undefined otherwise
35 */
37 value = 0;
38 size_t m = 1;
39 foralldir(d) {
40 value += m * cv[d];
41 m *= lattice.size(d);
42 }
43 }
44
45 /**
46 * @brief Convert to lattice coordinates
47 */
50 size_t v = value;
51 foralldir(d) {
52 res.e(d) = v % lattice.size(d);
53 v /= lattice.size(d);
54 }
55 return res;
56 }
57};
58
59#endif
T e(const int i, const int j) const
Standard array indexing operation for matrices.
Definition matrix.h:272
Running index for locating sites on the lattice.
Definition site_index.h:17
SiteIndex(const CoordinateVector &cv)
Construct from CoordinateVector.
Definition site_index.h:36
CoordinateVector coordinates() const
Convert to lattice coordinates.
Definition site_index.h:48
This header file defines:
#define foralldir(d)
Macro to loop over (all) Direction(s)
Definition coordinates.h:78