Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of SCI method #90

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/CI/CIInitial.f90
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ function CIInitial_calculateEnergyOne( n, thisA, thisB ) result (auxCIenergy)

end function CIInitial_calculateEnergyOne


function CIInitial_calculateEnergyTwo( n, thisA, thisB ) result (auxCIenergy)
implicit none
integer(8) :: thisA(:), thisB(:)
Expand Down Expand Up @@ -521,7 +522,7 @@ function CIInitial_calculateEnergyTwo( n, thisA, thisB ) result (auxCIenergy)

auxCIenergy = auxCIenergy + &
CIcore_instance%fourCenterIntegrals(i,j)%values(auxIndex, 1)

end if
end do
end do
Expand Down
83 changes: 48 additions & 35 deletions src/CI/CIJadamilu.f90
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ subroutine CIJadamilu_buildCouplingMatrix()
integer(8), allocatable :: indexConfB(:)
integer(1), allocatable :: couplingOrder(:)

numberOfSpecies = MolecularSystem_getNumberOfQuantumSpecies()
numberOfSpecies = CIcore_instance%numberOfQuantumSpecies
coupling = 0

!! allocate arrays
Expand Down Expand Up @@ -79,7 +79,7 @@ subroutine CIJadamilu_buildCouplingOrderList()
integer :: ssize
integer, allocatable :: cilevel(:)

numberOfSpecies = MolecularSystem_getNumberOfQuantumSpecies()
numberOfSpecies = CIcore_instance%numberOfQuantumSpecies

ssize = 1
do i = 1, numberOfSpecies
Expand Down Expand Up @@ -428,7 +428,7 @@ subroutine matvec2 ( nx, v, w, iter)
if ( abs(v(i) ) >= tol) nonzero = nonzero + 1
end do

numberOfSpecies = MolecularSystem_getNumberOfQuantumSpecies()
numberOfSpecies = CIcore_instance%numberOfQuantumSpecies

