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
37 class IsingModel {
38 private:
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
81 void initialize_neighbors();
82
85 void initialize_energy_diff();
86
89 void initialize_magnetization();
90
93 void initialize_energy();
94
97 IsingModel();
98
99 public:
105 IsingModel(int L, double T);
106
113 IsingModel(int L, double T, int val);
114
117 data_t Metropolis();
118
123 int get_E();
124
129 int get_M();
130};
131
132#endif
IsingModelTest
Test class for the Ising model.
Definition: test_suite.cpp:30
IsingModel
The Ising model in 2 dimensions.
Definition: IsingModel.hpp:37
IsingModel::M
int M
The current magnetic strength. unit: Unitless.
Definition: IsingModel.hpp:72
IsingModel::energy_diff
std::unordered_map< int, double > energy_diff
A hash map containing all possible energy changes.
Definition: IsingModel.hpp:56
IsingModel::T
double T
The temperature of the model.
Definition: IsingModel.hpp:60
IsingModel::L
int L
Size of the lattice.
Definition: IsingModel.hpp:64
IsingModel::lattice
arma::Mat< int > lattice
matrix where element .
Definition: IsingModel.hpp:42
IsingModel::initialize_lattice
void initialize_lattice()
Initialize the lattice with a random distribution of 1s and -1s.
Definition: IsingModel.cpp:44
IsingModel::Metropolis
data_t Metropolis()
The Metropolis algorithm.
Definition: IsingModel.cpp:96
IsingModel::initialize_energy
void initialize_energy()
Initialize the energy.
Definition: IsingModel.cpp:82
IsingModel::initialize_neighbors
void initialize_neighbors()
initialize the neighbors matrix.
Definition: IsingModel.cpp:56
IsingModel::initialize_magnetization
void initialize_magnetization()
Initialize the magnetization.
Definition: IsingModel.cpp:74
IsingModel::neighbors
arma::Mat< int > neighbors
matrix with the neighbors of each element .
Definition: IsingModel.hpp:52
IsingModel::get_M
int get_M()
Get the current magnetization.
Definition: IsingModel.cpp:140
IsingModel::get_E
int get_E()
Get the current energy.
Definition: IsingModel.cpp:135
IsingModel::IsingModel
IsingModel()
Constructor used for testing.
Definition: IsingModel.cpp:17
IsingModel::E
int E
The current energy state. unit: .
Definition: IsingModel.hpp:68
IsingModel::initialize_energy_diff
void initialize_energy_diff()
Initialize the hashmap with the correct values.
Definition: IsingModel.cpp:67
data_t
Definition: data_type.hpp:18
constants.hpp
Library of constants.
data_type.hpp
Header for the data_t type.
typedefs.hpp
Useful typedefs for cleaner code.
utils.hpp
Function prototypes and macros that are useful.