From 5eff0b0d370e4b00c0546ef845b3dd75c4dad04b Mon Sep 17 00:00:00 2001 From: Cory Date: Tue, 5 Dec 2023 19:32:43 +0100 Subject: [PATCH] Update docs --- docs/IsingModel_8cpp.html | 2 +- docs/IsingModel_8cpp_source.html | 146 +++++++-------- docs/IsingModel_8hpp.html | 2 +- docs/IsingModel_8hpp_source.html | 124 +++---------- docs/bug.html | 40 ++--- docs/data__type_8cpp.html | 2 +- docs/data__type_8cpp_source.html | 15 +- docs/data__type_8hpp.html | 2 +- docs/data__type_8hpp_source.html | 176 +++++++------------ docs/index.html | 10 +- docs/main_8cpp.html | 2 +- docs/main_8cpp_source.html | 119 +++++-------- docs/mcmc__progression_8cpp.html | 2 +- docs/mcmc__progression_8cpp_source.html | 51 +++--- docs/monte__carlo_8cpp.html | 2 +- docs/monte__carlo_8cpp_source.html | 128 ++++++-------- docs/monte__carlo_8hpp.html | 2 +- docs/monte__carlo_8hpp_source.html | 115 +++--------- docs/pd__estimate_8cpp.html | 2 +- docs/pd__estimate_8cpp_source.html | 53 +++--- docs/phase__transition_8cpp.html | 2 +- docs/phase__transition_8cpp_source.html | 57 +++--- docs/phase__transition__mpi_8cpp.html | 2 +- docs/phase__transition__mpi_8cpp_source.html | 93 +++++----- docs/test__suite_8cpp.html | 2 +- docs/test__suite_8cpp_source.html | 105 ++++------- docs/testlib_8cpp_source.html | 21 +-- docs/testlib_8hpp.html | 2 +- docs/testlib_8hpp_source.html | 152 +++------------- docs/time_8cpp_source.html | 95 ++++------ docs/utils_8cpp_source.html | 34 ++-- docs/utils_8hpp.html | 2 +- docs/utils_8hpp_source.html | 161 +++-------------- 33 files changed, 564 insertions(+), 1159 deletions(-) diff --git a/docs/IsingModel_8cpp.html b/docs/IsingModel_8cpp.html index 3b1eba4..cc15909 100644 --- a/docs/IsingModel_8cpp.html +++ b/docs/IsingModel_8cpp.html @@ -113,7 +113,7 @@ $(document).ready(function(){initNavTree('IsingModel_8cpp.html',''); initResizab
Janita Ovidie Sandtrøen Willumsen (janitaws)
Version
0.1
-
Bug:
No known bugs
+
Bug:
No known bugs

Definition in file IsingModel.cpp.

diff --git a/docs/IsingModel_8cpp_source.html b/docs/IsingModel_8cpp_source.html index 786afe0..2680950 100644 --- a/docs/IsingModel_8cpp_source.html +++ b/docs/IsingModel_8cpp_source.html @@ -101,175 +101,163 @@ $(document).ready(function(){initNavTree('IsingModel_8cpp_source.html',''); init
IsingModel.cpp
-Go to the documentation of this file.
1/** @file IsingModel.cpp
-
2 *
-
3 * @author Cory Alexander Balaton (coryab)
-
4 * @author Janita Ovidie Sandtrøen Willumsen (janitaws)
-
5 *
-
6 * @version 0.1
-
7 *
-
8 * @brief The implementation of the Ising model
-
9 *
-
10 * @bug No known bugs
-
11 * */
-
12#include "IsingModel.hpp"
+Go to the documentation of this file.
1
+
12#include "IsingModel.hpp"
13
- +
15{
- +
16 this->initialize_engine();
17}
18
-
19IsingModel::IsingModel(int L, double T)
+
19IsingModel::IsingModel(int L, double T)
20{
-
21 this->L = L;
-
22 this->T = T;
- - - - - - +
21 this->L = L;
+
22 this->T = T;
+
23 this->initialize_engine();
+
24 this->initialize_lattice();
+ + + +
28 this->initialize_energy();
29}
30
-
31IsingModel::IsingModel(int L, double T, int val)
+
31IsingModel::IsingModel(int L, double T, int val)
32{
-
33 this->L = L;
-
34 this->T = T;
- - - - - - +
33 this->L = L;
+
34 this->T = T;
+
35 this->initialize_engine();
+
36 this->initialize_lattice(val);
+ + + +
40 this->initialize_energy();
41}
42
- +
44{
45 std::random_device rd{};
-
46 this->engine = std::mt19937{rd()};
+
46 this->engine = std::mt19937{rd()};
47}
48
- +
50{
-
51 this->lattice.set_size(this->L, this->L);
+
51 this->lattice.set_size(this->L, this->L);
52
53 std::uniform_int_distribution<> coin_flip(0, 1);
54
-
55 for (size_t i = 0; i < this->lattice.n_elem; i++)
-
56 this->lattice(i) = 2 * coin_flip(this->engine) - 1;
+
55 for (size_t i = 0; i < this->lattice.n_elem; i++)
+
56 this->lattice(i) = 2 * coin_flip(this->engine) - 1;
57}
58
- +
60{
61 // If val is neither 1 or -1, then initialize random values.
62 if (val != 1 && val != -1) {
- +
63 this->initialize_lattice();
64 return;
65 }
-
66 this->lattice.set_size(this->L, this->L);
-
67 this->lattice.fill(val);
+
66 this->lattice.set_size(this->L, this->L);
+
67 this->lattice.fill(val);
68}
69
- +
71{
-
72 this->neighbors.set_size(this->L, 2);
+
72 this->neighbors.set_size(this->L, 2);
73
74 // Having i as a signed integer is necessary in this case.
-
75 for (int i = 0; i < (int)this->L; i++) {
-
76 this->neighbors(i, UP) = INDEX(i - 1, this->L);
-
77 this->neighbors(i, DOWN) = INDEX(i + 1, this->L);
+
75 for (int i = 0; i < (int)this->L; i++) {
+
76 this->neighbors(i, UP) = INDEX(i - 1, this->L);
+
77 this->neighbors(i, DOWN) = INDEX(i + 1, this->L);
78 }
79}
80
- +
82{
83 for (int i = -8; i <= 8; i += 4) {
-
84 this->energy_diff[i+8] = std::exp(-(double)i / this->T);
+
84 this->energy_diff[i+8] = std::exp(-(double)i / this->T);
85 }
86}
87
- +
89{
-
90 this->M = 0.;
-
91 for (size_t i = 0; i < this->lattice.n_elem; i++) {
-
92 this->M += this->lattice(i);
+
90 this->M = 0.;
+
91 for (size_t i = 0; i < this->lattice.n_elem; i++) {
+
92 this->M += this->lattice(i);
93 }
94}
95
- +
97{
-
98 this->E = 0.;
+
98 this->E = 0.;
99
100 // Loop through the matrix
-
101 for (size_t j = 0; j < this->L; j++) {
-
102 for (size_t i = 0; i < this->L; i++) {
-
103 this->E -= this->lattice(i, j)
-
104 * (this->lattice(i, this->neighbors(j, RIGHT))
-
105 + this->lattice(this->neighbors(i, DOWN), j));
+
101 for (size_t j = 0; j < this->L; j++) {
+
102 for (size_t i = 0; i < this->L; i++) {
+
103 this->E -= this->lattice(i, j)
+
104 * (this->lattice(i, this->neighbors(j, RIGHT))
+
105 + this->lattice(this->neighbors(i, DOWN), j));
106 }
107 }
108}
109
- +
111{
112 int ri, rj;
113 int dE;
114
115 // Create random distribution for indeces
-
116 std::uniform_int_distribution<> random_index(0, this->L - 1);
+
116 std::uniform_int_distribution<> random_index(0, this->L - 1);
117 // Create random distribution for acceptance
118 std::uniform_real_distribution<> random_number(0., 1.);
119
120 // Loop over the number of spins
-
121 for (size_t i = 0; i < this->lattice.n_elem; i++) {
+
121 for (size_t i = 0; i < this->lattice.n_elem; i++) {
122 // Get random indeces
123 ri = random_index(engine);
124 rj = random_index(engine);
125
126 // Calculate the difference in energy
-
127 dE = 2 * this->lattice(ri, rj)
-
128 * (this->lattice(ri, this->neighbors(rj, LEFT))
-
129 + this->lattice(ri, this->neighbors(rj, RIGHT))
-
130 + this->lattice(this->neighbors(ri, UP), rj)
-
131 + this->lattice(this->neighbors(ri, DOWN), rj));
+
127 dE = 2 * this->lattice(ri, rj)
+
128 * (this->lattice(ri, this->neighbors(rj, LEFT))
+
129 + this->lattice(ri, this->neighbors(rj, RIGHT))
+
130 + this->lattice(this->neighbors(ri, UP), rj)
+
131 + this->lattice(this->neighbors(ri, DOWN), rj));
132
133 // Choose whether or not to accept the new configuration
-
134 if (random_number(engine) <= this->energy_diff[dE+8]) {
+
134 if (random_number(engine) <= this->energy_diff[dE+8]) {
135 // Update if the configuration is accepted
-
136 this->lattice(ri, rj) *= -1;
-
137 this->M += 2 * this->lattice(ri, rj);
-
138 this->E += dE;
+
136 this->lattice(ri, rj) *= -1;
+
137 this->M += 2 * this->lattice(ri, rj);
+
138 this->E += dE;
139 }
140 }
141
-
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));
+
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));
144}
+
The definition of the Ising model.
#define UP
Used for the neighbor matrix in the class.
Definition: IsingModel.hpp:26
#define INDEX(I, N)
I modulo N.
Definition: IsingModel.hpp:23
#define DOWN
Used for the neighbor matrix in the class.
Definition: IsingModel.hpp:28
#define LEFT
Used for the neighbor matrix in the class.
Definition: IsingModel.hpp:27
#define RIGHT
Used for the neighbor matrix in the class.
Definition: IsingModel.hpp:29
-
The Ising model in 2 dimensions.
Definition: IsingModel.hpp:36
std::mt19937 engine
The RNG that is used for the Metropolis algorithm.
Definition: IsingModel.hpp:78
int64_t E
The current energy state. unit: .
Definition: IsingModel.hpp:70
double T
The temperature of the model.
Definition: IsingModel.hpp:62
int L
Size of the lattice.
Definition: IsingModel.hpp:66
+
arma::Mat< int > lattice
matrix where element .
Definition: IsingModel.hpp:44
void initialize_lattice()
Initialize the lattice with a random distribution of 1s and -1s.
Definition: IsingModel.cpp:49
-
IsingModel(int L, double T, int val)
Constructor for the Ising model.
Definition: IsingModel.cpp:31
-
IsingModel(int L, double T)
Constructor for the Ising model.
Definition: IsingModel.cpp:19
data_t Metropolis()
The Metropolis algorithm.
Definition: IsingModel.cpp:110
void initialize_energy()
Initialize the energy of the system.
Definition: IsingModel.cpp:96
void initialize_neighbors()
initialize the neighbors matrix.
Definition: IsingModel.cpp:70
double energy_diff[17]
An array containing all possible energy differences.
Definition: IsingModel.hpp:58
void initialize_magnetization()
Initialize the magnetization of the system.
Definition: IsingModel.cpp:88
+
arma::Mat< int > neighbors
matrix with the neighbors of each element .
Definition: IsingModel.hpp:54
void initialize_engine()
Initialize the RNG.
Definition: IsingModel.cpp:43
-
void initialize_lattice(int val)
Initialize the lattice with a specific value.
Definition: IsingModel.cpp:59
IsingModel()
Constructor used for testing.
Definition: IsingModel.cpp:14
int64_t M
The current magnetic strength. unit: Unitless.
Definition: IsingModel.hpp:74
void initialize_energy_diff()
Initialize the energy_diff array with the correct values.
Definition: IsingModel.cpp:81
Type to use with the IsingModel class and montecarlo module.
Definition: data_type.hpp:19
-
data_t(double E, double E2, double M, double M2, double M_abs)
Constructor with parameters.
Definition: data_type.hpp:45
diff --git a/docs/IsingModel_8hpp.html b/docs/IsingModel_8hpp.html index fb00296..3961aa1 100644 --- a/docs/IsingModel_8hpp.html +++ b/docs/IsingModel_8hpp.html @@ -146,7 +146,7 @@ Macros
Janita Ovidie Sandtrøen Willumsen (janitaws)
Version
0.1
-
Bug:
No known bugs
+
Bug:
No known bugs

Definition in file IsingModel.hpp.

Macro Definition Documentation

diff --git a/docs/IsingModel_8hpp_source.html b/docs/IsingModel_8hpp_source.html index b3123e4..bca822d 100644 --- a/docs/IsingModel_8hpp_source.html +++ b/docs/IsingModel_8hpp_source.html @@ -101,145 +101,71 @@ $(document).ready(function(){initNavTree('IsingModel_8hpp_source.html',''); init
IsingModel.hpp
-Go to the documentation of this file.
1/** @file IsingModel.hpp
-
2 *
-
3 * @author Cory Alexander Balaton (coryab)
-
4 * @author Janita Ovidie Sandtrøen Willumsen (janitaws)
-
5 *
-
6 * @version 0.1
-
7 *
-
8 * @brief The definition of the Ising model.
-
9 *
-
10 * @bug No known bugs
-
11 * */
-
12#ifndef __ISING_MODEL__
-
13#define __ISING_MODEL__
+Go to the documentation of this file.
1
+
12#ifndef __ISING_MODEL__
+
13#define __ISING_MODEL__
14
-
15#include "data_type.hpp"
-
16#include "utils.hpp"
+
15#include "data_type.hpp"
+
16#include "utils.hpp"
17
-
18#include <armadillo>
-
19#include <cstdint>
-
20#include <random>
-
21#include <unordered_map>
+
18#include <armadillo>
+
19#include <cstdint>
+
20#include <random>
+
21#include <unordered_map>
22
-
23#define INDEX(I, N) (I + N) % N ///< I modulo N
+
23#define INDEX(I, N) (I + N) % N
24
25// Indeces for the neighbor matrix.
-
26#define UP 0 ///< Used for the neighbor matrix in the class
-
27#define LEFT 0 ///< Used for the neighbor matrix in the class
-
28#define DOWN 1 ///< Used for the neighbor matrix in the class
-
29#define RIGHT 1 ///< Used for the neighbor matrix in the class
+
26#define UP 0
+
27#define LEFT 0
+
28#define DOWN 1
+
29#define RIGHT 1
30
-
31/** @brief The Ising model in 2 dimensions.
-
32 *
-
33 * @details None of the methods are parallelized, as there is very little
-
34 * benefit in doing so.
-
35 * */
- +
37private:
-
38 /** @brief Give access to private members to the test class IsingModelTest.
-
39 * */
-
40 friend class IsingModelTest;
+
40 friend class IsingModelTest;
41
-
42 /** @brief \f$ L \times L \f$ matrix where element \f$ x \in {-1, 1}\f$.
-
43 * */
-
44 arma::Mat<int> lattice;
+
44 arma::Mat<int> lattice;
45
-
46 /** @brief \f$ L \times 2 \f$ matrix with the neighbors of each element
-
47 * \f$ x_i \f$.
-
48 *
-
49 * @details The reason why it's \f$ L \times 2 \f$ instead of
-
50 * \f$ L \times 2 \f$, is that we can see that we can use the same column
-
51 * for the left and upper neighbor, and we can use the same column for the
-
52 * right and lower neighbor.
-
53 * */
-
54 arma::Mat<int> neighbors;
+
54 arma::Mat<int> neighbors;
55
-
56 /** @brief An array containing all possible energy differences.
-
57 * */
58 double energy_diff[17];
59
-
60 /** @brief The temperature of the model.
-
61 * */
62 double T;
63
-
64 /** @brief Size of the lattice.
-
65 * */
66 int L;
67
-
68 /** @brief The current energy state. unit: \f$ J \f$.
-
69 * */
70 int64_t E;
71
-
72 /** @brief The current magnetic strength. unit: Unitless.
-
73 * */
74 int64_t M;
75
-
76 /** @brief The RNG that is used for the Metropolis algorithm
-
77 * */
78 std::mt19937 engine;
79
-
80 /** @brief Initialize the RNG.
-
81 * */
82 void initialize_engine();
83
-
84 /** @brief Initialize the lattice with a random distribution of 1s and
-
85 * -1s.
-
86 * */
87 void initialize_lattice();
88
-
89 /** @brief Initialize the lattice with a specific value.
-
90 * */
-
91 void initialize_lattice(int val);
+
91 void initialize_lattice(int val);
92
-
93 /** @brief initialize the neighbors matrix.
-
94 * */
96
-
97 /** @brief Initialize the energy_diff array with the correct values.
-
98 * */
100
-
101 /** @brief Initialize the magnetization of the system.
-
102 * */
104
-
105 /** @brief Initialize the energy of the system.
-
106 * */
107 void initialize_energy();
108
-
109 /** @brief Constructor used for testing.
-
110 * */
111 IsingModel();
112
113public:
-
114 /** @brief Constructor for the Ising model.
-
115 *
-
116 * @param L The size of the lattice.
-
117 * @param T The temperature for the system.
-
118 * */
-
119 IsingModel(int L, double T);
+
119 IsingModel(int L, double T);
120
-
121 /** @brief Constructor for the Ising model.
-
122 *
-
123 * @param L The size of the lattice.
-
124 * @param T The temperature for the system.
-
125 * @param val The value to set for all spins.
-
126 * */
-
127 IsingModel(int L, double T, int val);
+
127 IsingModel(int L, double T, int val);
128
-
129 /** @brief The Metropolis algorithm.
-
130 * */
132};
133
-
134#endif
-
#define UP
Used for the neighbor matrix in the class.
Definition: IsingModel.hpp:26
-
#define INDEX(I, N)
I modulo N.
Definition: IsingModel.hpp:23
-
#define DOWN
Used for the neighbor matrix in the class.
Definition: IsingModel.hpp:28
-
#define LEFT
Used for the neighbor matrix in the class.
Definition: IsingModel.hpp:27
-
#define RIGHT
Used for the neighbor matrix in the class.
Definition: IsingModel.hpp:29
+
134#endif
Test class for the Ising model.
Definition: test_suite.cpp:36
The Ising model in 2 dimensions.
Definition: IsingModel.hpp:36
std::mt19937 engine
The RNG that is used for the Metropolis algorithm.
Definition: IsingModel.hpp:78
@@ -248,8 +174,6 @@ $(document).ready(function(){initNavTree('IsingModel_8hpp_source.html',''); init
int L
Size of the lattice.
Definition: IsingModel.hpp:66
arma::Mat< int > lattice
matrix where element .
Definition: IsingModel.hpp:44
void initialize_lattice()
Initialize the lattice with a random distribution of 1s and -1s.
Definition: IsingModel.cpp:49
-
IsingModel(int L, double T, int val)
Constructor for the Ising model.
Definition: IsingModel.cpp:31
-
IsingModel(int L, double T)
Constructor for the Ising model.
Definition: IsingModel.cpp:19
data_t Metropolis()
The Metropolis algorithm.
Definition: IsingModel.cpp:110
void initialize_energy()
Initialize the energy of the system.
Definition: IsingModel.cpp:96
void initialize_neighbors()
initialize the neighbors matrix.
Definition: IsingModel.cpp:70
@@ -257,12 +181,12 @@ $(document).ready(function(){initNavTree('IsingModel_8hpp_source.html',''); init
void initialize_magnetization()
Initialize the magnetization of the system.
Definition: IsingModel.cpp:88
arma::Mat< int > neighbors
matrix with the neighbors of each element .
Definition: IsingModel.hpp:54
void initialize_engine()
Initialize the RNG.
Definition: IsingModel.cpp:43
-
void initialize_lattice(int val)
Initialize the lattice with a specific value.
Definition: IsingModel.cpp:59
IsingModel()
Constructor used for testing.
Definition: IsingModel.cpp:14
int64_t M
The current magnetic strength. unit: Unitless.
Definition: IsingModel.hpp:74
void initialize_energy_diff()
Initialize the energy_diff array with the correct values.
Definition: IsingModel.cpp:81
Type to use with the IsingModel class and montecarlo module.
Definition: data_type.hpp:19
-
data_t(double E, double E2, double M, double M2, double M_abs)
Constructor with parameters.
Definition: data_type.hpp:45
+
Header for the data_t type.
+
Function prototypes and macros that are useful.
diff --git a/docs/bug.html b/docs/bug.html index d6f2015..a847847 100644 --- a/docs/bug.html +++ b/docs/bug.html @@ -103,39 +103,39 @@ $(document).ready(function(){initNavTree('bug.html',''); initResizable(); });
File data_type.cpp
-
No known bugs
-
File data_type.hpp
-
No known bugs
-
File IsingModel.cpp
-
No known bugs
-
File IsingModel.hpp
-
No known bugs
-
File main.cpp
-
No known bugs
-
File mcmc_progression.cpp
-
No known bugs
-
File monte_carlo.cpp
-
No known bugs
-
File monte_carlo.hpp
No known bugs
-
File pd_estimate.cpp
+
File data_type.hpp
+
No known bugs
+
File IsingModel.cpp
+
No known bugs
+
File IsingModel.hpp
+
No known bugs
+
File main.cpp
+
No known bugs
+
File mcmc_progression.cpp
+
No known bugs
+
File monte_carlo.cpp
No known bugs
-
File phase_transition.cpp
+
File monte_carlo.hpp
+
No known bugs
+
File pd_estimate.cpp
No known bugs
-
File phase_transition_mpi.cpp
+
File phase_transition.cpp
No known bugs
-
File test_suite.cpp
+
File phase_transition_mpi.cpp
No known bugs
+
File test_suite.cpp
+
No known bugs
File testlib.cpp
No known bugs
File testlib.hpp
-
No known bugs
+
No known bugs
File time.cpp
No known bugs
File utils.cpp
No known bugs
File utils.hpp
-
No known bugs
+
No known bugs
diff --git a/docs/data__type_8cpp.html b/docs/data__type_8cpp.html index 7bf8d17..75cb42a 100644 --- a/docs/data__type_8cpp.html +++ b/docs/data__type_8cpp.html @@ -113,7 +113,7 @@ $(document).ready(function(){initNavTree('data__type_8cpp.html',''); initResizab
Janita Ovidie Sandtrøen Willumsen (janitaws)
Version
1.0
-
Bug:
No known bugs
+
Bug:
No known bugs

Definition in file data_type.cpp.

diff --git a/docs/data__type_8cpp_source.html b/docs/data__type_8cpp_source.html index d8eb459..087ddc0 100644 --- a/docs/data__type_8cpp_source.html +++ b/docs/data__type_8cpp_source.html @@ -101,18 +101,9 @@ $(document).ready(function(){initNavTree('data__type_8cpp_source.html',''); init
data_type.cpp
-Go to the documentation of this file.
1/** @file data_type.cpp
-
2 *
-
3 * @author Cory Alexander Balaton (coryab)
-
4 * @author Janita Ovidie Sandtrøen Willumsen (janitaws)
-
5 *
-
6 * @version 1.0
-
7 *
-
8 * @brief Implementation for the data_t type.
-
9 *
-
10 * @bug No known bugs
-
11 * */
-
12#include "data_type.hpp"
+Go to the documentation of this file.
1
+
12#include "data_type.hpp"
+
Header for the data_t type.
diff --git a/docs/data__type_8hpp.html b/docs/data__type_8hpp.html index dd44aac..0413078 100644 --- a/docs/data__type_8hpp.html +++ b/docs/data__type_8hpp.html @@ -123,7 +123,7 @@ Classes
Janita Ovidie Sandtrøen Willumsen (janitaws)
Version
1.0
-
Bug:
No known bugs
+
Bug:
No known bugs

Definition in file data_type.hpp.

diff --git a/docs/data__type_8hpp_source.html b/docs/data__type_8hpp_source.html index b028bf3..9ec77de 100644 --- a/docs/data__type_8hpp_source.html +++ b/docs/data__type_8hpp_source.html @@ -101,171 +101,115 @@ $(document).ready(function(){initNavTree('data__type_8hpp_source.html',''); init
data_type.hpp
-Go to the documentation of this file.
1/** @file data_type.hpp
-
2 *
-
3 * @author Cory Alexander Balaton (coryab)
-
4 * @author Janita Ovidie Sandtrøen Willumsen (janitaws)
-
5 *
-
6 * @version 1.0
-
7 *
-
8 * @brief Header for the data_t type.
-
9 *
-
10 * @bug No known bugs
-
11 * */
-
12#ifndef __DATA_TYPE__
-
13#define __DATA_TYPE__
+Go to the documentation of this file.
1
+
12#ifndef __DATA_TYPE__
+
13#define __DATA_TYPE__
14
-
15#include <sys/types.h>
-
16#include <type_traits>
+
15#include <sys/types.h>
+
16#include <type_traits>
17
-
18/** @brief Type to use with the IsingModel class and montecarlo module.*/
-
19class data_t {
+
19class data_t {
20public:
-
21 double E; ///< Energy
-
22 double M; ///< Magnetization
-
23 double E2; ///< Energy squared
-
24 double M2; ///< Magnetization squared
-
25 double M_abs; ///< Absolute Magnetization
+
21 double E;
+
22 double M;
+
23 double E2;
+
24 double M2;
+
25 double M_abs;
26
-
27 /** @brief constructor with no parameters.
-
28 * */
30 {
-
31 this->E = 0.;
-
32 this->E2 = 0.;
-
33 this->M = 0.;
-
34 this->M2 = 0.;
-
35 this->M_abs = 0.;
+
31 this->E = 0.;
+
32 this->E2 = 0.;
+
33 this->M = 0.;
+
34 this->M2 = 0.;
+
35 this->M_abs = 0.;
36 }
37
-
38 /** @brief Constructor with parameters.
-
39 *
-
40 * @param E Initial energy
-
41 * @param E2 Initial energy squared
-
42 * @param M Initial magnetization
-
43 * @param M2 Initial magnetization squared
-
44 * @param M_abs Initial absolute magnetization*/
-
45 data_t(double E, double E2, double M, double M2, double M_abs)
+
45 data_t(double E, double E2, double M, double M2, double M_abs)
46 {
-
47 this->E = E;
-
48 this->E2 = E2;
-
49 this->M = M;
-
50 this->M2 = M2;
-
51 this->M_abs = M_abs;
+
47 this->E = E;
+
48 this->E2 = E2;
+
49 this->M = M;
+
50 this->M2 = M2;
+
51 this->M_abs = M_abs;
52 }
53
-
54 /** @brief Overload of the division operator.
-
55 *
-
56 * @param num The number to divide each field by.
-
57 *
-
58 * @return data_t
-
59 * */
-
60 template <class T> data_t operator/(T num)
+
60 template <class T> data_t operator/(T num)
61 {
62 data_t res;
-
63 res.E = this->E / (double)num;
-
64 res.E2 = this->E2 / (double)num;
-
65 res.M = this->M / (double)num;
-
66 res.M2 = this->M2 / (double)num;
-
67 res.M_abs = this->M_abs / (double)num;
+
63 res.E = this->E / (double)num;
+
64 res.E2 = this->E2 / (double)num;
+
65 res.M = this->M / (double)num;
+
66 res.M2 = this->M2 / (double)num;
+
67 res.M_abs = this->M_abs / (double)num;
68
69 return res;
70 }
71
72
-
73 /** @brief Overload of the division equals operator.
-
74 *
-
75 * @param num The number to divide each field by.
-
76 *
-
77 * @return data_t
-
78 * */
-
79 template <class T> data_t &operator/=(T num)
+
79 template <class T> data_t &operator/=(T num)
80 {
-
81 this->E /= (double)num;
-
82 this->E2 /= (double)num;
-
83 this->M /= (double)num;
-
84 this->M2 /= (double)num;
-
85 this->M_abs /= (double)num;
+
81 this->E /= (double)num;
+
82 this->E2 /= (double)num;
+
83 this->M /= (double)num;
+
84 this->M2 /= (double)num;
+
85 this->M_abs /= (double)num;
86
87 return *this;
88 }
89
-
90 /** @brief Overload of the multiply operator.
-
91 *
-
92 * @param num The number to multiply each field by.
-
93 *
-
94 * @return data_t
-
95 * */
-
96 template <class T> data_t operator*(T num)
+
96 template <class T> data_t operator*(T num)
97 {
98 data_t res;
-
99 res.E = this->E * (double)num;
-
100 res.E2 = this->E2 * (double)num;
-
101 res.M = this->M * (double)num;
-
102 res.M2 = this->M2 * (double)num;
-
103 res.M_abs = this->M_abs * (double)num;
+
99 res.E = this->E * (double)num;
+
100 res.E2 = this->E2 * (double)num;
+
101 res.M = this->M * (double)num;
+
102 res.M2 = this->M2 * (double)num;
+
103 res.M_abs = this->M_abs * (double)num;
104
105 return res;
106 }
107
-
108 /** @brief Overload of the multiply equals operator.
-
109 *
-
110 * @param num The number to multiply each field by.
-
111 *
-
112 * @return data_t
-
113 * */
-
114 template <class T> data_t &operator*=(T num)
+
114 template <class T> data_t &operator*=(T num)
115 {
-
116 this->E *= (double)num;
-
117 this->E2 *= (double)num;
-
118 this->M *= (double)num;
-
119 this->M2 *= (double)num;
-
120 this->M_abs *= (double)num;
+
116 this->E *= (double)num;
+
117 this->E2 *= (double)num;
+
118 this->M *= (double)num;
+
119 this->M2 *= (double)num;
+
120 this->M_abs *= (double)num;
121
122 return *this;
123 }
124
125
-
126 /** @brief Overload of the addition operator.
-
127 *
-
128 * @param b The data_t field to add.
-
129 *
-
130 * @return data_t
-
131 * */
- +
133 {
134 data_t res;
-
135 res.E = this->E + b.E;
-
136 res.E2 = this->E2 + b.E2;
-
137 res.M = this->M + b.M;
-
138 res.M2 = this->M2 + b.M2;
-
139 res.M_abs = this->M_abs + b.M_abs;
+
135 res.E = this->E + b.E;
+
136 res.E2 = this->E2 + b.E2;
+
137 res.M = this->M + b.M;
+
138 res.M2 = this->M2 + b.M2;
+
139 res.M_abs = this->M_abs + b.M_abs;
140
141 return res;
142 }
143
-
144 /** @brief Overload of the addition equals operator.
-
145 *
-
146 * @param b The data_t field to add.
-
147 *
-
148 * @return data_t
-
149 * */
-
150 data_t &operator+=(const data_t &b)
+
151 {
-
152 this->E += b.E;
-
153 this->E2 += b.E2;
-
154 this->M += b.M;
-
155 this->M2 += b.M2;
-
156 this->M_abs += b.M_abs;
+
152 this->E += b.E;
+
153 this->E2 += b.E2;
+
154 this->M += b.M;
+
155 this->M2 += b.M2;
+
156 this->M_abs += b.M_abs;
157
158 return *this;
159 }
160};
161
162// Declare a custom reduction for the data_t type.
-
163#pragma omp declare reduction(+ : data_t : omp_out += omp_in)
+
163#pragma omp declare reduction(+ : data_t : omp_out += omp_in)
164
-
165#endif
+
165#endif
Type to use with the IsingModel class and montecarlo module.
Definition: data_type.hpp:19
data_t operator+(const data_t &b)
Overload of the addition operator.
Definition: data_type.hpp:132
data_t(double E, double E2, double M, double M2, double M_abs)
Constructor with parameters.
Definition: data_type.hpp:45
diff --git a/docs/index.html b/docs/index.html index 0685e27..906cf19 100644 --- a/docs/index.html +++ b/docs/index.html @@ -152,17 +152,17 @@ Compiling Normal binaries

Compiling regular binaries is as easy as running this command:

make
-

The binaries will then be inside the **./bin** directory.

+

The binaries will then be inside the bin directory.

Profiling binaries

If you want to profile the programs (specifically the MPI program), then run this command

make profile
-

The binaries will then be inside the **./prof** directory.

+

The binaries will then be inside the prof directory.

Debugging binaries

If you want to debug the code, then use this command:

make debug
-

The binaries will then be inside the **./debug** directory.

+

The binaries will then be inside the debug directory.

Running programs

@@ -186,7 +186,7 @@ Running scripts

python3 python_scripts/<script-name>

Batch system

-

For the phase_transition_mpi program, there are scripts in the **./slurm_scripts** directory that come along with it. This is to be able to run it on a batch system using Slurm if you have access to one. The only program that should be executed by the user is the **./slurm_scripts/execute.script** script. You can see how to use this script by doing:

+

For the phase_transition_mpi program, there are scripts in the slurm_scripts directory that come along with it. This is to be able to run it on a batch system using Slurm if you have access to one. The only program that should be executed by the user is the slurm_scripts/execute.script script. You can see how to use this script by doing:

./slurm_scripts/execute.script --help

This is the recommended way of using the program. Here is a table using different parameters on the Fox cluster:

@@ -201,7 +201,7 @@ Batch system

If you happen to have such a system available to you, then you should clone this repo on that system, then compile the MPI program like this:

make bin/phase_transition_mpi
-

After compiling, you can schedule it by using the **./slurm_scripts/execute.script**:

+

After compiling, you can schedule it by using the slurm_scripts/execute.script:

./slurm_scripts/execute.script <parameters>

Performance

diff --git a/docs/main_8cpp.html b/docs/main_8cpp.html index 6ac48da..a80a908 100644 --- a/docs/main_8cpp.html +++ b/docs/main_8cpp.html @@ -143,7 +143,7 @@ Functions
Janita Ovidie Sandtrøen Willumsen (janitaws)
Version
0.1
-
Bug:
No known bugs
+
Bug:
No known bugs

Definition in file main.cpp.

Function Documentation

diff --git a/docs/main_8cpp_source.html b/docs/main_8cpp_source.html index 5ee72db..4a3e56e 100644 --- a/docs/main_8cpp_source.html +++ b/docs/main_8cpp_source.html @@ -101,26 +101,13 @@ $(document).ready(function(){initNavTree('main_8cpp_source.html',''); initResiza
main.cpp
-Go to the documentation of this file.
1/** @file main.cpp
-
2 *
-
3 * @author Cory Alexander Balaton (coryab)
-
4 * @author Janita Ovidie Sandtrøen Willumsen (janitaws)
-
5 *
-
6 * @version 0.1
-
7 *
-
8 * @brief The main program
-
9 *
-
10 * @bug No known bugs
-
11 * */
-
12#include "data_type.hpp"
-
13#include "monte_carlo.hpp"
-
14#include "utils.hpp"
+Go to the documentation of this file.
1
+
12#include "data_type.hpp"
+
13#include "monte_carlo.hpp"
+
14#include "utils.hpp"
15
-
16#include <getopt.h>
+
16#include <getopt.h>
17
-
18/** @brief Create the data for the burn-in time for temperatures 1.0 and 2.4
-
19 * for both unordered and ordered initial states.
-
20 * */
22{
23 // Test burn-in time
@@ -134,32 +121,25 @@ $(document).ready(function(){initNavTree('main_8cpp_source.html',''); initResiza
31 "./data/hp/burn_in_time/ordered_2_4.txt");
32}
33
-
34/** @brief Create the data used to estimate the probability distribution
-
35 * for tempratures 1.0 and 2.4.
-
36 * */
38{
39 // Estimate pd
-
40 montecarlo::pd_estimate(1.0, 20, 1000000,
+
40 montecarlo::pd_estimate(1.0, 20, 1000000,
41 "./data/hp/pd_estimate/estimate_1_0.txt");
-
42 montecarlo::pd_estimate(2.4, 20, 1000000,
+
42 montecarlo::pd_estimate(2.4, 20, 1000000,
43 "./data/hp/pd_estimate/estimate_2_4.txt");
44}
45
-
46/** @brief Create data using the same parameters except one uses burn-in time,
-
47 * while the other doesn't.
-
48 * */
50{
-
51 montecarlo::phase_transition(
-
52 100, 2.1, 2.4, 40, 1e5, montecarlo::mcmc_serial,
+
51 montecarlo::phase_transition(
+
52 100, 2.1, 2.4, 40, 1e5, montecarlo::mcmc_serial,
53 "./data/hp/test_burn_in_time/burn_in.txt", 5000);
-
54 montecarlo::phase_transition(
-
55 100, 2.1, 2.4, 40, 1e5, montecarlo::mcmc_serial,
+
54 montecarlo::phase_transition(
+
55 100, 2.1, 2.4, 40, 1e5, montecarlo::mcmc_serial,
56 "./data/hp/test_burn_in_time/no_burn_in.txt", 0);
57}
58
-
59/** @brief Test how much Openmp speeds up.*/
61{
62 // Test the openmp speedup
@@ -167,49 +147,46 @@ $(document).ready(function(){initNavTree('main_8cpp_source.html',''); initResiza
64 double t0, t1, t2;
65 int tries = 5;
66 t0 = omp_get_wtime();
-
67 for (size_t i = 0; i < tries; i++)
-
68 montecarlo::mcmc_serial(20, 1.0, 10000);
+
67 for (size_t i = 0; i < tries; i++)
+
68 montecarlo::mcmc_serial(20, 1.0, 10000);
69 t1 = omp_get_wtime();
-
70 for (size_t i = 0; i < tries; i++)
-
71 montecarlo::mcmc_parallel(20, 1.0, 10000);
+
70 for (size_t i = 0; i < tries; i++)
+
71 montecarlo::mcmc_parallel(20, 1.0, 10000);
72 t2 = omp_get_wtime();
73
74 std::cout << "Time serial : " << (t1 - t0) / tries << " seconds"
-
75 << '\n';
+
75 << '\n';
76 std::cout << "Time parallel : " << (t2 - t1) / tries << " seconds"
-
77 << '\n';
-
78 std::cout << "Speedup parallel: " << (t1 - t0) / (t2 - t1) << '\n';
+
77 << '\n';
+
78 std::cout << "Speedup parallel: " << (t1 - t0) / (t2 - t1) << '\n';
79}
80
-
81/** @brief Create data for studying phase transition.
-
82 * */
84{
85 double t0, t1;
86
87 t0 = omp_get_wtime();
88 // Phase transition
-
89 montecarlo::phase_transition(20, 2.1, 2.4, 40, 1e4,
-
90 montecarlo::mcmc_parallel,
+
89 montecarlo::phase_transition(20, 2.1, 2.4, 40, 1e4,
+
90 montecarlo::mcmc_parallel,
91 "./data/hp/phase_transition/size_20.txt");
-
92 montecarlo::phase_transition(40, 2.1, 2.4, 40, 1e4,
-
93 montecarlo::mcmc_parallel,
+
92 montecarlo::phase_transition(40, 2.1, 2.4, 40, 1e4,
+
93 montecarlo::mcmc_parallel,
94 "./data/hp/phase_transition/size_40.txt");
-
95 montecarlo::phase_transition(60, 2.1, 2.4, 40, 1e4,
-
96 montecarlo::mcmc_parallel,
+
95 montecarlo::phase_transition(60, 2.1, 2.4, 40, 1e4,
+
96 montecarlo::mcmc_parallel,
97 "./data/hp/phase_transition/size_60.txt");
-
98 montecarlo::phase_transition(80, 2.1, 2.4, 40, 1e4,
-
99 montecarlo::mcmc_parallel,
+
98 montecarlo::phase_transition(80, 2.1, 2.4, 40, 1e4,
+
99 montecarlo::mcmc_parallel,
100 "./data/hp/phase_transition/size_80.txt");
-
101 montecarlo::phase_transition(100, 2.1, 2.4, 40, 1e4,
-
102 montecarlo::mcmc_parallel,
+
101 montecarlo::phase_transition(100, 2.1, 2.4, 40, 1e4,
+
102 montecarlo::mcmc_parallel,
103 "./data/hp/phase_transition/size_100.txt");
104 t1 = omp_get_wtime();
105
106 std::cout << "Time: " << t1 - t0 << std::endl;
107}
108
-
109/** @brief A function that displays how to use the program and quits.*/
110void usage(std::string filename)
111{
112 std::cout << "Usage: " << filename << " OPTION ...\n"
@@ -224,10 +201,9 @@ $(document).ready(function(){initNavTree('main_8cpp_source.html',''); initResiza
121 exit(-1);
122}
123
-
124/** @brief The main function.*/
-
125int main(int argc, char **argv)
+
125int main(int argc, char **argv)
126{
-
127 static struct option long_options[] = {
+
127 static struct option long_options[] = {
128 {"all", no_argument, 0, 0},
129 {"create-burn-in-data", no_argument, 0, 0},
130 {"create-pd-estimate-data", no_argument, 0, 0},
@@ -244,52 +220,51 @@ $(document).ready(function(){initNavTree('main_8cpp_source.html',''); initResiza
141
142 if (c == -1)
143 break;
-
144 else if (c == 'h')
-
145 usage(argv[0]);
+
144 else if (c == 'h')
+
145 usage(argv[0]);
146
147 switch (option_index) {
148 case 0:
- - - - - + + + + +
154 break;
155 case 1:
- +
157 break;
158 case 2:
- +
160 break;
161 case 3:
- +
163 break;
164 case 4:
- +
166 break;
167 case 5:
- +
169 break;
170 case 6: // Not a mistake. This just goes to the default.
171 default:
-
172 usage(argv[0]);
+
172 usage(argv[0]);
173 }
174 }
175
176 return 0;
177}
Type to use with the IsingModel class and montecarlo module.
Definition: data_type.hpp:19
+
Header for the data_t type.
void test_parallel_speedup()
Test how much Openmp speeds up.
Definition: main.cpp:60
-
int main(int argc, char **argv)
The main function.
Definition: main.cpp:125
void create_pd_estimate_data()
Create the data used to estimate the probability distribution for tempratures 1.0 and 2....
Definition: main.cpp:37
void create_burn_in_time_data()
Create the data for the burn-in time for temperatures 1.0 and 2.4 for both unordered and ordered init...
Definition: main.cpp:21
void test_burn_in_time()
Create data using the same parameters except one uses burn-in time, while the other doesn't.
Definition: main.cpp:49
void create_phase_transition_data()
Create data for studying phase transition.
Definition: main.cpp:83
void usage(std::string filename)
A function that displays how to use the program and quits.
Definition: main.cpp:110
-
void phase_transition(int L, double start_T, double end_T, int points_T, int cycles, std::function< data_t(int, double, int, int)> monte_carlo, std::string outfile, int burn_in_time=BURN_IN_TIME)
Perform the MCMC algorithm using a range of temperatures.
-
data_t mcmc_parallel(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles in parallel.
-
data_t mcmc_serial(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles.
-
void pd_estimate(double T, int L, int cycles, const std::string filename, int burn_in_time=BURN_IN_TIME)
Estimate the probability distribution for the energy.
Definition: monte_carlo.cpp:77
+
Functions for Monte Carlo simulations.
+
int main()
The main function.
Definition: test_suite.cpp:110
+
Function prototypes and macros that are useful.
diff --git a/docs/mcmc__progression_8cpp.html b/docs/mcmc__progression_8cpp.html index af5487d..c856ba5 100644 --- a/docs/mcmc__progression_8cpp.html +++ b/docs/mcmc__progression_8cpp.html @@ -130,7 +130,7 @@ Functions
Janita Ovidie Sandtrøen Willumsen (janitaws)
Version
1.0
-
Bug:
No known bugs
+
Bug:
No known bugs

Definition in file mcmc_progression.cpp.

Function Documentation

diff --git a/docs/mcmc__progression_8cpp_source.html b/docs/mcmc__progression_8cpp_source.html index 1c590ff..705e4a1 100644 --- a/docs/mcmc__progression_8cpp_source.html +++ b/docs/mcmc__progression_8cpp_source.html @@ -101,28 +101,16 @@ $(document).ready(function(){initNavTree('mcmc__progression_8cpp_source.html',''
mcmc_progression.cpp
-Go to the documentation of this file.
1/** @file mcmc_progression.cpp
-
2 *
-
3 * @author Cory Alexander Balaton (coryab)
-
4 * @author Janita Ovidie Sandtrøen Willumsen (janitaws)
-
5 *
-
6 * @version 1.0
-
7 *
-
8 * @brief Execute the mcmc algorithm and write data to file after each
-
9 * Monte Carlo cycle.
-
10 *
-
11 * @bug No known bugs
-
12 * */
-
13#include "data_type.hpp"
-
14#include "monte_carlo.hpp"
-
15#include "utils.hpp"
+Go to the documentation of this file.
1
+
13#include "data_type.hpp"
+
14#include "monte_carlo.hpp"
+
15#include "utils.hpp"
16
-
17#include <getopt.h>
-
18#include <omp.h>
-
19#include <string>
+
17#include <getopt.h>
+
18#include <omp.h>
+
19#include <string>
20
-
21/** @brief A function that displays how to use the program and quits.*/
-
22void usage(std::string filename)
+
22void usage(std::string filename)
23{
24 std::cout << "Usage: " << filename
25 << " <temperature> <lattice size> "
@@ -131,11 +119,10 @@ $(document).ready(function(){initNavTree('mcmc__progression_8cpp_source.html',''
28 exit(-1);
29}
30
-
31/** @brief The main function.*/
-
32int main(int argc, char **argv)
+
32int main(int argc, char **argv)
33{
34 // Command options
-
35 struct option long_options[] = {
+
35 struct option long_options[] = {
36 {"help", 0, 0, 0}, {NULL, 0, NULL, 0}};
37
38 int option_index = -1;
@@ -152,17 +139,17 @@ $(document).ready(function(){initNavTree('mcmc__progression_8cpp_source.html',''
49 switch (option_index) {
50 case 0: // Not a mistake. This just goes to the default.
51 default:
-
52 usage(argv[0]);
+
52 usage(argv[0]);
53 }
54 break;
-
55 case 'h':
+
55 case 'h':
56 default:
-
57 usage(argv[0]);
+
57 usage(argv[0]);
58 }
59 }
60 // Check that the number of arguments is at least 6.
61 if (argc < 6) {
-
62 usage(argv[0]);
+
62 usage(argv[0]);
63 }
64
65 bool ordered = false;
@@ -182,7 +169,7 @@ $(document).ready(function(){initNavTree('mcmc__progression_8cpp_source.html',''
79
80 if (ordered) {
81 DEBUG("Hello");
-
82 montecarlo::progression(temp, L, cycles, 1, outfile, burn_in_time);
+
82 montecarlo::progression(temp, L, cycles, 1, outfile, burn_in_time);
83 }
84 else {
85 montecarlo::progression(temp, L, cycles, outfile, burn_in_time);
@@ -192,9 +179,11 @@ $(document).ready(function(){initNavTree('mcmc__progression_8cpp_source.html',''
89
90 std::cout << "Time: " << t1 - t0 << " seconds\n";
91}
-
int main(int argc, char **argv)
The main function.
Definition: main.cpp:125
-
void usage(std::string filename)
A function that displays how to use the program and quits.
Definition: main.cpp:110
-
void progression(double T, int L, int cycles, int value, const std::string filename, int burn_in_time=BURN_IN_TIME)
Write the expected values for each Monte Carlo cycles to file.
Definition: monte_carlo.cpp:46
+
Header for the data_t type.
+
void usage(std::string filename)
A function that displays how to use the program and quits.
+
Functions for Monte Carlo simulations.
+
int main()
The main function.
Definition: test_suite.cpp:110
+
Function prototypes and macros that are useful.
#define DEBUG(msg)
Writes a debug message.
Definition: utils.hpp:39
diff --git a/docs/monte__carlo_8cpp.html b/docs/monte__carlo_8cpp.html index 730314e..b5fd7a7 100644 --- a/docs/monte__carlo_8cpp.html +++ b/docs/monte__carlo_8cpp.html @@ -137,7 +137,7 @@ Functions
Janita Ovidie Sandtrøen Willumsen (janitaws)
Version
1.0
-
Bug:
No known bugs
+
Bug:
No known bugs

Definition in file monte_carlo.cpp.

Function Documentation

diff --git a/docs/monte__carlo_8cpp_source.html b/docs/monte__carlo_8cpp_source.html index d035ff8..86b876e 100644 --- a/docs/monte__carlo_8cpp_source.html +++ b/docs/monte__carlo_8cpp_source.html @@ -101,20 +101,10 @@ $(document).ready(function(){initNavTree('monte__carlo_8cpp_source.html',''); in
monte_carlo.cpp
-Go to the documentation of this file.
1/** @file monte_carlo.cpp
-
2 *
-
3 * @author Cory Alexander Balaton (coryab)
-
4 * @author Janita Ovidie Sandtrøen Willumsen (janitaws)
-
5 *
-
6 * @version 1.0
-
7 *
-
8 * @brief Implementation of the monte carlo functions
-
9 *
-
10 * @bug No known bugs
-
11 * */
-
12#include "monte_carlo.hpp"
+Go to the documentation of this file.
1
+
12#include "monte_carlo.hpp"
13
-
14namespace montecarlo {
+
14namespace montecarlo {
15void progression(double T, int L, int cycles, const std::string filename,
16 int burn_in_time)
17{
@@ -123,30 +113,30 @@ $(document).ready(function(){initNavTree('monte__carlo_8cpp_source.html',''); in
20 int n_spins = L * L;
21
22 // File stuff
-
23 std::string directory = utils::dirname(filename);
+
23 std::string directory = utils::dirname(filename);
24 std::ofstream ofile;
25
-
26 IsingModel ising(L, T);
+
26 IsingModel ising(L, T);
27
28 // Create path and open file
-
29 utils::mkpath(directory);
+
29 utils::mkpath(directory);
30 ofile.open(filename);
31
-
32 for (size_t i = 0; i < burn_in_time; i++) {
-
33 ising.Metropolis();
+
32 for (size_t i = 0; i < burn_in_time; i++) {
+
33 ising.Metropolis();
34 }
35
36 // Loop through cycles
-
37 for (size_t i = 1; i <= cycles; i++) {
-
38 data += ising.Metropolis();
+
37 for (size_t i = 1; i <= cycles; i++) {
+
38 data += ising.Metropolis();
39 tmp = data / (i * n_spins);
-
40 ofile << i << ',' << tmp.E << ',' << tmp.E2 << ',' << tmp.M << ','
-
41 << tmp.M2 << ',' << tmp.M_abs << '\n';
+
40 ofile << i << ',' << tmp.E << ',' << tmp.E2 << ',' << tmp.M << ','
+
41 << tmp.M2 << ',' << tmp.M_abs << '\n';
42 }
43 ofile.close();
44}
45
-
46void progression(double T, int L, int cycles, int value,
+
46void progression(double T, int L, int cycles, int value,
47 const std::string filename, int burn_in_time)
48{
49 // Set some variables
@@ -154,25 +144,25 @@ $(document).ready(function(){initNavTree('monte__carlo_8cpp_source.html',''); in
51 int n_spins = L * L;
52
53 // File stuff
-
54 std::string directory = utils::dirname(filename);
+
54 std::string directory = utils::dirname(filename);
55 std::ofstream ofile;
56
-
57 IsingModel ising(L, T, value);
+
57 IsingModel ising(L, T, value);
58
-
59 for (size_t i = 0; i < burn_in_time; i++) {
-
60 ising.Metropolis();
+
59 for (size_t i = 0; i < burn_in_time; i++) {
+
60 ising.Metropolis();
61 }
62
63 // Create path and open file
-
64 utils::mkpath(directory);
+
64 utils::mkpath(directory);
65 ofile.open(filename);
66
67 // Loop through cycles
-
68 for (size_t i = 1; i <= cycles; i++) {
-
69 data += ising.Metropolis();
+
68 for (size_t i = 1; i <= cycles; i++) {
+
69 data += ising.Metropolis();
70 tmp = data / (i * n_spins);
-
71 ofile << i << ',' << tmp.E << ',' << tmp.E2 << ',' << tmp.M << ','
-
72 << tmp.M2 << ',' << tmp.M_abs << '\n';
+
71 ofile << i << ',' << tmp.E << ',' << tmp.E2 << ',' << tmp.M << ','
+
72 << tmp.M2 << ',' << tmp.M_abs << '\n';
73 }
74 ofile.close();
75}
@@ -185,24 +175,24 @@ $(document).ready(function(){initNavTree('monte__carlo_8cpp_source.html',''); in
82 int n_spins = L * L;
83
84 // File stuff
-
85 std::string directory = utils::dirname(filename);
+
85 std::string directory = utils::dirname(filename);
86 std::ofstream ofile;
87
-
88 IsingModel ising(L, T);
+
88 IsingModel ising(L, T);
89
-
90 for (size_t i = 0; i < burn_in_time; i++) {
-
91 ising.Metropolis();
+
90 for (size_t i = 0; i < burn_in_time; i++) {
+
91 ising.Metropolis();
92 }
93
94 // Create path and open file
-
95 utils::mkpath(directory);
+
95 utils::mkpath(directory);
96 ofile.open(filename);
97
98 // Loop through cycles
-
99 for (size_t i = 1; i <= cycles; i++) {
-
100 data = ising.Metropolis() / n_spins;
-
101 ofile << data.E << ',' << data.E2 << ',' << data.M << ',' << data.M2
-
102 << ',' << data.M_abs << '\n';
+
99 for (size_t i = 1; i <= cycles; i++) {
+
100 data = ising.Metropolis() / n_spins;
+
101 ofile << data.E << ',' << data.E2 << ',' << data.M << ',' << data.M2
+
102 << ',' << data.M_abs << '\n';
103 }
104 ofile.close();
105}
@@ -211,18 +201,18 @@ $(document).ready(function(){initNavTree('monte__carlo_8cpp_source.html',''); in
108data_t mcmc_serial(int L, double T, int cycles, int burn_in_time)
109{
110 data_t data;
-
111 IsingModel model(L, T);
+
111 IsingModel model(L, T);
112
-
113 for (size_t i = 0; i < burn_in_time; i++) {
-
114 model.Metropolis();
+
113 for (size_t i = 0; i < burn_in_time; i++) {
+
114 model.Metropolis();
115 }
116
117 double E, M;
-
118 for (size_t i = 0; i < (uint)cycles; i++) {
-
119 data += model.Metropolis();
+
118 for (size_t i = 0; i < (uint)cycles; i++) {
+
119 data += model.Metropolis();
120 }
121
-
122 double norm = 1. / (double)cycles;
+
122 double norm = 1. / (double)cycles;
123
124 return data * norm;
125}
@@ -230,27 +220,27 @@ $(document).ready(function(){initNavTree('monte__carlo_8cpp_source.html',''); in
127data_t mcmc_parallel(int L, double T, int cycles, int burn_in_time)
128{
129 data_t data;
-
130#pragma omp parallel
+
130#pragma omp parallel
131 {
132 // Each thread creates an instance of IsingModel.
-
133 IsingModel model(L, T);
+
133 IsingModel model(L, T);
134
135 // Each thread runs the Metropolis algorithm before starting to collect
136 // samples
-
137 for (size_t i = 0; i < burn_in_time; i++) {
-
138 model.Metropolis();
+
137 for (size_t i = 0; i < burn_in_time; i++) {
+
138 model.Metropolis();
139 }
140
141 // Now each thread work on one loop together, but using their own
142 // instances of things, but the total of cycles add up.
143 // static ensure that each thread gets the same amount of iterations
-
144#pragma omp for schedule(static) reduction(+ : data)
-
145 for (size_t i = 0; i < (uint)cycles; i++) {
-
146 data += model.Metropolis();
+
144#pragma omp for schedule(static) reduction(+ : data)
+
145 for (size_t i = 0; i < (uint)cycles; i++) {
+
146 data += model.Metropolis();
147 }
148 }
149
-
150 double norm = 1. / (double)cycles;
+
150 double norm = 1. / (double)cycles;
151
152 return data * norm;
153}
@@ -265,47 +255,41 @@ $(document).ready(function(){initNavTree('monte__carlo_8cpp_source.html',''); in
162
163 data_t data;
164
-
165 utils::mkpath(utils::dirname(outfile));
+
165 utils::mkpath(utils::dirname(outfile));
166 ofile.open(outfile);
167
168 double temp, CV, X, E_var, M_var;
169
-
170 using utils::scientific_format;
-
171 for (size_t i = 0; i < points; i++) {
+
170 using utils::scientific_format;
+
171 for (size_t i = 0; i < points; i++) {
172 temp = start + dt * i;
173 data = monte_carlo(L, temp, cycles, burn_in_time);
-
174 E_var = (data.E2 - data.E * data.E) / (double)N;
-
175 M_var = (data.M2 - data.M_abs * data.M_abs) / (double)N;
+
174 E_var = (data.E2 - data.E * data.E) / (double)N;
+
175 M_var = (data.M2 - data.M_abs * data.M_abs) / (double)N;
176
-
177 ofile << scientific_format(temp) << ','
-
178 << scientific_format(data.E / (double)N) << ','
-
179 << scientific_format(data.M_abs / N) << ','
-
180 << scientific_format(E_var / (temp * temp)) << ','
-
181 << scientific_format(M_var / temp) << '\n';
+
177 ofile << scientific_format(temp) << ','
+
178 << scientific_format(data.E / (double)N) << ','
+
179 << scientific_format(data.M_abs / N) << ','
+
180 << scientific_format(E_var / (temp * temp)) << ','
+
181 << scientific_format(M_var / temp) << '\n';
182 }
183 ofile.close();
184}
185} // namespace montecarlo
The Ising model in 2 dimensions.
Definition: IsingModel.hpp:36
-
IsingModel(int L, double T, int val)
Constructor for the Ising model.
Definition: IsingModel.cpp:31
-
IsingModel(int L, double T)
Constructor for the Ising model.
Definition: IsingModel.cpp:19
data_t Metropolis()
The Metropolis algorithm.
Definition: IsingModel.cpp:110
Type to use with the IsingModel class and montecarlo module.
Definition: data_type.hpp:19
double M_abs
Absolute Magnetization.
Definition: data_type.hpp:25
double E
Energy.
Definition: data_type.hpp:21
-
data_t & operator+=(const data_t &b)
Overload of the addition equals operator.
Definition: data_type.hpp:150
double M2
Magnetization squared.
Definition: data_type.hpp:24
double E2
Energy squared.
Definition: data_type.hpp:23
double M
Magnetization.
Definition: data_type.hpp:22
-
void progression(double T, int L, int cycles, int value, const std::string filename, int burn_in_time=BURN_IN_TIME)
Write the expected values for each Monte Carlo cycles to file.
Definition: monte_carlo.cpp:46
+
Functions for Monte Carlo simulations.
void phase_transition(int L, double start_T, double end_T, int points_T, int cycles, std::function< data_t(int, double, int, int)> monte_carlo, std::string outfile, int burn_in_time=BURN_IN_TIME)
Perform the MCMC algorithm using a range of temperatures.
void progression(double T, int L, int cycles, const std::string filename, int burn_in_time=BURN_IN_TIME)
Write the expected values for each Monte Carlo cycles to file.
Definition: monte_carlo.cpp:15
data_t mcmc_parallel(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles in parallel.
data_t mcmc_serial(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles.
void pd_estimate(double T, int L, int cycles, const std::string filename, int burn_in_time=BURN_IN_TIME)
Estimate the probability distribution for the energy.
Definition: monte_carlo.cpp:77
-
bool mkpath(std::string path, int mode=0777)
Make path given.
Definition: utils.cpp:32
-
std::string scientific_format(double d, int width=20, int prec=10)
Turns a double into a string written in scientific format.
Definition: utils.cpp:16
-
std::string dirname(const std::string &path)
Get the directory name of the path.
Definition: utils.cpp:58
diff --git a/docs/monte__carlo_8hpp.html b/docs/monte__carlo_8hpp.html index 35dc9f4..5061b41 100644 --- a/docs/monte__carlo_8hpp.html +++ b/docs/monte__carlo_8hpp.html @@ -148,7 +148,7 @@ Functions
Janita Ovidie Sandtrøen Willumsen (janitaws)
Version
1.0
-
Bug:
No known bugs
+
Bug:
No known bugs

Definition in file monte_carlo.hpp.

Macro Definition Documentation

diff --git a/docs/monte__carlo_8hpp_source.html b/docs/monte__carlo_8hpp_source.html index 2f04bf6..cfb6f01 100644 --- a/docs/monte__carlo_8hpp_source.html +++ b/docs/monte__carlo_8hpp_source.html @@ -101,124 +101,53 @@ $(document).ready(function(){initNavTree('monte__carlo_8hpp_source.html',''); in
monte_carlo.hpp
-Go to the documentation of this file.
1/** @file monte_carlo.hpp
-
2 *
-
3 * @author Cory Alexander Balaton (coryab)
-
4 * @author Janita Ovidie Sandtrøen Willumsen (janitaws)
-
5 *
-
6 * @version 1.0
-
7 *
-
8 * @brief Functions for Monte Carlo simulations.
-
9 *
-
10 * @bug No known bugs
-
11 * */
-
12#ifndef __MONTE_CARLO__
-
13#define __MONTE_CARLO__
+Go to the documentation of this file.
1
+
12#ifndef __MONTE_CARLO__
+
13#define __MONTE_CARLO__
14
-
15#include "IsingModel.hpp"
-
16#include "data_type.hpp"
-
17#include "utils.hpp"
+
15#include "IsingModel.hpp"
+
16#include "data_type.hpp"
+
17#include "utils.hpp"
18
-
19#include <functional>
-
20#include <omp.h>
-
21#include <string>
+
19#include <functional>
+
20#include <omp.h>
+
21#include <string>
22
23// #define BURN_IN_TIME 12500
-
24#define BURN_IN_TIME 5000
+
24#define BURN_IN_TIME 5000
25
-
26namespace montecarlo {
-
27/** @brief Write the expected values for each Monte Carlo cycles to file.
-
28 *
-
29 * @param T Temperature
-
30 * @param L The size of the lattice
-
31 * @param cycles The amount of Monte Carlo cycles to do
-
32 * @param filename The file to write to
-
33 * @param burn_in_time The burn-in time to use
-
34 * */
+
26namespace montecarlo {
35void progression(double T, int L, int cycles, const std::string filename,
-
36 int burn_in_time = BURN_IN_TIME);
+
36 int burn_in_time = BURN_IN_TIME);
37
-
38/** @brief Write the expected values for each Monte Carlo cycles to file.
-
39 *
-
40 * @param T Temperature
-
41 * @param L The size of the lattice
-
42 * @param cycles The amount of Monte Carlo cycles to do
-
43 * @param value The value to set the elements in the lattice
-
44 * @param filename The file to write to
-
45 * @param burn_in_time The burn-in time to use
-
46 * */
-
47void progression(double T, int L, int cycles, int value,
-
48 const std::string filename, int burn_in_time = BURN_IN_TIME);
+
47void progression(double T, int L, int cycles, int value,
+
48 const std::string filename, int burn_in_time = BURN_IN_TIME);
49
-
50/** @brief Estimate the probability distribution for the energy.
-
51 *
-
52 * @param T The temperature of the Ising model
-
53 * @param L The size of the lattice
-
54 * @param cycles The amount of Monte Carlo cycles to do
-
55 * @param filename The file to write to
-
56 * @param burn_in_time The burn-in time to use
-
57 * */
58void pd_estimate(double T, int L, int cycles, const std::string filename,
-
59 int burn_in_time = BURN_IN_TIME);
+
59 int burn_in_time = BURN_IN_TIME);
60
-
61/** @brief Execute the Metropolis algorithm for a certain amount of Monte
-
62 * Carlo cycles.
-
63 *
-
64 * @param L The size of the lattice
-
65 * @param T The Temperature for the Ising model
-
66 * @param cycles The amount of Monte Carlo cycles to do
-
67 * @param burn_in_time The burn-in time to use
-
68 *
-
69 * @return data_t
-
70 * */
71data_t mcmc_serial(int L, double T, int cycles,
-
72 int burn_in_time = BURN_IN_TIME);
+
72 int burn_in_time = BURN_IN_TIME);
73
-
74/** @brief Execute the Metropolis algorithm for a certain amount of Monte
-
75 * Carlo cycles in parallel.
-
76 *
-
77 * @param L The size of the lattice
-
78 * @param T The Temperature for the Ising model
-
79 * @param cycles The amount of Monte Carlo cycles to do
-
80 * @param burn_in_time The burn-in time to use
-
81 *
-
82 * @return data_t
-
83 * */
84data_t mcmc_parallel(int L, double T, int cycles,
-
85 int burn_in_time = BURN_IN_TIME);
+
85 int burn_in_time = BURN_IN_TIME);
86
-
87/** @brief Perform the MCMC algorithm using a range of temperatures.
-
88 *
-
89 * @param L The size of the lattice
-
90 * @param start_T The start temperature
-
91 * @param end_T The end temperature
-
92 * @param point_T The amount of point to measure
-
93 * @param monte_carlo Which Monte Carlo implementation to use
-
94 * @param outfile The file to write the data to
-
95 * @param burn_in_time The burn-in time to use
-
96 * */
97void phase_transition(int L, double start_T, double end_T, int points_T,
98 int cycles,
99 std::function<data_t(int, double, int, int)> monte_carlo,
-
100 std::string outfile, int burn_in_time = BURN_IN_TIME);
+
100 std::string outfile, int burn_in_time = BURN_IN_TIME);
101}; // namespace montecarlo
102
-
103#endif
+
103#endif
+
The definition of the Ising model.
Type to use with the IsingModel class and montecarlo module.
Definition: data_type.hpp:19
-
void test_parallel_speedup()
Test how much Openmp speeds up.
Definition: main.cpp:60
-
int main(int argc, char **argv)
The main function.
Definition: main.cpp:125
-
void create_pd_estimate_data()
Create the data used to estimate the probability distribution for tempratures 1.0 and 2....
Definition: main.cpp:37
-
void create_burn_in_time_data()
Create the data for the burn-in time for temperatures 1.0 and 2.4 for both unordered and ordered init...
Definition: main.cpp:21
-
void test_burn_in_time()
Create data using the same parameters except one uses burn-in time, while the other doesn't.
Definition: main.cpp:49
-
void create_phase_transition_data()
Create data for studying phase transition.
Definition: main.cpp:83
-
void usage(std::string filename)
A function that displays how to use the program and quits.
Definition: main.cpp:110
-
void progression(double T, int L, int cycles, int value, const std::string filename, int burn_in_time=BURN_IN_TIME)
Write the expected values for each Monte Carlo cycles to file.
Definition: monte_carlo.cpp:46
+
Header for the data_t type.
void phase_transition(int L, double start_T, double end_T, int points_T, int cycles, std::function< data_t(int, double, int, int)> monte_carlo, std::string outfile, int burn_in_time=BURN_IN_TIME)
Perform the MCMC algorithm using a range of temperatures.
-
#define BURN_IN_TIME
Definition: monte_carlo.hpp:24
void progression(double T, int L, int cycles, const std::string filename, int burn_in_time=BURN_IN_TIME)
Write the expected values for each Monte Carlo cycles to file.
Definition: monte_carlo.cpp:15
data_t mcmc_parallel(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles in parallel.
data_t mcmc_serial(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles.
void pd_estimate(double T, int L, int cycles, const std::string filename, int burn_in_time=BURN_IN_TIME)
Estimate the probability distribution for the energy.
Definition: monte_carlo.cpp:77
+
Function prototypes and macros that are useful.
diff --git a/docs/pd__estimate_8cpp.html b/docs/pd__estimate_8cpp.html index 8d8fc1a..4f2f997 100644 --- a/docs/pd__estimate_8cpp.html +++ b/docs/pd__estimate_8cpp.html @@ -130,7 +130,7 @@ Functions
Janita Ovidie Sandtrøen Willumsen (janitaws)
Version
1.0
-
Bug:
No known bugs
+
Bug:
No known bugs

Definition in file pd_estimate.cpp.

Function Documentation

diff --git a/docs/pd__estimate_8cpp_source.html b/docs/pd__estimate_8cpp_source.html index 678da62..74ae71a 100644 --- a/docs/pd__estimate_8cpp_source.html +++ b/docs/pd__estimate_8cpp_source.html @@ -101,28 +101,16 @@ $(document).ready(function(){initNavTree('pd__estimate_8cpp_source.html',''); in
pd_estimate.cpp
-Go to the documentation of this file.
1/** @file pd_estimate.cpp
-
2 *
-
3 * @author Cory Alexander Balaton (coryab)
-
4 * @author Janita Ovidie Sandtrøen Willumsen (janitaws)
-
5 *
-
6 * @version 1.0
-
7 *
-
8 * @brief execute the mcmc algorithm and write data to file after each
-
9 * Monte Carlo cycles.
-
10 *
-
11 * @bug No known bugs
-
12 * */
-
13#include "data_type.hpp"
-
14#include "monte_carlo.hpp"
-
15#include "utils.hpp"
+Go to the documentation of this file.
1
+
13#include "data_type.hpp"
+
14#include "monte_carlo.hpp"
+
15#include "utils.hpp"
16
-
17#include <getopt.h>
-
18#include <omp.h>
-
19#include <string>
+
17#include <getopt.h>
+
18#include <omp.h>
+
19#include <string>
20
-
21/** @brief A function that displays how to use the program and quits.*/
-
22void usage(std::string filename)
+
22void usage(std::string filename)
23{
24 std::cout << "Usage: " << filename
25 << " <temperature> <lattice size> "
@@ -131,13 +119,10 @@ $(document).ready(function(){initNavTree('pd__estimate_8cpp_source.html',''); in
28 exit(-1);
29}
30
-
31/** @brief The main function
-
32 *
-
33 * */
-
34int main(int argc, char **argv)
+
34int main(int argc, char **argv)
35{
36 // Command options
-
37 struct option long_options[] = {{"help", 0, 0, 0}, {NULL, 0, NULL, 0}};
+
37 struct option long_options[] = {{"help", 0, 0, 0}, {NULL, 0, NULL, 0}};
38
39 int option_index = -1;
40 int c;
@@ -153,17 +138,17 @@ $(document).ready(function(){initNavTree('pd__estimate_8cpp_source.html',''); in
50 switch (option_index) {
51 case 0: // Not a mistake. This just goes to the default.
52 default:
-
53 usage(argv[0]);
+
53 usage(argv[0]);
54 }
55 break;
-
56 case 'h':
+
56 case 'h':
57 default:
-
58 usage(argv[0]);
+
58 usage(argv[0]);
59 }
60 }
61 // Check that the number of arguments is at least 8.
62 if (argc < 6) {
-
63 usage(argv[0]);
+
63 usage(argv[0]);
64 }
65
66 // Timing variables
@@ -175,15 +160,17 @@ $(document).ready(function(){initNavTree('pd__estimate_8cpp_source.html',''); in
72 int L = atoi(argv[2]), cycles = atoi(argv[3]), burn_in_time = atoi(argv[4]);
73 std::string outfile = argv[5];
74
-
75 montecarlo::pd_estimate(temp, L, cycles, outfile, burn_in_time);
+
75 montecarlo::pd_estimate(temp, L, cycles, outfile, burn_in_time);
76
77 t1 = omp_get_wtime();
78
79 std::cout << "Time: " << t1 - t0 << " seconds\n";
80}
-
int main(int argc, char **argv)
The main function.
Definition: main.cpp:125
-
void usage(std::string filename)
A function that displays how to use the program and quits.
Definition: main.cpp:110
-
void pd_estimate(double T, int L, int cycles, const std::string filename, int burn_in_time=BURN_IN_TIME)
Estimate the probability distribution for the energy.
Definition: monte_carlo.cpp:77
+
Header for the data_t type.
+
Functions for Monte Carlo simulations.
+
void usage(std::string filename)
A function that displays how to use the program and quits.
Definition: pd_estimate.cpp:22
+
int main()
The main function.
Definition: test_suite.cpp:110
+
Function prototypes and macros that are useful.
diff --git a/docs/phase__transition_8cpp.html b/docs/phase__transition_8cpp.html index bcd1725..4c76e1a 100644 --- a/docs/phase__transition_8cpp.html +++ b/docs/phase__transition_8cpp.html @@ -131,7 +131,7 @@ Functions Janita Ovidie Sandtrøen Willumsen (janitaws)
Version
1.0

This program takes in 4 arguments: the start temperature, the end temperature, the amount of temperature points to simulate, and the amount of monte carlo samples to collect, in that order.

-
Bug:
No known bugs
+
Bug:
No known bugs

Definition in file phase_transition.cpp.

Function Documentation

diff --git a/docs/phase__transition_8cpp_source.html b/docs/phase__transition_8cpp_source.html index 1259f10..301b7cd 100644 --- a/docs/phase__transition_8cpp_source.html +++ b/docs/phase__transition_8cpp_source.html @@ -101,31 +101,16 @@ $(document).ready(function(){initNavTree('phase__transition_8cpp_source.html',''
phase_transition.cpp
-Go to the documentation of this file.
1/** @file phase_transition.cpp
-
2 *
-
3 * @author Cory Alexander Balaton (coryab)
-
4 * @author Janita Ovidie Sandtrøen Willumsen (janitaws)
-
5 *
-
6 * @version 1.0
-
7 *
-
8 * @brief Sweep over different temperatures and generate data.
-
9 *
-
10 * @details This program takes in 4 arguments: the start temperature,
-
11 * the end temperature, the amount of temperature points to simulate, and
-
12 * the amount of monte carlo samples to collect, in that order.
-
13 *
-
14 * @bug No known bugs
-
15 * */
-
16#include "data_type.hpp"
-
17#include "monte_carlo.hpp"
-
18#include "utils.hpp"
+Go to the documentation of this file.
1
+
16#include "data_type.hpp"
+
17#include "monte_carlo.hpp"
+
18#include "utils.hpp"
19
-
20#include <getopt.h>
-
21#include <omp.h>
-
22#include <string>
+
20#include <getopt.h>
+
21#include <omp.h>
+
22#include <string>
23
-
24/** @brief A function that displays how to use the program and quits.*/
-
25void usage(std::string filename)
+
25void usage(std::string filename)
26{
27 std::cout << "Usage: " << filename
28 << " <start temperature> <end temperature> <points> "
@@ -134,11 +119,10 @@ $(document).ready(function(){initNavTree('phase__transition_8cpp_source.html',''
31 exit(-1);
32}
33
-
34/** @brief The main function.*/
-
35int main(int argc, char **argv)
+
35int main(int argc, char **argv)
36{
37 // Command options
-
38 struct option long_options[] = {{"help", 0, 0, 0}, {NULL, 0, NULL, 0}};
+
38 struct option long_options[] = {{"help", 0, 0, 0}, {NULL, 0, NULL, 0}};
39
40 int option_index = -1;
41 int c;
@@ -154,17 +138,17 @@ $(document).ready(function(){initNavTree('phase__transition_8cpp_source.html',''
51 switch (option_index) {
52 case 0: // Not a mistake. This just goes to the default.
53 default:
-
54 usage(argv[0]);
+
54 usage(argv[0]);
55 }
56 break;
-
57 case 'h':
+
57 case 'h':
58 default:
-
59 usage(argv[0]);
+
59 usage(argv[0]);
60 }
61 }
62 // Check that the number of arguments is at least 8.
63 if (argc < 8) {
-
64 usage(argv[0]);
+
64 usage(argv[0]);
65 }
66
67 // Timing variables
@@ -177,17 +161,18 @@ $(document).ready(function(){initNavTree('phase__transition_8cpp_source.html',''
74 burn_in_time = atoi(argv[6]), N = L * L;
75 std::string outfile = argv[7];
76
-
77 montecarlo::phase_transition(L, start, end, points, cycles,
-
78 montecarlo::mcmc_parallel, outfile, burn_in_time);
+
77 montecarlo::phase_transition(L, start, end, points, cycles,
+
78 montecarlo::mcmc_parallel, outfile, burn_in_time);
79
80 t1 = omp_get_wtime();
81
82 std::cout << "Time: " << t1 - t0 << " seconds\n";
83}
-
int main(int argc, char **argv)
The main function.
Definition: main.cpp:125
-
void usage(std::string filename)
A function that displays how to use the program and quits.
Definition: main.cpp:110
-
void phase_transition(int L, double start_T, double end_T, int points_T, int cycles, std::function< data_t(int, double, int, int)> monte_carlo, std::string outfile, int burn_in_time=BURN_IN_TIME)
Perform the MCMC algorithm using a range of temperatures.
-
data_t mcmc_parallel(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles in parallel.
+
Header for the data_t type.
+
Functions for Monte Carlo simulations.
+
void usage(std::string filename)
A function that displays how to use the program and quits.
+
int main()
The main function.
Definition: test_suite.cpp:110
+
Function prototypes and macros that are useful.
diff --git a/docs/phase__transition__mpi_8cpp.html b/docs/phase__transition__mpi_8cpp.html index 8966e3d..16a2831 100644 --- a/docs/phase__transition__mpi_8cpp.html +++ b/docs/phase__transition__mpi_8cpp.html @@ -131,7 +131,7 @@ Functions Janita Ovidie Sandtrøen Willumsen (janitaws)
Version
1.0

This program takes in 4 arguments: the start temperature, the end temperature, the amount of temperature points to simulate, and the amount of monte carlo samples to collect, in that order.

-
Bug:
No known bugs
+
Bug:
No known bugs

Definition in file phase_transition_mpi.cpp.

Function Documentation

diff --git a/docs/phase__transition__mpi_8cpp_source.html b/docs/phase__transition__mpi_8cpp_source.html index 0a1787b..cfecd2e 100644 --- a/docs/phase__transition__mpi_8cpp_source.html +++ b/docs/phase__transition__mpi_8cpp_source.html @@ -101,31 +101,16 @@ $(document).ready(function(){initNavTree('phase__transition__mpi_8cpp_source.htm
phase_transition_mpi.cpp
-Go to the documentation of this file.
1/** @file phase_transition_mpi.cpp
-
2 *
-
3 * @author Cory Alexander Balaton (coryab)
-
4 * @author Janita Ovidie Sandtrøen Willumsen (janitaws)
-
5 *
-
6 * @version 1.0
-
7 *
-
8 * @brief Sweep over different temperatures and generate data.
-
9 *
-
10 * @details This program takes in 4 arguments: the start temperature,
-
11 * the end temperature, the amount of temperature points to simulate, and
-
12 * the amount of monte carlo samples to collect, in that order.
-
13 *
-
14 * @bug No known bugs
-
15 * */
-
16#include "data_type.hpp"
-
17#include "monte_carlo.hpp"
-
18#include "utils.hpp"
+Go to the documentation of this file.
1
+
16#include "data_type.hpp"
+
17#include "monte_carlo.hpp"
+
18#include "utils.hpp"
19
-
20#include <getopt.h>
-
21#include <mpi.h>
-
22#include <string>
+
20#include <getopt.h>
+
21#include <mpi.h>
+
22#include <string>
23
-
24/** @brief A function that displays how to use the program and quits.*/
-
25void usage(std::string filename)
+
25void usage(std::string filename)
26{
27 std::cout
28 << "Usage: " << filename
@@ -137,11 +122,10 @@ $(document).ready(function(){initNavTree('phase__transition__mpi_8cpp_source.htm
34 exit(-1);
35}
36
-
37/** @brief The main function.*/
-
38int main(int argc, char **argv)
+
38int main(int argc, char **argv)
39{
40 // Command options
-
41 struct option long_options[] = {{"help", 0, 0, 0}, {NULL, 0, NULL, 0}};
+
41 struct option long_options[] = {{"help", 0, 0, 0}, {NULL, 0, NULL, 0}};
42
43 int option_index = -1;
44 int c;
@@ -157,17 +141,17 @@ $(document).ready(function(){initNavTree('phase__transition__mpi_8cpp_source.htm
54 switch (option_index) {
55 case 0: // Not a mistake. This just goes to the default.
56 default:
-
57 usage(argv[0]);
+
57 usage(argv[0]);
58 }
59 break;
-
60 case 'h':
+
60 case 'h':
61 default:
-
62 usage(argv[0]);
+
62 usage(argv[0]);
63 }
64 }
65 // Check that the number of arguments is at least 8.
66 if (argc < 8) {
-
67 usage(argv[0]);
+
67 usage(argv[0]);
68 }
69
70 // Timing variables
@@ -211,9 +195,9 @@ $(document).ready(function(){initNavTree('phase__transition__mpi_8cpp_source.htm
108 data_t i_data[i_points];
109
110 // Simulate and save data to array
-
111 for (size_t i = 0; i < i_points; i++) {
-
112 i_data[i] = montecarlo::mcmc_parallel(L, i_start + dt * i, cycles,
-
113 burn_in_time);
+
111 for (size_t i = 0; i < i_points; i++) {
+
112 i_data[i] = montecarlo::mcmc_parallel(L, i_start + dt * i, cycles,
+
113 burn_in_time);
114 }
115
116 // Rank 0 collects all the data and copies it to the "master"
@@ -223,17 +207,17 @@ $(document).ready(function(){initNavTree('phase__transition__mpi_8cpp_source.htm
120 std::copy_n(i_data, i_points, data);
121
122 // Collect i_data from other ranks in order and copy to data.
-
123 for (size_t i = 1; i < cluster_size; i++) {
+
123 for (size_t i = 1; i < cluster_size; i++) {
124 if (rank < remainder) {
125 MPI_Recv((void *)i_data,
-
126 sizeof(data_t) * (points / cluster_size + 1), MPI_CHAR,
+
126 sizeof(data_t) * (points / cluster_size + 1), MPI_CHAR,
127 i, MPI_ANY_TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
128 std::copy_n(i_data, points / cluster_size + 1,
129 data + (points / cluster_size) * i);
130 }
131 else {
132 MPI_Recv((void *)i_data,
-
133 sizeof(data_t) * (points / cluster_size), MPI_CHAR, i,
+
133 sizeof(data_t) * (points / cluster_size), MPI_CHAR, i,
134 MPI_ANY_TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
135 std::copy_n(i_data, points / cluster_size,
136 data + (points / cluster_size) * i + remainder);
@@ -241,30 +225,30 @@ $(document).ready(function(){initNavTree('phase__transition__mpi_8cpp_source.htm
138 }
139
140 // Write everything from data to file
-
141 utils::mkpath(utils::dirname(outfile));
+
141 utils::mkpath(utils::dirname(outfile));
142 ofile.open(outfile);
143
144 double temp, CV, X;
145
-
146 using utils::scientific_format;
-
147 for (size_t i = 0; i < points; i++) {
+
146 using utils::scientific_format;
+
147 for (size_t i = 0; i < points; i++) {
148 temp = start + dt * i;
-
149 CV = (data[i].E2 - data[i].E * data[i].E)
+
149 CV = (data[i].E2 - data[i].E * data[i].E)
150 / ((double)N * temp * temp);
-
151 X = (data[i].M2 - data[i].M_abs * data[i].M_abs)
+
151 X = (data[i].M2 - data[i].M_abs * data[i].M_abs)
152 / ((double)N * temp);
153
-
154 ofile << scientific_format(temp) << ','
-
155 << scientific_format(data[i].E / N) << ','
-
156 << scientific_format(data[i].M_abs / N) << ','
- -
158 << '\n';
+
154 ofile << scientific_format(temp) << ','
+
155 << scientific_format(data[i].E / N) << ','
+
156 << scientific_format(data[i].M_abs / N) << ','
+
157 << scientific_format(CV) << ',' << scientific_format(X)
+
158 << '\n';
159 }
160 ofile.close();
161 }
162 // For all other ranks, send the data to rank 0
163 else {
-
164 MPI_Send(i_data, i_points * sizeof(data_t), MPI_CHAR, 0, rank,
+
164 MPI_Send(i_data, i_points * sizeof(data_t), MPI_CHAR, 0, rank,
165 MPI_COMM_WORLD);
166 }
167
@@ -277,12 +261,15 @@ $(document).ready(function(){initNavTree('phase__transition__mpi_8cpp_source.htm
174 MPI_Finalize();
175}
Type to use with the IsingModel class and montecarlo module.
Definition: data_type.hpp:19
-
int main(int argc, char **argv)
The main function.
Definition: main.cpp:125
-
void usage(std::string filename)
A function that displays how to use the program and quits.
Definition: main.cpp:110
-
data_t mcmc_parallel(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles in parallel.
-
bool mkpath(std::string path, int mode=0777)
Make path given.
Definition: utils.cpp:32
-
std::string scientific_format(double d, int width=20, int prec=10)
Turns a double into a string written in scientific format.
Definition: utils.cpp:16
-
std::string dirname(const std::string &path)
Get the directory name of the path.
Definition: utils.cpp:58
+
double M_abs
Absolute Magnetization.
Definition: data_type.hpp:25
+
double E
Energy.
Definition: data_type.hpp:21
+
double M2
Magnetization squared.
Definition: data_type.hpp:24
+
double E2
Energy squared.
Definition: data_type.hpp:23
+
Header for the data_t type.
+
Functions for Monte Carlo simulations.
+
void usage(std::string filename)
A function that displays how to use the program and quits.
+
int main()
The main function.
Definition: test_suite.cpp:110
+
Function prototypes and macros that are useful.
diff --git a/docs/test__suite_8cpp.html b/docs/test__suite_8cpp.html index dd47d54..e069d9b 100644 --- a/docs/test__suite_8cpp.html +++ b/docs/test__suite_8cpp.html @@ -146,7 +146,7 @@ Functions
Janita Ovidie Sandtrøen Willumsen (janitaws)
Version
1.0
-
Bug:
No known bugs
+
Bug:
No known bugs

Definition in file test_suite.cpp.

Macro Definition Documentation

diff --git a/docs/test__suite_8cpp_source.html b/docs/test__suite_8cpp_source.html index ef0f705..8bd7672 100644 --- a/docs/test__suite_8cpp_source.html +++ b/docs/test__suite_8cpp_source.html @@ -101,88 +101,59 @@ $(document).ready(function(){initNavTree('test__suite_8cpp_source.html',''); ini
test_suite.cpp
-Go to the documentation of this file.
1/** @file test_suite.cpp
-
2 *
-
3 * @author Cory Alexander Balaton (coryab)
-
4 * @author Janita Ovidie Sandtrøen Willumsen (janitaws)
-
5 *
-
6 * @version 1.0
-
7 *
-
8 * @brief Sweep over different temperatures and generate data.
-
9 *
-
10 * @bug No known bugs
-
11 * */
-
12#include "IsingModel.hpp"
-
13#include "testlib.hpp"
+Go to the documentation of this file.
1
+
12#include "IsingModel.hpp"
+
13#include "testlib.hpp"
14
-
15/** @brief The analytic expected energy for a \f$ 2 \times 2 \f$ lattice.
-
16 * */
-
17#define EPS_2 (-2 * std::sinh(8.)) / (std::cosh(8.) + 3)
+
17#define EPS_2 (-2 * std::sinh(8.)) / (std::cosh(8.) + 3)
18
-
19/** @brief The analytic expected magnetization for a \f$ 2 \times 2 \f$
-
20 * lattice.
-
21 * */
-
22#define MAG_2 (std::exp(8.) + 1) / (2 * (cosh(8.) + 3))
+
22#define MAG_2 (std::exp(8.) + 1) / (2 * (cosh(8.) + 3))
23
-
24/** @brief The analytic heat capacity for a \f$ 2 \times 2 \f$ lattice.
-
25 * */
-
26#define CV_2
-
27 16 * (3 * std::cosh(8.) + 1) / ((std::cosh(8.) + 3) * (std::cosh(8.) + 3))
+
26#define CV_2 \
+
27 16 * (3 * std::cosh(8.) + 1) / ((std::cosh(8.) + 3) * (std::cosh(8.) + 3))
28
-
29/** @brief The analytic susceptibility for a \f$ 2 \times 2 \f$ lattice.*/
-
30#define X_2
-
31 (3 * std::exp(8.) + std::exp(-8.) + 3)
-
32 / ((std::cosh(8.) + 3) * (std::cosh(8.) + 3))
+
30#define X_2 \
+
31 (3 * std::exp(8.) + std::exp(-8.) + 3) \
+
32 / ((std::cosh(8.) + 3) * (std::cosh(8.) + 3))
33
-
34/** @brief Test class for the Ising model
-
35 * */
- +
37public:
-
38 /** @brief Test that initializing works as intended.
-
39 * */
41 {
42 IsingModel test;
-
43 test.L = 3;
-
44 test.T = 1.;
+
43 test.L = 3;
+
44 test.T = 1.;
45
46 // Test that initializing the lattice only yields 1s and -1s.
- -
48 std::function<bool(int)> f = [](int x) { return x == 1 || x == -1; };
-
49 ASSERT(testlib::assert_each(f, test.lattice),
+
47 test.initialize_lattice();
+
48 std::function<bool(int)> f = [](int x) { return x == 1 || x == -1; };
+
49 ASSERT(testlib::assert_each(f, test.lattice),
50 "Test lattice initialization.");
51
- -
53 arma::Mat<int> neighbor_matrix("2, 1 ; 0, 2 ; 1, 0");
-
54 ASSERT(testlib::is_equal(neighbor_matrix, test.neighbors),
+ +
53 arma::Mat<int> neighbor_matrix("2, 1 ; 0, 2 ; 1, 0");
+
54 ASSERT(testlib::is_equal(neighbor_matrix, test.neighbors),
55 "Test neighbor matrix.");
56
57 // Fill the lattice with 1s to be able to test the next functions.
-
58 test.lattice.fill(1);
+
58 test.lattice.fill(1);
59
60 // Test the initial magnetization.
- -
62 ASSERT(std::fabs(test.M - 9.) < 1e-8, "Test intial magnetization");
+ +
62 ASSERT(std::fabs(test.M - 9.) < 1e-8, "Test intial magnetization");
63
64 // Test that the initial energy is correct
- -
66 ASSERT(std::fabs(test.E - (-18)) < 1e-8, "Test initial energy.");
+
65 test.initialize_energy();
+
66 ASSERT(std::fabs(test.E - (-18)) < 1e-8, "Test initial energy.");
67 }
68
-
69 /** @brief Test numerical data with analytical data.
-
70 *
-
71 * @param tol The tolerance between the analytical and numerical solution.
-
72 * @param max_cycles The max number of Monte Carlo cycles.
-
73 *
-
74 * return int
-
75 * */
76 int test_2x2_lattice(double tol, int max_cycles)
77 {
78 data_t data, tmp;
-
79 size_t L = 2;
-
80 size_t n_spins = L * L;
+
79 size_t L = 2;
+
80 size_t n_spins = L * L;
81 double T = 1.;
-
82 size_t cycles = 0;
+
82 size_t cycles = 0;
83
84 // Create random engine using the mersenne twister
85 std::random_device rd;
@@ -194,14 +165,14 @@ $(document).ready(function(){initNavTree('test__suite_8cpp_source.html',''); ini
91
92 // Loop through cycles
93 while (cycles++ < max_cycles) {
-
94 data += test.Metropolis();
+
94 data += test.Metropolis();
95 tmp = data / 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)
+
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(
-
99 CV_2, (tmp.E2 - tmp.E * tmp.E) / (T * T) / n_spins, tol)
+
99 CV_2, (tmp.E2 - tmp.E * tmp.E) / (T * T) / n_spins, tol)
100 && testlib::close_to(
-
101 X_2, (tmp.M2 - tmp.M_abs * tmp.M_abs) / T / n_spins, tol)) {
+
101 X_2, (tmp.M2 - tmp.M_abs * tmp.M_abs) / T / n_spins, tol)) {
102 return cycles;
103 }
104 }
@@ -209,12 +180,11 @@ $(document).ready(function(){initNavTree('test__suite_8cpp_source.html',''); ini
106 }
107};
108
-
109/** @brief The main function.*/
110int main()
111{
112 IsingModelTest test;
113
- +
114 test.test_init_functions();
115
116 int res = 0;
117 int tmp;
@@ -222,8 +192,8 @@ $(document).ready(function(){initNavTree('test__suite_8cpp_source.html',''); ini
119 int accepted_values = 0;
120
121 // Run through the test multiple times to get a better estimate.
-
122 for (size_t i = 0; i < iterations; i++) {
-
123 tmp = test.test_2x2_lattice(1e-2, 1e5);
+
122 for (size_t i = 0; i < iterations; i++) {
+
123 tmp = test.test_2x2_lattice(1e-2, 1e5);
124 if (tmp == 0) {
125 continue;
126 }
@@ -235,6 +205,7 @@ $(document).ready(function(){initNavTree('test__suite_8cpp_source.html',''); ini
132
133 return 0;
134}
+
The definition of the Ising model.
Test class for the Ising model.
Definition: test_suite.cpp:36
int test_2x2_lattice(double tol, int max_cycles)
Test numerical data with analytical data.
Definition: test_suite.cpp:76
void test_init_functions()
Test that initializing works as intended.
Definition: test_suite.cpp:40
@@ -242,16 +213,17 @@ $(document).ready(function(){initNavTree('test__suite_8cpp_source.html',''); ini
int64_t E
The current energy state. unit: .
Definition: IsingModel.hpp:70
double T
The temperature of the model.
Definition: IsingModel.hpp:62
int L
Size of the lattice.
Definition: IsingModel.hpp:66
+
arma::Mat< int > lattice
matrix where element .
Definition: IsingModel.hpp:44
void initialize_lattice()
Initialize the lattice with a random distribution of 1s and -1s.
Definition: IsingModel.cpp:49
data_t Metropolis()
The Metropolis algorithm.
Definition: IsingModel.cpp:110
void initialize_energy()
Initialize the energy of the system.
Definition: IsingModel.cpp:96
void initialize_neighbors()
initialize the neighbors matrix.
Definition: IsingModel.cpp:70
void initialize_magnetization()
Initialize the magnetization of the system.
Definition: IsingModel.cpp:88
+
arma::Mat< int > neighbors
matrix with the neighbors of each element .
Definition: IsingModel.hpp:54
int64_t M
The current magnetic strength. unit: Unitless.
Definition: IsingModel.hpp:74
Type to use with the IsingModel class and montecarlo module.
Definition: data_type.hpp:19
double M_abs
Absolute Magnetization.
Definition: data_type.hpp:25
double E
Energy.
Definition: data_type.hpp:21
-
data_t & operator+=(const data_t &b)
Overload of the addition equals operator.
Definition: data_type.hpp:150
double M2
Magnetization squared.
Definition: data_type.hpp:24
double E2
Energy squared.
Definition: data_type.hpp:23
#define EPS_2
The analytic expected energy for a lattice.
Definition: test_suite.cpp:17
@@ -259,6 +231,7 @@ $(document).ready(function(){initNavTree('test__suite_8cpp_source.html',''); ini
#define X_2
The analytic susceptibility for a lattice.
Definition: test_suite.cpp:30
int main()
The main function.
Definition: test_suite.cpp:110
#define CV_2
The analytic heat capacity for a lattice.
Definition: test_suite.cpp:26
+
A small test library.
#define ASSERT(expr, msg)
A prettier assertion function.
Definition: testlib.hpp:31
diff --git a/docs/testlib_8cpp_source.html b/docs/testlib_8cpp_source.html index 3e93441..1b8d3f7 100644 --- a/docs/testlib_8cpp_source.html +++ b/docs/testlib_8cpp_source.html @@ -101,24 +101,14 @@ $(document).ready(function(){initNavTree('testlib_8cpp_source.html',''); initRes
testlib.cpp
-Go to the documentation of this file.
1/** @file testlib.cpp
-
2 *
-
3 * @author Cory Alexander Balaton (coryab)
-
4 * @author Janita Ovidie Sandtrøen Willumsen (janitaws)
-
5 *
-
6 * @version 1.0
-
7 *
-
8 * @brief Implementation of the testing library
-
9 *
-
10 * @bug No known bugs
-
11 * */
-
12#include "testlib.hpp"
+Go to the documentation of this file.
1
+
12#include "testlib.hpp"
13
-
14namespace details {
+
14namespace details {
15void m_assert(bool expr, std::string expr_str, std::string f, std::string file,
16 int line, std::string msg)
17{
-
18 std::function<void(const std::string &)> print_message =
+
18 std::function<void(const std::string &)> print_message =
19 [](const std::string &msg) {
20 if (msg.size() > 0) {
21 std::cout << "message: " << msg << "\n\n";
@@ -127,7 +117,7 @@ $(document).ready(function(){initNavTree('testlib_8cpp_source.html',''); initRes
24 std::cout << "\n";
25 }
26 };
-
27 std::string new_assert(f.size() + (expr ? 4 : 6), '-');
+
27 std::string new_assert(f.size() + (expr ? 4 : 6), '-');
28 std::cout << "\x1B[36m" << new_assert << "\033[0m\n";
29 std::cout << f << ": ";
30 if (expr) {
@@ -143,6 +133,7 @@ $(document).ready(function(){initNavTree('testlib_8cpp_source.html',''); initRes
40 }
41}
42} // namespace details
+
A small test library.
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.
Definition: testlib.cpp:15
diff --git a/docs/testlib_8hpp.html b/docs/testlib_8hpp.html index 99eafb6..0c61456 100644 --- a/docs/testlib_8hpp.html +++ b/docs/testlib_8hpp.html @@ -149,7 +149,7 @@ Functions Janita Ovidie Sandtrøen Willumsen (janitaws)
Version
1.0

This a small testing library that is tailored for the needs of the project. Anything that is in the details namespace should not be used directly, or else it might cause undefined behavior if not used correctly.

-
Bug:
No known bugs
+
Bug:
No known bugs

Definition in file testlib.hpp.

Macro Definition Documentation

diff --git a/docs/testlib_8hpp_source.html b/docs/testlib_8hpp_source.html index 8c92105..bc2eaa7 100644 --- a/docs/testlib_8hpp_source.html +++ b/docs/testlib_8hpp_source.html @@ -101,119 +101,55 @@ $(document).ready(function(){initNavTree('testlib_8hpp_source.html',''); initRes
testlib.hpp
-Go to the documentation of this file.
1/** @file testlib.hpp
-
2 *
-
3 * @author Cory Alexander Balaton (coryab)
-
4 * @author Janita Ovidie Sandtrøen Willumsen (janitaws)
-
5 *
-
6 * @version 1.0
-
7 *
-
8 * @brief A small test library.
-
9 *
-
10 * @details This a small testing library that is tailored for the needs of the
-
11 * project. Anything that is in the details namespace should not be used
-
12 * directly, or else it might cause undefined behavior if not used correctly.
-
13 *
-
14 * @bug No known bugs
-
15 * */
-
16#ifndef __TESTLIB__
-
17#define __TESTLIB__
+Go to the documentation of this file.
1
+
16#ifndef __TESTLIB__
+
17#define __TESTLIB__
18
-
19#include "utils.hpp"
+
19#include "utils.hpp"
20
-
21#include <armadillo>
-
22#include <string>
-
23#include <type_traits>
+
21#include <armadillo>
+
22#include <string>
+
23#include <type_traits>
24
-
25/** @def ASSERT(expr)
-
26 * @brief A prettier assertion function.
-
27 *
-
28 * This macro calls the m_assert function which is a more informative
-
29 * assertion function than the regular assert function from cassert.
-
30 * */
-
31#define ASSERT(expr, msg)
-
32 details::m_assert(expr, #expr, __METHOD_NAME__, __FILE__, __LINE__, msg)
+
31#define ASSERT(expr, msg) \
+
32 details::m_assert(expr, #expr, __METHOD_NAME__, __FILE__, __LINE__, msg)
33
-
34namespace details {
+
34namespace details {
35
-
36/** @brief Test an expression, confirm that test is ok, or abort execution.
-
37 *
-
38 * @details This function takes in an expression and prints an OK message if
-
39 * it's true, or it prints a fail message and aborts execution if it fails.
-
40 *
-
41 * @param expr The expression to be evaluated
-
42 * @param expr_str The stringified version of the expression
-
43 * @param func The function name of the caller
-
44 * @param file The file of the caller
-
45 * @param line The line number where this function is called from
-
46 * @param msg The message to be displayed
-
47 * */
-
48void m_assert(bool expr, std::string expr_str, std::string func,
+
48void m_assert(bool expr, std::string expr_str, std::string func,
49 std::string file, int line, std::string msg);
50} // namespace details
51
-
52namespace testlib {
+
52namespace testlib {
53
-
54/** @brief Test if two armadillo matrices/vectors are close to each other.
-
55 *
-
56 * @details This function takes in 2 matrices/vectors and checks if they are
-
57 * approximately equal to each other given a tolerance.
-
58 *
-
59 * @param a Matrix/vector a
-
60 * @param b Matrix/vector b
-
61 * @param tol The tolerance
-
62 *
-
63 * @return bool
-
64 * */
-
65template <class T,
-
66 class = typename std::enable_if<std::is_arithmetic<T>::value>::type>
+
65template <class T,
+
66 class = typename std::enable_if<std::is_arithmetic<T>::value>::type>
67static bool close_to(arma::Mat<T> &a, arma::Mat<T> &b, double tol = 1e-8)
68{
69 if (a.n_elem != b.n_elem) {
70 return false;
71 }
72
-
73 for (size_t i = 0; i < a.n_elem; i++) {
-
74 if (!close_to(a(i), b(i))) {
+
73 for (size_t i = 0; i < a.n_elem; i++) {
+
74 if (!close_to(a(i), b(i))) {
75 return false;
76 }
77 }
78 return true;
79}
80
-
81/** @brief Test if two numbers are close to each other.
-
82 *
-
83 * @details This function takes in 2 matrices/vectors and checks if they are
-
84 * approximately equal to each other given a tolerance.
-
85 *
-
86 * @param a Matrix/vector a
-
87 * @param b Matrix/vector b
-
88 * @param tol The tolerance
-
89 *
-
90 * @return bool
-
91 * */
-
92template <class T,
-
93 class = typename std::enable_if<std::is_arithmetic<T>::value>::type>
-
94static bool close_to(T a, T b, double tol = 1e-8)
+
92template <class T,
+
93 class = typename std::enable_if<std::is_arithmetic<T>::value>::type>
+
94static bool close_to(T a, T b, double tol = 1e-8)
95{
96 return std::fabs(a - b) < tol;
97}
98
-
99/** @brief Test if two armadillo matrices/vectors are equal.
-
100 *
-
101 * @details This function takes in 2 matrices/vectors and checks if they are
-
102 * equal to each other. This should only be used for integral types.
-
103 *
-
104 * @param a Matrix/vector a
-
105 * @param b Matrix/vector b
-
106 *
-
107 * @return bool
-
108 * */
-
109template <class T,
-
110 class = typename std::enable_if<std::is_integral<T>::value>::type>
+
109template <class T,
+
110 class = typename std::enable_if<std::is_integral<T>::value>::type>
111static bool is_equal(arma::Mat<T> &a, arma::Mat<T> &b)
112{
-
113 for (size_t i = 0; i < a.n_elem; i++) {
+
113 for (size_t i = 0; i < a.n_elem; i++) {
114 if (!(a(i) == b(i))) {
115 return false;
116 }
@@ -221,18 +157,11 @@ $(document).ready(function(){initNavTree('testlib_8hpp_source.html',''); initRes
118 return true;
119}
120
-
121/** @brief Test that all elements fulfill the condition.
-
122 *
-
123 * @param expr The boolean expression to apply to each element
-
124 * @param M The matrix/vector to iterate over
-
125 *
-
126 * @return bool
-
127 * */
-
128template <class T,
-
129 class = typename std::enable_if<std::is_arithmetic<T>::value>::type>
+
128template <class T,
+
129 class = typename std::enable_if<std::is_arithmetic<T>::value>::type>
130static bool assert_each(std::function<bool(T)> expr, arma::Mat<T> &M)
131{
-
132 for (size_t i = 0; i < M.n_elem; i++) {
+
132 for (size_t i = 0; i < M.n_elem; i++) {
133 if (!expr(M(i))) {
134 return false;
135 }
@@ -240,38 +169,11 @@ $(document).ready(function(){initNavTree('testlib_8hpp_source.html',''); initRes
137 return true;
138}
139} // namespace testlib
-
140#endif
-
Test class for the Ising model.
Definition: test_suite.cpp:36
-
int test_2x2_lattice(double tol, int max_cycles)
Test numerical data with analytical data.
Definition: test_suite.cpp:76
-
void test_init_functions()
Test that initializing works as intended.
Definition: test_suite.cpp:40
-
The Ising model in 2 dimensions.
Definition: IsingModel.hpp:36
-
int64_t E
The current energy state. unit: .
Definition: IsingModel.hpp:70
-
double T
The temperature of the model.
Definition: IsingModel.hpp:62
-
int L
Size of the lattice.
Definition: IsingModel.hpp:66
-
void initialize_lattice()
Initialize the lattice with a random distribution of 1s and -1s.
Definition: IsingModel.cpp:49
-
data_t Metropolis()
The Metropolis algorithm.
Definition: IsingModel.cpp:110
-
void initialize_energy()
Initialize the energy of the system.
Definition: IsingModel.cpp:96
-
void initialize_neighbors()
initialize the neighbors matrix.
Definition: IsingModel.cpp:70
-
void initialize_magnetization()
Initialize the magnetization of the system.
Definition: IsingModel.cpp:88
-
int64_t M
The current magnetic strength. unit: Unitless.
Definition: IsingModel.hpp:74
-
Type to use with the IsingModel class and montecarlo module.
Definition: data_type.hpp:19
-
double M_abs
Absolute Magnetization.
Definition: data_type.hpp:25
-
double E
Energy.
Definition: data_type.hpp:21
-
data_t & operator+=(const data_t &b)
Overload of the addition equals operator.
Definition: data_type.hpp:150
-
double M2
Magnetization squared.
Definition: data_type.hpp:24
-
double E2
Energy squared.
Definition: data_type.hpp:23
-
#define EPS_2
The analytic expected energy for a lattice.
Definition: test_suite.cpp:17
-
#define MAG_2
The analytic expected magnetization for a lattice.
Definition: test_suite.cpp:22
-
#define X_2
The analytic susceptibility for a lattice.
Definition: test_suite.cpp:30
-
int main()
The main function.
Definition: test_suite.cpp:110
-
#define CV_2
The analytic heat capacity for a lattice.
Definition: test_suite.cpp:26
+
140#endif
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.
Definition: testlib.hpp:67
-
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.
Definition: testlib.cpp:15
static bool is_equal(arma::Mat< T > &a, arma::Mat< T > &b)
Test if two armadillo matrices/vectors are equal.
Definition: testlib.hpp:111
-
static bool close_to(T a, T b, double tol=1e-8)
Test if two numbers are close to each other.
Definition: testlib.hpp:94
-
#define ASSERT(expr, msg)
A prettier assertion function.
Definition: testlib.hpp:31
static bool assert_each(std::function< bool(T)> expr, arma::Mat< T > &M)
Test that all elements fulfill the condition.
Definition: testlib.hpp:130
-
#define __METHOD_NAME__
Get the name of the current method/function without the return type.
Definition: utils.hpp:45
+
Function prototypes and macros that are useful.
diff --git a/docs/time_8cpp_source.html b/docs/time_8cpp_source.html index 19b3f8a..c28fc71 100644 --- a/docs/time_8cpp_source.html +++ b/docs/time_8cpp_source.html @@ -101,27 +101,15 @@ $(document).ready(function(){initNavTree('time_8cpp_source.html',''); initResiza
time.cpp
-Go to the documentation of this file.
1/** @file time.cpp
-
2 *
-
3 * @author Cory Alexander Balaton (coryab)
-
4 * @author Janita Ovidie Sandtrøen Willumsen (janitaws)
-
5 *
-
6 * @version 0.1
-
7 *
-
8 * @brief Timing various things.
-
9 *
-
10 * @bug No known bugs
-
11 * */
-
12#include "data_type.hpp"
-
13#include "monte_carlo.hpp"
-
14#include "utils.hpp"
+Go to the documentation of this file.
1
+
12#include "data_type.hpp"
+
13#include "monte_carlo.hpp"
+
14#include "utils.hpp"
15
-
16#include <getopt.h>
-
17#include <omp.h>
-
18#include <ostream>
+
16#include <getopt.h>
+
17#include <omp.h>
+
18#include <ostream>
19
-
20/** @brief Time phase transition using different lattice sizes.
-
21 * */
23{
24 std::string outfile = "data/hp/timing/lattice_sizes.txt";
@@ -129,26 +117,24 @@ $(document).ready(function(){initNavTree('time_8cpp_source.html',''); initResiza
26
27 int lattice_sizes[] = {20, 40, 60, 80, 100};
28
-
29 utils::mkpath(utils::dirname(outfile));
+
29 utils::mkpath(utils::dirname(outfile));
30 ofile.open(outfile);
31 double t0, t1, t2;
32 for (int L : lattice_sizes) {
33 t0 = omp_get_wtime();
-
34 montecarlo::phase_transition(L, 2.1, 2.4, 40, 20000,
-
35 montecarlo::mcmc_parallel, "/dev/null", 0);
+
34 montecarlo::phase_transition(L, 2.1, 2.4, 40, 20000,
+
35 montecarlo::mcmc_parallel, "/dev/null", 0);
36 t1 = omp_get_wtime();
-
37 montecarlo::phase_transition(L, 2.1, 2.4, 40, 20000,
-
38 montecarlo::mcmc_serial, "/dev/null", 0);
+
37 montecarlo::phase_transition(L, 2.1, 2.4, 40, 20000,
+
38 montecarlo::mcmc_serial, "/dev/null", 0);
39 t2 = omp_get_wtime();
-
40 ofile << utils::scientific_format(L) << ','
-
41 << utils::scientific_format(t1 - t0) << ','
-
42 << utils::scientific_format(t2 - t1) << '\n';
+
40 ofile << utils::scientific_format(L) << ','
+
41 << utils::scientific_format(t1 - t0) << ','
+
42 << utils::scientific_format(t2 - t1) << '\n';
43 }
44 ofile.close();
45}
46
-
47/** @brief Time phase transition using different sample sizes.
-
48 * */
50{
51 std::string outfile = "data/hp/timing/sample_sizes.txt";
@@ -156,26 +142,25 @@ $(document).ready(function(){initNavTree('time_8cpp_source.html',''); initResiza
53
54 int sample_sizes[] = {1000, 10000, 100000};
55
-
56 utils::mkpath(utils::dirname(outfile));
+
56 utils::mkpath(utils::dirname(outfile));
57 ofile.open(outfile);
58 double t0, t1, t2;
59 for (int samples : sample_sizes) {
60 t0 = omp_get_wtime();
-
61 montecarlo::phase_transition(20, 2.1, 2.4, 40, samples,
-
62 montecarlo::mcmc_parallel, "/dev/null", 0);
+
61 montecarlo::phase_transition(20, 2.1, 2.4, 40, samples,
+
62 montecarlo::mcmc_parallel, "/dev/null", 0);
63 t1 = omp_get_wtime();
-
64 montecarlo::phase_transition(20, 2.1, 2.4, 40, samples,
-
65 montecarlo::mcmc_serial, "/dev/null", 0);
+
64 montecarlo::phase_transition(20, 2.1, 2.4, 40, samples,
+
65 montecarlo::mcmc_serial, "/dev/null", 0);
66 t2 = omp_get_wtime();
-
67 ofile << utils::scientific_format(samples) << ','
-
68 << utils::scientific_format(t1 - t0) << ','
-
69 << utils::scientific_format(t2 - t1) << '\n';
+
67 ofile << utils::scientific_format(samples) << ','
+
68 << utils::scientific_format(t1 - t0) << ','
+
69 << utils::scientific_format(t2 - t1) << '\n';
70 }
71 ofile.close();
72}
73
-
74/** @brief A function that displays how to use the program and quits.*/
-
75void usage(std::string filename)
+
75void usage(std::string filename)
76{
77 std::cout << "Usage: " << filename << " OPTION ...\n"
78 << "At least one option should be used.\n\n"
@@ -186,10 +171,9 @@ $(document).ready(function(){initNavTree('time_8cpp_source.html',''); initResiza
83 exit(-1);
84}
85
-
86/** @brief The main function.*/
-
87int main(int argc, char **argv)
+
87int main(int argc, char **argv)
88{
-
89 struct option long_options[] = {{"all", 0, 0, 0},
+
89 struct option long_options[] = {{"all", 0, 0, 0},
90 {"time-lattice-sizes", 0, 0, 0},
91 {"time-sample-sizes", 0, 0, 0},
92 {"help", 0, 0, 0},
@@ -208,38 +192,35 @@ $(document).ready(function(){initNavTree('time_8cpp_source.html',''); initResiza
105 case 0:
106 switch (option_index) {
107 case 0:
- - + +
110 break;
111 case 1:
- +
113 break;
114 case 2:
- +
116 break;
117 case 3: // Not a mistake. This just goes to the default.
118 default:
-
119 usage(argv[0]);
+
119 usage(argv[0]);
120 }
121 break;
-
122 case 'h':
+
122 case 'h':
123 default:
-
124 usage(argv[0]);
+
124 usage(argv[0]);
125 }
126 }
127
128 return 0;
129}
-
int main(int argc, char **argv)
The main function.
Definition: main.cpp:125
-
void usage(std::string filename)
A function that displays how to use the program and quits.
Definition: main.cpp:110
-
void phase_transition(int L, double start_T, double end_T, int points_T, int cycles, std::function< data_t(int, double, int, int)> monte_carlo, std::string outfile, int burn_in_time=BURN_IN_TIME)
Perform the MCMC algorithm using a range of temperatures.
-
data_t mcmc_parallel(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles in parallel.
-
data_t mcmc_serial(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles.
+
Header for the data_t type.
+
Functions for Monte Carlo simulations.
+
int main()
The main function.
Definition: test_suite.cpp:110
void time_lattice_sizes()
Time phase transition using different lattice sizes.
Definition: time.cpp:22
+
void usage(std::string filename)
A function that displays how to use the program and quits.
Definition: time.cpp:75
void time_sample_sizes()
Time phase transition using different sample sizes.
Definition: time.cpp:49
-
bool mkpath(std::string path, int mode=0777)
Make path given.
Definition: utils.cpp:32
-
std::string scientific_format(double d, int width=20, int prec=10)
Turns a double into a string written in scientific format.
Definition: utils.cpp:16
-
std::string dirname(const std::string &path)
Get the directory name of the path.
Definition: utils.cpp:58
+
Function prototypes and macros that are useful.
diff --git a/docs/utils_8cpp_source.html b/docs/utils_8cpp_source.html index 74ed3fb..b76ccda 100644 --- a/docs/utils_8cpp_source.html +++ b/docs/utils_8cpp_source.html @@ -101,20 +101,10 @@ $(document).ready(function(){initNavTree('utils_8cpp_source.html',''); initResiz
utils.cpp
-Go to the documentation of this file.
1/** @file utils.cpp
-
2 *
-
3 * @author Cory Alexander Balaton (coryab)
-
4 * @author Janita Ovidie Sandtrøen Willumsen (janitaws)
-
5 *
-
6 * @version 1.0
-
7 *
-
8 * @brief Implementation of the utils
-
9 *
-
10 * @bug No known bugs
-
11 * */
-
12#include "utils.hpp"
+Go to the documentation of this file.
1
+
12#include "utils.hpp"
13
-
14namespace utils {
+
14namespace utils {
15
16std::string scientific_format(double d, int width, int prec)
17{
@@ -123,11 +113,11 @@ $(document).ready(function(){initNavTree('utils_8cpp_source.html',''); initResiz
20 return ss.str();
21}
22
-
23std::string scientific_format(const std::vector<double> &v, int width, int prec)
+
23std::string scientific_format(const std::vector<double> &v, int width, int prec)
24{
25 std::stringstream ss;
26 for (double elem : v) {
-
27 ss << scientific_format(elem, width, prec);
+
27 ss << scientific_format(elem, width, prec);
28 }
29 return ss.str();
30}
@@ -136,14 +126,14 @@ $(document).ready(function(){initNavTree('utils_8cpp_source.html',''); initResiz
33{
34 std::string cur_dir;
35 std::string::size_type pos = -1;
-
36 struct stat buf;
+
36 struct stat buf;
37
-
38 if (path.back() != '/') {
-
39 path += '/';
+
38 if (path.back() != '/') {
+
39 path += '/';
40 }
41 while (true) {
42 pos++;
-
43 pos = path.find('/', pos);
+
43 pos = path.find('/', pos);
44 if (pos != std::string::npos) {
45 cur_dir = path.substr(0, pos);
46 if (mkdir(cur_dir.c_str(), mode) != 0
@@ -165,8 +155,8 @@ $(document).ready(function(){initNavTree('utils_8cpp_source.html',''); initResiz
62
63std::string concatpath(const std::string &left, const std::string &right)
64{
-
65 if (left.back() != '/' and right.front() != '/') {
-
66 return left + '/' + right;
+
65 if (left.back() != '/' and right.front() != '/') {
+
66 return left + '/' + right;
67 }
68 else {
69 return left + right;
@@ -174,9 +164,9 @@ $(document).ready(function(){initNavTree('utils_8cpp_source.html',''); initResiz
71}
72
73} // namespace utils
+
Function prototypes and macros that are useful.
bool mkpath(std::string path, int mode=0777)
Make path given.
Definition: utils.cpp:32
std::string scientific_format(double d, int width=20, int prec=10)
Turns a double into a string written in scientific format.
Definition: utils.cpp:16
-
std::string scientific_format(const std::vector< double > &v, int width=20, int prec=10)
Turns a vector of doubles into a string written in scientific format.
Definition: utils.cpp:23
std::string concatpath(const std::string &left, const std::string &right)
Take 2 strings and concatenate them and make sure there is a directory separator (/) between them.
Definition: utils.cpp:63
std::string dirname(const std::string &path)
Get the directory name of the path.
Definition: utils.cpp:58
diff --git a/docs/utils_8hpp.html b/docs/utils_8hpp.html index ee2413b..08da83b 100644 --- a/docs/utils_8hpp.html +++ b/docs/utils_8hpp.html @@ -153,7 +153,7 @@ Functions Janita Ovidie Sandtrøen Willumsen (janitaws)
Version
1.0

These utility function are mainly for convenience and aren't directly related to the project. Anything that is in the details namespace should not be used directly, or else it might cause undefined behavior if not used correctly.

-
Bug:
No known bugs
+
Bug:
No known bugs

Definition in file utils.hpp.

Macro Definition Documentation

diff --git a/docs/utils_8hpp_source.html b/docs/utils_8hpp_source.html index 84ff5bc..57d47cd 100644 --- a/docs/utils_8hpp_source.html +++ b/docs/utils_8hpp_source.html @@ -101,172 +101,57 @@ $(document).ready(function(){initNavTree('utils_8hpp_source.html',''); initResiz
utils.hpp
-Go to the documentation of this file.
1/** @file utils.hpp
-
2 *
-
3 * @author Cory Alexander Balaton (coryab)
-
4 * @author Janita Ovidie Sandtrøen Willumsen (janitaws)
-
5 *
-
6 * @version 1.0
-
7 *
-
8 * @brief Function prototypes and macros that are useful.
-
9 *
-
10 * These utility function are mainly for convenience and aren't directly
-
11 * related to the project. Anything that is in the details namespace should
-
12 * not be used directly, or else it might cause undefined behavior if not used
-
13 * correctly.
-
14 *
-
15 * @bug No known bugs
-
16 * */
-
17#ifndef __UTILS__
-
18#define __UTILS__
+Go to the documentation of this file.
1
+
17#ifndef __UTILS__
+
18#define __UTILS__
19
-
20#include <armadillo>
-
21#include <iomanip>
-
22#include <sstream>
-
23#include <string>
-
24#include <sys/stat.h>
-
25#include <vector>
+
20#include <armadillo>
+
21#include <iomanip>
+
22#include <sstream>
+
23#include <string>
+
24#include <sys/stat.h>
+
25#include <vector>
26
-
27/** @def DEBUG(msg)
-
28 * @brief Writes a debug message
-
29 *
-
30 * This macro writes a debug message that includes the filename,
-
31 * line number, and a custom message. The function is wrapped in an ifdef
-
32 * that checks if DBG is defined, so one can choose to display the debug
-
33 * messages by adding the -DDBG flag when compiling.
-
34 * */
-
35#ifdef DBG
-
36#define DEBUG(msg)
-
37 std::cout << __FILE__ << " " << __LINE__ << ": " << msg << std::endl
-
38#else
-
39#define DEBUG(msg)
-
40#endif
+
35#ifdef DBG
+
36#define DEBUG(msg) \
+
37 std::cout << __FILE__ << " " << __LINE__ << ": " << msg << std::endl
+
38#else
+
39#define DEBUG(msg)
+
40#endif
41
-
42/** @def __METHOD_NAME__
-
43 * @brief Get the name of the current method/function without the return type.
-
44 * */
-
45#define __METHOD_NAME__ details::methodName(__PRETTY_FUNCTION__)
+
45#define __METHOD_NAME__ details::methodName(__PRETTY_FUNCTION__)
46
-
47namespace details {
-
48/** @brief Takes in the __PRETTY_FUNCTION__ string and removes the return type.
-
49 *
-
50 * @details This function should only be used for the __METHOD_NAME__ macro,
-
51 * since it takes the output from __PRETTY_FUNCTION__ and strips the return
-
52 * type.
-
53 *
-
54 * @param pretty_function The string from __PRETTY_FUNCTION__
-
55 *
-
56 * @return std::string
-
57 * */
+
47namespace details {
58inline std::string methodName(const std::string &pretty_function)
59{
-
60 size_t colons = pretty_function.find("::");
-
61 size_t begin = pretty_function.substr(0, colons).rfind(" ") + 1;
-
62 size_t end = pretty_function.rfind("(") - begin;
+
60 size_t colons = pretty_function.find("::");
+
61 size_t begin = pretty_function.substr(0, colons).rfind(" ") + 1;
+
62 size_t end = pretty_function.rfind("(") - begin;
63
64 return pretty_function.substr(begin, end) + "()";
65}
66
67} // namespace details
68
-
69namespace utils {
+
69namespace utils {
70
-
71/** @brief Turns a double into a string written in scientific format.
-
72 *
-
73 * @details The code is stolen from https://github.com/anderkve/FYS3150.
-
74 *
-
75 * @param d The number to stringify
-
76 * @param width The reserved width of the string
-
77 * @param prec The precision of the stringified number
-
78 *
-
79 * @return std::string
-
80 * */
81std::string scientific_format(double d, int width = 20, int prec = 10);
82
-
83/** @brief Turns a vector of doubles into a string written in scientific
-
84 * format.
-
85 *
-
86 * @details The code is stolen from https://github.com/anderkve/FYS3150.
-
87 *
-
88 * @param v The vector to stringify
-
89 * @param width The reserved width of the string
-
90 * @param prec The precision of the stringified number
-
91 *
-
92 * @return std::string
-
93 * */
-
94std::string scientific_format(const std::vector<double> &v, int width = 20,
+
94std::string scientific_format(const std::vector<double> &v, int width = 20,
95 int prec = 10);
96
-
97/** @brief Make path given.
-
98 *
-
99 * @details This tries to be the equivalent to "mkdir -p" and creates a new
-
100 * directory whenever it needs to.
-
101 *
-
102 * @param path The path to be created
-
103 * @param mode The mode/permissions for all the new directories
-
104 *
-
105 * @return bool Success/Fail
-
106 * */
107bool mkpath(std::string path, int mode = 0777);
108
-
109/** @brief Get the directory name of the path
-
110 *
-
111 * @param path The path to use.
-
112 *
-
113 * @return string
-
114 * */
115std::string dirname(const std::string &path);
116
-
117/** @brief Take 2 strings and concatenate them and make sure there is a
-
118 * directory separator (/) between them.
-
119 *
-
120 * @details This function doesn't care whether or not the values given as
-
121 * parameters are valid path strings. It is the responsibility of the user to make
-
122 * sure that the values given are valid path strings.
-
123 * The function only guarantees that the output string is a valid path string.
-
124 *
-
125 * @param left The left hand side of the result string
-
126 * @param right The right hand side of the result string
-
127 *
-
128 * @return string
-
129 * */
130std::string concatpath(const std::string &left, const std::string &right);
131
132} // namespace utils
133
-
134#endif
-
#define UP
Used for the neighbor matrix in the class.
Definition: IsingModel.hpp:26
-
#define INDEX(I, N)
I modulo N.
Definition: IsingModel.hpp:23
-
#define DOWN
Used for the neighbor matrix in the class.
Definition: IsingModel.hpp:28
-
#define LEFT
Used for the neighbor matrix in the class.
Definition: IsingModel.hpp:27
-
#define RIGHT
Used for the neighbor matrix in the class.
Definition: IsingModel.hpp:29
-
Test class for the Ising model.
Definition: test_suite.cpp:36
-
The Ising model in 2 dimensions.
Definition: IsingModel.hpp:36
-
std::mt19937 engine
The RNG that is used for the Metropolis algorithm.
Definition: IsingModel.hpp:78
-
int64_t E
The current energy state. unit: .
Definition: IsingModel.hpp:70
-
double T
The temperature of the model.
Definition: IsingModel.hpp:62
-
int L
Size of the lattice.
Definition: IsingModel.hpp:66
-
arma::Mat< int > lattice
matrix where element .
Definition: IsingModel.hpp:44
-
void initialize_lattice()
Initialize the lattice with a random distribution of 1s and -1s.
Definition: IsingModel.cpp:49
-
IsingModel(int L, double T, int val)
Constructor for the Ising model.
Definition: IsingModel.cpp:31
-
IsingModel(int L, double T)
Constructor for the Ising model.
Definition: IsingModel.cpp:19
-
data_t Metropolis()
The Metropolis algorithm.
Definition: IsingModel.cpp:110
-
void initialize_energy()
Initialize the energy of the system.
Definition: IsingModel.cpp:96
-
void initialize_neighbors()
initialize the neighbors matrix.
Definition: IsingModel.cpp:70
-
double energy_diff[17]
An array containing all possible energy differences.
Definition: IsingModel.hpp:58
-
void initialize_magnetization()
Initialize the magnetization of the system.
Definition: IsingModel.cpp:88
-
arma::Mat< int > neighbors
matrix with the neighbors of each element .
Definition: IsingModel.hpp:54
-
void initialize_engine()
Initialize the RNG.
Definition: IsingModel.cpp:43
-
void initialize_lattice(int val)
Initialize the lattice with a specific value.
Definition: IsingModel.cpp:59
-
IsingModel()
Constructor used for testing.
Definition: IsingModel.cpp:14
-
int64_t M
The current magnetic strength. unit: Unitless.
Definition: IsingModel.hpp:74
-
void initialize_energy_diff()
Initialize the energy_diff array with the correct values.
Definition: IsingModel.cpp:81
-
Type to use with the IsingModel class and montecarlo module.
Definition: data_type.hpp:19
-
data_t(double E, double E2, double M, double M2, double M_abs)
Constructor with parameters.
Definition: data_type.hpp:45
+
134#endif
std::string methodName(const std::string &pretty_function)
Takes in the PRETTY_FUNCTION string and removes the return type.
Definition: utils.hpp:58
bool mkpath(std::string path, int mode=0777)
Make path given.
Definition: utils.cpp:32
std::string scientific_format(double d, int width=20, int prec=10)
Turns a double into a string written in scientific format.
Definition: utils.cpp:16
-
std::string scientific_format(const std::vector< double > &v, int width=20, int prec=10)
Turns a vector of doubles into a string written in scientific format.
Definition: utils.cpp:23
std::string concatpath(const std::string &left, const std::string &right)
Take 2 strings and concatenate them and make sure there is a directory separator (/) between them.
Definition: utils.cpp:63
std::string dirname(const std::string &path)
Get the directory name of the path.
Definition: utils.cpp:58