-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcurrent-energy_tasep_interactions.cpp
284 lines (258 loc) · 7.22 KB
/
current-energy_tasep_interactions.cpp
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/**********************************************************************************************************
* Copyright (C) 2014
* Authors: Hamid Teimouri & Daniel Celis
* Rice university--Department of Chemistry
* This file is distributed under the terms of the
* GNU General Public License as published by the
* Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
* http://www.gnu.org/copyleft/gpl.txt
************************************************************************************************************/
//===========================================================================================================//
// Monte Carlo Siumulation of totally asymmetric simple exclusion process (TASEP) with interacting particles //
//===================================== Current vs. Interaction energy ======================================//
//===========================================================================================================//
#include <omp.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstring>
#include <math.h>
#include <time.h>
#include <numeric>
#include <cstdlib>
#include <vector>
#include <valarray>
#include <algorithm>
#include <cstddef>
#include <iomanip>
#include <ctime>
#include <cmath>
#include "ran3.h"
#define MBIG 1000000000
#define MSEED 161803398
#define MZ 0
#define FAC (1.0/MBIG)
using std::vector;
using namespace std;
long int dum;
const int L = 100;
long double T = 1e4;
long double Teq = T * 0.2;
long double Tdif = T - Teq;
long double dt = 0.1;
long double t;
int site;
int prevsite;
int nextsite;
int nnextsite;
long double J;
long double alpha;
long double beta;
long double epsilon;
long double eps_min;
long double eps_max;
long double deps;
long double theta;
long double q;
long double r;
long double lattice[L+2], p[L+1];
long double n_i_enter, i_enter, n_i_eject, i_eject, n_i_hop, q_hop, r_hop;
int j;
///////////////////////// Functions.////////////////////////
void initialise()
{
J = 0.0;
lattice[0] = 0;
lattice[L+1] = 0;
for(j = 1;j<=L;j++)
{
lattice[j]=0; p[j]=1;
}
n_i_enter = dt*alpha*p[1];
i_enter = q*n_i_enter;
n_i_eject = dt*beta*p[L];
i_eject = r*n_i_eject;
n_i_hop = dt*p[L/2];
q_hop = dt*q*p[L/2];
r_hop = dt*r*p[L/2];
}
void boundary_interactions()
{
if (site == 1 && lattice[site] == 0)
{
// Injection with rate alpha if in state (0,0)
if (lattice[nextsite] == 0 && ran3(&dum) <= n_i_enter)
{
lattice[site] = 1;
}
// Injection with rate q*alpha if in state (0,1) => Binding
if (lattice[nextsite] == 1 && ran3(&dum) <= i_enter)
{
lattice[site] = 1;
}
}
if (site == L && lattice[site] == 1)
{
// Ejection rate beta if in state (0,1)
if (lattice[prevsite] == 0 && ran3(&dum) <= n_i_eject)
{
lattice[site] = 0;
}
// Ejection rate r*beta if in state (1,1) => Disassociation
if (lattice[prevsite] == 1 && ran3(&dum) <= i_eject)
{
lattice[site] = 0;
}
}
}
void move()
{
for(j = 1; j <= L; j++)
{
site = rand()%L + 1;
prevsite = site - 1;
nextsite = site + 1;
nnextsite = nextsite + 1;
boundary_interactions();
if (lattice[site] == 1 && lattice[nextsite] == 0 && site >= 1 && site <= L-1)
{
if (lattice[prevsite] == lattice[nnextsite] && ran3(&dum) <= n_i_hop) // Bulk hopping with rate 1 if in state (0,1,0,0) or (1,1,0,1)
{
lattice[nextsite] = 1; // moves to state (0,0,1,0)
lattice[site] = 0;
if (site == L/2 && t >= Teq)
{
J++;
}
}
if (lattice[prevsite] != lattice[nnextsite])
{
if (lattice[prevsite] == 1 && ran3(&dum) <= r_hop)
{
lattice[nextsite] = 1; // moves to state (1,0,1,0)
lattice[site] = 0;
if (site == L/2 && t >= Teq)
{
J++;
}
}
if (lattice[prevsite] == 0 && ran3(&dum) <= q_hop)
{
lattice[nextsite] = 1; // moves to state (1,0,1,0)
lattice[site] = 0;
if (site == L/2 && t >= Teq)
{
J++;
}
}
}
} // End of site availability check.
} // End of loop through array.
}
void update()
{
dum=-time(NULL);
ran3(&dum);
for (t = 0; t <= T; t += dt) // Time loop allows for better averaging, and allows the system to reach steady state.
{
move(); // Move function.
} // End of time loop.
}
double cputime ( )
{
double time;
time = ( double ) clock ( ) / ( double ) CLOCKS_PER_SEC;
return time;
}
//===================================================================//
//============================ MAIN CODE ============================//
//===================================================================//
int main()
{
double cputime0;
double cputime1;
double cputime2;
const string program ="Monte Carlo Siumulation of totally asymmetric simple exclusion process (TASEP) with interacting particles.";
const string spaces(program.size(), '*');
const string stars = spaces;
cout<<"\n"<<endl;
cout<<stars<<endl;
cout<< program <<endl;
cout<< "Current v.s. Interaction Energy." <<endl;
cout<<stars<<endl;
cout<< "\nalpha = ";
cin>> alpha;
cin.ignore();
cout<< "beta = ";
cin>> beta;
cin.ignore();
cout<< "E_min = ";
cin>> eps_min;
cin.ignore();
cout<< "E_max = ";
cin>> eps_max;
cin.ignore();
cout<< "dE = ";
cin>> deps;
cin.ignore();
cout<< "theta = ";
cin>> theta;
cin.ignore();
cout<< "\n" << stars <<endl;
cout<< "Parameters:\n" <<endl;
cout<< " L = " << L << endl;
cout<< " T = " << T << endl;
cout<< " dt = " << dt <<endl;
cout<< " alpha = " << alpha << endl;
cout<< " beta = " << beta << endl;
cout<< " E_min = " << eps_min << endl;
cout<< " E_max = " << eps_max << endl;
cout<< " dE = " << deps << endl;
cout<< " theta = " << theta << endl;
cout<< "\n" << stars <<endl;
std::ostringstream fileNameStreamD("");
fileNameStreamD << "JE" << "[" << eps_min << "," << eps_max << "]" << "_th=" << theta <<"_a=" << alpha << "_b="<< beta <<".txt";
std::string fileNameD = fileNameStreamD.str();
ofstream q1(fileNameD.c_str());
#pragma omp parallel
#pragma omp for lastprivate(lattice, J)
epsilon = eps_min;
while(epsilon <= eps_max + deps)
{
q = exp(theta * epsilon);
r = exp((theta - 1) * epsilon);
initialise();
update();
q1<< epsilon <<" "<< J/Tdif <<endl;
epsilon += deps;
}
q1.close();
cputime2 = cputime ();
cputime0 = cputime2 - cputime1;
cout<< "Simulation Results:\n" <<endl;
cout<< " Elapsed cpu time for main computation:" <<endl;
cout<< " " << cputime2 << " seconds";
cout<< "\n" << stars <<endl;
std::ostringstream fileNameStreamL("");
fileNameStreamL << "Log_JE" << "[" << eps_min << "," << eps_max << "]" << "_th=" << theta <<"_a=" << alpha << "_b="<< beta <<".txt";
std::string fileNameL = fileNameStreamL.str();
ofstream q2(fileNameL.c_str());
q2<< stars <<endl;
q2<< "Parameters:\n" <<endl;
q2<< " L = " << L << endl;
q2<< " T = " << T << endl;
q2<< " dt = " << dt <<endl;
q2<< " alpha = " << alpha << endl;
q2<< " beta = " << beta << endl;
q2<< " E_min = " << eps_min << endl;
q2<< " E_max = " << eps_max << endl;
q2<< " dE = " << deps << endl;
q2<< " theta = " << theta << endl;
q2<< "\n" << stars << endl;
q2<< "Simulation Results:\n" <<endl;
q2<< " Elapsed cpu time for main computation:\n";
q2<< " " << cputime2 << " seconds" <<endl;
q2<< "\n" << stars <<endl;
q2.close();
}