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
| struct Chain{ // .// flush
public:
double *X;//coordinates
double *Y;
double *Z;
double *BX;//coordinates
double *BY;
double *BZ;
int N;//number of beads
};
int New (Chain *Ch,int num){
int i,j,N=Ch[num].N;
double x,y,z,fi,psi;
Ch[num].X[0]=Ch[num].Y[0]=Ch[num].Z[0]=0;
for (i=0;i<N-1;i++){
fi=PI2*rand()/(RAND_MAX+0.0);
psi=PI*rand()/(RAND_MAX+0.0);
j=rand();
switch(j%3){
case 0:{x=sin(psi)*cos(fi);
y=sin(psi)*sin(fi);
z=cos(psi);
break;
}
case 1:{z=sin(psi)*cos(fi);
x=sin(psi)*sin(fi);
y=cos(psi);
break;
}
case 2:{y=sin(psi)*cos(fi);
z=sin(psi)*sin(fi);
x=cos(psi);
break;
}
}
Ch[num].X[i+1]=Ch[num].X[i]+x;
Ch[num].Y[i+1]=Ch[num].Y[i]+y;
Ch[num].Z[i+1]=Ch[num].Z[i]+z;
}
return 1;
}
void Rotation(int num, int SN,double V0,double d2, Chain *Ch){
double psi,fi,dr;
int N=Ch[num].N-1,j;
double Vx,Vy,Vz;
int SN1,SN_1;
SN1=SN+1;
if (SN==N){SN1=N;}
SN_1=SN-1;
if (SN==0){SN_1=0;}
fi=PI2*rand()/(RAND_MAX+0.0);
psi=PI*rand()/(RAND_MAX+0.0);
j=rand();
switch(j%3){
case 0:{Vx=sin(psi)*cos(fi);
Vy=sin(psi)*sin(fi);
Vz=cos(psi);
break;
}
case 1:{Vz=sin(psi)*cos(fi);
Vx=sin(psi)*sin(fi);
Vy=cos(psi);
break;
}
case 2:{Vy=sin(psi)*cos(fi);
Vz=sin(psi)*sin(fi);
Vx=cos(psi);
break;
}
}
Vx/=V0,Vy/=V0,Vz/=V0;
Vx+=Ch[num].X[SN1]+Ch[num].X[SN_1]-2.0*Ch[num].X[SN];
Vy+=Ch[num].Y[SN1]+Ch[num].Y[SN_1]-2.0*Ch[num].Y[SN];
Vz+=Ch[num].Z[SN1]+Ch[num].Z[SN_1]-2.0*Ch[num].Z[SN];
dr=(Ch[num].X[SN1]-Ch[num].X[SN])*(Ch[num].X[SN1]-Ch[num].X[SN])+(Ch[num].Y[SN1]-Ch[num].Y[SN])*(Ch[num].Y[SN1]-Ch[num].Y[SN])+(Ch[num].Z[SN1]-Ch[num].Z[SN])*(Ch[num].Z[SN1]-Ch[num].Z[SN]);
dr=sqrt(dr);
if (dr>0.0001){
Vx+=(Ch[num].X[SN]-Ch[num].X[SN1])/dr;
Vy+=(Ch[num].Y[SN]-Ch[num].Y[SN1])/dr;
Vz+=(Ch[num].Z[SN]-Ch[num].Z[SN1])/dr;
}
dr=(Ch[num].X[SN_1]-Ch[num].X[SN])*(Ch[num].X[SN_1]-Ch[num].X[SN])+(Ch[num].Y[SN_1]-Ch[num].Y[SN])*(Ch[num].Y[SN_1]-Ch[num].Y[SN])+(Ch[num].Z[SN_1]-Ch[num].Z[SN])*(Ch[num].Z[SN_1]-Ch[num].Z[SN]);
dr=sqrt(dr);
if (dr>0.0001){
Vx+=(Ch[num].X[SN]-Ch[num].X[SN_1])/dr;
Vy+=(Ch[num].Y[SN]-Ch[num].Y[SN_1])/dr;
Vz+=(Ch[num].Z[SN]-Ch[num].Z[SN_1])/dr;
}
//flag
Vx*=V0,Vy*=V0,Vz*=V0;
//std::cout<<SN<<"\t"<<Vx<<"\t"<<Vy<<"\t"<<Vz<<"\n";
Ch[num].X[SN]+=d2*Vx;
Ch[num].Y[SN]+=d2*Vy;
Ch[num].Z[SN]+=d2*Vz;
}
int main(int argc, char* argv[])
{
char basic1[]="D:\\fran2\\RESU.txt";
char RESULT1[]="D:\\fran1\\RESULTS1.txt" ;
char RESULT[40];
char basic2[40];
char str1[40];
char *str2="CR_F.txt";
char *symbol1="_";
char symbol;
char S;
char *ptr;
if(argc<2)
{cout<<"\tROUSE \nEnter 1-for file reading , 2- for beginig\nindependent calculations \n 3-tray condition and ";
cout<<"\ndestination for target directory (D:\\fran1\\RESULTS5sg.txt)\n SCR LOCK- PAUSE of calculations";
return 0;}
if(argc==2) strcpy(basic2,argv[1]);
else strcpy(basic2,basic1);
int Nseg=5,GGGGG,NUMBEROFCYCLES=1000,NUMBERINSIDECYCLES=600,Numberchains=400;
int NumberT1=12,SKIP_COEF=2000,DRANVECTOR=70;
int ZAHL;
char SOURCE[10];
int RIGIDITY=3;
int i;
int AA[8];
strcpy(str1,argv[0]);
ptr = strpbrk(str1,symbol1);
strcpy((ptr-8),str2);
fstream READF;
READF.open(str1,ios::in);
i=0;
while(1)
{
//READF.get(symbol);
while(1)
{
READF>>symbol;
if(symbol=='=')break;
}
READF>>AA[i];
if(i==7)break;
i++;
}
Nseg=AA[0];
NUMBEROFCYCLES=AA[1];
NUMBERINSIDECYCLES=AA[2];
Numberchains=AA[3];
NumberT1=AA[4];
SKIP_COEF=AA[5];
DRANVECTOR=AA[6];
RIGIDITY=AA[7];
GGGGG=Nseg+1;
if(argc==2){ strcpy(basic2,argv[1]);strcpy(RESULT,RESULT1);}
else strcpy(basic2,basic1);
bool END=false;
double Rflori=0,Rfloribeg=0;
double V0=0.2;
double d2;
int SpentTime=0,Hf,N,CN,Time,TStep;
Time=NUMBEROFCYCLES;
N=GGGGG;
time_t t;
srand((unsigned) time(&t));
CN=Numberchains;
TStep=NUMBERINSIDECYCLES;
float vr;
d2=(DRANVECTOR/(10000+0.0));
V0=RIGIDITY*d2/2;
int NUMBER,j;
int ch,sg;
Chain *CH;
//memory allocation
CH = new Chain [CN];
for (i=0;i<CN;i++){
CH[i].N=N;
CH[i].X=new double [N];
CH[i].Y=new double [N];
CH[i].Z=new double [N];
CH[i].BX=new double [N];
CH[i].BY=new double [N];
CH[i].BZ=new double [N];
New(CH,i);
}
ofstream t3;
//SKIP_TIME
clock_t start;
start = clock();
for (i=0;i<SKIP_COEF;i++){
t3.open("C:\\condition.txt",ios::trunc);
t3<<"SKIP_COEF "<<(clock() - start) / (60*(CLK_TCK))<<"m Progress "<<100*((i+0.0)/(SKIP_COEF+0.0))<<"%"<<"\n";
t3.close();
//if(POSITION!=3) cout<<"S_C "<<i<<"\n";
for (j=0;j<TStep;j++){
for(ch=0;ch<CN;ch++){
for(sg=0;sg<N;sg++){
Rotation(ch,sg,V0,d2,CH);
}
}
}
}
fstream outside; char jj;
ofstream ttt;
ttt.open(basic2,ios::trunc);
ttt<<"N = "<<(N)<<"\nCN = "<<CN<<"\nTime = ";
ofstream::pos_type p = ttt.tellp();
ttt<<" "<<"\nTStep = "<<TStep<<"\nV0 = "<<V0<<"\nDeltaT= "<<d2<<"\n";
i=0;
for(ch=0;ch<CN;ch++)
{
for(sg=0;sg<N;sg++)
{
CH[ch].BX[sg]=CH[ch].X[sg];
CH[ch].BY[sg]=CH[ch].Y[sg];
CH[ch].BZ[sg]=CH[ch].Z[sg];
}
}
for(ch=0;ch<CN;ch++)
{Rfloribeg+=(CH[ch].BX[N-1]-CH[ch].BX[0])*
(CH[ch].BX[N-1]-CH[ch].BX[0])+
(CH[ch].BY[N-1]-CH[ch].BY[0])*
(CH[ch].BY[N-1]-CH[ch].BY[0])+
(CH[ch].BZ[N-1]-CH[ch].BZ[0])*
(CH[ch].BZ[N-1]-CH[ch].BZ[0]);
}
for (i=SpentTime;i<(SpentTime+Time);i++){
t3.open("C:\\condition.txt",ios::trunc);
t3<<"Time "<<(clock() - start) / (60*(CLK_TCK))<<"m Progress "<<100*((i+0.0)/(Time+0.0))<<"%"<<"\n";
t3.close();
ttt<<i<<"\n";
for (j=0;j<TStep;j++){
for(ch=0;ch<CN;ch++){
for(sg=0;sg<N;sg++){
Rotation(ch,sg,V0,d2,CH);
if(j==(TStep-1))
{ttt<<CH[ch].X[sg]<<';'<<CH[ch].Y[sg]<<';'<<CH[ch].Z[sg]<<"\n";}
}
}
}
if((END==false))
{
Rflori=0;
for(ch=0;ch<CN;ch++)
{Rflori+=(CH[ch].BX[N-1]-CH[ch].BX[0])*
(CH[ch].X[N-1]-CH[ch].X[0])+
(CH[ch].BY[N-1]-CH[ch].BY[0])*
(CH[ch].Y[N-1]-CH[ch].Y[0])+
(CH[ch].BZ[N-1]-CH[ch].BZ[0])*
(CH[ch].Z[N-1]-CH[ch].Z[0]);
}
if((Rflori/Rfloribeg)<=0.366){Time=i*NumberT1;END=true;}
}
}
ttt.seekp(p);
ttt<<i<<"\n";
ttt.close();
cout<<"Simulation compleat\n";
return 0;
} |