summaryrefslogtreecommitdiff
path: root/space_wolff.hpp
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2019-12-03 15:49:20 -0500
committerJaron Kent-Dobias <jaron@kent-dobias.com>2019-12-03 15:49:20 -0500
commit8056fe046011a46b25b6924b2d96229d06dbb4f7 (patch)
tree9ecef51cba09d366114fcf76e1f206e915e826f6 /space_wolff.hpp
parent27efccd705a36510a02054ddd27ad80826321a21 (diff)
downloadspace_wolff-8056fe046011a46b25b6924b2d96229d06dbb4f7.tar.gz
space_wolff-8056fe046011a46b25b6924b2d96229d06dbb4f7.tar.bz2
space_wolff-8056fe046011a46b25b6924b2d96229d06dbb4f7.zip
refactoring and generalization in preparation for pressure ensemble
Diffstat (limited to 'space_wolff.hpp')
-rw-r--r--space_wolff.hpp215
1 files changed, 99 insertions, 116 deletions
diff --git a/space_wolff.hpp b/space_wolff.hpp
index 02c544d..1335f07 100644
--- a/space_wolff.hpp
+++ b/space_wolff.hpp
@@ -244,125 +244,136 @@ public:
unsigned num_added() const { return n - wait; }
};
-template <class U, int D, class S> class Model;
+template <class U, int D, class R, class S> class Model;
-template <class U, int D, class S> class measurement {
+template <class U, int D, class R, class S> class measurement {
public:
- virtual void pre_cluster(const Model<U, D, S>&, unsigned, const Euclidean<U, D>&){};
- virtual void plain_bond_visited(const Model<U, D, S>&, const Spin<U, D, S>*, const Spin<U, D, S>*,
+ virtual void pre_cluster(const Model<U, D, R, S>&, unsigned, const R&){};
+ virtual void plain_bond_visited(const Model<U, D, R, S>&, const Spin<U, D, S>*, const Spin<U, D, S>*,
const Spin<U, D, S>&, double){};
- virtual void plain_site_transformed(const Model<U, D, S>&, const Spin<U, D, S>*,
+ virtual void plain_site_transformed(const Model<U, D, R, S>&, const Spin<U, D, S>*,
const Spin<U, D, S>&){};
- virtual void ghost_bond_visited(const Model<U, D, S>&, const Spin<U, D, S>&, const Spin<U, D, S>&,
+ virtual void ghost_bond_visited(const Model<U, D, R, S>&, const Spin<U, D, S>&, const Spin<U, D, S>&,
double){};
- virtual void ghost_site_transformed(const Model<U, D, S>&, const Euclidean<U, D>&){};
+ virtual void ghost_site_transformed(const Model<U, D, R, S>&, const R&){};
- virtual void post_cluster(const Model<U, D, S>&){};
+ virtual void post_cluster(const Model<U, D, R, S>&){};
};
-template <class U, int D, class S> class Model {
-public:
- U L;
- Euclidean<U, D> s0;
- std::vector<Spin<U, D, S>> s;
- Octree<U, D, S> dict;
- unsigned dDepth;
- unsigned nDepth;
- std::function<double(const Spin<U, D, S>&, const Spin<U, D, S>&)> Z;
- std::function<double(const Spin<U, D, S>&)> B;
- std::vector<Matrix<U, D>> mats;
- std::vector<Vector<U, D>> steps;
- double E;
- measurement<U, D, S>& A;
-
- void one_sequences(std::list<std::array<double, D>>& sequences, unsigned level) {
- if (level > 0) {
- unsigned new_level = level - 1;
- unsigned old_length = sequences.size();
- for (std::array<double, D>& sequence : sequences) {
- std::array<double, D> new_sequence = sequence;
- new_sequence[new_level] = -1;
- sequences.push_front(new_sequence);
- }
- one_sequences(sequences, new_level);
+template<int D>
+void one_sequences(std::list<std::array<double, D>>& sequences, unsigned level) {
+ if (level > 0) {
+ unsigned new_level = level - 1;
+ unsigned old_length = sequences.size();
+ for (std::array<double, D>& sequence : sequences) {
+ std::array<double, D> new_sequence = sequence;
+ new_sequence[new_level] = -1;
+ sequences.push_front(new_sequence);
}
+ one_sequences(sequences, new_level);
}
+}
- Model(U L, std::function<double(const Spin<U, D, S>&, const Spin<U, D, S>&)> Z,
- std::function<double(const Spin<U, D, S>&)> B, unsigned dDepth, unsigned nDepth,
- measurement<U, D, S>& A)
- : L(L), s0(L), dict(L, dDepth), Z(Z), B(B), dDepth(dDepth), nDepth(nDepth), A(A) {
- std::array<double, D> ini_sequence;
- ini_sequence.fill(1);
- std::list<std::array<double, D>> sequences;
- sequences.push_back(ini_sequence);
+template <class U, int D>
+std::vector<Vector<U, D>> torus_vecs(U L) {
+ std::vector<Vector<U, D>> vecs;
+ std::array<double, D> ini_sequence;
+ ini_sequence.fill(1);
+ std::list<std::array<double, D>> sequences;
+ sequences.push_back(ini_sequence);
+ sequences.pop_front(); // don't want the identity matrix!
+
+ for (std::array<double, D> sequence : sequences) {
+ Vector<U, D> v;
+ for (unsigned i = 0; i < D; i++) {
+ if (sequence[i] == 1) {
+ v(i) = 0;
+ } else {
+ v(i) = L / 2;
+ }
+ }
+
+ vecs.push_back(v);
+ }
- one_sequences(sequences, D);
+ return vecs;
+}
- sequences.pop_front(); // don't want the identity matrix!
+template <class U, int D>
+std::vector<Matrix<U, D>> torus_mats() {
+ std::vector<Matrix<U, D>> mats;
- for (std::array<double, D> sequence : sequences) {
- Matrix<U, D> m;
- for (unsigned i = 0; i < D; i++) {
- for (unsigned j = 0; j < D; j++) {
- if (i == j) {
- m(i, j) = sequence[i];
- } else {
- m(i, j) = 0;
- }
- }
- }
+ std::array<double, D> ini_sequence;
+ ini_sequence.fill(1);
+ std::list<std::array<double, D>> sequences;
+ sequences.push_back(ini_sequence);
- mats.push_back(m);
+ one_sequences(sequences, D);
- Vector<U, D> v;
- for (unsigned i = 0; i < D; i++) {
- if (sequence[i] == 1) {
- v(i) = 0;
+ sequences.pop_front(); // don't want the identity matrix!
+
+ for (std::array<double, D> sequence : sequences) {
+ Matrix<U, D> m;
+ for (unsigned i = 0; i < D; i++) {
+ for (unsigned j = 0; j < D; j++) {
+ if (i == j) {
+ m(i, j) = sequence[i];
} else {
- v(i) = L / 2;
+ m(i, j) = 0;
}
}
-
- steps.push_back(v);
}
- for (unsigned i = 0; i < D; i++) {
- for (unsigned j = 0; j < D; j++) {
- if (i != j) {
- Matrix<U, D> m;
- for (unsigned k = 0; k < D; k++) {
- for (unsigned l = 0; l < D; l++) {
- if ((k == i && l == j) || (k == j && l == i)) {
- if (i < j) {
- m(k, l) = 1;
- } else {
- m(k, l) = -1;
- }
+ mats.push_back(m);
+ }
+
+ for (unsigned i = 0; i < D; i++) {
+ for (unsigned j = 0; j < D; j++) {
+ if (i != j) {
+ Matrix<U, D> m;
+ for (unsigned k = 0; k < D; k++) {
+ for (unsigned l = 0; l < D; l++) {
+ if ((k == i && l == j) || (k == j && l == i)) {
+ if (i < j) {
+ m(k, l) = 1;
} else {
- m(k, l) = 0;
+ m(k, l) = -1;
}
+ } else {
+ m(k, l) = 0;
}
}
- mats.push_back(m);
}
+ mats.push_back(m);
}
}
}
- void update_energy() {
- E = 0;
- for (unsigned i = 0; i < s.size(); i++) {
- for (unsigned j = 0; j < i; j++) {
- E -= Z(s[i], s[j]);
- }
+ return mats;
+}
- E -= B(s0.inverse().act(s[i]));
- }
- }
+template <class U, int D, class R, class S> class Model {
+public:
+ U L;
+ R s0;
+ std::vector<Spin<U, D, S>> s;
+ Octree<U, D, S> dict;
+ unsigned dDepth;
+ unsigned nDepth;
+ std::function<double(const Spin<U, D, S>&, const Spin<U, D, S>&)> Z;
+ std::function<double(const Spin<U, D, S>&)> B;
+ std::function<R(const Model<U, D, R, S>&, randutils::mt19937_rng&)> g;
+ randutils::mt19937_rng rng;
+ measurement<U, D, R, S>& A;
+
+
+ Model(U L, std::function<double(const Spin<U, D, S>&, const Spin<U, D, S>&)> Z,
+ std::function<double(const Spin<U, D, S>&)> B, std::function<R(const Model<U, D, R, S>&, randutils::mt19937_rng&)> g, unsigned dDepth, unsigned nDepth,
+ measurement<U, D, R, S>& A)
+ : L(L), s0(L), dict(L, dDepth), Z(Z), B(B), g(g), dDepth(dDepth), nDepth(nDepth), rng(), A(A) {}
- void step(double T, unsigned ind, Euclidean<U, D> r, std::mt19937& rng) {
+ void step(double T, unsigned ind, Euclidean<U, D> r) {
unsigned cluster_size = 0;
std::uniform_real_distribution<double> dist(0.0, 1.0);
@@ -427,37 +438,11 @@ public:
}
}
- void wolff(double T, unsigned N, std::mt19937& rng) {
- std::uniform_real_distribution<double> t_dist(0, L);
- std::uniform_int_distribution<unsigned> r_dist(0, D - 1);
+ void wolff(double T, unsigned N) {
std::uniform_int_distribution<unsigned> ind_dist(0, s.size() - 1);
- std::uniform_int_distribution<unsigned> coin(0, mats.size() + steps.size() - 1);
for (unsigned i = 0; i < N; i++) {
- Vector<U, D> t;
- Matrix<U, D> m;
- unsigned flip = coin(rng);
- if (flip < mats.size()) {
- for (unsigned j = 0; j < D; j++) {
- t(j) = (U)t_dist(rng);
- }
- m = mats[flip];
- } else {
- for (unsigned j = 0; j < D; j++) {
- for (unsigned k = 0; k < D; k++) {
- if (j == k) {
- m(j, k) = 1;
- } else {
- m(j, k) = 0;
- }
- }
- }
-
- t = steps[flip - mats.size()];
- }
-
- Euclidean<U, D> g(L, t, m);
-
+ R g = g(*this, rng);
unsigned ind = ind_dist(rng);
A.pre_cluster(*this, ind, g);
@@ -465,8 +450,6 @@ public:
this->step(T, ind, g, rng);
A.post_cluster(*this);
-
- this->update_energy();
}
}
};