2 Dimensional Ising Model
Simulate the change in energy and magnetization in a ferro magnet
Loading...
Searching...
No Matches
IsingModel.hpp
Go to the documentation of this file.
1/** @file IsingModel.hpp
2 *
3 * @author Cory Alexander Balaton (coryab)
4 * @author Janita Ovidie Sandtrøen Willumsen (janitaws)
5 *
6 * @version 0.1
7 *
8 * @brief The definition of the Ising model.
9 *
10 * @bug No known bugs
11 * */
12#ifndef __ISING_MODEL__
13#define __ISING_MODEL__
14
15#include "data_type.hpp"
16#include "utils.hpp"
17
18#include <armadillo>
19#include <cstdint>
20#include <random>
21#include <unordered_map>
22
23#define INDEX(I, N) (I + N) % N ///< I modulo N
24
25// Indeces for the neighbor matrix.
26#define UP 0 ///< Used for the neighbor matrix in the class
27#define LEFT 0 ///< Used for the neighbor matrix in the class
28#define DOWN 1 ///< Used for the neighbor matrix in the class
29#define RIGHT 1 ///< Used for the neighbor matrix in the class
30
31/** @brief The Ising model in 2 dimensions.
32 *
33 * @details None of the methods are parallelized, as there is very little
34 * benefit in doing so.
35 * */
37private:
38 /** @brief Give access to private members to the test class IsingModelTest.
39 * */
40 friend class IsingModelTest;
41
42 /** @brief \f$ L \times L \f$ matrix where element \f$ x \in {-1, 1}\f$.
43 * */
44 arma::Mat<int> lattice;
45
46 /** @brief \f$ L \times 2 \f$ matrix with the neighbors of each element
47 * \f$ x_i \f$.
48 *
49 * @details The reason why it's \f$ L \times 2 \f$ instead of
50 * \f$ L \times 2 \f$, is that we can see that we can use the same column
51 * for the left and upper neighbor, and we can use the same column for the
52 * right and lower neighbor.
53 * */
54 arma::Mat<int> neighbors;
55
56 /** @brief An array containing all possible energy differences.
57 * */
58 double energy_diff[17];
59
60 /** @brief The temperature of the model.
61 * */
62 double T;
63
64 /** @brief Size of the lattice.
65 * */
66 int L;
67
68 /** @brief The current energy state. unit: \f$ J \f$.
69 * */
70 int64_t E;
71
72 /** @brief The current magnetic strength. unit: Unitless.
73 * */
74 int64_t M;
75
76 /** @brief The RNG that is used for the Metropolis algorithm
77 * */
78 std::mt19937 engine;
79
80 /** @brief Initialize the RNG.
81 * */
82 void initialize_engine();
83
84 /** @brief Initialize the lattice with a random distribution of 1s and
85 * -1s.
86 * */
87 void initialize_lattice();
88
89 /** @brief Initialize the lattice with a specific value.
90 * */
91 void initialize_lattice(int val);
92
93 /** @brief initialize the neighbors matrix.
94 * */
96
97 /** @brief Initialize the energy_diff array with the correct values.
98 * */
100
101 /** @brief Initialize the magnetization of the system.
102 * */
104
105 /** @brief Initialize the energy of the system.
106 * */
107 void initialize_energy();
108
109 /** @brief Constructor used for testing.
110 * */
111 IsingModel();
112
113public:
114 /** @brief Constructor for the Ising model.
115 *
116 * @param L The size of the lattice.
117 * @param T The temperature for the system.
118 * */
119 IsingModel(int L, double T);
120
121 /** @brief Constructor for the Ising model.
122 *
123 * @param L The size of the lattice.
124 * @param T The temperature for the system.
125 * @param val The value to set for all spins.
126 * */
127 IsingModel(int L, double T, int val);
128
129 /** @brief The Metropolis algorithm.
130 * */
132};
133
134#endif
#define UP
Used for the neighbor matrix in the class.
Definition: IsingModel.hpp:26
#define INDEX(I, N)
I modulo N.
Definition: IsingModel.hpp:23
#define DOWN
Used for the neighbor matrix in the class.
Definition: IsingModel.hpp:28
#define LEFT
Used for the neighbor matrix in the class.
Definition: IsingModel.hpp:27
#define RIGHT
Used for the neighbor matrix in the class.
Definition: IsingModel.hpp:29
Test class for the Ising model.
Definition: test_suite.cpp:36
The Ising model in 2 dimensions.
Definition: IsingModel.hpp:36
std::mt19937 engine
The RNG that is used for the Metropolis algorithm.
Definition: IsingModel.hpp:78
int64_t E
The current energy state. unit: .
Definition: IsingModel.hpp:70
double T
The temperature of the model.
Definition: IsingModel.hpp:62
int L
Size of the lattice.
Definition: IsingModel.hpp:66
arma::Mat< int > lattice
matrix where element .
Definition: IsingModel.hpp:44
void initialize_lattice()
Initialize the lattice with a random distribution of 1s and -1s.
Definition: IsingModel.cpp:49
IsingModel(int L, double T, int val)
Constructor for the Ising model.
Definition: IsingModel.cpp:31
IsingModel(int L, double T)
Constructor for the Ising model.
Definition: IsingModel.cpp:19
data_t Metropolis()
The Metropolis algorithm.
Definition: IsingModel.cpp:110
void initialize_energy()
Initialize the energy of the system.
Definition: IsingModel.cpp:96
void initialize_neighbors()
initialize the neighbors matrix.
Definition: IsingModel.cpp:70
double energy_diff[17]
An array containing all possible energy differences.
Definition: IsingModel.hpp:58
void initialize_magnetization()
Initialize the magnetization of the system.
Definition: IsingModel.cpp:88
arma::Mat< int > neighbors
matrix with the neighbors of each element .
Definition: IsingModel.hpp:54
void initialize_engine()
Initialize the RNG.
Definition: IsingModel.cpp:43
void initialize_lattice(int val)
Initialize the lattice with a specific value.
Definition: IsingModel.cpp:59
IsingModel()
Constructor used for testing.
Definition: IsingModel.cpp:14
int64_t M
The current magnetic strength. unit: Unitless.
Definition: IsingModel.hpp:74
void initialize_energy_diff()
Initialize the energy_diff array with the correct values.
Definition: IsingModel.cpp:81
Type to use with the IsingModel class and montecarlo module.
Definition: data_type.hpp:19
data_t(double E, double E2, double M, double M2, double M_abs)
Constructor with parameters.
Definition: data_type.hpp:45