1
c $Id: nwpw_xc.F 21510 2011-11-11 19:59:08Z bylaska $
3
* *********************************
7
* *********************************
8
subroutine nwpw_xc_init(nion0,nkatm0,
9
> nprj,nbasis,n1dgrid,psp_type,lmax0,
10
> nprj_max0,l_prj,m_prj,b_prj)
13
integer nprj(*),nbasis(*),n1dgrid(*),psp_type(*),lmax0(*)
15
integer l_prj(nprj_max0,*),m_prj(nprj_max0,*),b_prj(nprj_max0,*)
18
#include "mafdecls.fh"
22
c **** local variables ****
26
integer l,m,li,mi,lj,mj,bi,bj,iprj,jprj,lm
28
integer i_tlm,i_plm,i_rlm
31
real*8 tmp_theta,cs_theta,tmp_phi,tmp_gaunt
35
c **** external functions ****
36
integer control_gga,control_lmax_multipole
37
external control_gga,control_lmax_multipole
38
real*8 rtheta_lm,drtheta_lm,nwpw_gaunt,nwpw_gaunt2,nwpw_gaunt3
40
external rtheta_lm,drtheta_lm,nwpw_gaunt,nwpw_gaunt2,nwpw_gaunt3
41
external rtheta_lm_div
44
call nwpw_timing_start(4)
55
if (nprj(ia) .gt.nprj_max) nprj_max = nprj(ia)
56
if (nbasis(ia) .gt.nbasis_max) nbasis_max = nbasis(ia)
57
if (n1dgrid(ia).gt.n1dgrid_max) n1dgrid_max = n1dgrid(ia)
60
mult_l_max = control_lmax_multipole()
61
if (mult_l_max.lt.0) then
64
if (psp_type(ia).eq.4) then
65
if (mult_l_max.lt.(2*lmax0(ia))) mult_l_max = 2*lmax0(ia)
70
* ***paw_xc energies ***
71
ok = MA_alloc_get(mt_dbl,nion,"paw_xc_e",paw_xc_e(2),paw_xc_e(1))
74
* *** xc matrix arrays - nbasis_max**2 * (mult_l_max+1)**2 ***
75
mtr_size = 2*(nbasis_max**2)*((mult_l_max+1)**2)
77
> MA_alloc_get(mt_dbl,mtr_size,"paw_xc_matr",
78
> paw_xc_matr(2),paw_xc_matr(1))
82
> MA_alloc_get(mt_dbl,3*mtr_size,"paw_xc_dmatr_u",
83
> paw_xc_dmatr(2),paw_xc_dmatr(1))
86
> call errquit("init_paw_vxc: error allocating paw_xc_matr",
90
mtr_size = 2*nprj_max*nprj_max
91
ok = MA_alloc_get(mt_dbl,mtr_size,"paw_xc_pot",
92
> paw_xc_pot(2),paw_xc_pot(1))
94
> call errquit("init_paw_vxc: error allocating paw_xc_pot",
99
* *** spherical grid arrays ***
100
if(mult_l_max .eq. 0 ) then
104
paw_xc_nphi = 3*mult_l_max
105
paw_xc_ntheta = 3*mult_l_max
109
ok = MA_alloc_get(mt_dbl,paw_xc_nphi,"paw_xc_angle_phi",
110
> paw_xc_angle_phi(2),paw_xc_angle_phi(1))
113
> MA_alloc_get(mt_dbl,paw_xc_ntheta,"paw_xc_cos_theta",
114
> paw_xc_cos_theta(2),paw_xc_cos_theta(1))
117
> MA_alloc_get(mt_dbl,paw_xc_nphi,"paw_xc_w_phi",
118
> paw_xc_w_phi(2),paw_xc_w_phi(1))
121
> MA_alloc_get(mt_dbl,paw_xc_ntheta,"paw_xc_w_theta",
122
> paw_xc_w_theta(2),paw_xc_w_theta(1))
125
> MA_alloc_get(mt_dbl,
126
> paw_xc_ntheta*paw_xc_nphi*(mult_l_max+1)**2,
128
> paw_xc_tlm(2),paw_xc_tlm(1))
131
* **** used for generating derivatives of tlm's ****
134
c **** derivatives wrt to theta ****
136
> MA_alloc_get(mt_dbl,
137
> paw_xc_ntheta*paw_xc_nphi*(mult_l_max+1)**2,
138
> "paw_xc_dtlm_theta",
139
> paw_xc_dtlm_theta(2),paw_xc_dtlm_theta(1))
141
c **** derivatives wrt to phi ****
143
> MA_alloc_get(mt_dbl,
144
> paw_xc_ntheta*paw_xc_nphi*(mult_l_max+1)**2,
146
> paw_xc_dtlm_phi(2),paw_xc_dtlm_phi(1))
150
call nwpw_get_spher_grid(paw_xc_ntheta,paw_xc_nphi,
151
> dbl_mb(paw_xc_angle_phi(1)),
152
> dbl_mb(paw_xc_cos_theta(1)),
153
> dbl_mb(paw_xc_w_theta(1)),
154
> dbl_mb(paw_xc_w_phi(1)))
156
c **** define tlm's ****
158
do i_t=1,paw_xc_ntheta
162
tmp_theta = rtheta_lm(l,m,
163
> dbl_mb(paw_xc_cos_theta(1)+i_t-1))
164
angle_phi=dbl_mb(paw_xc_angle_phi(1)+i_p-1)
166
tmp_phi = dsin(abs(m)*angle_phi)
167
else if (m.gt.0) then
168
tmp_phi = dcos(abs(m)*angle_phi)
172
dbl_mb(paw_xc_tlm(1)+i_tlm) = tmp_theta*tmp_phi
181
c **** define derivative wrt to theta ****
183
do i_t=1,paw_xc_ntheta
187
tmp_theta = drtheta_lm(l,m,
188
> dbl_mb(paw_xc_cos_theta(1)+i_t-1))
189
angle_phi=dbl_mb(paw_xc_angle_phi(1)+i_p-1)
191
tmp_phi = dsin(abs(m)*angle_phi)
192
else if (m.gt.0) then
193
tmp_phi = dcos(abs(m)*angle_phi)
197
dbl_mb(paw_xc_dtlm_theta(1)+i_tlm) = tmp_theta*tmp_phi
204
c **** define derivative wrt to phi ****
206
do i_t=1,paw_xc_ntheta
211
dbl_mb(paw_xc_dtlm_phi(1)+ i_tlm) = 0.0d0
213
tmp_theta = rtheta_lm_div(l,m,
214
> dbl_mb(paw_xc_cos_theta(1)+i_t-1))
216
angle_phi=dbl_mb(paw_xc_angle_phi(1)+i_p-1)
218
tmp_phi = abs(m)*dcos(abs(m)*angle_phi)
219
else if (m.gt.0) then
220
tmp_phi = -abs(m)*dsin(abs(m)*angle_phi)
224
dbl_mb(paw_xc_dtlm_phi(1)+ i_tlm) = tmp_theta*tmp_phi
234
* *** temp arrays ***
235
nsize = 2*n1dgrid_max
237
> MA_alloc_get(mt_dbl,nsize,"rho_ae",rho_ae(2),rho_ae(1))
239
> MA_alloc_get(mt_dbl,nsize,"rho_ps",rho_ps(2),rho_ps(1))
241
* **** allocate gradient's and agr's ****
243
nsize = 2*3*n1dgrid_max
245
> MA_alloc_get(mt_dbl,nsize,
247
> rho_ae_prime(2),rho_ae_prime(1))
249
> MA_alloc_get(mt_dbl,nsize,
251
> rho_ps_prime(2),rho_ps_prime(1))
252
nsize = (2*2-1)*n1dgrid_max
254
> MA_alloc_get(mt_dbl,nsize,"agr_ae",agr_ae(2),agr_ae(1))
256
> MA_alloc_get(mt_dbl,nsize,"agr_ps",agr_ps(2),agr_ps(1))
258
> MA_alloc_get(mt_dbl,nsize,"fdn_ae",fdn_ae(2),fdn_ae(1))
260
> MA_alloc_get(mt_dbl,nsize,"fdn_ps",fdn_ps(2),fdn_ps(1))
263
nsize = 2*n1dgrid_max
265
> MA_alloc_get(mt_dbl,nsize,"vxc_ae",vxc_ae(2),vxc_ae(1))
267
> MA_alloc_get(mt_dbl,nsize,"vxc_ps",vxc_ps(2),vxc_ps(1))
269
> MA_alloc_get(mt_dbl,nsize,"exc_ae",exc_ae(2),exc_ae(1))
271
> MA_alloc_get(mt_dbl,nsize,"exc_ps",exc_ps(2),exc_ps(1))
273
> MA_alloc_get(mt_dbl,nsize,"xc_temp",
274
> xc_temp(2),xc_temp(1))
276
> MA_alloc_get(mt_dbl,nsize,"xc_temp2",
277
> xc_temp2(2),xc_temp2(1))
280
* *** allocate vxclm multipole expansion arrays ****
281
nsize = 2*n1dgrid_max*(mult_l_max+1)**2
284
> MA_alloc_get(mt_dbl,nsize,"paw_vxc_ae",
285
> paw_vxc_ae(2),paw_vxc_ae(1))
287
> MA_alloc_get(mt_dbl,nsize,"paw_vxc_ps",
288
> paw_vxc_ps(2),paw_vxc_ps(1))
290
* *** allocate dvxclm multipole expansion arrays ****
293
> MA_alloc_get(mt_dbl,3*nsize,
295
> paw_dvxc_ae(2),paw_dvxc_ae(1))
297
> MA_alloc_get(mt_dbl,3*nsize,
299
> paw_dvxc_ps(2),paw_dvxc_ps(1))
302
* *** allocate rholm multipole expansion arrays ****
304
> MA_alloc_get(mt_dbl,nsize,"paw_rho2_ae",
305
> paw_rho2_ae(2),paw_rho2_ae(1))
307
> MA_alloc_get(mt_dbl,nsize,"paw_rho2_ps",
308
> paw_rho2_ps(2),paw_rho2_ps(1))
310
* *** allocate rholm_prime multipole expansion arrays - need for GGA's****
313
> MA_alloc_get(mt_dbl,nsize,
314
> "paw_rho2_ae_prime",
315
> paw_rho2_ae_prime(2),paw_rho2_ae_prime(1))
317
> MA_alloc_get(mt_dbl,nsize,
318
> "paw_rho2_ps_prime",
319
> paw_rho2_ps_prime(2),paw_rho2_ps_prime(1))
322
> call errquit("nwpw_xc_init: error allocating work arrays",0,0)
324
c call nwpw_init_gntxc(mult_l_max)
325
c if ((gga.ge.10).and.(mult_l_max.ge.1)) then
326
c call nwpw_init_gntxc2(mult_l_max)
327
c call nwpw_init_gntxc3(mult_l_max)
331
* ***** set up index arrays for nwpw_xc_density_solve2 *****
332
ok = MA_alloc_get(mt_int,nkatm,"nindx_rholm",
333
> nindx_rholm(2),nindx_rholm(1))
335
> MA_alloc_get(mt_int,nkatm,"shift_rholm",
336
> shift_rholm(2),shift_rholm(1))
338
> call errquit("nwpw_xc_init: error allocating work arrays",0,0)
342
int_mb(shift_rholm(1)+ia-1) = nsize
351
if ((l.le.(li+lj)) .and. (l.ge.abs(li-lj))) then
352
tmp_gaunt = nwpw_gaunt(.false.,l,m,li,mi,lj,mj)
353
if (dabs(tmp_gaunt).gt.1.0d-11) then
362
int_mb(nindx_rholm(1)+ia-1) = nsize-int_mb(shift_rholm(1)+ia-1)
365
ok = MA_alloc_get(mt_int,nsize,"bi_rholm",bi_rholm(2),bi_rholm(1))
367
> MA_alloc_get(mt_int,nsize,"bj_rholm",bj_rholm(2),bj_rholm(1))
369
> MA_alloc_get(mt_int,nsize,"lm_rholm",lm_rholm(2),lm_rholm(1))
371
> MA_alloc_get(mt_int,nsize,"iprj_rholm",
372
> iprj_rholm(2),iprj_rholm(1))
374
> MA_alloc_get(mt_int,nsize,"jprj_rholm",
375
> jprj_rholm(2),jprj_rholm(1))
377
> MA_alloc_get(mt_dbl,nsize,"coeff_rholm",
378
> coeff_rholm(2),coeff_rholm(1))
380
> call errquit("nwpw_xc_init: error allocating work arrays",0,0)
395
if ((l.le.(li+lj)) .and. (l.ge.abs(li-lj))) then
396
tmp_gaunt = nwpw_gaunt(.false.,l,m,li,mi,lj,mj)
397
if (dabs(tmp_gaunt).gt.1.0d-11) then
398
dbl_mb(coeff_rholm(1)+nsize) = tmp_gaunt
399
int_mb(lm_rholm(1)+nsize) = lm
400
int_mb(iprj_rholm(1)+nsize) = iprj
401
int_mb(jprj_rholm(1)+nsize) = jprj
402
int_mb(bi_rholm(1)+nsize) = bi
403
int_mb(bj_rholm(1)+nsize) = bj
414
if ((gga.ge.10).and.(mult_l_max.gt.0)) then
415
ok = MA_alloc_get(mt_int,nkatm,"nindx_2rholm",
416
> nindx_2rholm(2),nindx_2rholm(1))
418
> MA_alloc_get(mt_int,nkatm,"shift_2rholm",
419
> shift_2rholm(2),shift_2rholm(1))
421
> call errquit("nwpw_xc_init: error allocating work arrays",0,0)
425
int_mb(shift_2rholm(1)+ia-1) = nsize
434
tmp_gaunt=nwpw_gaunt(.false.,l,m,li,mi,lj,mj)
435
if (dabs(tmp_gaunt).gt.1.0d-11) then
442
int_mb(nindx_2rholm(1)+ia-1)=nsize
443
> -int_mb(shift_2rholm(1)+ia-1)
445
ok = MA_alloc_get(mt_int,nsize,"bi_2rholm",
446
> bi_2rholm(2),bi_2rholm(1))
448
> MA_alloc_get(mt_int,nsize,"bj_2rholm",
449
> bj_2rholm(2),bj_2rholm(1))
451
> MA_alloc_get(mt_int,nsize,"lm_2rholm",
452
> lm_2rholm(2),lm_2rholm(1))
454
> MA_alloc_get(mt_int,nsize,"iprj_2rholm",
455
> iprj_2rholm(2),iprj_2rholm(1))
457
> MA_alloc_get(mt_int,nsize,"jprj_2rholm",
458
> jprj_2rholm(2),jprj_2rholm(1))
460
> MA_alloc_get(mt_dbl,nsize,"coeff_2rholm",
461
> coeff_2rholm(2),coeff_2rholm(1))
463
> call errquit("nwpw_xc_init: error allocating work arrays",0,0)
479
tmp_gaunt=nwpw_gaunt(.false.,l,m,li,mi,lj,mj)
480
if (dabs(tmp_gaunt).gt.1.0d-11) then
481
dbl_mb(coeff_2rholm(1)+nsize) = tmp_gaunt
482
int_mb(lm_2rholm(1)+nsize) = lm
483
int_mb(iprj_2rholm(1)+nsize) = iprj
484
int_mb(jprj_2rholm(1)+nsize) = jprj
485
int_mb(bi_2rholm(1)+nsize) = bi
486
int_mb(bj_2rholm(1)+nsize) = bj
496
ok = MA_alloc_get(mt_int,nkatm,"nindx_3rholm",
497
> nindx_3rholm(2),nindx_3rholm(1))
499
> MA_alloc_get(mt_int,nkatm,"shift_3rholm",
500
> shift_3rholm(2),shift_3rholm(1))
502
> call errquit("nwpw_xc_init: error allocating work arrays",0,0)
506
int_mb(shift_3rholm(1)+ia-1) = nsize
515
tmp_gaunt=nwpw_gaunt(.false.,l,m,li,mi,lj,mj)
516
if (dabs(tmp_gaunt).gt.1.0d-11) then
523
int_mb(nindx_3rholm(1)+ia-1)=nsize
524
> -int_mb(shift_3rholm(1)+ia-1)
526
ok = MA_alloc_get(mt_int,nsize,"bi_3rholm",
527
> bi_3rholm(2),bi_3rholm(1))
529
> MA_alloc_get(mt_int,nsize,"bj_3rholm",
530
> bj_3rholm(2),bj_3rholm(1))
532
> MA_alloc_get(mt_int,nsize,"lm_3rholm",
533
> lm_3rholm(2),lm_3rholm(1))
535
> MA_alloc_get(mt_int,nsize,"iprj_3rholm",
536
> iprj_3rholm(2),iprj_3rholm(1))
538
> MA_alloc_get(mt_int,nsize,"jprj_3rholm",
539
> jprj_3rholm(2),jprj_3rholm(1))
541
> MA_alloc_get(mt_dbl,nsize,"coeff_3rholm",
542
> coeff_3rholm(2),coeff_3rholm(1))
544
> call errquit("nwpw_xc_init: error allocating work arrays",0,0)
559
tmp_gaunt=nwpw_gaunt(.false.,l,m,li,mi,lj,mj)
560
if (dabs(tmp_gaunt).gt.1.0d-11) then
561
dbl_mb(coeff_3rholm(1)+nsize) = tmp_gaunt
562
int_mb(lm_3rholm(1)+nsize) = lm
563
int_mb(iprj_3rholm(1)+nsize) = iprj
564
int_mb(jprj_3rholm(1)+nsize) = jprj
565
int_mb(bi_3rholm(1)+nsize) = bi
566
int_mb(bj_3rholm(1)+nsize) = bj
579
call nwpw_timing_end(4)
583
* ********************************************
587
* ********************************************
588
subroutine nwpw_xc_solve(ii,ia,n1dgrid,nbasis,
589
> phi_ae,phi_ps,phi_ae_prime,phi_ps_prime,
590
> core_ae,core_ps,core_ae_prime,core_ps_prime,
592
> ispin,ne,nprj,sw1,sw2)
595
integer n1dgrid,nbasis
596
real*8 phi_ae(n1dgrid,nbasis)
597
real*8 phi_ps(n1dgrid,nbasis)
598
real*8 phi_ae_prime(n1dgrid,nbasis)
599
real*8 phi_ps_prime(n1dgrid,nbasis)
600
real*8 core_ae(n1dgrid)
601
real*8 core_ps(n1dgrid)
602
real*8 core_ae_prime(n1dgrid)
603
real*8 core_ps_prime(n1dgrid)
604
real*8 rgrid(n1dgrid)
607
integer ispin,ne(2),nprj
608
real*8 sw1(ne(1)+ne(2),nprj)
609
real*8 sw2(ne(1)+ne(2),nprj)
611
#include "mafdecls.fh"
612
#include "errquit.fh"
613
#include "nwpw_xc.fh"
616
integer i,j,np,i_tlm,i_tlm1,lmax2,nsize,shift,ig
620
* **** external functions ****
621
real*8 log_integrate_def
622
external log_integrate_def
624
call nwpw_timing_start(4)
625
call nwpw_timing_start(22)
627
* *** index for spin down in temp arrays ***
628
lmax2 = (mult_l_max+1)**2
629
dbl_mb(paw_xc_e(1)+ii-1)=0.0d0
631
* *** zero out vxclm multipole arrays ***
632
nsize = ispin*n1dgrid_max*lmax2
633
call dcopy(nsize,0.0d0,0,dbl_mb(paw_vxc_ae(1)),1)
634
call dcopy(nsize,0.0d0,0,dbl_mb(paw_vxc_ps(1)),1)
636
* *** zero out dvxclm multipole arrays ***
638
call dcopy(3*nsize,0.0d0,0,dbl_mb(paw_dvxc_ae(1)),1)
639
call dcopy(3*nsize,0.0d0,0,dbl_mb(paw_dvxc_ps(1)),1)
644
do i_t = 1,paw_xc_ntheta
645
do i_p = 1,paw_xc_nphi
647
* *** zero out temp arrays ***
648
nsize = ispin*n1dgrid_max
649
call dcopy(nsize,0.0d0,0,dbl_mb(rho_ae(1)),1)
650
call dcopy(nsize,0.0d0,0,dbl_mb(rho_ps(1)),1)
651
call dcopy(nsize,0.0d0,0,dbl_mb(vxc_ae(1)),1)
652
call dcopy(nsize,0.0d0,0,dbl_mb(vxc_ps(1)),1)
653
call dcopy(nsize,0.0d0,0,dbl_mb(exc_ae(1)),1)
654
call dcopy(nsize,0.0d0,0,dbl_mb(exc_ps(1)),1)
656
* *** find rholm multipole expansion on spherical grid ***
657
shift = int_mb(shift_rholm(1)+ia-1)
658
call nwpw_xc_density_solve2(ispin,ne,nprj,sw1,
659
> n1dgrid,nbasis,lmax2,
660
> int_mb(nindx_rholm(1)+ia-1),
661
> int_mb(lm_rholm(1)+shift),
662
> int_mb(iprj_rholm(1)+shift),
663
> int_mb(jprj_rholm(1)+shift),
664
> int_mb(bi_rholm(1)+shift),
665
> int_mb(bj_rholm(1)+shift),
666
> dbl_mb(coeff_rholm(1)+shift),
667
> phi_ae,phi_ps,rgrid,
668
> dbl_mb(paw_rho2_ae(1)),
669
> dbl_mb(paw_rho2_ps(1)))
672
* *** generate atomic densities on spherical grid ***
673
call nwpw_xc_gen_atomic_densities(n1dgrid,lmax2,ispin,
674
> dbl_mb(paw_rho2_ae(1)),
675
> dbl_mb(paw_xc_tlm(1)+i_tlm),
678
call nwpw_xc_gen_atomic_densities(n1dgrid,lmax2,ispin,
679
> dbl_mb(paw_rho2_ps(1)),
680
> dbl_mb(paw_xc_tlm(1)+i_tlm),
684
* ***************************************************
685
* *** find exchange-correlation on spherical grid ***
686
* ***************************************************
689
* **** LDA functionals on spherical grid ****
692
* **** LDA functionals of ae and ps atomic densities ****
693
call nwpw_vosko(n1dgrid,n1dgrid,ispin,
697
> dbl_mb(xc_temp(1)))
698
call nwpw_vosko(n1dgrid,n1dgrid,ispin,
702
> dbl_mb(xc_temp(1)))
705
* **** GGA functionals on spherical grid ****
708
* *** find rholm_prime multipole expansion on spherical grid ***
709
shift = int_mb(shift_rholm(1)+ia-1)
710
call nwpw_xc_density_prime_solve2(ispin,ne,nprj,sw1,
711
> n1dgrid,nbasis,lmax2,
712
> int_mb(nindx_rholm(1)+ia-1),
713
> int_mb(lm_rholm(1)+shift),
714
> int_mb(iprj_rholm(1)+shift),
715
> int_mb(jprj_rholm(1)+shift),
716
> int_mb(bi_rholm(1)+shift),
717
> int_mb(bj_rholm(1)+shift),
718
> dbl_mb(coeff_rholm(1)+shift),
720
> phi_ae_prime,phi_ps_prime,rgrid,
721
> dbl_mb(paw_rho2_ae_prime(1)),
722
> dbl_mb(paw_rho2_ps_prime(1)))
724
* *** generate the gradient of atomic densities in spherical ****
725
* **** coordinates on spherical grid ****
726
call nwpw_xc_gen_atomic_gradients(n1dgrid,lmax2,ispin,
727
> dbl_mb(paw_rho2_ae(1)),
728
> dbl_mb(paw_rho2_ae_prime(1)),
729
> dbl_mb(paw_xc_tlm(1)+i_tlm),
730
> dbl_mb(paw_xc_dtlm_theta(1)+i_tlm),
731
> dbl_mb(paw_xc_dtlm_phi(1)+i_tlm),
732
> rgrid,core_ae,core_ae_prime,
733
> dbl_mb(rho_ae_prime(1)))
735
call nwpw_xc_gen_atomic_gradients(n1dgrid,lmax2,ispin,
736
> dbl_mb(paw_rho2_ps(1)),
737
> dbl_mb(paw_rho2_ps_prime(1)),
738
> dbl_mb(paw_xc_tlm(1)+i_tlm),
739
> dbl_mb(paw_xc_dtlm_theta(1)+i_tlm),
740
> dbl_mb(paw_xc_dtlm_phi(1)+i_tlm),
741
> rgrid,core_ps,core_ps_prime,
742
> dbl_mb(rho_ps_prime(1)))
744
* **** generate agr ****
745
call nwpw_xc_gen_atomic_agr(n1dgrid,lmax2,ispin,
746
> dbl_mb(rho_ae_prime(1)),
748
call nwpw_xc_gen_atomic_agr(n1dgrid,lmax2,ispin,
749
> dbl_mb(rho_ps_prime(1)),
752
* **** GGA functionals of ae and ps atomic densities ****
753
call nwpw_gga(gga,n1dgrid,ispin,
757
> dbl_mb(vxc_ae(1)), !* df/dnup, df/dndn
758
> dbl_mb(fdn_ae(1)), !* df/d|grad nup|,df/d|grad ndn|, df/d|grad n|
759
> dbl_mb(xc_temp(1)))
760
call nwpw_gga(gga,n1dgrid,ispin,
764
> dbl_mb(vxc_ps(1)), !* df/dnup, df/dndn
765
> dbl_mb(fdn_ps(1)), !* df/d|grad nup|,df/d|grad ndn|, df/d|grad n|
766
> dbl_mb(xc_temp(1)))
769
c **** if restricted calculate df/d|grad n| *(grad n)/|grad n| ****
770
* ***** and put it in rho_prime ****
772
* **** if unrestricted calculate (df/d|grad nup|* (grad nup)/|grad nup|) ****
773
* **** + (df/d|grad n| * (grad n)/|grad n|) ****
774
* **** and calculate (df/d|grad ndn|* (grad ndn)/|grad ndn|) ****
775
* **** + (df/d|grad n| * (grad n)/|grad n|) ****
776
* ***** and put it in rho_prime ****
777
call nwpw_xc_gen_dvxc(n1dgrid,lmax2,ispin,
780
> dbl_mb(rho_ae_prime(1)))
781
call nwpw_xc_gen_dvxc(n1dgrid,lmax2,ispin,
784
> dbl_mb(rho_ps_prime(1)))
786
c **** find dvxclm multipole expansion ****
787
call nwpw_xc_addto_dvxclm(n1dgrid,lmax2,ispin,
788
> (dbl_mb(paw_xc_w_theta(1)+i_t-1)
789
> *dbl_mb(paw_xc_w_phi(1) +i_p-1)),
790
> dbl_mb(paw_xc_tlm(1)+i_tlm),
791
> dbl_mb(rho_ae_prime(1)),
792
> dbl_mb(rho_ps_prime(1)),
793
> dbl_mb(paw_dvxc_ae(1)),
794
> dbl_mb(paw_dvxc_ps(1)))
797
i_tlm = i_tlm + lmax2
800
* ************************************************************************************
801
* *** find vxclm the multipole expansion of atomic vxc=df/dn or (df/dnup,df/dndn) ***
802
* ************************************************************************************
803
call nwpw_xc_addto_vxclm(n1dgrid,lmax2,ispin,
804
> (dbl_mb(paw_xc_w_theta(1)+i_t-1)
805
> *dbl_mb(paw_xc_w_phi(1) +i_p-1)),
806
> dbl_mb(paw_xc_tlm(1)+i_tlm1),
809
> dbl_mb(paw_vxc_ae(1)),
810
> dbl_mb(paw_vxc_ps(1)))
811
i_tlm1 = i_tlm1 + lmax2
813
* ******************************************************
814
* *** compute the atomic exchange correlation energy ***
815
* ******************************************************
817
dbl_mb(xc_temp(1)+ig-1)=
819
> dbl_mb(rho_ae(1)+ig-1) +
820
> dbl_mb(rho_ae(1)+(ispin-1)*n1dgrid+ig-1)
821
> )*dbl_mb(exc_ae(1)+ig-1)
824
> dbl_mb(rho_ps(1)+ig-1)+
825
> dbl_mb(rho_ps(1)+(ispin-1)*n1dgrid+ig-1)
827
> dbl_mb(exc_ps(1)+ig-1)
829
exc_tmp = log_integrate_def(0,dbl_mb(xc_temp(1)),
830
> 2,rgrid,log_amesh,n1dgrid)
831
dbl_mb(paw_xc_e(1)+ii-1)=dbl_mb(paw_xc_e(1)+ii-1)+
833
> dbl_mb(paw_xc_w_theta(1)+i_t-1)*
834
> dbl_mb(paw_xc_w_phi(1)+i_p-1)
840
* *********************************************************
841
* **** non-local operator computation - LDA part ****
842
* *********************************************************
844
* **** compute (vxc^a)_nln'l'^lm radial integrals *****
845
call nwpw_xc_gen_matr(n1dgrid,nbasis,lmax2,ispin,
847
> phi_ae,phi_ps,rgrid,
848
> dbl_mb(paw_vxc_ae(1)),
849
> dbl_mb(paw_vxc_ps(1)),
850
> dbl_mb(xc_temp(1)),
851
> dbl_mb(paw_xc_matr(1)))
854
* **** xc potential non-local matrix elements ****
855
shift = int_mb(shift_rholm(1)+ia-1)
856
call nwpw_xc_sw1tosw2(ispin,ne,nprj,sw1,sw2,
857
> n1dgrid,nbasis,lmax2,
858
> int_mb(nindx_rholm(1)+ia-1),
859
> int_mb(lm_rholm(1)+shift),
860
> int_mb(iprj_rholm(1)+shift),
861
> int_mb(jprj_rholm(1)+shift),
862
> int_mb(bi_rholm(1)+shift),
863
> int_mb(bj_rholm(1)+shift),
864
> dbl_mb(coeff_rholm(1)+shift),
865
> dbl_mb(paw_xc_matr(1)))
869
c* *********************************************************
870
c* **** non-local operator computation - GGA part ****
871
c* *********************************************************
872
c if (gga.ge.10) then
874
c i_phi_ae0_prime = paw_basis_i_phi_ae_prime(ia)
875
c i_phi_ps0_prime = paw_basis_i_phi_ps_prime(ia)
877
c* **** compute (dvxc^a)_nln'l'^lm radial integrals *****
878
c call paw_xc_gen_dmatr(ng,nb,ic,istart,lmax2,ispin,
880
c > dbl_mb(i_phi_ae0),
881
c > dbl_mb(i_phi_ps0),
882
c > dbl_mb(i_phi_ae0_prime),
883
c > dbl_mb(i_phi_ps0_prime),
884
c > dbl_mb(i_r+istart-1),
885
c > dbl_mb(paw_dvxc_ae(1)),
886
c > dbl_mb(paw_dvxc_ps(1)),
887
c > dbl_mb(xc_c_temp(1)),
888
c > dbl_mb(paw_xc_dmatr(1)))
891
c* **** xc potential non-local matrix elements ****
892
c !i_pot0 = int_mb(i_paw_xc_pot(1) + in - 1)
894
c call paw_addto_potential_gntxc(ia,
895
c > dbl_mb(paw_xc_dmatr(1)+(ms-1)*nb2*lmax2*3),
896
c > dbl_mb(paw_xc_pot(1)+i_pot0+(ms-1)*paw_xc_pot_size))
899
cc **** theta and phi parts ****
900
c if (lmax2.gt.1) then
902
cc **** theta derivatives ****
904
c call paw_addto_potential_gntxc2(ia,
905
c > dbl_mb(paw_xc_dmatr(1)+nb2*lmax2+(ms-1)*nb2*lmax2*3),
906
c > dbl_mb(paw_xc_pot(1)+i_pot0+(ms-1)*paw_xc_pot_size))
909
cc **** phi derivatives ****
911
c call paw_addto_potential_gntxc3(ia,
912
c > dbl_mb(paw_xc_dmatr(1)+nb2*lmax2*2+(ms-1)*nb2*lmax2*3),
913
c > dbl_mb(paw_xc_pot(1)+i_pot0+(ms-1)*paw_xc_pot_size))
917
c end if !**lmax2>1**
925
cc **** xc non-local matrix elements ****
926
c call D3dB_Vector_Sumall(2*paw_xc_pot(3),
927
c > dbl_mb(paw_xc_pot(1)))
929
cc **** atomic exchange-correlation energies ****
930
c call D3dB_Vector_Sumall(paw_xc_e(3),dbl_mb(paw_xc_e(1)))
934
call nwpw_timing_end(4)
935
call nwpw_timing_end(22)
941
* *****************************************
945
* *****************************************
946
subroutine nwpw_xc_end()
949
#include "mafdecls.fh"
950
#include "errquit.fh"
951
#include "nwpw_xc.fh"
956
call nwpw_timing_start(4)
958
ok = ok.and.MA_free_heap(coeff_rholm(2))
959
ok = ok.and.MA_free_heap(jprj_rholm(2))
960
ok = ok.and.MA_free_heap(iprj_rholm(2))
961
ok = ok.and.MA_free_heap(lm_rholm(2))
962
ok = ok.and.MA_free_heap(bj_rholm(2))
963
ok = ok.and.MA_free_heap(bi_rholm(2))
964
ok = ok.and.MA_free_heap(shift_rholm(2))
965
ok = ok.and.MA_free_heap(nindx_rholm(2))
968
ok = ok.and.MA_free_heap(exc_ps(2))
969
ok = ok.and.MA_free_heap(exc_ae(2))
970
ok = ok.and.MA_free_heap(vxc_ps(2))
971
ok = ok.and.MA_free_heap(vxc_ae(2))
972
ok = ok.and.MA_free_heap(rho_ps(2))
973
ok = ok.and.MA_free_heap(rho_ae(2))
974
ok = ok.and.MA_free_heap(xc_temp(2))
975
ok = ok.and.MA_free_heap(xc_temp2(2))
977
ok = ok.and.MA_free_heap(paw_xc_e(2))
978
ok = ok.and.MA_free_heap(paw_xc_tlm(2))
979
ok = ok.and.MA_free_heap(paw_xc_w_theta(2) )
980
ok = ok.and.MA_free_heap(paw_xc_w_phi(2))
981
ok = ok.and.MA_free_heap(paw_xc_cos_theta(2))
982
ok = ok.and.MA_free_heap(paw_xc_angle_phi(2))
984
ok = ok.and.MA_free_heap(paw_xc_pot(2))
985
ok = ok.and.MA_free_heap(paw_xc_matr(2))
986
ok = ok.and.MA_free_heap(paw_vxc_ae(2))
987
ok = ok.and.MA_free_heap(paw_vxc_ps(2))
988
ok = ok.and.MA_free_heap(paw_rho2_ae(2))
989
ok = ok.and.MA_free_heap(paw_rho2_ps(2))
992
ok = ok.and.MA_free_heap(paw_rho2_ae_prime(2))
993
ok = ok.and.MA_free_heap(paw_rho2_ps_prime(2))
994
ok = ok.and.MA_free_heap(rho_ps_prime(2))
995
ok = ok.and.MA_free_heap(rho_ae_prime(2))
996
ok = ok.and.MA_free_heap(agr_ae(2))
997
ok = ok.and.MA_free_heap(agr_ps(2))
998
ok = ok.and.MA_free_heap(fdn_ae(2))
999
ok = ok.and.MA_free_heap(fdn_ps(2))
1000
ok = ok.and.MA_free_heap(paw_xc_dtlm_phi(2))
1001
ok = ok.and.MA_free_heap(paw_xc_dtlm_theta(2))
1002
ok = ok.and.MA_free_heap(paw_dvxc_ae(2))
1003
ok = ok.and.MA_free_heap(paw_dvxc_ps(2))
1004
ok = ok.and.MA_free_heap(paw_xc_dmatr(2))
1007
if ((gga.ge.10).and.(mult_l_max.gt.0)) then
1008
ok = ok.and.MA_free_heap(coeff_2rholm(2))
1009
ok = ok.and.MA_free_heap(jprj_2rholm(2))
1010
ok = ok.and.MA_free_heap(iprj_2rholm(2))
1011
ok = ok.and.MA_free_heap(lm_2rholm(2))
1012
ok = ok.and.MA_free_heap(bj_2rholm(2))
1013
ok = ok.and.MA_free_heap(bi_2rholm(2))
1014
ok = ok.and.MA_free_heap(shift_2rholm(2))
1015
ok = ok.and.MA_free_heap(nindx_2rholm(2))
1017
ok = ok.and.MA_free_heap(coeff_3rholm(2))
1018
ok = ok.and.MA_free_heap(jprj_3rholm(2))
1019
ok = ok.and.MA_free_heap(iprj_3rholm(2))
1020
ok = ok.and.MA_free_heap(lm_3rholm(2))
1021
ok = ok.and.MA_free_heap(bj_3rholm(2))
1022
ok = ok.and.MA_free_heap(bi_3rholm(2))
1023
ok = ok.and.MA_free_heap(shift_3rholm(2))
1024
ok = ok.and.MA_free_heap(nindx_3rholm(2))
1028
> call errquit("nwpw_xc_end: error freeing heap",0,MA_ERR)
1031
call nwpw_timing_end(4)
1036
* ******************************************
1038
* * nwpw_xc_energy_atom *
1040
* ******************************************
1041
real*8 function nwpw_xc_energy_atom()
1044
#include "mafdecls.fh"
1045
#include "errquit.fh"
1046
#include "nwpw_xc.fh"
1053
e = e + dbl_mb(paw_xc_e(1)+ii-1)
1055
nwpw_xc_energy_atom = e
1061
* ******************************************
1063
* * nwpw_xc_gen_sphere_rho *
1065
* ******************************************
1066
subroutine nwpw_xc_gen_sphere_rho(ng,lmax2,rholm,Tlm,rho)
1069
real*8 rholm(ng,lmax2)
1077
rho(ig) = rho(ig) + rholm(ig,lm)*Tlm(lm)
1085
* ******************************************
1087
* * nwpw_xc_rho_div_r *
1089
* ******************************************
1090
subroutine nwpw_xc_rho_div_r(ic,r,rho)
1098
rho(ig) = rho(ig)/r(ig)
1105
* ********************************************************
1107
* * nwpw_xc_addto_vxclm *
1109
* ********************************************************
1110
subroutine nwpw_xc_addto_vxclm(ic,lmax2,ispin,
1114
> vxclm_ae,vxclm_ps)
1116
integer ic,lmax2,ispin
1119
real*8 vxc_ae(ic,ispin)
1120
real*8 vxc_ps(ic,ispin)
1121
real*8 vxclm_ae(ic,lmax2,ispin)
1122
real*8 vxclm_ps(ic,lmax2,ispin)
1124
* **** local variables ****
1130
vxclm_ae(i,lm,ms) = vxclm_ae(i,lm,ms)
1131
> + vxc_ae(i,ms)*(tlm(lm)*alpha)
1132
vxclm_ps(i,lm,ms) = vxclm_ps(i,lm,ms)
1133
> + vxc_ps(i,ms)*(tlm(lm)*alpha)
1140
* ********************************************************
1142
* * nwpw_xc_gen_matr *
1144
* ********************************************************
1145
subroutine nwpw_xc_gen_matr(ng,nb,lmax2,ispin,log_amesh,
1147
> vxclm_ae,vxclm_ps,
1151
integer ng,nb,lmax2,ispin
1153
real*8 phi_ae(ng,nb)
1154
real*8 phi_ps(ng,nb)
1156
real*8 vxclm_ae(ng,lmax2,ispin)
1157
real*8 vxclm_ps(ng,lmax2,ispin)
1159
real*8 matr(nb,nb,lmax2,ispin)
1161
* **** local varialbles ****
1162
integer ig,i,j,lm,ms
1163
real*8 tmp_ae,tmp_ps
1165
* **** external functions ****
1166
real*8 log_integrate_def
1167
external log_integrate_def
1174
tmp_ae = phi_ae(ig,i)
1175
> *phi_ae(ig,j)/(r(ig)**2)
1176
tmp_ps = phi_ps(ig,i)
1177
> *phi_ps(ig,j)/(r(ig)**2)
1178
tmpC(ig) = vxclm_ae(ig,lm,ms)*tmp_ae
1179
> - vxclm_ps(ig,lm,ms)*tmp_ps
1181
matr(i,j,lm,ms)=log_integrate_def(0,tmpC,2,r,log_amesh,ng)
1182
if (i.ne.j) matr(j,i,lm,ms) = matr(i,j,lm,ms)
1191
* ********************************************************
1193
* * nwpw_xc_gen_atomic_densities *
1195
* ********************************************************
1196
subroutine nwpw_xc_gen_atomic_densities(ng,lmax2,ispin,
1202
integer ng,lmax2,ispin
1203
real*8 rholm(ng,lmax2,ispin)
1206
real*8 rho(ng,ispin)
1211
call nwpw_xc_gen_sphere_rho(ng,lmax2,
1215
call daxpy(ng,0.5d0,rhocore,1,rho(1,ms),1)
1217
rho(i,ms) = dabs(rho(i,ms))
1226
* ********************************************************
1228
* * nwpw_xc_gen_atomic_gradients *
1230
* ********************************************************
1231
subroutine nwpw_xc_gen_atomic_gradients(ic,lmax2,ispin,
1232
> rholm,rholm_prime,
1233
> tlm,dtlm_theta,dtlm_phi,
1234
> r,rhocore,rhocore_prime,
1237
integer ic,lmax2,ispin
1238
real*8 rholm(ic,lmax2,ispin)
1239
real*8 rholm_prime(ic,lmax2,ispin)
1241
real*8 dtlm_theta(lmax2)
1242
real*8 dtlm_phi(lmax2)
1245
real*8 rhocore_prime(ic)
1247
real*8 rho_prime(ic,3,ispin)
1252
call dcopy(3*ic*ispin,0.0d0,0,rho_prime,1)
1256
* *** find [d/dr paw_rho_ae] on spherical grid ***
1257
call nwpw_xc_gen_sphere_rho(ic,lmax2,
1258
> rholm_prime(1,1,ms),
1260
> rho_prime(1,1,ms))
1262
* *** add core d/dr densities***
1263
call daxpy(ic,0.5d0,rhocore_prime,1,rho_prime(1,1,ms),1)
1266
!*** only computate radial derivatives if lmax2==1 ****
1267
if (lmax2.gt.1) then
1269
* *** find (1/r) * d/dtheta paw_rho_ae on spherical grid ***
1270
call nwpw_xc_gen_sphere_rho(ic,lmax2,
1273
> rho_prime(1,2,ms))
1274
call nwpw_xc_rho_div_r(ic,r,rho_prime(1,2,ms))
1276
* *** find [(r*sin(theta)) * d/dphi paw_rho_ae] on spherical grid ***
1277
call nwpw_xc_gen_sphere_rho(ic,lmax2,
1280
> rho_prime(1,3,ms))
1281
call nwpw_xc_rho_div_r(ic,r,rho_prime(1,3,ms))
1292
* ************************************
1294
* * nwpw_xc_gen_atomic_agr *
1296
* ************************************
1298
* This function returns the absolute values of the gradient.
1300
* Entry - ic : number of grid points
1301
* ispin : restricted/unrestricted
1302
* rho_prime(ic,3,ispin) : gradient in spherical coordinates
1303
* of atomic spin densites nup and ndn
1305
* Exit - agr_in(*,1): |grad n| if restricted
1306
* Exit - agr_in(*,3): |grad nup|, |grad ndn|, and |grad n| if unrestricted
1308
subroutine nwpw_xc_gen_atomic_agr(ic,lmax2,ispin,
1312
integer ic,lmax2,ispin
1313
real*8 rho_prime(ic,3,ispin)
1314
real*8 agr(ic,*) !*(ic,2*ispin-1)
1319
!*** only computate radial derivatives if lmax2==1 ****
1320
if (lmax2.eq.1) then
1322
c **** compute |grad n| ****
1325
> = dsqrt( (rho_prime(ig,1,1)+rho_prime(ig,1,ispin))**2)
1328
c **** compute |grad nup| and |grad ndn| ****
1329
if (ispin.eq.2) then
1332
agr(ig,ms) = dsqrt(rho_prime(ig,1,ms)**2)
1339
!*** computate theta and phi derivatives if lmax2>1 ****
1341
c **** compute |grad n| ****
1344
> = dsqrt( (rho_prime(ig,1,1)+rho_prime(ig,1,ispin))**2
1345
> + (rho_prime(ig,2,1)+rho_prime(ig,2,ispin))**2
1346
> + (rho_prime(ig,3,1)+rho_prime(ig,3,ispin))**2)
1349
c **** compute |grad nup| and |grad ndn| ****
1350
if (ispin.eq.2) then
1353
agr(ig,ms) = dsqrt( rho_prime(ig,1,ms)**2
1354
> + rho_prime(ig,2,ms)**2
1355
> + rho_prime(ig,3,ms)**2)
1365
* ************************************
1367
* * nwpw_xc_gen_dvxc *
1369
* ************************************
1370
subroutine nwpw_xc_gen_dvxc(ic,lmax2,ispin,
1371
> fdn,agr,rho_prime)
1373
integer ic,lmax2,ispin
1376
real*8 rho_prime(ic,3,ispin)
1378
integer i,j,lm,ms,jmax
1379
real*8 drho1,drho2,drhoa
1381
!*** only computate radial derivatives if lmax2=1 ****
1382
if (lmax2.eq.1) then
1388
* *** restricted ****
1389
if (ispin.eq.1) then
1392
rho_prime(i,j,1) = (rho_prime(i,j,1)+rho_prime(i,j,1))
1393
> *(fdn(i,1)/agr(i,1))
1397
* *** unrestricted ****
1401
drho1 = rho_prime(i,j,1)
1402
drho2 = rho_prime(i,j,2)
1404
rho_prime(i,j,1) = (drho1/agr(i,1))*fdn(i,1)
1405
> + (drhoa/agr(i,3))*fdn(i,3)
1406
rho_prime(i,j,2) = (drho2/agr(i,2))*fdn(i,2)
1407
> + (drhoa/agr(i,3))*fdn(i,3)
1414
* ************************************
1416
* * nwpw_xc_addto_dvxclm *
1418
* ************************************
1419
subroutine nwpw_xc_addto_dvxclm(ic,lmax2,ispin,
1423
> dvxclm_ae,dvxclm_ps)
1425
integer ic,lmax2,ispin
1428
real*8 dvxc_ae(ic,3,ispin)
1429
real*8 dvxc_ps(ic,3,ispin)
1431
real*8 dvxclm_ae(ic,lmax2,3,ispin)
1432
real*8 dvxclm_ps(ic,lmax2,3,ispin)
1434
integer i,j,lm,ms,jmax
1436
!*** only computate radial derivatives if lmax2=1 ****
1437
if (lmax2.eq.1) then
1447
dvxclm_ae(i,lm,j,ms) = dvxclm_ae(i,lm,j,ms)
1448
> + dvxc_ae(i,j,ms)*(tlm(lm)*alpha)
1449
dvxclm_ps(i,lm,j,ms) = dvxclm_ps(i,lm,j,ms)
1450
> + dvxc_ps(i,j,ms)*(tlm(lm)*alpha)
1458
c* ************************************
1460
c* * nwpw_xc_gen_dmatr *
1462
c* ************************************
1464
c subroutine nwpw_xc_gen_dmatr(ng,nb,ic,istart,lmax2,
1465
c > ispin,log_amesh,
1467
c > phi_ae_prime,phi_ps_prime,
1469
c > dvxclm_ae,dvxclm_ps,
1473
c integer ng,nb,ic,istart,lmax2,ispin
1476
c real*8 phi_ae(ng,nb)
1477
c real*8 phi_ps(ng,nb)
1478
c real*8 phi_ae_prime(ng,nb)
1479
c real*8 phi_ps_prime(ng,nb)
1481
c real*8 dvxclm_ae(ic,lmax2,3,ispin)
1482
c real*8 dvxclm_ps(ic,lmax2,3,ispin)
1485
c real*8 dmatr(nb,nb,lmax2,3,ispin)
1487
c* **** local varialbles ****
1488
c integer ig,i,j,lm,ms
1489
c double precision tmp_ae,tmp_ps
1492
c* **** radial derivative integral ****
1500
c > = ( phi_ae_prime(ig+istart-1,i)*phi_ae(ig+istart-1,j)
1501
c > + phi_ae(ig+istart-1,i)*phi_ae_prime(ig+istart-1,j))
1503
c > - 2.0d0*phi_ae(ig+istart-1,i)*phi_ae(ig+istart-1,j)
1506
c > = ( phi_ps_prime(ig+istart-1,i)*phi_ps(ig+istart-1,j)
1507
c > + phi_ps(ig+istart-1,i)*phi_ps_prime(ig+istart-1,j))
1509
c > - 2.0d0*phi_ps(ig+istart-1,i)*phi_ps(ig+istart-1,j)
1513
c tmpC(ig) = dvxclm_ae(ig,lm,1,ms)*tmp_ae
1514
c > - dvxclm_ps(ig,lm,1,ms)*tmp_ps
1517
c dmatr(i,j,lm,1,ms)=log_integrate_def(0,tmpC,2,r,log_amesh,ic)
1518
c if (i.ne.j) dmatr(j,i,lm,1,ms) = dmatr(i,j,lm,1,ms)
1525
c* *** only comnpute theta and phi integrals if lmax2>1 ****
1526
c if (lmax2.gt.1) then
1528
c* **** theta derivative integral ****
1535
c tmp_ae = phi_ae(ig+istart-1,i)
1536
c > *phi_ae(ig+istart-1,j)
1538
c tmp_ps = phi_ps(ig+istart-1,i)
1539
c > *phi_ps(ig+istart-1,j)
1541
c tmpC(ig) = dvxclm_ae(ig,lm,2,ms)*tmp_ae
1542
c > - dvxclm_ps(ig,lm,2,ms)*tmp_ps
1544
c dmatr(i,j,lm,2,ms) =
1545
c > log_integrate_def(0,tmpC,2,r,log_amesh,ic,istart)
1546
c if (i.ne.j) dmatr(j,i,lm,2,ms) = dmatr(i,j,lm,2,ms)
1552
c* **** phi derivative integral ****
1559
c tmp_ae = phi_ae(ig+istart-1,i)
1560
c > *phi_ae(ig+istart-1,j)
1562
c tmp_ps = phi_ps(ig+istart-1,i)
1563
c > *phi_ps(ig+istart-1,j)
1565
c tmpC(ig) = dvxclm_ae(ig,lm,3,ms)*tmp_ae
1566
c > - dvxclm_ps(ig,lm,3,ms)*tmp_ps
1568
c dmatr(i,j,lm,3,ms)
1569
c > = log_integrate_def(0,tmpC,2,r,log_amesh,ic)
1570
c if (i.ne.j) dmatr(j,i,lm,3,ms) = dmatr(i,j,lm,3,ms)
1582
* *****************************************************
1584
* * nwpw_get_spher_grid *
1586
* *****************************************************
1587
subroutine nwpw_get_spher_grid(ntheta,nphi,angle_phi,
1588
> cos_theta,w_theta,w_phi)
1593
double precision cos_theta(ntheta)
1594
double precision angle_phi(nphi)
1595
double precision w_theta(ntheta)
1596
double precision w_phi(nphi)
1598
* *** local variables ***
1602
pi = 4.0d0*datan(1.0d0)
1604
* *** gaussian quadrature angular grid for cos_theta ***
1605
call nwpw_gauss_weights(-1.0d0,1.0d0,cos_theta,w_theta,ntheta)
1608
* *** linear angular grid for angle_phi***
1610
angle_phi(i) = 2.0d0*pi*(i-1)/dble(nphi-1)
1611
w_phi(i) = 2.0d0*pi/dble(nphi-1)
1613
w_phi(1) = 0.5d0*w_phi(1)
1614
w_phi(nphi) = w_phi(1)
1616
angle_phi(1) = 0.0d0
1622
* *****************************************************
1624
* * nwpw_gauss_weights *
1626
* *****************************************************
1627
subroutine nwpw_gauss_weights(x1, x2, x, w, n)
1630
double precision x1, x2
1631
double precision x(*), w(*)
1633
! *** local variables ***
1634
integer i, j, m, niter
1635
double precision eps
1636
parameter (eps = 3.0d-14)
1637
double precision p1, p2, p3, pp, xl, xm, z, z1,pi
1639
pi = 4.0d0*datan(1.0d0)
1641
xm = 0.5d0*(x2 + x1)
1642
xl = 0.5d0*(x2 - x1)
1645
z = cos(pi*(i - 0.25d0)/(n + 0.5d0))
1650
if (niter .ge. 1000000)
1651
> call errquit('cannot converge in gauss_weights',0,1)
1658
p1 = ((2.0d0*j - 1.0d0)*z*p2 - (j - 1.0d0)*p3)/j
1661
pp = n*(z*p1 - p2)/(z*z - 1.0d0)
1665
if (abs(z - z1) .gt. eps) go to 1
1667
x(n+1-i) = xm + xl*z
1668
w(i) = 2.0d0*xl/((1.0d0 - z*z)*pp*pp)
1675
c *********************************************
1677
c * nwpw_xc_density_solve2 *
1679
c *********************************************
1681
c Calculates the atomic density lm expansions from the
1682
c overlap coefficients.
1684
subroutine nwpw_xc_density_solve2(ispin,ne,nprj,sw1,
1685
> n1dgrid,nbasis,lmax2,
1687
> iprj_rholm,jprj_rholm,
1688
> bi_rholm,bj_rholm,
1692
> rholm_ae,rholm_ps)
1694
integer ispin,ne(2),nprj
1695
real*8 sw1(ne(1)+ne(2),nprj)
1696
integer n1dgrid,nbasis,lmax2
1697
integer nindx,lm_rholm(*),iprj_rholm(*),jprj_rholm(*)
1698
integer bi_rholm(*),bj_rholm(*)
1699
real*8 coeff_rholm(*)
1700
real*8 phi_ae(n1dgrid,nbasis),phi_ps(n1dgrid,nbasis)
1701
real*8 rgrid(n1dgrid)
1702
real*8 rholm_ae(n1dgrid,lmax2,ispin)
1703
real*8 rholm_ps(n1dgrid,lmax2,ispin)
1705
integer ms,n,i,lm,iprj,jprj,bi,bj,n1(2),n2(2)
1706
real*8 tmp_ms,coeff,w,scal
1708
* **** external functions ****
1709
real*8 lattice_omega
1710
external lattice_omega
1712
call nwpw_timing_start(21)
1717
scal = 1.0d0/lattice_omega()
1719
* ***init to zero***
1720
call dcopy(ispin*lmax2*n1dgrid,0.0d0,0,rholm_ae,1)
1721
call dcopy(ispin*lmax2*n1dgrid,0.0d0,0,rholm_ps,1)
1725
iprj = iprj_rholm(i)
1726
jprj = jprj_rholm(i)
1729
coeff = coeff_rholm(i)*scal
1731
if (ne(ms).gt.0) then
1734
w = w + sw1(n,iprj)*sw1(n,jprj)
1737
call nwpw_xc_density_gen_rho(n1dgrid,tmp_ms,
1738
> rgrid,phi_ae(1,bi),phi_ae(1,bj),
1739
> rholm_ae(1,lm+1,ms))
1740
call nwpw_xc_density_gen_rho(n1dgrid,tmp_ms,
1741
> rgrid,phi_ps(1,bi),phi_ps(1,bj),
1742
> rholm_ps(1,lm+1,ms))
1748
call nwpw_timing_end(21)
1752
subroutine nwpw_xc_density_gen_rho(ic,alpha,r,phi1,phi2,rho)
1755
double precision alpha
1756
double precision r(ic)
1757
double precision phi1(ic)
1758
double precision phi2(ic)
1759
double precision rho(ic)
1761
* **** local variables ****
1763
double precision tmp
1766
tmp = (phi1(i)*phi2(i))/(r(i)**2)
1767
rho(i) = rho(i) + alpha*tmp
1774
c *********************************************
1776
c * nwpw_xc_density_prime_solve2 *
1778
c *********************************************
1780
c Calculates the atomic density lm expansions from the
1781
c overlap coefficients.
1782
subroutine nwpw_xc_density_prime_solve2(ispin,ne,nprj,sw1,
1783
> n1dgrid,nbasis,lmax2,
1785
> iprj_rholm,jprj_rholm,
1786
> bi_rholm,bj_rholm,
1789
> dphi_ae,dphi_ps,rgrid,
1790
> rholm_ae_prime,rholm_ps_prime)
1792
integer ispin,ne(2),nprj
1793
real*8 sw1(ne(1)+ne(2),nprj)
1794
integer n1dgrid,nbasis,lmax2
1795
integer nindx,lm_rholm(*),iprj_rholm(*),jprj_rholm(*)
1796
integer bi_rholm(*),bj_rholm(*)
1797
real*8 coeff_rholm(*)
1798
real*8 phi_ae(n1dgrid,nbasis),phi_ps(n1dgrid,nbasis)
1799
real*8 dphi_ae(n1dgrid,nbasis),dphi_ps(n1dgrid,nbasis)
1800
real*8 rgrid(n1dgrid)
1801
real*8 rholm_ae_prime(n1dgrid,lmax2,ispin)
1802
real*8 rholm_ps_prime(n1dgrid,lmax2,ispin)
1804
integer ms,n,i,lm,iprj,jprj,bi,bj,n1(2),n2(2)
1805
real*8 tmp_ms,coeff,w,scal
1807
* **** external functions ****
1808
real*8 lattice_omega
1809
external lattice_omega
1811
call nwpw_timing_start(21)
1816
scal = 1.0d0/lattice_omega()
1818
* ***init to zero***
1819
call dcopy(n1dgrid*lmax2*ispin,0.0d0,0,rholm_ae_prime,1)
1820
call dcopy(n1dgrid*lmax2*ispin,0.0d0,0,rholm_ps_prime,1)
1824
iprj = iprj_rholm(i)
1825
jprj = jprj_rholm(i)
1828
coeff = coeff_rholm(i)*scal
1830
if (ne(ms).gt.0) then
1833
w = w + sw1(n,iprj)*sw1(n,jprj)
1836
call nwpw_xc_density_gen_drho(n1dgrid,tmp_ms,
1838
> phi_ae(1,bi),dphi_ae(1,bi),
1839
> phi_ae(1,bj),dphi_ae(1,bj),
1840
> rholm_ae_prime(1,lm+1,ms))
1841
call nwpw_xc_density_gen_drho(n1dgrid,tmp_ms,
1843
> phi_ps(1,bi),dphi_ps(1,bi),
1844
> phi_ps(1,bj),dphi_ps(1,bj),
1845
> rholm_ps_prime(1,lm+1,ms))
1850
call nwpw_timing_end(21)
1854
subroutine nwpw_xc_density_gen_drho(ic,alpha,r,
1860
double precision alpha
1861
double precision r(ic)
1862
double precision phi1(ic),dphi1(ic)
1863
double precision phi2(ic),dphi2(ic)
1864
double precision drho(ic)
1866
* **** local variables ****
1868
double precision tmp
1871
tmp = (dphi1(i)*phi2(i)+phi1(i)*dphi2(i))/(r(i)**2)
1872
> - 2.0d0*(phi1(i)*phi2(i))/(r(i)**3)
1873
drho(i) = drho(i) + alpha*tmp
1879
c *********************************************
1881
c * nwpw_xc_sw1tosw2 *
1883
c *********************************************
1885
subroutine nwpw_xc_sw1tosw2(ispin,ne,nprj,sw1,sw2,
1886
> n1dgrid,nbasis,lmax2,
1888
> iprj_rholm,jprj_rholm,
1889
> bi_rholm,bj_rholm,
1893
integer ispin,ne(2),nprj
1894
real*8 sw1(ne(1)+ne(2),nprj)
1895
real*8 sw2(ne(1)+ne(2),nprj)
1896
integer n1dgrid,nbasis,lmax2
1897
integer nindx,lm_rholm(*),iprj_rholm(*),jprj_rholm(*)
1898
integer bi_rholm(*),bj_rholm(*)
1899
real*8 coeff_rholm(*)
1900
real*8 matr(nbasis,nbasis,lmax2,ispin)
1902
integer ms,n,i,lm,iprj,jprj,bi,bj,n1(2),n2(2)
1903
real*8 tmp_ms,coeff,w,scal
1905
* **** external functions ****
1906
real*8 lattice_omega
1907
external lattice_omega
1909
call nwpw_timing_start(21)
1914
scal = 1.0d0/dsqrt(lattice_omega())
1916
* ***init to zero***
1919
iprj = iprj_rholm(i)
1920
jprj = jprj_rholm(i)
1923
coeff = coeff_rholm(i)*scal
1925
if (ne(ms).gt.0) then
1927
sw2(n,iprj) = sw2(n,iprj)
1928
> + coeff*matr(bi,bj,lm+1,ms)*sw1(n,jprj)
1933
call nwpw_timing_end(21)