45 std::random_device rd{};
46 this->
engine = std::mt19937{rd()};
53 std::uniform_int_distribution<> coin_flip(0, 1);
55 for (
size_t i = 0; i < this->
lattice.n_elem; i++)
62 if (val != 1 && val != -1) {
75 for (
int i = 0; i < (int)this->
L; i++) {
83 for (
int i = -8; i <= 8; i += 4) {
91 for (
size_t i = 0; i < this->
lattice.n_elem; i++) {
101 for (
size_t j = 0; j < this->
L; j++) {
102 for (
size_t i = 0; i < this->
L; i++) {
116 std::uniform_int_distribution<> random_index(0, this->
L - 1);
118 std::uniform_real_distribution<> random_number(0., 1.);
121 for (
size_t i = 0; i < this->
lattice.n_elem; i++) {
123 ri = random_index(
engine);
124 rj = random_index(
engine);
137 this->
M += 2 * this->
lattice(ri, rj);
142 return data_t((
double)this->
E, (
double)(this->E * this->E), (
double)this->
M,
143 (
double)(this->M * this->M), std::fabs((
double)this->M));
The definition of the Ising model.
#define UP
Used for the neighbor matrix in the class.
#define INDEX(I, N)
I modulo N.
#define DOWN
Used for the neighbor matrix in the class.
#define LEFT
Used for the neighbor matrix in the class.
#define RIGHT
Used for the neighbor matrix in the class.
std::mt19937 engine
The RNG that is used for the Metropolis algorithm.
int64_t E
The current energy state. unit: .
double T
The temperature of the model.
int L
Size of the lattice.
arma::Mat< int > lattice
matrix where element .
void initialize_lattice()
Initialize the lattice with a random distribution of 1s and -1s.
data_t Metropolis()
The Metropolis algorithm.
void initialize_energy()
Initialize the energy of the system.
void initialize_neighbors()
initialize the neighbors matrix.
double energy_diff[17]
An array containing all possible energy differences.
void initialize_magnetization()
Initialize the magnetization of the system.
arma::Mat< int > neighbors
matrix with the neighbors of each element .
void initialize_engine()
Initialize the RNG.
IsingModel()
Constructor used for testing.
int64_t M
The current magnetic strength. unit: Unitless.
void initialize_energy_diff()
Initialize the energy_diff array with the correct values.
Type to use with the IsingModel class and montecarlo module.