73#include "./base/base_uses.f90"
81 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'ec_orth_solver'
109 SUBROUTINE preconditioner(qs_env, matrix_ks, matrix_p, matrix_rhs, &
110 matrix_cg_z, eps_filter, iounit)
112 TYPE(qs_environment_type),
POINTER :: qs_env
113 TYPE(dbcsr_p_type),
DIMENSION(:),
INTENT(IN), &
114 POINTER :: matrix_ks, matrix_p, matrix_rhs
115 TYPE(dbcsr_p_type),
DIMENSION(:),
INTENT(INOUT), &
116 POINTER :: matrix_cg_z
117 REAL(KIND=
dp),
INTENT(IN) :: eps_filter
118 INTEGER,
INTENT(IN) :: iounit
120 CHARACTER(len=*),
PARAMETER :: routineN =
'preconditioner'
122 INTEGER :: handle, i, ispin, max_iter, nao, nspins
124 REAL(KIND=
dp) :: norm_res, t1, t2
125 REAL(KIND=
dp),
DIMENSION(:),
POINTER :: alpha, beta, new_norm, norm_ca, norm_rr
126 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_Ax, matrix_b, matrix_cg, &
128 TYPE(dft_control_type),
POINTER :: dft_control
129 TYPE(linres_control_type),
POINTER :: linres_control
131 CALL timeset(routinen, handle)
133 cpassert(
ASSOCIATED(qs_env))
134 cpassert(
ASSOCIATED(matrix_ks))
135 cpassert(
ASSOCIATED(matrix_p))
136 cpassert(
ASSOCIATED(matrix_rhs))
137 cpassert(
ASSOCIATED(matrix_cg_z))
139 NULLIFY (dft_control, linres_control)
144 dft_control=dft_control, &
145 linres_control=linres_control)
146 nspins = dft_control%nspins
149 ALLOCATE (alpha(nspins), beta(nspins), new_norm(nspins), norm_ca(nspins), norm_rr(nspins))
155 NULLIFY (matrix_ax, matrix_b, matrix_cg, matrix_res)
162 ALLOCATE (matrix_ax(ispin)%matrix)
163 ALLOCATE (matrix_b(ispin)%matrix)
164 ALLOCATE (matrix_cg(ispin)%matrix)
165 ALLOCATE (matrix_res(ispin)%matrix)
166 CALL dbcsr_create(matrix_ax(ispin)%matrix, name=
"linop MATRIX", &
167 template=matrix_ks(1)%matrix, &
168 matrix_type=dbcsr_type_no_symmetry)
169 CALL dbcsr_create(matrix_b(ispin)%matrix, name=
"MATRIX B", &
170 template=matrix_ks(1)%matrix, &
171 matrix_type=dbcsr_type_no_symmetry)
172 CALL dbcsr_create(matrix_cg(ispin)%matrix, name=
"TRIAL MATRIX", &
173 template=matrix_ks(1)%matrix, &
174 matrix_type=dbcsr_type_no_symmetry)
175 CALL dbcsr_create(matrix_res(ispin)%matrix, name=
"RESIDUE", &
176 template=matrix_ks(1)%matrix, &
177 matrix_type=dbcsr_type_no_symmetry)
186 CALL dbcsr_copy(matrix_cg_z(ispin)%matrix, matrix_rhs(ispin)%matrix)
189 CALL dbcsr_copy(matrix_res(ispin)%matrix, matrix_rhs(ispin)%matrix)
198 CALL hessian_op1(matrix_ks, matrix_p, matrix_cg_z, matrix_b, matrix_ax, eps_filter)
202 CALL dbcsr_add(matrix_res(ispin)%matrix, matrix_ax(ispin)%matrix, 1.0_dp, -1.0_dp)
206 CALL projector(qs_env, matrix_p, matrix_res, eps_filter)
210 CALL dbcsr_copy(matrix_cg(ispin)%matrix, matrix_res(ispin)%matrix)
215 WRITE (iounit,
"(/,T10,A)")
"Preconditioning of search direction"
216 WRITE (iounit,
"(/,T10,A,T25,A,T42,A,T62,A,/,T10,A)") &
217 "Iteration",
"Stepsize",
"Convergence",
"Time", &
227 iteration:
DO i = 1, max_iter
230 CALL hessian_op1(matrix_ks, matrix_p, matrix_cg, matrix_b, matrix_ax, eps_filter)
233 CALL projector(qs_env, matrix_p, matrix_ax, eps_filter)
238 CALL dbcsr_dot(matrix_res(ispin)%matrix, matrix_res(ispin)%matrix, norm_rr(ispin))
240 cpabort(
"Preconditioner: Tr[r_j*r_j] is an abnormal value (NaN/Inf)")
242 IF (norm_rr(ispin) .LT. 0.0_dp) cpabort(
"norm_rr < 0")
243 norm_res = max(norm_res, abs(norm_rr(ispin)/real(nao,
dp)))
246 CALL dbcsr_dot(matrix_cg(ispin)%matrix, matrix_ax(ispin)%matrix, norm_ca(ispin))
249 IF (norm_ca(ispin) .LT. linres_control%eps)
THEN
250 alpha(ispin) = 1.0_dp
252 alpha(ispin) = norm_rr(ispin)/norm_ca(ispin)
257 CALL dbcsr_add(matrix_cg_z(ispin)%matrix, matrix_cg(ispin)%matrix, 1.0_dp, alpha(ispin))
260 CALL dbcsr_add(matrix_res(ispin)%matrix, matrix_ax(ispin)%matrix, 1.0_dp, -alpha(ispin))
268 CALL dbcsr_dot(matrix_res(ispin)%matrix, matrix_res(ispin)%matrix, new_norm(ispin))
269 IF (new_norm(ispin) .LT. 0.0_dp) cpabort(
"tr(r_j+1*z_j+1) < 0")
271 cpabort(
"Preconditioner: Tr[r_j+1*z_j+1] is an abnormal value (NaN/Inf)")
272 norm_res = max(norm_res, new_norm(ispin)/real(nao,
dp))
274 IF (norm_rr(ispin) .LT. linres_control%eps*0.001_dp &
275 .OR. new_norm(ispin) .LT. linres_control%eps*0.001_dp)
THEN
279 beta(ispin) = new_norm(ispin)/norm_rr(ispin)
284 CALL dbcsr_add(matrix_cg(ispin)%matrix, matrix_res(ispin)%matrix, beta(ispin), 1.0_dp)
287 norm_rr(ispin) = new_norm(ispin)
291 IF (norm_res .LT. linres_control%eps)
THEN
296 IF (i .EQ. 1 .OR. mod(i, 1) .EQ. 0 .OR. converged)
THEN
298 WRITE (iounit,
"(T10,I5,T25,1E8.2,T33,F25.14,T58,F8.2)") &
299 i, maxval(alpha), norm_res, t2 - t1
308 WRITE (iounit,
"(/,T10,A,I4,A,/)")
"The precon solver converged in ", i,
" iterations."
315 IF (i == max_iter)
THEN
317 WRITE (iounit,
"(/,T10,A/)") &
318 "The precon solver didnt converge! Maximum number of iterations reached."
327 CALL projector(qs_env, matrix_p, matrix_cg_z, eps_filter)
335 DEALLOCATE (alpha, beta, new_norm, norm_ca, norm_rr)
337 CALL timestop(handle)
358 SUBROUTINE ec_response_ao(qs_env, p_env, matrix_hz, matrix_pz, matrix_wz, iounit, should_stop)
365 POINTER :: matrix_pz, matrix_wz
366 INTEGER,
INTENT(IN) :: iounit
367 LOGICAL,
INTENT(OUT) :: should_stop
369 CHARACTER(len=*),
PARAMETER :: routinen =
'ec_response_ao'
371 INTEGER :: handle, i, ispin, max_iter_lanczos, nao, &
372 nspins, s_sqrt_method, s_sqrt_order
374 REAL(kind=
dp) :: eps_filter, eps_lanczos, focc, &
375 min_shift, norm_res, old_conv, shift, &
377 REAL(kind=
dp),
DIMENSION(:),
POINTER :: alpha, beta, new_norm, norm_ca, norm_rr, &
379 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: ksmat, matrix_ax, matrix_cg, matrix_cg_z, &
380 matrix_ks, matrix_nsc, matrix_p, matrix_res, matrix_s, matrix_z, matrix_z0, rho_ao
381 TYPE(
dbcsr_type) :: matrix_s_sqrt, matrix_s_sqrt_inv, &
388 CALL timeset(routinen, handle)
390 cpassert(
ASSOCIATED(qs_env))
391 cpassert(
ASSOCIATED(matrix_hz))
392 cpassert(
ASSOCIATED(matrix_pz))
393 cpassert(
ASSOCIATED(matrix_wz))
395 NULLIFY (dft_control, ksmat, matrix_s, linres_control, rho)
400 dft_control=dft_control, &
401 linres_control=linres_control, &
405 nspins = dft_control%nspins
415 eps_filter = linres_control%eps_filter
419 ALLOCATE (alpha(nspins), beta(nspins), new_norm(nspins), norm_ca(nspins), norm_rr(nspins))
420 ALLOCATE (tr_rz00(nspins))
424 NULLIFY (matrix_p, matrix_ks, matrix_nsc)
429 ALLOCATE (matrix_p(ispin)%matrix)
430 ALLOCATE (matrix_ks(ispin)%matrix)
431 ALLOCATE (matrix_nsc(ispin)%matrix)
432 CALL dbcsr_create(matrix_p(ispin)%matrix, name=
"P_IN ORTHO", &
433 template=ksmat(1)%matrix, &
434 matrix_type=dbcsr_type_no_symmetry)
435 CALL dbcsr_create(matrix_ks(ispin)%matrix, name=
"KS_IN ORTHO", &
436 template=ksmat(1)%matrix, &
437 matrix_type=dbcsr_type_no_symmetry)
438 CALL dbcsr_create(matrix_nsc(ispin)%matrix, name=
"NSC IN ORTHO", &
439 template=ksmat(1)%matrix, &
440 matrix_type=dbcsr_type_no_symmetry)
448 IF (nspins == 1)
CALL dbcsr_scale(matrix_p(1)%matrix, 0.5_dp)
451 CALL dbcsr_create(matrix_s_sqrt, template=matrix_s(1)%matrix, &
452 matrix_type=dbcsr_type_no_symmetry)
453 CALL dbcsr_create(matrix_s_sqrt_inv, template=matrix_s(1)%matrix, &
454 matrix_type=dbcsr_type_no_symmetry)
456 SELECT CASE (s_sqrt_method)
459 matrix_s(1)%matrix, eps_filter, &
460 s_sqrt_order, eps_lanczos, max_iter_lanczos, symmetrize=.true.)
463 matrix_s(1)%matrix, eps_filter, &
464 s_sqrt_order, eps_lanczos, max_iter_lanczos)
466 cpabort(
"Unknown sqrt method.")
471 CALL transform_m_orth(matrix_p(ispin)%matrix, matrix_s_sqrt, eps_filter)
472 CALL transform_m_orth(matrix_ks(ispin)%matrix, matrix_s_sqrt_inv, eps_filter)
473 CALL transform_m_orth(matrix_nsc(ispin)%matrix, matrix_s_sqrt_inv, eps_filter)
482 CALL dbcsr_create(matrix_tmp, template=matrix_s(1)%matrix, matrix_type=dbcsr_type_no_symmetry)
484 NULLIFY (matrix_ax, matrix_cg, matrix_cg_z, matrix_res, matrix_z, matrix_z0)
493 ALLOCATE (matrix_ax(ispin)%matrix)
494 ALLOCATE (matrix_cg(ispin)%matrix)
495 ALLOCATE (matrix_cg_z(ispin)%matrix)
496 ALLOCATE (matrix_res(ispin)%matrix)
497 ALLOCATE (matrix_z(ispin)%matrix)
498 ALLOCATE (matrix_z0(ispin)%matrix)
499 CALL dbcsr_create(matrix_ax(ispin)%matrix, name=
"linop MATRIX", &
500 template=matrix_s(1)%matrix, &
501 matrix_type=dbcsr_type_no_symmetry)
502 CALL dbcsr_create(matrix_cg(ispin)%matrix, name=
"TRIAL MATRIX", &
503 template=matrix_s(1)%matrix, &
504 matrix_type=dbcsr_type_no_symmetry)
505 CALL dbcsr_create(matrix_cg_z(ispin)%matrix, name=
"MATRIX CG-Z", &
506 template=matrix_s(1)%matrix, &
507 matrix_type=dbcsr_type_no_symmetry)
508 CALL dbcsr_create(matrix_res(ispin)%matrix, name=
"RESIDUE", &
509 template=matrix_s(1)%matrix, &
510 matrix_type=dbcsr_type_no_symmetry)
511 CALL dbcsr_create(matrix_z(ispin)%matrix, name=
"Z-Matrix", &
512 template=matrix_s(1)%matrix, &
513 matrix_type=dbcsr_type_no_symmetry)
514 CALL dbcsr_create(matrix_z0(ispin)%matrix, name=
"p after precondi-Matrix", &
515 template=matrix_s(1)%matrix, &
516 matrix_type=dbcsr_type_no_symmetry)
525 IF (nspins == 1) focc = -4.0_dp
528 CALL commutator(matrix_nsc, matrix_p, matrix_res, eps_filter, .false., alpha=focc)
532 CALL dbcsr_copy(matrix_cg_z(ispin)%matrix, matrix_res(ispin)%matrix)
536 CALL projector(qs_env, matrix_p, matrix_cg_z, eps_filter)
539 CALL build_hessian_op(qs_env=qs_env, &
541 matrix_ks=matrix_ks, &
543 matrix_s_sqrt_inv=matrix_s_sqrt_inv, &
544 matrix_cg=matrix_cg_z, &
545 matrix_ax=matrix_ax, &
546 eps_filter=eps_filter)
550 CALL dbcsr_add(matrix_res(ispin)%matrix, matrix_ax(ispin)%matrix, 1.0_dp, -1.0_dp)
554 CALL projector(qs_env, matrix_p, matrix_res, eps_filter)
557 linres_control%flag =
""
558 IF (linres_control%preconditioner_type ==
precond_mlp)
THEN
562 matrix_ks=matrix_ks, &
564 matrix_rhs=matrix_res, &
565 matrix_cg_z=matrix_z0, &
566 eps_filter=eps_filter, &
568 linres_control%flag =
"PCG-AO"
572 CALL dbcsr_copy(matrix_z0(ispin)%matrix, matrix_res(ispin)%matrix)
573 linres_control%flag =
"CG-AO"
581 CALL dbcsr_copy(matrix_cg(ispin)%matrix, matrix_z0(ispin)%matrix)
584 CALL dbcsr_dot(matrix_res(ispin)%matrix, matrix_cg(ispin)%matrix, norm_rr(ispin))
586 IF (norm_rr(ispin) .LT. 0.0_dp) cpabort(
"norm_rr < 0")
587 norm_res = max(norm_res, abs(norm_rr(ispin)/real(nao,
dp)))
592 old_conv = norm_rr(1)
593 shift = min(10.0_dp, max(min_shift, 0.05_dp*old_conv))
598 WRITE (iounit,
"(/,T3,A,T16,A,T25,A,T38,A,T52,A,/,T3,A)") &
599 "Iteration",
"Method",
"Stepsize",
"Convergence",
"Time", &
605 should_stop = .false.
606 linres_control%converged = .false.
609 iteration:
DO i = 1, linres_control%max_iter
613 IF (norm_res .LT. linres_control%eps)
THEN
614 linres_control%converged = .true.
618 IF (i .EQ. 1 .OR. mod(i, 1) .EQ. 0 .OR. linres_control%converged &
619 .OR. restart .OR. should_stop)
THEN
621 WRITE (iounit,
"(T5,I5,T18,A3,T28,L1,T38,1E8.2,T48,F16.10,T68,F8.2)") &
622 i, linres_control%flag, restart, maxval(alpha), norm_res, t2 - t1
626 IF (linres_control%converged)
THEN
628 WRITE (iounit,
"(/,T2,A,I4,A,/)")
"The linear solver converged in ", i,
" iterations."
632 ELSE IF (should_stop)
THEN
634 WRITE (iounit,
"(/,T2,A,I4,A,/)")
"The linear solver did NOT converge! External stop"
641 IF (i == linres_control%max_iter)
THEN
643 WRITE (iounit,
"(/,T2,A/)") &
644 "The linear solver didnt converge! Maximum number of iterations reached."
647 linres_control%converged = .false.
651 CALL build_hessian_op(qs_env=qs_env, &
653 matrix_ks=matrix_ks, &
655 matrix_s_sqrt_inv=matrix_s_sqrt_inv, &
656 matrix_cg=matrix_cg, &
657 matrix_ax=matrix_ax, &
658 eps_filter=eps_filter)
661 CALL projector(qs_env, matrix_p, matrix_ax, eps_filter)
667 CALL dbcsr_dot(matrix_cg(ispin)%matrix, matrix_ax(ispin)%matrix, norm_ca(ispin))
669 IF (norm_ca(ispin) .LT. 0.0_dp)
THEN
674 CALL dbcsr_add(matrix_cg(ispin)%matrix, matrix_z0(ispin)%matrix, &
675 beta(ispin), -1.0_dp)
676 CALL dbcsr_dot(matrix_res(ispin)%matrix, matrix_res(ispin)%matrix, new_norm(ispin))
677 beta(ispin) = new_norm(ispin)/tr_rz00(ispin)
678 CALL dbcsr_add(matrix_cg(ispin)%matrix, matrix_res(ispin)%matrix, &
680 norm_rr(ispin) = new_norm(ispin)
682 CALL dbcsr_copy(matrix_res(ispin)%matrix, matrix_cg(ispin)%matrix)
683 CALL dbcsr_dot(matrix_res(ispin)%matrix, matrix_res(ispin)%matrix, norm_rr(ispin))
686 CALL build_hessian_op(qs_env=qs_env, &
688 matrix_ks=matrix_ks, &
690 matrix_s_sqrt_inv=matrix_s_sqrt_inv, &
691 matrix_cg=matrix_cg, &
692 matrix_ax=matrix_ax, &
693 eps_filter=eps_filter)
696 CALL projector(qs_env, matrix_p, matrix_ax, eps_filter)
698 CALL dbcsr_dot(matrix_cg(ispin)%matrix, matrix_ax(ispin)%matrix, norm_ca(ispin))
700 cpabort(
"tr(Ap_j*p_j) < 0")
702 cpabort(
"Preconditioner: Tr[Ap_j*p_j] is an abnormal value (NaN/Inf)")
710 IF (norm_ca(ispin) .LT. linres_control%eps)
THEN
711 alpha(ispin) = 1.0_dp
713 alpha(ispin) = norm_rr(ispin)/norm_ca(ispin)
718 CALL dbcsr_add(matrix_cg_z(ispin)%matrix, matrix_cg(ispin)%matrix, 1.0_dp, alpha(ispin))
723 IF (mod(i, linres_control%restart_every) .EQ. 0)
THEN
726 CALL build_hessian_op(qs_env=qs_env, &
728 matrix_ks=matrix_ks, &
730 matrix_s_sqrt_inv=matrix_s_sqrt_inv, &
731 matrix_cg=matrix_cg_z, &
732 matrix_ax=matrix_ax, &
733 eps_filter=eps_filter)
735 CALL commutator(matrix_nsc, matrix_p, matrix_res, eps_filter, .false., alpha=focc)
738 CALL dbcsr_add(matrix_res(ispin)%matrix, matrix_ax(ispin)%matrix, 1.0_dp, -1.0_dp)
741 CALL projector(qs_env, matrix_p, matrix_res, eps_filter)
746 CALL projector(qs_env, matrix_p, matrix_ax, eps_filter)
750 CALL dbcsr_add(matrix_res(ispin)%matrix, matrix_ax(ispin)%matrix, 1.0_dp, -alpha(ispin))
756 linres_control%flag =
""
757 IF (linres_control%preconditioner_type ==
precond_mlp)
THEN
761 matrix_ks=matrix_ks, &
763 matrix_rhs=matrix_res, &
764 matrix_cg_z=matrix_z0, &
765 eps_filter=eps_filter, &
767 linres_control%flag =
"PCG-AO"
770 CALL dbcsr_copy(matrix_z0(ispin)%matrix, matrix_res(ispin)%matrix)
772 linres_control%flag =
"CG-AO"
779 CALL dbcsr_dot(matrix_res(ispin)%matrix, matrix_z0(ispin)%matrix, new_norm(ispin))
780 IF (new_norm(ispin) .LT. 0.0_dp) cpabort(
"tr(r_j+1*z_j+1) < 0")
782 cpabort(
"Preconditioner: Tr[r_j+1*z_j+1] is an abnormal value (NaN/Inf)")
783 norm_res = max(norm_res, new_norm(ispin)/real(nao,
dp))
785 IF (norm_rr(ispin) .LT. linres_control%eps .OR. new_norm(ispin) .LT. linres_control%eps)
THEN
787 linres_control%converged = .true.
789 beta(ispin) = new_norm(ispin)/norm_rr(ispin)
794 CALL dbcsr_add(matrix_cg(ispin)%matrix, matrix_z0(ispin)%matrix, beta(ispin), 1.0_dp)
797 tr_rz00(ispin) = norm_rr(ispin)
798 norm_rr(ispin) = new_norm(ispin)
802 CALL external_control(should_stop,
"LS_SOLVER", target_time=qs_env%target_time, &
803 start_time=qs_env%start_time)
808 CALL projector(qs_env, matrix_p, matrix_cg_z, eps_filter)
811 CALL commutator(matrix_cg_z, matrix_p, matrix_z, eps_filter, .true., alpha=0.5_dp)
815 CALL transform_m_orth(matrix_z(ispin)%matrix, matrix_s_sqrt_inv, eps_filter)
818 CALL dbcsr_copy(matrix_pz(ispin)%matrix, matrix_z(ispin)%matrix, keep_sparsity=.true.)
823 CALL ec_wz_matrix(qs_env, matrix_pz, matrix_wz, eps_filter)
841 DEALLOCATE (alpha, beta, new_norm, norm_ca, norm_rr)
844 CALL timestop(handle)
859 SUBROUTINE ec_wz_matrix(qs_env, matrix_z, matrix_wz, eps_filter)
866 REAL(kind=
dp),
INTENT(IN) :: eps_filter
868 CHARACTER(len=*),
PARAMETER :: routinen =
'ec_wz_matrix'
870 INTEGER :: handle, ispin, nspins
871 REAL(kind=
dp) :: scaling
872 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_p, matrix_s
877 CALL timeset(routinen, handle)
879 cpassert(
ASSOCIATED(qs_env))
880 cpassert(
ASSOCIATED(matrix_z))
881 cpassert(
ASSOCIATED(matrix_wz))
884 dft_control=dft_control, &
885 matrix_ks=matrix_ks, &
888 nspins = dft_control%nspins
893 CALL dbcsr_create(matrix_tmp, template=matrix_z(1)%matrix, &
894 matrix_type=dbcsr_type_no_symmetry)
895 CALL dbcsr_create(matrix_tmp2, template=matrix_z(1)%matrix, &
896 matrix_type=dbcsr_type_no_symmetry)
900 IF (nspins == 1) scaling = 0.5_dp
906 CALL dbcsr_multiply(
"N",
"N", scaling, matrix_ks(ispin)%matrix, matrix_p(ispin)%matrix, &
907 0.0_dp, matrix_tmp, filter_eps=eps_filter, retain_sparsity=.false.)
910 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, matrix_z(ispin)%matrix, matrix_tmp, &
911 0.0_dp, matrix_tmp2, filter_eps=eps_filter, retain_sparsity=.false.)
917 CALL dbcsr_add(matrix_tmp, matrix_tmp2, 1.0_dp, 1.0_dp)
922 CALL dbcsr_copy(matrix_wz(ispin)%matrix, matrix_tmp, keep_sparsity=.true.)
930 CALL timestop(handle)
932 END SUBROUTINE ec_wz_matrix
951 SUBROUTINE hessian_op1(matrix_ks, matrix_p, matrix_cg, matrix_b, matrix_Ax, eps_filter)
954 POINTER :: matrix_ks, matrix_p, matrix_cg
956 POINTER :: matrix_b, matrix_ax
957 REAL(kind=
dp),
INTENT(IN) :: eps_filter
959 CHARACTER(len=*),
PARAMETER :: routinen =
'hessian_op1'
963 CALL timeset(routinen, handle)
965 cpassert(
ASSOCIATED(matrix_ks))
966 cpassert(
ASSOCIATED(matrix_p))
967 cpassert(
ASSOCIATED(matrix_cg))
968 cpassert(
ASSOCIATED(matrix_b))
969 cpassert(
ASSOCIATED(matrix_ax))
973 CALL commutator(matrix_cg, matrix_p, matrix_b, eps_filter, .true.)
977 CALL commutator(matrix_ks, matrix_b, matrix_ax, eps_filter, .false.)
979 CALL timestop(handle)
981 END SUBROUTINE hessian_op1
1000 SUBROUTINE build_hessian_op(qs_env, p_env, matrix_ks, matrix_p, matrix_s_sqrt_inv, &
1001 matrix_cg, matrix_Ax, eps_filter)
1006 POINTER :: matrix_ks, matrix_p
1007 TYPE(
dbcsr_type),
INTENT(IN) :: matrix_s_sqrt_inv
1009 POINTER :: matrix_cg
1011 POINTER :: matrix_ax
1012 REAL(kind=
dp),
INTENT(IN) :: eps_filter
1014 CHARACTER(len=*),
PARAMETER :: routinen =
'build_hessian_op'
1016 INTEGER :: handle, ispin, nspins
1017 REAL(kind=
dp) :: chksum
1018 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_b, rho1_ao
1023 CALL timeset(routinen, handle)
1025 cpassert(
ASSOCIATED(qs_env))
1026 cpassert(
ASSOCIATED(matrix_ks))
1027 cpassert(
ASSOCIATED(matrix_p))
1028 cpassert(
ASSOCIATED(matrix_cg))
1029 cpassert(
ASSOCIATED(matrix_ax))
1032 dft_control=dft_control, &
1033 para_env=para_env, &
1035 nspins = dft_control%nspins
1039 DO ispin = 1, nspins
1040 ALLOCATE (matrix_b(ispin)%matrix)
1041 CALL dbcsr_create(matrix_b(ispin)%matrix, name=
"[X,P] RSP DNSTY", &
1042 template=matrix_p(1)%matrix, &
1043 matrix_type=dbcsr_type_no_symmetry)
1047 CALL hessian_op1(matrix_ks, matrix_p, matrix_cg, matrix_b, matrix_ax, eps_filter)
1050 DO ispin = 1, nspins
1055 DO ispin = 1, nspins
1060 IF (chksum .GT. 1.0e-14_dp)
THEN
1070 DO ispin = 1, nspins
1072 CALL transform_m_orth(matrix_b(ispin)%matrix, matrix_s_sqrt_inv, eps_filter)
1076 CALL dbcsr_copy(rho1_ao(ispin)%matrix, matrix_b(ispin)%matrix, keep_sparsity=.true.)
1077 CALL dbcsr_copy(p_env%p1(ispin)%matrix, matrix_b(ispin)%matrix, keep_sparsity=.true.)
1083 DO ispin = 1, nspins
1084 CALL dbcsr_set(p_env%kpp1(ispin)%matrix, 0.0_dp)
1085 IF (
ASSOCIATED(p_env%kpp1_admm))
CALL dbcsr_set(p_env%kpp1_admm(ispin)%matrix, 0.0_dp)
1091 CALL hessian_op2(qs_env, p_env, matrix_ax, matrix_p, matrix_s_sqrt_inv, eps_filter)
1097 CALL timestop(handle)
1099 END SUBROUTINE build_hessian_op
1117 SUBROUTINE hessian_op2(qs_env, p_env, matrix_Ax, matrix_p, matrix_s_sqrt_inv, eps_filter)
1122 POINTER :: matrix_ax
1125 TYPE(
dbcsr_type),
INTENT(IN) :: matrix_s_sqrt_inv
1126 REAL(kind=
dp),
INTENT(IN) :: eps_filter
1128 CHARACTER(len=*),
PARAMETER :: routinen =
'hessian_op2'
1130 INTEGER :: handle, ispin, nspins
1131 REAL(kind=
dp) :: ekin_mol
1133 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_g, matrix_s, rho1_ao, rho_ao
1143 TYPE(
pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho1_r, rho_r, tau1_r, v_xc, v_xc_tau
1148 CALL timeset(routinen, handle)
1150 NULLIFY (admm_env, dft_control, input, matrix_s, para_env, rho, rho_r, rho1_g, rho1_r)
1153 admm_env=admm_env, &
1154 dft_control=dft_control, &
1156 matrix_s=matrix_s, &
1157 para_env=para_env, &
1159 nspins = dft_control%nspins
1161 cpassert(
ASSOCIATED(p_env%kpp1))
1162 cpassert(
ASSOCIATED(p_env%kpp1_env))
1163 kpp1_env => p_env%kpp1_env
1168 CALL qs_rho_get(p_env%rho1, rho_g=rho1_g, rho_r=rho1_r, tau_r=tau1_r)
1172 cpassert(
ASSOCIATED(pw_env))
1174 NULLIFY (auxbas_pw_pool, poisson_env, pw_pools)
1177 auxbas_pw_pool=auxbas_pw_pool, &
1178 pw_pools=pw_pools, &
1179 poisson_env=poisson_env)
1182 CALL auxbas_pw_pool%create_pw(pw=v_hartree_gspace)
1183 CALL auxbas_pw_pool%create_pw(pw=rho_tot_gspace)
1184 CALL auxbas_pw_pool%create_pw(pw=v_hartree_rspace)
1187 NULLIFY (v_xc, v_xc_tau, xc_section)
1189 IF (dft_control%do_admm)
THEN
1190 xc_section => admm_env%xc_section_primary
1203 xc_section=xc_section)
1205 DO ispin = 1, nspins
1206 CALL pw_scale(v_xc(ispin), v_xc(ispin)%pw_grid%dvol)
1207 IF (
ASSOCIATED(v_xc_tau))
THEN
1208 CALL pw_scale(v_xc_tau(ispin), v_xc_tau(ispin)%pw_grid%dvol)
1213 IF (dft_control%do_admm)
THEN
1215 IF (.NOT.
ASSOCIATED(kpp1_env%deriv_set_admm))
THEN
1216 xc_section_aux => admm_env%xc_section_aux
1217 CALL get_admm_env(qs_env%admm_env, rho_aux_fit=rho_aux)
1219 ALLOCATE (kpp1_env%deriv_set_admm, kpp1_env%rho_set_admm)
1221 rho_r, auxbas_pw_pool, &
1222 xc_section=xc_section_aux)
1229 DO ispin = 1, nspins
1230 CALL pw_axpy(rho1_g(ispin), rho_tot_gspace)
1235 vhartree=v_hartree_gspace)
1236 CALL pw_transfer(v_hartree_gspace, v_hartree_rspace)
1237 CALL pw_scale(v_hartree_rspace, v_hartree_rspace%pw_grid%dvol)
1240 DO ispin = 1, nspins
1241 CALL pw_axpy(v_hartree_rspace, v_xc(ispin))
1243 IF (nspins == 1)
THEN
1245 IF (
ASSOCIATED(v_xc_tau))
CALL pw_scale(v_xc_tau(1), 2.0_dp)
1248 DO ispin = 1, nspins
1250 CALL integrate_v_rspace(v_rspace=v_xc(ispin), &
1251 pmat=rho_ao(ispin), &
1252 hmat=p_env%kpp1(ispin), &
1254 calculate_forces=.false., &
1256 IF (
ASSOCIATED(v_xc_tau))
THEN
1257 CALL integrate_v_rspace(v_rspace=v_xc_tau(ispin), &
1258 pmat=rho_ao(ispin), &
1259 hmat=p_env%kpp1(ispin), &
1261 compute_tau=.true., &
1262 calculate_forces=.false., &
1275 IF (dft_control%qs_control%do_kg)
THEN
1279 cpassert(dft_control%nimages == 1)
1283 ks_matrix=p_env%kpp1, &
1284 ekin_mol=ekin_mol, &
1285 calc_force=.false., &
1295 DO ispin = 1, nspins
1296 ALLOCATE (matrix_g(ispin)%matrix)
1297 CALL dbcsr_copy(matrix_g(ispin)%matrix, p_env%kpp1(ispin)%matrix, &
1298 name=
"MATRIX Kernel")
1303 DO ispin = 1, nspins
1304 CALL transform_m_orth(matrix_g(ispin)%matrix, matrix_s_sqrt_inv, eps_filter)
1310 CALL commutator(matrix_g, matrix_p, matrix_ax, eps_filter, .false., 1.0_dp, 1.0_dp)
1313 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace)
1314 CALL auxbas_pw_pool%give_back_pw(v_hartree_rspace)
1315 CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace)
1316 DO ispin = 1, nspins
1317 CALL auxbas_pw_pool%give_back_pw(v_xc(ispin))
1320 IF (
ASSOCIATED(v_xc_tau))
THEN
1321 DO ispin = 1, nspins
1322 CALL auxbas_pw_pool%give_back_pw(v_xc_tau(ispin))
1324 DEALLOCATE (v_xc_tau)
1329 CALL timestop(handle)
1331 END SUBROUTINE hessian_op2
1349 SUBROUTINE commutator(a, b, res, eps_filter, anticomm, alpha, beta)
1352 POINTER :: a, b, res
1353 REAL(kind=
dp) :: eps_filter
1355 REAL(kind=
dp),
OPTIONAL :: alpha, beta
1357 CHARACTER(LEN=*),
PARAMETER :: routinen =
'commutator'
1359 INTEGER :: handle, ispin
1360 REAL(kind=
dp) :: facc, myalpha, mybeta
1363 CALL timeset(routinen, handle)
1365 cpassert(
ASSOCIATED(a))
1366 cpassert(
ASSOCIATED(b))
1367 cpassert(
ASSOCIATED(res))
1369 CALL dbcsr_create(work, template=a(1)%matrix, matrix_type=dbcsr_type_no_symmetry)
1370 CALL dbcsr_create(work2, template=a(1)%matrix, matrix_type=dbcsr_type_no_symmetry)
1374 IF (
PRESENT(alpha)) myalpha = alpha
1377 IF (
PRESENT(beta)) mybeta = beta
1380 IF (anticomm) facc = 1.0_dp
1382 DO ispin = 1,
SIZE(a)
1384 CALL dbcsr_multiply(
"N",
"N", myalpha, a(ispin)%matrix, b(ispin)%matrix, &
1385 0.0_dp, work, filter_eps=eps_filter)
1390 CALL dbcsr_add(work, work2, 1.0_dp, facc)
1392 CALL dbcsr_add(res(ispin)%matrix, work, mybeta, 1.0_dp)
1399 CALL timestop(handle)
1401 END SUBROUTINE commutator
1416 SUBROUTINE projector(qs_env, matrix_p, matrix_io, eps_filter)
1422 POINTER :: matrix_io
1423 REAL(kind=
dp),
INTENT(IN) :: eps_filter
1425 CHARACTER(len=*),
PARAMETER :: routinen =
'projector'
1427 INTEGER :: handle, ispin, nspins
1432 CALL timeset(routinen, handle)
1435 dft_control=dft_control, &
1437 nspins = dft_control%nspins
1439 CALL dbcsr_create(matrix_q, template=matrix_p(1)%matrix, &
1440 matrix_type=dbcsr_type_no_symmetry)
1441 CALL dbcsr_create(matrix_tmp, template=matrix_p(1)%matrix, &
1442 matrix_type=dbcsr_type_no_symmetry)
1445 CALL dbcsr_copy(matrix_q, matrix_p(1)%matrix)
1453 DO ispin = 1, nspins
1456 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, matrix_p(ispin)%matrix, matrix_io(ispin)%matrix, &
1457 0.0_dp, matrix_tmp, filter_eps=eps_filter)
1460 0.0_dp, matrix_io(ispin)%matrix, filter_eps=eps_filter)
1464 CALL dbcsr_add(matrix_io(ispin)%matrix, matrix_tmp, 1.0_dp, -1.0_dp)
1471 CALL timestop(handle)
1473 END SUBROUTINE projector
1487 SUBROUTINE transform_m_orth(matrix, matrix_trafo, eps_filter)
1489 REAL(kind=
dp) :: eps_filter
1491 CHARACTER(LEN=*),
PARAMETER :: routinen =
'transform_m_orth'
1496 CALL timeset(routinen, handle)
1498 CALL dbcsr_create(matrix_work, template=matrix, matrix_type=dbcsr_type_no_symmetry)
1499 CALL dbcsr_create(matrix_tmp, template=matrix, matrix_type=dbcsr_type_no_symmetry)
1502 0.0_dp, matrix_work, filter_eps=eps_filter)
1503 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, matrix_trafo, matrix_work, &
1504 0.0_dp, matrix_tmp, filter_eps=eps_filter)
1507 CALL dbcsr_add(matrix_tmp, matrix_work, 0.5_dp, 0.5_dp)
1515 CALL timestop(handle)
1517 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)
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.
computes preconditioners, and implements methods to apply them currently used in qs_ot
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, 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, 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, ecoul_1c, rho0_s_rs, rho0_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)
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.