Update code

This commit is contained in:
2023-11-21 11:24:34 +01:00
parent 816e38e9e4
commit f07fb8829b
12 changed files with 522 additions and 343 deletions

View File

@@ -18,31 +18,21 @@
#include <functional>
#include <string>
#include <omp.h>
#define BURN_IN_TIME 1000
//#define BURN_IN_TIME 12500
#define BURN_IN_TIME 5000
#define EPS_2 (-2 * std::sinh(8.)) / (std::cosh(8.) + 3)
#define MAG_2 (std::exp(8.) + 1) / (2 * cosh(8.) + 3)
#define CV_2 \
16 \
* (3 * std::cosh(8.) + std::cosh(8.) * std::cosh(8.) \
- std::sinh(8.) * std::sinh(8.)) \
/ ((std::cosh(8.) + 3) * (std::cosh(8.) + 3))
#define X_2 \
(3 * std::exp(8.) + std::exp(-8.) + 3) \
/ ((std::cosh(8.) + 3) * (std::cosh(8.) + 3))
#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 uint
* return int
* */
uint test_2x2_lattice(double tol, uint max_cycles);
int test_2x2_lattice(double tol, int max_cycles);
/** @brief Write the expected values for each Monte Carlo cycles to file.
*
@@ -51,7 +41,18 @@ uint test_2x2_lattice(double tol, uint 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, uint L, uint cycles,
void monte_carlo_progression(double T, int L, int cycles,
const std::string filename);
/** @brief Write the expected values for each Monte Carlo cycles to file.
*
* @param T Temperature
* @param L The size of the lattice
* @param cycles The amount of Monte Carlo cycles to do
* @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);
/** @brief Estimate the probability distribution for the energy.
@@ -61,26 +62,29 @@ void monte_carlo_progression(double T, uint L, uint cycles,
* @param cycles The amount of Monte Carlo cycles to do
* @param filename The file to write to
* */
void pd_estimate(double T, uint L, uint 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
/** @brief Execute the Metropolis algorithm for a certain amount of Monte
* Carlo cycles.
*
* @param data The data to store the results
* @param L The size of the lattice
* @param T The Temperature for the Ising model
* @param cycles The amount of Monte Carlo cycles to do*/
void monte_carlo_serial(data_t &data, uint L, double T, uint cycles);
/** @brief Execute the Metropolis algorithm for a certain amount of Monte
* Carlo cycles in parallel.
*
* @param data The data to store the results
* @param L The size of the lattice
* @param T The Temperature for the Ising model
* @param cycles The amount of Monte Carlo cycles to do
*
* @return data_t
* */
void monte_carlo_parallel(data_t &data, uint L, double T, uint cycles);
data_t monte_carlo_serial(int L, double T, int cycles);
/** @brief Execute the Metropolis algorithm for a certain amount of Monte
* Carlo cycles in parallel.
*
* @param L The size of the lattice
* @param T The Temperature for the Ising model
* @param cycles The amount of Monte Carlo cycles to do
*
* @return data_t
* */
data_t monte_carlo_parallel(int L, double T, int cycles);
/** @brief Perform the MCMC algorithm using a range of temperatures.
*
@@ -92,8 +96,8 @@ void monte_carlo_parallel(data_t &data, uint L, double T, uint cycles);
* @param outfile The file to write the data to
* */
void phase_transition(
uint L, double start_T, double end_T, uint points_T,
std::function<void(data_t &, uint, double, uint)> monte_carlo,
int L, double start_T, double end_T, int points_T,
std::function<data_t(int, double, int)> monte_carlo,
std::string outfile);
#endif