From 802b63ddf121b520db7942fe330cce6004fbeb6d Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Wed, 25 Jul 2018 16:22:50 -0400 Subject: got everyone recording data, and fixed huge bug in the updating of ReF and ImF --- lib/potts.h | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) (limited to 'lib/potts.h') diff --git a/lib/potts.h b/lib/potts.h index 732a76f..e61e4e1 100644 --- a/lib/potts.h +++ b/lib/potts.h @@ -4,6 +4,7 @@ #include #include "types.h" +#include "vector.h" /* The following is the minimum definition of a spin class. * @@ -30,8 +31,8 @@ class potts_t { public: q_t x; - typedef int *M_t; - typedef double *F_t; + typedef vector_t M_t; + typedef vector_t F_t; }; template @@ -44,56 +45,54 @@ void free_spin(potts_t s) { // do nothing! } -void free_spin(int *s) { - free(s); -} - -void free_spin(double *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; +void add(vector_t *s1, int a, potts_t s2) { + (s1->x)[s2.x] += a; } template -void add(typename potts_t::F_t *s1, double a, potts_t s2) { - (*s1)[s2.x] += a; +void add(vector_t *s1, double a, potts_t s2) { + (s1->x)[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; +vector_t scalar_multiple(int factor, potts_t s) { + vector_t M; + M.x = (int *)calloc(q, sizeof(int)); + M.x[s.x] += factor; return M; } template -typename potts_t::F_t scalar_multiple(double factor, potts_t s) { - double *F = (double *)calloc(q, sizeof(double)); - F[s.x] += factor; +vector_t scalar_multiple(double factor, potts_t s) { + vector_t F; + F.x = (double *)calloc(q, sizeof(double)); + F.x[s.x] += factor; return F; } +// we could inherit norm_squared from vector.h, but convention dictates that +// potts norms be changed by a constant factor template -double norm_squared(typename potts_t::F_t s) { +double norm_squared(vector_t s) { double total = 0; for (q_t i = 0; i < q; i++) { - total += pow(s[i], 2); + total += pow(s.x[i], 2); } return total * (double)q / ((double)q - 1.0); } +// we could inherit write_magnetization from vector.h, but since M.x must sum +// to nv we don't need to write the last element template -void write_magnetization(typename potts_t::M_t M, FILE *outfile) { - fwrite(&M, sizeof(int), q, outfile); +void write_magnetization(vector_t M, FILE *outfile) { + fwrite(M.x, sizeof(int), q - 1, outfile); } // knock yourself out -- cgit v1.2.3-70-g09d2