From 2242fd6f8b7f16b706d49a2288da3aa20f12314b Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Thu, 13 Feb 2020 15:00:31 -0500 Subject: Added gitignore and fixed Ising to work with new paradigm --- spheres_infinite.cpp | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) (limited to 'spheres_infinite.cpp') diff --git a/spheres_infinite.cpp b/spheres_infinite.cpp index 3505d6d..026486e 100644 --- a/spheres_infinite.cpp +++ b/spheres_infinite.cpp @@ -41,13 +41,13 @@ public: void post_cluster(const model& m) override { glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); - for (const Spin& s : m.s) { + 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(m.s0.inverse().act(s).x(0) + s.s * cos(2 * i * M_PI / n_points), - m.s0.inverse().act(s).x(1) + s.s * sin(2 * i * M_PI / n_points)); + glVertex2d(m.s0.inverse().act(*s).x(0) + s->s * cos(2 * i * M_PI / n_points), + m.s0.inverse().act(*s).x(1) + s->s * sin(2 * i * M_PI / n_points)); } glEnd(); } @@ -78,14 +78,14 @@ Gen, double> eGen(double ε) { m(0, 1) = -2 * cos(θ) * sin(θ); m(1, 0) = -2 * cos(θ) * sin(θ); - unsigned f_ind = rng.uniform((unsigned)0, (unsigned)M.s.size()); - t = M.s[f_ind].x; + 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, M.s[f_ind]); + return new SpinFlip, double>(M, g, s); }; } @@ -93,12 +93,15 @@ Gen, double> mGen(double ε) { return [ε](model& M, Rng& rng) -> Transformation, double>* { Matrix m; - unsigned f_ind1 = rng.uniform((unsigned)0, (unsigned)M.s.size()); - unsigned f_ind2 = rng.uniform((unsigned)0, (unsigned)M.s.size() - 1); - if (f_ind2 >= f_ind1) f_ind2++; + Spin* s1 = rng.pick(M.s); + Spin* s2 = rng.pick(M.s); - Vector t1 = M.s[f_ind1].x; - Vector t2 = M.s[f_ind2].x; + 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; @@ -110,7 +113,7 @@ Gen, double> mGen(double ε) { m(1, 0) = -2 * cos(θ) * sin(θ); Euclidean g(t - m * t, m); - return new PairFlip, double>(M, g, M.s[f_ind1], M.s[f_ind2]); + return new PairFlip, double>(M, g, s1, s2); }; } @@ -179,17 +182,19 @@ int main(int argc, char* argv[]) { auto g1 = eGen(0.5); auto g2 = mGen(0.2); animation A(L, 750, argc, argv); - model sphere(1, Z, B); + model sphere(1.0, Z, B); Rng rng; - sphere.s.reserve(n); + sphere.s.resize(n); unsigned nx = floor(sqrt(n)); - for (unsigned i = 0; i < n; i++) { - Vector pos = {(i / nx) * L / nx, (i % nx) * L / nx}; - sphere.s.push_back({pos, rng.uniform(0.25, 0.45)}); - sphere.dict.insert(&sphere.s.back()); + 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.25, 0.45); + sphere.s[i] = ss; + sphere.dict.insert(ss); } sphere.wolff(T, {g1, g2}, A, N); @@ -212,9 +217,10 @@ int main(int argc, char* argv[]) { std::ofstream snapfile; snapfile.open("sphere_snap.dat"); - for (Spin s : sphere.s) { - Spin rs = sphere.s0.inverse().act(s); + for (Spin* s : sphere.s) { + Spin rs = sphere.s0.inverse().act(*s); snapfile << rs.x.transpose() << "\n"; + delete s; } snapfile.close(); -- cgit v1.2.3-54-g00ecf