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
12#ifndef __ISING_MODEL__
13#define __ISING_MODEL__
14
15#include "constants.hpp"
16#include "data_type.hpp"
17#include "typedefs.hpp"
18#include "utils.hpp"
19
20#include <armadillo>
21#include <random>
22#include <unordered_map>
23
24#define INDEX(I, N) (I + N) % N
25
26// Indeces for the neighbor matrix.
27#define UP 0
28#define LEFT 0
29#define DOWN 1
30#define RIGHT 1
31
38private:
39 friend class IsingModelTest;
42 arma::Mat<int> lattice;
43
52 arma::Mat<int> neighbors;
53
56 std::unordered_map<int, double> energy_diff;
57
60 double T;
61
64 int L;
65
68 int E;
69
72 int M;
73
77 void initialize_lattice();
78
82
86
90
93 void initialize_energy();
94
97 IsingModel();
98
99public:
105 IsingModel(int L, double T);
106
113 IsingModel(int L, double T, int val);
114
118
123 int get_E();
124
129 int get_M();
130};
131
132#endif
Test class for the Ising model.
Definition: test_suite.cpp:30
The Ising model in 2 dimensions.
Definition: IsingModel.hpp:37
int M
The current magnetic strength. unit: Unitless.
Definition: IsingModel.hpp:72
std::unordered_map< int, double > energy_diff
A hash map containing all possible energy changes.
Definition: IsingModel.hpp:56
double T
The temperature of the model.
Definition: IsingModel.hpp:60
int L
Size of the lattice.
Definition: IsingModel.hpp:64
arma::Mat< int > lattice
matrix where element .
Definition: IsingModel.hpp:42
void initialize_lattice()
Initialize the lattice with a random distribution of 1s and -1s.
Definition: IsingModel.cpp:44
data_t Metropolis()
The Metropolis algorithm.
Definition: IsingModel.cpp:96
void initialize_energy()
Initialize the energy.
Definition: IsingModel.cpp:82
void initialize_neighbors()
initialize the neighbors matrix.
Definition: IsingModel.cpp:56
void initialize_magnetization()
Initialize the magnetization.
Definition: IsingModel.cpp:74
arma::Mat< int > neighbors
matrix with the neighbors of each element .
Definition: IsingModel.hpp:52
int get_M()
Get the current magnetization.
Definition: IsingModel.cpp:140
int get_E()
Get the current energy.
Definition: IsingModel.cpp:135
IsingModel()
Constructor used for testing.
Definition: IsingModel.cpp:17
int E
The current energy state. unit: .
Definition: IsingModel.hpp:68
void initialize_energy_diff()
Initialize the hashmap with the correct values.
Definition: IsingModel.cpp:67
Library of constants.
Header for the data_t type.
Useful typedefs for cleaner code.
Function prototypes and macros that are useful.