<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Ciao Paolo,<div class=""><br class=""></div><div class="">the code you commit has few issues on different compilers. Here one for example:</div><div class=""><br class=""></div><div class=""><font face="Courier New" class=""> pgf90 -fast -r8 -Mcache_align -mp -D__PGI -D__OPENMP -D__FFTW   -I../../include -I../../iotk/src -I../../Modules -I../../PHonon/Gamma/ -I../../PHonon/PH/ -I../../PW/src -I../../FFTXlib -I../../LAXlib -I../pw4gww -I../gww -I. -c plot_excwfn.F90 -o plot_excwfn.o<br class="">PGF90-S-0141-Derived Type object required on left of % (plot_excwfn.F90: 70)<br class="">PGF90-S-0075-Subscript, substring, or argument illegal in this context for v_rt (plot_excwfn.F90: 70)<br class="">PGF90-S-0038-Symbol, v_rt, has not been explicitly declared (plot_excwfn.F90)<br class="">  0 inform,   0 warnings,   3 severes, 0 fatal for plot_excwfn<br class="">make[2]: *** [plot_excwfn.o] Error 2</font><div class=""><br class=""></div><div class=""><br class=""></div><div class="">I will correct minor issues myself if those are immediate to fix. </div><div class=""><br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">--<br class="">Mr. Filippo SPIGA, M.Sc.<br class="">Quantum ESPRESSO Foundation<br class=""><a href="http://www.quantum-espresso.org" class="">http://www.quantum-espresso.org</a> ~ skype: filippo.spiga<br class=""><br class="">*****<br class="">Disclaimer: "Please note this message and any attachments are CONFIDENTIAL and may be privileged or otherwise protected from disclosure. The contents are not to be disclosed to anyone other than the addressee. Unauthorized recipients are requested to preserve this confidentiality and to advise the sender immediately of any error in transmission."</div>
</div>
<br class=""><blockquote type="cite" class="">On Mar 21, 2016, at 11:09 AM, <a href="mailto:puma@qeforge.qe-forge.org" class="">puma@qeforge.qe-forge.org</a> wrote:<br class=""><br class="">Author: puma<br class="">Date: 2016-03-21 12:09:18 +0100 (Mon, 21 Mar 2016)<br class="">New Revision: 12231<br class=""><br class="">Added:<br class="">  trunk/espresso/GWW/bse/absorption.f90<br class="">  trunk/espresso/GWW/bse/bse_basic_structure.f90<br class="">  trunk/espresso/GWW/bse/bse_main.f90<br class="">  trunk/espresso/GWW/bse/bse_wannier.f90<br class="">  trunk/espresso/GWW/bse/cgsolve.f90<br class="">  trunk/espresso/GWW/bse/check_basis.f90<br class="">  trunk/espresso/GWW/bse/conj_grad_stuff.f90<br class="">  trunk/espresso/GWW/bse/conjgrad.f90<br class="">  trunk/espresso/GWW/bse/contract_w_exc.f90<br class="">  trunk/espresso/GWW/bse/diago_exc.f90<br class="">  trunk/espresso/GWW/bse/direct_v_exc.f90<br class="">  trunk/espresso/GWW/bse/direct_w_exc.f90<br class="">  trunk/espresso/GWW/bse/dvpsi_bse.f90<br class="">  trunk/espresso/GWW/bse/exc_h_a.f90<br class="">  trunk/espresso/GWW/bse/exchange_exc.f90<br class="">  trunk/espresso/GWW/bse/exciton.f90<br class="">  trunk/espresso/GWW/bse/find_eig.f90<br class="">  trunk/espresso/GWW/bse/h_h.f90<br class="">  trunk/espresso/GWW/bse/lanczos.f90<br class="">  trunk/espresso/GWW/bse/openfil_bse.f90<br class="">  trunk/espresso/GWW/bse/plot_excwfn.f90<br class="">  trunk/espresso/GWW/bse/print_bse.f90<br class="">  trunk/espresso/GWW/bse/print_spectrum.f90<br class="">  trunk/espresso/GWW/bse/qpcorrections.f90<br class="">  trunk/espresso/GWW/bse/qpe_exc.f90<br class="">  trunk/espresso/GWW/bse/read_export.f90<br class="">  trunk/espresso/GWW/bse/rotate_wannier.f90<br class="">  trunk/espresso/GWW/bse/sdescent.f90<br class="">  trunk/espresso/GWW/bse/spectrum.f90<br class="">  trunk/espresso/GWW/bse/start_bse.f90<br class="">  trunk/espresso/GWW/bse/tmp.f90<br class="">  trunk/espresso/GWW/bse/transitions.f90<br class="">  trunk/espresso/GWW/bse/tspace.f90<br class="">  trunk/espresso/GWW/bse/write_wannier_matrix.f90<br class="">Log:<br class="">Fortran files of new GWL BSE code.<br class=""><br class=""><br class=""><br class="">Added: trunk/espresso/GWW/bse/absorption.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/absorption.f90<span class="Apple-tab-span" style="white-space:pre">  </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/absorption.f90<span class="Apple-tab-span" style="white-space:pre">   </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,280 @@<br class="">+subroutine absorption(vstate_r,psibar,fc,ieig,ampl,ipol)<br class="">+!this subroutine handles the computation of the absorption spectrum<br class="">+<br class="">+USE bse_wannier, ONLY : l_finite,r_pola,num_nbndv<br class="">+USE cell_base,   ONLY : at,alat<br class="">+USE bse_basic_structures<br class="">+USE fft_custom_gwl<br class="">+USE wvfct,       ONLY : npw<br class="">+<br class="">+<br class="">+implicit none<br class="">+TYPE(v_state_r),INTENT(in) :: vstate_r<br class="">+TYPE(fft_cus),  INTENT(in) :: fc<br class="">+REAL(DP),       INTENT(out):: ampl<br class="">+INTEGER,        INTENT(in) :: ieig,ipol<br class="">+COMPLEX(DP),    INTENT(in) :: psibar(npw,num_nbndv(1))<br class="">+<br class="">+REAL(DP) ::  imod_rpola<br class="">+REAL(DP) :: upol(3,3)<br class="">+<br class="">+data upol /1.0d0,0.0d0,0.0d0, 0.0d0,1.0d0,0.0d0, 0.0d0,0.0d0,1.0d0/<br class="">+<br class="">+call start_clock('absorption')<br class="">+if(l_finite) then<br class="">+   r_pola(1:3)=upol(1:3,ipol)<br class="">+   call amplitude_finite(vstate_r,fc,ieig,ampl)<br class="">+else<br class="">+   call amplitude(psibar(1,1),fc,ieig,ampl)<br class="">+endif<br class="">+<br class="">+call stop_clock('absorption')<br class="">+return<br class="">+end subroutine<br class="">+<br class="">+subroutine amplitude_finite(vstate_r,fc,ieig,ampl)<br class="">+!this subroutine computes the amplitude of each exciton for finite systems using <br class="">+!the matrix element of the position operator<br class="">+!WARNING: for now, it should be used only for calculation where the molecule is centered around the<br class="">+!origin of the supercell <br class="">+<br class="">+USE exciton<br class="">+USE bse_wannier, ONLY : num_nbndv,l_finite,r_pola<br class="">+USE cell_base,   ONLY : at,alat<br class="">+USE fft_custom_gwl<br class="">+USE bse_basic_structures<br class="">+USE mp_world,   ONLY : mpime, nproc<br class="">+USE mp_pools,    ONLY: nproc_pool<br class="">+USE mp,          ONLY : mp_barrier<br class="">+USE io_global,   ONLY : stdout<br class="">+USE wvfct,       ONLY : npw<br class="">+USE mp_world,             ONLY : world_comm<br class="">+<br class="">+<br class="">+implicit none<br class="">+TYPE(v_state_r), INTENT(in) :: vstate_r<br class="">+TYPE(fft_cus),   INTENT(in) :: fc<br class="">+REAL(DP),        INTENT(out):: ampl<br class="">+INTEGER,         INTENT(in) :: ieig<br class="">+<br class="">+TYPE(exc_r) :: rpsiv_r<br class="">+TYPE(exc)   :: rpsiv<br class="">+<br class="">+REAL(DP) :: r(3),rr(3),rdote<br class="">+INTEGER  :: ikstart,iklocal,ij,ii,ik,ifft,iktotal<br class="">+INTEGER  :: iv<br class="">+LOGICAL  :: debug<br class="">+INTEGER  :: iz,iy,ix,iqq<br class="">+REAL(DP) :: prod,prod2<br class="">+<br class="">+call start_clock('amplitude_finite')<br class="">+debug=.true.<br class="">+<br class="">+! each processor finds the starting index of its collection of FFT planes  <br class="">+ikstart=1<br class="">+do ii=1,mpime<br class="">+   ikstart=ikstart+fc%dfftt%npp(ii)<br class="">+enddo<br class="">+<br class="">+iktotal=0<br class="">+do ii=1,nproc_pool<br class="">+   iktotal=iktotal+fc%dfftt%npp(ii)<br class="">+enddo<br class="">+<br class="">+!if(debug) then<br class="">+!   write(stdout,*) 'mpime, iktotal=',mpime,iktotal<br class="">+!   write(stdout,*) 'mpime,fc%nrx3t',mpime,fc%nrx3t<br class="">+!   write(stdout,*) 'ikstart=',ikstart<br class="">+!endif<br class="">+<br class="">+!call flush_unit( stdout )<br class="">+!call mp_barrier<br class="">+<br class="">+<br class="">+! create the rpsiv_r excitonic vector (in real space)<br class="">+<br class="">+call initialize_exc_r(rpsiv_r)<br class="">+rpsiv_r%nrxxt=fc%nrxxt <br class="">+rpsiv_r%numb_v=num_nbndv(1)<br class="">+rpsiv_r%label=12<br class="">+allocate(rpsiv_r%ar(rpsiv_r%nrxxt,rpsiv_r%numb_v))<br class="">+<br class="">+rpsiv_r%ar(1:rpsiv_r%nrxxt,1:rpsiv_r%numb_v)=0.d0<br class="">+<br class="">+do iz=1,fc%dfftt%npp(mpime+1) <br class="">+   do iy=1,fc%nr2t<br class="">+      do ix=1,fc%nr1t<br class="">+          iqq=(iz-1)*(fc%nrx1t*fc%nrx2t)+(iy-1)*fc%nrx1t+ix <br class="">+          r(:)= (dble(ix-1)/dble(fc%nr1t)-int(2.d0*dble(ix-1)/dble(fc%nr1t)))*at(:,1)*alat+&<br class="">+            &(dble(iy-1)/dble(fc%nr2t)-int(2.d0*dble(iy-1)/dble(fc%nr2t)))*at(:,2)*alat+&<br class="">+            &(dble(iz-1+ikstart-1)/dble(fc%nr3t)-int(2.d0*dble(iz-1+ikstart-1)/dble(fc%nr3t)))*at(:,3)*alat<br class="">+<br class="">+!          r(:)=dble(ix-1)/dble(fc%nr1t)*at(:,1)*alat+&<br class="">+!               dble(iy-1)/dble(fc%nr2t)*at(:,2)*alat+&<br class="">+!               dble(iz-1+ikstart-1)/dble(fc%nr3t)*at(:,3)*alat<br class="">+<br class="">+!          if(debug) then<br class="">+!             rr(1)=dble(ix-1)/dble(fc%nr1t)-int(2.d0*dble((ix)-1)/dble(fc%nr1t))<br class="">+!             rr(2)=dble(iy-1)/dble(fc%nr2t)-int(2.d0*dble((iy)-1)/dble(fc%nr2t))<br class="">+!             rr(3)= dble(iz-1+ikstart-1)/dble(fc%nr3t)-int(2.d0*dble(iz-1+ikstart-1)/dble(fc%nr3t))<br class="">+!             write(stdout,*) 'rr',rr(1),rr(2),rr(3) <br class="">+!             write(stdout,*) 'rc',r(1),r(2),r(3)<br class="">+!             CALL flush_unit( stdout )   <br class="">+!          endif<br class="">+<br class="">+          rdote=r(1)*r_pola(1)+r(2)*r_pola(2)+r(3)*r_pola(3)   <br class="">+<br class="">+          rpsiv_r%ar(iqq,1:num_nbndv(1))=rdote*vstate_r%wfnrt(iqq,1:num_nbndv(1),1)<br class="">+  <br class="">+      enddo<br class="">+   enddo<br class="">+enddo<br class="">+<br class="">+!do ifft=0,fc%nrx1t*fc%nrx2t*fc%dfftt%npp(mpime+1)-1<br class="">+!<br class="">+!   iklocal=ifft/(fc%nrx1t*fc%nrx2t)+1<br class="">+!   ik=ikstart+iklocal-1<br class="">+!   ij=(ifft-(fc%nrx1t*fc%nrx2t)*(iklocal-1))/fc%nrx1t+1<br class="">+!   ii=ifft-(fc%nrx1t*fc%nrx2t)*(iklocal-1)-fc%nrx1t*(ij-1)<br class="">+!!   <br class="">+!   r(:)= (dble(ii-1)/dble(fc%nrx1t)-int(2.d0*dble((ii)-1)/dble(fc%nrx1t)))*at(:,1)*alat+&<br class="">+!        &(dble(ij-1)/dble(fc%nrx2t)-int(2.d0*dble((ij)-1)/dble(fc%nrx2t)))*at(:,2)*alat+&<br class="">+!        &(dble(ik-1)/dble(iktotal)-int(2.d0*dble((ik)-1)/dble(iktotal)))*at(:,3)*alat<br class="">+!!<br class="">+!   if(debug) then<br class="">+!      rr(1)=(dble((ii)-1)/dble(fc%nrx1t)-int(2.d0*dble((ii)-1)/dble(fc%nrx1t)))<br class="">+!      rr(2)=(dble((ij)-1)/dble(fc%nrx2t)-int(2.d0*dble((ij)-1)/dble(fc%nrx2t)))<br class="">+!      rr(3)=(dble((ik)-1)/dble(iktotal)-int(2.d0*dble((ik)-1)/dble(iktotal)))<br class="">+!      write(stdout,*) 'rr',rr(1),rr(2),rr(3) <br class="">+!      write(stdout,*) 'rc',r(1),r(2),r(3)<br class="">+!      CALL flush_unit( stdout )   <br class="">+!   endif<br class="">+!<br class="">+!   rdote=r(1)*r_pola(1)+r(2)*r_pola(2)+r(3)*r_pola(3)   <br class="">+!<br class="">+!   rpsiv_r%ar(ifft+1,1:num_nbndv(1))=rdote*vstate_r%wfnrt(ifft+1,1:num_nbndv(1),1)<br class="">+!<br class="">+!enddo<br class="">+<br class="">+<br class="">+<br class="">+!fft rpsiv_r to reciprocal space<br class="">+call initialize_exc(rpsiv)<br class="">+rpsiv%label=100<br class="">+rpsiv%npw=npw<br class="">+rpsiv%numb_v=num_nbndv(1)<br class="">+allocate(rpsiv%a(rpsiv%npw,rpsiv%numb_v)) <br class="">+<br class="">+!if (debug) then<br class="">+!   call mp_barrier<br class="">+!   write(stdout,*) 'rpsiv allocated'<br class="">+!   CALL flush_unit( stdout )   <br class="">+!endif<br class="">+<br class="">+call fftback_a_exc(rpsiv_r,fc,rpsiv)<br class="">+<br class="">+!if (debug) then<br class="">+!   call mp_barrier<br class="">+!   write(stdout,*) 'fft_performed'<br class="">+!   CALL flush_unit( stdout )   <br class="">+!endif<br class="">+<br class="">+<br class="">+!compute the exciton amplitude<br class="">+if(debug) then<br class="">+ call sproduct_exc(rpsiv,rpsiv,prod)<br class="">+ call sproduct_exc(bse_spectrum(ieig),bse_spectrum(ieig),prod2)<br class="">+ write(*,*) 'ieig, prod1', ieig, prod<br class="">+ write(*,*) 'ieig, prod2', ieig, prod2<br class="">+endif<br class="">+<br class="">+call sproduct_exc(bse_spectrum(ieig),rpsiv,ampl)<br class="">+ampl=ampl*ampl<br class="">+<br class="">+<br class="">+!if (debug) then<br class="">+!   call mp_barrier<br class="">+!   write(stdout,*) 'amplitude computed'<br class="">+!   CALL flush_unit( stdout )   <br class="">+!endif<br class="">+<br class="">+FLUSH( stdout )   <br class="">+call free_memory_exc_a_r(rpsiv_r)<br class="">+call free_memory_exc_a(rpsiv)<br class="">+<br class="">+call stop_clock('amplitude_finite')<br class="">+return<br class="">+end subroutine<br class="">+<br class="">+subroutine amplitude(psibar,fc,ieig,ampl)<br class="">+!this subroutine computes the amplitude of each exciton <br class="">+<br class="">+USE exciton<br class="">+USE bse_wannier, ONLY : num_nbndv,l_finite,r_pola<br class="">+USE cell_base,   ONLY : at,alat<br class="">+USE fft_custom_gwl<br class="">+USE bse_basic_structures<br class="">+USE mp_world,   ONLY : mpime, nproc<br class="">+USE mp_pools,    ONLY:nproc_pool<br class="">+USE mp,          ONLY : mp_barrier<br class="">+USE mp_world,             ONLY : world_comm<br class="">+USE io_global,   ONLY : stdout<br class="">+USE wvfct,       ONLY : npw<br class="">+<br class="">+<br class="">+implicit none<br class="">+TYPE(fft_cus),   INTENT(in) :: fc<br class="">+REAL(DP),        INTENT(out):: ampl<br class="">+INTEGER,         INTENT(in) :: ieig<br class="">+COMPLEX(DP),    INTENT(in) :: psibar(npw,num_nbndv(1))<br class="">+<br class="">+<br class="">+REAL(DP) :: r(3),rr(3),rdote,prod,prod2<br class="">+INTEGER  :: ikstart,iklocal,ij,ii,ik,ifft,iktotal<br class="">+INTEGER  :: iv<br class="">+LOGICAL  :: debug<br class="">+INTEGER  :: iz,iy,ix,iqq<br class="">+TYPE(exc)   :: rpsiv<br class="">+<br class="">+call start_clock('amplitude')<br class="">+debug=.false.<br class="">+<br class="">+call initialize_exc(rpsiv)<br class="">+rpsiv%label=100<br class="">+rpsiv%npw=npw<br class="">+rpsiv%numb_v=num_nbndv(1)<br class="">+allocate(rpsiv%a(rpsiv%npw,rpsiv%numb_v)) <br class="">+<br class="">+do iv=1,num_nbndv(1)<br class="">+   rpsiv%a(1:rpsiv%npw,iv)=psibar(1:npw,iv) <br class="">+enddo<br class="">+<br class="">+!check if there is something in the psibar vector<br class="">+! and in the bse_spectrum_vector<br class="">+if(debug) then<br class="">+ call sproduct_exc(rpsiv,rpsiv,prod)<br class="">+ call sproduct_exc(bse_spectrum(ieig),bse_spectrum(ieig),prod2)<br class="">+ write(*,*) 'ieig, prod1', ieig, prod<br class="">+ write(*,*) 'ieig, prod2', ieig, prod2<br class="">+endif<br class="">+<br class="">+<br class="">+!compute the exciton amplitude<br class="">+<br class="">+call sproduct_exc(bse_spectrum(ieig),rpsiv,ampl)<br class="">+ampl=ampl*ampl<br class="">+<br class="">+<br class="">+!if (debug) then<br class="">+!   call mp_barrier<br class="">+!   write(stdout,*) 'amplitude computed'<br class="">+!endif<br class="">+<br class="">+call free_memory_exc_a(rpsiv)<br class="">+<br class="">+FLUSH( stdout )   <br class="">+call mp_barrier(world_comm)<br class="">+<br class="">+call stop_clock('amplitude')<br class="">+return<br class="">+end subroutine<br class=""><br class="">Added: trunk/espresso/GWW/bse/bse_basic_structure.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/bse_basic_structure.f90<span class="Apple-tab-span" style="white-space:pre">      </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/bse_basic_structure.f90<span class="Apple-tab-span" style="white-space:pre">  </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,920 @@<br class="">+MODULE bse_basic_structures<br class="">+!this module describes the basis structures <br class="">+!which are obtained from the DFT and GW code<br class="">+  USE kinds, ONLY : DP<br class="">+<br class="">+  REAL(kind=DP), ALLOCATABLE :: vg_q(:) ! contains the elements V(G) of the Coulomb potential obtained upon integration over q<br class="">+<br class="">+  COMPLEX(kind=DP), ALLOCATABLE :: u_trans(:,:,:)!unitarian transformation from bloch wfcs to wannier'<br class="">+<br class="">+  TYPE wannier_o<br class="">+! this structures contains the overlap between the wannier square modules<br class="">+     integer :: numb_v ! number of valence bands for the two spin channels <br class="">+     real(kind=dp),dimension(:,:), pointer ::o(:,:) ! overlap matrix (numb_v*numb_v)   <br class="">+  END TYPE<br class="">+<br class="">+  TYPE ii_mat<br class="">+     integer :: numb_v! number of valence bands for the two spin channels <br class="">+     integer :: np_max ! maximum number of overlapping wannier orbitals for a given v<br class="">+     integer, dimension (:,:), pointer :: iimat(:,:) ! (np_max,numb_v) the rows of this matrix contain for each iv, <br class="">+                                                     !the set of jv for which   o_mat(iv,jv)>=s_bse<br class="">+ <br class="">+  END TYPE<br class="">+<br class="">+  TYPE vww_prod<br class="">+!this type contains the v*wv*wv' products needed for the exchange part of the<br class="">+!direct interaction term of the excitonic Hamiltonian<br class="">+     integer :: numb_v! number of valence bands for the two spin channels <br class="">+     integer :: npw ! number of plane wave per processor<br class="">+     integer :: np_max ! maximum number of overlapping wannier orbitals for a given v<br class="">+     complex(kind=dp), dimension (:,:,:), pointer :: vww(:,:,:) ! v*wv*wv' product in G space (npw,np_max,numb_v)<br class="">+<br class="">+  END TYPE<br class="">+  <br class="">+  TYPE bse_z<br class="">+! this type contains the z terms to build up the Wc term of the excitonic Hamiltonian<br class="">+!z_beta_v_v'=(v*phi_beta)*wv*Wv'<br class="">+     integer :: numb_v! number of valence bands for the two spin channels <br class="">+     integer :: np_max ! maximum number of overlapping wannier orbitals for a given v<br class="">+     integer :: numw_prod ! dimension of the polarizability basis<br class="">+     real(kind=dp), dimension (:,:,:), pointer :: z(:,:,:) ! v*phi_beta*wv*wv' product (numw_prod,np_max,numb_v)<br class="">+  END TYPE<br class="">+<br class="">+  TYPE v_state<br class="">+! this type contains the valence states wavefunctions and single particle energies<br class="">+!<br class="">+  integer :: nspin  ! number of spin channels<br class="">+  integer :: numb_v(2) ! number valence state<br class="">+  integer :: npw ! number of g-vectors per processor<br class="">+  real(kind=dp), dimension (:,:),pointer  :: esp(:,:) ! single particle energies (numb_v,nspin) <br class="">+  complex(kind=dp), dimension(:,:,:), pointer :: wfn(:,:,:) ! wave function in G space (npw,numb_v,nspin)  <br class="">+  integer ::gstart<br class="">+<br class="">+  END TYPE<br class="">+<br class="">+  TYPE v_state_r<br class="">+! this type contains the valence states wfns in real space on the dual grid <br class="">+  integer :: nspin  ! number of spin channels<br class="">+  integer :: numb_v(2) ! number of valence states<br class="">+  integer :: nrxxt ! number of r points per processor<br class="">+  real(kind=dp), dimension(:,:,:), pointer :: wfnrt(:,:,:) ! wave function in r-spce (dual grid) (nrxxt,numb_v,nspin)<br class="">+<br class="">+  END TYPE<br class="">+<br class="">+  TYPE c_state<br class="">+! this type contains the valence states wavefunctions and single particle energies<br class="">+!<br class="">+  integer :: nspin  ! number of spin channels<br class="">+  integer :: numb_c ! number valence state<br class="">+  integer :: npw ! number of g-vectors per processor<br class="">+  real(kind=dp), dimension (:,:),pointer  :: esp(:) ! single particle energies (numb_c) <br class="">+  complex(kind=dp), dimension(:,:), pointer :: wfn(:,:) ! wave function in G space (npw,numb_c)  <br class="">+  integer ::gstart<br class="">+<br class="">+  END TYPE<br class="">+<br class="">+  TYPE c_state_r<br class="">+! this type contains the valence states wfns in real space on the dual grid <br class="">+  integer :: nspin  ! number of spin channels<br class="">+  integer :: numb_c ! number of valence states<br class="">+  integer :: nrxxt ! number of r points per processor<br class="">+  real(kind=dp), dimension(:,:), pointer :: wfnrt(:,:) ! wave function in r-spce (dual grid) (nrxxt,numb_c)<br class="">+<br class="">+  END TYPE<br class="">+<br class="">+  CONTAINS<br class="">+<br class="">+      subroutine initialize_v_state_r(v_wfnr)<br class="">+      implicit none<br class="">+      type(v_state_r) :: v_wfnr<br class="">+      nullify(v_wfnr%wfnrt)<br class="">+      return<br class="">+      end subroutine<br class="">+<br class="">+      subroutine initialize_v_state(v_wfn)<br class="">+      implicit none<br class="">+      type(v_state) :: v_wfn<br class="">+      nullify(v_wfn%wfn)<br class="">+      nullify(v_wfn%esp)<br class="">+      return<br class="">+      end subroutine<br class="">+<br class="">+      subroutine initialize_c_state_r(c_wfnr)<br class="">+      implicit none<br class="">+      type(c_state_r) :: c_wfnr<br class="">+      nullify(c_wfnr%wfnrt)<br class="">+      return<br class="">+      end subroutine<br class="">+<br class="">+      subroutine initialize_c_state(c_wfn)<br class="">+      implicit none<br class="">+      type(c_state) :: c_wfn<br class="">+      nullify(c_wfn%wfn)<br class="">+      nullify(c_wfn%esp)<br class="">+      return<br class="">+      end subroutine<br class="">+  <br class="">+      subroutine initialize_wannier_o(o)<br class="">+      implicit none<br class="">+      type(wannier_o) :: o<br class="">+      nullify(o%o)<br class="">+      return<br class="">+      end subroutine<br class="">+  <br class="">+      subroutine initialize_imat(iimat)<br class="">+      implicit none<br class="">+      type(ii_mat) :: iimat<br class="">+      nullify(iimat%iimat)<br class="">+      return<br class="">+      end subroutine<br class="">+<br class="">+      subroutine initialize_vww_prod(vww)<br class="">+      implicit none<br class="">+      type(vww_prod) :: vww<br class="">+      nullify(vww%vww)<br class="">+      return<br class="">+      end subroutine<br class="">+<br class="">+      subroutine initialize_bse_z(z)<br class="">+      implicit none<br class="">+      type(bse_z) :: z<br class="">+      nullify(z%z)<br class="">+      return<br class="">+      end subroutine<br class="">+<br class="">+      subroutine free_v_state_r(v_wfnr)<br class="">+      implicit none<br class="">+      type(v_state_r) :: v_wfnr<br class="">+      if(associated(v_wfnr%wfnrt)) deallocate (v_wfnr%wfnrt)<br class="">+      nullify(v_wfnr%wfnrt)<br class="">+      return<br class="">+      end subroutine<br class="">+<br class="">+      subroutine free_v_state(v_wfn)<br class="">+      implicit none<br class="">+      type(v_state) :: v_wfn<br class="">+      if(associated(v_wfn%wfn)) deallocate (v_wfn%wfn)<br class="">+      nullify(v_wfn%wfn)<br class="">+      if(associated(v_wfn%esp)) deallocate (v_wfn%esp)<br class="">+      nullify(v_wfn%esp)<br class="">+      return<br class="">+      end subroutine<br class="">+<br class="">+      subroutine free_c_state_r(c_wfnr)<br class="">+      implicit none<br class="">+      type(c_state_r) :: c_wfnr<br class="">+      if(associated(c_wfnr%wfnrt)) deallocate (c_wfnr%wfnrt)<br class="">+      nullify(c_wfnr%wfnrt)<br class="">+      return<br class="">+      end subroutine<br class="">+<br class="">+      subroutine free_c_state(c_wfn)<br class="">+      implicit none<br class="">+      type(c_state) :: c_wfn<br class="">+      if(associated(c_wfn%wfn)) deallocate (c_wfn%wfn)<br class="">+      nullify(c_wfn%wfn)<br class="">+      if(associated(c_wfn%esp)) deallocate (c_wfn%esp)<br class="">+      nullify(c_wfn%esp)<br class="">+      return<br class="">+      end subroutine<br class="">+  <br class="">+      subroutine free_wannier_o(o)<br class="">+      implicit none<br class="">+      type(wannier_o) :: o<br class="">+      if(associated(o%o)) deallocate (o%o)<br class="">+      nullify(o%o)<br class="">+      return<br class="">+      end subroutine<br class="">+  <br class="">+      subroutine free_imat(iimat)<br class="">+      implicit none<br class="">+      type(ii_mat) :: iimat<br class="">+      if(associated(iimat%iimat)) deallocate (iimat%iimat)<br class="">+      nullify(iimat%iimat)<br class="">+      return<br class="">+      end subroutine<br class="">+<br class="">+      subroutine free_vww_prod(vww)<br class="">+      implicit none<br class="">+      type(vww_prod) :: vww<br class="">+      if(associated(vww%vww)) deallocate (vww%vww)<br class="">+      nullify(vww%vww)<br class="">+      return<br class="">+      end subroutine<br class="">+<br class="">+      subroutine free_bse_z(z)<br class="">+      implicit none<br class="">+      type(bse_z) :: z<br class="">+      if(associated(z%z)) deallocate (z%z)<br class="">+      nullify(z%z)<br class="">+      return<br class="">+      end subroutine<br class="">+<br class="">+      subroutine make_v_state(numb_v,v)<br class="">+      use io_global, ONLY : stdout, ionode <br class="">+      USE gvect,                 ONLY : gstart<br class="">+      USE lsda_mod,              ONLY : nspin<br class="">+      use wavefunctions_module,  ONLY : evc<br class="">+      use io_files,  ONLY : prefix, iunwfc, tmp_dir<br class="">+      USE io_files, ONLY: nwordwfc<br class="">+      USE wvfct,    ONLY : nbnd, npwx,npw,et<br class="">+      use mp_world, ONLY : mpime<br class="">+      USE mp,          ONLY :mp_barrier<br class="">+      USE mp_world,             ONLY : world_comm<br class="">+<br class="">+      implicit none<br class="">+<br class="">+      type(v_state) :: v<br class="">+      integer :: numb_v(2)<br class="">+  <br class="">+      integer :: is,ivmax,iv<br class="">+      logical :: debug<br class="">+<br class="">+      debug=.false.<br class="">+     <br class="">+      call start_clock('make_v_state')<br class="">+     <br class="">+      if(debug) then<br class="">+         write(*,*) 'make_v_state: in, mpime=',mpime<br class="">+         ! debug MARGHE<br class="">+         write(*,*) 'nbnd=', nbnd<br class="">+         write(*,*) 'numb_v(1)=', numb_v(1)<br class="">+      endif<br class="">+<br class="">+<br class="">+      v%nspin=nspin<br class="">+      v%numb_v(:)=numb_v(:)<br class="">+      v%npw=npw<br class="">+      v%gstart=gstart<br class="">+<br class="">+<br class="">+      allocate( evc( npwx, nbnd ) )<br class="">+  <br class="">+      if (nspin==1) then<br class="">+         ivmax= v%numb_v(1)<br class="">+      else <br class="">+         ivmax=max(v%numb_v(1),v%numb_v(2))<br class="">+      endif<br class="">+      <br class="">+<br class="">+<br class="">+      allocate( v%wfn(v%npw,ivmax,v%nspin))<br class="">+      allocate( v%esp(ivmax,v%nspin))<br class="">+<br class="">+<br class="">+      do is=1,nspin<br class="">+         call davcio(evc,2*nwordwfc,iunwfc,is,-1)<br class="">+         do iv=1,v%numb_v(is)<br class="">+            v%wfn(1:v%npw,1:v%numb_v(is),is)=evc(1:v%npw,1:v%numb_v(is))<br class="">+         enddo  <br class="">+            v%esp(1:v%numb_v(is),is)=et(1:v%numb_v(is),is)<br class="">+      enddo<br class="">+<br class="">+      deallocate(evc)<br class="">+<br class="">+      if(debug) then<br class="">+         write(*,*) 'make_v_state: out, mpime=',mpime<br class="">+      endif<br class="">+<br class="">+      call mp_barrier( world_comm )<br class="">+      call stop_clock('make_v_state')<br class="">+<br class="">+      return<br class="">+      end subroutine<br class="">+<br class="">+      subroutine make_c_state(numb_v,c)<br class="">+      use io_global, ONLY : stdout, ionode <br class="">+      USE gvect,                 ONLY : gstart<br class="">+      USE lsda_mod,              ONLY : nspin<br class="">+      use wavefunctions_module,  ONLY : evc<br class="">+      use io_files,  ONLY : prefix, iunwfc, tmp_dir<br class="">+      USE io_files, ONLY: nwordwfc<br class="">+      USE wvfct,    ONLY : nbnd, npwx,npw,et<br class="">+      use mp_world, ONLY : mpime<br class="">+      USE mp,          ONLY :mp_barrier<br class="">+      USE mp_world,             ONLY : world_comm<br class="">+<br class="">+      implicit none<br class="">+<br class="">+      type(c_state) :: c<br class="">+      integer :: numb_v(2)<br class="">+  <br class="">+      integer :: is,ic<br class="">+      logical :: debug<br class="">+<br class="">+      debug=.false.<br class="">+     <br class="">+      call start_clock('make_c_state')<br class="">+     <br class="">+      if(debug) then<br class="">+         write(*,*) 'make_c_state: in, mpime=',mpime<br class="">+         ! debug MARGHE<br class="">+         write(*,*) 'nbnd=', nbnd<br class="">+         write(*,*) 'numb_v(1)=', numb_v(1)<br class="">+      endif<br class="">+<br class="">+<br class="">+      c%nspin=nspin<br class="">+      c%numb_c=nbnd-numb_v(1)<br class="">+      c%npw=npw<br class="">+      c%gstart=gstart<br class="">+<br class="">+<br class="">+      allocate( evc( npwx, nbnd ) )<br class="">+  <br class="">+!      if (nspin==1) then<br class="">+!         ivmax= v%numb_v(1)<br class="">+!      else <br class="">+!         ivmax=max(v%numb_v(1),v%numb_v(2))<br class="">+!      endif<br class="">+      <br class="">+<br class="">+<br class="">+      allocate( c%wfn(c%npw,c%numb_c))<br class="">+      allocate( c%esp(c%numb_c))<br class="">+<br class="">+<br class="">+      do is=1,nspin<br class="">+         call davcio(evc,2*nwordwfc,iunwfc,is,-1)<br class="">+         do ic=1,c%numb_c<br class="">+            c%wfn(1:c%npw,1:c%numb_c)=evc(1:c%npw,numb_v(is)+1:nbnd)<br class="">+         enddo  <br class="">+            c%esp(1:c%numb_c)=et(numb_v(is)+1:nbnd,is)<br class="">+      enddo<br class="">+<br class="">+      deallocate(evc)<br class="">+<br class="">+      if(debug) then<br class="">+         write(*,*) 'make_c_state: out, mpime=',mpime<br class="">+      endif<br class="">+<br class="">+      call mp_barrier( world_comm )<br class="">+      call stop_clock('make_c_state')<br class="">+<br class="">+      return<br class="">+      end subroutine<br class="">+<br class="">+      subroutine c_times_cstate(v,cstate_in,cstate_out)<br class="">+      ! this subroutine multiplies each line ic of the c_state vector by the ic real component of the v vector<br class="">+      use kinds, only:DP<br class="">+      !use bse_wannier, only: qpe_imin,qpe_imax<br class="">+<br class="">+      implicit none<br class="">+<br class="">+      type(c_state),intent(in) :: cstate_in<br class="">+      type(c_state),intent(out) :: cstate_out<br class="">+<br class="">+      integer :: ib<br class="">+      real(kind=DP) :: v(cstate_in%numb_c)<br class="">+<br class="">+      do ib=1,cstate_in%numb_c<br class="">+         cstate_out%wfn(1:cstate_out%npw,ib)=cmplx(v(ib),0.d0)* cstate_out%wfn(1:cstate_in%npw,ib)<br class="">+      enddo<br class="">+     <br class="">+      return<br class="">+      end subroutine<br class="">+<br class="">+ <br class="">+      subroutine v_wfng_to_wfnr(vwfng,fc,vwfnr)<br class="">+     !this subroutine FFT the valence wfns to real space in the dual grid<br class="">+<br class="">+      USE kinds, ONLY : DP<br class="">+      USE fft_custom_gwl<br class="">+      USE bse_wannier, ONLY : dual_bse <br class="">+      USE wvfct,    ONLY : igk, g2kin, npwx, npw, nbnd, nbndx<br class="">+      USE io_global, ONLY : stdout, ionode, ionode_id<br class="">+      USE mp_world, ONLY : mpime, nproc,world_comm<br class="">+      USE mp_wave, ONLY : mergewf,splitwf<br class="">+      USE mp,             ONLY : mp_sum<br class="">+      USE gvect<br class="">+      USE wavefunctions_module, ONLY :  psic<br class="">+<br class="">+      implicit none<br class="">+<br class="">+      type(v_state) vwfng<br class="">+      type(v_state_r) vwfnr<br class="">+      type(fft_cus) :: fc<br class="">+<br class="">+      COMPLEX(kind=DP), allocatable :: vwfng_t(:,:,:)<br class="">+      COMPLEX(kind=DP), ALLOCATABLE :: evc_g(:)<br class="">+<br class="">+      integer :: ii,is<br class="">+      integer ::ivmax  <br class="">+<br class="">+      call start_clock('v_wfng_to_wfnr')<br class="">+  <br class="">+ <br class="">+      if (vwfng%nspin==1) then<br class="">+         ivmax= vwfng%numb_v(1)<br class="">+      else <br class="">+         ivmax=max(vwfng%numb_v(1),vwfng%numb_v(2))<br class="">+      endif<br class="">+<br class="">+<br class="">+      allocate(vwfng_t(fc%npwt,ivmax,vwfng%nspin))<br class="">+<br class="">+      vwfnr%nspin=vwfng%nspin<br class="">+      vwfnr%nrxxt=fc%nrxxt       <br class="">+      vwfnr%numb_v=vwfng%numb_v<br class="">+<br class="">+      allocate(vwfnr%wfnrt(vwfnr%nrxxt,ivmax,vwfnr%nspin))<br class="">+      <br class="">+      allocate(evc_g(fc%ngmt_g ))<br class="">+<br class="">+      if(fc%dual_t==4.d0) then<br class="">+      do is=1,vwfng%nspin<br class="">+         vwfng_t(1:fc%npwt,1:vwfng%numb_v(is),is)= vwfng%wfn(1:fc%npwt,1:vwfng%numb_v(is),is)<br class="">+      enddo<br class="">+      else<br class="">+         do is=1,vwfng%nspin<br class="">+           call reorderwfp_col(vwfng%numb_v(is),vwfng%npw,fc%npwt,vwfng%wfn(1,1,is),vwfng_t(1,1,is),vwfng%npw,&<br class="">+                 & fc%npwt,ig_l2g,fc%ig_l2gt,fc%ngmt_g,mpime, nproc,world_comm )<br class="">+<br class="">+           !do ii=1,vwfng%numb_v(is)<br class="">+           !   call mergewf(vwfng%wfn(:,ii,is),evc_g,vwfng%npw,ig_l2g,mpime,nproc,ionode_id,intra_pool_comm)<br class="">+           !   call splitwf(vwfng_t(:,ii,is),evc_g,fc%npwt,fc%ig_l2gt,mpime,nproc,ionode_id,intra_pool_comm)<br class="">+           !enddo<br class="">+         enddo<br class="">+      endif<br class="">+<br class="">+      do is=1,vwfng%nspin <br class="">+         do ii=1,vwfng%numb_v(is),2<br class="">+            psic(1:fc%nrxxt)=(0.d0,0.d0)<br class="">+            if (ii==vwfng%numb_v(is)) then<br class="">+               psic(fc%nlt(1:fc%npwt))  = vwfng_t(1:fc%npwt,ii,is)<br class="">+               psic(fc%nltm(1:fc%npwt)) = CONJG( vwfng_t(1:fc%npwt,ii,is) )<br class="">+            else<br class="">+               psic(fc%nlt(1:fc%npwt))=vwfng_t(1:fc%npwt,ii,is)+(0.d0,1.d0)*vwfng_t(1:fc%npwt,ii+1,is)<br class="">+               psic(fc%nltm(1:fc%npwt)) =CONJG(vwfng_t(1:fc%npwt,ii,is))+(0.d0,1.d0)*CONJG(vwfng_t(1:fc%npwt,ii+1,is))<br class="">+            endif<br class="">+            CALL cft3t( fc, psic, fc%nr1t, fc%nr2t, fc%nr3t, fc%nrx1t, fc%nrx2t, fc%nrx3t, 2 )<br class="">+            vwfnr%wfnrt(1:fc%nrxxt,ii,is)= DBLE(psic(1:fc%nrxxt))<br class="">+            if(ii/=vwfng%numb_v(is)) vwfnr%wfnrt(1:fc%nrxxt,ii+1,is)= DIMAG(psic(1:fc%nrxxt))<br class="">+         enddo<br class="">+      enddo<br class="">+<br class="">+      deallocate(evc_g)<br class="">+<br class="">+      call stop_clock('v_wfng_to_wfnr')<br class="">+<br class="">+      return<br class="">+      end subroutine<br class="">+<br class="">+      subroutine c_wfng_to_wfnr(cwfng,fc,cwfnr)<br class="">+     !this subroutine FFT the conduction wfns to real space in the dual grid<br class="">+<br class="">+      USE kinds, ONLY : DP<br class="">+      USE fft_custom_gwl<br class="">+      USE bse_wannier, ONLY : dual_bse, num_nbndv <br class="">+      USE wvfct,    ONLY : igk, g2kin, npwx, npw, nbnd, nbndx<br class="">+      USE io_global, ONLY : stdout, ionode, ionode_id<br class="">+      USE mp_world, ONLY : mpime, nproc,world_comm<br class="">+      USE mp_wave, ONLY : mergewf,splitwf<br class="">+      USE mp,             ONLY : mp_sum<br class="">+      USE gvect<br class="">+      USE wavefunctions_module, ONLY :  psic<br class="">+<br class="">+      implicit none<br class="">+<br class="">+      type(c_state) cwfng<br class="">+      type(c_state_r) cwfnr<br class="">+      type(fft_cus) :: fc<br class="">+<br class="">+      COMPLEX(kind=DP), allocatable :: cwfng_t(:,:)<br class="">+      COMPLEX(kind=DP), ALLOCATABLE :: evc_g(:)<br class="">+<br class="">+      integer :: ii,is<br class="">+      integer ::icmax  <br class="">+<br class="">+      call start_clock('c_wfng_to_wfnr')<br class="">+  <br class="">+ <br class="">+!      if (vwfng%nspin==1) then<br class="">+!         ivmax= vwfng%numb_v(1)<br class="">+!      else <br class="">+!         ivmax=max(vwfng%numb_v(1),vwfng%numb_v(2))<br class="">+!      endif<br class="">+!       icmax=nbnd-num_nbndv(1)<br class="">+<br class="">+<br class="">+      allocate(cwfng_t(fc%npwt,cwfng%numb_c))<br class="">+<br class="">+      cwfnr%nrxxt=fc%nrxxt       <br class="">+      cwfnr%numb_c=cwfng%numb_c<br class="">+<br class="">+      allocate(cwfnr%wfnrt(cwfnr%nrxxt,cwfnr%numb_c))<br class="">+      <br class="">+      allocate(evc_g(fc%ngmt_g ))<br class="">+<br class="">+      if(fc%dual_t==4.d0) then<br class="">+         cwfng_t(1:fc%npwt,1:cwfng%numb_c)= cwfng%wfn(1:fc%npwt,1:cwfng%numb_c)<br class="">+      else<br class="">+         call reorderwfp_col(cwfng%numb_c,cwfng%npw,fc%npwt,cwfng%wfn(1,1),cwfng_t(1,1),cwfng%npw,&<br class="">+                 & fc%npwt,ig_l2g,fc%ig_l2gt,fc%ngmt_g,mpime, nproc,world_comm )<br class="">+<br class="">+      endif<br class="">+<br class="">+      do ii=1,cwfng%numb_c,2<br class="">+           psic(1:fc%nrxxt)=(0.d0,0.d0)<br class="">+           if (ii==cwfng%numb_c) then<br class="">+              psic(fc%nlt(1:fc%npwt))  = cwfng_t(1:fc%npwt,ii)<br class="">+              psic(fc%nltm(1:fc%npwt)) = CONJG( cwfng_t(1:fc%npwt,ii) )<br class="">+           else<br class="">+              psic(fc%nlt(1:fc%npwt))=cwfng_t(1:fc%npwt,ii)+(0.d0,1.d0)*cwfng_t(1:fc%npwt,ii+1)<br class="">+              psic(fc%nltm(1:fc%npwt)) =CONJG(cwfng_t(1:fc%npwt,ii))+(0.d0,1.d0)*CONJG(cwfng_t(1:fc%npwt,ii+1))<br class="">+           endif<br class="">+           CALL cft3t( fc, psic, fc%nr1t, fc%nr2t, fc%nr3t, fc%nrx1t, fc%nrx2t, fc%nrx3t, 2 )<br class="">+           cwfnr%wfnrt(1:fc%nrxxt,ii)= DBLE(psic(1:fc%nrxxt))<br class="">+           if(ii/=cwfng%numb_c) cwfnr%wfnrt(1:fc%nrxxt,ii+1)= DIMAG(psic(1:fc%nrxxt))<br class="">+      enddo<br class="">+<br class="">+      deallocate(evc_g)<br class="">+<br class="">+      call stop_clock('c_wfng_to_wfnr')<br class="">+<br class="">+      return<br class="">+      end subroutine<br class="">+<br class="">+      subroutine write_wfnr(wfnr)<br class="">+      ! this subroutines writes on disk the type v_state_r for every processor<br class="">+!      USE io_files,             ONLY : find_free_unit, prefix<br class="">+      USE io_files,             ONLY :  tmp_dir,prefix<br class="">+      USE mp_world,  ONLY : mpime<br class="">+      implicit none<br class="">+<br class="">+      INTEGER, EXTERNAL :: find_free_unit<br class="">+      type(v_state_r) wfnr<br class="">+      INTEGER :: iw, iunw,is<br class="">+      CHARACTER(5) :: nproc<br class="">+<br class="">+      iunw=find_free_unit()<br class="">+      <br class="">+      write(nproc,'(5i1)') &<br class="">+           & mpime/10000,mod(mpime,10000)/1000,mod(mpime,1000)/100,mod(mpime,100)/10,mod(mpime,10)<br class="">+<br class="">+<br class="">+      open( unit=iunw, file=trim(tmp_dir)//trim(prefix)//'.wfnr_t.'// nproc , status='unknown',form='unformatted')<br class="">+<br class="">+      write(iunw) wfnr%numb_v  <br class="">+      write(iunw) wfnr%nspin<br class="">+      write(iunw) wfnr%nrxxt<br class="">+      <br class="">+      do is=1,wfnr%nspin<br class="">+         do iw=1,wfnr%numb_v(is)<br class="">+            write(iunw)  wfnr%wfnrt(1:wfnr%nrxxt,iw,is)<br class="">+         enddo<br class="">+      enddo <br class="">+      close(iunw)<br class="">+      end subroutine<br class="">+<br class="">+      subroutine read_wfnr(wfnr)<br class="">+      ! this subroutines reads from disk the type v_state_r for every processor<br class="">+!      USE io_files,             ONLY : find_free_unit, prefix<br class="">+      USE io_files,             ONLY : tmp_dir, prefix<br class="">+      USE mp_world,  ONLY : mpime<br class="">+      implicit none<br class="">+<br class="">+      INTEGER, EXTERNAL :: find_free_unit<br class="">+      type(v_state_r) wfnr<br class="">+      INTEGER :: iw, iunw,is<br class="">+      CHARACTER(5) :: nproc<br class="">+<br class="">+      iunw=find_free_unit()<br class="">+      <br class="">+      write(nproc,'(5i1)') &<br class="">+           & mpime/10000,mod(mpime,10000)/1000,mod(mpime,1000)/100,mod(mpime,100)/10,mod(mpime,10)<br class="">+<br class="">+<br class="">+      open( unit=iunw, file=trim(tmp_dir)//trim(prefix)//'.wfnr_t.'// nproc , status='old',form='unformatted')<br class="">+<br class="">+      read(iunw) wfnr%numb_v  <br class="">+      read(iunw) wfnr%nspin<br class="">+      read(iunw) wfnr%nrxxt<br class="">+<br class="">+      do is=1,wfnr%nspin<br class="">+         do iw=1,wfnr%numb_v(is)<br class="">+            read(iunw)  wfnr%wfnrt(1:wfnr%nrxxt,iw,is)<br class="">+         enddo<br class="">+      enddo<br class="">+ <br class="">+      close(iunw)<br class="">+      end subroutine<br class="">+<span class="Apple-tab-span" style="white-space:pre">   </span><br class="">+      subroutine write_cwfnr(wfnr)<br class="">+      ! this subroutines writes on disk the type v_state_r for every processor<br class="">+!      USE io_files,             ONLY : find_free_unit, prefix<br class="">+      USE io_files,             ONLY :  tmp_dir,prefix<br class="">+      USE mp_world,  ONLY : mpime<br class="">+      implicit none<br class="">+<br class="">+      INTEGER, EXTERNAL :: find_free_unit<br class="">+      type(c_state_r) wfnr<br class="">+      INTEGER :: iw, iunw,is<br class="">+      CHARACTER(5) :: nproc<br class="">+<br class="">+      iunw=find_free_unit()<br class="">+      <br class="">+      write(nproc,'(5i1)') &<br class="">+           & mpime/10000,mod(mpime,10000)/1000,mod(mpime,1000)/100,mod(mpime,100)/10,mod(mpime,10)<br class="">+<br class="">+<br class="">+      open( unit=iunw, file=trim(tmp_dir)//trim(prefix)//'.cwfnr_t.'// nproc , status='unknown',form='unformatted')<br class="">+<br class="">+      write(iunw) wfnr%numb_c  <br class="">+      write(iunw) wfnr%nrxxt<br class="">+      <br class="">+      do iw=1,wfnr%numb_c<br class="">+         write(iunw)  wfnr%wfnrt(1:wfnr%nrxxt,iw)<br class="">+      enddo<br class="">+<br class="">+      close(iunw)<br class="">+      end subroutine<br class="">+<br class="">+      subroutine read_cwfnr(wfnr)<br class="">+      ! this subroutines reads from disk the type v_state_r for every processor<br class="">+!      USE io_files,             ONLY : find_free_unit, prefix<br class="">+      USE io_files,             ONLY : tmp_dir,prefix<br class="">+      USE mp_world,  ONLY : mpime<br class="">+      implicit none<br class="">+<br class="">+      INTEGER, EXTERNAL :: find_free_unit<br class="">+      type(c_state_r) wfnr<br class="">+      INTEGER :: iw, iunw,is<br class="">+      CHARACTER(5) :: nproc<br class="">+<br class="">+      iunw=find_free_unit()<br class="">+      <br class="">+      write(nproc,'(5i1)') &<br class="">+           & mpime/10000,mod(mpime,10000)/1000,mod(mpime,1000)/100,mod(mpime,100)/10,mod(mpime,10)<br class="">+<br class="">+<br class="">+      open( unit=iunw, file=trim(tmp_dir)//trim(prefix)//'.cwfnr_t.'// nproc , status='old',form='unformatted')<br class="">+<br class="">+      read(iunw) wfnr%numb_c  <br class="">+      read(iunw) wfnr%nrxxt<br class="">+<br class="">+      do iw=1,wfnr%numb_c<br class="">+         read(iunw)  wfnr%wfnrt(1:wfnr%nrxxt,iw)<br class="">+      enddo<br class="">+<br class="">+      close(iunw)<br class="">+      end subroutine<br class="">+ <br class="">+<br class="">+      subroutine read_omat(ispin,o)<br class="">+      ! this subroutines reads the overlap matrix written by pw4gww<br class="">+!      USE io_files,             ONLY : find_free_unit, prefix<br class="">+      USE io_files,             ONLY : prefix,tmp_dir<br class="">+      USE io_global,            ONLY : ionode, ionode_id<br class="">+      USE mp,                   ONLY : mp_bcast<br class="">+      USE kinds,                ONLY : DP<br class="">+      USE mp_world,             ONLY : world_comm<br class="">+      <br class="">+      implicit none<br class="">+<br class="">+      INTEGER, EXTERNAL :: find_free_unit<br class="">+<br class="">+      type(wannier_o) :: o <br class="">+      integer ispin<br class="">+<br class="">+      integer ii,iunu<br class="">+      real(kind=DP) :: s_bse<br class="">+<br class="">+      if(ionode) then<br class="">+         iunu = find_free_unit()<br class="">+         if (ispin==1) open(unit=iunu,file=trim(tmp_dir)//trim(prefix)//'.wbse1',status='old',form='unformatted')<br class="">+         if (ispin==2) open(unit=iunu,file=trim(tmp_dir)//trim(prefix)//'.wbse2',status='old',form='unformatted')<br class="">+<br class="">+         read(iunu) o%numb_v<br class="">+         read(iunu) s_bse<br class="">+<br class="">+         allocate(o%o(o%numb_v,o%numb_v))<br class="">+<br class="">+         do ii=1,o%numb_v<br class="">+            read(iunu) o%o(1:o%numb_v,ii)<br class="">+         enddo<br class="">+         close(iunu)<br class="">+      endif<br class="">+      <br class="">+      CALL mp_bcast(o%numb_v, ionode_id , world_comm)<br class="">+      if(.not.ionode) then     <br class="">+        allocate(o%o(o%numb_v,o%numb_v))<br class="">+      endif<br class="">+      CALL mp_bcast(o%o, ionode_id, world_comm )<br class="">+<br class="">+      return<br class="">+      end subroutine<br class="">+<br class="">+      subroutine read_iimat(iimat,ispin) <br class="">+      ! this subroutines reads the ii matrix written by pw4gww<br class="">+!      USE io_files,             ONLY : find_free_unit, prefix<br class="">+      USE io_files,             ONLY :  prefix, tmp_dir<br class="">+      USE io_global,            ONLY : ionode, ionode_id<br class="">+      USE mp,                   ONLY : mp_bcast<br class="">+      USE mp_world,             ONLY : world_comm<br class="">+      USE kinds,                ONLY : DP<br class="">+<br class="">+      implicit none<br class="">+      INTEGER, EXTERNAL :: find_free_unit<br class="">+      type(ii_mat) :: iimat<br class="">+      integer ispin<br class="">+<br class="">+      real(kind=DP) :: s_bse<br class="">+      integer       :: iv,iuni<br class="">+      logical       :: debug<br class="">+<br class="">+      debug=.false.<br class="">+<br class="">+      if(ionode) then<br class="">+        iuni = find_free_unit()<br class="">+        if (ispin==1) open(unit=iuni,file=trim(tmp_dir)//trim(prefix)//'.iwwbse1',status='old',form='unformatted')<br class="">+        if (ispin==2) open(unit=iuni,file=trim(tmp_dir)//trim(prefix)//'.iwwbse2',status='old',form='unformatted')<br class="">+        read(iuni) iimat%numb_v<br class="">+        read(iuni) s_bse<br class="">+        read(iuni) iimat%np_max<br class="">+        if(debug) then<br class="">+          write(*,*) 'From read_iimat numb_v',iimat%numb_v<br class="">+          write(*,*) 'From read_iimat s_bse', s_bse<br class="">+          write(*,*) 'From read_iimat np_max',iimat%np_max<br class="">+        endif<br class="">+      endif<br class="">+<br class="">+      CALL mp_bcast(iimat%numb_v, ionode_id, world_comm )<br class="">+      CALL mp_bcast(iimat%np_max, ionode_id, world_comm )<br class="">+<br class="">+      allocate(iimat%iimat(iimat%np_max,iimat%numb_v))<br class="">+<br class="">+      if(ionode) then<br class="">+        if(debug) then<br class="">+           write(*,*) 'iimat matrix'  <br class="">+        endif<br class="">+        do iv=1, iimat%numb_v<br class="">+           read(iuni) iimat%iimat(1:iimat%np_max,iv)<br class="">+           if(debug) then<br class="">+              write(*,*) 'iv=',iv, iimat%iimat(1:iimat%np_max,iv)<br class="">+           endif<br class="">+        enddo<br class="">+        close(iuni)<br class="">+      endif<br class="">+<br class="">+      CALL mp_bcast(iimat%iimat, ionode_id, world_comm )<br class="">+<br class="">+      return <br class="">+      end subroutine<br class="">+<br class="">+      subroutine read_vww_prod(ispin,numb_v,npw,np_max,iimat,vww)<br class="">+      !each processor reads the vww(G) written by pw4gww<br class="">+      !be careful to check that the iimat that is passed to the subroutine is the related to the correct spin channel<br class="">+<br class="">+!      USE io_files,             ONLY : find_free_unit, prefix,diropn<br class="">+      USE io_files,             ONLY : prefix,diropn<br class="">+      USE io_global, ONLY : stdout, ionode <br class="">+<br class="">+      implicit none<br class="">+      INTEGER, EXTERNAL :: find_free_unit<br class="">+      type(vww_prod) :: vww<br class="">+      type(ii_mat)   :: iimat<br class="">+      integer        :: numb_v,npw,np_max,ispin<br class="">+<br class="">+      integer iv, ip, iungprod, ii,iundebug,i<br class="">+      logical exst,debug<br class="">+<br class="">+      debug=.false.<br class="">+     <br class="">+      if(debug) then<br class="">+         iundebug = find_free_unit()<br class="">+         open(iundebug,file='vww_bse.dat')<br class="">+      endif      <br class="">+ <br class="">+      vww%numb_v=numb_v<br class="">+      vww%npw=npw<br class="">+      vww%np_max=np_max<br class="">+<br class="">+      allocate(vww%vww(npw,np_max,numb_v))<br class="">+<br class="">+      vww%vww(1:npw,1:np_max,1:numb_v)=dcmplx(0.d0,0.d0)<br class="">+      <br class="">+      iungprod = find_free_unit()<br class="">+      if (ispin==1)  CALL diropn( iungprod, 'vww_bse1.',npw*2, exst)<br class="">+      if (ispin==2)  CALL diropn( iungprod, 'vww_bse2.',npw*2, exst)<br class="">+<br class="">+!      if(debug) then <br class="">+!         if(ionode) write(stdout,*) 'Read_vww_prod #1'<br class="">+!      endif<br class="">+<br class="">+      ii=0<br class="">+      do iv=1,numb_v<br class="">+         do ip=1, np_max <br class="">+            if(iimat%iimat(ip,iv)>0) then<br class="">+!               if(debug) then <br class="">+!                  if(ionode) write(stdout,*) 'Read_vww_prod #', ii<br class="">+!               endif<br class="">+               ii=ii+1<br class="">+               call davcio(vww%vww(:,ip,iv),npw*2,iungprod,ii,-1)<br class="">+               if(debug) then<br class="">+                  if(ionode) then<br class="">+                     do i=1,npw<br class="">+                        write(iundebug,*) vww%vww(i,ip,iv)   <br class="">+                     enddo<br class="">+                  endif<br class="">+               endif<br class="">+            endif<br class="">+         enddo<br class="">+      enddo<br class="">+<br class="">+      close(iungprod)   <br class="">+      if (debug) close(iundebug)   <br class="">+      return<br class="">+      end subroutine<br class="">+<br class="">+      subroutine read_z(ispin,iimat,z)<br class="">+      ! the ionode reads the z matrix and broadcast its value to the rest of the<br class="">+      ! processors.<br class="">+      !be careful to check that the iimat that is passed to the subroutine is the related to the correct spin channel<br class="">+<br class="">+<br class="">+!      USE io_files,             ONLY : find_free_unit, prefix<br class="">+      USE io_files,             ONLY :  prefix, tmp_dir<br class="">+      USE io_global,            ONLY : ionode, ionode_id<br class="">+      USE mp,                   ONLY : mp_bcast, mp_barrier<br class="">+      USE mp_world, ONLY : world_comm<br class="">+      USE kinds,                ONLY : DP<br class="">+      USE io_global, ONLY : stdout,ionode<br class="">+<br class="">+<br class="">+      implicit none<br class="">+      INTEGER, EXTERNAL :: find_free_unit<br class="">+      type(bse_z)    ::z <br class="">+      type(ii_mat)   :: iimat<br class="">+!      integer        :: numw_prod<br class="">+      integer        ::ispin<br class="">+<br class="">+      real(kind=DP) :: s_bse<br class="">+      integer       :: iv,iunz,ii<br class="">+<br class="">+      logical debug<br class="">+<br class="">+      debug=.false.<br class="">+<br class="">+      if(ionode) then <br class="">+         iunz = find_free_unit()<br class="">+         if(debug) then<br class="">+           if(ionode) write(stdout,*) 'read_z ',trim(tmp_dir)//trim(prefix)//'.zbse1'<br class="">+         endif<br class="">+<br class="">+<br class="">+         if (ispin==1) open(unit=iunz,file=trim(tmp_dir)//trim(prefix)//'.zbse1',status='old',form='unformatted')<br class="">+         if (ispin==2) open(unit=iunz,file=trim(tmp_dir)//trim(prefix)//'.zbse2',status='old',form='unformatted')<br class="">+         read(iunz) z%numb_v<br class="">+         read(iunz) s_bse <br class="">+         read(iunz) z%np_max<br class="">+         read(iunz) z%numw_prod<br class="">+<br class="">+         if(debug) then<br class="">+           if(ionode) write(stdout,*) 'z%numb_v=', z%numb_v<br class="">+           if(ionode) write(stdout,*) 's_bse=',s_bse<br class="">+           if(ionode) write(stdout,*) 'z%np_max=',z%np_max<br class="">+           if(ionode) write(stdout,*) 'z%numw_prod=', z%numw_prod<br class="">+         endif<br class="">+<br class="">+      endif <br class="">+<br class="">+      CALL mp_bcast(z%numb_v, ionode_id, world_comm )<br class="">+      CALL mp_bcast(z%np_max, ionode_id, world_comm )<br class="">+      CALL mp_bcast(z%numw_prod, ionode_id, world_comm )<br class="">+      call mp_barrier(world_comm)<br class="">+      <br class="">+      allocate(z%z(z%numw_prod,z%np_max,z%numb_v))<br class="">+     <br class="">+      if(ionode) then<br class="">+         do iv=1, z%numb_v<br class="">+            do ii=1,z%np_max<br class="">+               if(debug) then<br class="">+                 if(ionode) write(stdout,*)'read_z, ii=',ii <br class="">+               endif<br class="">+               if (iimat%iimat(ii,iv)>0) read(iunz) z%z(:,ii,iv)<br class="">+            enddo<br class="">+         enddo<br class="">+      endif<br class="">+<br class="">+      if(debug) then<br class="">+        if(ionode) write(stdout,*) 'read_z #1'<br class="">+      endif<br class="">+!<br class="">+<br class="">+      CALL mp_bcast(z%z, ionode_id, world_comm )<br class="">+      call mp_barrier(world_comm)<br class="">+<br class="">+      if(debug) then<br class="">+        if(ionode) write(stdout,*) 'read_z #2'<br class="">+      endif<br class="">+<br class="">+<br class="">+      if(ionode) close(iunz)<br class="">+      FLUSH( stdout )      <br class="">+ <br class="">+      return<br class="">+<br class="">+      end subroutine<br class="">+<br class="">+END MODULE<br class=""><br class="">Added: trunk/espresso/GWW/bse/bse_main.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/bse_main.f90<span class="Apple-tab-span" style="white-space:pre">     </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/bse_main.f90<span class="Apple-tab-span" style="white-space:pre">     </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,380 @@<br class="">+program bse_punch<br class="">+<br class="">+use io_global, ONLY : stdout, ionode, ionode_id<br class="">+use io_files,  ONLY : psfile, pseudo_dir,diropn,outdir<br class="">+!use io_files,  ONLY : prefix,outdir,tmp_dir,iunwfc,find_free_unit<br class="">+use io_files,  ONLY : prefix,outdir,tmp_dir,iunwfc<br class="">+use mp_world, ONLY : mpime<br class="">+use mp_pools, ONLY : kunit<br class="">+USE wvfct,     ONLY : nbnd, et, npwx<br class="">+USE gvecw,              ONLY : ecutwfc<br class="">+use pwcom<br class="">+USE wavefunctions_module, ONLY : evc<br class="">+use mp, ONLY: mp_bcast<br class="">+USE mp_world, ONLY : world_comm<br class="">+USE fft_base,             ONLY : dfftp<br class="">+use scf, only : vrs, vltot, v, kedtau<br class="">+USE fft_custom_gwl<br class="">+use bse_basic_structures<br class="">+use exciton<br class="">+USE constants,   ONLY: RYTOEV<br class="">+USE mp,          ONLY: mp_barrier<br class="">+USE qpe_exc,         ONLY: qpc<br class="">+use bse_wannier, ONLY: num_nbndv,&<br class="">+           l_truncated_coulomb,&<br class="">+           truncation_radius, &<br class="">+           numw_prod,&<br class="">+           dual_bse,&<br class="">+           l_verbose, &<br class="">+           lambda,eps,&<br class="">+           l_cgrad,maxit,cg_nreset,lm_delta,n_eig,eps_eig, scissor,&<br class="">+           l_plotexc,plotn_min,plotn_max,r_hole,l_plotaverage,&<br class="">+           l_tspace,nbndt,l_finite,r_pola,&<br class="">+           spectra_e_min,spectra_e_max,spectra_nstep,spectra_broad,&<br class="">+           l_restart,n_eig_start, nit_lcz,l_lanczos, l_restart_lcz, nlcz_restart,&<br class="">+           l_tdhf,l_fullbse,l_lf,l_rpa, l_contraction, l_gtrick, qpe_imin, qpe_imax,&<br class="">+           l_scissor<br class="">+implicit none<br class="">+INTEGER, EXTERNAL :: find_free_unit<br class="">+<br class="">+integer :: i, kunittmp, ios, is<br class="">+CHARACTER(LEN=256), EXTERNAL :: trimcheck<br class="">+character(len=200) :: pp_file<br class="">+logical ::  uspp_spsi, ascii, single_file, raw<br class="">+<br class="">+<br class="">+type(v_state) :: vstate<br class="">+type(v_state_r) :: vstate_r<br class="">+type(c_state)   :: cstate<br class="">+type(c_state)   :: wcstate<br class="">+type(exc) :: a_exc<br class="">+type(exc) :: b_exc<br class="">+!type(exc) :: a_excdiago,a_exchange <br class="">+!type(exc):: a_dirv<br class="">+!type(exc):: a_dirw<br class="">+!type(exc):: a_rot<br class="">+type(fft_cus) :: fc<br class="">+<br class="">+<br class="">+logical exst<br class="">+integer iuv<br class="">+<br class="">+logical :: debug<br class="">+<br class="">+real(kind=DP) :: sdeig<br class="">+<br class="">+<br class="">+<br class="">+NAMELIST /inputbse/ prefix,num_nbndv,dual_bse,outdir,l_truncated_coulomb,&<br class="">+                    truncation_radius, numw_prod, l_verbose,lambda,eps,&<br class="">+                    l_cgrad,maxit,cg_nreset,lm_delta,n_eig,eps_eig,&<br class="">+                    scissor,l_plotexc,plotn_min,plotn_max,r_hole,&<br class="">+                    l_plotaverage,l_tspace,nbndt,l_finite,r_pola,&<br class="">+                    spectra_e_min,spectra_e_max,spectra_nstep,spectra_broad,&<br class="">+                    l_restart,n_eig_start, nit_lcz,l_lanczos, l_restart_lcz, nlcz_restart,&<br class="">+                    l_fullbse,l_tdhf,l_lf,l_rpa,l_contraction,l_gtrick, qpe_imin, qpe_imax,&<br class="">+                    l_scissor<br class="">+<br class="">+debug=.false.<br class="">+            <br class="">+call start_bse( )<br class="">+call start_clock('bse_main')<br class="">+<br class="">+<br class="">+!<br class="">+!   set default values for variables in namelist<br class="">+!<br class="">+prefix='export'<br class="">+ CALL get_environment_variable( 'ESPRESSO_TMPDIR', outdir )<span class="Apple-tab-span" style="white-space:pre">     </span><br class="">+IF ( TRIM( outdir ) == ' ' ) outdir = './'<br class="">+  pp_file= ' '<br class="">+  uspp_spsi = .FALSE.<br class="">+  ascii = .FALSE.<br class="">+  single_file = .FALSE.<br class="">+  raw = .FALSE.<br class="">+<br class="">+<br class="">+<br class="">+num_nbndv(1:2) = 1<br class="">+l_truncated_coulomb = .false.<br class="">+truncation_radius = 10.d0<br class="">+numw_prod=1<br class="">+dual_bse=1.d0<br class="">+l_verbose=.true.<br class="">+lambda=0.001d0<br class="">+eps=0.0001d0<br class="">+maxit=100<br class="">+cg_nreset=50<br class="">+l_cgrad=.false.<br class="">+lm_delta=0.3<br class="">+n_eig=10<br class="">+eps_eig=0.0000000001<br class="">+scissor=0.d0<br class="">+l_plotexc=.false.<br class="">+plotn_min=0 <br class="">+plotn_max=0 <br class="">+r_hole(1:3)=0.d0<br class="">+l_plotaverage=.false.<br class="">+l_tspace=.false.<br class="">+nbndt=1<br class="">+l_finite=.false.<br class="">+r_pola(1:3)=1.d0<br class="">+spectra_e_min=0.d0<br class="">+spectra_e_max=10.d0<br class="">+spectra_nstep=100<br class="">+spectra_broad=0.01d0<br class="">+l_restart=0<br class="">+n_eig_start=0<br class="">+nit_lcz=100<br class="">+l_lanczos=.false.<br class="">+l_restart_lcz=.false.<br class="">+nlcz_restart=1<br class="">+l_fullbse=.true.<br class="">+l_tdhf=.false.<br class="">+l_lf=.false.<br class="">+l_rpa=.false.<br class="">+l_contraction=.false.<br class="">+l_gtrick=.false.<br class="">+qpe_imin=1<br class="">+qpe_imax=1<br class="">+l_scissor=.true.<br class="">+!<br class="">+!    Reading input file<br class="">+!<br class="">+IF ( ionode ) THEN<br class="">+      !<br class="">+      CALL input_from_file ( )<br class="">+      !<br class="">+      READ(5,inputbse,IOSTAT=ios)<br class="">+      !<br class="">+!      call read_namelists( 'PW4GWW' )<br class="">+      !<br class="">+      IF (ios /= 0) CALL errore ('pw4gww', 'reading inputbse namelist', ABS(ios) )<br class="">+      scissor=scissor/RYTOEV<br class="">+ENDIF<br class="">+<br class="">+<br class="">+!-------------------------------------------------------------------------<br class="">+! ... Broadcasting variables<br class="">+!------------------------------------------------------------------------<br class="">+<br class="">+   <br class="">+<br class="">+  tmp_dir = trimcheck( outdir )<br class="">+  CALL mp_bcast( outdir, ionode_id, world_comm )<br class="">+  CALL mp_bcast( tmp_dir, ionode_id, world_comm )<br class="">+  CALL mp_bcast( prefix, ionode_id , world_comm)<br class="">+  CALL mp_bcast( num_nbndv,     ionode_id , world_comm)<br class="">+  CALL mp_bcast(l_truncated_coulomb, ionode_id, world_comm)<br class="">+  CALL mp_bcast(truncation_radius, ionode_id, world_comm)<br class="">+  call mp_bcast(numw_prod, ionode_id, world_comm)<br class="">+  CALL mp_bcast(dual_bse, ionode_id, world_comm)<br class="">+  CALL mp_bcast( pp_file, ionode_id , world_comm)<br class="">+  CALL mp_bcast( uspp_spsi, ionode_id , world_comm)<br class="">+  CALL mp_bcast( ascii, ionode_id , world_comm)<br class="">+  CALL mp_bcast( single_file, ionode_id , world_comm)<br class="">+  CALL mp_bcast( raw, ionode_id , world_comm)<br class="">+  CALL mp_bcast( pseudo_dir, ionode_id , world_comm)<br class="">+  CALL mp_bcast( psfile, ionode_id , world_comm)<br class="">+  CALL mp_bcast( lambda, ionode_id , world_comm)<br class="">+  CALL mp_bcast( eps, ionode_id , world_comm)<br class="">+  CALL mp_bcast( maxit, ionode_id , world_comm)<br class="">+  CALL mp_bcast( cg_nreset, ionode_id , world_comm)<br class="">+  CALL mp_bcast( l_cgrad, ionode_id , world_comm)<br class="">+  CALL mp_bcast( lm_delta, ionode_id , world_comm)<br class="">+  CALL mp_bcast( n_eig, ionode_id , world_comm)<br class="">+  CALL mp_bcast( eps_eig, ionode_id , world_comm)<br class="">+  CALL mp_bcast( scissor, ionode_id , world_comm)<br class="">+  CALL mp_bcast( l_plotexc, ionode_id , world_comm)<br class="">+  CALL mp_bcast( plotn_min, ionode_id , world_comm) <br class="">+  CALL mp_bcast( plotn_max, ionode_id , world_comm) <br class="">+  CALL mp_bcast( r_hole, ionode_id, world_comm ) <br class="">+  CALL mp_bcast( l_plotaverage, ionode_id, world_comm ) <br class="">+  CALL mp_bcast( l_tspace, ionode_id, world_comm ) <br class="">+  CALL mp_bcast( nbndt, ionode_id, world_comm ) <br class="">+  CALL mp_bcast( l_finite, ionode_id, world_comm ) <br class="">+  CALL mp_bcast( r_pola, ionode_id, world_comm ) <br class="">+  CALL mp_bcast( spectra_e_min, ionode_id, world_comm ) <br class="">+  CALL mp_bcast( spectra_e_max, ionode_id, world_comm ) <br class="">+  CALL mp_bcast( spectra_nstep, ionode_id, world_comm ) <br class="">+  CALL mp_bcast( spectra_broad, ionode_id, world_comm ) <br class="">+  CALL mp_bcast( l_restart, ionode_id, world_comm ) <br class="">+  CALL mp_bcast( n_eig_start, ionode_id, world_comm ) <br class="">+  CALL mp_bcast( nit_lcz, ionode_id, world_comm ) <br class="">+  CALL mp_bcast( l_lanczos, ionode_id, world_comm ) <br class="">+  CALL mp_bcast( l_restart_lcz, ionode_id, world_comm ) <br class="">+  CALL mp_bcast( nlcz_restart, ionode_id, world_comm ) <br class="">+  CALL mp_bcast( l_fullbse, ionode_id, world_comm ) <br class="">+  CALL mp_bcast( l_tdhf, ionode_id, world_comm ) <br class="">+  CALL mp_bcast( l_lf, ionode_id, world_comm ) <br class="">+  CALL mp_bcast( l_rpa, ionode_id, world_comm ) <br class="">+  CALL mp_bcast( l_contraction, ionode_id, world_comm)<br class="">+  CALL mp_bcast( l_gtrick, ionode_id, world_comm)<br class="">+  CALL mp_bcast( l_scissor, ionode_id, world_comm)<br class="">+  CALL mp_bcast( qpe_imin, ionode_id, world_comm)<br class="">+  CALL mp_bcast( qpe_imax, ionode_id, world_comm)<br class="">+<br class="">+  call read_file <br class="">+! after read_file everything is known<br class="">+<br class="">+#if defined __PARA<br class="">+  kunittmp = kunit<br class="">+#else<br class="">+  kunittmp = 1<br class="">+#endif<br class="">+<br class="">+  call openfil_bse<br class="">+<br class="">+  call read_export(pp_file,kunittmp,uspp_spsi, ascii, single_file, raw)<br class="">+  call summary()  <br class="">+  call print_bseinfo()<br class="">+<br class="">+  CALL hinit0()<br class="">+  CALL set_vrs(vrs, vltot, v%of_r, kedtau, v%kin_r, dfftp%nnr, nspin, doublegrid )<br class="">+<br class="">+  if(l_verbose) write(stdout,*) 'To check, we print the KS eigenvalues:'<br class="">+  FLUSH( stdout )<br class="">+  !<br class="">+  CALL print_ks_energies()<br class="">+<br class="">+! inizialize dual grid once for all<br class="">+  fc%dual_t=dual_bse<br class="">+  fc%ecutt=ecutwfc<br class="">+  call initialize_fft_custom(fc)<br class="">+<br class="">+! read ks wavefunction, allocate and fill up the v_state object and c_state object<br class="">+  if (allocated(evc)) deallocate (evc)<br class="">+  call initialize_v_state(vstate)<br class="">+  call make_v_state(num_nbndv,vstate)<br class="">+  <br class="">+  call initialize_c_state(cstate)<br class="">+  call make_c_state(num_nbndv,cstate)<br class="">+<br class="">+  call initialize_c_state(wcstate)<br class="">+  call make_c_state(num_nbndv,wcstate)<br class="">+<br class="">+! FFT the valence states vector into r-space (using dual_bse)<br class="">+  call initialize_v_state_r(vstate_r)<br class="">+  call v_wfng_to_wfnr(vstate,fc,vstate_r)<br class="">+ <br class="">+  if(.not.l_gtrick) then<br class="">+     call v_wfng_to_wfnr(vstate,fc,vstate_r)<br class="">+  endif<br class="">+<br class="">+! if debug mode check polarizability basis orthonormality<br class="">+  if(debug) then<br class="">+     call check_basis(numw_prod,npw) <br class="">+  endif<br class="">+<br class="">+! allocate once for all vg_q<br class="">+  allocate(vg_q(npwx))<br class="">+  if(.not.l_truncated_coulomb) then<br class="">+     iuv = find_free_unit()<br class="">+     CALL diropn( iuv, 'vgq', npwx, exst )<br class="">+     CALL davcio(vg_q,npwx,iuv,1,-1)<br class="">+     close(iuv)<br class="">+  endif<br class="">+     <br class="">+<br class="">+  if(debug) write(*,*) 'vgq allocated'<br class="">+<br class="">+! QP corrections read and used to prepare wcstate<br class="">+  if(.not.l_scissor) then<br class="">+     allocate(qpc(qpe_imax))<br class="">+     call qpcorrections(wcstate)<br class="">+  endif<br class="">+<br class="">+  if(l_tspace) then<br class="">+!    solve the BSE in transition space<br class="">+     call tspace_diago(vstate,vstate_r,fc)<br class="">+  else<br class="">+!    solve the BSE with cg, or steepest descent procedure, compute the optical spectrum,<br class="">+!    and the excitonic wfns <br class="">+     if(l_lanczos) then<br class="">+        if(debug) write(*,*) 'Solve using Lanczos'<br class="">+        if(l_gtrick) call v_wfng_to_wfnr(vstate,fc,vstate_r)<br class="">+        call lanczos(vstate,vstate_r,cstate,wcstate,fc)<br class="">+     else<br class="">+        if(l_gtrick) call v_wfng_to_wfnr(vstate,fc,vstate_r)!still to be implemented<br class="">+        call find_eig(vstate,vstate_r,cstate,wcstate,fc)<br class="">+     endif<br class="">+     call mp_barrier(world_comm)<br class="">+  endif <br class="">+<br class="">+! <br class="">+<br class="">+<br class="">+! free memory<br class="">+  call free_v_state_r(vstate_r)<br class="">+  call free_v_state(vstate)<br class="">+  call free_c_state(cstate)<br class="">+  call free_c_state(wcstate)<br class="">+  if(.not.l_scissor) deallocate(qpc)<br class="">+<br class="">+  write(stdout,*) 'BSE COMPLETED'<br class="">+  call stop_clock('bse_main')<br class="">+  call print_clock('bse_main')<br class="">+  call print_clock('fft')<br class="">+  call print_clock('ffts')<br class="">+  call print_clock('fftw')<br class="">+  call print_clock('cft3t')<br class="">+  call print_clock('davcio')<br class="">+  call print_clock('make_v_state')<br class="">+  call print_clock('make_c_state')<br class="">+  call print_clock('v_wfng_to_wfnr')<br class="">+  call print_clock('c_wfng_to_wfnr')<br class="">+  call print_clock('c_times_exc')<br class="">+  call print_clock('pc_operator_exc')<br class="">+  call print_clock('sproduct_exc')<br class="">+  call print_clock('normalize_exc')<br class="">+  call print_clock('pout_operator_exc')<br class="">+  call print_clock('fft_a_exc')<br class="">+  call print_clock('fftback_a_exc')<br class="">+  call print_clock('urot_a')<br class="">+  CALL print_clock('cgsolve')<br class="">+  call print_clock('conjgrad')<br class="">+  call print_clock('linmin')<br class="">+  call print_clock('diago_exc')<br class="">+  call print_clock('direct_v_exc')<br class="">+  call print_clock('direct_w_exc')<br class="">+  call print_clock('direct_w_dgemv')<br class="">+  call print_clock('dgemv1')<br class="">+  call print_clock('dgemv2')<br class="">+  call print_clock('dgemv3')<br class="">+  call print_clock('dgemv4')<br class="">+  call print_clock('direct_w_cft3t')<br class="">+  call print_clock('wdirect_fftback')<br class="">+  call print_clock('exchange_exc')<br class="">+  call print_clock('direct_w_contract')<br class="">+  call print_clock('direct_v_contract')<br class="">+  call print_clock('dvpsi_e')<br class="">+  call print_clock('exc_h_a')<br class="">+  call print_clock('find_eig')<br class="">+  call print_clock('h_h')<br class="">+  call print_clock('lanczos')<br class="">+  call print_clock('lanczos_iterations')<br class="">+  call print_clock('lanczos_cf')<br class="">+  call print_clock('plot_excwfn')<br class="">+  call print_clock('print_spectrum')<br class="">+  call print_clock('read_export')<br class="">+  call print_clock('rotate_wannier_gamma_bse')<br class="">+  call print_clock('sdescent')<br class="">+  call print_clock('build_spectrum')<br class="">+  call print_clock('absorption')<br class="">+  call print_clock('amplitude_finite')<br class="">+  call print_clock('amplitude')<br class="">+  call print_clock('tspace_diago')<br class="">+  call print_clock('build_exch')<br class="">+  call print_clock('read_wannier_matrix')<br class="">+<br class="">+  CALL FLUSH( stdout )<br class="">+<br class="">+  call stop_pp<br class="">+<br class="">+  stop<br class="">+end program bse_punch<br class="">+<br class="">+<br class="">+<br class="">+<br class="">+<br class=""><br class="">Added: trunk/espresso/GWW/bse/bse_wannier.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/bse_wannier.f90<span class="Apple-tab-span" style="white-space:pre"> </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/bse_wannier.f90<span class="Apple-tab-span" style="white-space:pre">  </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,63 @@<br class="">+!this module contains bse code input variables  <br class="">+MODULE bse_wannier<br class="">+<br class="">+  USE kinds, ONLY: DP<br class="">+<br class="">+  INTEGER :: numw_prod!number of products w_i(r)*w_j(r) then of orthonormalized products<br class="">+  INTEGER :: num_nbndv(2) !number of valence bands<br class="">+  INTEGER :: nset!number of states to be read  written from/to file simultaneously<br class="">+  INTEGER :: maxit!maximun number of iterarion for conj gradient minimiaztion<br class="">+  INTEGER :: n_eig!number of excitoninc eigenvalues to be found<br class="">+  INTEGER :: cg_nreset!conj gradient variable number of steps after which <br class="">+                      !the residual is effectively computed with the application<br class="">+                      ! of the Hamiltonian  <br class="">+  INTEGER :: plotn_min!start plotting from plot_nmin eigenstate <br class="">+  INTEGER :: plotn_max!end plotting at plot_nmax eigenstate<br class="">+  INTEGER :: nbndt! total number of bands<br class="">+  INTEGER :: spectra_nstep! number of frequencies for which the spectrum will be<br class="">+                          !computed <br class="">+  INTEGER :: l_restart! if 1 restart from the computation of the n_eig_start<br class="">+                      ! vector; if 2 restart from the calculation of the<br class="">+                      ! absorption spectrum<br class="">+  INTEGER :: n_eig_start! eigenvector index where the calculation restarts from <br class="">+  INTEGER :: nlcz_restart! number of lanczos iteration where the calculation<br class="">+                            !restarts from<br class="">+  INTEGER :: nit_lcz! number of total lanczos iteration to be performed <br class="">+  INTEGER :: qpe_imin ! index of the lowest band for which GW energies are known<br class="">+  INTEGER :: qpe_imax ! index of the highest band for which GW energies are known <br class="">+  LOGICAL :: l_truncated_coulomb!if true the Coulomb potential is truncated<br class="">+  LOGICAL :: l_verbose!if true higher verbosity output<br class="">+  LOGICAL :: l_cgrad! if true conjgradient diago<br class="">+  LOGICAL :: l_plotexc !if true plot the excitonic wavefunctions<br class="">+  LOGICAL :: l_plotaverage !if true plot the average excitonic wavefunction (for degenerate states)<br class="">+  LOGICAL :: l_tspace !if true solve the BSE in transition space<br class="">+  LOGICAL :: l_finite !if true computes the spectrum using the expectation<br class="">+                       !value of the position operator, makes sense only for finite<br class="">+                       !systems<br class="">+  LOGICAL :: l_lanczos !if true computes absorption through a lanczos procedure<br class="">+  LOGICAL :: l_restart_lcz! if true restart the lanczos calculation from<br class="">+                          ! previous run<br class="">+  LOGICAL :: l_fullbse ! if true perform full BSE calculation<br class="">+  LOGICAL :: l_tdhf ! if true perform do not include Wc,i.e. perform<br class="">+                    ! a td-hf like calculation<br class="">+  LOGICAL :: l_lf   ! do not include the W=v+Wc term local fields only<br class="">+  LOGICAL :: l_rpa  ! RPA non-local field calculation<br class="">+  LOGICAL :: l_scissor! if true use scissor operator, else use computed QP energies<br class="">+  REAL(kind=DP) :: truncation_radius!truncation radius for Coulomb potential<br class="">+  REAL(kind=DP) :: dual_bse!dual factor for bse calculations<br class="">+  REAL(kind=DP) :: lambda!small positive real for steepest descendent<br class="">+  REAL(kind=DP) :: eps!small positive real for steepest descendent convergence<br class="">+  REAL(kind=DP) :: eps_eig!small positive real for steepest descendent convergence check on eigenstate<br class="">+  REAL(kind=DP) :: lm_delta! magnitude of the step along the search direction in<br class="">+                           ! the line minimization subroutine  <br class="">+  REAL(kind=DP) :: scissor!scissor operator opening the KS gap in eV<br class="">+  REAL(kind=DP) :: r_hole(3)!coordinate of the hole (in alat units) for the excitonic wavefunction plot<br class="">+  REAL(kind=DP) :: r_pola(3)!polarization direction<br class="">+  REAL(kind=DP) :: spectra_e_min!minimum energy for the absorption spectrum<br class="">+  REAL(kind=DP) :: spectra_e_max!max energy for the absorption spectrum<br class="">+  REAL(kind=DP) :: spectra_broad!range of broadening for the spectra (in eV) <br class="">+  LOGICAL :: l_contraction!if true uses contraction for speeding-up<br class="">+  LOGICAL :: l_gtrick!save arrays in G space for limiting memory usage<br class="">+<br class="">+END MODULE bse_wannier<br class="">+<br class=""><br class="">Added: trunk/espresso/GWW/bse/cgsolve.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/cgsolve.f90<span class="Apple-tab-span" style="white-space:pre"> </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/cgsolve.f90<span class="Apple-tab-span" style="white-space:pre">      </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,189 @@<br class="">+!<br class="">+! Copyright (C) 2003 PWSCF group<br class="">+! This file is distributed under the terms of the<br class="">+! GNU General Public License. See the file `License'<br class="">+! in the root directory of the present distribution,<br class="">+! or <a href="http://www.gnu.org/copyleft/gpl.txt" class="">http://www.gnu.org/copyleft/gpl.txt</a> .<br class="">+!<br class="">+!<br class="">+!-----------------------------------------------------------------------<br class="">+SUBROUTINE cgsolve (npw,evc,npwx,nbnd,overlap,      &<br class="">+     &              nbndx,orthonormal,precondition,diagonal, &<br class="">+     &              startwith0,e,b,u,h,Ah,pu,niter,eps,iter,x)<br class="">+  !-----------------------------------------------------------------------<br class="">+  !<br class="">+  !  conjugate-gradient solution of a system of constrained linear equations<br class="">+  !  "operator" is the linear operator - diagonal preconditioning allowed<br class="">+  !  x = solution, u = gradient, h = conjugate gradient, Ah = operator*h<br class="">+  !<br class="">+  USE io_global, ONLY : stdout<br class="">+  USE kinds,     ONLY : DP<br class="">+  USE becmod,    ONLY : calbec<br class="">+  USE io_global,   ONLY : ionode,stdout<br class="">+  USE gvect,                 ONLY : gstart<br class="">+  USE mp, ONLY : mp_sum, mp_barrier<br class="">+  USE mp_world,             ONLY : world_comm<br class="">+<br class="">+  IMPLICIT NONE<br class="">+  INTEGER npw, npwx, nbnd, nbndx, niter, iter<br class="">+  real(DP) :: diagonal(npw), e(nbnd), overlap(nbndx,nbnd)<br class="">+  COMPLEX(DP) :: x(npwx,nbnd), b(npwx,nbnd), u(npwx,nbnd),          &<br class="">+       h(npwx,nbnd),Ah(npwx,nbnd),evc(npwx,nbnd), pu(npwx,nbnd)<br class="">+  LOGICAL :: orthonormal, precondition,startwith0<br class="">+  !<br class="">+  INTEGER :: ibnd, jbnd, i, info<br class="">+  real(DP) :: lagrange(nbnd,nbnd)<br class="">+  real(DP) :: lambda, u_u, uu0, u_A_h, alfa, eps, uu(nbnd), ddot<br class="">+  logical ::  debug<br class="">+  real(kind=DP), allocatable :: omat(:,:)<br class="">+  integer j<br class="">+  EXTERNAL ddot, H_h<br class="">+  !<br class="">+  CALL start_clock('cgsolve')<br class="">+  debug=.false.<br class="">+  !<br class="">+  ! starting gradient |u> = (A|x>-|b>)-lambda|psi> (lambda=<Ax-b|psi_i>)<br class="">+  !<br class="">+  IF (.not.startwith0) THEN<br class="">+     CALL H_h(e,x,u)<br class="">+  ELSE<br class="">+     u (:,:) = (0.d0, 0.d0)<br class="">+     ! note that we assume x=0 on input<br class="">+  ENDIF<br class="">+  !<br class="">+<br class="">+  allocate(omat(nbnd,nbnd))<br class="">+  omat(1:nbnd,1:nbnd)=0.d0<br class="">+  if(debug) then<br class="">+     call dgemm('T','N',nbnd,nbnd,2*npw,2.d0,b,2*npwx,b,2*npwx,0.d0,omat,nbnd)<br class="">+     if(gstart==2) then<br class="">+        do i=1,nbnd<br class="">+           do j=1,nbnd<br class="">+              omat(i,j)=omat(i,j)-dble(b(1,i)*conjg(b(1,j)))<br class="">+           enddo<br class="">+        enddo<br class="">+     endif<br class="">+   <br class="">+     call mp_sum(omat,world_comm)  <br class="">+     do i=1,nbnd<br class="">+        do j=1,nbnd<br class="">+           if(ionode) write(*,*) 'nbnd1,nbnd2,omat4(1,2)', i,j,omat(i,j)<br class="">+        enddo<br class="">+     enddo<br class="">+  endif<br class="">+<br class="">+<br class="">+ <br class="">+  CALL daxpy(2*npwx*nbnd,-1.d0,b,1,u,1)<br class="">+<br class="">+  IF (precondition) THEN<br class="">+     CALL zvscal(npw,npwx,nbnd,diagonal,u,pu)<br class="">+     CALL calbec ( npw, evc, pu, lagrange )<br class="">+  ELSE<br class="">+     CALL calbec ( npw, evc,  u, lagrange )<br class="">+   ENDIF<br class="">+  IF (.not. orthonormal) &<br class="">+       CALL DPOTRS('U',nbnd,nbnd,overlap,nbndx,lagrange,nbnd,info)<br class="">+  IF (info/=0) CALL errore('cgsolve','error in potrs',info)<br class="">+  !<br class="">+  CALL dgemm ('N', 'N', 2*npw, nbnd, nbnd, -1.d0, evc, &<br class="">+       2*npwx, lagrange, nbnd, 1.d0, u, 2*npwx)<br class="">+  !<br class="">+  ! starting conjugate gradient |h> = |u><br class="">+  IF (precondition) THEN<br class="">+     CALL zvscal(npw,npwx,nbnd,diagonal,u,h)<br class="">+  ELSE<br class="">+     CALL zcopy(npwx,nbnd,u,1,h,1)<br class="">+  ENDIF<br class="">+  ! uu = <u|h><br class="">+  CALL pw_dot('Y',npw,nbnd,u,npwx,h,npwx,uu)<br class="">+  u_u = 0.0d0<br class="">+  DO ibnd=1,nbnd<br class="">+     u_u = u_u + uu(ibnd)<br class="">+  ENDDO<br class="">+  !<br class="">+  !      print '("  iter # ",i3,"  u_u = ",e10.4)', 0, u_u<br class="">+  !<br class="">+  !   main iteration loop<br class="">+  !<br class="">+  DO iter = 1, niter<br class="">+  <br class="">+     !<br class="">+     ! calculate A|h><br class="">+     !<br class="">+     CALL H_h(e,h(1,1),Ah(1,1))<br class="">+     !<br class="">+     ! u_A_h = <u|A|h> (NB: must be equal to <h|A|h>)<br class="">+     IF (precondition) THEN<br class="">+        CALL zvscal(npw,npwx,nbnd,diagonal,u,pu)<br class="">+        ! uu = <u|PA|h><br class="">+        CALL pw_dot('Y',npw,nbnd,pu,npwx,Ah,npwx,uu)<br class="">+     ELSE<br class="">+        ! uu = <u|A|h><br class="">+        CALL pw_dot('Y',npw,nbnd, u,npwx,Ah,npwx,uu)<br class="">+     ENDIF<br class="">+     u_A_h = 0.0d0<br class="">+     DO ibnd=1,nbnd<br class="">+        u_A_h = u_A_h + uu(ibnd)<br class="">+     ENDDO<br class="">+     !<br class="">+     lambda = - u_u / u_A_h<br class="">+     ! update the gradient and the trial solution<br class="">+     uu0 = u_u<br class="">+     u_u = 0.0d0<br class="">+     CALL daxpy(2*npwx*nbnd,lambda, h,1,x,1)<br class="">+     CALL daxpy(2*npwx*nbnd,lambda,Ah,1,u,1)<br class="">+     ! lagrange multipliers ensure orthogonality of the solution<br class="">+     IF (precondition) THEN<br class="">+        CALL zvscal(npw,npwx,nbnd,diagonal,u,pu)<br class="">+        CALL calbec ( npw, evc, pu, lagrange )<br class="">+     ELSE<br class="">+        CALL calbec ( npw, evc,  u, lagrange )<br class="">+     ENDIF<br class="">+     IF (.not. orthonormal) &<br class="">+          CALL DPOTRS('U',nbnd,nbnd,overlap,nbndx,lagrange,nbnd,info)<br class="">+     IF (info/=0) CALL errore('cgsolve','error in potrs',info)<br class="">+     CALL dgemm ('N', 'N', 2*npw, nbnd, nbnd,-1.d0, evc, &<br class="">+          2*npwx, lagrange, nbndx, 1.d0, u, 2*npwx)<br class="">+     IF (precondition) THEN<br class="">+        CALL zvscal(npw,npwx,nbnd,diagonal,u,pu)<br class="">+        ! uu = <u|A|u><br class="">+        CALL pw_dot('Y',npw,nbnd, u,npwx,pu,npwx,uu)<br class="">+     ELSE<br class="">+        ! uu = <u|u><br class="">+        CALL pw_dot('Y',npw,nbnd, u,npwx, u,npwx,uu)<br class="">+     ENDIF<br class="">+     u_u = 0.0d0<br class="">+     DO ibnd=1,nbnd<br class="">+        u_u = u_u + uu(ibnd)<br class="">+     ENDDO<br class="">+     !         print '("  iter # ",i3,"  u_u = ",e10.4)', iter, u_u<br class="">+     !<br class="">+     IF( u_u <= eps) GOTO 10<br class="">+     IF (iter==niter) THEN<br class="">+        WRITE( stdout,'("   *** Conjugate Gradient minimization",   &<br class="">+             &    " not converged after ",i3," iterations"/ &<br class="">+             &    " residual norm |Ax-b|^2 : ",e10.4)') iter,u_u<br class="">+        GOTO 10<br class="">+     ENDIF<br class="">+     !   update the conjugate gradient<br class="">+     alfa =  u_u / uu0<br class="">+     DO ibnd = 1,nbnd<br class="">+        IF (precondition) THEN<br class="">+           DO i=1,npw<br class="">+              h(i,ibnd) = alfa*h(i,ibnd) + u(i,ibnd)*diagonal(i)<br class="">+           ENDDO<br class="">+        ELSE<br class="">+           DO i=1,npw<br class="">+              h(i,ibnd) = alfa*h(i,ibnd) + u(i,ibnd)<br class="">+           ENDDO<br class="">+        ENDIF<br class="">+     ENDDO<br class="">+  ENDDO<br class="">+  !<br class="">+10 CONTINUE<br class="">+  CALL stop_clock('cgsolve')<br class="">+  !<br class="">+  deallocate(omat)<br class="">+  RETURN<br class="">+END SUBROUTINE cgsolve<br class=""><br class="">Added: trunk/espresso/GWW/bse/check_basis.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/check_basis.f90<span class="Apple-tab-span" style="white-space:pre">     </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/check_basis.f90<span class="Apple-tab-span" style="white-space:pre">  </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,82 @@<br class="">+subroutine check_basis(numwprod,npw)<br class="">+! checking if the polarizability basis is orthonormal<br class="">+<br class="">+USE fft_custom_gwl<br class="">+!USE io_files,             ONLY : find_free_unit, prefix, diropn<br class="">+USE io_files,             ONLY : prefix, diropn<br class="">+USE wavefunctions_module, ONLY :  psic<br class="">+USE mp,          ONLY :mp_barrier<br class="">+use io_global, ONLY : stdout, ionode <br class="">+USE kinds, ONLY : DP<br class="">+USE mp,             ONLY : mp_sum<br class="">+use mp_world, ONLY : mpime<br class="">+USE mp_world,             ONLY : world_comm<br class="">+USE gvect,          ONLY : gstart,ngm_g<br class="">+<br class="">+<br class="">+implicit none<br class="">+INTEGER, EXTERNAL :: find_free_unit<br class="">+REAL(kind=DP), EXTERNAL :: ddot<br class="">+<br class="">+integer numwprod<br class="">+integer npw<br class="">+<br class="">+COMPLEX(kind=DP), ALLOCATABLE :: p_basis(:,:)<br class="">+real(kind=DP) :: prod<br class="">+INTEGER ::iungprod<br class="">+INTEGER ::iunnorm<br class="">+LOGICAL       :: exst<br class="">+integer :: ii,jj<br class="">+<br class="">+<br class="">+<br class="">+iungprod = find_free_unit()<br class="">+allocate(p_basis(npw,numwprod))<br class="">+CALL diropn( iungprod, 'wiwjwfc_red', npw*2, exst )<br class="">+<br class="">+do ii=1,numwprod<br class="">+   call davcio(p_basis(:,ii),npw*2,iungprod,ii,-1)<br class="">+enddo<br class="">+<br class="">+call mp_barrier(world_comm)<br class="">+close(iungprod)<br class="">+<br class="">+<br class="">+! check normalization<br class="">+if(ionode) then<br class="">+   iunnorm = find_free_unit()<br class="">+   open(iunnorm, file='pol_basis_norm.dat',status='unknown',form='formatted')<br class="">+   write(iunnorm,*) '# Pol_vector_i, Norm'<br class="">+endif<br class="">+<br class="">+do ii=1,numwprod   <br class="">+   prod=2.d0*ddot(2*npw,p_basis(:,ii),1,p_basis(:,ii),1)<br class="">+   if (gstart==2) prod=prod-p_basis(1,ii)*p_basis(1,ii)<br class="">+   call mp_sum(prod,world_comm)<br class="">+!   prod=prod/ngm_g<br class="">+   if(ionode) write(iunnorm,*) ii,prod<br class="">+enddo   <br class="">+<br class="">+if(ionode) close(iunnorm)<br class="">+<br class="">+!check orthogonality<br class="">+<br class="">+if(ionode) then<br class="">+   iunnorm = find_free_unit()<br class="">+   open(iunnorm, file='pol_basis_ortho.dat',status='unknown',form='formatted')<br class="">+   write(iunnorm,*) '# Pol_vector_i, #Polarization vector j, Product'<br class="">+endif<br class="">+<br class="">+do ii=1,numwprod<br class="">+   do jj=ii+1,numwprod   <br class="">+      prod=2.d0*ddot(2*npw,p_basis(:,ii),1,p_basis(:,jj),1)<br class="">+      if (gstart==2) prod=prod-p_basis(1,ii)*p_basis(1,jj)<br class="">+      call mp_sum(prod,world_comm)<br class="">+!      prod=prod/ngm_g<br class="">+      if(ionode) write(iunnorm,*) ii,jj,prod<br class="">+   enddo<br class="">+enddo   <br class="">+<br class="">+if(ionode) close(iunnorm)<br class="">+return<br class="">+end subroutine<br class=""><br class="">Added: trunk/espresso/GWW/bse/conj_grad_stuff.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/conj_grad_stuff.f90<span class="Apple-tab-span" style="white-space:pre">      </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/conj_grad_stuff.f90<span class="Apple-tab-span" style="white-space:pre">      </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,305 @@<br class="">+subroutine linmin(i_state,a_exc,fpa,dfa,h,modh,x,vstatecg,vstate_rcg,cstate,wcstate,fc,delta_eig,restart,iter,cgstatus,step_rel)<br class="">+! This subroutine approximates the minimum of the functional<br class="">+! f=<a_exc|Hexc|a_exc>-lambda*(<a_exc|a_exc>-1)<br class="">+! along a given direction |h> with the vertex of a <br class="">+! parabola passing through the points (a_exc,fpa), and (b_exc=a_exc+delta*grad f,fpb) and having<br class="">+! slope -dfa at the a_exc point.<br class="">+! it updates the vector |a_exc> setting it at the <br class="">+! found minimum position, and it updates the value of the functional fpa, and returns its <br class="">+! gradient, |x>, at the new position  <br class="">+<br class="">+USE exciton <br class="">+USE fft_custom_gwl <br class="">+USE io_global, ONLY : stdout,ionode<br class="">+USE wvfct,    ONLY : npw<br class="">+use bse_wannier, ONLY:num_nbndv,lm_delta,eps,maxit<br class="">+USE bse_basic_structures  <br class="">+!USE mp,          ONLY :mp_barrier<br class="">+!USE constants,        ONLY: RYTOEV<br class="">+<br class="">+implicit none<br class="">+type(exc), intent(inout) :: a_exc<br class="">+type(exc), intent(out) :: x<br class="">+type(exc), intent(in) :: h<br class="">+real(kind=DP), intent(inout) :: dfa,fpa<br class="">+real(kind=DP), intent(inout) :: modh<br class="">+real(kind=DP), intent(inout):: step_rel<br class="">+logical, intent(inout) ::cgstatus<br class="">+<br class="">+type(v_state) :: vstatecg<br class="">+type(v_state_r) :: vstate_rcg<br class="">+type(c_state) :: cstate<br class="">+type(c_state) :: wcstate<br class="">+type(fft_cus) :: fc<br class="">+<br class="">+real(kind=DP) :: fp_out, fpb, fpv,delta_new,b,c,a,delta_eig,hsquare,fpc<br class="">+<br class="">+type(exc) :: b_exc<br class="">+type(exc) :: c_exc<br class="">+type(exc) :: v_exc<br class="">+type(exc) :: xb<br class="">+type(exc) :: xv<br class="">+<br class="">+integer :: is,j,i,i_state,iter<br class="">+real(kind=DP):: step,fptmp<br class="">+real(kind=DP) ::e_expected,pb,pc<br class="">+logical ::restart,fit_3p<br class="">+integer :: fit_ok<br class="">+<br class="">+real(kind=DP) :: deri,sca<br class="">+<br class="">+call start_clock('linmin')<br class="">+fit_3p=.true.<br class="">+<br class="">+<br class="">+!initialize internal vectors<br class="">+!second point for the qudratic fit<br class="">+call initialize_exc(b_exc)<br class="">+b_exc%label=1<br class="">+b_exc%npw=npw<br class="">+b_exc%numb_v=num_nbndv(1)<br class="">+allocate(b_exc%a(b_exc%npw,b_exc%numb_v))<br class="">+<br class="">+if(fit_3p) then<br class="">+!this variable is needed if we want to find the <br class="">+!parabola equations given three points<br class="">+   call initialize_exc(c_exc)<br class="">+   c_exc%label=1<br class="">+   c_exc%npw=npw<br class="">+   c_exc%numb_v=num_nbndv(1)<br class="">+   allocate(c_exc%a(c_exc%npw,c_exc%numb_v))<br class="">+endif<br class="">+<br class="">+!gradient at the second point for the qudratic fit<br class="">+call initialize_exc(xb)<br class="">+xb%label=1<br class="">+xb%npw=npw<br class="">+xb%numb_v=num_nbndv(1)<br class="">+allocate(xb%a(xb%npw,xb%numb_v))<br class="">+<br class="">+!position of the vertex of the qudratic fit<br class="">+call initialize_exc(v_exc)<br class="">+v_exc%label=1<br class="">+v_exc%npw=npw<br class="">+v_exc%numb_v=num_nbndv(1)<br class="">+allocate(v_exc%a(v_exc%npw,v_exc%numb_v))<br class="">+<br class="">+!gradient at the position of the vertex of the qudratic fit<br class="">+call initialize_exc(xv)<br class="">+xv%label=1<br class="">+xv%npw=npw<br class="">+xv%numb_v=num_nbndv(1)<br class="">+allocate(xv%a(xv%npw,xv%numb_v))<br class="">+<br class="">+!for debug purpose plot the energies along the search line<br class="">+!if(.not.cgstatus) then<br class="">+!   do j=0,50<br class="">+!    step=step_rel/25<br class="">+!      b_exc%a(1:b_exc%npw,1:b_exc%numb_v)=a_exc%a(1:a_exc%npw,1:a_exc%numb_v)+&<br class="">+!                             step*dble(j)*h%a(1:h%npw,1:h%numb_v) <br class="">+!      do is = 1,vstatecg%nspin<br class="">+!         call pc_operator_exc(b_exc,vstatecg,is)<br class="">+!      enddo<br class="">+!      call pout_operator_exc(b_exc,i_state)<br class="">+!<br class="">+!      call normalize_exc(b_exc)<br class="">+!<br class="">+!!compute the function (and the gradient) at the new b_exc position<br class="">+!      call exc_h_a(b_exc,xb,vstatecg,vstate_rcg,fc) <br class="">+!      call sproduct_exc(b_exc,xb,fpb)<br class="">+!<br class="">+!      write(stdout,*) 'en_prof', iter, dble(j), fpb<br class="">+!   enddo<br class="">+!endif<br class="">+<br class="">+<br class="">+<br class="">+!take one step along the search direction<br class="">+b_exc%a(1:b_exc%npw,1:b_exc%numb_v)=a_exc%a(1:a_exc%npw,1:a_exc%numb_v)+step_rel*h%a(1:h%npw,1:h%numb_v) <br class="">+<br class="">+<br class="">+!project into the conduction manifold,remove any component along previous<br class="">+!eigenstates, and normalize b_exc<br class="">+do is = 1,vstatecg%nspin<br class="">+   call pc_operator_exc(b_exc,vstatecg,is)<br class="">+enddo<br class="">+<br class="">+call pout_operator_exc(b_exc,i_state)!DEBUG<br class="">+<br class="">+call normalize_exc(b_exc)<br class="">+<br class="">+!compute the function at the new b_exc position<br class="">+call exc_h_a(b_exc,xb,vstatecg,vstate_rcg,cstate,wcstate,fc) <br class="">+call sproduct_exc(b_exc,xb,fpb)<br class="">+<br class="">+<br class="">+call exc_h_a(a_exc,xb,vstatecg,vstate_rcg,cstate,wcstate,fc)<br class="">+call sproduct_exc(a_exc,xb,sca)<br class="">+xb%a(1:xb%npw,1:xb%numb_v)=xb%a(1:xb%npw,1:xb%numb_v)&<br class="">+                          -sca*a_exc%a(1:b_exc%npw,1:b_exc%numb_v)<br class="">+call sproduct_exc(xb,h,deri)<br class="">+deri=deri*2.d0<br class="">+<br class="">+!compute the quadratic fit<br class="">+if(.not.fit_3p) then <br class="">+   b=deri!-dfa DEBUG<br class="">+   c=fpa<br class="">+   pb=step_rel<br class="">+   a= (fpb-b*pb-c)/((pb)**2.d0)<br class="">+<br class="">+endif<br class="">+<br class="">+if(fit_3p) then<br class="">+! find the third point C and compute there the function fpc<br class="">+   c_exc%a(1:c_exc%npw,1:c_exc%numb_v)=a_exc%a(1:a_exc%npw,1:a_exc%numb_v)+0.5d0*step_rel*h%a(1:h%npw,1:h%numb_v) <br class="">+   do is = 1,vstatecg%nspin<br class="">+      call pc_operator_exc(c_exc,vstatecg,is)<br class="">+   enddo<br class="">+<br class="">+   call pout_operator_exc(c_exc,i_state)<br class="">+<br class="">+   call normalize_exc(c_exc)<br class="">+<br class="">+!  xv is used here a tmp variable<br class="">+   call exc_h_a(c_exc,xv,vstatecg,vstate_rcg,cstate,wcstate,fc) <br class="">+   call sproduct_exc(c_exc,xv,fpc)<br class="">+<br class="">+   pb=step_rel<br class="">+   pc=0.5d0*step_rel<br class="">+   <br class="">+   c=fpa <br class="">+   a=(fpb*pc-fpc*pb-fpa*(pc-pb))/(pc*pb*(pb-pc))<br class="">+   b=(-fpb*pc*pc+fpc*pb*pb+fpa*(pc*pc-pb*pb))/(pc*pb*(pb-pc))<br class="">+<br class="">+endif<br class="">+<br class="">+<br class="">+delta_new=-b/(2.d0*a)<br class="">+<br class="">+!compute the coordinate of the parabola vertex<br class="">+v_exc%a(:,:)=a_exc%a(:,:)+delta_new*h%a(:,:) <br class="">+<br class="">+!write(stdout,*) 'delta_new',iter, delta_new<br class="">+<br class="">+!compute the expected value for the minimum from the parabolic fit<br class="">+e_expected=-b**2/(4*a)+c<br class="">+<br class="">+!project into the conduction manifold, remove any component along previous<br class="">+!eigenstates and normalize v_exc<br class="">+do is = 1,vstatecg%nspin<br class="">+   call pc_operator_exc(v_exc,vstatecg,is)<br class="">+enddo<br class="">+<br class="">+call pout_operator_exc(v_exc,i_state)<br class="">+call normalize_exc(v_exc)<br class="">+<br class="">+!compute the function (and the gradient) at the new v_exc position<br class="">+call exc_h_a(v_exc,xv,vstatecg,vstate_rcg,cstate,wcstate,fc) <br class="">+call sproduct_exc(v_exc,xv,fpv)<br class="">+xv%a(1:xv%npw,1:xv%numb_v)=xv%a(1:xv%npw,1:xv%numb_v)&<br class="">+                          -fpv*v_exc%a(1:v_exc%npw,1:v_exc%numb_v)<br class="">+<br class="">+!write(stdout,*) 'min', iter, e_expected<br class="">+!write(stdout,*) 'fpa', iter, fpa<br class="">+!write(stdout,*) 'fpb', iter, fpb<br class="">+!write(stdout,*) 'fpv', iter, fpv<br class="">+!write(stdout,*) 'FIT PARAMETER A', iter, a<br class="">+!write(stdout,*) 'FIT PARAMETER B', iter, b<br class="">+!write(stdout,*) 'FIT PARAMETER C', iter, c<br class="">+<br class="">+!find where our functional is minimum among the last three points<br class="">+<br class="">+if ((fpv<=fpa).and.(fpv<=fpb)) then<br class="">+!     the quadratic fit found a good position update the information<br class="">+   fit_ok=1<br class="">+   cgstatus=.true.<br class="">+   a_exc%a(:,:)=v_exc%a(:,:)<br class="">+!   write(stdout,*) 'Quadratic fit: V new point, fpv=',fpv, 'fpa=',fpa  <br class="">+   fpa=fpv      <br class="">+   x%a(1:x%npw,1:x%numb_v)=xv%a(1:xv%npw,1:xv%numb_v)<br class="">+else<br class="">+!take a steepest descent step and restart the cg<br class="">+   write(stdout,*) 'WARNING:I restart the cg'<br class="">+   cgstatus=.false.<br class="">+   fit_ok=0<br class="">+   j=1<br class="">+   fptmp=fpa+0.1d0<br class="">+   do while (fptmp>=fpa)<br class="">+      step=(0.3d0)*(0.1d0**j)<br class="">+      b_exc%a(:,:)=a_exc%a(:,:)+step_rel*step*h%a(:,:) <br class="">+<br class="">+!  project into the conduction manifold remove any component along previous<br class="">+!  eigenstates, and normalize b_exc<br class="">+      do is = 1,vstatecg%nspin<br class="">+         call pc_operator_exc(b_exc,vstatecg,is)<br class="">+      enddo<br class="">+      call pout_operator_exc(b_exc,i_state)<br class="">+      call normalize_exc(b_exc)<br class="">+<br class="">+!  compute the function (and the gradient) at the new b_exc position<br class="">+      call exc_h_a(b_exc,xb,vstatecg,vstate_rcg,cstate,wcstate,fc) <br class="">+      call sproduct_exc(b_exc,xb,fptmp)<br class="">+      xb%a(1:xb%npw,1:xb%numb_v)=xb%a(1:xb%npw,1:xb%numb_v)&<br class="">+                          -fptmp*b_exc%a(1:b_exc%npw,1:b_exc%numb_v)<br class="">+  <br class="">+      if(fptmp>=fpa) then! look in the opposite direction<br class="">+         b_exc%a(:,:)=a_exc%a(:,:)-step_rel*step*h%a(:,:)<br class="">+!        project into the conduction manifold remove any component along previous<br class="">+!        eigenstates, and normalize b_exc<br class="">+         do is = 1,vstatecg%nspin<br class="">+            call pc_operator_exc(b_exc,vstatecg,is)<br class="">+         enddo<br class="">+         call pout_operator_exc(b_exc,i_state)<br class="">+         call normalize_exc(b_exc)<br class="">+<br class="">+!  compute the function (and the gradient) at the new b_exc position<br class="">+         call exc_h_a(b_exc,xb,vstatecg,vstate_rcg,cstate,wcstate,fc) <br class="">+         call sproduct_exc(b_exc,xb,fptmp)<br class="">+         xb%a(1:xb%npw,1:xb%numb_v)=xb%a(1:xb%npw,1:xb%numb_v)&<br class="">+                          -fptmp*b_exc%a(1:b_exc%npw,1:b_exc%numb_v)<br class="">+    <br class="">+      endif<br class="">+      j=j+1<br class="">+   enddo <br class="">+   <br class="">+   a_exc%a(:,:)=b_exc%a(:,:)<br class="">+   fpa=fptmp      <br class="">+   x%a(1:x%npw,1:x%numb_v)=xb%a(1:xb%npw,1:xb%numb_v)<br class="">+endif   <br class="">+<br class="">+<br class="">+!project into the conduction manifold<br class="">+do is = 1,vstatecg%nspin<br class="">+   call pc_operator_exc(x,vstatecg,is)<br class="">+enddo<br class="">+call pout_operator_exc(x,i_state)<br class="">+!compute dfa, i.e. the magnitude of the gradient at the position a_exc<br class="">+call sproduct_exc(x,x,dfa)<br class="">+dfa=sqrt(dfa)<br class="">+<br class="">+<br class="">+!compute delta_eig (using as a tmp variable b)<br class="">+call exc_h_a(a_exc,b_exc,vstatecg,vstate_rcg,cstate,wcstate,fc) <br class="">+<br class="">+call sproduct_exc(b_exc,b_exc,hsquare)<br class="">+<br class="">+delta_eig=hsquare-fpa**2<br class="">+<br class="">+! set the magnitude of the next step <br class="">+if(cgstatus) then <br class="">+   step_rel=2.d0*delta_new <br class="">+else<br class="">+   step_rel=(0.3d0)*(0.1d0**(j-1))<br class="">+endif<br class="">+<br class="">+!write(stdout,*) 'fit_ok', iter, fit_ok<br class="">+!free memory<br class="">+call free_memory_exc_a(b_exc)<br class="">+if(fit_3p) call free_memory_exc_a(c_exc)<br class="">+call free_memory_exc_a(v_exc)<br class="">+call free_memory_exc_a(xb)<br class="">+call free_memory_exc_a(xv)<br class="">+<br class="">+call stop_clock('linmin')<br class="">+return<br class="">+end subroutine <br class=""><br class="">Added: trunk/espresso/GWW/bse/conjgrad.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/conjgrad.f90<span class="Apple-tab-span" style="white-space:pre">        </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/conjgrad.f90<span class="Apple-tab-span" style="white-space:pre">     </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,198 @@<br class="">+subroutine conjgrad(i_state,vstatecg,vstate_rcg,cstate,wcstate,fc,en)<br class="">+use exciton <br class="">+use bse_basic_structures <br class="">+USE fft_custom_gwl <br class="">+USE io_global, ONLY : stdout,ionode<br class="">+USE wvfct,    ONLY : npw<br class="">+use bse_wannier, ONLY:num_nbndv,eps,maxit,eps_eig,lm_delta<br class="">+USE mp,          ONLY :mp_barrier<br class="">+USE mp_world,             ONLY : world_comm<br class="">+USE constants,        ONLY: RYTOEV<br class="">+<br class="">+implicit none<br class="">+<br class="">+type(exc) :: a_exc<br class="">+type(exc) :: x<br class="">+type(exc) :: g<br class="">+type(exc) :: h<br class="">+<br class="">+type(v_state) :: vstatecg<br class="">+type(v_state_r) :: vstate_rcg<br class="">+type(c_state) :: cstate<br class="">+type(c_state) :: wcstate<br class="">+type(fft_cus) :: fc<br class="">+<br class="">+!real(kind=DP) :: ha,hb,hc<br class="">+<br class="">+real(kind=dp), intent(out) :: en<br class="">+<br class="">+real(kind=DP) :: fp,fp_out,dfp,cg_lambda,dfg,step_rel<br class="">+real(kind=DP) :: eigout,gg,dgg,gam,delta,hsquare,delta_eig,modh<br class="">+integer :: i, is, i_state<br class="">+<br class="">+logical :: restart<br class="">+logical :: cgstatus<br class="">+<br class="">+call start_clock('conjgrad')<br class="">+<br class="">+restart=.false.<br class="">+cgstatus=.false.<br class="">+<br class="">+if(ionode) write(stdout,*) 'Conjugate gradient started.'<br class="">+if(ionode) write(stdout,*) 'Looking for eigenvalue number:',i_state<br class="">+if(ionode) write(stdout,*) 'eps=',eps<br class="">+if(ionode) write(stdout,*) 'eps_eig=',eps_eig<br class="">+<br class="">+!create initial random excitonic wavefunction vector a_exc <br class="">+call initialize_exc(a_exc)<br class="">+a_exc%label=1<br class="">+a_exc%npw=npw<br class="">+a_exc%numb_v=num_nbndv(1)<br class="">+allocate(a_exc%a(a_exc%npw,a_exc%numb_v))<br class="">+<br class="">+call random_exc(a_exc)<br class="">+<br class="">+!project into the conduction manifold<br class="">+do is = 1,vstatecg%nspin<br class="">+   call pc_operator_exc(a_exc,vstatecg,is)<br class="">+enddo<br class="">+<br class="">+!project out all the previous found state<br class="">+call pout_operator_exc(a_exc,i_state)<br class="">+ <br class="">+!and normalize it<br class="">+call normalize_exc(a_exc)<br class="">+<br class="">+!initialize the other (internal) vectors<br class="">+!within the cc iteration x is the gradient vector <br class="">+call initialize_exc(x)<br class="">+x%label=1<br class="">+x%npw=npw<br class="">+x%numb_v=num_nbndv(1)<br class="">+allocate(x%a(x%npw,x%numb_v))<br class="">+<br class="">+!within the cg iteration g is the vector that stores (minus) the previous-step's gradient  <br class="">+call initialize_exc(g)<br class="">+g%label=1<br class="">+g%npw=npw<br class="">+g%numb_v=num_nbndv(1)<br class="">+allocate(g%a(g%npw,g%numb_v))<br class="">+<br class="">+!within the cg gradient iteration h is storing the search direction <br class="">+!check if really needed<br class="">+call initialize_exc(h)<br class="">+h%label=1<br class="">+h%npw=npw<br class="">+h%numb_v=num_nbndv(1)<br class="">+allocate(h%a(h%npw,h%numb_v))<br class="">+<br class="">+<br class="">+!Compute gradient at the initial guess position  <br class="">+call exc_h_a(a_exc,x,vstatecg,vstate_rcg,cstate,wcstate,fc) <br class="">+<br class="">+!Compute function value fp at the initial guess position a_exc<br class="">+call sproduct_exc(a_exc,x,fp)<br class="">+!call sproduct_exc(x,x,hsquare)<br class="">+<br class="">+x%a(1:x%npw,1:x%numb_v)=x%a(1:x%npw,1:x%numb_v)&<br class="">+                          -fp*a_exc%a(1:a_exc%npw,1:a_exc%numb_v)<br class="">+<br class="">+!Project the gradient into the conduction states manifold<br class="">+!Remove any component along the eigenstates already found<br class="">+do is = 1,vstatecg%nspin<br class="">+   call pc_operator_exc(x,vstatecg,is)<br class="">+enddo<br class="">+call pout_operator_exc(x,i_state)<br class="">+<br class="">+!Compute dfp, i.e. the magnitude of the gradient at the initial guess position a_exc<br class="">+call sproduct_exc(x,x,dfp)<br class="">+dfp=sqrt(dfp)<br class="">+dfg=dfp<br class="">+modh=dfp<br class="">+<br class="">+!Set initial g and h values <br class="">+g%a(1:g%npw,1:g%numb_v)=-x%a(1:x%npw,1:x%numb_v)<br class="">+h%a(1:h%npw,1:h%numb_v)=g%a(1:g%npw,1:g%numb_v)<br class="">+<br class="">+!Start CG iterations<br class="">+step_rel=lm_delta<br class="">+delta=100<br class="">+delta_eig=dfp-fp**2<br class="">+i=1<br class="">+do while ((i<=maxit).and.((delta>=eps).or.(delta_eig>eps_eig)))<br class="">+   <br class="">+   if(i>1)delta=abs(eigout-fp*RYTOEV)<br class="">+!  note that delta_eig is calculated for each step within linmin<br class="">+   <br class="">+   eigout=fp*RYTOEV<br class="">+   if(ionode) write(stdout,*) 'CG: eig#',i_state,'it=', i, 'Eig (eV)=',eigout <br class="">+!   if(ionode) write(stdout,*) 'CG: eig#',i_state,'it=', i, 'delta_eig=',delta_eig<br class="">+<br class="">+!   if(ionode) write(stdout,*) 'CG: it=', i, 'Delta(eV)=',delta<br class="">+<br class="">+   call linmin(i_state,a_exc,fp,dfp,h,modh,x,vstatecg,vstate_rcg,cstate,wcstate,fc,delta_eig,restart,i,cgstatus,step_rel)<br class="">+<br class="">+   if(cgstatus) then   <br class="">+<br class="">+      gg=dfg**2.d0 <br class="">+      if (gg==0.d0) exit<br class="">+<br class="">+      call sproduct_exc(g,x,dgg)<br class="">+      dgg=dfp**2+dgg<br class="">+<br class="">+      gam=max(dgg/gg,0.d0)<br class="">+<br class="">+      g%a(1:g%npw,1:g%numb_v)=-x%a(1:x%npw,1:x%numb_v)<br class="">+      dfg=dfp<br class="">+<br class="">+      h%a(1:h%npw,1:h%numb_v)= g%a(1:g%npw,1:g%numb_v)+gam*h%a(1:h%npw,1:h%numb_v)<br class="">+!      x%a(1:x%npw,1:x%numb_v)=h%a(1:h%npw,1:h%numb_v)<br class="">+     <br class="">+      call sproduct_exc(h,h,modh)<br class="">+      modh=sqrt(modh)<br class="">+<br class="">+   else <br class="">+   ! every 20 iterations restart the CG or if parabolic fit didn't work<br class="">+   <br class="">+ <br class="">+      h%a(1:h%npw,1:h%numb_v)=-x%a(1:x%npw,1:x%numb_v)<br class="">+      g%a(1:g%npw,1:g%numb_v)=-x%a(1:x%npw,1:x%numb_v)<br class="">+      dfg=dfp<br class="">+      modh=dfp<br class="">+<br class="">+<br class="">+   endif<br class="">+   <br class="">+   i=i+1<br class="">+<br class="">+   call mp_barrier(world_comm)<br class="">+enddo<br class="">+<br class="">+bse_spectrum(i_state)%a(1:bse_spectrum(i_state)%npw,1:bse_spectrum(i_state)%numb_v)=&<br class="">+                         a_exc%a(1:a_exc%npw,1:a_exc%numb_v)<br class="">+<br class="">+<br class="">+bse_spectrum(i_state)%e=fp*RYTOEV<br class="">+<br class="">+en=fp<br class="">+<br class="">+<br class="">+if(i==maxit)  then<br class="">+   if(ionode) write(stdout,*) 'WARNING Conjugate gradient: Max iteration reached'<br class="">+   if(ionode) write(stdout,*) 'Please increase the max iteration number or decrease accuracy' <br class="">+endif<br class="">+<br class="">+<br class="">+<br class="">+!free memory<br class="">+call free_memory_exc_a(a_exc)<br class="">+call free_memory_exc_a(h)<br class="">+call free_memory_exc_a(g)<br class="">+call free_memory_exc_a(x)<br class="">+<br class="">+<br class="">+call stop_clock('conjgrad')<br class="">+<br class="">+if(ionode) write(stdout,*) 'Conjugate gradient ended.'<br class="">+return<br class="">+end subroutine<br class=""><br class="">Added: trunk/espresso/GWW/bse/contract_w_exc.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/contract_w_exc.f90<span class="Apple-tab-span" style="white-space:pre">  </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/contract_w_exc.f90<span class="Apple-tab-span" style="white-space:pre">       </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,716 @@<br class="">+MODULE contract_w<br class="">+<br class="">+USE kinds, ONLY : DP,sgl<br class="">+use bse_basic_structures, ONLY : ii_mat<br class="">+<br class="">+SAVE<br class="">+<br class="">+type(ii_mat) :: iimat_contract<br class="">+REAL(kind=sgl), POINTER  :: vphipizeta_save(:,:)<br class="">+REAL(kind=sgl), POINTER  :: vww_save(:,:)<br class="">+COMPLEX(kind=sgl), POINTER  :: vphipizeta_save_g(:,:)<br class="">+COMPLEX(kind=sgl), POINTER  :: vww_save_g(:,:)<br class="">+INTEGER, POINTER ::  vpmax_ii(:),vpmax_ii_start(:),vpmax_ii_end(:)<br class="">+INTEGER :: vpmax_tot<br class="">+<br class="">+CONTAINS<br class="">+<br class="">+subroutine free_memory_contrac_w<br class="">+  use bse_wannier, ONLY : l_gtrick<br class="">+  implicit none<br class="">+  if(.not.l_gtrick) then<br class="">+     deallocate(vphipizeta_save)<br class="">+  else<br class="">+     deallocate(vphipizeta_save_g)<br class="">+  endif<br class="">+  deallocate(vpmax_ii)<br class="">+  deallocate(vpmax_ii_start,vpmax_ii_end)<br class="">+  if(.not.l_gtrick) then<br class="">+     deallocate(vww_save)<br class="">+  else<br class="">+     deallocate(vww_save_g)<br class="">+  endif<br class="">+end subroutine free_memory_contrac_w<br class="">+<br class="">+subroutine contract_w_build(fc)<br class="">+! this subroutine computes the w part of the direct term of the exc Hamiltonian<br class="">+<br class="">+USE wvfct,                 ONLY :  npw <br class="">+USE fft_custom_gwl<br class="">+use bse_basic_structures<br class="">+use exciton<br class="">+USE gvect<br class="">+use bse_wannier, ONLY: l_truncated_coulomb, &<br class="">+           truncation_radius, l_gtrick<br class="">+USE constants,        ONLY : e2, fpi<br class="">+USE cell_base,        ONLY : tpiba,omega,tpiba2<br class="">+!USE io_files,             ONLY : find_free_unit, prefix, diropn<br class="">+USE io_files,             ONLY :  prefix, diropn<br class="">+USE wavefunctions_module, ONLY :  psic<br class="">+USE io_global, ONLY : stdout, ionode, ionode_id<br class="">+USE mp_world, ONLY : mpime, nproc<br class="">+USE mp_pools, ONLY: intra_pool_comm<br class="">+USE mp_wave, ONLY : mergewf,splitwf<br class="">+USE polarization<br class="">+USE lsda_mod, ONLY :nspin<br class="">+USE io_global, ONLY : stdout,ionode<br class="">+USE mp,          ONLY :mp_barrier<br class="">+USE mp_world,             ONLY : world_comm<br class="">+<br class="">+<br class="">+<br class="">+<br class="">+<br class="">+implicit none<br class="">+INTEGER, EXTERNAL :: find_free_unit<br class="">+logical :: debug=.false.<br class="">+<br class="">+type(bse_z) :: z<br class="">+type(polaw) :: pw<br class="">+<br class="">+type(fft_cus) :: fc<br class="">+type(ii_mat) :: iimat<br class="">+<br class="">+<br class="">+<br class="">+REAL(kind=DP), ALLOCATABLE :: fac(:)<br class="">+COMPLEX(kind=DP), ALLOCATABLE :: p_basis(:,:)<br class="">+COMPLEX(kind=DP), ALLOCATABLE :: p_basis_t(:,:)<br class="">+REAL(kind=DP), ALLOCATABLE :: p_basis_r(:,:)<br class="">+REAL(kind=DP), ALLOCATABLE :: zvphi(:)<br class="">+REAL(kind=DP), ALLOCATABLE :: zvv(:)<br class="">+COMPLEX(kind=DP), ALLOCATABLE :: evc_g(:)<br class="">+<br class="">+INTEGER ::iungprod<br class="">+INTEGER :: ig,ii,iv,ispin<br class="">+REAL(kind=DP) :: qq<br class="">+LOGICAL       :: exst<br class="">+<br class="">+<br class="">+INTEGER :: vpmax,k<br class="">+REAL(kind=DP), allocatable :: zp(:,:)<br class="">+REAL(kind=DP), allocatable :: pizeta(:,:)<br class="">+REAL(kind=DP), allocatable :: vphipizeta(:,:)<br class="">+<br class="">+INTEGER ::  kilobytes<br class="">+<br class="">+<br class="">+call start_clock('direct_w_exc')<br class="">+CALL memstat( kilobytes )<br class="">+write(stdout,*) 'memory0', kilobytes<br class="">+FLUSH(stdout)<br class="">+<br class="">+<br class="">+<br class="">+<br class="">+! read  iimat<br class="">+call initialize_imat(iimat)<br class="">+<br class="">+do ispin=1,nspin<br class="">+   call read_iimat(iimat,ispin) <br class="">+enddo<br class="">+<br class="">+! read z terms<br class="">+call initialize_bse_z(z)<br class="">+call read_z(1,iimat,z)<br class="">+<br class="">+FLUSH( stdout ) <br class="">+<br class="">+! get Coulomb potential<br class="">+allocate(fac(npw))<br class="">+if(l_truncated_coulomb) then<br class="">+   do ig=1,npw<br class="">+      qq = g(1,ig)**2.d0 + g(2,ig)**2.d0 + g(3,ig)**2.d0<br class="">+      if (qq > 1.d-8) then<br class="">+         fac(ig)=(e2*fpi/(tpiba2*qq))*(1.d0-dcos(dsqrt(qq)*truncation_radius*tpiba))<br class="">+      else<br class="">+         fac(ig)=e2*fpi*(truncation_radius**2.d0/2.d0)<br class="">+     endif<br class="">+   enddo<br class="">+    fac(:)=fac(:)/omega<br class="">+else<br class="">+<br class="">+   fac(:)=0.d0<br class="">+   fac(1:npw)=vg_q(1:npw)<br class="">+endif<br class="">+<br class="">+<br class="">+! read polarization basis and multiply per V<br class="">+<br class="">+iungprod = find_free_unit()<br class="">+allocate(p_basis(npw,z%numw_prod))<br class="">+CALL diropn( iungprod, 'wiwjwfc_red', npw*2, exst )<br class="">+<br class="">+do ii=1,z%numw_prod<br class="">+   call davcio(p_basis(:,ii),npw*2,iungprod,ii,-1)<br class="">+   p_basis(1:npw,ii)=p_basis(1:npw,ii)*dcmplx(fac(1:npw))<br class="">+enddo<br class="">+<br class="">+call mp_barrier(world_comm)<br class="">+<br class="">+close(iungprod)<br class="">+CALL memstat( kilobytes )<br class="">+write(stdout,*) 'memory1', kilobytes<br class="">+FLUSH(stdout)<br class="">+! FFT to real space (dual grid)<br class="">+allocate(p_basis_t(fc%npwt,z%numw_prod)) <br class="">+allocate(p_basis_r(fc%nrxxt,z%numw_prod))<br class="">+allocate(evc_g(fc%ngmt_g ))<br class="">+<br class="">+<br class="">+if(fc%dual_t==4.d0) then<br class="">+   p_basis_t(1:fc%npwt,1:z%numw_prod)=p_basis(1:npw,1:z%numw_prod)<br class="">+else<br class="">+    call reorderwfp_col(z%numw_prod,npw,fc%npwt,p_basis(1,1),p_basis_t(1,1),npw,fc%npwt, &<br class="">+           & ig_l2g,fc%ig_l2gt,fc%ngmt_g,mpime, nproc,intra_pool_comm )<br class="">+<br class="">+!   do ii=1,z%numw_prod<br class="">+!      call mergewf(p_basis(:,ii),evc_g,a_in%npw,ig_l2g,mpime,nproc,ionode_id,intra_pool_comm)<br class="">+!      call splitwf(p_basis_t(:,ii),evc_g,fc%npwt,fc%ig_l2gt,mpime,nproc,ionode_id,intra_pool_comm)<br class="">+!   enddo<br class="">+endif<br class="">+<br class="">+deallocate(evc_g)<br class="">+deallocate(p_basis)<br class="">+<br class="">+call start_clock('direct_w_cft3t')<br class="">+do ii=1,z%numw_prod,2<br class="">+   psic(1:fc%nrxxt)=(0.d0,0.d0)<br class="">+   if (ii==z%numw_prod) then<br class="">+      psic(fc%nlt(1:fc%npwt))  = p_basis_t(1:fc%npwt,ii)<br class="">+      psic(fc%nltm(1:fc%npwt)) = CONJG( p_basis_t(1:fc%npwt,ii) )<br class="">+   else<br class="">+      psic(fc%nlt(1:fc%npwt))=p_basis_t(1:fc%npwt,ii)+(0.d0,1.d0)*p_basis_t(1:fc%npwt,ii+1)<br class="">+      psic(fc%nltm(1:fc%npwt))=CONJG(p_basis_t(1:fc%npwt,ii))+(0.d0,1.d0)*CONJG(p_basis_t(1:fc%npwt,ii+1))<br class="">+   endif<br class="">+      CALL cft3t( fc, psic, fc%nr1t, fc%nr2t, fc%nr3t, fc%nrx1t, fc%nrx2t, fc%nrx3t, 2 )<br class="">+       p_basis_r(1:fc%nrxxt,ii)= DBLE(psic(1:fc%nrxxt))<br class="">+      if(ii/=z%numw_prod) p_basis_r(1:fc%nrxxt,ii+1)= DIMAG(psic(1:fc%nrxxt))<br class="">+enddo<br class="">+call stop_clock('direct_w_cft3t')<br class="">+<br class="">+deallocate(p_basis_t) <br class="">+<br class="">+!read P<br class="">+call initialize_polaw(pw)<br class="">+call read_polaw_global(0, pw)<br class="">+<br class="">+<br class="">+call mp_barrier(world_comm)<br class="">+<br class="">+CALL memstat( kilobytes )<br class="">+write(stdout,*) 'memory2', kilobytes<br class="">+FLUSH(stdout)<br class="">+<br class="">+<br class="">+! allocate tmp matrix<br class="">+<br class="">+<br class="">+!compute line by line the output excitonic vector<br class="">+<br class="">+!!!!!!!!!!!!!!!!!dgemm subroutine!!!!!!!!!!!!!!!!!!!!!<br class="">+call start_clock('direct_w_dgemv')<br class="">+write(stdout,*) 'memory2',z%numw_prod,iimat%np_max<br class="">+allocate(zp(z%numw_prod,iimat%np_max))<br class="">+!!allocate(pizeta(z%numw_prod,iimat%np_max)) <br class="">+!!allocate(vphipizeta(fc%nrxxt,iimat%np_max)) <br class="">+!calculate vpmax_tot<br class="">+vpmax_tot=0<br class="">+allocate(vpmax_ii( iimat%numb_v))<br class="">+allocate(vpmax_ii_start( iimat%numb_v))<br class="">+allocate(vpmax_ii_end( iimat%numb_v))<br class="">+do iv=1, iimat%numb_v<br class="">+<br class="">+   vpmax=0<br class="">+   vpmax_ii_start(iv)=vpmax_tot+1<br class="">+   do ii=1, iimat%np_max<br class="">+      if (iimat%iimat(ii,iv)==0) cycle<br class="">+      vpmax=vpmax+1<br class="">+   enddo<br class="">+   vpmax_ii(iv)=vpmax<br class="">+   vpmax_tot=vpmax_tot+vpmax<br class="">+   vpmax_ii_end(iv)=vpmax_tot<br class="">+enddo<br class="">+write(stdout,*)  'VPHIZETA_SAVE :', fc%nrxxt,vpmax_tot<br class="">+FLUSH(stdout)<br class="">+if(.not.l_gtrick) then<br class="">+   allocate(vphipizeta_save(fc%nrxxt,vpmax_tot))<br class="">+else<br class="">+   allocate(vphipizeta_save_g(fc%npwt,vpmax_tot))<br class="">+endif<br class="">+write(stdout,*)  'VPHIZETA_SAVE :', fc%nrxxt,vpmax_tot<br class="">+!<br class="">+CALL memstat( kilobytes )<br class="">+write(stdout,*) 'memory3', kilobytes<br class="">+FLUSH(stdout)<br class="">+do iv=1, iimat%numb_v<br class="">+   zp(1:z%numw_prod,1:iimat%np_max)=0.d0<br class="">+   vpmax=0<br class="">+ <br class="">+   write(stdout,*) 'DEBUG1'<br class="">+   FLUSH(stdout)<br class="">+   call start_clock('dgemv1')<br class="">+   do ii=1, iimat%np_max<br class="">+      if (iimat%iimat(ii,iv)==0) cycle<br class="">+      vpmax=vpmax+1<br class="">+      do k=1, z%numw_prod<br class="">+         zp(k,vpmax)=z%z(k,ii,iv)!ATTENZIONE era zp(ii)<br class="">+      enddo<br class="">+   enddo<br class="">+   write(stdout,*) 'DEBUG2'<br class="">+  FLUSH(stdout)<br class="">+  if(vpmax>0) then<br class="">+     allocate(pizeta(z%numw_prod,vpmax)) <br class="">+     allocate(vphipizeta(fc%nrxxt,vpmax)) <br class="">+  else<br class="">+     allocate(pizeta(z%numw_prod,1))<br class="">+     allocate(vphipizeta(fc%nrxxt,1))<br class="">+  endif<br class="">+   call stop_clock('dgemv1')<br class="">+<br class="">+<br class="">+   call start_clock('dgemv2.1')<br class="">+   write(stdout,*) 'DEBUG2', z%numw_prod,pw%numpw<br class="">+   FLUSH(stdout)<br class="">+<br class="">+   call dgemm('N','N', z%numw_prod,vpmax, z%numw_prod,1.d0,pw%pw,z%numw_prod,zp,&<br class="">+              z%numw_prod,0.d0,pizeta,z%numw_prod)<br class="">+   call stop_clock('dgemv2')<br class="">+<br class="">+   write(stdout,*) 'DEBUG3'<br class="">+   FLUSH(stdout)<br class="">+   call start_clock('dgemv3')<br class="">+   call dgemm('N','N', fc%nrxxt, vpmax, z%numw_prod,1.d0,p_basis_r(1,1),fc%nrxxt,&<br class="">+              pizeta(1,1), z%numw_prod, 0.d0, vphipizeta(1,1),fc%nrxxt)<br class="">+   call stop_clock('dgemv3')<br class="">+   if(.not.l_gtrick) then<br class="">+      vphipizeta_save(1:fc%nrxxt,vpmax_ii_start(iv):vpmax_ii_end(iv))= real(vphipizeta(1:fc%nrxxt,1:vpmax))<br class="">+   else<br class="">+      do ii=1,vpmax,2<br class="">+         if(ii==vpmax) then<br class="">+            psic(1:fc%nrxxt)=dcmplx(vphipizeta(1:fc%nrxxt,ii),0.d0)<br class="">+         else<br class="">+            psic(1:fc%nrxxt)=dcmplx(vphipizeta(1:fc%nrxxt,ii),vphipizeta(1:fc%nrxxt,ii+1))<br class="">+         endif<br class="">+         CALL cft3t(fc, psic, fc%nr1t, fc%nr2t, fc%nr3t, fc%nrx1t, fc%nrx2t, fc%nrx3t, -2 )<br class="">+         if(ii==vpmax) then<br class="">+            vphipizeta_save_g(1:fc%npwt,vpmax_ii_start(iv)+ii-1)=cmplx(psic(fc%nlt(1:fc%npwt)))<br class="">+         else<br class="">+            vphipizeta_save_g(1:fc%npwt,vpmax_ii_start(iv)+ii-1)=&<br class="">+                 &cmplx(0.5d0*(psic(fc%nlt(1:fc%npwt))+conjg( psic(fc%nltm(1:fc%npwt)))))<br class="">+            vphipizeta_save_g(1:fc%npwt,vpmax_ii_start(iv)+ii-1+1)=&<br class="">+                 &cmplx((0.d0,-0.5d0)*(psic(fc%nlt(1:fc%npwt)) - conjg(psic(fc%nltm(1:fc%npwt)))))<br class="">+         endif<br class="">+      enddo<br class="">+   endif<br class="">+     write(stdout,*) 'DEBUG4'<br class="">+     FLUSH(stdout)<br class="">+   !<br class="">+!<br class="">+   deallocate(pizeta)<br class="">+   deallocate(vphipizeta)<br class="">+call mp_barrier(world_comm)<br class="">+enddo<br class="">+call stop_clock('direct_w_dgemv')<br class="">+<br class="">+deallocate(zp)<br class="">+deallocate(p_basis_r)<br class="">+<br class="">+call free_bse_z(z)<br class="">+call free_memory_polaw(pw)<br class="">+call free_imat(iimat)<br class="">+<br class="">+<br class="">+FLUSH( stdout )<br class="">+CALL memstat( kilobytes )<br class="">+write(stdout,*) 'memory4', kilobytes<br class="">+FLUSH(stdout)<br class="">+call stop_clock('direct_w_exc')<br class="">+<br class="">+return<br class="">+end subroutine contract_w_build<br class="">+<br class="">+<br class="">+<br class="">+subroutine contract_w_apply(a_in,fc,a_out)<br class="">+! this subroutine computes the w part of the direct term of the exc Hamiltonian<br class="">+ <br class="">+USE fft_custom_gwl<br class="">+use bse_basic_structures<br class="">+use exciton<br class="">+USE gvect<br class="">+use bse_wannier, ONLY: l_truncated_coulomb, &<br class="">+           truncation_radius,l_gtrick<br class="">+USE constants,        ONLY : e2, fpi<br class="">+USE cell_base,        ONLY : tpiba,omega,tpiba2<br class="">+!USE io_files,             ONLY : find_free_unit, prefix, diropn<br class="">+USE io_files,             ONLY :  prefix, diropn<br class="">+USE wavefunctions_module, ONLY :  psic<br class="">+USE io_global, ONLY : stdout, ionode, ionode_id<br class="">+USE mp_world, ONLY : mpime, nproc<br class="">+USE mp_pools, ONLY: intra_pool_comm<br class="">+USE mp_wave, ONLY : mergewf,splitwf<br class="">+USE polarization<br class="">+USE lsda_mod, ONLY :nspin<br class="">+USE io_global, ONLY : stdout,ionode<br class="">+USE mp,          ONLY :mp_barrier<br class="">+USE mp_world,             ONLY : world_comm<br class="">+<br class="">+<br class="">+<br class="">+<br class="">+<br class="">+implicit none<br class="">+INTEGER, EXTERNAL :: find_free_unit<br class="">+<br class="">+type(polaw) :: pw<br class="">+type(exc):: a_in<br class="">+type(exc):: a_out<br class="">+type(exc_r):: a_in_rt<br class="">+type(exc_r):: a_tmp_rt<br class="">+type(fft_cus) :: fc<br class="">+<br class="">+<br class="">+<br class="">+<br class="">+<br class="">+INTEGER ::iungprod<br class="">+INTEGER :: ig,ii,iv,ispin<br class="">+REAL(kind=DP) :: qq<br class="">+LOGICAL       :: exst<br class="">+<br class="">+<br class="">+INTEGER ::k<br class="">+<br class="">+<br class="">+logical debug<br class="">+<br class="">+call start_clock('direct_w_contract')<br class="">+<br class="">+debug=.false.<br class="">+! read  iimat<br class="">+<br class="">+!FFT the input excitonic vector to real space (dual grid)<br class="">+call initialize_exc_r(a_in_rt)<br class="">+call fft_a_exc(a_in,fc,a_in_rt)<br class="">+<br class="">+call mp_barrier(world_comm)<br class="">+<br class="">+! allocate tmp matrix<br class="">+call initialize_exc_r(a_tmp_rt)<br class="">+a_tmp_rt%nrxxt=fc%nrxxt <br class="">+a_tmp_rt%numb_v=a_in%numb_v<br class="">+a_tmp_rt%label=12<br class="">+allocate(a_tmp_rt%ar(a_tmp_rt%nrxxt,a_tmp_rt%numb_v))<br class="">+<br class="">+!compute line by line the output excitonic vector<br class="">+<br class="">+!!!!!!!!!!!!!!!!!dgemm subroutine!!!!!!!!!!!!!!!!!!!!!<br class="">+call start_clock('contract_w_dgemv')<br class="">+<br class="">+<br class="">+!<br class="">+a_tmp_rt%ar(1:a_tmp_rt%nrxxt,1:a_tmp_rt%numb_v) =0.d0<br class="">+!<br class="">+do iv=1, a_in%numb_v<br class="">+<br class="">+   if(.not.l_gtrick) then<br class="">+      do ii=1,vpmax_ii(iv)<br class="">+         a_tmp_rt%ar(1:fc%nrxxt,iv)= &<br class="">+              &a_tmp_rt%ar(1:fc%nrxxt,iv)+a_in_rt%ar(1:fc%nrxxt,iimat_contract%iimat(ii,iv))*&<br class="">+              &dble(vphipizeta_save(1:fc%nrxxt,vpmax_ii_start(iv)-1+ii))<br class="">+      enddo<br class="">+   else<br class="">+      do ii=1,vpmax_ii(iv),2<br class="">+         psic(1:fc%nrxxt)=(0.d0,0.d0)<br class="">+         if (ii==vpmax_ii(iv)) then<br class="">+            psic(fc%nlt(1:fc%npwt))  = dcmplx(vphipizeta_save_g(1:fc%npwt,vpmax_ii_start(iv)-1+ii))<br class="">+            psic(fc%nltm(1:fc%npwt)) = dcmplx(CONJG( vphipizeta_save_g(1:fc%npwt,vpmax_ii_start(iv)-1+ii) ))<br class="">+         else<br class="">+            psic(fc%nlt(1:fc%npwt))= dcmplx(vphipizeta_save_g(1:fc%npwt,vpmax_ii_start(iv)-1+ii))+&<br class="">+                 &(0.0,1.0)* dcmplx(vphipizeta_save_g(1:fc%npwt,vpmax_ii_start(iv)-1+ii+1))<br class="">+            psic(fc%nltm(1:fc%npwt))=DCMPLX(CONJG( vphipizeta_save_g(1:fc%npwt,vpmax_ii_start(iv)-1+ii))+&<br class="">+                 &(0.0,1.0)*CONJG( vphipizeta_save_g(1:fc%npwt,vpmax_ii_start(iv)-1+ii+1)))<br class="">+         endif<br class="">+         CALL cft3t( fc, psic, fc%nr1t, fc%nr2t, fc%nr3t, fc%nrx1t, fc%nrx2t, fc%nrx3t, 2 )<br class="">+         a_tmp_rt%ar(1:fc%nrxxt,iv)= &<br class="">+              &a_tmp_rt%ar(1:fc%nrxxt,iv)+a_in_rt%ar(1:fc%nrxxt,iimat_contract%iimat(ii,iv))*&<br class="">+              &dble(psic(1:fc%nrxxt))<br class="">+         if (ii/=vpmax_ii(iv)) then<br class="">+             a_tmp_rt%ar(1:fc%nrxxt,iv)= &<br class="">+                  &a_tmp_rt%ar(1:fc%nrxxt,iv)+a_in_rt%ar(1:fc%nrxxt,iimat_contract%iimat(ii+1,iv))*&<br class="">+                  &dimag(psic(1:fc%nrxxt))<br class="">+<br class="">+         endif<br class="">+      enddo<br class="">+   endif<br class="">+<br class="">+<br class="">+<br class="">+enddo<br class="">+call stop_clock('contract_w_dgemv')<br class="">+<br class="">+<br class="">+<br class="">+<br class="">+call free_memory_exc_a_r(a_in_rt)<br class="">+<br class="">+<br class="">+<br class="">+call start_clock('wdirect_fftback')<br class="">+!FFT back to provide the output excitonic wave vector in G-space<br class="">+call fftback_a_exc(a_tmp_rt,fc,a_out)<br class="">+call stop_clock('wdirect_fftback')<br class="">+<br class="">+call free_memory_exc_a_r(a_tmp_rt)<br class="">+<br class="">+FLUSH( stdout )<br class="">+call stop_clock('direct_w_contract')<br class="">+<br class="">+return<br class="">+end subroutine contract_w_apply<br class="">+<br class="">+<br class="">+subroutine contract_v_build(fc)<br class="">+!TO BE CALLED AFTER CONTRACT_W_BUILD  <br class="">+!IMPORTANT: REQUIRES IIMAT_CONTRACT<br class="">+! computes the v part of the direct term of the exc Hamiltonian <br class="">+USE fft_custom_gwl<br class="">+use bse_basic_structures<br class="">+use exciton<br class="">+USE wavefunctions_module, ONLY :  psic<br class="">+USE gvect,                 ONLY : ig_l2g<br class="">+USE io_global, ONLY : stdout, ionode, ionode_id<br class="">+USE mp_world, ONLY : mpime, nproc<br class="">+USE mp_pools, ONLY: intra_pool_comm<br class="">+USE mp_wave, ONLY : mergewf,splitwf<br class="">+USE io_global, ONLY : stdout,ionode<br class="">+USE lsda_mod, ONLY :nspin<br class="">+USE gvect, ONLY : gstart<br class="">+USE mp, ONLY : mp_sum<br class="">+USE mp_world,             ONLY : world_comm<br class="">+USE wvfct,                 ONLY :  npw<br class="">+USE bse_wannier, ONLY : l_gtrick<br class="">+<br class="">+implicit none<br class="">+<br class="">+<br class="">+type(vww_prod) :: vww<br class="">+type(fft_cus) :: fc<br class="">+<br class="">+<br class="">+COMPLEX(kind=DP), allocatable :: vwwg_t(:,:)<br class="">+COMPLEX(kind=DP), ALLOCATABLE :: evc_g(:)<br class="">+<br class="">+<br class="">+!real(kind=dp), allocatable :: phivwwr(:,:)<br class="">+COMPLEX(kind=DP) :: csca<br class="">+<br class="">+integer ii, iv,ispin, iimax<br class="">+<br class="">+logical debug<br class="">+<br class="">+write(stdout,*) 'Routine contract_v_build'<br class="">+<br class="">+debug=.false.<br class="">+<br class="">+!if(debug) then <br class="">+!   if(ionode) write(stdout,*) 'Direct_v_exc #1'<br class="">+!endif<br class="">+write(stdout,*) 'VWW_SAVE :', fc%nrxxt,vpmax_tot<br class="">+if(.not.l_gtrick) then<br class="">+   allocate(vww_save(fc%nrxxt,vpmax_tot))<br class="">+else<br class="">+   allocate(vww_save_g(fc%npwt,vpmax_tot))<br class="">+endif<br class="">+<br class="">+<br class="">+call initialize_vww_prod(vww)<br class="">+call read_vww_prod(1,iimat_contract%numb_v,npw,iimat_contract%np_max,iimat_contract,vww)<br class="">+<br class="">+!if(debug) then <br class="">+!   if(ionode) write(stdout,*) 'Direct_v_exc #6'<br class="">+!endif<br class="">+<br class="">+! for every element iv of the excitonic wavefunction vector, here we FFT all<br class="">+! the available v*w_iv*w_ivp(G) products, multiply by a_in_rt%ar(:,ivp)<br class="">+! sum over ivp, and FFT back<br class="">+<br class="">+allocate(vwwg_t(fc%npwt,iimat_contract%np_max))<br class="">+!allocate(phivwwr(fc%nrxxt,a_in%numb_v))<br class="">+allocate(evc_g(fc%ngmt_g ))<br class="">+<br class="">+<br class="">+write(stdout,*) 'ATT1'<br class="">+do iv=1,iimat_contract%numb_v<br class="">+    <br class="">+   vwwg_t(1:fc%npwt,1:iimat_contract%np_max)=dcmplx(0.d0,0.d0)<br class="">+   iimax=0<br class="">+   do ii=1,iimat_contract%np_max<br class="">+      if (iimat_contract%iimat(ii,iv)>0) then<br class="">+         iimax=iimax+1<br class="">+      else<br class="">+         exit<br class="">+      endif<br class="">+   enddo<br class="">+   if(iimax>0) then<br class="">+      call reorderwfp_col(iimax,vww%npw,fc%npwt,vww%vww(1,1,iv),vwwg_t, vww%npw,fc%npwt, &<br class="">+           & ig_l2g,fc%ig_l2gt,fc%ngmt_g,mpime, nproc,intra_pool_comm )<br class="">+   endif<br class="">+   <br class="">+   if(.not.l_gtrick) then<br class="">+      do ii=1,vpmax_ii(iv),2<br class="">+        <br class="">+      <br class="">+         psic(1:fc%nrxxt)=(0.d0,0.d0)<br class="">+         if (ii==vpmax_ii(iv)) then<br class="">+            psic(fc%nlt(1:fc%npwt))  = vwwg_t(1:fc%npwt,ii)<br class="">+            psic(fc%nltm(1:fc%npwt)) = CONJG( vwwg_t(1:fc%npwt,ii) )<br class="">+         else      <br class="">+            psic(fc%nlt(1:fc%npwt))=vwwg_t(1:fc%npwt,ii)+(0.d0,1.d0)*vwwg_t(1:fc%npwt,ii+1)<br class="">+            psic(fc%nltm(1:fc%npwt))=CONJG(vwwg_t(1:fc%npwt,ii))+(0.d0,1.d0)*CONJG(vwwg_t(1:fc%npwt,ii+1))<br class="">+         endif<br class="">+         CALL cft3t( fc, psic, fc%nr1t, fc%nr2t, fc%nr3t, fc%nrx1t, fc%nrx2t, fc%nrx3t, 2 )<br class="">+         vww_save(1:fc%nrxxt,vpmax_ii_start(iv)+ii-1)=real(psic(1:fc%nrxxt))<br class="">+         if (ii/=vpmax_ii(iv)) then<br class="">+            vww_save(1:fc%nrxxt,vpmax_ii_start(iv)+ii)=aimag(psic(1:fc%nrxxt))<br class="">+         endif<br class="">+<br class="">+      enddo<br class="">+   else<br class="">+      do ii=1,vpmax_ii(iv)<br class="">+         vww_save_g(1:fc%npwt,vpmax_ii_start(iv)+ii-1)=cmplx(vwwg_t(1:fc%npwt,ii))<br class="">+      end do<br class="">+   endif<br class="">+enddo<br class="">+<br class="">+!if(debug) then <br class="">+!   if(ionode) write(stdout,*) 'Direct_v_exc #7'<br class="">+!endif<br class="">+<br class="">+FLUSH( stdout )<br class="">+<br class="">+<br class="">+call free_vww_prod(vww)<br class="">+deallocate(vwwg_t)<br class="">+!deallocate(vwwr_t)<br class="">+deallocate(evc_g)<br class="">+<br class="">+<br class="">+end subroutine<br class="">+<br class="">+<br class="">+subroutine contract_v_apply(a_in,fc,a_out)<br class="">+! computes the v part of the direct term of the exc Hamiltonian<br class="">+USE fft_custom_gwl<br class="">+use bse_basic_structures<br class="">+use exciton<br class="">+USE wavefunctions_module, ONLY :  psic<br class="">+USE gvect,                 ONLY : ig_l2g<br class="">+USE io_global, ONLY : stdout, ionode, ionode_id<br class="">+USE mp_world, ONLY : mpime, nproc<br class="">+USE mp_pools, ONLY: intra_pool_comm<br class="">+USE mp_wave, ONLY : mergewf,splitwf<br class="">+USE io_global, ONLY : stdout,ionode<br class="">+USE lsda_mod, ONLY :nspin<br class="">+USE gvect, ONLY : gstart<br class="">+USE mp, ONLY : mp_sum<br class="">+USE mp_world,             ONLY : world_comm<br class="">+USE bse_wannier, ONLY : l_gtrick<br class="">+<br class="">+<br class="">+implicit none<br class="">+type(exc), intent(in) :: a_in<br class="">+type(exc):: a_out<br class="">+type(exc_r):: a_in_rt<br class="">+type(exc_r):: a_tmp_rt<br class="">+<br class="">+<br class="">+type(fft_cus) :: fc<br class="">+<br class="">+<br class="">+COMPLEX(kind=DP), allocatable :: vwwg_t(:,:)<br class="">+COMPLEX(kind=DP), ALLOCATABLE :: evc_g(:)<br class="">+<br class="">+COMPLEX(kind=DP) :: csca<br class="">+<br class="">+integer ii, iv,ispin, iimax<br class="">+<br class="">+logical debug<br class="">+<br class="">+call start_clock('direct_v_contract')<br class="">+debug=.false.<br class="">+<br class="">+call initialize_exc_r(a_tmp_rt)<br class="">+a_tmp_rt%nrxxt=fc%nrxxt<br class="">+a_tmp_rt%numb_v=a_in%numb_v<br class="">+a_tmp_rt%label=12<br class="">+allocate(a_tmp_rt%ar(a_tmp_rt%nrxxt,a_tmp_rt%numb_v))<br class="">+<br class="">+<br class="">+! FFT a_in to real space (dual grid)<br class="">+call initialize_exc_r(a_in_rt)<br class="">+call fft_a_exc(a_in,fc,a_in_rt)<br class="">+<br class="">+<br class="">+<br class="">+<br class="">+<br class="">+a_tmp_rt%ar(1:a_tmp_rt%nrxxt,1:a_tmp_rt%numb_v) =0.d0<br class="">+do iv=1,a_in%numb_v<br class="">+  <br class="">+<br class="">+   if(.not.l_gtrick) then<br class="">+      do ii=1,vpmax_ii(iv)<br class="">+         a_tmp_rt%ar(1:fc%nrxxt,iv)= &<br class="">+              &a_tmp_rt%ar(1:fc%nrxxt,iv)+DBLE(vww_save(1:fc%nrxxt,vpmax_ii_start(iv)+ii-1))*&<br class="">+              &a_in_rt%ar(1:a_in_rt%nrxxt,iimat_contract%iimat(ii,iv))<br class="">+      enddo<br class="">+   else<br class="">+      do ii=1,vpmax_ii(iv),2<br class="">+         psic(1:fc%nrxxt)=(0.d0,0.d0)<br class="">+         if (ii==vpmax_ii(iv)) then<br class="">+            psic(fc%nlt(1:fc%npwt))  = dcmplx(vww_save_g(1:fc%npwt,vpmax_ii_start(iv)+ii-1))<br class="">+            psic(fc%nltm(1:fc%npwt)) = dcmplx(CONJG(  vww_save_g(1:fc%npwt,vpmax_ii_start(iv)+ii-1) ))<br class="">+         else<br class="">+            psic(fc%nlt(1:fc%npwt))=dcmplx(vww_save_g(1:fc%npwt,vpmax_ii_start(iv)+ii-1)+&<br class="">+                 &(0.0,1.0)*vww_save_g(1:fc%npwt,vpmax_ii_start(iv)+ii-1+1))<br class="">+            psic(fc%nltm(1:fc%npwt))=dcmplx(CONJG(vww_save_g(1:fc%npwt,vpmax_ii_start(iv)+ii-1))&<br class="">+                 &+(0.0,1.0)*CONJG(vww_save_g(1:fc%npwt,vpmax_ii_start(iv)+ii-1+1)))<br class="">+         endif<br class="">+         call start_clock('d_v_fft')<br class="">+         CALL cft3t( fc, psic, fc%nr1t, fc%nr2t, fc%nr3t, fc%nrx1t, fc%nrx2t, fc%nrx3t, 2 )<br class="">+         call stop_clock('d_v_fft')<br class="">+         a_tmp_rt%ar(1:fc%nrxxt,iv)= &<br class="">+              &a_tmp_rt%ar(1:fc%nrxxt,iv)+DBLE(psic(1:fc%nrxxt))*&<br class="">+              &a_in_rt%ar(1:a_in_rt%nrxxt,iimat_contract%iimat(ii,iv))<br class="">+         if (ii/=vpmax_ii(iv)) then<br class="">+            a_tmp_rt%ar(1:fc%nrxxt,iv)= &<br class="">+                 &a_tmp_rt%ar(1:fc%nrxxt,iv)+DIMAG(psic(1:fc%nrxxt))*&<br class="">+                 &a_in_rt%ar(1:a_in_rt%nrxxt,iimat_contract%iimat(ii+1,iv))<br class="">+         endif<br class="">+      enddo<br class="">+   endif<br class="">+enddo<br class="">+<br class="">+<br class="">+<br class="">+call free_memory_exc_a_r(a_in_rt)<br class="">+<br class="">+call fftback_a_exc(a_tmp_rt,fc,a_out)<br class="">+<br class="">+! free memory                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              <br class="">+call free_memory_exc_a_r(a_tmp_rt)<br class="">+<br class="">+<br class="">+<br class="">+call stop_clock('direct_v_contract')<br class="">+end subroutine<br class="">+<br class="">+<br class="">+<br class="">+<br class="">+<br class="">+<br class="">+<br class="">+END MODULE contract_w<br class=""><br class="">Added: trunk/espresso/GWW/bse/diago_exc.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/diago_exc.f90<span class="Apple-tab-span" style="white-space:pre"> </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/diago_exc.f90<span class="Apple-tab-span" style="white-space:pre">    </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,166 @@<br class="">+subroutine diago_exc(a,v,cstate,wcstate)<br class="">+! this subroutine applies the diagonal part of the excitonic Hamiltonian to the excitonic<br class="">+! wavefunction vector (a%a)<br class="">+<br class="">+USE kinds,            ONLY : DP<br class="">+USE exciton<br class="">+use bse_basic_structures<br class="">+USE wvfct,            ONLY : igk,g2kin,npwx<br class="">+USE noncollin_module, ONLY : npol<br class="">+USE uspp,             ONLY : vkb,nkb<br class="">+USE becmod,           ONLY : becp,allocate_bec_type,deallocate_bec_type<br class="">+USE g_psi_mod,        ONLY : h_diag, s_diag<br class="">+USE klist,            ONLY : xk<br class="">+USE gvect<br class="">+USE cell_base,        ONLY: tpiba,tpiba2<br class="">+USE constants,        ONLY: RYTOEV <br class="">+use io_global,        ONLY : stdout, ionode <br class="">+use bse_wannier,      ONLY : scissor,l_scissor,qpe_imin,qpe_imax<br class="">+use qpe_exc<br class="">+<br class="">+<br class="">+implicit none<br class="">+<br class="">+type(exc) :: a<br class="">+type(v_state) :: v<br class="">+type(c_state) :: cstate<br class="">+type(c_state) :: wcstate<br class="">+<br class="">+<br class="">+type(exc) :: a1,a2<br class="">+COMPLEX(kind=DP), ALLOCATABLE :: psi_1(:,:)<br class="">+COMPLEX(kind=DP), ALLOCATABLE :: u_0(:,:)<br class="">+<br class="">+<br class="">+<br class="">+logical :: debug<br class="">+real(kind=dp) :: prod<br class="">+real(kind=dp), allocatable :: vb_en(:)<br class="">+integer :: is<br class="">+<br class="">+call start_clock('diago_exc')<br class="">+debug=.false.<br class="">+<br class="">+allocate(psi_1(a%npw,a%numb_v))<br class="">+allocate(u_0(a%npw,a%numb_v))<br class="">+<br class="">+ALLOCATE( h_diag( npwx,npol ) )<br class="">+ALLOCATE( s_diag( npwx,npol ) )<br class="">+<br class="">+ALLOCATE(vb_en(a%numb_v))<br class="">+<br class="">+!just copy a in a temporary variable to apply the different part of the diago<br class="">+!Hamiltonian <br class="">+<br class="">+call initialize_exc(a1)<br class="">+call initialize_exc(a2)<br class="">+<br class="">+allocate(a1%a(a%npw,a%numb_v))<br class="">+<br class="">+a1%npw=a%npw<br class="">+a1%numb_v=a%numb_v<br class="">+a1%label=20<br class="">+<br class="">+allocate(a2%a(a%npw,a%numb_v))<br class="">+<br class="">+a2%npw=a%npw<br class="">+a2%numb_v=a%numb_v<br class="">+a2%label=30<br class="">+<br class="">+a2%a(1:a2%npw,1:a2%numb_v)=a%a(1:a%npw,1:a%numb_v)<br class="">+<br class="">+call allocate_bec_type ( nkb, a%numb_v, becp)<br class="">+<br class="">+IF ( nkb > 0 )  CALL init_us_2( a%npw, igk, xk(1,1), vkb )<br class="">+g2kin(1:a%npw) = ( (g(1,igk(1:a%npw)) )**2 + &<br class="">+       ( g(2,igk(1:a%npw)) )**2 + &<br class="">+       ( g(3,igk(1:a%npw)) )**2 ) * tpiba2<br class="">+<br class="">+<br class="">+psi_1(1:a%npw,1:a%numb_v)=a%a(1:a%npw,1:a%numb_v)<br class="">+<br class="">+    <br class="">+!calculate H|\phi_i><br class="">+call h_psi( a%npw, a%npw, a%numb_v,psi_1(1,1), u_0 )<br class="">+a1%a(1:a%npw,1:a%numb_v)=u_0(1:a%npw,1:a%numb_v)<br class="">+<br class="">+<br class="">+!project into the conduction manifold<br class="">+do is = 1,v%nspin<br class="">+  call pc_operator_exc(a1,v,is)<br class="">+enddo<br class="">+<br class="">+!check if everything is ok, the 'scalar' product of a1%a with a%a should be<br class="">+!greater than e_lumo<br class="">+<br class="">+if (debug) then<br class="">+  call sproduct_exc(a,a1,prod)<br class="">+  prod=prod*RYTOEV<br class="">+  if(ionode) write(stdout,*) 'exc_diago, prod (eV)=',prod<br class="">+  if(ionode) write(stdout,*) 'prod should be greater than LUMO level'<br class="">+  CALL flush_unit( stdout )<br class="">+end if<br class="">+<br class="">+if(.not.l_scissor) then<br class="">+   if (qpe_imax>a%numb_v) then<br class="">+      do is=1,a%numb_v<br class="">+         vb_en(is)= qpcbarc<br class="">+      enddo<br class="">+      call c_times_exc(a2,vb_en)<br class="">+      a1%a(1:a%npw,1:a%numb_v)=a1%a(1:a%npw,1:a%numb_v)+a2%a(1:a%npw,1:a%numb_v)<br class="">+      a2%a(1:a2%npw,1:a2%numb_v)=a%a(1:a%npw,1:a%numb_v) <br class="">+      call poutcstate_exc(a2,a2,cstate,wcstate)<br class="">+      a1%a(1:a%npw,1:a%numb_v)=a1%a(1:a%npw,1:a%numb_v)+a2%a(1:a%npw,1:a%numb_v)<br class="">+   else <br class="">+      do is=1,a%numb_v<br class="">+         vb_en(is)= qpcbarc<br class="">+      enddo<br class="">+      call c_times_exc(a2,vb_en)<br class="">+      a1%a(1:a%npw,1:a%numb_v)=a1%a(1:a%npw,1:a%numb_v)+a2%a(1:a%npw,1:a%numb_v)<br class="">+   endif<br class="">+endif<br class="">+<br class="">+<br class="">+<br class="">+!multiply each line of the excitonic wavefunction vector with the corresponding<br class="">+!single particle valence state energy<br class="">+<br class="">+if(l_scissor) then<br class="">+   do is=1,a%numb_v<br class="">+      vb_en(is)= v%esp(is,1)-scissor <br class="">+   enddo<br class="">+<br class="">+   call c_times_exc(a,vb_en)<br class="">+   if (debug) then<br class="">+     do is=1,a%numb_v<br class="">+        prod=vb_en(is)*RYTOEV<br class="">+        if(ionode) write(stdout,*) 'exc_diago, band i  (eV)=',prod<br class="">+     enddo<br class="">+   end if<br class="">+else !not scissor<br class="">+   do is=1,a%numb_v<br class="">+      vb_en(is)= v%esp(is,1)+qpc(is)<br class="">+   enddo<br class="">+   call c_times_exc(a,vb_en)<br class="">+endif<br class="">+<br class="">+<br class="">+! sum-up the two terms<br class="">+a%a(1:a%npw,1:a%numb_v)=-a%a(1:a%npw,1:a%numb_v)+a1%a(1:a%npw,1:a%numb_v)<br class="">+<br class="">+deallocate(psi_1)<br class="">+deallocate(u_0)<br class="">+<br class="">+deallocate(h_diag)<br class="">+deallocate(s_diag)<br class="">+<br class="">+deallocate(vb_en)<br class="">+<br class="">+call deallocate_bec_type(becp)<br class="">+call free_memory_exc_a(a1)<br class="">+call free_memory_exc_a(a2)<br class="">+<br class="">+call stop_clock('diago_exc')<br class="">+return<br class="">+end subroutine<br class="">+<br class=""><br class="">Added: trunk/espresso/GWW/bse/direct_v_exc.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/direct_v_exc.f90<span class="Apple-tab-span" style="white-space:pre">       </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/direct_v_exc.f90<span class="Apple-tab-span" style="white-space:pre"> </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,173 @@<br class="">+subroutine direct_v_exc(a_in,fc,a_out)<br class="">+! computes the v part of the direct term of the exc Hamiltonian <br class="">+USE fft_custom_gwl<br class="">+use bse_basic_structures<br class="">+use exciton<br class="">+USE wavefunctions_module, ONLY :  psic<br class="">+USE gvect,                 ONLY : ig_l2g<br class="">+USE io_global, ONLY : stdout, ionode, ionode_id<br class="">+USE mp_world, ONLY : mpime, nproc<br class="">+USE mp_pools, ONLY: intra_pool_comm<br class="">+USE mp_wave, ONLY : mergewf,splitwf<br class="">+USE io_global, ONLY : stdout,ionode<br class="">+USE lsda_mod, ONLY :nspin<br class="">+USE gvect, ONLY : gstart<br class="">+USE mp, ONLY : mp_sum<br class="">+USE mp_world,             ONLY : world_comm<br class="">+<br class="">+<br class="">+<br class="">+implicit none<br class="">+type(exc), intent(in) :: a_in<br class="">+type(exc):: a_out<br class="">+type(exc_r):: a_in_rt<br class="">+type(exc_r):: a_tmp_rt<br class="">+type(ii_mat) :: iimat<br class="">+type(vww_prod) :: vww<br class="">+type(fft_cus) :: fc<br class="">+<br class="">+<br class="">+COMPLEX(kind=DP), allocatable :: vwwg_t(:,:)<br class="">+COMPLEX(kind=DP), ALLOCATABLE :: evc_g(:)<br class="">+<br class="">+<br class="">+!real(kind=dp), allocatable :: phivwwr(:,:)<br class="">+COMPLEX(kind=DP) :: csca<br class="">+<br class="">+integer ii, iv,ispin, iimax<br class="">+<br class="">+logical debug<br class="">+<br class="">+call start_clock('direct_v_exc')<br class="">+debug=.false.<br class="">+<br class="">+!if(debug) then <br class="">+!   if(ionode) write(stdout,*) 'Direct_v_exc #1'<br class="">+!endif<br class="">+<br class="">+<br class="">+! allocate tmp matrix<br class="">+call initialize_exc_r(a_tmp_rt)<br class="">+a_tmp_rt%nrxxt=fc%nrxxt <br class="">+a_tmp_rt%numb_v=a_in%numb_v<br class="">+a_tmp_rt%label=12<br class="">+allocate(a_tmp_rt%ar(a_tmp_rt%nrxxt,a_tmp_rt%numb_v))<br class="">+<br class="">+<br class="">+! FFT a_in to real space (dual grid)<br class="">+call initialize_exc_r(a_in_rt)<br class="">+call fft_a_exc(a_in,fc,a_in_rt)<br class="">+<br class="">+<br class="">+! read iimat, that tells us for every w_iv which other valence band ivp is<br class="">+! overlapping, and read the corresponding v*w_iv*w_ivp(G) products<br class="">+<br class="">+call initialize_imat(iimat)<br class="">+<br class="">+do ispin=1,nspin<br class="">+! note that for spin-polarized case, probably this do-loop will have to include<br class="">+! also the rest of the subroutine, or something like that<br class="">+   call read_iimat(iimat,ispin)   <br class="">+enddo<br class="">+<br class="">+<br class="">+if(debug) then <br class="">+   if(ionode) write(stdout,*) 'Direct_v_exc #5'<br class="">+   if(ionode) write(stdout,*) 'a_in%numb_v=',a_in%numb_v<br class="">+   if(ionode) write(stdout,*) 'a_in%npw=',a_in%npw<br class="">+   if(ionode) write(stdout,*) 'iimat%np_max=',iimat%np_max<br class="">+endif<br class="">+<br class="">+call initialize_vww_prod(vww)<br class="">+call read_vww_prod(1,a_in%numb_v,a_in%npw,iimat%np_max,iimat,vww)<br class="">+<br class="">+!if(debug) then <br class="">+!   if(ionode) write(stdout,*) 'Direct_v_exc #6'<br class="">+!endif<br class="">+<br class="">+! for every element iv of the excitonic wavefunction vector, here we FFT all<br class="">+! the available v*w_iv*w_ivp(G) products, multiply by a_in_rt%ar(:,ivp)<br class="">+! sum over ivp, and FFT back<br class="">+<br class="">+allocate(vwwg_t(fc%npwt,iimat%np_max))<br class="">+!allocate(phivwwr(fc%nrxxt,a_in%numb_v))<br class="">+allocate(evc_g(fc%ngmt_g ))<br class="">+<br class="">+<br class="">+<br class="">+a_tmp_rt%ar(1:a_tmp_rt%nrxxt,1:a_tmp_rt%numb_v) =0.d0<br class="">+do iv=1,a_in%numb_v<br class="">+    <br class="">+   vwwg_t(1:fc%npwt,1:iimat%np_max)=dcmplx(0.d0,0.d0)<br class="">+   iimax=0<br class="">+   do ii=1,iimat%np_max<br class="">+      if (iimat%iimat(ii,iv)>0) then<br class="">+         iimax=iimax+1<br class="">+      else<br class="">+         exit<br class="">+      endif<br class="">+   enddo<br class="">+   if(iimax>0) then<br class="">+      call reorderwfp_col(iimax,vww%npw,fc%npwt,vww%vww(1,1,iv),vwwg_t, vww%npw,fc%npwt, &<br class="">+           & ig_l2g,fc%ig_l2gt,fc%ngmt_g,mpime, nproc,intra_pool_comm )<br class="">+   endif<br class="">+!!!!!!!!!!!!!!!!<br class="">+!   do ii=1,iimat%np_max<br class="">+!      if (iimat%iimat(ii,iv)==0) exit<br class="">+!      if(fc%dual_t==4.d0) then<br class="">+!         vwwg_t(1:fc%npwt,ii)= vww%vww(1:fc%npwt,ii,iv)<br class="">+!      else<br class="">+!        call reorderwfp_col(1,vww%npw,fc%npwt,vww%vww(1,ii,iv),vwwg_t(1,ii), vww%npw,fc%npwt, &<br class="">+!           & ig_l2g,fc%ig_l2gt,fc%ngmt_g,mpime, nproc,intra_pool_comm )<br class="">+!<br class="">+!      endif<br class="">+!<br class="">+!      <br class="">+!   enddo<br class="">+<br class="">+   <br class="">+   do ii=1,iimat%np_max,2<br class="">+      if(debug) then<br class="">+         if(ionode) write(stdout,*) 'ii,iv,iimat', ii,iv,iimat%iimat(ii,iv)<br class="">+      endif <br class="">+      if (iimat%iimat(ii,iv)==0) exit<br class="">+      psic(:)=(0.d0,0.d0)<br class="">+      if ((ii==iimat%np_max).or.(iimat%iimat(ii+1,iv)==0)) then<br class="">+          psic(fc%nlt(1:fc%npwt))  = vwwg_t(1:fc%npwt,ii)<br class="">+          psic(fc%nltm(1:fc%npwt)) = CONJG( vwwg_t(1:fc%npwt,ii) )<br class="">+      else      <br class="">+          psic(fc%nlt(1:fc%npwt))=vwwg_t(1:fc%npwt,ii)+(0.d0,1.d0)*vwwg_t(1:fc%npwt,ii+1)<br class="">+          psic(fc%nltm(1:fc%npwt))=CONJG(vwwg_t(1:fc%npwt,ii))+(0.d0,1.d0)*CONJG(vwwg_t(1:fc%npwt,ii+1))<br class="">+      endif<br class="">+      CALL cft3t( fc, psic, fc%nr1t, fc%nr2t, fc%nr3t, fc%nrx1t, fc%nrx2t, fc%nrx3t, 2 )<br class="">+      a_tmp_rt%ar(1:fc%nrxxt,iv)= &<br class="">+            &a_tmp_rt%ar(1:fc%nrxxt,iv)+DBLE(psic(1:fc%nrxxt))*a_in_rt%ar(1:a_in_rt%nrxxt,iimat%iimat(ii,iv))<br class="">+      if ((ii/=iimat%np_max).and.(iimat%iimat(ii+1,iv)/=0)) then<br class="">+         a_tmp_rt%ar(1:fc%nrxxt,iv)=&<br class="">+         &a_tmp_rt%ar(1:fc%nrxxt,iv)+DIMAG(psic(1:fc%nrxxt))*a_in_rt%ar(1:a_in_rt%nrxxt,iimat%iimat(ii+1,iv))<br class="">+      endif<br class="">+   enddo<br class="">+enddo<br class="">+<br class="">+!if(debug) then <br class="">+!   if(ionode) write(stdout,*) 'Direct_v_exc #7'<br class="">+!endif<br class="">+<br class="">+<br class="">+call free_memory_exc_a_r(a_in_rt)<br class="">+<br class="">+call fftback_a_exc(a_tmp_rt,fc,a_out)<br class="">+<br class="">+! free memory<br class="">+call free_memory_exc_a_r(a_tmp_rt)<br class="">+call free_imat(iimat)<br class="">+call free_vww_prod(vww)<br class="">+deallocate(vwwg_t)<br class="">+!deallocate(vwwr_t)<br class="">+deallocate(evc_g)<br class="">+<br class="">+<br class="">+call stop_clock('direct_v_exc')<br class="">+end subroutine<br class="">+<br class="">+<br class=""><br class="">Added: trunk/espresso/GWW/bse/direct_w_exc.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/direct_w_exc.f90<span class="Apple-tab-span" style="white-space:pre">  </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/direct_w_exc.f90<span class="Apple-tab-span" style="white-space:pre"> </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,273 @@<br class="">+subroutine direct_w_exc(a_in,fc,a_out)<br class="">+! this subroutine computes the w part of the direct term of the exc Hamiltonian<br class="">+ <br class="">+USE fft_custom_gwl<br class="">+use bse_basic_structures<br class="">+use exciton<br class="">+USE gvect<br class="">+use bse_wannier, ONLY: l_truncated_coulomb, &<br class="">+           truncation_radius<br class="">+USE constants,        ONLY : e2, fpi<br class="">+USE cell_base,        ONLY : tpiba,omega,tpiba2<br class="">+!USE io_files,             ONLY : find_free_unit, prefix, diropn<br class="">+USE io_files,             ONLY :  prefix, diropn<br class="">+USE wavefunctions_module, ONLY :  psic<br class="">+USE io_global, ONLY : stdout, ionode, ionode_id<br class="">+USE mp_world, ONLY : mpime, nproc<br class="">+USE mp_pools, ONLY: intra_pool_comm<br class="">+USE mp_wave, ONLY : mergewf,splitwf<br class="">+USE polarization<br class="">+USE lsda_mod, ONLY :nspin<br class="">+USE io_global, ONLY : stdout,ionode<br class="">+USE mp,          ONLY :mp_barrier<br class="">+USE mp_world,             ONLY : world_comm<br class="">+<br class="">+<br class="">+<br class="">+<br class="">+<br class="">+implicit none<br class="">+INTEGER, EXTERNAL :: find_free_unit<br class="">+type(bse_z) :: z<br class="">+type(polaw) :: pw<br class="">+type(exc):: a_in<br class="">+type(exc):: a_out<br class="">+type(exc_r):: a_in_rt<br class="">+type(exc_r):: a_tmp_rt<br class="">+type(fft_cus) :: fc<br class="">+type(ii_mat) :: iimat<br class="">+<br class="">+<br class="">+<br class="">+REAL(kind=DP), ALLOCATABLE :: fac(:)<br class="">+COMPLEX(kind=DP), ALLOCATABLE :: p_basis(:,:)<br class="">+COMPLEX(kind=DP), ALLOCATABLE :: p_basis_t(:,:)<br class="">+REAL(kind=DP), ALLOCATABLE :: p_basis_r(:,:)<br class="">+REAL(kind=DP), ALLOCATABLE :: zvphi(:)<br class="">+REAL(kind=dp), ALLOCATABLE :: zvv(:)<br class="">+COMPLEX(kind=DP), ALLOCATABLE :: evc_g(:)<br class="">+<br class="">+INTEGER ::iungprod<br class="">+INTEGER :: ig,ii,iv,ispin<br class="">+REAL(kind=DP) :: qq<br class="">+LOGICAL       :: exst<br class="">+<br class="">+<br class="">+INTEGER :: vpmax,k<br class="">+REAL(kind=DP), allocatable :: zp(:,:)<br class="">+REAL(kind=DP), allocatable :: pizeta(:,:)<br class="">+REAL(kind=DP), allocatable :: vphipizeta(:,:)<br class="">+<br class="">+logical debug<br class="">+<br class="">+call start_clock('direct_w_exc')<br class="">+<br class="">+debug=.false.<br class="">+<br class="">+<br class="">+<br class="">+! read  iimat<br class="">+call initialize_imat(iimat)<br class="">+<br class="">+do ispin=1,nspin<br class="">+   call read_iimat(iimat,ispin) <br class="">+enddo<br class="">+<br class="">+! read z terms<br class="">+call initialize_bse_z(z)<br class="">+call read_z(1,iimat,z)<br class="">+<br class="">+<br class="">+! get Coulomb potential<br class="">+allocate(fac(a_in%npw))<br class="">+if(l_truncated_coulomb) then<br class="">+   do ig=1,a_in%npw<br class="">+      qq = g(1,ig)**2.d0 + g(2,ig)**2.d0 + g(3,ig)**2.d0<br class="">+      if (qq > 1.d-8) then<br class="">+         fac(ig)=(e2*fpi/(tpiba2*qq))*(1.d0-dcos(dsqrt(qq)*truncation_radius*tpiba))<br class="">+      else<br class="">+         fac(ig)=e2*fpi*(truncation_radius**2.d0/2.d0)<br class="">+     endif<br class="">+   enddo<br class="">+    fac(:)=fac(:)/omega<br class="">+else<br class="">+   fac(:)=0.d0<br class="">+   fac(1:a_in%npw)=vg_q(1:a_in%npw)<br class="">+endif<br class="">+<br class="">+<br class="">+! read polarization basis and multiply per V<br class="">+<br class="">+iungprod = find_free_unit()<br class="">+allocate(p_basis(a_in%npw,z%numw_prod))<br class="">+CALL diropn( iungprod, 'wiwjwfc_red', a_in%npw*2, exst )<br class="">+<br class="">+do ii=1,z%numw_prod<br class="">+   call davcio(p_basis(:,ii),a_in%npw*2,iungprod,ii,-1)<br class="">+   p_basis(1:a_in%npw,ii)=p_basis(1:a_in%npw,ii)*dcmplx(fac(1:a_in%npw))<br class="">+enddo<br class="">+<br class="">+call mp_barrier(world_comm)<br class="">+<br class="">+close(iungprod)<br class="">+<br class="">+! FFT to real space (dual grid)<br class="">+allocate(p_basis_t(fc%npwt,z%numw_prod)) <br class="">+allocate(p_basis_r(fc%nrxxt,z%numw_prod))<br class="">+allocate(evc_g(fc%ngmt_g ))<br class="">+<br class="">+if(fc%dual_t==4.d0) then<br class="">+   p_basis_t(1:fc%npwt,1:z%numw_prod)=p_basis(1:a_in%npw,1:z%numw_prod)<br class="">+else<br class="">+    call reorderwfp_col(z%numw_prod,a_in%npw,fc%npwt,p_basis(1,1),p_basis_t(1,1),a_in%npw,fc%npwt, &<br class="">+           & ig_l2g,fc%ig_l2gt,fc%ngmt_g,mpime, nproc,intra_pool_comm )<br class="">+<br class="">+!   do ii=1,z%numw_prod<br class="">+!      call mergewf(p_basis(:,ii),evc_g,a_in%npw,ig_l2g,mpime,nproc,ionode_id,intra_pool_comm)<br class="">+!      call splitwf(p_basis_t(:,ii),evc_g,fc%npwt,fc%ig_l2gt,mpime,nproc,ionode_id,intra_pool_comm)<br class="">+!   enddo<br class="">+endif<br class="">+<br class="">+deallocate(evc_g)<br class="">+deallocate(p_basis)<br class="">+<br class="">+call start_clock('direct_w_cft3t')<br class="">+do ii=1,z%numw_prod,2<br class="">+   psic(1:fc%nrxxt)=(0.d0,0.d0)<br class="">+   if (ii==z%numw_prod) then<br class="">+      psic(fc%nlt(1:fc%npwt))  = p_basis_t(1:fc%npwt,ii)<br class="">+      psic(fc%nltm(1:fc%npwt)) = CONJG( p_basis_t(1:fc%npwt,ii) )<br class="">+   else<br class="">+      psic(fc%nlt(1:fc%npwt))=p_basis_t(1:fc%npwt,ii)+(0.d0,1.d0)*p_basis_t(1:fc%npwt,ii+1)<br class="">+      psic(fc%nltm(1:fc%npwt))=CONJG(p_basis_t(1:fc%npwt,ii))+(0.d0,1.d0)*CONJG(p_basis_t(1:fc%npwt,ii+1))<br class="">+   endif<br class="">+      CALL cft3t( fc, psic, fc%nr1t, fc%nr2t, fc%nr3t, fc%nrx1t, fc%nrx2t, fc%nrx3t, 2 )<br class="">+       p_basis_r(1:fc%nrxxt,ii)= DBLE(psic(1:fc%nrxxt))<br class="">+      if(ii/=z%numw_prod) p_basis_r(1:fc%nrxxt,ii+1)= DIMAG(psic(1:fc%nrxxt))<br class="">+enddo<br class="">+call stop_clock('direct_w_cft3t')<br class="">+<br class="">+deallocate(p_basis_t) <br class="">+<br class="">+!read P<br class="">+call initialize_polaw(pw)<br class="">+call read_polaw_global(0, pw)<br class="">+<br class="">+<br class="">+call mp_barrier(world_comm)<br class="">+<br class="">+!FFT the input excitonic vector to real space (dual grid)<br class="">+call initialize_exc_r(a_in_rt)<br class="">+call fft_a_exc(a_in,fc,a_in_rt)<br class="">+<br class="">+call mp_barrier(world_comm)<br class="">+<br class="">+! allocate tmp matrix<br class="">+call initialize_exc_r(a_tmp_rt)<br class="">+a_tmp_rt%nrxxt=fc%nrxxt <br class="">+a_tmp_rt%numb_v=a_in%numb_v<br class="">+a_tmp_rt%label=12<br class="">+allocate(a_tmp_rt%ar(a_tmp_rt%nrxxt,a_tmp_rt%numb_v))<br class="">+<br class="">+!compute line by line the output excitonic vector<br class="">+<br class="">+!!!!!!!!!!!!!!!!!dgemm subroutine!!!!!!!!!!!!!!!!!!!!!<br class="">+call start_clock('direct_w_dgemv')<br class="">+allocate(zp(z%numw_prod,iimat%np_max))<br class="">+!!allocate(pizeta(z%numw_prod,iimat%np_max)) <br class="">+!!allocate(vphipizeta(fc%nrxxt,iimat%np_max)) <br class="">+!<br class="">+a_tmp_rt%ar(1:a_tmp_rt%nrxxt,1:a_tmp_rt%numb_v) =0.d0<br class="">+!<br class="">+do iv=1, a_in%numb_v<br class="">+   zp(1:z%numw_prod,1:iimat%np_max)=0.d0<br class="">+   vpmax=0<br class="">+ <br class="">+   call start_clock('dgemv1')<br class="">+   do ii=1, iimat%np_max<br class="">+      if (iimat%iimat(ii,iv)==0) cycle<br class="">+      vpmax=vpmax+1<br class="">+      do k=1, z%numw_prod<br class="">+         zp(k,ii)=z%z(k,ii,iv)<br class="">+      enddo<br class="">+   enddo<br class="">+<br class="">+   allocate(pizeta(z%numw_prod,vpmax)) <br class="">+   allocate(vphipizeta(fc%nrxxt,vpmax)) <br class="">+<br class="">+   call stop_clock('dgemv1')<br class="">+<br class="">+<br class="">+   call start_clock('dgemv2')<br class="">+   call dgemm('N','N', z%numw_prod,vpmax, z%numw_prod,1.d0,pw%pw,z%numw_prod,zp(1,1),&<br class="">+              z%numw_prod,0.d0,pizeta(1,1),z%numw_prod)<br class="">+   call stop_clock('dgemv2')<br class="">+<br class="">+<br class="">+   call start_clock('dgemv3')<br class="">+   call dgemm('N','N', fc%nrxxt, vpmax, z%numw_prod,1.d0,p_basis_r(1,1),fc%nrxxt,&<br class="">+              pizeta(1,1), z%numw_prod, 0.d0, vphipizeta(1,1),fc%nrxxt)<br class="">+   call stop_clock('dgemv3')<br class="">+<br class="">+!!     sum up<br class="">+   call start_clock('dgemv4')<br class="">+   do ii=1,vpmax<br class="">+      a_tmp_rt%ar(1:fc%nrxxt,iv)= &<br class="">+            &a_tmp_rt%ar(1:fc%nrxxt,iv)+a_in_rt%ar(1:fc%nrxxt,iimat%iimat(ii,iv))*vphipizeta(1:fc%nrxxt,ii)<br class="">+   enddo<br class="">+!<br class="">+   call stop_clock('dgemv4')<br class="">+!<br class="">+!<br class="">+   deallocate(pizeta)<br class="">+   deallocate(vphipizeta)<br class="">+call mp_barrier(world_comm)<br class="">+enddo<br class="">+call stop_clock('direct_w_dgemv')<br class="">+<br class="">+deallocate(zp)<br class="">+<br class="">+!!!!!!!!!!!!!!!!!!dgemv subroutine!!!!!!!!!!!!!!!!!!!!!<br class="">+!call start_clock('direct_w_dgemv')<br class="">+!allocate(zvv(z%numw_prod))<br class="">+!allocate(zvphi(fc%nrxxt))<br class="">+!a_tmp_rt%ar(1:a_tmp_rt%nrxxt,1:a_tmp_rt%numb_v) =0.d0<br class="">+!!<br class="">+!do iv=1, a_in%numb_v<br class="">+!   do ii=1, iimat%np_max !ii is ivp<br class="">+!      if (iimat%iimat(ii,iv)==0) exit<br class="">+!      call start_clock('dgemv1')<br class="">+!      call dgemv('N',z%numw_prod,z%numw_prod,1.d0,pw%pw,z%numw_prod,z%z(1,ii,iv),1,0.d0,zvv,1)<br class="">+!      call stop_clock('dgemv1')<br class="">+!      call start_clock('dgemv2')<br class="">+!      call dgemv('N',fc%nrxxt,z%numw_prod,1.d0,p_basis_r,fc%nrxxt,zvv,1,0.d0,zvphi,1)<br class="">+!      call stop_clock('dgemv2')<br class="">+!!     sum up<br class="">+!      call start_clock('dgemv3')<br class="">+!      a_tmp_rt%ar(1:fc%nrxxt,iv)= &<br class="">+!            &a_tmp_rt%ar(1:fc%nrxxt,iv)+a_in_rt%ar(1:a_in_rt%nrxxt,iimat%iimat(ii,iv))*zvphi(1:fc%nrxxt)<br class="">+!      call stop_clock('dgemv3')<br class="">+!   enddo<br class="">+!enddo<br class="">+!call stop_clock('direct_w_dgemv')<br class="">+<br class="">+!deallocate(zvv)<br class="">+!deallocate(zvphi)<br class="">+<br class="">+call free_memory_exc_a_r(a_in_rt)<br class="">+call free_bse_z(z)<br class="">+call free_memory_polaw(pw)<br class="">+call free_imat(iimat)<br class="">+<br class="">+call start_clock('wdirect_fftback')<br class="">+!FFT back to provide the output excitonic wave vector in G-space<br class="">+call fftback_a_exc(a_tmp_rt,fc,a_out)<br class="">+call stop_clock('wdirect_fftback')<br class="">+<br class="">+call free_memory_exc_a_r(a_tmp_rt)<br class="">+<br class="">+call stop_clock('direct_w_exc')<br class="">+<br class="">+return<br class="">+end subroutine<br class="">+<br class=""><br class="">Added: trunk/espresso/GWW/bse/dvpsi_bse.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/dvpsi_bse.f90<span class="Apple-tab-span" style="white-space:pre">     </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/dvpsi_bse.f90<span class="Apple-tab-span" style="white-space:pre">    </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,254 @@<br class="">+!<br class="">+! Copyright (C) 2003-2007 Quantum ESPRESSO group<br class="">+! This file is distributed under the terms of the<br class="">+! GNU General Public License. See the file `License'<br class="">+! in the root directory of the present distribution,<br class="">+! or <a href="http://www.gnu.org/copyleft/gpl.txt" class="">http://www.gnu.org/copyleft/gpl.txt</a> .<br class="">+!<br class="">+!<br class="">+!----------------------------------------------------------------------<br class="">+SUBROUTINE dvpsi_e(kpoint,ipol,dvpsi2)<br class="">+  !----------------------------------------------------------------------<br class="">+  ! MARGHE: DA RIPULIRE E OTTIMIZZARE<br class="">+  ! Calculates x * psi_k  for each k-points and for the 3 polarizations<br class="">+  ! Requires on input: vkb, evc, igk<br class="">+  !<br class="">+  USE ions_base, ONLY : ntyp => nsp, nat, ityp<br class="">+  USE kinds, ONLY: DP<br class="">+  USE pwcom<br class="">+  USE uspp, ONLY: nkb, vkb, dvan<br class="">+  USE uspp_param, ONLY: nh<br class="">+  USE wavefunctions_module,  ONLY: evc<br class="">+  USE wvfct,    ONLY : nbnd, npwx,et<br class="">+  USE becmod, ONLY: bec_type, becp, calbec, allocate_bec_type, deallocate_bec_type<br class="">+  USE io_files, ONLY: nwordwfc,iunwfc<br class="">+  USE lsda_mod,              ONLY : nspin<br class="">+  USE control_flags,    ONLY : gamma_only<br class="">+  USE io_global,   ONLY : ionode,stdout<br class="">+  USE gvect,                 ONLY : gstart<br class="">+  USE mp, ONLY : mp_sum, mp_barrier<br class="">+  USE mp_world,             ONLY : world_comm<br class="">+  use bse_wannier, ONLY:num_nbndv<br class="">+  USE gvecw,              ONLY :  ecutwfc<br class="">+!  USE cgcom<br class="">+  !<br class="">+  IMPLICIT NONE<br class="">+  INTEGER :: kpoint, ipol,is,niter_ph<br class="">+  INTEGER :: i,l, na,nt, ibnd,jbnd, info, ih,jkb, iter<br class="">+  real(DP) :: upol(3,3),tr2_ph<br class="">+  real(DP), ALLOCATABLE :: gk(:,:), q(:), overlap(:,:), &<br class="">+       becp_(:,:), dbec(:,:), dbec_(:,:)<br class="">+  real(DP), ALLOCATABLE :: becp2_(:,:), dbec2(:,:), dbec2_(:,:)<br class="">+  COMPLEX(DP), ALLOCATABLE :: dvkb(:,:), dvkb1(:,:), work(:,:), &<br class="">+       &           gr(:,:), h(:,:)<br class="">+  COMPLEX(DP), ALLOCATABLE:: dpsi(:,:), evc2(:,:),dpsi2(:,:)<br class="">+  COMPLEX(DP) :: dvpsi(npwx , nbnd)<br class="">+  COMPLEX(DP) :: dvpsi2(npwx , num_nbndv(1))<br class="">+  <br class="">+  LOGICAL:: precondition, orthonormal,startwith0,debug<br class="">+  EXTERNAL H_h<br class="">+  data upol /1.0d0,0.0d0,0.0d0, 0.0d0,1.0d0,0.0d0, 0.0d0,0.0d0,1.0d0/<br class="">+  real(kind=DP), allocatable :: omat(:,:)<br class="">+  integer j<br class="">+<br class="">+  !<br class="">+  CALL start_clock('dvpsi_e')<br class="">+<br class="">+  CALL gk_sort (xk(1,kpoint),ngm,g,ecutwfc/tpiba2,npw,igk,g2kin)<br class="">+  CALL init_us_2 (npw, igk, xk(1,kpoint), vkb)<br class="">+  <br class="">+  gamma_only=.true.<br class="">+  debug=.true.<br class="">+<br class="">+<br class="">+  allocate(omat(nbnd,nbnd))<br class="">+<br class="">+  allocate( evc( npwx, nbnd ) )<br class="">+  allocate( evc2( npwx, num_nbndv(1) ) )<br class="">+  do is=1,nspin<br class="">+     call davcio(evc,2*nwordwfc,iunwfc,is,-1) <br class="">+  enddo<br class="">+  evc2(1:npwx,1:num_nbndv(1))=evc(1:npwx, 1:num_nbndv(1))<br class="">+<br class="">+  !<br class="">+  !   becp contains <beta|psi> - used in H_h<br class="">+  !<br class="">+  CALL allocate_bec_type ( nkb, nbnd, becp )<br class="">+  ALLOCATE ( gk   ( 3, npwx) )<br class="">+  ALLOCATE ( dvkb ( npwx, nkb) )<br class="">+  ALLOCATE ( dvkb1( npwx, nkb) )<br class="">+  ALLOCATE ( becp_(nkb,nbnd), dbec ( nkb, nbnd), dbec_(nkb, nbnd) )<br class="">+  ALLOCATE ( becp2_(nkb,num_nbndv(1)), dbec2 ( nkb, num_nbndv(1)), dbec2_(nkb, num_nbndv(1)) )<br class="">+  ALLOCATE ( dpsi (npwx , nbnd))<br class="">+  ALLOCATE ( dpsi2 (npwx , num_nbndv(1)))<br class="">+  !<br class="">+  DO i = 1,npw<br class="">+     gk(1,i) = (xk(1,kpoint)+g(1,igk(i)))*tpiba<br class="">+     gk(2,i) = (xk(2,kpoint)+g(2,igk(i)))*tpiba<br class="">+     gk(3,i) = (xk(3,kpoint)+g(3,igk(i)))*tpiba<br class="">+     g2kin(i)= gk(1,i)**2 + gk(2,i)**2 + gk(3,i)**2<br class="">+  ENDDO<br class="">+  !<br class="">+  !  this is  the kinetic contribution to [H,x]:  -2i (k+G)_ipol * psi<br class="">+  !<br class="">+  dpsi(1:npwx,1:nbnd)=(0.d0,0.d0)  <br class="">+  dpsi2(1:npwx,1:num_nbndv(1))=(0.d0,0.d0)  <br class="">+  <br class="">+  DO ibnd = 1,nbnd<br class="">+     DO i = 1,npw<br class="">+        dpsi(i,ibnd) = gk(ipol,i)*(0.0d0,-2.0d0) * evc(i,ibnd)<br class="">+     ENDDO<br class="">+  ENDDO<br class="">+  DO ibnd = 1,num_nbndv(1)<br class="">+     DO i = 1,npw<br class="">+        dpsi2(i,ibnd) = gk(ipol,i)*(0.0d0,-2.0d0) * evc2(i,ibnd)<br class="">+     ENDDO<br class="">+  ENDDO<br class="">+<br class="">+  !<br class="">+  DO i = 1,npw<br class="">+     IF (g2kin(i)>1.0d-10) THEN<br class="">+        gk(1,i) = gk(1,i)/sqrt(g2kin(i))<br class="">+        gk(2,i) = gk(2,i)/sqrt(g2kin(i))<br class="">+        gk(3,i) = gk(3,i)/sqrt(g2kin(i))<br class="">+     ENDIF<br class="">+  ENDDO<br class="">+  !<br class="">+  ! and these are the contributions from nonlocal pseudopotentials<br class="">+  ! ( upol(3,3) are the three unit vectors along x,y,z)<br class="">+  !<br class="">+<br class="">+<br class="">+  CALL gen_us_dj(kpoint,dvkb)<br class="">+  CALL gen_us_dy(kpoint,upol(1,ipol),dvkb1)<br class="">+<br class="">+  !<br class="">+  DO jkb = 1, nkb<br class="">+     DO i = 1,npw<br class="">+        dvkb(i,jkb) =(0.d0,-1.d0)*(dvkb1(i,jkb) + dvkb(i,jkb)*gk(ipol,i))<br class="">+     ENDDO<br class="">+  ENDDO<br class="">+  !<br class="">+  CALL calbec ( npw,  vkb, evc,  becp )<br class="">+  CALL calbec ( npw, dvkb, evc,  dbec )<br class="">+  !<br class="">+  jkb = 0<br class="">+  DO nt=1, ntyp<br class="">+     DO na = 1,nat<br class="">+        IF (nt==ityp(na)) THEN<br class="">+           DO ih=1,nh(nt)<br class="">+              jkb=jkb+1<br class="">+              DO ibnd = 1,nbnd<br class="">+                 dbec_(jkb,ibnd) = dbec(jkb,ibnd)*dvan(ih,ih,nt)<br class="">+!                     if(ionode) write(*,*) 'dbec(j,ib)',  dbec(jkb,ibnd)<br class="">+!                     if(ionode) write(*,*) 'dvan(ih,ih,nt)', dvan(ih,ih,nt)<br class="">+                 becp_(jkb,ibnd) =becp%r(jkb,ibnd)*dvan(ih,ih,nt)<br class="">+              ENDDO<br class="">+           ENDDO<br class="">+        ENDIF<br class="">+     ENDDO<br class="">+  ENDDO<br class="">+<br class="">+ dbec2_(1:nkb,1:num_nbndv(1))=dbec_(1:nkb,1:num_nbndv(1)) <br class="">+ becp2_(1:nkb,1:num_nbndv(1))=becp_(1:nkb,1:num_nbndv(1)) <br class="">+<br class="">+<br class="">+<br class="">+  !<br class="">+  IF (jkb/=nkb) CALL errore('dvpsi_e','unexpected error',1)<br class="">+  !<br class="">+  CALL dgemm ('N', 'N', 2*npw, nbnd, nkb,-1.d0, vkb, &<br class="">+       2*npwx, dbec_, nkb, 1.d0, dpsi, 2*npwx)<br class="">+<br class="">+  CALL dgemm ('N', 'N', 2*npw, num_nbndv(1), nkb,-1.d0, vkb, &<br class="">+       2*npwx, dbec2_, nkb, 1.d0, dpsi2, 2*npwx)<br class="">+<br class="">+  FLUSH( stdout )<br class="">+<br class="">+  CALL dgemm ('N', 'N', 2*npw, nbnd, nkb, 1.d0,dvkb, &<br class="">+       2*npwx, becp_, nkb, 1.d0, dpsi, 2*npwx)<br class="">+<br class="">+  CALL dgemm ('N', 'N', 2*npw, num_nbndv(1), nkb, 1.d0,dvkb, &<br class="">+       2*npwx, becp2_, nkb, 1.d0, dpsi2, 2*npwx)<br class="">+  !<br class="">+  DEALLOCATE(dbec, dbec_, becp_)<br class="">+  DEALLOCATE(dbec2, dbec2_, becp2_)<br class="">+  DEALLOCATE(dvkb1)<br class="">+  DEALLOCATE(dvkb)<br class="">+  DEALLOCATE(gk)<br class="">+<br class="">+  !<br class="">+  !   dpsi contains now [H,x] psi_v  for the three cartesian polarizations.<br class="">+  !   Now solve the linear systems (H-e_v)*(x*psi_v) = [H,x]*psi_v<br class="">+  !<br class="">+!  ALLOCATE  ( overlap( nbnd, nbnd))<br class="">+!  ALLOCATE  ( work(npwx, nbnd))<br class="">+!  ALLOCATE  ( gr( npwx, nbnd))<br class="">+!  ALLOCATE  ( h ( npwx, nbnd))<br class="">+!  ALLOCATE  ( q ( npwx))<br class="">+  !<br class="">+  ALLOCATE  ( overlap( num_nbndv(1), num_nbndv(1)))<br class="">+  ALLOCATE  ( work(npwx, num_nbndv(1)))<br class="">+  ALLOCATE  ( gr( npwx, num_nbndv(1)))<br class="">+  ALLOCATE  ( h ( npwx, num_nbndv(1)))<br class="">+  ALLOCATE  ( q ( npwx))<br class="">+!<br class="">+  orthonormal = .false.<br class="">+  precondition= .true.<br class="">+  !<br class="">+  IF (precondition) THEN<br class="">+     DO i = 1,npw<br class="">+        q(i) = 1.0d0/max(1.d0,g2kin(i))<br class="">+     ENDDO<br class="">+     CALL zvscal(npw,npwx,num_nbndv(1),q,evc2,work)<br class="">+     CALL calbec ( npw, work, evc2, overlap)<br class="">+     CALL DPOTRF('U',num_nbndv(1),overlap,num_nbndv(1),info)<br class="">+     IF (info/=0) CALL errore('solve_ph','cannot factorize',info)<br class="">+  ENDIF<br class="">+  !<br class="">+  startwith0= .true.<br class="">+  dvpsi2(:,:) = (0.d0, 0.d0)<br class="">+  niter_ph = 50<br class="">+  tr2_ph = 1.0d-12<br class="">+  !<br class="">+  CALL cgsolve (npw,evc2,npwx,num_nbndv(1),overlap,num_nbndv(1),   &<br class="">+       orthonormal,precondition,q,startwith0,et(1,1),&<br class="">+       dpsi2,gr,h,dpsi2,work,niter_ph,tr2_ph,iter,dvpsi2)<br class="">+<br class="">+!  IF (precondition) THEN<br class="">+!     DO i = 1,npw<br class="">+!        q(i) = 1.0d0/max(1.d0,g2kin(i))<br class="">+!     ENDDO<br class="">+!     CALL zvscal(npw,npwx,nbnd,q,evc,work)<br class="">+!     CALL calbec ( npw, work, evc, overlap)<br class="">+!     CALL DPOTRF('U',nbnd,overlap,nbnd,info)<br class="">+!     IF (info/=0) CALL errore('solve_ph','cannot factorize',info)<br class="">+!  ENDIF<br class="">+!  !<br class="">+!  startwith0= .true.<br class="">+!  dvpsi(:,:) = (0.d0, 0.d0)<br class="">+!  niter_ph = 50<br class="">+!  tr2_ph = 1.0d-12<br class="">+  !<br class="">+!  CALL cgsolve (H_h,npw,evc,npwx,nbnd,overlap,nbnd,   &<br class="">+!       orthonormal,precondition,q,startwith0,et(1,1),&<br class="">+!       dpsi,gr,h,dpsi,work,niter_ph,tr2_ph,iter,dvpsi)<br class="">+  !<br class="">+  DEALLOCATE(q)<br class="">+  DEALLOCATE(h)<br class="">+  DEALLOCATE(gr)<br class="">+  DEALLOCATE(work)<br class="">+  DEALLOCATE(overlap)<br class="">+  DEALLOCATE(dpsi)<br class="">+  DEALLOCATE(evc)<br class="">+  DEALLOCATE(dpsi2)<br class="">+  DEALLOCATE(evc2)<br class="">+  DEALLOCATE(omat)<br class="">+<br class="">+  CALL deallocate_bec_type ( becp )<br class="">+  <br class="">+  !<br class="">+  CALL stop_clock('dvpsi_e')<br class="">+  !<br class="">+  RETURN<br class="">+END SUBROUTINE dvpsi_e<br class=""><br class="">Added: trunk/espresso/GWW/bse/exc_h_a.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/exc_h_a.f90<span class="Apple-tab-span" style="white-space:pre">    </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/exc_h_a.f90<span class="Apple-tab-span" style="white-space:pre">      </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,222 @@<br class="">+subroutine exc_h_a(a_in,a_out,vstate,vstate_r,cstate,wcstate,fc) <br class="">+!this subroutine applies the excitonic hamiltonian exc_h_a on a given vector<br class="">+!(a_in) and returns the transformed vector (a_out)<br class="">+!if l_gtrick==.true. uses vstate only and does not use vstate_r<br class="">+<br class="">+use exciton<br class="">+use bse_basic_structures<br class="">+<br class="">+use bse_wannier, ONLY:num_nbndv,l_truncated_coulomb, &<br class="">+                      truncation_radius,l_fullbse,l_tdhf,l_lf,l_rpa,&<br class="">+                      l_contraction<br class="">+use pwcom<br class="">+USE wvfct,     ONLY : npwx<br class="">+!use io_files,  ONLY : find_free_unit,diropn<br class="">+use io_files,  ONLY : diropn<br class="">+USE io_global, ONLY : stdout,ionode<br class="">+USE fft_custom_gwl<br class="">+USE mp,          ONLY :mp_barrier<br class="">+USE mp_world,             ONLY : world_comm<br class="">+USE contract_w<br class="">+<br class="">+implicit none<br class="">+INTEGER, EXTERNAL :: find_free_unit<br class="">+<br class="">+type(exc) :: a_in<br class="">+type(exc) :: a_out ! to be initialized and allocated outside this subroutine<br class="">+type(v_state) :: vstate<br class="">+type(v_state_r) :: vstate_r<br class="">+type(c_state) :: cstate<br class="">+type(c_state) :: wcstate<br class="">+type(fft_cus) :: fc<br class="">+<br class="">+type(exc) :: a_excdiago,a_exchange <br class="">+type(exc):: a_dirv<br class="">+type(exc):: a_dirw<br class="">+type(exc):: a_rot<br class="">+<br class="">+<br class="">+integer iuv<br class="">+logical exst<br class="">+logical debug<br class="">+<br class="">+!variables introduced for debug purposes<br class="">+real(kind=DP) prod_test1 <br class="">+real(kind=DP) prod_test2 <br class="">+<br class="">+call start_clock('exc_h_a')<br class="">+debug=.true.<br class="">+<br class="">+  if(debug) then <br class="">+     write(stdout,*) 'Starting exc_h_a subroutine'<br class="">+  endif<br class="">+<br class="">+  call mp_barrier(world_comm)<br class="">+<br class="">+! initialize and nullify all needed excitonic vectors<br class="">+  call initialize_exc(a_excdiago)<br class="">+  a_excdiago%label=2<br class="">+  a_excdiago%npw=npw<br class="">+  a_excdiago%numb_v=num_nbndv(1)<br class="">+  allocate(a_excdiago%a(a_excdiago%npw,a_excdiago%numb_v))<br class="">+  a_excdiago%a(1:a_excdiago%npw,1:a_excdiago%numb_v)=dcmplx(0.d0,0.d0)<br class="">+<br class="">+  call initialize_exc(a_exchange)<br class="">+  a_exchange%label=3<br class="">+  a_exchange%npw=npw<br class="">+  a_exchange%numb_v=num_nbndv(1)<br class="">+  allocate(a_exchange%a(a_exchange%npw,a_exchange%numb_v))<br class="">+  a_exchange%a(1:a_exchange%npw,1:a_exchange%numb_v)=dcmplx(0.d0,0.d0)<br class="">+<br class="">+  call initialize_exc(a_dirv)<br class="">+  a_dirv%label=4<br class="">+  a_dirv%npw=npw<br class="">+  a_dirv%numb_v=num_nbndv(1)<br class="">+  allocate(a_dirv%a(a_dirv%npw,a_dirv%numb_v))<br class="">+  a_dirv%a(1:a_dirv%npw,1:a_dirv%numb_v)=dcmplx(0.d0,0.d0)<br class="">+<br class="">+  call initialize_exc(a_dirw)<br class="">+  a_dirw%label=6<br class="">+  a_dirw%npw=npw<br class="">+  a_dirw%numb_v=num_nbndv(1)<br class="">+  allocate(a_dirw%a(a_dirw%npw,a_dirw%numb_v))<br class="">+  a_dirw%a(1:a_dirw%npw,1:a_dirw%numb_v)=dcmplx(0.d0,0.d0)<br class="">+<br class="">+! apply the diagonal part of the excitonic Hamiltonian to a copy of a_exc<br class="">+  a_excdiago%a(1:a_excdiago%npw,1:a_excdiago%numb_v)=a_in%a(1:a_in%npw,1:a_in%numb_v)<br class="">+  call diago_exc(a_excdiago,vstate,cstate,wcstate)<br class="">+<br class="">+  if(debug) then <br class="">+     write(stdout,*) 'Diagonal part computed'<br class="">+  endif<br class="">+  call mp_barrier(world_comm)<br class="">+  call initialize_exc(a_rot)<br class="">+<br class="">+! apply the exchange term of the Hamiltonian<br class="">+  if(.not.l_rpa) then<br class="">+!     if(.not.l_truncated_coulomb) then<br class="">+!        iuv = find_free_unit()<br class="">+!        CALL diropn( iuv, 'vgq', npwx, exst )<br class="">+!        CALL davcio(vg_q,npwx,iuv,1,-1)<br class="">+!        close(iuv)<br class="">+!     endif<br class="">+<br class="">+<br class="">+     if(debug) then <br class="">+        write(stdout,*) 'vg_q read'<br class="">+     call mp_barrier(world_comm)<br class="">+     endif<br class="">+<br class="">+     call exchange_exc(a_in,vstate,vstate_r,fc,a_exchange)<br class="">+<br class="">+     if(debug) then <br class="">+        write(stdout,*) 'Exchange part computed'<br class="">+     endif<br class="">+<br class="">+     call mp_barrier(world_comm)<br class="">+<br class="">+!    apply the direct term of the Hamiltonian (v part)<br class="">+     <br class="">+     if(.not.l_lf) then<br class="">+   <br class="">+        call initialize_exc(a_rot)<br class="">+        a_rot%label=5<br class="">+        a_rot%npw=npw<br class="">+        a_rot%numb_v=num_nbndv(1)<br class="">+        allocate(a_rot%a(a_rot%npw,a_rot%numb_v))<br class="">+<br class="">+!       first rotate the excitonic wave function wave vector to use the wannier<br class="">+!       wavefunctions<br class="">+        if(debug) write(stdout,*)  'DEBUG1'<br class="">+        Call urot_a(a_in,a_rot,1)<br class="">+        if(debug) write(stdout,*)  'DEBUG2'<br class="">+        if(.not.l_contraction) then<br class="">+           call direct_v_exc(a_rot,fc,a_dirv)<br class="">+        else<br class="">+           call contract_v_apply(a_rot,fc,a_dirv)<br class="">+        endif<br class="">+        if(debug) write(stdout,*)  'DEBUG3'<br class="">+        call pc_operator_exc(a_dirv,vstate,1)<br class="">+        if(debug) write(stdout,*)  'DEBUG4'<br class="">+!        and rotate back<br class="">+        call urot_a(a_dirv,a_rot,0)<br class="">+        a_dirv%a(1:a_dirv%npw,1:a_dirv%numb_v)=a_rot%a(1:a_rot%npw,1:a_rot%numb_v)<br class="">+<br class="">+        if(debug) write(stdout,*)  'DEBUG5'<br class="">+        call mp_barrier(world_comm)<br class="">+!<br class="">+        if(debug) then <br class="">+            write(stdout,*) 'After direct_v_exc'<br class="">+        endif<br class="">+<br class="">+! apply the direct term of the excitonic Hamiltonian (Wc part)<br class="">+<br class="">+  <br class="">+        if(.not.l_tdhf) then<br class="">+           call urot_a(a_in,a_rot,1)<br class="">+<br class="">+           if(debug) then <br class="">+              write(stdout,*) 'Before direct_W_exc'<br class="">+           endif<br class="">+<br class="">+           !if(.true.) then !DEBUG<br class="">+           if(.not.l_contraction) then<br class="">+              call direct_w_exc(a_rot,fc,a_dirw)<br class="">+           else<br class="">+              call contract_w_apply(a_rot,fc,a_dirw)<br class="">+           endif<br class="">+           call pc_operator_exc(a_dirw,vstate,1)<br class="">+<br class="">+!           and rotate back<br class="">+           call urot_a(a_dirw,a_rot,0)<br class="">+           a_dirw%a(1:a_dirw%npw,1:a_dirw%numb_v)=a_rot%a(1:a_rot%npw,1:a_rot%numb_v)<br class="">+<br class="">+           call mp_barrier(world_comm)<br class="">+           if(debug) then <br class="">+              write(stdout,*) 'After direct_W_exc'<br class="">+           endif<br class="">+<br class="">+<br class="">+<br class="">+<br class="">+        endif ! .not.l_tdhf<br class="">+     endif ! .not.l_lf<br class="">+  endif  ! .not. l_rpa  <br class="">+<br class="">+! sum up all the terms<br class="">+! only valid for spin-singlet class of solutions (non-spin polarized case)<br class="">+  a_out%a(1:a_out%npw,1:a_out%numb_v)=a_excdiago%a(1:a_out%npw,1:a_out%numb_v)&<br class="">+                                      -a_dirv%a(1:a_out%npw,1:a_out%numb_v)&<br class="">+                                     -a_dirw%a(1:a_out%npw,1:a_out%numb_v)&<br class="">+                                     +2.d0*a_exchange%a(1:a_out%npw,1:a_out%numb_v)<br class="">+<br class="">+! free memory<br class="">+  call free_memory_exc_a(a_rot)<br class="">+  call free_memory_exc_a(a_excdiago)<br class="">+  call free_memory_exc_a(a_exchange)<br class="">+  call free_memory_exc_a(a_dirv)<br class="">+  call free_memory_exc_a(a_dirw)<br class="">+<br class="">+<br class="">+<br class="">+  call stop_clock('exc_h_a')<br class="">+<br class="">+if(debug) then<br class="">+  call print_clock('exc_h_a')<br class="">+  call print_clock('diago_exc')<br class="">+  call print_clock('exchange_exc')<br class="">+  call print_clock('direct_v_exc')<br class="">+  call print_clock('direct_w_contract')<br class="">+  call print_clock('wdirect_fftback')<br class="">+  call print_clock('contract_w_dgemv')<br class="">+  call print_clock('direct_v_contract')<br class="">+  call print_clock('d_v_fft')<br class="">+endif<br class="">+<br class="">+ return<br class="">+end subroutine exc_h_a<br class="">+<br class="">+<br class="">+<br class="">+<br class="">+<br class=""><br class="">Added: trunk/espresso/GWW/bse/exchange_exc.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/exchange_exc.f90<span class="Apple-tab-span" style="white-space:pre">    </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/exchange_exc.f90<span class="Apple-tab-span" style="white-space:pre"> </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,188 @@<br class="">+subroutine exchange_exc(a_in,v,v_rt,fc,a_out)<br class="">+! this subroutine applies the exchange term of the Hamiltonian to the excitonic<br class="">+! wavefuntion vector a <br class="">+!if l_gtrick==.true. uses vonly and does not use v_rt     <br class="">+<br class="">+USE kinds,            ONLY : DP<br class="">+USE exciton<br class="">+use bse_basic_structures<br class="">+use bse_wannier,      ONLY: l_truncated_coulomb, &<br class="">+                             truncation_radius, &<br class="">+                             dual_bse<br class="">+USE gvect<br class="">+USE constants,        ONLY : e2, fpi<br class="">+USE cell_base,        ONLY : tpiba,omega,tpiba2<br class="">+!USE mp_wave,          ONLY : mergewf,splitwf<br class="">+USE fft_custom_gwl<br class="">+USE gvecw,              ONLY : ecutwfc<br class="">+USE io_global, ONLY : stdout, ionode, ionode_id<br class="">+USE mp_world, ONLY : mpime, nproc<br class="">+USE mp_pools, ONLY: intra_pool_comm<br class="">+USE mp_world,             ONLY : world_comm<br class="">+USE wavefunctions_module, ONLY :  psic<br class="">+USE mp,          ONLY :mp_barrier<br class="">+<br class="">+!USE io_files,         ONLY : find_free_unit<br class="">+<br class="">+<br class="">+implicit none<br class="">+INTEGER, EXTERNAL :: find_free_unit<br class="">+type(exc) :: a_in,a_out<br class="">+type(exc_r) :: a_rt<br class="">+type(v_state) :: v<br class="">+type(v_state_r) :: v_rt<br class="">+type(fft_cus) :: fc<br class="">+<br class="">+<br class="">+REAL(kind=DP), ALLOCATABLE :: fac(:)<br class="">+COMPLEX(kind=DP), ALLOCATABLE :: fac_t(:)<br class="">+COMPLEX(kind=DP), ALLOCATABLE :: cfac(:)<br class="">+COMPLEX(kind=DP), ALLOCATABLE :: evc_g(:)<br class="">+REAL(kind=DP) :: qq<br class="">+integer ig,iv,iunu<br class="">+COMPLEX(kind=DP), allocatable :: psiv_phiv(:)<br class="">+<br class="">+logical :: debug<br class="">+<br class="">+call start_clock('exchange_exc')<br class="">+debug=.false.<br class="">+<br class="">+if(debug) then <br class="">+  write(*,*) 'Starting to compute the exchange term'<br class="">+  call mp_barrier(world_comm)<br class="">+endif<br class="">+<br class="">+allocate(fac(a_in%npw))<br class="">+allocate(cfac(a_in%npw))<br class="">+<br class="">+if(l_truncated_coulomb) then<br class="">+   do ig=1,a_in%npw<br class="">+     qq = g(1,ig)**2.d0 + g(2,ig)**2.d0 + g(3,ig)**2.d0<br class="">+     if (qq > 1.d-8) then<br class="">+        fac(ig)=(e2*fpi/(tpiba2*qq))*(1.d0-dcos(dsqrt(qq)*truncation_radius*tpiba))<br class="">+     else<br class="">+        fac(ig)=e2*fpi*(truncation_radius**2.d0/2.d0)<br class="">+     endif<br class="">+   enddo<br class="">+   fac(:)=fac(:)/omega<br class="">+else<br class="">+   fac(:)=0.d0<br class="">+   fac(1:a_in%npw)=vg_q(1:a_in%npw)<br class="">+   !set the 0 component of v to 0 to have vbar (see S. Albrecht phD thesis or Onida,Reining,and Rubio RMP)<br class="">+   if (v%gstart==2) fac(1)=0.d0<br class="">+endif<br class="">+<br class="">+cfac(1:a_in%npw)=dcmplx(fac(1:a_in%npw))<br class="">+<br class="">+<br class="">+if(debug) then <br class="">+  write(*,*) 'vbar built'<br class="">+  call mp_barrier(world_comm)<br class="">+endif<br class="">+<br class="">+! now distribuite the G vector in the dual grid order<br class="">+<br class="">+allocate(fac_t(fc%npwt))<br class="">+allocate(evc_g(fc%ngmt_g))<br class="">+call reorderwfp_col(1,a_in%npw,fc%npwt,cfac(1),fac_t(1),a_in%npw,fc%npwt, &<br class="">+     & ig_l2g,fc%ig_l2gt,fc%ngmt_g,mpime, nproc,intra_pool_comm )<br class="">+<br class="">+!call  mergewf(cfac,evc_g,a_in%npw,ig_l2g,mpime,nproc,ionode_id,intra_pool_comm)<br class="">+!call  splitwf(fac_t,evc_g,fc%npwt,fc%ig_l2gt,mpime,nproc,ionode_id,intra_pool_comm)<br class="">+deallocate(evc_g)<br class="">+<br class="">+<br class="">+if(debug) then <br class="">+  write(*,*) 'vbar distributed'<br class="">+  call mp_barrier(world_comm)<br class="">+endif<br class="">+<br class="">+!FFT the excitonic wavefunction vector to real space (dual grid)<br class="">+call initialize_exc_r(a_rt)<br class="">+call fft_a_exc(a_in,fc,a_rt)<br class="">+<br class="">+if(debug) then <br class="">+  write(*,*) 'fft exc state'<br class="">+  call mp_barrier(world_comm)<br class="">+endif<br class="">+!compute the psi_iv(r)*phi_iv(r) product in r-space (dual grid) for every iv <br class="">+!FFT back to G space (dual grid order), multiply with vbar, and sum over iv<br class="">+ <br class="">+!be careful! for the moment there is no spin structure in the a_in_r object so this works<br class="">+!only for nspin==1<br class="">+<br class="">+allocate(psiv_phiv(fc%npwt))<br class="">+<br class="">+psiv_phiv(1:fc%npwt)=(0.d0,0.d0)<br class="">+<br class="">+do iv=1,a_in%numb_v,2<br class="">+   if(debug) then <br class="">+     write(*,*) 'exchange term main loop iv=',iv<br class="">+     write(*,*) 'a_in%numb_v=',a_in%numb_v<br class="">+     write(*,*) 'a_rt%nrxxt=',a_rt%nrxxt<br class="">+!     call mp_barrier<br class="">+   endif<br class="">+   a_rt%ar(1:a_rt%nrxxt,iv) = a_rt%ar(1:a_rt%nrxxt,iv)*v_rt%wfnrt(1:v_rt%nrxxt,iv,1)<br class="">+   if(iv/=a_in%numb_v) a_rt%ar(1:a_rt%nrxxt,iv+1) = a_rt%ar(1:a_rt%nrxxt,iv+1)*v_rt%wfnrt(1:v_rt%nrxxt,iv+1,1)<br class="">+   if (iv==a_in%numb_v) then <br class="">+      psic(1:fc%nrxxt)=dcmplx(a_rt%ar(1:fc%nrxxt,iv),0.d0)<br class="">+   else<br class="">+      psic(1:fc%nrxxt)=dcmplx(a_rt%ar(1:fc%nrxxt,iv),a_rt%ar(1:fc%nrxxt,iv+1))<br class="">+   endif <br class="">+   if(debug) then <br class="">+     write(*,*) 'before fft'<br class="">+     write(*,*) 'fc%nr1t',fc%nr1t<br class="">+     write(*,*) 'fc%nr2t',fc%nr2t<br class="">+     write(*,*) 'fc%nr3t',fc%nr3t<br class="">+     write(*,*) 'fc%nrx1t',fc%nrx1t<br class="">+     write(*,*) 'fc%nrx2t',fc%nrx2t<br class="">+     write(*,*) 'fc%nrx3t',fc%nrx3t<br class="">+!     call mp_barrier<br class="">+   endif<br class="">+   CALL cft3t(fc, psic, fc%nr1t, fc%nr2t, fc%nr3t, fc%nrx1t, fc%nrx2t, fc%nrx3t, -2 )<br class="">+   if(debug) then <br class="">+     write(*,*) 'after fft'<br class="">+     call mp_barrier(world_comm)<br class="">+   endif<br class="">+   if (iv==a_in%numb_v) then <br class="">+      psiv_phiv(1:fc%npwt)= psiv_phiv(1:fc%npwt)+psic(fc%nlt(1:fc%npwt))*fac_t(1:fc%npwt)<br class="">+   else<br class="">+      psiv_phiv(1:fc%npwt)= psiv_phiv(1:fc%npwt)+&<br class="">+           &0.5*(psic(fc%nlt(1:fc%npwt))+conjg( psic(fc%nltm(1:fc%npwt))))*fac_t(1:fc%npwt)+&<br class="">+           &(0.d0,-0.5d0)*(psic(fc%nlt(1:fc%npwt))-conjg(psic(fc%nltm(1:fc%npwt))))*fac_t(1:fc%npwt)<br class="">+   endif<br class="">+   if(debug) then <br class="">+     write(*,*) 'end of loop'<br class="">+     call mp_barrier(world_comm)<br class="">+   endif<br class="">+enddo<br class="">+<br class="">+if(fc%gstart_t==2) psiv_phiv(1)= (0.d0,0.d0)<br class="">+<br class="">+!FFT to real space and multiply by valence state wavefunction vector to create<br class="">+!the components of the excitonic vector and then FFT back <br class="">+<br class="">+psic(:)=0.d0<br class="">+psic(fc%nlt(1:fc%npwt))  = psiv_phiv(1:fc%npwt)<br class="">+psic(fc%nltm(1:fc%npwt)) = CONJG(psiv_phiv(1:fc%npwt))<br class="">+<br class="">+CALL cft3t( fc, psic, fc%nr1t, fc%nr2t, fc%nr3t, fc%nrx1t, fc%nrx2t, fc%nrx3t, 2 )<br class="">+<br class="">+do iv=1,a_in%numb_v<br class="">+    a_rt%ar(1:a_rt%nrxxt,iv)=v_rt%wfnrt(1:v_rt%nrxxt,iv,1)*dble(psic(1:fc%nrxxt))<br class="">+enddo<br class="">+<br class="">+call fftback_a_exc(a_rt,fc,a_out)<br class="">+<br class="">+! project into the conduction band manifold<br class="">+<br class="">+call pc_operator_exc(a_out,v,1)<br class="">+<br class="">+deallocate(fac_t)<br class="">+call free_memory_exc_a_r(a_rt)<br class="">+<br class="">+call stop_clock('exchange_exc')<br class="">+<br class="">+return<br class="">+end subroutine<br class="">+<br class=""><br class="">Added: trunk/espresso/GWW/bse/exciton.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/exciton.f90<span class="Apple-tab-span" style="white-space:pre">  </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/exciton.f90<span class="Apple-tab-span" style="white-space:pre">      </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,621 @@<br class="">+module exciton<br class="">+! this module cointains variables and subroutines related to <br class="">+! the excitonic wave functions and energies<br class="">+<br class="">+USE kinds, ONLY : DP<br class="">+<br class="">+type exc<br class="">+!excitonic wavefunction vector in G space<br class="">+    integer npw ! number of plane waves per processor<br class="">+    integer numb_v ! number of valnce state<br class="">+!    real(kind=dp), dimension (:), pointer :: e_ks ! Kohn-Sham energy of valence states  <br class="">+    complex(kind=dp), dimension (:,:), pointer :: a ! vector on which Hexc can be applied  a(npw,nbnd_v)<br class="">+    INTEGER :: label!label to read/write to disk<br class="">+    real(kind=DP) :: e ! energy of the excitonic eigenstate<br class="">+end type exc<br class="">+<br class="">+type exc_r<br class="">+!excitonic wavefunction vector in real space (double grid)<br class="">+    integer nrxxt ! number of plane waves per processor<br class="">+    integer numb_v ! number of valnce state<br class="">+!    real(kind=dp), dimension (:), pointer :: e_ks ! Kohn-Sham energy of valence states  <br class="">+    real(kind=dp), dimension (:,:), pointer :: ar ! vector on which Hexc can be applied  a(npw,nbnd_v)<br class="">+    INTEGER :: label!label to read/write to disk<br class="">+end type exc_r<br class="">+<br class="">+type spectrum<br class="">+!collection of eigenvalues and optical amplitudes <br class="">+    integer neig<br class="">+    real(kind=dp), dimension(:), pointer:: en <br class="">+    real(kind=dp), dimension(:,:), pointer:: a<br class="">+end type spectrum<br class="">+<br class="">+<br class="">+type(exc), allocatable :: bse_spectrum(:)<br class="">+!type(exc), dimension(:), pointer :: bse_spectrum<br class="">+!this variable contains the excitonic eigenvectors and eigenvalues<br class="">+!to be deleted probably for memory issues<br class="">+<br class="">+<br class="">+<br class="">+contains<br class="">+<br class="">+   SUBROUTINE initialize_exc(a)<br class="">+   !this subroutine initializes exc<br class="">+      implicit none<br class="">+      TYPE(exc) :: a<br class="">+      nullify(a%a)<br class="">+!      nullify(a%e_ks)<br class="">+      return<br class="">+   END SUBROUTINE <br class="">+<br class="">+   SUBROUTINE initialize_exc_r(a_r)<br class="">+   !this subroutine initializes exc_r<br class="">+      implicit none<br class="">+      TYPE(exc_r) :: a_r<br class="">+      nullify(a_r%ar)<br class="">+!      nullify(a%e_ks)<br class="">+      return<br class="">+   END SUBROUTINE <br class="">+<br class="">+   SUBROUTINE initialize_spectrum(s)<br class="">+   !this subroutine initializes spectrum<br class="">+      implicit none<br class="">+      TYPE(spectrum) :: s<br class="">+      nullify(s%en)<br class="">+      nullify(s%a)<br class="">+      return<br class="">+   END SUBROUTINE <br class="">+<br class="">+   SUBROUTINE free_memory_exc_a(a)<br class="">+   !this subroutine deallocates exc<br class="">+      implicit none<br class="">+      TYPE(exc) a<br class="">+      if(associated(a%a)) deallocate(a%a)<br class="">+      nullify(a%a)<br class="">+!      if(associated(a%e_ks)) deallocate(a%e_ks)<br class="">+!      nullify(a%e_ks)<br class="">+      return<br class="">+   END SUBROUTINE<br class="">+<br class="">+   SUBROUTINE free_memory_exc_a_r(a_r)<br class="">+   !this subroutine deallocates exc_r <br class="">+      implicit none<br class="">+      TYPE(exc_r) a_r<br class="">+      if(associated(a_r%ar)) deallocate(a_r%ar)<br class="">+      nullify(a_r%ar)<br class="">+      return<br class="">+   END SUBROUTINE<br class="">+<br class="">+   SUBROUTINE free_memory_spectrum(s)<br class="">+   !this subroutine deallocates exc<br class="">+      implicit none<br class="">+      TYPE(spectrum) s<br class="">+      if(associated(s%en)) deallocate(s%en)<br class="">+      nullify(s%en)<br class="">+      if(associated(s%a)) deallocate(s%a)<br class="">+      nullify(s%a)<br class="">+      return<br class="">+   END SUBROUTINE<br class="">+<br class="">+<br class="">+    SUBROUTINE write_exc(a)<br class="">+    !this subroutine writes the excitonic vectors on disk<br class="">+    !the file name is taken from the label<br class="">+!    USE io_files,             ONLY : find_free_unit, prefix<br class="">+    USE io_files,             ONLY : prefix,tmp_dir<br class="">+    USE mp_world,  ONLY : mpime<br class="">+    implicit none<br class="">+    INTEGER, EXTERNAL :: find_free_unit<br class="">+    TYPE(exc) :: a!the exc wavefunction to be written<br class="">+<br class="">+    INTEGER :: iw, jw, iuna<br class="">+    CHARACTER(5) :: nfile<br class="">+    CHARACTER(5) :: nproc<br class="">+<br class="">+    if(a%label >= 0 ) then<br class="">+      write(nfile,'(5i1)') &<br class="">+        & a%label/10000,mod(a%label,10000)/1000,mod(a%label,1000)/100,mod(a%label,100)/10,mod(a%label,10)<br class="">+      write(nproc,'(5i1)') &<br class="">+        & mpime/10000,mod(mpime,10000)/1000,mod(mpime,1000)/100,mod(mpime,100)/10,mod(mpime,10)<br class="">+      iuna = find_free_unit()<br class="">+      open( unit=iuna, file=trim(tmp_dir)//trim(prefix)//'-exc_a.'// nfile //'.'// nproc , &<br class="">+           &status='unknown',form='unformatted')<br class="">+    else<br class="">+      write(nfile,'(5i1)') &<br class="">+        & -a%label/10000,mod(-a%label,10000)/1000,mod(-a%label,1000)/100,mod(-a%label,100)/10,mod(-a%label,10)<br class="">+      write(nproc,'(5i1)') &<br class="">+        & mpime/10000,mod(mpime,10000)/1000,mod(mpime,1000)/100,mod(mpime,100)/10,mod(mpime,10)<br class="">+      iuna = find_free_unit()<br class="">+      open( unit=iuna, file=trim(tmp_dir)//trim(prefix)//'-exc_a.-'// nfile //'.'// nproc , &<br class="">+           &status='unknown',form='formatted')<br class="">+    endif<br class="">+    write(iuna) a%label<br class="">+    write(iuna) a%npw<br class="">+    write(iuna) a%numb_v<br class="">+    write(iuna) a%e<br class="">+    do iw=1,a%numb_v<br class="">+       write(iuna)  a%a(1:a%npw,iw)<br class="">+    enddo<br class="">+    close(iuna)<br class="">+<br class="">+    return<br class="">+    END SUBROUTINE<br class="">+<br class="">+    SUBROUTINE  read_exc(label, a,l_verbose)<br class="">+    !this subroutine reads the excitonic vectors from disk<br class="">+    !the file name is taken from the label<br class="">+<br class="">+<br class="">+!    USE io_files,             ONLY : find_free_unit, prefix<br class="">+    USE io_files,             ONLY :  prefix,tmp_dir<br class="">+    USE io_global,            ONLY : stdout<br class="">+    USE mp_world,  ONLY : mpime<br class="">+    implicit none<br class="">+    INTEGER, EXTERNAL :: find_free_unit<br class="">+    TYPE(exc) :: a!the excitonic wave function to be read<br class="">+    INTEGER :: label! the label identifing the required excitonic wavefunction<br class="">+    LOGICAL, INTENT(in) :: l_verbose<br class="">+    INTEGER :: iw, jw, iuna<br class="">+    CHARACTER(5) :: nfile<br class="">+    CHARACTER(5) :: nproc<br class="">+<br class="">+<br class="">+<br class="">+!first deallocate<br class="">+    call free_memory_exc_a(a)<br class="">+<br class="">+<br class="">+    if(label >= 0 ) then<br class="">+      write(nfile,'(5i1)') label/10000,mod(label,10000)/1000,mod(label,1000)/100,mod(label,100)/10,mod(label,10)<br class="">+      write(nproc,'(5i1)') mpime/10000,mod(mpime,10000)/1000,mod(mpime,1000)/100,mod(mpime,100)/10,mod(mpime,10)<br class="">+      iuna = find_free_unit()<br class="">+      open( unit=iuna, file=trim(tmp_dir)//trim(prefix)//'-exc_a.'//nfile//'.'//nproc, status='old',form='unformatted')<br class="">+    else<br class="">+      write(nfile,'(5i1)') -label/10000,mod(-label,10000)/1000,mod(-label,1000)/100,mod(-label,100)/10,mod(-label,10)<br class="">+      write(nproc,'(5i1)') mpime/10000,mod(mpime,10000)/1000,mod(mpime,1000)/100,mod(mpime,100)/10,mod(mpime,10)<br class="">+      iuna = find_free_unit()<br class="">+      open( unit=iuna, file=trim(tmp_dir)//trim(prefix)//'-exc_a.-'//nfile//'.'//nproc, status='old',form='unformatted')<br class="">+    endif<br class="">+    read(iuna) a%label<br class="">+    read(iuna) a%npw<br class="">+    read(iuna) a%numb_v<br class="">+    read(iuna) a%e<br class="">+<br class="">+!now allocate<br class="">+    allocate(a%a(a%npw,a%numb_v))<br class="">+    do iw=1,a%numb_v<br class="">+       read(iuna)  a%a(1:a%npw,iw)<br class="">+    enddo<br class="">+    close(iuna)<br class="">+<br class="">+    return<br class="">+    END SUBROUTINE<br class="">+<br class="">+    SUBROUTINE c_times_exc(a, c )<br class="">+! this subroutine multiplies each iv line of the excitonic wave-function<br class="">+! matrix (a%a) with the iv element of the real number vector (c).<br class="">+<br class="">+    USE kinds, ONLY : DP<br class="">+<br class="">+    implicit none<br class="">+    type(exc) :: a<br class="">+    real(kind=dp) :: c(a%numb_v)<br class="">+<br class="">+    integer iv<br class="">+    <br class="">+    call start_clock('c_times_exc')<br class="">+<br class="">+    do iv=1, a%numb_v<br class="">+       a%a(1:a%npw,iv)=cmplx(c(iv),0.d0)*a%a(1:a%npw,iv)  <br class="">+    enddo<br class="">+<br class="">+    call stop_clock('c_times_exc')<br class="">+<br class="">+    return<br class="">+    END SUBROUTINE<br class="">+<br class="">+    SUBROUTINE random_exc(a)<br class="">+! this subroutine returns a random excitonic-wavefunction vector (a%a) <br class="">+<br class="">+    USE random_numbers, ONLY : randy<br class="">+    USE kinds, ONLY : DP<br class="">+    USE gvect,          ONLY : gstart<br class="">+<br class="">+    implicit none<br class="">+    type(exc) ::a<br class="">+<br class="">+    real(kind=DP):: r1,r2<br class="">+    integer      ::  iv,ig<br class="">+<br class="">+    do iv=1,a%numb_v<br class="">+       do ig=1,a%npw<br class="">+          r1=randy()<br class="">+          r2=randy()<br class="">+          a%a(ig,iv)=cmplx(r1,r2)<br class="">+          if (gstart==2) a%a(1,iv)=cmplx(r1,0.d0)<br class="">+       enddo<br class="">+    enddo  <br class="">+    return<br class="">+    END SUBROUTINE<br class="">+<br class="">+<br class="">+    SUBROUTINE pc_operator_exc(a,v,is)<br class="">+! this subroutine projects the excitonic wave-function vector into the conduction states manifold    <br class="">+    USE bse_basic_structures<br class="">+    USE mp, ONLY : mp_sum<br class="">+    USE mp_world,             ONLY : world_comm<br class="">+    USE wvfct,    ONLY : npw,npwx<br class="">+<br class="">+    implicit none<br class="">+    type(exc) :: a ! excitonic wfns vector to be projected on the conduction state manifold <br class="">+    type(v_state) :: v ! valence states vector in G space  <br class="">+<br class="">+    REAL(kind=DP), ALLOCATABLE :: prod(:)<br class="">+    integer :: iv, iiv,is<br class="">+<br class="">+    call start_clock('pc_operator_exc')<br class="">+<br class="">+    allocate(prod(a%numb_v))<br class="">+<br class="">+    do iv=1,a%numb_v<br class="">+       call dgemm('T','N', a%numb_v,1,2*a%npw,2.d0,v%wfn(:,:,is),2*npw,a%a(:,iv),2*a%npw,&<br class="">+            & 0.d0,prod,a%numb_v)<br class="">+        do iiv=1,a%numb_v<br class="">+           if(v%gstart==2) prod(iiv)=prod(iiv)-dble(conjg(v%wfn(1,iiv,is))*a%a(1,iv))<br class="">+        enddo<br class="">+        call mp_sum(prod(:), world_comm )<br class="">+        call dgemm('N','N',2*a%npw,1,a%numb_v,-1.d0,v%wfn(:,:,is),2*npw,prod,&<br class="">+          &a%numb_v,1.d0,a%a(:,iv),2*a%npw)<br class="">+    enddo<br class="">+<br class="">+    deallocate(prod)<br class="">+<br class="">+    call stop_clock('pc_operator_exc')<br class="">+<br class="">+    return<br class="">+    END SUBROUTINE<br class="">+<br class="">+    <br class="">+    SUBROUTINE poutcstate_exc(a_in,a_out,cstate,wcstate)<br class="">+! this subroutine projects out from the excitonic vectors the component along the conduction states for which the <br class="">+! the QP are known, and it multiplies it by a weighted vector (used to avoid scissor)<br class="">+    USE bse_basic_structures<br class="">+!    USE qpe, ONLY : qpc<br class="">+    USE mp, ONLY : mp_sum<br class="">+    USE mp_world,             ONLY : world_comm<br class="">+    USE wvfct,    ONLY : npw,npwx<br class="">+   <br class="">+<br class="">+    implicit none<br class="">+    type(exc), intent(in) :: a_in ! excitonic wfns vector to be projected on the conduction state manifold <br class="">+    type(exc), intent(out) :: a_out ! final<br class="">+    <br class="">+    type(c_state) :: cstate ! GW corrected conduction states vector in G space  <br class="">+    type(c_state) :: wcstate ! weighted GW corrected conduction states vector in G space  <br class="">+<br class="">+    REAL(kind=DP), ALLOCATABLE :: prod(:)<br class="">+    integer :: iv, ic<br class="">+<br class="">+    call start_clock('poutcstate_exc')<br class="">+<br class="">+    allocate(prod(cstate%numb_c))<br class="">+<br class="">+    do iv=1,a_in%numb_v<br class="">+       call dgemm('T','N', cstate%numb_c,1,2*a_in%npw,2.d0,cstate%wfn(:,:),2*npw,a_in%a(:,iv),2*a_in%npw,&<br class="">+            & 0.d0,prod,cstate%numb_c)<br class="">+!       call dgemm('T','N', a%numb_v,1,2*a%npw,2.d0,v%wfn(:,:,is),2*npwx,a%a(:,iv),2*a%npw,&<br class="">+!            & 0.d0,prod,a%numb_v)<br class="">+        do ic=1,cstate%numb_c<br class="">+           if(cstate%gstart==2) prod(ic)=prod(ic)-dble(conjg(cstate%wfn(1,ic))*a_in%a(1,iv))<br class="">+        enddo<br class="">+        call mp_sum(prod(:), world_comm )<br class="">+        call dgemm('N','N',2*a_in%npw,1,cstate%numb_c,1.d0,wcstate%wfn(:,:),2*npw,prod,&<br class="">+          &cstate%numb_c,0.d0,a_out%a(:,iv),2*a_in%npw)<br class="">+    enddo<br class="">+<br class="">+    deallocate(prod)<br class="">+<br class="">+    call stop_clock('poutcstate_exc')<br class="">+<br class="">+    return<br class="">+    END SUBROUTINE<br class="">+<br class="">+<br class="">+    SUBROUTINE sproduct_exc(a1,a2,prod)<br class="">+! this subroutine returns the scalar product (prod) between two<br class="">+! excitonic-wavefunctions, input wave functions are given in G-space<br class="">+    use io_global, ONLY : stdout, ionode <br class="">+    USE kinds, ONLY : DP<br class="">+    USE mp,             ONLY : mp_sum, mp_barrier<br class="">+    USE mp_world,             ONLY : world_comm<br class="">+    use mp_world, ONLY : mpime<br class="">+    USE gvect,          ONLY : gstart,ngm_g<br class="">+<br class="">+    implicit none<br class="">+    REAL(kind=DP), EXTERNAL :: ddot<br class="">+    type(exc) :: a1,a2<br class="">+    real(kind=DP) :: prod<br class="">+    integer :: ii<br class="">+<br class="">+    logical :: debug<br class="">+    debug=.false.<br class="">+<br class="">+!compute the dot product<br class="">+!    if(debug) then<br class="">+!      write(*,*) 'sproduct_exc in, mpime=',mpime<br class="">+!    endif<br class="">+    call start_clock('sproduct_exc')<br class="">+    prod=0.d0<br class="">+    do ii=1,a1%numb_v<br class="">+       prod=prod+2.d0*ddot(2*a1%npw,a1%a(:,ii),1,a2%a(:,ii),1)<br class="">+       if (gstart==2) prod=prod-a1%a(1,ii)*a2%a(1,ii)<br class="">+    enddo<br class="">+! sum over processor<br class="">+    call mp_sum(prod, world_comm)<br class="">+<br class="">+<br class="">+<br class="">+!    if(debug) then<br class="">+!      write(*,*) 'sproduct_exc out, mpime=',mpime<br class="">+!      write(*,*) 'sproduct_exc out, ngm_g= ',ngm_g<br class="">+!    endif<br class="">+<br class="">+    call stop_clock('sproduct_exc')<br class="">+    return<br class="">+    END SUBROUTINE<br class="">+<br class="">+<br class="">+    SUBROUTINE normalize_exc(a)<br class="">+! this subroutine normalizes the excitonic wave function to 1   <br class="">+    USE kinds, ONLY : DP<br class="">+    use io_global, ONLY : stdout, ionode <br class="">+    use mp_world, ONLY : mpime<br class="">+<br class="">+<br class="">+    implicit none<br class="">+    type(exc) :: a<br class="">+    real(kind=DP) :: prod<br class="">+<br class="">+    logical :: debug<br class="">+    debug=.false. <br class="">+<br class="">+    call start_clock('normalize_exc')<br class="">+<br class="">+    if(debug) then<br class="">+      write(*,*) 'normalize_exc in, mpime=',mpime<br class="">+    endif<br class="">+<br class="">+    call sproduct_exc(a,a,prod)<br class="">+<br class="">+    prod=1/sqrt(prod)<br class="">+<br class="">+    a%a(1:a%npw,1:a%numb_v)= a%a(1:a%npw,1:a%numb_v)*prod<br class="">+ <br class="">+    if(debug) then<br class="">+    ! check normalization'<br class="">+       call sproduct_exc(a,a,prod)<br class="">+       if(ionode) write(stdout,*) 'normalize exc check, prod=',prod<br class="">+    endif <br class="">+<br class="">+    if(debug) then<br class="">+      write(*,*) 'normalize_exc out, mpime=',mpime<br class="">+    endif<br class="">+    <br class="">+    call stop_clock('normalize_exc')<br class="">+<br class="">+    return<br class="">+    END SUBROUTINE<br class="">+    <br class="">+    SUBROUTINE pout_operator_exc(a,i_state)<br class="">+!   this subroutine projects out a component |b> from an excitonic<br class="">+!   wavevector |a> <br class="">+<br class="">+    implicit none<br class="">+    type(exc) :: a<br class="">+    integer   :: i_state, i<br class="">+    real(kind=DP), allocatable :: prod(:)<br class="">+<br class="">+    call start_clock('pout_operator_exc')<br class="">+    allocate(prod(i_state-1))<br class="">+    <br class="">+    do i=1,(i_state-1) <br class="">+       call sproduct_exc(a,bse_spectrum(i),prod(i))<br class="">+    enddo<br class="">+    <br class="">+    do i=1,(i_state-1)<br class="">+       a%a(1:a%npw,1:a%numb_v)=a%a(1:a%npw,1:a%numb_v)-prod(i)*&<br class="">+                      bse_spectrum(i)%a(1:bse_spectrum(i)%npw,1:bse_spectrum(i)%numb_v)<br class="">+    enddo<br class="">+<br class="">+!    call normalize_exc(a)<br class="">+    deallocate(prod)<br class="">+    call stop_clock('pout_operator_exc')<br class="">+    return<br class="">+    END SUBROUTINE<br class="">+<br class="">+    SUBROUTINE fft_a_exc(ag,fc,ar)<br class="">+!   this subroutine performs an FFT to real space of the excitonic wavefunction<br class="">+!   vector using the dual grid<br class="">+    USE kinds, ONLY : DP<br class="">+    USE gvect,                 ONLY : ig_l2g<br class="">+    USE fft_custom_gwl<br class="">+    USE bse_wannier, ONLY : dual_bse <br class="">+    USE wvfct,    ONLY : npwx<br class="">+    USE gvecw,              ONLY : gcutw, ecutwfc<br class="">+    USE io_global, ONLY : stdout, ionode, ionode_id<br class="">+    USE mp_world, ONLY : mpime, nproc<br class="">+    USE mp_pools, ONLY : intra_pool_comm<br class="">+!    USE mp_wave, ONLY : mergewf,splitwf<br class="">+    USE wavefunctions_module, ONLY :  psic<br class="">+<br class="">+<br class="">+    implicit none<br class="">+ <br class="">+    type(exc) ag<br class="">+    type(exc_r) ar<br class="">+    type(fft_cus) :: fc<br class="">+<br class="">+    COMPLEX(kind=DP), allocatable :: ag_t(:,:)<br class="">+    COMPLEX(kind=DP), ALLOCATABLE :: evc_g(:)<br class="">+<br class="">+    integer :: ii<br class="">+<br class="">+! FFT the wannier function to r-space (dual grid)<br class="">+    <br class="">+   call start_clock('fft_a_exc')<br class="">+<br class="">+    allocate(ag_t(fc%npwt,ag%numb_v))<br class="">+    <br class="">+    ar%nrxxt=fc%nrxxt <br class="">+    ar%numb_v=ag%numb_v<br class="">+    ar%label=ag%label<br class="">+<br class="">+    allocate(ar%ar(ar%nrxxt,ar%numb_v))<br class="">+    <br class="">+    allocate(evc_g(fc%ngmt_g )) <br class="">+<br class="">+    if(fc%dual_t==4.d0) then<br class="">+       ag_t(1:fc%npwt,1:ag%numb_v)= ag%a(1:fc%npwt,1:ag%numb_v)<br class="">+    else<br class="">+       call reorderwfp_col(ag%numb_v,ag%npw,fc%npwt,ag%a(1,1),ag_t(1,1),ag%npw ,fc%npwt, &<br class="">+           & ig_l2g,fc%ig_l2gt,fc%ngmt_g,mpime, nproc,intra_pool_comm )<br class="">+<br class="">+!       do ii=1,ag%numb_v<br class="">+!          call mergewf(ag%a(:,ii),evc_g,ag%npw,ig_l2g,mpime,nproc,ionode_id,intra_pool_comm)<br class="">+!          call splitwf(ag_t(:,ii),evc_g,fc%npwt,fc%ig_l2gt,mpime,nproc,ionode_id,intra_pool_comm)<br class="">+!       enddo<br class="">+    endif<br class="">+<br class="">+    do ii=1,ag%numb_v,2<br class="">+       psic(:)=(0.d0,0.d0)<br class="">+       if (ii==ag%numb_v) then<br class="">+          psic(fc%nlt(1:fc%npwt))  = ag_t(1:fc%npwt,ii)<br class="">+          psic(fc%nltm(1:fc%npwt)) = CONJG( ag_t(1:fc%npwt,ii) )<br class="">+       else<br class="">+          psic(fc%nlt(1:fc%npwt))=ag_t(1:fc%npwt,ii)+(0.d0,1.d0)*ag_t(1:fc%npwt,ii+1)<br class="">+          psic(fc%nltm(1:fc%npwt))=CONJG(ag_t(1:fc%npwt,ii))+(0.d0,1.d0)*CONJG(ag_t(1:fc%npwt,ii+1))<br class="">+       endif<br class="">+       CALL cft3t( fc, psic, fc%nr1t, fc%nr2t, fc%nr3t, fc%nrx1t, fc%nrx2t, fc%nrx3t, 2 )<br class="">+       ar%ar(1:fc%nrxxt,ii)= DBLE(psic(1:fc%nrxxt))<br class="">+       if(ii/=ag%numb_v) ar%ar(1:fc%nrxxt,ii+1)= DIMAG(psic(1:fc%nrxxt))<br class="">+    enddo<br class="">+<br class="">+    deallocate(evc_g)<br class="">+    call stop_clock('fft_a_exc')<br class="">+    return<br class="">+    END SUBROUTINE <br class="">+<br class="">+    SUBROUTINE fftback_a_exc(ar,fc,ag)<br class="">+!   this subroutine performs an FFT G space of the excitonic wavefunction<br class="">+!   from the dual R-grid and reorders the wavefunction in the pw grid order <br class="">+    USE kinds, ONLY : DP<br class="">+    USE gvect,                 ONLY : ig_l2g<br class="">+    USE fft_custom_gwl<br class="">+    USE bse_wannier, ONLY : dual_bse <br class="">+    USE wvfct,    ONLY : npwx<br class="">+    USE gvecw,              ONLY : gcutw, ecutwfc<br class="">+    USE io_global, ONLY : stdout, ionode, ionode_id<br class="">+    USE mp_world, ONLY : mpime, nproc<br class="">+    USE mp_pools, ONLY : intra_pool_comm<br class="">+!    USE mp_wave, ONLY : mergewf,splitwf<br class="">+    USE wavefunctions_module, ONLY :  psic<br class="">+<br class="">+<br class="">+    implicit none<br class="">+ <br class="">+    type(exc) ag<br class="">+    type(exc_r) ar<br class="">+    type(fft_cus) :: fc<br class="">+    integer :: ii,iv<br class="">+    COMPLEX(kind=DP), ALLOCATABLE :: evc_g(:)<br class="">+    COMPLEX(kind=DP), allocatable :: ag_t(:,:)<br class="">+<br class="">+<br class="">+! FFT the wannier function to g-space ( from dual grid), and put back in the pw<br class="">+! grid order <br class="">+<br class="">+    call start_clock('fftback_a_exc')<br class="">+    allocate(ag_t(fc%npwt,ar%numb_v))<br class="">+    allocate(evc_g(fc%ngmt_g ))<br class="">+<br class="">+<br class="">+    do iv=1, ag%numb_v,2<br class="">+       if (iv==ag%numb_v) then <br class="">+          psic(1:fc%nrxxt)=dcmplx(ar%ar(1:ar%nrxxt,iv),0.d0)<br class="">+       else<br class="">+          psic(1:fc%nrxxt)=dcmplx(ar%ar(1:fc%nrxxt,iv),ar%ar(1:fc%nrxxt,iv+1))<br class="">+       endif<br class="">+       CALL cft3t(fc, psic, fc%nr1t, fc%nr2t, fc%nr3t, fc%nrx1t, fc%nrx2t, fc%nrx3t, -2 )<br class="">+       if (iv==ag%numb_v) then <br class="">+          ag_t(1:fc%npwt,iv)=psic(fc%nlt(1:fc%npwt))<br class="">+       else<br class="">+          ag_t(1:fc%npwt,iv)=0.5d0*(psic(fc%nlt(1:fc%npwt))+conjg( psic(fc%nltm(1:fc%npwt))))<br class="">+          ag_t(1:fc%npwt,iv+1)=(0.d0,-0.5d0)*(psic(fc%nlt(1:fc%npwt)) - conjg(psic(fc%nltm(1:fc%npwt))))<br class="">+       endif<br class="">+    enddo<br class="">+ <br class="">+    if(fc%dual_t==4.d0) then<br class="">+       ag%a(1:fc%npwt,1:ag%numb_v)=ag_t(1:fc%npwt,1:ag%numb_v)<br class="">+    else<br class="">+        call reorderwfp_col(ag%numb_v,fc%npwt,ag%npw,ag_t(1,1),ag%a(1,1),fc%npwt,ag%npw, &<br class="">+           & fc%ig_l2gt,ig_l2g,fc%ngmt_g,mpime, nproc,intra_pool_comm )<br class="">+<br class="">+!       do iv=1, ag%numb_v<br class="">+!          call mergewf(ag_t(:,iv),evc_g,fc%npwt,fc%ig_l2gt,mpime,nproc,ionode_id,intra_pool_comm)<br class="">+!          call splitwf(ag%a(:,iv),evc_g,ag%npw,ig_l2g,mpime,nproc,ionode_id,intra_pool_comm)<br class="">+!       enddo<br class="">+    endif <br class="">+<br class="">+    deallocate(evc_g)<br class="">+    call stop_clock('fftback_a_exc')<br class="">+    return<br class="">+  END SUBROUTINE fftback_a_exc<br class="">+<br class="">+    SUBROUTINE urot_a(a_in,a_out,itrasp)<br class="">+    USE wvfct,     ONLY : nbnd,npwx<br class="">+    USE bse_basic_structures, ONLY : u_trans<br class="">+    USE lsda_mod,             ONLY : nspin<br class="">+    USE io_global, ONLY : stdout <br class="">+<br class="">+<br class="">+<br class="">+    implicit none <br class="">+    type(exc):: a_in<br class="">+    type(exc):: a_out<br class="">+    integer  :: itrasp ! if 1 takes U^T<br class="">+    REAL(kind=DP), ALLOCATABLE :: tmp_rot(:,:)<br class="">+    logical debug<br class="">+    integer :: ii<br class="">+<br class="">+<br class="">+    call start_clock('urot_a')<br class="">+<br class="">+    debug=.false.<br class="">+    allocate(u_trans(nbnd,nbnd,nspin))<br class="">+    call read_wannier_matrix<br class="">+<br class="">+<br class="">+    allocate(tmp_rot(a_in%numb_v,a_in%numb_v))<br class="">+    tmp_rot(1:a_in%numb_v,1:a_in%numb_v)=dble(u_trans(1:a_in%numb_v,1:a_in%numb_v,1))<br class="">+<br class="">+!DEBUG <br class="">+!    tmp_rot=0.d0<br class="">+!    do ii=1, a_in%numb_v<br class="">+!       tmp_rot(ii,ii)=1.d0<br class="">+!    enddo<br class="">+!fine DEBUG<br class="">+<br class="">+   <br class="">+    if (itrasp==0) call rotate_wannier_gamma_bse(tmp_rot,a_in,a_out,1,0)<br class="">+    if (itrasp==1) call rotate_wannier_gamma_bse(tmp_rot,a_in,a_out,1,1)<br class="">+<br class="">+    deallocate(u_trans)<br class="">+    deallocate(tmp_rot)<br class="">+<br class="">+    call stop_clock('urot_a')<br class="">+    return<br class="">+    END SUBROUTINE <br class="">+     <br class="">+<br class="">+end module  exciton<br class=""><br class="">Added: trunk/espresso/GWW/bse/find_eig.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/find_eig.f90<span class="Apple-tab-span" style="white-space:pre">  </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/find_eig.f90<span class="Apple-tab-span" style="white-space:pre">     </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,197 @@<br class="">+subroutine find_eig(vstate,vstate_r,cstate,wcstate,fc)<br class="">+!this subroutine finds the lowest n_eig eigenvectors and eigenvalues <br class="">+!through the  conjugate gradient or steepest descent minimization scheme<br class="">+!for each eigenvector it computes the optical amplitude and eventually the<br class="">+!excitonic wavefunction<br class="">+<br class="">+USE exciton<br class="">+USE io_global, ONLY : stdout,ionode<br class="">+<br class="">+USE bse_basic_structures<br class="">+USE fft_custom_gwl<br class="">+USE wvfct,    ONLY : npw,npwx,nbnd<br class="">+USE bse_wannier, ONLY:num_nbndv,eps,lambda,maxit,n_eig,l_cgrad,l_plotexc,&<br class="">+                      plotn_min,plotn_max,l_plotaverage,l_restart,l_verbose,&<br class="">+                      n_eig_start,l_finite,l_contraction,l_gtrick<br class="">+USE mp,          ONLY : mp_barrier<br class="">+USE mp_world,             ONLY : world_comm<br class="">+USE constants,   ONLY : RYTOEV<br class="">+USE contract_w<br class="">+USE lsda_mod, ONLY :nspin<br class="">+!USE eqv,         ONLY : dpsi, dvpsi, eprec<br class="">+<br class="">+<br class="">+<br class="">+implicit none<br class="">+!type(exc), allocatable :: bse_spectrum(:)<br class="">+type(v_state) :: vstate<br class="">+type(v_state_r) :: vstate_r<br class="">+type(c_state) :: cstate<br class="">+type(c_state) :: wcstate<br class="">+type(fft_cus) :: fc<br class="">+<br class="">+type(spectrum) :: bse_sp<br class="">+<br class="">+type(v_state) :: psibar(3) ! formula (43) of Rev. Mod. Phys. 73, 515 <br class="">+                           ! for the three polarization directions computed through DFPT <br class="">+integer :: i,nstart,ipol,ispin<br class="">+complex(DP), allocatable:: dvpsi(:,:)<br class="">+<br class="">+real(DP) :: EVTORY<br class="">+<br class="">+<br class="">+<br class="">+EVTORY=1.d0/RYTOEV<br class="">+<br class="">+call start_clock('find_eig')<br class="">+<br class="">+write(stdout,*) 'Routine find_eig'<br class="">+FLUSH(stdout)<br class="">+<br class="">+call initialize_spectrum(bse_sp)<br class="">+<br class="">+if(l_contraction) then<br class="">+   write(stdout,*) 'CALL contract_w_build'<br class="">+   FLUSH(stdout)<br class="">+   call contract_w_build(fc)<br class="">+endif<br class="">+bse_sp%neig=n_eig<br class="">+allocate(bse_sp%en(bse_sp%neig))<br class="">+allocate(bse_sp%a(bse_sp%neig,3))<br class="">+<br class="">+allocate(bse_spectrum(n_eig))<br class="">+<br class="">+if(l_contraction) then<br class="">+! read  iimat<br class="">+   call initialize_imat(iimat_contract)<br class="">+   do ispin=1,nspin<br class="">+      call read_iimat(iimat_contract,ispin)<br class="">+   enddo<br class="">+   write(stdout,*) 'CALL contract_v_build'<br class="">+   call FLUSH(stdout)<br class="">+   call contract_v_build(fc)<br class="">+endif<br class="">+<br class="">+write(stdout,*) 'FIND_EIG 1'<br class="">+call FLUSH(stdout)<br class="">+<br class="">+do i=1,n_eig<br class="">+   call initialize_exc(bse_spectrum(i))<br class="">+   bse_spectrum(i)%npw=npw<br class="">+   bse_spectrum(i)%numb_v=num_nbndv(1)<br class="">+   allocate(bse_spectrum(i)%a(bse_spectrum(i)%npw,bse_spectrum(i)%numb_v)) <br class="">+   bse_spectrum(i)%label=i<br class="">+enddo<br class="">+<br class="">+<br class="">+write(stdout,*) 'FIND_EIG 2'<br class="">+call FLUSH(stdout)<br class="">+<br class="">+if(l_restart==1)then<br class="">+   nstart=n_eig_start<br class="">+   do i=1,n_eig_start-1<br class="">+      call read_exc(i, bse_spectrum(i),l_verbose)<br class="">+      bse_sp%en(i)=bse_spectrum(i)%e*EVTORY<br class="">+   enddo<br class="">+else<br class="">+   nstart=1<br class="">+endif<br class="">+<br class="">+write(stdout,*) 'FIND_EIG 3'<br class="">+call FLUSH(stdout)<br class="">+<br class="">+!compute the eigenfunction and eigenvalues<br class="">+if(l_restart<2) then<br class="">+   do i=nstart,n_eig<br class="">+      if(l_cgrad) then<br class="">+         call conjgrad(i,vstate,vstate_r,cstate,wcstate,fc,bse_sp%en(i)) <br class="">+      else<br class="">+         call sdescent(i,vstate,vstate_r,cstate,wcstate,fc,bse_sp%en(i))<br class="">+      endif<br class="">+      call write_exc(bse_spectrum(i))<br class="">+   enddo<br class="">+else if(l_restart==2) then<br class="">+   do i=1,n_eig<br class="">+      call read_exc(i, bse_spectrum(i),l_verbose)<br class="">+      bse_sp%en(i)=bse_spectrum(i)%e*EVTORY<br class="">+   enddo<br class="">+endif<br class="">+<br class="">+<br class="">+call mp_barrier(world_comm)<br class="">+<br class="">+if(l_gtrick)  call v_wfng_to_wfnr(vstate,fc,vstate_r)<br class="">+<br class="">+!compute the optical amplitudes <br class="">+<br class="">+!compute the  |psibar(iv)><br class="">+if(.not.l_finite) then<br class="">+   allocate (dvpsi ( npwx , num_nbndv(1)))<br class="">+   do ipol=1,3 <br class="">+      call initialize_v_state(psibar(ipol))<br class="">+      psibar(ipol)%nspin= vstate%nspin<br class="">+      psibar(ipol)%numb_v(:)=vstate%numb_v(:)<br class="">+      psibar(ipol)%npw=npw<br class="">+      psibar(ipol)%gstart=vstate%gstart<br class="">+      <br class="">+      allocate( psibar(ipol)%wfn(psibar(ipol)%npw,psibar(ipol)%numb_v(1),psibar(ipol)%nspin))<br class="">+     <br class="">+      call dvpsi_e (1, ipol,dvpsi(1,1))<br class="">+      do i=1,num_nbndv(1)<br class="">+         psibar(ipol)%wfn(1:npw,i,1)&<br class="">+             & = dvpsi(1:npw,i)<br class="">+      enddo<br class="">+   enddo<br class="">+   deallocate (dvpsi)<br class="">+endif<br class="">+call mp_barrier(world_comm)<br class="">+<br class="">+do ipol=1,3<br class="">+   do i=1,n_eig<br class="">+      call absorption(vstate_r,psibar(ipol)%wfn(1,1,1),fc,i,bse_sp%a(i,ipol),ipol)<br class="">+!      if(ionode) write(stdout,*)'Eigv#',i,'E',bse_spectrum(i)%e, 'Amp',bse_sp%a(i)  <br class="">+!      if(ionode) write(stdout,*)'Eigv#',i,'E',bse_sp%en(i), 'Amp',bse_sp%a(i)  <br class="">+   enddo<br class="">+enddo<br class="">+call mp_barrier(world_comm)<br class="">+<br class="">+!build up the spectrum<br class="">+do ipol=1,3<br class="">+   call build_spectrum(bse_sp%a(1,ipol),bse_sp%en(1),ipol)<br class="">+enddo<br class="">+call mp_barrier(world_comm)<br class="">+<br class="">+!plot the excitonic wfn<br class="">+if(l_plotexc) then<br class="">+   if(l_plotaverage) then<br class="">+      call plot_excwfn(plotn_min,plotn_max,vstate_r,fc)<br class="">+   else<br class="">+      do i=plotn_min,plotn_max<br class="">+         call plot_excwfn(i,i,vstate_r,fc)<br class="">+      enddo <br class="">+   endif<br class="">+endif<br class="">+<br class="">+<br class="">+do i=1,n_eig<br class="">+   call free_memory_exc_a(bse_spectrum(i))<br class="">+enddo<br class="">+<br class="">+deallocate(bse_spectrum)<br class="">+<br class="">+call free_memory_spectrum(bse_sp)<br class="">+do ipol=1,3<br class="">+   call free_v_state(psibar(ipol))<br class="">+enddo<br class="">+<br class="">+if(l_contraction) then<br class="">+   call free_memory_contrac_w<br class="">+   call free_imat(iimat_contract)<br class="">+endif<br class="">+<br class="">+call stop_clock('find_eig')<br class="">+return<br class="">+<br class="">+<br class="">+<br class="">+end subroutine<br class=""><br class="">Added: trunk/espresso/GWW/bse/h_h.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/h_h.f90<span class="Apple-tab-span" style="white-space:pre"> </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/h_h.f90<span class="Apple-tab-span" style="white-space:pre">  </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,69 @@<br class="">+!<br class="">+! Copyright (C) 2003-2007 Quantum ESPRESSO group<br class="">+! This file is distributed under the terms of the<br class="">+! GNU General Public License. See the file `License'<br class="">+! in the root directory of the present distribution,<br class="">+! or <a href="http://www.gnu.org/copyleft/gpl.txt" class="">http://www.gnu.org/copyleft/gpl.txt</a> .<br class="">+!<br class="">+!<br class="">+!-----------------------------------------------------------------------<br class="">+SUBROUTINE H_h(e,h,Ah)<br class="">+  !-----------------------------------------------------------------------<br class="">+  !<br class="">+  USE kinds, ONLY: DP<br class="">+!  USE wvfct, ONLY: nbnd, npwx, npw, g2kin, igk<br class="">+  USE wvfct, ONLY: npwx, npw, g2kin, igk<br class="">+  USE gvect, ONLY : gstart<br class="">+  USE uspp,     ONLY : vkb, nkb<br class="">+  USE lsda_mod, ONLY : current_spin<br class="">+  USE scf,      ONLY : vrs<br class="">+  USE becmod, ONLY: bec_type, becp, calbec<br class="">+!  USE cgcom<br class="">+  USE electrons_base, ONLY: nel<br class="">+  use bse_wannier, ONLY:num_nbndv<br class="">+  !<br class="">+  IMPLICIT NONE<br class="">+  !<br class="">+  real(DP):: e(num_nbndv(1))<br class="">+  COMPLEX(DP):: h(npwx,num_nbndv(1)), Ah(npwx,num_nbndv(1))<br class="">+!  real(DP), allocatable     :: e(:)<br class="">+!  COMPLEX(DP), allocatable  :: h(:,:), Ah(:,:)<br class="">+  !<br class="">+  INTEGER:: j,ibnd,nbnd<br class="">+  !<br class="">+  CALL start_clock('h_h')<br class="">+<br class="">+  ! valid only for non-spin resolved calculations<br class="">+  nbnd=num_nbndv(1)<br class="">+<br class="">+  !<br class="">+  ! [(k+G)^2 - e ]psi<br class="">+  DO ibnd = 1,nbnd<br class="">+     ! set to zero the imaginary part of h at G=0<br class="">+     !  needed for numerical stability<br class="">+     IF (gstart==2) h(1,ibnd) = cmplx( dble(h(1,ibnd)),0.d0,kind=DP)<br class="">+     DO j = 1,npw<br class="">+        ah(j,ibnd) = (g2kin(j)-e(ibnd)) * h(j,ibnd)<br class="">+     ENDDO<br class="">+  ENDDO<br class="">+  ! V_Loc psi<br class="">+  CALL vloc_psi_gamma(npwx, npw, nbnd, h, vrs(1,current_spin), ah)<br class="">+  ! V_NL psi<br class="">+   CALL calbec  ( npw, vkb, h, becp, nbnd )<br class="">+  IF (nkb > 0) CALL add_vuspsi (npwx, npw, nbnd, ah)<br class="">+  ! set to zero the imaginary part of ah at G=0<br class="">+  !  needed for numerical stability<br class="">+  IF (gstart==2) THEN<br class="">+     DO ibnd = 1, nbnd<br class="">+        ah(1,ibnd) = cmplx( dble(ah(1,ibnd)),0.d0,kind=DP)<br class="">+     ENDDO<br class="">+  ENDIF<br class="">+<br class="">+!  DEALLOCATE(h)<br class="">+!  DEALLOCATE(Ah)<br class="">+!  DEALLOCATE(e)<br class="">+  !<br class="">+  CALL stop_clock('h_h')<br class="">+  !<br class="">+  RETURN<br class="">+END SUBROUTINE H_h<br class=""><br class="">Added: trunk/espresso/GWW/bse/lanczos.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/lanczos.f90<span class="Apple-tab-span" style="white-space:pre">        </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/lanczos.f90<span class="Apple-tab-span" style="white-space:pre">      </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,426 @@<br class="">+subroutine lanczos(vstate,vstate_r,cstate,wcstate,fc)<br class="">+!this subroutine computes the absorption spectrum through the lanczos procedure<br class="">+USE exciton<br class="">+<br class="">+USE bse_basic_structures<br class="">+USE fft_custom_gwl<br class="">+USE bse_wannier, ONLY: nit_lcz, l_contraction<br class="">+USE contract_w<br class="">+USE lsda_mod, ONLY :nspin<br class="">+USE io_global, ONLY : stdout<br class="">+<br class="">+implicit none<br class="">+type(v_state),   intent(in) :: vstate<br class="">+type(v_state_r), intent(in) :: vstate_r<br class="">+type(c_state),   intent(in) :: cstate<br class="">+type(c_state),   intent(in) :: wcstate<br class="">+type(fft_cus),   intent(in) :: fc<br class="">+<br class="">+<br class="">+real(kind=DP), allocatable :: a(:,:),b(:,:)<br class="">+integer :: ispin<br class="">+<br class="">+call start_clock('lanczos')<br class="">+allocate (a(nit_lcz,3))<br class="">+allocate (b(nit_lcz,3))<br class="">+if(l_contraction) then<br class="">+   write(stdout,*) 'CALL contract_w_build'<br class="">+   FLUSH(stdout)<br class="">+   call contract_w_build(fc)<br class="">+   call initialize_imat(iimat_contract)<br class="">+   do ispin=1,nspin<br class="">+      call read_iimat(iimat_contract,ispin)<br class="">+   enddo<br class="">+   write(stdout,*) 'CALL contract_v_build'<br class="">+   FLUSH(stdout)<br class="">+   call contract_v_build(fc)<br class="">+<br class="">+endif<br class="">+<br class="">+<br class="">+!perform lanczos iterations<br class="">+<br class="">+call lanczos_iterations(vstate,vstate_r,cstate,wcstate,fc,a(1,1),b(1,1))<br class="">+<br class="">+!build the continuum fraction<br class="">+<br class="">+call lanczos_cf(a(1,1),b(1,1))<br class="">+<br class="">+if(l_contraction) then<br class="">+   call free_memory_contrac_w<br class="">+   call free_imat(iimat_contract)<br class="">+endif<br class="">+<br class="">+deallocate(a)<br class="">+deallocate(b)<br class="">+<br class="">+call stop_clock('lanczos')<br class="">+return<br class="">+end subroutine<br class="">+<br class="">+subroutine lanczos_iterations(vstate,vstate_r,cstate,wcstate,fc,a,b)<br class="">+!this subroutine computes the lanczos iteration to get the a(i) and b(i) for the<br class="">+!continued fraction<br class="">+<br class="">+USE exciton<br class="">+<br class="">+USE bse_basic_structures<br class="">+USE fft_custom_gwl<br class="">+USE wvfct,       ONLY : npw,npwx,nbnd<br class="">+USE bse_wannier, ONLY: num_nbndv, nit_lcz,l_restart_lcz, nlcz_restart<br class="">+USE mp,          ONLY : mp_barrier,mp_bcast<br class="">+USE mp_world,    ONLY : world_comm,mpime<br class="">+USE io_global,   ONLY : ionode,ionode_id<br class="">+use io_files,    ONLY : tmp_dir, prefix<br class="">+<br class="">+<br class="">+implicit none<br class="">+INTEGER, EXTERNAL :: find_free_unit<br class="">+type(v_state),   intent(in) :: vstate<br class="">+type(v_state_r), intent(in) :: vstate_r<br class="">+type(c_state),   intent(in) :: cstate<br class="">+type(c_state),   intent(in) :: wcstate<br class="">+type(fft_cus),   intent(in) :: fc<br class="">+<br class="">+integer :: i,ipol,j,is,iunab,iuni,nstart<br class="">+complex(DP), allocatable:: dvpsi(:,:) !formula (43) of Rev. Mod. Phys. 73, 515 <br class="">+<br class="">+<br class="">+type(exc) im1_s ! |i-1> <br class="">+type(exc) i_s ! |i><br class="">+type(exc) ip1_s ! |i+1><br class="">+<br class="">+real(kind=DP) :: bi,bim1<br class="">+real(kind=DP), intent(inout) :: a(nit_lcz,3),b(nit_lcz,3)<br class="">+CHARACTER(5) :: nproc<br class="">+CHARACTER(5) :: nfile<br class="">+<br class="">+logical :: debug<br class="">+<br class="">+call start_clock('lanczos_iterations')<br class="">+debug=.true.<br class="">+<br class="">+call initialize_exc(im1_s)<br class="">+im1_s%label=1<br class="">+im1_s%npw=npw<br class="">+im1_s%numb_v=num_nbndv(1)<br class="">+allocate(im1_s%a(im1_s%npw,im1_s%numb_v))<br class="">+<br class="">+call initialize_exc(i_s)<br class="">+i_s%label=1<br class="">+i_s%npw=npw<br class="">+i_s%numb_v=num_nbndv(1)<br class="">+allocate(i_s%a(i_s%npw,i_s%numb_v))<br class="">+<br class="">+call initialize_exc(ip1_s)<br class="">+ip1_s%label=1<br class="">+ip1_s%npw=npw<br class="">+ip1_s%numb_v=num_nbndv(1)<br class="">+allocate(ip1_s%a(ip1_s%npw,ip1_s%numb_v))<br class="">+<br class="">+allocate (dvpsi ( npwx , num_nbndv(1)))<br class="">+<br class="">+if(l_restart_lcz) then<br class="">+   if(ionode) then<br class="">+      if(debug) write(*,*) 'Restarting lanczos'<br class="">+      iunab = find_free_unit()<br class="">+      open(unit=iunab, file=trim(tmp_dir)//trim(prefix)//'.lczrestart_ab.dat', status='unknown', form='unformatted')<br class="">+      read(iunab) a(1:nlcz_restart,1), a(1:nlcz_restart,2), a(1:nlcz_restart,3)<br class="">+      read(iunab) b(1:nlcz_restart,1), b(1:nlcz_restart,2), b(1:nlcz_restart,3)<br class="">+      close(iunab)<br class="">+   endif<br class="">+   call mp_bcast(a(1:(nlcz_restart),1:3),ionode_id, world_comm)<br class="">+   call mp_bcast(b(1:(nlcz_restart),1:3),ionode_id, world_comm)<br class="">+endif<br class="">+<br class="">+do ipol=1,3 <br class="">+<br class="">+   if(.not.l_restart_lcz) then<br class="">+!     compute the  |psibar(iv)> and set it as initial excitonic state |i-1> for <br class="">+!     the lanczos procedure<br class="">+      if(debug) write(*,*) 'before dvpsi'<br class="">+      call dvpsi_e (1, ipol,dvpsi(1,1))<br class="">+      if(debug) write(*,*) 'after dvpsi'<br class="">+      do i=1,num_nbndv(1)<br class="">+         im1_s%a(1:npw,i)= dvpsi(1:npw,i)<br class="">+      enddo<br class="">+<br class="">+      call normalize_exc(im1_s)<br class="">+      if(debug) write(*,*) 'after normalize_exc'<br class="">+ <br class="">+!     apply the exc Hamiltonian  <br class="">+      call exc_h_a(im1_s,i_s,vstate,vstate_r,cstate,wcstate,fc) <br class="">+      if(debug) write(*,*) 'after exc_h_a'<br class="">+<br class="">+!     a(1)= <1|H|1><br class="">+      call sproduct_exc(im1_s,i_s,a(1,ipol))<br class="">+<br class="">+      do i=1,num_nbndv(1)<br class="">+         i_s%a(1:npw,i)=i_s%a(1:npw,i)-dcmplx(a(1,ipol),0.d0)*im1_s%a(1:npw,i)<br class="">+      enddo<br class="">+<br class="">+!     b(1)=bim1=|H|1>-a(1)|1>|<br class="">+      call sproduct_exc(i_s,i_s,bim1)<br class="">+      b(1,ipol)=sqrt(bim1)<br class="">+<br class="">+!     project into the conduction manifold<br class="">+      do is = 1,vstate%nspin<br class="">+         call pc_operator_exc(i_s,vstate,is)<br class="">+      enddo<br class="">+ <br class="">+!     and normalize <br class="">+      call normalize_exc(i_s)<br class="">+<br class="">+<br class="">+!     apply the exc Hamiltonian  <br class="">+      call exc_h_a(i_s,ip1_s,vstate,vstate_r,cstate,wcstate,fc) <br class="">+   <br class="">+!     a(2)= <2|H|2><br class="">+      call sproduct_exc(i_s,ip1_s,a(2,ipol))<br class="">+<br class="">+      do i=1,num_nbndv(1)<br class="">+         ip1_s%a(1:npw,i)=ip1_s%a(1:npw,i)-dcmplx(a(2,ipol),0.d0)*i_s%a(1:npw,i)-dcmplx(b(1,ipol),0.d0)*im1_s%a(1:npw,i)<br class="">+      enddo<br class="">+<br class="">+!    b(2)=bi=|H|2>-a(2)|2>-b(1)|1>|<br class="">+      call sproduct_exc(ip1_s,ip1_s,bi)<br class="">+      b(2,ipol)=sqrt(bi)<br class="">+<br class="">+!     project into the conduction manifold<br class="">+      do is = 1,vstate%nspin<br class="">+         call pc_operator_exc(ip1_s,vstate,is)<br class="">+      enddo<br class="">+ <br class="">+!     and normalize <br class="">+      call normalize_exc(ip1_s)<br class="">+      nstart=3<br class="">+    else<br class="">+!   read starting excitonic vector<br class="">+      nstart=nlcz_restart+1<br class="">+      iuni = find_free_unit()<br class="">+      write(nproc,'(5i1)') &<br class="">+              & mpime/10000,mod(mpime,10000)/1000,mod(mpime,1000)/100,mod(mpime,100)/10,mod(mpime,10)<br class="">+      write(nfile,'(5i1)') &<br class="">+           & ipol/10000,mod(ipol,10000)/1000,mod(ipol,1000)/100,mod(ipol,100)/10,mod(ipol,10)<br class="">+      open( unit=iuni, file=trim(tmp_dir)//trim(prefix)//'.lcz_is.'// nfile //'.'// nproc , status='unknown',form='unformatted')<br class="">+      read(iuni) i_s%label<br class="">+      read(iuni) i_s%npw<br class="">+      read(iuni) i_s%numb_v<br class="">+      read(iuni) i_s%e<br class="">+      do j=1,i_s%numb_v<br class="">+         read(iuni)  i_s%a(1:i_s%npw,j)<br class="">+      enddo<br class="">+      close(iuni)<br class="">+<br class="">+      iuni = find_free_unit()<br class="">+      write(nproc,'(5i1)') &<br class="">+              & mpime/10000,mod(mpime,10000)/1000,mod(mpime,1000)/100,mod(mpime,100)/10,mod(mpime,10)<br class="">+      write(nfile,'(5i1)') &<br class="">+           & ipol/10000,mod(ipol,10000)/1000,mod(ipol,1000)/100,mod(ipol,100)/10,mod(ipol,10)<br class="">+      open( unit=iuni, file=trim(tmp_dir)//trim(prefix)//'.lcz_ip1s.'// nfile //'.'// nproc , status='unknown',form='unformatted')<br class="">+      read(iuni) ip1_s%label<br class="">+      read(iuni) ip1_s%npw<br class="">+      read(iuni) ip1_s%numb_v<br class="">+      read(iuni) ip1_s%e<br class="">+      do j=1,ip1_s%numb_v<br class="">+         read(iuni)  ip1_s%a(1:ip1_s%npw,j)<br class="">+      enddo<br class="">+      close(iuni)<br class="">+    endif<br class="">+<br class="">+!   Now start lanczos iteration<br class="">+<br class="">+    do j=nstart,nit_lcz<br class="">+<br class="">+      if(ionode.and.(mod(j,10)==0)) write(*,*) 'lanczos iteration #', j<br class="">+      do i=1,num_nbndv(1)<br class="">+         im1_s%a(1:npw,i)=i_s%a(1:npw,i) ! |j-1>=|j><br class="">+      enddo<br class="">+<br class="">+      do i=1,num_nbndv(1)<br class="">+         i_s%a(1:npw,i)=ip1_s%a(1:npw,i) ! |j>=|j+1><br class="">+      enddo<br class="">+     <br class="">+!     apply the exc Hamiltonian  <br class="">+      call exc_h_a(i_s,ip1_s,vstate,vstate_r,cstate,wcstate,fc) <br class="">+   <br class="">+!     a(j)= <j|H|j><br class="">+      call sproduct_exc(i_s,ip1_s,a(j,ipol))<br class="">+<br class="">+      do i=1,num_nbndv(1)<br class="">+         ip1_s%a(1:npw,i)=ip1_s%a(1:npw,i)-dcmplx(a(j,ipol),0.d0)*i_s%a(1:npw,i)&<br class="">+                          -dcmplx(b(j-1,ipol),0.d0)*im1_s%a(1:npw,i)<br class="">+      enddo<br class="">+<br class="">+!     b(j)=|H|j>-a(j)|j>-b(j-1)|j-1>|<br class="">+      call sproduct_exc(ip1_s,ip1_s,bi)<br class="">+      b(j,ipol)=sqrt(bi)<br class="">+<br class="">+!     project into the conduction manifold<br class="">+      do is = 1,vstate%nspin<br class="">+         call pc_operator_exc(ip1_s,vstate,is)<br class="">+      enddo<br class="">+ <br class="">+!     and normalize <br class="">+      call normalize_exc(ip1_s)<br class="">+     <br class="">+      call mp_barrier(world_comm)<br class="">+    enddo ! end of lanczos iterations<br class="">+<br class="">+!    write restart information on file<br class="">+<br class="">+   iuni = find_free_unit()<br class="">+   write(nproc,'(5i1)') &<br class="">+           & mpime/10000,mod(mpime,10000)/1000,mod(mpime,1000)/100,mod(mpime,100)/10,mod(mpime,10)<br class="">+   write(nfile,'(5i1)') &<br class="">+        & ipol/10000,mod(ipol,10000)/1000,mod(ipol,1000)/100,mod(ipol,100)/10,mod(ipol,10)<br class="">+   open( unit=iuni, file=trim(tmp_dir)//trim(prefix)//'.lcz_is.'// nfile //'.'// nproc , status='unknown',form='unformatted')<br class="">+   write(iuni) i_s%label<br class="">+   write(iuni) i_s%npw<br class="">+   write(iuni) i_s%numb_v<br class="">+   write(iuni) i_s%e<br class="">+   do j=1,i_s%numb_v<br class="">+      write(iuni)  i_s%a(1:i_s%npw,j)<br class="">+   enddo<br class="">+   close(iuni)<br class="">+<br class="">+   iuni = find_free_unit()<br class="">+   write(nproc,'(5i1)') &<br class="">+           & mpime/10000,mod(mpime,10000)/1000,mod(mpime,1000)/100,mod(mpime,100)/10,mod(mpime,10)<br class="">+   write(nfile,'(5i1)') &<br class="">+        & ipol/10000,mod(ipol,10000)/1000,mod(ipol,1000)/100,mod(ipol,100)/10,mod(ipol,10)<br class="">+   open( unit=iuni, file=trim(tmp_dir)//trim(prefix)//'.lcz_ip1s.'// nfile //'.'// nproc , status='unknown',form='unformatted')<br class="">+   write(iuni) ip1_s%label<br class="">+   write(iuni) ip1_s%npw<br class="">+   write(iuni) ip1_s%numb_v<br class="">+   write(iuni) ip1_s%e<br class="">+   do j=1,ip1_s%numb_v<br class="">+      write(iuni)  ip1_s%a(1:ip1_s%npw,j)<br class="">+   enddo<br class="">+   close(iuni)<br class="">+<br class="">+enddo !ipol<br class="">+<br class="">+!    write restart information on file<br class="">+if(ionode) then<br class="">+      iunab = find_free_unit()<br class="">+      open(unit=iunab, file=trim(tmp_dir)//trim(prefix)//'.lczrestart_ab.dat', status='unknown', form='unformatted')<br class="">+      write(iunab) a(1:nit_lcz,1), a(1:nit_lcz,2), a(1:nit_lcz,3)<br class="">+      write(iunab) b(1:nit_lcz,1), b(1:nit_lcz,2), b(1:nit_lcz,3)<br class="">+      close(iunab)<br class="">+endif<br class="">+<br class="">+if(debug) then<br class="">+   if(ionode) then<br class="">+     do ipol=1,3<br class="">+       do j=1,nit_lcz<br class="">+         write(*,*) 'ipol, it, a', ipol, j, a(j,ipol)<br class="">+       enddo<br class="">+     enddo<br class="">+     do ipol=1,3<br class="">+       do j=1,nit_lcz<br class="">+         write(*,*) 'ipol, it, b', ipol, j, b(j,ipol)<br class="">+       enddo<br class="">+     enddo<br class="">+    endif<br class="">+endif <br class="">+<br class="">+!free memory<br class="">+deallocate (dvpsi)<br class="">+call free_memory_exc_a(im1_s)<br class="">+call free_memory_exc_a(i_s)<br class="">+call free_memory_exc_a(ip1_s)<br class="">+<br class="">+call stop_clock('lanczos_iterations')<br class="">+return<br class="">+end subroutine<br class="">+<br class="">+<br class="">+subroutine lanczos_cf(a,b)<br class="">+<br class="">+USE bse_wannier, ONLY: nit_lcz, spectra_e_min,spectra_e_max,spectra_nstep<br class="">+USE constants,   ONLY : RYTOEV, PI<br class="">+USE kinds,       ONLY: DP<br class="">+USE io_global, ONLY : ionode<br class="">+<br class="">+implicit none<br class="">+real(DP), intent(in) :: a(nit_lcz,3),b(nit_lcz,3)<br class="">+<br class="">+complex(DP), allocatable      :: comega_g(:)<br class="">+complex(DP), allocatable      :: den(:)<br class="">+real(DP), allocatable         :: abss(:,:)    ! epsilon2<br class="">+real(DP), allocatable         :: rp_abss(:,:) ! epsilon1<br class="">+real(DP)                      :: eta,step,e_start<br class="">+<br class="">+integer :: ipol,j,i<br class="">+logical :: debug, im<br class="">+<br class="">+call start_clock('lanczos_cf')<br class="">+debug=.false.<br class="">+eta=0.001d0<br class="">+<br class="">+allocate(comega_g(spectra_nstep))<br class="">+allocate(den(spectra_nstep))<br class="">+allocate(abss(spectra_nstep,3))<br class="">+allocate(rp_abss(spectra_nstep,3))<br class="">+<br class="">+!build the energy grid (including a small imaginary part eta)<br class="">+step=(spectra_e_max-spectra_e_min)/(dble(spectra_nstep-1)*RYTOEV)<br class="">+e_start=spectra_e_min/RYTOEV<br class="">+<br class="">+do i=0, spectra_nstep-1<br class="">+   comega_g(i+1)=dcmplx((e_start+dble(i)*step),eta)<br class="">+enddo<br class="">+<br class="">+do ipol=1,3<br class="">+!  build the continued fraction<br class="">+   <br class="">+   den(1:spectra_nstep)=comega_g(1:spectra_nstep)-dcmplx(a(nit_lcz,ipol),0.d0)<br class="">+<br class="">+   if((debug).and.(ionode)) then<br class="">+            write(*,*) 'ipol, den'<br class="">+         do i=1,spectra_nstep<br class="">+            write(*,'(I1,I6,2F8.4)') ipol, i, real(den(i)), aimag(den(i))<br class="">+      enddo<br class="">+   endif <br class="">+<br class="">+   do j=nit_lcz-1,1,-1<br class="">+      den(1:spectra_nstep)= comega_g(1:spectra_nstep)&<br class="">+                            -dcmplx(a(j,ipol),0.d0)&<br class="">+                            -dcmplx(b(j,ipol)**2.d0,0.d0)/den(1:spectra_nstep)<br class="">+<br class="">+      if((debug).and.(ionode)) then<br class="">+            write(*,*) 'ipol, den'<br class="">+         do i=1,spectra_nstep<br class="">+            write(*,'(I1,I6,2F8.4)') ipol, i, real(den(i)), aimag(den(i))<br class="">+         enddo<br class="">+      endif <br class="">+<br class="">+   enddo<br class="">+<br class="">+   abss(1:spectra_nstep,ipol)=-4*PI*aimag(dcmplx(1.d0,0.d0)/den(1:spectra_nstep))<br class="">+   rp_abss(1:spectra_nstep,ipol)=1.d0-4*PI*real(dcmplx(1.d0,0.d0)/den(1:spectra_nstep))<br class="">+<br class="">+   if((debug).and.(ionode)) then<br class="">+     write(*,*) 'ABSORPTION ipol', ipol<br class="">+     do i=1,spectra_nstep<br class="">+        write(*,'(I6,F8.4,F12.4)') i, real(comega_g(i))*RYTOEV, abss(i,ipol)<br class="">+     enddo<br class="">+   endif <br class="">+<br class="">+<br class="">+enddo !ipol<br class="">+im=.true.<br class="">+call print_spectrum(abss,im)<br class="">+im=.false.<br class="">+call print_spectrum(rp_abss,im)<br class="">+<br class="">+<br class="">+deallocate(comega_g)<br class="">+deallocate(den)<br class="">+deallocate(abss)<br class="">+<br class="">+call stop_clock('lanczos_cf')<br class="">+return<br class="">+end subroutine<br class="">+<br class=""><br class="">Added: trunk/espresso/GWW/bse/openfil_bse.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/openfil_bse.f90<span class="Apple-tab-span" style="white-space:pre">    </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/openfil_bse.f90<span class="Apple-tab-span" style="white-space:pre">  </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,39 @@<br class="">+SUBROUTINE openfil_bse()<br class="">+!<br class="">+! ... This routine opens all files needed to the self consistent run,<br class="">+! ... sets various file names, units, record lengths<br class="">+  USE wvfct,          ONLY : nbnd, npwx<br class="">+  use control_flags,  ONLY:  twfcollect<br class="">+  USE io_files,       ONLY : prefix, iunwfc, nwordwfc,nwordatwfc, diropn<br class="">+  USE noncollin_module, ONLY : npol<br class="">+  USE basis,            ONLY : natomwfc<br class="">+  USE ions_base,        ONLY : nat, ityp<br class="">+  USE noncollin_module,   ONLY : noncolin<br class="">+  USE uspp_param,         ONLY : n_atom_wfc<br class="">+<br class="">+<br class="">+<br class="">+  IMPLICIT NONE<br class="">+  !<br class="">+  LOGICAL       :: exst<br class="">+  !<br class="">+  !<br class="">+  twfcollect=.false.<br class="">+  !<br class="">+  ! ... nwordwfc is the record length for the direct-access file<br class="">+  ! ... containing wavefunctions<br class="">+  !<br class="">+  nwordwfc = nbnd * npwx * npol<br class="">+  !<br class="">+  CALL diropn( iunwfc, 'wfc', 2*nwordwfc, exst )<br class="">+  !<br class="">+  IF ( .NOT. exst ) THEN<br class="">+     call errore ('openfil_pw4gww','file '//TRIM( prefix )//'.wfc'//' not found',1)     <br class="">+  END IF<br class="">+  natomwfc = n_atom_wfc( nat, ityp, noncolin )<br class="">+  nwordatwfc = 2*npwx*natomwfc*npol<br class="">+<br class="">+  RETURN<br class="">+  !<br class="">+END SUBROUTINE openfil_bse<br class="">+<br class=""><br class="">Added: trunk/espresso/GWW/bse/plot_excwfn.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/plot_excwfn.f90<span class="Apple-tab-span" style="white-space:pre"> </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/plot_excwfn.f90<span class="Apple-tab-span" style="white-space:pre">  </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,182 @@<br class="">+subroutine plot_excwfn(nstart,nend,vstate_r,fc)<br class="">+! this subroutine computes and writes on file the nplot-th excitonic wavefunction<br class="">+! to be read by pp.x<br class="">+! note that this subroutine is working only for gamma only calculations <br class="">+<br class="">+USE exciton<br class="">+USE bse_wannier, ONLY:num_nbndv,&<br class="">+                      r_hole,l_plotaverage<br class="">+use bse_basic_structures<br class="">+USE pwcom<br class="">+USE fft_custom_gwl<br class="">+USE io_global, ONLY : stdout,ionode,ionode_id<br class="">+USE io_files, ONLY : tmp_dir,prefix<br class="">+USE mp_world, ONLY : mpime, nproc<br class="">+USE mp, ONLY: mp_sum<br class="">+USE mp_world,             ONLY : world_comm<br class="">+!USE io_files, ONLY : find_free_unit<br class="">+USE ions_base,      ONLY : nat, tau, atm,ityp<br class="">+ <br class="">+implicit none<br class="">+INTEGER, EXTERNAL :: find_free_unit<br class="">+<br class="">+integer :: nplot,nstart,nend<br class="">+type(v_state_r) :: vstate_r<br class="">+type(exc_r) :: a_rt<br class="">+type(fft_cus) :: fc<br class="">+<br class="">+integer ::nxh,nyh,nzh,nh<br class="">+INTEGER :: nr3s_start, nr3s_end<br class="">+real(kind=dp), allocatable :: psi_exc(:)<br class="">+real(kind=dp), allocatable :: psi_excio(:)<br class="">+real(kind=dp), allocatable :: psi_excsum(:)<br class="">+real(kind=dp), allocatable :: v_rh(:)<br class="">+<br class="">+integer :: iv,ii,iplane,iz,ounit,ix,iy,iip<br class="">+logical :: debug<br class="">+<br class="">+CHARACTER(5) :: nfile<br class="">+<br class="">+call start_clock('plot_excwfn')<br class="">+debug=.true.<br class="">+<br class="">+!check if all variables are ok from read_file in main <br class="">+if (debug) then<br class="">+   if(ionode) then<br class="">+      !bg(:,i) are the reciprocal lattice vectors, b_i,<br class="">+      !in tpiba=2pi/alat units: b_i(:) = bg(:,i)/tpiba<br class="">+      !at(:,i) are the lattice vectors of the simulation cell, a_i,<br class="">+      !in alat units: a_i(:) = at(:,i)/alat<br class="">+      write(stdout,*) 'plotexcwfn bg(:,1)=',bg(1,1),bg(2,1),bg(3,1)<br class="">+      write(stdout,*) 'plotexcwfn bg(:,2)=',bg(1,2),bg(2,2),bg(3,2)<br class="">+      write(stdout,*) 'plotexcwfn bg(:,3)=',bg(1,3),bg(2,3),bg(3,3)<br class="">+      write(stdout,*) 'plotexcwfn alat=',alat<br class="">+   endif<br class="">+endif<br class="">+<br class="">+!find FFT grid point (dual grid) closer to r_hole (given in alat units)<br class="">+<br class="">+nxh = nint ( (r_hole(1)*bg(1,1) + r_hole(2)*bg(2,1) + r_hole(3)*bg(3,1) )*fc%nr1t) + 1<br class="">+nyh = nint ( (r_hole(1)*bg(1,2) + r_hole(2)*bg(2,2) + r_hole(3)*bg(3,2) )*fc%nr2t) + 1<br class="">+nzh = nint ( (r_hole(1)*bg(1,3) + r_hole(2)*bg(2,3) + r_hole(3)*bg(3,3) )*fc%nr3t) + 1<br class="">+<br class="">+allocate(v_rh(num_nbndv(1)))<br class="">+v_rh(:)=0.d0<br class="">+<br class="">+<br class="">+!get the valence wavefunctions at the nxh,nyh,nzh (only one processor has it!) <br class="">+#ifndef __PARA<br class="">+nh=(nzh-1)*fc%nrx1t*fc%nrx2t+(nyh-1)*fc%nrx1t+nxh<br class="">+v_rh(:)=v_rt%wfnrt(nh,:,1)<br class="">+#else<br class="">+nr3s_start=0<br class="">+nr3s_end =0<br class="">+do ii=1,mpime+1<br class="">+   nr3s_start=nr3s_end+1<br class="">+   nr3s_end=nr3s_end+fc%dfftt%npp(ii)<br class="">+enddo<br class="">+<br class="">+<br class="">+do iplane=1,fc%dfftt%npp(mpime+1)<br class="">+   iz=nr3s_start+iplane-1<br class="">+   if (iz==nzh) then<br class="">+      nh=(iplane-1)*fc%nrx1t*fc%nrx2t+(nyh-1)*fc%nrx1t+nxh<br class="">+      v_rh(:)=vstate_r%wfnrt(nh,:,1)<br class="">+   endif<br class="">+enddo<br class="">+call mp_sum(v_rh,world_comm)<br class="">+#endif<br class="">+<br class="">+<br class="">+if (debug) then<br class="">+   if(ionode) write(stdout,*) 'plotexcwfn qui'<br class="">+endif<br class="">+!stop<br class="">+<br class="">+!allocate and initialize the excitonic wavefunction <br class="">+allocate(psi_exc(fc%nrxxt))<br class="">+psi_exc(1:fc%nrxxt)=0.d0<br class="">+<br class="">+allocate(psi_excsum(fc%nrx1t*fc%nrx2t*fc%nrx3t))<br class="">+psi_excsum(1:fc%nrx1t*fc%nrx2t*fc%nrx3t)=0.d0<br class="">+<br class="">+do nplot=nstart,nend<br class="">+if (debug) then<br class="">+   if(ionode) write(stdout,*) 'plotexcwfn qui2',nplot<br class="">+endif<br class="">+!<br class="">+!FFT the excitonic wavefunction vector to real space (dual grid)<br class="">+   call initialize_exc_r(a_rt)<br class="">+   call fft_a_exc(bse_spectrum(nplot),fc,a_rt)<br class="">+<br class="">+!now compute the exitonic wavefunction<br class="">+   do iv=1,num_nbndv(1)<br class="">+      psi_exc(1:fc%nrxxt)=psi_exc(1:fc%nrxxt)+v_rh(iv)*&<br class="">+                                           a_rt%ar(1:a_rt%nrxxt,iv)<br class="">+   enddo<br class="">+<br class="">+if (debug) then<br class="">+   if(ionode) write(stdout,*) 'plotexcwfn qui3',nplot<br class="">+endif<br class="">+!square modulus<br class="">+   psi_exc(1:fc%nrxxt)=psi_exc(1:fc%nrxxt)**2<br class="">+<br class="">+   if(debug) then<br class="">+      if(ionode) write(stdout,*) 'fc%nr1t, fc%nr2t, fc%nr3t', fc%nr1t, fc%nr2t, fc%nr3t<br class="">+      if(ionode) write(stdout,*) 'fc%nrx1t, fc%nrx2t, fc%nrx3t', fc%nrx1t, fc%nrx2t, fc%nrx3t<br class="">+   endif<br class="">+<br class="">+!Now gather the excitonic wavefunction from all the processors<br class="">+!and sum for the l_plotaverage case (when nstart is different from nend) <br class="">+<br class="">+   allocate(psi_excio(fc%nrx1t*fc%nrx2t*fc%nrx3t))<br class="">+<br class="">+   psi_excio(1:fc%nrx1t*fc%nrx3t*fc%nrx3t)=0.d0<br class="">+   do iplane=1,fc%dfftt%npp(mpime+1)<br class="">+     iz=nr3s_start+iplane-1<br class="">+     do iy=1,fc%nr2t<br class="">+        do ix=1,fc%nr1t<br class="">+           ii=(iz-1)*(fc%nrx1t*fc%nrx2t)+(iy-1)*fc%nrx1t+ix<br class="">+           iip=(iplane-1)*fc%nrx1t*fc%nrx2t+(iy-1)*fc%nrx1t+ix<br class="">+           psi_excio(ii)=psi_exc(iip) <br class="">+        enddo<br class="">+     enddo <br class="">+   enddo<br class="">+   call mp_sum(psi_excio,world_comm)<br class="">+<br class="">+   psi_excsum(1:fc%nrx1t*fc%nrx3t*fc%nrx3t)=psi_excsum(1:fc%nrx1t*fc%nrx3t*fc%nrx3t)+&<br class="">+                      psi_excio(1:fc%nrx1t*fc%nrx3t*fc%nrx3t)/(real(nend)-real(nstart)+1.d0)<br class="">+<br class="">+   if (debug) then<br class="">+      if(ionode) write(stdout,*) 'plotexcwfn qui3',nplot<br class="">+   endif<br class="">+   call free_memory_exc_a_r(a_rt)<br class="">+   deallocate(psi_excio)<br class="">+enddo ! nplot<br class="">+<br class="">+<br class="">+!<br class="">+! XCRYSDEN FORMAT<br class="">+!<br class="">+if(ionode) then<br class="">+   ounit=find_free_unit()<br class="">+!   open(ounit,file='exc_average.xsf',form='formatted')<br class="">+   if(l_plotaverage)   open(ounit,file='exc_average.xsf',form='formatted')<br class="">+   if(.not.l_plotaverage)   then<br class="">+       write(nfile,'(5i1)') &<br class="">+        & nstart/10000,mod(nstart,10000)/1000,mod(nstart,1000)/100,mod(nstart,100)/10,mod(nstart,10)<br class="">+      open(ounit,file=trim(tmp_dir)//trim(prefix)//'.exc.xsf'//nfile,form='formatted')<br class="">+   endif<br class="">+   CALL xsf_struct (alat, at, nat, tau, atm, ityp, ounit)<br class="">+   CALL xsf_fast_datagrid_3d &<br class="">+             (psi_excsum, fc%nr1t, fc%nr2t, fc%nr3t, fc%nrx1t, fc%nrx2t, fc%nrx3t, at, alat, ounit)<br class="">+!   close(ounit)   <br class="">+endif<br class="">+<br class="">+<br class="">+deallocate(v_rh,psi_exc)<br class="">+<br class="">+deallocate(psi_excsum)<br class="">+<br class="">+call stop_clock('plot_excwfn')<br class="">+end subroutine plot_excwfn<br class=""><br class="">Added: trunk/espresso/GWW/bse/print_bse.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/print_bse.f90<span class="Apple-tab-span" style="white-space:pre">     </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/print_bse.f90<span class="Apple-tab-span" style="white-space:pre">    </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,24 @@<br class="">+subroutine print_bseinfo()<br class="">+!prints basic info from the BSE input file<br class="">+USE io_global, ONLY : ionode<br class="">+USE bse_wannier, ONLY : l_truncated_coulomb, truncation_radius, &<br class="">+           numw_prod,&<br class="">+           dual_bse,&<br class="">+           lambda,eps,&<br class="">+           l_cgrad,maxit,n_eig,eps_eig, scissor,&<br class="">+           l_plotexc,plotn_min,plotn_max,r_hole,l_plotaverage,&<br class="">+           spectra_e_min,spectra_e_max,spectra_broad,&<br class="">+           l_restart,n_eig_start, nit_lcz,l_lanczos<br class="">+implicit none<br class="">+<br class="">+if(ionode) then<br class="">+   write(*,*) 'Dimension of the polarizability basis:', numw_prod<br class="">+   write(*,*) 'Scissor operator (eV)=', scissor<br class="">+   if(l_truncated_coulomb) then<br class="">+      write(*,*) 'Using truncated Coulomb interaction'<br class="">+      write(*,*) 'Truncation Radius (a.u.)=', truncation_radius<br class="">+   endif<br class="">+endif<br class="">+<br class="">+return<br class="">+end subroutine<br class=""><br class="">Added: trunk/espresso/GWW/bse/print_spectrum.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/print_spectrum.f90<span class="Apple-tab-span" style="white-space:pre">      </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/print_spectrum.f90<span class="Apple-tab-span" style="white-space:pre">       </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,107 @@<br class="">+subroutine print_spectrum(aspectrum,im)<br class="">+!this subroutine applies a gaussian broadening and prints the absorption<br class="">+!spectrum on file<br class="">+<br class="">+USE exciton<br class="">+USE io_global,   ONLY : stdout,ionode<br class="">+USE bse_wannier, ONLY : spectra_e_min,spectra_e_max,n_eig,spectra_nstep,spectra_broad,l_lanczos<br class="">+USE constants,   ONLY : RYTOEV, PI<br class="">+USE cell_base,   ONLY : omega<br class="">+USE io_files,    ONLY : tmp_dir,prefix<br class="">+<br class="">+implicit none<br class="">+<br class="">+INTEGER, EXTERNAL :: find_free_unit<br class="">+<br class="">+REAL(kind=DP), INTENT(inout)  :: aspectrum(spectra_nstep,3)<br class="">+INTEGER           :: ipol<br class="">+<br class="">+REAL(DP), ALLOCATABLE :: omega_g(:),broad_abs(:,:)<br class="">+REAL(DP)    :: step,prefac,sumdos,norm<br class="">+INTEGER     :: i,j,iun <br class="">+<br class="">+LOGICAL     :: debug, im<br class="">+<br class="">+call start_clock('print_spectrum')<br class="">+debug=.false.<br class="">+ <br class="">+allocate(omega_g(spectra_nstep))<br class="">+allocate(broad_abs(spectra_nstep,3))<br class="">+<br class="">+!build the omega grid (in eV)<br class="">+step=(spectra_e_max-spectra_e_min)/dble(spectra_nstep-1)<br class="">+<br class="">+do i=0, spectra_nstep-1<br class="">+   omega_g(i+1)=(spectra_e_min+dble(i)*step)<br class="">+enddo<br class="">+<br class="">+<br class="">+prefac=4.d0*PI/omega<br class="">+!prefac=1.d0<br class="">+do ipol=1,3<br class="">+   aspectrum(1:spectra_nstep,ipol)=prefac*aspectrum(1:spectra_nstep,ipol)<br class="">+<br class="">+   broad_abs(1:spectra_nstep, ipol)=0.d0<br class="">+   do i=1,spectra_nstep <br class="">+        norm=0.d0<br class="">+        do j=1,spectra_nstep<br class="">+           broad_abs(i,ipol)=broad_abs(i,ipol)+&<br class="">+                    aspectrum(j,ipol)*exp(-((omega_g(i)-omega_g(j))**2)/(2.d0*spectra_broad**2))<br class="">+           norm=norm+exp(-((omega_g(i)-omega_g(j))**2)/(2.d0*spectra_broad**2))<br class="">+        enddo<br class="">+        broad_abs(i, ipol)=broad_abs(i, ipol)/norm<br class="">+   enddo<br class="">+enddo<br class="">+<br class="">+!print absorption aspectrum on file<br class="">+if(im) then<br class="">+   do ipol=1,3<br class="">+      if(ionode) then<br class="">+         iun = find_free_unit()<br class="">+<br class="">+         if (ipol==1) then<br class="">+            open(unit=iun, file=trim(tmp_dir)//trim(prefix)//'.eps2x.dat', status='unknown', form='formatted')<br class="">+         elseif (ipol==2) then<br class="">+            open(unit=iun, file=trim(tmp_dir)//trim(prefix)//'.eps2y.dat', status='unknown', form='formatted')<br class="">+         elseif (ipol==3) then<br class="">+            open(unit=iun, file=trim(tmp_dir)//trim(prefix)//'.eps2z.dat', status='unknown', form='formatted')<br class="">+         endif<br class="">+      <br class="">+!         write(*,*) '# Energy(eV)   Eps2 Eps2(Nogaussbroad)'<br class="">+         write(iun,*) '# Energy(eV)   Eps2 Eps2(Nogaussbroad)'<br class="">+         do i=1,spectra_nstep<br class="">+            write(iun,*) omega_g(i),broad_abs(i,ipol),aspectrum(i,ipol)<br class="">+            !write(*,*) omega_g(i),broad_abs(i,ipol),aspectrum(i,ipol)<br class="">+         enddo<br class="">+         close(iun)<br class="">+      endif<br class="">+   enddo <br class="">+else<br class="">+   do ipol=1,3<br class="">+      if(ionode) then<br class="">+         iun = find_free_unit()<br class="">+<br class="">+         if (ipol==1) then<br class="">+            open(unit=iun, file=trim(tmp_dir)//trim(prefix)//'.eps1x.dat', status='unknown', form='formatted')<br class="">+         elseif (ipol==2) then<br class="">+            open(unit=iun, file=trim(tmp_dir)//trim(prefix)//'.eps1y.dat', status='unknown', form='formatted')<br class="">+         elseif (ipol==3) then<br class="">+            open(unit=iun, file=trim(tmp_dir)//trim(prefix)//'.eps1z.dat', status='unknown', form='formatted')<br class="">+         endif<br class="">+      <br class="">+!         write(*,*) '# Energy(eV)   Eps1 Eps1(Nogaussbroad)'<br class="">+         write(iun,*) '# Energy(eV)   Eps1 Eps1(Nogaussbroad)'<br class="">+         do i=1,spectra_nstep<br class="">+            write(iun,*) omega_g(i),broad_abs(i,ipol),aspectrum(i,ipol)<br class="">+            !write(*,*) omega_g(i),broad_abs(i,ipol),aspectrum(i,ipol)<br class="">+         enddo<br class="">+         close(iun)<br class="">+      endif<br class="">+   enddo <br class="">+endif<br class="">+<br class="">+deallocate(omega_g,broad_abs)<br class="">+call stop_clock('print_spectrum')<br class="">+<br class="">+end subroutine<br class="">+<br class=""><br class="">Added: trunk/espresso/GWW/bse/qpcorrections.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/qpcorrections.f90<span class="Apple-tab-span" style="white-space:pre">   </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/qpcorrections.f90<span class="Apple-tab-span" style="white-space:pre">        </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,42 @@<br class="">+subroutine qpcorrections(wcstate)<br class="">+! this subroutine reads the qp corrections and gives the correct weight to each line of the <br class="">+! wcstate vector<br class="">+<br class="">+!USE qpe,         ONLY: qpc,qpcbarc,qpcbarv<br class="">+USE qpe_exc         <br class="">+USE bse_wannier, ONLY: qpe_imin, qpe_imax, num_nbndv,scissor<br class="">+USE kinds,        ONLY : DP<br class="">+USE bse_basic_structures<br class="">+<br class="">+implicit none<br class="">+type(c_state)   :: wcstate<br class="">+real(kind=DP), allocatable :: qpcw(:)<br class="">+<br class="">+<br class="">+call build_qpc(qpc)<br class="">+allocate(qpcw(wcstate%numb_c))<br class="">+qpcw=0.d0<br class="">+<br class="">+if (qpe_imin <= num_nbndv(1)) then<br class="">+   qpcbarv=qpc(qpe_imin)<br class="">+   qpc(1:qpe_imin)=qpcbarv<br class="">+else<br class="">+!case only conduction bands corrections are computed, valence shifts rigidly <br class="">+   qpc(1:qpe_imin)=-scissor<br class="">+endif<br class="">+<br class="">+if (qpe_imax > num_nbndv(1)) then<br class="">+   qpcbarc=qpc(qpe_imax)<br class="">+   qpcw(1:qpe_imax-num_nbndv(1))=qpc(num_nbndv(1)+1:qpe_imax)-qpcbarc<br class="">+   <br class="">+   call c_times_cstate(qpcw,wcstate,wcstate)<br class="">+else<br class="">+!case only valence bands corrections are computed, conduction shifts rigidly <br class="">+   qpcbarc=scissor<br class="">+endif<br class="">+<br class="">+<br class="">+<br class="">+<br class="">+return<br class="">+end subroutine<br class=""><br class="">Added: trunk/espresso/GWW/bse/qpe_exc.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/qpe_exc.f90<span class="Apple-tab-span" style="white-space:pre">   </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/qpe_exc.f90<span class="Apple-tab-span" style="white-space:pre">      </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,61 @@<br class="">+MODULE qpe_exc<br class="">+!this modules contains variables and subroutines related to the use of QP energies<br class="">+!in the BSE kernel beyond the scissor operator<br class="">+ <br class="">+USE kinds, ONLY : DP<br class="">+USE io_global, ONLY : ionode,ionode_id<br class="">+USE mp, ONLY : mp_bcast<br class="">+USE mp_world, ONLY : world_comm<br class="">+<br class="">+REAL(kind=DP), pointer :: qpc(:)  ! vector containing QPC<br class="">+REAL(kind=DP)          :: qpcbarc ! average qpc to be applied for higher <br class="">+                                  ! (band index above qpc_imax) energy states<br class="">+REAL(kind=DP)          :: qpcbarv ! average qpc to be applied for lower <br class="">+                                  ! (band index below qpc_imin) energy states<br class="">+<br class="">+CONTAINS<br class="">+<br class="">+    SUBROUTINE build_qpc(qpc)<br class="">+    !this subroutine reads bands.dat and builds the qp correction vector<br class="">+    USE bse_wannier, ONLY : qpe_imin,qpe_imax<br class="">+    USE kinds, ONLY : DP<br class="">+    USE io_files, ONLY : tmp_dir,prefix<br class="">+    USE wvfct,    ONLY : nbnd<br class="">+    USE constants,   ONLY: RYTOEV<br class="">+<br class="">+    implicit none<br class="">+     <br class="">+    INTEGER, EXTERNAL :: find_free_unit<br class="">+    integer :: ib, iun, idum<br class="">+    logical :: debug<br class="">+    real(kind=DP) :: qpc(qpe_imax)<br class="">+    real(kind=DP)          :: rdum,edft,egw,dumm1,dumm2,dumm3,dumm4<br class="">+        <br class="">+    qpc(1:qpe_imax)=0.d0<br class="">+<br class="">+    iun = find_free_unit()  <br class="">+    if(ionode) then<br class="">+       open(iun,file=trim(tmp_dir)//trim(prefix)//'-bands.dat', status='old', form='formatted')<br class="">+       <br class="">+       read(iun,*) idum<br class="">+       read(iun,*) idum<br class="">+<br class="">+       do ib=1,qpe_imin-1<br class="">+          read(iun,*) idum,dumm1,dumm2,dumm3,dumm4<br class="">+       enddo<br class="">+<br class="">+       do ib=qpe_imin,qpe_imax<br class="">+          read(iun,*) idum, edft,rdum,egw,rdum<br class="">+          qpc(ib)=(egw-edft)/RYTOEV<br class="">+       <br class="">+       enddo<br class="">+ <br class="">+       close(iun)<br class="">+    endif<br class="">+    do ib=qpe_imin,qpe_imax<br class="">+       call mp_bcast(qpc(ib), ionode_id, world_comm )<br class="">+    enddo<br class="">+    return<br class="">+    END SUBROUTINE<br class="">+<br class="">+end MODULE qpe_exc<br class=""><br class="">Added: trunk/espresso/GWW/bse/read_export.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/read_export.f90<span class="Apple-tab-span" style="white-space:pre">     </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/read_export.f90<span class="Apple-tab-span" style="white-space:pre">  </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,305 @@<br class="">+subroutine read_export (pp_file,kunit,uspp_spsi, ascii, single_file, raw)<br class="">+  !-----------------------------------------------------------------------<br class="">+  !<br class="">+  use iotk_module<br class="">+<br class="">+<br class="">+  use kinds,          ONLY : DP <br class="">+  use pwcom  <br class="">+  use control_flags,  ONLY : gamma_only  <br class="">+  use becmod,         ONLY : bec_type, becp, calbec, &<br class="">+                             allocate_bec_type, deallocate_bec_type<br class="">+!  use symme,          ONLY : nsym, s, invsym, sname, irt, ftau<br class="">+!  use symme,          ONLY : nsym, s, invsym, irt, ftau<br class="">+!  use char,           ONLY : sname<br class="">+! occhio sname is in symme which is now outside pwcom<br class="">+  use  uspp,          ONLY : nkb, vkb<br class="">+  use wavefunctions_module,  ONLY : evc<br class="">+  use io_files,       ONLY : nd_nmbr, outdir, prefix, iunwfc, nwordwfc, iunsat, nwordatwfc<br class="">+  use io_files,       ONLY : pseudo_dir, psfile<br class="">+  use io_global,      ONLY : ionode, stdout<br class="">+  USE ions_base,      ONLY : atm, nat, ityp, tau, nsp<br class="">+  use mp_world,      ONLY : nproc,  mpime<br class="">+  use mp_pools,      ONLY : my_pool_id, intra_pool_comm, inter_pool_comm, nproc_pool<br class="">+  USE mp_world,             ONLY : world_comm<br class="">+  use mp,             ONLY : mp_sum, mp_max<br class="">+!  use ldaU,           ONLY : swfcatom, lda_plus_u<br class="">+  use ldaU,           ONLY :  lda_plus_u<br class="">+  USE gvecw,              ONLY :  ecutwfc<br class="">+<br class="">+  implicit none<br class="">+<br class="">+  CHARACTER(5), PARAMETER :: fmt_name="QEXPT"<br class="">+  CHARACTER(5), PARAMETER :: fmt_version="1.1.0"<br class="">+<br class="">+  integer, intent(in) :: kunit<br class="">+  character(80), intent(in) :: pp_file<br class="">+  logical, intent(in) :: uspp_spsi, ascii, single_file, raw<br class="">+<br class="">+  integer :: i, j, k, ig, ik, ibnd, na, ngg,ig_, ierr<br class="">+  integer, allocatable :: kisort(:)<br class="">+  real(DP) :: xyz(3), tmp(3)<br class="">+  integer :: npool, nkbl, nkl, nkr, npwx_g<br class="">+  integer :: ike, iks, npw_g, ispin, local_pw<br class="">+  integer, allocatable :: ngk_g( : )<br class="">+  integer, allocatable :: itmp_g( :, : )<br class="">+  real(DP),allocatable :: rtmp_g( :, : )<br class="">+  real(DP),allocatable :: rtmp_gg( : )<br class="">+  integer, allocatable :: itmp1( : )<br class="">+  integer, allocatable :: igwk( :, : )<br class="">+  integer, allocatable :: l2g_new( : )<br class="">+  integer, allocatable :: igk_l2g( :, : )<br class="">+<br class="">+<br class="">+  real(DP) :: wfc_scal <br class="">+  logical :: twf0, twfm<br class="">+  character(iotk_attlenx) :: attr<br class="">+  complex(DP), allocatable :: sevc (:,:)<br class="">+<br class="">+  call start_clock('read_export')<br class="">+  write(stdout,*) "nkstot=", nkstot<br class="">+<br class="">+  IF( nkstot > 0 ) THEN<br class="">+<br class="">+     IF( ( kunit < 1 ) .OR. ( MOD( nkstot, kunit ) /= 0 ) ) &<br class="">+       CALL errore( ' write_export ',' wrong kunit ', 1 )<br class="">+<br class="">+     IF( ( nproc_pool > nproc ) .OR. ( MOD( nproc, nproc_pool ) /= 0 ) ) &<br class="">+       CALL errore( ' write_export ',' nproc_pool ', 1 )<br class="">+<br class="">+     !  find out the number of pools<br class="">+     npool = nproc / nproc_pool<br class="">+<br class="">+     !  find out number of k points blocks<br class="">+     nkbl = nkstot / kunit<br class="">+<br class="">+     !  k points per pool<br class="">+     nkl = kunit * ( nkbl / npool )<br class="">+<br class="">+     !  find out the reminder<br class="">+     nkr = ( nkstot - nkl * npool ) / kunit<br class="">+<br class="">+     !  Assign the reminder to the first nkr pools<br class="">+     IF( my_pool_id < nkr ) nkl = nkl + kunit<br class="">+<br class="">+     !  find out the index of the first k point in this pool<br class="">+     iks = nkl * my_pool_id + 1<br class="">+     IF( my_pool_id >= nkr ) iks = iks + nkr * kunit<br class="">+<br class="">+     !  find out the index of the last k point in this pool<br class="">+     ike = iks + nkl - 1<br class="">+<br class="">+  END IF<br class="">+<br class="">+  write(stdout,*) "after first init"<br class="">+<br class="">+  ! find out the global number of G vectors: ngm_g  <br class="">+  ngm_g = ngm<br class="">+  call mp_sum( ngm_g , world_comm )<br class="">+<br class="">+  ! collect all G vectors across processors within the pools<br class="">+  ! and compute their modules<br class="">+  !<br class="">+  allocate( itmp_g( 3, ngm_g ) )<br class="">+  allocate( rtmp_g( 3, ngm_g ) )<br class="">+  allocate( rtmp_gg( ngm_g ) )<br class="">+<br class="">+  itmp_g = 0<br class="">+  do  ig = 1, ngm<br class="">+    itmp_g( 1, ig_l2g( ig ) ) = mill(1, ig )<br class="">+    itmp_g( 2, ig_l2g( ig ) ) = mill(2, ig )<br class="">+    itmp_g( 3, ig_l2g( ig ) ) = mill(3, ig )<br class="">+  end do<br class="">+  call mp_sum( itmp_g , world_comm )<br class="">+  !<br class="">+  ! here we are in crystal units<br class="">+  rtmp_g(1:3,1:ngm_g) = REAL( itmp_g(1:3,1:ngm_g) )<br class="">+  !<br class="">+  ! go to cartesian units (tpiba)<br class="">+  call cryst_to_cart( ngm_g, rtmp_g, bg , 1 )<br class="">+  !<br class="">+  ! compute squared moduli<br class="">+  do  ig = 1, ngm_g <br class="">+     rtmp_gg(ig) = rtmp_g(1,ig)**2 + rtmp_g(2,ig)**2 + rtmp_g(3,ig)**2 <br class="">+  enddo<br class="">+  deallocate( rtmp_g )<br class="">+<br class="">+  ! build the G+k array indexes<br class="">+  allocate ( igk_l2g ( npwx, nks ) )<br class="">+  allocate ( kisort( npwx ) )<br class="">+  do ik = 1, nks<br class="">+     kisort = 0<br class="">+     npw = npwx<br class="">+     call gk_sort (xk (1, ik+iks-1), ngm, g, ecutwfc / tpiba2, npw, kisort(1), g2kin)<br class="">+     !<br class="">+     ! mapping between local and global G vector index, for this kpoint<br class="">+     !<br class="">+     DO ig = 1, npw<br class="">+        !<br class="">+        igk_l2g(ig,ik) = ig_l2g( kisort(ig) )<br class="">+        !<br class="">+     END DO<br class="">+     !<br class="">+     igk_l2g( npw+1 : npwx, ik ) = 0<br class="">+     !<br class="">+     ngk (ik) = npw<br class="">+  end do<br class="">+  deallocate (kisort)<br class="">+<br class="">+  ! compute the global number of G+k vectors for each k point<br class="">+  allocate( ngk_g( nkstot ) )<br class="">+  ngk_g = 0<br class="">+  ngk_g( iks:ike ) = ngk( 1:nks )<br class="">+  CALL mp_sum( ngk_g, world_comm )<br class="">+<br class="">+  ! compute the Maximum G vector index among all G+k and processors<br class="">+  npw_g = MAXVAL( igk_l2g(:,:) )<br class="">+  CALL mp_max( npw_g, world_comm )<br class="">+<br class="">+  ! compute the Maximum number of G vector among all k points<br class="">+  npwx_g = MAXVAL( ngk_g( 1:nkstot ) )<br class="">+<br class="">+  deallocate(rtmp_gg)<br class="">+<br class="">+  allocate( igwk( npwx_g,nkstot ) )<br class="">+<br class="">+  write(stdout,*) "after g stuff"<br class="">+<br class="">+! wfc grids<br class="">+<br class="">+  DO ik = 1, nkstot<br class="">+    igwk(:,ik) = 0<br class="">+    !<br class="">+    ALLOCATE( itmp1( npw_g ), STAT= ierr )<br class="">+    IF ( ierr/=0 ) CALL errore('pw_export','allocating itmp1', ABS(ierr) )<br class="">+    itmp1 = 0<br class="">+    ! <br class="">+    IF( ik >= iks .AND. ik <= ike ) THEN <br class="">+      DO  ig = 1, ngk( ik-iks+1 )<br class="">+        itmp1( igk_l2g( ig, ik-iks+1 ) ) = igk_l2g( ig, ik-iks+1 ) <br class="">+      END DO<br class="">+    END IF<br class="">+    !<br class="">+    CALL mp_sum( itmp1, world_comm )<br class="">+    !<br class="">+    ngg = 0<br class="">+    DO  ig = 1, npw_g<br class="">+      IF( itmp1( ig ) == ig ) THEN<br class="">+        ngg = ngg + 1<br class="">+        igwk( ngg , ik) = ig<br class="">+      END IF<br class="">+    END DO<br class="">+    IF( ngg /= ngk_g( ik ) ) THEN<br class="">+      WRITE( stdout,*) ' ik, ngg, ngk_g = ', ik, ngg, ngk_g( ik )<br class="">+    END IF<br class="">+    !<br class="">+    DEALLOCATE( itmp1 )<br class="">+    !<br class="">+  ENDDO<br class="">+  !<br class="">+  deallocate( itmp_g )<br class="">+  <br class="">+  write(stdout,*)"after wfc waves"<br class="">+<br class="">+#ifdef __PARA<br class="">+  call poolrecover (et, nbnd, nkstot, nks)<br class="">+#endif<br class="">+ <br class="">+  wfc_scal = 1.0d0<br class="">+  twf0 = .true.<br class="">+  twfm = .false.<br class="">+<br class="">+  do ik = 1, nkstot<br class="">+     local_pw = 0<br class="">+     IF( (ik >= iks) .AND. (ik <= ike) ) THEN<br class="">+<br class="">+       call davcio (evc, 2*nwordwfc, iunwfc, (ik-iks+1), - 1)<br class="">+!       IF ( lda_plus_u ) CALL davcio( swfcatom, nwordatwfc, iunsat, (ik-iks+1), -1 )<br class="">+       local_pw = ngk(ik-iks+1)<br class="">+<br class="">+     ENDIF<br class="">+<br class="">+<br class="">+     allocate(l2g_new(local_pw))<br class="">+<br class="">+     l2g_new = 0<br class="">+     do ig = 1, local_pw<br class="">+       ngg = igk_l2g(ig,ik-iks+1)<br class="">+       do ig_ = 1, ngk_g(ik)<br class="">+         if(ngg == igwk(ig_,ik)) then<br class="">+           l2g_new(ig) = ig_<br class="">+           exit<br class="">+         end if<br class="">+       end do<br class="">+     end do<br class="">+<br class="">+<br class="">+     ispin = isk( ik )<br class="">+     !  WRITE(0,*) ' ### ', ik,nkstot,iks,ike,kunit,nproc,nproc_pool <br class="">+     deallocate(l2g_new)<br class="">+  end do<br class="">+  !  <br class="">+<br class="">+  write(stdout,*) "after davcio"<br class="">+<br class="">+  ! If specified and if USPP are used the wfcs S_psi are written  <br class="">+  ! | spsi_nk > = \hat S | psi_nk >  <br class="">+  ! where S is the overlap operator of US PP <br class="">+  !  <br class="">+  IF ( uspp_spsi .AND. nkb > 0 ) THEN<br class="">+<br class="">+       ALLOCATE( sevc(npwx,nbnd), STAT=ierr )<br class="">+       IF (ierr/=0) CALL errore( ' read_export ',' Unable to allocate SEVC ', ABS(ierr) )<br class="">+<br class="">+       CALL init_us_1<br class="">+       CALL init_at_1<br class="">+<br class="">+       CALL allocate_bec_type (nkb,nbnd,becp)<br class="">+<br class="">+       do ik = 1, nkstot<br class="">+ <br class="">+           local_pw = 0<br class="">+           IF( (ik >= iks) .AND. (ik <= ike) ) THEN<br class="">+               <br class="">+               CALL gk_sort (xk (1, ik+iks-1), ngm, g, ecutwfc / tpiba2, npw, igk, g2kin)<br class="">+               CALL davcio (evc, 2*nwordwfc, iunwfc, (ik-iks+1), - 1)<br class="">+<br class="">+               CALL init_us_2(npw, igk, xk(1, ik), vkb)<br class="">+               local_pw = ngk(ik-iks+1)<br class="">+                            <br class="">+               IF ( gamma_only ) THEN<br class="">+                  if(nkb>0) CALL calbec ( ngk_g(ik), vkb, evc, becp )<br class="">+               ELSE<br class="">+                  CALL calbec ( npw, vkb, evc, becp )<br class="">+               ENDIF<br class="">+               CALL s_psi(npwx, npw, nbnd, evc, sevc)<br class="">+           ENDIF<br class="">+<br class="">+           ALLOCATE(l2g_new(local_pw))<br class="">+<br class="">+           l2g_new = 0<br class="">+           DO ig = 1, local_pw<br class="">+             ngg = igk_l2g(ig,ik-iks+1)<br class="">+             DO ig_ = 1, ngk_g(ik)<br class="">+               IF(ngg == igwk(ig_,ik)) THEN<br class="">+                 l2g_new(ig) = ig_<br class="">+                 EXIT<br class="">+               ENDIF<br class="">+             ENDDO<br class="">+           ENDDO<br class="">+<br class="">+           ispin = isk( ik )<br class="">+           DEALLOCATE(l2g_new)<br class="">+       ENDDO<br class="">+      <br class="">+       DEALLOCATE( sevc, STAT=ierr )<br class="">+       IF ( ierr/= 0 ) CALL errore('read_export','Unable to deallocate SEVC',ABS(ierr))<br class="">+       CALL deallocate_bec_type ( becp )<br class="">+  ENDIF<br class="">+<br class="">+  DEALLOCATE( igk_l2g )<br class="">+  DEALLOCATE( igwk )<br class="">+  DEALLOCATE ( ngk_g )<br class="">+  call stop_clock('read_export')<br class="">+<br class="">+end subroutine read_export<br class=""><br class="">Added: trunk/espresso/GWW/bse/rotate_wannier.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/rotate_wannier.f90<span class="Apple-tab-span" style="white-space:pre">     </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/rotate_wannier.f90<span class="Apple-tab-span" style="white-space:pre">       </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,97 @@<br class="">+!-----------------------------------------<br class="">+subroutine rotate_wannier_gamma_bse( rot_u,a_in,a_out,ispin, itrasp)<br class="">+!----------------------------------------<br class="">+!<br class="">+! (GAMMA-ONLY CALCULATIONS) and rotate the wavefunctions<br class="">+! according to rot_u<br class="">+! only ispin states used (not implemented ye<br class="">+! ONLY -NORMCONSERVING<br class="">+<br class="">+<br class="">+  USE kinds,    ONLY : DP<br class="">+  USE us<br class="">+  USE wvfct,    ONLY : igk, g2kin, npwx, npw, nbndx,nbnd<br class="">+  USE gvect<br class="">+  USE basis<br class="">+  USE klist<br class="">+  USE constants, ONLY : e2, pi, tpi, fpi<br class="">+  USE io_files, ONLY: nwordwfc<br class="">+  USE cell_base, ONLY: at, alat, tpiba, omega, tpiba2<br class="">+!  USE wavefunctions_module, ONLY: evc<br class="">+  use exciton<br class="">+  USE io_global, ONLY : stdout <br class="">+<br class="">+<br class="">+  implicit none<br class="">+<br class="">+  INTEGER, INTENT(in) :: ispin!+1 or -1<br class="">+   type(exc):: a_in, a_out<br class="">+  REAL(kind=DP) :: rot_u(a_in%numb_v,a_in%numb_v)<br class="">+  INTEGER, INTENT(in) :: itrasp!if 1 takes U^T<br class="">+ <br class="">+<br class="">+<br class="">+<br class="">+  REAL(kind=DP), ALLOCATABLE  :: evc0(:,:),evc_re(:,:),evc_im(:,:)!reads wavefunctions here<br class="">+  integer i,j,k,ig<br class="">+  logical debug<br class="">+<br class="">+  call start_clock('rotate_wannier_gamma_bse')<br class="">+  debug=.true.<br class="">+<br class="">+  allocate( evc0(npw,a_in%numb_v))<br class="">+  allocate( evc_re(npw,a_in%numb_v))<br class="">+  allocate( evc_im(npw,a_in%numb_v))<br class="">+<br class="">+  if(debug) then <br class="">+     write(stdout,*) 'rotate wannier #1'<br class="">+  endif<br class="">+<br class="">+!now real part<br class="">+  if(itrasp/=1) then<br class="">+     evc0(1:a_in%npw,1:a_in%numb_v)=dble(a_in%a(1:a_in%npw,1:a_in%numb_v))<br class="">+     call dgemm('N','N',npw,a_in%numb_v,a_in%numb_v,1.d0,evc0,npw,rot_u,a_in%numb_v,0.d0,evc_re,npw)<br class="">+!now imaginary part<br class="">+     evc0(1:a_in%npw,1:a_in%numb_v)=dimag(a_in%a(1:a_in%npw,1:a_in%numb_v))<br class="">+     call dgemm('N','N',npw,a_in%numb_v,a_in%numb_v,1.d0,evc0,npw,rot_u,a_in%numb_v,0.d0,evc_im,npw)<br class="">+  else<br class="">+     evc0(1:a_in%npw,1:a_in%numb_v)=dble(a_in%a(1:a_in%npw,1:a_in%numb_v))<br class="">+     call dgemm('N','T',npw,a_in%numb_v,a_in%numb_v,1.d0,evc0,npw,rot_u,a_in%numb_v,0.d0,evc_re,npw)<br class="">+     !now imaginary part                                                                                                <br class="">+     evc0(1:a_in%npw,1:a_in%numb_v)=dimag(a_in%a(1:a_in%npw,1:a_in%numb_v))<br class="">+     call dgemm('N','T',npw,a_in%numb_v,a_in%numb_v,1.d0,evc0,npw,rot_u,a_in%numb_v,0.d0,evc_im,npw)<br class="">+  endif<br class="">+<br class="">+  <br class="">+!  do i=1,nbnd<br class="">+!     do ig=1,npw<br class="">+!        evc(ig,i)=dcmplx(evc_re(ig,i),evc_im(ig,i))<br class="">+!     enddo<br class="">+!  enddo<br class="">+<br class="">+<br class="">+ a_out%a(1:a_in%npw,1:a_in%numb_v)=dcmplx(evc_re(1:a_in%npw,1:a_in%numb_v),evc_im(1:a_in%npw,1:a_in%numb_v))<br class="">+  <br class="">+<br class="">+<br class="">+!rotate<br class="">+!  do i=1,nbnd<br class="">+!     do j=1,nbnd<br class="">+!        do ig=1,npw<br class="">+!           evc(ig,i)=evc(ig,i)+rot_u(j,i)*evc0(ig,j)<br class="">+!        enddo<br class="">+!     enddo<br class="">+!  enddo<br class="">+<br class="">+<br class="">+<br class="">+<br class="">+  DEALLOCATE(evc0)<br class="">+  deallocate(evc_re,evc_im)<br class="">+<br class="">+<br class="">+  call stop_clock('rotate_wannier_gamma_bse')<br class="">+  return<br class="">+<br class="">+end subroutine rotate_wannier_gamma_bse<br class="">+<br class=""><br class="">Added: trunk/espresso/GWW/bse/sdescent.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/sdescent.f90<span class="Apple-tab-span" style="white-space:pre">   </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/sdescent.f90<span class="Apple-tab-span" style="white-space:pre">     </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,130 @@<br class="">+subroutine sdescent(i_state,vstatesd,vstate_rsd,cstate,cstate_r,fc,en)<br class="">+<br class="">+use exciton<br class="">+use bse_basic_structures<br class="">+USE fft_custom_gwl<br class="">+USE io_global, ONLY : stdout,ionode<br class="">+USE wvfct,    ONLY : npw<br class="">+use bse_wannier, ONLY:num_nbndv,eps,lambda,eps_eig<br class="">+USE mp,          ONLY :mp_barrier<br class="">+USE mp_world,             ONLY : world_comm<br class="">+USE constants,        ONLY: RYTOEV<br class="">+<br class="">+<br class="">+<br class="">+implicit none<br class="">+<br class="">+type(exc) :: a_in<br class="">+type(exc) :: a_out<br class="">+type(v_state) :: vstatesd<br class="">+type(v_state_r) :: vstate_rsd<br class="">+type(c_state) :: cstate<br class="">+type(c_state_r) :: cstate_r<br class="">+type(fft_cus) :: fc<br class="">+<br class="">+real(kind=DP), intent(out) :: en<br class="">+real(kind=DP) :: eigout<br class="">+real(kind=DP) :: eig<br class="">+real(kind=DP) ::delta,delta_eig,hsquare<br class="">+<br class="">+integer :: it,is,i,i_state<br class="">+<br class="">+call start_clock('sdescent')<br class="">+<br class="">+!create a random excitonic wavefunction vector a_exc<br class="">+!and normalize it<br class="">+call initialize_exc(a_in)<br class="">+a_in%label=50<br class="">+a_in%npw=npw<br class="">+a_in%numb_v=num_nbndv(1)<br class="">+allocate(a_in%a(a_in%npw,a_in%numb_v))<br class="">+<br class="">+call random_exc(a_in)<br class="">+!project into the conduction manifold<br class="">+<br class="">+do is = 1,vstatesd%nspin<br class="">+   call pc_operator_exc(a_in,vstatesd,is)<br class="">+enddo<br class="">+<br class="">+!project out all the previous found state<br class="">+call pout_operator_exc(a_in,i_state)<br class="">+<br class="">+call normalize_exc(a_in)<br class="">+CALL mp_barrier(world_comm)<br class="">+<br class="">+call initialize_exc(a_out)<br class="">+a_out%label=1<br class="">+a_out%npw=npw<br class="">+a_out%numb_v=num_nbndv(1)<br class="">+allocate(a_out%a(a_out%npw,a_out%numb_v))<br class="">+<br class="">+eig=0.d0<br class="">+eigout=100.d0<br class="">+delta_eig=100.d0<br class="">+delta=100.d0<br class="">+<br class="">+if(ionode) write(stdout,*) 'Steepest descent started.'<br class="">+if(ionode) write(stdout,*) 'lambda=',lambda<br class="">+if(ionode) write(stdout,*) 'eps',eps<br class="">+<br class="">+it=0<br class="">+!do while(((abs(delta))>=eps)) <br class="">+do while(((abs(delta))>=eps).or.(abs(delta_eig)>eps_eig)) <br class="">+!   write(*,*) 's descent, iteration, delta=',it,delta<br class="">+! |a_out>=H|a_in><br class="">+   call exc_h_a(a_in,a_out,vstatesd,vstate_rsd,cstate,cstate_r,fc) <br class="">+   call mp_barrier(world_comm)<br class="">+!   call normalize_exc(a_out)<br class="">+   <br class="">+!  eigout= <psi_(it)|H|psi_(it)>/<psi_(it)|psi_(it)>  <br class="">+   call sproduct_exc(a_out,a_in,eigout)<br class="">+   eigout=eigout*RYTOEV<br class="">+   write(*,*) 'sd. eig# =',i_state, 'it=', it, 'E(eV)=', eigout <br class="">+  <br class="">+!  check how good it is as an eigenstate <br class="">+   call sproduct_exc(a_out,a_out,hsquare)<br class="">+   hsquare=hsquare*RYTOEV*RYTOEV<br class="">+<br class="">+   delta_eig=hsquare-eigout**2<br class="">+ <br class="">+   eigout=eigout*RYTOEV<br class="">+! compute |psi_(it+1)><br class="">+   a_out%a(1:a_out%npw,1:a_out%numb_v)=(1.d0+lambda*eigout)*a_in%a(1:a_in%npw,1:a_in%numb_v)&<br class="">+                          -lambda*a_out%a(1:a_out%npw,1:a_out%numb_v)<br class="">+<br class="">+   !project into the conduction manifold<br class="">+<br class="">+   do is = 1,vstatesd%nspin<br class="">+      call pc_operator_exc(a_out,vstatesd,is)<br class="">+   enddo<br class="">+<br class="">+   !project out all the previous found state<br class="">+   call pout_operator_exc(a_out,i_state)<br class="">+   call normalize_exc(a_out)<br class="">+<br class="">+   a_in%a(1:a_out%npw,1:a_out%numb_v)= a_out%a(1:a_out%npw,1:a_out%numb_v)<br class="">+<br class="">+   call mp_barrier(world_comm)<br class="">+<br class="">+   it=it+1<br class="">+   delta=eig-eigout<br class="">+   eig=eigout<br class="">+enddo<br class="">+<br class="">+bse_spectrum(i_state)%a(1:bse_spectrum(i_state)%npw,1:bse_spectrum(i_state)%numb_v)=&<br class="">+                         a_out%a(1:a_out%npw,1:a_out%numb_v)<br class="">+<br class="">+<br class="">+bse_spectrum(i_state)%e=eigout<br class="">+en=eigout<br class="">+<br class="">+!if(ionode) write(stdout,*) 'Lowest eigenvalue=',eig<br class="">+<br class="">+<br class="">+!free memory<br class="">+call free_memory_exc_a(a_out)<br class="">+call free_memory_exc_a(a_in)<br class="">+<br class="">+call stop_clock('sdescent')<br class="">+return<br class="">+end subroutine sdescent<br class=""><br class="">Added: trunk/espresso/GWW/bse/spectrum.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/spectrum.f90<span class="Apple-tab-span" style="white-space:pre">       </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/spectrum.f90<span class="Apple-tab-span" style="white-space:pre">     </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,136 @@<br class="">+subroutine build_spectrum(ampl,en,ipol)<br class="">+!this subroutine builds up the absorption spectrum<br class="">+!and prints it on file<br class="">+<br class="">+USE exciton<br class="">+USE io_global,   ONLY : stdout,ionode<br class="">+USE bse_wannier, ONLY : spectra_e_min,spectra_e_max,n_eig,spectra_nstep,spectra_broad<br class="">+USE constants,   ONLY : RYTOEV, PI<br class="">+USE cell_base,   ONLY : omega<br class="">+USE io_files,    ONLY : tmp_dir,prefix<br class="">+<br class="">+implicit none<br class="">+<br class="">+REAL(DP), INTENT(in)  :: ampl(n_eig), en(n_eig)<br class="">+<br class="">+INTEGER, EXTERNAL :: find_free_unit<br class="">+<br class="">+REAL(DP), ALLOCATABLE :: omega_g(:),absorption(:),broad_abs(:),excdos(:)<br class="">+COMPLEX(DP), ALLOCATABLE :: den(:,:),cspectrum(:),campl(:)<br class="">+REAL(DP)    :: eta,step,prefac,sumdos,norm<br class="">+COMPLEX(DP) :: lambda_sum<br class="">+INTEGER     :: i,j,iun,ipol <br class="">+<br class="">+LOGICAL     :: debug<br class="">+<br class="">+call start_clock('build_spectrum')<br class="">+debug=.true.<br class="">+eta=0.001<br class="">+<br class="">+if(debug) then<br class="">+   if(ionode) then<br class="">+     do i=1,n_eig<br class="">+        write(stdout,*) '#',i,'E=',en(i),'A=',ampl(i)<br class="">+     enddo<br class="">+   endif<br class="">+endif<br class="">+ <br class="">+allocate(omega_g(spectra_nstep))<br class="">+allocate(absorption(spectra_nstep))<br class="">+allocate(excdos(spectra_nstep))<br class="">+allocate(broad_abs(spectra_nstep))<br class="">+allocate(cspectrum(spectra_nstep))<br class="">+allocate(den(spectra_nstep,n_eig))<br class="">+allocate(campl(n_eig))<br class="">+<br class="">+if (ipol==1) then<br class="">+!convert energy range in Ry<br class="">+   spectra_e_min=spectra_e_min/RYTOEV<br class="">+   spectra_e_max=spectra_e_max/RYTOEV<br class="">+endif<br class="">+<br class="">+!build the omega grid<br class="">+step=(spectra_e_max-spectra_e_min)/dble(spectra_nstep-1)<br class="">+<br class="">+do i=0, spectra_nstep-1<br class="">+   den(i+1,1:n_eig)=dcmplx(1.d0,0.d0)/(dcmplx(en(1:n_eig),0.d0)-dcmplx(spectra_e_min+dble(i)*step,eta))<br class="">+   omega_g(i+1)=(spectra_e_min+dble(i)*step)*RYTOEV<br class="">+enddo<br class="">+<br class="">+!compute the absorption spectrum<br class="">+campl(1:n_eig)=dcmplx(ampl(1:n_eig),0.d0)<br class="">+!campl(1:n_eig)=dcmplx(1.d0,0.d0)<br class="">+<br class="">+cspectrum(1:spectra_nstep)=(0.d0,0.d0)<br class="">+<br class="">+call zgemm('N','N',spectra_nstep,1,n_eig,(1.d0,0.d0),den,spectra_nstep,campl,n_eig,(0.d0,0.d0),cspectrum,spectra_nstep)<br class="">+<br class="">+prefac=8.d0*PI/omega<br class="">+!prefac=1.d0<br class="">+absorption(1:spectra_nstep)=prefac*aimag(cspectrum(1:spectra_nstep))<br class="">+<br class="">+!add gaussian broadening<br class="">+broad_abs(1:spectra_nstep)=0.d0<br class="">+do i=1,spectra_nstep <br class="">+     norm=0.d0<br class="">+     do j=1,spectra_nstep<br class="">+        broad_abs(i)=broad_abs(i)+&<br class="">+                     absorption(j)*exp(-((omega_g(i)-omega_g(j))**2)/(2.d0*spectra_broad**2))<br class="">+        norm=norm+exp(-((omega_g(i)-omega_g(j))**2)/(2.d0*spectra_broad**2))<br class="">+     enddo<br class="">+     broad_abs(i)=broad_abs(i)/norm<br class="">+enddo<br class="">+<br class="">+!compute DOS using a lorentzian<br class="">+if (ipol==1) then<br class="">+   excdos(1:spectra_nstep)=0.d0<br class="">+   do i=0,spectra_nstep-1<br class="">+       do j=1,n_eig<br class="">+          excdos(i+1)=excdos(i+1)+2.d0*eta/(PI*((en(j)-spectra_e_min-dble(i)*step)**2+eta**2))<br class="">+       enddo<br class="">+   enddo<br class="">+   excdos(1:spectra_nstep)=excdos(1:spectra_nstep)/(2.d0*n_eig)<br class="">+endif<br class="">+<br class="">+<br class="">+<br class="">+write(*,*) 'Absorption' <br class="">+write(*,*) 'Energy(eV)   Eps2 Eps2(Nogaussbroad)'<br class="">+<br class="">+!print absorption spectrum on file<br class="">+if(ionode) then<br class="">+   iun = find_free_unit()<br class="">+<br class="">+   if (ipol==1) then<br class="">+      open(unit=iun, file=trim(tmp_dir)//trim(prefix)//'.eps2x.dat', status='unknown', form='formatted')<br class="">+   elseif (ipol==2) then<br class="">+      open(unit=iun, file=trim(tmp_dir)//trim(prefix)//'.eps2y.dat', status='unknown', form='formatted')<br class="">+   elseif (ipol==3) then<br class="">+      open(unit=iun, file=trim(tmp_dir)//trim(prefix)//'.eps2z.dat', status='unknown', form='formatted')<br class="">+   endif<br class="">+<br class="">+   do i=1,spectra_nstep<br class="">+      write(iun,*) omega_g(i),broad_abs(i), absorption (i)<br class="">+      write(*,*) omega_g(i),broad_abs(i), absorption(i)<br class="">+   enddo<br class="">+   close(iun)<br class="">+endif<br class="">+<br class="">+!print excdos spectrum on file<br class="">+if(ionode.and.(ipol==1)) then<br class="">+   sumdos=0.d0<br class="">+   iun = find_free_unit()<br class="">+   open(unit=iun, file=trim(tmp_dir)//trim(prefix)//'.excdos.dat', status='unknown', form='formatted')<br class="">+   do i=1,spectra_nstep<br class="">+      write(iun,*) omega_g(i),excdos(i)<br class="">+      sumdos=sumdos+excdos(i)<br class="">+   enddo<br class="">+   close(iun)<br class="">+   write(*,*) 'sumdos=',sumdos/dble(spectra_nstep)<br class="">+endif<br class="">+<br class="">+deallocate(omega_g,absorption,broad_abs,cspectrum,den,campl,excdos)<br class="">+<br class="">+call stop_clock('build_spectrum')<br class="">+end subroutine<br class="">+<br class=""><br class="">Added: trunk/espresso/GWW/bse/start_bse.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/start_bse.f90<span class="Apple-tab-span" style="white-space:pre">    </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/start_bse.f90<span class="Apple-tab-span" style="white-space:pre">    </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,18 @@<br class="">+subroutine start_bse<br class="">+  !<br class="">+  !  Usage: [mpirun, mpprun, whatever] postproc [-npool N]<br class="">+  !<br class="">+  !  Wrapper routine for postprocessing initialization<br class="">+  !<br class="">+  USE mp_global,     ONLY: mp_startup<br class="">+  USE environment,   ONLY: environment_start<br class="">+  implicit none<br class="">+  character(len=9) :: code = 'BSE'<br class="">+  !<br class="">+#ifdef __PARA<br class="">+  CALL mp_startup ( )<br class="">+#endif<br class="">+  CALL environment_start ( code )<br class="">+  ! <br class="">+  return<br class="">+end subroutine start_bse<br class=""><br class="">Added: trunk/espresso/GWW/bse/tmp.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/tmp.f90<span class="Apple-tab-span" style="white-space:pre">       </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/tmp.f90<span class="Apple-tab-span" style="white-space:pre">  </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,45 @@<br class="">+subroutine make_v_state(numb_v,v)<br class="">+  USE gvect,                 ONLY : gstart<br class="">+  USE lsda_mod,              ONLY : nspin<br class="">+  use wavefunctions_module,  ONLY : evc<br class="">+  use io_files,  ONLY : prefix, iunwfc<br class="">+  USE wvfct,    ONLY : nbnd, npwx,npw<br class="">+  implicit none<br class="">+<br class="">+  type(v_state) :: v<br class="">+  integer :: numb_v<br class="">+  <br class="">+  integer :: is,ivmax<br class="">+<br class="">+  v%nspin=nspin<br class="">+  v%numb_v(:)=numb_v(:)<br class="">+  v%npw=npw<br class="">+  v%gstart=gstart<br class="">+<br class="">+  allocate( evc( npwx, nbnd ) )<br class="">+  <br class="">+  if (nspin==1) then<br class="">+     ivmax= v%numb_v(1)<br class="">+  else <br class="">+     ivmax=max(v%numb_v(1),v%numb_v(2))<br class="">+  endif<br class="">+<br class="">+  allocate( v%wfn(v%npw,ivmax,v%nspin)<br class="">+  allocate( v%esp(ivmax,v%nspin)<br class="">+<br class="">+  do is=1,nspin<br class="">+     call davcio(evc,2*nwordwfc,iunwfc,is,-1)<br class="">+     do iv=1,v%numb_v(is)<br class="">+        v%wfn(1:v%npw,1:v%numb_v(is),is)=evc(1:v%npw,1:v%numb_v(is))<br class="">+     enddo  <br class="">+        v%esp(1:v%numb_v(is),is)=et(1:v%numb_v(is),is)<br class="">+  enddo<br class="">+<br class="">+  deallocate(evc)<br class="">+<br class="">+  <br class="">+<br class="">+<br class="">+  return<br class="">+end subroutine<br class="">+<br class=""><br class="">Added: trunk/espresso/GWW/bse/transitions.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/transitions.f90<span class="Apple-tab-span" style="white-space:pre">    </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/transitions.f90<span class="Apple-tab-span" style="white-space:pre">  </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,13 @@<br class="">+! this module contains the variables related to the solution of the BSE <br class="">+! in transition space<br class="">+<br class="">+MODULE transitions<br class="">+<br class="">+USE kinds, ONLY: DP<br class="">+INTEGER, ALLOCATABLE :: ttab(:,:) !maps the (iv,ic) couple into the it index<br class="">+INTEGER, ALLOCATABLE :: itiv(:)!for the it-th transition gives the<br class="">+INTEGER, ALLOCATABLE :: itic(:)!corresponding valence and conduction band index respectively <br class="">+REAL(KIND=DP), ALLOCATABLE :: exch(:,:) !excitonic Hamiltonian in transition space<br class="">+<br class="">+<br class="">+END MODULE transitions<br class=""><br class="">Added: trunk/espresso/GWW/bse/tspace.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/tspace.f90<span class="Apple-tab-span" style="white-space:pre">   </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/tspace.f90<span class="Apple-tab-span" style="white-space:pre">       </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,187 @@<br class="">+subroutine tspace_diago(vstate,vstate_r,fc)<br class="">+! this subroutine solves teh BSE equation in transition space<br class="">+<br class="">+USE bse_wannier, ONLY : num_nbndv<br class="">+USE transitions, ONLY : ttab,itiv,itic,exch<br class="">+USE wvfct,       ONLY : nbnd<br class="">+USE io_global,   ONLY : stdout,ionode<br class="">+USE kinds,       ONLY : DP<br class="">+USE constants,   ONLY : RYTOEV<br class="">+USE mp,          ONLY : mp_barrier<br class="">+USE mp_world,             ONLY : world_comm<br class="">+USE bse_basic_structures <br class="">+USE fft_custom_gwl <br class="">+<br class="">+<br class="">+implicit none<br class="">+type(v_state) vstate<br class="">+type(v_state_r) vstate_r<br class="">+type(fft_cus) :: fc<br class="">+<br class="">+integer                         :: nt,it ! number of transitions<br class="">+real(kind=DP),    allocatable   :: eig(:)<br class="">+<br class="">+! for zheev<br class="">+integer                         :: info<br class="">+real(kind=DP), allocatable   :: work(:)<br class="">+<br class="">+call start_clock('tspace_diago')<br class="">+! compute the number of transitions<br class="">+nt=num_nbndv(1)*(nbnd-num_nbndv(1))<br class="">+if(ionode) write(stdout,*) 'number of transitions nt:', nt<br class="">+<br class="">+! allocate and build the transition table (c,v)-->it<br class="">+allocate(ttab(nbnd,num_nbndv(1)))<br class="">+allocate(itiv(nt))<br class="">+allocate(itic(nt))<br class="">+<br class="">+call build_ttab<br class="">+<br class="">+! allocate and build the excitonic Hamiltonian in transition space<br class="">+allocate(exch(nt,nt))<br class="">+exch(1:nt,1:nt)=0.d0<br class="">+<br class="">+call mp_barrier(world_comm)<br class="">+call build_exch(vstate,vstate_r,fc)<br class="">+<br class="">+call mp_barrier(world_comm)<br class="">+! diagonalize (not parallel so only one proc will do it)<br class="">+<br class="">+allocate(eig(nt))<br class="">+if(ionode) then<br class="">+   allocate(work(3*nt-1))<br class="">+   call dsyev('V', 'U', nt, exch, nt, eig, work, 3*nt-1 , info)<br class="">+   eig(1:nt)=eig(1:nt)*RYTOEV <br class="">+   deallocate(work)<br class="">+endif<br class="">+<br class="">+call mp_barrier(world_comm)<br class="">+<br class="">+if(ionode) then<br class="">+   do it=1,nt <br class="">+      write(stdout,*) 'Eigenvalue number', it, eig(it)<br class="">+   enddo<br class="">+endif<br class="">+<br class="">+deallocate(ttab,itic,itiv,exch,eig)<br class="">+call stop_clock('tspace_diago')<br class="">+return<br class="">+end subroutine<br class="">+<br class="">+!--------------------!<br class="">+subroutine build_exch(vstate,vstate_r,fc)<br class="">+!this subroutine builds the excitonic Hamiltonian in transition space<br class="">+<br class="">+USE bse_wannier,           ONLY : num_nbndv<br class="">+USE wvfct,                 ONLY : nbnd, npwx,npw,et<br class="">+USE lsda_mod,              ONLY : nspin<br class="">+USE wavefunctions_module,  ONLY : evc<br class="">+USE io_files,              ONLY : prefix, iunwfc, nwordwfc<br class="">+USE transitions,           ONLY : ttab,exch<br class="">+USE io_global,             ONLY : stdout,ionode<br class="">+USE bse_basic_structures <br class="">+USE fft_custom_gwl <br class="">+USE exciton <br class="">+<br class="">+<br class="">+implicit none<br class="">+type(v_state),intent(in)    :: vstate<br class="">+type(v_state_r), intent(in) :: vstate_r<br class="">+type(fft_cus), intent(in)   :: fc<br class="">+<br class="">+!internal<br class="">+type(exc) :: phic<br class="">+type(exc) :: phicp<br class="">+type(exc) :: hphic<br class="">+integer   :: iv,ivp,ic,icp,is<br class="">+<br class="">+call start_clock('build_exch')<br class="">+<br class="">+call initialize_exc(phic)<br class="">+phic%label=1<br class="">+phic%npw=npw<br class="">+phic%numb_v=num_nbndv(1)<br class="">+allocate(phic%a(phic%npw,phic%numb_v))<br class="">+<br class="">+call initialize_exc(hphic)<br class="">+hphic%label=1<br class="">+hphic%npw=npw<br class="">+hphic%numb_v=num_nbndv(1)<br class="">+allocate(hphic%a(hphic%npw,hphic%numb_v))<br class="">+<br class="">+call initialize_exc(phicp)<br class="">+phicp%label=1<br class="">+phicp%npw=npw<br class="">+phicp%numb_v=num_nbndv(1)<br class="">+allocate(phicp%a(phicp%npw,phicp%numb_v))<br class="">+<br class="">+allocate( evc( npwx, nbnd ) )<br class="">+<br class="">+!read wavefunctions<br class="">+do is=1,nspin<br class="">+   call davcio(evc,2*nwordwfc,iunwfc,is,-1)<br class="">+enddo<br class="">+<br class="">+if(ionode) write(stdout,*) 'wfns read from disk'<br class="">+<br class="">+do iv=1,num_nbndv(1)<br class="">+   do ic=num_nbndv(1)+1,nbnd<br class="">+      <br class="">+      if(ionode) write(stdout,*) 'iv ic', iv, ic<br class="">+      phic%a(1:phic%npw,1:phic%numb_v)=dcmplx(0.d0,0.d0)<br class="">+      phic%a(1:phic%npw,iv)=evc(1:npw,ic)<br class="">+      call normalize_exc(phic)<br class="">+      !apply tyhe excitonic Hamiltonian to this ic,iv state<br class="">+      call exc_h_a(phic,hphic,vstate,vstate_r,fc) <br class="">+     <br class="">+      do ivp=iv,num_nbndv(1)<br class="">+          do icp= ic,nbnd<br class="">+             if(ionode) write(stdout,*) 'ivp icp', ivp, icp<br class="">+             phicp%a(1:phicp%npw,1:phicp%numb_v)=dcmplx(0.d0,0.d0)<br class="">+             phicp%a(1:phicp%npw,ivp)=evc(1:npw,icp)<br class="">+             call normalize_exc(phicp)<br class="">+             call sproduct_exc(phicp,hphic,exch(ttab(ic,iv),ttab(icp,ivp)))<br class="">+             if(ionode) write(stdout,*) 'Exc. Hamiltonian built for transition:', ttab(ic,iv),ttab(icp,ivp) <br class="">+          enddo !icp<br class="">+      enddo !ivp<br class="">+   enddo !ic<br class="">+enddo !iv<br class="">+<br class="">+call free_memory_exc_a(phic)<br class="">+deallocate(evc)<br class="">+<br class="">+call stop_clock('build_exch')<br class="">+return<br class="">+endsubroutine<br class="">+<br class="">+!--------------------!<br class="">+subroutine build_ttab<br class="">+!this subroutine builds the transition table<br class="">+<br class="">+USE wvfct,    ONLY : nbnd<br class="">+USE bse_wannier, ONLY:num_nbndv<br class="">+use transitions, ONLY:ttab,itiv,itic<br class="">+USE io_global, ONLY : stdout,ionode<br class="">+<br class="">+implicit none<br class="">+integer       :: it,iv,ic<br class="">+<br class="">+it=1<br class="">+<br class="">+do iv=1,num_nbndv(1)<br class="">+   do ic=num_nbndv(1)+1,nbnd<br class="">+      ttab(ic,iv)=it<br class="">+      itiv(it)=iv<br class="">+      itic(it)=ic<br class="">+      it=it+1<br class="">+   enddo<br class="">+enddo<br class="">+<br class="">+it=it-1<br class="">+<br class="">+if(ionode) write(stdout,*) 'ttab built, number of transitions found:', it<br class="">+if(ionode) write(stdout,*) 'total number of bands', nbnd<br class="">+if(ionode) write(stdout,*) 'number of valence bands', num_nbndv(1)<br class="">+return<br class="">+end subroutine<br class="">+!--------------------!<br class=""><br class="">Added: trunk/espresso/GWW/bse/write_wannier_matrix.f90<br class="">===================================================================<br class="">--- trunk/espresso/GWW/bse/write_wannier_matrix.f90<span class="Apple-tab-span" style="white-space:pre">  </span>                        (rev 0)<br class="">+++ trunk/espresso/GWW/bse/write_wannier_matrix.f90<span class="Apple-tab-span" style="white-space:pre"> </span>2016-03-21 11:09:18 UTC (rev 12231)<br class="">@@ -0,0 +1,59 @@<br class="">+ subroutine read_wannier_matrix<br class="">+!this read the inverse transfromation matrix from KS eigenstates<br class="">+!to ML wanniers on file, to be read by GWW code<br class="">+!the INVERSE matrix is calculated here<br class="">+<br class="">+  USE kinds, ONLY : DP<br class="">+!  USE wannier_gw, ONLY : u_trans, num_nbndv<br class="">+  USE wvfct,    ONLY : et,nbnd<br class="">+  USE io_global, ONLY : stdout,ionode,ionode_id<br class="">+!  USE io_files, ONLY : find_free_unit, prefix<br class="">+  USE io_files, ONLY : prefix, tmp_dir<br class="">+  USE mp, ONLY : mp_bcast<br class="">+  USE mp_world,             ONLY : world_comm<br class="">+  USE lsda_mod, ONLY :nspin<br class="">+  USE bse_basic_structures, ONLY : u_trans<br class="">+  use bse_wannier, ONLY:num_nbndv<br class="">+ <br class="">+  implicit none<br class="">+  INTEGER, EXTERNAL :: find_free_unit<br class="">+<br class="">+<br class="">+<br class="">+  INTEGER :: iunu, iw, is<br class="">+  INTEGER :: idumm<br class="">+  REAL(kind=DP), ALLOCATABLE :: rdummv(:)<br class="">+  <br class="">+  call start_clock('read_wannier_matrix')<br class="">+  allocate(rdummv(nbnd))<br class="">+<br class="">+<br class="">+  if(ionode) then<br class="">+     iunu = find_free_unit()<br class="">+     open(unit=iunu,file=trim(tmp_dir)//trim(prefix)//'.wannier',status='old',form='unformatted')<br class="">+  <br class="">+     read(iunu) idumm<br class="">+     read(iunu) idumm<br class="">+  endif<br class="">+  do is=1,nspin<br class="">+     if(ionode) then<br class="">+        read(iunu) idumm<br class="">+        read(iunu) rdummv(1:nbnd)<br class="">+        read(iunu) rdummv(1:nbnd)<br class="">+        read(iunu) rdummv(1:nbnd)<br class="">+     endif<br class="">+ <br class="">+<br class="">+     do iw=1,nbnd<br class="">+        if(ionode) read(iunu) u_trans(1:nbnd,iw,is)<br class="">+        call mp_bcast(u_trans(1:nbnd,iw,is),ionode_id, world_comm)       <br class="">+     enddo<br class="">+  enddo<br class="">+  if(ionode) close(iunu)<br class="">+  <br class="">+  deallocate(rdummv)<br class="">+<br class="">+<br class="">+  call stop_clock('read_wannier_matrix')<br class="">+  return<br class="">+end subroutine read_wannier_matrix<br class=""><br class="">_______________________________________________<br class="">Q-e-commits mailing list<br class=""><a href="mailto:Q-e-commits@qe-forge.org" class="">Q-e-commits@qe-forge.org</a><br class="">http://qe-forge.org/mailman/listinfo/q-e-commits<br class=""></blockquote><br class=""></div></div></body></html>