2021-02-12 12:04:21 +01:00
|
|
|
program QMCChem_dataset_test
|
|
|
|
use Sherman_Morrison, only : MaponiA3
|
2021-02-12 19:31:31 +01:00
|
|
|
use Utils, only : Read_dataset
|
2021-02-12 12:04:21 +01:00
|
|
|
use, intrinsic :: iso_c_binding, only : c_int, c_double
|
|
|
|
implicit none
|
|
|
|
|
2021-02-12 17:48:49 +01:00
|
|
|
integer :: i, j, col !! Iterators
|
2021-02-12 12:04:21 +01:00
|
|
|
integer :: cycle_id, dim, n_updates
|
|
|
|
integer(c_int), dimension(:), allocatable :: Updates_index
|
2021-02-22 09:50:42 +01:00
|
|
|
real(c_double), dimension(:,:), allocatable :: Updates
|
|
|
|
real(c_double), dimension(:,:), allocatable :: S, S_inv, S_inv_trans
|
2021-02-12 12:04:21 +01:00
|
|
|
|
2021-02-22 10:51:07 +01:00
|
|
|
call Read_dataset("dataset.dat", &
|
2021-02-12 19:31:31 +01:00
|
|
|
cycle_id, &
|
|
|
|
dim, &
|
|
|
|
n_updates, &
|
|
|
|
S, &
|
|
|
|
S_inv, &
|
|
|
|
Updates_index, &
|
|
|
|
Updates)
|
The algorithm now works for the following 4x4 example with 2 updates:
S = [1,0,1,-1; 0,1,1,0; -1,0,-1,0; 1,1,1,1]
S_inv = [1,-1,1,1; 1,0,2,1; -1,1,-2,-1; -1,0,-1,0]
u1 = [0,-2,0,0]
u2 = [0,-1,0,0]
upd_idx = [2,4]
To go from Maponi's examples where the number of updates is always equal
to the the dimension of the matrix, and the decomposition is always
diagonal, to cases with a non-diagonal decomposition and a number of
updates unequal to its size, the following changed needed to be made:
* in the calculation of the {y0k} an extra inner for-loop needs to be
added to make it a full matrix-vector multiplication due to the fact
that A0 is not a diagonal matrix
* in some places the use of the update-order vector p needs
the be replaced with that of upd_idx to make sure the correct
component of the ylk is selected and the proper rank-1 matrices are
constructed
* when a matrix is passed from Fortran to C++ with 2D adressing, it is
passed in colum-major order. The passed matrix needs to be transposed
before passing to C++. Doing this inside the algorithm will break
compatibility with called from C/C++.
2021-02-21 18:28:08 +01:00
|
|
|
|
2021-02-12 17:48:49 +01:00
|
|
|
!! Write current S and S_inv to file for check in Octave
|
|
|
|
open(unit = 2000, file = "Slater_old.dat")
|
2021-02-18 19:43:20 +01:00
|
|
|
open(unit = 3000, file = "Slater_old_inv.dat")
|
2021-02-12 17:48:49 +01:00
|
|
|
do i=1,dim
|
|
|
|
do j=1,dim
|
|
|
|
write(2000,"(E23.15, 1X)", advance="no") S(i,j)
|
2021-02-22 09:50:42 +01:00
|
|
|
write(3000,"(E23.15, 1X)", advance="no") S_inv(i,j)
|
2021-02-12 17:48:49 +01:00
|
|
|
end do
|
|
|
|
write(2000,*)
|
|
|
|
write(3000,*)
|
|
|
|
end do
|
|
|
|
close(2000)
|
|
|
|
close(3000)
|
|
|
|
|
2021-02-18 19:43:20 +01:00
|
|
|
!! Write Updates to file to check
|
|
|
|
open(unit = 2000, file = "Updates.dat")
|
|
|
|
do i=1,dim
|
|
|
|
do j=1,n_updates
|
|
|
|
write(2000,"(E23.15, 1X)", advance="no") Updates(i,j)
|
|
|
|
end do
|
|
|
|
write(2000,*)
|
|
|
|
end do
|
|
|
|
close(2000)
|
2021-02-12 17:48:49 +01:00
|
|
|
|
2021-02-18 19:43:20 +01:00
|
|
|
!! Update S
|
2021-02-12 17:48:49 +01:00
|
|
|
do j=1,n_updates
|
|
|
|
do i=1,dim
|
|
|
|
col = Updates_index(j)
|
2021-02-18 19:43:20 +01:00
|
|
|
S(i,col) = S(i,col) + Updates(i,j)
|
2021-02-12 17:48:49 +01:00
|
|
|
end do
|
|
|
|
end do
|
|
|
|
|
2021-02-22 09:50:42 +01:00
|
|
|
!! Update S_inv
|
|
|
|
call MaponiA3(S_inv, dim, n_updates, Updates, Updates_index)
|
2021-02-18 19:43:20 +01:00
|
|
|
|
2021-02-12 17:48:49 +01:00
|
|
|
!! Write new S and S_inv to file for check in Octave
|
2021-02-18 19:43:20 +01:00
|
|
|
open(unit = 4000, file = "Slater.dat")
|
|
|
|
open(unit = 5000, file = "Slater_inv.dat")
|
2021-02-12 17:48:49 +01:00
|
|
|
do i=1,dim
|
|
|
|
do j=1,dim
|
2021-02-18 19:43:20 +01:00
|
|
|
write(4000,"(E23.15, 1X)", advance="no") S(i,j)
|
|
|
|
write(5000,"(E23.15, 1X)", advance="no") S_inv(i,j)
|
2021-02-12 17:48:49 +01:00
|
|
|
end do
|
2021-02-18 19:43:20 +01:00
|
|
|
write(4000,*)
|
|
|
|
write(5000,*)
|
2021-02-12 17:48:49 +01:00
|
|
|
end do
|
2021-02-18 19:43:20 +01:00
|
|
|
close(4000)
|
|
|
|
close(5000)
|
2021-02-12 12:04:21 +01:00
|
|
|
|
|
|
|
deallocate(S, S_inv, Updates, Updates_index)
|
|
|
|
end program
|