summaryrefslogtreecommitdiff
path: root/spheres.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'spheres.cpp')
-rw-r--r--spheres.cpp104
1 files changed, 104 insertions, 0 deletions
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<double(spin<double, D, double>, spin<double, D, double>)> Z =
+ [L] (spin<double, D, double> s1, spin<double, D, double> s2) -> double {
+ vector<double, D> 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<double>::infinity();
+ } else {
+ return 0;
+ }
+ };
+
+ std::function<double(spin<double, D, double>)> B =
+ [L, H] (spin<double, D, double> s) -> double {
+ return H * sin(2 * M_PI * 3 * s.x(0) / L);
+ };
+
+ std::function<std::set<unsigned>(model<double, D, double>&, unsigned, spin<double, D, double>)> neighbors =
+ [] (model<double, D, double>& m, unsigned i0, spin<double, D, double> s1) -> std::set<unsigned> {
+ std::set<unsigned> nn;
+ if (i0 < m.s.size()) {
+ std::set<unsigned> os1 = m.dict.on_site(s1.x);
+ std::set<unsigned> nn0 = m.dict.nearest_neighbors(m.s[i0].x);
+ std::set<unsigned> nn1 = m.dict.nearest_neighbors(s1.x);
+ std::set<unsigned> nnn0 = m.dict.next_nearest_neighbors(m.s[i0].x);
+ std::set<unsigned> 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<double, D, double> sphere(L, Z, B, neighbors);
+
+ randutils::auto_seed_128 seeds;
+ std::mt19937 rng{seeds};
+
+ std::uniform_real_distribution<double> dist(0.0, L);
+
+ for (unsigned i = 0; i < n; i++) {
+ vector<double, D> pos = {dist(rng), dist(rng)};
+ sphere.s.push_back({pos, 0.5});
+ sphere.dict.record<double>(pos, i);
+ }
+
+ sphere.wolff(T, N, rng);
+
+ for (spin<double, D, double> s : sphere.s) {
+ spin<double, D, double> rs = sphere.s0.inverse().act(s);
+ std::cout << s.x.transpose() << "\n";
+ }
+
+ return 0;
+}
+