104 lines
2.1 KiB
C++
104 lines
2.1 KiB
C++
/** @file IsingModel.hpp
|
|
*
|
|
* @author Cory Alexander Balaton (coryab)
|
|
* @author Janita Ovidie Sandtrøen Willumsen (janitaws)
|
|
*
|
|
* @version 0.1
|
|
*
|
|
* @brief The definition of the Ising model.
|
|
*
|
|
* @bug No known bugs
|
|
* */
|
|
#ifndef __ISING_MODEL__
|
|
#define __ISING_MODEL__
|
|
|
|
#include "typedefs.hpp"
|
|
|
|
#include <armadillo>
|
|
#include <random>
|
|
#include <unordered_map>
|
|
|
|
// Faster modulo
|
|
#define INDEX(I, N) (I + N) % N
|
|
|
|
// Indeces for the neighbor matrix.
|
|
#define UP 0
|
|
#define LEFT 0
|
|
#define DOWN 1
|
|
#define RIGHT 1
|
|
|
|
/** @brief The Ising model in 2 dimensions.
|
|
*
|
|
* @details Here we set \f$ J = 1 \f$, and the Boltzmann constant
|
|
* \f$ k_B = 1 \f$.
|
|
* */
|
|
class IsingModel {
|
|
private:
|
|
friend class IsingModelTest;
|
|
/** @brief \f$ L \cross L \f$ matrix where element $ x \in {-1, 1}$.
|
|
* */
|
|
arma::Mat<int> lattice;
|
|
|
|
arma::Mat<uint> neighbors;
|
|
|
|
/** @brief A hash map containing all possible energy changes.
|
|
* */
|
|
std::unordered_map<int, double> energy_diff;
|
|
|
|
/** @brief Temperature
|
|
* */
|
|
double T;
|
|
|
|
uint L;
|
|
|
|
/** @brief The current energy state. unit: \f$ J \f$.
|
|
* */
|
|
int E;
|
|
|
|
/** @brief The current magnetic strength. unit: Unitless.
|
|
* */
|
|
int M;
|
|
|
|
/** @brief Energy per spin. unit: \f$ J \f$.
|
|
* */
|
|
double eps;
|
|
|
|
/** @brief Magnetization per spin. unit: Unitless.
|
|
* */
|
|
double m;
|
|
|
|
/** @brief Initialize the lattice with a random distribution of 1s and
|
|
* -1s.
|
|
* */
|
|
void initialize_lattice();
|
|
|
|
void initialize_neighbors();
|
|
|
|
/** @brief Initialize the hashmap with the correct values.
|
|
* */
|
|
void initialize_energy_diff();
|
|
|
|
/** @brief Initialize the model.
|
|
* */
|
|
void initialize_magnetization();
|
|
|
|
void initialize_energy();
|
|
|
|
public:
|
|
/** @brief Constructor for the Ising model.
|
|
*
|
|
* @param L The size of the lattice.
|
|
* */
|
|
IsingModel(uint L, double T);
|
|
|
|
/** @brief Constructor for the Ising model.
|
|
*
|
|
* @param L The size of the lattice.
|
|
* */
|
|
IsingModel(uint L, double T, int val);
|
|
|
|
void Metropolis(std::mt19937 engine);
|
|
};
|
|
|
|
#endif
|