17#define EPS_2 (-2 * std::sinh(8.)) / (std::cosh(8.) + 3)
19#define MAG_2 (std::exp(8.) + 1) / (2 * (cosh(8.) + 3))
22 16 * (3 * std::cosh(8.) + 1) / ((std::cosh(8.) + 3) * (std::cosh(8.) + 3))
25 (3 * std::exp(8.) + std::exp(-8.) + 3) \
26 / ((std::cosh(8.) + 3) * (std::cosh(8.) + 3))
42 std::function<bool(
int)> f = [](
int x) {
return x == 1 || x == -1; };
44 "Test lattice initialization.");
47 arma::Mat<int> neighbor_matrix(
"2, 1 ; 0, 2 ; 1, 0");
49 "Test neighbor matrix.");
56 ASSERT(std::fabs(test.
M - 9.) < 1e-8,
"Test intial magnetization");
60 ASSERT(std::fabs(test.
E - (-18)) < 1e-8,
"Test initial energy.");
74 size_t n_spins = L * L;
79 std::random_device rd;
80 std::mt19937 engine(rd());
84 int arr[]{0, 0, 0, 0};
89 while (cycles++ < max_cycles) {
96 if (testlib::close_to(EPS_2, tmp.E / n_spins, tol)
97 && testlib::close_to(MAG_2, tmp.M_abs / n_spins, tol)
98 && testlib::close_to(CV_2, (tmp.E2 - tmp.E * tmp.E) / (T * T)
100 && testlib::close_to(X_2, (tmp.M2 - tmp.M_abs * tmp.M_abs) / T
155 for (
size_t i=0; i < 1000; i++) {
158 std::cout <<
"not enough cycles\n";
164 std::cout <<
"Res: " << res / 1000 << std::endl;
The definition of the Ising model.
Test class for the Ising model.
int test_2x2_lattice(double tol, int max_cycles)
Test numerical data with analytical data.
void test_init_functions()
Test That initializing works as intended.
The Ising model in 2 dimensions.
int M
The current magnetic strength. unit: Unitless.
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.
void initialize_neighbors()
initialize the neighbors matrix.
void initialize_magnetization()
Initialize the magnetization.
arma::Mat< int > neighbors
matrix with the neighbors of each element .
int E
The current energy state. unit: .
int main()
The main function.
#define ASSERT(expr, msg)
A prettier assertion function.