-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdynmat.cpp
716 lines (624 loc) · 23.3 KB
/
dynmat.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
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
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
#include "dynmat.h"
#include "global.h"
#include "input.h"
#include "interpolate.h"
#include "memory.h"
#include "version.h"
#include "zheevd.h"
#include <cmath>
#include <cstdlib>
#include <cstring>
/* ----------------------------------------------------------------------------
* Class DynMat stores the Dynamic Matrix read from the binary file from
* fix-phonon and incorporates some operations w.r.t the DM.
* ---------------------------------------------------------------------------- */
DynMat::DynMat(int narg, char **arg)
{
input = NULL;
attyp = NULL;
memory = NULL;
M_inv_sqrt = NULL;
interpolate = NULL;
DM_q = DM_all = NULL;
binfile = funit = dmfile = NULL;
attyp = NULL;
basis = NULL;
flag_reset_gamma = flag_skip = 0;
symprec = -1.;
int flag_save = 0;
// analyze the command line options
int iarg = 1;
while (narg > iarg){
if (strcmp(arg[iarg], "-s") == 0){
flag_reset_gamma = flag_skip = 1;
} else if (strcmp(arg[iarg], "-r") == 0){
flag_reset_gamma = 1;
} else if (strcmp(arg[iarg], "-p") == 0){
if (++iarg >= narg) help();
else symprec = fabs(atof(arg[iarg]));
} else if (strcmp(arg[iarg], "-h") == 0){
help();
} else if (strcmp(arg[iarg], "-save") == 0){
flag_save = 1;
} else {
if (binfile) delete []binfile;
int n = strlen(arg[iarg]) + 1;
binfile = new char[n];
strcpy(binfile, arg[iarg]);
}
iarg++;
}
ShowVersion();
input = new UserInput(flag_save);
// get the binary file name from user input if not found in command line
char str[MAXLINE];
if (binfile == NULL) {
char *ptr = NULL;
printf("\n");
do {
printf("Please input the binary file name from fix_phonon: ");
input->read_stdin(str);
ptr = strtok(str, " \n\t\r\f");
} while (ptr == NULL);
int n = strlen(ptr) + 1;
binfile = new char[n];
strcpy(binfile, ptr);
}
// open the binary file
FILE *fp = fopen(binfile, "rb");
if (fp == NULL) {
printf("\nFile %s not found! Programe terminated.\n", binfile);
help();
}
// read header info from the binary file
if (fread(&sysdim, sizeof(int), 1, fp) != 1){
printf("\nError while reading sysdim from file: %s\n", binfile);
fclose(fp);
exit(2);
}
if (fread(&nx, sizeof(int), 1, fp) != 1){
printf("\nError while reading nx from file: %s\n", binfile);
fclose(fp);
exit(2);
}
if (fread(&ny, sizeof(int), 1, fp) != 1){
printf("\nError while reading ny from file: %s\n", binfile);
fclose(fp);
exit(2);
}
if (fread(&nz, sizeof(int), 1, fp) != 1){
printf("\nError while reading nz from file: %s\n", binfile);
fclose(fp);
exit(2);
}
if (fread(&nucell, sizeof(int), 1, fp) != 1){
printf("\nError while reading nucell from file: %s\n", binfile);
fclose(fp);
exit(2);
}
if (fread(&boltz, sizeof(double), 1, fp) != 1){
printf("\nError while reading boltz from file: %s\n", binfile);
fclose(fp);
exit(2);
}
fftdim = sysdim * nucell;
fftdim2 = fftdim * fftdim;
npt = nx * ny * nz;
// display info related to the read file
ShowInfo();
if (sysdim < 1||sysdim > 3||nx < 1||ny < 1||nz < 1||nucell < 1){
printf("Wrong values read from header of file: %s, please check the binary file!\n", binfile);
fclose(fp); exit(3);
}
Define_Conversion_Factor();
// now to allocate memory for DM
memory = new Memory();
memory->create(DM_all, npt, fftdim2, "DynMat:DM_all");
memory->create(DM_q, fftdim,fftdim,"DynMat:DM_q");
// read all dynamical matrix info into DM_all
if (fread(DM_all[0], sizeof(doublecomplex), npt*size_t(fftdim2), fp) != npt*size_t(fftdim2)) {
printf("\nError while reading the DM from file: %s\n", binfile);
fclose(fp);
exit(1);
}
// now try to read unit cell info from the binary file
memory->create(basis, nucell, sysdim, "DynMat:basis");
memory->create(attyp, nucell, "DynMat:attyp");
memory->create(M_inv_sqrt, nucell, "DynMat:M_inv_sqrt");
if (fread(&Tmeasure, sizeof(double), 1, fp) != 1){
printf("\nError while reading temperature from file: %s\n", binfile);
fclose(fp);
exit(3);
}
if (fread(&basevec[0], sizeof(double), 9, fp) != 9){
printf("\nError while reading lattice info from file: %s\n", binfile);
fclose(fp);
exit(3);
}
if (fread(basis[0], sizeof(double), fftdim, fp) != (size_t)fftdim){
printf("\nError while reading basis info from file: %s\n", binfile);
fclose(fp);
exit(3);
}
if (fread(&attyp[0], sizeof(int), nucell, fp) != (size_t)nucell){
printf("\nError while reading atom types from file: %s\n", binfile);
fclose(fp);
exit(3);
}
if (fread(&M_inv_sqrt[0], sizeof(double), nucell, fp) != (size_t)nucell){
printf("\nError while reading atomic masses from file: %s\n", binfile);
fclose(fp);
exit(3);
}
fclose(fp);
car2dir();
real2rec();
// initialize interpolation
interpolate = new Interpolate(nx,ny,nz,fftdim2,DM_all);
interpolate->input = input;
if (flag_reset_gamma) interpolate->reset_gamma();
// Enforcing Austic Sum Rule
EnforceASR();
// get the dynamical matrix from force constant matrix: D = 1/M x Phi
for (int idq = 0; idq < npt; ++idq){
int ndim =0;
for (int idim = 0; idim < fftdim; ++idim)
for (int jdim = 0; jdim < fftdim; ++jdim){
double inv_mass = M_inv_sqrt[idim/sysdim] * M_inv_sqrt[jdim/sysdim];
DM_all[idq][ndim].r *= inv_mass;
DM_all[idq][ndim].i *= inv_mass;
ndim++;
}
}
// ask for the interpolation method
interpolate->set_method();
return;
}
/* ----------------------------------------------------------------------------
* Free the memories used.
* ---------------------------------------------------------------------------- */
DynMat::~DynMat()
{
// destroy all memory allocated
if (funit) delete []funit;
if (dmfile) delete []dmfile;
if (binfile) delete []binfile;
if (interpolate) delete interpolate;
memory->destroy(DM_q);
memory->destroy(attyp);
memory->destroy(basis);
memory->destroy(DM_all);
memory->destroy(M_inv_sqrt);
delete memory;
return;
}
/* ----------------------------------------------------------------------------
* method to write DM_q to file, single point
* ---------------------------------------------------------------------------- */
void DynMat::writeDMq(double *q)
{
FILE *fp;
// only ask for file name for the first time
// other calls will append the result to the file.
if (dmfile == NULL){
char str[MAXLINE], *ptr;
printf("\n");
while ( 1 ){
printf("Please input the filename to output the DM at selected q: ");
input->read_stdin(str);
ptr = strtok(str, " \r\t\n\f");
if (ptr) break;
}
int n = strlen(ptr) + 1;
dmfile = new char[n];
strcpy(dmfile, ptr);
fp = fopen(dmfile,"w");
} else {
fp = fopen(dmfile,"a");
}
fprintf(fp,"# q = [%lg %lg %lg]\n", q[0], q[1], q[2]);
for (int i = 0; i < fftdim; ++i){
for (int j = 0; j < fftdim; ++j) fprintf(fp,"%lg %lg\t", DM_q[i][j].r, DM_q[i][j].i);
fprintf(fp,"\n");
}
fprintf(fp,"\n");
fclose(fp);
return;
}
/* ----------------------------------------------------------------------------
* method to write DM_q to file, dispersion-like
* ---------------------------------------------------------------------------- */
void DynMat::writeDMq(double *q, const double qr, FILE *fp)
{
fprintf(fp, "%lg %lg %lg %lg ", q[0], q[1], q[2], qr);
for (int i = 0; i < fftdim; ++i)
for (int j = 0; j < fftdim; ++j) fprintf(fp,"%lg %lg\t", DM_q[i][j].r, DM_q[i][j].i);
fprintf(fp,"\n");
return;
}
/* ----------------------------------------------------------------------------
* method to evaluate the eigenvalues of current q-point;
* return the eigenvalues in egv.
* cLapack subroutine zheevd is employed.
* ---------------------------------------------------------------------------- */
int DynMat::geteigen(double *egv, int flag)
{
char jobz, uplo;
int n, lda, lwork, lrwork, *iwork, liwork, info;
doublecomplex *work;
double *w = &egv[0], *rwork;
n = fftdim;
if (flag) jobz = 'V';
else jobz = 'N';
uplo = 'U';
lwork = (n+2)*n;
lrwork = 1 + (5+n+n)*n;
liwork = 3 + 5*n;
lda = n;
memory->create(work, lwork, "geteigen:work");
memory->create(rwork, lrwork, "geteigen:rwork");
memory->create(iwork, liwork, "geteigen:iwork");
zheevd_(&jobz, &uplo, &n, DM_q[0], &lda, w, work, &lwork, rwork, &lrwork, iwork, &liwork, &info);
// to get w instead of w^2; and convert w into v (THz hopefully)
for (int i = 0; i < n; ++i){
if (w[i]>= 0.) w[i] = sqrt(w[i]);
else w[i] = -sqrt(-w[i]);
w[i] *= eml2f;
}
memory->destroy(work);
memory->destroy(rwork);
memory->destroy(iwork);
return info;
}
/* ----------------------------------------------------------------------------
* method to get the Dynamical Matrix at q
* ---------------------------------------------------------------------------- */
void DynMat::getDMq(double *q)
{
interpolate->execute(q, DM_q[0]);
return;
}
/* ----------------------------------------------------------------------------
* method to get the Dynamical Matrix at q
* ---------------------------------------------------------------------------- */
void DynMat::getDMq(double *q, double *wt)
{
interpolate->execute(q, DM_q[0]);
if (flag_skip && interpolate->UseGamma ) wt[0] = 0.;
return;
}
/* ----------------------------------------------------------------------------
* private method to convert the cartisan coordinate of basis into fractional
* ---------------------------------------------------------------------------- */
void DynMat::car2dir()
{
double mat[9];
for (int idim = 0; idim < 9; ++idim) mat[idim] = basevec[idim];
GaussJordan(3, mat);
for (int i = 0; i < nucell; ++i){
double x[3];
x[0] = x[1] = x[2] = 0.;
for (int idim = 0; idim < sysdim; idim++) x[idim] = basis[i][idim];
for (int idim = 0; idim < sysdim; idim++)
basis[i][idim] = x[0]*mat[idim] + x[1]*mat[3+idim] + x[2]*mat[6+idim];
}
return;
}
/* ----------------------------------------------------------------------------
* private method to enforce the acoustic sum rule on force constant matrix at G
* ---------------------------------------------------------------------------- */
void DynMat::EnforceASR()
{
char str[MAXLINE];
int nasr = 20;
if (nucell <= 1) nasr = 1;
printf("\n================================================================================");
// compute and display eigenvalues of Phi at gamma before ASR
if (nucell > 100){
printf("\nYour unit cell is rather large, eigenvalue evaluation takes some time...");
fflush(stdout);
}
double *egvs = new double[fftdim];
for (int i = 0; i < fftdim; ++i)
for (int j = 0; j < fftdim; ++j) DM_q[i][j] = DM_all[0][i*fftdim+j];
geteigen(egvs, 0);
printf("\nEigenvalues of Phi at gamma before enforcing ASR:\n");
for (int i = 0; i < fftdim; ++i){
printf("%lg ", egvs[i]);
if (i%10 == 9) printf("\n");
if (i == 99){ printf("...... (%d more skipped)\n", fftdim-100); break;}
}
printf("\n\n");
// ask for iterations to enforce ASR
printf("Please input the # of iterations to enforce ASR [%d]: ", nasr);
input->read_stdin(str);
char *ptr = strtok(str," \t\n\r\f");
if (ptr) nasr = atoi(ptr);
if (nasr < 1){
puts("================================================================================");
return;
}
for (int iit = 0; iit < nasr; ++iit){
// simple ASR; the resultant matrix might not be symmetric
for (int a = 0; a < sysdim; ++a)
for (int b = 0; b < sysdim; ++b){
for (int k = 0; k < nucell; ++k){
double sum = 0.;
for (int kp = 0; kp < nucell; ++kp){
int idx = (k*sysdim+a)*fftdim+kp*sysdim+b;
sum += DM_all[0][idx].r;
}
sum /= double(nucell);
for (int kp = 0; kp < nucell; ++kp){
int idx = (k*sysdim+a)*fftdim+kp*sysdim+b;
DM_all[0][idx].r -= sum;
}
}
}
// symmetrize
for (int k = 0; k < nucell; ++k)
for (int kp = k; kp < nucell; ++kp){
double csum = 0.;
for (int a = 0; a < sysdim; ++a)
for (int b = 0; b < sysdim; ++b){
int idx = (k*sysdim+a)*fftdim+kp*sysdim+b;
int jdx = (kp*sysdim+b)*fftdim+k*sysdim+a;
csum = (DM_all[0][idx].r + DM_all[0][jdx].r )*0.5;
DM_all[0][idx].r = DM_all[0][jdx].r = csum;
}
}
}
// symmetric ASR
for (int a = 0; a < sysdim; ++a)
for (int b = 0; b < sysdim; ++b){
for (int k = 0; k < nucell; ++k){
double sum = 0.;
for (int kp = 0; kp < nucell; ++kp){
int idx = (k*sysdim+a)*fftdim+kp*sysdim+b;
sum += DM_all[0][idx].r;
}
sum /= double(nucell-k);
for (int kp = k; kp < nucell; ++kp){
int idx = (k*sysdim+a)*fftdim+kp*sysdim+b;
int jdx = (kp*sysdim+b)*fftdim+k*sysdim+a;
DM_all[0][idx].r -= sum;
DM_all[0][jdx].r = DM_all[0][idx].r;
}
}
}
// compute and display eigenvalues of Phi at gamma after ASR
for (int i = 0; i < fftdim; ++i)
for (int j = 0; j < fftdim; ++j) DM_q[i][j] = DM_all[0][i*fftdim+j];
geteigen(egvs, 0);
printf("Eigenvalues of Phi at gamma after enforcing ASR:\n");
for (int i = 0; i < fftdim; ++i){
printf("%lg ", egvs[i]);
if (i%10 == 9) printf("\n");
if (i == 99){ printf("...... (%d more skiped)", fftdim-100); break;}
}
delete[] egvs;
puts("\n================================================================================\n");
return;
}
/* ----------------------------------------------------------------------------
* private method to get the reciprocal lattice vectors from the real space ones
* ---------------------------------------------------------------------------- */
void DynMat::real2rec()
{
ibasevec[0] = basevec[4]*basevec[8] - basevec[5]*basevec[7];
ibasevec[1] = basevec[5]*basevec[6] - basevec[3]*basevec[8];
ibasevec[2] = basevec[3]*basevec[7] - basevec[4]*basevec[6];
ibasevec[3] = basevec[7]*basevec[2] - basevec[8]*basevec[1];
ibasevec[4] = basevec[8]*basevec[0] - basevec[6]*basevec[2];
ibasevec[5] = basevec[6]*basevec[1] - basevec[7]*basevec[0];
ibasevec[6] = basevec[1]*basevec[5] - basevec[2]*basevec[4];
ibasevec[7] = basevec[2]*basevec[3] - basevec[0]*basevec[5];
ibasevec[8] = basevec[0]*basevec[4] - basevec[1]*basevec[3];
double vol = 0.;
for (int i = 0; i < sysdim; ++i) vol += ibasevec[i] * basevec[i];
vol = 8.*atan(1.)/vol;
for (int i = 0; i < 9; ++i) ibasevec[i] *= vol;
printf("\n================================================================================");
printf("\nBasis vectors of the unit cell in real space:");
for (int i = 0; i < sysdim; ++i){
printf("\n A%d: ", i+1);
for (int j = 0; j < sysdim; ++j) printf("%8.4f ", basevec[i*3+j]);
}
printf("\nBasis vectors of the corresponding reciprocal cell:");
for (int i = 0; i < sysdim; ++i){
printf("\n B%d: ", i+1);
for (int j = 0; j < sysdim; ++j) printf("%8.4f ", ibasevec[i*3+j]);
}
puts("\n================================================================================");
return;
}
/* ----------------------------------------------------------------------
* private method, to get the inverse of a double matrix by means of
* Gaussian-Jordan Elimination with full pivoting; square matrix required.
*
* Adapted from the Numerical Recipes in Fortran.
* --------------------------------------------------------------------*/
void DynMat::GaussJordan(int n, double *Mat)
{
int i,icol,irow,j,k,l,ll,idr,idc;
int *indxc,*indxr,*ipiv;
double big, nmjk;
double dum, pivinv;
indxc = new int[n];
indxr = new int[n];
ipiv = new int[n];
irow = icol = -1;
for (i = 0; i < n; ++i) ipiv[i] = 0;
for (i = 0; i < n; ++i){
big = 0.0;
for (j = 0; j < n; ++j){
if (ipiv[j] != 1){
for (k = 0; k < n; ++k){
if (ipiv[k] == 0){
idr = j * n + k;
nmjk = fabs(Mat[idr]);
if (nmjk >= big){
big = nmjk;
irow = j;
icol = k;
}
} else if (ipiv[k] > 1){
printf("DynMat: Singular matrix in double GaussJordan!\n"); exit(1);
}
}
}
}
ipiv[icol] += 1;
if (irow != icol){
for (l = 0; l < n; ++l){
idr = irow*n+l;
idc = icol*n+l;
dum = Mat[idr];
Mat[idr] = Mat[idc];
Mat[idc] = dum;
}
}
indxr[i] = irow;
indxc[i] = icol;
idr = icol * n + icol;
if (Mat[idr] == 0.){
printf("DynMat: Singular matrix in double GaussJordan!");
exit(1);
}
pivinv = 1./ Mat[idr];
Mat[idr] = 1.;
idr = icol*n;
for (l = 0; l < n; ++l) Mat[idr+l] *= pivinv;
for (ll = 0; ll < n; ++ll){
if (ll != icol){
idc = ll * n + icol;
dum = Mat[idc];
Mat[idc] = 0.;
idc -= icol;
for (l = 0; l < n; ++l) Mat[idc+l] -= Mat[idr+l]*dum;
}
}
}
for (l = n-1; l >= 0; --l){
int rl = indxr[l];
int cl = indxc[l];
if (rl != cl){
for (k = 0; k < n; ++k){
idr = k * n + rl;
idc = k * n + cl;
dum = Mat[idr];
Mat[idr] = Mat[idc];
Mat[idc] = dum;
}
}
}
delete []indxr;
delete []indxc;
delete []ipiv;
return;
}
/* ----------------------------------------------------------------------------
* Public method to reset the interpolation method
* ---------------------------------------------------------------------------- */
void DynMat::reset_interp_method()
{
interpolate->set_method();
return;
}
/* ----------------------------------------------------------------------------
* Private method to display help info
* ---------------------------------------------------------------------------- */
void DynMat::help()
{
ShowVersion();
printf("\nUsage:\n phana [options] [file]\n\n");
printf("Available options:\n");
printf(" -r To reset the dynamical matrix at the gamma point by a 4th order\n");
printf(" polynomial interpolation along the [100] direction; this might be\n");
printf(" useful for systems with charges. As for charged system, the dynamical\n");
printf(" matrix at Gamma is far from accurate because of the long range nature\n");
printf(" of Coulombic interaction. By reset it by interpolation, will partially\n");
printf(" elliminate the unwanted behavior, but the result is still inaccurate.\n");
printf(" By default, this is not set; and not expected for uncharged systems.\n\n");
printf(" -s This will reset the dynamical matrix at the gamma point, too, but it\n");
printf(" will also inform the code to skip all q-points that is in the vicinity\n");
printf(" of the gamma point when evaluating phonon DOS and/or phonon dispersion.\n\n");
printf(" By default, this is not set; and not expected for uncharged systems.\n\n");
printf(" -p prec To define the precision for symmetry identification with spglib.\n");
printf(" By default, 1.e-3.\n\n");
printf(" -save To record user input in `script.inp`, facilitating scripting.\n\n");
printf(" -h To print out this help info.\n\n");
printf(" file To define the filename that carries the binary dynamical matrice generated\n");
printf(" by fix-phonon. If not provided, the code will ask for it.\n");
printf("\n\n");
exit(0);
}
/* ----------------------------------------------------------------------------
* Private method to display the version info
* ---------------------------------------------------------------------------- */
void DynMat::ShowVersion()
{
printf(" ____ _ _ __ _ _ __ \n");
printf(" ( _ \\( )_( ) /__\\ ( \\( ) /__\\ \n");
printf(" )___/ ) _ ( /(__)\\ ) ( /(__)\\ \n");
printf(" (__) (_) (_)(__)(__)(_)\\_)(__)(__)\n");
printf("\nPHonon ANAlyzer for Fix-Phonon, version 2.%02d, compiled on %s.\n", VERSION, __DATE__);
printf("Reference: https://doi.org/10.1016/j.cpc.2011.04.019\n");
return;
}
/* ----------------------------------------------------------------------------
* Private method to define the conversion factor from the DM measured to THZ
* for the phonon frequency and force constants.
* ---------------------------------------------------------------------------- */
void DynMat::Define_Conversion_Factor()
{
funit = new char[4];
strcpy(funit, "THz");
if (fabs(boltz - 1.) <= ZERO){ // LJ Unit
eml2f = eml2fc = 1.;
delete[] funit;
funit = new char[27];
strcpy(funit,"sqrt(epsilon/(m.sigma^2))");
} else if (fabs(boltz - 0.0019872067) <= ZERO){ // real
eml2f = 3.255487031;
eml2fc = 0.0433641042418;
} else if (fabs(boltz*1.e3 - 8.617343e-2) <= ZERO){ // metal
eml2f = 15.633304237154924;
eml2fc = 1.;
} else if (fabs(boltz*1.e20 - 1.3806504e-3) <= ZERO){ // si
eml2f = 1.591549431e-13;
eml2fc = 0.06241509074460763;
} else if (fabs(boltz*1.e13 - 1.3806504e-3) <= ZERO){ // cgs
eml2f = 1.591549431e-13;
eml2fc = 6.241509074460763e-05;
} else if (fabs(boltz*1.e3 - 3.16681534e-3) <= ZERO){ // electron
eml2f = 154.10792761319672;
eml2fc = 97.1736242922823;
} else if (fabs(boltz*1.e5 - 1.3806504e-3) <= ZERO){ // micro
eml2f = 1.5915494309189532e-07;
eml2fc = 6.241509074460763e-05;
} else if (fabs(boltz - 0.013806504) <= ZERO){ // nano
eml2f = 0.0001591549431;
eml2fc = 6.241509074460763e-05;
} else {
printf("WARNING: Perhaps because of float precision, I cannot get the factor to convert\n");
printf("sqrt(E/ML^2)/(2*pi) into THz, instead, I set it to 1; you should check the unit\nused by LAMMPS.\n");
eml2f = eml2fc = 1.;
}
return;
}
/* ----------------------------------------------------------------------------
* Private method to output the information read
* ---------------------------------------------------------------------------- */
void DynMat::ShowInfo()
{
puts("\n================================================================================");
printf("Dynamical matrix is read from file: %s\n", binfile);
printf("The system size in three dimension: %d x %d x %d\n", nx, ny, nz);
printf("Number of atoms per unit cell : %d\n", nucell);
printf("System dimension : %d\n", sysdim);
printf("Boltzmann constant in used units : %g\n", boltz);
puts("================================================================================");
return;
}
/* --------------------------------------------------------------------*/