PageRenderTime 57ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/src/TRAN_Set_IntegPath.c

https://github.com/certik/openmx
C | 1133 lines | 581 code | 295 blank | 257 comment | 70 complexity | 31cde782fd8630865e7abff1f42abb64 MD5 | raw file
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <math.h>
  5. #ifdef nompi
  6. #include "mimic_mpi.h"
  7. #else
  8. #include <mpi.h>
  9. #endif
  10. #include "tran_prototypes.h"
  11. #include "tran_variables.h"
  12. #include "lapack_prototypes.h"
  13. #define PI 3.1415926535897932384626
  14. typedef struct {
  15. double a,b;
  16. } dlists;
  17. /* Taisuke Ozaki Copyright (C) */
  18. static void Eigen_DGGEVX( int n, double **a, double **s, double *eval,
  19. double *resr, double *resi );
  20. /* Taisuke Ozaki Copyright (C) */
  21. static void zero_cfrac( int n, dcomplex *zp, dcomplex *Rp );
  22. /* Taisuke Ozaki Copyright (C) */
  23. static int dlists_cmp(const dlists *x, const dlists *y);
  24. /* Taisuke Ozaki Copyright (C) */
  25. static void dqsort(long n, double *a, double *b);
  26. /*
  27. * (0,3) -> (1,3)
  28. * A |
  29. * | V
  30. * (0,2) (1,2) ->(1+|VR-VL|,2)
  31. */
  32. void TRAN_Set_IntegPath_Square(void)
  33. {
  34. static int method=1; /* log or linear for the (1,3)->(1,2) path */
  35. int i,itotal;
  36. double x;
  37. double fac;
  38. dcomplex dx;
  39. tran_omega_n_scf=0;
  40. for (i=0;i<=3;i++) {
  41. tran_omega_n_scf += tran_square_path_div[i];
  42. }
  43. if (tran_bias_apply) {
  44. tran_omega_n_scf += tran_square_path_bias_div;
  45. }
  46. /* allocation */
  47. tran_omega_scf = (dcomplex*)malloc(sizeof(dcomplex)*tran_omega_n_scf);
  48. tran_omega_weight_scf=(dcomplex*)malloc(sizeof(dcomplex)*tran_omega_n_scf);
  49. tran_integ_method_scf=(int*)malloc(sizeof(int)*tran_omega_n_scf);
  50. /* calculate freq */
  51. /* spec = -1/PI Im G^R(w) */
  52. fac = 1.0/PI;
  53. itotal=0;
  54. /* (0,2)->(0,3) divided by div[0] */
  55. dx.r = 0.0;
  56. dx.i = ( tran_square_path_ene[3]- tran_square_path_ene[2] ) / tran_square_path_div[0];
  57. for (i=0;i<tran_square_path_div[0];i++) {
  58. x = (double)i+0.5;
  59. tran_omega_scf[itotal].r = tran_square_path_ene[0] + dx.r*x;
  60. tran_omega_scf[itotal].i = tran_square_path_ene[2] + dx.i*x;
  61. tran_omega_weight_scf[itotal].r = -dx.r*fac;
  62. tran_omega_weight_scf[itotal].i = -dx.i*fac;
  63. tran_integ_method_scf[itotal] = 1; /* equiv */
  64. itotal++;
  65. }
  66. /* (0,3) -> (1,3) by div[1] */
  67. dx.r = ( tran_square_path_ene[1]- tran_square_path_ene[0] ) / tran_square_path_div[1];
  68. dx.i = 0.0;
  69. for (i=0;i<tran_square_path_div[1];i++) {
  70. x=(double)i+0.5;
  71. tran_omega_scf[itotal].r = tran_square_path_ene[0] + dx.r*x;
  72. tran_omega_scf[itotal].i = tran_square_path_ene[3] + dx.i*x;
  73. tran_omega_weight_scf[itotal].r = -dx.r*fac;
  74. tran_omega_weight_scf[itotal].i = -dx.i*fac;
  75. tran_integ_method_scf[itotal] = 1; /* equiv */
  76. itotal++;
  77. }
  78. /* (1,3) -> (1,2) by div[2] */
  79. if (method==1) { /* linear */
  80. dx.r = 0.0;
  81. dx.i = ( tran_square_path_ene[2]- tran_square_path_ene[3] ) / tran_square_path_div[2];
  82. for (i=0;i<tran_square_path_div[2];i++) {
  83. x=i+0.5;
  84. tran_omega_scf[itotal].r = tran_square_path_ene[1] + dx.r*x;
  85. tran_omega_scf[itotal].i = tran_square_path_ene[3] + dx.i*x;
  86. tran_omega_weight_scf[itotal].r = -dx.r*fac;
  87. tran_omega_weight_scf[itotal].i = -dx.i*fac;
  88. tran_integ_method_scf[itotal] = 1; /* equiv */
  89. itotal++;
  90. }
  91. }
  92. else if (method==2) { /* log */
  93. /*
  94. c assuming
  95. c theta(1/2+i) = exp(th1+delta(1/2+i))
  96. c boundary condition
  97. c theta(0) = exp(th1) = exp( log(w4) ) = w4
  98. c theta(N3)= exp(th1+delta*N3)) = exp(th1+(th2-th1)/N3*N3) = exp(th2)= w3
  99. c delta = (th2-th1)/N3
  100. c integral weight
  101. c int d theta = int exp(th1+delta x) delta dx
  102. c => weight = exp(th1+delta(1/2+i))delta for ith
  103. c
  104. */
  105. double th1, th2,delta;
  106. th1 = log( tran_square_path_ene[3] );
  107. th2 = log (tran_square_path_ene[2] );
  108. delta = (th2-th1)/tran_square_path_div[2];
  109. for (i=0;i<tran_square_path_div[2];i++) {
  110. x = 0.5+i;
  111. tran_omega_scf[itotal].r = tran_square_path_ene[1] ;
  112. tran_omega_scf[itotal].i = exp(th1+delta*x);
  113. tran_omega_weight_scf[itotal].r = 0.0;
  114. tran_omega_weight_scf[itotal].i = -delta*exp(th1+delta*x)*fac;
  115. tran_integ_method_scf[itotal] = 1; /* equiv */
  116. itotal++;
  117. }
  118. } /* method */
  119. if ( tran_bias_apply ) {
  120. /* bias case, (NEGF) */
  121. /* path (1,2)-> (| V_L - V_R | + biasV ,2) */
  122. dx.r = ( fabs(tran_biasvoltage_e[0]-tran_biasvoltage_e[1]) +
  123. tran_square_path_bias_expandenergy ) / tran_square_path_bias_div;
  124. dx.i = 0;
  125. for (i=0;i<tran_square_path_bias_div;i++) {
  126. x=(double)i+0.5;
  127. tran_omega_scf[itotal].r = tran_square_path_ene[1] + dx.r*x;
  128. tran_omega_scf[itotal].i = tran_square_path_ene[2] + dx.i*x;
  129. /* -i/pi int A dw
  130. * -i dw = (dw.r+ i dw.i)*(-i) = ( dw.i -i dw.r )
  131. */
  132. tran_omega_weight_scf[itotal].r = dx.i*fac;
  133. tran_omega_weight_scf[itotal].i = -dx.r*fac;
  134. tran_integ_method_scf[itotal] = 2; /* non-equiv. */
  135. itotal++;
  136. }
  137. }
  138. /*debug*/
  139. printf("integral path\n");
  140. printf("id freq weight\n");
  141. for (i=0;i<tran_omega_n_scf;i++) {
  142. printf("%d %lf %lf %lf %lf\n",i, tran_omega_scf[i].r, tran_omega_scf[i].i,
  143. tran_omega_weight_scf[i].r, tran_omega_weight_scf[i].i);
  144. }
  145. printf("\n");
  146. /*end debug*/
  147. }
  148. /*****************************************************************************************
  149. *****************************************************************************************
  150. *****************************************************************************************/
  151. /*
  152. spectra = -1/pi Im G^R(w)
  153. */
  154. /*
  155. ----------
  156. / \ (1-gamma,3)
  157. / -------------(1,3)
  158. | x
  159. | x
  160. | x
  161. ---+------------------------------>
  162. (0,2)
  163. n = int_C A(x) nF(x) dx
  164. (0,2) -> (1-gamma,3) divided by n0
  165. (1-gamma,3)->(1,3) divided by n1
  166. if (applied_bias) additional points
  167. use
  168. double tran_thermalarc_path_ene[5];
  169. int tran_thermalarc_path_ene_fix[5];
  170. int tran_thermalarc_path_div[2];
  171. double tran_thermalarc_path_bias_expandenergy; for NEGF
  172. int tran_thermalarc_path_bias_div; for NEGF
  173. */
  174. void TRAN_Set_IntegPath_ThermalArc(void)
  175. {
  176. double f,factor,beta;
  177. double chem;
  178. int n_max;
  179. int i, itotal;
  180. double gamma, w1,w2,w3,w4;
  181. double a,b;
  182. double th1,th2,dth;
  183. /* find chem=chemical potential */
  184. chem = ( ChemP_e[0] < ChemP_e[1] )? ChemP_e[0] : ChemP_e[1] ;
  185. if ( tran_bias_apply ) {
  186. chem -= tran_thermalarc_path_bias_expandenergy;
  187. }
  188. n_max=100;
  189. f= PI*(2*n_max+1)*tran_temperature;
  190. if ( f< tran_thermalarc_path_ene[3] ) {
  191. printf("PI*(2*n_max+1)*tran_temperature (%lf) < tran_thermalarc_path_ene[3] (%lf)\n",
  192. f,tran_thermalarc_path_ene[3]);
  193. exit(0);
  194. }
  195. /* count max thermal freq */
  196. for (i=0;i<=n_max;i++) {
  197. f = (2.0*(double)i+1.0)*PI*tran_temperature;
  198. if (f> tran_thermalarc_path_ene[3]) {
  199. break;
  200. }
  201. }
  202. n_max = i;
  203. /* storage size */
  204. tran_omega_n_scf=0;
  205. for (i=0;i<=3;i++) {
  206. tran_omega_n_scf += tran_square_path_div[i];
  207. }
  208. tran_omega_n_scf += n_max; /* contribution of thermal freq */
  209. if (tran_bias_apply) {
  210. tran_omega_n_scf += tran_square_path_bias_div;
  211. }
  212. /* allocation */
  213. tran_omega_scf = (dcomplex*)malloc(sizeof(dcomplex)*tran_omega_n_scf);
  214. tran_omega_weight_scf=(dcomplex*)malloc(sizeof(dcomplex)*tran_omega_n_scf);
  215. tran_integ_method_scf=(int*)malloc(sizeof(int)*tran_omega_n_scf);
  216. /* calculate freq */
  217. /* spec = -1/PI Im G^R(w) */
  218. factor = 1.0/PI;
  219. itotal=0;
  220. /************
  221. 1st contribution
  222. calculate arc
  223. -----------
  224. / \
  225. / \(2,4)-(gamma,0)
  226. |
  227. |
  228. ---------+---------------------------
  229. (1,3) (b,0)
  230. radius = a
  231. center = (b,0)
  232. a^2 = (w1-b)^2+w3^2
  233. a^2 = (w2-gamma-b)^2+w4^2
  234. 0 = w1^2 -2 w1 b + w3^2
  235. - ( (w2-gamma)^2 - 2(w2-gamma) b + w4^2 )
  236. b = ( w1^2 + w3^2 - (w2-gamma)^2 - w4^2 ) / ( w1- (w2-gamma) )/2.0
  237. ******************/
  238. w1 = tran_thermalarc_path_ene[0];
  239. w2 = tran_thermalarc_path_ene[1];
  240. w3 = tran_thermalarc_path_ene[2];
  241. w4 = tran_thermalarc_path_ene[3];
  242. gamma = tran_thermalarc_path_ene[4];
  243. b = ( sqr( w1 ) +sqr(w3) - sqr( w2-gamma ) - sqr( w4 ) )/
  244. ( w1- w2+ gamma )*0.5;
  245. a = sqrt( sqr(w1-b) + sqr(w3) );
  246. /* comment
  247. (1,0) is 0 degree
  248. (sqrt(2)/2,sqrt(2)/2) is 45 degree
  249. (-1,0) is 180 degree */
  250. th1 = acos( (w1-b)/a );
  251. th2 = asin( w4/a );
  252. dth = (th2-th1)/tran_thermalarc_path_div[0];
  253. /* int_C a(x) nF(x) dx
  254. = int_C a(x(t)) (nF(x(t)) dx/dt) dt ,
  255. here calculate (nF(x(t)) dx/dt) */
  256. for (i=0;i<tran_thermalarc_path_div[0] ;i++) {
  257. double x,th,d;
  258. dcomplex z,z2,z1,fermi,dxdth;
  259. x=0.5+i;
  260. th = th1 + dth*x;
  261. z.r = a*cos(th)+b;
  262. z.i = a*sin(th);
  263. tran_omega_scf[itotal].r = z.r;
  264. tran_omega_scf[itotal].i = z.i;
  265. z2.r = beta*(z.r-chem); z2.i = beta*(z.i);
  266. z_exp_inline(z2,z1);
  267. z1.r += 1.0; /* z1 = exp(beta(z-chem))+1 */
  268. d = sqr(z1.r)+ sqr(z1.i);
  269. fermi.r = z1.r/d; fermi.i = -z1.i/d; /* fermi = 1/ (nf(beta(z-chem))+1 ) */
  270. dxdth.r= -a *sin(th)* dth; dxdth.i = a* cos(th)* dth;
  271. z_mul_inline(fermi, dxdth, z1);
  272. tran_omega_weight_scf[itotal].r = z1.r*factor;
  273. tran_omega_weight_scf[itotal].i = z1.i*factor;
  274. tran_integ_method_scf[itotal]=1;
  275. itotal++;
  276. }
  277. /*
  278. (2,4)-(gamma,0) -> (2,4)
  279. */
  280. {
  281. dcomplex w_int;
  282. w_int.r = gamma/w2; w_int.i =0.0;
  283. for (i=0;i<tran_thermalarc_path_div[1];i++) {
  284. double x,d;
  285. dcomplex z,z1,z2,fermi;
  286. x=0.5+i;
  287. z.r = w2-gamma+w_int.r*x; z.i = w4;
  288. tran_omega_scf[itotal].r = z.r;
  289. tran_omega_scf[itotal].i = z.i;
  290. z2.r = beta*(z.r-chem); z2.i = beta*(z.i);
  291. z_exp_inline(z2,z1); /* exp(beta(z-chem)) */
  292. z1.r += 1.0; /* z1 = exp(beta(z-chem))+1 */
  293. d = sqr(z1.r)+ sqr(z1.i);
  294. fermi.r = z1.r/d; fermi.i = -z1.i/d;
  295. z_mul_inline( w_int, fermi, z2);
  296. tran_omega_weight_scf[itotal].r = -z2.r*factor;
  297. tran_omega_weight_scf[itotal].i = -z2.i*factor;
  298. tran_integ_method_scf[itotal]=1;
  299. itotal++;
  300. }
  301. }
  302. /* contour integral */
  303. for (i=0;i<n_max;i++) {
  304. double th;
  305. th = (2.0*(double)i+1.0)*PI*tran_temperature;
  306. tran_omega_scf[itotal].r = chem;
  307. tran_omega_scf[itotal].i= th;
  308. tran_omega_weight_scf[itotal].r=0;
  309. tran_omega_weight_scf[itotal].i=-factor*2.0*PI*tran_temperature;
  310. tran_integ_method_scf[itotal]=1;
  311. itotal++;
  312. }
  313. /* applied bias */
  314. if (tran_bias_apply) {
  315. dcomplex w_int;
  316. factor = 1.0/(2.0*PI);
  317. w_int.r = (fabs(ChemP_e[0]-ChemP_e[1])+ tran_thermalarc_path_bias_expandenergy )/ tran_thermalarc_path_bias_div;
  318. w_int.i=0;
  319. for (i=0;i<tran_thermalarc_path_bias_div;i++) {
  320. double x;
  321. x=0.5+i;
  322. tran_omega_scf[itotal].r = chem+ w_int.r*x;
  323. tran_omega_scf[itotal].i = w2;
  324. tran_omega_weight_scf[itotal].r= w_int.i*factor;
  325. tran_omega_weight_scf[itotal].i= -w_int.r*factor;
  326. tran_integ_method_scf[itotal]=2;
  327. itotal++;
  328. }
  329. }
  330. }
  331. /* Taisuke Ozaki Copyright (C) */
  332. void TRAN_Set_IntegPath_GaussHG( double kBvalue, double Electronic_Temperature )
  333. {
  334. int p;
  335. double beta,R;
  336. R = 1.0e+12;
  337. if ( tran_bias_apply ){
  338. if (TRAN_Kspace_grid2==1 && TRAN_Kspace_grid3==1)
  339. tran_omega_n_scf = 2*(tran_num_poles + 1);
  340. else
  341. tran_omega_n_scf = 4*(tran_num_poles + 1);
  342. }
  343. else{
  344. if (TRAN_Kspace_grid2==1 && TRAN_Kspace_grid3==1)
  345. tran_omega_n_scf = tran_num_poles + 1;
  346. else
  347. tran_omega_n_scf = 2*(tran_num_poles + 1);
  348. }
  349. /* allocation */
  350. tran_omega_scf = (dcomplex*)malloc(sizeof(dcomplex)*tran_omega_n_scf);
  351. tran_omega_weight_scf=(dcomplex*)malloc(sizeof(dcomplex)*tran_omega_n_scf);
  352. tran_integ_method_scf=(int*)malloc(sizeof(int)*tran_omega_n_scf);
  353. zero_cfrac( tran_num_poles, tran_omega_scf, tran_omega_weight_scf );
  354. beta = 1.0/kBvalue/Electronic_Temperature;
  355. /*
  356. for (p=0; p<tran_num_poles; p++){
  357. printf("p=%3d zp.r=%15.12f zp.i=%15.12f Rp.r=%15.12f Rp.i=%15.12f\n",
  358. p, tran_zp[p].r, tran_zp[p].i, tran_Rp[p].r, tran_Rp[p].i );
  359. }
  360. */
  361. /* bias case */
  362. if ( tran_bias_apply ){
  363. /*************************************
  364. (1) finite bias and only Gamma point
  365. p=0,tran_num_poles-1
  366. poles for mu_L
  367. p=tran_num_poles
  368. iR for mu_L
  369. p=tran_num_poles+1,2*tran_num_poles
  370. poles for mu_R
  371. p=2*tran_num_poles+1
  372. iR for mu_R
  373. *************************************/
  374. if (TRAN_Kspace_grid2==1 && TRAN_Kspace_grid3==1){
  375. /* contribution of poles */
  376. for (p=0; p<tran_num_poles; p++){
  377. tran_omega_scf[p].r = ChemP_e[0];
  378. tran_omega_scf[p].i = tran_omega_scf[p].i/beta;
  379. tran_omega_weight_scf[p].r = -2.0*tran_omega_weight_scf[p].r/beta;
  380. tran_omega_weight_scf[p].i = 0.0;
  381. tran_integ_method_scf[p] = 3;
  382. tran_omega_scf[tran_num_poles+p+1].r = ChemP_e[1];
  383. tran_omega_scf[tran_num_poles+p+1].i = tran_omega_scf[p].i;
  384. tran_omega_weight_scf[tran_num_poles+p+1].r = tran_omega_weight_scf[p].r;
  385. tran_omega_weight_scf[tran_num_poles+p+1].i = 0.0;
  386. tran_integ_method_scf[tran_num_poles+p+1] = 4;
  387. }
  388. /* contribution of the half circle contour integral */
  389. tran_omega_scf[tran_num_poles].r = 0.0;
  390. tran_omega_scf[tran_num_poles].i = R;
  391. tran_omega_weight_scf[tran_num_poles].r = 0.0;
  392. tran_omega_weight_scf[tran_num_poles].i = 0.5*R;
  393. tran_integ_method_scf[tran_num_poles] = 3;
  394. tran_omega_scf[2*tran_num_poles+1].r = 0.0;
  395. tran_omega_scf[2*tran_num_poles+1].i = R;
  396. tran_omega_weight_scf[2*tran_num_poles+1].r = 0.0;
  397. tran_omega_weight_scf[2*tran_num_poles+1].i = 0.5*R;
  398. tran_integ_method_scf[2*tran_num_poles+1] = 4;
  399. }
  400. /*************************************
  401. (2) finite bias and lots of k-points
  402. p=0,tran_num_poles-1
  403. poles for retarded with mu_L
  404. p=tran_num_poles
  405. iR for retarded with mu_L
  406. p=tran_num_poles+1,2*tran_num_poles
  407. poles for advanced with mu_L
  408. p=2*tran_num_poles+1
  409. iR for advanced with mu_L
  410. p=2*tran_num_poles+2,3*tran_num_poles+1
  411. poles for retarded with mu_R
  412. p=3*tran_num_poles + 2
  413. iR for retarded with mu_L
  414. p=3*tran_num_poles+3,4*tran_num_poles+2
  415. poles for advanced with mu_L
  416. p=4*tran_num_poles+3
  417. iR for advanced with mu_L
  418. *************************************/
  419. else{
  420. /* contribution of poles */
  421. for (p=0; p<tran_num_poles; p++){
  422. /* retarded with mu_L */
  423. tran_omega_scf[p].r = ChemP_e[0];
  424. tran_omega_scf[p].i = tran_omega_scf[p].i/beta;
  425. tran_omega_weight_scf[p].r = -tran_omega_weight_scf[p].r/beta;
  426. tran_omega_weight_scf[p].i = 0.0;
  427. tran_integ_method_scf[p] = 3;
  428. /* advanced with mu_L */
  429. tran_omega_scf[tran_num_poles+p+1].r = ChemP_e[0];
  430. tran_omega_scf[tran_num_poles+p+1].i = -tran_omega_scf[p].i;
  431. tran_omega_weight_scf[tran_num_poles+p+1].r = tran_omega_weight_scf[p].r;
  432. tran_omega_weight_scf[tran_num_poles+p+1].i = 0.0;
  433. tran_integ_method_scf[tran_num_poles+p+1] = 3;
  434. /* retarded with mu_R */
  435. tran_omega_scf[2*tran_num_poles+p+2].r = ChemP_e[1];
  436. tran_omega_scf[2*tran_num_poles+p+2].i = tran_omega_scf[p].i;
  437. tran_omega_weight_scf[2*tran_num_poles+p+2].r = tran_omega_weight_scf[p].r;
  438. tran_omega_weight_scf[2*tran_num_poles+p+2].i = 0.0;
  439. tran_integ_method_scf[2*tran_num_poles+p+2] = 4;
  440. /* advanced with mu_R */
  441. tran_omega_scf[3*tran_num_poles+p+3].r = ChemP_e[1];
  442. tran_omega_scf[3*tran_num_poles+p+3].i = -tran_omega_scf[p].i;
  443. tran_omega_weight_scf[3*tran_num_poles+p+3].r = tran_omega_weight_scf[p].r;
  444. tran_omega_weight_scf[3*tran_num_poles+p+3].i = 0.0;
  445. tran_integ_method_scf[3*tran_num_poles+p+3] = 4;
  446. }
  447. /* contribution of the half circle contour integral */
  448. tran_omega_scf[tran_num_poles].r = 0.0;
  449. tran_omega_scf[tran_num_poles].i = R;
  450. tran_omega_weight_scf[tran_num_poles].r = 0.0;
  451. tran_omega_weight_scf[tran_num_poles].i = 0.25*R;
  452. tran_integ_method_scf[tran_num_poles] = 3;
  453. tran_omega_scf[2*tran_num_poles+1].r = 0.0;
  454. tran_omega_scf[2*tran_num_poles+1].i = R;
  455. tran_omega_weight_scf[2*tran_num_poles+1].r = 0.0;
  456. tran_omega_weight_scf[2*tran_num_poles+1].i = 0.25*R;
  457. tran_integ_method_scf[2*tran_num_poles+1] = 3;
  458. tran_omega_scf[3*tran_num_poles+2].r = 0.0;
  459. tran_omega_scf[3*tran_num_poles+2].i = R;
  460. tran_omega_weight_scf[3*tran_num_poles+2].r = 0.0;
  461. tran_omega_weight_scf[3*tran_num_poles+2].i = 0.25*R;
  462. tran_integ_method_scf[3*tran_num_poles+2] = 4;
  463. tran_omega_scf[4*tran_num_poles+3].r = 0.0;
  464. tran_omega_scf[4*tran_num_poles+3].i = R;
  465. tran_omega_weight_scf[4*tran_num_poles+3].r = 0.0;
  466. tran_omega_weight_scf[4*tran_num_poles+3].i = 0.25*R;
  467. tran_integ_method_scf[4*tran_num_poles+3] = 4;
  468. }
  469. }
  470. /* zero-bias case */
  471. else {
  472. /*************************************
  473. (3) zero-bias and only Gamma point
  474. *************************************/
  475. if (TRAN_Kspace_grid2==1 && TRAN_Kspace_grid3==1){
  476. /* contribution of poles */
  477. for (p=0; p<tran_num_poles; p++){
  478. tran_omega_scf[p].r = ChemP_e[0];
  479. tran_omega_scf[p].i = tran_omega_scf[p].i/beta;
  480. tran_omega_weight_scf[p].r = -2.0*tran_omega_weight_scf[p].r/beta;
  481. tran_omega_weight_scf[p].i = 0.0;
  482. }
  483. /* contribution of the half circle contour integral */
  484. tran_omega_scf[tran_num_poles].r = 0.0;
  485. tran_omega_scf[tran_num_poles].i = R;
  486. tran_omega_weight_scf[tran_num_poles].r = 0.0;
  487. tran_omega_weight_scf[tran_num_poles].i = 0.5*R;
  488. /* set the integral method in 1 */
  489. for (p=0; p<=tran_num_poles; p++){
  490. tran_integ_method_scf[p] = 1;
  491. }
  492. }
  493. /*************************************
  494. (4) zero-bias and lots of k-points
  495. p=0,tran_num_poles-1
  496. poles for retarded
  497. p=tran_num_poles
  498. iR for retarded
  499. p=tran_num_poles+1,2*tran_num_poles
  500. poles for advanced
  501. p=2*tran_num_poles+1
  502. iR for advanced
  503. *************************************/
  504. else{
  505. /* contribution of poles */
  506. for (p=0; p<tran_num_poles; p++){
  507. tran_omega_scf[p].r = ChemP_e[0];
  508. tran_omega_scf[p].i = tran_omega_scf[p].i/beta;
  509. tran_omega_weight_scf[p].r = -tran_omega_weight_scf[p].r/beta;
  510. tran_omega_weight_scf[p].i = 0.0;
  511. tran_integ_method_scf[p] = 1;
  512. tran_omega_scf[tran_num_poles+p+1].r = ChemP_e[0];
  513. tran_omega_scf[tran_num_poles+p+1].i =-tran_omega_scf[p].i;
  514. tran_omega_weight_scf[tran_num_poles+p+1].r = tran_omega_weight_scf[p].r;
  515. tran_omega_weight_scf[tran_num_poles+p+1].i = 0.0;
  516. tran_integ_method_scf[tran_num_poles+p+1] = 1;
  517. }
  518. /* contribution of the half circle contour integral */
  519. tran_omega_scf[tran_num_poles].r = 0.0;
  520. tran_omega_scf[tran_num_poles].i = R;
  521. tran_omega_weight_scf[tran_num_poles].r = 0.0;
  522. tran_omega_weight_scf[tran_num_poles].i = 0.25*R;
  523. tran_integ_method_scf[tran_num_poles] = 1;
  524. tran_omega_scf[2*tran_num_poles+1].r = 0.0;
  525. tran_omega_scf[2*tran_num_poles+1].i = R;
  526. tran_omega_weight_scf[2*tran_num_poles+1].r = 0.0;
  527. tran_omega_weight_scf[2*tran_num_poles+1].i = 0.25*R;
  528. tran_integ_method_scf[2*tran_num_poles+1] = 1;
  529. }
  530. }
  531. /*
  532. printf("ChemP_e[0]=%15.12f\n",ChemP_e[0]);
  533. printf("ChemP_e[1]=%15.12f\n",ChemP_e[1]);
  534. */
  535. }
  536. /* Taisuke Ozaki Copyright (C) */
  537. void zero_cfrac( int n, dcomplex *zp, dcomplex *Rp )
  538. {
  539. static int i,j,N;
  540. static double **a,**s,*eval,*resr,*resi;
  541. /* check input parameters */
  542. if (n<=0){
  543. printf("\ncould not find the number of zeros\n\n");
  544. MPI_Finalize();
  545. exit(0);
  546. }
  547. /* the total number of zeros including minus value */
  548. N = 2*n + 1;
  549. /* allocation of arrays */
  550. a = (double**)malloc(sizeof(double*)*(N+2));
  551. for (i=0; i<(N+2); i++){
  552. a[i] = (double*)malloc(sizeof(double)*(N+2));
  553. }
  554. s = (double**)malloc(sizeof(double*)*(N+2));
  555. for (i=0; i<(N+2); i++){
  556. s[i] = (double*)malloc(sizeof(double)*(N+2));
  557. }
  558. eval = (double*)malloc(sizeof(double)*(n+3));
  559. resr = (double*)malloc(sizeof(double)*(n+3));
  560. resi = (double*)malloc(sizeof(double)*(n+3));
  561. /* initialize arrays */
  562. for (i=0; i<(N+2); i++){
  563. for (j=0; j<(N+2); j++){
  564. a[i][j] = 0.0;
  565. s[i][j] = 0.0;
  566. }
  567. }
  568. /* set matrix elements */
  569. s[2][1] = 1.0;
  570. s[2][2] = -0.5;
  571. for (i=3; i<=N; i++){
  572. s[i][i-1] = -0.5;
  573. s[i-1][i] = 0.5;
  574. }
  575. a[1][1] = -2.0;
  576. a[1][2] = 1.0;
  577. a[2][2] = -1.0;
  578. for (i=3; i<=N; i++){
  579. a[i][i] = -(2.0*(double)i - 3.0);
  580. }
  581. /* diagonalization */
  582. Eigen_DGGEVX( N, a, s, eval, resr, resi );
  583. for (i=0; i<n; i++){
  584. zp[i].r = 0.0;
  585. zp[i].i = eval[i+1];
  586. Rp[i].r = resr[i+1];
  587. Rp[i].i = 0.0;
  588. }
  589. /* print result */
  590. /*
  591. for (i=1; i<=n; i++){
  592. printf("i=%4d eval=%18.14f resr=%18.15f resi=%18.15f\n",i,eval[i],resr[i],resi[i]);
  593. }
  594. */
  595. /*
  596. for (i=1; i<=n; i++){
  597. printf("%4d 0.0 %18.14f\n",i,eval[i]);
  598. }
  599. MPI_Finalize();
  600. exit(0);
  601. */
  602. /* free of arrays */
  603. for (i=0; i<(N+2); i++){
  604. free(a[i]);
  605. }
  606. free(a);
  607. for (i=0; i<(N+2); i++){
  608. free(s[i]);
  609. }
  610. free(s);
  611. free(eval);
  612. free(resr);
  613. free(resi);
  614. }
  615. /* Taisuke Ozaki Copyright (C) */
  616. void dqsort(long n, double *a, double *b)
  617. {
  618. int i;
  619. dlists *AB;
  620. AB = (dlists*)malloc(sizeof(dlists)*n);
  621. for (i=0; i<n; i++){
  622. AB[i].a = a[i+1];
  623. AB[i].b = b[i+1];
  624. }
  625. qsort(AB, n, sizeof(dlists), (int(*)(const void*, const void*))dlists_cmp);
  626. for (i=0; i<n; i++){
  627. a[i+1] = AB[i].a;
  628. b[i+1] = AB[i].b;
  629. }
  630. free(AB);
  631. }
  632. /* Taisuke Ozaki Copyright (C) */
  633. int dlists_cmp(const dlists *x, const dlists *y)
  634. {
  635. return (x->a < y->a ? -1 :
  636. y->a < x->a ? 1 : 0);
  637. }
  638. /* Taisuke Ozaki Copyright (C) */
  639. void Eigen_DGGEVX( int n, double **a, double **s, double *eval, double *resr, double *resi )
  640. {
  641. static int i,j,k,l,num;
  642. static char balanc = 'N';
  643. static char jobvl = 'V';
  644. static char jobvr = 'V';
  645. static char sense = 'B';
  646. static double *A;
  647. static double *b;
  648. static double *alphar;
  649. static double *alphai;
  650. static double *beta;
  651. static double *vl;
  652. static double *vr;
  653. static double *lscale;
  654. static double *rscale;
  655. static double abnrm;
  656. static double bbnrm;
  657. static double *rconde;
  658. static double *rcondv;
  659. static double *work;
  660. static double *tmpvecr,*tmpveci;
  661. static INTEGER *iwork;
  662. static INTEGER lda,ldb,ldvl,ldvr,ilo,ihi;
  663. static INTEGER lwork,info;
  664. static logical *bwork;
  665. static double sumr,sumi,tmpr,tmpi;
  666. static double *sortnum;
  667. lda = n;
  668. ldb = n;
  669. ldvl = n;
  670. ldvr = n;
  671. A = (double*)malloc(sizeof(double)*n*n);
  672. b = (double*)malloc(sizeof(double)*n*n);
  673. alphar = (double*)malloc(sizeof(double)*n);
  674. alphai = (double*)malloc(sizeof(double)*n);
  675. beta = (double*)malloc(sizeof(double)*n);
  676. vl = (double*)malloc(sizeof(double)*n*n);
  677. vr = (double*)malloc(sizeof(double)*n*n);
  678. lscale = (double*)malloc(sizeof(double)*n);
  679. rscale = (double*)malloc(sizeof(double)*n);
  680. rconde = (double*)malloc(sizeof(double)*n);
  681. rcondv = (double*)malloc(sizeof(double)*n);
  682. lwork = 2*n*n + 12*n + 16;
  683. work = (double*)malloc(sizeof(double)*lwork);
  684. iwork = (INTEGER*)malloc(sizeof(INTEGER)*(n+6));
  685. bwork = (logical*)malloc(sizeof(logical)*n);
  686. tmpvecr = (double*)malloc(sizeof(double)*(n+2));
  687. tmpveci = (double*)malloc(sizeof(double)*(n+2));
  688. sortnum = (double*)malloc(sizeof(double)*(n+2));
  689. /* convert two dimensional arrays to one-dimensional arrays */
  690. for (i=0; i<n; i++) {
  691. for (j=0; j<n; j++) {
  692. A[j*n+i]= a[i+1][j+1];
  693. b[j*n+i]= s[i+1][j+1];
  694. }
  695. }
  696. /* call dggevx_() */
  697. F77_NAME(dggevx,DGGEVX)(
  698. &balanc, &jobvl, & jobvr, &sense, &n, A, &lda, b, &ldb,
  699. alphar, alphai, beta, vl, &ldvl, vr, &ldvr, &ilo, &ihi,
  700. lscale, rscale, &abnrm, &bbnrm, rconde, rcondv, work,
  701. &lwork, iwork, bwork, &info );
  702. if (info!=0){
  703. printf("Errors in dggevx_() info=%2d\n",info);
  704. }
  705. /*
  706. for (i=0; i<n; i++){
  707. printf("i=%4d %18.13f %18.13f %18.13f\n",i,alphar[i],alphai[i],beta[i]);
  708. }
  709. printf("\n");
  710. */
  711. num = 0;
  712. for (i=0; i<n; i++){
  713. if ( 1.0e-13<fabs(beta[i]) && 0.0<alphai[i]/beta[i] ){
  714. /* normalize the eigenvector */
  715. for (j=0; j<n; j++) {
  716. sumr = 0.0;
  717. sumi = 0.0;
  718. for (k=0; k<n; k++) {
  719. sumr += s[j+1][k+1]*vr[i*n +k];
  720. sumi += s[j+1][k+1]*vr[(i+1)*n+k];
  721. }
  722. tmpvecr[j] = sumr;
  723. tmpveci[j] = sumi;
  724. }
  725. sumr = 0.0;
  726. sumi = 0.0;
  727. for (k=0; k<n; k++) {
  728. sumr += vl[i*n+k]*tmpvecr[k] + vl[(i+1)*n+k]*tmpveci[k];
  729. sumi += vl[i*n+k]*tmpveci[k] - vl[(i+1)*n+k]*tmpvecr[k];
  730. }
  731. /* calculate zero point and residue */
  732. eval[num+1] = alphai[i]/beta[i];
  733. tmpr = vr[i*n]*vl[i*n] + vr[(i+1)*n]*vl[(i+1)*n];
  734. tmpi = -vr[i*n]*vl[(i+1)*n] + vr[(i+1)*n]*vl[i*n];
  735. resr[num+1] = tmpi/sumi;
  736. resi[num+1] = -tmpr/sumi;
  737. num++;
  738. }
  739. else{
  740. /*
  741. printf("i=%4d %18.13f %18.13f %18.13f\n",i+1,alphar[i],alphai[i],beta[i]);
  742. */
  743. }
  744. }
  745. /* check round-off error */
  746. for (i=1; i<=num; i++){
  747. if (1.0e-8<fabs(resi[i])){
  748. printf("Could not calculate zero points and residues due to round-off error\n");
  749. MPI_Finalize();
  750. exit(0);
  751. }
  752. }
  753. /* sorting */
  754. dqsort(num,eval,resr);
  755. /* free arraies */
  756. free(A);
  757. free(b);
  758. free(alphar);
  759. free(alphai);
  760. free(beta);
  761. free(vl);
  762. free(vr);
  763. free(lscale);
  764. free(rscale);
  765. free(rconde);
  766. free(rcondv);
  767. free(work);
  768. free(iwork);
  769. free(bwork);
  770. free(tmpvecr);
  771. free(tmpveci);
  772. free(sortnum);
  773. }
  774. void TRAN_Set_IntegPath( double kBvalue, double Electronic_Temperature )
  775. {
  776. if ( tran_integ_pathtype==1 ) {
  777. TRAN_Set_IntegPath_Square();
  778. }
  779. else if ( tran_integ_pathtype==10 ) {
  780. TRAN_Set_IntegPath_ThermalArc();
  781. }
  782. /* Taisuke Ozaki Copyright (C) */
  783. else if ( tran_integ_pathtype==3 ) {
  784. TRAN_Set_IntegPath_GaussHG( kBvalue, Electronic_Temperature );
  785. }
  786. else {
  787. printf("abort tran_integ_pathtype=%d, not supported\n",tran_integ_pathtype);
  788. exit(10);
  789. }
  790. }