76 USE ieee_arithmetic,
ONLY: ieee_is_finite
173#include "./base/base_uses.f90"
179 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_scf_diagonalization'
181 TYPE,
PRIVATE :: kp_diag_workspace_type
182 TYPE(cp_cfm_type) :: cksmat, cmos, csmat, csmat_base, cwork
183 TYPE(cp_cfm_diag_workspace_type) :: solver
184 TYPE(local_gemm_ctxt_type) :: gemm_ctx
185 COMPLEX(KIND=dp),
ALLOCATABLE :: phase(:, :)
186 END TYPE kp_diag_workspace_type
203 REAL(kind=
dp) :: shift
206 IF (scf_env%iter_count <= 1 .OR. scf_env%adiis_check_next)
RETURN
207 IF (.NOT.
ASSOCIATED(scf_env%scf_subspace_buffer))
RETURN
208 shift = scf_env%adiis_shift*(1.0_dp - scf_env%scf_subspace_buffer%diis_weight)
219 SUBROUTINE shift_candidate_real(fock, overlap, mos, shift)
223 REAL(kind=
dp),
INTENT(IN) :: shift
226 REAL(kind=
dp) :: maxocc
227 REAL(kind=
dp),
DIMENSION(:),
POINTER :: occupation
231 IF (shift == 0.0_dp)
RETURN
232 CALL get_mo_set(mos, nao=nao, nmo=nmo, maxocc=maxocc, occupation_numbers=occupation, mo_coeff=coeff)
234 CALL parallel_gemm(
"N",
"N", nao, nmo, nao, 1.0_dp, overlap, coeff, 0.0_dp, sc)
236 CALL parallel_gemm(
"N",
"T", nao, nao, nmo, -shift, sc, sc, 1.0_dp, fock)
238 END SUBROUTINE shift_candidate_real
251 SUBROUTINE shift_candidate_complex(fock, overlap, mos, coeff, work, shift, local, gemm_ctx)
256 REAL(kind=
dp),
INTENT(IN) :: shift
257 LOGICAL,
INTENT(IN) :: local
261 REAL(kind=
dp) :: maxocc
262 REAL(kind=
dp),
DIMENSION(:),
POINTER :: occupation
265 IF (shift == 0.0_dp)
RETURN
266 CALL get_mo_set(mos, nao=nao, nmo=nmo, maxocc=maxocc, occupation_numbers=occupation, cmo_coeff=cmos)
270 cpassert(product(overlap%matrix_struct%context%num_pe) == 1)
271 cpassert(product(coeff%matrix_struct%context%num_pe) == 1)
272 cpassert(product(work%matrix_struct%context%num_pe) == 1)
273 cpassert(product(fock%matrix_struct%context%num_pe) == 1)
274 CALL gemm_ctx%gemm(
"N",
"N", nao, nmo, nao,
z_one, &
275 overlap%local_data,
SIZE(overlap%local_data, 1), &
276 coeff%local_data,
SIZE(coeff%local_data, 1),
z_zero, &
277 work%local_data,
SIZE(work%local_data, 1))
278 CALL gemm_ctx%gemm(
"N",
"C", nao, nao, nmo, cmplx(-shift, kind=
dp), &
279 work%local_data,
SIZE(work%local_data, 1), &
280 work%local_data,
SIZE(work%local_data, 1),
z_one, &
281 fock%local_data,
SIZE(fock%local_data, 1))
284 CALL parallel_gemm(
"N",
"C", nao, nao, nmo, cmplx(-shift, kind=
dp), work, work,
z_one, fock)
286 END SUBROUTINE shift_candidate_complex
303 matrix_s, scf_control, scf_section, &
308 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s
311 LOGICAL,
INTENT(INOUT) :: diis_step
313 INTEGER :: cdiis_cholesky_method, cdiis_ncall, &
315 LOGICAL :: cdiis_step, do_level_shift, owns_ortho, &
316 use_adiis, use_cdiis, use_jacobi, &
318 REAL(kind=
dp) :: candidate_shift, cdiis_error, &
319 diis_error, diis_weight, eps_diis
321 TYPE(
dbcsr_type),
POINTER :: effective_ks_dbcsr, ortho_dbcsr
323 nspin =
SIZE(matrix_ks)
324 NULLIFY (effective_ks_dbcsr, ortho, ortho_dbcsr)
327 use_subspace_fock = .false.
329 IF (.NOT.
ASSOCIATED(scf_env%scf_subspace_buffer))
THEN
330 cpabort(
"ADIIS is only available in the main Quickstep SCF workflow")
332 use_subspace_fock = scf_env%scf_subspace_buffer%use_combined_fock
335 eps_diis = scf_control%eps_diis
337 IF (use_adiis .AND.
ASSOCIATED(scf_env%scf_diis_buffer))
THEN
338 IF (.NOT. scf_env%skip_diis .AND. scf_env%iter_count > 1 .AND. &
339 .NOT. scf_env%adiis_check_next .AND. &
340 .NOT. scf_env%scf_subspace_buffer%last_restart .AND. &
341 scf_env%scf_subspace_buffer%nstored > 0)
THEN
342 use_cdiis = scf_env%iter_delta < eps_diis .OR. scf_env%scf_diis_buffer%ncall > 0
349 ELSE IF (use_subspace_fock)
THEN
350 CALL copy_dbcsr_to_fm(scf_env%scf_subspace_buffer%combined_fock(ispin, 1)%matrix, &
351 scf_env%scf_work1(ispin))
359 diis_error = scf_env%scf_subspace_buffer%last_old_fock_weight
360 diis_weight = scf_env%scf_subspace_buffer%diis_weight
362 cdiis_ncall = scf_env%scf_diis_buffer%ncall
363 CALL qs_diis_b_step(scf_env%scf_diis_buffer, mos, scf_env%scf_work1, &
364 scf_env%scf_work2, scf_env%iter_delta, cdiis_error, cdiis_step, &
365 eps_diis, 2, s_matrix=matrix_s, scf_section=scf_section)
366 IF (.NOT. ieee_is_finite(cdiis_error) .OR. cdiis_error >= eps_diis)
THEN
368 IF (cdiis_ncall < scf_env%scf_diis_buffer%nbuffer)
THEN
370 scf_env%scf_diis_buffer%ncall = cdiis_ncall
378 diis_weight = min(1.0_dp, diis_weight + 0.5_dp)
383 IF (diis_weight < 1.0_dp)
THEN
385 IF (use_subspace_fock)
THEN
387 scf_env%scf_subspace_buffer%combined_fock(ispin, 1)%matrix, scf_env%scf_work2)
392 1.0_dp - diis_weight, scf_env%scf_work2)
395 diis_step = cdiis_step .AND. diis_weight >= 1.0_dp
396 IF (diis_step) diis_error = cdiis_error
397 ELSE IF (
ASSOCIATED(scf_env%scf_diis_buffer))
THEN
398 IF (scf_env%scf_diis_buffer%ncall > 0)
CALL qs_diis_b_clear(scf_env%scf_diis_buffer)
401 scf_env%scf_subspace_buffer%diis_weight = diis_weight
403 IF (scf_env%iter_count > 1 .AND. .NOT. scf_env%skip_diis)
THEN
404 CALL qs_diis_b_step(scf_env%scf_diis_buffer, mos, scf_env%scf_work1, &
405 scf_env%scf_work2, scf_env%iter_delta, diis_error, diis_step, &
406 eps_diis, scf_control%nmixing, &
408 scf_section=scf_section)
414 candidate_shift = 0.0_dp
416 IF (candidate_shift > 0.0_dp)
THEN
419 CALL shift_candidate_real(scf_env%scf_work1(ispin), scf_env%scf_work2, mos(ispin), candidate_shift)
423 do_level_shift = ((scf_control%level_shift /= 0.0_dp) .AND. &
424 ((scf_control%density_guess ==
core_guess) .OR. &
425 (scf_env%iter_count > 1)))
427 IF (.NOT. use_adiis .AND. (scf_env%iter_count > 1) .AND. &
428 (scf_env%iter_delta < scf_control%diagonalization%eps_jacobi))
THEN
434 IF (use_adiis .AND. .NOT. diis_step)
THEN
435 scf_env%iter_param = diis_error
436 IF (scf_env%scf_subspace_buffer%last_restart)
THEN
437 scf_env%iter_method =
"ADIIS/Rst."
439 scf_env%iter_method =
"ADIIS/Diag."
441 ELSE IF (diis_step)
THEN
442 scf_env%iter_param = diis_error
444 scf_env%iter_method =
"DIIS/Jacobi"
446 scf_env%iter_method =
"DIIS/Diag."
449 IF (scf_env%mixing_method == 0)
THEN
450 scf_env%iter_method =
"NoMix/Diag."
451 ELSE IF (scf_env%mixing_method == 1)
THEN
452 scf_env%iter_param = scf_env%p_mix_alpha
454 scf_env%iter_method =
"P_Mix/Jacobi"
456 scf_env%iter_method =
"P_Mix/Diag."
458 ELSE IF (scf_env%mixing_method > 1)
THEN
459 scf_env%iter_param = scf_env%mixing_store%alpha
461 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Jacobi"
463 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Diag."
468 IF (scf_env%cholesky_method ==
cholesky_dbcsr .AND. .NOT. use_cdiis)
THEN
469 ortho_dbcsr => scf_env%ortho_dbcsr
471 effective_ks_dbcsr => matrix_ks(ispin)%matrix
472 IF (use_subspace_fock)
THEN
473 effective_ks_dbcsr => scf_env%scf_subspace_buffer%combined_fock(ispin, 1)%matrix
475 CALL eigensolver_dbcsr(matrix_ks=effective_ks_dbcsr, matrix_ks_fm=scf_env%scf_work1(ispin), &
477 ortho_dbcsr=ortho_dbcsr, &
478 ksbuf1=scf_env%buf1_dbcsr, ksbuf2=scf_env%buf2_dbcsr)
482 cdiis_cholesky_method = scf_env%cholesky_method
487 ortho => scf_env%ortho_m1
489 ortho => scf_env%ortho
493 IF (.NOT.
ASSOCIATED(ortho))
THEN
501 matrix_s=matrix_s(ispin)%matrix, &
503 work=scf_env%scf_work2)
505 IF (do_level_shift)
THEN
506 CALL eigensolver(matrix_ks_fm=scf_env%scf_work1(ispin), &
509 work=scf_env%scf_work2, &
510 cholesky_method=cdiis_cholesky_method, &
511 do_level_shift=do_level_shift, &
512 level_shift=scf_control%level_shift, &
513 matrix_u_fm=scf_env%ortho, &
514 use_jacobi=use_jacobi)
516 CALL eigensolver(matrix_ks_fm=scf_env%scf_work1(ispin), &
519 work=scf_env%scf_work2, &
520 cholesky_method=cdiis_cholesky_method, &
521 do_level_shift=do_level_shift, &
522 level_shift=scf_control%level_shift, &
523 use_jacobi=use_jacobi)
529 scf_env%cholesky_method = cdiis_cholesky_method
532 IF (owns_ortho)
DEALLOCATE (ortho)
534 ortho => scf_env%ortho
537 IF (.NOT.
ASSOCIATED(ortho))
THEN
542 IF (do_level_shift)
THEN
544 IF (
ASSOCIATED(scf_env%scf_work1_red) .AND.
ASSOCIATED(scf_env%scf_work2_red) &
545 .AND.
ASSOCIATED(scf_env%ortho_red) .AND.
ASSOCIATED(scf_env%ortho_m1_red))
THEN
549 work=scf_env%scf_work2, &
550 do_level_shift=do_level_shift, &
551 level_shift=scf_control%level_shift, &
552 matrix_u_fm=scf_env%ortho_m1, &
553 use_jacobi=use_jacobi, &
554 jacobi_threshold=scf_control%diagonalization%jacobi_threshold, &
555 matrix_ks_fm_red=scf_env%scf_work1_red(ispin), &
556 ortho_red=scf_env%ortho_red, &
557 work_red=scf_env%scf_work2_red, &
558 matrix_u_fm_red=scf_env%ortho_m1_red)
563 work=scf_env%scf_work2, &
564 do_level_shift=do_level_shift, &
565 level_shift=scf_control%level_shift, &
566 matrix_u_fm=scf_env%ortho_m1, &
567 use_jacobi=use_jacobi, &
568 jacobi_threshold=scf_control%diagonalization%jacobi_threshold)
573 IF (
ASSOCIATED(scf_env%scf_work1_red) .AND.
ASSOCIATED(scf_env%scf_work2_red) &
574 .AND.
ASSOCIATED(scf_env%ortho_red))
THEN
578 work=scf_env%scf_work2, &
579 do_level_shift=do_level_shift, &
580 level_shift=scf_control%level_shift, &
581 use_jacobi=use_jacobi, &
582 jacobi_threshold=scf_control%diagonalization%jacobi_threshold, &
583 matrix_ks_fm_red=scf_env%scf_work1_red(ispin), &
584 ortho_red=scf_env%ortho_red, &
585 work_red=scf_env%scf_work2_red)
590 work=scf_env%scf_work2, &
591 do_level_shift=do_level_shift, &
592 level_shift=scf_control%level_shift, &
593 use_jacobi=use_jacobi, &
594 jacobi_threshold=scf_control%diagonalization%jacobi_threshold)
599 IF (owns_ortho)
DEALLOCATE (ortho)
616 matrix_s, scf_control, scf_section, &
620 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(INOUT) :: mos
621 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s
624 LOGICAL,
INTENT(INOUT) :: diis_step
628 INTEGER :: ispin, nspin
629 REAL(kind=
dp) :: total_zeff_corr
631 nspin =
SIZE(matrix_ks)
634 matrix_s, scf_control, scf_section, diis_step)
636 total_zeff_corr = 0.0_dp
637 total_zeff_corr = scf_env%sum_zeff_corr
639 IF (abs(total_zeff_corr) > 0.0_dp)
THEN
641 smear=scf_control%smear, tot_zeff_corr=total_zeff_corr)
643 IF (
PRESENT(probe) .EQV. .true.)
THEN
644 scf_control%smear%do_smear = .false.
646 smear=scf_control%smear, &
649 IF (.NOT. scf_control%gce%do_gce)
THEN
651 smear=scf_control%smear)
654 smear=scf_control%smear, &
662 scf_env%p_mix_new(ispin, 1)%matrix)
689 diis_step, diis_error, qs_env, probe, added_mos_auto_grow, potential)
691 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks, matrix_s
695 LOGICAL,
INTENT(IN) :: update_p
696 LOGICAL,
INTENT(INOUT) :: diis_step
697 REAL(
dp),
INTENT(INOUT),
OPTIONAL :: diis_error
701 LOGICAL,
INTENT(OUT),
OPTIONAL :: added_mos_auto_grow
702 REAL(
dp),
INTENT(IN),
OPTIONAL,
TARGET :: potential(:, :)
704 CHARACTER(len=*),
PARAMETER :: routinen =
'do_general_diag_kp'
706 COMPLEX(KIND=dp),
ALLOCATABLE,
DIMENSION(:) :: coeffs
707 REAL(
dp),
POINTER :: effective_u(:, :), adiis_u(:, :)
708 INTEGER :: cdiis_ncall, handle, ib, ikp, ispin, kplocal, kpmax, &
709 lattice_fft, nb, nkp, nspin, omp_threads, nworkers, nentry
710 INTEGER,
DIMENSION(2) :: kp_range
711 INTEGER,
DIMENSION(3) :: nkp_grid
712 INTEGER,
DIMENSION(:, :),
POINTER :: kp_dist
713 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
714 LOGICAL :: adiis_cdiis, cache_smat, cdiis_step, do_diis, my_added_mos_auto_grow, prepared_ops, prepared_part, &
715 reuse_smat, spin_grid_fft, use_adiis, use_grid_fft, use_local_kpoints,
use_real_wfn
716 REAL(kind=
dp) :: diis_weight
717 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues
718 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: xkp
719 TYPE(
cp_cfm_type),
POINTER :: cksmat, cmos, csmat, cwork
720 TYPE(kp_diag_workspace_type),
ALLOCATABLE,
TARGET :: workspace(:)
724 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: fmwork
726 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: adiis_ks, effective_ks
738 CALL timeset(routinen, handle)
740 my_added_mos_auto_grow = .false.
741 IF (
PRESENT(added_mos_auto_grow)) added_mos_auto_grow = .false.
743 NULLIFY (adiis_ks, effective_ks, sab_nl)
745 kp_dist=kp_dist, sab_nl=sab_nl, &
746 cell_to_index=cell_to_index, nkp_grid=nkp_grid, lattice_fft=lattice_fft)
747 cpassert(
ASSOCIATED(sab_nl))
748 kplocal = kp_range(2) - kp_range(1) + 1
749 kpmax = maxval(kp_dist(2, :) - kp_dist(1, :) + 1)
755 cpassert(
ASSOCIATED(scf_env%scf_subspace_buffer))
757 adiis_cdiis = .false.
758 IF (use_adiis .AND.
ASSOCIATED(kpoints%scf_diis_buffer))
THEN
759 IF (scf_env%iter_count > 1 .AND. .NOT. scf_env%skip_diis .AND. &
760 .NOT. scf_env%adiis_check_next .AND. &
761 .NOT. scf_env%scf_subspace_buffer%last_restart .AND. &
762 scf_env%scf_subspace_buffer%nstored > 0 .AND. &
763 PRESENT(diis_error) .AND.
PRESENT(qs_env))
THEN
764 adiis_cdiis = scf_env%iter_delta < scf_control%eps_diis .OR. &
765 kpoints%scf_diis_buffer%ncall > 0
768 IF ((.NOT. use_adiis .AND. scf_env%iter_count > 1 .AND. .NOT. scf_env%skip_diis .AND. &
769 .NOT.
use_real_wfn .AND.
PRESENT(diis_error) .AND.
PRESENT(qs_env)) .OR. &
770 adiis_cdiis) do_diis = .true.
772 adiis_ks => matrix_ks
774 IF (
ALLOCATED(kpoints%lowdin_v)) adiis_u => kpoints%lowdin_v
776 IF (scf_env%scf_subspace_buffer%use_combined_fock)
THEN
777 adiis_ks => scf_env%scf_subspace_buffer%combined_fock
778 IF (
ASSOCIATED(adiis_u)) adiis_u => scf_env%scf_subspace_buffer%combined_aux
781 effective_ks => matrix_ks
782 NULLIFY (effective_u)
783 IF (
ALLOCATED(kpoints%lowdin_v)) effective_u => kpoints%lowdin_v
784 IF (
PRESENT(potential))
THEN
785 cpassert(.NOT. update_p)
786 effective_u => potential
788 IF (use_adiis .AND. .NOT. adiis_cdiis)
THEN
789 effective_ks => adiis_ks
790 effective_u => adiis_u
792 IF (use_adiis .AND. .NOT. do_diis)
THEN
793 scf_env%scf_subspace_buffer%diis_weight = 0.0_dp
794 IF (
ASSOCIATED(kpoints%scf_diis_buffer))
THEN
795 IF (kpoints%scf_diis_buffer%ncall > 0)
CALL qs_diis_b_clear_kp(kpoints%scf_diis_buffer)
799 para_env => kpoints%blacs_env_all%para_env
800 nspin =
SIZE(matrix_ks, 1)
804 use_local_kpoints = kpoints%para_env_kp%num_pe == 1 .AND. .NOT.
use_real_wfn
806 IF (para_env%num_pe == 1 .AND. omp_threads == 1)
THEN
808 use_local_kpoints = .false.
813 NULLIFY (scf_section)
817 fmwork => scf_env%scf_work1
823 CALL mpools_get(mpools, ao_ao_fm_pools=ao_ao_fm_pools)
834 cache_smat = para_env%num_pe > 1 .AND. update_p .AND. .NOT.
use_real_wfn
837 reuse_smat =
ALLOCATED(kpoints%scf_smat)
838 IF (.NOT. reuse_smat)
THEN
839 ALLOCATE (kpoints%scf_smat(kplocal))
844 cpassert(
SIZE(kpoints%scf_smat) == kplocal)
848 prepared_ops = .false.
850 IF (para_env%num_pe > 1 .OR. use_local_kpoints)
THEN
852 IF (.NOT. reuse_smat)
THEN
854 prepared_ops = prepared_ops .AND. prepared_part
858 use_local_kpoints = use_local_kpoints .AND. prepared_ops
861 IF (use_local_kpoints)
THEN
862 nworkers = min(omp_threads, kplocal)
866 kp => kpoints%kp_env(1)%kpoint_env
871 mo_struct => kp%mos(1)%cmo_coeff%matrix_struct
873 CALL kp_diag_workspaces_create(workspace, nworkers, matrix_struct, mo_struct, nentry, &
874 use_local_kpoints, scf_env%cholesky_method ==
cholesky_off)
875 cksmat => workspace(1)%cksmat
876 csmat => workspace(1)%csmat
877 cwork => workspace(1)%cwork
878 cmos => workspace(1)%cmos
884 ALLOCATE (ks_grid(nspin))
885 SELECT CASE (lattice_fft)
887 use_grid_fft = nkp >= 27
889 use_grid_fft = .true.
891 use_grid_fft = .false.
893 cpabort(
"Unknown lattice FFT selection mode")
895 IF (prepared_ops) use_grid_fft = .false.
897 IF (use_grid_fft)
THEN
899 CALL dbcsr_create(rmatrix, template=matrix_ks(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
902 IF (use_grid_fft .AND. .NOT. reuse_smat)
THEN
904 cell_to_index, sab_nl, use_grid_fft, &
905 max_storage_bytes=512_int_8*1024_int_8**2/int(nspin + 1,
int_8))
907 IF (use_grid_fft)
THEN
910 cell_to_index, sab_nl, spin_grid_fft, &
911 max_storage_bytes=512_int_8*1024_int_8**2/int(nspin + 1,
int_8))
912 use_grid_fft = use_grid_fft .AND. spin_grid_fft
915 IF (.NOT. use_grid_fft)
THEN
923 IF (.NOT. use_local_kpoints)
THEN
927 ks_grid(ispin), use_grid_fft, matrix_row=ispin)
928 IF (.NOT. cache_smat .OR. (.NOT. reuse_smat .AND. ispin == 1))
THEN
940 cdiis_ncall = kpoints%scf_diis_buffer%ncall
943 IF (use_local_kpoints)
THEN
944 CALL kp_diag_local_phase(op_ctx, kpoints, workspace, scf_env, scf_control, nspin, &
945 cache_smat, reuse_smat, use_adiis, ib, .true., 1.0_dp, potential=effective_u)
949 CALL harvest_operators(ikp, ispin)
950 IF (ikp > kplocal) cycle
953 local=.false., gemm_ctx=workspace(1)%gemm_ctx)
960 ALLOCATE (coeffs(nb))
961 CALL qs_diis_b_step_kp(kpoints%scf_diis_buffer, coeffs, ib, nb, scf_env%iter_delta, diis_error, &
962 cdiis_step, scf_control%eps_diis, nspin, nkp, kplocal, &
963 merge(2, scf_control%nmixing, use_adiis), &
964 scf_section, kpoints%para_env_inter_kp)
967 diis_weight = scf_env%scf_subspace_buffer%diis_weight
968 IF (.NOT. ieee_is_finite(diis_error) .OR. diis_error >= scf_control%eps_diis)
THEN
970 IF (cdiis_ncall < kpoints%scf_diis_buffer%nbuffer)
THEN
972 kpoints%scf_diis_buffer%ncall = cdiis_ncall
980 diis_weight = min(1.0_dp, diis_weight + 0.5_dp)
985 scf_env%scf_subspace_buffer%diis_weight = diis_weight
986 diis_step = cdiis_step .AND. diis_weight >= 1.0_dp
987 IF (.NOT. diis_step) diis_error = scf_env%scf_subspace_buffer%last_old_fock_weight
989 diis_step = cdiis_step
994 IF (use_adiis .AND. diis_weight < 1.0_dp)
THEN
997 use_local_kpoints = use_local_kpoints .AND. prepared_part
1001 IF (.NOT. update_p .OR. use_adiis) diis_step = .false.
1004 IF (use_local_kpoints)
THEN
1006 IF (do_diis) effective_u => adiis_u
1007 CALL kp_diag_local_phase(op_ctx, kpoints, workspace, scf_env, scf_control, nspin, &
1008 cache_smat, reuse_smat, use_adiis, ib, .false., diis_weight, coeffs, effective_u)
1013 IF (use_adiis .AND. diis_weight < 1.0_dp)
THEN
1015 use_grid=.false., matrix_row=ispin)
1017 IF (ikp <= kplocal .AND.
ASSOCIATED(adiis_u))
THEN
1018 CALL lowdin_kp_apply(kpoints%kp_env(ikp)%kpoint_env, adiis_u(:, ispin), cmat=cwork)
1021 IF (ikp > kplocal) cycle
1022 CALL cp_cfm_to_cfm(kpoints%scf_diis_buffer%smat(ikp), csmat)
1023 CALL kp_diis_candidate(kpoints, ikp, ispin, coeffs, diis_weight, cksmat, cwork)
1029 CALL harvest_operators(ikp, ispin)
1030 IF (ikp > kplocal) cycle
1032 kp => kpoints%kp_env(ikp)%kpoint_env
1034 CALL get_mo_set(kp%mos(ispin), mo_coeff=mo_coeff, eigenvalues=eigenvalues)
1035 IF (use_adiis)
CALL shift_candidate_real(rksmat, rsmat, kp%mos(ispin), &
1038 CALL cp_fm_geeig_canon(rksmat, rsmat, mo_coeff, eigenvalues, fmlocal, scf_control%eps_eigval)
1040 CALL cp_fm_geeig(rksmat, rsmat, mo_coeff, eigenvalues, fmlocal)
1043 CALL kp_solve_complex(kp%mos(ispin), workspace(1), scf_env, scf_control, use_adiis, .false.)
1048 IF (
ALLOCATED(coeffs))
DEALLOCATE (coeffs)
1054 IF (
PRESENT(probe) .EQV. .true.)
THEN
1055 scf_control%smear%do_smear = .false.
1060 added_mos_auto=scf_control%added_mos_auto, &
1061 added_mos_auto_grow=my_added_mos_auto_grow)
1063 IF (my_added_mos_auto_grow)
THEN
1064 IF (
PRESENT(added_mos_auto_grow)) added_mos_auto_grow = .true.
1070 matrix_s(1, 1)%matrix, sab_nl, fmwork, overlap_rs=matrix_s)
1079 DEALLOCATE (ks_grid)
1085 IF (
ALLOCATED(workspace))
CALL kp_diag_workspaces_release(workspace)
1088 CALL timestop(handle)
1099 SUBROUTINE harvest_operators(round, spin)
1100 INTEGER,
INTENT(IN) :: round, spin
1105 IF (round <= kplocal .AND.
ASSOCIATED(effective_u))
THEN
1106 CALL lowdin_kp_apply(kpoints%kp_env(round)%kpoint_env, effective_u(:, spin), rmat=rksmat)
1108 IF (round <= kplocal .AND. do_diis)
THEN
1114 IF (round <= kplocal .AND.
ASSOCIATED(effective_u))
THEN
1115 CALL lowdin_kp_apply(kpoints%kp_env(round)%kpoint_env, effective_u(:, spin), cmat=cksmat)
1117 IF (.NOT. cache_smat .OR. (.NOT. reuse_smat .AND. spin == 1))
THEN
1122 IF (round > kplocal)
RETURN
1123 kp => kpoints%kp_env(round)%kpoint_env
1124 IF (cache_smat)
THEN
1125 IF (.NOT. reuse_smat .AND. spin == 1)
THEN
1131 END SUBROUTINE harvest_operators
1152 SUBROUTINE kp_diag_local_phase(ctx, kpoints, workspace, scf_env, scf_control, nspin, &
1153 cache_smat, reuse_smat, use_adiis, ib, store_error, diis_weight, coeffs, potential)
1156 TYPE(kp_diag_workspace_type),
TARGET,
INTENT(INOUT) :: workspace(:)
1159 INTEGER,
INTENT(IN) :: nspin, ib
1160 LOGICAL,
INTENT(IN) :: cache_smat, reuse_smat, use_adiis, store_error
1161 REAL(kind=
dp),
INTENT(IN) :: diis_weight
1162 COMPLEX(KIND=dp),
OPTIONAL,
INTENT(IN) :: coeffs(:)
1163 REAL(
dp),
OPTIONAL,
INTENT(IN) :: potential(:, :)
1165 INTEGER :: ik, ikp, ispin, kplocal, nworkers, thread
1166 LOGICAL :: build_h, build_s
1168 TYPE(kp_diag_workspace_type),
POINTER :: work
1170 kplocal = kpoints%kp_range(2) - kpoints%kp_range(1) + 1
1171 nworkers =
SIZE(workspace)
1172 build_s = .NOT.
PRESENT(coeffs) .AND. .NOT. reuse_smat
1173 build_h = .NOT.
PRESENT(coeffs) .OR. diis_weight < 1.0_dp
1183 ik = kpoints%kp_range(1) + ikp - 1
1184 kp => kpoints%kp_env(ikp)%kpoint_env
1185 work => workspace(thread)
1191 IF (
PRESENT(coeffs))
THEN
1193 IF (
PRESENT(potential))
CALL lowdin_kp_apply(kp, potential(:, ispin), cmat=work%csmat_base)
1196 IF (
PRESENT(potential))
CALL lowdin_kp_apply(kp, potential(:, ispin), cmat=work%cksmat)
1199 IF (
PRESENT(coeffs))
THEN
1200 CALL cp_cfm_to_cfm(kpoints%scf_diis_buffer%smat(ikp), work%csmat)
1201 CALL kp_diis_candidate(kpoints, ikp, ispin, coeffs, diis_weight, work%cksmat, work%csmat_base)
1203 IF (reuse_smat)
THEN
1208 IF (cache_smat .AND. .NOT. reuse_smat .AND. ispin == 1)
THEN
1212 IF (store_error)
THEN
1214 ispin, ikp, work%cmos, local=.true., gemm_ctx=work%gemm_ctx)
1216 CALL kp_solve_complex(kp%mos(ispin), work, scf_env, scf_control, use_adiis, .true.)
1222 END SUBROUTINE kp_diag_local_phase
1234 SUBROUTINE kp_diis_candidate(kpoints, ikp, ispin, coeffs, weight, fock, adiis_fock)
1236 INTEGER,
INTENT(IN) :: ikp, ispin
1237 COMPLEX(KIND=dp),
INTENT(IN) :: coeffs(:)
1238 REAL(kind=
dp),
INTENT(IN) :: weight
1245 DO jb = 1,
SIZE(coeffs)
1249 cmplx(1.0_dp - weight, kind=
dp), adiis_fock)
1250 END SUBROUTINE kp_diis_candidate
1261 SUBROUTINE kp_solve_complex(mos, work, scf_env, scf_control, use_adiis, local)
1263 TYPE(kp_diag_workspace_type),
INTENT(INOUT) :: work
1266 LOGICAL,
INTENT(IN) :: use_adiis, local
1268 REAL(kind=
dp),
POINTER :: eigenvalues(:)
1270 CALL get_mo_set(mos, eigenvalues=eigenvalues)
1271 IF (use_adiis)
CALL shift_candidate_complex(work%cksmat, work%csmat, mos, work%cmos, work%cwork, &
1276 scf_control%eps_eigval, ws=work%solver)
1278 CALL cp_cfm_geeig_canon(work%cksmat, work%csmat, mos%cmo_coeff, eigenvalues, work%cwork, &
1279 scf_control%eps_eigval)
1283 CALL cp_cfm_geeig_local(work%cksmat, work%csmat, mos%cmo_coeff, eigenvalues, ws=work%solver)
1285 CALL cp_cfm_geeig(work%cksmat, work%csmat, mos%cmo_coeff, eigenvalues, work%cwork)
1288 END SUBROUTINE kp_solve_complex
1300 SUBROUTINE kp_diag_workspaces_create(workspace, nworkers, matrix_struct, mo_struct, nentry, local, canonical)
1301 TYPE(kp_diag_workspace_type),
ALLOCATABLE, &
1302 INTENT(OUT) :: workspace(:)
1303 INTEGER,
INTENT(IN) :: nworkers
1305 INTEGER,
INTENT(IN) :: nentry
1306 LOGICAL,
INTENT(IN) :: local, canonical
1310 ALLOCATE (workspace(nworkers))
1316 IF (.NOT. local) cycle
1319 ALLOCATE (workspace(i)%phase(1, nentry))
1320 n = matrix_struct%nrow_global
1325 workspace(i)%csmat%local_data)
1328 END SUBROUTINE kp_diag_workspaces_create
1334 SUBROUTINE kp_diag_workspaces_release(workspace)
1335 TYPE(kp_diag_workspace_type),
ALLOCATABLE, &
1336 INTENT(INOUT) :: workspace(:)
1340 DO i = 1,
SIZE(workspace)
1341 CALL workspace(i)%gemm_ctx%destroy()
1348 DEALLOCATE (workspace)
1349 END SUBROUTINE kp_diag_workspaces_release
1366 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks, matrix_s
1368 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: fmwork
1370 CHARACTER(len=*),
PARAMETER :: routinen =
'diag_kp_basic'
1372 INTEGER :: handle, ikp, ispin, kplocal, kpmax, nspin
1373 INTEGER,
DIMENSION(2) :: kp_range
1374 INTEGER,
DIMENSION(:, :),
POINTER :: kp_dist
1376 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues
1388 CALL timeset(routinen, handle)
1392 kp_dist=kp_dist, sab_nl=sab_nl)
1393 cpassert(
ASSOCIATED(sab_nl))
1394 kplocal = kp_range(2) - kp_range(1) + 1
1395 kpmax = maxval(kp_dist(2, :) - kp_dist(1, :) + 1)
1399 CALL mpools_get(mpools, ao_ao_fm_pools=ao_ao_fm_pools)
1411 kp => kpoints%kp_env(1)%kpoint_env
1412 mo_struct => kp%mos(1)%cmo_coeff%matrix_struct
1416 nspin =
SIZE(matrix_ks, 1)
1423 use_grid=.false., matrix_row=ispin)
1442 IF (ikp > kplocal) cycle
1443 kp => kpoints%kp_env(ikp)%kpoint_env
1445 CALL get_mo_set(kp%mos(ispin), mo_coeff=mo_coeff, eigenvalues=eigenvalues)
1446 CALL cp_fm_geeig(rksmat, rsmat, mo_coeff, eigenvalues, fmlocal)
1448 CALL get_mo_set(kp%mos(ispin), eigenvalues=eigenvalues)
1449 CALL cp_cfm_geeig(cksmat, csmat, cmos, eigenvalues, cwork)
1468 CALL timestop(handle)
1488 ks_env, scf_section, scf_control)
1493 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(INOUT) :: mos
1499 CHARACTER(LEN=*),
PARAMETER :: routinen =
'do_scf_diag_subspace'
1500 REAL(kind=
dp),
PARAMETER :: rone = 1.0_dp, rzero = 0.0_dp
1502 INTEGER :: handle, i, iloop, ispin, nao, nmo, &
1504 LOGICAL :: converged
1505 REAL(
dp) :: ene_diff, ene_old, iter_delta, max_val, &
1506 sum_band, sum_val, t1, t2
1507 REAL(kind=
dp),
DIMENSION(:),
POINTER :: mo_eigenvalues, mo_occupations
1508 TYPE(
cp_1d_r_p_type),
ALLOCATABLE,
DIMENSION(:) :: eval_first, occ_first
1510 TYPE(
cp_fm_type),
POINTER :: c0, chc, evec, mo_coeff
1512 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s, rho_ao
1513 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: rho_ao_kp
1519 CALL timeset(routinen, handle)
1520 NULLIFY (c0, chc, energy, evec, matrix_ks, mo_coeff, mo_eigenvalues, &
1521 mo_occupations, dft_control, rho_ao, rho_ao_kp)
1525 extension=
".scfLog")
1529 CALL qs_rho_get(rho, rho_ao=rho_ao, rho_ao_kp=rho_ao_kp)
1531 ALLOCATE (eval_first(nspin))
1532 ALLOCATE (occ_first(nspin))
1536 eigenvalues=mo_eigenvalues, &
1537 occupation_numbers=mo_occupations)
1538 ALLOCATE (eval_first(ispin)%array(nmo))
1539 ALLOCATE (occ_first(ispin)%array(nmo))
1540 eval_first(ispin)%array(1:nmo) = mo_eigenvalues(1:nmo)
1541 occ_first(ispin)%array(1:nmo) = mo_occupations(1:nmo)
1546 CALL dbcsr_copy(subspace_env%p_matrix_store(ispin)%matrix, rho_ao(ispin)%matrix)
1547 CALL dbcsr_copy(rho_ao(ispin)%matrix, scf_env%p_mix_new(ispin, 1)%matrix)
1550 subspace_env%p_matrix_mix => scf_env%p_mix_new
1552 NULLIFY (matrix_ks, energy, para_env, matrix_s)
1554 matrix_ks=matrix_ks, &
1556 matrix_s=matrix_s, &
1557 para_env=para_env, &
1558 dft_control=dft_control)
1562 CALL mixing_allocate(qs_env, subspace_env%mixing_method, scf_env%p_mix_new, &
1563 scf_env%p_delta, nspin, subspace_env%mixing_store)
1564 IF (dft_control%qs_control%gapw)
THEN
1565 CALL get_qs_env(qs_env=qs_env, rho_atom_set=rho_atom)
1566 CALL mixing_init(subspace_env%mixing_method, rho, subspace_env%mixing_store, &
1567 para_env, rho_atom=rho_atom)
1568 ELSE IF (dft_control%qs_control%dftb .OR. dft_control%qs_control%xtb)
THEN
1570 ELSE IF (dft_control%qs_control%semi_empirical)
THEN
1571 cpabort(
'SE Code not possible')
1573 CALL mixing_init(subspace_env%mixing_method, rho, subspace_env%mixing_store, para_env)
1579 IF (output_unit > 0)
THEN
1580 WRITE (output_unit,
"(/T19,A)")
'<<<<<<<<< SUBSPACE ROTATION <<<<<<<<<<'
1581 WRITE (output_unit,
"(T4,A,T13,A,T21,A,T38,A,T51,A,T65,A/,T4,A)") &
1582 "In-step",
"Time",
"Convergence",
"Band ene.",
"Total ene.",
"Energy diff.", repeat(
"-", 74)
1590 DO iloop = 1, subspace_env%max_iter
1593 ene_old = energy%total
1597 just_energy=.false., print_active=.false.)
1602 DO ispin = 1,
SIZE(matrix_ks)
1606 eigenvalues=mo_eigenvalues, &
1607 occupation_numbers=mo_occupations, &
1611 chc => subspace_env%chc_mat(ispin)
1612 evec => subspace_env%c_vec(ispin)
1613 c0 => subspace_env%c0(ispin)
1617 CALL parallel_gemm(
'T',
'N', nmo, nmo, nao, rone, c0, work, rzero, chc)
1623 CALL parallel_gemm(
'N',
'N', nao, nmo, nmo, rone, c0, evec, rzero, mo_coeff)
1625 IF (.NOT. scf_control%gce%do_gce)
THEN
1627 smear=scf_control%smear)
1630 smear=scf_control%smear, &
1631 gce=scf_control%gce)
1636 subspace_env%p_matrix_mix(ispin, 1)%matrix)
1639 sum_band = sum_band + mo_eigenvalues(i)*mo_occupations(i)
1647 scf_env%mixing_store, rho_ao_kp, para_env, iter_delta, iloop)
1650 subspace_env%p_matrix_mix, delta=iter_delta)
1655 CALL dbcsr_copy(rho_ao(ispin)%matrix, subspace_env%p_matrix_mix(ispin, 1)%matrix)
1661 CALL gspace_mixing(qs_env, scf_env%mixing_method, subspace_env%mixing_store, &
1662 rho, para_env, scf_env%iter_count)
1665 ene_diff = energy%total - ene_old
1666 converged = (abs(ene_diff) < subspace_env%eps_ene .AND. &
1667 iter_delta < subspace_env%eps_adapt*scf_env%iter_delta)
1669 IF (output_unit > 0)
THEN
1670 WRITE (output_unit,
"(T4,I5,T11,F8.3,T18,E14.4,T34,F12.5,T46,F16.8,T62,E14.4)") &
1671 iloop, t2 - t1, iter_delta, sum_band, energy%total, ene_diff
1675 IF (output_unit > 0)
WRITE (output_unit,
"(T10,A,I6,A,/)") &
1676 " Reached convergence in ", iloop,
" iterations "
1682 NULLIFY (subspace_env%p_matrix_mix)
1685 CALL dbcsr_copy(scf_env%p_mix_new(ispin, 1)%matrix, rho_ao(ispin)%matrix)
1686 CALL dbcsr_copy(rho_ao(ispin)%matrix, subspace_env%p_matrix_store(ispin)%matrix)
1688 DEALLOCATE (eval_first(ispin)%array, occ_first(ispin)%array)
1690 DEALLOCATE (eval_first, occ_first)
1692 CALL timestop(handle)
1706 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(IN) :: mos
1708 CHARACTER(LEN=*),
PARAMETER :: routinen =
'diag_subspace_allocate'
1710 INTEGER :: handle, i, ispin, nmo, nspin
1717 CALL timeset(routinen, handle)
1719 NULLIFY (sab_orb, matrix_s)
1720 CALL get_qs_env(qs_env=qs_env, sab_orb=sab_orb, &
1725 IF (.NOT.
ASSOCIATED(subspace_env%p_matrix_store))
THEN
1729 ALLOCATE (subspace_env%p_matrix_store(i)%matrix)
1730 CALL dbcsr_create(matrix=subspace_env%p_matrix_store(i)%matrix, template=matrix_s(1)%matrix, &
1731 name=
"DENSITY_STORE", matrix_type=dbcsr_type_symmetric)
1734 CALL dbcsr_set(subspace_env%p_matrix_store(i)%matrix, 0.0_dp)
1739 ALLOCATE (subspace_env%chc_mat(nspin))
1740 ALLOCATE (subspace_env%c_vec(nspin))
1741 ALLOCATE (subspace_env%c0(nspin))
1744 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff, nmo=nmo)
1745 CALL cp_fm_create(subspace_env%c0(ispin), mo_coeff%matrix_struct)
1746 NULLIFY (fm_struct_tmp)
1748 para_env=mo_coeff%matrix_struct%para_env, &
1749 context=mo_coeff%matrix_struct%context)
1750 CALL cp_fm_create(subspace_env%chc_mat(ispin), fm_struct_tmp,
"chc")
1751 CALL cp_fm_create(subspace_env%c_vec(ispin), fm_struct_tmp,
"vec")
1755 CALL timestop(handle)
1772 scf_section, diis_step)
1775 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(INOUT) :: mos
1779 LOGICAL,
INTENT(INOUT) :: diis_step
1781 INTEGER :: ispin, nspin
1782 LOGICAL :: do_level_shift, use_jacobi
1783 REAL(kind=
dp) :: diis_error
1785 nspin =
SIZE(matrix_ks)
1790 IF (scf_env%iter_count > 1 .AND. .NOT. scf_env%skip_diis)
THEN
1791 CALL qs_diis_b_step(scf_env%scf_diis_buffer, mos, scf_env%scf_work1, &
1792 scf_env%scf_work2, scf_env%iter_delta, diis_error, diis_step, &
1793 scf_control%eps_diis, scf_control%nmixing, &
1794 scf_section=scf_section)
1799 IF ((scf_env%iter_count > 1) .AND. (scf_env%iter_delta < scf_control%diagonalization%eps_jacobi))
THEN
1802 use_jacobi = .false.
1805 do_level_shift = ((scf_control%level_shift /= 0.0_dp) .AND. &
1806 ((scf_control%density_guess ==
core_guess) .OR. (scf_env%iter_count > 1)))
1808 scf_env%iter_param = diis_error
1809 IF (use_jacobi)
THEN
1810 scf_env%iter_method =
"DIIS/Jacobi"
1812 scf_env%iter_method =
"DIIS/Diag."
1815 IF (scf_env%mixing_method == 1)
THEN
1816 scf_env%iter_param = scf_env%p_mix_alpha
1817 IF (use_jacobi)
THEN
1818 scf_env%iter_method =
"P_Mix/Jacobi"
1820 scf_env%iter_method =
"P_Mix/Diag."
1822 ELSE IF (scf_env%mixing_method > 1)
THEN
1823 scf_env%iter_param = scf_env%mixing_store%alpha
1824 IF (use_jacobi)
THEN
1825 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Jacobi"
1827 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Diag."
1831 scf_env%iter_delta = 0.0_dp
1835 mo_set=mos(ispin), &
1836 work=scf_env%scf_work2, &
1837 do_level_shift=do_level_shift, &
1838 level_shift=scf_control%level_shift, &
1839 use_jacobi=use_jacobi, &
1840 jacobi_threshold=scf_control%diagonalization%jacobi_threshold)
1843 IF (.NOT. scf_control%gce%do_gce)
THEN
1845 smear=scf_control%smear)
1848 smear=scf_control%smear, &
1849 gce=scf_control%gce)
1855 scf_env%p_mix_new(ispin, 1)%matrix)
1874 scf_control, scf_section, diis_step)
1877 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(INOUT) :: mos
1878 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s
1881 LOGICAL,
INTENT(INOUT) :: diis_step
1883 INTEGER :: homo, ispin, nmo, nspin
1884 REAL(kind=
dp) :: diis_error, eps_iter
1885 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues
1888 NULLIFY (eigenvalues)
1890 nspin =
SIZE(matrix_ks)
1894 scf_env%scf_work1(ispin))
1897 IF ((scf_env%iter_count > 1) .AND. (.NOT. scf_env%skip_diis))
THEN
1898 CALL qs_diis_b_step(scf_env%scf_diis_buffer, mos, scf_env%scf_work1, &
1899 scf_env%scf_work2, scf_env%iter_delta, diis_error, diis_step, &
1900 scf_control%eps_diis, scf_control%nmixing, &
1901 s_matrix=matrix_s, &
1902 scf_section=scf_section)
1907 eps_iter = scf_control%diagonalization%eps_iter
1909 scf_env%iter_param = diis_error
1910 scf_env%iter_method =
"DIIS/OTdiag"
1913 matrix_ks(ispin)%matrix, keep_sparsity=.true.)
1915 eps_iter = max(eps_iter, scf_control%diagonalization%eps_adapt*diis_error)
1917 IF (scf_env%mixing_method == 1)
THEN
1918 scf_env%iter_param = scf_env%p_mix_alpha
1919 scf_env%iter_method =
"P_Mix/OTdiag."
1920 ELSE IF (scf_env%mixing_method > 1)
THEN
1921 scf_env%iter_param = scf_env%mixing_store%alpha
1922 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/OTdiag."
1926 scf_env%iter_delta = 0.0_dp
1930 mo_coeff=mo_coeff, &
1931 eigenvalues=eigenvalues, &
1935 matrix_s=matrix_s(1)%matrix, &
1936 matrix_c_fm=mo_coeff, &
1938 min(ispin,
SIZE(scf_env%ot_preconditioner)))%preconditioner, &
1939 eps_gradient=eps_iter, &
1940 iter_max=scf_control%diagonalization%max_iter, &
1942 ot_settings=scf_control%diagonalization%ot_settings)
1944 evals_arg=eigenvalues, &
1947 mos(ispin)%mo_coeff_b)
1952 smear=scf_control%smear)
1957 scf_env%p_mix_new(ispin, 1)%matrix)
1973 SUBROUTINE do_ot_diag_kp(matrix_ks, matrix_s, matrix_t, kpoints, scf_env, scf_control, &
1974 diis_step, added_mos_auto_grow)
1975 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks, matrix_s, matrix_t
1979 LOGICAL,
INTENT(INOUT) :: diis_step
1980 LOGICAL,
INTENT(OUT) :: added_mos_auto_grow
1982 INTEGER :: ikp, ispin, ks_spin, nspin
1984 REAL(kind=
dp) :: eps_iter
1985 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues
1988 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: fmwork
1990 TYPE(
dbcsr_type),
POINTER :: matrix_h_im, matrix_h_re, matrix_s_im, &
1991 matrix_s_re, matrix_t_im, matrix_t_re
1996 NULLIFY (coeff_re, eigenvalues, fmwork, kp, matrix_h_im, matrix_h_re, &
1997 matrix_s_im, matrix_s_re, matrix_t_im, matrix_t_re, sab_nl)
1998 added_mos_auto_grow = .false.
2000 eps_iter = scf_control%diagonalization%eps_iter
2001 nspin =
SIZE(matrix_ks, 1)
2002 store_kinetic = scf_control%diagonalization%ot_settings%preconditioner_type == &
2004 IF (store_kinetic)
THEN
2005 cpassert(
ASSOCIATED(matrix_t))
2008 cpassert(
ASSOCIATED(sab_nl))
2012 IF (scf_env%iter_count <= 1)
THEN
2016 IF (store_kinetic)
THEN
2022 scf_env%iter_delta = 0.0_dp
2023 DO ikp = 1,
SIZE(kpoints%kp_env)
2024 kp => kpoints%kp_env(ikp)%kpoint_env
2025 cpassert(
ASSOCIATED(kp%ot_hmat) .AND.
ASSOCIATED(kp%ot_smat))
2026 IF (
SIZE(kp%ot_smat) >= 2)
THEN
2028 kp%ot_smat(1), kp%ot_smat(2), &
2029 matrix_s_re, matrix_s_im)
2032 kp%ot_smat(1), kp%ot_smat(1), &
2033 matrix_s_re, matrix_s_im)
2036 IF (store_kinetic)
THEN
2037 cpassert(
ASSOCIATED(kp%ot_tmat))
2038 IF (
SIZE(kp%ot_tmat) >= 2)
THEN
2040 kp%ot_tmat(1), kp%ot_tmat(2), &
2041 matrix_t_re, matrix_t_im)
2044 kp%ot_tmat(1), kp%ot_tmat(1), &
2045 matrix_t_re, matrix_t_im)
2050 ks_spin = min(ispin,
SIZE(kp%ot_hmat, 2))
2051 IF (
SIZE(kp%ot_hmat, 1) >= 2)
THEN
2053 kp%ot_hmat(1, ks_spin), kp%ot_hmat(2, ks_spin), &
2054 matrix_h_re, matrix_h_im)
2057 kp%ot_hmat(1, ks_spin), kp%ot_hmat(1, ks_spin), &
2058 matrix_h_re, matrix_h_im)
2061 CALL get_mo_set(kp%mos(ispin), eigenvalues=eigenvalues)
2063 CALL get_mo_set(kp%mos(ispin), mo_coeff=coeff_re)
2064 CALL cp_fm_create(coeff_im_work, coeff_re%matrix_struct, &
2065 name=
'real k-point OT imaginary work')
2069 matrix_s=matrix_s_re, matrix_s_im=matrix_s_im, &
2070 matrix_c_cfm=cmo_work, &
2071 eps_gradient=eps_iter, &
2072 iter_max=scf_control%diagonalization%max_iter, &
2073 eigenvalues=eigenvalues, silent=.true., &
2074 ot_settings=scf_control%diagonalization%ot_settings, &
2075 matrix_t=matrix_t_re, matrix_t_im=matrix_t_im, &
2076 mo_set=kp%mos(ispin))
2082 matrix_s=matrix_s_re, matrix_s_im=matrix_s_im, &
2083 matrix_c_cfm=kp%mos(ispin)%cmo_coeff, &
2084 eps_gradient=eps_iter, &
2085 iter_max=scf_control%diagonalization%max_iter, &
2086 eigenvalues=eigenvalues, silent=.true., &
2087 ot_settings=scf_control%diagonalization%ot_settings, &
2088 matrix_t=matrix_t_re, matrix_t_im=matrix_t_im, &
2089 mo_set=kp%mos(ispin))
2101 added_mos_auto=scf_control%added_mos_auto, &
2102 added_mos_auto_grow=added_mos_auto_grow)
2103 IF (added_mos_auto_grow)
RETURN
2106 fmwork => scf_env%scf_work1
2108 matrix_s(1, 1)%matrix, sab_nl, fmwork, overlap_rs=matrix_s)
2109 IF (scf_env%mixing_method == 0)
THEN
2110 scf_env%iter_method =
'NoMix/OTdiag.'
2111 ELSE IF (scf_env%mixing_method == 1)
THEN
2112 scf_env%iter_param = scf_env%p_mix_alpha
2113 scf_env%iter_method =
'P_Mix/OTdiag.'
2115 scf_env%iter_param = scf_env%mixing_store%alpha
2116 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
'/OTdiag.'
2138 scf_control, scf_section, diis_step, &
2146 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(IN) :: mos
2147 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s
2150 LOGICAL,
INTENT(INOUT) :: diis_step
2151 LOGICAL,
INTENT(IN) :: orthogonal_basis
2153 CHARACTER(LEN=*),
PARAMETER :: routinen =
'do_roks_diag'
2155 INTEGER :: handle, homoa, homob, imo, nalpha, nao, &
2157 REAL(kind=
dp) :: diis_error, level_shift_loc
2158 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eiga, eigb, occa, occb
2159 TYPE(
cp_fm_type),
POINTER :: ksa, ksb, mo2ao, moa, mob, ortho, work
2163 CALL timeset(routinen, handle)
2166 ortho => scf_env%ortho_m1
2168 ortho => scf_env%ortho
2170 work => scf_env%scf_work2
2172 ksa => scf_env%scf_work1(1)
2173 ksb => scf_env%scf_work1(2)
2186 occupation_numbers=occa, &
2193 occupation_numbers=occb, &
2198 IF ((scf_control%level_shift /= 0.0_dp) .AND. &
2199 ((scf_control%density_guess ==
core_guess) .OR. &
2201 (scf_env%iter_count > 1)))
THEN
2202 level_shift_loc = scf_control%level_shift
2204 level_shift_loc = 0.0_dp
2207 IF ((scf_env%iter_count > 1) .OR. &
2208 (scf_control%density_guess ==
core_guess) .OR. &
2214 CALL cp_fm_symm(
"L",
"U", nao, nao, 1.0_dp, ksa, moa, 0.0_dp, work)
2215 CALL parallel_gemm(
"T",
"N", nao, nao, nao, 1.0_dp, moa, work, 0.0_dp, ksa)
2217 CALL cp_fm_symm(
"L",
"U", nao, nao, 1.0_dp, ksb, moa, 0.0_dp, work)
2218 CALL parallel_gemm(
"T",
"N", nao, nao, nao, 1.0_dp, moa, work, 0.0_dp, ksb)
2229 cpabort(
"Unknown ROKS scheme requested")
2235 IF (orthogonal_basis)
THEN
2248 CALL parallel_gemm(
"N",
"T", nao, nao, nao, 1.0_dp, ksa, mo2ao, 0.0_dp, work)
2249 CALL parallel_gemm(
"N",
"N", nao, nao, nao, 1.0_dp, mo2ao, work, 0.0_dp, ksa)
2263 IF (scf_env%iter_count > 1)
THEN
2264 IF (orthogonal_basis)
THEN
2267 kc=scf_env%scf_work1, &
2269 delta=scf_env%iter_delta, &
2270 error_max=diis_error, &
2271 diis_step=diis_step, &
2272 eps_diis=scf_control%eps_diis, &
2273 scf_section=scf_section, &
2275 cpassert(scf_env%iter_delta == scf_env%iter_delta)
2279 kc=scf_env%scf_work1, &
2281 delta=scf_env%iter_delta, &
2282 error_max=diis_error, &
2283 diis_step=diis_step, &
2284 eps_diis=scf_control%eps_diis, &
2285 scf_section=scf_section, &
2286 s_matrix=matrix_s, &
2292 scf_env%iter_param = diis_error
2293 scf_env%iter_method =
"DIIS/Diag."
2295 IF (scf_env%mixing_method == 1)
THEN
2296 scf_env%iter_param = scf_env%p_mix_alpha
2297 scf_env%iter_method =
"P_Mix/Diag."
2298 ELSE IF (scf_env%mixing_method > 1)
THEN
2299 scf_env%iter_param = scf_env%mixing_store%alpha
2300 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Diag."
2304 scf_env%iter_delta = 0.0_dp
2306 IF (level_shift_loc /= 0.0_dp)
THEN
2311 CALL cp_fm_symm(
"L",
"U", nao, nao, 1.0_dp, ksa, moa, 0.0_dp, work)
2312 CALL parallel_gemm(
"T",
"N", nao, nao, nao, 1.0_dp, moa, work, 0.0_dp, ksa)
2316 DO imo = homob + 1, homoa
2319 DO imo = homoa + 1, nmo
2323 ELSE IF (.NOT. orthogonal_basis)
THEN
2326 SELECT CASE (scf_env%cholesky_method)
2332 "SOLVE", pos=
"RIGHT")
2334 "SOLVE", pos=
"LEFT", transa=
"T")
2338 "MULTIPLY", pos=
"RIGHT")
2340 "MULTIPLY", pos=
"LEFT", transa=
"T")
2342 CALL cp_fm_symm(
"L",
"U", nao, nao, 1.0_dp, ksa, ortho, 0.0_dp, work)
2343 CALL parallel_gemm(
"N",
"N", nao, nao, nao, 1.0_dp, ortho, work, 0.0_dp, ksa)
2354 IF (level_shift_loc /= 0.0_dp)
THEN
2357 CALL parallel_gemm(
"N",
"N", nao, nmo, nao, 1.0_dp, ortho, work, 0.0_dp, moa)
2359 IF (orthogonal_basis)
THEN
2362 SELECT CASE (scf_env%cholesky_method)
2368 CALL parallel_gemm(
"N",
"N", nao, nmo, nao, 1.0_dp, ortho, work, 0.0_dp, moa)
2375 IF (level_shift_loc /= 0.0_dp)
THEN
2376 DO imo = homob + 1, homoa
2377 eiga(imo) = eiga(imo) - 0.5_dp*level_shift_loc
2379 DO imo = homoa + 1, nmo
2380 eiga(imo) = eiga(imo) - level_shift_loc
2395 CALL timestop(handle)
2413 scf_control, scf_section, check_moconv_only)
2416 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(INOUT) :: mos
2420 LOGICAL,
INTENT(IN),
OPTIONAL :: check_moconv_only
2422 CHARACTER(LEN=*),
PARAMETER :: routinen =
'do_block_krylov_diag'
2423 REAL(kind=
dp),
PARAMETER :: rone = 1.0_dp, rzero = 0.0_dp
2425 INTEGER :: handle, homo, ispin, iter, nao, nmo, &
2427 LOGICAL :: converged, my_check_moconv_only
2428 REAL(
dp) :: eps_iter, t1, t2
2429 REAL(kind=
dp),
DIMENSION(:),
POINTER :: mo_eigenvalues
2430 TYPE(
cp_fm_type),
POINTER :: c0, c1, chc, evec, ks, mo_coeff, ortho, &
2435 CALL timeset(routinen, handle)
2438 extension=
".scfLog")
2440 my_check_moconv_only = .false.
2441 IF (
PRESENT(check_moconv_only)) my_check_moconv_only = check_moconv_only
2443 NULLIFY (mo_coeff, ortho, work, ks)
2444 NULLIFY (mo_eigenvalues)
2448 ortho => scf_env%ortho_m1
2450 ortho => scf_env%ortho
2452 work => scf_env%scf_work2
2454 DO ispin = 1,
SIZE(matrix_ks)
2456 scf_env%scf_work1(ispin))
2459 IF (scf_env%mixing_method == 1)
THEN
2460 scf_env%iter_param = scf_env%p_mix_alpha
2461 scf_env%iter_method =
"P_Mix/Lanczos"
2464 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Lanc."
2467 DO ispin = 1,
SIZE(matrix_ks)
2469 ks => scf_env%scf_work1(ispin)
2476 eigenvalues=mo_eigenvalues, &
2480 c0 => scf_env%krylov_space%mo_conv(ispin)
2481 c1 => scf_env%krylov_space%mo_refine(ispin)
2482 SELECT CASE (scf_env%cholesky_method)
2489 "SOLVE", pos=
"RIGHT")
2491 "SOLVE", pos=
"LEFT", transa=
"T")
2495 "MULTIPLY", pos=
"RIGHT")
2497 "MULTIPLY", pos=
"LEFT", transa=
"T")
2501 scf_env%krylov_space%nmo_nc = nmo
2502 scf_env%krylov_space%nmo_conv = 0
2505 IF (output_unit > 0)
THEN
2506 WRITE (output_unit,
"(/T15,A)")
'<<<<<<<<< LANCZOS REFINEMENT <<<<<<<<<<'
2507 WRITE (output_unit,
"(T8,A,T15,A,T23,A,T36,A,T49,A,T60,A,/,T8,A)") &
2508 " Spin ",
" Cycle ", &
2509 " conv. MOS ",
" B2MAX ",
" B2MIN ",
" Time", repeat(
"-", 60)
2511 eps_iter = max(scf_env%krylov_space%eps_conv, scf_env%krylov_space%eps_adapt*scf_env%iter_delta)
2515 IF (my_check_moconv_only)
THEN
2518 nao, eps_iter, ispin, check_moconv_only=my_check_moconv_only)
2520 IF (output_unit > 0)
THEN
2521 WRITE (output_unit,
'(T8,I3,T16,I5,T24,I6,T33,E12.4,2x,E12.4,T60,F8.3)') &
2522 ispin, iter, scf_env%krylov_space%nmo_conv, &
2523 scf_env%krylov_space%max_res_norm, scf_env%krylov_space%min_res_norm, t2 - t1
2529 DO iter = 1, scf_env%krylov_space%max_iter
2531 nao, eps_iter, ispin)
2533 IF (output_unit > 0)
THEN
2534 WRITE (output_unit,
'(T8,I3,T16,I5,T24,I6,T33,E12.4,2x,E12.4,T60,F8.3)') &
2535 ispin, iter, scf_env%krylov_space%nmo_conv, &
2536 scf_env%krylov_space%max_res_norm, scf_env%krylov_space%min_res_norm, t2 - t1
2539 IF (scf_env%krylov_space%max_res_norm < eps_iter)
THEN
2541 IF (output_unit > 0)
WRITE (output_unit, *) &
2542 " Reached convergence in ", iter,
" iterations "
2547 IF (.NOT. converged .AND. output_unit > 0)
THEN
2548 WRITE (output_unit,
"(T4, A)")
" WARNING Lanczos refinement could "// &
2549 "not converge all the mos:"
2550 WRITE (output_unit,
"(T40,A,T70,I10)")
" number of not converged mos ", &
2551 scf_env%krylov_space%nmo_nc
2552 WRITE (output_unit,
"(T40,A,T70,E10.2)")
" max norm of the residual ", &
2553 scf_env%krylov_space%max_res_norm
2561 chc => scf_env%krylov_space%chc_mat(ispin)
2562 evec => scf_env%krylov_space%c_vec(ispin)
2563 CALL parallel_gemm(
'N',
'N', nao, nmo, nao, rone, ks, c0, rzero, work)
2564 CALL parallel_gemm(
'T',
'N', nmo, nmo, nao, rone, c0, work, rzero, chc)
2568 CALL parallel_gemm(
'N',
'N', nao, nmo, nmo, rone, c0, evec, rzero, c1)
2569 c0 => scf_env%krylov_space%mo_refine(ispin)
2578 IF (.NOT. scf_control%gce%do_gce)
THEN
2580 smear=scf_control%smear)
2583 smear=scf_control%smear, &
2584 gce=scf_control%gce)
2589 scf_env%p_mix_new(ispin, 1)%matrix)
2593 IF (output_unit > 0)
THEN
2594 WRITE (output_unit,
"(T15,A/)")
'<<<<<<<<< END LANCZOS REFINEMENT <<<<<<<<<<'
2600 CALL timestop(handle)
2620 scf_control, scf_section, check_moconv_only)
2624 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(INOUT) :: mos
2625 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s
2628 LOGICAL,
INTENT(IN),
OPTIONAL :: check_moconv_only
2630 CHARACTER(LEN=*),
PARAMETER :: routinen =
'do_block_davidson_diag'
2632 INTEGER :: handle, ispin, nspins, output_unit
2633 LOGICAL :: do_prec, my_check_moconv_only
2637 CALL timeset(routinen, handle)
2640 extension=
".scfLog")
2642 IF (output_unit > 0)
THEN
2643 WRITE (output_unit,
"(/T15,A)")
'<<<<<<<<< DAVIDSON ITERATIONS <<<<<<<<<<'
2646 IF (scf_env%mixing_method == 1)
THEN
2647 scf_env%iter_param = scf_env%p_mix_alpha
2648 scf_env%iter_method =
"P_Mix/Dav."
2650 scf_env%iter_param = scf_env%mixing_store%alpha
2651 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Dav."
2654 my_check_moconv_only = .false.
2655 IF (
PRESENT(check_moconv_only)) my_check_moconv_only = check_moconv_only
2657 IF (scf_env%block_davidson_env(1)%prec_type /= 0 .AND. &
2658 scf_env%iter_count >= scf_env%block_davidson_env(1)%first_prec)
THEN
2662 nspins =
SIZE(matrix_ks)
2664 IF (do_prec .AND. (scf_env%iter_count == scf_env%block_davidson_env(1)%first_prec .OR. &
2665 modulo(scf_env%iter_count, scf_env%block_davidson_env(1)%niter_new_prec) == 0))
THEN
2667 prec_type=scf_env%block_davidson_env(1)%prec_type, nspins=nspins)
2669 scf_env%block_davidson_env(1)%prec_type, &
2670 scf_env%block_davidson_env(1)%solver_type, &
2671 scf_env%block_davidson_env(1)%energy_gap, nspins, &
2672 convert_to_dbcsr=scf_env%block_davidson_env(1)%use_sparse_mos, &
2676 DO ispin = 1, nspins
2677 IF (scf_env%block_davidson_env(ispin)%use_sparse_mos)
THEN
2678 IF (.NOT. do_prec)
THEN
2680 matrix_ks(ispin)%matrix, matrix_s(1)%matrix, output_unit)
2683 matrix_ks(ispin)%matrix, matrix_s(1)%matrix, output_unit, &
2684 scf_env%ot_preconditioner(ispin)%preconditioner)
2688 IF (.NOT. do_prec)
THEN
2690 matrix_ks(ispin)%matrix, matrix_s(1)%matrix, output_unit)
2693 matrix_ks(ispin)%matrix, matrix_s(1)%matrix, output_unit, &
2694 scf_env%ot_preconditioner(ispin)%preconditioner)
2699 IF (.NOT. scf_control%gce%do_gce)
THEN
2701 smear=scf_control%smear)
2704 smear=scf_control%smear, &
2705 gce=scf_control%gce)
2708 DO ispin = 1, nspins
2711 scf_env%p_mix_new(ispin, 1)%matrix)
2714 IF (output_unit > 0)
THEN
2715 WRITE (output_unit,
"(T15,A/)")
'<<<<<<<<< END DAVIDSON ITERATION <<<<<<<<<<'
2721 CALL timestop(handle)
2739 scf_control, added_mos_auto_grow)
2743 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks_kp, matrix_s_kp
2746 LOGICAL,
INTENT(OUT),
OPTIONAL :: added_mos_auto_grow
2748 CHARACTER(LEN=*),
PARAMETER :: routinen =
'do_block_davidson_diag_kp'
2749 REAL(kind=
dp),
PARAMETER :: empty_factor = 5.0_dp, &
2750 eps_iter_cap = 1.0e-4_dp
2752 INTEGER :: channel, first_prec, handle, ispin, iw, &
2753 iwork, kplocal, kpmax, local_kpoint, &
2754 nchannels, nspin, output_unit
2755 INTEGER,
DIMENSION(2) :: kp_range
2756 INTEGER,
DIMENSION(:, :),
POINTER :: kp_dist
2757 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
2758 LOGICAL :: do_prec, my_added_mos_auto_grow, &
2760 REAL(kind=
dp) :: eps_iter, eps_iter_empty
2761 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: xkp
2763 TYPE(
cp_fm_pool_p_type),
DIMENSION(:),
POINTER :: ao_ao_fm_pools, kp_ao_ao_fm_pools
2765 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: fmwork
2786 CALL timeset(routinen, handle)
2790 extension=
".scfLog")
2791 IF (output_unit > 0)
THEN
2792 WRITE (output_unit,
"(/T15,A)")
'<<<<<<<<< DAVIDSON ITERATIONS <<<<<<<<<<'
2795 CALL get_kpoint_info(kpoints, kp_range=kp_range, kp_dist=kp_dist, xkp=xkp, &
2797 cell_to_index=cell_to_index, mpools=kp_mpools)
2799 cpabort(
'Davidson Kp requires complex K-point MOS')
2801 para_env => kpoints%blacs_env_all%para_env
2802 kplocal = kp_range(2) - kp_range(1) + 1
2803 kpmax = maxval(kp_dist(2, :) - kp_dist(1, :) + 1)
2804 nspin =
SIZE(matrix_ks_kp, 1)
2805 nchannels = kplocal*nspin
2807 IF (scf_env%mixing_method == 1)
THEN
2808 scf_env%iter_param = scf_env%p_mix_alpha
2809 scf_env%iter_method =
"P_Mix/Dav."
2810 ELSE IF (scf_env%mixing_method > 1)
THEN
2811 scf_env%iter_param = scf_env%mixing_store%alpha
2812 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Dav."
2822 first_prec = max(scf_env%block_davidson_env(1)%first_prec, 2)
2824 IF (scf_env%block_davidson_env(1)%prec_type /=
ot_precond_none .AND. &
2825 scf_env%iter_count >= first_prec)
THEN
2842 eps_iter = scf_env%block_davidson_env(1)%eps_iter
2843 eps_iter_empty = eps_iter
2844 IF (scf_control%diagonalization%eps_adapt > 0.0_dp .AND. scf_env%iter_delta > 0.0_dp)
THEN
2854 IF (scf_env%iter_delta < scf_env%block_davidson_env(1)%eps_iter_used)
THEN
2855 scf_env%block_davidson_env(1)%eps_iter_prev = &
2856 min(scf_env%block_davidson_env(1)%eps_iter_prev, &
2857 max(scf_env%block_davidson_env(1)%eps_iter, &
2858 0.1_dp*scf_env%block_davidson_env(1)%eps_iter_used))
2864 eps_iter = min(max(eps_iter, min(scf_control%diagonalization%eps_adapt*scf_env%iter_delta/ &
2865 scf_env%block_davidson_env(1)%noise_scale, &
2866 eps_iter_cap)), scf_env%block_davidson_env(1)%eps_iter_prev)
2867 eps_iter_empty = empty_factor*eps_iter
2870 scf_env%block_davidson_env(1)%eps_iter_prev = eps_iter
2871 scf_env%block_davidson_env(1)%eps_iter_used = eps_iter
2875 IF (scf_control%diagonalization%eps_adapt > 0.0_dp .AND. para_env%is_source() .AND. &
2879 WRITE (unit=iw, fmt=
"(T3,'EPS_ADAPT step',I5,' delta=',ES9.2,' eps_occ=',ES9.2,' eps_empty=',ES9.2)") &
2880 scf_env%iter_count, scf_env%iter_delta, eps_iter, eps_iter_empty
2888 CALL mpools_get(mpools, ao_ao_fm_pools=ao_ao_fm_pools)
2889 ALLOCATE (fmwork(4))
2896 CALL mpools_get(kp_mpools, ao_ao_fm_pools=kp_ao_ao_fm_pools)
2900 CALL cp_cfm_create(csmat_base, matrix_struct, name=
"dav_sk_base")
2902 IF (do_prec .AND. (scf_env%iter_count == first_prec .OR. &
2903 modulo(scf_env%iter_count, &
2904 scf_env%block_davidson_env(1)%niter_new_prec) == 0))
THEN
2905 CALL davidson_kp_prepare_preconditioners( &
2906 qs_env, scf_env, matrix_ks_kp, matrix_s_kp, kpoints, op_ctx)
2909 DO local_kpoint = 1, kpmax
2919 IF (local_kpoint > kplocal) cycle
2920 kp => kpoints%kp_env(local_kpoint)%kpoint_env
2923 IF (scf_env%iter_count == 1 .AND. .NOT. kp%mos_prefilled)
THEN
2927 CALL cold_start_mo_init(kp, ispin, cksmat, csmat)
2929 channel = (local_kpoint - 1)*nspin + ispin
2932 kp%mos(ispin), cksmat, csmat, output_unit, &
2933 eps_iter, eps_iter_empty, &
2934 scf_env%ot_preconditioner(channel)%preconditioner)
2937 kp%mos(ispin), cksmat, csmat, output_unit, &
2938 eps_iter, eps_iter_empty)
2945 my_added_mos_auto_grow = .false.
2947 added_mos_auto=scf_control%added_mos_auto, &
2948 added_mos_auto_grow=my_added_mos_auto_grow)
2949 IF (my_added_mos_auto_grow)
THEN
2953 IF (
PRESENT(added_mos_auto_grow)) added_mos_auto_grow = .true.
2957 matrix_s_kp(1, 1)%matrix, sab_nl, fmwork, overlap_rs=matrix_s_kp)
2969 IF (output_unit > 0)
THEN
2970 WRITE (output_unit,
"(T15,A/)")
'<<<<<<<<< END DAVIDSON ITERATION <<<<<<<<<<'
2975 CALL timestop(handle)
2988 SUBROUTINE cold_start_mo_init(kp, ispin, cksmat, csmat)
2991 INTEGER,
INTENT(IN) :: ispin
2994 CHARACTER(LEN=*),
PARAMETER :: routinen =
'cold_start_mo_init'
2997 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues
3000 CALL timeset(routinen, handle)
3002 CALL get_mo_set(kp%mos(ispin), eigenvalues=eigenvalues)
3003 CALL cp_cfm_create(cwork, cksmat%matrix_struct, name=
"dav_cold_cwork")
3004 CALL cp_cfm_geeig(cksmat, csmat, kp%mos(ispin)%cmo_coeff, eigenvalues, cwork)
3007 CALL timestop(handle)
3009 END SUBROUTINE cold_start_mo_init
3021 SUBROUTINE davidson_kp_prepare_preconditioners( &
3022 qs_env, scf_env, matrix_ks_kp, matrix_s_kp, kpoints, op_ctx)
3026 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks_kp, matrix_s_kp
3030 CHARACTER(LEN=*),
PARAMETER :: routinen =
'davidson_kp_prepare_preconditioners'
3032 INTEGER :: channel, handle, ispin, kplocal, kpmax, &
3033 local_kpoint, nchannels, nmo, nspin, &
3034 prec_type, solver_type
3035 INTEGER,
DIMENSION(2) :: kp_range
3036 INTEGER,
DIMENSION(:, :),
POINTER :: kp_dist
3037 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
3038 REAL(kind=
dp) :: energy_gap
3039 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues
3040 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: xkp
3043 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_t_kp
3044 TYPE(
dbcsr_type),
POINTER :: matrix_h_im, matrix_h_re, matrix_s_im, &
3045 matrix_s_re, matrix_t_im, matrix_t_re
3051 CALL timeset(routinen, handle)
3053 CALL get_kpoint_info(kpoints, kp_range=kp_range, kp_dist=kp_dist, xkp=xkp, sab_nl=sab_nl, &
3054 cell_to_index=cell_to_index)
3055 CALL get_qs_env(qs_env, kinetic_kp=matrix_t_kp)
3058 blacs_env => kpoints%blacs_env
3059 para_env => kpoints%para_env_kp
3060 kplocal = kp_range(2) - kp_range(1) + 1
3061 kpmax = maxval(kp_dist(2, :) - kp_dist(1, :) + 1)
3062 nspin =
SIZE(matrix_ks_kp, 1)
3063 nchannels = kplocal*nspin
3064 prec_type = scf_env%block_davidson_env(1)%prec_type
3065 solver_type = scf_env%block_davidson_env(1)%solver_type
3066 energy_gap = scf_env%block_davidson_env(1)%energy_gap
3072 IF (
ASSOCIATED(scf_env%ot_preconditioner))
THEN
3073 DO channel = 1,
SIZE(scf_env%ot_preconditioner)
3074 IF (
ASSOCIATED(scf_env%ot_preconditioner(channel)%preconditioner))
THEN
3076 DEALLOCATE (scf_env%ot_preconditioner(channel)%preconditioner)
3079 DEALLOCATE (scf_env%ot_preconditioner)
3080 NULLIFY (scf_env%ot_preconditioner)
3082 ALLOCATE (scf_env%ot_preconditioner(nchannels))
3083 DO channel = 1, nchannels
3084 ALLOCATE (scf_env%ot_preconditioner(channel)%preconditioner)
3086 para_env, blacs_env)
3089 NULLIFY (eigenvalues, matrix_h_im, matrix_h_re, matrix_s_im, matrix_s_re, &
3090 matrix_t_im, matrix_t_re)
3092 cpassert(
ASSOCIATED(matrix_t_kp))
3096 DO local_kpoint = 1, kpmax
3104 mat_re=matrix_s_re, mat_im=matrix_s_im, &
3111 mat_re=matrix_t_re, mat_im=matrix_t_im, &
3120 mat_re=matrix_h_re, mat_im=matrix_h_im, matrix_row=ispin, slot=
kpoint_slot_ks)
3122 IF (local_kpoint <= kplocal)
THEN
3123 kp => kpoints%kp_env(local_kpoint)%kpoint_env
3124 channel = (local_kpoint - 1)*nspin + ispin
3132 CALL get_mo_set(kp%mos(ispin), eigenvalues=eigenvalues, &
3134 CALL cp_cfm_create(matrix_c, kp%mos(ispin)%cmo_coeff%matrix_struct, name=
"dav pc C")
3137 scf_env%ot_preconditioner(channel)%preconditioner, &
3138 'dav pc H', matrix_h)
3140 scf_env%ot_preconditioner(channel)%preconditioner, &
3141 'dav pc S', matrix_s)
3144 matrix_c, matrix_h, matrix_s, eigenvalues(1:nmo), &
3148 scf_env%ot_preconditioner(channel)%preconditioner, &
3149 matrix_c, matrix_h, matrix_s, energy_gap)
3156 scf_env%ot_preconditioner(channel)%preconditioner, &
3157 matrix_t_re, matrix_t_im, matrix_s_re, matrix_s_im, energy_gap, solver_type)
3160 scf_env%ot_preconditioner(channel)%preconditioner, &
3161 matrix_s_re, matrix_s_im, solver_type)
3178 CALL timestop(handle)
3180 END SUBROUTINE davidson_kp_prepare_preconditioners
3194 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s
3197 LOGICAL,
INTENT(IN),
OPTIONAL :: lowdin_forces
3199 CHARACTER(len=*),
PARAMETER :: routinen =
'diag_kp_smat'
3200 COMPLEX(KIND=dp),
PARAMETER :: cone = (1.0_dp, 0.0_dp), &
3201 czero = (0.0_dp, 0.0_dp)
3203 COMPLEX(KIND=dp),
ALLOCATABLE,
DIMENSION(:) :: ceig
3204 INTEGER :: handle, ikp, kplocal, kpmax, nao
3205 INTEGER,
DIMENSION(2) :: kp_range
3206 INTEGER,
DIMENSION(:, :),
POINTER :: kp_dist
3208 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: eigenvalues
3219 CALL timeset(routinen, handle)
3223 kp_dist=kp_dist, sab_nl=sab_nl)
3224 cpassert(
ASSOCIATED(sab_nl))
3225 kplocal = kp_range(2) - kp_range(1) + 1
3226 kpmax = maxval(kp_dist(2, :) - kp_dist(1, :) + 1)
3230 CALL mpools_get(mpools, ao_ao_fm_pools=ao_ao_fm_pools)
3243 ALLOCATE (eigenvalues(nao), ceig(nao))
3264 IF (ikp > kplocal) cycle
3265 kp => kpoints%kp_env(ikp)%kpoint_env
3266 save_spectrum =
ALLOCATED(kp%lowdin_sqrt)
3267 IF (
PRESENT(lowdin_forces)) save_spectrum = lowdin_forces
3269 IF (
ALLOCATED(kp%lowdin_sqrt))
DEALLOCATE (kp%lowdin_sqrt)
3275 cpassert(all(eigenvalues(1:nao) >= 0.0_dp))
3276 IF (save_spectrum)
THEN
3277 IF (any(eigenvalues <= 0.0_dp))
THEN
3278 cpabort(
"Lowdin forces require a positive definite overlap")
3280 ALLOCATE (kp%lowdin_sqrt(nao))
3281 kp%lowdin_sqrt(:) = sqrt(eigenvalues)
3292 eigenvalues(1:nao) = sqrt(eigenvalues(1:nao))
3295 CALL parallel_gemm(
"N",
"T", nao, nao, nao, 1.0_dp, rsmat, fmlocal, &
3300 ceig(1:nao) = sqrt(eigenvalues(1:nao))
3303 CALL parallel_gemm(
"N",
"C", nao, nao, nao, cone, csmat, cwork, &
3311 DEALLOCATE (eigenvalues, ceig)
3321 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_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_column_scale(matrix_a, scaling)
Scales columns of the full matrix by corresponding factors.
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)
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_column_scale(matrixa, scaling)
scales column i of matrix a with scaling(i)
subroutine, public cp_fm_scale_and_add(alpha, matrix_a, beta, matrix_b)
calc A <- alpha*A + beta*B optimized for alpha == 1.0 (just add beta*B) and beta == 0....
subroutine, public cp_fm_uplo_to_full(matrix, work, uplo)
given a triangular matrix according to uplo, computes the corresponding full matrix
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.
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
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
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)
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 to complete reciprocal-grid transform 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_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_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
subroutine, public kpoint_operator_store(kpoints, ao_ao_fm, matrix_ks, matrix_s, matrix_t)
Prepare owned split-FM operators for OT without entering an SCF eigensolver. H (or the initialization...
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_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 exit of the routine that...
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_pools, 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 ...
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)
...
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.
to create arrays of pools
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 one driver call. Created and released in the same driver routine an...
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.