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

Loading...
Searching...
No Matches
IsingModel.hpp
Go to the documentation of this file.
/** @file IsingModel.hpp
*
* @author Cory Alexander Balaton (coryab)
* @author Janita Ovidie Sandtrøen Willumsen (janitaws)
*
* @version 0.1
*
* @brief The definition of the Ising model.
*
* @bug No known bugs
* */
#ifndef __ISING_MODEL__
#define __ISING_MODEL__
#include "data_type.hpp"
#include "utils.hpp"
#include <armadillo>
#include <cstdint>
#include <random>
#include <unordered_map>
#define INDEX(I, N) (I + N) % N ///< I modulo N
// Indeces for the neighbor matrix.
#define UP 0 ///< Used for the neighbor matrix in the class
#define LEFT 0 ///< Used for the neighbor matrix in the class
#define DOWN 1 ///< Used for the neighbor matrix in the class
#define RIGHT 1 ///< Used for the neighbor matrix in the class
/** @brief The Ising model in 2 dimensions.
*
* @details None of the methods are parallelized, as there is very little
* benefit in doing so.
* */
class IsingModel {
private:
/** @brief Give access to private members to the test class IsingModelTest.
* */
friend class IsingModelTest;
/** @brief \f$ L \times L \f$ matrix where element \f$ x \in {-1, 1}\f$.
* */
arma::Mat<int> lattice;
/** @brief \f$ L \times 2 \f$ matrix with the neighbors of each element
* \f$ x_i \f$.
*
* @details The reason why it's \f$ L \times 2 \f$ instead of
* \f$ L \times 2 \f$, is that we can see that we can use the same column
* for the left and upper neighbor, and we can use the same column for the
* right and lower neighbor.
* */
arma::Mat<int> neighbors;
/** @brief An array containing all possible energy differences.
* */
double energy_diff[17];
/** @brief The temperature of the model.
* */
double T;
/** @brief Size of the lattice.
* */
int L;
/** @brief The current energy state. unit: \f$ J \f$.
* */
int64_t E;
/** @brief The current magnetic strength. unit: Unitless.
* */
int64_t M;
/** @brief The RNG that is used for the Metropolis algorithm
* */
std::mt19937 engine;
/** @brief Initialize the RNG.
* */
void initialize_engine();
/** @brief Initialize the lattice with a random distribution of 1s and
* -1s.
* */
void initialize_lattice();
/** @brief Initialize the lattice with a specific value.
* */
void initialize_lattice(int val);
/** @brief initialize the neighbors matrix.
* */
void initialize_neighbors();
/** @brief Initialize the energy_diff array with the correct values.
* */
void initialize_energy_diff();
/** @brief Initialize the magnetization of the system.
* */
void initialize_magnetization();
/** @brief Initialize the energy of the system.
* */
void initialize_energy();
/** @brief Constructor used for testing.
* */
IsingModel();
public:
/** @brief Constructor for the Ising model.
*
* @param L The size of the lattice.
* @param T The temperature for the system.
* */
IsingModel(int L, double T);
/** @brief Constructor for the Ising model.
*
* @param L The size of the lattice.
* @param T The temperature for the system.
* @param val The value to set for all spins.
* */
IsingModel(int L, double T, int val);
/** @brief The Metropolis algorithm.
* */
data_t Metropolis();
};
#endif
UP
#define UP
Used for the neighbor matrix in the class.
Definition: IsingModel.hpp:26
INDEX
#define INDEX(I, N)
I modulo N.
Definition: IsingModel.hpp:23
DOWN
#define DOWN
Used for the neighbor matrix in the class.
Definition: IsingModel.hpp:28
LEFT
#define LEFT
Used for the neighbor matrix in the class.
Definition: IsingModel.hpp:27
RIGHT
#define RIGHT
Used for the neighbor matrix in the class.
Definition: IsingModel.hpp:29
IsingModelTest
Test class for the Ising model.
Definition: test_suite.cpp:36
IsingModel
The Ising model in 2 dimensions.
Definition: IsingModel.hpp:36
IsingModel::engine
std::mt19937 engine
The RNG that is used for the Metropolis algorithm.
Definition: IsingModel.hpp:78
IsingModel::E
int64_t E
The current energy state. unit: .
Definition: IsingModel.hpp:70
IsingModel::T
double T
The temperature of the model.
Definition: IsingModel.hpp:62
IsingModel::L
int L
Size of the lattice.
Definition: IsingModel.hpp:66
IsingModel::lattice
arma::Mat< int > lattice
matrix where element .
Definition: IsingModel.hpp:44
IsingModel::initialize_lattice
void initialize_lattice()
Initialize the lattice with a random distribution of 1s and -1s.
Definition: IsingModel.cpp:49
IsingModel::IsingModel
IsingModel(int L, double T, int val)
Constructor for the Ising model.
Definition: IsingModel.cpp:31
IsingModel::IsingModel
IsingModel(int L, double T)
Constructor for the Ising model.
Definition: IsingModel.cpp:19
IsingModel::Metropolis
data_t Metropolis()
The Metropolis algorithm.
Definition: IsingModel.cpp:110
IsingModel::initialize_energy
void initialize_energy()
Initialize the energy of the system.
Definition: IsingModel.cpp:96
IsingModel::initialize_neighbors
void initialize_neighbors()
initialize the neighbors matrix.
Definition: IsingModel.cpp:70
IsingModel::energy_diff
double energy_diff[17]
An array containing all possible energy differences.
Definition: IsingModel.hpp:58
IsingModel::initialize_magnetization
void initialize_magnetization()
Initialize the magnetization of the system.
Definition: IsingModel.cpp:88
IsingModel::neighbors
arma::Mat< int > neighbors
matrix with the neighbors of each element .
Definition: IsingModel.hpp:54
IsingModel::initialize_engine
void initialize_engine()
Initialize the RNG.
Definition: IsingModel.cpp:43
IsingModel::initialize_lattice
void initialize_lattice(int val)
Initialize the lattice with a specific value.
Definition: IsingModel.cpp:59
IsingModel::IsingModel
IsingModel()
Constructor used for testing.
Definition: IsingModel.cpp:14
IsingModel::M
int64_t M
The current magnetic strength. unit: Unitless.
Definition: IsingModel.hpp:74
IsingModel::initialize_energy_diff
void initialize_energy_diff()
Initialize the energy_diff array with the correct values.
Definition: IsingModel.cpp:81
data_t
Type to use with the IsingModel class and montecarlo module.
Definition: data_type.hpp:19
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