summaryrefslogtreecommitdiff
path: root/examples/simple_measurement.hpp
blob: 217f4f0c1b35c2a1d97c191f0d462abe1d93e526 (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

#include <wolff/measurement.hpp>

using namespace wolff;

template <class R_t, class X_t>
class simple_measurement : public measurement<R_t, X_t> {
  private:
    N_t n;

    double E;
    typename X_t::M_t M;
    v_t C;

    double totalE;
    typename X_t::F_t totalM;
    double totalC;

  public:
    simple_measurement(const system<R_t, X_t>& S) {
      n = 0;
      M = S.nv * S.s[0];
      E = 0;

#ifdef WOLFF_BOND_DEPENDENCE
      for (v_t i = 0; i < S.nv; i++) {
        for (v_t j : S.G.adjacency[i]) {
          E -= 0.5 * S.Z(i, S.s[i], j, S.s[j]);
        }
      }
#else
      E -= S.ne * S.Z(S.s[0], S.s[0]);
#endif

#ifndef WOLFF_NO_FIELD
#ifdef WOLFF_SITE_DEPENDENCE
      for (v_t i = 0; i < S.nv; i++) {
        E -= S.B(i, S.s[i]);
      }
#else
      E -= S.nv * S.B(S.s[0]);
#endif
#endif

      totalE = 0;
      totalM = 0.0 * (S.s[0]);
      totalC = 0;
    }

    void pre_cluster(N_t, N_t, const system<R_t, X_t>&, v_t, const R_t&) {
      C = 0;
    }

    void plain_bond_visited(const system<R_t, X_t>&, v_t, const X_t&, v_t, double dE) {
      E += dE;
    }

    void ghost_bond_visited(const system<R_t, X_t>&, v_t, const X_t& s_old, const X_t& s_new, double dE) {
      E += dE;
      M += s_new - s_old;
    }

    void plain_site_transformed(const system<R_t, X_t>& S, v_t i, const X_t& si_new) {
      C++;

#ifdef WOLFF_NO_FIELD
      M += si_new - S.s[i];
#endif
    }

    void post_cluster(N_t, N_t, const system<R_t, X_t>&) {
      totalE += E;
      totalM += M;
      totalC += C;
      n++;
    }

    double avgE() {
      return totalE / n;
    }

    typename X_t::F_t avgM() {
      return totalM / n;
    }

    double avgC() {
      return totalC / n;
    }
};