-
Notifications
You must be signed in to change notification settings - Fork 0
/
act_4chemicals.cpp
451 lines (269 loc) · 7.74 KB
/
act_4chemicals.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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
// Exact Computation of Auto-Chemotaxis
// for a one cell system
// 4 chemicals
#include <iostream.h>
#include <math.h>
#include <fstream.h>
#define IM1 2147483563
#define IM2 2147483399
#define AM (1.0/IM1)
#define IMM1 (IM1-1)
#define IA1 40014
#define IA2 40692
#define IQ1 53668
#define IQ2 52774
#define IR1 12211
#define IR2 3791
#define NTAB 32
#define NDIV (1+IMM1/NTAB)
#define EPS 1.2e-7
#define RNMX (1.0-EPS)
float ran2(long *idum) {
int j;
long k;
static long idum2=123456789;
static long iy=0;
static long iv[NTAB];
float temp;
if (*idum <= 0) {
if (-(*idum) < 1) *idum=1;
else *idum = -(*idum);
idum2=(*idum);
for (j=NTAB+7;j>=0;j--) {
k = (*idum)/IQ1;
*idum=IA1*(*idum-k*IQ1)-k*IR1;
if (*idum < 0) *idum += IM1;
if (j < NTAB) iv[j] = *idum;
}
iy=iv[0];
}
k=(*idum)/IQ1;
*idum=IA1*(*idum-k*IQ1)-k*IR1;
if (*idum < 0) *idum += IM1;
k=idum2/IQ2;
idum2=IA2*(idum2-k*IQ2)-k*IR2;
if (idum2 < 0) idum2 += IM2;
j = iy/NDIV;
iy = iv[j]-idum2;
iv[j] = *idum;
if (iy < 1) iy += IMM1;
if ((temp=AM*iy) > RNMX) return RNMX;
else return temp;
}
double p[300002] [5]; // position of cells at ith timestep and sample number k
double grad_1 [5];
double grad_2 [5];
double grad_3 [5];
double grad_4 [5];
double rg[300002];
double rg1[300002];
double rg2[300002];
double rg3[300002];
double rg4[300002];
double gr[5];
int i,j,k,celln,celln1,ith,jinit,kr;
double sum,tp,t,ts,ts_a,a,b,c,pi,r,v1,v2;
double Dp_1,Dp_2,Dp_3,Dp_4,D,Beta,alpha_1,alpha_2,alpha_3,alpha_4,v;
double x1,x2,wy,lambda_1,lambda_2,lambda_3,lambda_4,e;
double sum_a,sum_ab,ss,dist;
double sum_b,sum1,phi,a1,b1,c1,epsilon_p,epsilon_c;
int sample,sample_max,i_max;
int cell_max;
long idum = -7856;
int main () {
pi = 3.1415265359;
D = 0.1; //0.001;
cout<<"Dp_1"<<endl;
//cin>>Dp_1;
Dp_1 = 0.07;
cout<<"Dp_2"<<endl;
//cin>>Dp_2;
Dp_2 = 0.198;
cout<<"Dp_3"<<endl;
//cin>>Dp_3;
Dp_3 = 0.253;
cout<<"Dp_4"<<endl;
//cin>>Dp_4;
Dp_4 = 0.120;
Beta = -1;
//alpha = 0;
ofstream posOut("act6.txt");
for (kr=1; kr<=1; kr++) {
cout<<"alpha_1"<<endl;
cin>>alpha_1;
// alpha_1 = 0.245;
cout<<"alpha_2"<<endl;
//cin>>alpha_2;
alpha_2 = 0.0;
cout<<"alpha_3"<<endl;
//cin>>alpha_3;
alpha_3 = 0.4;
cout<<"alpha_4"<<endl;
//cin>>alpha_4;
alpha_4 = 0.577;
for (i=0; i<=i_max+2; i++) {rg[i]=0; rg1[i]=0; rg2[i]=0; rg3[i]=0; gr[i]=0;}
ts = 0.1;
cell_max = 0;
cout<<"lambda_1"<<endl;
//cin>>lambda_1;
lambda_1 = 0.032;
cout<<"lambda_2"<<endl;
//cin>>lambda_2;
lambda_2 = 0.014;
cout<<"lambda_3"<<endl;
//cin>>lambda_3;
lambda_3 = 0.068;
cout<<"lambda_4"<<endl;
//cin>>lambda_4;
lambda_4 = 0.029;
ith = 3000;
sample_max = 0;
i_max = 3000;
ss = 0.01;
cout<<((alpha_1*0.936237)/(4*pow(Dp_1,1.5)*sqrt(lambda_1))) - (alpha_2/(4*pow(Dp_2,1.5)*sqrt(lambda_2))) + ((alpha_3*0.907162)/(4*pow(Dp_3,1.5)*sqrt(lambda_3))) - ((alpha_4*0.939294)/(4*pow(Dp_4,1.5)*sqrt(lambda_4)));
div_t divresult_a;
for (sample=0; sample<=sample_max; sample++) {
p[0] [0] = 0;
divresult_a = div (sample,1);
if (divresult_a.rem == 0) {cout<<sample<<endl;}
for (i=0; i<=i_max; i++) {
t = i*ts;
// Compute the gradient at the current cell position
// Chemical A
sum_a = 0;
if (t > 0) {
jinit = 0;
if (i>=ith) {jinit=i-ith;}
for (j=jinit; j<=(i-1); j++) {
tp = j*ts;
a = pow(4*Dp_1*(t-tp),-1.5);
b = p[i] [0] - p[j] [0];
c = exp( ( -(b*b)/ (4*Dp_1*(t-tp)) ) - (lambda_1*(t-tp)) );
sum_a = sum_a + (a*b*c)*ts;
}
// Chemical A is a chemo-repellent
grad_1 [0] = sum_a * (-2*Beta / pow(pi,0.5));
// Chemical B
sum_a = 0;
jinit = 0;
if (i>=ith) {jinit=i-ith;}
for (j=jinit; j<=(i-1); j++) {
tp = j*ts;
a = pow(4*Dp_2*(t-tp),-1.5);
b = p[i] [0] - p[j] [0];
c = exp( ( -(b*b)/ (4*Dp_2*(t-tp)) ) - (lambda_2*(t-tp)) );
sum_a = sum_a + (a*b*c)*ts;
}
// Chemical B is a chemo-attractant
grad_2 [0] = sum_a * (2*Beta / pow(pi,0.5));
// Chemical C
sum_a = 0;
jinit = 0;
if (i>=ith) {jinit=i-ith;}
for (j=jinit; j<=(i-1); j++) {
tp = j*ts;
a = pow(4*Dp_3*(t-tp),-1.5);
b = p[i] [0] - p[j] [0];
c = exp( ( -(b*b)/ (4*Dp_3*(t-tp)) ) - (lambda_3*(t-tp)) );
sum_a = sum_a + (a*b*c)*ts;
}
// Chemical C is a chemo-repellent
grad_3 [0] = sum_a * (-2*Beta / pow(pi,0.5));
// Chemical D
sum_a = 0;
jinit = 0;
if (i>=ith) {jinit=i-ith;}
for (j=jinit; j<=(i-1); j++) {
tp = j*ts;
a = pow(4*Dp_4*(t-tp),-1.5);
b = p[i] [0] - p[j] [0];
c = exp( ( -(b*b)/ (4*Dp_4*(t-tp)) ) - (lambda_4*(t-tp)) );
sum_a = sum_a + (a*b*c)*ts;
}
// Chemical D is a chemo-attractant
grad_4 [0] = sum_a * (2*Beta / pow(pi,0.5));
}
// Generate a Gaussian random number
do { x1 = 2.0 * ran2(&idum) - 1.0;
x2 = 2.0 * ran2(&idum) - 1.0;
wy = x1 * x1 + x2 * x2;
} while ( wy >= 1.0 );
wy = sqrt( (-2.0 * log( wy ) ) / wy );
r = x1 * wy;
if (i==100) {
v = (pow(((2*D)/ts),0.5) * r) + (alpha_1 * grad_1[0]) + (alpha_2 * grad_2[0]) + (alpha_3 * grad_3[0]) + (alpha_4 * grad_4[0]);
}
else
{
v = (alpha_1 * grad_1[0]) + (alpha_2 * grad_2[0]) + (alpha_3 * grad_3[0]) + (alpha_4 * grad_4[0]);
}
p[i+1] [0] = p[i] [0] + (v*ts);
// v1 = sqrt(pow((alpha * grad [0]),2));
// v2 = sqrt(pow((pow(((2*D)/ts),0.5) * r),2));
//if (v1 > v2) {rg[i] = 1;} else {rg[i]=0;}
//if ( abs(p [i+1] [0] - p[i+1] [1]) <= 5) { rg[i+1] = rg[i+1] + 1; }
//if ( ((p [i+1] [0]) <= 0.5)&&((p [i+1] [0]) >= 0.2) ) { rg1[i+1] = rg1[i+1] + 1; }
//if ( ((p [i+1] [1]) <= -0.2)&&((p [i+1] [1]) >= -0.5) ) {rg2[i+1] = rg2[i+1] + 1; }
rg[i+1] = rg[i+1] + pow(p [i+1] [0],2);
rg1[i+1] = rg1[i+1] + p [i+1] [0];
//rg1[i+1] = rg1[i+1] + p [i+1] [1];
//rg2[i+1] = rg2[i+1] + p [i+1] [2];
//rg3[i+1] = rg3[i+1] + p [i+1] [3];
//rg4[i+1] = rg4[i+1] + p [i+1] [4];
//sum1 = 1;
//for (celln=0; celln<=cell_max; celln++) {
//sum1 = sum1 * p[i+1] [celln];
//}
//gr[i+1] = gr[i+1] + sum1;
}
}
posOut<<endl;
for (i=0; i<=i_max; i++) {
divresult_a = div (i,5);
if (divresult_a.rem == 0) {
// posOut<<i*ts<<" "<<((rg[i]/(sample_max+1)))-pow(((rg1[i]/(sample_max+1))),2)<<endl;
posOut<<i*ts<<" "<<p[i][0]<<endl;
}
}
}
return 0;
}
// Output results to a file
//for (i=0; i<=i_max; i++) {
//sum_a = 0;
//sum_ab = 0;
//for (sample=0; sample<=sample_max; sample++) {
//for (celln=0; celln<=cell_max; celln++) {
// Calculate the Variance
//sum_a = sum_a + p [i] [celln] [sample];
//sum_ab = sum_ab + pow((p [i] [celln] [sample]),2);
//posOut<<p [i] [sample]<<" ";
//}
//}
//divresult_a = div (i,1);
//if (divresult_a.rem == 0) {
//posOut<<i*ts<<" "<<(sum_ab/((sample_max+1)*(cell_max+1))) - pow((sum_a/((sample_max+1)*(cell_max+1))),2)<<endl;
//}
//}
// Calculate Cell density
//for (celln=0; celln<=cell_max; celln++) {
//for (j=90; j<=110; j++) {
//d = (j-100) * ss;
//e = ((j+1)-100) * ss;
//if ((p [i] [celln] [sample] > d)&&(p [i] [celln] [sample] <= e)) {
//dist = (e - p [i] [celln] [sample])/ss;
//cd [i] [j+1] = cd [i] [j+1] + 1 - dist;
//cd [i] [j] = cd [i] [j] + dist;
//}
//}
//}
//}
//}
// Output Cell Density
//for (i=0; i<=i_max; i++) {
//for (j=90; j<=110; j++) {
//posOut<<cd [i] [j]/(sample_max+1)<<" ";
//}
//posOut<<endl;
//}
//}