2 Dimensional Ising Model
Simulate the change in energy and magnetization in a ferro magnet
Loading...
Searching...
No Matches
IsingModel Class Reference

The Ising model in 2 dimensions. More...

#include <IsingModel.hpp>

Public Member Functions

 IsingModel (int L, double T)
 Constructor for the Ising model.
 
 IsingModel (int L, double T, int val)
 Constructor for the Ising model.
 
data_t Metropolis ()
 The Metropolis algorithm.
 

Private Member Functions

void initialize_engine ()
 Initialize the RNG.
 
void initialize_lattice ()
 Initialize the lattice with a random distribution of 1s and -1s.
 
void initialize_lattice (int val)
 Initialize the lattice with a specific value.
 
void initialize_neighbors ()
 initialize the neighbors matrix.
 
void initialize_energy_diff ()
 Initialize the energy_diff array with the correct values.
 
void initialize_magnetization ()
 Initialize the magnetization of the system.
 
void initialize_energy ()
 Initialize the energy of the system.
 
 IsingModel ()
 Constructor used for testing.
 

Private Attributes

arma::Mat< int > lattice
 \( L \times L \) matrix where element \( x \in {-1, 1}\).
 
arma::Mat< int > neighbors
 \( L \times 2 \) matrix with the neighbors of each element \( x_i \).
 
double energy_diff [17]
 An array containing all possible energy differences.
 
double T
 The temperature of the model.
 
int L
 Size of the lattice.
 
int64_t E
 The current energy state. unit: \( J \).
 
int64_t M
 The current magnetic strength. unit: Unitless.
 
std::mt19937 engine
 The RNG that is used for the Metropolis algorithm.
 

Friends

class IsingModelTest
 Give access to private members to the test class IsingModelTest.
 

Detailed Description

The Ising model in 2 dimensions.

None of the methods are parallelized, as there is very little benefit in doing so.

Definition at line 36 of file IsingModel.hpp.

Constructor & Destructor Documentation

◆ IsingModel() [1/3]

IsingModel::IsingModel ( )
private

Constructor used for testing.

Definition at line 14 of file IsingModel.cpp.

◆ IsingModel() [2/3]

IsingModel::IsingModel ( int  L,
double  T 
)

Constructor for the Ising model.

Parameters
LThe size of the lattice.
TThe temperature for the system.

Definition at line 19 of file IsingModel.cpp.

◆ IsingModel() [3/3]

IsingModel::IsingModel ( int  L,
double  T,
int  val 
)

Constructor for the Ising model.

Parameters
LThe size of the lattice.
TThe temperature for the system.
valThe value to set for all spins.

Definition at line 31 of file IsingModel.cpp.

Member Function Documentation

◆ initialize_energy()

void IsingModel::initialize_energy ( )
private

Initialize the energy of the system.

Definition at line 96 of file IsingModel.cpp.

◆ initialize_energy_diff()

void IsingModel::initialize_energy_diff ( )
private

Initialize the energy_diff array with the correct values.

Definition at line 81 of file IsingModel.cpp.

◆ initialize_engine()

void IsingModel::initialize_engine ( )
private

Initialize the RNG.

Definition at line 43 of file IsingModel.cpp.

◆ initialize_lattice() [1/2]

void IsingModel::initialize_lattice ( )
private

Initialize the lattice with a random distribution of 1s and -1s.

Definition at line 49 of file IsingModel.cpp.

◆ initialize_lattice() [2/2]

void IsingModel::initialize_lattice ( int  val)
private

Initialize the lattice with a specific value.

Definition at line 59 of file IsingModel.cpp.

◆ initialize_magnetization()

void IsingModel::initialize_magnetization ( )
private

Initialize the magnetization of the system.

Definition at line 88 of file IsingModel.cpp.

◆ initialize_neighbors()

void IsingModel::initialize_neighbors ( )
private

initialize the neighbors matrix.

Definition at line 70 of file IsingModel.cpp.

◆ Metropolis()

data_t IsingModel::Metropolis ( )

The Metropolis algorithm.

Definition at line 110 of file IsingModel.cpp.

Friends And Related Function Documentation

◆ IsingModelTest

friend class IsingModelTest
friend

Give access to private members to the test class IsingModelTest.

Definition at line 40 of file IsingModel.hpp.

Member Data Documentation

◆ E

int64_t IsingModel::E
private

The current energy state. unit: \( J \).

Definition at line 70 of file IsingModel.hpp.

◆ energy_diff

double IsingModel::energy_diff[17]
private

An array containing all possible energy differences.

Definition at line 58 of file IsingModel.hpp.

◆ engine

std::mt19937 IsingModel::engine
private

The RNG that is used for the Metropolis algorithm.

Definition at line 78 of file IsingModel.hpp.

◆ L

int IsingModel::L
private

Size of the lattice.

Definition at line 66 of file IsingModel.hpp.

◆ lattice

arma::Mat<int> IsingModel::lattice
private

\( L \times L \) matrix where element \( x \in {-1, 1}\).

Definition at line 44 of file IsingModel.hpp.

◆ M

int64_t IsingModel::M
private

The current magnetic strength. unit: Unitless.

Definition at line 74 of file IsingModel.hpp.

◆ neighbors

arma::Mat<int> IsingModel::neighbors
private

\( L \times 2 \) matrix with the neighbors of each element \( x_i \).

The reason why it's \( L \times 2 \) instead of \( L \times 2 \), 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.

Definition at line 54 of file IsingModel.hpp.

◆ T

double IsingModel::T
private

The temperature of the model.

Definition at line 62 of file IsingModel.hpp.


The documentation for this class was generated from the following files: