Update documentation

This commit is contained in:
2023-12-04 22:23:55 +01:00
parent d318491dfe
commit b20fe658b9
15 changed files with 132 additions and 171 deletions

View File

@@ -12,9 +12,7 @@
#ifndef __ISING_MODEL__
#define __ISING_MODEL__
#include "constants.hpp"
#include "data_type.hpp"
#include "typedefs.hpp"
#include "utils.hpp"
#include <armadillo>
@@ -22,13 +20,13 @@
#include <random>
#include <unordered_map>
#define INDEX(I, N) (I + N) % N
#define INDEX(I, N) (I + N) % N ///< I modulo N
// Indeces for the neighbor matrix.
#define UP 0
#define LEFT 0
#define DOWN 1
#define RIGHT 1
#define UP 0 ///< Used for the neighbor matrix in the class
#define LEFT 0 ///< Used for the neighbor matrix in the class
#define DOWN 1 ///< Used for the neighbor matrix in the class
#define RIGHT 1 ///< Used for the neighbor matrix in the class
/** @brief The Ising model in 2 dimensions.
*
@@ -37,7 +35,10 @@
* */
class IsingModel {
private:
/** @brief Give access to private members to the test class IsingModelTest.
* */
friend class IsingModelTest;
/** @brief \f$ L \times L \f$ matrix where element \f$ x \in {-1, 1}\f$.
* */
arma::Mat<int> lattice;
@@ -52,9 +53,8 @@ private:
* */
arma::Mat<int> neighbors;
/** @brief A hash map containing all possible energy changes.
/** @brief An array containing all possible energy differences.
* */
//std::unordered_map<int, double> energy_diff;
double energy_diff[17];
/** @brief The temperature of the model.
@@ -73,27 +73,36 @@ private:
* */
int64_t M;
/** @brief The RNG that is used for the Metropolis algorithm
* */
std::mt19937 engine;
/** @brief Initialize the RNG.
* */
void initialize_engine();
/** @brief Initialize the lattice with a random distribution of 1s and
* -1s.
* */
void initialize_lattice();
/** @brief Initialize the lattice with a specific value.
* */
void initialize_lattice(int val);
/** @brief initialize the neighbors matrix.
* */
void initialize_neighbors();
/** @brief Initialize the hashmap with the correct values.
/** @brief Initialize the energy_diff array with the correct values.
* */
void initialize_energy_diff();
/** @brief Initialize the magnetization.
/** @brief Initialize the magnetization of the system.
* */
void initialize_magnetization();
/** @brief Initialize the energy.
/** @brief Initialize the energy of the system.
* */
void initialize_energy();
@@ -120,18 +129,6 @@ public:
/** @brief The Metropolis algorithm.
* */
data_t Metropolis();
/** @brief Get the current energy.
*
* @return double
* */
int get_E();
/** @brief Get the current magnetization.
*
* @return double
* */
int get_M();
};
#endif

View File

@@ -1,19 +0,0 @@
/** @file constants.hpp
*
* @author Cory Alexander Balaton (coryab)
* @author Janita Ovidie Sandtrøen Willumsen (janitaws)
*
* @version 1.0
*
* @brief Library of constants
*
* @bug No known bugs
* */
#ifndef __CONST__
#define __CONST__
/** @brief Boltzmann constant. unit \f$ \frac{J}{K} \f$.
* */
#define k_B 1.380649e-23
#endif

View File

