summaryrefslogtreecommitdiff
path: root/lib/include/wolff/models/ising.hpp
blob: d2f6f914cec348b8ba2a4b6f519e9c639b18d1d5 (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

#ifndef WOLFF_MODELS_ISING_H
#define WOLFF_MODELS_ISING_H

#define WOLFF_FINITE_STATES_N 2

#include "../system.hpp"

namespace wolff {

#include "../types.h"

class ising_t {
  public:
    bool x;

    ising_t() : x(false) {}

    ising_t(bool x) : x(x) {} 
    ising_t(q_t x) : x((bool)x) {}

    ising_t act(const ising_t& s) const {
      if (x) {
        return ising_t(!s.x);
      } else {
        return ising_t(s.x);
      }
    }

    ising_t act_inverse(const ising_t& s) const {
      return this->act(s);
    }

    typedef int M_t;
    typedef double F_t;

    inline M_t operator*(v_t a) const {
      if (x) {
        return -(M_t)a;
      } else {
        return (M_t)a;
      }
    }

    inline F_t operator*(double a) const {
      if (x) {
        return -a;
      } else {
        return a;
      }
    }

    inline M_t operator-(const ising_t &s) const {
      if (x == s.x) {
        return 0;
      } else {
        if (x) {
          return -2;
        } else {
          return 2;
        }
      }
    }

    inline int operator*(const ising_t& s) const {
      if (x == s.x) {
        return 1;
      } else {
        return -1;
      }
    }

    q_t enumerate() const {
      return (q_t)x;
    }
};

inline ising_t::M_t operator*(v_t a, const ising_t& s) {
  return s * a;
}

inline ising_t::F_t operator*(double a, const ising_t& s) {
  return s * a;
}

ising_t gen_ising(std::mt19937&, const system<ising_t, ising_t>&, v_t) {
  return ising_t(true);
};

}

#endif