-
Notifications
You must be signed in to change notification settings - Fork 3
/
spins.h
90 lines (59 loc) · 1.39 KB
/
spins.h
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef SPINS_H
#define SPINS_H
// spins.h
// a small class that contains a vector of lattice Ising spins
#include <vector>
#include <iostream>
#include "MersenneTwister.h"
using namespace std;
class Spins
{
public:
int N_; //total number of lattice sites
//the lattice is a vector of vectors: no double counting
vector<int> spin;
//public functions
Spins(int N);
Spins();
void resize(int N);
void flip(int index);
void print();
void randomize();
};
//constructor 1
//takes the total number of lattice sites
Spins::Spins(){
spin.clear();
}
//constructor 2
//takes the total number of lattice sites
Spins::Spins(int N){
N_ = N;
spin.resize(N_,1); //assign every spin as 1
}
//takes the total number of lattice sites
void Spins::resize(int N){
N_ = N;
spin.resize(N_,1); //assign every spin as 1
}
void Spins::randomize(){
MTRand irand(129345); //random number
int ising_spin;
for (int i = 0; i<spin.size(); i++){
ising_spin = 2*irand.randInt(1)-1;
//cout<<ising_spin<<" ";
spin.at(i) = ising_spin;
}
}//randomize
//a single-spin flip
void Spins::flip(int index){
spin.at(index) *= -1;
}//flip
//a print function
void Spins::print(){
for (int i=0;i<spin.size();i++){
cout<<(spin[i]+1)/2<<" ";
}//i
cout<<endl;
}//print
#endif