#include #include #include "space_wolff.hpp" #include const unsigned D = 2; typedef Model, double> model; class animation : public measurement, double> { private: uint64_t t1; uint64_t t2; unsigned n; unsigned tmp; unsigned wait; Euclidean s0_tmp; public: animation(double L, unsigned w, int argc, char* argv[]) : s0_tmp(0), wait(1000) { t1 = 0; t2 = 0; n = 0; glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(w, w); glutCreateWindow("wolffWindow"); glClearColor(0.0, 0.0, 0.0, 0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-L, L, -L, L); } void plain_site_transformed(const model& m, const Transformation, double>& t) override { if (n > wait) { if (t.current().size() > 1) { glColor3f(0.0f, 0.0f, 1.0f); } else { glColor3f(0.0f, 1.0f, 0.0f); } for (const Spin* s : t.current()) { if (s != NULL) { glBegin(GL_POLYGON); unsigned n_points = 50; for (unsigned i = 0; i < n_points; i++) { glVertex2d(s0_tmp.act(*s).x(0) + s->s * cos(2 * i * M_PI / n_points), s0_tmp.act(*s).x(1) + s->s * sin(2 * i * M_PI / n_points)); } glEnd(); } } } tmp++; } void pre_cluster(const model& m, unsigned, const Transformation, double>* t) override { s0_tmp = m.s0.inverse(); tmp = 0; glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); /* glBegin(GL_LINE); Vector r_center = s0_tmp.act({t->r.t, 0}); glEnd(); */ for (const Spin* s : m.s) { glBegin(GL_POLYGON); unsigned n_points = 50; glColor3f(0.0f, 0.0f, 0.0f); for (unsigned i = 0; i < n_points; i++) { glVertex2d(s0_tmp.act(*s).x(0) + s->s * cos(2 * i * M_PI / n_points), s0_tmp.act(*s).x(1) + s->s * sin(2 * i * M_PI / n_points)); } glEnd(); } glFlush(); } void post_cluster(const model& m) override { glFlush(); t1 += tmp; t2 += tmp * tmp; if (n > wait) { sleep(2); } n++; } void clear() { t1 = 0; t2 = 0; n = 0; } double var() { return (t2 - t1 * t1 / (double)n) / (double)n; } }; Gen, double> eGen(double ε) { return [ε](model& M, Rng& rng) -> Transformation, double>* { Vector t; Matrix m; double θ = rng.uniform((double)0.0, 2 * M_PI); m(0, 0) = -cos(2 * θ); m(1, 1) = cos(2 * θ); m(0, 1) = -2 * cos(θ) * sin(θ); m(1, 0) = -2 * cos(θ) * sin(θ); Spin* s = rng.pick(M.s); t = s->x; for (unsigned j = 0; j < D; j++) { t(j) += rng.variate(0.0, ε); } Euclidean g(t - m * t, m); return new SpinFlip, double>(M, g, s); }; } Gen, double> mGen(double ε) { return [ε](model& M, Rng& rng) -> Transformation, double>* { Matrix m; Spin* s1 = rng.pick(M.s); Spin* s2 = rng.pick(M.s); while (s1 == s2) { s2 = rng.pick(M.s); } Vector t1 = s1->x; Vector t2 = s2->x; Vector t12 = t1 - t2; Vector t = (t1 + t2) / 2; double θ = atan2(t12(1), t12(0)) + rng.variate(0.0, ε) / t12.norm(); m(0, 0) = -cos(2 * θ); m(1, 1) = cos(2 * θ); m(0, 1) = -2 * cos(θ) * sin(θ); m(1, 0) = -2 * cos(θ) * sin(θ); Vector t3 = t - m * t; if (t3(0) != t3(0)) { std::cout << t3 << "\n" << t << "\n" << m << "\n" << t12 << "\n" ; getchar(); } Euclidean g(t3, m); return new PairFlip, double>(M, g, s1, s2); }; } Gen, double> rGen(double ε) { return [ε](model& M, Rng& rng) -> Transformation, double>* { Vector t; Matrix m; double θ = rng.uniform((double)0.0, 2 * M_PI); m(0, 0) = -cos(2 * θ); m(1, 1) = cos(2 * θ); m(0, 1) = -2 * cos(θ) * sin(θ); m(1, 0) = -2 * cos(θ) * sin(θ); Spin* s = rng.pick(M.s); t = M.s0.t; for (unsigned j = 0; j < D; j++) { t(j) += rng.variate(0.0, ε); } Euclidean g(t - m * t, m); return new SpinFlip, double>(M, g, s); }; } 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; double k = 1e2; double a = 0.1; int opt; while ((opt = getopt(argc, argv, "n:N:L:T:H:a:k:")) != -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; case 'a': a = atof(optarg); break; case 'k': k = atof(optarg); break; default: exit(1); } } std::function&, const Spin&)> Z = [L, a, k](const Spin& s1, const Spin& s2) -> double { Vector d = s1.x - s2.x; double σ = s1.s + s2.s; double δ = σ - sqrt(d.transpose() * d); if (δ > -a * σ) { return 0.5 * k * (2 * pow(a * σ, 2) - pow(δ, 2)); } else if (δ > -2 * a * σ) { return 0.5 * k * pow(δ + 2 * a * σ, 2); } else { return 0; } }; std::function)> B = [L, H](Spin s) -> double { return H * s.x.norm(); }; auto g1 = eGen(1); auto g2 = mGen(0.1); auto g3 = rGen(1); animation A(L, 750, argc, argv); model sphere(1.0, Z, B); Rng rng; sphere.s.resize(n); unsigned nx = floor(sqrt(n)); for (unsigned i = 0; i < sphere.s.size(); i++) { Spin* ss = new Spin(); ss->x = {(i / nx) * L / nx, (i % nx) * L / nx}; ss->s = rng.uniform(0.45, 0.45); sphere.s[i] = ss; sphere.dict.insert(ss); } sphere.wolff(T, {g1, g2}, A, N); std::ofstream outfile; outfile.open("test.dat"); /* for (signed i = -10; i <= 10; i++) { A.clear(); double ε = pow(2, -4 + i / 2.0); auto gn = eGen(ε); sphere.wolff(T, gn, A, N); outfile << ε << " " << A.var() / sphere.s.size() << std::endl; std::cout << ε << " " << A.var() / sphere.s.size() << std::endl; } */ outfile.close(); std::ofstream snapfile; snapfile.open("sphere_snap.dat"); for (Spin* s : sphere.s) { Spin rs = sphere.s0.inverse().act(*s); snapfile << rs.x.transpose() << "\n"; delete s; } snapfile.close(); return 0; }