summaryrefslogtreecommitdiff
path: root/soft_spheres.cpp
blob: cdd6f31fc2e2ccdac8eb7ec72f2246f7ee9ec526 (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
#include "animation.hpp"

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

  unsigned N = 1200;
  double R = 0.023;
  double ε = 0.01;
  unsigned steps = 1e6;
  double β = 1;

  initializeAnimation(argc, argv);

  Rng r;

  Model<2, SoftSphere<2, n>> m(N, 2 * R * 1.25);

  for (unsigned i = 0; i < N; i++) {
    Position<2> x = {r.uniform(0.0, 1.0), r.uniform(0.0, 1.0)};
    double rad = pow(r.uniform(pow(2.219, -2), 1.0), -0.5) * R / 2.219;
    m.insert(SoftSphere<2, n>(x, rad));
  }

  for (unsigned i = 0; i < steps * N; i++) {
    SoftSphere<2, n>& s = r.pick(m.particles);
    Vector<2> Δx;
    for (double& Δxi : Δx) {
      Δxi = r.variate<double, std::normal_distribution>(0, ε);
    }

    for (unsigned j = 0; j < N; j++)
      m.metropolis(β, s, Δx, r);

    SoftSphere<2, n>& s1 = r.pick(m.particles);
    SoftSphere<2, n>& s2 = r.pick(m.particles);

    Vector<2> t1 = s1.x;
    Vector<2> t2 = s2.x;
    Vector<2> t = (t1 + t2) / 2;

    Matrix<2> mat;

    mat(0, 0) = -1;
    mat(1, 1) = -1;
    mat(0, 1) = 0;
    mat(1, 0) = 0;

    Euclidean<2> g(t - mat * t, mat);

    std::cout << m.clusterFlip(1, g, s1, r) << std::endl;
    
    draw(m);
  }

  return 0;
}