From 8056fe046011a46b25b6924b2d96229d06dbb4f7 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Tue, 3 Dec 2019 15:49:20 -0500 Subject: refactoring and generalization in preparation for pressure ensemble --- spheres.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) (limited to 'spheres.cpp') diff --git a/spheres.cpp b/spheres.cpp index 25c5a67..9e67b87 100644 --- a/spheres.cpp +++ b/spheres.cpp @@ -2,7 +2,10 @@ #include "space_wolff.hpp" #include -class animation : public measurement { +const unsigned D = 2; +typedef Model, double> model; + +class animation : public measurement, double> { public: animation(double L, unsigned w, int argc, char *argv[]) { glutInit(&argc, argv); @@ -15,7 +18,7 @@ class animation : public measurement { gluOrtho2D(-1, L + 1, -1 , L + 1); } - void post_cluster(const Model& m) override { + 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) { @@ -32,6 +35,41 @@ class animation : public measurement { } }; +std::function(const model&, randutils::mt19937_rng&)> eGen(const std::vector>& mats, const std::vector>& vecs) { + return [&mats, &vecs] (const model& M, randutils::mt19937_rng& rng) -> Euclidean { + std::uniform_real_distribution t_dist(0, M.L); + std::uniform_int_distribution r_dist(0, D - 1); + std::uniform_int_distribution ind_dist(0, M.s.size() - 1); + std::uniform_int_distribution coin(0, mats.size() + vecs.size() - 1); + + Vector t; + Matrix m; + unsigned flip = coin(rng); + if (flip < mats.size()) { + for (unsigned j = 0; j < D; j++) { + t(j) = (double)t_dist(rng); + } + m = mats[flip]; + } else { + for (unsigned j = 0; j < D; j++) { + for (unsigned k = 0; k < D; k++) { + if (j == k) { + m(j, k) = 1; + } else { + m(j, k) = 0; + } + } + } + + t = vecs[flip - mats.size()]; + } + + Euclidean g(M.L, t, m); + return g; + }; + +} + int main(int argc, char* argv[]) { const unsigned D = 2; @@ -85,8 +123,11 @@ int main(int argc, char* argv[]) { return H * sin(2 * M_PI * 3 * s.x(0) / L); }; + std::vector> mats = torus_mats(); + std::vector> vecs = torus_vecs(L); + auto g = eGen(mats, vecs); animation A(L, 750, argc, argv); - Model sphere(L, Z, B, std::floor(log2(L)), 2, A); + model sphere(L, Z, B, g, std::floor(log2(L)), 2, A); randutils::auto_seed_128 seeds; std::mt19937 rng{seeds}; @@ -102,7 +143,7 @@ int main(int argc, char* argv[]) { } - sphere.wolff(T, N, rng); + sphere.wolff(T, N); std::ofstream snapfile; snapfile.open("sphere_snap.dat"); -- cgit v1.2.3-54-g00ecf