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

#ifndef WOLFF_SYSTEM_H
#define WOLFF_SYSTEM_H

#include <functional>
#include <vector>
#include <random>

#include "graph.hpp"

namespace wolff {

#include "types.h"

template <class R_t, class X_t>
class measurement;

template <class R_t, class X_t>
class system {
  public:
    v_t nv; // number of vertices
    v_t ne; // number of edges
    graph G; // the graph defining the lattice with ghost
    double T; // the temperature
    std::vector<X_t> s; // the state of the ordinary spins

#ifdef WOLFF_BOND_DEPENDENCE
    std::function <double(v_t, const X_t&, v_t, const X_t&)> Z; // coupling between sites
#else
    std::function <double(const X_t&, const X_t&)> Z; // coupling between sites
#endif

#ifndef WOLFF_NO_FIELD
    R_t s0; // the current state of the ghost site
#ifdef WOLFF_SITE_DEPENDENCE
    std::function <double(v_t, const X_t&)> B; // coupling with the external field
#else
    std::function <double(const X_t&)> B; // coupling with the external field
#endif
#endif

#ifdef WOLFF_USE_FINITE_STATES
    std::array<std::array<std::array<double, WOLFF_FINITE_STATES_N>, WOLFF_FINITE_STATES_N>, WOLFF_FINITE_STATES_N> Zp;
#ifndef WOLFF_NO_FIELD
    std::array<std::array<double, WOLFF_FINITE_STATES_N>, WOLFF_FINITE_STATES_N> Bp;
#endif
#endif

    system(graph g, double T,
#ifdef WOLFF_BOND_DEPENDENCE
        std::function <double(v_t, const X_t&, v_t, const X_t&)> Z
#else
        std::function <double(const X_t&, const X_t&)> Z
#endif
#ifndef WOLFF_NO_FIELD
#ifdef WOLFF_SITE_DEPENDENCE
        , std::function <double(v_t, const X_t&)> B
#else
        , std::function <double(const X_t&)> B
#endif
#endif
        ) : G(g), T(T), Z(Z)
#ifndef WOLFF_NO_FIELD
             , s0(), B(B)
#endif
    {
      nv = G.nv;
      ne = G.ne;
      s.resize(nv);
#ifndef WOLFF_NO_FIELD
      G.add_ghost();
#endif
#ifdef WOLFF_USE_FINITE_STATES
      this->finite_states_init();
#endif
    }

    void flip_cluster(v_t, const R_t&, std::mt19937&, measurement<R_t, X_t>&);
    void run_wolff(N_t, std::function <R_t(std::mt19937&, const system<R_t, X_t>&, v_t)> r_gen, measurement<R_t, X_t>& A, std::mt19937& rng);

#ifdef WOLFF_USE_FINITE_STATES
    void finite_states_init() {
#ifndef WOLFF_NO_FIELD
      for (q_t i = 0; i < WOLFF_FINITE_STATES_N; i++) {
        for (q_t j = 0; j < WOLFF_FINITE_STATES_N; j++) {
          Bp[i][j] = 1.0 - exp(-(B(X_t(i)) - B(X_t(j))) / T);
        }
      }
#endif
      for (q_t i = 0; i < WOLFF_FINITE_STATES_N; i++) {
        for (q_t j = 0; j < WOLFF_FINITE_STATES_N; j++) {
          for (q_t k = 0; k < WOLFF_FINITE_STATES_N; k++) {
            Zp[i][j][k] = 1.0 - exp(-(Z(X_t(i), X_t(k)) - Z(X_t(j), X_t(k))) / T);
          }
        }
      }
    }
#endif

};

}

#endif