2 Dimensional Ising Model
Simulate the change in energy and magnetization in a ferro magnet
Loading...
Searching...
No Matches
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__
14
15#include "IsingModel.hpp"
16#include "data_type.hpp"
17#include "utils.hpp"
18
19#include <functional>
20#include <omp.h>
21#include <string>
22
23// #define BURN_IN_TIME 12500
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 * */
35void progression(double T, int L, int cycles, const std::string filename,
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);
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);
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);
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);
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);
101}; // namespace montecarlo
102
103#endif
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 anbd 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:53
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:91