assemble the DIIS B matrix:
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=ip), | intent(in) | :: | n | |||
integer(kind=ip), | intent(in) | :: | nmat | |||
integer(kind=ip), | intent(in) | :: | ndiis | |||
real(kind=rp), | intent(in), | dimension(n, ndiis) | :: | e | ||
real(kind=rp), | intent(inout), | dimension(ndiis+1, ndiis+1) | :: | b |
subroutine makeb(n,nmat,ndiis,e,b)
!! assemble the DIIS B matrix:
implicit none
integer(ip), intent(in) :: n, nmat, ndiis
real(rp), dimension(n, ndiis), intent(in) :: e
real(rp), dimension(ndiis+1, ndiis+1), intent(inout) :: b
integer(ip) :: i
real(rp) :: bij
if(nmat == 1) then
! 1st built:
! [ 0 | 1 ]
! b = [ --+---- ]
! [ 1 | e*e ]
b(1,1) = 0.0_rp
b(1,2) = 1.0_rp
b(2,1) = 1.0_rp
b(2,2) = dot_product(e(:,1),e(:,1))
else
! subsequent builts
! first, update the lagrangian line:
b(nmat+1,1) = 1.0_rp
b(1,nmat+1) = 1.0_rp
! now, compute the new matrix elements:
do i = 1, nmat - 1
bij = dot_product(e(:,i),e(:,nmat))
b(nmat+1,i+1) = bij
b(i+1,nmat+1) = bij
end do
b(nmat+1,nmat+1) = dot_product(e(:,nmat),e(:,nmat))
end if
end subroutine makeb