From 734dea28279ce7272e6ed23f821c69c225e2d947 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Fri, 14 Feb 2020 14:22:59 -0500 Subject: Split up Ising-related functions and added an executable for measuring Ising energy autocorrelation time. --- ising_autocorrelation.cpp | 115 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 ising_autocorrelation.cpp (limited to 'ising_autocorrelation.cpp') diff --git a/ising_autocorrelation.cpp b/ising_autocorrelation.cpp new file mode 100644 index 0000000..053be01 --- /dev/null +++ b/ising_autocorrelation.cpp @@ -0,0 +1,115 @@ +#include +#include + +#include "ising.hpp" +#include "quantity.hpp" + +class Autocorrelation : public measurement, signed> { +public: + Quantity E; + Autocorrelation(unsigned lag) : E(lag) {} + + void post_cluster(const isingModel& m) override { + double E_tmp = 0; + + TorusGroup s0Inv = m.s0.inverse(); + + for (const isingSpin* si : m.s) { + E_tmp -= m.B(s0Inv.act(*si)); + + for (const isingSpin* sj : m.dict.neighbors(si->x)) { + if (si != sj) { + E_tmp -= m.Z(*si, *sj) / 2; + } + } + } + + E.add(E_tmp); + } +}; + +int main(int argc, char* argv[]) { + unsigned L = 32; + unsigned N = 1000; + unsigned mod = 0; + unsigned multi = 1e4; + double mag = 0.5; + double pop = 1.0; + double T = 2.0 / log(1.0 + sqrt(2.0)); + double H = 1.0; + double ε = 0.1; + unsigned lag = 1e2; + + int opt; + + while ((opt = getopt(argc, argv, "N:L:T:H:e:m:M:r:p:l:")) != -1) { + switch (opt) { + case 'N': + N = (unsigned)atof(optarg); + break; + case 'L': + L = atoi(optarg); + break; + case 'T': + T = atof(optarg); + break; + case 'H': + H = atof(optarg); + break; + case 'e': + ε = atof(optarg); + break; + case 'm': + mod = atoi(optarg); + break; + case 'M': + multi = atoi(optarg); + break; + case 'r': + mag = atof(optarg); + break; + case 'p': + pop = atof(optarg); + break; + case 'l': + lag = (unsigned)atof(optarg); + break; + default: + exit(1); + } + } + + isingModel ising(L, isingZ(L), isingBMod(L, mod, H)); + isingPopulate(ising, L, pop, mag); + + auto g = isingGen(L); + + measurement, signed> A_empty; + + ising.wolff(T, {g}, A_empty, N); + + Autocorrelation A(lag); + + while (true) { + ising.wolff(T, {g}, A, N); + std::array τ = A.E.τ(); + std::cout << A.E.num_added() << " " << A.E.avg() << " " << τ[0] << " " << τ[1] << " " << τ[1] / τ[0] << "\n"; + if (τ[1] / τ[0] < ε && τ[0] * multi < A.E.num_added()) { + break; + } + } + + std::ofstream outfile; + outfile.open("out.dat", std::ios::app); + + std::array act = A.E.τ(); + std::vector ρ = A.E.ρ(); + + outfile << L << " " << T << " " << mod << " " << H << " " << A.E.num_added() << " " << + A.E.avg() << " " << A.E.serr() << " " << act[0] << " " << act[1]; for (double ρi : ρ) { + outfile << " " << ρi; + } + outfile << "\n"; + + return 0; +} -- cgit v1.2.3-54-g00ecf