allocate ( indexConf ( numberOfSpecies, nproc ) )
allocate ( auxindexConf ( numberOfSpecies, nproc ) )
Expand Down Expand Up @@ -654,7 +654,7 @@ function CIJadamilu_buildMatrixRecursion2(nproc, s, indexConf, auxindexConf, cc,
integer :: auxcilevel(:,:)
integer, allocatable :: counter(:)

numberOfSpecies = MolecularSystem_getNumberOfQuantumSpecies()
numberOfSpecies = CIcore_instance%numberOfQuantumSpecies

allocate (counter(numberOfSpecies))
counter = 0
Expand Down Expand Up @@ -709,6 +709,7 @@ subroutine CIJadamilu_buildRow( nn, indexConfA, c, w, vc, cilevelA)
integer :: numberOfSpecies, s
integer, allocatable :: stringAinB(:)
integer(4) :: coupling
integer(4) :: coupling2
integer(4) :: ssize,auxcoupling(3) !! 0,1,2
integer(8) :: indexConfA(:)
integer(8), allocatable :: indexConfB(:)
Expand All @@ -723,7 +724,7 @@ subroutine CIJadamilu_buildRow( nn, indexConfA, c, w, vc, cilevelA)

!!$ CIcore_instance%timeA(1) = omp_get_wtime()

numberOfSpecies = MolecularSystem_getNumberOfQuantumSpecies()
numberOfSpecies = CIcore_instance%numberOfQuantumSpecies

do i = 1, numberOfSpecies

Expand All @@ -746,23 +747,27 @@ subroutine CIJadamilu_buildRow( nn, indexConfA, c, w, vc, cilevelA)
do ci = 1, size(CIcore_instance%numberOfStrings(i)%values, dim = 1)
do b = 1 + ssize , CIcore_instance%numberOfStrings(i)%values(ci) + ssize

!b = ssize + bb
do p = CIcore_instance%numberOfCoreOrbitals%values(i)+1, &
CIcore_instance%numberOfOccupiedOrbitals%values(i)
!do p = 1, &
!do p = CIcore_instance%numberOfCoreOrbitals%values(i)+1, &
! CIcore_instance%numberOfOccupiedOrbitals%values(i)
! stringAinB(p) = CIcore_instance%orbitals(i)%values( &
! CIcore_instance%strings(i)%values(p,a),b)
!end do

stringAinB(p) = CIcore_instance%orbitals(i)%values( &
CIcore_instance%strings(i)%values(p,a),b)
!coupling = CIcore_instance%numberOfOccupiedOrbitals%values(i) - sum ( stringAinB ) - CIcore_instance%numberOfCoreOrbitals%values(i)

!coupling = 0
!!$omp simd
!do p = CIcore_instance%numberOfCoreOrbitals%values(i)+1, CIcore_instance%numberOfOrbitals%values(i)
! coupling = coupling + CIcore_instance%orbitals(i)%values(p,a) * CIcore_instance%orbitals(i)%values(p,b)
!end do
!coupling = CIcore_instance%numberOfOccupiedOrbitals%values(i) - coupling - CIcore_instance%numberOfCoreOrbitals%values(i)

!stringBinA(p) = CIcore_instance%orbitals(i)%values( &
! CIcore_instance%strings(i)%values(p,b),a)
end do

coupling = CIcore_instance%numberOfOccupiedOrbitals%values(i) - sum ( stringAinB ) - &
CIcore_instance%numberOfCoreOrbitals%values(i)
coupling = CIcore_instance%numberOfOccupiedOrbitals%values(i) - sum(CIcore_instance%orbitals(i)%values(:,a) * CIcore_instance%orbitals(i)%values(:,b)) ! - CIcore_instance%numberOfCoreOrbitals%values(i)

! coupling = CIcore_instance%numberOfOccupiedOrbitals%values(i) - sum ( stringAinB )
!!$omp simd
!coupling = sum(abs(CIcore_instance%orbitals(i)%values(:,a) - CIcore_instance%orbitals(i)%values(:,b)))
!coupling = coupling / 2

if ( coupling <= 2 ) then

Expand Down Expand Up @@ -823,6 +828,7 @@ subroutine CIJadamilu_buildRow( nn, indexConfA, c, w, vc, cilevelA)
do ci = 1, size(CIcore_instance%numberOfStrings(i)%values, dim = 1) !! 1 is always zero
cilevel(i) = ci - 1

if ( CIcore_instance%nCouplingOneTwo(i,nn)%values( 2,ci ) == 0 ) cycle
auxos = CIJadamilu_buildRowRecursionFirstOne( i, indexConfA, indexConfB, nn, cilevel )

end do
Expand All @@ -832,7 +838,6 @@ subroutine CIJadamilu_buildRow( nn, indexConfA, c, w, vc, cilevelA)
!!$ CIcore_instance%timeB(3) = omp_get_wtime()

!!$ CIcore_instance%timeA(4) = omp_get_wtime()

!$omp atomic
w(c) = w(c) + vc*CIcore_instance%diagonalHamiltonianMatrix%values(c)
!$omp end atomic
Expand All @@ -849,7 +854,7 @@ subroutine CIJadamilu_buildRow( nn, indexConfA, c, w, vc, cilevelA)

do ci = 1, size(CIcore_instance%numberOfStrings(i)%values, dim = 1) !! 1 is always zero
cilevel(i) = ci - 1

if ( CIcore_instance%nCouplingOneTwo(i,nn)%values( 2,ci ) == 0 ) cycle
do u = 1, CIcore_instance%sizeciorderlist
if ( sum(abs(cilevel - &
CIcore_instance%ciorderlist( CIcore_instance%auxciorderlist(u), :))) == 0 ) then
Expand Down Expand Up @@ -877,7 +882,7 @@ subroutine CIJadamilu_buildRow( nn, indexConfA, c, w, vc, cilevelA)

do ci = 1, size(CIcore_instance%numberOfStrings(i)%values, dim = 1) !! 1 is always zero
cilevel(i) = ci - 1

if ( CIcore_instance%nCouplingOneTwo(i,nn)%values( 3,ci ) == 0 ) cycle
do u = 1, CIcore_instance%sizeCiOrderList
if ( sum(abs(cilevel - &
CIcore_instance%ciOrderList( CIcore_instance%auxciOrderList(u), :))) == 0 ) then
Expand Down Expand Up @@ -911,7 +916,9 @@ subroutine CIJadamilu_buildRow( nn, indexConfA, c, w, vc, cilevelA)

do ci = 1, size(CIcore_instance%numberOfStrings(i)%values, dim = 1) !! 1 is always zero
cilevel(i) = ci - 1
if ( CIcore_instance%nCouplingOneTwo(i,nn)%values( 2,ci ) == 0 ) cycle
do cj = 1, size(CIcore_instance%numberOfStrings(j)%values, dim = 1) !! 1 is always zero
if ( CIcore_instance%nCouplingOneTwo(j,nn)%values( 2,cj ) == 0 ) cycle
cilevel(j) = cj - 1
do u = 1, CIcore_instance%sizeCiOrderList
if ( sum(abs(cilevel - &
Expand Down Expand Up @@ -984,7 +991,7 @@ recursive function CIJadamilu_buildRowRecursionSecondOne( ii, indexConfB, w, vc
real(8) :: CIenergy
integer :: cilevel(:)

numberOfSpecies = MolecularSystem_getNumberOfQuantumSpecies()
numberOfSpecies = CIcore_instance%numberOfQuantumSpecies
ci = cilevel(ii) + 1
ssize = CIcore_instance%nCouplingSize(ii,nn)%values( 2,ci )

Expand Down Expand Up @@ -1030,7 +1037,7 @@ function CIJadamilu_buildRowRecursionSecondTwoCal( ii, indexConfA, indexConfB, w
real(8) :: CIenergy
integer :: cilevel(:)

numberOfSpecies = MolecularSystem_getNumberOfQuantumSpecies()
numberOfSpecies = CIcore_instance%numberOfQuantumSpecies
ci = cilevel(ii) + 1
ssize = CIcore_instance%nCouplingSize(ii,nn)%values( 3,ci )

Expand Down Expand Up @@ -1075,7 +1082,7 @@ function CIJadamilu_buildRowRecursionSecondTwoGet( ii, indexConfA, indexConfB, w
real(8) :: CIenergy
integer :: cilevel(:)

numberOfSpecies = MolecularSystem_getNumberOfQuantumSpecies()
numberOfSpecies = CIcore_instance%numberOfQuantumSpecies
ci = cilevel(ii) + 1
ssize = CIcore_instance%nCouplingSize(ii,nn)%values( 3,ci )

Expand Down Expand Up @@ -1107,20 +1114,22 @@ end function CIJadamilu_buildRowRecursionSecondTwoGet
function CIJadamilu_buildRowRecursionSecondTwoDiff( ii, jj, indexConfB, w, vc, dd, nn, cilevel, u ) result (os)
implicit none

integer, intent(in) :: ii, nn, u, jj
integer, intent(in) :: cilevel(:)
integer(8), intent(out) :: dd(:)
real(8), intent(in) :: vc
integer(8), intent(inout) :: indexConfB(:)
real(8), intent(inout) :: w(:)
integer(8) :: ai,aj,d, aai, aaj
integer :: ii, nn, ci, u, k, jj, cj
integer :: ssizei, ssizej
integer :: ci, k, cj
integer(8) :: ssizei, ssizej
integer(8) :: dd_i_shift, dd_j_shift
integer :: bi, bj, factor, factori
integer :: auxIndex1, auxIndex2, auxIndex
integer :: os,numberOfSpecies
integer(8) :: indexConfB(:)
integer(8) :: dd(:)
real(8) :: vc
real(8) :: w(:)
real(8) :: CIenergy
integer :: cilevel(:)

numberOfSpecies = MolecularSystem_getNumberOfQuantumSpecies()
numberOfSpecies = CIcore_instance%numberOfQuantumSpecies
ci = cilevel(ii) + 1
cj = cilevel(jj) + 1
ssizei = CIcore_instance%nCouplingSize(ii,nn)%values( 2,ci )
Expand All @@ -1131,11 +1140,16 @@ function CIJadamilu_buildRowRecursionSecondTwoDiff( ii, jj, indexConfB, w, vc, d
CIcore_instance%ciOrderSize1(u,k) )* CIcore_instance%ciOrderSize2(u,k)
end do

dd_i_shift = - CIcore_instance%numberOfStrings2(ii)%values(ci) + &
CIcore_instance%ciOrderSize1(u,ii)

dd_j_shift = - CIcore_instance%numberOfStrings2(jj)%values(cj) + &
CIcore_instance%ciOrderSize1(u,jj)

do aai = 1, CIcore_instance%nCouplingOneTwo(ii,nn)%values( 2,ci )
ai = ssizei + aai
indexConfB(ii) = CIcore_instance%couplingMatrix(ii,nn)%values(ai, 2)
dd(ii) = (indexConfB(ii) - CIcore_instance%numberOfStrings2(ii)%values(ci) + &
CIcore_instance%ciOrderSize1(u,ii) )* CIcore_instance%ciOrderSize2(u,ii)
dd(ii) = (indexConfB(ii) + dd_i_shift )* CIcore_instance%ciOrderSize2(u,ii)

bi = indexConfB(ii)
factori = CIcore_instance%couplingMatrixFactorOne(ii,nn)%values(bi)
Expand All @@ -1146,8 +1160,7 @@ function CIJadamilu_buildRowRecursionSecondTwoDiff( ii, jj, indexConfB, w, vc, d
aj = ssizej + aaj
indexConfB(jj) = CIcore_instance%couplingMatrix(jj,nn)%values(aj, 2)

dd(jj) = (indexConfB(jj) - CIcore_instance%numberOfStrings2(jj)%values(cj) + &
CIcore_instance%ciOrderSize1(u,jj) )* CIcore_instance%ciOrderSize2(u,jj)
dd(jj) = (indexConfB(jj) + dd_j_shift )* CIcore_instance%ciOrderSize2(u,jj)

d = sum(dd)
!CIenergy = vc*CIcore_calculateEnergyTwoDiff ( ii, jj, indexConfB, nn )
Expand Down
8 changes: 8 additions & 0 deletions src/CI/CIOrder.f90
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ subroutine CIOrder_settingCILevel()

CIcore_instance%maxCILevel = sum(CIcore_instance%CILevel)

case ( "SCI" ) !! same as FCI

do i=1, numberOfSpecies
CIcore_instance%CILevel(i) = CIcore_instance%numberOfOccupiedOrbitals%values(i)
end do

CIcore_instance%maxCILevel = sum(CIcore_instance%CILevel)

case ( "CIS" )

do i=1, numberOfSpecies
Expand Down
Loading
Loading