70#include "./base/base_uses.f90"
76 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_diis'
105 INTEGER,
INTENT(in) :: nbuffer
107 CHARACTER(len=*),
PARAMETER :: routinen =
'qs_diis_b_create'
113 CALL timeset(routinen, handle)
115 NULLIFY (diis_buffer%b_matrix)
116 NULLIFY (diis_buffer%error)
117 NULLIFY (diis_buffer%param)
118 diis_buffer%nbuffer = nbuffer
119 diis_buffer%ncall = 0
121 CALL timestop(handle)
140 SUBROUTINE qs_diis_b_check_i_alloc(diis_buffer, matrix_struct, nspin, &
145 INTEGER,
INTENT(IN) :: nspin
148 CHARACTER(LEN=*),
PARAMETER :: routinen =
'qs_diis_b_check_i_alloc'
150 INTEGER :: handle, ibuffer, ispin, nbuffer, &
156 CALL timeset(routinen, handle)
160 nbuffer = diis_buffer%nbuffer
162 IF (.NOT.
ASSOCIATED(diis_buffer%error))
THEN
163 ALLOCATE (diis_buffer%error(nbuffer, nspin))
166 DO ibuffer = 1, nbuffer
168 name=
"qs_diis_b%error("// &
171 matrix_struct=matrix_struct)
176 IF (.NOT.
ASSOCIATED(diis_buffer%param))
THEN
177 ALLOCATE (diis_buffer%param(nbuffer, nspin))
180 DO ibuffer = 1, nbuffer
182 name=
"qs_diis_b%param("// &
185 matrix_struct=matrix_struct)
190 IF (.NOT.
ASSOCIATED(diis_buffer%b_matrix))
THEN
191 ALLOCATE (diis_buffer%b_matrix(nbuffer + 1, nbuffer + 1))
192 diis_buffer%b_matrix = 0.0_dp
195 IF (output_unit > 0)
THEN
196 WRITE (unit=output_unit, fmt=
"(/,T9,A)") &
197 "DIIS | The SCF DIIS buffer was allocated and initialized"
203 CALL timestop(handle)
205 END SUBROUTINE qs_diis_b_check_i_alloc
229 diis_step, eps_diis, nmixing, s_matrix, scf_section, roks)
232 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(IN) :: mo_array
235 REAL(kind=
dp),
INTENT(IN) :: delta
236 REAL(kind=
dp),
INTENT(OUT) :: error_max
237 LOGICAL,
INTENT(OUT) :: diis_step
238 REAL(kind=
dp),
INTENT(IN) :: eps_diis
239 INTEGER,
INTENT(IN),
OPTIONAL :: nmixing
243 LOGICAL,
INTENT(IN),
OPTIONAL :: roks
245 CHARACTER(LEN=*),
PARAMETER :: routinen =
'qs_diis_b_step'
246 REAL(kind=
dp),
PARAMETER :: eigenvalue_threshold = 1.0e-12_dp
248 CHARACTER(LEN=2*default_string_length) :: message
249 INTEGER :: handle, homo, ib, imo, ispin, jb, &
250 my_nmixing, nao, nb, nb1, nmo, nspin, &
252 LOGICAL :: eigenvectors_discarded, my_roks
253 REAL(kind=
dp) :: maxocc, tmp
254 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: ev, occ
255 REAL(kind=
dp),
DIMENSION(:),
POINTER :: occa, occb
256 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: a, b
258 TYPE(
cp_fm_type),
POINTER :: c, new_errors, old_errors, parameters
263 CALL timeset(routinen, handle)
265 nspin =
SIZE(mo_array)
268 IF (
PRESENT(roks))
THEN
276 IF (
PRESENT(nmixing)) my_nmixing = nmixing
278 NULLIFY (c, new_errors, old_errors, parameters, matrix_struct, a, b, occa, occb)
283 IF (diis_buffer%nbuffer < 1)
THEN
284 CALL timestop(handle)
289 matrix_struct=matrix_struct)
290 CALL qs_diis_b_check_i_alloc(diis_buffer, &
291 matrix_struct=matrix_struct, &
293 scf_section=scf_section)
297 ib =
modulo(diis_buffer%ncall, diis_buffer%nbuffer) + 1
298 diis_buffer%ncall = diis_buffer%ncall + 1
299 nb = min(diis_buffer%ncall, diis_buffer%nbuffer)
308 occupation_numbers=occa, &
311 new_errors => diis_buffer%error(ib, ispin)
312 parameters => diis_buffer%param(ib, ispin)
323 occupation_numbers=occb)
326 occ(imo) = sqrt(occa(imo) + occb(imo))
333 CALL cp_fm_symm(
"L",
"U", nao, homo, 1.0_dp, parameters, sc, 0.0_dp, kc(ispin))
335 IF (
PRESENT(s_matrix))
THEN
338 CALL cp_fm_symm(
"L",
"U", nao, homo, 1.0_dp, new_errors, c, 0.0_dp, sc)
345 CALL parallel_gemm(
"N",
"T", nao, nao, homo, 1.0_dp, sc, kc(ispin), 0.0_dp, new_errors)
346 CALL parallel_gemm(
"N",
"T", nao, nao, homo, 1.0_dp, kc(ispin), sc, -1.0_dp, new_errors)
353 CALL cp_fm_symm(
"L",
"U", nao, homo, maxocc, parameters, c, 0.0_dp, kc(ispin))
355 IF (
PRESENT(s_matrix))
THEN
359 CALL cp_fm_symm(
"L",
"U", nao, homo, 2.0_dp, new_errors, c, 0.0_dp, sc)
361 CALL parallel_gemm(
"N",
"T", nao, nao, homo, 1.0_dp, sc, kc(ispin), 0.0_dp, new_errors)
362 CALL parallel_gemm(
"N",
"T", nao, nao, homo, 1.0_dp, kc(ispin), sc, -1.0_dp, new_errors)
365 CALL parallel_gemm(
"N",
"T", nao, nao, homo, 1.0_dp, c, kc(ispin), 0.0_dp, new_errors)
366 CALL parallel_gemm(
"N",
"T", nao, nao, homo, 1.0_dp, kc(ispin), c, -1.0_dp, new_errors)
372 error_max = max(error_max, tmp)
378 diis_step = ((diis_buffer%ncall >= my_nmixing) .AND. (delta < eps_diis))
382 IF (output_unit > 0)
THEN
383 WRITE (unit=output_unit, fmt=
"(/,T9,A,I4,/,(T9,A,ES12.3))") &
384 "DIIS | Current SCF DIIS buffer size: ", nb, &
385 "DIIS | Maximum SCF DIIS error vector element:", error_max, &
386 "DIIS | Current SCF convergence: ", delta, &
387 "DIIS | Threshold value for a DIIS step: ", eps_diis
388 IF (error_max < eps_diis)
THEN
389 WRITE (unit=output_unit, fmt=
"(T9,A)") &
390 "DIIS | => The SCF DIIS buffer will be updated"
392 WRITE (unit=output_unit, fmt=
"(T9,A)") &
393 "DIIS | => No update of the SCF DIIS buffer"
395 IF (diis_step .AND. (error_max < eps_diis))
THEN
396 WRITE (unit=output_unit, fmt=
"(T9,A,/)") &
397 "DIIS | => A SCF DIIS step will be performed"
399 WRITE (unit=output_unit, fmt=
"(T9,A,/)") &
400 "DIIS | => No SCF DIIS step will be performed"
406 IF (error_max < eps_diis)
THEN
408 b => diis_buffer%b_matrix
413 old_errors => diis_buffer%error(jb, ispin)
414 new_errors => diis_buffer%error(ib, ispin)
416 b(jb, ib) = b(jb, ib) + tmp
418 b(ib, jb) = b(jb, ib)
433 ALLOCATE (a(nb1, nb1))
434 ALLOCATE (b(nb1, nb1))
439 b(1:nb, 1:nb) = diis_buffer%b_matrix(1:nb, 1:nb)
441 b(1:nb, nb1) = -1.0_dp
442 b(nb1, 1:nb) = -1.0_dp
450 a(1:nb1, 1:nb1) = b(1:nb1, 1:nb1)
452 eigenvectors_discarded = .false.
455 IF (abs(ev(jb)) < eigenvalue_threshold)
THEN
456 IF (output_unit > 0)
THEN
457 IF (.NOT. eigenvectors_discarded)
THEN
458 WRITE (unit=output_unit, fmt=
"(T9,A)") &
459 "DIIS | Checking eigenvalues of the DIIS error matrix"
461 WRITE (unit=message, fmt=
"(T9,A,I6,A,ES10.1,A,ES10.1)") &
462 "DIIS | Eigenvalue ", jb,
" = ", ev(jb),
" is smaller than "// &
463 "threshold ", eigenvalue_threshold
465 WRITE (unit=output_unit, fmt=
"(T9,A)") trim(message)
466 eigenvectors_discarded = .true.
468 a(1:nb1, jb) = 0.0_dp
470 a(1:nb1, jb) = a(1:nb1, jb)/ev(jb)
474 IF ((output_unit > 0) .AND. eigenvectors_discarded)
THEN
475 WRITE (unit=output_unit, fmt=
"(T9,A,/)") &
476 "DIIS | The corresponding eigenvectors were discarded"
479 ev(1:nb) = matmul(a(1:nb, 1:nb1), b(nb1, 1:nb1))
486 parameters => diis_buffer%param(jb, ispin)
498 parameters => diis_buffer%param(ib, ispin)
507 CALL timestop(handle)
522 diis_buffer%ncall = 0
545 diis_step, eps_diis, nmixing, s_matrix, threshold)
552 INTEGER,
INTENT(IN) :: unit_nr, iscf
553 LOGICAL,
INTENT(OUT) :: diis_step
554 REAL(kind=
dp),
INTENT(IN) :: eps_diis
555 INTEGER,
INTENT(IN),
OPTIONAL :: nmixing
557 REAL(kind=
dp),
INTENT(IN) :: threshold
559 CHARACTER(LEN=*),
PARAMETER :: routinen =
'qs_diis_b_step_4lscf'
560 REAL(kind=
dp),
PARAMETER :: eigenvalue_threshold = 1.0e-12_dp
562 INTEGER :: handle, ib, ispin, jb, my_nmixing, nb, &
564 REAL(kind=
dp) :: error_max, tmp
565 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: ev
566 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: a, b
569 TYPE(
dbcsr_type) :: matrix_kserr_t, matrix_tmp
570 TYPE(
dbcsr_type),
POINTER :: new_errors, old_errors, parameters
573 CALL timeset(routinen, handle)
574 nspin = ls_scf_env%nspins
577 IF (
PRESENT(nmixing)) my_nmixing = nmixing
578 NULLIFY (new_errors, old_errors, parameters, a, b)
581 IF (diis_buffer%nbuffer < 1)
THEN
582 CALL timestop(handle)
590 CALL qs_diis_b_check_i_alloc_sparse( &
596 ib =
modulo(diis_buffer%ncall, diis_buffer%nbuffer) + 1
597 diis_buffer%ncall = diis_buffer%ncall + 1
598 nb = min(diis_buffer%ncall, diis_buffer%nbuffer)
601 template=ls_scf_env%matrix_ks(1), &
605 template=ls_scf_env%matrix_ks(1), &
611 new_errors => diis_buffer%error(ib, ispin)%matrix
612 parameters => diis_buffer%param(ib, ispin)%matrix
615 matrix_ks(ispin)%matrix)
617 IF (
PRESENT(s_matrix))
THEN
621 1.0_dp, ls_scf_env%matrix_p(ispin), &
623 0.0_dp, matrix_tmp, &
624 filter_eps=threshold)
627 1.0_dp, matrix_ks(ispin)%matrix, &
629 0.0_dp, new_errors, &
630 filter_eps=threshold)
642 1.0_dp, matrix_ks(ispin)%matrix, &
643 ls_scf_env%matrix_p(ispin), &
644 0.0_dp, new_errors, &
645 filter_eps=threshold)
656 error_max = max(error_max, tmp)
662 diis_step = (diis_buffer%ncall >= my_nmixing)
664 IF (unit_nr > 0)
THEN
665 WRITE (unit_nr,
'(A29,I3,A3,4(I3,A1))') &
666 "DIIS: (ncall,nbuffer,ib,nb)=(", iscf,
")=(", &
667 diis_buffer%ncall,
",", diis_buffer%nbuffer,
",", ib,
",", nb,
")"
668 WRITE (unit_nr,
'(A57,I3,A3,L1,A1,F10.8,A1,F4.2,A1,L1,A1)') &
669 "DIIS: (diis_step,error_max,eps_diis,error_max<eps_diis)=(", &
670 iscf,
")=(", diis_step,
",", error_max,
",", eps_diis,
",", &
671 (error_max < eps_diis),
")"
672 WRITE (unit_nr,
'(A75)') &
673 "DIIS: diis_step=T : Perform DIIS error_max<eps_diis=T : Update DIIS buffer"
677 IF (error_max < eps_diis)
THEN
678 b => diis_buffer%b_matrix
682 old_errors => diis_buffer%error(jb, ispin)%matrix
683 new_errors => diis_buffer%error(ib, ispin)%matrix
687 b(jb, ib) = b(jb, ib) + tmp
689 b(ib, jb) = b(jb, ib)
698 ALLOCATE (a(nb1, nb1))
699 ALLOCATE (b(nb1, nb1))
702 b(1:nb, 1:nb) = diis_buffer%b_matrix(1:nb, 1:nb)
703 b(1:nb, nb1) = -1.0_dp
704 b(nb1, 1:nb) = -1.0_dp
708 a(1:nb1, 1:nb1) = b(1:nb1, 1:nb1)
710 IF (abs(ev(jb)) < eigenvalue_threshold)
THEN
711 a(1:nb1, jb) = 0.0_dp
713 a(1:nb1, jb) = a(1:nb1, jb)/ev(jb)
717 ev(1:nb) = matmul(a(1:nb, 1:nb1), b(nb1, 1:nb1))
720 IF (iscf .GE. ls_scf_env%iter_ini_diis)
THEN
722 IF (unit_nr > 0)
THEN
723 WRITE (unit_nr,
'(A40,I3)')
'DIIS: Updating Kohn-Sham matrix at iscf=', iscf
727 CALL dbcsr_set(matrix_ks(ispin)%matrix, &
730 parameters => diis_buffer%param(jb, ispin)%matrix
731 CALL dbcsr_add(matrix_ks(ispin)%matrix, parameters, &
743 parameters => diis_buffer%param(ib, ispin)%matrix
745 matrix_ks(ispin)%matrix)
750 CALL timestop(handle)
767 SUBROUTINE qs_diis_b_check_i_alloc_sparse(diis_buffer, ls_scf_env, &
772 INTEGER,
INTENT(IN) :: nspin
774 CHARACTER(LEN=*),
PARAMETER :: routinen =
'qs_diis_b_check_i_alloc_sparse'
776 INTEGER :: handle, ibuffer, ispin, nbuffer
781 CALL timeset(routinen, handle)
785 nbuffer = diis_buffer%nbuffer
787 IF (.NOT.
ASSOCIATED(diis_buffer%error))
THEN
788 ALLOCATE (diis_buffer%error(nbuffer, nspin))
791 DO ibuffer = 1, nbuffer
792 ALLOCATE (diis_buffer%error(ibuffer, ispin)%matrix)
794 CALL dbcsr_create(diis_buffer%error(ibuffer, ispin)%matrix, &
795 template=ls_scf_env%matrix_ks(1), &
801 IF (.NOT.
ASSOCIATED(diis_buffer%param))
THEN
802 ALLOCATE (diis_buffer%param(nbuffer, nspin))
805 DO ibuffer = 1, nbuffer
806 ALLOCATE (diis_buffer%param(ibuffer, ispin)%matrix)
807 CALL dbcsr_create(diis_buffer%param(ibuffer, ispin)%matrix, &
808 template=ls_scf_env%matrix_ks(1), &
814 IF (.NOT.
ASSOCIATED(diis_buffer%b_matrix))
THEN
815 ALLOCATE (diis_buffer%b_matrix(nbuffer + 1, nbuffer + 1))
817 diis_buffer%b_matrix = 0.0_dp
820 CALL timestop(handle)
822 END SUBROUTINE qs_diis_b_check_i_alloc_sparse
836 diis_buffer%ncall = 0
851 INTEGER,
INTENT(in) :: nbuffer
853 NULLIFY (diis_buffer%b_matrix)
854 NULLIFY (diis_buffer%error)
855 NULLIFY (diis_buffer%param)
856 diis_buffer%nbuffer = nbuffer
857 diis_buffer%ncall = 0
869 INTEGER,
INTENT(in) :: nbuffer
871 NULLIFY (diis_buffer%b_matrix)
872 NULLIFY (diis_buffer%error)
873 NULLIFY (diis_buffer%param)
874 NULLIFY (diis_buffer%smat)
875 diis_buffer%nbuffer = nbuffer
876 diis_buffer%ncall = 0
889 SUBROUTINE qs_diis_b_check_i_alloc_kp(diis_buffer, matrix_struct, nspin, nkp, scf_section)
893 INTEGER,
INTENT(IN) :: nspin, nkp
896 CHARACTER(LEN=*),
PARAMETER :: routinen =
'qs_diis_b_check_i_alloc_kp'
898 INTEGER :: handle, ibuffer, ikp, ispin, nbuffer, &
904 CALL timeset(routinen, handle)
908 nbuffer = diis_buffer%nbuffer
910 IF (.NOT.
ASSOCIATED(diis_buffer%error))
THEN
911 ALLOCATE (diis_buffer%error(nbuffer, nspin, nkp))
915 DO ibuffer = 1, nbuffer
917 name=
"qs_diis_b%error("// &
920 matrix_struct=matrix_struct)
926 IF (.NOT.
ASSOCIATED(diis_buffer%param))
THEN
927 ALLOCATE (diis_buffer%param(nbuffer, nspin, nkp))
931 DO ibuffer = 1, nbuffer
933 name=
"qs_diis_b%param("// &
936 matrix_struct=matrix_struct)
942 IF (.NOT.
ASSOCIATED(diis_buffer%smat))
THEN
943 ALLOCATE (diis_buffer%smat(nkp))
946 name=
"kp_cfm_smat("// &
949 matrix_struct=matrix_struct)
953 IF (.NOT.
ASSOCIATED(diis_buffer%b_matrix))
THEN
954 ALLOCATE (diis_buffer%b_matrix(nbuffer + 1, nbuffer + 1))
955 diis_buffer%b_matrix = 0.0_dp
958 IF (output_unit > 0)
THEN
959 WRITE (unit=output_unit, fmt=
"(/,T9,A)") &
960 "DIIS | The SCF DIIS buffer was allocated and initialized"
966 CALL timestop(handle)
968 END SUBROUTINE qs_diis_b_check_i_alloc_kp
978 diis_buffer%ncall = 0
990 INTEGER,
INTENT(OUT) :: ib, nb
992 ib =
modulo(diis_buffer%ncall, diis_buffer%nbuffer) + 1
993 diis_buffer%ncall = diis_buffer%ncall + 1
994 nb = min(diis_buffer%ncall, diis_buffer%nbuffer)
1014 INTEGER,
INTENT(IN) :: ib
1015 TYPE(
mo_set_type),
DIMENSION(:, :),
POINTER :: mos
1017 INTEGER,
INTENT(IN) :: ispin, ikp, nkp_local
1020 CHARACTER(LEN=*),
PARAMETER :: routinen =
'qs_diis_b_calc_err_kp'
1022 INTEGER :: handle, homo, nao, nmo, nspin
1025 TYPE(
cp_cfm_type),
POINTER :: new_errors, parameters, smat
1029 NULLIFY (matrix_struct, imos, rmos, parameters, new_errors, smat)
1031 CALL timeset(routinen, handle)
1037 IF (diis_buffer%nbuffer < 1)
THEN
1038 CALL timestop(handle)
1041 nspin =
SIZE(mos, 2)
1044 CALL qs_diis_b_check_i_alloc_kp(diis_buffer, &
1045 matrix_struct=matrix_struct, &
1046 nspin=nspin, nkp=nkp_local, &
1047 scf_section=scf_section)
1050 CALL get_mo_set(mos(1, ispin), nao=nao, nmo=nmo, homo=homo, mo_coeff=rmos, maxocc=maxocc)
1051 CALL get_mo_set(mos(2, ispin), mo_coeff=imos)
1052 NULLIFY (matrix_struct)
1057 new_errors => diis_buffer%error(ib, ispin, ikp)
1058 parameters => diis_buffer%param(ib, ispin, ikp)
1059 smat => diis_buffer%smat(ikp)
1066 CALL parallel_gemm(
"N",
"N", nao, homo, nao, cmplx(maxocc, kind=
dp), parameters, cmos, (0.0_dp, 0.0_dp), kc)
1068 CALL parallel_gemm(
"N",
"N", nao, homo, nao, (2.0_dp, 0.0_dp), smat, cmos, (0.0_dp, 0.0_dp), sc)
1071 CALL parallel_gemm(
"N",
"T", nao, nao, homo, (1.0_dp, 0.0_dp), sc, kc, (0.0_dp, 0.0_dp), new_errors)
1072 CALL parallel_gemm(
"N",
"T", nao, nao, homo, (1.0_dp, 0.0_dp), kc, sc, (-1.0_dp, 0.0_dp), new_errors)
1077 CALL timestop(handle)
1099 nspin, nkp, nkp_local, nmixing, scf_section, para_env)
1102 COMPLEX(KIND=dp),
DIMENSION(:),
INTENT(INOUT) :: coeffs
1103 INTEGER,
INTENT(IN) :: ib, nb
1104 REAL(kind=
dp),
INTENT(IN) :: delta
1105 REAL(kind=
dp),
INTENT(OUT) :: error_max
1106 LOGICAL,
INTENT(OUT) :: diis_step
1107 REAL(kind=
dp),
INTENT(IN) :: eps_diis
1108 INTEGER,
INTENT(IN) :: nspin, nkp, nkp_local
1109 INTEGER,
INTENT(IN),
OPTIONAL :: nmixing
1113 CHARACTER(LEN=*),
PARAMETER :: routinen =
'qs_diis_b_step_kp'
1114 REAL(kind=
dp),
PARAMETER :: eigenvalue_threshold = 1.0e-12_dp
1116 CHARACTER(LEN=2*default_string_length) :: message
1117 COMPLEX(KIND=dp) :: tmp
1118 COMPLEX(KIND=dp),
ALLOCATABLE,
DIMENSION(:, :) :: a, b
1119 INTEGER :: handle, ikp, ispin, jb, my_nmixing, nb1, &
1121 LOGICAL :: eigenvectors_discarded
1122 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: ev
1129 NULLIFY (matrix_struct, new_errors, logger)
1131 CALL timeset(routinen, handle)
1136 IF (
PRESENT(nmixing)) my_nmixing = nmixing
1141 IF (diis_buffer%nbuffer < 1)
THEN
1142 CALL timestop(handle)
1147 diis_step = ((diis_buffer%ncall >= my_nmixing) .AND. (delta < eps_diis))
1150 CALL cp_cfm_get_info(diis_buffer%error(ib, 1, 1), matrix_struct=matrix_struct)
1154 ALLOCATE (b(nb, nb))
1157 DO ikp = 1, nkp_local
1159 new_errors => diis_buffer%error(ib, ispin, ikp)
1160 CALL cp_cfm_to_fm(diis_buffer%error(jb, ispin, ikp), rerr, ierr)
1164 b(jb, ib) = b(jb, ib) + 1.0_dp/real(nkp,
dp)*tmp
1167 b(ib, jb) = conjg(b(jb, ib))
1172 CALL para_env%sum(b)
1174 error_max = sqrt(real(b(ib, ib))**2 + aimag(b(ib, ib))**2)
1177 extension=
".scfLog")
1178 IF (output_unit > 0)
THEN
1179 WRITE (unit=output_unit, fmt=
"(/,T9,A,I4,/,(T9,A,ES12.3))") &
1180 "DIIS | Current SCF DIIS buffer size: ", nb, &
1181 "DIIS | Maximum SCF DIIS error at last step: ", error_max, &
1182 "DIIS | Current SCF convergence: ", delta, &
1183 "DIIS | Threshold value for a DIIS step: ", eps_diis
1184 IF (error_max < eps_diis)
THEN
1185 WRITE (unit=output_unit, fmt=
"(T9,A)") &
1186 "DIIS | => The SCF DIIS buffer will be updated"
1188 WRITE (unit=output_unit, fmt=
"(T9,A)") &
1189 "DIIS | => No update of the SCF DIIS buffer"
1191 IF (diis_step .AND. (error_max < eps_diis))
THEN
1192 WRITE (unit=output_unit, fmt=
"(T9,A,/)") &
1193 "DIIS | => A SCF DIIS step will be performed"
1195 WRITE (unit=output_unit, fmt=
"(T9,A,/)") &
1196 "DIIS | => No SCF DIIS step will be performed"
1201 IF (error_max < eps_diis)
THEN
1203 diis_buffer%b_matrix(ib, jb) = b(ib, jb)
1204 diis_buffer%b_matrix(jb, ib) = b(jb, ib)
1217 ALLOCATE (a(nb1, nb1))
1218 ALLOCATE (b(nb1, nb1))
1222 b(1:nb, 1:nb) = diis_buffer%b_matrix(1:nb, 1:nb)
1224 b(1:nb, nb1) = -1.0_dp
1225 b(nb1, 1:nb) = -1.0_dp
1226 b(nb1, nb1) = 0.0_dp
1230 a(1:nb1, 1:nb1) = 0.0_dp
1231 CALL diag_complex(b(1:nb1, 1:nb1), a(1:nb1, 1:nb1), ev(1:nb1))
1232 b(1:nb1, 1:nb1) = a(1:nb1, 1:nb1)
1234 eigenvectors_discarded = .false.
1237 IF (abs(ev(jb)) < eigenvalue_threshold)
THEN
1238 IF (output_unit > 0)
THEN
1239 IF (.NOT. eigenvectors_discarded)
THEN
1240 WRITE (unit=output_unit, fmt=
"(T9,A)") &
1241 "DIIS | Checking eigenvalues of the DIIS error matrix"
1243 WRITE (unit=message, fmt=
"(T9,A,I6,A,ES10.1,A,ES10.1)") &
1244 "DIIS | Eigenvalue ", jb,
" = ", ev(jb),
" is smaller than "// &
1245 "threshold ", eigenvalue_threshold
1247 WRITE (unit=output_unit, fmt=
"(T9,A)") trim(message)
1248 eigenvectors_discarded = .true.
1250 a(1:nb1, jb) = 0.0_dp
1252 a(1:nb1, jb) = a(1:nb1, jb)/ev(jb)
1256 IF ((output_unit > 0) .AND. eigenvectors_discarded)
THEN
1257 WRITE (unit=output_unit, fmt=
"(T9,A,/)") &
1258 "DIIS | The corresponding eigenvectors were discarded"
1261 coeffs(1:nb) = -matmul(a(1:nb, 1:nb1), conjg(b(nb1, 1:nb1)))
1271 CALL timestop(handle)
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
Basic linear algebra operations for complex full matrices.
subroutine, public cp_cfm_trace(matrix_a, matrix_b, trace)
Returns the trace of matrix_a^T matrix_b, i.e sum_{i,j}(matrix_a(i,j)*matrix_b(i,j)) .
Represents a complex full matrix distributed on many processors.
subroutine, public cp_cfm_create(matrix, matrix_struct, name)
Creates a new full matrix with the given structure.
subroutine, public cp_cfm_release(matrix)
Releases a full matrix.
subroutine, public cp_fm_to_cfm(msourcer, msourcei, mtarget)
Construct a complex full matrix by taking its real and imaginary parts from two separate real-value f...
subroutine, public cp_cfm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, matrix_struct, para_env)
Returns information about a full matrix.
subroutine, public cp_cfm_to_fm(msource, mtargetr, mtargeti)
Copy real and imaginary parts of a complex full matrix into separate real-value full matrices.
subroutine, public dbcsr_transposed(transposed, normal, shallow_data_copy, transpose_distribution, use_distribution)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_multiply(transa, transb, alpha, matrix_a, matrix_b, beta, matrix_c, first_row, last_row, first_column, last_column, first_k, last_k, retain_sparsity, filter_eps, flop)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
real(dp) function, public dbcsr_maxabs(matrix)
Compute the maxabs norm of a dbcsr matrix.
subroutine, public dbcsr_dot(matrix_a, matrix_b, trace)
Computes the dot product of two matrices, also known as the trace of their matrix product.
DBCSR operations in CP2K.
subroutine, public copy_dbcsr_to_fm(matrix, fm)
Copy a DBCSR matrix to a BLACS matrix.
basic linear algebra operations for full matrices
subroutine, public cp_fm_column_scale(matrixa, scaling)
scales column i of matrix a with scaling(i)
subroutine, public cp_fm_scale_and_add(alpha, matrix_a, beta, matrix_b)
calc A <- alpha*A + beta*B optimized for alpha == 1.0 (just add beta*B) and beta == 0....
subroutine, public cp_fm_scale(alpha, matrix_a)
scales a matrix matrix_a = alpha * matrix_b
subroutine, public cp_fm_symm(side, uplo, m, n, alpha, matrix_a, matrix_b, beta, matrix_c)
computes matrix_c = beta * matrix_c + alpha * matrix_a * matrix_b computes matrix_c = beta * matrix_c...
represent the structure of a full matrix
represent a full matrix distributed on many processors
subroutine, public cp_fm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, nrow_locals, ncol_locals, matrix_struct, para_env)
returns all kind of information about the full matrix
subroutine, public cp_fm_maxabsval(matrix, a_max, ir_max, ic_max)
find the maximum absolute value of the matrix element maxval(abs(matrix))
subroutine, public cp_fm_set_all(matrix, alpha, beta)
set all elements of a matrix to the same value, and optionally the diagonal to a different one
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp)
creates a new full matrix with the given structure
various routines to log and control the output. The idea is that decisions about where to log should ...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
Types needed for a linear scaling quickstep SCF run based on the density matrix.
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
Collection of simple mathematical functions and subroutines.
subroutine, public diag_complex(matrix, eigenvectors, eigenvalues)
Diagonalizes a local complex Hermitian matrix using LAPACK. Based on cp_cfm_heevd.
subroutine, public diamat_all(a, eigval, dac)
Diagonalize the symmetric n by n matrix a using the LAPACK library. Only the upper triangle of matrix...
Interface to the message passing library MPI.
basic linear algebra operations for full matrixes
buffer for the diis of the scf
Apply the direct inversion in the iterative subspace (DIIS) of Pulay in the framework of an SCF itera...
subroutine, public qs_diis_b_info_kp(diis_buffer, ib, nb)
Update info about the current buffer step ib and the current number of buffers nb.
pure subroutine, public qs_diis_b_create_sparse(diis_buffer, nbuffer)
Allocates an SCF DIIS buffer for LS-SCF calculation.
pure subroutine, public qs_diis_b_clear(diis_buffer)
clears the buffer
subroutine, public qs_diis_b_create(diis_buffer, nbuffer)
Allocates an SCF DIIS buffer.
subroutine, public qs_diis_b_step_4lscf(diis_buffer, qs_env, ls_scf_env, unit_nr, iscf, diis_step, eps_diis, nmixing, s_matrix, threshold)
Update the SCF DIIS buffer in linear scaling SCF (LS-SCF), and if appropriate does a diis step.
subroutine, public qs_diis_b_calc_err_kp(diis_buffer, ib, mos, kc, sc, ispin, ikp, nkp_local, scf_section)
Calculate and store the error for a given k-point.
subroutine, public qs_diis_b_create_kp(diis_buffer, nbuffer)
Allocates an SCF DIIS buffer for k-points.
subroutine, public qs_diis_b_step_kp(diis_buffer, coeffs, ib, nb, delta, error_max, diis_step, eps_diis, nspin, nkp, nkp_local, nmixing, scf_section, para_env)
Update the SCF DIIS buffer, and if appropriate does a diis step, for k-points.
subroutine, public qs_diis_b_step(diis_buffer, mo_array, kc, sc, delta, error_max, diis_step, eps_diis, nmixing, s_matrix, scf_section, roks)
Update the SCF DIIS buffer, and if appropriate does a diis step.
pure subroutine, public qs_diis_b_clear_sparse(diis_buffer)
clears the DIIS buffer in LS-SCF calculation
pure subroutine, public qs_diis_b_clear_kp(diis_buffer)
clears the buffer
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs)
Get the QUICKSTEP environment.
Definition and initialisation of the mo data type.
subroutine, public get_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, eigenvalues, occupation_numbers, mo_coeff, mo_coeff_b, uniform_occupation, kts, mu, flexible_electron_count)
Get the components of a MO set data structure.
Utilities for string manipulations.
subroutine, public compress(string, full)
Eliminate multiple space characters in a string. If full is .TRUE., then all spaces are eliminated.
Represent a complex full matrix.
keeps the information about the structure of a full matrix
type of a logger, at the moment it contains just a print level starting at which level it should be l...
stores all the informations relevant to an mpi environment
build arrau of pointers to diis buffers in the k-point (complex full matrices) case
build array of pointers to diis buffers for sparse matrix case
keeps a buffer with the previous values of s,p,k