2
3
4
5
6
7
8
9
10
11
12
13
14
15
26
27
28
29
30
31#define ASSERT(expr, msg)
32 details::m_assert(expr, #expr, __METHOD_NAME__, __FILE__, __LINE__, msg)
37
38
39
40
41
42
43
44
45
46
47
48void m_assert(
bool expr, std::string expr_str, std::string func,
49 std::string file,
int line, std::string msg);
55
56
57
58
59
60
61
62
63
64
67static bool close_to(arma::Mat<T> &a, arma::Mat<T> &b,
double tol = 1e-8)
69 if (a.n_elem != b.n_elem) {
73 for (size_t i = 0; i < a.n_elem; i++) {
74 if (!close_to(a(i), b(i))) {
82
83
84
85
86
87
88
89
90
91
94static bool close_to(T a, T b,
double tol = 1e-8)
96 return std::fabs(a - b) < tol;
100
101
102
103
104
105
106
107
108
111static bool is_equal(arma::Mat<T> &a, arma::Mat<T> &b)
113 for (size_t i = 0; i < a.n_elem; i++) {
114 if (!(a(i) == b(i))) {
122
123
124
125
126
127
130static bool assert_each(std::function<
bool(T)> expr, arma::Mat<T> &M)
132 for (size_t i = 0; i < M.n_elem; i++) {
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.
int64_t E
The current energy state. unit: .
double T
The temperature of the model.
int L
Size of the lattice.
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.
void initialize_magnetization()
Initialize the magnetization of the system.
int64_t M
The current magnetic strength. unit: Unitless.
Type to use with the IsingModel class and montecarlo module.
double M_abs
Absolute Magnetization.
data_t & operator+=(const data_t &b)
Overload of the addition equals operator.
double M2
Magnetization squared.
#define EPS_2
The analytic expected energy for a lattice.
#define MAG_2
The analytic expected magnetization for a lattice.
#define X_2
The analytic susceptibility for a lattice.
int main()
The main function.
#define CV_2
The analytic heat capacity for a lattice.
static bool close_to(arma::Mat< T > &a, arma::Mat< T > &b, double tol=1e-8)
Test if two armadillo matrices/vectors are close to each other.
void m_assert(bool expr, std::string expr_str, std::string func, std::string file, int line, std::string msg)
Test an expression, confirm that test is ok, or abort execution.
static bool is_equal(arma::Mat< T > &a, arma::Mat< T > &b)
Test if two armadillo matrices/vectors are equal.
static bool close_to(T a, T b, double tol=1e-8)
Test if two numbers are close to each other.
#define ASSERT(expr, msg)
A prettier assertion function.
static bool assert_each(std::function< bool(T)> expr, arma::Mat< T > &M)
Test that all elements fulfill the condition.
#define __METHOD_NAME__
Get the name of the current method/function without the return type.