# 2 Dimensional Ising Model: include/data_type.hpp Source File

Loading...
Searching...
No Matches
data_type.hpp
Go to the documentation of this file.
/** @file data_type.hpp
*
* @author Cory Alexander Balaton (coryab)
* @author Janita Ovidie Sandtrøen Willumsen (janitaws)
*
* @version 1.0
*
* @brief Header for the data_t type.
*
* @bug No known bugs
* */
#ifndef __DATA_TYPE__
#define __DATA_TYPE__
#include <sys/types.h>
#include <type_traits>
/** @brief Type to use with the IsingModel class and montecarlo module.*/
class data_t {
public:
double E; ///< Energy
double M; ///< Magnetization
double E2; ///< Energy squared
double M2; ///< Magnetization squared
double M_abs; ///< Absolute Magnetization
/** @brief constructor with no parameters.
* */
data_t()
{
this -> E = 0.;
this -> E2 = 0.;
this -> M = 0.;
this -> M2 = 0.;
this -> M_abs = 0.;
}
/** @brief Constructor with parameters.
*
* @param E Initial energy
* @param E2 Initial energy squared
* @param M Initial magnetization
* @param M2 Initial magnetization squared
* @param M_abs Initial absolute magnetization*/
data_t(double E, double E2, double M, double M2, double M_abs)
{
this -> E = E;
this -> E2 = E2;
this -> M = M;
this -> M2 = M2;
this -> M_abs = M_abs;
}
/** @brief Overload of the division operator.
*
* @param num The number to divide each field by.
*
* @return data_t
* */
template <class T> data_t operator/(T num)
{
data_t res;
res. E = this -> E / (double)num;
res. E2 = this -> E2 / (double)num;
res. M = this -> M / (double)num;
res. M2 = this -> M2 / (double)num;
res. M_abs = this -> M_abs / (double)num;
return res;
}
/** @brief Overload of the division equals operator.
*
* @param num The number to divide each field by.
*
* @return data_t
* */
template <class T> data_t &operator/=(T num)
{
this -> E /= (double)num;
this -> E2 /= (double)num;
this -> M /= (double)num;
this -> M2 /= (double)num;
this -> M_abs /= (double)num;
return *this;
}
/** @brief Overload of the multiply operator.
*
* @param num The number to multiply each field by.
*
* @return data_t
* */
template <class T> data_t operator*(T num)
{
data_t res;
res. E = this -> E * (double)num;
res. E2 = this -> E2 * (double)num;
res. M = this -> M * (double)num;
res. M2 = this -> M2 * (double)num;
res. M_abs = this -> M_abs * (double)num;
return res;
}
/** @brief Overload of the multiply equals operator.
*
* @param num The number to multiply each field by.
*
* @return data_t
* */
template <class T> data_t &operator*=(T num)
{
this -> E *= (double)num;
this -> E2 *= (double)num;
this -> M *= (double)num;
this -> M2 *= (double)num;
this -> M_abs *= (double)num;
return *this;
}
/** @brief Overload of the addition operator.
*
* @param b The data_t field to add.
*
* @return data_t
* */
data_t operator+(const data_t &b)
{
data_t res;
res. E = this -> E + b. E;
res. E2 = this -> E2 + b. E2;
res. M = this -> M + b. M;
res. M2 = this -> M2 + b. M2;
res. M_abs = this -> M_abs + b. M_abs;
return res;
}
/** @brief Overload of the addition equals operator.
*
* @param b The data_t field to add.
*
* @return data_t
* */
data_t &operator+=(const data_t &b)
{
this -> E += b. E;
this -> E2 += b. E2;
this -> M += b. M;
this -> M2 += b. M2;
this -> M_abs += b. M_abs;
return *this;
}
};
// Declare a custom reduction for the data_t type.
#pragma omp declare reduction(+ : data_t : omp_out += omp_in)
#endif
data_t
Type to use with the IsingModel class and montecarlo module.
Definition: data_type.hpp:19
data_t::operator+
data_t operator+(const data_t &b)
Overload of the addition operator.
Definition: data_type.hpp:132
data_t::data_t
data_t(double E, double E2, double M, double M2, double M_abs)
Constructor with parameters.
Definition: data_type.hpp:45
data_t::operator/
data_t operator/(T num)
Overload of the division operator.
Definition: data_type.hpp:60
data_t::M_abs
double M_abs
Absolute Magnetization.
Definition: data_type.hpp:25
data_t::E
double E
Energy.
Definition: data_type.hpp:21
data_t::operator+=
data_t & operator+=(const data_t &b)
Overload of the addition equals operator.
Definition: data_type.hpp:150
data_t::operator*=
data_t & operator*=(T num)
Overload of the multiply equals operator.
Definition: data_type.hpp:114
data_t::M2
double M2
Magnetization squared.
Definition: data_type.hpp:24
data_t::operator*
data_t operator*(T num)
Overload of the multiply operator.
Definition: data_type.hpp:96
data_t::operator/=
data_t & operator/=(T num)
Overload of the division equals operator.
Definition: data_type.hpp:79
data_t::data_t
data_t()
constructor with no parameters.
Definition: data_type.hpp:29
data_t::E2
double E2
Energy squared.
Definition: data_type.hpp:23
data_t::M
double M
Magnetization.
Definition: data_type.hpp:22