diff options
Diffstat (limited to 'space_wolff.hpp')
-rw-r--r-- | space_wolff.hpp | 47 |
1 files changed, 15 insertions, 32 deletions
diff --git a/space_wolff.hpp b/space_wolff.hpp index 9d529a3..3314ef9 100644 --- a/space_wolff.hpp +++ b/space_wolff.hpp @@ -8,32 +8,15 @@ #include <vector> #include "euclidean.hpp" +#include "measurement.hpp" #include "octree.hpp" #include "quantity.hpp" -#include "spin.hpp" #include "random.hpp" +#include "spin.hpp" #include "transformation.hpp" -template <class U, int D, class R, class S> class Model; - -template <class U, int D, class R, class S> class measurement { -public: - 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, R, 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, R, S>&, const R&){}; - - virtual void post_cluster(const Model<U, D, R, S>&){}; -}; - 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; @@ -43,42 +26,42 @@ public: 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) - : L(L), s0(L), Z(Z), B(B), rng(), dict(L, std::floor(L)) {} + : s0(L), Z(Z), B(B), rng(), dict(L, std::floor(L)) {} void step(double T, Transformation<U, D, R, S>* t0, measurement<U, D, R, S>& A) { std::queue<Transformation<U, D, R, S>*> queue; queue.push(t0); - std::set<Spin<U, D, S>*> visited; + std::set<Spin<U, D, S>*> cluster = t0->current(); while (!queue.empty()) { Transformation<U, D, R, S>* t = queue.front(); queue.pop(); - std::set<Spin<U, D, S>*> c = t->current(); - if (!std::any_of(c.begin(), c.end(), [&visited](Spin<U, D, S>* s) { return visited.contains(s); })) { - visited.insert(c.begin(), c.end()); - - for (Spin<U, D, S>* s : t->toConsider()) { + for (Spin<U, D, S>* s : t->toConsider()) { + if (!cluster.contains(s)) { double ΔE = t->ΔE(s); if (ΔE > 0 && 1.0 - exp(-ΔE / T) > rng.uniform<double>(0, 1)) { - queue.push(t->createNew(s)); + cluster.insert(s); + queue.push(t->createNew(T, cluster, s, rng)); } } - - t->apply(); } + + A.plain_site_transformed(*this, *t); + t->apply(); delete t; } } void resize(double T, double P) {} - void wolff(double T, std::vector<Gen<U, D, R, S>> gs, - measurement<U, D, R, S>& A, unsigned N) { + void wolff(double T, std::vector<Gen<U, D, R, S>> gs, measurement<U, D, R, S>& A, unsigned N) { for (unsigned i = 0; i < N; i++) { Gen<U, D, R, S>& g = rng.pick(gs); - Transformation<U, D, R, S> *t = g(*this, rng); + Transformation<U, D, R, S>* t = g(*this, rng); + + A.pre_cluster(*this, i, t); this->step(T, t, A); |