subroutine diago_exc_cg(data_input, bd, pp, pt, pm, x) USE input_simple_exc USE simple_objects USE derived_objects USE kinds, ONLY : DP USE io_global, ONLY : stdout, ionode USE constants, ONLY : rytoev USE mp, ONLY : mp_barrier USE mp_world, ONLY : world_comm implicit none TYPE(input_options), INTENT(in) :: data_input TYPE(bands), INTENT(in) :: bd TYPE(prod_proj), INTENT(in) :: pp TYPE(potential), INTENT(in) :: pt TYPE(prod_mix), INTENT(in) :: pm TYPE(exc) :: h, Hx, Hx1, Hh, xtest TYPE(exc) :: x(data_input%nvec) INTEGER :: i, j, k, count=1, beginning, rate, end,kf COMPLEX(kind=DP) :: d=(0.1d0,0.0d0), a, b, c, fd, f2d, alpha,stim, minus=(-1.0d0,0.0d0), echeck COMPLEX(kind=DP), allocatable :: energy(:) LOGICAL :: test TYPE(exc) :: etmp1,etmp2,etmp3,etmp4 REAL(kind=DP) :: ene0,dene0,ene1,ene2,passop,passo,stima,enew,gamma,esse,essenew,ene COMPLEX(kind=DP) :: passot=(1.d0,0.d0),passos,sca, passot2=(0.4d0,0.d0) LOGICAL :: l_ok REAL(kind=DP) :: norm INTEGER :: icon INTEGER :: jj COMPLEX(kind=DP),ALLOCATABLE :: prods(:) TYPE(exc):: exc_a, exc_b allocate(prods(data_input%nvec)) call setup_exc(bd,h) call setup_exc(bd,Hx) call setup_exc(bd,Hx1) call setup_exc(bd,Hh) call setup_exc(bd,xtest) call setup_exc(bd,etmp1) call setup_exc(bd,etmp2) call setup_exc(bd,etmp3) call setup_exc(bd,etmp4) call setup_exc(bd,exc_a) call setup_exc(bd,exc_b) call mp_barrier(world_comm) allocate(energy(data_input%nvec)) write(stdout,*)data_input%nvec vectors: do j=1,data_input%nvec icon=0 call setup_exc(bd,x(j)) call randomize_exc(x(j)) !project out previously found states do jj=1,j-1 prods(jj)=-x(jj)*x(j) enddo do jj=1,j-1 exc_a=x(j) exc_b=prods(jj)*x(jj) !write(stdout,*) 'ENTRA DEBUG' x(j)=exc_a+exc_b !write(stdout,*) 'ESCI DEBUG' enddo call normalize_exc(x(j)) !x(j)%avc=0.d0 !x(j)%avc(1,1,1)=(1.d0,0.d0) call hamiltonian(data_input, 1, bd, pp, pt, pm, x(j), Hx,0) do jj=1,j-1 prods(jj)=-x(jj)*Hx enddo do jj=1,j-1 exc_a=Hx exc_b=prods(jj)*x(jj) Hx=exc_a+exc_b enddo call mp_barrier(world_comm) energy(j)=x(j)*Hx*rytoev!energy initialization h=(-1.d0,0.d0)*Hx!search direction initialization !call normalize_exc(h) esse=dble(h*h) ! h=minus*h l_ok=.true. iterate:do i=1,data_input%max_nstep echeck=energy(j) call mp_barrier(world_comm) call hamiltonian(data_input, 1, bd, pp, pt, pm, h, Hh,0) do jj=1,j-1 prods(jj)=-x(jj)*Hh enddo do jj=1,j-1 exc_a=Hh exc_b=prods(jj)*x(jj) !write(stdout,*) 'ENTRA DEBUG' Hh=exc_a+exc_b !write(stdout,*) 'ESCI DEBUG' enddo ene0=dble(x(j)*Hx) dene0=2.d0*dble(x(j)*Hh)-2.d0*ene0*dble(x(j)*h) norm=sqrt(dble(h*h)) if(.true.) then if(dene0>0.d0) then !dene0=-dene0 passot=-(1.d0,0.d0) passot2=-(2.d0,0.d0) else passot=(1.d0,0.d0) passot2=(2.,0.d0) endif else if(dene0>0.d0) then !dene0=-dene0 passot=-(0.5d0,0.d0)/norm passot2=-(1.d0,0.d0)/norm else passot=(0.5d0,0.d0)/norm passot2=(1.,0.d0)/norm endif endif etmp1=passot*h call sum_exc_sub(etmp2,x(j),etmp1) do jj=1,j-1 prods(jj)=-x(jj)*etmp2 enddo do jj=1,j-1 exc_a=etmp2 exc_b=prods(jj)*x(jj) etmp2=exc_a+exc_b enddo call normalize_exc(etmp2) call hamiltonian(data_input, 1, bd, pp, pt, pm, etmp2, etmp3,0) do jj=1,j-1 prods(jj)=-x(jj)*etmp3 enddo do jj=1,j-1 exc_a=etmp3 exc_b=prods(jj)*x(jj) etmp3=exc_a+exc_b enddo ene1=dble(etmp2*etmp3) etmp1=passot2*h call sum_exc_sub(etmp2,x(j),etmp1) do jj=1,j-1 prods(jj)=-x(jj)*etmp2 enddo do jj=1,j-1 exc_a=etmp2 exc_b=prods(jj)*x(jj) etmp2=exc_a+exc_b enddo call normalize_exc(etmp2) call hamiltonian(data_input, 1, bd, pp, pt, pm, etmp2, etmp3,0) do jj=1,j-1 prods(jj)=-x(jj)*etmp3 enddo do jj=1,j-1 exc_a=etmp3 exc_b=prods(jj)*x(jj) etmp3=exc_a+exc_b enddo ene2=dble(etmp2*etmp3) !call minparabola(ene0,dene0,ene1,dble(passot),passo,stima,l_ok) call minparabola2(ene0,ene1,ene2,dble(passot),dble(passot2),passo,stima,l_ok) ! do k=-1000,1000 ! passos=cmplx(dble(k)/20.d0,0.d0) ! etmp1=passos*h ! call sum_exc_sub(etmp2,x(j),etmp1) ! call normalize_exc(etmp2) ! call hamiltonian(data_input, 1, bd, pp, pt, pm, etmp2, etmp3,0) ! ene=dble(etmp2*etmp3) ! write(stdout,*) dble(k)/20.d0, ene*rytoev ! enddo if(l_ok) then passos=cmplx(passo,0.d0) etmp1=passos*h call sum_exc_sub(xtest,x(j),etmp1) else !write(stdout,*) l_ok,norm h=minus*Hx !ene2=ene0 !kf=0 !do k=1,40 ! sca=cmplx(dble(k)/10.d0,0.d0) ! etmp1=sca*h ! call sum_exc_sub(xtest,x(j),etmp1) ! call normalize_exc(xtest) ! call hamiltonian(data_input, 1, bd, pp, pt, pm, xtest, Hx1,0) ! enew=dble(xtest*Hx1) ! ! if(enew