From 6e8b19e1f1a244ef09e1b63d7593250d6ce01692 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Sun, 14 Oct 2018 20:54:01 -0400 Subject: added site and bond dependence, activated by compiler flags --- lib/include/wolff/cluster.hpp | 9 +++++ lib/include/wolff/state.hpp | 76 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 71 insertions(+), 14 deletions(-) (limited to 'lib/include') diff --git a/lib/include/wolff/cluster.hpp b/lib/include/wolff/cluster.hpp index 104f3c2..e9dff7b 100644 --- a/lib/include/wolff/cluster.hpp +++ b/lib/include/wolff/cluster.hpp @@ -65,7 +65,11 @@ void flip_cluster(state_t& s, v_t v0, const R_t& r, std::mt19937& rand non_ghost = vn; } +#ifdef SITE_DEPENDENCE + dE = s.H(non_ghost, rs_old) - s.H(non_ghost, rs_new); +#else dE = s.H(rs_old) - s.H(rs_new); +#endif #ifdef FINITE_STATES prob = H_probs[state_to_ind(rs_old)][state_to_ind(rs_new)]; @@ -76,7 +80,12 @@ void flip_cluster(state_t& s, v_t v0, const R_t& r, std::mt19937& rand } else // this is a perfectly normal bond! #endif { +#ifdef BOND_DEPENDENCE + dE = s.J(v, s.spins[v], vn, s.spins[vn]) - s.J(v, si_new, vn, s.spins[vn]); +#else dE = s.J(s.spins[v], s.spins[vn]) - s.J(si_new, s.spins[vn]); +#endif + #ifdef FINITE_STATES prob = J_probs[state_to_ind(s.spins[v])][state_to_ind(si_new)][state_to_ind(s.spins[vn])]; diff --git a/lib/include/wolff/state.hpp b/lib/include/wolff/state.hpp index 1f5e359..e7c0ac3 100644 --- a/lib/include/wolff/state.hpp +++ b/lib/include/wolff/state.hpp @@ -16,35 +16,83 @@ class state_t { public: D_t D; L_t L; - v_t nv; - v_t ne; - graph_t g; - double T; - std::vector spins; - R_t R; - double E; + v_t nv; // the number of vertices in the lattice + v_t ne; // the number of edges in the lattice + graph_t g; // the graph defining the lattice without ghost + double T; // the temperature + std::vector spins; // the state of the ordinary spins +#ifndef NOFIELD + R_t R; // the current state of the ghost site +#endif + double E; // the system's total energy typename X_t::M_t M; // the "sum" of the spins, like the total magnetization - v_t last_cluster_size; + v_t last_cluster_size; // the size of the last cluster std::vector ReF; std::vector ImF; - std::function J; +#ifdef BOND_DEPENDENCE + std::function J; // coupling between sites +#else + std::function J; // coupling between sites +#endif + #ifndef NOFIELD - std::function H; +#ifdef SITE_DEPENDENCE + std::function H; // coupling with the external field +#else + std::function H; // coupling with the external field +#endif +#endif - state_t(D_t D, L_t L, double T, std::function J, std::function H) : D(D), L(L), g(D, L), T(T), R(), J(J), H(H) { + state_t(D_t D, L_t L, double T, +#ifdef BOND_DEPENDENCE + std::function J +#else + std::function J +#endif +#ifndef NOFIELD +#ifdef SITE_DEPENDENCE + , std::function H #else - state_t(D_t D, L_t L, double T, std::function J) : D(D), L(L), g(D, L), T(T), R(), J(J) { + , std::function H +#endif +#endif + ) : D(D), L(L), g(D, L), T(T), +#ifndef NOFIELD + R(), #endif + J(J) +#ifndef NOFIELD + , H(H) +#endif + { nv = g.nv; ne = g.ne; spins.resize(nv); +#ifdef BOND_DEPENDENCE + E = 0; + for (v_t v = 0; v < nv; v++) { + for (const v_t &vn : g.v_adj[v]) { + if (v < vn) { + E -= J(v, spins[v], vn, spins[vn]); + } + } + } +#else + E = - (double)ne * J(spins[0], spins[0]); +#endif + #ifndef NOFIELD g.add_ext(); - E = - (double)ne * J(spins[0], spins[0]) - (double)nv * H(spins[0]); +#ifdef SITE_DEPENDENCE + for (v_t i = 0; i < nv; i++) { + E -= H(i, spins[i]); + } #else - E = - (double)ne * J(spins[0], spins[0]); + E -= (double)nv * H(spins[0]); +#endif #endif + M = spins[0] * nv; last_cluster_size = 0; ReF.resize(D); -- cgit v1.2.3-70-g09d2