80 USE ieee_arithmetic,
ONLY: ieee_is_finite
184#include "./base/base_uses.f90"
190 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_scf_diagonalization'
195 REAL(KIND=
dp),
PARAMETER,
PRIVATE :: occ_tol = 1.0e-3_dp
197 TYPE,
PRIVATE :: kp_diag_workspace_type
198 TYPE(cp_cfm_type) :: cksmat, cmos, csmat, csmat_base, cwork
199 TYPE(cp_cfm_diag_workspace_type) :: solver
200 TYPE(lanczos_workspace_type) :: lan_ws
201 TYPE(local_gemm_ctxt_type) :: gemm_ctx
202 COMPLEX(KIND=dp),
ALLOCATABLE :: phase(:, :)
203 END TYPE kp_diag_workspace_type
220 REAL(kind=
dp) :: shift
223 IF (scf_env%iter_count <= 1 .OR. scf_env%adiis_check_next)
RETURN
224 IF (.NOT.
ASSOCIATED(scf_env%scf_subspace_buffer))
RETURN
225 shift = scf_env%adiis_shift*(1.0_dp - scf_env%scf_subspace_buffer%diis_weight)
236 SUBROUTINE shift_candidate_real(fock, overlap, mos, shift)
240 REAL(kind=
dp),
INTENT(IN) :: shift
243 REAL(kind=
dp) :: maxocc
244 REAL(kind=
dp),
DIMENSION(:),
POINTER :: occupation
248 IF (shift == 0.0_dp)
RETURN
249 CALL get_mo_set(mos, nao=nao, nmo=nmo, maxocc=maxocc, occupation_numbers=occupation, mo_coeff=coeff)
251 CALL parallel_gemm(
"N",
"N", nao, nmo, nao, 1.0_dp, overlap, coeff, 0.0_dp, sc)
253 CALL parallel_gemm(
"N",
"T", nao, nao, nmo, -shift, sc, sc, 1.0_dp, fock)
255 END SUBROUTINE shift_candidate_real
268 SUBROUTINE shift_candidate_complex(fock, overlap, mos, coeff, work, shift, local, gemm_ctx)
273 REAL(kind=
dp),
INTENT(IN) :: shift
274 LOGICAL,
INTENT(IN) :: local
278 REAL(kind=
dp) :: maxocc
279 REAL(kind=
dp),
DIMENSION(:),
POINTER :: occupation
282 IF (shift == 0.0_dp)
RETURN
283 CALL get_mo_set(mos, nao=nao, nmo=nmo, maxocc=maxocc, occupation_numbers=occupation, cmo_coeff=cmos)
287 cpassert(product(overlap%matrix_struct%context%num_pe) == 1)
288 cpassert(product(coeff%matrix_struct%context%num_pe) == 1)
289 cpassert(product(work%matrix_struct%context%num_pe) == 1)
290 cpassert(product(fock%matrix_struct%context%num_pe) == 1)
291 CALL gemm_ctx%gemm(
"N",
"N", nao, nmo, nao,
z_one, &
292 overlap%local_data,
SIZE(overlap%local_data, 1), &
293 coeff%local_data,
SIZE(coeff%local_data, 1),
z_zero, &
294 work%local_data,
SIZE(work%local_data, 1))
295 CALL gemm_ctx%gemm(
"N",
"C", nao, nao, nmo, cmplx(-shift, kind=
dp), &
296 work%local_data,
SIZE(work%local_data, 1), &
297 work%local_data,
SIZE(work%local_data, 1),
z_one, &
298 fock%local_data,
SIZE(fock%local_data, 1))
301 CALL parallel_gemm(
"N",
"C", nao, nao, nmo, cmplx(-shift, kind=
dp), work, work,
z_one, fock)
303 END SUBROUTINE shift_candidate_complex
320 matrix_s, scf_control, scf_section, &
325 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s
328 LOGICAL,
INTENT(INOUT) :: diis_step
330 INTEGER :: cdiis_cholesky_method, cdiis_ncall, &
332 LOGICAL :: cdiis_step, do_level_shift, owns_ortho, &
333 use_adiis, use_cdiis, use_jacobi, &
335 REAL(kind=
dp) :: candidate_shift, cdiis_error, &
336 diis_error, diis_weight, eps_diis
338 TYPE(
dbcsr_type),
POINTER :: effective_ks_dbcsr, ortho_dbcsr
340 nspin =
SIZE(matrix_ks)
341 NULLIFY (effective_ks_dbcsr, ortho, ortho_dbcsr)
344 use_subspace_fock = .false.
346 IF (.NOT.
ASSOCIATED(scf_env%scf_subspace_buffer))
THEN
347 cpabort(
"ADIIS is only available in the main Quickstep SCF workflow")
349 use_subspace_fock = scf_env%scf_subspace_buffer%use_combined_fock
352 eps_diis = scf_control%eps_diis
354 IF (use_adiis .AND.
ASSOCIATED(scf_env%scf_diis_buffer))
THEN
355 IF (.NOT. scf_env%skip_diis .AND. scf_env%iter_count > 1 .AND. &
356 .NOT. scf_env%adiis_check_next .AND. &
357 .NOT. scf_env%scf_subspace_buffer%last_restart .AND. &
358 scf_env%scf_subspace_buffer%nstored > 0)
THEN
359 use_cdiis = scf_env%iter_delta < eps_diis .OR. scf_env%scf_diis_buffer%ncall > 0
364 IF (use_subspace_fock .AND. .NOT. use_cdiis)
THEN
365 CALL copy_dbcsr_to_fm(scf_env%scf_subspace_buffer%combined_fock(ispin, 1)%matrix, &
366 scf_env%scf_work1(ispin), scf_env%fm_copy_plan(ispin), check_plan=.true.)
369 scf_env%fm_copy_plan(ispin), check_plan=.true.)
375 diis_error = scf_env%scf_subspace_buffer%last_old_fock_weight
376 diis_weight = scf_env%scf_subspace_buffer%diis_weight
378 cdiis_ncall = scf_env%scf_diis_buffer%ncall
379 CALL qs_diis_b_step(scf_env%scf_diis_buffer, mos, scf_env%scf_work1, &
380 scf_env%scf_work2, scf_env%iter_delta, cdiis_error, cdiis_step, &
381 eps_diis, 2, s_matrix=matrix_s, scf_section=scf_section)
382 IF (.NOT. ieee_is_finite(cdiis_error) .OR. cdiis_error >= eps_diis)
THEN
384 IF (cdiis_ncall < scf_env%scf_diis_buffer%nbuffer)
THEN
386 scf_env%scf_diis_buffer%ncall = cdiis_ncall
394 diis_weight = min(1.0_dp, diis_weight + 0.5_dp)
399 IF (diis_weight < 1.0_dp)
THEN
401 IF (use_subspace_fock)
THEN
403 scf_env%scf_subspace_buffer%combined_fock(ispin, 1)%matrix, scf_env%scf_work2, &
404 scf_env%fm_copy_plan(ispin), check_plan=.true.)
407 scf_env%fm_copy_plan(ispin), check_plan=.true.)
410 1.0_dp - diis_weight, scf_env%scf_work2)
413 diis_step = cdiis_step .AND. diis_weight >= 1.0_dp
414 IF (diis_step) diis_error = cdiis_error
415 ELSE IF (
ASSOCIATED(scf_env%scf_diis_buffer))
THEN
416 IF (scf_env%scf_diis_buffer%ncall > 0)
CALL qs_diis_b_clear(scf_env%scf_diis_buffer)
419 scf_env%scf_subspace_buffer%diis_weight = diis_weight
421 IF (scf_env%iter_count > 1 .AND. .NOT. scf_env%skip_diis)
THEN
422 CALL qs_diis_b_step(scf_env%scf_diis_buffer, mos, scf_env%scf_work1, &
423 scf_env%scf_work2, scf_env%iter_delta, diis_error, diis_step, &
424 eps_diis, scf_control%nmixing, &
426 scf_section=scf_section)
432 candidate_shift = 0.0_dp
434 IF (candidate_shift > 0.0_dp)
THEN
435 CALL copy_dbcsr_to_fm(matrix_s(1)%matrix, scf_env%scf_work2, scf_env%fm_copy_plan(0), check_plan=.true.)
437 CALL shift_candidate_real(scf_env%scf_work1(ispin), scf_env%scf_work2, mos(ispin), candidate_shift)
441 do_level_shift = ((scf_control%level_shift /= 0.0_dp) .AND. &
442 ((scf_control%density_guess ==
core_guess) .OR. &
443 (scf_env%iter_count > 1)))
445 IF (.NOT. use_adiis .AND. (scf_env%iter_count > 1) .AND. &
446 (scf_env%iter_delta < scf_control%diagonalization%eps_jacobi))
THEN
452 IF (use_adiis .AND. .NOT. diis_step)
THEN
453 scf_env%iter_param = diis_error
454 IF (scf_env%scf_subspace_buffer%last_restart)
THEN
455 scf_env%iter_method =
"ADIIS/Rst."
457 scf_env%iter_method =
"ADIIS/Diag."
459 ELSE IF (diis_step)
THEN
460 scf_env%iter_param = diis_error
462 scf_env%iter_method =
"DIIS/Jacobi"
464 scf_env%iter_method =
"DIIS/Diag."
467 IF (scf_env%mixing_method == 0)
THEN
468 scf_env%iter_method =
"NoMix/Diag."
469 ELSE IF (scf_env%mixing_method == 1)
THEN
470 scf_env%iter_param = scf_env%p_mix_alpha
472 scf_env%iter_method =
"P_Mix/Jacobi"
474 scf_env%iter_method =
"P_Mix/Diag."
476 ELSE IF (scf_env%mixing_method > 1)
THEN
477 scf_env%iter_param = scf_env%mixing_store%alpha
479 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Jacobi"
481 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Diag."
486 IF (scf_env%cholesky_method ==
cholesky_dbcsr .AND. .NOT. use_cdiis)
THEN
487 ortho_dbcsr => scf_env%ortho_dbcsr
489 effective_ks_dbcsr => matrix_ks(ispin)%matrix
490 IF (use_subspace_fock)
THEN
491 effective_ks_dbcsr => scf_env%scf_subspace_buffer%combined_fock(ispin, 1)%matrix
493 CALL eigensolver_dbcsr(matrix_ks=effective_ks_dbcsr, matrix_ks_fm=scf_env%scf_work1(ispin), &
495 ortho_dbcsr=ortho_dbcsr, &
496 ksbuf1=scf_env%buf1_dbcsr, ksbuf2=scf_env%buf2_dbcsr)
500 cdiis_cholesky_method = scf_env%cholesky_method
505 ortho => scf_env%ortho_m1
507 ortho => scf_env%ortho
511 IF (.NOT.
ASSOCIATED(ortho))
THEN
519 matrix_s=matrix_s(ispin)%matrix, &
521 work=scf_env%scf_work2)
523 IF (do_level_shift)
THEN
524 CALL eigensolver(matrix_ks_fm=scf_env%scf_work1(ispin), &
527 work=scf_env%scf_work2, &
528 cholesky_method=cdiis_cholesky_method, &
529 do_level_shift=do_level_shift, &
530 level_shift=scf_control%level_shift, &
531 matrix_u_fm=scf_env%ortho, &
532 use_jacobi=use_jacobi)
534 CALL eigensolver(matrix_ks_fm=scf_env%scf_work1(ispin), &
537 work=scf_env%scf_work2, &
538 cholesky_method=cdiis_cholesky_method, &
539 do_level_shift=do_level_shift, &
540 level_shift=scf_control%level_shift, &
541 use_jacobi=use_jacobi)
547 scf_env%cholesky_method = cdiis_cholesky_method
550 IF (owns_ortho)
DEALLOCATE (ortho)
552 ortho => scf_env%ortho
555 IF (.NOT.
ASSOCIATED(ortho))
THEN
560 IF (do_level_shift)
THEN
562 IF (
ASSOCIATED(scf_env%scf_work1_red) .AND.
ASSOCIATED(scf_env%scf_work2_red) &
563 .AND.
ASSOCIATED(scf_env%ortho_red) .AND.
ASSOCIATED(scf_env%ortho_m1_red))
THEN
567 work=scf_env%scf_work2, &
568 do_level_shift=do_level_shift, &
569 level_shift=scf_control%level_shift, &
570 matrix_u_fm=scf_env%ortho_m1, &
571 use_jacobi=use_jacobi, &
572 jacobi_threshold=scf_control%diagonalization%jacobi_threshold, &
573 matrix_ks_fm_red=scf_env%scf_work1_red(ispin), &
574 ortho_red=scf_env%ortho_red, &
575 work_red=scf_env%scf_work2_red, &
576 matrix_u_fm_red=scf_env%ortho_m1_red)
581 work=scf_env%scf_work2, &
582 do_level_shift=do_level_shift, &
583 level_shift=scf_control%level_shift, &
584 matrix_u_fm=scf_env%ortho_m1, &
585 use_jacobi=use_jacobi, &
586 jacobi_threshold=scf_control%diagonalization%jacobi_threshold)
591 IF (
ASSOCIATED(scf_env%scf_work1_red) .AND.
ASSOCIATED(scf_env%scf_work2_red) &
592 .AND.
ASSOCIATED(scf_env%ortho_red))
THEN
596 work=scf_env%scf_work2, &
597 do_level_shift=do_level_shift, &
598 level_shift=scf_control%level_shift, &
599 use_jacobi=use_jacobi, &
600 jacobi_threshold=scf_control%diagonalization%jacobi_threshold, &
601 matrix_ks_fm_red=scf_env%scf_work1_red(ispin), &
602 ortho_red=scf_env%ortho_red, &
603 work_red=scf_env%scf_work2_red)
608 work=scf_env%scf_work2, &
609 do_level_shift=do_level_shift, &
610 level_shift=scf_control%level_shift, &
611 use_jacobi=use_jacobi, &
612 jacobi_threshold=scf_control%diagonalization%jacobi_threshold)
617 IF (owns_ortho)
DEALLOCATE (ortho)
634 matrix_s, scf_control, scf_section, &
638 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(INOUT) :: mos
639 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s
642 LOGICAL,
INTENT(INOUT) :: diis_step
646 INTEGER :: ispin, nspin
647 REAL(kind=
dp) :: total_zeff_corr
649 nspin =
SIZE(matrix_ks)
652 matrix_s, scf_control, scf_section, diis_step)
654 total_zeff_corr = 0.0_dp
655 total_zeff_corr = scf_env%sum_zeff_corr
657 IF (abs(total_zeff_corr) > 0.0_dp)
THEN
659 smear=scf_control%smear, tot_zeff_corr=total_zeff_corr)
661 IF (
PRESENT(probe) .EQV. .true.)
THEN
662 scf_control%smear%do_smear = .false.
664 smear=scf_control%smear, &
667 IF (.NOT. scf_control%gce%do_gce)
THEN
669 smear=scf_control%smear)
672 smear=scf_control%smear, &
680 scf_env%p_mix_new(ispin, 1)%matrix)
707 diis_step, diis_error, qs_env, probe, added_mos_auto_grow, potential)
709 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks, matrix_s
713 LOGICAL,
INTENT(IN) :: update_p
714 LOGICAL,
INTENT(INOUT) :: diis_step
715 REAL(
dp),
INTENT(INOUT),
OPTIONAL :: diis_error
719 LOGICAL,
INTENT(OUT),
OPTIONAL :: added_mos_auto_grow
720 REAL(
dp),
INTENT(IN),
OPTIONAL,
TARGET :: potential(:, :)
722 CHARACTER(len=*),
PARAMETER :: routinen =
'do_general_diag_kp'
724 COMPLEX(KIND=dp),
ALLOCATABLE,
DIMENSION(:) :: coeffs
725 REAL(
dp),
POINTER :: effective_u(:, :), adiis_u(:, :)
726 INTEGER :: cdiis_ncall, handle, ib, ikp, ispin, kplocal, kpmax, &
727 lattice_fft, nb, nkp, nspin, omp_threads, nworkers, fft_ready
728 INTEGER,
DIMENSION(2) :: kp_range
729 INTEGER,
DIMENSION(3) :: nkp_grid
730 INTEGER,
DIMENSION(:, :),
POINTER :: kp_dist
731 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
732 LOGICAL :: adiis_cdiis, cache_smat, cdiis_step, do_diis, my_added_mos_auto_grow, prepared_ops, prepared_part, &
733 reuse_smat, spin_grid_fft, use_adiis, use_grid_fft, use_local_kpoints,
use_real_wfn
734 REAL(kind=
dp) :: diis_weight
735 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues
736 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: xkp
737 TYPE(
cp_cfm_type),
POINTER :: cksmat, cmos, csmat, cwork
738 TYPE(kp_diag_workspace_type),
ALLOCATABLE,
TARGET :: workspace(:)
742 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: fmwork
744 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: adiis_ks, effective_ks
756 CALL timeset(routinen, handle)
758 my_added_mos_auto_grow = .false.
759 IF (
PRESENT(added_mos_auto_grow)) added_mos_auto_grow = .false.
761 NULLIFY (adiis_ks, effective_ks, sab_nl)
763 kp_dist=kp_dist, sab_nl=sab_nl, &
764 cell_to_index=cell_to_index, nkp_grid=nkp_grid, lattice_fft=lattice_fft)
765 cpassert(
ASSOCIATED(sab_nl))
766 kplocal = kp_range(2) - kp_range(1) + 1
767 kpmax = maxval(kp_dist(2, :) - kp_dist(1, :) + 1)
773 cpassert(
ASSOCIATED(scf_env%scf_subspace_buffer))
775 adiis_cdiis = .false.
776 IF (use_adiis .AND.
ASSOCIATED(kpoints%scf_diis_buffer))
THEN
777 IF (scf_env%iter_count > 1 .AND. .NOT. scf_env%skip_diis .AND. &
778 .NOT. scf_env%adiis_check_next .AND. &
779 .NOT. scf_env%scf_subspace_buffer%last_restart .AND. &
780 scf_env%scf_subspace_buffer%nstored > 0 .AND. &
781 PRESENT(diis_error) .AND.
PRESENT(qs_env))
THEN
782 adiis_cdiis = scf_env%iter_delta < scf_control%eps_diis .OR. &
783 kpoints%scf_diis_buffer%ncall > 0
786 IF ((.NOT. use_adiis .AND. scf_env%iter_count > 1 .AND. .NOT. scf_env%skip_diis .AND. &
787 .NOT.
use_real_wfn .AND.
PRESENT(diis_error) .AND.
PRESENT(qs_env)) .OR. &
788 adiis_cdiis) do_diis = .true.
790 adiis_ks => matrix_ks
792 IF (
ALLOCATED(kpoints%lowdin_v)) adiis_u => kpoints%lowdin_v
794 IF (scf_env%scf_subspace_buffer%use_combined_fock)
THEN
795 adiis_ks => scf_env%scf_subspace_buffer%combined_fock
796 IF (
ASSOCIATED(adiis_u)) adiis_u => scf_env%scf_subspace_buffer%combined_aux
799 effective_ks => matrix_ks
800 NULLIFY (effective_u)
801 IF (
ALLOCATED(kpoints%lowdin_v)) effective_u => kpoints%lowdin_v
802 IF (
PRESENT(potential))
THEN
803 cpassert(.NOT. update_p)
804 effective_u => potential
806 IF (use_adiis .AND. .NOT. adiis_cdiis)
THEN
807 effective_ks => adiis_ks
808 effective_u => adiis_u
810 IF (use_adiis .AND. .NOT. do_diis)
THEN
811 scf_env%scf_subspace_buffer%diis_weight = 0.0_dp
812 IF (
ASSOCIATED(kpoints%scf_diis_buffer))
THEN
813 IF (kpoints%scf_diis_buffer%ncall > 0)
CALL qs_diis_b_clear_kp(kpoints%scf_diis_buffer)
817 para_env => kpoints%blacs_env_all%para_env
818 nspin =
SIZE(matrix_ks, 1)
822 use_local_kpoints = kpoints%para_env_kp%num_pe == 1 .AND. .NOT.
use_real_wfn
826 NULLIFY (scf_section)
830 fmwork => scf_env%scf_work1
836 CALL mpools_get(mpools, ao_ao_fm_pool=ao_ao_fm_pool)
850 reuse_smat =
ALLOCATED(kpoints%scf_smat)
851 IF (.NOT. reuse_smat)
THEN
852 ALLOCATE (kpoints%scf_smat(kplocal))
857 cpassert(
SIZE(kpoints%scf_smat) == kplocal)
861 prepared_ops = .false.
864 IF (.NOT. reuse_smat)
THEN
866 prepared_ops = prepared_ops .AND. prepared_part
869 use_local_kpoints = use_local_kpoints .AND. prepared_ops
871 IF (use_local_kpoints) nworkers = min(omp_threads, kplocal)
873 kp => kpoints%kp_env(1)%kpoint_env
878 mo_struct => kp%mos(1)%cmo_coeff%matrix_struct
880 CALL kp_diag_workspaces_create(workspace, nworkers, matrix_struct, mo_struct, 0, &
881 use_local_kpoints, scf_env%cholesky_method ==
cholesky_off)
882 cksmat => workspace(1)%cksmat
883 csmat => workspace(1)%csmat
884 cwork => workspace(1)%cwork
885 cmos => workspace(1)%cmos
891 ALLOCATE (ks_grid(nspin))
892 SELECT CASE (lattice_fft)
894 use_grid_fft = nkp >= 27
896 use_grid_fft = .true.
898 use_grid_fft = .false.
900 cpabort(
"Unknown lattice FFT selection mode")
902 use_grid_fft = use_grid_fft .AND. .NOT. prepared_ops
904 IF (use_grid_fft)
THEN
906 CALL dbcsr_create(rmatrix, template=matrix_ks(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
909 IF (use_grid_fft .AND. .NOT. reuse_smat)
THEN
911 cell_to_index, sab_nl, use_grid_fft, &
912 max_storage_bytes=512_int_8*1024_int_8**2/int(nspin + 1,
int_8))
913 fft_ready = merge(1, 0, use_grid_fft)
914 CALL para_env%min(fft_ready)
915 use_grid_fft = fft_ready == 1
917 IF (use_grid_fft)
THEN
920 cell_to_index, sab_nl, spin_grid_fft, &
921 max_storage_bytes=512_int_8*1024_int_8**2/int(nspin + 1,
int_8))
922 use_grid_fft = use_grid_fft .AND. spin_grid_fft
924 fft_ready = merge(1, 0, use_grid_fft)
925 CALL para_env%min(fft_ready)
926 use_grid_fft = fft_ready == 1
928 IF (.NOT. use_grid_fft)
THEN
936 IF (.NOT. use_local_kpoints)
THEN
940 ks_grid(ispin), use_grid_fft, matrix_row=ispin)
941 IF (.NOT. cache_smat .OR. (.NOT. reuse_smat .AND. ispin == 1))
THEN
953 cdiis_ncall = kpoints%scf_diis_buffer%ncall
956 IF (use_local_kpoints)
THEN
957 CALL kp_diag_local_phase(op_ctx, kpoints, workspace, scf_env, scf_control, nspin, &
958 cache_smat, reuse_smat, use_adiis, ib, .true., 1.0_dp, potential=effective_u)
962 CALL harvest_operators(ikp, ispin)
963 IF (ikp > kplocal) cycle
966 local=.false., gemm_ctx=workspace(1)%gemm_ctx)
973 ALLOCATE (coeffs(nb))
974 CALL qs_diis_b_step_kp(kpoints%scf_diis_buffer, coeffs, ib, nb, scf_env%iter_delta, diis_error, &
975 cdiis_step, scf_control%eps_diis, nspin, nkp, kplocal, &
976 merge(2, scf_control%nmixing, use_adiis), &
977 scf_section, kpoints%para_env_inter_kp)
980 diis_weight = scf_env%scf_subspace_buffer%diis_weight
981 IF (.NOT. ieee_is_finite(diis_error) .OR. diis_error >= scf_control%eps_diis)
THEN
983 IF (cdiis_ncall < kpoints%scf_diis_buffer%nbuffer)
THEN
985 kpoints%scf_diis_buffer%ncall = cdiis_ncall
993 diis_weight = min(1.0_dp, diis_weight + 0.5_dp)
998 scf_env%scf_subspace_buffer%diis_weight = diis_weight
999 diis_step = cdiis_step .AND. diis_weight >= 1.0_dp
1000 IF (.NOT. diis_step) diis_error = scf_env%scf_subspace_buffer%last_old_fock_weight
1002 diis_step = cdiis_step
1007 IF (use_adiis .AND. diis_weight < 1.0_dp)
THEN
1010 use_local_kpoints = use_local_kpoints .AND. prepared_part
1014 IF (.NOT. update_p .OR. use_adiis) diis_step = .false.
1017 IF (use_local_kpoints)
THEN
1019 IF (do_diis) effective_u => adiis_u
1020 CALL kp_diag_local_phase(op_ctx, kpoints, workspace, scf_env, scf_control, nspin, &
1021 cache_smat, reuse_smat, use_adiis, ib, .false., diis_weight, coeffs, effective_u)
1026 IF (use_adiis .AND. diis_weight < 1.0_dp)
THEN
1028 use_grid=.false., matrix_row=ispin)
1030 IF (ikp <= kplocal .AND.
ASSOCIATED(adiis_u))
THEN
1031 CALL lowdin_kp_apply(kpoints%kp_env(ikp)%kpoint_env, adiis_u(:, ispin), cmat=cwork)
1034 IF (ikp > kplocal) cycle
1035 CALL cp_cfm_to_cfm(kpoints%scf_diis_buffer%smat(ikp), csmat)
1036 CALL kp_diis_candidate(kpoints, ikp, ispin, coeffs, diis_weight, cksmat, cwork)
1042 CALL harvest_operators(ikp, ispin)
1043 IF (ikp > kplocal) cycle
1045 kp => kpoints%kp_env(ikp)%kpoint_env
1047 CALL get_mo_set(kp%mos(ispin), mo_coeff=mo_coeff, eigenvalues=eigenvalues)
1048 IF (use_adiis)
CALL shift_candidate_real(rksmat, rsmat, kp%mos(ispin), &
1051 CALL cp_fm_geeig_canon(rksmat, rsmat, mo_coeff, eigenvalues, fmlocal, scf_control%eps_eigval)
1053 CALL cp_fm_geeig(rksmat, rsmat, mo_coeff, eigenvalues, fmlocal)
1056 CALL kp_solve_complex(kp%mos(ispin), workspace(1), scf_env, scf_control, use_adiis, .false.)
1061 IF (
ALLOCATED(coeffs))
DEALLOCATE (coeffs)
1067 IF (
PRESENT(probe) .EQV. .true.)
THEN
1068 scf_control%smear%do_smear = .false.
1073 added_mos_auto=scf_control%added_mos_auto, &
1074 added_mos_auto_grow=my_added_mos_auto_grow)
1076 IF (my_added_mos_auto_grow)
THEN
1077 IF (
PRESENT(added_mos_auto_grow)) added_mos_auto_grow = .true.
1083 matrix_s(1, 1)%matrix, sab_nl, fmwork, overlap_rs=matrix_s)
1092 DEALLOCATE (ks_grid)
1098 IF (
ALLOCATED(workspace))
CALL kp_diag_workspaces_release(workspace)
1101 CALL timestop(handle)
1112 SUBROUTINE harvest_operators(round, spin)
1113 INTEGER,
INTENT(IN) :: round, spin
1118 IF (round <= kplocal .AND.
ASSOCIATED(effective_u))
THEN
1119 CALL lowdin_kp_apply(kpoints%kp_env(round)%kpoint_env, effective_u(:, spin), rmat=rksmat)
1121 IF (round <= kplocal .AND. do_diis)
THEN
1127 IF (round <= kplocal .AND.
ASSOCIATED(effective_u))
THEN
1128 CALL lowdin_kp_apply(kpoints%kp_env(round)%kpoint_env, effective_u(:, spin), cmat=cksmat)
1130 IF (.NOT. cache_smat .OR. (.NOT. reuse_smat .AND. spin == 1))
THEN
1135 IF (round > kplocal)
RETURN
1136 kp => kpoints%kp_env(round)%kpoint_env
1137 IF (cache_smat)
THEN
1138 IF (.NOT. reuse_smat .AND. spin == 1)
THEN
1144 END SUBROUTINE harvest_operators
1165 SUBROUTINE kp_diag_local_phase(ctx, kpoints, workspace, scf_env, scf_control, nspin, &
1166 cache_smat, reuse_smat, use_adiis, ib, store_error, diis_weight, coeffs, potential)
1169 TYPE(kp_diag_workspace_type),
TARGET,
INTENT(INOUT) :: workspace(:)
1172 INTEGER,
INTENT(IN) :: nspin, ib
1173 LOGICAL,
INTENT(IN) :: cache_smat, reuse_smat, use_adiis, store_error
1174 REAL(kind=
dp),
INTENT(IN) :: diis_weight
1175 COMPLEX(KIND=dp),
OPTIONAL,
INTENT(IN) :: coeffs(:)
1176 REAL(
dp),
OPTIONAL,
INTENT(IN) :: potential(:, :)
1178 COMPLEX(KIND=dp),
ALLOCATABLE :: operators(:, :, :, :)
1179 REAL(kind=
dp),
ALLOCATABLE :: block_work(:)
1180 INTEGER :: first, ik, ikp, ispin, j, kplocal, nbatch, nmatrices, nworkers, thread, width
1181 INTEGER(KIND=int_8) :: work_size
1182 LOGICAL :: build_h, build_s
1184 TYPE(kp_diag_workspace_type),
POINTER :: work
1186 kplocal = kpoints%kp_range(2) - kpoints%kp_range(1) + 1
1187 IF (kplocal == 0)
RETURN
1188 nworkers =
SIZE(workspace)
1189 build_s = .NOT.
PRESENT(coeffs) .AND. .NOT. reuse_smat
1190 build_h = .NOT.
PRESENT(coeffs) .OR. diis_weight < 1.0_dp
1191 nmatrices = merge(1, 0, build_h) + merge(1, 0, build_s)
1203 work => workspace(thread)
1204 ALLOCATE (operators(
SIZE(work%cksmat%local_data, 1),
SIZE(work%cksmat%local_data, 2), width, nmatrices), &
1205 block_work(work_size))
1207 DO first = 1, kplocal, width
1208 nbatch = min(width, kplocal - first + 1)
1209 ik = kpoints%kp_range(1) + first - 1
1219 kp => kpoints%kp_env(ikp)%kpoint_env
1221 IF (
PRESENT(coeffs))
THEN
1222 work%csmat_base%local_data(:, :) = operators(:, :, j, 1)
1223 IF (
PRESENT(potential))
CALL lowdin_kp_apply(kp, potential(:, ispin), cmat=work%csmat_base)
1225 work%cksmat%local_data(:, :) = operators(:, :, j, 1)
1226 IF (
PRESENT(potential))
CALL lowdin_kp_apply(kp, potential(:, ispin), cmat=work%cksmat)
1229 IF (
PRESENT(coeffs))
THEN
1230 CALL cp_cfm_to_cfm(kpoints%scf_diis_buffer%smat(ikp), work%csmat)
1231 CALL kp_diis_candidate(kpoints, ikp, ispin, coeffs, diis_weight, work%cksmat, work%csmat_base)
1233 IF (reuse_smat)
THEN
1236 work%csmat%local_data(:, :) = operators(:, :, j, nmatrices)
1238 IF (cache_smat .AND. .NOT. reuse_smat .AND. ispin == 1)
THEN
1242 IF (store_error)
THEN
1244 ispin, ikp, work%cmos, local=.true., gemm_ctx=work%gemm_ctx)
1246 CALL kp_solve_complex(kp%mos(ispin), work, scf_env, scf_control, use_adiis, .true.)
1252 DEALLOCATE (operators, block_work)
1255 END SUBROUTINE kp_diag_local_phase
1267 SUBROUTINE kp_diis_candidate(kpoints, ikp, ispin, coeffs, weight, fock, adiis_fock)
1269 INTEGER,
INTENT(IN) :: ikp, ispin
1270 COMPLEX(KIND=dp),
INTENT(IN) :: coeffs(:)
1271 REAL(kind=
dp),
INTENT(IN) :: weight
1278 DO jb = 1,
SIZE(coeffs)
1282 cmplx(1.0_dp - weight, kind=
dp), adiis_fock)
1283 END SUBROUTINE kp_diis_candidate
1294 SUBROUTINE kp_solve_complex(mos, work, scf_env, scf_control, use_adiis, local)
1296 TYPE(kp_diag_workspace_type),
INTENT(INOUT) :: work
1299 LOGICAL,
INTENT(IN) :: use_adiis, local
1301 REAL(kind=
dp),
POINTER :: eigenvalues(:)
1303 CALL get_mo_set(mos, eigenvalues=eigenvalues)
1304 IF (use_adiis)
CALL shift_candidate_complex(work%cksmat, work%csmat, mos, work%cmos, work%cwork, &
1309 scf_control%eps_eigval, ws=work%solver)
1311 CALL cp_cfm_geeig_canon(work%cksmat, work%csmat, mos%cmo_coeff, eigenvalues, work%cwork, &
1312 scf_control%eps_eigval)
1316 CALL cp_cfm_geeig_local(work%cksmat, work%csmat, mos%cmo_coeff, eigenvalues, ws=work%solver)
1318 CALL cp_cfm_geeig(work%cksmat, work%csmat, mos%cmo_coeff, eigenvalues, work%cwork)
1321 END SUBROUTINE kp_solve_complex
1336 SUBROUTINE kp_diag_workspaces_create(workspace, nworkers, matrix_struct, mo_struct, nentry, local, canonical, &
1337 lanczos, nkrylov, nblock)
1338 TYPE(kp_diag_workspace_type),
ALLOCATABLE, &
1339 INTENT(OUT) :: workspace(:)
1340 INTEGER,
INTENT(IN) :: nworkers
1342 INTEGER,
INTENT(IN) :: nentry
1343 LOGICAL,
INTENT(IN) :: local, canonical
1344 LOGICAL,
INTENT(IN),
OPTIONAL :: lanczos
1345 INTEGER,
INTENT(IN),
OPTIONAL :: nkrylov, nblock
1348 LOGICAL :: my_lanczos
1350 my_lanczos = .false.
1351 IF (
PRESENT(lanczos)) my_lanczos = lanczos
1353 ALLOCATE (workspace(nworkers))
1361 IF (local .OR. my_lanczos)
THEN
1366 ALLOCATE (workspace(i)%phase(1, nentry))
1367 n = matrix_struct%nrow_global
1372 workspace(i)%csmat%local_data)
1375 IF (my_lanczos)
THEN
1379 END SUBROUTINE kp_diag_workspaces_create
1385 SUBROUTINE kp_diag_workspaces_release(workspace)
1386 TYPE(kp_diag_workspace_type),
ALLOCATABLE, &
1387 INTENT(INOUT) :: workspace(:)
1391 DO i = 1,
SIZE(workspace)
1392 CALL workspace(i)%gemm_ctx%destroy()
1400 DEALLOCATE (workspace)
1401 END SUBROUTINE kp_diag_workspaces_release
1416 PURE FUNCTION kp_adaptive_eps_iter(eps_iter, eps_adapt, iter_error, noise_scale, cap)
RESULT(eps)
1417 REAL(kind=
dp),
INTENT(IN) :: eps_iter, eps_adapt, iter_error, &
1419 REAL(kind=
dp) :: eps
1421 IF (eps_adapt <= 0.0_dp .OR. iter_error <= 0.0_dp)
THEN
1424 eps = max(eps_iter, min(eps_adapt*iter_error/noise_scale, cap))
1426 END FUNCTION kp_adaptive_eps_iter
1443 SUBROUTINE kp_diag_exit_chain(kpoints, scf_env, scf_control, matrix_s_kp, sab_nl, fmwork, grow)
1447 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s_kp
1450 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: fmwork
1451 LOGICAL,
INTENT(OUT) :: grow
1454 added_mos_auto=scf_control%added_mos_auto, &
1455 added_mos_auto_grow=grow)
1459 matrix_s_kp(1, 1)%matrix, sab_nl, fmwork, overlap_rs=matrix_s_kp)
1460 END SUBROUTINE kp_diag_exit_chain
1473 SUBROUTINE kp_eps_col_by_occupation(occupation, eps_iter, eps_iter_empty, eps_col)
1474 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN),
POINTER :: occupation
1475 REAL(kind=
dp),
INTENT(IN) :: eps_iter, eps_iter_empty
1476 REAL(kind=
dp),
DIMENSION(:),
INTENT(OUT) :: eps_col
1480 DO imo = 1,
SIZE(occupation)
1481 IF (occupation(imo) < occ_tol)
THEN
1482 eps_col(imo) = eps_iter_empty
1484 eps_col(imo) = eps_iter
1487 END SUBROUTINE kp_eps_col_by_occupation
1506 SUBROUTINE kp_diag_setup(qs_env, kpoints, nspin, matrix_ks_kp, matrix_s_kp, fmwork, op_ctx, &
1507 matrix_struct, prepare, prepared)
1510 INTEGER,
INTENT(IN) :: nspin
1511 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks_kp, matrix_s_kp
1512 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: fmwork
1515 LOGICAL,
INTENT(IN) :: prepare
1516 LOGICAL,
INTENT(OUT),
OPTIONAL :: prepared
1519 LOGICAL :: ks_ready, s_ready
1523 IF (
PRESENT(prepared)) prepared = .false.
1525 CALL mpools_get(mpools, ao_ao_fm_pool=ao_ao_fm_pool)
1526 ALLOCATE (fmwork(4))
1535 IF (
PRESENT(prepared)) prepared = ks_ready .AND. s_ready
1538 CALL mpools_get(kp_mpools, ao_ao_fm_pool=kp_ao_ao_fm_pool)
1540 END SUBROUTINE kp_diag_setup
1549 SUBROUTINE kp_diag_finalize(qs_env, fmwork, op_ctx)
1551 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: fmwork
1560 CALL mpools_get(mpools, ao_ao_fm_pool=ao_ao_fm_pool)
1565 END SUBROUTINE kp_diag_finalize
1582 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks, matrix_s
1584 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: fmwork
1586 CHARACTER(len=*),
PARAMETER :: routinen =
'diag_kp_basic'
1588 INTEGER :: handle, ikp, ispin, kplocal, kpmax, nspin
1589 INTEGER,
DIMENSION(2) :: kp_range
1590 INTEGER,
DIMENSION(:, :),
POINTER :: kp_dist
1592 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues
1604 CALL timeset(routinen, handle)
1608 kp_dist=kp_dist, sab_nl=sab_nl)
1609 cpassert(
ASSOCIATED(sab_nl))
1610 kplocal = kp_range(2) - kp_range(1) + 1
1611 kpmax = maxval(kp_dist(2, :) - kp_dist(1, :) + 1)
1615 CALL mpools_get(mpools, ao_ao_fm_pool=ao_ao_fm_pool)
1627 kp => kpoints%kp_env(1)%kpoint_env
1628 mo_struct => kp%mos(1)%cmo_coeff%matrix_struct
1632 nspin =
SIZE(matrix_ks, 1)
1639 use_grid=.false., matrix_row=ispin)
1658 IF (ikp > kplocal) cycle
1659 kp => kpoints%kp_env(ikp)%kpoint_env
1661 CALL get_mo_set(kp%mos(ispin), mo_coeff=mo_coeff, eigenvalues=eigenvalues)
1662 CALL cp_fm_geeig(rksmat, rsmat, mo_coeff, eigenvalues, fmlocal)
1664 CALL get_mo_set(kp%mos(ispin), eigenvalues=eigenvalues)
1665 CALL cp_cfm_geeig(cksmat, csmat, cmos, eigenvalues, cwork)
1684 CALL timestop(handle)
1704 ks_env, scf_section, scf_control)
1709 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(INOUT) :: mos
1715 CHARACTER(LEN=*),
PARAMETER :: routinen =
'do_scf_diag_subspace'
1716 REAL(kind=
dp),
PARAMETER :: rone = 1.0_dp, rzero = 0.0_dp
1718 INTEGER :: handle, i, iloop, ispin, nao, nmo, &
1720 LOGICAL :: converged
1721 REAL(
dp) :: ene_diff, ene_old, iter_delta, max_val, &
1722 sum_band, sum_val, t1, t2
1723 REAL(kind=
dp),
DIMENSION(:),
POINTER :: mo_eigenvalues, mo_occupations
1724 TYPE(
cp_1d_r_p_type),
ALLOCATABLE,
DIMENSION(:) :: eval_first, occ_first
1726 TYPE(
cp_fm_type),
POINTER :: c0, chc, evec, mo_coeff
1728 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s, rho_ao
1729 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: rho_ao_kp
1735 CALL timeset(routinen, handle)
1736 NULLIFY (c0, chc, energy, evec, matrix_ks, mo_coeff, mo_eigenvalues, &
1737 mo_occupations, dft_control, rho_ao, rho_ao_kp)
1741 extension=
".scfLog")
1745 CALL qs_rho_get(rho, rho_ao=rho_ao, rho_ao_kp=rho_ao_kp)
1747 ALLOCATE (eval_first(nspin))
1748 ALLOCATE (occ_first(nspin))
1752 eigenvalues=mo_eigenvalues, &
1753 occupation_numbers=mo_occupations)
1754 ALLOCATE (eval_first(ispin)%array(nmo))
1755 ALLOCATE (occ_first(ispin)%array(nmo))
1756 eval_first(ispin)%array(1:nmo) = mo_eigenvalues(1:nmo)
1757 occ_first(ispin)%array(1:nmo) = mo_occupations(1:nmo)
1762 CALL dbcsr_copy(subspace_env%p_matrix_store(ispin)%matrix, rho_ao(ispin)%matrix)
1763 CALL dbcsr_copy(rho_ao(ispin)%matrix, scf_env%p_mix_new(ispin, 1)%matrix)
1766 subspace_env%p_matrix_mix => scf_env%p_mix_new
1768 NULLIFY (matrix_ks, energy, para_env, matrix_s)
1770 matrix_ks=matrix_ks, &
1772 matrix_s=matrix_s, &
1773 para_env=para_env, &
1774 dft_control=dft_control)
1778 CALL mixing_allocate(qs_env, subspace_env%mixing_method, scf_env%p_mix_new, &
1779 scf_env%p_delta, nspin, subspace_env%mixing_store)
1780 IF (dft_control%qs_control%gapw)
THEN
1781 CALL get_qs_env(qs_env=qs_env, rho_atom_set=rho_atom)
1782 CALL mixing_init(subspace_env%mixing_method, rho, subspace_env%mixing_store, &
1783 para_env, rho_atom=rho_atom)
1784 ELSE IF (dft_control%qs_control%dftb .OR. dft_control%qs_control%xtb)
THEN
1786 ELSE IF (dft_control%qs_control%semi_empirical)
THEN
1787 cpabort(
'SE Code not possible')
1789 CALL mixing_init(subspace_env%mixing_method, rho, subspace_env%mixing_store, para_env)
1795 IF (output_unit > 0)
THEN
1796 WRITE (output_unit,
"(/T19,A)")
'<<<<<<<<< SUBSPACE ROTATION <<<<<<<<<<'
1797 WRITE (output_unit,
"(T4,A,T13,A,T21,A,T38,A,T51,A,T65,A/,T4,A)") &
1798 "In-step",
"Time",
"Convergence",
"Band ene.",
"Total ene.",
"Energy diff.", repeat(
"-", 74)
1806 DO iloop = 1, subspace_env%max_iter
1809 ene_old = energy%total
1813 just_energy=.false., print_active=.false.)
1818 DO ispin = 1,
SIZE(matrix_ks)
1822 eigenvalues=mo_eigenvalues, &
1823 occupation_numbers=mo_occupations, &
1827 chc => subspace_env%chc_mat(ispin)
1828 evec => subspace_env%c_vec(ispin)
1829 c0 => subspace_env%c0(ispin)
1833 CALL parallel_gemm(
'T',
'N', nmo, nmo, nao, rone, c0, work, rzero, chc)
1839 CALL parallel_gemm(
'N',
'N', nao, nmo, nmo, rone, c0, evec, rzero, mo_coeff)
1841 IF (.NOT. scf_control%gce%do_gce)
THEN
1843 smear=scf_control%smear)
1846 smear=scf_control%smear, &
1847 gce=scf_control%gce)
1852 subspace_env%p_matrix_mix(ispin, 1)%matrix)
1855 sum_band = sum_band + mo_eigenvalues(i)*mo_occupations(i)
1863 scf_env%mixing_store, rho_ao_kp, para_env, iter_delta, iloop)
1866 subspace_env%p_matrix_mix, delta=iter_delta)
1871 CALL dbcsr_copy(rho_ao(ispin)%matrix, subspace_env%p_matrix_mix(ispin, 1)%matrix)
1877 CALL gspace_mixing(qs_env, scf_env%mixing_method, subspace_env%mixing_store, &
1878 rho, para_env, scf_env%iter_count)
1881 ene_diff = energy%total - ene_old
1882 converged = (abs(ene_diff) < subspace_env%eps_ene .AND. &
1883 iter_delta < subspace_env%eps_adapt*scf_env%iter_delta)
1885 IF (output_unit > 0)
THEN
1886 WRITE (output_unit,
"(T4,I5,T11,F8.3,T18,E14.4,T34,F12.5,T46,F16.8,T62,E14.4)") &
1887 iloop, t2 - t1, iter_delta, sum_band, energy%total, ene_diff
1891 IF (output_unit > 0)
WRITE (output_unit,
"(T10,A,I6,A,/)") &
1892 " Reached convergence in ", iloop,
" iterations "
1898 NULLIFY (subspace_env%p_matrix_mix)
1901 CALL dbcsr_copy(scf_env%p_mix_new(ispin, 1)%matrix, rho_ao(ispin)%matrix)
1902 CALL dbcsr_copy(rho_ao(ispin)%matrix, subspace_env%p_matrix_store(ispin)%matrix)
1904 DEALLOCATE (eval_first(ispin)%array, occ_first(ispin)%array)
1906 DEALLOCATE (eval_first, occ_first)
1908 CALL timestop(handle)
1922 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(IN) :: mos
1924 CHARACTER(LEN=*),
PARAMETER :: routinen =
'diag_subspace_allocate'
1926 INTEGER :: handle, i, ispin, nmo, nspin
1933 CALL timeset(routinen, handle)
1935 NULLIFY (sab_orb, matrix_s)
1936 CALL get_qs_env(qs_env=qs_env, sab_orb=sab_orb, &
1941 IF (.NOT.
ASSOCIATED(subspace_env%p_matrix_store))
THEN
1945 ALLOCATE (subspace_env%p_matrix_store(i)%matrix)
1946 CALL dbcsr_create(matrix=subspace_env%p_matrix_store(i)%matrix, template=matrix_s(1)%matrix, &
1947 name=
"DENSITY_STORE", matrix_type=dbcsr_type_symmetric)
1950 CALL dbcsr_set(subspace_env%p_matrix_store(i)%matrix, 0.0_dp)
1955 ALLOCATE (subspace_env%chc_mat(nspin))
1956 ALLOCATE (subspace_env%c_vec(nspin))
1957 ALLOCATE (subspace_env%c0(nspin))
1960 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff, nmo=nmo)
1961 CALL cp_fm_create(subspace_env%c0(ispin), mo_coeff%matrix_struct)
1962 NULLIFY (fm_struct_tmp)
1964 para_env=mo_coeff%matrix_struct%para_env, &
1965 context=mo_coeff%matrix_struct%context)
1966 CALL cp_fm_create(subspace_env%chc_mat(ispin), fm_struct_tmp,
"chc")
1967 CALL cp_fm_create(subspace_env%c_vec(ispin), fm_struct_tmp,
"vec")
1971 CALL timestop(handle)
1988 scf_section, diis_step)
1991 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(INOUT) :: mos
1995 LOGICAL,
INTENT(INOUT) :: diis_step
1997 INTEGER :: ispin, nspin
1998 LOGICAL :: do_level_shift, use_jacobi
1999 REAL(kind=
dp) :: diis_error
2001 nspin =
SIZE(matrix_ks)
2005 scf_env%fm_copy_plan(ispin), check_plan=.true.)
2007 IF (scf_env%iter_count > 1 .AND. .NOT. scf_env%skip_diis)
THEN
2008 CALL qs_diis_b_step(scf_env%scf_diis_buffer, mos, scf_env%scf_work1, &
2009 scf_env%scf_work2, scf_env%iter_delta, diis_error, diis_step, &
2010 scf_control%eps_diis, scf_control%nmixing, &
2011 scf_section=scf_section)
2016 IF ((scf_env%iter_count > 1) .AND. (scf_env%iter_delta < scf_control%diagonalization%eps_jacobi))
THEN
2019 use_jacobi = .false.
2022 do_level_shift = ((scf_control%level_shift /= 0.0_dp) .AND. &
2023 ((scf_control%density_guess ==
core_guess) .OR. (scf_env%iter_count > 1)))
2025 scf_env%iter_param = diis_error
2026 IF (use_jacobi)
THEN
2027 scf_env%iter_method =
"DIIS/Jacobi"
2029 scf_env%iter_method =
"DIIS/Diag."
2032 IF (scf_env%mixing_method == 1)
THEN
2033 scf_env%iter_param = scf_env%p_mix_alpha
2034 IF (use_jacobi)
THEN
2035 scf_env%iter_method =
"P_Mix/Jacobi"
2037 scf_env%iter_method =
"P_Mix/Diag."
2039 ELSE IF (scf_env%mixing_method > 1)
THEN
2040 scf_env%iter_param = scf_env%mixing_store%alpha
2041 IF (use_jacobi)
THEN
2042 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Jacobi"
2044 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Diag."
2048 scf_env%iter_delta = 0.0_dp
2052 mo_set=mos(ispin), &
2053 work=scf_env%scf_work2, &
2054 do_level_shift=do_level_shift, &
2055 level_shift=scf_control%level_shift, &
2056 use_jacobi=use_jacobi, &
2057 jacobi_threshold=scf_control%diagonalization%jacobi_threshold)
2060 IF (.NOT. scf_control%gce%do_gce)
THEN
2062 smear=scf_control%smear)
2065 smear=scf_control%smear, &
2066 gce=scf_control%gce)
2072 scf_env%p_mix_new(ispin, 1)%matrix)
2091 scf_control, scf_section, diis_step)
2094 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(INOUT) :: mos
2095 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s
2098 LOGICAL,
INTENT(INOUT) :: diis_step
2100 INTEGER :: homo, ispin, nmo, nspin
2101 REAL(kind=
dp) :: diis_error, eps_iter
2102 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues
2105 NULLIFY (eigenvalues)
2107 nspin =
SIZE(matrix_ks)
2111 scf_env%scf_work1(ispin))
2114 IF ((scf_env%iter_count > 1) .AND. (.NOT. scf_env%skip_diis))
THEN
2115 CALL qs_diis_b_step(scf_env%scf_diis_buffer, mos, scf_env%scf_work1, &
2116 scf_env%scf_work2, scf_env%iter_delta, diis_error, diis_step, &
2117 scf_control%eps_diis, scf_control%nmixing, &
2118 s_matrix=matrix_s, &
2119 scf_section=scf_section)
2124 eps_iter = scf_control%diagonalization%eps_iter
2126 scf_env%iter_param = diis_error
2127 scf_env%iter_method =
"DIIS/OTdiag"
2130 matrix_ks(ispin)%matrix, keep_sparsity=.true.)
2132 eps_iter = max(eps_iter, scf_control%diagonalization%eps_adapt*diis_error)
2134 IF (scf_env%mixing_method == 1)
THEN
2135 scf_env%iter_param = scf_env%p_mix_alpha
2136 scf_env%iter_method =
"P_Mix/OTdiag."
2137 ELSE IF (scf_env%mixing_method > 1)
THEN
2138 scf_env%iter_param = scf_env%mixing_store%alpha
2139 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/OTdiag."
2143 scf_env%iter_delta = 0.0_dp
2147 mo_coeff=mo_coeff, &
2148 eigenvalues=eigenvalues, &
2152 matrix_s=matrix_s(1)%matrix, &
2153 matrix_c_fm=mo_coeff, &
2155 min(ispin,
SIZE(scf_env%ot_preconditioner)))%preconditioner, &
2156 eps_gradient=eps_iter, &
2157 iter_max=scf_control%diagonalization%max_iter, &
2159 ot_settings=scf_control%diagonalization%ot_settings)
2161 evals_arg=eigenvalues, &
2164 mos(ispin)%mo_coeff_b)
2169 smear=scf_control%smear)
2174 scf_env%p_mix_new(ispin, 1)%matrix)
2190 SUBROUTINE do_ot_diag_kp(matrix_ks, matrix_s, matrix_t, kpoints, scf_env, scf_control, &
2191 diis_step, added_mos_auto_grow)
2192 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks, matrix_s, matrix_t
2196 LOGICAL,
INTENT(INOUT) :: diis_step
2197 LOGICAL,
INTENT(OUT) :: added_mos_auto_grow
2199 INTEGER :: ikp, ispin, ks_spin, nspin
2201 REAL(kind=
dp) :: eps_iter
2202 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues
2205 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: fmwork
2207 TYPE(
dbcsr_type),
POINTER :: matrix_h_im, matrix_h_re, matrix_s_im, &
2208 matrix_s_re, matrix_t_im, matrix_t_re
2214 NULLIFY (coeff_re, eigenvalues, fmwork, kp, matrix_h_im, matrix_h_re, &
2215 matrix_s_im, matrix_s_re, matrix_t_im, matrix_t_re, sab_nl)
2216 added_mos_auto_grow = .false.
2218 eps_iter = scf_control%diagonalization%eps_iter
2219 nspin =
SIZE(matrix_ks, 1)
2220 store_kinetic = scf_control%diagonalization%ot_settings%preconditioner_type == &
2222 IF (store_kinetic)
THEN
2223 cpassert(
ASSOCIATED(matrix_t))
2226 cpassert(
ASSOCIATED(sab_nl))
2230 IF (scf_env%iter_count <= 1)
THEN
2235 IF (store_kinetic)
THEN
2242 scf_env%iter_delta = 0.0_dp
2243 DO ikp = 1,
SIZE(kpoints%kp_env)
2244 kp => kpoints%kp_env(ikp)%kpoint_env
2245 cpassert(
ASSOCIATED(kp%ot_hmat) .AND.
ASSOCIATED(kp%ot_smat))
2246 IF (
SIZE(kp%ot_smat) >= 2)
THEN
2248 kp%ot_smat(1), kp%ot_smat(2), &
2249 matrix_s_re, matrix_s_im)
2252 kp%ot_smat(1), kp%ot_smat(1), &
2253 matrix_s_re, matrix_s_im)
2256 IF (store_kinetic)
THEN
2257 cpassert(
ASSOCIATED(kp%ot_tmat))
2258 IF (
SIZE(kp%ot_tmat) >= 2)
THEN
2260 kp%ot_tmat(1), kp%ot_tmat(2), &
2261 matrix_t_re, matrix_t_im)
2264 kp%ot_tmat(1), kp%ot_tmat(1), &
2265 matrix_t_re, matrix_t_im)
2270 ks_spin = min(ispin,
SIZE(kp%ot_hmat, 2))
2271 IF (
SIZE(kp%ot_hmat, 1) >= 2)
THEN
2273 kp%ot_hmat(1, ks_spin), kp%ot_hmat(2, ks_spin), &
2274 matrix_h_re, matrix_h_im)
2277 kp%ot_hmat(1, ks_spin), kp%ot_hmat(1, ks_spin), &
2278 matrix_h_re, matrix_h_im)
2281 CALL get_mo_set(kp%mos(ispin), eigenvalues=eigenvalues)
2283 CALL get_mo_set(kp%mos(ispin), mo_coeff=coeff_re)
2284 CALL cp_fm_create(coeff_im_work, coeff_re%matrix_struct, &
2285 name=
'real k-point OT imaginary work')
2289 matrix_s=matrix_s_re, matrix_s_im=matrix_s_im, &
2290 matrix_c_cfm=cmo_work, &
2291 eps_gradient=eps_iter, &
2292 iter_max=scf_control%diagonalization%max_iter, &
2293 eigenvalues=eigenvalues, silent=.true., &
2294 ot_settings=scf_control%diagonalization%ot_settings, &
2295 matrix_t=matrix_t_re, matrix_t_im=matrix_t_im, &
2296 mo_set=kp%mos(ispin))
2302 matrix_s=matrix_s_re, matrix_s_im=matrix_s_im, &
2303 matrix_c_cfm=kp%mos(ispin)%cmo_coeff, &
2304 eps_gradient=eps_iter, &
2305 iter_max=scf_control%diagonalization%max_iter, &
2306 eigenvalues=eigenvalues, silent=.true., &
2307 ot_settings=scf_control%diagonalization%ot_settings, &
2308 matrix_t=matrix_t_re, matrix_t_im=matrix_t_im, &
2309 mo_set=kp%mos(ispin))
2320 fmwork => scf_env%scf_work1
2321 CALL kp_diag_exit_chain(kpoints, scf_env, scf_control, matrix_s, sab_nl, fmwork, added_mos_auto_grow)
2322 IF (added_mos_auto_grow)
RETURN
2323 IF (scf_env%mixing_method == 0)
THEN
2324 scf_env%iter_method =
'NoMix/OTdiag.'
2325 ELSE IF (scf_env%mixing_method == 1)
THEN
2326 scf_env%iter_param = scf_env%p_mix_alpha
2327 scf_env%iter_method =
'P_Mix/OTdiag.'
2329 scf_env%iter_param = scf_env%mixing_store%alpha
2330 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
'/OTdiag.'
2352 scf_control, scf_section, diis_step, &
2360 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(IN) :: mos
2361 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s
2364 LOGICAL,
INTENT(INOUT) :: diis_step
2365 LOGICAL,
INTENT(IN) :: orthogonal_basis
2367 CHARACTER(LEN=*),
PARAMETER :: routinen =
'do_roks_diag'
2369 INTEGER :: handle, homoa, homob, imo, nalpha, nao, &
2371 REAL(kind=
dp) :: diis_error, level_shift_loc
2372 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eiga, eigb, occa, occb
2373 TYPE(
cp_fm_type),
POINTER :: ksa, ksb, mo2ao, moa, mob, ortho, work
2377 CALL timeset(routinen, handle)
2380 ortho => scf_env%ortho_m1
2382 ortho => scf_env%ortho
2384 work => scf_env%scf_work2
2386 ksa => scf_env%scf_work1(1)
2387 ksb => scf_env%scf_work1(2)
2389 CALL copy_dbcsr_to_fm(matrix_ks(1)%matrix, ksa, scf_env%fm_copy_plan(1), check_plan=.true.)
2390 CALL copy_dbcsr_to_fm(matrix_ks(2)%matrix, ksb, scf_env%fm_copy_plan(2), check_plan=.true.)
2400 occupation_numbers=occa, &
2407 occupation_numbers=occb, &
2412 IF ((scf_control%level_shift /= 0.0_dp) .AND. &
2413 ((scf_control%density_guess ==
core_guess) .OR. &
2415 (scf_env%iter_count > 1)))
THEN
2416 level_shift_loc = scf_control%level_shift
2418 level_shift_loc = 0.0_dp
2421 IF ((scf_env%iter_count > 1) .OR. &
2422 (scf_control%density_guess ==
core_guess) .OR. &
2428 CALL cp_fm_symm(
"L",
"U", nao, nao, 1.0_dp, ksa, moa, 0.0_dp, work)
2429 CALL parallel_gemm(
"T",
"N", nao, nao, nao, 1.0_dp, moa, work, 0.0_dp, ksa)
2431 CALL cp_fm_symm(
"L",
"U", nao, nao, 1.0_dp, ksb, moa, 0.0_dp, work)
2432 CALL parallel_gemm(
"T",
"N", nao, nao, nao, 1.0_dp, moa, work, 0.0_dp, ksb)
2443 cpabort(
"Unknown ROKS scheme requested")
2449 IF (orthogonal_basis)
THEN
2462 CALL parallel_gemm(
"N",
"T", nao, nao, nao, 1.0_dp, ksa, mo2ao, 0.0_dp, work)
2463 CALL parallel_gemm(
"N",
"N", nao, nao, nao, 1.0_dp, mo2ao, work, 0.0_dp, ksa)
2477 IF (scf_env%iter_count > 1)
THEN
2478 IF (orthogonal_basis)
THEN
2481 kc=scf_env%scf_work1, &
2483 delta=scf_env%iter_delta, &
2484 error_max=diis_error, &
2485 diis_step=diis_step, &
2486 eps_diis=scf_control%eps_diis, &
2487 scf_section=scf_section, &
2489 cpassert(scf_env%iter_delta == scf_env%iter_delta)
2493 kc=scf_env%scf_work1, &
2495 delta=scf_env%iter_delta, &
2496 error_max=diis_error, &
2497 diis_step=diis_step, &
2498 eps_diis=scf_control%eps_diis, &
2499 scf_section=scf_section, &
2500 s_matrix=matrix_s, &
2506 scf_env%iter_param = diis_error
2507 scf_env%iter_method =
"DIIS/Diag."
2509 IF (scf_env%mixing_method == 1)
THEN
2510 scf_env%iter_param = scf_env%p_mix_alpha
2511 scf_env%iter_method =
"P_Mix/Diag."
2512 ELSE IF (scf_env%mixing_method > 1)
THEN
2513 scf_env%iter_param = scf_env%mixing_store%alpha
2514 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Diag."
2518 scf_env%iter_delta = 0.0_dp
2520 IF (level_shift_loc /= 0.0_dp)
THEN
2525 CALL cp_fm_symm(
"L",
"U", nao, nao, 1.0_dp, ksa, moa, 0.0_dp, work)
2526 CALL parallel_gemm(
"T",
"N", nao, nao, nao, 1.0_dp, moa, work, 0.0_dp, ksa)
2530 DO imo = homob + 1, homoa
2533 DO imo = homoa + 1, nmo
2537 ELSE IF (.NOT. orthogonal_basis)
THEN
2540 SELECT CASE (scf_env%cholesky_method)
2546 "SOLVE", pos=
"RIGHT")
2548 "SOLVE", pos=
"LEFT", transa=
"T")
2552 "MULTIPLY", pos=
"RIGHT")
2554 "MULTIPLY", pos=
"LEFT", transa=
"T")
2556 CALL cp_fm_symm(
"L",
"U", nao, nao, 1.0_dp, ksa, ortho, 0.0_dp, work)
2557 CALL parallel_gemm(
"N",
"N", nao, nao, nao, 1.0_dp, ortho, work, 0.0_dp, ksa)
2568 IF (level_shift_loc /= 0.0_dp)
THEN
2571 CALL parallel_gemm(
"N",
"N", nao, nmo, nao, 1.0_dp, ortho, work, 0.0_dp, moa)
2573 IF (orthogonal_basis)
THEN
2576 SELECT CASE (scf_env%cholesky_method)
2582 CALL parallel_gemm(
"N",
"N", nao, nmo, nao, 1.0_dp, ortho, work, 0.0_dp, moa)
2589 IF (level_shift_loc /= 0.0_dp)
THEN
2590 DO imo = homob + 1, homoa
2591 eiga(imo) = eiga(imo) - 0.5_dp*level_shift_loc
2593 DO imo = homoa + 1, nmo
2594 eiga(imo) = eiga(imo) - level_shift_loc
2609 CALL timestop(handle)
2627 scf_control, scf_section, check_moconv_only)
2630 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(INOUT) :: mos
2634 LOGICAL,
INTENT(IN),
OPTIONAL :: check_moconv_only
2636 CHARACTER(LEN=*),
PARAMETER :: routinen =
'do_block_krylov_diag'
2637 REAL(kind=
dp),
PARAMETER :: rone = 1.0_dp, rzero = 0.0_dp
2639 INTEGER :: handle, homo, ispin, iter, nao, nmo, &
2641 LOGICAL :: converged, my_check_moconv_only
2642 REAL(
dp) :: eps_iter, t1, t2
2643 REAL(kind=
dp),
DIMENSION(:),
POINTER :: mo_eigenvalues
2644 TYPE(
cp_fm_type),
POINTER :: c0, c1, chc, evec, ks, mo_coeff, ortho, &
2649 CALL timeset(routinen, handle)
2652 extension=
".scfLog")
2654 my_check_moconv_only = .false.
2655 IF (
PRESENT(check_moconv_only)) my_check_moconv_only = check_moconv_only
2657 NULLIFY (mo_coeff, ortho, work, ks)
2658 NULLIFY (mo_eigenvalues)
2662 ortho => scf_env%ortho_m1
2664 ortho => scf_env%ortho
2666 work => scf_env%scf_work2
2668 DO ispin = 1,
SIZE(matrix_ks)
2670 scf_env%scf_work1(ispin), scf_env%fm_copy_plan(ispin), check_plan=.true.)
2673 IF (scf_env%mixing_method == 1)
THEN
2674 scf_env%iter_param = scf_env%p_mix_alpha
2675 scf_env%iter_method =
"P_Mix/Lanczos"
2677 scf_env%iter_param = scf_env%mixing_store%alpha
2678 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Lanc."
2681 DO ispin = 1,
SIZE(matrix_ks)
2683 ks => scf_env%scf_work1(ispin)
2690 eigenvalues=mo_eigenvalues, &
2694 c0 => scf_env%krylov_space%mo_conv(ispin)
2695 c1 => scf_env%krylov_space%mo_refine(ispin)
2696 SELECT CASE (scf_env%cholesky_method)
2703 "SOLVE", pos=
"RIGHT")
2705 "SOLVE", pos=
"LEFT", transa=
"T")
2709 "MULTIPLY", pos=
"RIGHT")
2711 "MULTIPLY", pos=
"LEFT", transa=
"T")
2715 scf_env%krylov_space%nmo_nc = nmo
2716 scf_env%krylov_space%nmo_conv = 0
2719 IF (output_unit > 0)
THEN
2720 WRITE (output_unit,
"(/T15,A)")
'<<<<<<<<< LANCZOS REFINEMENT <<<<<<<<<<'
2721 WRITE (output_unit,
"(T8,A,T15,A,T23,A,T36,A,T49,A,T60,A,/,T8,A)") &
2722 " Spin ",
" Cycle ", &
2723 " conv. MOS ",
" B2MAX ",
" B2MIN ",
" Time", repeat(
"-", 60)
2725 eps_iter = kp_adaptive_eps_iter(scf_env%krylov_settings%eps_conv, scf_env%krylov_settings%eps_adapt, &
2726 scf_env%iter_delta, 1.0_dp, huge(1.0_dp))
2730 IF (my_check_moconv_only)
THEN
2733 nao, eps_iter, ispin, check_moconv_only=my_check_moconv_only)
2735 IF (output_unit > 0)
THEN
2736 WRITE (output_unit,
'(T8,I3,T16,I5,T24,I6,T33,E12.4,2x,E12.4,T60,F8.3)') &
2737 ispin, iter, scf_env%krylov_space%nmo_conv, &
2738 scf_env%krylov_space%max_res_norm, scf_env%krylov_space%min_res_norm, t2 - t1
2744 DO iter = 1, scf_env%krylov_settings%max_iter
2746 nao, eps_iter, ispin)
2748 IF (output_unit > 0)
THEN
2749 WRITE (output_unit,
'(T8,I3,T16,I5,T24,I6,T33,E12.4,2x,E12.4,T60,F8.3)') &
2750 ispin, iter, scf_env%krylov_space%nmo_conv, &
2751 scf_env%krylov_space%max_res_norm, scf_env%krylov_space%min_res_norm, t2 - t1
2754 IF (scf_env%krylov_space%max_res_norm < eps_iter)
THEN
2756 IF (output_unit > 0)
WRITE (output_unit, *) &
2757 " Reached convergence in ", iter,
" iterations "
2762 IF (.NOT. converged .AND. output_unit > 0)
THEN
2763 WRITE (output_unit,
"(T4, A)")
" WARNING Lanczos refinement could "// &
2764 "not converge all the mos:"
2765 WRITE (output_unit,
"(T40,A,T70,I10)")
" number of not converged mos ", &
2766 scf_env%krylov_space%nmo_nc
2767 WRITE (output_unit,
"(T40,A,T70,E10.2)")
" max norm of the residual ", &
2768 scf_env%krylov_space%max_res_norm
2776 chc => scf_env%krylov_space%chc_mat(ispin)
2777 evec => scf_env%krylov_space%c_vec(ispin)
2778 CALL parallel_gemm(
'N',
'N', nao, nmo, nao, rone, ks, c0, rzero, work)
2779 CALL parallel_gemm(
'T',
'N', nmo, nmo, nao, rone, c0, work, rzero, chc)
2783 CALL parallel_gemm(
'N',
'N', nao, nmo, nmo, rone, c0, evec, rzero, c1)
2784 c0 => scf_env%krylov_space%mo_refine(ispin)
2793 IF (.NOT. scf_control%gce%do_gce)
THEN
2795 smear=scf_control%smear)
2798 smear=scf_control%smear, &
2799 gce=scf_control%gce)
2804 scf_env%p_mix_new(ispin, 1)%matrix)
2808 IF (output_unit > 0)
THEN
2809 WRITE (output_unit,
"(T15,A/)")
'<<<<<<<<< END LANCZOS REFINEMENT <<<<<<<<<<'
2815 CALL timestop(handle)
2835 scf_control, scf_section, check_moconv_only)
2839 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(INOUT) :: mos
2840 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s
2843 LOGICAL,
INTENT(IN),
OPTIONAL :: check_moconv_only
2845 CHARACTER(LEN=*),
PARAMETER :: routinen =
'do_block_davidson_diag'
2847 INTEGER :: handle, ispin, nspins, output_unit
2848 LOGICAL :: do_prec, my_check_moconv_only
2852 CALL timeset(routinen, handle)
2855 extension=
".scfLog")
2857 IF (output_unit > 0)
THEN
2858 WRITE (output_unit,
"(/T15,A)")
'<<<<<<<<< DAVIDSON ITERATIONS <<<<<<<<<<'
2861 IF (scf_env%mixing_method == 1)
THEN
2862 scf_env%iter_param = scf_env%p_mix_alpha
2863 scf_env%iter_method =
"P_Mix/Dav."
2865 scf_env%iter_param = scf_env%mixing_store%alpha
2866 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Dav."
2869 my_check_moconv_only = .false.
2870 IF (
PRESENT(check_moconv_only)) my_check_moconv_only = check_moconv_only
2872 IF (scf_env%block_davidson_env(1)%prec_type /= 0 .AND. &
2873 scf_env%iter_count >= scf_env%block_davidson_env(1)%first_prec)
THEN
2877 nspins =
SIZE(matrix_ks)
2879 IF (do_prec .AND. (scf_env%iter_count == scf_env%block_davidson_env(1)%first_prec .OR. &
2880 modulo(scf_env%iter_count, scf_env%block_davidson_env(1)%niter_new_prec) == 0))
THEN
2882 prec_type=scf_env%block_davidson_env(1)%prec_type, nspins=nspins)
2884 scf_env%block_davidson_env(1)%prec_type, &
2885 scf_env%block_davidson_env(1)%solver_type, &
2886 scf_env%block_davidson_env(1)%energy_gap, nspins, &
2887 convert_to_dbcsr=scf_env%block_davidson_env(1)%use_sparse_mos, &
2891 DO ispin = 1, nspins
2892 IF (scf_env%block_davidson_env(ispin)%use_sparse_mos)
THEN
2893 IF (.NOT. do_prec)
THEN
2895 matrix_ks(ispin)%matrix, matrix_s(1)%matrix, output_unit)
2898 matrix_ks(ispin)%matrix, matrix_s(1)%matrix, output_unit, &
2899 scf_env%ot_preconditioner(ispin)%preconditioner)
2903 IF (.NOT. do_prec)
THEN
2905 matrix_ks(ispin)%matrix, matrix_s(1)%matrix, output_unit)
2908 matrix_ks(ispin)%matrix, matrix_s(1)%matrix, output_unit, &
2909 scf_env%ot_preconditioner(ispin)%preconditioner)
2914 IF (.NOT. scf_control%gce%do_gce)
THEN
2916 smear=scf_control%smear)
2919 smear=scf_control%smear, &
2920 gce=scf_control%gce)
2923 DO ispin = 1, nspins
2926 scf_env%p_mix_new(ispin, 1)%matrix)
2929 IF (output_unit > 0)
THEN
2930 WRITE (output_unit,
"(T15,A/)")
'<<<<<<<<< END DAVIDSON ITERATION <<<<<<<<<<'
2936 CALL timestop(handle)
2954 scf_control, added_mos_auto_grow)
2958 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks_kp, matrix_s_kp
2961 LOGICAL,
INTENT(OUT),
OPTIONAL :: added_mos_auto_grow
2963 CHARACTER(LEN=*),
PARAMETER :: routinen =
'do_block_davidson_diag_kp'
2964 REAL(kind=
dp),
PARAMETER :: empty_factor = 5.0_dp, &
2965 eps_iter_cap = 1.0e-4_dp
2967 INTEGER :: channel, first_prec, handle, ispin, iw, &
2968 kplocal, kpmax, local_kpoint, &
2969 nchannels, nspin, output_unit
2970 INTEGER,
DIMENSION(2) :: kp_range
2971 INTEGER,
DIMENSION(:, :),
POINTER :: kp_dist
2972 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
2974 REAL(kind=
dp) :: eps_iter, eps_iter_empty
2975 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: xkp
2978 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: fmwork
2998 CALL timeset(routinen, handle)
3002 extension=
".scfLog")
3003 IF (output_unit > 0)
THEN
3004 WRITE (output_unit,
"(/T15,A)")
'<<<<<<<<< DAVIDSON ITERATIONS <<<<<<<<<<'
3007 CALL get_kpoint_info(kpoints, kp_range=kp_range, kp_dist=kp_dist, xkp=xkp, &
3009 cell_to_index=cell_to_index)
3011 cpabort(
'Davidson Kp requires complex K-point MOS')
3013 para_env => kpoints%blacs_env_all%para_env
3014 kplocal = kp_range(2) - kp_range(1) + 1
3015 kpmax = maxval(kp_dist(2, :) - kp_dist(1, :) + 1)
3016 nspin =
SIZE(matrix_ks_kp, 1)
3017 nchannels = kplocal*nspin
3019 IF (scf_env%mixing_method == 1)
THEN
3020 scf_env%iter_param = scf_env%p_mix_alpha
3021 scf_env%iter_method =
"P_Mix/Dav."
3022 ELSE IF (scf_env%mixing_method > 1)
THEN
3023 scf_env%iter_param = scf_env%mixing_store%alpha
3024 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Dav."
3034 first_prec = max(scf_env%block_davidson_env(1)%first_prec, 2)
3036 IF (scf_env%block_davidson_env(1)%prec_type /=
ot_precond_none .AND. &
3037 scf_env%iter_count >= first_prec)
THEN
3054 eps_iter = scf_env%block_davidson_env(1)%eps_iter
3055 eps_iter_empty = eps_iter
3056 IF (scf_control%diagonalization%eps_adapt > 0.0_dp .AND. scf_env%iter_delta > 0.0_dp)
THEN
3066 IF (scf_env%iter_delta < scf_env%block_davidson_env(1)%eps_iter_used)
THEN
3067 scf_env%block_davidson_env(1)%eps_iter_prev = &
3068 min(scf_env%block_davidson_env(1)%eps_iter_prev, &
3069 max(scf_env%block_davidson_env(1)%eps_iter, &
3070 0.1_dp*scf_env%block_davidson_env(1)%eps_iter_used))
3076 eps_iter = min(max(eps_iter, min(scf_control%diagonalization%eps_adapt*scf_env%iter_delta/ &
3077 scf_env%block_davidson_env(1)%noise_scale, &
3078 eps_iter_cap)), scf_env%block_davidson_env(1)%eps_iter_prev)
3079 eps_iter_empty = empty_factor*eps_iter
3082 scf_env%block_davidson_env(1)%eps_iter_prev = eps_iter
3083 scf_env%block_davidson_env(1)%eps_iter_used = eps_iter
3087 IF (scf_control%diagonalization%eps_adapt > 0.0_dp .AND. para_env%is_source() .AND. &
3091 WRITE (unit=iw, fmt=
"(T3,'EPS_ADAPT step',I5,' delta=',ES9.2,' eps_occ=',ES9.2,' eps_empty=',ES9.2)") &
3092 scf_env%iter_count, scf_env%iter_delta, eps_iter, eps_iter_empty
3098 CALL kp_diag_setup(qs_env, kpoints, nspin, matrix_ks_kp, matrix_s_kp, fmwork, op_ctx, &
3099 matrix_struct, .true.)
3102 CALL cp_cfm_create(csmat_base, matrix_struct, name=
"dav_sk_base")
3104 IF (do_prec .AND. (scf_env%iter_count == first_prec .OR. &
3105 modulo(scf_env%iter_count, &
3106 scf_env%block_davidson_env(1)%niter_new_prec) == 0))
THEN
3107 CALL davidson_kp_prepare_preconditioners( &
3108 qs_env, scf_env, matrix_ks_kp, matrix_s_kp, kpoints, op_ctx)
3111 DO local_kpoint = 1, kpmax
3121 IF (local_kpoint > kplocal) cycle
3122 kp => kpoints%kp_env(local_kpoint)%kpoint_env
3125 IF (scf_env%iter_count == 1 .AND. .NOT. kp%mos_prefilled)
THEN
3129 CALL cold_start_mo_init(kp, ispin, cksmat, csmat)
3131 channel = (local_kpoint - 1)*nspin + ispin
3134 kp%mos(ispin), cksmat, csmat, output_unit, &
3135 eps_iter, eps_iter_empty, &
3136 scf_env%ot_preconditioner(channel)%preconditioner)
3139 kp%mos(ispin), cksmat, csmat, output_unit, &
3140 eps_iter, eps_iter_empty)
3148 CALL kp_diag_exit_chain(kpoints, scf_env, scf_control, matrix_s_kp, sab_nl, fmwork, my_grow)
3149 IF (my_grow .AND.
PRESENT(added_mos_auto_grow)) added_mos_auto_grow = .true.
3154 CALL kp_diag_finalize(qs_env, fmwork, op_ctx)
3156 IF (output_unit > 0)
THEN
3157 WRITE (output_unit,
"(T15,A/)")
'<<<<<<<<< END DAVIDSON ITERATION <<<<<<<<<<'
3162 CALL timestop(handle)
3183 scf_control, check_moconv_only, added_mos_auto_grow)
3187 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks_kp, matrix_s_kp
3190 LOGICAL,
INTENT(IN),
OPTIONAL :: check_moconv_only
3191 LOGICAL,
INTENT(OUT),
OPTIONAL :: added_mos_auto_grow
3193 CHARACTER(LEN=*),
PARAMETER :: routinen =
'do_block_krylov_diag_kp'
3194 REAL(kind=
dp),
PARAMETER :: empty_factor = 5.0_dp, &
3195 eps_iter_cap = 1.0e-4_dp, &
3196 noise_scale = 100.0_dp
3198 INTEGER :: handle, ik, ikp, ispin, kplocal, kpmax, &
3199 local_kpoint, max_iter, nentry, nspin, &
3201 INTEGER,
DIMENSION(2) :: kp_range
3202 INTEGER,
DIMENSION(:, :),
POINTER :: kp_dist
3203 LOGICAL :: my_check_moconv_only, my_grow, &
3204 prepared_ops, use_local_kpoints, &
3206 REAL(kind=
dp) :: eps_iter, eps_iter_empty
3208 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: fmwork
3210 TYPE(kp_diag_workspace_type),
ALLOCATABLE,
TARGET :: workspace(:)
3221 CALL timeset(routinen, handle)
3223 my_check_moconv_only = .false.
3224 IF (
PRESENT(check_moconv_only)) my_check_moconv_only = check_moconv_only
3228 extension=
".scfLog")
3233 cpabort(
'k-point Lanczos refinement requires complex k-point MOS')
3235 kplocal = kp_range(2) - kp_range(1) + 1
3238 kpmax = maxval(kp_dist(2, :) - kp_dist(1, :) + 1)
3239 nspin =
SIZE(matrix_ks_kp, 1)
3241 IF (scf_env%mixing_method == 1)
THEN
3242 scf_env%iter_param = scf_env%p_mix_alpha
3243 scf_env%iter_method =
"P_Mix/Lanczos"
3245 scf_env%iter_param = scf_env%mixing_store%alpha
3246 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Lanc."
3254 eps_iter = kp_adaptive_eps_iter(scf_env%krylov_settings%eps_conv, scf_env%krylov_settings%eps_adapt, &
3255 scf_env%iter_delta, noise_scale, eps_iter_cap)
3259 eps_iter_empty = eps_iter
3260 IF (scf_env%krylov_settings%eps_adapt > 0.0_dp) eps_iter_empty = empty_factor*eps_iter
3261 max_iter = scf_env%krylov_settings%max_iter
3266 use_local_kpoints = kpoints%para_env_kp%num_pe == 1
3268 IF (my_check_moconv_only) use_local_kpoints = .false.
3272 CALL kp_diag_setup(qs_env, kpoints, nspin, matrix_ks_kp, matrix_s_kp, fmwork, op_ctx, &
3273 matrix_struct, use_local_kpoints, prepared_ops)
3274 use_local_kpoints = use_local_kpoints .AND. prepared_ops
3278 kp => kpoints%kp_env(1)%kpoint_env
3279 mo_struct => kp%mos(1)%cmo_coeff%matrix_struct
3280 CALL kp_diag_workspaces_create(workspace, 1, matrix_struct, mo_struct, nentry, &
3281 use_local_kpoints, scf_env%cholesky_method ==
cholesky_off, &
3282 lanczos=.true., nkrylov=scf_env%krylov_settings%nkrylov, &
3283 nblock=scf_env%krylov_settings%nblock)
3285 IF (output_unit > 0 .AND. .NOT. my_check_moconv_only)
THEN
3286 WRITE (output_unit,
"(/T15,A)")
'<<<<<<<<< LANCZOS REFINEMENT <<<<<<<<<<'
3287 WRITE (output_unit,
"(T8,A,T15,A,T23,A,T36,A,T49,A,T60,A,/,T8,A)") &
3288 " Spin ",
" Cycle ", &
3289 " conv. MOS ",
" B2MAX ",
" B2MIN ",
" Time", repeat(
"-", 60)
3292 IF (use_local_kpoints)
THEN
3297 kp => kpoints%kp_env(ikp)%kpoint_env
3298 ik = kp_range(1) + ikp - 1
3300 workspace(1)%csmat_base)
3303 workspace(1)%cksmat)
3304 IF (scf_env%iter_count == 1 .AND. .NOT. kp%mos_prefilled)
THEN
3307 CALL cold_start_mo_init(kp, ispin, workspace(1)%cksmat, workspace(1)%csmat_base)
3310 CALL lanczos_refine_channel(kp, ispin, scf_env, my_check_moconv_only, eps_iter, &
3311 eps_iter_empty, max_iter, workspace(1), output_unit, .true.)
3316 DO local_kpoint = 1, kpmax
3328 cmat=workspace(1)%cksmat, matrix_row=ispin)
3329 IF (local_kpoint > kplocal) cycle
3330 kp => kpoints%kp_env(local_kpoint)%kpoint_env
3332 IF (scf_env%iter_count == 1 .AND. .NOT. kp%mos_prefilled)
THEN
3335 CALL cold_start_mo_init(kp, ispin, workspace(1)%cksmat, workspace(1)%csmat_base)
3339 CALL lanczos_refine_channel(kp, ispin, scf_env, my_check_moconv_only, eps_iter, &
3340 eps_iter_empty, max_iter, workspace(1), output_unit, .true.)
3349 IF (.NOT. my_check_moconv_only)
THEN
3350 CALL kp_diag_exit_chain(kpoints, scf_env, scf_control, matrix_s_kp, sab_nl, fmwork, my_grow)
3351 IF (my_grow .AND.
PRESENT(added_mos_auto_grow)) added_mos_auto_grow = .true.
3354 CALL kp_diag_workspaces_release(workspace)
3355 CALL kp_diag_finalize(qs_env, fmwork, op_ctx)
3357 IF (output_unit > 0 .AND. .NOT. my_check_moconv_only)
THEN
3358 WRITE (output_unit,
"(T15,A/)")
'<<<<<<<<< END LANCZOS REFINEMENT <<<<<<<<<<'
3363 CALL timestop(handle)
3394 SUBROUTINE lanczos_refine_channel(kp, ispin, scf_env, check_moconv_only, eps_iter, eps_iter_empty, &
3395 max_iter, work, output_unit, print_row)
3397 INTEGER,
INTENT(IN) :: ispin
3399 LOGICAL,
INTENT(IN) :: check_moconv_only
3400 REAL(kind=
dp),
INTENT(IN) :: eps_iter, eps_iter_empty
3401 INTEGER,
INTENT(IN) :: max_iter
3402 TYPE(kp_diag_workspace_type),
INTENT(INOUT) :: work
3403 INTEGER,
INTENT(IN) :: output_unit
3404 LOGICAL,
INTENT(IN) :: print_row
3406 CHARACTER(LEN=*),
PARAMETER :: routinen =
'lanczos_refine_channel'
3408 INTEGER :: handle, iter, nmo, nmo_conv, nmo_nc
3409 LOGICAL :: any_refined, converged, need_suffix_rr, &
3410 next_need_suffix_rr, step_refined
3411 REAL(kind=
dp) :: max_res, min_res, t1, t2
3412 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: eps_col
3413 REAL(kind=
dp),
DIMENSION(:),
POINTER :: mo_eigenvalues, occupation
3416 CALL timeset(routinen, handle)
3418 CALL get_mo_set(mo_set=kp%mos(ispin), nmo=nmo, &
3419 eigenvalues=mo_eigenvalues, occupation_numbers=occupation, &
3420 cmo_coeff=cmo_coeff)
3429 cmplx(0.5_dp, 0.0_dp, kind=
dp), work%cwork)
3445 ALLOCATE (eps_col(nmo))
3446 CALL kp_eps_col_by_occupation(occupation, eps_iter, eps_iter_empty, eps_col)
3449 any_refined = .false.
3450 need_suffix_rr = .false.
3454 work%lan_ws, max_res, min_res, nmo_conv, nmo_nc, &
3455 check_moconv_only=check_moconv_only)
3456 IF (check_moconv_only)
THEN
3457 DEALLOCATE (eps_col)
3458 IF (print_row .AND. output_unit > 0)
THEN
3459 WRITE (output_unit,
'(T8,I3,T16,I5,T24,I6,T33,E12.4,2x,E12.4)') &
3460 ispin, 0, nmo_conv, max_res, min_res
3462 CALL timestop(handle)
3466 IF (nmo_nc == 0)
THEN
3468 IF (print_row .AND. output_unit > 0 .AND. max_iter >= 1)
THEN
3469 WRITE (output_unit,
'(T8,I3,T16,I5,T24,I6,T33,E12.4,2x,E12.4,T60,F8.3)') &
3470 ispin, 1, nmo_conv, max_res, min_res, t2 - t1
3474 DO iter = 1, max_iter
3477 scf_env%krylov_settings%nkrylov, scf_env%krylov_settings%nblock, &
3478 iter == 1, need_suffix_rr, work%lan_ws, &
3479 max_res, min_res, nmo_conv, nmo_nc, step_refined, &
3480 next_need_suffix_rr)
3481 need_suffix_rr = next_need_suffix_rr
3482 any_refined = any_refined .OR. step_refined
3484 IF (print_row .AND. output_unit > 0)
THEN
3485 WRITE (output_unit,
'(T8,I3,T16,I5,T24,I6,T33,E12.4,2x,E12.4,T60,F8.3)') &
3486 ispin, iter, nmo_conv, max_res, min_res, t2 - t1
3488 IF (nmo_nc == 0)
THEN
3494 DEALLOCATE (eps_col)
3496 IF (any_refined)
THEN
3499 IF (.NOT. converged .AND. print_row .AND. output_unit > 0)
THEN
3500 WRITE (output_unit,
"(T4, A)")
" WARNING Lanczos refinement could "// &
3501 "not converge all the mos:"
3502 WRITE (output_unit,
"(T40,A,T70,I10)")
" number of not converged mos ", nmo_nc
3503 WRITE (output_unit,
"(T40,A,T70,E10.2)")
" max norm of the residual ", max_res
3510 CALL timestop(handle)
3511 END SUBROUTINE lanczos_refine_channel
3522 SUBROUTINE cold_start_mo_init(kp, ispin, cksmat, csmat)
3525 INTEGER,
INTENT(IN) :: ispin
3528 CHARACTER(LEN=*),
PARAMETER :: routinen =
'cold_start_mo_init'
3531 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues
3534 CALL timeset(routinen, handle)
3536 CALL get_mo_set(kp%mos(ispin), eigenvalues=eigenvalues)
3539 CALL cp_cfm_create(chwork, cksmat%matrix_struct, name=
"kp_cold_h")
3540 CALL cp_cfm_create(cswork, csmat%matrix_struct, name=
"kp_cold_s")
3543 CALL cp_cfm_create(cwork, cksmat%matrix_struct, name=
"kp_cold_work")
3544 CALL cp_cfm_geeig(chwork, cswork, kp%mos(ispin)%cmo_coeff, eigenvalues, cwork)
3549 CALL timestop(handle)
3551 END SUBROUTINE cold_start_mo_init
3563 SUBROUTINE davidson_kp_prepare_preconditioners( &
3564 qs_env, scf_env, matrix_ks_kp, matrix_s_kp, kpoints, op_ctx)
3568 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks_kp, matrix_s_kp
3572 CHARACTER(LEN=*),
PARAMETER :: routinen =
'davidson_kp_prepare_preconditioners'
3574 INTEGER :: channel, handle, ispin, kplocal, kpmax, &
3575 local_kpoint, nchannels, nmo, nspin, &
3576 prec_type, solver_type
3577 INTEGER,
DIMENSION(2) :: kp_range
3578 INTEGER,
DIMENSION(:, :),
POINTER :: kp_dist
3579 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
3580 REAL(kind=
dp) :: energy_gap
3581 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues
3582 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: xkp
3585 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_t_kp
3586 TYPE(
dbcsr_type),
POINTER :: matrix_h_im, matrix_h_re, matrix_s_im, &
3587 matrix_s_re, matrix_t_im, matrix_t_re
3593 CALL timeset(routinen, handle)
3595 CALL get_kpoint_info(kpoints, kp_range=kp_range, kp_dist=kp_dist, xkp=xkp, sab_nl=sab_nl, &
3596 cell_to_index=cell_to_index)
3597 CALL get_qs_env(qs_env, kinetic_kp=matrix_t_kp)
3600 blacs_env => kpoints%blacs_env
3601 para_env => kpoints%para_env_kp
3602 kplocal = kp_range(2) - kp_range(1) + 1
3603 kpmax = maxval(kp_dist(2, :) - kp_dist(1, :) + 1)
3604 nspin =
SIZE(matrix_ks_kp, 1)
3605 nchannels = kplocal*nspin
3606 prec_type = scf_env%block_davidson_env(1)%prec_type
3607 solver_type = scf_env%block_davidson_env(1)%solver_type
3608 energy_gap = scf_env%block_davidson_env(1)%energy_gap
3614 IF (
ASSOCIATED(scf_env%ot_preconditioner))
THEN
3615 DO channel = 1,
SIZE(scf_env%ot_preconditioner)
3616 IF (
ASSOCIATED(scf_env%ot_preconditioner(channel)%preconditioner))
THEN
3618 DEALLOCATE (scf_env%ot_preconditioner(channel)%preconditioner)
3621 DEALLOCATE (scf_env%ot_preconditioner)
3622 NULLIFY (scf_env%ot_preconditioner)
3624 ALLOCATE (scf_env%ot_preconditioner(nchannels))
3625 DO channel = 1, nchannels
3626 ALLOCATE (scf_env%ot_preconditioner(channel)%preconditioner)
3628 para_env, blacs_env)
3631 NULLIFY (eigenvalues, matrix_h_im, matrix_h_re, matrix_s_im, matrix_s_re, &
3632 matrix_t_im, matrix_t_re)
3634 cpassert(
ASSOCIATED(matrix_t_kp))
3638 DO local_kpoint = 1, kpmax
3646 mat_re=matrix_s_re, mat_im=matrix_s_im, &
3653 mat_re=matrix_t_re, mat_im=matrix_t_im, &
3662 mat_re=matrix_h_re, mat_im=matrix_h_im, matrix_row=ispin, slot=
kpoint_slot_ks)
3664 IF (local_kpoint <= kplocal)
THEN
3665 kp => kpoints%kp_env(local_kpoint)%kpoint_env
3666 channel = (local_kpoint - 1)*nspin + ispin
3674 CALL get_mo_set(kp%mos(ispin), eigenvalues=eigenvalues, &
3676 CALL cp_cfm_create(matrix_c, kp%mos(ispin)%cmo_coeff%matrix_struct, name=
"dav pc C")
3679 scf_env%ot_preconditioner(channel)%preconditioner, &
3680 'dav pc H', matrix_h)
3682 scf_env%ot_preconditioner(channel)%preconditioner, &
3683 'dav pc S', matrix_s)
3686 matrix_c, matrix_h, matrix_s, eigenvalues(1:nmo), &
3690 scf_env%ot_preconditioner(channel)%preconditioner, &
3691 matrix_c, matrix_h, matrix_s, energy_gap)
3698 scf_env%ot_preconditioner(channel)%preconditioner, &
3699 matrix_t_re, matrix_t_im, matrix_s_re, matrix_s_im, energy_gap, solver_type)
3702 scf_env%ot_preconditioner(channel)%preconditioner, &
3703 matrix_s_re, matrix_s_im, solver_type)
3720 CALL timestop(handle)
3722 END SUBROUTINE davidson_kp_prepare_preconditioners
3736 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s
3739 LOGICAL,
INTENT(IN),
OPTIONAL :: lowdin_forces
3741 CHARACTER(len=*),
PARAMETER :: routinen =
'diag_kp_smat'
3742 COMPLEX(KIND=dp),
PARAMETER :: cone = (1.0_dp, 0.0_dp), &
3743 czero = (0.0_dp, 0.0_dp)
3745 COMPLEX(KIND=dp),
ALLOCATABLE,
DIMENSION(:) :: ceig
3746 INTEGER :: handle, ikp, kplocal, kpmax, nao
3747 INTEGER,
DIMENSION(2) :: kp_range
3748 INTEGER,
DIMENSION(:, :),
POINTER :: kp_dist
3750 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: eigenvalues
3761 CALL timeset(routinen, handle)
3765 kp_dist=kp_dist, sab_nl=sab_nl)
3766 cpassert(
ASSOCIATED(sab_nl))
3767 kplocal = kp_range(2) - kp_range(1) + 1
3768 kpmax = maxval(kp_dist(2, :) - kp_dist(1, :) + 1)
3772 CALL mpools_get(mpools, ao_ao_fm_pool=ao_ao_fm_pool)
3785 ALLOCATE (eigenvalues(nao), ceig(nao))
3806 IF (ikp > kplocal) cycle
3807 kp => kpoints%kp_env(ikp)%kpoint_env
3808 save_spectrum =
ALLOCATED(kp%lowdin_sqrt)
3809 IF (
PRESENT(lowdin_forces)) save_spectrum = lowdin_forces
3811 IF (
ALLOCATED(kp%lowdin_sqrt))
DEALLOCATE (kp%lowdin_sqrt)
3817 cpassert(all(eigenvalues(1:nao) >= 0.0_dp))
3818 IF (save_spectrum)
THEN
3819 IF (any(eigenvalues <= 0.0_dp))
THEN
3820 cpabort(
"Lowdin forces require a positive definite overlap")
3822 ALLOCATE (kp%lowdin_sqrt(nao))
3823 kp%lowdin_sqrt(:) = sqrt(eigenvalues)
3834 eigenvalues(1:nao) = sqrt(eigenvalues(1:nao))
3837 CALL parallel_gemm(
"N",
"T", nao, nao, nao, 1.0_dp, rsmat, fmlocal, &
3842 ceig(1:nao) = sqrt(eigenvalues(1:nao))
3845 CALL parallel_gemm(
"N",
"C", nao, nao, nao, cone, csmat, cwork, &
3853 DEALLOCATE (eigenvalues, ceig)
3863 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....
various utilities that regard array of different kinds: output, allocation,... maybe it is not a good...
methods related to the blacs parallel environment
Basic linear algebra operations for complex full matrices.
subroutine, public cp_cfm_scale_and_add(alpha, matrix_a, beta, matrix_b)
Scale and add two BLACS matrices (a = alpha*a + beta*b).
subroutine, public cp_cfm_transpose(matrix, trans, matrixt)
Transposes a BLACS distributed complex matrix.
subroutine, public cp_cfm_scale_and_add_fm(alpha, matrix_a, beta, matrix_b)
Scale and add two BLACS matrices (a = alpha*a + beta*b). where b is a real matrix (adapted from cp_cf...
subroutine, public cp_cfm_triangular_multiply(triangular_matrix, matrix_b, side, transa_tr, invert_tr, uplo_tr, unit_diag_tr, n_rows, n_cols, alpha)
Multiplies in place by a triangular matrix: matrix_b = alpha op(triangular_matrix) matrix_b or (if si...
subroutine, public cp_cfm_column_scale(matrix_a, scaling, first_col, source)
Scales columns of the full matrix by corresponding factors.
various cholesky decomposition related routines
subroutine, public cp_cfm_cholesky_decompose(matrix, n, info_out)
Used to replace a symmetric positive definite matrix M with its Cholesky decomposition U: M = U^T * U...
used for collecting diagonalization schemes available for cp_cfm_type
subroutine, public cp_cfm_geeig_canon(amatrix, bmatrix, eigenvectors, eigenvalues, work, epseig, nmo_retained)
General Eigenvalue Problem AX = BXE Use canonical orthogonalization.
subroutine, public cp_cfm_geeig_local(amatrix, bmatrix, eigenvectors, eigenvalues, ws)
Solve a generalized complex eigenproblem using the local LAPACK backend. This routine is restricted t...
subroutine, public cp_cfm_local_workspace_prepare(ws, n, a, b)
Query LAPACK once per matrix order/solver and retain private scratch across k points.
subroutine, public cp_cfm_geeig_canon_local(amatrix, bmatrix, eigenvectors, eigenvalues, work, epseig, ws)
Canonical generalized complex diagonalization on a one-rank BLACS grid.
subroutine, public cp_cfm_heevd(matrix, eigenvectors, eigenvalues)
Perform a diagonalisation of a complex matrix.
subroutine, public cp_cfm_geeig(amatrix, bmatrix, eigenvectors, eigenvalues, work, lowest_subset)
General Eigenvalue Problem AX = BXE Single option version: Cholesky decomposition of B.
Represents a complex full matrix distributed on many processors.
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_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
Creates a new full matrix with the given structure.
subroutine, public cp_cfm_set_all(matrix, alpha, beta)
Set all elements of the full matrix to alpha. Besides, set all diagonal matrix elements to beta (if g...
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.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_release_p(matrix)
...
subroutine, public dbcsr_deallocate_matrix(matrix)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_init_p(matrix)
...
subroutine, public dbcsr_set(matrix, alpha)
...
Routines that link DBCSR and CP2K concepts together.
subroutine, public cp_dbcsr_alloc_block_from_nbl(matrix, sab_orb, desymmetrize)
allocate the blocks of a dbcsr based on the neighbor list
DBCSR operations in CP2K.
subroutine, public cp_dbcsr_sm_fm_multiply(matrix, fm_in, fm_out, ncol, alpha, beta)
multiply a dbcsr with a fm matrix
subroutine, public copy_dbcsr_to_fm(matrix, fm, plan, check_plan)
Copy a DBCSR matrix to a BLACS matrix.
subroutine, public copy_fm_to_dbcsr(fm, matrix, keep_sparsity)
Copy a BLACS matrix to a dbcsr matrix.
Basic linear algebra operations for full matrices.
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_uplo_to_full(matrix, work, uplo)
given a triangular matrix according to uplo, computes the corresponding full matrix
subroutine, public cp_fm_column_scale(matrixa, scaling, first_col, source)
Scales columns of the full matrix by corresponding factors.
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...
various cholesky decomposition related routines
subroutine, public cp_fm_cholesky_restore(fm_matrix, neig, fm_matrixb, fm_matrixout, op, pos, transa)
apply Cholesky decomposition op can be "SOLVE" (out = U^-1 * in) or "MULTIPLY" (out = U * in) pos can...
subroutine, public cp_fm_cholesky_reduce(matrix, matrixb, itype)
reduce a matrix pencil A,B to normal form B has to be cholesky decomposed with cp_fm_cholesky_decompo...
used for collecting some of the diagonalization schemes available for cp_fm_type. cp_fm_power also mo...
subroutine, public cp_fm_geeig_canon(amatrix, bmatrix, eigenvectors, eigenvalues, work, epseig, nmo_retained)
General Eigenvalue Problem AX = BXE Use canonical diagonalization : U*s**(-1/2).
logical, save, public direct_generalized_diagonalization
subroutine, public cp_fm_geeig(amatrix, bmatrix, eigenvectors, eigenvalues, work)
General Eigenvalue Problem AX = BXE. Use cuSOLVERMp directly when requested and large enough; otherwi...
subroutine, public choose_eigv_solver(matrix, eigenvectors, eigenvalues, info)
Choose the Eigensolver depending on which library is available ELPA seems to be unstable for small sy...
logical function, public diag_check_requested()
Return whether diagonalization checks should be performed.
logical, save, public diag_lib_explicit
pool for for elements that are retained and released
subroutine, public fm_pool_create_fm(pool, element, name)
returns an element, allocating it if none is in the pool
subroutine, public fm_pool_give_back_fm(pool, element)
returns the element to the pool
type(cp_fm_struct_type) function, pointer, public fm_pool_get_el_struct(pool)
returns the structure of the elements in this pool
represent the structure of a full matrix
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
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_add_to_element(matrix, irow_global, icol_global, alpha)
...
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
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 ...
recursive integer function, public cp_logger_get_default_unit_nr(logger, local, skip_not_ionode)
asks the default unit number of the given logger. try to use cp_logger_get_unit_nr
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, parameter, public debug_print_level
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,...
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, file_access)
...
Add the DFT+U contribution to the Hamiltonian matrix.
subroutine, public lowdin_kp_apply(kp, v, rmat, cmat)
Add B diag(v) B**H before any solver, DIIS residual, or history storage uses H(k).
Defines the basic variable types.
integer, parameter, public int_8
integer, parameter, public dp
Routines needed for kpoint calculation.
subroutine, public kpoint_density_transform(kpoint, denmat, wtype, tempmat, sab_nl, fmwork, for_aux_fit, pmat_ext, overlap_rs, mixed_aux_orb)
generate real space density matrices in DBCSR format
subroutine, public kpoint_set_mo_occupation(kpoint, smear, probe, added_mos_auto, added_mos_auto_grow, separate_spin_occupations)
Given the eigenvalues of all kpoints, calculates the occupation numbers.
subroutine, public rskp_transform_grid_release(grid)
Release a reciprocal-grid transformation cache.
subroutine, public rskp_transform_grid_prepare(grid, rmatrix, rsmat, ispin, xkp, nkp_grid, cell_to_index, sab_nl, used_fft, is_complex, rs_sign, max_storage_bytes)
Prepare a batched real-cell transform to a regular grid or subset for local DBCSR blocks....
subroutine, public kpoint_density_matrices(kpoint, energy_weighted, for_aux_fit)
Calculate kpoint density matrices (rho(k), owned by kpoint groups).
Types and basic routines needed for a kpoint calculation.
subroutine, public get_kpoint_info(kpoint, kp_scheme, nkp_grid, kp_shift, symmetry, verbose, full_grid, use_real_wfn, eps_geo, parallel_group_size, kp_range, nkp, xkp, wkp, para_env, blacs_env_all, para_env_kp, para_env_inter_kp, blacs_env, kp_env, kp_aux_env, mpools, iogrp, nkp_groups, kp_dist, cell_to_index, index_to_cell, sab_nl, sab_nl_nosym, inversion_symmetry_only, symmetry_backend, symmetry_reduction_method, gamma_centered, lattice_fft)
Retrieve information from a kpoint environment.
integer, parameter, public local_gemm_pu_gpu
Machine interface based on Fortran 2003 and POSIX.
subroutine, public m_flush(lunit)
flushes units if the &GLOBAL flag is set accordingly
real(kind=dp) function, public m_walltime()
returns time from a real-time clock, protected against rolling early/easily
Definition of mathematical constants and functions.
complex(kind=dp), parameter, public z_one
complex(kind=dp), parameter, public z_zero
Interface to the message passing library MPI.
basic linear algebra operations for full matrixes
computes preconditioners, and implements methods to apply them currently used in qs_ot
subroutine, public make_complex_full_single_inverse(preconditioner_env, matrix_c0, matrix_h, matrix_s, energy_gap)
Build a gauge-covariant FULL_SINGLE_INVERSE operator for a complex k-point channel.
subroutine, public make_complex_full_all(preconditioner_env, matrix_c0, matrix_h, matrix_s, c0_evals, energy_gap)
Build the state-selective FULL_ALL operator for a complex k-point channel. The occupied/reference sub...
subroutine, public init_preconditioner(preconditioner_env, para_env, blacs_env)
...
subroutine, public destroy_preconditioner(preconditioner_env)
...
computes preconditioners, and implements methods to apply them currently used in qs_ot
subroutine, public make_preconditioner_complex_full_s_inverse(preconditioner_env, matrix_s_re, matrix_s_im, solver_type)
Construct a complex FULL_S_INVERSE preconditioner.
subroutine, public dbcsr_pair_to_cfm(matrix_re, matrix_im, preconditioner_env, matrix_name, matrix)
Copy a real/imaginary DBCSR pair to one distributed complex full matrix.
subroutine, public restart_preconditioner(qs_env, preconditioner, prec_type, nspins)
Allows for a restart of the preconditioner depending on the method it purges all arrays or keeps them...
subroutine, public prepare_preconditioner(qs_env, mos, matrix_ks, matrix_s, ot_preconditioner, prec_type, solver_type, energy_gap, nspins, has_unit_metric, convert_to_dbcsr, chol_type, full_mo_set, chebyshev_degree, low_rank_base, fermi_low_rank_max_rank, lattice_fft, lattice_fft_local_cells)
...
subroutine, public make_preconditioner_complex_full_kinetic(preconditioner_env, matrix_t_re, matrix_t_im, matrix_s_re, matrix_s_im, energy_gap, solver_type)
Construct a complex FULL_KINETIC preconditioner.
collects routines that calculate density matrices
module that contains the definitions of the scf types
integer, parameter, public direct_mixing_nr
integer, parameter, public gspace_mixing_nr
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.
subroutine, public qs_diis_b_calc_err_kp(diis_buffer, ib, mos, kc, sc, ispin, ikp, cmos, real_wfn, local, gemm_ctx)
Calculate and store the error for a given k-point.
pure subroutine, public qs_diis_b_clear(diis_buffer)
clears the buffer
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_inter_kp)
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_kp(diis_buffer)
clears the buffer
subroutine, public qs_diis_b_check_i_alloc_kp(diis_buffer, matrix_struct, nspin, nkp, scf_section)
Allocate and initialize a DIIS buffer for nao*nao parameter variables and with a buffer size of nbuff...
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, mimic, 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, sab_cneo, 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, matrix_vhxc, 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, xcint_weights, 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, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_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, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
subroutine, public gspace_mixing(qs_env, mixing_method, mixing_store, rho, para_env, iter_count, auxiliary)
Driver for the g-space mixing, calls the proper routine given the requested method.
Assembly of real and complex k-point operators from real-space DBCSR matrices. Outputs use the distri...
subroutine, public kpoint_operator_context_create(ctx, kpoints, ao_ao_fm, nspin)
Create an empty operator context. The context owns no buffers after this call; they are created on fi...
subroutine, public kpoint_operator_prepare(ctx, rsmat, slot, prepared, matrix_row, target)
Prepare an immutable operator slot for group-local assembly. Refresh after the source values change,...
subroutine, public kpoint_operator_finish(ctx, ikp, ispin, slot, cmat, fm_re)
Finish one started instance: build its prepared group-local operator, or merge received parts into cm...
subroutine, public kpoint_operator_store(ctx, matrix_ks, matrix_s, matrix_t)
Prepare owned split-FM operators for OT without entering an SCF eigensolver. H (or the initialization...
subroutine, public kpoint_operator_work_size(ctx, nentry)
Size per-worker phase scratch for direct assembly into a solver matrix.
subroutine, public kpoint_operator_get(ctx, ikp, ispin, rsmat, cmat, fm_re, fm_im, mat_re, mat_im, matrix_row, slot, grid)
Assemble one operator for one global round and spin in one call: run the single-group transfer of the...
integer, parameter, public kpoint_spin_free
Row of rsmat that carries the spin-free operator image. S and T carry no spin copies: drivers launch ...
subroutine, public kpoint_operator_batch_size(ctx, nworkers, nmatrices, width, work_size)
Size local k tiles, budgeting operator outputs and block scratch over all workers....
subroutine, public kpoint_operator_evaluate(ctx, ispin, slot, ik, phase, target, fm_re, fm_im)
Evaluate an immutable prepared operator with exclusively caller-owned output and scratch....
integer, parameter, public kpoint_slot_s
integer, parameter, public kpoint_slot_t
integer, parameter, public kpoint_slot_ks
subroutine, public kpoint_operator_get_local(matrix_rs, kpoints, kp, ispin, cache_re, cache_im, matrix_re, matrix_im)
Read an operator inside a group-local OT loop, after collective cache preparation....
subroutine, public kpoint_operator_evaluate_batch(ctx, ispin, slot, first_k, batch, work)
Assemble a caller-owned complex k tile using real block/image contractions. The prepared route and sn...
subroutine, public kpoint_operator_start(ctx, ikp, ispin, rsmat, slot, grid, use_grid, matrix_row)
Start one operator for one global round and spin. The service walks all groups with a k point in this...
subroutine, public kpoint_operator_context_release(ctx)
Release the context together with every buffer it created. Call once, at the end of the fixed-layout ...
routines that build the Kohn-Sham matrix (i.e calculate the coulomb and xc parts
subroutine, public qs_ks_update_qs_env(qs_env, calculate_forces, just_energy, print_active)
updates the Kohn Sham matrix of the given qs_env (facility method)
subroutine, public qs_ks_did_change(ks_env, s_mstruct_changed, rho_changed, potential_changed, full_reset)
tells that some of the things relevant to the ks calculation did change. has to be called when change...
wrapper for the pools of matrixes
subroutine, public mpools_get(mpools, ao_mo_fm_pools, ao_ao_fm_pool, mo_mo_fm_pools, ao_mosub_fm_pools, mosub_mosub_fm_pools, maxao_maxmo_fm_pool, maxao_maxao_fm_pool, maxmo_maxmo_fm_pool)
returns various attributes of the mpools (notably the pools contained in it)
elemental subroutine, public charge_mixing_init(mixing_store)
initialiation needed when charge mixing is used
subroutine, public mixing_init(mixing_method, rho, mixing_store, para_env, rho_atom, auxiliary)
initialiation needed when gspace mixing is used
subroutine, public mixing_allocate(qs_env, mixing_method, p_mix_new, p_delta, nspins, mixing_store)
allocation needed when density mixing is used
subroutine, public self_consistency_check(rho_ao, p_delta, para_env, p_out, delta)
...
collects routines that perform operations directly related to MOs
Set occupation of molecular orbitals.
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, cmo_coeff)
Get the components of a MO set data structure.
Define the neighbor list data types and the corresponding functionality.
an eigen-space solver for the generalised symmetric eigenvalue problem for sparse matrices,...
subroutine, public ot_eigensolver_complex(matrix_h, matrix_h_im, matrix_s, matrix_s_im, matrix_c_cfm, preconditioner, eps_gradient, iter_max, eigenvalues, silent, ot_settings, matrix_t, matrix_t_im, mo_set)
solve a fixed complex Hermitian generalized eigenproblem by OT
subroutine, public ot_eigensolver(matrix_h, matrix_s, matrix_orthogonal_space_fm, matrix_c_fm, preconditioner, eps_gradient, iter_max, size_ortho_space, silent, ot_settings)
...
methods of the rho structure (defined in qs_rho_types)
subroutine, public qs_rho_update_rho(rho_struct, qs_env, rho_xc_external, local_rho_set, task_list_external, task_list_external_soft, pw_env_external, para_env_external)
updates rho_r and rho_g to the rhorho_ao. if use_kinetic_energy_density also computes tau_r and tau_g...
superstucture that hold various representations of the density and keeps track of which ones are vali...
subroutine, public qs_rho_get(rho_struct, rho_ao, rho_ao_im, rho_ao_kp, rho_ao_im_kp, rho_r, drho_r, rho_g, drho_g, tau_r, tau_g, rho_r_valid, drho_r_valid, rho_g_valid, drho_g_valid, tau_r_valid, tau_g_valid, tot_rho_r, tot_rho_g, rho_r_sccs, soft_valid, complex_rho_ao)
returns info about the density described by this object. If some representation is not available an e...
module that contains the algorithms to perform an iterative diagonalization by the block-Davidson app...
subroutine, public generate_extended_space_c(bdav_env, mos, matrix_h, matrix_s, output_unit, eps_iter, eps_iter_empty, preconditioner)
iterative diagonalization by the block-Davidson approach for one complex K point; complex counterpart...
subroutine, public generate_extended_space_sparse(bdav_env, mo_set, matrix_h, matrix_s, output_unit, preconditioner)
...
subroutine, public generate_extended_space(bdav_env, mo_set, matrix_h, matrix_s, output_unit, preconditioner)
...
Different diagonalization schemes that can be used for the iterative solution of the eigenvalue probl...
subroutine, public do_general_diag_kp(matrix_ks, matrix_s, kpoints, scf_env, scf_control, update_p, diis_step, diis_error, qs_env, probe, added_mos_auto_grow, potential)
Kpoint diagonalization routine Transforms matrices to kpoint, distributes kpoint groups,...
subroutine, public general_eigenproblem(scf_env, mos, matrix_ks, matrix_s, scf_control, scf_section, diis_step)
the inner loop of scf, specific to diagonalization with S matrix basically, in goes the ks matrix out...
subroutine, public diag_kp_smat(matrix_s, kpoints, fmwork, lowdin_forces)
Kpoint diagonalization routine Transforms matrices to kpoint, distributes kpoint groups,...
subroutine, public do_block_davidson_diag_kp(qs_env, scf_env, matrix_ks_kp, matrix_s_kp, kpoints, scf_control, added_mos_auto_grow)
block-Davidson SCF step for complex K points, one channel per (local kpoint, spin); mirrors do_block_...
subroutine, public diag_subspace_allocate(subspace_env, qs_env, mos)
...
subroutine, public do_ot_diag(scf_env, mos, matrix_ks, matrix_s, scf_control, scf_section, diis_step)
the inner loop of scf, specific to iterative diagonalization using OT with S matrix; basically,...
subroutine, public do_block_davidson_diag(qs_env, scf_env, mos, matrix_ks, matrix_s, scf_control, scf_section, check_moconv_only)
iterative diagonalization using the block davidson space approach
subroutine, public do_roks_diag(scf_env, mos, matrix_ks, matrix_s, scf_control, scf_section, diis_step, orthogonal_basis)
Solve a set restricted open Kohn-Sham (ROKS) equations based on the alpha and beta Kohn-Sham matrices...
subroutine, public diag_kp_basic(matrix_ks, matrix_s, kpoints, fmwork)
Kpoint diagonalization routine Transforms matrices to kpoint, distributes kpoint groups,...
subroutine, public do_scf_diag_subspace(qs_env, scf_env, subspace_env, mos, rho, ks_env, scf_section, scf_control)
inner loop within MOS subspace, to refine occupation and density, before next diagonalization of the ...
subroutine, public do_block_krylov_diag_kp(qs_env, scf_env, matrix_ks_kp, matrix_s_kp, kpoints, scf_control, check_moconv_only, added_mos_auto_grow)
Block Krylov (Lanczos) refinement of the k-point MOS, the complex counterpart of do_block_krylov_diag...
real(kind=dp) function adiis_candidate_shift(scf_env)
Fade candidate regularization through handover; never regularize a raw-map check.
subroutine, public do_block_krylov_diag(scf_env, mos, matrix_ks, scf_control, scf_section, check_moconv_only)
iterative diagonalization using the block Krylov-space approach
subroutine, public do_special_diag(scf_env, mos, matrix_ks, scf_control, scf_section, diis_step)
the inner loop of scf, specific to diagonalization without S matrix basically, in goes the ks matrix ...
subroutine, public do_ot_diag_kp(matrix_ks, matrix_s, matrix_t, kpoints, scf_env, scf_control, diis_step, added_mos_auto_grow)
fixed-H OT diagonalization for real or complex K-point channels
subroutine, public do_general_diag(scf_env, mos, matrix_ks, matrix_s, scf_control, scf_section, diis_step, probe)
...
Complex block-Lanczos refinement kernel for k-point SCF diagonalization. Processes unconverged column...
subroutine, public lanczos_channel_end(c0, ws)
Defensive full-width Cholesky orthonormalization at the end of a channel's refinement sweeps,...
subroutine, public lanczos_workspace_release(ws)
Release the kernel workspace. Safe on a workspace that was never created: the matrix components defau...
subroutine, public lanczos_channel_begin(ks, c0, eval, eps_col, ws, max_res_norm, min_res_norm, nmo_conv, nmo_nc, check_moconv_only)
Entry preparation of one (k-point, spin) channel before its inner Lanczos sweeps: orthonormalizes the...
subroutine, public lanczos_sweep_suffix(ks, c0, eval, eps_col, nkrylov, nblock, first_sweep, need_suffix_rr, ws, max_res_norm, min_res_norm, nmo_conv, nmo_nc, step_refined, next_need_suffix_rr)
Run one inner Lanczos sweep on the unconverged suffix of c0. When the previous sweep ran in multi-blo...
subroutine, public lanczos_workspace_create(ws, mo_struct, ao_struct, nkrylov, nblock)
Create the kernel workspace at the worst-case widths of the run. The basis budget holds the larger of...
module that contains the algorithms to perform an iterative diagonalization by the block-Lanczos appr...
subroutine, public lanczos_refinement(krylov_space, ks, c0, c1, eval, nao, eps_iter, ispin, check_moconv_only)
lanczos refinement by blocks of non-converged MOs
subroutine, public lanczos_refinement_2v(krylov_space, ks, c0, c1, eval, nao, eps_iter, ispin, check_moconv_only)
...
groups fairly general SCF methods, so that modules other than qs_scf can use them too split off from ...
subroutine, public eigensolver_simple(matrix_ks, mo_set, work, do_level_shift, level_shift, use_jacobi, jacobi_threshold)
...
subroutine, public eigensolver_dbcsr(matrix_ks, matrix_ks_fm, mo_set, ortho_dbcsr, ksbuf1, ksbuf2)
...
subroutine, public scf_env_density_mixing(p_mix_new, mixing_store, rho_ao, para_env, iter_delta, iter_count, diis, invert)
perform (if requested) a density mixing
subroutine, public eigensolver(matrix_ks_fm, mo_set, ortho, work, cholesky_method, do_level_shift, level_shift, matrix_u_fm, use_jacobi)
Diagonalise the Kohn-Sham matrix to get a new set of MO eigen- vectors and MO eigenvalues....
subroutine, public eigensolver_symm(matrix_ks_fm, mo_set, ortho, work, do_level_shift, level_shift, matrix_u_fm, use_jacobi, jacobi_threshold, ortho_red, work_red, matrix_ks_fm_red, matrix_u_fm_red)
...
subroutine, public eigensolver_generalized(matrix_ks_fm, matrix_s, mo_set, work)
Solve the generalized eigenvalue problem.
module that contains the definitions of the scf types
parameters that control an scf iteration
represent a pointer to a 1d array
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
Represent a complex full matrix.
represent a pool of elements with the same structure
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...
Keeps information about a specific k-point.
Contains information about kpoints.
stores all the informations relevant to an mpi environment
Caller-owned assembly context for a fixed geometry and parallel layout. OT retains it for one inner S...
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...
container for the pools of matrixes used by qs
keeps the density in various representations, keeping track of which ones are valid.
Caller-owned scratch of the refinement kernel: every matrix and array that the sweeps of one channel ...