-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsim.hpp
59 lines (45 loc) · 1.39 KB
/
sim.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef SIM_HPP
#define SIM_HPP
#include <valarray>
#include <random>
#include <fstream>
#include <string>
#include "utils.hpp"
#include "config.hpp"
class Sim
{
public:
Sim(size_t N, size_t Nmeasure, double Nthermal, double stride
, std::string const& filename, double temperature, double kb, double J
, Vec H, bool ferroStart, std::string const& outstate, std::string const& intstate);
Sim(Config const& params);
void run();
double energy() const;
Spin magnetization() const;
private:
// Return the right index using periodic boundary conditions
size_t index(int i, int j, int k) const;
size_t index(std::valarray<size_t> v) const;
// Run it without storing any informations
void quietRun(size_t Nsteps);
// Compute only the difference in energy
double deltaE(std::valarray<size_t> site, Spin const& newSpin) const;
// Store and load the state of the simulation
void storeState(std::string const& filename) const;
void loadState(std::string const& filename);
// Simulation params
size_t _N; // Size of our system along one dimension
size_t _Nmeasure;
size_t _Nthermal;
size_t _stride;
std::ofstream _out;
std::string _outstate;
// Physical params
double _kbT; // Temperature (in energy units)
double _J;
Vec _H;
Grid3D<Spin> _spins;
double _energy;
Vec _magnetization;
};
#endif