73#include "./base/base_uses.f90"
81 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'ec_orth_solver'
110 SUBROUTINE ec_preconditioner(qs_env, matrix_ks, matrix_p, matrix_rhs, &
111 matrix_cg_z, eps_filter, iounit, silent)
113 TYPE(qs_environment_type),
POINTER :: qs_env
114 TYPE(dbcsr_p_type),
DIMENSION(:),
INTENT(IN), &
115 POINTER :: matrix_ks, matrix_p, matrix_rhs
116 TYPE(dbcsr_p_type),
DIMENSION(:),
INTENT(INOUT), &
117 POINTER :: matrix_cg_z
118 REAL(KIND=
dp),
INTENT(IN) :: eps_filter
119 INTEGER,
INTENT(IN) :: iounit
120 LOGICAL,
INTENT(IN),
OPTIONAL :: silent
122 CHARACTER(len=*),
PARAMETER :: routineN =
'ec_preconditioner'
124 INTEGER :: handle, i, ispin, max_iter, nao, nspins
125 LOGICAL :: converged, my_silent
126 REAL(KIND=
dp) :: norm_res, t1, t2
127 REAL(KIND=
dp),
DIMENSION(:),
POINTER :: alpha, beta, new_norm, norm_ca, norm_rr
128 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_Ax, matrix_b, matrix_cg, &
130 TYPE(dft_control_type),
POINTER :: dft_control
131 TYPE(linres_control_type),
POINTER :: linres_control
133 CALL timeset(routinen, handle)
136 IF (
PRESENT(silent)) my_silent = silent
138 cpassert(
ASSOCIATED(qs_env))
139 cpassert(
ASSOCIATED(matrix_ks))
140 cpassert(
ASSOCIATED(matrix_p))
141 cpassert(
ASSOCIATED(matrix_rhs))
142 cpassert(
ASSOCIATED(matrix_cg_z))
144 NULLIFY (dft_control, linres_control)
149 dft_control=dft_control, &
150 linres_control=linres_control)
151 nspins = dft_control%nspins
154 ALLOCATE (alpha(nspins), beta(nspins), new_norm(nspins), norm_ca(nspins), norm_rr(nspins))
160 NULLIFY (matrix_ax, matrix_b, matrix_cg, matrix_res)
167 ALLOCATE (matrix_ax(ispin)%matrix)
168 ALLOCATE (matrix_b(ispin)%matrix)
169 ALLOCATE (matrix_cg(ispin)%matrix)
170 ALLOCATE (matrix_res(ispin)%matrix)
171 CALL dbcsr_create(matrix_ax(ispin)%matrix, name=
"linop MATRIX", &
172 template=matrix_ks(1)%matrix, &
173 matrix_type=dbcsr_type_no_symmetry)
174 CALL dbcsr_create(matrix_b(ispin)%matrix, name=
"MATRIX B", &
175 template=matrix_ks(1)%matrix, &
176 matrix_type=dbcsr_type_no_symmetry)
177 CALL dbcsr_create(matrix_cg(ispin)%matrix, name=
"TRIAL MATRIX", &
178 template=matrix_ks(1)%matrix, &
179 matrix_type=dbcsr_type_no_symmetry)
180 CALL dbcsr_create(matrix_res(ispin)%matrix, name=
"RESIDUE", &
181 template=matrix_ks(1)%matrix, &
182 matrix_type=dbcsr_type_no_symmetry)
191 CALL dbcsr_copy(matrix_cg_z(ispin)%matrix, matrix_rhs(ispin)%matrix)
194 CALL dbcsr_copy(matrix_res(ispin)%matrix, matrix_rhs(ispin)%matrix)
203 CALL hessian_op1(matrix_ks, matrix_p, matrix_cg_z, matrix_b, matrix_ax, eps_filter)
207 CALL dbcsr_add(matrix_res(ispin)%matrix, matrix_ax(ispin)%matrix, 1.0_dp, -1.0_dp)
211 CALL projector(qs_env, matrix_p, matrix_res, eps_filter)
215 CALL dbcsr_copy(matrix_cg(ispin)%matrix, matrix_res(ispin)%matrix)
219 IF (iounit > 0 .AND. .NOT. my_silent)
THEN
220 WRITE (iounit,
"(/,T10,A)")
"Preconditioning of search direction"
221 WRITE (iounit,
"(/,T10,A,T25,A,T42,A,T62,A,/,T10,A)") &
222 "Iteration",
"Stepsize",
"Convergence",
"Time", &
232 iteration:
DO i = 1, max_iter
235 CALL hessian_op1(matrix_ks, matrix_p, matrix_cg, matrix_b, matrix_ax, eps_filter)
238 CALL projector(qs_env, matrix_p, matrix_ax, eps_filter)
243 CALL dbcsr_dot(matrix_res(ispin)%matrix, matrix_res(ispin)%matrix, norm_rr(ispin))
245 cpabort(
"Preconditioner: Tr[r_j*r_j] is an abnormal value (NaN/Inf)")
247 IF (norm_rr(ispin) < 0.0_dp) cpabort(
"norm_rr < 0")
248 norm_res = max(norm_res, abs(norm_rr(ispin)/real(nao,
dp)))
251 CALL dbcsr_dot(matrix_cg(ispin)%matrix, matrix_ax(ispin)%matrix, norm_ca(ispin))
254 IF (norm_ca(ispin) < linres_control%eps)
THEN
255 alpha(ispin) = 1.0_dp
257 alpha(ispin) = norm_rr(ispin)/norm_ca(ispin)
262 CALL dbcsr_add(matrix_cg_z(ispin)%matrix, matrix_cg(ispin)%matrix, 1.0_dp, alpha(ispin))
265 CALL dbcsr_add(matrix_res(ispin)%matrix, matrix_ax(ispin)%matrix, 1.0_dp, -alpha(ispin))
273 CALL dbcsr_dot(matrix_res(ispin)%matrix, matrix_res(ispin)%matrix, new_norm(ispin))
274 IF (new_norm(ispin) < 0.0_dp) cpabort(
"tr(r_j+1*z_j+1) < 0")
276 cpabort(
"Preconditioner: Tr[r_j+1*z_j+1] is an abnormal value (NaN/Inf)")
277 norm_res = max(norm_res, new_norm(ispin)/real(nao,
dp))
279 IF (norm_rr(ispin) < linres_control%eps*0.001_dp &
280 .OR. new_norm(ispin) < linres_control%eps*0.001_dp)
THEN
284 beta(ispin) = new_norm(ispin)/norm_rr(ispin)
289 CALL dbcsr_add(matrix_cg(ispin)%matrix, matrix_res(ispin)%matrix, beta(ispin), 1.0_dp)
292 norm_rr(ispin) = new_norm(ispin)
296 IF (norm_res < linres_control%eps)
THEN
301 IF (i == 1 .OR. mod(i, 1) == 0 .OR. converged)
THEN
302 IF (iounit > 0 .AND. .NOT. my_silent)
THEN
303 WRITE (iounit,
"(T10,I5,T25,1E8.2,T33,F25.14,T58,F8.2)") &
304 i, maxval(alpha), norm_res, t2 - t1
312 IF (iounit > 0 .AND. .NOT. my_silent)
THEN
313 WRITE (iounit,
"(/,T10,A,I4,A,/)")
"The precon solver converged in ", i,
" iterations."
320 IF (i == max_iter)
THEN
322 WRITE (iounit,
"(/,T10,A/)") &
323 "The precon solver didnt converge! Maximum number of iterations reached."
332 CALL projector(qs_env, matrix_p, matrix_cg_z, eps_filter)
340 DEALLOCATE (alpha, beta, new_norm, norm_ca, norm_rr)
342 CALL timestop(handle)
344 END SUBROUTINE ec_preconditioner
364 SUBROUTINE ec_response_ao(qs_env, p_env, matrix_hz, matrix_pz, matrix_wz, iounit, &
372 POINTER :: matrix_pz, matrix_wz
373 INTEGER,
INTENT(IN) :: iounit
374 LOGICAL,
INTENT(OUT) :: should_stop
375 LOGICAL,
INTENT(IN),
OPTIONAL :: silent
377 CHARACTER(len=*),
PARAMETER :: routinen =
'ec_response_ao'
379 INTEGER :: handle, i, ispin, max_iter_lanczos, nao, &
380 nspins, s_sqrt_method, s_sqrt_order
381 LOGICAL :: my_silent, restart
382 REAL(kind=
dp) :: eps_filter, eps_lanczos, focc, &
383 min_shift, norm_res, old_conv, shift, &
385 REAL(kind=
dp),
DIMENSION(:),
POINTER :: alpha, beta, new_norm, norm_ca, norm_rr, &
387 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: ksmat, matrix_ax, matrix_cg, matrix_cg_z, &
388 matrix_ks, matrix_nsc, matrix_p, matrix_res, matrix_s, matrix_z, matrix_z0, rho_ao
389 TYPE(
dbcsr_type) :: matrix_s_sqrt, matrix_s_sqrt_inv, &
396 CALL timeset(routinen, handle)
399 IF (
PRESENT(silent)) my_silent = silent
401 cpassert(
ASSOCIATED(qs_env))
402 cpassert(
ASSOCIATED(matrix_hz))
403 cpassert(
ASSOCIATED(matrix_pz))
404 cpassert(
ASSOCIATED(matrix_wz))
406 NULLIFY (dft_control, ksmat, matrix_s, linres_control, rho)
411 dft_control=dft_control, &
412 linres_control=linres_control, &
416 nspins = dft_control%nspins
426 eps_filter = linres_control%eps_filter
430 ALLOCATE (alpha(nspins), beta(nspins), new_norm(nspins), norm_ca(nspins), norm_rr(nspins))
431 ALLOCATE (tr_rz00(nspins))
435 NULLIFY (matrix_p, matrix_ks, matrix_nsc)
440 ALLOCATE (matrix_p(ispin)%matrix)
441 ALLOCATE (matrix_ks(ispin)%matrix)
442 ALLOCATE (matrix_nsc(ispin)%matrix)
443 CALL dbcsr_create(matrix_p(ispin)%matrix, name=
"P_IN ORTHO", &
444 template=ksmat(1)%matrix, &
445 matrix_type=dbcsr_type_no_symmetry)
446 CALL dbcsr_create(matrix_ks(ispin)%matrix, name=
"KS_IN ORTHO", &
447 template=ksmat(1)%matrix, &
448 matrix_type=dbcsr_type_no_symmetry)
449 CALL dbcsr_create(matrix_nsc(ispin)%matrix, name=
"NSC IN ORTHO", &
450 template=ksmat(1)%matrix, &
451 matrix_type=dbcsr_type_no_symmetry)
459 IF (nspins == 1)
CALL dbcsr_scale(matrix_p(1)%matrix, 0.5_dp)
462 CALL dbcsr_create(matrix_s_sqrt, template=matrix_s(1)%matrix, &
463 matrix_type=dbcsr_type_no_symmetry)
464 CALL dbcsr_create(matrix_s_sqrt_inv, template=matrix_s(1)%matrix, &
465 matrix_type=dbcsr_type_no_symmetry)
467 SELECT CASE (s_sqrt_method)
470 matrix_s(1)%matrix, eps_filter, &
471 s_sqrt_order, eps_lanczos, max_iter_lanczos, symmetrize=.true.)
474 matrix_s(1)%matrix, eps_filter, &
475 s_sqrt_order, eps_lanczos, max_iter_lanczos)
477 cpabort(
"Unknown sqrt method.")
482 CALL transform_m_orth(matrix_p(ispin)%matrix, matrix_s_sqrt, eps_filter)
483 CALL transform_m_orth(matrix_ks(ispin)%matrix, matrix_s_sqrt_inv, eps_filter)
484 CALL transform_m_orth(matrix_nsc(ispin)%matrix, matrix_s_sqrt_inv, eps_filter)
493 CALL dbcsr_create(matrix_tmp, template=matrix_s(1)%matrix, matrix_type=dbcsr_type_no_symmetry)
495 NULLIFY (matrix_ax, matrix_cg, matrix_cg_z, matrix_res, matrix_z, matrix_z0)
504 ALLOCATE (matrix_ax(ispin)%matrix)
505 ALLOCATE (matrix_cg(ispin)%matrix)
506 ALLOCATE (matrix_cg_z(ispin)%matrix)
507 ALLOCATE (matrix_res(ispin)%matrix)
508 ALLOCATE (matrix_z(ispin)%matrix)
509 ALLOCATE (matrix_z0(ispin)%matrix)
510 CALL dbcsr_create(matrix_ax(ispin)%matrix, name=
"linop MATRIX", &
511 template=matrix_s(1)%matrix, &
512 matrix_type=dbcsr_type_no_symmetry)
513 CALL dbcsr_create(matrix_cg(ispin)%matrix, name=
"TRIAL MATRIX", &
514 template=matrix_s(1)%matrix, &
515 matrix_type=dbcsr_type_no_symmetry)
516 CALL dbcsr_create(matrix_cg_z(ispin)%matrix, name=
"MATRIX CG-Z", &
517 template=matrix_s(1)%matrix, &
518 matrix_type=dbcsr_type_no_symmetry)
519 CALL dbcsr_create(matrix_res(ispin)%matrix, name=
"RESIDUE", &
520 template=matrix_s(1)%matrix, &
521 matrix_type=dbcsr_type_no_symmetry)
522 CALL dbcsr_create(matrix_z(ispin)%matrix, name=
"Z-Matrix", &
523 template=matrix_s(1)%matrix, &
524 matrix_type=dbcsr_type_no_symmetry)
525 CALL dbcsr_create(matrix_z0(ispin)%matrix, name=
"p after precondi-Matrix", &
526 template=matrix_s(1)%matrix, &
527 matrix_type=dbcsr_type_no_symmetry)
536 IF (nspins == 1) focc = -4.0_dp
539 CALL commutator(matrix_nsc, matrix_p, matrix_res, eps_filter, .false., alpha=focc)
543 CALL dbcsr_copy(matrix_cg_z(ispin)%matrix, matrix_res(ispin)%matrix)
547 CALL projector(qs_env, matrix_p, matrix_cg_z, eps_filter)
550 CALL build_hessian_op(qs_env=qs_env, &
552 matrix_ks=matrix_ks, &
554 matrix_s_sqrt_inv=matrix_s_sqrt_inv, &
555 matrix_cg=matrix_cg_z, &
556 matrix_ax=matrix_ax, &
557 eps_filter=eps_filter)
561 CALL dbcsr_add(matrix_res(ispin)%matrix, matrix_ax(ispin)%matrix, 1.0_dp, -1.0_dp)
565 CALL projector(qs_env, matrix_p, matrix_res, eps_filter)
568 linres_control%flag =
""
569 IF (linres_control%preconditioner_type ==
precond_mlp)
THEN
572 CALL ec_preconditioner(qs_env=qs_env, &
573 matrix_ks=matrix_ks, &
575 matrix_rhs=matrix_res, &
576 matrix_cg_z=matrix_z0, &
577 eps_filter=eps_filter, &
578 iounit=iounit, silent=silent)
579 linres_control%flag =
"PCG-AO"
583 CALL dbcsr_copy(matrix_z0(ispin)%matrix, matrix_res(ispin)%matrix)
584 linres_control%flag =
"CG-AO"
592 CALL dbcsr_copy(matrix_cg(ispin)%matrix, matrix_z0(ispin)%matrix)
595 CALL dbcsr_dot(matrix_res(ispin)%matrix, matrix_cg(ispin)%matrix, norm_rr(ispin))
597 IF (norm_rr(ispin) < 0.0_dp) cpabort(
"norm_rr < 0")
598 norm_res = max(norm_res, abs(norm_rr(ispin)/real(nao,
dp)))
603 old_conv = norm_rr(1)
604 shift = min(10.0_dp, max(min_shift, 0.05_dp*old_conv))
608 IF (iounit > 0 .AND. .NOT. my_silent)
THEN
609 WRITE (iounit,
"(/,T3,A,T16,A,T25,A,T38,A,T52,A,/,T3,A)") &
610 "Iteration",
"Method",
"Stepsize",
"Convergence",
"Time", &
616 should_stop = .false.
617 linres_control%converged = .false.
620 iteration:
DO i = 1, linres_control%max_iter
624 IF (norm_res < linres_control%eps)
THEN
625 linres_control%converged = .true.
629 IF (i == 1 .OR. mod(i, 1) == 0 .OR. linres_control%converged &
630 .OR. restart .OR. should_stop)
THEN
631 IF (iounit > 0 .AND. .NOT. my_silent)
THEN
632 WRITE (iounit,
"(T5,I5,T18,A3,T28,L1,T38,1E8.2,T48,F16.10,T68,F8.2)") &
633 i, linres_control%flag, restart, maxval(alpha), norm_res, t2 - t1
637 IF (linres_control%converged)
THEN
639 WRITE (iounit,
"(/,T2,A,I4,A,T73,F8.2,/)")
"The linear solver converged in ", &
640 i,
" iterations.", t2 - t1
644 ELSE IF (should_stop)
THEN
646 WRITE (iounit,
"(/,T2,A,I4,A,/)")
"The linear solver did NOT converge! External stop"
653 IF (i == linres_control%max_iter)
THEN
655 WRITE (iounit,
"(/,T2,A/)") &
656 "The linear solver didnt converge! Maximum number of iterations reached."
659 linres_control%converged = .false.
663 CALL build_hessian_op(qs_env=qs_env, &
665 matrix_ks=matrix_ks, &
667 matrix_s_sqrt_inv=matrix_s_sqrt_inv, &
668 matrix_cg=matrix_cg, &
669 matrix_ax=matrix_ax, &
670 eps_filter=eps_filter)
673 CALL projector(qs_env, matrix_p, matrix_ax, eps_filter)
679 CALL dbcsr_dot(matrix_cg(ispin)%matrix, matrix_ax(ispin)%matrix, norm_ca(ispin))
681 IF (norm_ca(ispin) < 0.0_dp)
THEN
686 CALL dbcsr_add(matrix_cg(ispin)%matrix, matrix_z0(ispin)%matrix, &
687 beta(ispin), -1.0_dp)
688 CALL dbcsr_dot(matrix_res(ispin)%matrix, matrix_res(ispin)%matrix, new_norm(ispin))
689 beta(ispin) = new_norm(ispin)/tr_rz00(ispin)
690 CALL dbcsr_add(matrix_cg(ispin)%matrix, matrix_res(ispin)%matrix, &
692 norm_rr(ispin) = new_norm(ispin)
694 CALL dbcsr_copy(matrix_res(ispin)%matrix, matrix_cg(ispin)%matrix)
695 CALL dbcsr_dot(matrix_res(ispin)%matrix, matrix_res(ispin)%matrix, norm_rr(ispin))
698 CALL build_hessian_op(qs_env=qs_env, &
700 matrix_ks=matrix_ks, &
702 matrix_s_sqrt_inv=matrix_s_sqrt_inv, &
703 matrix_cg=matrix_cg, &
704 matrix_ax=matrix_ax, &
705 eps_filter=eps_filter)
708 CALL projector(qs_env, matrix_p, matrix_ax, eps_filter)
710 CALL dbcsr_dot(matrix_cg(ispin)%matrix, matrix_ax(ispin)%matrix, norm_ca(ispin))
712 cpabort(
"tr(Ap_j*p_j) < 0")
714 cpabort(
"Preconditioner: Tr[Ap_j*p_j] is an abnormal value (NaN/Inf)")
722 IF (norm_ca(ispin) < linres_control%eps)
THEN
723 alpha(ispin) = 1.0_dp
725 alpha(ispin) = norm_rr(ispin)/norm_ca(ispin)
730 CALL dbcsr_add(matrix_cg_z(ispin)%matrix, matrix_cg(ispin)%matrix, 1.0_dp, alpha(ispin))
735 IF (mod(i, linres_control%restart_every) == 0)
THEN
738 CALL build_hessian_op(qs_env=qs_env, &
740 matrix_ks=matrix_ks, &
742 matrix_s_sqrt_inv=matrix_s_sqrt_inv, &
743 matrix_cg=matrix_cg_z, &
744 matrix_ax=matrix_ax, &
745 eps_filter=eps_filter)
747 CALL commutator(matrix_nsc, matrix_p, matrix_res, eps_filter, .false., alpha=focc)
750 CALL dbcsr_add(matrix_res(ispin)%matrix, matrix_ax(ispin)%matrix, 1.0_dp, -1.0_dp)
753 CALL projector(qs_env, matrix_p, matrix_res, eps_filter)
758 CALL projector(qs_env, matrix_p, matrix_ax, eps_filter)
762 CALL dbcsr_add(matrix_res(ispin)%matrix, matrix_ax(ispin)%matrix, 1.0_dp, -alpha(ispin))
768 linres_control%flag =
""
769 IF (linres_control%preconditioner_type ==
precond_mlp)
THEN
772 CALL ec_preconditioner(qs_env=qs_env, &
773 matrix_ks=matrix_ks, &
775 matrix_rhs=matrix_res, &
776 matrix_cg_z=matrix_z0, &
777 eps_filter=eps_filter, &
778 iounit=iounit, silent=silent)
779 linres_control%flag =
"PCG-AO"
782 CALL dbcsr_copy(matrix_z0(ispin)%matrix, matrix_res(ispin)%matrix)
784 linres_control%flag =
"CG-AO"
791 CALL dbcsr_dot(matrix_res(ispin)%matrix, matrix_z0(ispin)%matrix, new_norm(ispin))
792 IF (new_norm(ispin) < 0.0_dp) cpabort(
"tr(r_j+1*z_j+1) < 0")
794 cpabort(
"Preconditioner: Tr[r_j+1*z_j+1] is an abnormal value (NaN/Inf)")
795 norm_res = max(norm_res, new_norm(ispin)/real(nao,
dp))
797 IF (norm_rr(ispin) < linres_control%eps .OR. new_norm(ispin) < linres_control%eps)
THEN
799 linres_control%converged = .true.
801 beta(ispin) = new_norm(ispin)/norm_rr(ispin)
806 CALL dbcsr_add(matrix_cg(ispin)%matrix, matrix_z0(ispin)%matrix, beta(ispin), 1.0_dp)
809 tr_rz00(ispin) = norm_rr(ispin)
810 norm_rr(ispin) = new_norm(ispin)
814 CALL external_control(should_stop,
"LS_SOLVER", target_time=qs_env%target_time, &
815 start_time=qs_env%start_time)
820 CALL projector(qs_env, matrix_p, matrix_cg_z, eps_filter)
823 CALL commutator(matrix_cg_z, matrix_p, matrix_z, eps_filter, .true., alpha=0.5_dp)
827 CALL transform_m_orth(matrix_z(ispin)%matrix, matrix_s_sqrt_inv, eps_filter)
830 CALL dbcsr_copy(matrix_pz(ispin)%matrix, matrix_z(ispin)%matrix, keep_sparsity=.true.)
835 CALL ec_wz_matrix(qs_env, matrix_pz, matrix_wz, eps_filter)
853 DEALLOCATE (alpha, beta, new_norm, norm_ca, norm_rr)
856 CALL timestop(handle)
871 SUBROUTINE ec_wz_matrix(qs_env, matrix_z, matrix_wz, eps_filter)
878 REAL(kind=
dp),
INTENT(IN) :: eps_filter
880 CHARACTER(len=*),
PARAMETER :: routinen =
'ec_wz_matrix'
882 INTEGER :: handle, ispin, nspins
883 REAL(kind=
dp) :: scaling
884 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_p, matrix_s
889 CALL timeset(routinen, handle)
891 cpassert(
ASSOCIATED(qs_env))
892 cpassert(
ASSOCIATED(matrix_z))
893 cpassert(
ASSOCIATED(matrix_wz))
896 dft_control=dft_control, &
897 matrix_ks=matrix_ks, &
900 nspins = dft_control%nspins
905 CALL dbcsr_create(matrix_tmp, template=matrix_z(1)%matrix, &
906 matrix_type=dbcsr_type_no_symmetry)
907 CALL dbcsr_create(matrix_tmp2, template=matrix_z(1)%matrix, &
908 matrix_type=dbcsr_type_no_symmetry)
912 IF (nspins == 1) scaling = 0.5_dp
918 CALL dbcsr_multiply(
"N",
"N", scaling, matrix_ks(ispin)%matrix, matrix_p(ispin)%matrix, &
919 0.0_dp, matrix_tmp, filter_eps=eps_filter, retain_sparsity=.false.)
922 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, matrix_z(ispin)%matrix, matrix_tmp, &
923 0.0_dp, matrix_tmp2, filter_eps=eps_filter, retain_sparsity=.false.)
929 CALL dbcsr_add(matrix_tmp, matrix_tmp2, 1.0_dp, 1.0_dp)
934 CALL dbcsr_copy(matrix_wz(ispin)%matrix, matrix_tmp, keep_sparsity=.true.)
942 CALL timestop(handle)
944 END SUBROUTINE ec_wz_matrix
963 SUBROUTINE hessian_op1(matrix_ks, matrix_p, matrix_cg, matrix_b, matrix_Ax, eps_filter)
966 POINTER :: matrix_ks, matrix_p, matrix_cg
968 POINTER :: matrix_b, matrix_ax
969 REAL(kind=
dp),
INTENT(IN) :: eps_filter
971 CHARACTER(len=*),
PARAMETER :: routinen =
'hessian_op1'
975 CALL timeset(routinen, handle)
977 cpassert(
ASSOCIATED(matrix_ks))
978 cpassert(
ASSOCIATED(matrix_p))
979 cpassert(
ASSOCIATED(matrix_cg))
980 cpassert(
ASSOCIATED(matrix_b))
981 cpassert(
ASSOCIATED(matrix_ax))
985 CALL commutator(matrix_cg, matrix_p, matrix_b, eps_filter, .true.)
989 CALL commutator(matrix_ks, matrix_b, matrix_ax, eps_filter, .false.)
991 CALL timestop(handle)
993 END SUBROUTINE hessian_op1
1012 SUBROUTINE build_hessian_op(qs_env, p_env, matrix_ks, matrix_p, matrix_s_sqrt_inv, &
1013 matrix_cg, matrix_Ax, eps_filter)
1018 POINTER :: matrix_ks, matrix_p
1019 TYPE(
dbcsr_type),
INTENT(IN) :: matrix_s_sqrt_inv
1021 POINTER :: matrix_cg
1023 POINTER :: matrix_ax
1024 REAL(kind=
dp),
INTENT(IN) :: eps_filter
1026 CHARACTER(len=*),
PARAMETER :: routinen =
'build_hessian_op'
1028 INTEGER :: handle, ispin, nspins
1029 REAL(kind=
dp) :: chksum
1030 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_b, rho1_ao
1035 CALL timeset(routinen, handle)
1037 cpassert(
ASSOCIATED(qs_env))
1038 cpassert(
ASSOCIATED(matrix_ks))
1039 cpassert(
ASSOCIATED(matrix_p))
1040 cpassert(
ASSOCIATED(matrix_cg))
1041 cpassert(
ASSOCIATED(matrix_ax))
1044 dft_control=dft_control, &
1045 para_env=para_env, &
1047 nspins = dft_control%nspins
1051 DO ispin = 1, nspins
1052 ALLOCATE (matrix_b(ispin)%matrix)
1053 CALL dbcsr_create(matrix_b(ispin)%matrix, name=
"[X,P] RSP DNSTY", &
1054 template=matrix_p(1)%matrix, &
1055 matrix_type=dbcsr_type_no_symmetry)
1059 CALL hessian_op1(matrix_ks, matrix_p, matrix_cg, matrix_b, matrix_ax, eps_filter)
1062 DO ispin = 1, nspins
1067 DO ispin = 1, nspins
1072 IF (chksum > 1.0e-14_dp)
THEN
1082 DO ispin = 1, nspins
1084 CALL transform_m_orth(matrix_b(ispin)%matrix, matrix_s_sqrt_inv, eps_filter)
1088 CALL dbcsr_copy(rho1_ao(ispin)%matrix, matrix_b(ispin)%matrix, keep_sparsity=.true.)
1089 CALL dbcsr_copy(p_env%p1(ispin)%matrix, matrix_b(ispin)%matrix, keep_sparsity=.true.)
1095 DO ispin = 1, nspins
1096 CALL dbcsr_set(p_env%kpp1(ispin)%matrix, 0.0_dp)
1097 IF (
ASSOCIATED(p_env%kpp1_admm))
CALL dbcsr_set(p_env%kpp1_admm(ispin)%matrix, 0.0_dp)
1103 CALL hessian_op2(qs_env, p_env, matrix_ax, matrix_p, matrix_s_sqrt_inv, eps_filter)
1109 CALL timestop(handle)
1111 END SUBROUTINE build_hessian_op
1129 SUBROUTINE hessian_op2(qs_env, p_env, matrix_Ax, matrix_p, matrix_s_sqrt_inv, eps_filter)
1134 POINTER :: matrix_ax
1137 TYPE(
dbcsr_type),
INTENT(IN) :: matrix_s_sqrt_inv
1138 REAL(kind=
dp),
INTENT(IN) :: eps_filter
1140 CHARACTER(len=*),
PARAMETER :: routinen =
'hessian_op2'
1142 INTEGER :: handle, ispin, nspins
1143 REAL(kind=
dp) :: ekin_mol
1145 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_g, matrix_s, rho1_ao, rho_ao
1155 TYPE(
pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho1_r, rho_r, tau1_r, v_xc, v_xc_tau
1160 CALL timeset(routinen, handle)
1162 NULLIFY (admm_env, dft_control, input, matrix_s, para_env, rho, rho_r, rho1_g, rho1_r)
1165 admm_env=admm_env, &
1166 dft_control=dft_control, &
1168 matrix_s=matrix_s, &
1169 para_env=para_env, &
1171 nspins = dft_control%nspins
1173 cpassert(
ASSOCIATED(p_env%kpp1))
1174 cpassert(
ASSOCIATED(p_env%kpp1_env))
1175 kpp1_env => p_env%kpp1_env
1180 CALL qs_rho_get(p_env%rho1, rho_g=rho1_g, rho_r=rho1_r, tau_r=tau1_r)
1184 cpassert(
ASSOCIATED(pw_env))
1186 NULLIFY (auxbas_pw_pool, poisson_env, pw_pools)
1189 auxbas_pw_pool=auxbas_pw_pool, &
1190 pw_pools=pw_pools, &
1191 poisson_env=poisson_env)
1194 CALL auxbas_pw_pool%create_pw(pw=v_hartree_gspace)
1195 CALL auxbas_pw_pool%create_pw(pw=rho_tot_gspace)
1196 CALL auxbas_pw_pool%create_pw(pw=v_hartree_rspace)
1199 NULLIFY (v_xc, v_xc_tau, xc_section)
1201 IF (dft_control%do_admm)
THEN
1202 xc_section => admm_env%xc_section_primary
1215 xc_section=xc_section)
1217 DO ispin = 1, nspins
1218 CALL pw_scale(v_xc(ispin), v_xc(ispin)%pw_grid%dvol)
1219 IF (
ASSOCIATED(v_xc_tau))
THEN
1220 CALL pw_scale(v_xc_tau(ispin), v_xc_tau(ispin)%pw_grid%dvol)
1225 IF (dft_control%do_admm)
THEN
1227 IF (.NOT.
ASSOCIATED(kpp1_env%deriv_set_admm))
THEN
1228 xc_section_aux => admm_env%xc_section_aux
1229 CALL get_admm_env(qs_env%admm_env, rho_aux_fit=rho_aux)
1231 ALLOCATE (kpp1_env%deriv_set_admm, kpp1_env%rho_set_admm)
1233 rho_r, auxbas_pw_pool, &
1234 xc_section=xc_section_aux)
1241 DO ispin = 1, nspins
1242 CALL pw_axpy(rho1_g(ispin), rho_tot_gspace)
1247 vhartree=v_hartree_gspace)
1248 CALL pw_transfer(v_hartree_gspace, v_hartree_rspace)
1249 CALL pw_scale(v_hartree_rspace, v_hartree_rspace%pw_grid%dvol)
1252 DO ispin = 1, nspins
1253 CALL pw_axpy(v_hartree_rspace, v_xc(ispin))
1255 IF (nspins == 1)
THEN
1257 IF (
ASSOCIATED(v_xc_tau))
CALL pw_scale(v_xc_tau(1), 2.0_dp)
1260 DO ispin = 1, nspins
1262 CALL integrate_v_rspace(v_rspace=v_xc(ispin), &
1263 pmat=rho_ao(ispin), &
1264 hmat=p_env%kpp1(ispin), &
1266 calculate_forces=.false., &
1268 IF (
ASSOCIATED(v_xc_tau))
THEN
1269 CALL integrate_v_rspace(v_rspace=v_xc_tau(ispin), &
1270 pmat=rho_ao(ispin), &
1271 hmat=p_env%kpp1(ispin), &
1273 compute_tau=.true., &
1274 calculate_forces=.false., &
1287 IF (dft_control%qs_control%do_kg)
THEN
1291 cpassert(dft_control%nimages == 1)
1295 ks_matrix=p_env%kpp1, &
1296 ekin_mol=ekin_mol, &
1297 calc_force=.false., &
1307 DO ispin = 1, nspins
1308 ALLOCATE (matrix_g(ispin)%matrix)
1309 CALL dbcsr_copy(matrix_g(ispin)%matrix, p_env%kpp1(ispin)%matrix, &
1310 name=
"MATRIX Kernel")
1315 DO ispin = 1, nspins
1316 CALL transform_m_orth(matrix_g(ispin)%matrix, matrix_s_sqrt_inv, eps_filter)
1322 CALL commutator(matrix_g, matrix_p, matrix_ax, eps_filter, .false., 1.0_dp, 1.0_dp)
1325 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace)
1326 CALL auxbas_pw_pool%give_back_pw(v_hartree_rspace)
1327 CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace)
1328 DO ispin = 1, nspins
1329 CALL auxbas_pw_pool%give_back_pw(v_xc(ispin))
1332 IF (
ASSOCIATED(v_xc_tau))
THEN
1333 DO ispin = 1, nspins
1334 CALL auxbas_pw_pool%give_back_pw(v_xc_tau(ispin))
1336 DEALLOCATE (v_xc_tau)
1341 CALL timestop(handle)
1343 END SUBROUTINE hessian_op2
1361 SUBROUTINE commutator(a, b, res, eps_filter, anticomm, alpha, beta)
1364 POINTER :: a, b, res
1365 REAL(kind=
dp) :: eps_filter
1367 REAL(kind=
dp),
OPTIONAL :: alpha, beta
1369 CHARACTER(LEN=*),
PARAMETER :: routinen =
'commutator'
1371 INTEGER :: handle, ispin
1372 REAL(kind=
dp) :: facc, myalpha, mybeta
1375 CALL timeset(routinen, handle)
1377 cpassert(
ASSOCIATED(a))
1378 cpassert(
ASSOCIATED(b))
1379 cpassert(
ASSOCIATED(res))
1381 CALL dbcsr_create(work, template=a(1)%matrix, matrix_type=dbcsr_type_no_symmetry)
1382 CALL dbcsr_create(work2, template=a(1)%matrix, matrix_type=dbcsr_type_no_symmetry)
1386 IF (
PRESENT(alpha)) myalpha = alpha
1389 IF (
PRESENT(beta)) mybeta = beta
1392 IF (anticomm) facc = 1.0_dp
1394 DO ispin = 1,
SIZE(a)
1396 CALL dbcsr_multiply(
"N",
"N", myalpha, a(ispin)%matrix, b(ispin)%matrix, &
1397 0.0_dp, work, filter_eps=eps_filter)
1402 CALL dbcsr_add(work, work2, 1.0_dp, facc)
1404 CALL dbcsr_add(res(ispin)%matrix, work, mybeta, 1.0_dp)
1411 CALL timestop(handle)
1413 END SUBROUTINE commutator
1428 SUBROUTINE projector(qs_env, matrix_p, matrix_io, eps_filter)
1434 POINTER :: matrix_io
1435 REAL(kind=
dp),
INTENT(IN) :: eps_filter
1437 CHARACTER(len=*),
PARAMETER :: routinen =
'projector'
1439 INTEGER :: handle, ispin, nspins
1444 CALL timeset(routinen, handle)
1447 dft_control=dft_control, &
1449 nspins = dft_control%nspins
1451 CALL dbcsr_create(matrix_q, template=matrix_p(1)%matrix, &
1452 matrix_type=dbcsr_type_no_symmetry)
1453 CALL dbcsr_create(matrix_tmp, template=matrix_p(1)%matrix, &
1454 matrix_type=dbcsr_type_no_symmetry)
1457 CALL dbcsr_copy(matrix_q, matrix_p(1)%matrix)
1465 DO ispin = 1, nspins
1468 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, matrix_p(ispin)%matrix, matrix_io(ispin)%matrix, &
1469 0.0_dp, matrix_tmp, filter_eps=eps_filter)
1472 0.0_dp, matrix_io(ispin)%matrix, filter_eps=eps_filter)
1476 CALL dbcsr_add(matrix_io(ispin)%matrix, matrix_tmp, 1.0_dp, -1.0_dp)
1483 CALL timestop(handle)
1485 END SUBROUTINE projector
1499 SUBROUTINE transform_m_orth(matrix, matrix_trafo, eps_filter)
1501 REAL(kind=
dp) :: eps_filter
1503 CHARACTER(LEN=*),
PARAMETER :: routinen =
'transform_m_orth'
1508 CALL timeset(routinen, handle)
1510 CALL dbcsr_create(matrix_work, template=matrix, matrix_type=dbcsr_type_no_symmetry)
1511 CALL dbcsr_create(matrix_tmp, template=matrix, matrix_type=dbcsr_type_no_symmetry)
1514 0.0_dp, matrix_work, filter_eps=eps_filter)
1515 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, matrix_trafo, matrix_work, &
1516 0.0_dp, matrix_tmp, filter_eps=eps_filter)
1519 CALL dbcsr_add(matrix_tmp, matrix_work, 0.5_dp, 0.5_dp)
1527 CALL timestop(handle)
1529 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...
Routines used for Harris functional Kohn-Sham calculation.
subroutine, public create_kernel(qs_env, vxc, vxc_tau, rho, rho1_r, rho1_g, tau1_r, xc_section, compute_virial, virial_xc)
Creation of second derivative xc-potential.
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, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, 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.
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...
Exchange and Correlation functional calculations.
subroutine, public xc_prep_2nd_deriv(deriv_set, rho_set, rho_r, pw_pool, xc_section, tau_r)
Prepare objects for the calculation of the 2nd derivatives of the density functional....
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.