From 7b4ab37cc6c728b399e9279e186c9d6c596ef523 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Fri, 26 Jul 2019 15:20:27 -0400 Subject: split into different files, added command line interface, and implemented hard spheres --- spheres.cpp | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 spheres.cpp (limited to 'spheres.cpp') diff --git a/spheres.cpp b/spheres.cpp new file mode 100644 index 0000000..106ce4e --- /dev/null +++ b/spheres.cpp @@ -0,0 +1,104 @@ + +#include "space_wolff.hpp" + +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; + + int opt; + + while ((opt = getopt(argc, argv, "n:N:L:T:H:")) != -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; + default: + exit(1); + } + } + + std::function, spin)> Z = + [L] (spin s1, spin s2) -> double { + vector diff = s1.x - s2.x; + for (unsigned i = 0; i < D; i++) { + if (fabs(diff(i)) > L / 2) { + diff(i) = L - fabs(diff(i)); + } else { + diff(i) = fabs(diff(i)); + } + } + if (diff.transpose() * diff < pow(s1.s + s2.s, 2)) { + return -std::numeric_limits::infinity(); + } else { + return 0; + } + }; + + std::function)> B = + [L, H] (spin s) -> double { + return H * sin(2 * M_PI * 3 * s.x(0) / L); + }; + + std::function(model&, unsigned, spin)> neighbors = + [] (model& m, unsigned i0, spin s1) -> std::set { + std::set nn; + if (i0 < m.s.size()) { + std::set os1 = m.dict.on_site(s1.x); + std::set nn0 = m.dict.nearest_neighbors(m.s[i0].x); + std::set nn1 = m.dict.nearest_neighbors(s1.x); + std::set nnn0 = m.dict.next_nearest_neighbors(m.s[i0].x); + std::set nnn1 = m.dict.next_nearest_neighbors(s1.x); + nn.insert(nn0.begin(), nn0.end()); + nn.insert(nn1.begin(), nn1.end()); + nn.insert(nnn0.begin(), nnn0.end()); + nn.insert(nnn1.begin(), nnn1.end()); + nn.insert(os1.begin(), os1.end()); + nn.insert(m.s.size()); + } else { + for (unsigned i = 0; i < m.s.size(); i++) { + nn.insert(i); + } + } + return nn; + }; + + model sphere(L, Z, B, neighbors); + + randutils::auto_seed_128 seeds; + std::mt19937 rng{seeds}; + + std::uniform_real_distribution dist(0.0, L); + + for (unsigned i = 0; i < n; i++) { + vector pos = {dist(rng), dist(rng)}; + sphere.s.push_back({pos, 0.5}); + sphere.dict.record(pos, i); + } + + sphere.wolff(T, N, rng); + + for (spin s : sphere.s) { + spin rs = sphere.s0.inverse().act(s); + std::cout << s.x.transpose() << "\n"; + } + + return 0; +} + -- cgit v1.2.3-54-g00ecf