|
| 1 | +module solver_class |
| 2 | + |
| 3 | + use t2g_hamiltonian_class |
| 4 | + use linalg |
| 5 | + |
| 6 | + !The Hamiltonian class - returns the diagonal and off diagonal |
| 7 | + !blocks of the Hamiltonian |
| 8 | + |
| 9 | + implicit none |
| 10 | + private |
| 11 | + real :: pi = 3.1415926535897931d0 ! Class-wide private constant |
| 12 | + integer,parameter :: dp = selected_real_kind(15,307) |
| 13 | + integer :: dim_fix |
| 14 | + integer :: system_size |
| 15 | + complex(kind=8), dimension(:,:,:), allocatable :: dLeft,cLeft,dRight,cRight |
| 16 | + |
| 17 | + !Construct the Solver class |
| 18 | + type, public :: Solver |
| 19 | + type(Hamiltonian) :: Ham |
| 20 | + integer :: num_steps = 1500 |
| 21 | + integer :: Nsize = 8192 |
| 22 | + integer :: dim = 6 |
| 23 | + real(kind=8) :: min_inv_field = 30.d0 |
| 24 | + real(kind=8) :: max_inv_field = 6000.d0 |
| 25 | + logical :: verbose = .true. |
| 26 | + contains |
| 27 | + procedure :: run => run_iter |
| 28 | +! procedure :: dos => get_dos |
| 29 | + end type Solver |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | +contains |
| 34 | + |
| 35 | + subroutine initialize(this) |
| 36 | + class(Solver), intent(in) :: this |
| 37 | + |
| 38 | + system_size = this%Nsize |
| 39 | + dim_fix = this%dim |
| 40 | + |
| 41 | + allocate(dLeft(system_size,dim_fix,dim_fix),cLeft(system_size,dim_fix,dim_fix)) |
| 42 | + allocate(dRight(system_size,dim_fix,dim_fix),cRight(system_size,dim_fix,dim_fix)) |
| 43 | + |
| 44 | + end subroutine initialize |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | + subroutine run_iter(this) |
| 49 | + class(Solver), intent(in) :: this |
| 50 | + integer :: b |
| 51 | + real(kind=8) :: dos, dfield, bfield, invbfield |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | + !system_size = this%Nsize |
| 56 | + do b=1,this%num_steps |
| 57 | + call initialize(this) |
| 58 | + dos = 0.d0 |
| 59 | + dfield = (this%max_inv_field - this%min_inv_field)/this%num_steps |
| 60 | + bfield = 1.d0/(1.d0*this%min_inv_field + 1.d0*(b-1)*dfield) |
| 61 | + invbfield = 1.d0/bfield |
| 62 | + |
| 63 | + |
| 64 | + dos = get_dos(this,bfield) |
| 65 | + |
| 66 | + if (this%verbose) then |
| 67 | + write(6,"(3F30.15,1I10)"), bfield, invbfield, dos, system_size |
| 68 | + endif |
| 69 | + |
| 70 | + deallocate(dLeft,cLeft,dRight,cRight) |
| 71 | + |
| 72 | + enddo |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | + end subroutine run_iter |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | + function get_dos(this, bfield) result(dos2) |
| 84 | + !Gets a diagonal block of the Hamiltonian |
| 85 | + class(Solver), intent(in) :: this |
| 86 | + real(kind=8), intent(in) :: bfield |
| 87 | + real(kind=8) :: dos2 |
| 88 | + complex(kind=8), dimension(dim_fix,dim_fix) :: block |
| 89 | + |
| 90 | + dLeft(:,:,:) = dcmplx(0.d0,0.d0) |
| 91 | + cLeft(:,:,:) = dcmplx(0.d0,0.d0) |
| 92 | + dRight(:,:,:) = dcmplx(0.d0,0.d0) |
| 93 | + cRight(:,:,:) = dcmplx(0.d0,0.d0) |
| 94 | + |
| 95 | + |
| 96 | + call downsweep(this, bfield) |
| 97 | + call upsweep(this, bfield) |
| 98 | + dos2 = calc_dos(this, bfield) |
| 99 | + |
| 100 | + end function get_dos |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | + subroutine downsweep(this, bfield) |
| 105 | + class(Solver), intent(in) :: this |
| 106 | + real(kind=8), intent(in) :: bfield |
| 107 | + complex(kind=8), dimension(dim_fix,dim_fix) :: extra_term |
| 108 | + complex(kind=8), dimension(dim_fix,dim_fix) :: dinv |
| 109 | + integer :: i |
| 110 | + |
| 111 | + do i=1,system_size-1 |
| 112 | + if (i.eq.1) then |
| 113 | + dLeft(i,:,:) = this%Ham%diag(i,bfield,0.d0,0.d0) |
| 114 | + else |
| 115 | + extra_term = matmul(cLeft(i-1,:,:),this%Ham%rBlock(i-1,bfield,0.d0,0.d0)) |
| 116 | + dLeft(i,:,:) = this%Ham%diag(i,bfield,0.d0,0.d0) + extra_term |
| 117 | + endif |
| 118 | + |
| 119 | + dinv = findinv(dLeft(i,:,:), dim_fix) |
| 120 | + cLeft(i,:,:) = dcmplx(-1.d0,0.d0)*matmul(this%Ham%lBlock(i+1,bfield,0.d0,0.d0),dinv) |
| 121 | + enddo |
| 122 | + |
| 123 | + i = system_size |
| 124 | + dLeft(i,:,:) = this%Ham%diag(i, bfield,0.d0,0.d0) & |
| 125 | + + matmul(cLeft(i-1,:,:),this%Ham%rBlock(i-1,bfield,0.d0,0.d0)) |
| 126 | + |
| 127 | + end subroutine downsweep |
| 128 | + |
| 129 | + |
| 130 | + subroutine upsweep(this, bfield) |
| 131 | + class(Solver), intent(in) :: this |
| 132 | + real(kind=8), intent(in) :: bfield |
| 133 | + complex(kind=8), dimension(dim_fix,dim_fix) :: extra_term |
| 134 | + complex(kind=8), dimension(dim_fix,dim_fix) :: dinv |
| 135 | + integer :: i,j |
| 136 | + |
| 137 | + do j=0,system_size-2 |
| 138 | + i = system_size - j |
| 139 | + if (i.eq.system_size) then |
| 140 | + dRight(i,:,:) = this%Ham%diag(i,bfield,0.d0,0.d0) |
| 141 | + else |
| 142 | + extra_term = matmul(cRight(i+1,:,:),this%Ham%lBlock(i+1,bfield,0.d0,0.d0)) |
| 143 | + dRight(i,:,:) = this%Ham%diag(i,bfield,0.d0,0.d0) + extra_term |
| 144 | + endif |
| 145 | + |
| 146 | + dinv = findinv(dRight(i,:,:), dim_fix) |
| 147 | + cRight(i,:,:) = dcmplx(-1.d0,0.d0)*matmul(this%Ham%rBlock(i-1,bfield,0.d0,0.d0),dinv) |
| 148 | + enddo |
| 149 | + |
| 150 | + i = 1 |
| 151 | + dRight(i,:,:) = this%Ham%diag(i, bfield,0.d0,0.d0) & |
| 152 | + + matmul(cRight(i+1,:,:),this%Ham%lBlock(i+1,bfield,0.d0,0.d0)) |
| 153 | + |
| 154 | + end subroutine upsweep |
| 155 | + |
| 156 | + |
| 157 | + |
| 158 | + |
| 159 | + function calc_dos(this, bfield) result(dos1) |
| 160 | + class(Solver), intent(in) :: this |
| 161 | + real(kind=8), intent(in) :: bfield |
| 162 | + real(kind=8) :: dos1 |
| 163 | + complex(kind=8) :: trace |
| 164 | + |
| 165 | + complex(kind=8), dimension(dim_fix,dim_fix) :: ginv, g |
| 166 | + integer :: i,j |
| 167 | + |
| 168 | + dos1=0.d0 |
| 169 | + do i=1,system_size |
| 170 | + ginv = - this%Ham%diag(i, bfield,0.d0,0.d0) + dLeft(i,:,:) + dRight(i,:,:) |
| 171 | + g = findinv(ginv, dim_fix) |
| 172 | + |
| 173 | + trace = cmplx(0.d0,0.d0) |
| 174 | + do j=1,dim_fix |
| 175 | + trace = trace + g(j,j) |
| 176 | + enddo |
| 177 | + dos1 = dos1 - ( 1.d0/ (pi * system_size) ) * aimag(trace) |
| 178 | + !write(6,*) i,dos1 |
| 179 | + enddo |
| 180 | + |
| 181 | + end function calc_dos |
| 182 | + |
| 183 | + |
| 184 | + |
| 185 | +end module solver_class |
| 186 | + |
| 187 | + |
0 commit comments