@@ -15,10 +15,17 @@
#include <sys/types.h>
#include <type_traits>
/** @brief Type to use with the IsingModel class and montecarlo module.*/
class data_t {
public:
double E, M, E2, M2, M_abs;
double E; ///< Energy
double M; ///< Magnetization
double E2; ///< Energy squared
double M2; ///< Magnetization squared
double M_abs; ///< Absolute Magnetization
/** @brief constructor with no parameters.
* */
data_t()
{
this->E = 0.;
@@ -28,6 +35,13 @@ public:
this->M_abs = 0.;
}
/** @brief Constructor with parameters.
*
* @param E Initial energy
* @param E2 Initial energy squared
* @param M Initial magnetization
* @param M2 Initial magnetization squared
* @param M_abs Initial absolute magnetization*/
data_t(double E, double E2, double M, double M2, double M_abs)
{
this->E = E;
@@ -37,6 +51,12 @@ public:
this->M_abs = M_abs;
}
/** @brief Overload of the division operator.
*
* @param num The number to divide each field by.
*
* @return data_t
* */
template <class T> data_t operator/(T num)
{
data_t res;
@@ -49,6 +69,13 @@ public:
return res;
}
/** @brief Overload of the division equals operator.
*
* @param num The number to divide each field by.
*
* @return data_t
* */
template <class T> data_t &operator/=(T num)
{
this->E /= (double)num;
@@ -60,6 +87,12 @@ public:
return *this;
}
/** @brief Overload of the multiply operator.
*
* @param num The number to multiply each field by.
*
* @return data_t
* */
template <class T> data_t operator*(T num)
{
data_t res;
@@ -72,6 +105,12 @@ public:
return res;
}
/** @brief Overload of the multiply equals operator.
*
* @param num The number to multiply each field by.
*
* @return data_t
* */
template <class T> data_t &operator*=(T num)
{
this->E *= (double)num;
@@ -83,6 +122,13 @@ public:
return *this;
}
/** @brief Overload of the addition operator.
*
* @param b The data_t field to add.
*
* @return data_t
* */
data_t operator+(const data_t &b)
{
data_t res;
@@ -95,6 +141,12 @@ public:
return res;
}
/** @brief Overload of the addition equals operator.
*
* @param b The data_t field to add.
*
* @return data_t
* */
data_t &operator+=(const data_t &b)
{
this->E += b.E;
@@ -105,17 +157,9 @@ public:
return *this;
}
template <class T> void operator=(T num)
{
this->E = (double)num;
this->E2 = (double)num;
this->M = (double)num;
this->M2 = (double)num;
this->M_abs = (double)num;
}
};
// Declare a custom reduction for the data_t type.
#pragma omp declare reduction(+ : data_t : omp_out += omp_in)
#endif

View File

@@ -30,6 +30,7 @@ namespace montecarlo {
* @param L The size of the lattice
* @param cycles The amount of Monte Carlo cycles to do
* @param filename The file to write to
* @param burn_in_time The burn-in time to use
* */
void progression(double T, int L, int cycles, const std::string filename,
int burn_in_time = BURN_IN_TIME);
@@ -41,6 +42,7 @@ void progression(double T, int L, int cycles, const std::string filename,
* @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
* @param burn_in_time The burn-in time to use
* */
void progression(double T, int L, int cycles, int value,
const std::string filename, int burn_in_time = BURN_IN_TIME);
@@ -51,6 +53,7 @@ void progression(double T, int L, int cycles, int value,
* @param L The size of the lattice
* @param cycles The amount of Monte Carlo cycles to do
* @param filename The file to write to
* @param burn_in_time The burn-in time to use
* */
void pd_estimate(double T, int L, int cycles, const std::string filename,
int burn_in_time = BURN_IN_TIME);
@@ -61,6 +64,7 @@ void pd_estimate(double T, int L, int cycles, const std::string filename,
* @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
* @param burn_in_time The burn-in time to use
*
* @return data_t
* */
@@ -73,6 +77,7 @@ data_t mcmc_serial(int L, double T, int cycles,
* @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
* @param burn_in_time The burn-in time to use
*
* @return data_t
* */
@@ -87,6 +92,7 @@ data_t mcmc_parallel(int L, double T, int cycles,
* @param point_T The amount of point to measure
* @param monte_carlo Which Monte Carlo implementation to use
* @param outfile The file to write the data to
* @param burn_in_time The burn-in time to use
* */
void phase_transition(int L, double start_T, double end_T, int points_T,
int cycles,

View File

@@ -8,7 +8,7 @@
* @brief A small test library.
*
* @details 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
* 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
@@ -32,6 +32,7 @@
details::m_assert(expr, #expr, __METHOD_NAME__, __FILE__, __LINE__, msg)
namespace details {
/** @brief Test an expression, confirm that test is ok, or abort execution.
*
* @details This function takes in an expression and prints an OK message if
@@ -49,6 +50,7 @@ void m_assert(bool expr, std::string expr_str, std::string func,
} // namespace details
namespace testlib {
/** @brief Test if two armadillo matrices/vectors are close to each other.
*
* @details This function takes in 2 matrices/vectors and checks if they are

View File

@@ -1,18 +0,0 @@
/** @file typedefs.hpp
*
* @author Cory Alexander Balaton (coryab)
* @author Janita Ovidie Sandtrøen Willumsen (janitaws)
*
* @version 1.0
*
* @brief Useful typedefs for cleaner code.
*
* @details These typedefs make the code more readable and easy to follow
* along.
*
* @bug No known bugs
* */
#ifndef __TYPEDEFS__
#define __TYPEDEFS__
#endif