summaryrefslogtreecommitdiff
path: root/spheres.cpp
blob: 106ce4eba4f38fcaa333e5be9642187533d94603 (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

#include "space_wolff.hpp"

int main(int argc, char* argv[]) {
  const unsigned D = 2;

  double L = 32;
  unsigned N = 1000;
  double T = 2.0 / log(1.0 + sqrt(2.0));
  double H = 1.0;
  unsigned n = 25;

  int opt;

  while ((opt = getopt(argc, argv, "n:N:L:T:H:")) != -1) {
    switch (opt) {
      case 'n': 
        n = (unsigned)atof(optarg);
        break;
      case 'N': 
        N = (unsigned)atof(optarg);
        break;
      case 'L':
        L = atof(optarg);
        break;
      case 'T':
        T = atof(optarg);
        break;
      case 'H':
        H = atof(optarg);
        break;
      default:
        exit(1);
    }
  }

  std::function<double(spin<double, D, double>, spin<double, D, double>)> Z =
    [L] (spin<double, D, double> s1, spin<double, D, double> s2) -> double {
      vector<double, D> diff = s1.x - s2.x;
      for (unsigned i = 0; i < D; i++) {
        if (fabs(diff(i)) > L / 2) {
          diff(i) = L - fabs(diff(i));
        } else {
          diff(i) = fabs(diff(i));
        }
      }
      if (diff.transpose() * diff < pow(s1.s + s2.s, 2)) {
        return -std::numeric_limits<double>::infinity();
      } else {
        return 0;
      }
    };

  std::function<double(spin<double, D, double>)> B =
    [L, H] (spin<double, D, double> s) -> double {
      return H * sin(2 * M_PI * 3 * s.x(0) / L);
    };

  std::function<std::set<unsigned>(model<double, D, double>&, unsigned, spin<double, D, double>)> neighbors =
    [] (model<double, D, double>& m, unsigned i0, spin<double, D, double> s1) -> std::set<unsigned> {
      std::set<unsigned> nn;
      if (i0 < m.s.size()) {
        std::set<unsigned> os1 = m.dict.on_site(s1.x);
        std::set<unsigned> nn0 = m.dict.nearest_neighbors(m.s[i0].x);
        std::set<unsigned> nn1 = m.dict.nearest_neighbors(s1.x);
        std::set<unsigned> nnn0 = m.dict.next_nearest_neighbors(m.s[i0].x);
        std::set<unsigned> nnn1 = m.dict.next_nearest_neighbors(s1.x);
        nn.insert(nn0.begin(), nn0.end());
        nn.insert(nn1.begin(), nn1.end());
        nn.insert(nnn0.begin(), nnn0.end());
        nn.insert(nnn1.begin(), nnn1.end());
        nn.insert(os1.begin(), os1.end());
        nn.insert(m.s.size());
      } else {
        for (unsigned i = 0; i < m.s.size(); i++) {
          nn.insert(i);
        }
      }
      return nn;
    };

  model<double, D, double> sphere(L, Z, B, neighbors);

  randutils::auto_seed_128 seeds;
  std::mt19937 rng{seeds};

  std::uniform_real_distribution<double> dist(0.0, L);

  for (unsigned i = 0; i < n; i++) {
    vector<double, D> pos = {dist(rng), dist(rng)};
    sphere.s.push_back({pos, 0.5});
    sphere.dict.record<double>(pos, i);
  }

  sphere.wolff(T, N, rng);

  for (spin<double, D, double> s : sphere.s) {
    spin<double, D, double> rs = sphere.s0.inverse().act(s);
    std::cout << s.x.transpose() << "\n";
  }

  return 0;
}