diff options
Diffstat (limited to 'ising.cpp')
-rw-r--r-- | ising.cpp | 37 |
1 files changed, 23 insertions, 14 deletions
@@ -1,18 +1,25 @@ #include "space_wolff.hpp" +std::function<double(spin<signed, 2, signed>)> B_sin(unsigned L, unsigned n, double H) { + return [n, H, L] (spin<signed, 2, signed> s) -> double { + return H * cos(2 * M_PI * n * s.x[0] / ((double)L)); + }; +} + int main(int argc, char* argv[]) { const unsigned D = 2; unsigned L = 32; unsigned N = 1000; + unsigned mod = 0; double T = 2.0 / log(1.0 + sqrt(2.0)); double H = 1.0; double ε = 0.1; int opt; - while ((opt = getopt(argc, argv, "N:L:T:H:e:")) != -1) { + while ((opt = getopt(argc, argv, "N:L:T:H:e:m:")) != -1) { switch (opt) { case 'N': N = (unsigned)atof(optarg); @@ -29,6 +36,9 @@ int main(int argc, char* argv[]) { case 'e': ε = atof(optarg); break; + case 'm': + mod = atoi(optarg); + break; default: exit(1); } @@ -62,11 +72,19 @@ int main(int argc, char* argv[]) { } }; - std::function<double(spin<signed, D, signed>)> B = + std::function<double(spin<signed, D, signed>)> B_face = [L, H] (spin<signed, D, signed> s) -> double { return H * s.s * smiley[s.x(1) * 16 / L][s.x(0) * 16 / L]; }; + std::function<double(spin<signed, D, signed>)> B; + + if (mod > 0) { + B = B_sin(L, mod, H); + } else { + B = B_face; + } + std::function<std::set<unsigned>(model<signed, D, signed>&, unsigned, spin<signed, D, signed>)> neighbors = [] (model<signed, D, signed>& m, unsigned i0, spin<signed, D, signed> s1) -> std::set<unsigned> { std::set<unsigned> nn; @@ -127,7 +145,7 @@ int main(int argc, char* argv[]) { ising.wolff(T, N, rng); std::array<double, 2> τ = ising.Eq.τ(); std::cout << τ[0] << " " << τ[1] << " " << τ[1] / τ[0] << "\n"; - if (τ[1] / τ[0] < ε) { + if (τ[1] / τ[0] < ε && τ[0] * 1e4 < ising.Eq.num_added()) { break; } } @@ -140,20 +158,11 @@ int main(int argc, char* argv[]) { } std::ofstream outfile; - outfile.open("snap.dat"); - - for (unsigned i = 0; i < L; i++) { - for (unsigned j = 0; j < L; j++) { - unsigned out = output[L * i + j] == 1 ? 1 : 0; - outfile << out << " "; - } - outfile << "\n"; - } - outfile.close(); + outfile.open("out.dat", std::ios::app); std::array<double, 2> act = ising.Eq.τ(); - std::cout << act[0] << " " << act[1] << "\n"; + outfile << L << " " << T << " " << mod << " " << H << " " << ising.Cq.avg() << " " << ising.Cq.serr() << " " << act[0] << " " << act[1] << "\n"; return 0; } |