summaryrefslogtreecommitdiff
path: root/lib/dihedral.h
blob: 82388358775c1f02055d099385275394057e7719 (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

#pragma once

#include "types.h"
#include "potts.h"

template <class T, q_t q>
struct dihedral_t { bool is_reflection; T x; };

template <class T, q_t q>
void init(dihedral_t<T, q> *ptr) {
  ptr->is_reflection = false;
  ptr->x = (T)0;
}

template <class T, q_t q>
dihedral_t<T, q> copy(dihedral_t<T, q> r) {
  return r;
}

template <class T, q_t q>
void free_spin(dihedral_t<T, q> r) {
  // do nothing!
}

template <q_t q>
potts_t<q> act(dihedral_t<q_t, q> r, potts_t<q> s) {
  potts_t<q> s2;
  if (r.is_reflection) {
    s2.x = ((q + r.x) - s.x) % q;
  } else {
    s2.x = (r.x + s.x) % q;
  }

  return s2;
}

template <q_t q>
dihedral_t<q_t,q> act(dihedral_t<q_t,q> r1, dihedral_t<q_t,q> r2) {
  dihedral_t<q_t,q> r3;

  if (r1.is_reflection) {
    r3.is_reflection = !(r2.is_reflection);
    r3.x = ((q + r1.x) - r2.x) % q;
  } else {
    r3.is_reflection = r2.is_reflection;
    r3.x = (r1.x + r2.x) % q;
  }

  return r3;
}

template <q_t q>
potts_t<q> act_inverse(dihedral_t<q_t,q> r, potts_t<q> s) {
  potts_t<q> s2;
  if (r.is_reflection) {
    s2.x = ((r.x + q) - s.x) % q;
  } else {
    s2.x = ((s.x + q) - r.x) % q;
  }

  return s2;
}

template <q_t q>
dihedral_t<q_t, q> act_inverse(dihedral_t<q_t,q> r1, dihedral_t<q_t,q> r2) {
  dihedral_t<q_t,q> r3;

  if (r1.is_reflection) {
    r3.is_reflection = !(r2.is_reflection);
    r3.x = ((r1.x + q) - r2.x) % q;
  } else {
    r3.is_reflection = r2.is_reflection;
    r3.x = ((r2.x + q) - r1.x) % q;
  }

  return r3;
}