166 lines
3.8 KiB
C++
166 lines
3.8 KiB
C++
/** @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
|