Repository navigation
Expand file tree
/
Copy pathising_model.cc
More file actions
159 lines (138 loc) · 3.36 KB
/
Copy pathising_model.cc
File metadata and controls
159 lines (138 loc) · 3.36 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//C++ STD
#include <stdio.h>
#include <math.h>
#include <cmath>
#include <stdlib.h>
#include <iostream>
#include <fstream>
using namespace std;
double PI = 2. * asin(1.0);
int big_X[1000][50];
int big_Y[1000][50];
double boltz(double E,double T){
double k = 1.0;//8.617*pow(10,-5);
return exp(-E/(k*T));
}
int getRandomNumber(int min, int max){
static const double fraction = 1.0 / (static_cast<double>(RAND_MAX) + 1.0);
return static_cast<int>(rand() * fraction * (max - min + 1) + min);
}
void set_string(){
for (size_t j = 0; j < 1000; j++) {
for (size_t i = 0; i < 50; i++) {
int v = getRandomNumber(0,1);
if(v == 0)v=-1;
big_X[j][i] = v;
big_Y[j][i] = v;
}
}
}
double calc_X_E(int k){
double buff = 0.0;
for (size_t i = 0; i < 50; i++) {
if(i < 49){
buff = buff + big_X[k][i]*big_X[k][i+1];
}
else{
buff = buff + big_X[k][49]*big_X[k][0];
}
}
return -buff;
}
double calc_Y_E(int k){
double buff = 0.0;
for (size_t i = 0; i < 50; i++) {
if(i < 49){
buff = buff + big_Y[k][i]*big_Y[k][i+1];
}
else{
buff = buff + big_Y[k][49]*big_Y[k][0];
}
}
return -buff;
}
double calc_avg_E(){
double buff = 0.0;
for (size_t k = 0; k < 1000; k++) {
buff = buff + calc_X_E(k);
}
return buff/1000.0;
}
double calc_avg_E2(){
double buff = 0.0;
for (size_t k = 0; k < 1000; k++) {
double cE = calc_X_E(k);
buff = buff + cE*cE;
}
return buff/1000.0;
}
double calc_M(int k){
double buff = 0.0;
for (size_t i = 0; i < 50; i++) {
buff = buff + big_X[k][i];
}
return -buff;
}
double calc_avg_M(){
double buff = 0.0;
for (size_t k = 0; k < 1000; k++) {
buff = buff + calc_M(k);
}
return buff/1000.0;
}
double calc_avg_M2(){
double buff = 0.0;
for (size_t k = 0; k < 1000; k++) {
double cM = calc_M(k);
buff = buff + cM*cM;
}
return buff/1000.0;
}
double calc_epsilon(){
return calc_avg_E()/50.;
}
double calc_c(double T){
return (calc_avg_E2() - pow(calc_avg_E(),2))/(50.0 * T*T);
}
double calc_m(){
return calc_avg_M()/50.;
}
double calc_chi(double T){
return (calc_avg_M2() - pow(calc_avg_M(),2))/(50.0 * T);
}
void reset_string(double T){
for (size_t i = 0; i < 1000; i++) {
int j = getRandomNumber(0,49);
big_Y[i][j] = big_Y[i][j] * -1;
double del_E = calc_Y_E(i) - calc_X_E(i);
double X0 = (((double) getRandomNumber(0,10000000))/10000000.);
double B0 = boltz(del_E,T);
if(del_E < 0){
big_X[i][j] = big_X[i][j] * -1;
}
else if(X0 < B0){
big_X[i][j] = big_X[i][j] * -1;
}
else{
big_Y[i][j] = big_Y[i][j] * -1;
}
}
}
void RW_int(){
ofstream fs;
fs.open("/home/jpond/workspace/ComputationalPhysics/dataFiles/a.dat");
for (double i = 0.1; i < 5.1; i += .1){
for (size_t j = 0; j < 1000000; j++) {
reset_string(i);
}
fs << i << "\t" << calc_epsilon() << "\t" << calc_c(i) << "\t" << calc_m() << "\t" << calc_chi(i) << endl;
set_string();
}
fs.close();
}
int main(int argc, char const *argv[]) {
srand(time(0));
set_string();
RW_int();
return 0;
}