#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); } }