diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2019-01-14 15:47:59 -0500 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2019-01-14 15:47:59 -0500 |
commit | 49ac78a6c04e215950bc9c0f97368605e63da15b (patch) | |
tree | 64b770c543a0c90bc7dcbc06ceaaa31e96e541ce /lib/wolff_models/ising.hpp | |
parent | 994cbf1a3b611ff4c94ced3b1630e51fd249d7ed (diff) | |
download | c++-49ac78a6c04e215950bc9c0f97368605e63da15b.tar.gz c++-49ac78a6c04e215950bc9c0f97368605e63da15b.tar.bz2 c++-49ac78a6c04e215950bc9c0f97368605e63da15b.zip |
Large refactoring around changes in the graph class.
- Graphs now use lists of references instead of vectors of indicies.
- Vertices and edges have associated classes that can be given arbitrary properties via template specification.
- All essential library headers have been combined into one, wolff.hpp.
Diffstat (limited to 'lib/wolff_models/ising.hpp')
-rw-r--r-- | lib/wolff_models/ising.hpp | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/lib/wolff_models/ising.hpp b/lib/wolff_models/ising.hpp new file mode 100644 index 0000000..345eeff --- /dev/null +++ b/lib/wolff_models/ising.hpp @@ -0,0 +1,92 @@ + +#ifndef WOLFF_MODELS_ISING_H +#define WOLFF_MODELS_ISING_H + +#define WOLFF_FINITE_STATES_N 2 + +#include "wolff.hpp" + +namespace wolff { + + class ising_t { + public: + bool x; + + ising_t() : x(false) {} + + ising_t(bool x) : x(x) {} + ising_t(unsigned x) : x((bool)x) {} + + ising_t act(const ising_t& s) const { + if (x) { + return ising_t(!s.x); + } else { + return ising_t(s.x); + } + } + + ising_t act_inverse(const ising_t& s) const { + return this->act(s); + } + + typedef int M_t; + typedef double F_t; + + inline M_t operator*(unsigned a) const { + if (x) { + return -(M_t)a; + } else { + return (M_t)a; + } + } + + inline F_t operator*(double a) const { + if (x) { + return -a; + } else { + return a; + } + } + + inline M_t operator-(const ising_t &s) const { + if (x == s.x) { + return 0; + } else { + if (x) { + return -2; + } else { + return 2; + } + } + } + + inline int operator*(const ising_t& s) const { + if (x == s.x) { + return 1; + } else { + return -1; + } + } + + unsigned enumerate() const { + return (unsigned)x; + } + }; + + inline ising_t::M_t operator*(unsigned a, const ising_t& s) { + return s * a; + } + + inline ising_t::F_t operator*(double a, const ising_t& s) { + return s * a; + } + + template <class G_t> + ising_t gen_ising(std::mt19937&, const system<ising_t, ising_t, G_t>&, const typename G_t::vertex&) { + return ising_t(true); + }; + +} + +#endif + |