Make changes
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#include "utils.hpp"
|
||||
|
||||
#include <armadillo>
|
||||
#include <cstdint>
|
||||
#include <random>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -53,7 +54,8 @@ private:
|
||||
|
||||
/** @brief A hash map containing all possible energy changes.
|
||||
* */
|
||||
std::unordered_map<int, double> energy_diff;
|
||||
//std::unordered_map<int, double> energy_diff;
|
||||
double energy_diff[17];
|
||||
|
||||
/** @brief The temperature of the model.
|
||||
* */
|
||||
@@ -65,12 +67,15 @@ private:
|
||||
|
||||
/** @brief The current energy state. unit: \f$ J \f$.
|
||||
* */
|
||||
int E;
|
||||
int64_t E;
|
||||
|
||||
/** @brief The current magnetic strength. unit: Unitless.
|
||||
* */
|
||||
int M;
|
||||
int64_t M;
|
||||
|
||||
std::mt19937 engine;
|
||||
|
||||
void initialize_engine();
|
||||
/** @brief Initialize the lattice with a random distribution of 1s and
|
||||
* -1s.
|
||||
* */
|
||||
|
||||
@@ -49,7 +49,7 @@ public:
|
||||
return res;
|
||||
}
|
||||
|
||||
template <class T> data_t& operator/=(T num)
|
||||
template <class T> data_t &operator/=(T num)
|
||||
{
|
||||
this->E /= (double)num;
|
||||
this->E2 /= (double)num;
|
||||
@@ -72,7 +72,7 @@ public:
|
||||
return res;
|
||||
}
|
||||
|
||||
template <class T> data_t& operator*=(T num)
|
||||
template <class T> data_t &operator*=(T num)
|
||||
{
|
||||
this->E *= (double)num;
|
||||
this->E2 *= (double)num;
|
||||
@@ -95,7 +95,7 @@ public:
|
||||
return res;
|
||||
}
|
||||
|
||||
data_t& operator+=(const data_t &b)
|
||||
data_t &operator+=(const data_t &b)
|
||||
{
|
||||
this->E += b.E;
|
||||
this->E2 += b.E2;
|
||||
@@ -116,4 +116,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
#pragma omp declare reduction(+ : data_t : omp_out += omp_in)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*
|
||||
* @version 1.0
|
||||
*
|
||||
* @brief Functions for monte carlo simulations.
|
||||
* @brief Functions for Monte Carlo simulations.
|
||||
*
|
||||
* @bug No known bugs
|
||||
* */
|
||||
@@ -17,23 +17,13 @@
|
||||
#include "utils.hpp"
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <omp.h>
|
||||
#include <string>
|
||||
|
||||
//#define BURN_IN_TIME 12500
|
||||
// #define BURN_IN_TIME 12500
|
||||
#define BURN_IN_TIME 5000
|
||||
|
||||
#pragma omp declare reduction(+: data_t: omp_out += omp_in)
|
||||
|
||||
/** @brief Test numerical data with analytical data.
|
||||
*
|
||||
* @param tol The tolerance between the analytical and numerical solution.
|
||||
* @param max_cycles The max number of Monte Carlo cycles.
|
||||
*
|
||||
* return int
|
||||
* */
|
||||
int test_2x2_lattice(double tol, int max_cycles);
|
||||
|
||||
namespace montecarlo {
|
||||
/** @brief Write the expected values for each Monte Carlo cycles to file.
|
||||
*
|
||||
* @param T Temperature
|
||||
@@ -41,8 +31,8 @@ int test_2x2_lattice(double tol, int max_cycles);
|
||||
* @param cycles The amount of Monte Carlo cycles to do
|
||||
* @param filename The file to write to
|
||||
* */
|
||||
void monte_carlo_progression(double T, int L, int cycles,
|
||||
const std::string filename);
|
||||
void progression(double T, int L, int cycles,
|
||||
const std::string filename);
|
||||
|
||||
/** @brief Write the expected values for each Monte Carlo cycles to file.
|
||||
*
|
||||
@@ -52,8 +42,8 @@ void monte_carlo_progression(double T, int L, int cycles,
|
||||
* @param value The value to set the elements in the lattice
|
||||
* @param filename The file to write to
|
||||
* */
|
||||
void monte_carlo_progression(double T, int L, int cycles, int value,
|
||||
const std::string filename);
|
||||
void progression(double T, int L, int cycles, int value,
|
||||
const std::string filename);
|
||||
|
||||
/** @brief Estimate the probability distribution for the energy.
|
||||
*
|
||||
@@ -62,7 +52,8 @@ void monte_carlo_progression(double T, int L, int cycles, int value,
|
||||
* @param cycles The amount of Monte Carlo cycles to do
|
||||
* @param filename The file to write to
|
||||
* */
|
||||
void pd_estimate(double T, int L, int cycles, const std::string filename);
|
||||
void pd_estimate(double T, int L, int cycles,
|
||||
const std::string filename);
|
||||
|
||||
/** @brief Execute the Metropolis algorithm for a certain amount of Monte
|
||||
* Carlo cycles.
|
||||
@@ -73,7 +64,7 @@ void pd_estimate(double T, int L, int cycles, const std::string filename);
|
||||
*
|
||||
* @return data_t
|
||||
* */
|
||||
data_t monte_carlo_serial(int L, double T, int cycles);
|
||||
data_t mcmc_serial(int L, double T, int cycles, int burn_in_time = BURN_IN_TIME);
|
||||
|
||||
/** @brief Execute the Metropolis algorithm for a certain amount of Monte
|
||||
* Carlo cycles in parallel.
|
||||
@@ -84,7 +75,7 @@ data_t monte_carlo_serial(int L, double T, int cycles);
|
||||
*
|
||||
* @return data_t
|
||||
* */
|
||||
data_t monte_carlo_parallel(int L, double T, int cycles);
|
||||
data_t mcmc_parallel(int L, double T, int cycles, int burn_in_time = BURN_IN_TIME);
|
||||
|
||||
/** @brief Perform the MCMC algorithm using a range of temperatures.
|
||||
*
|
||||
@@ -95,9 +86,10 @@ data_t monte_carlo_parallel(int L, double T, int cycles);
|
||||
* @param monte_carlo Which Monte Carlo implementation to use
|
||||
* @param outfile The file to write the data to
|
||||
* */
|
||||
void phase_transition(
|
||||
int L, double start_T, double end_T, int points_T,
|
||||
std::function<data_t(int, double, int)> monte_carlo,
|
||||
std::string outfile);
|
||||
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);
|
||||
}; // namespace montecarlo
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user