(git:27c966b)
Loading...
Searching...
No Matches
qs_ot.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief orbital transformations
10!> \par History
11!> Added Taylor expansion based computation of the matrix functions (01.2004)
12!> added additional rotation variables for non-equivalent occupied orbs (08.2004)
13!> \author Joost VandeVondele (06.2002)
14! **************************************************************************************************
15MODULE qs_ot
17 USE cp_dbcsr_api, ONLY: &
23 dbcsr_type_no_symmetry
32 USE cp_dbcsr_diag, ONLY: cp_dbcsr_heevd,&
34 USE kinds, ONLY: dp
38 USE qs_ot_types, ONLY: qs_ot_type
39#include "./base/base_uses.f90"
40
41 IMPLICIT NONE
42 PRIVATE
43
44 PUBLIC :: qs_ot_get_p
45 PUBLIC :: qs_ot_get_orbitals
46 PUBLIC :: qs_ot_get_derivative
54 PUBLIC :: qs_ot_p2m_diag
55 PUBLIC :: qs_ot_ref_update
56 PUBLIC :: qs_ot_spectral_kernel
57 PUBLIC :: qs_ot_spectral_values
59
60 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_ot'
61
62CONTAINS
63
64! **************************************************************************************************
65!> \brief gets ready to use the preconditioner/ or renew the preconditioner
66!> only keeps a pointer to the preconditioner.
67!> If you change the preconditioner, you have to call this routine
68!> you remain responsible of proper deallocate of your preconditioner
69!> (or you can reuse it on the next step of the computation)
70!> \param qs_ot_env ...
71!> \param preconditioner ...
72! **************************************************************************************************
73 SUBROUTINE qs_ot_new_preconditioner(qs_ot_env, preconditioner)
74 TYPE(qs_ot_type) :: qs_ot_env
75 TYPE(preconditioner_type), POINTER :: preconditioner
76
77 INTEGER :: ncoef
78
79 qs_ot_env%preconditioner => preconditioner
80 qs_ot_env%preconditioner_changed = .true.
81 qs_ot_env%os_valid = .false.
82 IF (.NOT. ASSOCIATED(qs_ot_env%matrix_psc0)) THEN
83 CALL dbcsr_init_p(qs_ot_env%matrix_psc0)
84 CALL dbcsr_copy(qs_ot_env%matrix_psc0, qs_ot_env%matrix_sc0, 'matrix_psc0')
85 END IF
86 IF (qs_ot_env%has_complex_kpoint_state .AND. &
87 .NOT. ASSOCIATED(qs_ot_env%matrix_psc0_im)) THEN
88 CALL dbcsr_init_p(qs_ot_env%matrix_psc0_im)
89 CALL dbcsr_copy(qs_ot_env%matrix_psc0_im, qs_ot_env%matrix_sc0_im, 'matrix_psc0_im')
90 END IF
91
92 IF (.NOT. qs_ot_env%use_dx) THEN
93 qs_ot_env%use_dx = .true.
94 CALL dbcsr_init_p(qs_ot_env%matrix_dx)
95 CALL dbcsr_copy(qs_ot_env%matrix_dx, qs_ot_env%matrix_gx, 'matrix_dx')
96 IF (qs_ot_env%has_complex_kpoint_state) THEN
97 CALL dbcsr_init_p(qs_ot_env%matrix_dx_im)
98 CALL dbcsr_copy(qs_ot_env%matrix_dx_im, qs_ot_env%matrix_gx_im, 'matrix_dx_im')
99 END IF
100 IF (qs_ot_env%settings%do_rotation) THEN
101 CALL dbcsr_init_p(qs_ot_env%rot_mat_dx)
102 CALL dbcsr_copy(qs_ot_env%rot_mat_dx, qs_ot_env%rot_mat_gx, 'rot_mat_dx')
103 IF (qs_ot_env%has_complex_kpoint_state) THEN
104 CALL dbcsr_init_p(qs_ot_env%rot_mat_dx_im)
105 CALL dbcsr_copy(qs_ot_env%rot_mat_dx_im, qs_ot_env%rot_mat_gx_im, 'rot_mat_dx_im')
106 END IF
107 END IF
108 IF (qs_ot_env%settings%do_ener) THEN
109 ncoef = SIZE(qs_ot_env%ener_gx)
110 ALLOCATE (qs_ot_env%ener_dx(ncoef))
111 qs_ot_env%ener_dx = 0.0_dp
112 END IF
113 END IF
114
115 END SUBROUTINE qs_ot_new_preconditioner
116
117! **************************************************************************************************
118!> \brief multiply paired real/imaginary DBCSR matrices, with optional conjugate transposes
119!> \param op_a N or C
120!> \param op_b N or C
121!> \param a_re real part of A
122!> \param a_im imaginary part of A
123!> \param b_re real part of B
124!> \param b_im imaginary part of B
125!> \param c_re real part of A*B
126!> \param c_im imaginary part of A*B
127!> \param tmp real workspace shaped like C
128! **************************************************************************************************
129 SUBROUTINE qs_ot_complex_multiply(op_a, op_b, a_re, a_im, b_re, b_im, c_re, c_im, tmp)
130 CHARACTER(LEN=1), INTENT(IN) :: op_a, op_b
131 TYPE(dbcsr_type) :: a_re, a_im, b_re, b_im, c_re, c_im, tmp
132
133 CHARACTER(LEN=1) :: db_op_a, db_op_b
134 REAL(kind=dp) :: sign_a, sign_b
135
136 IF (op_a /= 'N' .AND. op_a /= 'C') THEN
137 cpabort("Complex matrix product expects N or C for op_a")
138 END IF
139 IF (op_b /= 'N' .AND. op_b /= 'C') THEN
140 cpabort("Complex matrix product expects N or C for op_b")
141 END IF
142 db_op_a = merge('N', 'T', op_a == 'N')
143 db_op_b = merge('N', 'T', op_b == 'N')
144 sign_a = merge(1.0_dp, -1.0_dp, op_a == 'N')
145 sign_b = merge(1.0_dp, -1.0_dp, op_b == 'N')
146
147 CALL dbcsr_multiply(db_op_a, db_op_b, 1.0_dp, a_re, b_re, 0.0_dp, c_re)
148 CALL dbcsr_multiply(db_op_a, db_op_b, 1.0_dp, a_im, b_im, 0.0_dp, tmp)
149 CALL dbcsr_add(c_re, tmp, alpha_scalar=1.0_dp, beta_scalar=-sign_a*sign_b)
150
151 CALL dbcsr_multiply(db_op_a, db_op_b, sign_b, a_re, b_im, 0.0_dp, c_im)
152 CALL dbcsr_multiply(db_op_a, db_op_b, sign_a, a_im, b_re, 0.0_dp, tmp)
153 CALL dbcsr_add(c_im, tmp, alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
154
155 END SUBROUTINE qs_ot_complex_multiply
156
157! **************************************************************************************************
158!> \brief ...
159!> \param qs_ot_env ...
160!> \param C_NEW ...
161!> \param SC ...
162!> \param G_OLD ...
163!> \param D ...
164! **************************************************************************************************
165 SUBROUTINE qs_ot_on_the_fly_localize(qs_ot_env, C_NEW, SC, G_OLD, D)
166 !
167 TYPE(qs_ot_type) :: qs_ot_env
168 TYPE(dbcsr_type), POINTER :: c_new, sc, g_old, d
169
170 CHARACTER(len=*), PARAMETER :: routinen = 'qs_ot_on_the_fly_localize'
171 INTEGER, PARAMETER :: taylor_order = 50
172 REAL(kind=dp), PARAMETER :: alpha = 0.1_dp, f2_eps = 0.01_dp
173
174 INTEGER :: col, col_size, handle, i, k, n, p, row, &
175 row_size
176 REAL(dp), DIMENSION(:, :), POINTER :: block
177 REAL(kind=dp) :: expfactor, f2, norm_fro, norm_gct, tmp
178 TYPE(dbcsr_distribution_type) :: dist
179 TYPE(dbcsr_iterator_type) :: iter
180 TYPE(dbcsr_type), POINTER :: c, gp1, gp2, gu, u
181 TYPE(mp_comm_type) :: group
182
183 CALL timeset(routinen, handle)
184 !
185 !
186 CALL dbcsr_get_info(c_new, nfullrows_total=n, nfullcols_total=k)
187 !
188 ! C = C*expm(-G)
189 gu => qs_ot_env%buf1_k_k_nosym ! a buffer
190 u => qs_ot_env%buf2_k_k_nosym ! a buffer
191 gp1 => qs_ot_env%buf3_k_k_nosym ! a buffer
192 gp2 => qs_ot_env%buf4_k_k_nosym ! a buffer
193 c => qs_ot_env%buf1_n_k ! a buffer
194 !
195 ! compute the derivative of the norm
196 !-------------------------------------------------------------------
197 ! (x^2+eps)^1/2
198 f2 = 0.0_dp
199 CALL dbcsr_copy(c, c_new)
200 CALL dbcsr_iterator_start(iter, c)
201 DO WHILE (dbcsr_iterator_blocks_left(iter))
202 CALL dbcsr_iterator_next_block(iter, row, col, block, row_size=row_size, col_size=col_size)
203 DO p = 1, col_size ! p
204 DO i = 1, row_size ! i
205 tmp = sqrt(block(i, p)**2 + f2_eps)
206 f2 = f2 + tmp
207 block(i, p) = block(i, p)/tmp
208 END DO
209 END DO
210 END DO
211 CALL dbcsr_iterator_stop(iter)
212 CALL dbcsr_get_info(c, group=group)
213 CALL group%sum(f2)
214 !
215 !
216 CALL dbcsr_multiply('T', 'N', 1.0_dp, c, c_new, 0.0_dp, gu)
217 !
218 ! antisymetrize
219 CALL dbcsr_get_info(gu, distribution=dist)
220 CALL dbcsr_transposed(u, gu, shallow_data_copy=.false., &
221 use_distribution=dist, &
222 transpose_distribution=.false.)
223 CALL dbcsr_add(gu, u, alpha_scalar=-0.5_dp, beta_scalar=0.5_dp)
224 !-------------------------------------------------------------------
225 !
226 norm_fro = dbcsr_frobenius_norm(gu)
227 norm_gct = dbcsr_gershgorin_norm(gu)
228 !write(*,*) 'qs_ot_localize: ||P-I||_f=',norm_fro,' ||P-I||_GCT=',norm_gct
229 !
230 !kscale = CEILING(LOG(MIN(norm_fro,norm_gct))/LOG(2.0_dp))
231 !scale = LOG(MIN(norm_fro,norm_gct))/LOG(2.0_dp)
232 !write(*,*) 'qs_ot_localize: scale=',scale,' kscale=',kscale
233 !
234 ! rescale for steepest descent
235 CALL dbcsr_scale(gu, -alpha)
236 !
237 ! compute unitary transform
238 ! zeroth and first order
239 expfactor = 1.0_dp
240 CALL dbcsr_copy(u, gu)
241 CALL dbcsr_scale(u, expfactor)
242 CALL dbcsr_add_on_diag(u, 1.0_dp)
243 ! other orders
244 CALL dbcsr_copy(gp1, gu)
245 DO i = 2, taylor_order
246 ! new power of G
247 CALL dbcsr_multiply('N', 'N', 1.0_dp, gu, gp1, 0.0_dp, gp2)
248 CALL dbcsr_copy(gp1, gp2)
249 ! add to the taylor expansion so far
250 expfactor = expfactor/real(i, kind=dp)
251 CALL dbcsr_add(u, gp1, alpha_scalar=1.0_dp, beta_scalar=expfactor)
252 norm_fro = dbcsr_frobenius_norm(gp1)
253 !write(*,*) 'Taylor expansion i=',i,' norm(X^i)/i!=',norm_fro*expfactor
254 IF (norm_fro*expfactor < 1.0e-10_dp) EXIT
255 END DO
256 !
257 ! rotate MOs
258 CALL dbcsr_multiply('N', 'N', 1.0_dp, c_new, u, 0.0_dp, c)
259 CALL dbcsr_copy(c_new, c)
260 !
261 ! rotate SC
262 CALL dbcsr_multiply('N', 'N', 1.0_dp, sc, u, 0.0_dp, c)
263 CALL dbcsr_copy(sc, c)
264 !
265 ! rotate D_i
266 CALL dbcsr_multiply('N', 'N', 1.0_dp, d, u, 0.0_dp, c)
267 CALL dbcsr_copy(d, c)
268 !
269 ! rotate G_i-1
270 IF (ASSOCIATED(g_old)) THEN
271 CALL dbcsr_multiply('N', 'N', 1.0_dp, g_old, u, 0.0_dp, c)
272 CALL dbcsr_copy(g_old, c)
273 END IF
274 !
275 CALL timestop(handle)
276 END SUBROUTINE qs_ot_on_the_fly_localize
277
278! **************************************************************************************************
279!> \brief ...
280!> \param qs_ot_env ...
281!> \param C_OLD ...
282!> \param C_TMP ...
283!> \param C_NEW ...
284!> \param P ...
285!> \param SC ...
286!> \param update ...
287! **************************************************************************************************
288 SUBROUTINE qs_ot_ref_chol(qs_ot_env, C_OLD, C_TMP, C_NEW, P, SC, update)
289 !
290 TYPE(qs_ot_type) :: qs_ot_env
291 TYPE(dbcsr_type) :: c_old, c_tmp, c_new, p, sc
292 LOGICAL, INTENT(IN) :: update
293
294 CHARACTER(len=*), PARAMETER :: routinen = 'qs_ot_ref_chol'
295
296 INTEGER :: handle, k, n
297
298 CALL timeset(routinen, handle)
299 !
300 CALL dbcsr_get_info(c_new, nfullrows_total=n, nfullcols_total=k)
301 !
302 ! P = U'*U
303 CALL cp_dbcsr_cholesky_decompose(p, k, qs_ot_env%para_env, qs_ot_env%blacs_env)
304 !
305 ! C_NEW = C_OLD*inv(U)
306 CALL cp_dbcsr_cholesky_restore(c_old, k, p, c_new, op="SOLVE", pos="RIGHT", &
307 transa="N", para_env=qs_ot_env%para_env, blacs_env=qs_ot_env%blacs_env)
308 !
309 ! Update SC if needed
310 IF (update) THEN
311 CALL cp_dbcsr_cholesky_restore(sc, k, p, c_tmp, op="SOLVE", pos="RIGHT", &
312 transa="N", para_env=qs_ot_env%para_env, blacs_env=qs_ot_env%blacs_env)
313 CALL dbcsr_copy(sc, c_tmp)
314 END IF
315 !
316 CALL timestop(handle)
317 END SUBROUTINE qs_ot_ref_chol
318
319! **************************************************************************************************
320!> \brief ...
321!> \param qs_ot_env ...
322!> \param C_OLD ...
323!> \param C_TMP ...
324!> \param C_NEW ...
325!> \param P ...
326!> \param SC ...
327!> \param update ...
328! **************************************************************************************************
329 SUBROUTINE qs_ot_ref_lwdn(qs_ot_env, C_OLD, C_TMP, C_NEW, P, SC, update)
330 !
331 TYPE(qs_ot_type) :: qs_ot_env
332 TYPE(dbcsr_type) :: c_old, c_tmp, c_new, p, sc
333 LOGICAL, INTENT(IN) :: update
334
335 CHARACTER(len=*), PARAMETER :: routinen = 'qs_ot_ref_lwdn'
336
337 INTEGER :: handle, i, k, n
338 REAL(dp), ALLOCATABLE, DIMENSION(:) :: eig, fun
339 TYPE(dbcsr_type), POINTER :: v, w
340
341 CALL timeset(routinen, handle)
342 !
343 CALL dbcsr_get_info(c_new, nfullrows_total=n, nfullcols_total=k)
344 !
345 v => qs_ot_env%buf1_k_k_nosym ! a buffer
346 w => qs_ot_env%buf2_k_k_nosym ! a buffer
347 ALLOCATE (eig(k), fun(k))
348 !
349 CALL cp_dbcsr_syevd(p, v, eig, qs_ot_env%para_env, qs_ot_env%blacs_env)
350 !
351 ! compute the P^(-1/2)
352 DO i = 1, k
353 IF (eig(i) <= 0.0_dp) THEN
354 cpabort("P not positive definite")
355 END IF
356 IF (eig(i) < 1.0e-8_dp) THEN
357 fun(i) = 0.0_dp
358 ELSE
359 fun(i) = 1.0_dp/sqrt(eig(i))
360 END IF
361 END DO
362 CALL dbcsr_copy(w, v)
363 CALL dbcsr_scale_by_vector(v, alpha=fun, side='right')
364 CALL dbcsr_multiply('N', 'T', 1.0_dp, w, v, 0.0_dp, p)
365 !
366 ! Update C
367 CALL dbcsr_multiply('N', 'N', 1.0_dp, c_old, p, 0.0_dp, c_new)
368 !
369 ! Update SC if needed
370 IF (update) THEN
371 CALL dbcsr_multiply('N', 'N', 1.0_dp, sc, p, 0.0_dp, c_tmp)
372 CALL dbcsr_copy(sc, c_tmp)
373 END IF
374 !
375 DEALLOCATE (eig, fun)
376 !
377 CALL timestop(handle)
378 END SUBROUTINE qs_ot_ref_lwdn
379
380! **************************************************************************************************
381!> \brief ...
382!> \param qs_ot_env ...
383!> \param C_OLD ...
384!> \param C_TMP ...
385!> \param C_NEW ...
386!> \param P ...
387!> \param SC ...
388!> \param norm_in ...
389!> \param update ...
390! **************************************************************************************************
391 SUBROUTINE qs_ot_ref_poly(qs_ot_env, C_OLD, C_TMP, C_NEW, P, SC, norm_in, update)
392 !
393 TYPE(qs_ot_type) :: qs_ot_env
394 TYPE(dbcsr_type), POINTER :: c_old, c_tmp, c_new, p
395 TYPE(dbcsr_type) :: sc
396 REAL(dp), INTENT(IN) :: norm_in
397 LOGICAL, INTENT(IN) :: update
398
399 CHARACTER(len=*), PARAMETER :: routinen = 'qs_ot_ref_poly'
400
401 INTEGER :: handle, irefine, k, n
402 LOGICAL :: quick_exit
403 REAL(dp) :: norm, norm_fro, norm_gct, occ_in, &
404 occ_out, rescale
405 TYPE(dbcsr_type), POINTER :: buf1, buf2, buf_nosym, ft, fy
406
407 CALL timeset(routinen, handle)
408 !
409 CALL dbcsr_get_info(c_new, nfullrows_total=n, nfullcols_total=k)
410 !
411 buf_nosym => qs_ot_env%buf1_k_k_nosym ! a buffer
412 buf1 => qs_ot_env%buf1_k_k_sym ! a buffer
413 buf2 => qs_ot_env%buf2_k_k_sym ! a buffer
414 fy => qs_ot_env%buf3_k_k_sym ! a buffer
415 ft => qs_ot_env%buf4_k_k_sym ! a buffer
416 !
417 ! initialize the norm (already computed in qs_ot_get_orbitals_ref)
418 norm = norm_in
419 !
420 ! can we do a quick exit?
421 quick_exit = .false.
422 IF (norm < qs_ot_env%settings%eps_irac_quick_exit) quick_exit = .true.
423 !
424 ! lets refine
425 rescale = 1.0_dp
426 DO irefine = 1, qs_ot_env%settings%max_irac
427 !
428 ! rescaling
429 IF (norm > 1.0_dp) THEN
430 CALL dbcsr_scale(p, 1.0_dp/norm)
431 rescale = rescale/sqrt(norm)
432 END IF
433 !
434 ! get the refinement polynomial
435 CALL qs_ot_refine(p, fy, buf1, buf2, qs_ot_env%settings%irac_degree, &
436 qs_ot_env%settings%eps_irac_filter_matrix)
437 !
438 ! collect the transformation
439 IF (irefine == 1) THEN
440 CALL dbcsr_copy(ft, fy, name='FT')
441 ELSE
442 CALL dbcsr_multiply('N', 'N', 1.0_dp, ft, fy, 0.0_dp, buf1)
443 IF (qs_ot_env%settings%eps_irac_filter_matrix > 0.0_dp) THEN
444 occ_in = dbcsr_get_occupation(buf1)
445 CALL dbcsr_filter(buf1, qs_ot_env%settings%eps_irac_filter_matrix)
446 occ_out = dbcsr_get_occupation(buf1)
447 END IF
448 CALL dbcsr_copy(ft, buf1, name='FT')
449 END IF
450 !
451 ! quick exit if possible
452 IF (quick_exit) THEN
453 EXIT
454 END IF
455 !
456 ! P = FY^T * P * FY
457 CALL dbcsr_multiply('N', 'N', 1.0_dp, p, fy, 0.0_dp, buf_nosym)
458 IF (qs_ot_env%settings%eps_irac_filter_matrix > 0.0_dp) THEN
459 occ_in = dbcsr_get_occupation(buf_nosym)
460 CALL dbcsr_filter(buf_nosym, qs_ot_env%settings%eps_irac_filter_matrix)
461 occ_out = dbcsr_get_occupation(buf_nosym)
462 END IF
463 CALL dbcsr_multiply('N', 'N', 1.0_dp, fy, buf_nosym, 0.0_dp, p)
464 IF (qs_ot_env%settings%eps_irac_filter_matrix > 0.0_dp) THEN
465 occ_in = dbcsr_get_occupation(p)
466 CALL dbcsr_filter(p, qs_ot_env%settings%eps_irac_filter_matrix)
467 occ_out = dbcsr_get_occupation(p)
468 END IF
469 !
470 ! check ||P-1||_gct
471 CALL dbcsr_add_on_diag(p, -1.0_dp)
472 norm_fro = dbcsr_frobenius_norm(p)
473 norm_gct = dbcsr_gershgorin_norm(p)
474 CALL dbcsr_add_on_diag(p, 1.0_dp)
475 norm = min(norm_gct, norm_fro)
476 !
477 ! printing
478 !
479 ! blows up
480 IF (norm > 1.0e10_dp) THEN
481 CALL cp_abort(__location__, &
482 "Refinement blows up! "// &
483 "We need you to improve the code, please post your input on "// &
484 "the forum https://www.cp2k.org/")
485 END IF
486 !
487 ! can we do a quick exit next step?
488 IF (norm < qs_ot_env%settings%eps_irac_quick_exit) quick_exit = .true.
489 !
490 ! are we done?
491 IF (norm < qs_ot_env%settings%eps_irac) EXIT
492 !
493 END DO
494 !
495 ! C_NEW = C_NEW * FT * rescale
496 CALL dbcsr_multiply('N', 'N', rescale, c_old, ft, 0.0_dp, c_new)
497 IF (qs_ot_env%settings%eps_irac_filter_matrix > 0.0_dp) THEN
498 occ_in = dbcsr_get_occupation(c_new)
499 CALL dbcsr_filter(c_new, qs_ot_env%settings%eps_irac_filter_matrix)
500 occ_out = dbcsr_get_occupation(c_new)
501 END IF
502 !
503 ! update SC = SC * FY * rescale
504 IF (update) THEN
505 CALL dbcsr_multiply('N', 'N', rescale, sc, ft, 0.0_dp, c_tmp)
506 IF (qs_ot_env%settings%eps_irac_filter_matrix > 0.0_dp) THEN
507 occ_in = dbcsr_get_occupation(c_tmp)
508 CALL dbcsr_filter(c_tmp, qs_ot_env%settings%eps_irac_filter_matrix)
509 occ_out = dbcsr_get_occupation(c_tmp)
510 END IF
511 CALL dbcsr_copy(sc, c_tmp)
512 END IF
513 !
514 CALL timestop(handle)
515 END SUBROUTINE qs_ot_ref_poly
516
517! **************************************************************************************************
518!> \brief ...
519!> \param qs_ot_env1 ...
520!> \return ...
521! **************************************************************************************************
522 FUNCTION qs_ot_ref_update(qs_ot_env1) RESULT(update)
523 !
524 TYPE(qs_ot_type) :: qs_ot_env1
525 LOGICAL :: update
526
527 update = .false.
528 SELECT CASE (qs_ot_env1%settings%ot_method)
529 CASE ("CG", "SD")
530 SELECT CASE (qs_ot_env1%settings%line_search_method)
531 CASE ("2PNT")
532 IF (qs_ot_env1%line_search_count == 2) update = .true.
533 CASE DEFAULT
534 cpabort("NYI")
535 END SELECT
536 CASE ("DIIS")
537 update = .true.
538 CASE ("BROY", "LBFG")
539 ! These minimizers retain positions or secants in one fixed REF chart.
540 update = .false.
541 CASE DEFAULT
542 cpabort("NYI")
543 END SELECT
544 END FUNCTION qs_ot_ref_update
545
546! **************************************************************************************************
547!> \brief ...
548!> \param qs_ot_env1 ...
549!> \param norm_in ...
550!> \param ortho_irac ...
551! **************************************************************************************************
552 SUBROUTINE qs_ot_ref_decide(qs_ot_env1, norm_in, ortho_irac)
553 !
554 TYPE(qs_ot_type) :: qs_ot_env1
555 REAL(dp), INTENT(IN) :: norm_in
556 CHARACTER(LEN=*), INTENT(INOUT) :: ortho_irac
557
558 ortho_irac = qs_ot_env1%settings%ortho_irac
559 IF (norm_in < qs_ot_env1%settings%eps_irac_switch) ortho_irac = "POLY"
560 END SUBROUTINE qs_ot_ref_decide
561
562! **************************************************************************************************
563!> \brief ...
564!> \param matrix_c ...
565!> \param matrix_s ...
566!> \param matrix_x ...
567!> \param matrix_sx ...
568!> \param matrix_gx_old ...
569!> \param matrix_dx ...
570!> \param qs_ot_env ...
571!> \param qs_ot_env1 ...
572! **************************************************************************************************
573 SUBROUTINE qs_ot_get_orbitals_ref(matrix_c, matrix_s, matrix_x, matrix_sx, &
574 matrix_gx_old, matrix_dx, qs_ot_env, qs_ot_env1)
575 !
576 TYPE(dbcsr_type), POINTER :: matrix_c, matrix_s, matrix_x, matrix_sx, &
577 matrix_gx_old, matrix_dx
578 TYPE(qs_ot_type) :: qs_ot_env, qs_ot_env1
579
580 CHARACTER(len=*), PARAMETER :: routinen = 'qs_ot_get_orbitals_ref'
581
582 CHARACTER(LEN=4) :: ortho_irac
583 INTEGER :: handle, k, n
584 LOGICAL :: on_the_fly_loc, update
585 REAL(dp) :: norm, norm_fro, norm_gct, occ_in, occ_out
586 TYPE(dbcsr_type), POINTER :: c_new, c_old, c_tmp, d, g_old, p, s, sc
587
588 CALL timeset(routinen, handle)
589
590 CALL dbcsr_get_info(matrix_c, nfullrows_total=n, nfullcols_total=k)
591 !
592 c_new => matrix_c
593 c_old => matrix_x ! need to be carefully updated for the gradient !
594 sc => matrix_sx ! need to be carefully updated for the gradient !
595 g_old => matrix_gx_old ! need to be carefully updated for localization !
596 d => matrix_dx ! need to be carefully updated for localization !
597 s => matrix_s
598
599 p => qs_ot_env%p_k_k_sym ! a buffer
600 c_tmp => qs_ot_env%buf1_n_k ! a buffer
601 !
602 ! do we need to update C_OLD and SC?
603 update = qs_ot_ref_update(qs_ot_env1)
604 !
605 ! do we want to on the fly localize?
606 ! for the moment this is set from the input,
607 ! later we might want to localize every n-step or
608 ! when the sparsity increases...
609 on_the_fly_loc = qs_ot_env1%settings%on_the_fly_loc
610 !
611 ! compute SC = S*C
612 IF (ASSOCIATED(s)) THEN
613 CALL dbcsr_multiply('N', 'N', 1.0_dp, s, c_old, 0.0_dp, sc)
614 IF (qs_ot_env1%settings%eps_irac_filter_matrix > 0.0_dp) THEN
615 occ_in = dbcsr_get_occupation(sc)
616 CALL dbcsr_filter(sc, qs_ot_env1%settings%eps_irac_filter_matrix)
617 occ_out = dbcsr_get_occupation(sc)
618 END IF
619 ELSE
620 CALL dbcsr_copy(sc, c_old)
621 END IF
622 !
623 ! compute P = C'*SC
624 CALL dbcsr_multiply('T', 'N', 1.0_dp, c_old, sc, 0.0_dp, p)
625 IF (qs_ot_env1%settings%eps_irac_filter_matrix > 0.0_dp) THEN
626 occ_in = dbcsr_get_occupation(p)
627 CALL dbcsr_filter(p, qs_ot_env1%settings%eps_irac_filter_matrix)
628 occ_out = dbcsr_get_occupation(p)
629 END IF
630 !
631 ! check ||P-1||_f and ||P-1||_gct
632 CALL dbcsr_add_on_diag(p, -1.0_dp)
633 norm_fro = dbcsr_frobenius_norm(p)
634 norm_gct = dbcsr_gershgorin_norm(p)
635 CALL dbcsr_add_on_diag(p, 1.0_dp)
636 norm = min(norm_gct, norm_fro)
637 CALL qs_ot_ref_decide(qs_ot_env1, norm, ortho_irac)
638 !
639 ! select the orthogonality method
640 SELECT CASE (ortho_irac)
641 CASE ("CHOL")
642 CALL qs_ot_ref_chol(qs_ot_env, c_old, c_tmp, c_new, p, sc, update)
643 CASE ("LWDN")
644 CALL qs_ot_ref_lwdn(qs_ot_env, c_old, c_tmp, c_new, p, sc, update)
645 CASE ("POLY")
646 CALL qs_ot_ref_poly(qs_ot_env, c_old, c_tmp, c_new, p, sc, norm, update)
647 CASE DEFAULT
648 cpabort("Wrong argument")
649 END SELECT
650 !
651 ! We update the C_i+1 and localization
652 IF (update) THEN
653 IF (on_the_fly_loc) THEN
654 CALL qs_ot_on_the_fly_localize(qs_ot_env, c_new, sc, g_old, d)
655 END IF
656 CALL dbcsr_copy(c_old, c_new)
657 END IF
658
659 IF (qs_ot_env%settings%do_rotation) THEN
660 CALL qs_ot_generate_rotation(qs_ot_env)
661 CALL dbcsr_multiply('N', 'N', 1.0_dp, c_new, qs_ot_env%rot_mat_u, &
662 0.0_dp, c_tmp)
663 CALL dbcsr_copy(c_new, c_tmp)
664 END IF
665 !
666 CALL timestop(handle)
667 END SUBROUTINE qs_ot_get_orbitals_ref
668
669! **************************************************************************************************
670!> \brief refinement polynomial of degree 2,3 and 4 (PRB 70, 193102 (2004))
671!> \param P ...
672!> \param FY ...
673!> \param P2 ...
674!> \param T ...
675!> \param irac_degree ...
676!> \param eps_irac_filter_matrix ...
677! **************************************************************************************************
678 SUBROUTINE qs_ot_refine(P, FY, P2, T, irac_degree, eps_irac_filter_matrix)
679 TYPE(dbcsr_type), INTENT(inout) :: p, fy, p2, t
680 INTEGER, INTENT(in) :: irac_degree
681 REAL(dp), INTENT(in) :: eps_irac_filter_matrix
682
683 CHARACTER(len=*), PARAMETER :: routinen = 'qs_ot_refine'
684
685 INTEGER :: handle, k
686 REAL(dp) :: occ_in, occ_out, r
687
688 CALL timeset(routinen, handle)
689
690 CALL dbcsr_get_info(p, nfullcols_total=k)
691 SELECT CASE (irac_degree)
692 CASE (2)
693 ! C_out = C_in * ( 15/8 * I - 10/8 * P + 3/8 * P^2)
694 r = 3.0_dp/8.0_dp
695 CALL dbcsr_multiply('N', 'N', r, p, p, 0.0_dp, fy)
696 IF (eps_irac_filter_matrix > 0.0_dp) THEN
697 occ_in = dbcsr_get_occupation(fy)
698 CALL dbcsr_filter(fy, eps_irac_filter_matrix)
699 occ_out = dbcsr_get_occupation(fy)
700 END IF
701 r = -10.0_dp/8.0_dp
702 CALL dbcsr_add(fy, p, alpha_scalar=1.0_dp, beta_scalar=r)
703 r = 15.0_dp/8.0_dp
704 CALL dbcsr_add_on_diag(fy, alpha=r)
705 CASE (3)
706 ! C_out = C_in * ( 35/16 * I - 35/16 * P + 21/16 * P^2 - 5/16 P^3)
707 CALL dbcsr_multiply('N', 'N', 1.0_dp, p, p, 0.0_dp, p2)
708 IF (eps_irac_filter_matrix > 0.0_dp) THEN
709 occ_in = dbcsr_get_occupation(p2)
710 CALL dbcsr_filter(p2, eps_irac_filter_matrix)
711 occ_out = dbcsr_get_occupation(p2)
712 END IF
713 r = -5.0_dp/16.0_dp
714 CALL dbcsr_multiply('N', 'N', r, p2, p, 0.0_dp, fy)
715 IF (eps_irac_filter_matrix > 0.0_dp) THEN
716 occ_in = dbcsr_get_occupation(fy)
717 CALL dbcsr_filter(fy, eps_irac_filter_matrix)
718 occ_out = dbcsr_get_occupation(fy)
719 END IF
720 r = 21.0_dp/16.0_dp
721 CALL dbcsr_add(fy, p2, alpha_scalar=1.0_dp, beta_scalar=r)
722 r = -35.0_dp/16.0_dp
723 CALL dbcsr_add(fy, p, alpha_scalar=1.0_dp, beta_scalar=r)
724 r = 35.0_dp/16.0_dp
725 CALL dbcsr_add_on_diag(fy, alpha=r)
726 CASE (4)
727 ! C_out = C_in * ( 315/128 * I - 420/128 * P + 378/128 * P^2 - 180/128 P^3 + 35/128 P^4 )
728 ! = C_in * ( 315/128 * I - 420/128 * P + 378/128 * P^2 + ( - 180/128 * P + 35/128 * P^2 ) * P^2 )
729 CALL dbcsr_multiply('N', 'N', 1.0_dp, p, p, 0.0_dp, p2) ! P^2
730 IF (eps_irac_filter_matrix > 0.0_dp) THEN
731 occ_in = dbcsr_get_occupation(p2)
732 CALL dbcsr_filter(p2, eps_irac_filter_matrix)
733 occ_out = dbcsr_get_occupation(p2)
734 END IF
735 r = -180.0_dp/128.0_dp
736 CALL dbcsr_add(t, p, alpha_scalar=0.0_dp, beta_scalar=r) ! T=-180/128*P
737 r = 35.0_dp/128.0_dp
738 CALL dbcsr_add(t, p2, alpha_scalar=1.0_dp, beta_scalar=r) ! T=T+35/128*P^2
739 CALL dbcsr_multiply('N', 'N', 1.0_dp, t, p2, 0.0_dp, fy) ! Y=T*P^2
740 IF (eps_irac_filter_matrix > 0.0_dp) THEN
741 occ_in = dbcsr_get_occupation(fy)
742 CALL dbcsr_filter(fy, eps_irac_filter_matrix)
743 occ_out = dbcsr_get_occupation(fy)
744 END IF
745 r = 378.0_dp/128.0_dp
746 CALL dbcsr_add(fy, p2, alpha_scalar=1.0_dp, beta_scalar=r) ! Y=Y+378/128*P^2
747 r = -420.0_dp/128.0_dp
748 CALL dbcsr_add(fy, p, alpha_scalar=1.0_dp, beta_scalar=r) ! Y=Y-420/128*P
749 r = 315.0_dp/128.0_dp
750 CALL dbcsr_add_on_diag(fy, alpha=r) ! Y=Y+315/128*I
751 CASE DEFAULT
752 cpabort("This irac_order NYI")
753 END SELECT
754 CALL timestop(handle)
755 END SUBROUTINE qs_ot_refine
756
757! **************************************************************************************************
758!> \brief ...
759!> \param matrix_hc ...
760!> \param matrix_x ...
761!> \param matrix_sx ...
762!> \param matrix_gx ...
763!> \param qs_ot_env ...
764! **************************************************************************************************
765 SUBROUTINE qs_ot_get_derivative_ref(matrix_hc, matrix_x, matrix_sx, matrix_gx, &
766 qs_ot_env)
767 TYPE(dbcsr_type), POINTER :: matrix_hc, matrix_x, matrix_sx, matrix_gx
768 TYPE(qs_ot_type) :: qs_ot_env
769
770 CHARACTER(len=*), PARAMETER :: routinen = 'qs_ot_get_derivative_ref'
771
772 INTEGER :: handle, k, n
773 REAL(dp) :: occ_in, occ_out
774 TYPE(dbcsr_type), POINTER :: c, chc, g, hc, hc_work, sc
775
776 CALL timeset(routinen, handle)
777
778 CALL dbcsr_get_info(matrix_x, nfullrows_total=n, nfullcols_total=k)
779 !
780 c => matrix_x ! NBsf*NOcc
781 sc => matrix_sx ! NBsf*NOcc need to be up2date
782 hc => matrix_hc ! NBsf*NOcc
783 g => matrix_gx ! NBsf*NOcc
784 chc => qs_ot_env%buf1_k_k_sym ! buffer
785
786 IF (qs_ot_env%settings%do_rotation) THEN
787 ! The physical orbitals are C_current=Q*U. Pull dE/dC_current
788 ! back to the unrotated REF basis before projecting it.
789 CALL qs_ot_rot_mat_derivative(qs_ot_env)
790 hc_work => qs_ot_env%buf1_n_k
791 CALL dbcsr_multiply('N', 'T', 1.0_dp, hc, qs_ot_env%rot_mat_u, &
792 0.0_dp, hc_work)
793 ELSE
794 hc_work => hc
795 END IF
796
797 ! C'*(H*C)
798 CALL dbcsr_multiply('T', 'N', 1.0_dp, c, hc_work, 0.0_dp, chc)
799 IF (qs_ot_env%settings%eps_irac_filter_matrix > 0.0_dp) THEN
800 occ_in = dbcsr_get_occupation(chc)
801 CALL dbcsr_filter(chc, qs_ot_env%settings%eps_irac_filter_matrix)
802 occ_out = dbcsr_get_occupation(chc)
803 END IF
804 ! (S*C)*(C'*H*C)
805 CALL dbcsr_multiply('N', 'N', 1.0_dp, sc, chc, 0.0_dp, g)
806 IF (qs_ot_env%settings%eps_irac_filter_matrix > 0.0_dp) THEN
807 occ_in = dbcsr_get_occupation(g)
808 CALL dbcsr_filter(g, qs_ot_env%settings%eps_irac_filter_matrix)
809 occ_out = dbcsr_get_occupation(g)
810 END IF
811 ! G = 2*(1-S*C*C')*H*C
812 CALL dbcsr_add(g, hc_work, alpha_scalar=-1.0_dp, beta_scalar=1.0_dp)
813 !
814 CALL timestop(handle)
815 END SUBROUTINE qs_ot_get_derivative_ref
816
817! **************************************************************************************************
818!> \brief Transpose a square DBCSR matrix while retaining its target distribution.
819!> \param matrix source matrix
820!> \param transposed transposed matrix
821!> \param identity_template square matrix template
822! **************************************************************************************************
823 SUBROUTINE qs_ot_square_transpose(matrix, transposed, identity_template)
824 TYPE(dbcsr_type) :: matrix, transposed, identity_template
825
826 TYPE(dbcsr_type) :: identity
827
828 CALL dbcsr_copy(transposed, matrix, name='square_transposed')
829 CALL dbcsr_copy(identity, identity_template, name='transpose_identity')
830 CALL dbcsr_set(identity, 0.0_dp)
831 CALL dbcsr_add_on_diag(identity, 1.0_dp)
832 CALL dbcsr_multiply('T', 'N', 1.0_dp, matrix, identity, 0.0_dp, transposed)
833 CALL dbcsr_release(identity)
834
835 END SUBROUTINE qs_ot_square_transpose
836
837! **************************************************************************************************
838!> \brief computes p=x*S*x and the matrix functionals related matrices
839!> \param matrix_x ...
840!> \param matrix_sx ...
841!> \param qs_ot_env ...
842! **************************************************************************************************
843 SUBROUTINE qs_ot_get_p(matrix_x, matrix_sx, qs_ot_env)
844
845 TYPE(dbcsr_type), POINTER :: matrix_x, matrix_sx
846 TYPE(qs_ot_type) :: qs_ot_env
847
848 CHARACTER(len=*), PARAMETER :: routinen = 'qs_ot_get_p'
849 REAL(kind=dp), PARAMETER :: rone = 1.0_dp, rzero = 0.0_dp
850
851 INTEGER :: handle, k, max_iter, n
852 LOGICAL :: converged
853 REAL(kind=dp) :: max_ev, min_ev, threshold
854
855 CALL timeset(routinen, handle)
856
857 CALL dbcsr_get_info(matrix_x, nfullrows_total=n, nfullcols_total=k)
858
859 ! get the overlap
860 CALL dbcsr_multiply('T', 'N', rone, matrix_x, matrix_sx, rzero, &
861 qs_ot_env%matrix_p)
862
863 ! get an upper bound for the largest eigenvalue
864 ! try using lancos first and fall back to gershgorin norm if it fails
865 max_iter = 30; threshold = 1.0e-03_dp
866 CALL arnoldi_extremal(qs_ot_env%matrix_p, max_ev, min_ev, converged, threshold, max_iter)
867 qs_ot_env%largest_eval_upper_bound = max(max_ev, abs(min_ev))
868
869 IF (.NOT. converged) qs_ot_env%largest_eval_upper_bound = dbcsr_gershgorin_norm(qs_ot_env%matrix_p)
870 CALL decide_strategy(qs_ot_env)
871 IF (qs_ot_env%do_taylor) THEN
872 CALL qs_ot_p2m_taylor(qs_ot_env)
873 ELSE
874 CALL qs_ot_p2m_diag(qs_ot_env)
875 END IF
876
877 IF (qs_ot_env%settings%do_rotation) THEN
878 CALL qs_ot_generate_rotation(qs_ot_env)
879 END IF
880
881 CALL timestop(handle)
882
883 END SUBROUTINE qs_ot_get_p
884
885! **************************************************************************************************
886!> \brief computes the rotation matrix rot_mat_u that is associated to a given
887!> rot_mat_x using rot_mat_u=exp(rot_mat_x)
888!> \param qs_ot_env a valid qs_ot_env
889!> \par History
890!> 08.2004 created [Joost VandeVondele]
891!> 12.2024 Rewrite to use only real matrices [Ole Schuett]
892! **************************************************************************************************
893 SUBROUTINE qs_ot_generate_rotation(qs_ot_env)
894
895 TYPE(qs_ot_type) :: qs_ot_env
896
897 CHARACTER(len=*), PARAMETER :: routinen = 'qs_ot_generate_rotation'
898
899 INTEGER :: handle, k
900 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: exp_evals_im, exp_evals_re
901 TYPE(dbcsr_type) :: buf_1, buf_2
902
903 CALL timeset(routinen, handle)
904
905 CALL dbcsr_get_info(qs_ot_env%rot_mat_x, nfullrows_total=k)
906
907 IF (k /= 0) THEN
908 ! We want to compute: rot_mat_u = exp(i*rot_mat_x)
909
910 ! Diagonalize: matrix = i*rot_mat_x.
911 ! Note that matrix is imaginary and hermitian because rot_mat_x is real and anti-symmetric.
912 CALL cp_dbcsr_heevd(matrix_im=qs_ot_env%rot_mat_x, & ! matrix_re omitted because it's zero
913 eigenvectors_re=qs_ot_env%rot_mat_evec_re, &
914 eigenvectors_im=qs_ot_env%rot_mat_evec_im, &
915 eigenvalues=qs_ot_env%rot_mat_evals, &
916 para_env=qs_ot_env%para_env, &
917 blacs_env=qs_ot_env%blacs_env)
918
919 ! Compute: exp_evals = EXP(-i*rot_mat_evals)
920 ALLOCATE (exp_evals_re(k), exp_evals_im(k))
921 exp_evals_re(:) = cos(-qs_ot_env%rot_mat_evals(:))
922 exp_evals_im(:) = sin(-qs_ot_env%rot_mat_evals(:))
923
924 ! Compute: rot_mat_u = \sum_ij exp_evals_ij * |rot_mat_evec_i> <rot_mat_evec_j|
925 ! Note that we need only two matrix multiplications because rot_mat_u is real.
926 CALL dbcsr_copy(buf_1, qs_ot_env%rot_mat_evec_re, name="buf_1")
927 CALL dbcsr_scale_by_vector(buf_1, alpha=exp_evals_re, side='right')
928 CALL dbcsr_copy(buf_2, qs_ot_env%rot_mat_evec_im, name="buf_2")
929 CALL dbcsr_scale_by_vector(buf_2, alpha=exp_evals_im, side='right')
930 CALL dbcsr_add(buf_1, buf_2, alpha_scalar=+1.0_dp, beta_scalar=-1.0_dp)
931 CALL dbcsr_multiply('N', 'T', 1.0_dp, buf_1, qs_ot_env%rot_mat_evec_re, 0.0_dp, qs_ot_env%rot_mat_u)
932
933 CALL dbcsr_copy(buf_1, qs_ot_env%rot_mat_evec_im)
934 CALL dbcsr_scale_by_vector(buf_1, alpha=exp_evals_re, side='right')
935 CALL dbcsr_copy(buf_2, qs_ot_env%rot_mat_evec_re)
936 CALL dbcsr_scale_by_vector(buf_2, alpha=exp_evals_im, side='right')
937 CALL dbcsr_add(buf_1, buf_2, alpha_scalar=+1.0_dp, beta_scalar=+1.0_dp)
938 CALL dbcsr_multiply('N', 'T', 1.0_dp, buf_1, qs_ot_env%rot_mat_evec_im, 1.0_dp, qs_ot_env%rot_mat_u)
939
940 ! Clean up.
941 CALL dbcsr_release(buf_1)
942 CALL dbcsr_release(buf_2)
943 DEALLOCATE (exp_evals_re, exp_evals_im)
944 END IF
945
946 CALL timestop(handle)
947
948 END SUBROUTINE qs_ot_generate_rotation
949
950! **************************************************************************************************
951!> \brief computes the derivative fields with respect to rot_mat_x
952!> \param qs_ot_env valid qs_ot_env. In particular qs_ot_generate_rotation has to be called before
953!> and the rot_mat_dedu matrix has to be up to date
954!> \par History
955!> 08.2004 created [ Joost VandeVondele ]
956!> 12.2024 Rewrite to use only real matrices [Ole Schuett]
957! **************************************************************************************************
958 SUBROUTINE qs_ot_rot_mat_derivative(qs_ot_env)
959 TYPE(qs_ot_type) :: qs_ot_env
960
961 CHARACTER(len=*), PARAMETER :: routinen = 'qs_ot_rot_mat_derivative'
962
963 INTEGER :: col, handle, i, iblock, j, k, max_blocks, nblocks, row
964 INTEGER, ALLOCATABLE, DIMENSION(:) :: cols, rows
965 INTEGER, DIMENSION(:), POINTER :: col_blk_offset, col_blk_size, row_blk_offset, row_blk_size
966 REAL(kind=dp) :: e1, e2
967 TYPE(dbcsr_type) :: outer_deriv_re, outer_deriv_im, mat_buf, &
968 inner_deriv_re, inner_deriv_im
969 TYPE(dbcsr_distribution_type) :: dist
970 TYPE(dbcsr_iterator_type) :: iter
971 REAL(dp), DIMENSION(:, :), POINTER :: block_in_re, block_in_im, block_out_re, block_out_im
972 LOGICAL :: duplicate, found_in_im, found_in_re, found_out_im, &
973 found_out_re
974 REAL(kind=dp) :: im_part, re_part
975 COMPLEX(dp) :: cval_in, cval_out
976 CALL timeset(routinen, handle)
977
978 CALL dbcsr_get_info(qs_ot_env%rot_mat_u, nfullrows_total=k)
979 IF (k /= 0) THEN
980 CALL dbcsr_copy(qs_ot_env%matrix_buf1, qs_ot_env%rot_mat_dedu)
981 ! now we get to the derivative wrt the antisymmetric matrix rot_mat_x
982 CALL dbcsr_copy(mat_buf, qs_ot_env%rot_mat_dedu, "mat_buf")
983
984 ! inner_deriv_ij = <rot_mat_evec_i| rot_mat_dedu |rot_mat_evec_j>
985 CALL dbcsr_copy(inner_deriv_re, qs_ot_env%rot_mat_dedu, "inner_deriv_re") ! TODO just create
986 CALL dbcsr_copy(inner_deriv_im, qs_ot_env%rot_mat_dedu, "inner_deriv_im") ! TODO just create
987
988 CALL dbcsr_multiply('T', 'N', +1.0_dp, qs_ot_env%rot_mat_dedu, qs_ot_env%rot_mat_evec_im, 0.0_dp, mat_buf)
989 CALL dbcsr_multiply('T', 'N', +1.0_dp, qs_ot_env%rot_mat_evec_im, mat_buf, 0.0_dp, inner_deriv_re)
990 CALL dbcsr_multiply('T', 'N', +1.0_dp, qs_ot_env%rot_mat_evec_re, mat_buf, 0.0_dp, inner_deriv_im)
991
992 CALL dbcsr_multiply('T', 'N', +1.0_dp, qs_ot_env%rot_mat_dedu, qs_ot_env%rot_mat_evec_re, 0.0_dp, mat_buf)
993 CALL dbcsr_multiply('T', 'N', +1.0_dp, qs_ot_env%rot_mat_evec_re, mat_buf, 1.0_dp, inner_deriv_re)
994 CALL dbcsr_multiply('T', 'N', -1.0_dp, qs_ot_env%rot_mat_evec_im, mat_buf, 1.0_dp, inner_deriv_im)
995
996 ! Real and imaginary products can have different sparse block patterns.
997 ! Form their union explicitly and treat a missing partner block as zero.
998 max_blocks = 0
999 CALL dbcsr_iterator_start(iter, inner_deriv_re)
1000 DO WHILE (dbcsr_iterator_blocks_left(iter))
1001 CALL dbcsr_iterator_next_block(iter, row, col)
1002 max_blocks = max_blocks + 1
1003 END DO
1004 CALL dbcsr_iterator_stop(iter)
1005 CALL dbcsr_iterator_start(iter, inner_deriv_im)
1006 DO WHILE (dbcsr_iterator_blocks_left(iter))
1007 CALL dbcsr_iterator_next_block(iter, row, col)
1008 max_blocks = max_blocks + 1
1009 END DO
1010 CALL dbcsr_iterator_stop(iter)
1011
1012 ALLOCATE (rows(max(max_blocks, 1)), cols(max(max_blocks, 1)))
1013 nblocks = 0
1014 CALL dbcsr_iterator_start(iter, inner_deriv_re)
1015 DO WHILE (dbcsr_iterator_blocks_left(iter))
1016 CALL dbcsr_iterator_next_block(iter, row, col)
1017 duplicate = .false.
1018 DO iblock = 1, nblocks
1019 duplicate = duplicate .OR. (rows(iblock) == row .AND. cols(iblock) == col)
1020 END DO
1021 IF (.NOT. duplicate) THEN
1022 nblocks = nblocks + 1
1023 rows(nblocks) = row
1024 cols(nblocks) = col
1025 END IF
1026 END DO
1027 CALL dbcsr_iterator_stop(iter)
1028 CALL dbcsr_iterator_start(iter, inner_deriv_im)
1029 DO WHILE (dbcsr_iterator_blocks_left(iter))
1030 CALL dbcsr_iterator_next_block(iter, row, col)
1031 duplicate = .false.
1032 DO iblock = 1, nblocks
1033 duplicate = duplicate .OR. (rows(iblock) == row .AND. cols(iblock) == col)
1034 END DO
1035 IF (.NOT. duplicate) THEN
1036 nblocks = nblocks + 1
1037 rows(nblocks) = row
1038 cols(nblocks) = col
1039 END IF
1040 END DO
1041 CALL dbcsr_iterator_stop(iter)
1042
1043 CALL dbcsr_get_info(inner_deriv_re, distribution=dist, row_blk_size=row_blk_size, &
1044 col_blk_size=col_blk_size)
1045 CALL dbcsr_create(outer_deriv_re, "outer_deriv_re", dist, dbcsr_type_no_symmetry, &
1046 row_blk_size, col_blk_size)
1047 CALL dbcsr_create(outer_deriv_im, "outer_deriv_im", dist, dbcsr_type_no_symmetry, &
1048 row_blk_size, col_blk_size)
1049 IF (nblocks > 0) THEN
1050 CALL dbcsr_reserve_blocks(outer_deriv_re, rows=rows(1:nblocks), cols=cols(1:nblocks))
1051 CALL dbcsr_reserve_blocks(outer_deriv_im, rows=rows(1:nblocks), cols=cols(1:nblocks))
1052 END IF
1053 CALL dbcsr_finalize(outer_deriv_re)
1054 CALL dbcsr_finalize(outer_deriv_im)
1055 CALL dbcsr_set(outer_deriv_re, 0.0_dp)
1056 CALL dbcsr_set(outer_deriv_im, 0.0_dp)
1057
1058 CALL dbcsr_get_info(outer_deriv_re, row_blk_offset=row_blk_offset, col_blk_offset=col_blk_offset)
1059 CALL dbcsr_iterator_start(iter, outer_deriv_re)
1060 DO WHILE (dbcsr_iterator_blocks_left(iter))
1061 CALL dbcsr_iterator_next_block(iter, row, col)
1062 CALL dbcsr_get_block_p(inner_deriv_re, row, col, block_in_re, found_in_re)
1063 CALL dbcsr_get_block_p(inner_deriv_im, row, col, block_in_im, found_in_im)
1064 CALL dbcsr_get_block_p(outer_deriv_re, row, col, block_out_re, found_out_re)
1065 CALL dbcsr_get_block_p(outer_deriv_im, row, col, block_out_im, found_out_im)
1066 cpassert(found_out_re .AND. found_out_im)
1067
1068 DO i = 1, SIZE(block_out_re, 1)
1069 DO j = 1, SIZE(block_out_re, 2)
1070 e1 = qs_ot_env%rot_mat_evals(row_blk_offset(row) + i - 1)
1071 e2 = qs_ot_env%rot_mat_evals(col_blk_offset(col) + j - 1)
1072 re_part = 0.0_dp
1073 im_part = 0.0_dp
1074 IF (found_in_re) re_part = block_in_re(i, j)
1075 IF (found_in_im) im_part = block_in_im(i, j)
1076 cval_in = cmplx(re_part, im_part, dp)
1077 cval_out = cval_in*cint(e1, e2)
1078 block_out_re(i, j) = real(cval_out)
1079 block_out_im(i, j) = aimag(cval_out)
1080 END DO
1081 END DO
1082 END DO
1083 CALL dbcsr_iterator_stop(iter)
1084 DEALLOCATE (rows, cols)
1085 CALL dbcsr_release(inner_deriv_re)
1086 CALL dbcsr_release(inner_deriv_im)
1087
1088 ! Compute: matrix_buf1 = \sum_i outer_deriv_ij * |rot_mat_evec_i> <rot_mat_evec_j|
1089 CALL dbcsr_multiply('N', 'N', +1.0_dp, qs_ot_env%rot_mat_evec_re, outer_deriv_re, 0.0_dp, mat_buf)
1090 CALL dbcsr_multiply('N', 'N', -1.0_dp, qs_ot_env%rot_mat_evec_im, outer_deriv_im, 1.0_dp, mat_buf)
1091 CALL dbcsr_multiply('N', 'T', +1.0_dp, mat_buf, qs_ot_env%rot_mat_evec_re, 0.0_dp, qs_ot_env%matrix_buf1)
1092
1093 CALL dbcsr_multiply('N', 'N', +1.0_dp, qs_ot_env%rot_mat_evec_re, outer_deriv_im, 0.0_dp, mat_buf)
1094 CALL dbcsr_multiply('N', 'N', +1.0_dp, qs_ot_env%rot_mat_evec_im, outer_deriv_re, 1.0_dp, mat_buf)
1095 CALL dbcsr_multiply('N', 'T', +1.0_dp, mat_buf, qs_ot_env%rot_mat_evec_im, 1.0_dp, qs_ot_env%matrix_buf1)
1096
1097 ! Account for anti-symmetry of rot_mat_x without relying on
1098 ! STRICT-only matrix buffers. REF uses the same finite chart.
1099 CALL qs_ot_square_transpose(qs_ot_env%matrix_buf1, mat_buf, qs_ot_env%rot_mat_u)
1100 CALL dbcsr_copy(qs_ot_env%rot_mat_gx, mat_buf)
1101 CALL dbcsr_add(qs_ot_env%rot_mat_gx, qs_ot_env%matrix_buf1, &
1102 alpha_scalar=1.0_dp, beta_scalar=-1.0_dp)
1103
1104 CALL dbcsr_release(mat_buf)
1105 CALL dbcsr_release(outer_deriv_re)
1106 CALL dbcsr_release(outer_deriv_im)
1107 END IF
1108 CALL timestop(handle)
1109 CONTAINS
1110
1111! **************************************************************************************************
1112!> \brief ...
1113!> \param e1 ...
1114!> \param e2 ...
1115!> \return ...
1116! **************************************************************************************************
1117 FUNCTION cint(e1, e2)
1118 REAL(kind=dp) :: e1, e2
1119 COMPLEX(KIND=dp) :: cint
1120
1121 COMPLEX(KIND=dp) :: l1, l2, x
1122 INTEGER :: i
1123
1124 l1 = (0.0_dp, -1.0_dp)*e1
1125 l2 = (0.0_dp, -1.0_dp)*e2
1126 IF (abs(l1 - l2) > 0.5_dp) THEN
1127 cint = (exp(l1) - exp(l2))/(l1 - l2)
1128 ELSE
1129 x = 1.0_dp
1130 cint = 0.0_dp
1131 DO i = 1, 16
1132 cint = cint + x
1133 x = x*(l1 - l2)/real(i + 1, kind=dp)
1134 END DO
1135 cint = cint*exp(l2)
1136 END IF
1137 END FUNCTION cint
1138 END SUBROUTINE qs_ot_rot_mat_derivative
1139
1140! **************************************************************************************************
1141!> \brief decide strategy
1142!> tries to decide if the taylor expansion of cos(sqrt(xsx)) converges rapidly enough
1143!> to make a taylor expansion of the functions cos(sqrt(xsx)) and sin(sqrt(xsx))/sqrt(xsx)
1144!> and their derivatives faster than their computation based on diagonalization since xsx can
1145!> be very small, especially during dynamics, only a few terms might indeed be needed we find
1146!> the necessary order N to have largest_eval_upper_bound**(N+1)/(2(N+1))! < eps_taylor
1147!> \param qs_ot_env ...
1148! **************************************************************************************************
1149 SUBROUTINE decide_strategy(qs_ot_env)
1150 TYPE(qs_ot_type) :: qs_ot_env
1151
1152 INTEGER :: n
1153 REAL(kind=dp) :: num_error
1154
1155 qs_ot_env%do_taylor = .false.
1156 n = 0
1157 num_error = qs_ot_env%largest_eval_upper_bound/(2.0_dp)
1158 DO WHILE (num_error > qs_ot_env%settings%eps_taylor .AND. n <= qs_ot_env%settings%max_taylor)
1159 n = n + 1
1160 num_error = num_error*qs_ot_env%largest_eval_upper_bound/real((2*n + 1)*(2*n + 2), kind=dp)
1161 END DO
1162 ! An O(P) matrix-function term can be below eps_taylor while its O(X)
1163 ! orbital derivative is still needed near P=X^T*S*X=0.
1164 qs_ot_env%taylor_order = max(1, n)
1165 IF (qs_ot_env%taylor_order <= qs_ot_env%settings%max_taylor) THEN
1166 qs_ot_env%do_taylor = .true.
1167 END IF
1168
1169 END SUBROUTINE decide_strategy
1170
1171! **************************************************************************************************
1172!> \brief c=(c0*cos(p^0.5)+x*sin(p^0.5)*p^(-0.5)) x rot_mat_u
1173!> this assumes that x is already ortho to S*C0, and that p is x*S*x
1174!> rot_mat_u is an optional rotation matrix
1175!> \param matrix_c ...
1176!> \param matrix_x ...
1177!> \param qs_ot_env ...
1178! **************************************************************************************************
1179 SUBROUTINE qs_ot_get_orbitals(matrix_c, matrix_x, qs_ot_env)
1180
1181 TYPE(dbcsr_type), POINTER :: matrix_c, matrix_x
1182 TYPE(qs_ot_type) :: qs_ot_env
1183
1184 CHARACTER(len=*), PARAMETER :: routinen = 'qs_ot_get_orbitals'
1185 REAL(kind=dp), PARAMETER :: rone = 1.0_dp, rzero = 0.0_dp
1186
1187 INTEGER :: handle, k, n
1188 TYPE(dbcsr_type), POINTER :: matrix_kk
1189
1190 CALL timeset(routinen, handle)
1191
1192 CALL dbcsr_get_info(matrix_x, nfullrows_total=n, nfullcols_total=k)
1193
1194 ! rotate the multiplying matrices cosp and sinp instead of the result,
1195 ! this should be cheaper for large basis sets
1196 IF (qs_ot_env%settings%do_rotation) THEN
1197 matrix_kk => qs_ot_env%matrix_buf1
1198 CALL dbcsr_multiply('N', 'N', rone, qs_ot_env%matrix_cosp, &
1199 qs_ot_env%rot_mat_u, rzero, matrix_kk)
1200 ELSE
1201 matrix_kk => qs_ot_env%matrix_cosp
1202 END IF
1203
1204 CALL dbcsr_multiply('N', 'N', rone, qs_ot_env%matrix_c0, matrix_kk, &
1205 rzero, matrix_c)
1206
1207 IF (qs_ot_env%settings%do_rotation) THEN
1208 matrix_kk => qs_ot_env%matrix_buf1
1209 CALL dbcsr_multiply('N', 'N', rone, qs_ot_env%matrix_sinp, &
1210 qs_ot_env%rot_mat_u, rzero, matrix_kk)
1211 ELSE
1212 matrix_kk => qs_ot_env%matrix_sinp
1213 END IF
1214 CALL dbcsr_multiply('N', 'N', rone, matrix_x, matrix_kk, &
1215 rone, matrix_c)
1216
1217 CALL timestop(handle)
1218
1219 END SUBROUTINE qs_ot_get_orbitals
1220
1221! **************************************************************************************************
1222!> \brief this routines computes dE/dx=dx, with dx ortho to sc0
1223!> needs dE/dC=hc,C0,X,SX,p
1224!> if preconditioned it will not be the derivative, but the lagrangian multiplier
1225!> is changed so that P*dE/dx is the right derivative (i.e. in the allowed subspace)
1226!> \param matrix_hc ...
1227!> \param matrix_x ...
1228!> \param matrix_sx ...
1229!> \param matrix_gx ...
1230!> \param qs_ot_env ...
1231! **************************************************************************************************
1232 SUBROUTINE qs_ot_get_derivative(matrix_hc, matrix_x, matrix_sx, matrix_gx, &
1233 qs_ot_env)
1234 TYPE(dbcsr_type), POINTER :: matrix_hc, matrix_x, matrix_sx, matrix_gx
1235 TYPE(qs_ot_type) :: qs_ot_env
1236
1237 CHARACTER(len=*), PARAMETER :: routinen = 'qs_ot_get_derivative'
1238 REAL(kind=dp), PARAMETER :: rone = 1.0_dp, rzero = 0.0_dp
1239
1240 INTEGER :: handle
1241 TYPE(dbcsr_type), POINTER :: matrix_hc_local
1242
1243 CALL timeset(routinen, handle)
1244
1245 NULLIFY (matrix_hc_local)
1246
1247 ! could in principle be taken inside qs_ot_get_derivative_* for increased efficiency
1248 ! create a local rotated version of matrix_hc leaving matrix_hc untouched (needed
1249 ! for lagrangian multipliers)
1250 IF (qs_ot_env%settings%do_rotation) THEN
1251 CALL dbcsr_copy(matrix_gx, matrix_hc) ! use gx as temporary
1252 CALL dbcsr_init_p(matrix_hc_local)
1253 CALL dbcsr_copy(matrix_hc_local, matrix_hc, name='matrix_hc_local')
1254 CALL dbcsr_set(matrix_hc_local, 0.0_dp)
1255 CALL dbcsr_multiply('N', 'T', rone, matrix_gx, qs_ot_env%rot_mat_u, rzero, matrix_hc_local)
1256 ELSE
1257 matrix_hc_local => matrix_hc
1258 END IF
1259
1260 IF (qs_ot_env%do_taylor) THEN
1261 CALL qs_ot_get_derivative_taylor(matrix_hc_local, matrix_x, matrix_sx, matrix_gx, qs_ot_env)
1262 ELSE
1263 CALL qs_ot_get_derivative_diag(matrix_hc_local, matrix_x, matrix_sx, matrix_gx, qs_ot_env)
1264 END IF
1265
1266 CALL qs_ot_project_gradient(qs_ot_env, matrix_gx)
1267 ! also treat the rot_mat gradient here
1268 IF (qs_ot_env%settings%do_rotation) THEN
1269 CALL qs_ot_rot_mat_derivative(qs_ot_env)
1270 END IF
1271
1272 IF (qs_ot_env%settings%do_rotation) THEN
1273 CALL dbcsr_release_p(matrix_hc_local)
1274 END IF
1275
1276 CALL timestop(handle)
1277
1278 END SUBROUTINE qs_ot_get_derivative
1279
1280! **************************************************************************************************
1281!> \brief Project a real STRICT gradient, or an identity-metric fallback direction.
1282!> \param qs_ot_env OT channel state
1283!> \param matrix_gx real component to project in place
1284!> \param use_preconditioner use the attached preconditioner, default true
1285! **************************************************************************************************
1286 SUBROUTINE qs_ot_project_gradient(qs_ot_env, matrix_gx, use_preconditioner)
1287 TYPE(qs_ot_type) :: qs_ot_env
1288 TYPE(dbcsr_type), POINTER :: matrix_gx
1289 LOGICAL, INTENT(IN), OPTIONAL :: use_preconditioner
1290
1291 REAL(kind=dp), PARAMETER :: rone = 1.0_dp, rzero = 0.0_dp
1292
1293 LOGICAL :: preconditioned
1294 TYPE(dbcsr_type), POINTER :: target_re
1295
1296 preconditioned = .true.
1297 IF (PRESENT(use_preconditioner)) preconditioned = use_preconditioner
1298 IF (.NOT. preconditioned) qs_ot_env%os_valid = .false.
1299 IF (preconditioned .AND. ASSOCIATED(qs_ot_env%preconditioner)) THEN
1300 target_re => qs_ot_env%matrix_psc0
1301 ELSE
1302 target_re => qs_ot_env%matrix_sc0
1303 END IF
1304 ! first make the matrix os if not yet valid
1305 IF (.NOT. qs_ot_env%os_valid) THEN
1306 ! this assumes that the preconditioner is a single matrix
1307 ! that maps sc0 onto psc0
1308
1309 IF (preconditioned .AND. ASSOCIATED(qs_ot_env%preconditioner)) THEN
1310 CALL apply_preconditioner(qs_ot_env%preconditioner, qs_ot_env%matrix_sc0, &
1311 qs_ot_env%matrix_psc0)
1312 END IF
1313 CALL dbcsr_multiply('T', 'N', rone, &
1314 qs_ot_env%matrix_sc0, target_re, &
1315 rzero, qs_ot_env%matrix_os)
1316 CALL cp_dbcsr_cholesky_decompose(qs_ot_env%matrix_os, &
1317 para_env=qs_ot_env%para_env, blacs_env=qs_ot_env%blacs_env)
1318 CALL cp_dbcsr_cholesky_invert(qs_ot_env%matrix_os, &
1319 para_env=qs_ot_env%para_env, blacs_env=qs_ot_env%blacs_env, &
1320 uplo_to_full=.true.)
1321 qs_ot_env%os_valid = preconditioned
1322 END IF
1323 CALL dbcsr_multiply('T', 'N', rone, target_re, matrix_gx, &
1324 rzero, qs_ot_env%matrix_buf1_ortho)
1325 CALL dbcsr_multiply('N', 'N', rone, qs_ot_env%matrix_os, &
1326 qs_ot_env%matrix_buf1_ortho, rzero, qs_ot_env%matrix_buf2_ortho)
1327 CALL dbcsr_multiply('N', 'N', -rone, qs_ot_env%matrix_sc0, &
1328 qs_ot_env%matrix_buf2_ortho, rone, matrix_gx)
1329
1330 END SUBROUTINE qs_ot_project_gradient
1331
1332! **************************************************************************************************
1333!> \brief ...
1334!> \param matrix_hc ...
1335!> \param matrix_x ...
1336!> \param matrix_sx ...
1337!> \param matrix_gx ...
1338!> \param qs_ot_env ...
1339! **************************************************************************************************
1340 SUBROUTINE qs_ot_get_derivative_diag(matrix_hc, matrix_x, matrix_sx, matrix_gx, &
1341 qs_ot_env)
1342
1343 TYPE(dbcsr_type), POINTER :: matrix_hc, matrix_x, matrix_sx, matrix_gx
1344 TYPE(qs_ot_type) :: qs_ot_env
1345
1346 CHARACTER(len=*), PARAMETER :: routinen = 'qs_ot_get_derivative_diag'
1347 REAL(kind=dp), PARAMETER :: rone = 1.0_dp, rzero = 0.0_dp
1348
1349 INTEGER :: handle, k, n
1350 TYPE(dbcsr_distribution_type) :: dist
1351
1352 CALL timeset(routinen, handle)
1353
1354 CALL dbcsr_get_info(matrix_x, nfullrows_total=n, nfullcols_total=k)
1355
1356 ! go for the derivative now
1357 ! this de/dc*(dX/dx)*sinp
1358 CALL dbcsr_multiply('N', 'N', rone, matrix_hc, qs_ot_env%matrix_sinp, rzero, matrix_gx)
1359 ! overlap hc*x
1360 CALL dbcsr_multiply('T', 'N', rone, matrix_hc, matrix_x, rzero, qs_ot_env%matrix_buf2)
1361 ! get it in the basis of the eigenvectors
1362 CALL dbcsr_multiply('N', 'N', rone, qs_ot_env%matrix_buf2, qs_ot_env%matrix_r, &
1363 rzero, qs_ot_env%matrix_buf1)
1364 CALL dbcsr_multiply('T', 'N', rone, qs_ot_env%matrix_r, qs_ot_env%matrix_buf1, &
1365 rzero, qs_ot_env%matrix_buf2)
1366
1367 ! get the schur product of O_uv*B_uv
1368 CALL dbcsr_hadamard_product(qs_ot_env%matrix_buf2, qs_ot_env%matrix_sinp_b, &
1369 qs_ot_env%matrix_buf3)
1370
1371 ! overlap hc*c0
1372 CALL dbcsr_multiply('T', 'N', rone, matrix_hc, qs_ot_env%matrix_c0, rzero, &
1373 qs_ot_env%matrix_buf2)
1374 ! get it in the basis of the eigenvectors
1375 CALL dbcsr_multiply('N', 'N', rone, qs_ot_env%matrix_buf2, qs_ot_env%matrix_r, &
1376 rzero, qs_ot_env%matrix_buf1)
1377 CALL dbcsr_multiply('T', 'N', rone, qs_ot_env%matrix_r, qs_ot_env%matrix_buf1, &
1378 rzero, qs_ot_env%matrix_buf2)
1379
1380 CALL dbcsr_hadamard_product(qs_ot_env%matrix_buf2, qs_ot_env%matrix_cosp_b, &
1381 qs_ot_env%matrix_buf4)
1382
1383 ! add the two bs and compute b+b^T
1384 CALL dbcsr_add(qs_ot_env%matrix_buf3, qs_ot_env%matrix_buf4, &
1385 alpha_scalar=rone, beta_scalar=rone)
1386
1387 ! get the b in the eigenvector basis
1388 CALL dbcsr_multiply('N', 'T', rone, qs_ot_env%matrix_buf3, qs_ot_env%matrix_r, &
1389 rzero, qs_ot_env%matrix_buf1)
1390 CALL dbcsr_multiply('N', 'N', rone, qs_ot_env%matrix_r, qs_ot_env%matrix_buf1, &
1391 rzero, qs_ot_env%matrix_buf3)
1392 CALL dbcsr_get_info(qs_ot_env%matrix_buf3, distribution=dist)
1393 CALL dbcsr_transposed(qs_ot_env%matrix_buf1, qs_ot_env%matrix_buf3, &
1394 shallow_data_copy=.false., use_distribution=dist, &
1395 transpose_distribution=.false.)
1396 CALL dbcsr_add(qs_ot_env%matrix_buf3, qs_ot_env%matrix_buf1, &
1397 alpha_scalar=rone, beta_scalar=rone)
1398
1399 ! and add to the derivative
1400 CALL dbcsr_multiply('N', 'N', rone, matrix_sx, qs_ot_env%matrix_buf3, &
1401 rone, matrix_gx)
1402 CALL timestop(handle)
1403
1404 END SUBROUTINE qs_ot_get_derivative_diag
1405
1406! **************************************************************************************************
1407!> \brief compute the derivative of the taylor expansion below
1408!> \param matrix_hc ...
1409!> \param matrix_x ...
1410!> \param matrix_sx ...
1411!> \param matrix_gx ...
1412!> \param qs_ot_env ...
1413! **************************************************************************************************
1414 SUBROUTINE qs_ot_get_derivative_taylor(matrix_hc, matrix_x, matrix_sx, matrix_gx, &
1415 qs_ot_env)
1416
1417 TYPE(dbcsr_type), POINTER :: matrix_hc, matrix_x, matrix_sx, matrix_gx
1418 TYPE(qs_ot_type) :: qs_ot_env
1419
1420 CHARACTER(len=*), PARAMETER :: routinen = 'qs_ot_get_derivative_taylor'
1421 REAL(kind=dp), PARAMETER :: rone = 1.0_dp, rzero = 0.0_dp
1422
1423 INTEGER :: handle, i, k, n
1424 REAL(kind=dp) :: cosfactor, sinfactor
1425 TYPE(dbcsr_distribution_type) :: dist
1426 TYPE(dbcsr_type), POINTER :: matrix_left, matrix_right
1427
1428 CALL timeset(routinen, handle)
1429
1430 CALL dbcsr_get_info(matrix_x, nfullrows_total=n, nfullcols_total=k)
1431
1432 ! go for the derivative now
1433 ! this de/dc*(dX/dx)*sinp i.e. zeroth order
1434 CALL dbcsr_multiply('N', 'N', rone, matrix_hc, qs_ot_env%matrix_sinp, rzero, matrix_gx)
1435
1436 IF (qs_ot_env%taylor_order <= 0) THEN
1437 CALL timestop(handle)
1438 RETURN
1439 END IF
1440
1441 ! we store the matrix that will multiply sx in matrix_r
1442 CALL dbcsr_set(qs_ot_env%matrix_r, rzero)
1443
1444 ! just better names for matrix_cosp_b and matrix_sinp_b (they are buffer space here)
1445 matrix_left => qs_ot_env%matrix_cosp_b
1446 matrix_right => qs_ot_env%matrix_sinp_b
1447
1448 ! overlap hc*x and add its transpose to matrix_left
1449 CALL dbcsr_multiply('T', 'N', rone, matrix_hc, matrix_x, rzero, matrix_left)
1450 CALL dbcsr_get_info(matrix_left, distribution=dist)
1451 CALL dbcsr_transposed(qs_ot_env%matrix_buf1, matrix_left, &
1452 shallow_data_copy=.false., use_distribution=dist, &
1453 transpose_distribution=.false.)
1454 CALL dbcsr_add(matrix_left, qs_ot_env%matrix_buf1, &
1455 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
1456 CALL dbcsr_copy(matrix_right, matrix_left)
1457
1458 ! first order
1459 sinfactor = -1.0_dp/(2.0_dp*3.0_dp)
1460 CALL dbcsr_add(qs_ot_env%matrix_r, matrix_left, &
1461 alpha_scalar=1.0_dp, beta_scalar=sinfactor)
1462
1463 ! M
1464 ! OM+MO
1465 ! OOM+OMO+MOO
1466 ! ...
1467 DO i = 2, qs_ot_env%taylor_order
1468 sinfactor = sinfactor*(-1.0_dp)/real(2*i*(2*i + 1), kind=dp)
1469 CALL dbcsr_multiply('N', 'N', rone, qs_ot_env%matrix_p, matrix_left, rzero, qs_ot_env%matrix_buf1)
1470 CALL dbcsr_multiply('N', 'N', rone, matrix_right, qs_ot_env%matrix_p, rzero, matrix_left)
1471 CALL dbcsr_copy(matrix_right, matrix_left)
1472 CALL dbcsr_add(matrix_left, qs_ot_env%matrix_buf1, &
1473 1.0_dp, 1.0_dp)
1474 CALL dbcsr_add(qs_ot_env%matrix_r, matrix_left, &
1475 alpha_scalar=1.0_dp, beta_scalar=sinfactor)
1476 END DO
1477
1478 ! overlap hc*c0 and add its transpose to matrix_left
1479 CALL dbcsr_multiply('T', 'N', rone, matrix_hc, qs_ot_env%matrix_c0, rzero, matrix_left)
1480 CALL dbcsr_get_info(matrix_left, distribution=dist)
1481 CALL dbcsr_transposed(qs_ot_env%matrix_buf1, matrix_left, &
1482 shallow_data_copy=.false., use_distribution=dist, &
1483 transpose_distribution=.false.)
1484 CALL dbcsr_add(matrix_left, qs_ot_env%matrix_buf1, 1.0_dp, 1.0_dp)
1485 CALL dbcsr_copy(matrix_right, matrix_left)
1486
1487 ! first order
1488 cosfactor = -1.0_dp/(1.0_dp*2.0_dp)
1489 CALL dbcsr_add(qs_ot_env%matrix_r, matrix_left, &
1490 alpha_scalar=1.0_dp, beta_scalar=cosfactor)
1491
1492 ! M
1493 ! OM+MO
1494 ! OOM+OMO+MOO
1495 ! ...
1496 DO i = 2, qs_ot_env%taylor_order
1497 cosfactor = cosfactor*(-1.0_dp)/real(2*i*(2*i - 1), kind=dp)
1498 CALL dbcsr_multiply('N', 'N', rone, qs_ot_env%matrix_p, matrix_left, rzero, qs_ot_env%matrix_buf1)
1499 CALL dbcsr_multiply('N', 'N', rone, matrix_right, qs_ot_env%matrix_p, rzero, matrix_left)
1500 CALL dbcsr_copy(matrix_right, matrix_left)
1501 CALL dbcsr_add(matrix_left, qs_ot_env%matrix_buf1, 1.0_dp, 1.0_dp)
1502 CALL dbcsr_add(qs_ot_env%matrix_r, matrix_left, &
1503 alpha_scalar=1.0_dp, beta_scalar=cosfactor)
1504 END DO
1505
1506 ! and add to the derivative
1507 CALL dbcsr_multiply('N', 'N', rone, matrix_sx, qs_ot_env%matrix_r, rone, matrix_gx)
1508
1509 CALL timestop(handle)
1510
1511 END SUBROUTINE qs_ot_get_derivative_taylor
1512
1513! *************************************************************************************************
1514!> \brief computes a taylor expansion.
1515!> \param qs_ot_env ...
1516! **************************************************************************************************
1517 SUBROUTINE qs_ot_p2m_taylor(qs_ot_env)
1518 TYPE(qs_ot_type) :: qs_ot_env
1519
1520 CHARACTER(len=*), PARAMETER :: routinen = 'qs_ot_p2m_taylor'
1521 REAL(kind=dp), PARAMETER :: rone = 1.0_dp, rzero = 0.0_dp
1522
1523 INTEGER :: handle, i, k
1524 REAL(kind=dp) :: cosfactor, sinfactor
1525
1526 CALL timeset(routinen, handle)
1527
1528 ! zeroth order
1529 CALL dbcsr_set(qs_ot_env%matrix_cosp, rzero)
1530 CALL dbcsr_set(qs_ot_env%matrix_sinp, rzero)
1531 CALL dbcsr_add_on_diag(qs_ot_env%matrix_cosp, rone)
1532 CALL dbcsr_add_on_diag(qs_ot_env%matrix_sinp, rone)
1533
1534 IF (qs_ot_env%taylor_order <= 0) THEN
1535 CALL timestop(handle)
1536 RETURN
1537 END IF
1538
1539 ! first order
1540 cosfactor = -1.0_dp/(1.0_dp*2.0_dp)
1541 sinfactor = -1.0_dp/(2.0_dp*3.0_dp)
1542 CALL dbcsr_add(qs_ot_env%matrix_cosp, qs_ot_env%matrix_p, alpha_scalar=1.0_dp, beta_scalar=cosfactor)
1543 CALL dbcsr_add(qs_ot_env%matrix_sinp, qs_ot_env%matrix_p, alpha_scalar=1.0_dp, beta_scalar=sinfactor)
1544 IF (qs_ot_env%taylor_order <= 1) THEN
1545 CALL timestop(handle)
1546 RETURN
1547 END IF
1548
1549 ! other orders
1550 CALL dbcsr_get_info(qs_ot_env%matrix_p, nfullrows_total=k)
1551 CALL dbcsr_copy(qs_ot_env%matrix_r, qs_ot_env%matrix_p)
1552
1553 DO i = 2, qs_ot_env%taylor_order
1554 ! new power of p
1555 CALL dbcsr_multiply('N', 'N', rone, qs_ot_env%matrix_p, qs_ot_env%matrix_r, &
1556 rzero, qs_ot_env%matrix_buf1)
1557 CALL dbcsr_copy(qs_ot_env%matrix_r, qs_ot_env%matrix_buf1)
1558 ! add to the taylor expansion so far
1559 cosfactor = cosfactor*(-1.0_dp)/real(2*i*(2*i - 1), kind=dp)
1560 sinfactor = sinfactor*(-1.0_dp)/real(2*i*(2*i + 1), kind=dp)
1561 CALL dbcsr_add(qs_ot_env%matrix_cosp, qs_ot_env%matrix_r, &
1562 alpha_scalar=1.0_dp, beta_scalar=cosfactor)
1563 CALL dbcsr_add(qs_ot_env%matrix_sinp, qs_ot_env%matrix_r, &
1564 alpha_scalar=1.0_dp, beta_scalar=sinfactor)
1565 END DO
1566
1567 CALL timestop(handle)
1568
1569 END SUBROUTINE qs_ot_p2m_taylor
1570
1571! **************************************************************************************************
1572!> \brief given p, computes - eigenstuff (matrix_r,evals)
1573!> - cos(p^0.5),p^(-0.5)*sin(p^0.5)
1574!> - the real b matrices, needed for the derivatives of these guys
1575!> cosp_b_ij=(1/(2pii) * int(cos(z^1/2)/((z-eval(i))*(z-eval(j))))
1576!> sinp_b_ij=(1/(2pii) * int(z^(-1/2)*sin(z^1/2)/((z-eval(i))*(z-eval(j))))
1577!> \param qs_ot_env ...
1578! **************************************************************************************************
1579 SUBROUTINE qs_ot_p2m_diag(qs_ot_env)
1580 TYPE(qs_ot_type) :: qs_ot_env
1581
1582 CHARACTER(len=*), PARAMETER :: routinen = 'qs_ot_p2m_diag'
1583
1584 INTEGER :: handle, phase
1585 LOGICAL :: cosine
1586 TYPE(dbcsr_type), POINTER :: kernel, matrix, matrix_im
1587
1588 CALL timeset(routinen, handle)
1589 IF (qs_ot_env%has_complex_kpoint_state) THEN
1590 CALL cp_dbcsr_heevd(matrix_re=qs_ot_env%matrix_p, matrix_im=qs_ot_env%matrix_p_im, &
1591 eigenvectors_re=qs_ot_env%matrix_r, eigenvectors_im=qs_ot_env%matrix_r_im, &
1592 eigenvalues=qs_ot_env%evals, para_env=qs_ot_env%para_env, &
1593 blacs_env=qs_ot_env%blacs_env)
1594 ELSE
1595 CALL dbcsr_copy(qs_ot_env%matrix_buf1, qs_ot_env%matrix_p)
1596 CALL cp_dbcsr_syevd(qs_ot_env%matrix_buf1, qs_ot_env%matrix_r, qs_ot_env%evals, &
1597 qs_ot_env%para_env, qs_ot_env%blacs_env)
1598 END IF
1599 qs_ot_env%evals(:) = max(0.0_dp, qs_ot_env%evals(:))
1600 DO phase = 1, 2
1601 cosine = phase == 1
1602 IF (cosine) THEN
1603 matrix => qs_ot_env%matrix_cosp
1604 matrix_im => qs_ot_env%matrix_cosp_im
1605 kernel => qs_ot_env%matrix_cosp_b
1606 ELSE
1607 matrix => qs_ot_env%matrix_sinp
1608 matrix_im => qs_ot_env%matrix_sinp_im
1609 kernel => qs_ot_env%matrix_sinp_b
1610 END IF
1611 CALL qs_ot_spectral_values(qs_ot_env%evals, qs_ot_env%dum, cosine)
1612 CALL dbcsr_copy(qs_ot_env%matrix_buf1, qs_ot_env%matrix_r)
1613 CALL dbcsr_scale_by_vector(qs_ot_env%matrix_buf1, alpha=qs_ot_env%dum, side='right')
1614 IF (qs_ot_env%has_complex_kpoint_state) THEN
1615 CALL dbcsr_copy(qs_ot_env%matrix_buf1_im, qs_ot_env%matrix_r_im)
1616 CALL dbcsr_scale_by_vector(qs_ot_env%matrix_buf1_im, alpha=qs_ot_env%dum, side='right')
1617 CALL qs_ot_complex_multiply('N', 'C', qs_ot_env%matrix_buf1, qs_ot_env%matrix_buf1_im, &
1618 qs_ot_env%matrix_r, qs_ot_env%matrix_r_im, &
1619 matrix, matrix_im, qs_ot_env%matrix_buf2)
1620 ELSE
1621 ! Retain the original real-path operand order.
1622 CALL dbcsr_multiply('N', 'T', 1.0_dp, qs_ot_env%matrix_r, qs_ot_env%matrix_buf1, 0.0_dp, matrix)
1623 END IF
1624 qs_ot_env%dum(:) = sqrt(qs_ot_env%evals(:))
1625 CALL dbcsr_copy(kernel, matrix)
1626 CALL qs_ot_spectral_kernel_dbcsr(qs_ot_env%dum, kernel, cosine)
1627 END DO
1628 CALL timestop(handle)
1629 END SUBROUTINE qs_ot_p2m_diag
1630
1631! **************************************************************************************************
1632!> \brief Evaluate cos(sqrt(P)) or sinc(sqrt(P)) on the nonnegative eigenvalues of P.
1633!> \param evals nonnegative eigenvalues
1634!> \param values function values
1635!> \param cosine select cosine; otherwise sinc
1636! **************************************************************************************************
1637 SUBROUTINE qs_ot_spectral_values(evals, values, cosine)
1638 REAL(dp), INTENT(IN) :: evals(:)
1639 REAL(dp), INTENT(OUT) :: values(:)
1640 LOGICAL, INTENT(IN) :: cosine
1641
1642 INTEGER :: i
1643
1644 IF (cosine) THEN
1645 DO i = 1, SIZE(evals)
1646 values(i) = cos(sqrt(evals(i)))
1647 END DO
1648 ELSE
1649 DO i = 1, SIZE(evals)
1650 values(i) = qs_ot_sinc(sqrt(evals(i)))
1651 END DO
1652 END IF
1653 END SUBROUTINE qs_ot_spectral_values
1654
1655! **************************************************************************************************
1656!> \brief Build a block of the real STRICT Frechet kernel, including coincident eigenvalues.
1657!> \param roots_i square roots of the row eigenvalues
1658!> \param roots_j square roots of the column eigenvalues
1659!> \param block dense output block
1660!> \param cosine select cosine; otherwise sinc
1661! **************************************************************************************************
1662 SUBROUTINE qs_ot_spectral_kernel(roots_i, roots_j, block, cosine)
1663 REAL(dp), INTENT(IN) :: roots_i(:), roots_j(:)
1664 REAL(dp), INTENT(OUT) :: block(:, :)
1665 LOGICAL, INTENT(IN) :: cosine
1666
1667 INTEGER :: i, j
1668 REAL(dp) :: a, b
1669
1670 IF (cosine) THEN
1671 DO j = 1, SIZE(roots_j)
1672 DO i = 1, SIZE(roots_i)
1673 a = (roots_i(i) - roots_j(j))/2.0_dp
1674 b = (roots_i(i) + roots_j(j))/2.0_dp
1675 block(i, j) = -0.5_dp*qs_ot_sinc(a)*qs_ot_sinc(b)
1676 END DO
1677 END DO
1678 ELSE
1679 DO j = 1, SIZE(roots_j)
1680 DO i = 1, SIZE(roots_i)
1681 block(i, j) = qs_ot_sincf(roots_i(i), roots_j(j))
1682 END DO
1683 END DO
1684 END IF
1685 END SUBROUTINE qs_ot_spectral_kernel
1686
1687! **************************************************************************************************
1688!> \brief Fill the existing blocks of a STRICT Frechet kernel with the shared dense formulas.
1689!> \param roots square roots of the eigenvalues
1690!> \param matrix distributed kernel
1691!> \param cosine select cosine; otherwise sinc
1692! **************************************************************************************************
1693 SUBROUTINE qs_ot_spectral_kernel_dbcsr(roots, matrix, cosine)
1694 REAL(dp), INTENT(IN) :: roots(:)
1695 TYPE(dbcsr_type), INTENT(INOUT) :: matrix
1696 LOGICAL, INTENT(IN) :: cosine
1697
1698 INTEGER :: col, nc, nr, row
1699 LOGICAL :: transposed
1700 REAL(dp), POINTER :: block(:, :)
1701 TYPE(dbcsr_iterator_type) :: iter
1702
1703 CALL dbcsr_iterator_start(iter, matrix)
1704 DO WHILE (dbcsr_iterator_blocks_left(iter))
1705 CALL dbcsr_iterator_next_block(iter, block=block, transposed=transposed, &
1706 row_size=nr, col_size=nc, row_offset=row, col_offset=col)
1707 IF (transposed) THEN
1708 CALL qs_ot_spectral_kernel(roots(col:col + nc - 1), roots(row:row + nr - 1), block, cosine)
1709 ELSE
1710 CALL qs_ot_spectral_kernel(roots(row:row + nr - 1), roots(col:col + nc - 1), block, cosine)
1711 END IF
1712 END DO
1713 CALL dbcsr_iterator_stop(iter)
1714 END SUBROUTINE qs_ot_spectral_kernel_dbcsr
1715
1716! **************************************************************************************************
1717!> \brief computes sin(x)/x for all values of the argument
1718!> \param x ...
1719!> \return ...
1720! **************************************************************************************************
1721 FUNCTION qs_ot_sinc(x)
1722
1723 REAL(kind=dp), INTENT(IN) :: x
1724 REAL(kind=dp) :: qs_ot_sinc
1725
1726 REAL(kind=dp), PARAMETER :: q1 = 1.0_dp, q2 = -q1/(2.0_dp*3.0_dp), q3 = -q2/(4.0_dp*5.0_dp), &
1727 q4 = -q3/(6.0_dp*7.0_dp), q5 = -q4/(8.0_dp*9.0_dp), q6 = -q5/(10.0_dp*11.0_dp), &
1728 q7 = -q6/(12.0_dp*13.0_dp), q8 = -q7/(14.0_dp*15.0_dp), q9 = -q8/(16.0_dp*17.0_dp), &
1729 q10 = -q9/(18.0_dp*19.0_dp)
1730
1731 REAL(kind=dp) :: y
1732
1733 IF (abs(x) > 0.5_dp) THEN
1734 qs_ot_sinc = sin(x)/x
1735 ELSE
1736 y = x*x
1737 qs_ot_sinc = q1 + y*(q2 + y*(q3 + y*(q4 + y*(q5 + y*(q6 + y*(q7 + y*(q8 + y*(q9 + y*(q10)))))))))
1738 END IF
1739 END FUNCTION qs_ot_sinc
1740
1741! **************************************************************************************************
1742!> \brief computes (1/(x^2-y^2))*(sinc(x)-sinc(y)) for all positive values of the arguments
1743!> \param xa ...
1744!> \param ya ...
1745!> \return ...
1746! **************************************************************************************************
1747 FUNCTION qs_ot_sincf(xa, ya)
1748
1749 REAL(kind=dp), INTENT(IN) :: xa, ya
1750 REAL(kind=dp) :: qs_ot_sincf
1751
1752 INTEGER :: i
1753 REAL(kind=dp) :: a, b, rs, sf, x, xs, y, ybx, ybxs
1754
1755 ! this is currently a limit of the routine, could be removed rather easily
1756 IF (xa < 0) cpabort("x is negative")
1757 IF (ya < 0) cpabort("y is negative")
1758
1759 IF (xa < ya) THEN
1760 x = ya
1761 y = xa
1762 ELSE
1763 x = xa
1764 y = ya
1765 END IF
1766
1767 IF (x < 0.5_dp) THEN ! use series, keeping in mind that x,y,x+y,x-y can all be zero
1768
1769 qs_ot_sincf = 0.0_dp
1770 IF (x > 0.0_dp) THEN
1771 ybx = y/x
1772 ELSE ! should be irrelevant !?
1773 ybx = 0.0_dp
1774 END IF
1775
1776 sf = -1.0_dp/((1.0_dp + ybx)*6.0_dp)
1777 rs = 1.0_dp
1778 ybxs = ybx
1779 xs = 1.0_dp
1780
1781 DO i = 1, 10
1782 qs_ot_sincf = qs_ot_sincf + sf*rs*xs*(1.0_dp + ybxs)
1783 sf = -sf/(real((2*i + 2), dp)*real((2*i + 3), dp))
1784 rs = rs + ybxs
1785 ybxs = ybxs*ybx
1786 xs = xs*x*x
1787 END DO
1788
1789 ELSE ! no series expansion
1790 IF (x - y > 0.1_dp) THEN ! safe to use the normal form
1791 qs_ot_sincf = (qs_ot_sinc(x) - qs_ot_sinc(y))/((x + y)*(x - y))
1792 ELSE
1793 a = (x + y)/2.0_dp
1794 b = (x - y)/2.0_dp ! might be close to zero
1795 ! y (=(a-b)) can not be close to zero since it is close to x>0.5
1796 qs_ot_sincf = (qs_ot_sinc(b)*cos(a) - qs_ot_sinc(a)*cos(b))/(2*x*y)
1797 END IF
1798 END IF
1799
1800 END FUNCTION qs_ot_sincf
1801
1802END MODULE qs_ot
arnoldi iteration using dbcsr
Definition arnoldi_api.F:16
subroutine, public arnoldi_extremal(matrix_a, max_ev, min_ev, converged, threshold, max_iter)
simple wrapper to estimate extremal eigenvalues with arnoldi, using the old lanczos interface this hi...
subroutine, public dbcsr_transposed(transposed, normal, shallow_data_copy, transpose_distribution, use_distribution)
...
subroutine, public dbcsr_release_p(matrix)
...
subroutine, public dbcsr_scale(matrix, alpha_scalar)
...
logical function, public dbcsr_iterator_blocks_left(iterator)
...
subroutine, public dbcsr_iterator_stop(iterator)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_get_block_p(matrix, row, col, block, found, row_size, col_size)
...
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_reserve_blocks(matrix, rows, cols)
...
subroutine, public dbcsr_init_p(matrix)
...
subroutine, public dbcsr_iterator_next_block(iterator, row, column, block, block_number_argument_has_been_removed, row_size, col_size, row_offset, col_offset, transposed)
...
subroutine, public dbcsr_filter(matrix, eps)
...
real(kind=dp) function, public dbcsr_get_occupation(matrix)
...
subroutine, public dbcsr_finalize(matrix)
...
subroutine, public dbcsr_iterator_start(iterator, matrix, shared, dynamic, dynamic_byrows)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
Interface to (sca)lapack for the Cholesky based procedures.
subroutine, public cp_dbcsr_cholesky_decompose(matrix, n, para_env, blacs_env)
used to replace a symmetric positive def. matrix M with its cholesky decomposition U: M = U^T * U,...
subroutine, public cp_dbcsr_cholesky_restore(matrix, neig, matrixb, matrixout, op, pos, transa, para_env, blacs_env)
...
subroutine, public cp_dbcsr_cholesky_invert(matrix, n, para_env, blacs_env, uplo_to_full)
used to replace the cholesky decomposition by the inverse
real(dp) function, public dbcsr_gershgorin_norm(matrix)
Compute the gershgorin norm 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.
real(dp) function, public dbcsr_frobenius_norm(matrix)
Compute the frobenius norm of a dbcsr matrix.
subroutine, public dbcsr_hadamard_product(matrix_a, matrix_b, matrix_c)
Hadamard product: C = A . B (C needs to be different from A and B).
subroutine, public dbcsr_scale_by_vector(matrix, alpha, side)
Scales the rows/columns of given matrix.
Interface to (sca)lapack for the Cholesky based procedures.
subroutine, public cp_dbcsr_heevd(matrix_re, matrix_im, eigenvectors_re, eigenvectors_im, eigenvalues, para_env, blacs_env)
...
subroutine, public cp_dbcsr_syevd(matrix, eigenvectors, eigenvalues, para_env, blacs_env)
...
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Interface to the message passing library MPI.
types of preconditioners
computes preconditioners, and implements methods to apply them currently used in qs_ot
orbital transformations
Definition qs_ot_types.F:15
orbital transformations
Definition qs_ot.F:15
subroutine, public qs_ot_complex_multiply(op_a, op_b, a_re, a_im, b_re, b_im, c_re, c_im, tmp)
multiply paired real/imaginary DBCSR matrices, with optional conjugate transposes
Definition qs_ot.F:130
subroutine, public qs_ot_get_p(matrix_x, matrix_sx, qs_ot_env)
computes p=x*S*x and the matrix functionals related matrices
Definition qs_ot.F:844
logical function, public qs_ot_ref_update(qs_ot_env1)
...
Definition qs_ot.F:523
subroutine, public qs_ot_spectral_kernel(roots_i, roots_j, block, cosine)
Build a block of the real STRICT Frechet kernel, including coincident eigenvalues.
Definition qs_ot.F:1663
subroutine, public qs_ot_spectral_values(evals, values, cosine)
Evaluate cos(sqrt(P)) or sinc(sqrt(P)) on the nonnegative eigenvalues of P.
Definition qs_ot.F:1638
subroutine, public qs_ot_square_transpose(matrix, transposed, identity_template)
Transpose a square DBCSR matrix while retaining its target distribution.
Definition qs_ot.F:824
subroutine, public qs_ot_p2m_diag(qs_ot_env)
given p, computes - eigenstuff (matrix_r,evals)
Definition qs_ot.F:1580
subroutine, public qs_ot_get_derivative_ref(matrix_hc, matrix_x, matrix_sx, matrix_gx, qs_ot_env)
...
Definition qs_ot.F:767
subroutine, public qs_ot_get_orbitals(matrix_c, matrix_x, qs_ot_env)
c=(c0*cos(p^0.5)+x*sin(p^0.5)*p^(-0.5)) x rot_mat_u this assumes that x is already ortho to S*C0,...
Definition qs_ot.F:1180
subroutine, public qs_ot_rot_mat_derivative(qs_ot_env)
computes the derivative fields with respect to rot_mat_x
Definition qs_ot.F:959
subroutine, public qs_ot_get_orbitals_ref(matrix_c, matrix_s, matrix_x, matrix_sx, matrix_gx_old, matrix_dx, qs_ot_env, qs_ot_env1)
...
Definition qs_ot.F:575
subroutine, public qs_ot_get_derivative(matrix_hc, matrix_x, matrix_sx, matrix_gx, qs_ot_env)
this routines computes dE/dx=dx, with dx ortho to sc0 needs dE/dC=hc,C0,X,SX,p if preconditioned it w...
Definition qs_ot.F:1234
subroutine, public qs_ot_new_preconditioner(qs_ot_env, preconditioner)
gets ready to use the preconditioner/ or renew the preconditioner only keeps a pointer to the precond...
Definition qs_ot.F:74
subroutine, public qs_ot_generate_rotation(qs_ot_env)
computes the rotation matrix rot_mat_u that is associated to a given rot_mat_x using rot_mat_u=exp(ro...
Definition qs_ot.F:894
subroutine, public qs_ot_project_gradient(qs_ot_env, matrix_gx, use_preconditioner)
Project a real STRICT gradient, or an identity-metric fallback direction.
Definition qs_ot.F:1287