From e3fbb92e68f0410f106285c9a49ecf8cd0a488a9 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Sat, 21 Jul 2018 19:43:16 -0400 Subject: added visualization, and started potts --- lib/potts.h | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 lib/potts.h (limited to 'lib/potts.h') diff --git a/lib/potts.h b/lib/potts.h new file mode 100644 index 0000000..e7f0899 --- /dev/null +++ b/lib/potts.h @@ -0,0 +1,100 @@ +#pragma once + +#include +#include + +#include "types.h" + +/* The following is the minimum definition of a spin class. + * + * The class must contain an M_t and an F_t for holding the sum of an + * integer number of spins and a double-weighted number of spins, + * respectively. + * + * void init(X_t *p); + * void free_spin(X_t p); + * void free_spin(M_t p); + * void free_spin(F_t p); + * X_t copy(X_t x); + * void add(M_t *x1, int factor, X_t x2); + * void add(F_t *x1, double factor, X_t x2); + * M_t scalar_multiple(int factor, X_t x); + * F_t scalar_multiple(double factor, X_t x); + * double norm_squared(F_t x); + * void write_magnetization(M_t M, FILE *outfile); + * + */ + +template +class potts_t { + public: + q_t x; + + typedef int *M_t; + typedef double *F_t; +}; + +template +void init(potts_t *p) { + p->x = 0; +} + +template +void free_spin(potts_t s) { + // do nothing! +} + +template +void free_spin(typename potts_t::M_t s) { + free(s); +} + +template +void free_spin(typename potts_t::F_t s) { + free(s); +} + +template +potts_t copy(potts_t s) { + return s; +} + +template +void add(typename potts_t::M_t s1, int a, potts_t s2) { + s1[s2.x] += a; +} + +template +void add(typename potts_t::F_t s1, double a, potts_t s2) { + s1[s2.x] += a; +} + +template +typename potts_t::M_t scalar_multiple(int factor, potts_t s) { + int *M = (int *)calloc(q, sizeof(int)); + M[s.x] += factor; + return M; +} + +template +typename potts_t::F_t scalar_multiple(double factor, potts_t s) { + int *F = (double *)calloc(q, sizeof(double)); + M[s.x] += factor; + return M; +} + +template +double norm_squared(typename potts::F_t s) { + double total = 0; + for (q_t i = 0; i < q; i++) { + total += pow(s[i], 2); + } + + return total * (double)q / ((double)q - 1.0); +} + +template +void write_magnetization(typename potts_t::M_t M, FILE *outfile) { + fwrite(&M, sizeof(int), q, outfile); +} + -- cgit v1.2.3-70-g09d2