15void progression(
double T,
int L,
int cycles,
const std::string filename,
23 std::string directory = utils::dirname(filename);
29 utils::mkpath(directory);
32 for (
size_t i = 0; i < burn_in_time; i++) {
37 for (
size_t i = 1; i <= cycles; i++) {
39 tmp = data / (i * n_spins);
40 ofile << i <<
',' << tmp.
E <<
',' << tmp.
E2 <<
',' << tmp.
M <<
','
41 << tmp.
M2 <<
',' << tmp.
M_abs <<
'\n';
47 const std::string filename,
int burn_in_time)
54 std::string directory = utils::dirname(filename);
59 for (
size_t i = 0; i < burn_in_time; i++) {
64 utils::mkpath(directory);
68 for (
size_t i = 1; i <= cycles; i++) {
70 tmp = data / (i * n_spins);
71 ofile << i <<
',' << tmp.
E <<
',' << tmp.
E2 <<
',' << tmp.
M <<
','
72 << tmp.
M2 <<
',' << tmp.
M_abs <<
'\n';
77void pd_estimate(
double T,
int L,
int cycles,
const std::string filename,
85 std::string directory = utils::dirname(filename);
90 for (
size_t i = 0; i < burn_in_time; i++) {
95 utils::mkpath(directory);
99 for (
size_t i = 1; i <= cycles; i++) {
101 ofile << data.
E <<
',' << data.
E2 <<
',' << data.
M <<
',' << data.
M2
102 <<
',' << data.
M_abs <<
'\n';
113 for (
size_t i = 0; i < burn_in_time; i++) {
118 for (
size_t i = 0; i < (uint)cycles; i++) {
122 double norm = 1. / (double)cycles;
137 for (
size_t i = 0; i < burn_in_time; i++) {
144#pragma omp for schedule(static) reduction(+ : data)
145 for (
size_t i = 0; i < (uint)cycles; i++) {
150 double norm = 1. / (double)cycles;
156 std::function<
data_t(
int,
double,
int,
int)> monte_carlo,
157 std::string outfile,
int burn_in_time)
159 double dt = (end - start) / (
double)points;
165 utils::mkpath(utils::dirname(outfile));
168 double temp, CV, X, E_var, M_var;
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;
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';
The Ising model in 2 dimensions.
data_t Metropolis()
The Metropolis algorithm.
Type to use with the IsingModel class and montecarlo module.
double M_abs
Absolute Magnetization.
double M2
Magnetization squared.
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.
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.