74#include "./base/base_uses.f90"
82 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'ec_orth_solver'
111 SUBROUTINE ec_preconditioner(qs_env, matrix_ks, matrix_p, matrix_rhs, &
112 matrix_cg_z, eps_filter, iounit, silent)
114 TYPE(qs_environment_type),
POINTER :: qs_env
115 TYPE(dbcsr_p_type),
DIMENSION(:),
INTENT(IN), &
116 POINTER :: matrix_ks, matrix_p, matrix_rhs
117 TYPE(dbcsr_p_type),
DIMENSION(:),
INTENT(INOUT), &
118 POINTER :: matrix_cg_z
119 REAL(KIND=
dp),
INTENT(IN) :: eps_filter
120 INTEGER,
INTENT(IN) :: iounit
121 LOGICAL,
INTENT(IN),
OPTIONAL :: silent
123 CHARACTER(len=*),
PARAMETER :: routineN =
'ec_preconditioner'
125 INTEGER :: handle, i, ispin, max_iter, nao, nspins
126 LOGICAL :: converged, my_silent
127 REAL(KIND=
dp) :: norm_res, t1, t2
128 REAL(KIND=
dp),
DIMENSION(:),
POINTER :: alpha, beta, new_norm, norm_ca, norm_rr
129 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_Ax, matrix_b, matrix_cg, &
131 TYPE(dft_control_type),
POINTER :: dft_control
132 TYPE(linres_control_type),
POINTER :: linres_control
134 CALL timeset(routinen, handle)
137 IF (
PRESENT(silent)) my_silent = silent
139 cpassert(
ASSOCIATED(qs_env))
140 cpassert(
ASSOCIATED(matrix_ks))
141 cpassert(
ASSOCIATED(matrix_p))
142 cpassert(
ASSOCIATED(matrix_rhs))
143 cpassert(
ASSOCIATED(matrix_cg_z))
145 NULLIFY (dft_control, linres_control)
150 dft_control=dft_control, &
151 linres_control=linres_control)
152 nspins = dft_control%nspins
155 ALLOCATE (alpha(nspins), beta(nspins), new_norm(nspins), norm_ca(nspins), norm_rr(nspins))
161 NULLIFY (matrix_ax, matrix_b, matrix_cg, matrix_res)
168 ALLOCATE (matrix_ax(ispin)%matrix)
169 ALLOCATE (matrix_b(ispin)%matrix)
170 ALLOCATE (matrix_cg(ispin)%matrix)
171 ALLOCATE (matrix_res(ispin)%matrix)
172 CALL dbcsr_create(matrix_ax(ispin)%matrix, name=
"linop MATRIX", &
173 template=matrix_ks(1)%matrix, &
174 matrix_type=dbcsr_type_no_symmetry)
175 CALL dbcsr_create(matrix_b(ispin)%matrix, name=
"MATRIX B", &
176 template=matrix_ks(1)%matrix, &
177 matrix_type=dbcsr_type_no_symmetry)
178 CALL dbcsr_create(matrix_cg(ispin)%matrix, name=
"TRIAL MATRIX", &
179 template=matrix_ks(1)%matrix, &
180 matrix_type=dbcsr_type_no_symmetry)
181 CALL dbcsr_create(matrix_res(ispin)%matrix, name=
"RESIDUE", &
182 template=matrix_ks(1)%matrix, &
183 matrix_type=dbcsr_type_no_symmetry)
192 CALL dbcsr_copy(matrix_cg_z(ispin)%matrix, matrix_rhs(ispin)%matrix)
195 CALL dbcsr_copy(matrix_res(ispin)%matrix, matrix_rhs(ispin)%matrix)
204 CALL hessian_op1(matrix_ks, matrix_p, matrix_cg_z, matrix_b, matrix_ax, eps_filter)
208 CALL dbcsr_add(matrix_res(ispin)%matrix, matrix_ax(ispin)%matrix, 1.0_dp, -1.0_dp)
212 CALL projector(qs_env, matrix_p, matrix_res, eps_filter)
216 CALL dbcsr_copy(matrix_cg(ispin)%matrix, matrix_res(ispin)%matrix)
220 IF (iounit > 0 .AND. .NOT. my_silent)
THEN
221 WRITE (iounit,
"(/,T10,A)")
"Preconditioning of search direction"
222 WRITE (iounit,
"(/,T10,A,T25,A,T42,A,T62,A,/,T10,A)") &
223 "Iteration",
"Stepsize",
"Convergence",
"Time", &
233 iteration:
DO i = 1, max_iter
236 CALL hessian_op1(matrix_ks, matrix_p, matrix_cg, matrix_b, matrix_ax, eps_filter)
239 CALL projector(qs_env, matrix_p, matrix_ax, eps_filter)
244 CALL dbcsr_dot(matrix_res(ispin)%matrix, matrix_res(ispin)%matrix, norm_rr(ispin))
246 cpabort(
"Preconditioner: Tr[r_j*r_j] is an abnormal value (NaN/Inf)")
249 IF (norm_rr(ispin) < 0.0_dp) cpabort(
"norm_rr < 0")
250 norm_res = max(norm_res, abs(norm_rr(ispin)/real(nao,
dp)))
253 CALL dbcsr_dot(matrix_cg(ispin)%matrix, matrix_ax(ispin)%matrix, norm_ca(ispin))
256 IF (norm_ca(ispin) < linres_control%eps)
THEN
257 alpha(ispin) = 1.0_dp
259 alpha(ispin) = norm_rr(ispin)/norm_ca(ispin)
264 CALL dbcsr_add(matrix_cg_z(ispin)%matrix, matrix_cg(ispin)%matrix, 1.0_dp, alpha(ispin))
267 CALL dbcsr_add(matrix_res(ispin)%matrix, matrix_ax(ispin)%matrix, 1.0_dp, -alpha(ispin))
275 CALL dbcsr_dot(matrix_res(ispin)%matrix, matrix_res(ispin)%matrix, new_norm(ispin))
276 IF (new_norm(ispin) < 0.0_dp) cpabort(
"tr(r_j+1*z_j+1) < 0")
278 cpabort(
"Preconditioner: Tr[r_j+1*z_j+1] is an abnormal value (NaN/Inf)")
280 norm_res = max(norm_res, new_norm(ispin)/real(nao,
dp))
282 IF (norm_rr(ispin) < linres_control%eps*0.001_dp &
283 .OR. new_norm(ispin) < linres_control%eps*0.001_dp)
THEN
287 beta(ispin) = new_norm(ispin)/norm_rr(ispin)
292 CALL dbcsr_add(matrix_cg(ispin)%matrix, matrix_res(ispin)%matrix, beta(ispin), 1.0_dp)
295 norm_rr(ispin) = new_norm(ispin)
299 IF (norm_res < linres_control%eps)
THEN
304 IF (i == 1 .OR. mod(i, 1) == 0 .OR. converged)
THEN
305 IF (iounit > 0 .AND. .NOT. my_silent)
THEN
306 WRITE (iounit,
"(T10,I5,T25,1E8.2,T33,F25.14,T58,F8.2)") &
307 i, maxval(alpha), norm_res, t2 - t1
315 IF (iounit > 0 .AND. .NOT. my_silent)
THEN
316 WRITE (iounit,
"(/,T10,A,I4,A,/)")
"The precon solver converged in ", i,
" iterations."
323 IF (i == max_iter)
THEN
325 WRITE (iounit,
"(/,T10,A/)") &
326 "The precon solver didnt converge! Maximum number of iterations reached."
335 CALL projector(qs_env, matrix_p, matrix_cg_z, eps_filter)
343 DEALLOCATE (alpha, beta, new_norm, norm_ca, norm_rr)
345 CALL timestop(handle)
347 END SUBROUTINE ec_preconditioner
367 SUBROUTINE ec_response_ao(qs_env, p_env, matrix_hz, matrix_pz, matrix_wz, iounit, &
375 POINTER :: matrix_pz, matrix_wz
376 INTEGER,
INTENT(IN) :: iounit
377 LOGICAL,
INTENT(OUT) :: should_stop
378 LOGICAL,
INTENT(IN),
OPTIONAL :: silent
380 CHARACTER(len=*),
PARAMETER :: routinen =
'ec_response_ao'
382 INTEGER :: handle, i, ispin, max_iter_lanczos, nao, &
383 nspins, s_sqrt_method, s_sqrt_order
384 LOGICAL :: my_silent, restart
385 REAL(kind=
dp) :: eps_filter, eps_lanczos, focc, &
386 min_shift, norm_res, old_conv, shift, &
388 REAL(kind=
dp),
DIMENSION(:),
POINTER :: alpha, beta, new_norm, norm_ca, norm_rr, &
390 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: ksmat, matrix_ax, matrix_cg, matrix_cg_z, &
391 matrix_ks, matrix_nsc, matrix_p, matrix_res, matrix_s, matrix_z, matrix_z0, rho_ao
392 TYPE(
dbcsr_type) :: matrix_s_sqrt, matrix_s_sqrt_inv, &
399 CALL timeset(routinen, handle)
402 IF (
PRESENT(silent)) my_silent = silent
404 cpassert(
ASSOCIATED(qs_env))
405 cpassert(
ASSOCIATED(matrix_hz))
406 cpassert(
ASSOCIATED(matrix_pz))
407 cpassert(
ASSOCIATED(matrix_wz))
409 NULLIFY (dft_control, ksmat, matrix_s, linres_control, rho)
414 dft_control=dft_control, &
415 linres_control=linres_control, &
419 nspins = dft_control%nspins
429 eps_filter = linres_control%eps_filter
433 ALLOCATE (alpha(nspins), beta(nspins), new_norm(nspins), norm_ca(nspins), norm_rr(nspins))
434 ALLOCATE (tr_rz00(nspins))
438 NULLIFY (matrix_p, matrix_ks, matrix_nsc)
443 ALLOCATE (matrix_p(ispin)%matrix)
444 ALLOCATE (matrix_ks(ispin)%matrix)
445 ALLOCATE (matrix_nsc(ispin)%matrix)
446 CALL dbcsr_create(matrix_p(ispin)%matrix, name=
"P_IN ORTHO", &
447 template=ksmat(1)%matrix, &
448 matrix_type=dbcsr_type_no_symmetry)
449 CALL dbcsr_create(matrix_ks(ispin)%matrix, name=
"KS_IN ORTHO", &
450 template=ksmat(1)%matrix, &
451 matrix_type=dbcsr_type_no_symmetry)
452 CALL dbcsr_create(matrix_nsc(ispin)%matrix, name=
"NSC IN ORTHO", &
453 template=ksmat(1)%matrix, &
454 matrix_type=dbcsr_type_no_symmetry)
462 IF (nspins == 1)
CALL dbcsr_scale(matrix_p(1)%matrix, 0.5_dp)
465 CALL dbcsr_create(matrix_s_sqrt, template=matrix_s(1)%matrix, &
466 matrix_type=dbcsr_type_no_symmetry)
467 CALL dbcsr_create(matrix_s_sqrt_inv, template=matrix_s(1)%matrix, &
468 matrix_type=dbcsr_type_no_symmetry)
470 SELECT CASE (s_sqrt_method)
473 matrix_s(1)%matrix, eps_filter, &
474 s_sqrt_order, eps_lanczos, max_iter_lanczos, symmetrize=.true.)
477 matrix_s(1)%matrix, eps_filter, &
478 s_sqrt_order, eps_lanczos, max_iter_lanczos)
480 cpabort(
"Unknown sqrt method.")
485 CALL transform_m_orth(matrix_p(ispin)%matrix, matrix_s_sqrt, eps_filter)
486 CALL transform_m_orth(matrix_ks(ispin)%matrix, matrix_s_sqrt_inv, eps_filter)
487 CALL transform_m_orth(matrix_nsc(ispin)%matrix, matrix_s_sqrt_inv, eps_filter)
496 CALL dbcsr_create(matrix_tmp, template=matrix_s(1)%matrix, matrix_type=dbcsr_type_no_symmetry)
498 NULLIFY (matrix_ax, matrix_cg, matrix_cg_z, matrix_res, matrix_z, matrix_z0)
507 ALLOCATE (matrix_ax(ispin)%matrix)
508 ALLOCATE (matrix_cg(ispin)%matrix)
509 ALLOCATE (matrix_cg_z(ispin)%matrix)
510 ALLOCATE (matrix_res(ispin)%matrix)
511 ALLOCATE (matrix_z(ispin)%matrix)
512 ALLOCATE (matrix_z0(ispin)%matrix)
513 CALL dbcsr_create(matrix_ax(ispin)%matrix, name=
"linop MATRIX", &
514 template=matrix_s(1)%matrix, &
515 matrix_type=dbcsr_type_no_symmetry)
516 CALL dbcsr_create(matrix_cg(ispin)%matrix, name=
"TRIAL MATRIX", &
517 template=matrix_s(1)%matrix, &
518 matrix_type=dbcsr_type_no_symmetry)
519 CALL dbcsr_create(matrix_cg_z(ispin)%matrix, name=
"MATRIX CG-Z", &
520 template=matrix_s(1)%matrix, &
521 matrix_type=dbcsr_type_no_symmetry)
522 CALL dbcsr_create(matrix_res(ispin)%matrix, name=
"RESIDUE", &
523 template=matrix_s(1)%matrix, &
524 matrix_type=dbcsr_type_no_symmetry)
525 CALL dbcsr_create(matrix_z(ispin)%matrix, name=
"Z-Matrix", &
526 template=matrix_s(1)%matrix, &
527 matrix_type=dbcsr_type_no_symmetry)
528 CALL dbcsr_create(matrix_z0(ispin)%matrix, name=
"p after precondi-Matrix", &
529 template=matrix_s(1)%matrix, &
530 matrix_type=dbcsr_type_no_symmetry)
539 IF (nspins == 1) focc = -4.0_dp
542 CALL commutator(matrix_nsc, matrix_p, matrix_res, eps_filter, .false., alpha=focc)
546 CALL dbcsr_copy(matrix_cg_z(ispin)%matrix, matrix_res(ispin)%matrix)
550 CALL projector(qs_env, matrix_p, matrix_cg_z, eps_filter)
553 CALL build_hessian_op(qs_env=qs_env, &
555 matrix_ks=matrix_ks, &
557 matrix_s_sqrt_inv=matrix_s_sqrt_inv, &
558 matrix_cg=matrix_cg_z, &
559 matrix_ax=matrix_ax, &
560 eps_filter=eps_filter)
564 CALL dbcsr_add(matrix_res(ispin)%matrix, matrix_ax(ispin)%matrix, 1.0_dp, -1.0_dp)
568 CALL projector(qs_env, matrix_p, matrix_res, eps_filter)
571 linres_control%flag =
""
572 IF (linres_control%preconditioner_type ==
precond_mlp)
THEN
575 CALL ec_preconditioner(qs_env=qs_env, &
576 matrix_ks=matrix_ks, &
578 matrix_rhs=matrix_res, &
579 matrix_cg_z=matrix_z0, &
580 eps_filter=eps_filter, &
581 iounit=iounit, silent=silent)
582 linres_control%flag =
"PCG-AO"
586 CALL dbcsr_copy(matrix_z0(ispin)%matrix, matrix_res(ispin)%matrix)
587 linres_control%flag =
"CG-AO"
595 CALL dbcsr_copy(matrix_cg(ispin)%matrix, matrix_z0(ispin)%matrix)
598 CALL dbcsr_dot(matrix_res(ispin)%matrix, matrix_cg(ispin)%matrix, norm_rr(ispin))
600 IF (norm_rr(ispin) < 0.0_dp) cpabort(
"norm_rr < 0")
601 norm_res = max(norm_res, abs(norm_rr(ispin)/real(nao,
dp)))
606 old_conv = norm_rr(1)
607 shift = min(10.0_dp, max(min_shift, 0.05_dp*old_conv))
611 IF (iounit > 0 .AND. .NOT. my_silent)
THEN
612 WRITE (iounit,
"(/,T3,A,T16,A,T25,A,T38,A,T52,A,/,T3,A)") &
613 "Iteration",
"Method",
"Stepsize",
"Convergence",
"Time", &
619 should_stop = .false.
620 linres_control%converged = .false.
623 iteration:
DO i = 1, linres_control%max_iter
627 IF (norm_res < linres_control%eps)
THEN
628 linres_control%converged = .true.
632 IF (i == 1 .OR. mod(i, 1) == 0 .OR. linres_control%converged &
633 .OR. restart .OR. should_stop)
THEN
634 IF (iounit > 0 .AND. .NOT. my_silent)
THEN
635 WRITE (iounit,
"(T5,I5,T18,A3,T28,L1,T38,1E8.2,T48,F16.10,T68,F8.2)") &
636 i, linres_control%flag, restart, maxval(alpha), norm_res, t2 - t1
640 IF (linres_control%converged)
THEN
642 WRITE (iounit,
"(/,T2,A,I4,A,T73,F8.2,/)")
"The linear solver converged in ", &
643 i,
" iterations.", t2 - t1
647 ELSE IF (should_stop)
THEN
649 WRITE (iounit,
"(/,T2,A,I4,A,/)")
"The linear solver did NOT converge! External stop"
656 IF (i == linres_control%max_iter)
THEN
658 WRITE (iounit,
"(/,T2,A/)") &
659 "The linear solver didnt converge! Maximum number of iterations reached."
662 linres_control%converged = .false.
666 CALL build_hessian_op(qs_env=qs_env, &
668 matrix_ks=matrix_ks, &
670 matrix_s_sqrt_inv=matrix_s_sqrt_inv, &
671 matrix_cg=matrix_cg, &
672 matrix_ax=matrix_ax, &
673 eps_filter=eps_filter)
676 CALL projector(qs_env, matrix_p, matrix_ax, eps_filter)
682 CALL dbcsr_dot(matrix_cg(ispin)%matrix, matrix_ax(ispin)%matrix, norm_ca(ispin))
684 IF (norm_ca(ispin) < 0.0_dp)
THEN
689 CALL dbcsr_add(matrix_cg(ispin)%matrix, matrix_z0(ispin)%matrix, &
690 beta(ispin), -1.0_dp)
691 CALL dbcsr_dot(matrix_res(ispin)%matrix, matrix_res(ispin)%matrix, new_norm(ispin))
692 beta(ispin) = new_norm(ispin)/tr_rz00(ispin)
693 CALL dbcsr_add(matrix_cg(ispin)%matrix, matrix_res(ispin)%matrix, &
695 norm_rr(ispin) = new_norm(ispin)
697 CALL dbcsr_copy(matrix_res(ispin)%matrix, matrix_cg(ispin)%matrix)
698 CALL dbcsr_dot(matrix_res(ispin)%matrix, matrix_res(ispin)%matrix, norm_rr(ispin))
701 CALL build_hessian_op(qs_env=qs_env, &
703 matrix_ks=matrix_ks, &
705 matrix_s_sqrt_inv=matrix_s_sqrt_inv, &
706 matrix_cg=matrix_cg, &
707 matrix_ax=matrix_ax, &
708 eps_filter=eps_filter)
711 CALL projector(qs_env, matrix_p, matrix_ax, eps_filter)
713 CALL dbcsr_dot(matrix_cg(ispin)%matrix, matrix_ax(ispin)%matrix, norm_ca(ispin))
715 cpabort(
"tr(Ap_j*p_j) < 0")
717 cpabort(
"Preconditioner: Tr[Ap_j*p_j] is an abnormal value (NaN/Inf)")
726 IF (norm_ca(ispin) < linres_control%eps)
THEN
727 alpha(ispin) = 1.0_dp
729 alpha(ispin) = norm_rr(ispin)/norm_ca(ispin)
734 CALL dbcsr_add(matrix_cg_z(ispin)%matrix, matrix_cg(ispin)%matrix, 1.0_dp, alpha(ispin))
739 IF (mod(i, linres_control%restart_every) == 0)
THEN
742 CALL build_hessian_op(qs_env=qs_env, &
744 matrix_ks=matrix_ks, &
746 matrix_s_sqrt_inv=matrix_s_sqrt_inv, &
747 matrix_cg=matrix_cg_z, &
748 matrix_ax=matrix_ax, &
749 eps_filter=eps_filter)
751 CALL commutator(matrix_nsc, matrix_p, matrix_res, eps_filter, .false., alpha=focc)
754 CALL dbcsr_add(matrix_res(ispin)%matrix, matrix_ax(ispin)%matrix, 1.0_dp, -1.0_dp)
757 CALL projector(qs_env, matrix_p, matrix_res, eps_filter)
762 CALL projector(qs_env, matrix_p, matrix_ax, eps_filter)
766 CALL dbcsr_add(matrix_res(ispin)%matrix, matrix_ax(ispin)%matrix, 1.0_dp, -alpha(ispin))
772 linres_control%flag =
""
773 IF (linres_control%preconditioner_type ==
precond_mlp)
THEN
776 CALL ec_preconditioner(qs_env=qs_env, &
777 matrix_ks=matrix_ks, &
779 matrix_rhs=matrix_res, &
780 matrix_cg_z=matrix_z0, &
781 eps_filter=eps_filter, &
782 iounit=iounit, silent=silent)
783 linres_control%flag =
"PCG-AO"
786 CALL dbcsr_copy(matrix_z0(ispin)%matrix, matrix_res(ispin)%matrix)
788 linres_control%flag =
"CG-AO"
795 CALL dbcsr_dot(matrix_res(ispin)%matrix, matrix_z0(ispin)%matrix, new_norm(ispin))
796 IF (new_norm(ispin) < 0.0_dp) cpabort(
"tr(r_j+1*z_j+1) < 0")
798 cpabort(
"Preconditioner: Tr[r_j+1*z_j+1] is an abnormal value (NaN/Inf)")
800 norm_res = max(norm_res, new_norm(ispin)/real(nao,
dp))
802 IF (norm_rr(ispin) < linres_control%eps .OR. new_norm(ispin) < linres_control%eps)
THEN
804 linres_control%converged = .true.
806 beta(ispin) = new_norm(ispin)/norm_rr(ispin)
811 CALL dbcsr_add(matrix_cg(ispin)%matrix, matrix_z0(ispin)%matrix, beta(ispin), 1.0_dp)
814 tr_rz00(ispin) = norm_rr(ispin)
815 norm_rr(ispin) = new_norm(ispin)
819 CALL external_control(should_stop,
"LS_SOLVER", target_time=qs_env%target_time, &
820 start_time=qs_env%start_time)
825 CALL projector(qs_env, matrix_p, matrix_cg_z, eps_filter)
828 CALL commutator(matrix_cg_z, matrix_p, matrix_z, eps_filter, .true., alpha=0.5_dp)
832 CALL transform_m_orth(matrix_z(ispin)%matrix, matrix_s_sqrt_inv, eps_filter)
835 CALL dbcsr_copy(matrix_pz(ispin)%matrix, matrix_z(ispin)%matrix, keep_sparsity=.true.)
840 CALL ec_wz_matrix(qs_env, matrix_pz, matrix_wz, eps_filter)
858 DEALLOCATE (alpha, beta, new_norm, norm_ca, norm_rr)
861 CALL timestop(handle)
876 SUBROUTINE ec_wz_matrix(qs_env, matrix_z, matrix_wz, eps_filter)
883 REAL(kind=
dp),
INTENT(IN) :: eps_filter
885 CHARACTER(len=*),
PARAMETER :: routinen =
'ec_wz_matrix'
887 INTEGER :: handle, ispin, nspins
888 REAL(kind=
dp) :: scaling
889 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_p, matrix_s
894 CALL timeset(routinen, handle)
896 cpassert(
ASSOCIATED(qs_env))
897 cpassert(
ASSOCIATED(matrix_z))
898 cpassert(
ASSOCIATED(matrix_wz))
901 dft_control=dft_control, &
902 matrix_ks=matrix_ks, &
905 nspins = dft_control%nspins
910 CALL dbcsr_create(matrix_tmp, template=matrix_z(1)%matrix, &
911 matrix_type=dbcsr_type_no_symmetry)
912 CALL dbcsr_create(matrix_tmp2, template=matrix_z(1)%matrix, &
913 matrix_type=dbcsr_type_no_symmetry)
917 IF (nspins == 1) scaling = 0.5_dp
923 CALL dbcsr_multiply(
"N",
"N", scaling, matrix_ks(ispin)%matrix, matrix_p(ispin)%matrix, &
924 0.0_dp, matrix_tmp, filter_eps=eps_filter, retain_sparsity=.false.)
927 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, matrix_z(ispin)%matrix, matrix_tmp, &
928 0.0_dp, matrix_tmp2, filter_eps=eps_filter, retain_sparsity=.false.)
934 CALL dbcsr_add(matrix_tmp, matrix_tmp2, 1.0_dp, 1.0_dp)
939 CALL dbcsr_copy(matrix_wz(ispin)%matrix, matrix_tmp, keep_sparsity=.true.)
947 CALL timestop(handle)
949 END SUBROUTINE ec_wz_matrix
968 SUBROUTINE hessian_op1(matrix_ks, matrix_p, matrix_cg, matrix_b, matrix_Ax, eps_filter)
971 POINTER :: matrix_ks, matrix_p, matrix_cg
973 POINTER :: matrix_b, matrix_ax
974 REAL(kind=
dp),
INTENT(IN) :: eps_filter
976 CHARACTER(len=*),
PARAMETER :: routinen =
'hessian_op1'
980 CALL timeset(routinen, handle)
982 cpassert(
ASSOCIATED(matrix_ks))
983 cpassert(
ASSOCIATED(matrix_p))
984 cpassert(
ASSOCIATED(matrix_cg))
985 cpassert(
ASSOCIATED(matrix_b))
986 cpassert(
ASSOCIATED(matrix_ax))
990 CALL commutator(matrix_cg, matrix_p, matrix_b, eps_filter, .true.)
994 CALL commutator(matrix_ks, matrix_b, matrix_ax, eps_filter, .false.)
996 CALL timestop(handle)
998 END SUBROUTINE hessian_op1
1017 SUBROUTINE build_hessian_op(qs_env, p_env, matrix_ks, matrix_p, matrix_s_sqrt_inv, &
1018 matrix_cg, matrix_Ax, eps_filter)
1023 POINTER :: matrix_ks, matrix_p
1024 TYPE(
dbcsr_type),
INTENT(IN) :: matrix_s_sqrt_inv
1026 POINTER :: matrix_cg
1028 POINTER :: matrix_ax
1029 REAL(kind=
dp),
INTENT(IN) :: eps_filter
1031 CHARACTER(len=*),
PARAMETER :: routinen =
'build_hessian_op'
1033 INTEGER :: handle, ispin, nspins
1034 REAL(kind=
dp) :: chksum
1035 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_b, rho1_ao
1040 CALL timeset(routinen, handle)
1042 cpassert(
ASSOCIATED(qs_env))
1043 cpassert(
ASSOCIATED(matrix_ks))
1044 cpassert(
ASSOCIATED(matrix_p))
1045 cpassert(
ASSOCIATED(matrix_cg))
1046 cpassert(
ASSOCIATED(matrix_ax))
1049 dft_control=dft_control, &
1050 para_env=para_env, &
1052 nspins = dft_control%nspins
1056 DO ispin = 1, nspins
1057 ALLOCATE (matrix_b(ispin)%matrix)
1058 CALL dbcsr_create(matrix_b(ispin)%matrix, name=
"[X,P] RSP DNSTY", &
1059 template=matrix_p(1)%matrix, &
1060 matrix_type=dbcsr_type_no_symmetry)
1064 CALL hessian_op1(matrix_ks, matrix_p, matrix_cg, matrix_b, matrix_ax, eps_filter)
1067 DO ispin = 1, nspins
1072 DO ispin = 1, nspins
1077 IF (chksum > 1.0e-14_dp)
THEN
1087 DO ispin = 1, nspins
1089 CALL transform_m_orth(matrix_b(ispin)%matrix, matrix_s_sqrt_inv, eps_filter)
1093 CALL dbcsr_copy(rho1_ao(ispin)%matrix, matrix_b(ispin)%matrix, keep_sparsity=.true.)
1094 CALL dbcsr_copy(p_env%p1(ispin)%matrix, matrix_b(ispin)%matrix, keep_sparsity=.true.)
1100 DO ispin = 1, nspins
1101 CALL dbcsr_set(p_env%kpp1(ispin)%matrix, 0.0_dp)
1102 IF (
ASSOCIATED(p_env%kpp1_admm))
CALL dbcsr_set(p_env%kpp1_admm(ispin)%matrix, 0.0_dp)
1108 CALL hessian_op2(qs_env, p_env, matrix_ax, matrix_p, matrix_s_sqrt_inv, eps_filter)
1114 CALL timestop(handle)
1116 END SUBROUTINE build_hessian_op
1134 SUBROUTINE hessian_op2(qs_env, p_env, matrix_Ax, matrix_p, matrix_s_sqrt_inv, eps_filter)
1139 POINTER :: matrix_ax
1142 TYPE(
dbcsr_type),
INTENT(IN) :: matrix_s_sqrt_inv
1143 REAL(kind=
dp),
INTENT(IN) :: eps_filter
1145 CHARACTER(len=*),
PARAMETER :: routinen =
'hessian_op2'
1147 INTEGER :: handle, ispin, nspins
1148 REAL(kind=
dp) :: ekin_mol
1150 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_g, matrix_s, rho1_ao, rho_ao
1160 TYPE(
pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho1_r, rho_r, tau1_r, v_xc, v_xc_tau
1164 TYPE(
rho_atom_type),
DIMENSION(:),
POINTER :: rho0_atom_set, rho1_atom_set
1167 CALL timeset(routinen, handle)
1169 NULLIFY (admm_env, dft_control, input, matrix_s, para_env, rho, rho_r, rho1_g, rho1_r)
1172 admm_env=admm_env, &
1173 dft_control=dft_control, &
1175 matrix_s=matrix_s, &
1176 para_env=para_env, &
1178 nspins = dft_control%nspins
1180 cpassert(
ASSOCIATED(p_env%kpp1))
1181 cpassert(
ASSOCIATED(p_env%kpp1_env))
1182 kpp1_env => p_env%kpp1_env
1187 CALL qs_rho_get(p_env%rho1, rho_g=rho1_g, rho_r=rho1_r, tau_r=tau1_r)
1191 cpassert(
ASSOCIATED(pw_env))
1194 CALL get_qs_env(qs_env, xcint_weights=weights)
1196 NULLIFY (auxbas_pw_pool, poisson_env, pw_pools)
1199 auxbas_pw_pool=auxbas_pw_pool, &
1200 pw_pools=pw_pools, &
1201 poisson_env=poisson_env)
1204 CALL auxbas_pw_pool%create_pw(pw=v_hartree_gspace)
1205 CALL auxbas_pw_pool%create_pw(pw=rho_tot_gspace)
1206 CALL auxbas_pw_pool%create_pw(pw=v_hartree_rspace)
1209 NULLIFY (v_xc, v_xc_tau, xc_section)
1211 IF (dft_control%do_admm)
THEN
1212 xc_section => admm_env%xc_section_primary
1218 CALL qs_fxc_create(qs_env, rho, p_env%rho1, rho0_atom_set, xc_section, .false., &
1219 v_xc, v_xc_tau, rho1_atom_set)
1221 DO ispin = 1, nspins
1222 CALL pw_scale(v_xc(ispin), v_xc(ispin)%pw_grid%dvol)
1223 IF (
ASSOCIATED(v_xc_tau))
THEN
1224 CALL pw_scale(v_xc_tau(ispin), v_xc_tau(ispin)%pw_grid%dvol)
1229 IF (dft_control%do_admm)
THEN
1231 IF (.NOT.
ASSOCIATED(kpp1_env%deriv_set_admm))
THEN
1232 xc_section_aux => admm_env%xc_section_aux
1234 ALLOCATE (kpp1_env%deriv_set_admm, kpp1_env%rho_set_admm)
1235 CALL qs_fxc_prep(qs_env, rho_aux, kpp1_env%rho_set_admm, kpp1_env%deriv_set_admm, &
1236 xc_section_aux, pw_env, is_triplet=.false.)
1243 DO ispin = 1, nspins
1244 CALL pw_axpy(rho1_g(ispin), rho_tot_gspace)
1249 vhartree=v_hartree_gspace)
1250 CALL pw_transfer(v_hartree_gspace, v_hartree_rspace)
1251 CALL pw_scale(v_hartree_rspace, v_hartree_rspace%pw_grid%dvol)
1254 DO ispin = 1, nspins
1255 CALL pw_axpy(v_hartree_rspace, v_xc(ispin))
1257 IF (nspins == 1)
THEN
1259 IF (
ASSOCIATED(v_xc_tau))
CALL pw_scale(v_xc_tau(1), 2.0_dp)
1262 DO ispin = 1, nspins
1264 CALL integrate_v_rspace(v_rspace=v_xc(ispin), &
1265 pmat=rho_ao(ispin), &
1266 hmat=p_env%kpp1(ispin), &
1268 calculate_forces=.false., &
1270 IF (
ASSOCIATED(v_xc_tau))
THEN
1271 CALL integrate_v_rspace(v_rspace=v_xc_tau(ispin), &
1272 pmat=rho_ao(ispin), &
1273 hmat=p_env%kpp1(ispin), &
1275 compute_tau=.true., &
1276 calculate_forces=.false., &
1289 IF (dft_control%qs_control%do_kg)
THEN
1293 cpassert(dft_control%nimages == 1)
1297 ks_matrix=p_env%kpp1, &
1298 ekin_mol=ekin_mol, &
1299 calc_force=.false., &
1309 DO ispin = 1, nspins
1310 ALLOCATE (matrix_g(ispin)%matrix)
1311 CALL dbcsr_copy(matrix_g(ispin)%matrix, p_env%kpp1(ispin)%matrix, &
1312 name=
"MATRIX Kernel")
1317 DO ispin = 1, nspins
1318 CALL transform_m_orth(matrix_g(ispin)%matrix, matrix_s_sqrt_inv, eps_filter)
1324 CALL commutator(matrix_g, matrix_p, matrix_ax, eps_filter, .false., 1.0_dp, 1.0_dp)
1327 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace)
1328 CALL auxbas_pw_pool%give_back_pw(v_hartree_rspace)
1329 CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace)
1330 DO ispin = 1, nspins
1331 CALL auxbas_pw_pool%give_back_pw(v_xc(ispin))
1334 IF (
ASSOCIATED(v_xc_tau))
THEN
1335 DO ispin = 1, nspins
1336 CALL auxbas_pw_pool%give_back_pw(v_xc_tau(ispin))
1338 DEALLOCATE (v_xc_tau)
1343 CALL timestop(handle)
1345 END SUBROUTINE hessian_op2
1363 SUBROUTINE commutator(a, b, res, eps_filter, anticomm, alpha, beta)
1366 POINTER :: a, b, res
1367 REAL(kind=
dp) :: eps_filter
1369 REAL(kind=
dp),
OPTIONAL :: alpha, beta
1371 CHARACTER(LEN=*),
PARAMETER :: routinen =
'commutator'
1373 INTEGER :: handle, ispin
1374 REAL(kind=
dp) :: facc, myalpha, mybeta
1377 CALL timeset(routinen, handle)
1379 cpassert(
ASSOCIATED(a))
1380 cpassert(
ASSOCIATED(b))
1381 cpassert(
ASSOCIATED(res))
1383 CALL dbcsr_create(work, template=a(1)%matrix, matrix_type=dbcsr_type_no_symmetry)
1384 CALL dbcsr_create(work2, template=a(1)%matrix, matrix_type=dbcsr_type_no_symmetry)
1388 IF (
PRESENT(alpha)) myalpha = alpha
1391 IF (
PRESENT(beta)) mybeta = beta
1394 IF (anticomm) facc = 1.0_dp
1396 DO ispin = 1,
SIZE(a)
1398 CALL dbcsr_multiply(
"N",
"N", myalpha, a(ispin)%matrix, b(ispin)%matrix, &
1399 0.0_dp, work, filter_eps=eps_filter)
1404 CALL dbcsr_add(work, work2, 1.0_dp, facc)
1406 CALL dbcsr_add(res(ispin)%matrix, work, mybeta, 1.0_dp)
1413 CALL timestop(handle)
1415 END SUBROUTINE commutator
1430 SUBROUTINE projector(qs_env, matrix_p, matrix_io, eps_filter)
1436 POINTER :: matrix_io
1437 REAL(kind=
dp),
INTENT(IN) :: eps_filter
1439 CHARACTER(len=*),
PARAMETER :: routinen =
'projector'
1441 INTEGER :: handle, ispin, nspins
1446 CALL timeset(routinen, handle)
1449 dft_control=dft_control, &
1451 nspins = dft_control%nspins
1453 CALL dbcsr_create(matrix_q, template=matrix_p(1)%matrix, &
1454 matrix_type=dbcsr_type_no_symmetry)
1455 CALL dbcsr_create(matrix_tmp, template=matrix_p(1)%matrix, &
1456 matrix_type=dbcsr_type_no_symmetry)
1459 CALL dbcsr_copy(matrix_q, matrix_p(1)%matrix)
1467 DO ispin = 1, nspins
1470 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, matrix_p(ispin)%matrix, matrix_io(ispin)%matrix, &
1471 0.0_dp, matrix_tmp, filter_eps=eps_filter)
1474 0.0_dp, matrix_io(ispin)%matrix, filter_eps=eps_filter)
1478 CALL dbcsr_add(matrix_io(ispin)%matrix, matrix_tmp, 1.0_dp, -1.0_dp)
1485 CALL timestop(handle)
1487 END SUBROUTINE projector
1501 SUBROUTINE transform_m_orth(matrix, matrix_trafo, eps_filter)
1503 REAL(kind=
dp) :: eps_filter
1505 CHARACTER(LEN=*),
PARAMETER :: routinen =
'transform_m_orth'
1510 CALL timeset(routinen, handle)
1512 CALL dbcsr_create(matrix_work, template=matrix, matrix_type=dbcsr_type_no_symmetry)
1513 CALL dbcsr_create(matrix_tmp, template=matrix, matrix_type=dbcsr_type_no_symmetry)
1516 0.0_dp, matrix_work, filter_eps=eps_filter)
1517 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, matrix_trafo, matrix_work, &
1518 0.0_dp, matrix_tmp, filter_eps=eps_filter)
1521 CALL dbcsr_add(matrix_tmp, matrix_work, 0.5_dp, 0.5_dp)
1529 CALL timestop(handle)
1531 END SUBROUTINE transform_m_orth
Types and set/get functions for auxiliary density matrix methods.
subroutine, public get_admm_env(admm_env, mo_derivs_aux_fit, mos_aux_fit, sab_aux_fit, sab_aux_fit_asymm, sab_aux_fit_vs_orb, matrix_s_aux_fit, matrix_s_aux_fit_kp, matrix_s_aux_fit_vs_orb, matrix_s_aux_fit_vs_orb_kp, task_list_aux_fit, matrix_ks_aux_fit, matrix_ks_aux_fit_kp, matrix_ks_aux_fit_im, matrix_ks_aux_fit_dft, matrix_ks_aux_fit_hfx, matrix_ks_aux_fit_dft_kp, matrix_ks_aux_fit_hfx_kp, rho_aux_fit, rho_aux_fit_buffer, admm_dm)
Get routine for the ADMM env.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_transposed(transposed, normal, shallow_data_copy, transpose_distribution, use_distribution)
...
subroutine, public dbcsr_scale(matrix, alpha_scalar)
...
subroutine, public dbcsr_desymmetrize(matrix_a, matrix_b)
...
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_filter(matrix, eps)
...
subroutine, public dbcsr_finalize(matrix)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
real(kind=dp) function, public dbcsr_checksum(matrix, pos)
Calculates the checksum of a DBCSR matrix.
subroutine, public dbcsr_add_on_diag(matrix, alpha)
Adds the given scalar to the diagonal of the matrix. Reserves any missing diagonal blocks.
subroutine, public dbcsr_dot(matrix_a, matrix_b, trace)
Computes the dot product of two matrices, also known as the trace of their matrix product.
DBCSR operations in CP2K.
Routines to handle the external control of CP2K.
subroutine, public external_control(should_stop, flag, globenv, target_time, start_time, force_check)
External manipulations during a run : when the <PROJECT_NAME>.EXIT_$runtype command is sent the progr...
AO-based conjugate-gradient response solver routines.
subroutine, public ec_response_ao(qs_env, p_env, matrix_hz, matrix_pz, matrix_wz, iounit, should_stop, silent)
AO-based conjugate gradient linear response solver. In goes the right hand side B of the equation AZ=...
Routines useful for iterative matrix calculations.
subroutine, public matrix_sqrt_newton_schulz(matrix_sqrt, matrix_sqrt_inv, matrix, threshold, order, eps_lanczos, max_iter_lanczos, symmetrize, converged, iounit)
compute the sqrt of a matrix via the sign function and the corresponding Newton-Schulz iterations the...
subroutine, public matrix_sqrt_proot(matrix_sqrt, matrix_sqrt_inv, matrix, threshold, order, eps_lanczos, max_iter_lanczos, symmetrize, converged)
compute the sqrt of a matrix via the general algorithm for the p-th root of Richters et al....
Routines for a Kim-Gordon-like partitioning into molecular subunits.
subroutine, public kg_ekin_subset(qs_env, ks_matrix, ekin_mol, calc_force, do_kernel, pmat_ext)
Calculates the subsystem Hohenberg-Kohn kinetic energy and the forces.
Defines the basic variable types.
integer, parameter, public dp
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
Collection of simple mathematical functions and subroutines.
logical function, public abnormal_value(a)
determines if a value is not normal (e.g. for Inf and Nan) based on IO to work also under optimizatio...
Interface to the message passing library MPI.
container for various plainwaves related things
subroutine, public pw_env_get(pw_env, pw_pools, cube_info, gridlevel_info, auxbas_pw_pool, auxbas_grid, auxbas_rs_desc, auxbas_rs_grid, rs_descs, rs_grids, xc_pw_pool, vdw_pw_pool, poisson_env, interp_section)
returns the various attributes of the pw env
functions related to the poisson solver on regular grids
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
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.
Setup Routine for Fxc Potentials.
subroutine, public qs_fxc_prep(qs_env, rho0_struct, xc_rho_set, xc_deriv_set, xc_section, pw_env_ext, is_triplet)
...
subroutine, public qs_fxc_create(qs_env, rho0_struct, rho1_struct, rho0_atom_set, xc_section, do_onecenter, fxc_rho, fxc_tau, rho1_atom_set, do_scale, is_triplet, spinflip, no_weights, uf_grid_results, pw_env_ext, kind_set_external, para_env_external, compute_virial, virial_xc)
...
Integrate single or product functions over a potential on a RS grid.
basis types for the calculation of the perturbation of density theory.
subroutine, public apply_xc_admm(qs_env, p_env)
...
subroutine, public apply_hfx(qs_env, p_env)
Update action of TDDFPT operator on trial vectors by adding exact-exchange term.
Type definitiona for linear response calculations.
Utility functions for the perturbation calculations.
subroutine, public p_env_finish_kpp1(qs_env, p_env)
...
subroutine, public p_env_update_rho(p_env, qs_env)
...
subroutine, public p_env_check_i_alloc(p_env, qs_env)
checks that the intenal storage is allocated, and allocs it if needed
basis types for the calculation of the perturbation of density theory.
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...
stores some data used in wavefunction fitting
stores all the informations relevant to an mpi environment
contained for different pw related things
environment for the poisson solver
to create arrays of pools
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
environment that keeps the informations and temporary val to build the kpp1 kernel matrix
General settings for linear response calculations.
Represent a qs system that is perturbed. Can calculate the linear operator and the rhs of the system ...
keeps the density in various representations, keeping track of which ones are valid.