summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2018-10-14 20:54:01 -0400
committerJaron Kent-Dobias <jaron@kent-dobias.com>2018-10-14 20:54:01 -0400
commit6e8b19e1f1a244ef09e1b63d7593250d6ce01692 (patch)
tree4c7e177f71020884711d804babf2e1550f18d748 /lib
parent4b8f4005c30f5ad66408216f4ef78f75ad08741f (diff)
downloadc++-6e8b19e1f1a244ef09e1b63d7593250d6ce01692.tar.gz
c++-6e8b19e1f1a244ef09e1b63d7593250d6ce01692.tar.bz2
c++-6e8b19e1f1a244ef09e1b63d7593250d6ce01692.zip
added site and bond dependence, activated by compiler flags
Diffstat (limited to 'lib')
-rw-r--r--lib/include/wolff/cluster.hpp9
-rw-r--r--lib/include/wolff/state.hpp76
2 files changed, 71 insertions, 14 deletions
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<R_t, X_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<R_t, X_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<X_t> 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<X_t> 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<typename X_t::F_t> ReF;
std::vector<typename X_t::F_t> ImF;
- std::function <double(const X_t&, const X_t&)> J;
+#ifdef BOND_DEPENDENCE
+ std::function <double(v_t, const X_t&, v_t, const X_t&)> J; // coupling between sites
+#else
+ std::function <double(const X_t&, const X_t&)> J; // coupling between sites
+#endif
+
#ifndef NOFIELD
- std::function <double(const X_t&)> H;
+#ifdef SITE_DEPENDENCE
+ std::function <double(v_t, const X_t&)> H; // coupling with the external field
+#else
+ std::function <double(const X_t&)> H; // coupling with the external field
+#endif
+#endif
- state_t(D_t D, L_t L, double T, std::function <double(const X_t&, const X_t&)> J, std::function <double(const X_t&)> 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 <double(v_t, const X_t&, v_t, const X_t&)> J
+#else
+ std::function <double(const X_t&, const X_t&)> J
+#endif
+#ifndef NOFIELD
+#ifdef SITE_DEPENDENCE
+ , std::function <double(v_t, const X_t&)> H
#else
- state_t(D_t D, L_t L, double T, std::function <double(const X_t&, const X_t&)> J) : D(D), L(L), g(D, L), T(T), R(), J(J) {
+ , std::function <double(const X_t&)> 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);