20 fm_pools_create_fm_vect,&
21 fm_pools_give_back_fm_vect
35 USE dbcsr_api,
ONLY: dbcsr_p_type,&
55 #include "./base/base_uses.f90"
59 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_tddfpt_eigensolver'
75 TYPE(qs_p_env_type) :: p_env
76 TYPE(qs_environment_type),
POINTER :: qs_env
79 CHARACTER(len=*),
PARAMETER :: routinen =
'eigensolver'
81 INTEGER :: handle, n_ev, nspins, output_unit, &
83 LOGICAL :: do_kernel_save
84 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: ievals
85 TYPE(dft_control_type),
POINTER :: dft_control
87 CALL timeset(routinen, handle)
93 CALL get_qs_env(qs_env, dft_control=dft_control)
94 n_ev = dft_control%tddfpt_control%n_ev
95 nspins = dft_control%nspins
97 ALLOCATE (ievals(n_ev))
102 do_kernel_save = dft_control%tddfpt_control%do_kernel
103 dft_control%tddfpt_control%do_kernel = .false.
104 IF (output_unit > 0)
THEN
105 WRITE (output_unit, *)
" Generating initial guess"
106 WRITE (output_unit, *)
108 IF (
ASSOCIATED(dft_control%tddfpt_control%lumos))
THEN
111 IF (output_unit > 0)
WRITE (output_unit, *)
"LUMOS are needed in TDDFPT!"
114 DO restarts = 1, dft_control%tddfpt_control%n_restarts
115 IF (iterative_solver(ievals, t_env, p_env, qs_env, ievals))
EXIT
116 IF (output_unit > 0)
THEN
117 WRITE (output_unit, *)
" Restarting"
118 WRITE (output_unit, *)
121 dft_control%tddfpt_control%do_kernel = do_kernel_save
126 IF (output_unit > 0)
THEN
127 WRITE (output_unit, *)
128 WRITE (output_unit, *)
" Doing TDDFPT calculation"
129 WRITE (output_unit, *)
131 DO restarts = 1, dft_control%tddfpt_control%n_restarts
132 IF (iterative_solver(ievals, t_env, p_env, qs_env, t_env%evals))
EXIT
133 IF (output_unit > 0)
THEN
134 WRITE (output_unit, *)
" Restarting"
135 WRITE (output_unit, *)
144 CALL timestop(handle)
166 FUNCTION iterative_solver(in_evals, &
167 t_env, p_env, qs_env, &
168 out_evals)
RESULT(res)
170 REAL(kind=
dp),
DIMENSION(:) :: in_evals
172 TYPE(qs_p_env_type) :: p_env
173 TYPE(qs_environment_type),
POINTER :: qs_env
174 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL :: out_evals
177 CHARACTER(len=*),
PARAMETER :: routinen =
'iterative_solver', &
178 routinep = modulen//
':'//routinen
181 INTEGER :: col, handle, i, iev, iter, j, k, &
182 max_krylovspace_dim, max_kv, n_ev, &
183 n_kv, nspins, output_unit, row, spin
184 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: must_improve
185 REAL(
dp) :: atilde_ij, convergence, tmp, tmp2
186 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: evals_difference, evals_tmp
187 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: evals
188 TYPE(cp_blacs_env_type),
POINTER :: blacs_env
189 TYPE(cp_fm_pool_p_type),
DIMENSION(:),
POINTER :: ao_mo_fm_pools
190 TYPE(cp_fm_struct_p_type),
ALLOCATABLE, &
191 DIMENSION(:) :: kv_fm_struct
192 TYPE(cp_fm_struct_type),
POINTER :: tilde_fm_struct
193 TYPE(cp_fm_type) :: atilde, us
194 TYPE(cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: r, x
195 TYPE(cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: ab, b, sb
196 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s
197 TYPE(dft_control_type),
POINTER :: dft_control
198 TYPE(mp_para_env_type),
POINTER :: para_env
199 TYPE(tddfpt_control_type),
POINTER :: tddfpt_control
203 CALL timeset(routinen, handle)
205 NULLIFY (ao_mo_fm_pools, tddfpt_control, &
206 tilde_fm_struct, matrix_s, dft_control, &
211 dft_control=dft_control, &
215 tddfpt_control => dft_control%tddfpt_control
217 n_ev = tddfpt_control%n_ev
218 nspins = dft_control%nspins
220 IF (dft_control%tddfpt_control%diag_method ==
tddfpt_lanczos)
THEN
222 ELSE IF (dft_control%tddfpt_control%diag_method ==
tddfpt_davidson)
THEN
230 max_krylovspace_dim = sum(p_env%n_ao(1:nspins)*p_env%n_mo(1:nspins))
231 max_kv = tddfpt_control%max_kv
232 IF (max_krylovspace_dim <= max_kv)
THEN
233 max_kv = max_krylovspace_dim
234 IF (output_unit > 0)
THEN
235 WRITE (output_unit, *)
" Setting the maximum number of krylov vectors to ", max_kv,
"!!"
242 CALL mpools_get(qs_env%mpools, ao_mo_fm_pools=ao_mo_fm_pools)
243 CALL fm_pools_create_fm_vect(ao_mo_fm_pools, x, name=routinep//
":X")
244 CALL fm_pools_create_fm_vect(ao_mo_fm_pools, r, name=routinep//
":R")
246 ALLOCATE (evals_difference(n_ev))
248 ALLOCATE (must_improve(n_ev))
250 ALLOCATE (evals(max_kv, 0:max_kv))
251 ALLOCATE (evals_tmp(max_kv))
253 ALLOCATE (b(max_kv, nspins), ab(max_kv, nspins), &
256 ALLOCATE (kv_fm_struct(nspins))
260 p_env%n_ao(spin), p_env%n_mo(spin))
263 IF (output_unit > 0)
THEN
264 WRITE (output_unit,
'(2X,A,T69,A)') &
265 "nvec",
"Convergence"
266 WRITE (output_unit,
'(2X,A)') &
267 "-----------------------------------------------------------------------------"
275 CALL allocate_krylov_vectors(b,
"b-", k + 1, n_kv, nspins, kv_fm_struct)
276 CALL allocate_krylov_vectors(ab,
"Ab-", k + 1, n_kv, nspins, kv_fm_struct)
277 CALL allocate_krylov_vectors(sb,
"Sb-", k + 1, n_kv, nspins, kv_fm_struct)
282 IF (k <=
SIZE(t_env%evecs, 1))
THEN
286 CALL cp_fm_to_fm(t_env%evecs(k, spin), b(k, spin))
292 IF (mode ==
'L')
THEN
295 IF (tddfpt_control%invert_S)
THEN
296 CALL cp_fm_symm(
'L',
'U', p_env%n_ao(spin), p_env%n_mo(spin), &
297 1.0_dp, t_env%invS(spin), ab(k - 1, spin), &
300 CALL cp_fm_to_fm(ab(k - 1, spin), b(k, spin))
304 ELSE IF (mode ==
'D')
THEN
306 iev = must_improve(i)
312 CALL cp_fm_to_fm(ab(j, spin), x(spin))
314 -evals(iev, iter - 1), sb(j, spin))
320 IF (tddfpt_control%invert_S)
THEN
321 CALL cp_fm_symm(
'L',
'U', p_env%n_ao(spin), p_env%n_mo(spin), &
322 1.0_dp, t_env%invS(spin), r(spin), &
325 CALL cp_fm_to_fm(r(spin), x(spin))
331 IF (dft_control%tddfpt_control%precond)
THEN
332 DO col = 1, p_env%n_mo(spin)
333 IF (col <= n_ev)
THEN
334 tmp2 = abs(evals(iev, iter - 1) - in_evals(col))
336 tmp2 = abs(evals(iev, iter - 1) - (in_evals(n_ev) + 10.0_dp))
339 tmp2 = max(tmp2, 100*epsilon(1.0_dp))
340 DO row = 1, p_env%n_ao(spin)
346 CALL cp_fm_to_fm(x(spin), b(k, spin))
352 IF (output_unit > 0)
WRITE (output_unit, *)
"unknown mode"
359 DO j = 1, tddfpt_control%n_reortho
364 CALL cp_fm_to_fm(b(k, spin), x(spin))
366 CALL apply_op(x, ab(k, :), p_env, qs_env, &
367 dft_control%tddfpt_control%do_kernel)
380 CALL cp_fm_release(atilde)
381 CALL cp_fm_release(us)
402 CALL cp_fm_trace(b(i, spin), ab(j, spin), tmp)
403 atilde_ij = atilde_ij + tmp
412 evals_tmp(:) = evals(:, iter)
414 evals(:, iter) = evals_tmp(:)
419 evals_difference = 1.0_dp
422 evals_difference(:) = abs((evals(1:n_ev, iter - 1) - evals(1:n_ev, iter)))
424 IF (output_unit > 0)
THEN
425 WRITE (output_unit, *)
427 WRITE (output_unit,
'(2X,F10.7,T69,ES11.4)') evals(i, iter)*
evolt, evals_difference(i)
429 WRITE (output_unit, *)
432 convergence = maxval(evals_difference)
433 IF (output_unit > 0)
WRITE (output_unit,
'(2X,I4,T69,ES11.4)') k, convergence
435 IF (convergence < tddfpt_control%tolerance)
THEN
441 IF (mode ==
'L')
THEN
446 IF (evals_difference(i) > tddfpt_control%tolerance) must_improve(i) = 1
451 n_kv = sum(must_improve)
454 IF (must_improve(i) == 1)
THEN
461 IF (k + n_kv > max_kv)
EXIT iteration
467 IF (
PRESENT(out_evals))
THEN
468 out_evals(1:n_ev) = evals(1:n_ev, iter)
485 CALL cp_fm_release(atilde)
486 CALL cp_fm_release(us)
488 CALL fm_pools_give_back_fm_vect(ao_mo_fm_pools, x)
489 CALL fm_pools_give_back_fm_vect(ao_mo_fm_pools, r)
493 CALL cp_fm_release(b)
494 CALL cp_fm_release(ab)
495 CALL cp_fm_release(sb)
496 DEALLOCATE (evals, evals_tmp, evals_difference, must_improve, kv_fm_struct)
498 CALL timestop(handle)
500 END FUNCTION iterative_solver
517 SUBROUTINE apply_op(X, R, p_env, qs_env, do_kernel)
519 TYPE(cp_fm_type),
DIMENSION(:),
INTENT(INOUT) :: x, r
520 TYPE(qs_p_env_type) :: p_env
521 TYPE(qs_environment_type),
POINTER :: qs_env
522 LOGICAL,
INTENT(IN) :: do_kernel
524 CHARACTER(LEN=*),
PARAMETER :: routinen =
'apply_op'
526 INTEGER :: handle, nspins, spin
527 INTEGER,
SAVE :: counter = 0
528 TYPE(dft_control_type),
POINTER :: dft_control
530 NULLIFY (dft_control)
532 CALL timeset(routinen, handle)
534 counter = counter + 1
535 CALL get_qs_env(qs_env, dft_control=dft_control)
536 nspins = dft_control%nspins
541 CALL p_op_l1(p_env, qs_env, x, r)
549 CALL dbcsr_set(p_env%p1(spin)%matrix, 0.0_dp)
551 matrix_v=p_env%psi0d(spin), &
553 ncol=p_env%n_mo(spin), &
559 CALL p_op_l2(p_env, qs_env, p_env%p1, x, &
560 alpha=1.0_dp, beta=0.0_dp)
567 CALL timestop(handle)
569 END SUBROUTINE apply_op
580 SUBROUTINE allocate_krylov_vectors(vectors, vectors_name, &
581 startv, n_v, nspins, fm_struct)
583 TYPE(cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: vectors
584 CHARACTER(LEN=*),
INTENT(IN) :: vectors_name
585 INTEGER,
INTENT(IN) :: startv, n_v, nspins
586 TYPE(cp_fm_struct_p_type),
DIMENSION(:), &
587 INTENT(IN) :: fm_struct
589 CHARACTER(LEN=*),
PARAMETER :: routinen =
'allocate_krylov_vectors', &
590 routinep = modulen//
':'//routinen
592 CHARACTER(LEN=default_string_length) :: mat_name
593 INTEGER :: index, spin
596 DO index = startv, startv + n_v - 1
597 mat_name = routinep//vectors_name//trim(cp_to_string(index)) &
598 //
","//trim(cp_to_string(spin))
600 fm_struct(spin)%struct, mat_name)
601 IF (.NOT.
ASSOCIATED(vectors(index, spin)%matrix_struct)) &
602 cpabort(
"Could not allocate "//trim(mat_name)//
".")
606 END SUBROUTINE allocate_krylov_vectors
methods related to the blacs parallel environment
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
DBCSR operations in CP2K.
subroutine, public cp_dbcsr_sm_fm_multiply(matrix, fm_in, fm_out, ncol, alpha, beta)
multiply a dbcsr with a fm matrix
subroutine, public cp_dbcsr_plus_fm_fm_t(sparse_matrix, matrix_v, matrix_g, ncol, alpha, keep_sparsity, symmetry_mode)
performs the multiplication sparse_matrix+dense_mat*dens_mat^T if matrix_g is not explicitly given,...
basic linear algebra operations for full matrices
subroutine, public cp_fm_scale_and_add(alpha, matrix_a, beta, matrix_b)
calc A <- alpha*A + beta*B optimized for alpha == 1.0 (just add beta*B) and beta == 0....
subroutine, public cp_fm_symm(side, uplo, m, n, alpha, matrix_a, matrix_b, beta, matrix_c)
computes matrix_c = beta * matrix_c + alpha * matrix_a * matrix_b computes matrix_c = beta * matrix_c...
used for collecting some of the diagonalization schemes available for cp_fm_type. cp_fm_power also mo...
subroutine, public cp_fm_syevd(matrix, eigenvectors, eigenvalues, info)
Computes all eigenvalues and vectors of a real symmetric matrix significantly faster than syevx,...
pool for for elements that are retained and released
represent the structure of a full matrix
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
subroutine, public cp_fm_get_element(matrix, irow_global, icol_global, alpha, local)
returns an element of a fm this value is valid on every cpu using this call is expensive
subroutine, public cp_fm_set_all(matrix, alpha, beta)
set all elements of a matrix to the same value, and optionally the diagonal to a different one
subroutine, public cp_fm_set_element(matrix, irow_global, icol_global, alpha)
sets an element of a matrix
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp)
creates a new full matrix with the given structure
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
Interface to the message passing library MPI.
Definition of physical constants:
real(kind=dp), parameter, public evolt
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_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, 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, rhs)
Get the QUICKSTEP environment.
wrapper for the pools of matrixes
subroutine, public mpools_get(mpools, ao_mo_fm_pools, ao_ao_fm_pools, mo_mo_fm_pools, ao_mosub_fm_pools, mosub_mosub_fm_pools, maxao_maxmo_fm_pool, maxao_maxao_fm_pool, maxmo_maxmo_fm_pool)
returns various attributes of the mpools (notably the pools contained in it)
Utility functions for the perturbation calculations.
subroutine, public p_op_l1(p_env, qs_env, v, res)
Evaluates Fv (S_mo)^-1 - Sv(epsilon) and stores it in res.
subroutine, public p_postortho(p_env, qs_env, v, n_cols)
does a postorthogonalization on the given matrix vector: v = (I-SP) v
subroutine, public p_op_l2(p_env, qs_env, p1, res, alpha, beta)
evaluates res = alpha kpp1(v)*psi0 + beta res with kpp1 evaluated with p=qs_envrhorho_ao,...
subroutine, public p_preortho(p_env, qs_env, v, n_cols)
does a preorthogonalization of the given matrix: v = (I-PS)v
basis types for the calculation of the perturbation of density theory.
subroutine, public eigensolver(p_env, qs_env, t_env)
...
subroutine, public reorthogonalize(X, V_set, SV_set, work, n)
...
subroutine, public co_initial_guess(matrices, energies, n_v, qs_env)
...
subroutine, public normalize(X, tmp_vec, metric)
...