diff options
Diffstat (limited to 'lib/height.h')
-rw-r--r-- | lib/height.h | 75 |
1 files changed, 51 insertions, 24 deletions
diff --git a/lib/height.h b/lib/height.h index 16c4dc5..81d3a2d 100644 --- a/lib/height.h +++ b/lib/height.h @@ -2,61 +2,88 @@ #pragma once #include <cmath> +#include <stdio.h> #include "types.h" -// object definition +/* 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 T> -struct height_t { T x; }; +struct height_t { + T x; + + typedef T M_t; + typedef double F_t; +}; -// init, copy, add, subtract, scalar_multiple, free_spin, and -// write_magnetization are necessary for the operation of wolff.h template <class T> -void init(height_t *ptr) { +void init(height_t<T> *ptr) { ptr->x = (T)0; } template <class T> -height_t <T> copy (height_t h) { - return h; +void free_spin(height_t<T> h) { + // do nothing! } template <class T> -void add (height_t <T> *h1, height_t <T> h2) { - h1->x += h2.x; +void free_spin(T h) { + // do nothing! } -template <class T> -void subtract (height_t <T> *h1, height_T <T> h2) { - h1->x -= h2.x; +void free_spin(double h) { + // do nothing! } template <class T> -height_t <T> scalar_multiple(v_t a, height_t <T> h) { - height_t <T> hm; - hm.x = a * h.x; +height_t<T> copy(height_t<T> h) { + return h; +} - return hm; +template <class T> +void add(T *h1, int a, height_t<T> h2) { + (*h1) += a * h2.x; } template <class T> -void free_spin (height_t <T> h) { +void add(double *h1, double a, height_t<T> h2) { + (*h1) += a * h2.x; } template <class T> -void write_magnetization(height_t <T> M, FILE *outfile) { - fwrite(&(M.x), sizeof(T), 1, outfile); +T scalar_multiple(int factor, height_t<T> h) { + return factor * h.x; } template <class T> -double correlation_component(height_t <T> h) { - return (double)h.x; +double scalar_multiple(double factor, height_t<T> h) { + return factor * h.x; } -// below here are not necessary for operation +double norm_squared(double h) { + return pow(h, 2); +} template <class T> -T dot(height_t <T> h1, height_t <T> h2) { - return (h1.x - h2.x) * (h1.x - h2.x); +void write_magnetization(T M, FILE *outfile) { + fwrite(&M, sizeof(T), 1, outfile); } |