From 1160baa61bad605cf8a1d583e8ae356a54a942df Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Thu, 26 Jul 2018 16:18:40 -0400 Subject: many changes, including new spin spaces and groups and cleaning up core library code --- lib/torus.h | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 lib/torus.h (limited to 'lib/torus.h') diff --git a/lib/torus.h b/lib/torus.h new file mode 100644 index 0000000..2aead52 --- /dev/null +++ b/lib/torus.h @@ -0,0 +1,64 @@ + +#pragma once + +#include +#include +#include "types.h" + +template +class torus_t : public std::array { + public: + typedef std::array M_t; + typedef std::array F_t; + + torus_t() { + this->fill(0); + } + + inline torus_t operator*(v_t a) const { + torus_t x; + for (q_t i = 0; i < n; i++) { + x[i] = a * (*this)[i]; + } + + return x; + } + + inline torus_t operator*(double a) const { + torus_t x; + for (q_t i = 0; i < n; i++) { + x[i] = a * (*this)[i]; + } + + return x; + } + + inline torus_t& operator+=(const torus_t& x) { + for (q_t i = 0; i < n; i++) { + (*this)[i] += x[i]; + } + } + + inline torus_t& operator-=(const torus_t& x) { + for (q_t i = 0; i < n; i++) { + (*this)[i] -= x[i]; + } + } +}; + +template +double norm_squared(const torus_t& x) { + double tmp = 0; + for (const double& xi : x) { + tmp += pow(xi, 2); + } + return tmp; +} + +void write_magnetization(const torus_t& x, FILE *outfile) { + for (const double& xi : x) { + float tmp_xi = (float)xi; + fwrite(&tmp_xi, sizeof(float), 1, outfile); + } +} + -- cgit v1.2.3-70-g09d2