18 deallocate_arnoldi_env,&
19 get_selected_ritz_val,&
20 get_selected_ritz_vector,&
21 set_arnoldi_initial_vector,&
77#include "./base/base_uses.f90"
83 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'preconditioner_makes'
105 c0_evals, energy_gap)
108 TYPE(
cp_cfm_type),
INTENT(IN) :: matrix_c0, matrix_h, matrix_s
109 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN),
OPTIONAL :: c0_evals
110 REAL(kind=
dp),
INTENT(IN) :: energy_gap
112 CHARACTER(len=*),
PARAMETER :: routinen =
'make_complex_full_all'
115 TYPE(
cp_cfm_type) :: matrix_diag_work, matrix_s_copy, &
118 CALL timeset(routinen, handle)
120 matrix_tmp, matrix_s_copy, c0_evals, energy_gap)
121 CALL cp_cfm_create(matrix_diag_work, matrix_h%matrix_struct, &
122 name=
'complex FULL_ALL diagonalization work')
123 CALL cp_cfm_geeig(matrix_tmp, matrix_s_copy, preconditioner_env%complex_fm, &
124 preconditioner_env%full_evals, matrix_diag_work)
125 k =
SIZE(preconditioner_env%occ_evals)
126 preconditioner_env%full_evals(1:k) = preconditioner_env%occ_evals(:)
127 CALL cp_cfm_to_cfm(matrix_c0, preconditioner_env%complex_fm, k)
131 CALL timestop(handle)
146 matrix_tmp, matrix_s_copy, c0_evals, energy_gap)
149 TYPE(
cp_cfm_type),
INTENT(IN) :: matrix_c0, matrix_h, matrix_s
150 TYPE(
cp_cfm_type),
INTENT(OUT) :: matrix_tmp, matrix_s_copy
151 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN),
OPTIONAL :: c0_evals
152 REAL(kind=
dp),
INTENT(IN) :: energy_gap
154 CHARACTER(len=*),
PARAMETER :: routinen =
'prepare_complex_full_all'
155 REAL(kind=
dp),
PARAMETER :: fudge_factor = 0.25_dp, &
156 lambda_base = 10.0_dp
158 COMPLEX(KIND=dp),
ALLOCATABLE,
DIMENSION(:) :: shifted_evals
159 INTEGER :: handle, k, n
160 REAL(kind=
dp) :: error_estimate, lambda
161 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: residual_norm_sq
162 TYPE(
cp_cfm_type) :: matrix_chc, matrix_hc0, matrix_sc0, &
163 matrix_sc_chc, matrix_shifted_sc
165 CALL timeset(routinen, handle)
169 cpassert(k > 0 .AND. k <= n)
170 IF (
PRESENT(c0_evals))
THEN
171 cpassert(
SIZE(c0_evals) >= k)
173 cpassert(energy_gap > 0.0_dp)
175 IF (
ASSOCIATED(preconditioner_env%complex_fm))
THEN
177 DEALLOCATE (preconditioner_env%complex_fm)
179 IF (
ASSOCIATED(preconditioner_env%occ_evals))
DEALLOCATE (preconditioner_env%occ_evals)
180 IF (
ASSOCIATED(preconditioner_env%full_evals))
DEALLOCATE (preconditioner_env%full_evals)
182 ALLOCATE (preconditioner_env%complex_fm)
183 CALL cp_cfm_create(preconditioner_env%complex_fm, matrix_h%matrix_struct, &
184 name=
'complex FULL_ALL eigenvectors')
185 ALLOCATE (preconditioner_env%full_evals(n), preconditioner_env%occ_evals(k))
187 CALL cp_cfm_create(matrix_hc0, matrix_c0%matrix_struct, name=
'complex FULL_ALL HC')
188 CALL cp_cfm_create(matrix_sc0, matrix_c0%matrix_struct, name=
'complex FULL_ALL SC')
189 CALL cp_cfm_create(matrix_chc, matrix_c0%matrix_struct, nrow=k, ncol=k, &
190 name=
'complex FULL_ALL CHC')
192 name=
'complex FULL_ALL SC CHC')
193 CALL cp_cfm_create(matrix_shifted_sc, matrix_c0%matrix_struct, &
194 name=
'complex FULL_ALL shifted SC')
195 CALL cp_cfm_create(matrix_tmp, matrix_h%matrix_struct, name=
'complex FULL_ALL projected H')
196 CALL cp_cfm_create(matrix_s_copy, matrix_s%matrix_struct, name=
'complex FULL_ALL S copy')
205 ALLOCATE (shifted_evals(k), residual_norm_sq(k))
206 IF (
PRESENT(c0_evals))
THEN
207 preconditioner_env%occ_evals(:) = c0_evals(1:k)
212 preconditioner_env%occ_evals(:) = real(shifted_evals, kind=
dp)
214 shifted_evals(:) = cmplx(preconditioner_env%occ_evals, 0.0_dp, kind=
dp)
222 transa_tr=
'C', invert_tr=.true., uplo_tr=
'U')
225 error_estimate = sqrt(maxval(residual_norm_sq))
226 preconditioner_env%energy_gap = max(energy_gap, error_estimate*fudge_factor)
227 lambda = lambda_base + error_estimate
239 shifted_evals(:) = cmplx(preconditioner_env%occ_evals - lambda, 0.0_dp, kind=
dp)
248 DEALLOCATE (residual_norm_sq, shifted_evals)
255 CALL timestop(handle)
268 energy_homo, energy_gap)
271 TYPE(
cp_cfm_type),
INTENT(IN) :: matrix_h, matrix_s
272 REAL(kind=
dp),
INTENT(IN) :: energy_homo, energy_gap
274 CHARACTER(len=*),
PARAMETER :: routinen =
'make_complex_full_single'
276 COMPLEX(KIND=dp),
ALLOCATABLE,
DIMENSION(:) :: scaling
277 INTEGER :: handle, i, n
278 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: eigenvalues
279 TYPE(
cp_cfm_type) :: matrix_diag_a, matrix_diag_b, &
280 matrix_eigenvectors, &
281 matrix_scaled_eigenvectors, matrix_work
283 CALL timeset(routinen, handle)
287 cpassert(energy_gap > 0.0_dp)
289 IF (
ASSOCIATED(preconditioner_env%complex_fm))
THEN
291 DEALLOCATE (preconditioner_env%complex_fm)
293 IF (
ASSOCIATED(preconditioner_env%occ_evals))
DEALLOCATE (preconditioner_env%occ_evals)
294 IF (
ASSOCIATED(preconditioner_env%full_evals))
DEALLOCATE (preconditioner_env%full_evals)
296 ALLOCATE (preconditioner_env%complex_fm)
297 CALL cp_cfm_create(preconditioner_env%complex_fm, matrix_h%matrix_struct, &
298 name=
'complex FULL_SINGLE preconditioner')
300 name=
'complex FULL_SINGLE diagonalization A')
302 name=
'complex FULL_SINGLE diagonalization B')
303 CALL cp_cfm_create(matrix_eigenvectors, matrix_h%matrix_struct, &
304 name=
'complex FULL_SINGLE eigenvectors')
305 CALL cp_cfm_create(matrix_scaled_eigenvectors, matrix_h%matrix_struct, &
306 name=
'complex FULL_SINGLE scaled eigenvectors')
308 name=
'complex FULL_SINGLE diagonalization work')
310 ALLOCATE (eigenvalues(n), scaling(n))
313 CALL cp_cfm_geeig(matrix_diag_a, matrix_diag_b, matrix_eigenvectors, &
314 eigenvalues, matrix_work)
316 scaling(i) = cmplx(1.0_dp/max(eigenvalues(i) - energy_homo, energy_gap), &
319 CALL cp_cfm_to_cfm(matrix_eigenvectors, matrix_scaled_eigenvectors)
322 matrix_eigenvectors,
z_zero, preconditioner_env%complex_fm)
324 preconditioner_env%energy_gap = energy_gap
328 DEALLOCATE (scaling, eigenvalues)
335 CALL timestop(handle)
351 preconditioner_env, matrix_c0, matrix_h, matrix_s, energy_gap, max_rank, &
352 spectral_window, degeneracy_tolerance)
355 TYPE(
cp_cfm_type),
INTENT(IN) :: matrix_c0, matrix_h, matrix_s
356 REAL(kind=
dp),
INTENT(IN) :: energy_gap
357 INTEGER,
INTENT(IN) :: max_rank
358 REAL(kind=
dp),
INTENT(IN) :: spectral_window, degeneracy_tolerance
360 INTEGER :: k, max_rank_eff, n
361 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: active_evals, common_evals
362 TYPE(
cp_cfm_type) :: matrix_chc, matrix_hc0, matrix_vectors
365 cpassert(k > 0 .AND. k <= n)
366 cpassert(max_rank == -1 .OR. max_rank > 0)
367 cpassert(spectral_window > 0.0_dp)
368 cpassert(degeneracy_tolerance >= 0.0_dp)
370 CALL cp_cfm_create(matrix_hc0, matrix_c0%matrix_struct, name=
'complex FERMI_LOW_RANK HC')
371 CALL cp_cfm_create(matrix_chc, matrix_c0%matrix_struct, nrow=k, ncol=k, &
372 name=
'complex FERMI_LOW_RANK CHC')
373 CALL cp_cfm_create(matrix_vectors, matrix_chc%matrix_struct, &
374 name=
'complex FERMI_LOW_RANK active vectors')
375 ALLOCATE (active_evals(k), common_evals(k))
378 CALL cp_cfm_heevd(matrix_chc, matrix_vectors, active_evals)
379 preconditioner_env%spectral_reference = maxval(active_evals)
380 common_evals(:) = preconditioner_env%spectral_reference
383 common_evals, energy_gap)
384 preconditioner_env%spectral_window = spectral_window
385 preconditioner_env%spectral_base_scale = 1.0_dp/spectral_window
386 preconditioner_env%spectral_max_rank = max_rank
387 max_rank_eff = max_rank
388 IF (max_rank_eff == -1) max_rank_eff = n - k
390 preconditioner_env%full_evals, k, max_rank_eff, degeneracy_tolerance)
392 preconditioner_env%lattice_fft_active = .false.
396 DEALLOCATE (common_evals, active_evals)
417 preconditioner_env, matrix_c0, matrix_h, matrix_s, energy_gap, occupation_signature)
420 TYPE(
cp_cfm_type),
INTENT(IN) :: matrix_c0, matrix_h, matrix_s
421 REAL(kind=
dp),
INTENT(IN) :: energy_gap
422 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN), &
423 OPTIONAL :: occupation_signature
425 COMPLEX(KIND=dp),
CONTIGUOUS,
DIMENSION(:, :), &
427 INTEGER :: group, i, j, k, n, ncol_local, ngroup, &
428 nrow_local, output_column
429 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: group_representative, occupation_group
430 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
431 REAL(kind=
dp) :: occupation_tolerance, rayleigh_bound, &
433 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: group_shift, occupied_evals
434 TYPE(
cp_cfm_type) :: matrix_c_canonical, matrix_chc, &
435 matrix_hc0, matrix_occ_vectors
438 cpassert(k > 0 .AND. k <= n)
441 name=
'complex covariant FULL_ALL HC')
442 CALL cp_cfm_create(matrix_chc, matrix_c0%matrix_struct, nrow=k, ncol=k, &
443 name=
'complex covariant FULL_ALL CHC')
444 CALL cp_cfm_create(matrix_occ_vectors, matrix_chc%matrix_struct, &
445 name=
'complex covariant FULL_ALL occupied rotation')
446 CALL cp_cfm_create(matrix_c_canonical, matrix_c0%matrix_struct, &
447 name=
'complex covariant FULL_ALL canonical C')
448 ALLOCATE (occupied_evals(k))
453 IF (
PRESENT(occupation_signature))
THEN
454 cpassert(
SIZE(occupation_signature, 1) == k)
455 cpassert(
SIZE(occupation_signature, 2) > 0)
456 ALLOCATE (group_representative(k), occupation_group(k))
457 occupation_tolerance = 64.0_dp*epsilon(1.0_dp)* &
458 max(1.0_dp, maxval(abs(occupation_signature)))
461 occupation_group(i) = 0
463 IF (maxval(abs(occupation_signature(i, :) - &
464 occupation_signature(group_representative(group), :))) <= &
465 occupation_tolerance)
THEN
466 occupation_group(i) = group
470 IF (occupation_group(i) == 0)
THEN
472 group_representative(ngroup) = i
473 occupation_group(i) = ngroup
476 DEALLOCATE (group_representative)
480 shift_stride = 4.0_dp*max(1.0_dp, rayleigh_bound)
481 ALLOCATE (group_shift(ngroup))
483 group_shift(group) = shift_stride* &
484 (real(group, kind=
dp) - 0.5_dp*real(ngroup + 1, kind=
dp))
486 CALL cp_cfm_get_info(matrix_chc, nrow_local=nrow_local, ncol_local=ncol_local, &
487 row_indices=row_indices, col_indices=col_indices, &
488 local_data=chc_local)
491 IF (occupation_group(row_indices(i)) /= occupation_group(col_indices(j)))
THEN
493 ELSE IF (row_indices(i) == col_indices(j))
THEN
494 group = occupation_group(row_indices(i))
495 chc_local(i, j) = chc_local(i, j) + &
496 cmplx(group_shift(group), 0.0_dp, kind=
dp)
503 CALL cp_cfm_heevd(matrix_chc, matrix_occ_vectors, occupied_evals)
504 IF (
PRESENT(occupation_signature))
THEN
508 DO i = 1, count(occupation_group == group)
509 output_column = output_column + 1
510 occupied_evals(output_column) = occupied_evals(output_column) - group_shift(group)
513 cpassert(output_column == k)
514 DEALLOCATE (group_shift)
516 DEALLOCATE (occupation_group)
519 z_zero, matrix_c_canonical)
522 occupied_evals, energy_gap)
523 IF (
ASSOCIATED(preconditioner_env%occ_rotation_complex))
THEN
525 DEALLOCATE (preconditioner_env%occ_rotation_complex)
527 ALLOCATE (preconditioner_env%occ_rotation_complex)
528 CALL cp_cfm_create(preconditioner_env%occ_rotation_complex, matrix_occ_vectors%matrix_struct, &
529 name=
'complex covariant FULL_ALL occupied rotation')
530 CALL cp_cfm_to_cfm(matrix_occ_vectors, preconditioner_env%occ_rotation_complex)
533 DEALLOCATE (occupied_evals)
554 energy_homo, eigenvalues_ot, energy_gap, &
558 TYPE(
dbcsr_type),
OPTIONAL,
POINTER :: matrix_s, matrix_t
560 REAL(kind=
dp) :: energy_homo
561 REAL(kind=
dp),
DIMENSION(:) :: eigenvalues_ot
562 REAL(kind=
dp) :: energy_gap
563 INTEGER :: my_solver_type
565 INTEGER :: precon_type
567 precon_type = preconditioner_env%in_use
568 SELECT CASE (precon_type)
571 cpabort(
"Only PRECOND_SOLVER DEFAULT for the moment")
573 IF (
PRESENT(matrix_s))
THEN
574 CALL make_full_single(preconditioner_env, preconditioner_env%fm, &
575 matrix_h, matrix_s, energy_homo, energy_gap)
577 CALL make_full_single_ortho(preconditioner_env, preconditioner_env%fm, &
578 matrix_h, energy_homo, energy_gap)
583 IF (.NOT.
PRESENT(matrix_s))
THEN
584 cpabort(
"Type for S=1 not implemented")
586 CALL make_full_s_inverse(preconditioner_env, matrix_s)
590 IF (.NOT. (
PRESENT(matrix_s) .AND.
PRESENT(matrix_t)))
THEN
591 cpabort(
"Type for S=1 not implemented")
593 CALL make_full_kinetic(preconditioner_env, matrix_t, matrix_s, energy_gap)
596 CALL make_full_single_inverse(preconditioner_env, mo_coeff, matrix_h, energy_gap, &
600 cpabort(
"Only PRECOND_SOLVER DEFAULT for the moment")
602 CALL make_full_all(preconditioner_env, mo_coeff, matrix_h, matrix_s, &
603 eigenvalues_ot, energy_gap)
607 cpabort(
"Only PRECOND_SOLVER DEFAULT for the moment")
609 CALL make_full_all(preconditioner_env, mo_coeff, matrix_h, matrix_s, &
610 eigenvalues_ot, energy_gap, common_reference=energy_homo)
613 cpabort(
"Type not implemented")
623 SUBROUTINE make_full_s_inverse(preconditioner_env, matrix_s)
627 CHARACTER(len=*),
PARAMETER :: routinen =
'make_full_s_inverse'
631 CALL timeset(routinen, handle)
633 cpassert(
ASSOCIATED(matrix_s))
635 IF (.NOT.
ASSOCIATED(preconditioner_env%sparse_matrix))
THEN
636 ALLOCATE (preconditioner_env%sparse_matrix)
638 CALL dbcsr_copy(preconditioner_env%sparse_matrix, matrix_s, name=
"full_kinetic")
640 CALL timestop(handle)
642 END SUBROUTINE make_full_s_inverse
652 SUBROUTINE make_full_kinetic(preconditioner_env, matrix_t, matrix_s, &
655 TYPE(
dbcsr_type),
POINTER :: matrix_t, matrix_s
656 REAL(kind=
dp) :: energy_gap
658 CHARACTER(len=*),
PARAMETER :: routinen =
'make_full_kinetic'
661 REAL(kind=
dp) :: shift
663 CALL timeset(routinen, handle)
665 cpassert(
ASSOCIATED(matrix_t))
666 cpassert(
ASSOCIATED(matrix_s))
668 IF (.NOT.
ASSOCIATED(preconditioner_env%sparse_matrix))
THEN
669 ALLOCATE (preconditioner_env%sparse_matrix)
671 CALL dbcsr_copy(preconditioner_env%sparse_matrix, matrix_t, name=
"full_kinetic")
673 shift = max(0.0_dp, energy_gap)
675 CALL dbcsr_add(preconditioner_env%sparse_matrix, matrix_s, &
676 alpha_scalar=1.0_dp, beta_scalar=shift)
678 CALL timestop(handle)
680 END SUBROUTINE make_full_kinetic
691 SUBROUTINE make_full_single(preconditioner_env, fm, matrix_h, matrix_s, &
692 energy_homo, energy_gap)
695 TYPE(
dbcsr_type),
POINTER :: matrix_h, matrix_s
696 REAL(kind=
dp) :: energy_homo, energy_gap
698 CHARACTER(len=*),
PARAMETER :: routinen =
'make_full_single'
700 INTEGER :: handle, i, n
701 REAL(kind=
dp),
DIMENSION(:),
POINTER :: evals
705 CALL timeset(routinen, handle)
707 NULLIFY (fm_struct_tmp, evals)
709 IF (
ASSOCIATED(fm))
THEN
718 context=preconditioner_env%ctxt, &
719 para_env=preconditioner_env%para_env)
721 CALL cp_fm_create(fm, fm_struct_tmp, name=
"preconditioner")
730 SELECT CASE (preconditioner_env%cholesky_use)
737 invert_tr=.false., uplo_tr=
"U", n_rows=n, n_cols=n, alpha=1.0_dp)
739 invert_tr=.false., uplo_tr=
"U", n_rows=n, n_cols=n, alpha=1.0_dp)
743 cpabort(
"cholesky type not implemented")
748 SELECT CASE (preconditioner_env%cholesky_use)
751 invert_tr=.false., uplo_tr=
"U", n_rows=n, n_cols=n, alpha=1.0_dp)
753 evals(i) = 1.0_dp/max(evals(i) - energy_homo, energy_gap)
759 evals(i) = 1.0_dp/max(evals(i) - energy_homo, energy_gap)
765 CALL parallel_gemm(
'N',
'T', n, n, n, 1.0_dp, fm, fm_h, 0.0_dp, fm_s)
772 CALL timestop(handle)
774 END SUBROUTINE make_full_single
784 SUBROUTINE make_full_single_ortho(preconditioner_env, fm, matrix_h, &
785 energy_homo, energy_gap)
789 REAL(kind=
dp) :: energy_homo, energy_gap
791 CHARACTER(len=*),
PARAMETER :: routinen =
'make_full_single_ortho'
793 INTEGER :: handle, i, n
794 REAL(kind=
dp),
DIMENSION(:),
POINTER :: evals
798 CALL timeset(routinen, handle)
799 NULLIFY (fm_struct_tmp, evals)
801 IF (
ASSOCIATED(fm))
THEN
810 context=preconditioner_env%ctxt, &
811 para_env=preconditioner_env%para_env)
813 CALL cp_fm_create(fm, fm_struct_tmp, name=
"preconditioner")
822 evals(i) = 1.0_dp/max(evals(i) - energy_homo, energy_gap)
826 CALL parallel_gemm(
'N',
'T', n, n, n, 1.0_dp, fm, fm_h, 0.0_dp, fm_s)
833 CALL timestop(handle)
835 END SUBROUTINE make_full_single_ortho
857 SUBROUTINE make_full_all(preconditioner_env, matrix_c0, matrix_h, matrix_s, c0_evals, energy_gap, &
862 TYPE(
dbcsr_type),
OPTIONAL,
POINTER :: matrix_s
863 REAL(kind=
dp),
DIMENSION(:) :: c0_evals
864 REAL(kind=
dp) :: energy_gap
865 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: common_reference
867 CHARACTER(len=*),
PARAMETER :: routinen =
'make_full_all'
868 REAL(kind=
dp),
PARAMETER :: fudge_factor = 0.25_dp, &
869 lambda_base = 10.0_dp
871 INTEGER :: handle, k, n
872 REAL(kind=
dp) :: error_estimate, lambda
873 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: diag, shifted_evals
875 TYPE(
cp_fm_type) :: matrix_hc0, matrix_left, matrix_sc0, &
876 matrix_shc0, matrix_tmp, ortho
879 CALL timeset(routinen, handle)
881 IF (
ASSOCIATED(preconditioner_env%fm))
THEN
883 DEALLOCATE (preconditioner_env%fm)
884 NULLIFY (preconditioner_env%fm)
888 context=preconditioner_env%ctxt, &
889 para_env=preconditioner_env%para_env)
890 ALLOCATE (preconditioner_env%fm)
891 CALL cp_fm_create(preconditioner_env%fm, fm_struct_tmp, name=
"preconditioner_env%fm")
892 IF (
PRESENT(matrix_s))
CALL cp_fm_create(ortho, fm_struct_tmp, name=
"ortho")
893 CALL cp_fm_create(matrix_tmp, fm_struct_tmp, name=
"matrix_tmp")
895 ALLOCATE (preconditioner_env%full_evals(n))
896 ALLOCATE (preconditioner_env%occ_evals(k))
899 IF (
PRESENT(matrix_s))
THEN
912 CALL cp_fm_create(matrix_sc0, matrix_c0%matrix_struct, name=
"sc0")
913 IF (
PRESENT(matrix_s))
THEN
918 CALL cp_fm_create(matrix_hc0, matrix_c0%matrix_struct, name=
"hc0")
923 IF (
PRESENT(matrix_s))
THEN
924 CALL cp_fm_create(matrix_shc0, matrix_c0%matrix_struct, name=
"shc0")
925 SELECT CASE (preconditioner_env%cholesky_use)
929 invert_tr=.false., uplo_tr=
"U", n_rows=n, n_cols=k, alpha=1.0_dp)
933 cpabort(
"cholesky type not implemented")
940 IF (
PRESENT(common_reference))
THEN
942 error_estimate = sqrt(max(0.0_dp, sum(diag) - sum(c0_evals**2)))
944 error_estimate = maxval(sqrt(abs(diag - c0_evals**2)))
951 preconditioner_env%energy_gap = max(energy_gap, error_estimate*fudge_factor)
953 matrix_pre => preconditioner_env%fm
956 CALL parallel_gemm(
'N',
'T', n, n, k, -1.0_dp, matrix_hc0, matrix_sc0, 1.0_dp, matrix_tmp)
959 context=preconditioner_env%ctxt, &
960 para_env=preconditioner_env%para_env)
961 CALL cp_fm_create(matrix_left, fm_struct_tmp, name=
"matrix_left")
963 CALL parallel_gemm(
'T',
'N', k, n, n, 1.0_dp, matrix_c0, matrix_tmp, 0.0_dp, matrix_left)
965 CALL parallel_gemm(
'N',
'N', n, n, k, -1.0_dp, matrix_sc0, matrix_left, 1.0_dp, matrix_tmp)
968 ALLOCATE (shifted_evals(k))
969 lambda = lambda_base + error_estimate
970 IF (
PRESENT(common_reference))
THEN
971 shifted_evals(:) = common_reference - lambda
973 shifted_evals(:) = c0_evals - lambda
977 CALL parallel_gemm(
'N',
'T', n, n, k, 1.0_dp, matrix_hc0, matrix_sc0, 1.0_dp, matrix_tmp)
980 IF (
PRESENT(matrix_s))
THEN
981 SELECT CASE (preconditioner_env%cholesky_use)
984 invert_tr=.false., uplo_tr=
"U", n_rows=n, n_cols=n, alpha=1.0_dp)
986 invert_tr=.false., uplo_tr=
"U", n_rows=n, n_cols=n, alpha=1.0_dp)
992 IF (
PRESENT(matrix_s))
THEN
993 SELECT CASE (preconditioner_env%cholesky_use)
996 invert_tr=.false., uplo_tr=
"U", n_rows=n, n_cols=n, alpha=1.0_dp)
1005 IF (
PRESENT(common_reference))
THEN
1006 preconditioner_env%occ_evals = common_reference
1007 preconditioner_env%full_evals(1:k) = common_reference
1009 preconditioner_env%occ_evals = c0_evals
1011 preconditioner_env%full_evals(1:k) = c0_evals
1018 DEALLOCATE (shifted_evals)
1019 CALL timestop(handle)
1021 END SUBROUTINE make_full_all
1040 SUBROUTINE make_full_single_inverse(preconditioner_env, matrix_c0, matrix_h, energy_gap, matrix_s)
1044 REAL(kind=
dp) :: energy_gap
1045 TYPE(
dbcsr_type),
OPTIONAL,
POINTER :: matrix_s
1047 CHARACTER(len=*),
PARAMETER :: routinen =
'make_full_single_inverse'
1049 INTEGER :: handle, k, n
1050 REAL(kind=
dp) :: max_ev, min_ev, pre_shift
1051 TYPE(arnoldi_env_type) :: arnoldi_env
1053 TYPE(
dbcsr_type),
TARGET :: dbcsr_cthc, dbcsr_hc, dbcsr_sc, mo_dbcsr
1055 CALL timeset(routinen, handle)
1067 IF (.NOT.
ASSOCIATED(preconditioner_env%sparse_matrix))
THEN
1068 ALLOCATE (preconditioner_env%sparse_matrix)
1072 CALL dbcsr_copy(preconditioner_env%sparse_matrix, matrix_h)
1076 IF (
PRESENT(matrix_s))
THEN
1077 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, matrix_s, mo_dbcsr, 0.0_dp, dbcsr_sc)
1084 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, matrix_h, mo_dbcsr, 0.0_dp, dbcsr_hc)
1085 CALL dbcsr_multiply(
"T",
"N", 1.0_dp, mo_dbcsr, dbcsr_hc, 0.0_dp, dbcsr_cthc)
1088 ALLOCATE (matrices(1))
1089 matrices(1)%matrix => dbcsr_cthc
1090 CALL setup_arnoldi_env(arnoldi_env, matrices, max_iter=20, threshold=1.0e-3_dp, selection_crit=2, &
1091 nval_request=1, nrestarts=8, generalized_ev=.false., iram=.false.)
1092 IF (
ASSOCIATED(preconditioner_env%max_ev_vector))
THEN
1093 CALL set_arnoldi_initial_vector(arnoldi_env, preconditioner_env%max_ev_vector)
1096 max_ev = real(get_selected_ritz_val(arnoldi_env, 1),
dp)
1099 IF (.NOT.
ASSOCIATED(preconditioner_env%max_ev_vector))
ALLOCATE (preconditioner_env%max_ev_vector)
1100 CALL get_selected_ritz_vector(arnoldi_env, 1, matrices(1)%matrix, preconditioner_env%max_ev_vector)
1101 CALL deallocate_arnoldi_env(arnoldi_env)
1102 DEALLOCATE (matrices)
1107 CALL dbcsr_multiply(
"N",
"N", 2.0_dp, dbcsr_sc, dbcsr_cthc, 0.0_dp, dbcsr_hc)
1108 CALL dbcsr_multiply(
"N",
"T", -1.0_dp, dbcsr_hc, dbcsr_sc, 1.0_dp, preconditioner_env%sparse_matrix)
1112 IF (
PRESENT(matrix_s))
THEN
1113 ALLOCATE (matrices(2))
1114 matrices(1)%matrix => preconditioner_env%sparse_matrix
1115 matrices(2)%matrix => matrix_s
1116 CALL setup_arnoldi_env(arnoldi_env, matrices, max_iter=20, threshold=2.0e-2_dp, selection_crit=3, &
1117 nval_request=1, nrestarts=21, generalized_ev=.true., iram=.false.)
1119 ALLOCATE (matrices(1))
1120 matrices(1)%matrix => preconditioner_env%sparse_matrix
1121 CALL setup_arnoldi_env(arnoldi_env, matrices, max_iter=20, threshold=2.0e-2_dp, selection_crit=3, &
1122 nval_request=1, nrestarts=8, generalized_ev=.false., iram=.false.)
1124 IF (
ASSOCIATED(preconditioner_env%min_ev_vector))
THEN
1125 CALL set_arnoldi_initial_vector(arnoldi_env, preconditioner_env%min_ev_vector)
1130 min_ev = real(get_selected_ritz_val(arnoldi_env, 1),
dp)
1133 IF (.NOT.
ASSOCIATED(preconditioner_env%min_ev_vector))
ALLOCATE (preconditioner_env%min_ev_vector)
1134 CALL get_selected_ritz_vector(arnoldi_env, 1, matrices(1)%matrix, preconditioner_env%min_ev_vector)
1135 CALL deallocate_arnoldi_env(arnoldi_env)
1136 DEALLOCATE (matrices)
1141 pre_shift = max(1.5_dp*(min_ev - max_ev), energy_gap)
1142 IF (min_ev < pre_shift)
THEN
1143 pre_shift = pre_shift - min_ev
1147 IF (
PRESENT(matrix_s))
THEN
1148 CALL dbcsr_add(preconditioner_env%sparse_matrix, matrix_s, 1.0_dp, pre_shift)
1158 CALL timestop(handle)
1160 END SUBROUTINE make_full_single_inverse
1174 TYPE(
cp_cfm_type),
INTENT(IN) :: matrix_c0, matrix_h, matrix_s
1175 REAL(kind=
dp),
INTENT(IN) :: energy_gap
1177 CHARACTER(len=*),
PARAMETER :: routinen =
'make_complex_full_single_inverse'
1179 INTEGER :: handle, i, k, n
1180 REAL(kind=
dp) :: max_ev, min_ev, pre_shift, target_edge
1181 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: occupied_evals, operator_evals
1182 TYPE(
cp_cfm_type) :: matrix_chc, matrix_diag_a, matrix_diag_b, matrix_diag_evec, &
1183 matrix_diag_work, matrix_hc0, matrix_occ_diag_a, matrix_occ_diag_b, matrix_occ_diag_evec, &
1184 matrix_occ_diag_work, matrix_operator, matrix_sc0, matrix_sc_chc
1186 CALL timeset(routinen, handle)
1190 cpassert(k > 0 .AND. k <= n)
1191 cpassert(energy_gap > 0.0_dp)
1193 CALL cp_cfm_create(matrix_hc0, matrix_c0%matrix_struct, name=
'complex FULL_SINGLE HC')
1194 CALL cp_cfm_create(matrix_sc0, matrix_c0%matrix_struct, name=
'complex FULL_SINGLE SC')
1195 CALL cp_cfm_create(matrix_chc, matrix_c0%matrix_struct, nrow=k, ncol=k, &
1196 name=
'complex FULL_SINGLE CHC')
1197 CALL cp_cfm_create(matrix_sc_chc, matrix_c0%matrix_struct, &
1198 name=
'complex FULL_SINGLE SC CHC')
1199 CALL cp_cfm_create(matrix_operator, matrix_h%matrix_struct, &
1200 name=
'complex FULL_SINGLE operator')
1202 name=
'complex FULL_SINGLE diagonalization A')
1204 name=
'complex FULL_SINGLE diagonalization B')
1205 CALL cp_cfm_create(matrix_diag_evec, matrix_h%matrix_struct, nrow=n, ncol=1, &
1206 name=
'complex FULL_SINGLE eigenvectors')
1207 CALL cp_cfm_create(matrix_diag_work, matrix_h%matrix_struct, &
1208 name=
'complex FULL_SINGLE diagonalization work')
1209 CALL cp_cfm_create(matrix_occ_diag_a, matrix_c0%matrix_struct, nrow=k, ncol=k, &
1210 name=
'complex FULL_SINGLE occupied diagonalization A')
1211 CALL cp_cfm_create(matrix_occ_diag_b, matrix_c0%matrix_struct, nrow=k, ncol=k, &
1212 name=
'complex FULL_SINGLE occupied diagonalization B', set_zero=.true.)
1213 CALL cp_cfm_create(matrix_occ_diag_evec, matrix_c0%matrix_struct, nrow=k, ncol=k, &
1214 name=
'complex FULL_SINGLE occupied eigenvectors')
1215 CALL cp_cfm_create(matrix_occ_diag_work, matrix_c0%matrix_struct, nrow=k, ncol=k, &
1216 name=
'complex FULL_SINGLE occupied diagonalization work')
1226 CALL cp_cfm_gemm(
'N',
'C', n, n, k, -2.0_dp*
z_one, matrix_sc_chc, matrix_sc0, &
1227 z_one, matrix_operator)
1229 z_one, matrix_operator)
1231 ALLOCATE (occupied_evals(k), operator_evals(1))
1236 CALL cp_cfm_geeig(matrix_occ_diag_a, matrix_occ_diag_b, matrix_occ_diag_evec, &
1237 occupied_evals, matrix_occ_diag_work)
1238 max_ev = maxval(occupied_evals)
1241 CALL cp_cfm_geeig(matrix_diag_a, matrix_diag_b, matrix_diag_evec, &
1242 operator_evals, matrix_diag_work, lowest_subset=.true.)
1243 min_ev = operator_evals(1)
1244 target_edge = max(1.5_dp*(min_ev - max_ev), energy_gap)
1245 pre_shift = max(0.0_dp, target_edge - min_ev)
1246 IF (pre_shift > 0.0_dp)
THEN
1248 cmplx(pre_shift, 0.0_dp, kind=
dp), matrix_s)
1251 CALL store_complex_inverse(preconditioner_env, matrix_operator, &
1254 DEALLOCATE (operator_evals, occupied_evals)
1269 CALL timestop(handle)
1297 TYPE(
cp_cfm_type),
INTENT(IN) :: matrix_t, matrix_s
1298 REAL(kind=
dp),
INTENT(IN) :: energy_gap
1300 REAL(kind=
dp) :: shift
1303 shift = max(0.0_dp, energy_gap)
1304 CALL cp_cfm_create(matrix_operator, matrix_t%matrix_struct, &
1305 name=
'complex FULL_KINETIC operator')
1308 CALL store_complex_inverse(preconditioner_env, matrix_operator, &
1321 SUBROUTINE store_complex_inverse(preconditioner_env, matrix_operator, &
1322 preconditioner_kind, energy_gap)
1326 INTEGER,
INTENT(IN) :: preconditioner_kind
1327 REAL(kind=
dp),
INTENT(IN) :: energy_gap
1331 IF (
ASSOCIATED(preconditioner_env%complex_fm))
THEN
1333 DEALLOCATE (preconditioner_env%complex_fm)
1335 ALLOCATE (preconditioner_env%complex_fm)
1336 CALL cp_cfm_create(preconditioner_env%complex_fm, matrix_operator%matrix_struct, &
1337 name=
'complex inverse preconditioner')
1338 CALL cp_cfm_to_cfm(matrix_operator, preconditioner_env%complex_fm)
1345 preconditioner_env%energy_gap = energy_gap
1346 preconditioner_env%in_use = preconditioner_kind
1349 END SUBROUTINE store_complex_inverse
arnoldi iteration using dbcsr
subroutine, public arnoldi_ev(matrix, arnoldi_env)
Driver routine for different arnoldi eigenvalue methods the selection which one is to be taken is mad...
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).
real(kind=dp) function, public cp_cfm_norm(matrix, mode)
Norm of matrix using (p)zlange.
subroutine, public cp_cfm_vectorsnorm(matrix, norm_array, squared)
find the norm of each column norm_{j}= sqrt( \sum_{i} A_{ij}*conjg(A_{ij}) ) Complex-valued mirror of...
subroutine, public cp_cfm_gemm(transa, transb, m, n, k, alpha, matrix_a, matrix_b, beta, matrix_c, a_first_col, a_first_row, b_first_col, b_first_row, c_first_col, c_first_row)
Performs one of the matrix-matrix operations: matrix_c = alpha * op1( matrix_a ) * op2( matrix_b ) + ...
subroutine, public cp_cfm_get_diag(matrix, diag, n_active)
returns the diagonal of a complex full matrix: diag(i)= A_{ii}. Each diagonal entry is owned by one p...
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_uplo_to_full(matrix, workspace, uplo)
...
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...
subroutine, public cp_cfm_cholesky_invert(matrix, n, info_out)
Used to replace Cholesky decomposition by the inverse.
used for collecting diagonalization schemes available for cp_cfm_type
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_cfm_set_element(matrix, irow_global, icol_global, alpha)
Set the matrix element (irow_global,icol_global) of the full matrix to alpha.
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_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, matrix_struct, para_env)
Returns information about a full matrix.
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_multiply(transa, transb, alpha, matrix_a, matrix_b, beta, matrix_c, first_row, last_row, first_column, last_column, first_k, last_k, retain_sparsity, filter_eps, flop)
...
subroutine, public dbcsr_get_info(matrix, nblkrows_total, nblkcols_total, nfullrows_total, nfullcols_total, nblkrows_local, nblkcols_local, nfullrows_local, nfullcols_local, my_prow, my_pcol, local_rows, local_cols, proc_row_dist, proc_col_dist, row_blk_size, col_blk_size, row_blk_offset, col_blk_offset, distribution, name, matrix_type, group)
...
subroutine, public dbcsr_release(matrix)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
subroutine, public dbcsr_add_on_diag(matrix, alpha)
Adds the given scalar to the diagonal of the matrix. Reserves any missing diagonal blocks.
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 cp_fm_to_dbcsr_row_template(matrix, fm_in, template)
Utility function to copy a specially shaped fm to dbcsr_matrix The result matrix will be the matrix i...
subroutine, public cp_dbcsr_m_by_n_from_template(matrix, template, m, n, sym)
Utility function to create an arbitrary shaped dbcsr matrix with the same processor grid as the templ...
Basic linear algebra operations for full matrices.
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_triangular_invert(matrix_a, uplo_tr)
inverts a triangular matrix
subroutine, public cp_fm_triangular_multiply(triangular_matrix, matrix_b, side, transpose_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...
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_decompose(matrix, n, info_out)
used to replace a symmetric positive def. matrix M with its cholesky decomposition U: M = U^T * U,...
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 choose_eigv_solver(matrix, eigenvectors, eigenvalues, info)
Choose the Eigensolver depending on which library is available ELPA seems to be unstable for small sy...
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_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
subroutine, public cp_fm_vectorsnorm(matrix, norm_array, squared)
find the norm of each column norm_{j}= sqrt( \sum_{i} A_{ij}*A_{ij} )
Defines the basic variable types.
integer, parameter, public dp
Small algebraic helpers for the rotationally covariant low-rank OT preconditioner.
pure integer function, public low_rank_select_rank(eigenvalues, nocc, max_rank, degeneracy_tolerance)
Select a bounded spectral rank without cutting a degenerate boundary manifold.
Definition of mathematical constants and functions.
complex(kind=dp), parameter, public z_one
complex(kind=dp), parameter, public z_zero
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_kinetic(preconditioner_env, matrix_t, matrix_s, energy_gap)
Build the inverse complex kinetic-plus-overlap preconditioner.
subroutine, public make_complex_full_s_inverse(preconditioner_env, matrix_s)
Build the inverse complex overlap preconditioner.
subroutine, public make_complex_full_all_covariant(preconditioner_env, matrix_c0, matrix_h, matrix_s, energy_gap, occupation_signature)
Build the gauge-covariant FULL_ALL inverse for a complex k-point channel.
subroutine, public make_complex_full_single(preconditioner_env, matrix_h, matrix_s, energy_homo, energy_gap)
Build the complex spectral FULL_SINGLE preconditioner.
subroutine, public prepare_complex_full_all(preconditioner_env, matrix_c0, matrix_h, matrix_s, matrix_tmp, matrix_s_copy, c0_evals, energy_gap)
Prepare the FULL_ALL eigenproblem using the same construction for every solver.
subroutine, public make_complex_fermi_low_rank(preconditioner_env, matrix_c0, matrix_h, matrix_s, energy_gap, max_rank, spectral_window, degeneracy_tolerance)
Build the bounded low-rank spectral inverse for a complex k-point channel.
subroutine, public make_preconditioner_matrix(preconditioner_env, matrix_h, matrix_s, matrix_t, mo_coeff, energy_homo, eigenvalues_ot, energy_gap, my_solver_type)
...
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...
Represent a complex full matrix.
keeps the information about the structure of a full matrix