From 468c25eabd1aaac7d02988fef97b66bb378988b3 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Wed, 26 Feb 2020 09:14:04 -0500 Subject: More cleanup and temperary saving routines for presentation --- dimers.cpp | 23 +++++---------------- dimers_torus.cpp | 28 +++++++------------------- spheres.hpp | 55 ++++++++++++++++++++++++++++++++------------------ spheres_infinite.cpp | 57 +++++++++++++++++++++++++++++++++++++++++----------- 4 files changed, 92 insertions(+), 71 deletions(-) diff --git a/dimers.cpp b/dimers.cpp index d5cfdf4..722c33c 100644 --- a/dimers.cpp +++ b/dimers.cpp @@ -57,18 +57,7 @@ int main(int argc, char* argv[]) { } auto zSingle = zSpheres(a, k); - - std::function>&, - const Spin>&)> - Z = [zSingle, a, k](const Spin>& s1, - const Spin>& s2) -> double { - Spin s11 = {.x = s1.x + s1.s.relativePosition, .s = s1.s.radius}; - Spin s12 = {.x = s1.x - s1.s.relativePosition, .s = s1.s.radius}; - Spin s21 = {.x = s2.x + s2.s.relativePosition, .s = s2.s.radius}; - Spin s22 = {.x = s2.x - s2.s.relativePosition, .s = s2.s.radius}; - - return zSingle(s11, s21) + zSingle(s12, s21) + zSingle(s11, s22) + zSingle(s12, s22); - }; + auto Z = zDimers(zSingle); auto g1 = nudgeGen>(1); auto g2 = swapGen>(0.1); @@ -104,18 +93,16 @@ int main(int argc, char* argv[]) { file.close(); - /* std::ofstream snapfile; - snapfile.open("sphere_snap.dat"); + snapfile.open("dimers_field_snap.dat"); - for (Spin* s : sphere.s) { - Spin rs = sphere.s0.inverse().act(*s); - snapfile << rs.s << " " << rs.x.transpose() << "\n"; + for (Spin>* s : sphere.s) { + Spin> rs = sphere.s0.inverse().act(*s); + snapfile << rs.s.radius << " " << rs.x.transpose() << " " << rs.s.relativePosition.transpose() << "\n"; delete s; } snapfile.close(); - */ return 0; } diff --git a/dimers_torus.cpp b/dimers_torus.cpp index ec7c73a..4b44a83 100644 --- a/dimers_torus.cpp +++ b/dimers_torus.cpp @@ -58,22 +58,10 @@ int main(int argc, char* argv[]) { } auto zSingle = zSpheresTorus(L, a, k); + auto Z = zDimers(zSingle); - std::function>&, - const Spin>&)> - Z = [L, zSingle, a, k](const Spin>& s1, - const Spin>& s2) -> double { - Spin s11 = {.x = s1.x + s1.s.relativePosition, .s = s1.s.radius}; - Spin s12 = {.x = s1.x - s1.s.relativePosition, .s = s1.s.radius}; - Spin s21 = {.x = s2.x + s2.s.relativePosition, .s = s2.s.radius}; - Spin s22 = {.x = s2.x - s2.s.relativePosition, .s = s2.s.radius}; - - return zSingle(s11, s21) + zSingle(s12, s21) + zSingle(s11, s22) + zSingle(s12, s22); - }; - - std::function>)> B = [L, H](Spin> s) -> double { - return H * s.x(1); - }; + std::function>)> B = + [L, H](Spin> s) -> double { return H * s.x(1); }; auto g1 = uniformGenTorus>(L); @@ -97,18 +85,16 @@ int main(int argc, char* argv[]) { sphere.wolff(T, {g1}, A, N); - /* std::ofstream snapfile; - snapfile.open("sphere_snap.dat"); + snapfile.open("dimers_torus_snap.dat"); - for (Spin* s : sphere.s) { - Spin rs = sphere.s0.inverse().act(*s); - snapfile << rs.s << " " << rs.x.transpose() << "\n"; + for (Spin>* s : sphere.s) { + Spin> rs = sphere.s0.inverse().act(*s); + snapfile << rs.s.radius << " " << rs.x.transpose() << " " << rs.s.relativePosition.transpose() << "\n"; delete s; } snapfile.close(); - */ return 0; } diff --git a/spheres.hpp b/spheres.hpp index 60154f6..2ca0851 100644 --- a/spheres.hpp +++ b/spheres.hpp @@ -1,26 +1,26 @@ #include "space_wolff.hpp" -template -double softPotential(double a, double k, const Vector& diff, double σ) { - double δ = σ - sqrt(diff.transpose() * diff); - - 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; - } +template using Sphere = Spin; + +template double softPotential(double a, double k, const Vector& diff, double σ) { + double δ = σ - sqrt(diff.transpose() * diff); + + 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; + } } -template -double hardPotential(const Vector& diff, double σ) { - if (pow(σ, 2) < diff.transpose() * diff) { - return 0; - } else { - return -std::numeric_limits::infinity(); - } +template double hardPotential(const Vector& diff, double σ) { + if (pow(σ, 2) < diff.transpose() * diff) { + return 0; + } else { + return -std::numeric_limits::infinity(); + } } template @@ -35,8 +35,23 @@ zSpheres(double a, double k) { template std::function&, const Spin&)> zSpheresTorus(double L, double a, double k) { - return [L, a, k](const Spin& s1, const Spin& s2) -> double { - return softPotential(a, k, diff(L, s1.x, s2.x), s1.s + s2.s); + return [L, a, k](const Spin& s1, const Spin& s2) -> double { + return softPotential(a, k, diff(L, s1.x, s2.x), s1.s + s2.s); + }; +} + +template +std::function>&, + const Spin>&)> +zDimers(std::function&, const Sphere&)> zSingle) { + return [zSingle](const Spin>& s1, + const Spin>& s2) -> double { + Spin s11 = {.x = s1.x + s1.s.relativePosition, .s = s1.s.radius}; + Spin s12 = {.x = s1.x - s1.s.relativePosition, .s = s1.s.radius}; + Spin s21 = {.x = s2.x + s2.s.relativePosition, .s = s2.s.radius}; + Spin s22 = {.x = s2.x - s2.s.relativePosition, .s = s2.s.radius}; + + return zSingle(s11, s21) + zSingle(s12, s21) + zSingle(s11, s22) + zSingle(s12, s22); }; } diff --git a/spheres_infinite.cpp b/spheres_infinite.cpp index af91427..3fd6da2 100644 --- a/spheres_infinite.cpp +++ b/spheres_infinite.cpp @@ -10,6 +10,46 @@ const unsigned D = 2; typedef Model, double> model; +class SaveFlip : public measurement, Radius> { + std::ofstream snapfile; + unsigned n; + + public: + SaveFlip() {} + + void pre_cluster(const Model, Radius>& m, unsigned, + const Transformation, Radius>* t) override { + snapfile.open("sphere_flip.dat"); + n = 0; + for (const Sphere* s : m.s) { + snapfile << s << " " << s->s << " " << s->x.transpose() << " "; + } + snapfile << "\n"; + } + + void plain_site_transformed(const Model, Radius>& m, + const Transformation, Radius>& t) override { + for (const Sphere* s : t.current()) { + snapfile << s << " "; + } + snapfile << "\n"; + n++; + } + + void post_cluster(const Model, Radius>& m) override { + for (const Sphere* s : m.s) { + snapfile << s << " " << s->s << " " << s->x.transpose() << " "; + } + snapfile << "\n"; + snapfile.close(); + std::cout << n << "\n"; + if (2 < n && n < 20) { + getchar(); + } + } + +}; + int main(int argc, char* argv[]) { const unsigned D = 2; @@ -65,7 +105,7 @@ int main(int argc, char* argv[]) { }; auto g1 = nudgeGen(1); - auto g2 = swapGen(0.1); + auto g2 = swapGen(0.01); auto g3 = accrossGen(0.1); auto g4 = centerGen(0); @@ -93,20 +133,13 @@ int main(int argc, char* argv[]) { sphere.dict.insert(ss); } - sphere.wolff(T, {g1, g2, g3, g4}, A, N); - - file.close(); + measurement, Radius> A_tmp; - std::ofstream snapfile; - snapfile.open("sphere_snap.dat"); + sphere.wolff(T, {g1, g2, g3, g4}, A_tmp, N); - for (Spin* s : sphere.s) { - Spin rs = sphere.s0.inverse().act(*s); - snapfile << rs.s << " " << rs.x.transpose() << "\n"; - delete s; - } + SaveFlip A_new; + sphere.wolff(T, {g2}, A_new, 10000); - snapfile.close(); return 0; } -- cgit v1.2.3