summaryrefslogtreecommitdiff
path: root/euclidean.hpp
blob: b1ce2c6e5c1407ace88aa236f42349ea7ee19e64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130

#pragma once

#include "matrix.hpp"
#include "spin.hpp"
#include "vector.hpp"

template <class T, int D> class Euclidean {
public:
  Vector<T, D> t;
  Matrix<T, D> r;

  Euclidean(T L) {
    for (unsigned i = 0; i < D; i++) {
      t(i) = 0;
      r(i, i) = 1;
      for (unsigned j = 1; j < D; j++) {
        r(i, (i + j) % D) = 0;
      }
    }
  }

  Euclidean(Vector<T, D> t0, Matrix<T, D> r0) {
    t = t0;
    r = r0;
  }

  Vector<T, D> act(const Vector<T, D>& x) const {
    return t + r * x;
  }

  template <class S> Spin<T, D, S> act(const Spin<T, D, S>& s) const {
    Spin<T, D, S> s_new;

    s_new.x = this->act(s.x);
    s_new.s = s.s;

    return s_new;
  }

  Euclidean act(const Euclidean& x) const {
    Vector<T, D> tnew = r * x.t + t;
    Matrix<T, D> rnew = r * x.r;

    Euclidean pnew(tnew, rnew);

    return pnew;
  }

  Euclidean inverse() const {
    Vector<T, D> tnew = -r.transpose() * t;
    Matrix<T, D> rnew = r.transpose();

    Euclidean pnew(tnew, rnew);

    return pnew;
  }
};

template <class T, int D> class TorusGroup {
private:
  T L;

public:
  Vector<T, D> t;
  Matrix<T, D> r;

  /** brief TorusGroup - default constructor, constructs the identity
   */
  TorusGroup(T L) : L(L) {
    for (unsigned i = 0; i < D; i++) {
      t(i) = 0;
      r(i, i) = 1;
      for (unsigned j = 1; j < D; j++) {
        r(i, (i + j) % D) = 0;
      }
    }
  }

  TorusGroup(T L, Vector<T, D> t0, Matrix<T, D> r0) : L(L) {
    t = t0;
    r = r0;
  }

  template <class S> Spin<T, D, S> act(const Spin<T, D, S>& s) const {
    Spin<T, D, S> s_new;

    s_new.x = t + r * s.x;
    s_new.s = s.s;

    for (unsigned i = 0; i < D; i++) {
      s_new.x(i) = fmod(L + s_new.x(i), L);
    }

    return s_new;
  }

  Vector<T, D> act(const Vector<T, D>& s) const {
    Vector<T, D> s_new = t + r * s;

    for (unsigned i = 0; i < D; i++) {
      s_new(i) = fmod(L + s_new(i), L);
    }

    return s_new;
  }

  TorusGroup act(const TorusGroup& x) const {
    Vector<T, D> tnew = r * x.t + t;
    Matrix<T, D> rnew = r * x.r;

    for (unsigned i = 0; i < D; i++) {
      tnew(i) = fmod(L + tnew(i), L);
    }

    TorusGroup pnew(this->L, tnew, rnew);

    return pnew;
  }

  TorusGroup inverse() const {
    Vector<T, D> tnew = -r.transpose() * t;
    Matrix<T, D> rnew = r.transpose();

    TorusGroup pnew(this->L, tnew, rnew);

    return pnew;
  }
};