23 integer,
parameter ::
dp = kind(1.0d0)
52 logical :: integration
64 character(20) :: bml_type
74 integer,
parameter :: nkey_char = 1, nkey_int = 5, nkey_re = 2, nkey_log = 2
75 character(len=*) :: filename
78 character(len=50),
parameter :: keyvector_char(nkey_char) = [character(len=100) :: &
80 character(len=100) :: valvector_char(nkey_char) = [character(len=100) :: &
83 character(len=50),
parameter :: keyvector_int(nkey_int) = [character(len=50) :: &
84 'Verbose=',
'NFirst=',
'NRefI=',
'NRefF=',
'MDim=']
85 integer :: valvector_int(nkey_int) = (/ &
88 character(len=50),
parameter :: keyvector_re(nkey_re) = [character(len=50) :: &
89 'NumthreshI=',
'NumthreshF=' ]
90 real(
dp) :: valvector_re(nkey_re) = (/&
93 character(len=50),
parameter :: keyvector_log(nkey_log) = [character(len=100) :: &
95 logical :: valvector_log(nkey_log) = (/&
99 character(len=50),
parameter :: startstop(2) = [character(len=50) :: &
103 ,keyvector_int,valvector_int,keyvector_re,valvector_re,&
104 keyvector_log,valvector_log,trim(filename),startstop)
107 if(valvector_char(1) ==
"Dense")
then
108 input%bml_type = bml_matrix_dense
109 elseif(valvector_char(1) ==
"Ellpack")
then
110 input%bml_type = bml_matrix_ellpack
111 elseif(valvector_char(1) ==
"Ellblock")
then
112 input%bml_type = bml_matrix_ellblock
116 input%verbose = valvector_int(1)
117 input%nfirst = valvector_int(2)
118 input%nrefi = valvector_int(3)
119 input%nreff = valvector_int(4)
120 input%mdim = valvector_int(5)
123 input%zsp = valvector_log(1)
124 input%integration = valvector_log(2)
127 input%numthresi = valvector_re(1)
128 input%numthresf = valvector_re(2)
139 ,zk4_bml,zk5_bml,zk6_bml,norb,bml_type,bml_element_type)
140 integer :: norb, igenz
141 character(20) :: bml_type, my_bml_element_type
142 character(20),
optional :: bml_element_type
143 type(bml_matrix_t) :: zk1_bml
144 type(bml_matrix_t) :: zk2_bml
145 type(bml_matrix_t) :: zk3_bml
146 type(bml_matrix_t) :: zk4_bml
147 type(bml_matrix_t) :: zk5_bml
148 type(bml_matrix_t) :: zk6_bml
150 if(
present(bml_element_type))
then
151 my_bml_element_type = bml_element_type
153 my_bml_element_type = bml_element_real
158 if(bml_get_n(zk1_bml).le.0)
then
159 call bml_zero_matrix(bml_type,my_bml_element_type,
dp,norb,norb,zk1_bml)
160 call bml_zero_matrix(bml_type,my_bml_element_type,
dp,norb,norb,zk2_bml)
161 call bml_zero_matrix(bml_type,my_bml_element_type,
dp,norb,norb,zk3_bml)
162 call bml_zero_matrix(bml_type,my_bml_element_type,
dp,norb,norb,zk4_bml)
163 call bml_zero_matrix(bml_type,my_bml_element_type,
dp,norb,norb,zk5_bml)
164 call bml_zero_matrix(bml_type,my_bml_element_type,
dp,norb,norb,zk6_bml)
181 subroutine prg_buildzdiag(smat_bml,zmat_bml,threshold,mdimin,bml_type,verbose,err_out)
183 real(
dp) :: err_check
184 character(len=*),
intent(in) :: bml_type
185 character(20) :: bml_element_type
186 integer :: i, j, mdim, norb
187 integer,
intent(in) :: mdimin
188 integer,
optional,
intent(in) :: verbose
189 logical,
optional,
intent(inout) :: err_out
192 real(
dp) :: invsqrt, threshold
193 real(
dp),
allocatable :: nono_evals(:), nonotmp(:,:), smat(:,:), umat(:,:)
194 real(
dp),
allocatable :: zmat(:,:)
195 type(bml_matrix_t) :: nonotmp_bml, saux_bml, umat_bml, umat_t_bml
196 type(bml_matrix_t) :: zmat_bml
197 type(bml_matrix_t),
intent(inout) :: smat_bml
199 type(c_ptr) :: nonotmp_bml_c_ptr, umat_bml_c_ptr
201 real(c_double),
pointer :: nonotmp_bml_ptr(:,:), umat_bml_ptr(:,:)
205 if(
present(verbose))
then
207 write(*,*)
"";
write(*,*)
"In buildzdiag ..."
211 if(bml_get_precision(smat_bml) == 1 .or.&
212 &bml_get_precision(smat_bml) == 2)
then
213 bml_element_type =
"real"
214 elseif(bml_get_precision(smat_bml) == 3 .or.&
215 &bml_get_precision(smat_bml) == 4)
then
216 bml_element_type =
"complex"
219 norb = bml_get_n(smat_bml)
220 mdim = bml_get_m(smat_bml)
223 allocate(nono_evals(norb))
225 if(.not. bml_allocated(zmat_bml))
then
226 call bml_zero_matrix(bml_matrix_dense,bml_element_type,
dp,norb,norb,zmat_bml)
230 call bml_zero_matrix(bml_type,bml_element_type,
dp,norb,norb,umat_bml)
231 call bml_zero_matrix(bml_type,bml_element_type,
dp,norb,norb,nonotmp_bml)
235 call bml_diagonalize(smat_bml,nono_evals,umat_bml)
237 if(
present(verbose))
then
239 write(*,*)
"Time for S diag = "//
to_string(
mls() - mls_i)//
" ms"
242 if(any(nono_evals.le.0.0_dp))
then
243 if(
present(verbose))
then
244 if(
present(err_out))
then
247 stop
"ERROR at prg_buildZdiag: Overlap matrix is not possitive definite..."
250 stop
"ERROR at prg_buildZdiag: Overlap matrix is not possitive definite..."
254 umat_bml_c_ptr = bml_get_data_ptr_dense(umat_bml)
255 nonotmp_bml_c_ptr = bml_get_data_ptr_dense(nonotmp_bml)
256 ld = bml_get_ld_dense(umat_bml)
257 call c_f_pointer(umat_bml_c_ptr,umat_bml_ptr,shape=[ld,norb])
258 call c_f_pointer(nonotmp_bml_c_ptr,nonotmp_bml_ptr,shape=[ld,norb])
264 nonotmp_bml_ptr(j,i) = umat_bml_ptr(i,j) / sqrt(nono_evals(i))
271 allocate(umat(norb,norb))
272 allocate(nonotmp(norb,norb))
274 call bml_export_to_dense(umat_bml, umat)
285 invsqrt = 1.0_dp/sqrt(nono_evals(i))
287 nonotmp(i,j) = umat(j,i) * invsqrt
291 call bml_import_from_dense(bml_type, nonotmp, nonotmp_bml, threshold, mdim)
297 call bml_multiply(umat_bml,nonotmp_bml,zmat_bml,1.0_dp,0.0_dp,threshold)
299 deallocate(nono_evals)
300 call bml_deallocate(umat_bml)
301 call bml_deallocate(nonotmp_bml)
319 bml_type,zk1_bml,zk2_bml,zk3_bml&
320 ,zk4_bml,zk5_bml,zk6_bml,nfirst,nrefi,nreff&
321 ,thresholdi,thresholdf,integration,verbose)
325 character(20) :: bml_type
326 integer :: kk, i, igenz, mdim
327 integer :: nfirst, norb, nref, nreff
328 integer :: nrefi, verbose
329 logical :: integration
330 real(
dp) :: sec_i, sec_ii
331 real(
dp) :: threshold, thresholdf, thresholdi
332 type(bml_matrix_t) :: smat_bml, zk1_bml, zk2_bml, zk3_bml
333 type(bml_matrix_t) :: zk4_bml, zk5_bml, zk6_bml, zmat_bml
335 norb = bml_get_n(smat_bml)
336 if(mdim<0) mdim = norb
340 if(verbose.eq.1)sec_ii=
mls()
343 if(igenz.lt.nfirst)
then
344 nref=nrefi; threshold = thresholdi
346 nref=nreff; threshold = thresholdf
349 if(verbose.eq.1)sec_i=
mls()
351 if(verbose.eq.1)
write(*,*)
"Time for prg_initial estimate "//
to_string(
mls()-sec_i)//
" ms"
353 if(verbose.eq.1)sec_i=
mls()
356 &,zk4_bml,zk5_bml,zk6_bml,igenz,norb,bml_type,threshold)
358 if(verbose.eq.1)
write(*,*)
"Time for xl scheme "//
to_string(
mls()-sec_i)//
" ms"
360 if(verbose.eq.1)sec_i=
mls()
362 if(verbose.eq.1)
write(*,*)
"Time for prg_genz_sp_ref "//
to_string(
mls()-sec_i)//
" ms"
369 if(verbose.eq.1)
write(*,*)
"Time for prg_buildZsparse "//
to_string(igenz)//
" "//
to_string(
mls()-sec_ii)//
" ms"
385 character(20) :: bml_type, bml_type_f, bml_element_type
386 integer :: i, ii, j, jj
387 integer :: k, l, mdim, norb
388 integer,
allocatable :: kk(:)
389 real(
dp) :: err_check, invsqrt, threshold, thresholdz0
390 real(
dp),
allocatable :: sitmp(:,:), smat(:,:), sthres(:,:), stmp(:,:)
391 real(
dp),
allocatable :: stmp_evals(:), utmp(:,:), zmat(:,:), ztmp(:,:)
392 type(bml_matrix_t) :: sitmp_bml, sthres_bml, stmp_bml, utmp_bml
393 type(bml_matrix_t) :: xtmp_bml, zmat_bml
394 type(bml_matrix_t),
intent(in) :: smat_bml
400 bml_type= bml_matrix_dense
402 if(bml_get_precision(smat_bml) == 1 .or.&
403 &bml_get_precision(smat_bml) == 2)
then
404 bml_element_type =
"real"
405 elseif(bml_get_precision(smat_bml) == 3 .or.&
406 &bml_get_precision(smat_bml) == 4)
then
407 bml_element_type =
"complex"
411 allocate(zmat(norb,norb))
414 allocate(sthres(norb,norb))
416 allocate(smat(norb,norb))
417 call bml_export_to_dense(smat_bml,smat)
419 call bml_zero_matrix(bml_type,bml_element_type,
dp,norb,norb,sthres_bml)
421 call bml_import_from_dense(bml_type,smat,sthres_bml,thresholdz0,mdim)
423 call bml_export_to_dense(sthres_bml,sthres)
435 if(abs(sthres(i,j)).gt.thresholdz0)
then
443 call bml_zero_matrix(bml_type,bml_element_type,
dp, k,k,stmp_bml)
444 call bml_zero_matrix(bml_type,bml_element_type,
dp, k,k,sitmp_bml)
445 call bml_zero_matrix(bml_type,bml_element_type,
dp, k,k,utmp_bml)
446 call bml_zero_matrix(bml_type,bml_element_type,
dp, k,k,xtmp_bml)
448 allocate(stmp(k,k),sitmp(k,k))
449 allocate(utmp(k,k),stmp_evals(k),ztmp(k,k))
459 stmp(l,j) = smat(kk(l),kk(j))
463 call bml_import_from_dense(bml_type, stmp, stmp_bml)
464 call bml_diagonalize(stmp_bml,stmp_evals,utmp_bml)
465 call bml_export_to_dense(utmp_bml,utmp)
468 invsqrt = 1.0_dp/sqrt(stmp_evals(j))
470 sitmp(l,j) = utmp(l,j) * invsqrt
476 call bml_import_from_dense(bml_type , utmp , utmp_bml)
477 call bml_import_from_dense(bml_type, sitmp, sitmp_bml)
478 call bml_multiply(sitmp_bml,utmp_bml,xtmp_bml,1.0_dp,0.0_dp)
479 call bml_export_to_dense(xtmp_bml,ztmp)
484 zmat(i,kk(l)) = ztmp(j,l)
489 deallocate(stmp,sitmp)
491 deallocate(stmp_evals)
493 call bml_deallocate(sitmp_bml)
494 call bml_deallocate(stmp_bml)
495 call bml_deallocate(utmp_bml)
499 call bml_zero_matrix(bml_type_f,bml_element_type,
dp,norb,norb,zmat_bml)
500 call bml_import_from_dense(bml_type_f,zmat, zmat_bml,threshold,mdim)
509 call bml_deallocate(sthres_bml)
527 character(20) :: bml_type, bml_type_f, bml_element_type
528 integer :: i, ii, j, jj
529 integer :: k, l, mdim, norb
530 integer,
allocatable :: kk(:)
531 real(
dp),
intent(in) :: threshold
532 real(
dp) :: err_check, invsqrt
533 real(
dp) :: thresholdz0
534 real(
dp),
allocatable :: sitmp(:,:), smat(:,:), sthres(:,:)
535 real(
dp),
allocatable :: stmp(:,:)
536 real(
dp),
allocatable :: stmp_evals(:), utmp(:,:)
537 real(
dp),
allocatable :: zmat(:,:), ztmp(:,:)
538 type(bml_matrix_t) :: sitmp_bml, sthres_bml, stmp_bml
539 type(bml_matrix_t) :: xtmp_bml, zmat_bml, utmp_bml
540 type(bml_matrix_t),
intent(in) :: smat_bml
547 bml_type= bml_matrix_dense
549 if(bml_get_precision(smat_bml) == 1 .or.&
550 &bml_get_precision(smat_bml) == 2)
then
551 bml_element_type =
"real"
552 elseif(bml_get_precision(smat_bml) == 3 .or.&
553 &bml_get_precision(smat_bml) == 4)
then
554 bml_element_type =
"complex"
558 allocate(zmat(norb,norb))
559 allocate(sthres(norb,norb))
561 allocate(smat(norb,norb))
562 call bml_export_to_dense(smat_bml,smat)
565 call bml_zero_matrix(bml_type,bml_element_type,
dp,norb,norb,sthres_bml)
568 call bml_import_from_dense(bml_type,smat,sthres_bml,threshold,mdim)
571 call bml_export_to_dense(sthres_bml,sthres)
588 if(abs(sthres(i,j)).gt.threshold)
then
596 call bml_zero_matrix(bml_type,bml_element_type,
dp, k,k,stmp_bml)
597 call bml_zero_matrix(bml_type,bml_element_type,
dp, k,k,sitmp_bml)
598 call bml_zero_matrix(bml_type,bml_element_type,
dp, k,k,utmp_bml)
599 call bml_zero_matrix(bml_type,bml_element_type,
dp, k,k,xtmp_bml)
601 allocate(stmp(k,k),sitmp(k,k))
602 allocate(utmp(k,k),stmp_evals(k),ztmp(k,k))
612 stmp(l,j) = smat(kk(l),kk(j))
616 call bml_import_from_dense(bml_matrix_dense, stmp, stmp_bml)
617 call bml_diagonalize(stmp_bml,stmp_evals,utmp_bml)
618 call bml_export_to_dense(utmp_bml,utmp)
621 invsqrt = 1.0_dp/sqrt(stmp_evals(j))
623 sitmp(l,j) = utmp(l,j) * invsqrt
629 call bml_import_from_dense(bml_type, utmp, utmp_bml)
630 call bml_import_from_dense(bml_type, sitmp, sitmp_bml)
631 call bml_multiply(sitmp_bml,utmp_bml,xtmp_bml,1.0_dp,0.0_dp)
632 call bml_export_to_dense(xtmp_bml,ztmp)
638 zmat(i,kk(l)) = ztmp(j,l)
643 deallocate(stmp,sitmp)
645 deallocate(stmp_evals)
647 call bml_deallocate(sitmp_bml)
648 call bml_deallocate(stmp_bml)
649 call bml_deallocate(utmp_bml)
654 call bml_import_from_dense(bml_type_f,zmat,zmat_bml,threshold,mdim, &
655 bml_get_distribution_mode(smat_bml))
665 call bml_deallocate(sthres_bml)
680 &,zk4_bml,zk5_bml,zk6_bml,igenz,norb,bml_type&
682 integer :: igenz,norb,KK
683 character(20) :: bml_element_type
684 real(dp) :: alpha, kappa, c0, c1, c2, c3, c4, c5
685 real(dp) :: threshold
686 type(bml_matrix_t) :: zmat_bml
687 type(bml_matrix_t) :: zk1_bml,zk2_bml,zk3_bml,zk4_bml,zk5_bml,zk6_bml
688 character(20) :: bml_type
695 if(bml_get_precision(zmat_bml) == 1 .or.&
696 &bml_get_precision(zmat_bml) == 2)
then
697 bml_element_type =
"real"
698 elseif(bml_get_precision(zmat_bml) == 3 .or.&
699 &bml_get_precision(zmat_bml) == 4)
then
700 bml_element_type =
"complex"
715 call bml_zero_matrix(bml_type,bml_element_type,dp,norb ,norb,zk1_bml)
716 call bml_zero_matrix(bml_type,bml_element_type,dp,norb ,norb,zk2_bml)
717 call bml_zero_matrix(bml_type,bml_element_type,dp,norb ,norb,zk3_bml)
718 call bml_zero_matrix(bml_type,bml_element_type,dp,norb ,norb,zk4_bml)
719 call bml_zero_matrix(bml_type,bml_element_type,dp,norb ,norb,zk5_bml)
720 call bml_zero_matrix(bml_type,bml_element_type,dp,norb ,norb,zk6_bml)
722 call bml_copy(zmat_bml,zk1_bml);
call bml_copy(zmat_bml,zk2_bml);
call bml_copy(zmat_bml,zk3_bml)
723 call bml_copy(zmat_bml,zk4_bml);
call bml_copy(zmat_bml,zk5_bml);
call bml_copy(zmat_bml,zk6_bml)
729 call bml_add_deprecated(1.0_dp,zmat_bml,-1.0_dp,zk6_bml,threshold)
730 call bml_scale(kappa,zmat_bml)
731 call bml_add_deprecated(1.0_dp,zmat_bml,2.0_dp,zk6_bml,threshold)
732 call bml_add_deprecated(1.0_dp,zmat_bml,-1.0_dp,zk5_bml,threshold)
735 call bml_add_deprecated(1.0_dp,zmat_bml,c0,zk6_bml,threshold)
736 call bml_add_deprecated(1.0_dp,zmat_bml,c1,zk5_bml,threshold)
737 call bml_add_deprecated(1.0_dp,zmat_bml,c2,zk4_bml,threshold)
738 call bml_add_deprecated(1.0_dp,zmat_bml,c3,zk3_bml,threshold)
739 call bml_add_deprecated(1.0_dp,zmat_bml,c4,zk2_bml,threshold)
740 call bml_add_deprecated(1.0_dp,zmat_bml,c5,zk1_bml,threshold)
746 call bml_copy(zk2_bml,zk1_bml)
747 call bml_copy(zk3_bml,zk2_bml)
748 call bml_copy(zk4_bml,zk3_bml)
749 call bml_copy(zk5_bml,zk4_bml)
750 call bml_copy(zk6_bml,zk5_bml)
751 call bml_copy(zmat_bml,zk6_bml)
767 integer,
intent(inout) :: norb
768 integer,
intent(in) :: nref
769 real(
dp) :: err_check, sec_i
770 real(
dp),
allocatable :: smat(:,:), zmat(:,:)
771 real(
dp),
intent(in) :: threshold
772 type(bml_matrix_t) :: temp_bml
773 type(bml_matrix_t) :: temp1_bml
774 type(bml_matrix_t) :: temp2_bml
775 type(bml_matrix_t) :: idscaled_bml
776 type(bml_matrix_t) :: xmat_t_bml
777 type(bml_matrix_t),
intent(inout) :: zmat_bml
778 type(bml_matrix_t) :: aux_bml
779 type(bml_matrix_t),
intent(in) :: smat_bml
780 character(20),
intent(in) :: bml_type
781 character(20) :: bml_element_type
783 norb = bml_get_n(smat_bml)
786 if(bml_get_precision(smat_bml) == 1 .or.&
787 &bml_get_precision(smat_bml) == 2)
then
788 bml_element_type =
"real"
789 elseif(bml_get_precision(smat_bml) == 3 .or.&
790 &bml_get_precision(smat_bml) == 4)
then
791 bml_element_type =
"complex"
794 call bml_zero_matrix(bml_type,bml_element_type,
dp,norb,norb,idscaled_bml)
796 call bml_add_identity(idscaled_bml, 1.0_dp, threshold)
797 call bml_scale(1.8750_dp,idscaled_bml)
799 call bml_noinit_matrix(bml_type,bml_element_type,
dp,norb ,norb,temp_bml)
800 call bml_noinit_matrix(bml_type,bml_element_type,
dp,norb ,norb,temp2_bml)
806 call bml_transpose_new(zmat_bml, xmat_t_bml)
807 call bml_add_deprecated(0.50_dp,zmat_bml, 0.50_dp, xmat_t_bml,threshold)
809 call bml_multiply(smat_bml,zmat_bml,temp_bml, 1.0_dp, 0.0_dp,threshold)
811 call bml_multiply(zmat_bml,temp_bml, temp2_bml, 1.0_dp, 0.0_dp,threshold)
813 call bml_multiply(temp2_bml, temp2_bml, temp_bml, 1.0_dp, 0.0_dp,threshold)
815 call bml_scale(0.3750_dp, temp_bml)
816 call bml_scale(-1.250_dp, temp2_bml)
819 call bml_add_deprecated(1.0_dp,temp2_bml,1.0_dp, idscaled_bml,threshold)
820 call bml_add_deprecated(1.0_dp,temp_bml,1.0_dp, temp2_bml,threshold)
822 call bml_multiply(zmat_bml,temp_bml,temp2_bml, 1.0_dp, 0.0_dp,threshold)
824 call bml_copy(temp2_bml,zmat_bml)
827 call bml_deallocate(temp_bml)
828 call bml_deallocate(temp1_bml)
829 call bml_deallocate(temp2_bml)
831 write(*,*)
"Time for ref loop "//
to_string(
mls()-sec_i)//
" ms"
834 call bml_deallocate(idscaled_bml)
835 call bml_deallocate(xmat_t_bml)
To produce a matrix which is needed to orthogonalize .
subroutine, public prg_buildzsparse(smat_bml, zmat_bml, igenz, mdim, bml_type, zk1_bml, zk2_bml, zk3_bml, zk4_bml, zk5_bml, zk6_bml, nfirst, nrefi, nreff, thresholdi, thresholdf, integration, verbose)
Inverse factorization using Niklasson's algorithm.
subroutine, public prg_genz_sp_initial_zmat(smat_bml, zmat_bml, norb, mdim, bml_type_f, threshold)
Initial estimation of Z.
subroutine, public prg_genz_sp_ref(smat_bml, zmat_bml, nref, norb, bml_type, threshold)
Iterative refinement.
subroutine, public prg_parse_zsp(input, filename)
The parser for genz solver.
subroutine, public prg_buildzdiag(smat_bml, zmat_bml, threshold, mdimin, bml_type, verbose, err_out)
Usual subroutine involving diagonalization. , where = eigenvectors and = eigenvalues....
subroutine prg_genz_sp_int(zmat_bml, zk1_bml, zk2_bml, zk3_bml, zk4_bml, zk5_bml, zk6_bml, igenz, norb, bml_type, threshold)
Inverse factorization using Niklasson's algorithm.
subroutine, public prg_genz_sp_initialz0(smat_bml, zmat_bml, norb, mdim, bml_type_f, threshold)
Initial estimation of Z.
subroutine, public prg_init_zspmat(igenz, zk1_bml, zk2_bml, zk3_bml, zk4_bml, zk5_bml, zk6_bml, norb, bml_type, bml_element_type)
Initiates the matrices for the Xl integration of Z.
Some general parsing functions.
subroutine, public prg_parsing_kernel(keyvector_char, valvector_char, keyvector_int, valvector_int, keyvector_re, valvector_re, keyvector_log, valvector_log, filename, startstop)
The general parsing function. It is used to vectorize a set of "keywords" "value" pairs as included i...
Module to handle input output files for the PROGRESS lib.
Input for the genz driver. This type controlls all the variables that are needed by genz.