-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUNIT1.bak
486 lines (428 loc) · 14.8 KB
/
UNIT1.bak
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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
//---------------------------------------------------------------------------
#include <vcl\vcl.h>
#pragma hdrstop
#include <math.h>
#include <strstream>
#include <iostream>
#include <fstream>
#include <conio.h>
#include "Unit1.h"
#include <complex>
//---------------------------------------------------------------------------
#pragma resource "*.dfm"
TForm1 *Form1;
int const
// Number of atoms
Nat = 1000, Nat2 = Nat/2;
double const
pi=3.1415926535897932385,
// Time step
dt=0.005, dt2=dt*dt,
// Discreteness parameter
alpha=1.0/6.0,
beta=1.0/120.0,
A=0.01,
ADB=1.5,
teta=0.398,
omegaDB=2.27,
delta=-0.0,
// Calculate from time tMIN to time tMAX
tMIN =0.0,
// V hard=0.1303
//tMAX = dt, // 0h
//tMAX = 115.112-10.0*7.674, // 5h
//tMAX = 115.112-5.0*7.674, // 10h
tMAX = 1115.112, // 15h
//tMAX = 115.112+5.0*7.674+0.01, // 20h
//tMAX = 115.112+5.0*7.674+0.01, // 20h
//tMAX = dt, // 0h
//tMAX = 3.523*150, // 5h
//tMAX = 3.523*10, // 10h
//tMAX = 3.523*15+0.03, // 15h
//tMAX = 3.523*20+0.04, // 20h
// Parameters of Shtormer method
k1=7.0/6.0, k2=5.0/12.0, k3=1.0/3.0, k4=1.0/12.0;
int X1,X2,X3,found;
double e1do,e2do,e3do,e1po,e2po,e3po,TotEn,Kin,Pot,omega,tmax,tmaxP,xmax,xmaxP,
DBT,DBomega,DBampl,
P1i,P2i,P1f,P2f,E1i,E2i,E1f,E2f,Ap,Am,Af,Adot,MaxA,Xp,Xm,Xf,Xdot,Rp,Rm,Rf,Rdot,Sp,Sm,Sf,Sdot,Alpha4,XX1,YY1,YY2,V,Amplitudek,MaxKinEner,MinKinEner=100.0;
// Arrays
double *u0,*u1,*u2,*u3,*p,*f0,*f1,*f2,*f3,*analit,*EnerOfAtoms;
double sqr (double x) {return x*x;}
double cube (double x) {return x*x*x;}
double DET (double a, double b, double c, double d, double e, double f, double g, double h, double i)
{return a*(e*i-h*f)-d*(b*i-h*c)+g*(b*f-e*c);}
double Ch(double x) {return ( exp(x)+exp(-x) )/2.0;}
double Sh(double x) {return ( exp(x)-exp(-x) )/2.0;}
double Th(double x) {return ( exp(x)-exp(-x) )/( exp(x)+exp(-x) );}
double KinkIM(double x, double t);
double GAMMA(double x);
//double Solution(double x, double t) {return bkRunf(x,t);}
double Solution(double x, double t) {return KinkIM(x,t);}
double PotEnergy (double x[]);
double KinEnergy (double x0[],double x1[],
double x2[],double x3[]);
void EnergyOfAtoms (double x0[],double x1[],
double x2[],double x3[]);
double EnerFromTo (double x0[],double x1[],
double x2[],double x3[],
int From, int To);
double MomtFromTo (double x0[],double x1[],
double x2[],double x3[],
int From, int To);
void ForceCulc (double x[], double y[]);
void PrintOutData();
void ShowMesh();
void ShowAtoms(int, double z[]);
void ShowEnergy(int, double z[]);
void Add_HIST_E(double Al, double Ar);
void Add_HIST_P(double Al, double Ar);
double MR11(double r);
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner){
u0 = new double [Nat*8]; u1 = new double [Nat*8];
u2 = new double [Nat*8]; u3 = new double [Nat*8];
f0 = new double [Nat*8]; f1 = new double [Nat*8];
f2 = new double [Nat*8]; f3 = new double [Nat*8];
p = new double [Nat*8]; analit = new double [Nat*8];
EnerOfAtoms = new double [Nat*8];
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender){
// DB parameters from analytics
ofstream OFSOa("Analit.txt",ios::out);
OFSOa.precision(10);
int PLO=1;
if (PLO==1){
/*
// soft-type anharm
double omega=0.99999;
while (omega>0.75){
double A,theta,AR,thetaR;
A=4.0*atan(sqrt(1.0-omega*omega)/omega);
theta=sqrt(1.0-omega*omega);
double Omega=1.0-omega;
thetaR=sqrt(2.0*Omega);
AR=4.0*thetaR;
OFSOa.width(12); OFSOa << omega; OFSOa << " ";// 1
OFSOa.width(12); OFSOa << A; OFSOa << " "; // 2
OFSOa.width(12); OFSOa << theta; OFSOa << " "; // 3
OFSOa.width(12); OFSOa << AR; OFSOa << " "; // 4
OFSOa.width(12); OFSOa << thetaR; OFSOa << " "; // 5
OFSOa << "\n";
omega-=0.002;
}
*/
// hard-type anharm
double omega=2.2361;
while (omega<2.41){
double AR,thetaR;
double Omega=omega-sqrt(5.0);
thetaR=sqrt(2.0*sqrt(5.0)*Omega);
AR=4.0*thetaR;
OFSOa.width(12); OFSOa << omega; OFSOa << " ";// 1
OFSOa.width(12); OFSOa << AR; OFSOa << " "; // 4
OFSOa.width(12); OFSOa << thetaR; OFSOa << " "; // 5
OFSOa << "\n";
omega+=0.002;
}
}
ofstream OFSOee("Energies_l.txt",ios::out);
OFSOee.precision(10);
ofstream OFSOr("Results_l.txt",ios::out);
OFSOr.precision(10);
ofstream OFSOd("Displ_l_5h.txt",ios::out);
OFSOd.precision(10);
ofstream OFSOdb("DBparam_l.txt",ios::out);
OFSOdb.precision(10);
omega=2.24;
while (omega<2.24000001){
Form1->Canvas->TextOut(25,50,"omega =");
Form1->Canvas->TextOut(95,50,omega);
// Zero into files
for(int i = 0; i<Nat; i++){
u0[i]=0.0; u1[i]=0.0; u2[i]=0.0; u3[i]=0.0;
f0[i]=0.0; f1[i]=0.0; f2[i]=0.0; f3[i]=0.0;
p[i]=0.0;
}
//**********************************************
// INITIAL CONDITIONS
//**********************************************
//double t0=tMIN; //#Changed
// incert DB in the center of the chain
for(int i=Nat2-100; i<Nat2+100; i++){
if (i%2==0){
u0[i]=ADB*cos(-omegaDB*0.0*dt+delta*(i-Nat2))/Ch(teta*(i-Nat2));
u1[i]=ADB*cos(-omegaDB*1.0*dt+delta*(i-Nat2))/Ch(teta*(i-Nat2));
u2[i]=ADB*cos(-omegaDB*2.0*dt+delta*(i-Nat2))/Ch(teta*(i-Nat2));
u3[i]=ADB*cos(-omegaDB*3.0*dt+delta*(i-Nat2))/Ch(teta*(i-Nat2));
}
else {
u0[i]=-ADB*cos(-omegaDB*0.0*dt+delta*(i-Nat2))/Ch(teta*(i-Nat2));
u1[i]=-ADB*cos(-omegaDB*1.0*dt+delta*(i-Nat2))/Ch(teta*(i-Nat2));
u2[i]=-ADB*cos(-omegaDB*2.0*dt+delta*(i-Nat2))/Ch(teta*(i-Nat2));
u3[i]=-ADB*cos(-omegaDB*3.0*dt+delta*(i-Nat2))/Ch(teta*(i-Nat2));
}
}
//**********************************************
// MD CALCULATION
//**********************************************
double t = tMIN;
float nit = 0;
tmax=0.0;
tmaxP=0.0;
xmax=0.0;
xmaxP=0.0;
double averV=0.0;
int CaverV=0;
while (t<=tMAX+0.0000001){
// Stormer procedure
ForceCulc(u0,f0);
for(int i=0; i<Nat; i++){
p[i] = 2.0*u0[i]-u1[i]
+ dt2*(k1*f0[i]-k2*f1[i]+k3*f2[i]-k4*f3[i]);
}
// Replace
for(int i=0; i<Nat; i++){
u3[i] = u2[i]; u2[i] = u1[i]; u1[i] = u0[i]; u0[i] = p[i];
f3[i] = f2[i]; f2[i] = f1[i]; f1[i] = f0[i];
}
// AC driving (displacement)
// if (t<50.0)
// u0[Nat2]=A*sin(omega*t);
// Show solution
if (fmod(nit,5000) == 0){
EnergyOfAtoms(u0,u1,u2,u3);
ShowMesh();
ShowAtoms(clRed,u0);
ShowEnergy(clBlue,EnerOfAtoms);
}// show solution
// Save displ
// if (fmod(nit,2) == 0){
// OFSOd.width(12); OFSOd << t; OFSOd << " "; // 1
// OFSOd.width(12); OFSOd << u0[Nat2+0]; OFSOd << " "; // 2
// OFSOd.width(12); OFSOd << u0[Nat2+1]; OFSOd << " "; // 3
// OFSOd.width(12); OFSOd << u0[Nat2+2]; OFSOd << " "; // 4
// OFSOd << "\n";
// }
// if ( nit == 6*572-11){
// if ( nit == 1538-100){
// for(int i=Nat2-20; i<Nat2+20; i++){
// OFSOd.width(12); OFSOd << i; OFSOd << " "; // 1
// OFSOd.width(12); OFSOd << u0[i]; OFSOd << " "; // 2
// OFSOd << "\n";
// }
// }
// Find DB parameters
if ((long)nit%20000==0){
EnergyOfAtoms(u0,u1,u2,u3);
for(int i=1; i<Nat-2; i++){
if ((EnerOfAtoms[i]>EnerOfAtoms[i-1])&&(EnerOfAtoms[i]>EnerOfAtoms[i+1])&&(EnerOfAtoms[i]>0.15)){
double ul,um,ur,a,b,c,xx,VDB;
ul=EnerOfAtoms[i-1];
um=EnerOfAtoms[i];
ur=EnerOfAtoms[i+1];
//a=um; //#Changed
b=(ur-ul)/(2.0);
c=(ur-2.0*um+ul)/(2.0);
//xx=-b/(2.0*c); //#Changed
xmax=i-b/(2.0*c);
VDB=(xmax-xmaxP)/(20000.0*dt);
xmaxP=xmax;
if (nit>2000){
OFSOdb.width(12); OFSOdb << t; OFSOdb << " "; // 1
OFSOdb.width(12); OFSOdb << VDB; OFSOdb << " "; // 2
OFSOdb.width(12); OFSOdb << ADB; OFSOdb << " "; // 3
OFSOdb << "\n";
if (VDB>0.005){
averV+=VDB;
CaverV+=1;
}
}
}
}
}
// Screen view
if (fmod(nit,10) == 0){
Kin=KinEnergy(u0,u1,u2,u3);
Pot=PotEnergy(u0);
TotEn = Kin+Pot;
double uMAX=-1000.0;
int iMAX=0;
for(int i=0; i<Nat; i++){
if (u0[i]>uMAX){
uMAX=u0[i];
iMAX=i;
}
}
Form1->Canvas->Brush->Color = clBtnFace;
Form1->Canvas->TextOut(25,65,"Kin =");
Form1->Canvas->TextOut(95,65,Kin);
Form1->Canvas->TextOut(25,80,"Pot =");
Form1->Canvas->TextOut(95,80,Pot);
Form1->Canvas->TextOut(25,95,"TotEn =");
Form1->Canvas->TextOut(95,95,TotEn);
Form1->Canvas->TextOut(25,140,"t = ");
Form1->Canvas->TextOut(95,140,t);
OFSOee.width(12); OFSOee << t; OFSOee << " "; // 1
OFSOee.width(12); OFSOee << Pot; OFSOee << " "; // 2
OFSOee.width(12); OFSOee << Kin; OFSOee << " "; // 3
OFSOee.width(12); OFSOee << TotEn; OFSOee << " "; // 4
OFSOee.width(12); OFSOee << uMAX; OFSOee << " "; // 5
OFSOee.width(12); OFSOee << iMAX; OFSOee << " "; // 6
OFSOee << "\n";
}// for Screen view
t += dt;
nit +=1;
}//while (t<=tMAX+0.0000001)
// Calculate energy
Kin=KinEnergy(u0,u1,u2,u3);
Pot=PotEnergy(u0);
TotEn = Kin+Pot;
for(int i=Nat2-20; i<Nat2+40; i++){
OFSOd.width(12); OFSOd << i; OFSOd << " "; // 1
OFSOd.width(12); OFSOd << u0[i]; OFSOd << " "; // 2
OFSOd << "\n";
}
// Save energy and power
OFSOr.width(12); OFSOr << ADB; OFSOr << " "; // 1
OFSOr.width(12); OFSOr << fabs(delta); OFSOr << " "; // 3
OFSOr.width(12); OFSOr << averV/(1.0*CaverV); OFSOr << " "; // 2
OFSOr.width(12); OFSOr << teta; OFSOr << " "; // 5
OFSOr.width(12); OFSOr << DBomega; OFSOr << " "; // 3
OFSOr << "\n";
omega+=0.01;
}//while (omega<3.0)
//Cloze the file
OFSOee.close();
}
//---------------------------------------------------------------------------
//************************************
//************************************
//************************************
//************************************
// PROCEDURES
//************************************
//************************************
//************************************
//************************************
// Calculation of forces with forth derivative
void ForceCulc (double u[], double f[]){
for(int i=1; i<Nat-1; i++){
double u2=u[i]*u[i];
f[i] = (u[i-1]-2.0*u[i]+u[i+1]) - u[i]*(1.0+alpha*u2+beta*u2*u2);
}
f[0] = (u[Nat-1]-2.0*u[0]+u[1]) - u[0]*(1.0+alpha*u[0]*u[0]+beta*u[0]*u[0]*u[0]*u[0]);
f[Nat-1] = (u[Nat-2]-2.0*u[Nat-1]+u[0]) - u[Nat-1]*(1.0+alpha*u[Nat-1]*u[Nat-1]+beta*u[Nat-1]*u[Nat-1]*u[Nat-1]*u[Nat-1]);
}
// Potential energy of the chain
double PotEnergy (double x[])
{double Pot = 0.0;
for(int i=0; i<Nat-1; i++)
{ Pot += 0.5*sqr(x[i+1]-x[i])+0.5*sqr(x[i])+0.25*alpha*sqr(x[i]*x[i])+(1.0/6.0)*beta*sqr(x[i]*x[i]*x[i]); }
Pot += 0.5*sqr(x[Nat-1]-x[0])+0.5*sqr(x[Nat-1])+0.25*alpha*sqr(x[Nat-1]*x[Nat-1])+(1.0/6.0)*beta*sqr(x[Nat-1]*x[Nat-1]*x[Nat-1]);
return Pot;}
// Kinetic energy of the chain
double KinEnergy (double x0[],double x1[],double x2[],double x3[])
{double Kin = 0.0;
for(int i=0; i<Nat; i++)
{ //Kin += 0.5*sqr((2.0*x0[i]+3.0*x1[i]-6.0*x2[i]+x3[i])/(6.0*dt));
Kin += 0.5*sqr((11.0*x0[i]-18.0*x1[i]+9.0*x2[i]-2.0*x3[i])/(6.0*dt));
}
return Kin;}
// Energy of atoms
void EnergyOfAtoms (double x0[],double x1[],double x2[],double x3[]){
double Kin;
double Pot;
for(int i=0; i<Nat-1; i++){
Kin = 0.5*sqr((11.0*x0[i]-18.0*x1[i]+9.0*x2[i]-2.0*x3[i])/(6.0*dt));
Pot = 0.5*sqr(x0[i+1]-x0[i])+0.5*sqr(x0[i])+0.25*alpha*sqr(x0[i]*x0[i])+(1.0/6.0)*beta*sqr(x0[i]*x0[i]*x0[i]);
EnerOfAtoms[i]=Kin+Pot;
}
EnerOfAtoms[Nat-1]=0.0;
}
/*
// PrintOut the numerical data
void PrintOutData()
{Form1->Canvas->Brush->Color = clBtnFace;
Form1->Canvas->TextOut(25,80,"Time t =");
Form1->Canvas->TextOut(80,80,t+t0);
Form1->Canvas->TextOut(25,95,"Potential energy per atom =");
Form1->Canvas->TextOut(170,95,AverPot);
Form1->Canvas->TextOut(25,110,"Kinetic energy per atom =");
Form1->Canvas->TextOut(170,110,AverKin);
Form1->Canvas->TextOut(25,125,"Total energy per atom =");
Form1->Canvas->TextOut(170,125,AverEn);
Form1->Canvas->TextOut(25,140,"Lost energy per atom =");
Form1->Canvas->TextOut(170,140,AverEn0-AverEn);}
*/
// Show the frame for the picture of atoms
void ShowMesh()
{Form1->Canvas->Brush->Color = clWhite;
Form1->Canvas->Rectangle(1,270,670,630);
Form1->Canvas->MoveTo(40,300);
Form1->Canvas->LineTo(40,600);
Form1->Canvas->LineTo(640,600);
Form1->Canvas->LineTo(640,300);
Form1->Canvas->LineTo(40,300);
Form1->Canvas->MoveTo(40,375);
Form1->Canvas->LineTo(640,375);
Form1->Canvas->MoveTo(40,450);
Form1->Canvas->LineTo(640,450);
Form1->Canvas->MoveTo(40,525);
Form1->Canvas->LineTo(640,525);
Form1->Canvas->MoveTo(90,300);
Form1->Canvas->LineTo(90,600);
Form1->Canvas->MoveTo(140,300);
Form1->Canvas->LineTo(140,600);
Form1->Canvas->MoveTo(190,300);
Form1->Canvas->LineTo(190,600);
Form1->Canvas->MoveTo(240,300);
Form1->Canvas->LineTo(240,600);
Form1->Canvas->MoveTo(290,300);
Form1->Canvas->LineTo(290,600);
Form1->Canvas->MoveTo(340,300);
Form1->Canvas->LineTo(340,600);
Form1->Canvas->MoveTo(390,300);
Form1->Canvas->LineTo(390,600);
Form1->Canvas->MoveTo(440,300);
Form1->Canvas->LineTo(440,600);
Form1->Canvas->MoveTo(490,300);
Form1->Canvas->LineTo(490,600);
Form1->Canvas->MoveTo(540,300);
Form1->Canvas->LineTo(540,600);
Form1->Canvas->MoveTo(590,300);
Form1->Canvas->LineTo(590,600);
Form1->Canvas->TextOut(40,608,"1");
Form1->Canvas->TextOut(630,608,Nat);
Form1->Canvas->TextOut(330,608,Nat2);
Form1->Canvas->TextOut(10,298,"+12.6");
Form1->Canvas->TextOut(10,373,"+6.28");
Form1->Canvas->TextOut(10,448," 0.00");
Form1->Canvas->TextOut(10,523,"-6.28");
Form1->Canvas->TextOut(10,598,"-12.6");
}
// Show displacements of atoms
void ShowAtoms(TColor Col, double x0[]){
int x,y;
for (int i=0; i<Nat; i++){
x = 40 + floor(i*600.0/Nat);
y = 450 - floor(1.0*pi*x0[i]*150.0/(4.0*pi));
Form1->Canvas->Pixels[x][y] = Col;
Form1->Canvas->Pixels[x+1][y] = Col;
Form1->Canvas->Pixels[x][y+1] = Col;
Form1->Canvas->Pixels[x+1][y+1] = Col;
}
}
// Show energy of atoms
void ShowEnergy(TColor Col, double x0[]){
int x,y;
for (int i=0; i<Nat; i++){
x = 40 + floor(i*600.0/Nat);
y = 450 - floor(1.0*pi*x0[i]*150.0/(4.0*pi));
Form1->Canvas->Pixels[x][y] = Col;
Form1->Canvas->Pixels[x+1][y] = Col;
Form1->Canvas->Pixels[x][y+1] = Col;
Form1->Canvas->Pixels[x+1][y+1] = Col;
}
}