From 2ebf2f181edac37bfb932dbb353101e37e97223a Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Sun, 16 Feb 2020 21:02:25 -0500 Subject: More work on new transformations, and animation of cluster formation --- space_wolff.hpp | 8 +++--- spheres_infinite.cpp | 69 ++++++++++++++++++++++++++++++++++++++-------------- transformation.hpp | 58 ++++++++++++++++++++++++++++--------------- 3 files changed, 94 insertions(+), 41 deletions(-) diff --git a/space_wolff.hpp b/space_wolff.hpp index 63bf118..dc06011 100644 --- a/space_wolff.hpp +++ b/space_wolff.hpp @@ -18,11 +18,10 @@ template class Model; template class measurement { public: - virtual void pre_cluster(const Model&, unsigned, const R&){}; + virtual void pre_cluster(const Model&, unsigned, const Transformation, double>*){}; virtual void plain_bond_visited(const Model&, const Spin*, const Spin*, const Spin&, double){}; - virtual void plain_site_transformed(const Model&, const Spin*, - const Spin&){}; + virtual void plain_site_transformed(const Model&, const Transformation&){}; virtual void ghost_bond_visited(const Model&, const Spin&, const Spin&, double){}; @@ -70,6 +69,7 @@ public: } } + A.plain_site_transformed(*this, *t); t->apply(); } delete t; @@ -84,6 +84,8 @@ public: Gen& g = rng.pick(gs); Transformation *t = g(*this, rng); + A.pre_cluster(*this, i, t); + this->step(T, t, A); A.post_cluster(*this); diff --git a/spheres_infinite.cpp b/spheres_infinite.cpp index b39f164..77a3582 100644 --- a/spheres_infinite.cpp +++ b/spheres_infinite.cpp @@ -14,9 +14,10 @@ private: uint64_t t2; unsigned n; unsigned tmp; + Euclidean s0_tmp; public: - animation(double L, unsigned w, int argc, char* argv[]) { + animation(double L, unsigned w, int argc, char* argv[]) : s0_tmp(0) { t1 = 0; t2 = 0; n = 0; @@ -31,30 +32,58 @@ public: gluOrtho2D(-L, L, -L, L); } - void pre_cluster(const model&, unsigned, const Euclidean&) override { tmp = 0; } - - void plain_site_transformed(const model&, const Spin*, - const Spin&) override { + void plain_site_transformed(const model& m, const Transformation, double>& t) override { + if (n > 5000) { + 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 post_cluster(const model& m) override { + 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(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(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 > 5000) { + sleep(2); + } n++; } @@ -95,17 +124,21 @@ Gen, double> mGen(double ε) { 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; + + while (s1 == s2 || 1 / t12.norm() < rng.uniform(0, 1)) { + s1 = rng.pick(M.s); + s2 = rng.pick(M.s); + t1 = s1->x; + t2 = s2->x; + t12 = t1 - t2; + } + Vector t = (t1 + t2) / 2; - double θ = atan2(t12[1], t12[0]) + rng.variate(0.0, ε); + double θ = atan2(t12[1], t12[0]) + rng.variate(0.0, ε) / t12.norm(); m(0, 0) = -cos(2 * θ); m(1, 1) = cos(2 * θ); @@ -201,9 +234,9 @@ int main(int argc, char* argv[]) { return H * s.x.norm(); }; - auto g1 = eGen(2); - auto g2 = mGen(0.5); - auto g3 = rGen(5); + auto g1 = eGen(0.5); + auto g2 = mGen(0.05); + auto g3 = rGen(1); animation A(L, 750, argc, argv); model sphere(1.0, Z, B); @@ -220,7 +253,7 @@ int main(int argc, char* argv[]) { sphere.dict.insert(ss); } - sphere.wolff(T, {g1, g2, g3}, A, N); + sphere.wolff(T, {g1, g2}, A, N); std::ofstream outfile; outfile.open("test.dat"); diff --git a/transformation.hpp b/transformation.hpp index ad3b49f..717a033 100644 --- a/transformation.hpp +++ b/transformation.hpp @@ -9,10 +9,12 @@ template class Model; template class Transformation { public: + const R r; + Transformation(const R& r) : r(r) {} virtual std::set*> current() const { return {NULL}; } virtual std::set*> toConsider() const { return {}; } virtual double ΔE(const Spin*) const { return 0; } - virtual Transformation* createNew(double T, std::set*>&, Spin*, Rng& rng) const { return new Transformation(); } + virtual Transformation* createNew(double T, std::set*>&, Spin*, Rng& rng) const { return new Transformation(r); } virtual void apply(){}; }; @@ -23,11 +25,10 @@ template class SpinFlip : public Transformati private: Model& M; Spin* sOld; - const R r; Spin sNew; public: - SpinFlip(Model& M, const R& r, Spin* s) : M(M), r(r) { + SpinFlip(Model& M, const R& r, Spin* s) : M(M), Transformation(r) { sOld = s; sNew = r.act(*s); } @@ -72,12 +73,11 @@ private: Model& M; Spin* s1Old; Spin* s2Old; - const R r; Spin s1New; Spin s2New; public: - PairFlip(Model& M, const R& r, Spin* s1, Spin* s2) : M(M), r(r) { + PairFlip(Model& M, const R& r, Spin* s1, Spin* s2) : M(M), Transformation(r) { s1Old = s1; s2Old = s2; s1New = r.act(*s1); @@ -133,11 +133,10 @@ public: template class FieldFlip : public Transformation { private: Model& M; - const R r; R s0New; public: - FieldFlip(Model& M, const R& r) : M(M), r(r), s0New(r.act(M.s0)) {} + FieldFlip(Model& M, const R& r) : M(M), Transformation(r), s0New(r.act(M.s0)) {} std::set*> toConsider() const override { std::set*> neighbors; @@ -156,16 +155,16 @@ public: } Transformation* createNew(double T, std::set*>& v, Spin* s, Rng&) const { - return new SpinFlip(M, r, s); + return new SpinFlip(M, this->r, s); } Transformation* createNew(double, std::set*>&, Spin* s, Rng&) const { - Vector v = r.act(*s).x; + Vector v = this->r.act(*s).x; std::set*> on_site = M.dict.at(v); if (on_site.empty()) { - return new SpinFlip(M, r, s); + return new SpinFlip(M, this->r, s); } else { - return new PairFlip(M, r, s, *on_site.begin()); + return new PairFlip(M, this->r, s, *on_site.begin()); } } @@ -175,18 +174,37 @@ public: template Transformation* SpinFlip::createNew(double T, std::set*>& v, Spin* s, Rng& rng) const { if (s == NULL) { - return new FieldFlip(M, r); + return new FieldFlip(M, this->r); } else { - return new SpinFlip(M, r, s); + SpinFlip* t = new SpinFlip(M, this->r, s); + Spin* sMax = NULL; + double ΔEMax = 0.0; + for (Spin* ss : t->toConsider()) { + if (ss != NULL && ss != s && !v.contains(ss)) { + double ΔE = t->ΔE(ss); + if (ΔE > ΔEMax) { + sMax = ss; + ΔEMax = ΔE; + } + } + } + if (sMax == NULL || 1.0 - exp(-ΔEMax / T) < rng.uniform(0, 1) || v.contains(sMax)) { + return t; + } else { + delete t; + v.insert(s); + v.insert(sMax); + return new PairFlip(M, this->r, s, sMax); + } } } template Transformation* PairFlip::createNew(double T, std::set*>& v, Spin* s, Rng& rng) const { if (s == NULL) { - return new FieldFlip(M, r); + return new FieldFlip(M, this->r); } else { - SpinFlip* t = new SpinFlip(M, r, s); + SpinFlip* t = new SpinFlip(M, this->r, s); Spin* sMax = NULL; double ΔEMax = 0.0; for (Spin* ss : t->toConsider()) { @@ -204,7 +222,7 @@ Transformation* PairFlip::createNew(double T, std::set(M, r, s, sMax); + return new PairFlip(M, this->r, s, sMax); } } } @@ -212,14 +230,14 @@ Transformation* PairFlip::createNew(double T, std::set Transformation* PairFlip::createNew(double, std::set*>&, Spin* s, Rng&) const { if (s == NULL) { - return new FieldFlip(M, r); + return new FieldFlip(M, this->r); } else { - Vector v = r.act(*s).x; + Vector v = this->r.act(*s).x; std::set*> on_site = M.dict.at(v); if (on_site.empty()) { - return new SpinFlip(M, r, s); + return new SpinFlip(M, this->r, s); } else { - return new PairFlip(M, r, s, *on_site.begin()); + return new PairFlip(M, this->r, s, *on_site.begin()); } } } -- cgit v1.2.3-54-g00ecf