(git:e68414f)
Loading...
Searching...
No Matches
qs_tddfpt2_types.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2025 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
9 USE admm_types, ONLY: admm_type,&
14 USE cp_dbcsr_api, ONLY: &
17 dbcsr_type, dbcsr_type_antisymmetric
29 USE cp_fm_types, ONLY: cp_fm_create,&
40 USE kinds, ONLY: dp
43 USE pw_env_types, ONLY: pw_env_get
45 USE pw_types, ONLY: pw_c1d_gs_type,&
55 USE qs_rho0_methods, ONLY: init_rho0
58 USE qs_rho_types, ONLY: qs_rho_create,&
64#include "./base/base_uses.f90"
65
66 IMPLICIT NONE
67
68 PRIVATE
69
70 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_tddfpt2_types'
71
72 LOGICAL, PARAMETER, PRIVATE :: debug_this_module = .false.
73 ! number of first derivative components (3: d/dx, d/dy, d/dz)
74 INTEGER, PARAMETER, PRIVATE :: nderivs = 3
75 INTEGER, PARAMETER, PRIVATE :: maxspins = 2
76
80
81! **************************************************************************************************
82!> \brief Ground state molecular orbitals.
83!> \par History
84!> * 06.2016 created [Sergey Chulkov]
85! **************************************************************************************************
87 !> occupied MOs stored in a matrix form [nao x nmo_occ]
88 TYPE(cp_fm_type), POINTER :: mos_occ => null()
89 !> virtual MOs stored in a matrix form [nao x nmo_virt]
90 TYPE(cp_fm_type), POINTER :: mos_virt => null()
91 !> negated occupied orbital energy matrix [nmo_occ x nmo_occ]: - mos_occ^T * KS * mos_occ .
92 !> Allocated when orbital energy correction is in use, otherwise it is just a diagonal
93 !> matrix with 'evals_occ' on its diagonal
94 TYPE(cp_fm_type), POINTER :: evals_occ_matrix => null()
95 !> (non-corrected) occupied orbital energies
96 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: evals_occ
97 !> (non-corrected) virtual orbital energies
98 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: evals_virt
99 !> phase of occupied MOs; +1.0 -- positive, -1.0 -- negative;
100 !> it is mainly needed to make the restart file transferable
101 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: phases_occ
102 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: phases_virt
104
105! **************************************************************************************************
106!> \brief Set of temporary ("work") matrices.
107!> \par History
108!> * 01.2017 created [Sergey Chulkov]
109! **************************************************************************************************
111 !
112 ! *** globally distributed dense matrices ***
113 !
114 !> pool of dense [nao x nmo_occ(spin)] matrices;
115 !> used mainly to dynamically expand the list of trial vectors
116 TYPE(cp_fm_pool_p_type), ALLOCATABLE, DIMENSION(:) :: fm_pool_ao_mo_occ
117 !> S * mos_occ(spin)
118 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: s_c0
119 !> S * \rho_0(spin)
120 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: s_c0_c0t
121 !
122 ! *** dense matrices distributed across parallel (sub)groups ***
123 !
124 !> evects_sub(1:nspins, 1:nstates): a copy of the last 'nstates' trial vectors distributed
125 !> across parallel (sub)groups. Here 'nstates' is the number of requested excited states which
126 !> is typically much smaller than the total number of Krylov's vectors. Allocated only if
127 !> the number of parallel groups > 1, otherwise we use the original globally distributed vectors.
128 !> evects_sub(spin, state) == null() means that the trial vector is assigned to a different (sub)group
129 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: evects_sub
130 !> action of TDDFPT operator on trial vectors distributed across parallel (sub)groups
131 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: aop_evects_sub
132 !> electron density expressed in terms of atomic orbitals using primary basis set
133 TYPE(cp_fm_type), POINTER :: rho_ao_orb_fm_sub => null()
134 !
135 ! NOTE: we do not need the next 2 matrices in case of a sparse matrix 'tddfpt_subgroup_env_type%admm_A'
136 !
137 !> electron density expressed in terms of atomic orbitals using auxiliary basis set;
138 !> can be seen as a group-specific version of the matrix 'admm_type%work_aux_aux'
139 TYPE(cp_fm_type), POINTER :: rho_ao_aux_fit_fm_sub => null()
140 !> group-specific version of the matrix 'admm_type%work_aux_orb' with shape [nao_aux x nao]
141 TYPE(cp_fm_type), POINTER :: wfm_aux_orb_sub => null()
142 !
143 ! *** sparse matrices distributed across parallel (sub)groups ***
144 !
145 !> sparse matrix with shape [nao x nao] distributed across subgroups;
146 !> Aop_evects_sub(spin,:) = A_ia_munu_sub(spin) * mos_occ(spin)
147 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: a_ia_munu_sub => null()
148 !
149 ! *** structures to store electron densities distributed across parallel (sub)groups ***
150 !
151 !> electron density in terms of primary basis set
152 TYPE(qs_rho_type), POINTER :: rho_orb_struct_sub => null()
153 !> electron density for XC in GAPW_XC
154 TYPE(qs_rho_type), POINTER :: rho_xc_struct_sub => null()
155 !> electron density in terms of auxiliary basis set
156 TYPE(qs_rho_type), POINTER :: rho_aux_fit_struct_sub => null()
157 !> group-specific copy of a Coulomb/xc-potential on a real-space grid
158 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: a_ia_rspace_sub => null()
159 !> group-specific copy of a reciprocal-space grid
160 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: wpw_gspace_sub => null()
161 !> group-specific copy of a real-space grid
162 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: wpw_rspace_sub => null()
163 !> group-specific copy of a real-space grid for the kinetic energy density
164 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: wpw_tau_rspace_sub => null()
165 !
166 ! *** real space pw grid to hold fxc kernel <> A_ia_rspace_sub ***
167 !
168 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: fxc_rspace_sub => null()
169 !
170 ! *** globally distributed matrices required to compute exact exchange terms ***
171 !
172 !> globally distributed version of the matrix 'rho_ao_orb_fm_sub' to store the electron density
173 TYPE(cp_fm_type), POINTER :: hfx_fm_ao_ao => null()
174 !> sparse matrix to store the electron density in terms of auxiliary (ADMM calculation)
175 !> or primary (regular calculation) basis set
176 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: hfx_rho_ao_symm => null(), hfx_rho_ao_asymm => null()
177 !> exact exchange expressed in terms of auxiliary or primary basis set
178 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: hfx_hmat_symm => null(), hfx_hmat_asymm => null()
179 !> SR exact exchage matrices
180 TYPE(cp_fm_type), POINTER :: hfxsr_fm_ao_ao => null()
181 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: hfxsr_rho_ao_symm => null(), hfxsr_rho_ao_asymm => null()
182 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: hfxsr_hmat_symm => null(), hfxsr_hmat_asymm => null()
183 !
184 ! *** matrices required for sTDA kernel, all matrices are within subgroups
185 !
186 ! Short-range gamma exchange matrix
187 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: gamma_exchange => null()
188 !Lowdin MO coefficients: NAO*NOCC
189 TYPE(cp_fm_type), DIMENSION(:), POINTER :: ctransformed => null()
190 !S^1/2
191 TYPE(dbcsr_type), POINTER :: shalf => null()
192 !Eigenvalues/eigenvectors of the overlap matrix, used in sTDA forces (Lowdin derivatives)
193 REAL(kind=dp), DIMENSION(:), POINTER :: s_eigenvalues => null()
194 TYPE(cp_fm_type), POINTER :: s_eigenvectors => null()
195 TYPE(cp_fm_type), POINTER :: slambda => null()
196 !Ewald environments
197 TYPE(ewald_environment_type), POINTER :: ewald_env => null()
198 TYPE(ewald_pw_type), POINTER :: ewald_pw => null()
199 !> GAPW local atomic grids
200 TYPE(hartree_local_type), POINTER :: hartree_local => null()
201 TYPE(local_rho_type), POINTER :: local_rho_set => null()
202 TYPE(local_rho_type), POINTER :: local_rho_set_admm => null()
203 END TYPE tddfpt_work_matrices
204
205CONTAINS
206
207! **************************************************************************************************
208!> \brief Allocate work matrices for full kernel
209!> \param work_matrices work matrices (allocated on exit)
210!> \param gs_mos occupied and virtual molecular orbitals optimised for the ground state
211!> \param nstates number of excited states to converge
212!> \param do_hfx flag that requested to allocate work matrices required for computation
213!> of exact-exchange terms
214!> \param do_admm ...
215!> \param do_hfxlr ...
216!> \param do_exck ...
217!> \param do_sf ...
218!> \param qs_env Quickstep environment
219!> \param sub_env parallel group environment
220!> \par History
221!> * 02.2017 created [Sergey Chulkov]
222! **************************************************************************************************
223 SUBROUTINE tddfpt_create_work_matrices(work_matrices, gs_mos, nstates, do_hfx, do_admm, &
224 do_hfxlr, do_exck, do_sf, qs_env, sub_env)
225 TYPE(tddfpt_work_matrices), INTENT(out) :: work_matrices
226 TYPE(tddfpt_ground_state_mos), DIMENSION(:), &
227 INTENT(in) :: gs_mos
228 INTEGER, INTENT(in) :: nstates
229 LOGICAL, INTENT(in) :: do_hfx, do_admm, do_hfxlr, do_exck, do_sf
230 TYPE(qs_environment_type), POINTER :: qs_env
231 TYPE(tddfpt_subgroup_env_type), INTENT(in) :: sub_env
232
233 CHARACTER(LEN=*), PARAMETER :: routinen = 'tddfpt_create_work_matrices'
234
235 INTEGER :: evecs_dim, handle, igroup, ispin, &
236 istate, nao, nao_aux, natom, ngroups, &
237 nspins
238 INTEGER, DIMENSION(maxspins) :: nmo_occ, nmo_virt
239 TYPE(admm_type), POINTER :: admm_env
240 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
241 TYPE(cp_blacs_env_type), POINTER :: blacs_env
242 TYPE(cp_fm_struct_p_type), DIMENSION(maxspins) :: fm_struct_evects
243 TYPE(cp_fm_struct_type), POINTER :: fm_struct
244 TYPE(dbcsr_distribution_type), POINTER :: dbcsr_dist
245 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s, matrix_s_aux_fit, rho_ia_ao, &
246 rho_xc_ao
247 TYPE(dbcsr_type), POINTER :: dbcsr_template_hfx
248 TYPE(dft_control_type), POINTER :: dft_control
249 TYPE(mp_para_env_type), POINTER :: para_env
250 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
251 POINTER :: sab_hfx
252 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
253 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
254
255 CALL timeset(routinen, handle)
256
257 ! sTDA
258 NULLIFY (work_matrices%shalf)
259 NULLIFY (work_matrices%ewald_env)
260 NULLIFY (work_matrices%ewald_pw)
261 NULLIFY (work_matrices%gamma_exchange)
262 NULLIFY (work_matrices%ctransformed)
263 NULLIFY (work_matrices%S_eigenvalues)
264 NULLIFY (work_matrices%S_eigenvectors)
265 NULLIFY (work_matrices%slambda)
266
267 ! GAPW
268 NULLIFY (work_matrices%hartree_local)
269 NULLIFY (work_matrices%local_rho_set)
270 NULLIFY (work_matrices%local_rho_set_admm)
271
272 ! EXCK
273 NULLIFY (work_matrices%rho_xc_struct_sub)
274
275 nspins = SIZE(gs_mos)
276 IF (do_sf) THEN
277 evecs_dim = 1
278 ELSE
279 evecs_dim = nspins
280 END IF
281 CALL get_qs_env(qs_env, blacs_env=blacs_env, matrix_s=matrix_s)
282 CALL dbcsr_get_info(matrix_s(1)%matrix, nfullrows_total=nao)
283
284 DO ispin = 1, nspins
285 nmo_occ(ispin) = SIZE(gs_mos(ispin)%evals_occ)
286 nmo_virt(ispin) = SIZE(gs_mos(ispin)%evals_virt)
287 END DO
288
289 IF (do_admm) THEN
290 cpassert(do_hfx)
291 cpassert(ASSOCIATED(sub_env%admm_A))
292 CALL get_admm_env(qs_env%admm_env, matrix_s_aux_fit=matrix_s_aux_fit)
293 CALL dbcsr_get_info(matrix_s_aux_fit(1)%matrix, nfullrows_total=nao_aux)
294 END IF
295
296 NULLIFY (fm_struct)
297 ALLOCATE (work_matrices%fm_pool_ao_mo_occ(nspins))
298 DO ispin = 1, nspins
299 NULLIFY (work_matrices%fm_pool_ao_mo_occ(ispin)%pool)
300 CALL cp_fm_struct_create(fm_struct, nrow_global=nao, ncol_global=nmo_occ(ispin), context=blacs_env)
301 CALL fm_pool_create(work_matrices%fm_pool_ao_mo_occ(ispin)%pool, fm_struct)
302 CALL cp_fm_struct_release(fm_struct)
303 END DO
304
305 ALLOCATE (work_matrices%S_C0_C0T(nspins))
306 CALL cp_fm_struct_create(fm_struct, nrow_global=nao, ncol_global=nao, context=blacs_env)
307 DO ispin = 1, nspins
308 CALL cp_fm_create(work_matrices%S_C0_C0T(ispin), fm_struct)
309 END DO
310 CALL cp_fm_struct_release(fm_struct)
311
312 ALLOCATE (work_matrices%S_C0(nspins))
313 DO ispin = 1, nspins
314 CALL fm_pool_create_fm(work_matrices%fm_pool_ao_mo_occ(ispin)%pool, work_matrices%S_C0(ispin))
315
316 CALL cp_dbcsr_sm_fm_multiply(matrix_s(1)%matrix, gs_mos(ispin)%mos_occ, work_matrices%S_C0(ispin), &
317 ncol=nmo_occ(ispin), alpha=1.0_dp, beta=0.0_dp)
318 CALL parallel_gemm('N', 'T', nao, nao, nmo_occ(ispin), 1.0_dp, work_matrices%S_C0(ispin), &
319 gs_mos(ispin)%mos_occ, 0.0_dp, work_matrices%S_C0_C0T(ispin))
320 END DO
321
322 IF (sub_env%is_split) THEN
323 DO ispin = 1, evecs_dim
324 CALL cp_fm_struct_create(fm_struct_evects(ispin)%struct, nrow_global=nao, &
325 ncol_global=nmo_occ(ispin), context=sub_env%blacs_env)
326 END DO
327
328 ALLOCATE (work_matrices%evects_sub(evecs_dim, nstates), work_matrices%Aop_evects_sub(evecs_dim, nstates))
329
330 CALL blacs_env%get(para_env=para_env)
331 igroup = sub_env%group_distribution(para_env%mepos)
332 ngroups = sub_env%ngroups
333
334 DO istate = ngroups - igroup, nstates, ngroups
335 DO ispin = 1, evecs_dim
336 CALL cp_fm_create(work_matrices%evects_sub(ispin, istate), fm_struct_evects(ispin)%struct)
337 CALL cp_fm_create(work_matrices%Aop_evects_sub(ispin, istate), fm_struct_evects(ispin)%struct)
338 END DO
339 END DO
340
341 DO ispin = evecs_dim, 1, -1
342 CALL cp_fm_struct_release(fm_struct_evects(ispin)%struct)
343 END DO
344 END IF
345
346 CALL cp_fm_struct_create(fm_struct, nrow_global=nao, ncol_global=nao, context=sub_env%blacs_env)
347 ALLOCATE (work_matrices%rho_ao_orb_fm_sub)
348 CALL cp_fm_create(work_matrices%rho_ao_orb_fm_sub, fm_struct)
349 CALL cp_fm_struct_release(fm_struct)
350
351 NULLIFY (work_matrices%rho_ao_aux_fit_fm_sub, work_matrices%wfm_aux_orb_sub)
352 IF (do_admm) THEN
353 CALL cp_fm_struct_create(fm_struct, nrow_global=nao_aux, ncol_global=nao_aux, context=sub_env%blacs_env)
354 ALLOCATE (work_matrices%rho_ao_aux_fit_fm_sub)
355 CALL cp_fm_create(work_matrices%rho_ao_aux_fit_fm_sub, fm_struct)
356 CALL cp_fm_struct_release(fm_struct)
357
358 CALL cp_fm_struct_create(fm_struct, nrow_global=nao_aux, ncol_global=nao, context=sub_env%blacs_env)
359 ALLOCATE (work_matrices%wfm_aux_orb_sub)
360 CALL cp_fm_create(work_matrices%wfm_aux_orb_sub, fm_struct)
361 CALL cp_fm_struct_release(fm_struct)
362 END IF
363
364 ! group-specific dbcsr matrices
365 NULLIFY (work_matrices%A_ia_munu_sub)
366 CALL dbcsr_allocate_matrix_set(work_matrices%A_ia_munu_sub, evecs_dim)
367 DO ispin = 1, evecs_dim
368 CALL dbcsr_init_p(work_matrices%A_ia_munu_sub(ispin)%matrix)
369 CALL tddfpt_dbcsr_create_by_dist(work_matrices%A_ia_munu_sub(ispin)%matrix, template=matrix_s(1)%matrix, &
370 dbcsr_dist=sub_env%dbcsr_dist, sab=sub_env%sab_orb)
371 END DO
372
373 ! group-specific response density
374 NULLIFY (rho_ia_ao)
375 CALL dbcsr_allocate_matrix_set(rho_ia_ao, nspins)
376 DO ispin = 1, nspins
377 CALL dbcsr_init_p(rho_ia_ao(ispin)%matrix)
378 CALL tddfpt_dbcsr_create_by_dist(rho_ia_ao(ispin)%matrix, template=matrix_s(1)%matrix, &
379 dbcsr_dist=sub_env%dbcsr_dist, sab=sub_env%sab_orb)
380 END DO
381
382 NULLIFY (work_matrices%rho_orb_struct_sub)
383 ALLOCATE (work_matrices%rho_orb_struct_sub)
384 CALL qs_rho_create(work_matrices%rho_orb_struct_sub)
385 CALL qs_rho_set(work_matrices%rho_orb_struct_sub, rho_ao=rho_ia_ao)
386 CALL qs_rho_rebuild(work_matrices%rho_orb_struct_sub, qs_env, rebuild_ao=.false., &
387 rebuild_grids=.true., pw_env_external=sub_env%pw_env)
388 CALL get_qs_env(qs_env, dft_control=dft_control)
389 IF (dft_control%qs_control%gapw_xc) THEN
390 NULLIFY (rho_xc_ao)
391 CALL dbcsr_allocate_matrix_set(rho_xc_ao, nspins)
392 DO ispin = 1, nspins
393 CALL dbcsr_init_p(rho_xc_ao(ispin)%matrix)
394 CALL tddfpt_dbcsr_create_by_dist(rho_xc_ao(ispin)%matrix, template=matrix_s(1)%matrix, &
395 dbcsr_dist=sub_env%dbcsr_dist, sab=sub_env%sab_orb)
396 END DO
397 NULLIFY (work_matrices%rho_xc_struct_sub)
398 ALLOCATE (work_matrices%rho_xc_struct_sub)
399 CALL qs_rho_create(work_matrices%rho_xc_struct_sub)
400 CALL qs_rho_set(work_matrices%rho_xc_struct_sub, rho_ao=rho_xc_ao)
401 CALL qs_rho_rebuild(work_matrices%rho_xc_struct_sub, qs_env, rebuild_ao=.false., &
402 rebuild_grids=.true., pw_env_external=sub_env%pw_env)
403 END IF
404
405 NULLIFY (work_matrices%rho_aux_fit_struct_sub)
406 IF (do_admm) THEN
407 NULLIFY (rho_ia_ao)
408 CALL dbcsr_allocate_matrix_set(rho_ia_ao, nspins)
409 DO ispin = 1, nspins
410 CALL dbcsr_init_p(rho_ia_ao(ispin)%matrix)
411 CALL tddfpt_dbcsr_create_by_dist(rho_ia_ao(ispin)%matrix, template=matrix_s_aux_fit(1)%matrix, &
412 dbcsr_dist=sub_env%dbcsr_dist, sab=sub_env%sab_aux_fit)
413 END DO
414
415 ALLOCATE (work_matrices%rho_aux_fit_struct_sub)
416 CALL qs_rho_create(work_matrices%rho_aux_fit_struct_sub)
417 CALL qs_rho_set(work_matrices%rho_aux_fit_struct_sub, rho_ao=rho_ia_ao)
418 CALL qs_rho_rebuild(work_matrices%rho_aux_fit_struct_sub, qs_env, rebuild_ao=.false., &
419 rebuild_grids=.true., pw_env_external=sub_env%pw_env)
420 END IF
421
422 ! work plain-wave grids
423 CALL pw_env_get(sub_env%pw_env, auxbas_pw_pool=auxbas_pw_pool)
424 ALLOCATE (work_matrices%A_ia_rspace_sub(nspins))
425 ALLOCATE (work_matrices%wpw_gspace_sub(nspins), work_matrices%wpw_rspace_sub(nspins), &
426 work_matrices%wpw_tau_rspace_sub(nspins))
427 DO ispin = 1, nspins
428 CALL auxbas_pw_pool%create_pw(work_matrices%A_ia_rspace_sub(ispin))
429 CALL auxbas_pw_pool%create_pw(work_matrices%wpw_gspace_sub(ispin))
430 CALL auxbas_pw_pool%create_pw(work_matrices%wpw_rspace_sub(ispin))
431 CALL auxbas_pw_pool%create_pw(work_matrices%wpw_tau_rspace_sub(ispin))
432 END DO
433
434 ! fxc kernel potential real space grid
435 IF (do_exck) THEN
436 ! we need spins: aa, ab, bb
437 ALLOCATE (work_matrices%fxc_rspace_sub(3))
438 DO ispin = 1, 3
439 CALL auxbas_pw_pool%create_pw(work_matrices%fxc_rspace_sub(ispin))
440 END DO
441 ELSE
442 NULLIFY (work_matrices%fxc_rspace_sub)
443 END IF
444
445 ! GAPW initializations
446 IF (dft_control%qs_control%gapw) THEN
447 CALL get_qs_env(qs_env, &
448 atomic_kind_set=atomic_kind_set, &
449 natom=natom, &
450 qs_kind_set=qs_kind_set)
451 CALL local_rho_set_create(work_matrices%local_rho_set)
452 CALL allocate_rho_atom_internals(work_matrices%local_rho_set%rho_atom_set, atomic_kind_set, &
453 qs_kind_set, dft_control, sub_env%para_env)
454 CALL init_rho0(work_matrices%local_rho_set, qs_env, dft_control%qs_control%gapw_control, &
455 zcore=0.0_dp)
456 CALL rho0_s_grid_create(sub_env%pw_env, work_matrices%local_rho_set%rho0_mpole)
457 CALL hartree_local_create(work_matrices%hartree_local)
458 CALL init_coulomb_local(work_matrices%hartree_local, natom)
459 ELSEIF (dft_control%qs_control%gapw_xc) THEN
460 CALL get_qs_env(qs_env, &
461 atomic_kind_set=atomic_kind_set, &
462 qs_kind_set=qs_kind_set)
463 CALL local_rho_set_create(work_matrices%local_rho_set)
464 CALL allocate_rho_atom_internals(work_matrices%local_rho_set%rho_atom_set, atomic_kind_set, &
465 qs_kind_set, dft_control, sub_env%para_env)
466 END IF
467
468 ! HFX-related globally distributed matrices
469 NULLIFY (work_matrices%hfx_fm_ao_ao, work_matrices%hfx_rho_ao_symm, work_matrices%hfx_hmat_symm, &
470 work_matrices%hfx_rho_ao_asymm, work_matrices%hfx_hmat_asymm)
471 IF (do_hfx) THEN
472 IF (do_admm) THEN
473 CALL get_qs_env(qs_env, dbcsr_dist=dbcsr_dist)
474 CALL get_admm_env(qs_env%admm_env, sab_aux_fit=sab_hfx)
475 dbcsr_template_hfx => matrix_s_aux_fit(1)%matrix
476 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc) THEN
477 CALL get_qs_env(qs_env, admm_env=admm_env, atomic_kind_set=atomic_kind_set)
478 CALL local_rho_set_create(work_matrices%local_rho_set_admm)
479 CALL allocate_rho_atom_internals(work_matrices%local_rho_set_admm%rho_atom_set, &
480 atomic_kind_set, admm_env%admm_gapw_env%admm_kind_set, &
481 dft_control, sub_env%para_env)
482 END IF
483 ELSE
484 CALL get_qs_env(qs_env, dbcsr_dist=dbcsr_dist, sab_orb=sab_hfx)
485 dbcsr_template_hfx => matrix_s(1)%matrix
486 END IF
487
488 CALL cp_fm_struct_create(fm_struct, nrow_global=nao, ncol_global=nao, context=blacs_env)
489 ALLOCATE (work_matrices%hfx_fm_ao_ao)
490 CALL cp_fm_create(work_matrices%hfx_fm_ao_ao, fm_struct)
491 CALL cp_fm_struct_release(fm_struct)
492
493 CALL dbcsr_allocate_matrix_set(work_matrices%hfx_rho_ao_symm, nspins)
494 CALL dbcsr_allocate_matrix_set(work_matrices%hfx_rho_ao_asymm, nspins)
495 DO ispin = 1, nspins
496 CALL dbcsr_init_p(work_matrices%hfx_rho_ao_symm(ispin)%matrix)
497 CALL tddfpt_dbcsr_create_by_dist(work_matrices%hfx_rho_ao_symm(ispin)%matrix, &
498 template=dbcsr_template_hfx, dbcsr_dist=dbcsr_dist, sab=sab_hfx)
499
500 CALL dbcsr_init_p(work_matrices%hfx_rho_ao_asymm(ispin)%matrix)
501 CALL dbcsr_create(work_matrices%hfx_rho_ao_asymm(ispin)%matrix, matrix_type=dbcsr_type_antisymmetric, &
502 template=work_matrices%hfx_rho_ao_symm(ispin)%matrix)
503 CALL dbcsr_complete_redistribute(work_matrices%hfx_rho_ao_symm(ispin)%matrix, &
504 work_matrices%hfx_rho_ao_asymm(ispin)%matrix)
505 END DO
506
507 CALL dbcsr_allocate_matrix_set(work_matrices%hfx_hmat_symm, nspins)
508 CALL dbcsr_allocate_matrix_set(work_matrices%hfx_hmat_asymm, nspins)
509 DO ispin = 1, nspins
510 CALL dbcsr_init_p(work_matrices%hfx_hmat_symm(ispin)%matrix)
511 CALL tddfpt_dbcsr_create_by_dist(work_matrices%hfx_hmat_symm(ispin)%matrix, &
512 template=dbcsr_template_hfx, dbcsr_dist=dbcsr_dist, sab=sab_hfx)
513
514 CALL dbcsr_init_p(work_matrices%hfx_hmat_asymm(ispin)%matrix)
515 CALL dbcsr_create(work_matrices%hfx_hmat_asymm(ispin)%matrix, matrix_type=dbcsr_type_antisymmetric, &
516 template=work_matrices%hfx_hmat_symm(ispin)%matrix)
517 CALL dbcsr_complete_redistribute(work_matrices%hfx_hmat_symm(ispin)%matrix, &
518 work_matrices%hfx_hmat_asymm(ispin)%matrix)
519 END DO
520 END IF
521
522 ! matrices needed to do HFX short range calllculations
523 NULLIFY (work_matrices%hfxsr_fm_ao_ao, work_matrices%hfxsr_rho_ao_symm, work_matrices%hfxsr_hmat_symm, &
524 work_matrices%hfxsr_rho_ao_asymm, work_matrices%hfxsr_hmat_asymm)
525 ! matrices needed to do HFX long range calllculations
526 IF (do_hfxlr) THEN
527 DO ispin = 1, nspins
528 CALL cp_fm_struct_create(fm_struct_evects(ispin)%struct, nrow_global=nao, &
529 ncol_global=nmo_occ(ispin), context=sub_env%blacs_env)
530 END DO
531 CALL dbcsr_init_p(work_matrices%shalf)
532 CALL dbcsr_create(work_matrices%shalf, template=matrix_s(1)%matrix)
533 ALLOCATE (work_matrices%ctransformed(nspins))
534 DO ispin = 1, nspins
535 CALL cp_fm_create(work_matrices%ctransformed(ispin), fm_struct_evects(ispin)%struct)
536 END DO
537 ! forces
538 ALLOCATE (work_matrices%S_eigenvalues(nao))
539 NULLIFY (fm_struct)
540 CALL cp_fm_struct_create(fm_struct, nrow_global=nao, ncol_global=nao, context=blacs_env)
541 ALLOCATE (work_matrices%S_eigenvectors, work_matrices%slambda)
542 CALL cp_fm_create(work_matrices%S_eigenvectors, fm_struct)
543 CALL cp_fm_create(work_matrices%slambda, fm_struct)
544 !
545 CALL cp_fm_struct_release(fm_struct)
546 DO ispin = 1, nspins
547 CALL cp_fm_struct_release(fm_struct_evects(ispin)%struct)
548 END DO
549 END IF
550
551 CALL timestop(handle)
552
553 END SUBROUTINE tddfpt_create_work_matrices
554
555! **************************************************************************************************
556!> \brief Allocate work matrices for hfxsr
557!> \param work_matrices work matrices (allocated on exit)
558!> \param qs_env ...
559!> \param admm_env ...
560! **************************************************************************************************
561 SUBROUTINE hfxsr_create_work_matrices(work_matrices, qs_env, admm_env)
562 TYPE(tddfpt_work_matrices), INTENT(inout) :: work_matrices
563 TYPE(qs_environment_type), POINTER :: qs_env
564 TYPE(admm_type), POINTER :: admm_env
565
566 CHARACTER(LEN=*), PARAMETER :: routinen = 'hfxsr_create_work_matrices'
567
568 INTEGER :: handle, ispin, nao, nao_aux, nspins
569 TYPE(cp_blacs_env_type), POINTER :: blacs_env
570 TYPE(cp_fm_struct_type), POINTER :: fm_struct
571 TYPE(dbcsr_distribution_type), POINTER :: dbcsr_dist
572 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s, matrix_s_aux_fit
573 TYPE(dbcsr_type), POINTER :: dbcsr_template_hfx
574 TYPE(dft_control_type), POINTER :: dft_control
575 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
576 POINTER :: sab_hfx
577
578 CALL timeset(routinen, handle)
579
580 ! matrices needed to do HFX short range calllculations
581 NULLIFY (work_matrices%hfxsr_fm_ao_ao, work_matrices%hfxsr_rho_ao_symm, work_matrices%hfxsr_hmat_symm, &
582 work_matrices%hfxsr_rho_ao_asymm, work_matrices%hfxsr_hmat_asymm)
583
584 CALL get_qs_env(qs_env, dft_control=dft_control, matrix_s=matrix_s, &
585 blacs_env=blacs_env, dbcsr_dist=dbcsr_dist)
586 nspins = dft_control%nspins
587 CALL dbcsr_get_info(matrix_s(1)%matrix, nfullrows_total=nao)
588 CALL get_admm_env(admm_env, matrix_s_aux_fit=matrix_s_aux_fit)
589 dbcsr_template_hfx => matrix_s_aux_fit(1)%matrix
590 CALL dbcsr_get_info(dbcsr_template_hfx, nfullrows_total=nao_aux)
591
592 CALL cp_fm_struct_create(fm_struct, nrow_global=nao, ncol_global=nao, context=blacs_env)
593 ALLOCATE (work_matrices%hfxsr_fm_ao_ao)
594 CALL cp_fm_create(work_matrices%hfxsr_fm_ao_ao, fm_struct)
595 CALL cp_fm_struct_release(fm_struct)
596
597 CALL get_admm_env(admm_env, sab_aux_fit=sab_hfx)
598 CALL dbcsr_allocate_matrix_set(work_matrices%hfxsr_rho_ao_symm, nspins)
599 CALL dbcsr_allocate_matrix_set(work_matrices%hfxsr_rho_ao_asymm, nspins)
600 DO ispin = 1, nspins
601 CALL dbcsr_init_p(work_matrices%hfxsr_rho_ao_symm(ispin)%matrix)
602 CALL tddfpt_dbcsr_create_by_dist(work_matrices%hfxsr_rho_ao_symm(ispin)%matrix, &
603 template=dbcsr_template_hfx, dbcsr_dist=dbcsr_dist, sab=sab_hfx)
604
605 CALL dbcsr_init_p(work_matrices%hfxsr_rho_ao_asymm(ispin)%matrix)
606 CALL dbcsr_create(work_matrices%hfxsr_rho_ao_asymm(ispin)%matrix, matrix_type=dbcsr_type_antisymmetric, &
607 template=work_matrices%hfxsr_rho_ao_symm(ispin)%matrix)
608 CALL dbcsr_complete_redistribute(work_matrices%hfxsr_rho_ao_symm(ispin)%matrix, &
609 work_matrices%hfxsr_rho_ao_asymm(ispin)%matrix)
610 END DO
611
612 CALL dbcsr_allocate_matrix_set(work_matrices%hfxsr_hmat_symm, nspins)
613 CALL dbcsr_allocate_matrix_set(work_matrices%hfxsr_hmat_asymm, nspins)
614 DO ispin = 1, nspins
615 CALL dbcsr_init_p(work_matrices%hfxsr_hmat_symm(ispin)%matrix)
616 CALL tddfpt_dbcsr_create_by_dist(work_matrices%hfxsr_hmat_symm(ispin)%matrix, &
617 template=dbcsr_template_hfx, dbcsr_dist=dbcsr_dist, sab=sab_hfx)
618
619 CALL dbcsr_init_p(work_matrices%hfxsr_hmat_asymm(ispin)%matrix)
620 CALL dbcsr_create(work_matrices%hfxsr_hmat_asymm(ispin)%matrix, matrix_type=dbcsr_type_antisymmetric, &
621 template=work_matrices%hfxsr_hmat_symm(ispin)%matrix)
622 CALL dbcsr_complete_redistribute(work_matrices%hfxsr_hmat_symm(ispin)%matrix, &
623 work_matrices%hfxsr_hmat_asymm(ispin)%matrix)
624 END DO
625
626 CALL timestop(handle)
627
628 END SUBROUTINE hfxsr_create_work_matrices
629
630! **************************************************************************************************
631!> \brief Allocate work matrices for sTDA kernel
632!> \param work_matrices work matrices (allocated on exit)
633!> \param gs_mos occupied and virtual molecular orbitals optimised for the ground state
634!> \param nstates number of excited states to converge
635!> \param qs_env Quickstep environment
636!> \param sub_env parallel group environment
637!> \par History
638!> * 04.2019 created from full kernel version [JHU]
639! **************************************************************************************************
640 SUBROUTINE stda_create_work_matrices(work_matrices, gs_mos, nstates, qs_env, sub_env)
641 TYPE(tddfpt_work_matrices), INTENT(out) :: work_matrices
642 TYPE(tddfpt_ground_state_mos), DIMENSION(:), &
643 INTENT(in) :: gs_mos
644 INTEGER, INTENT(in) :: nstates
645 TYPE(qs_environment_type), POINTER :: qs_env
646 TYPE(tddfpt_subgroup_env_type), INTENT(in) :: sub_env
647
648 CHARACTER(LEN=*), PARAMETER :: routinen = 'stda_create_work_matrices'
649
650 INTEGER :: handle, igroup, ispin, istate, nao, &
651 ngroups, nspins
652 INTEGER, DIMENSION(maxspins) :: nmo_occ, nmo_virt
653 TYPE(cp_blacs_env_type), POINTER :: blacs_env
654 TYPE(cp_fm_struct_p_type), DIMENSION(maxspins) :: fm_struct_evects
655 TYPE(cp_fm_struct_type), POINTER :: fm_struct
656 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
657 TYPE(mp_para_env_type), POINTER :: para_env
658
659 CALL timeset(routinen, handle)
660
661 NULLIFY (work_matrices%gamma_exchange, work_matrices%ctransformed)
662
663 nspins = SIZE(gs_mos)
664 CALL get_qs_env(qs_env, blacs_env=blacs_env, matrix_s=matrix_s)
665 CALL dbcsr_get_info(matrix_s(1)%matrix, nfullrows_total=nao)
666
667 DO ispin = 1, nspins
668 nmo_occ(ispin) = SIZE(gs_mos(ispin)%evals_occ)
669 nmo_virt(ispin) = SIZE(gs_mos(ispin)%evals_virt)
670 END DO
671
672 NULLIFY (fm_struct)
673 ALLOCATE (work_matrices%fm_pool_ao_mo_occ(nspins))
674 DO ispin = 1, nspins
675 NULLIFY (work_matrices%fm_pool_ao_mo_occ(ispin)%pool)
676 CALL cp_fm_struct_create(fm_struct, nrow_global=nao, ncol_global=nmo_occ(ispin), context=blacs_env)
677 CALL fm_pool_create(work_matrices%fm_pool_ao_mo_occ(ispin)%pool, fm_struct)
678 CALL cp_fm_struct_release(fm_struct)
679 END DO
680
681 ALLOCATE (work_matrices%S_C0_C0T(nspins))
682 CALL cp_fm_struct_create(fm_struct, nrow_global=nao, ncol_global=nao, context=blacs_env)
683 DO ispin = 1, nspins
684 CALL cp_fm_create(work_matrices%S_C0_C0T(ispin), fm_struct)
685 END DO
686 CALL cp_fm_struct_release(fm_struct)
687
688 ALLOCATE (work_matrices%S_C0(nspins))
689 DO ispin = 1, nspins
690 CALL fm_pool_create_fm(work_matrices%fm_pool_ao_mo_occ(ispin)%pool, work_matrices%S_C0(ispin))
691
692 CALL cp_dbcsr_sm_fm_multiply(matrix_s(1)%matrix, gs_mos(ispin)%mos_occ, work_matrices%S_C0(ispin), &
693 ncol=nmo_occ(ispin), alpha=1.0_dp, beta=0.0_dp)
694 CALL parallel_gemm('N', 'T', nao, nao, nmo_occ(ispin), 1.0_dp, work_matrices%S_C0(ispin), &
695 gs_mos(ispin)%mos_occ, 0.0_dp, work_matrices%S_C0_C0T(ispin))
696 END DO
697
698 DO ispin = 1, nspins
699 CALL cp_fm_struct_create(fm_struct_evects(ispin)%struct, nrow_global=nao, &
700 ncol_global=nmo_occ(ispin), context=sub_env%blacs_env)
701 END DO
702
703 IF (sub_env%is_split) THEN
704 ALLOCATE (work_matrices%evects_sub(nspins, nstates), work_matrices%Aop_evects_sub(nspins, nstates))
705
706 CALL blacs_env%get(para_env=para_env)
707 igroup = sub_env%group_distribution(para_env%mepos)
708 ngroups = sub_env%ngroups
709
710 DO istate = ngroups - igroup, nstates, ngroups
711 DO ispin = 1, nspins
712 CALL cp_fm_create(work_matrices%evects_sub(ispin, istate), fm_struct_evects(ispin)%struct)
713 CALL cp_fm_create(work_matrices%Aop_evects_sub(ispin, istate), fm_struct_evects(ispin)%struct)
714 END DO
715 END DO
716 END IF
717
718 ! sTDA specific work arrays
719 ALLOCATE (work_matrices%ctransformed(nspins))
720 DO ispin = 1, nspins
721 CALL cp_fm_create(work_matrices%ctransformed(ispin), fm_struct_evects(ispin)%struct)
722 END DO
723 NULLIFY (work_matrices%shalf)
724 CALL dbcsr_init_p(work_matrices%shalf)
725 CALL dbcsr_create(work_matrices%shalf, template=matrix_s(1)%matrix)
726 ! forces
727 ALLOCATE (work_matrices%S_eigenvalues(nao))
728 NULLIFY (fm_struct)
729 CALL cp_fm_struct_create(fm_struct, nrow_global=nao, ncol_global=nao, context=blacs_env)
730 ALLOCATE (work_matrices%S_eigenvectors, work_matrices%slambda)
731 CALL cp_fm_create(work_matrices%S_eigenvectors, fm_struct)
732 CALL cp_fm_create(work_matrices%slambda, fm_struct)
733 CALL cp_fm_struct_release(fm_struct)
734
735 DO ispin = nspins, 1, -1
736 CALL cp_fm_struct_release(fm_struct_evects(ispin)%struct)
737 END DO
738
739 NULLIFY (work_matrices%rho_ao_orb_fm_sub)
740 NULLIFY (work_matrices%rho_ao_aux_fit_fm_sub, work_matrices%wfm_aux_orb_sub)
741 NULLIFY (work_matrices%rho_aux_fit_struct_sub)
742 NULLIFY (work_matrices%rho_orb_struct_sub)
743 NULLIFY (work_matrices%hfx_fm_ao_ao, work_matrices%hfx_rho_ao_symm, work_matrices%hfx_hmat_symm, &
744 work_matrices%hfx_rho_ao_asymm, work_matrices%hfx_hmat_asymm)
745 NULLIFY (work_matrices%hfxsr_fm_ao_ao, work_matrices%hfxsr_rho_ao_symm, work_matrices%hfxsr_hmat_symm, &
746 work_matrices%hfxsr_rho_ao_asymm, work_matrices%hfxsr_hmat_asymm)
747 NULLIFY (work_matrices%A_ia_rspace_sub, work_matrices%wpw_gspace_sub, &
748 work_matrices%wpw_rspace_sub)
749 NULLIFY (work_matrices%fxc_rspace_sub)
750 NULLIFY (work_matrices%A_ia_munu_sub)
751
752 NULLIFY (work_matrices%ewald_env)
753 NULLIFY (work_matrices%ewald_pw)
754
755 NULLIFY (work_matrices%hartree_local)
756 NULLIFY (work_matrices%local_rho_set)
757 NULLIFY (work_matrices%local_rho_set_admm)
758 NULLIFY (work_matrices%rho_xc_struct_sub)
759
760 CALL timestop(handle)
761
762 END SUBROUTINE stda_create_work_matrices
763
764! **************************************************************************************************
765!> \brief Release work matrices.
766!> \param work_matrices work matrices (destroyed on exit)
767!> \param sub_env parallel group environment
768!> \par History
769!> * 02.2017 created [Sergey Chulkov]
770! **************************************************************************************************
771 SUBROUTINE tddfpt_release_work_matrices(work_matrices, sub_env)
772 TYPE(tddfpt_work_matrices), INTENT(inout) :: work_matrices
773 TYPE(tddfpt_subgroup_env_type), INTENT(in) :: sub_env
774
775 CHARACTER(LEN=*), PARAMETER :: routinen = 'tddfpt_release_work_matrices'
776
777 INTEGER :: handle, ispin
778 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
779
780 CALL timeset(routinen, handle)
781
782 ! HFX-related matrices
783 IF (ASSOCIATED(work_matrices%hfx_hmat_symm)) THEN
784 DO ispin = SIZE(work_matrices%hfx_hmat_symm), 1, -1
785 CALL dbcsr_deallocate_matrix(work_matrices%hfx_hmat_symm(ispin)%matrix)
786 END DO
787 DEALLOCATE (work_matrices%hfx_hmat_symm)
788 END IF
789
790 IF (ASSOCIATED(work_matrices%hfx_hmat_asymm)) THEN
791 DO ispin = SIZE(work_matrices%hfx_hmat_asymm), 1, -1
792 CALL dbcsr_deallocate_matrix(work_matrices%hfx_hmat_asymm(ispin)%matrix)
793 END DO
794 DEALLOCATE (work_matrices%hfx_hmat_asymm)
795 END IF
796
797 IF (ASSOCIATED(work_matrices%hfx_rho_ao_symm)) THEN
798 DO ispin = SIZE(work_matrices%hfx_rho_ao_symm), 1, -1
799 CALL dbcsr_deallocate_matrix(work_matrices%hfx_rho_ao_symm(ispin)%matrix)
800 END DO
801 DEALLOCATE (work_matrices%hfx_rho_ao_symm)
802 END IF
803
804 IF (ASSOCIATED(work_matrices%hfx_rho_ao_asymm)) THEN
805 DO ispin = SIZE(work_matrices%hfx_rho_ao_asymm), 1, -1
806 CALL dbcsr_deallocate_matrix(work_matrices%hfx_rho_ao_asymm(ispin)%matrix)
807 END DO
808 DEALLOCATE (work_matrices%hfx_rho_ao_asymm)
809 END IF
810
811 IF (ASSOCIATED(work_matrices%hfx_fm_ao_ao)) THEN
812 CALL cp_fm_release(work_matrices%hfx_fm_ao_ao)
813 DEALLOCATE (work_matrices%hfx_fm_ao_ao)
814 END IF
815
816 ! HFXSR-related matrices
817 IF (ASSOCIATED(work_matrices%hfxsr_hmat_symm)) THEN
818 DO ispin = SIZE(work_matrices%hfxsr_hmat_symm), 1, -1
819 CALL dbcsr_deallocate_matrix(work_matrices%hfxsr_hmat_symm(ispin)%matrix)
820 END DO
821 DEALLOCATE (work_matrices%hfxsr_hmat_symm)
822 END IF
823
824 IF (ASSOCIATED(work_matrices%hfxsr_hmat_asymm)) THEN
825 DO ispin = SIZE(work_matrices%hfxsr_hmat_asymm), 1, -1
826 CALL dbcsr_deallocate_matrix(work_matrices%hfxsr_hmat_asymm(ispin)%matrix)
827 END DO
828 DEALLOCATE (work_matrices%hfxsr_hmat_asymm)
829 END IF
830
831 IF (ASSOCIATED(work_matrices%hfxsr_rho_ao_symm)) THEN
832 DO ispin = SIZE(work_matrices%hfxsr_rho_ao_symm), 1, -1
833 CALL dbcsr_deallocate_matrix(work_matrices%hfxsr_rho_ao_symm(ispin)%matrix)
834 END DO
835 DEALLOCATE (work_matrices%hfxsr_rho_ao_symm)
836 END IF
837
838 IF (ASSOCIATED(work_matrices%hfxsr_rho_ao_asymm)) THEN
839 DO ispin = SIZE(work_matrices%hfxsr_rho_ao_asymm), 1, -1
840 CALL dbcsr_deallocate_matrix(work_matrices%hfxsr_rho_ao_asymm(ispin)%matrix)
841 END DO
842 DEALLOCATE (work_matrices%hfxsr_rho_ao_asymm)
843 END IF
844
845 IF (ASSOCIATED(work_matrices%hfxsr_fm_ao_ao)) THEN
846 CALL cp_fm_release(work_matrices%hfxsr_fm_ao_ao)
847 DEALLOCATE (work_matrices%hfxsr_fm_ao_ao)
848 END IF
849
850 ! real-space and reciprocal-space grids
851 IF (ASSOCIATED(sub_env%pw_env)) THEN
852 CALL pw_env_get(sub_env%pw_env, auxbas_pw_pool=auxbas_pw_pool)
853 DO ispin = SIZE(work_matrices%wpw_rspace_sub), 1, -1
854 CALL auxbas_pw_pool%give_back_pw(work_matrices%wpw_rspace_sub(ispin))
855 CALL auxbas_pw_pool%give_back_pw(work_matrices%wpw_tau_rspace_sub(ispin))
856 CALL auxbas_pw_pool%give_back_pw(work_matrices%wpw_gspace_sub(ispin))
857 CALL auxbas_pw_pool%give_back_pw(work_matrices%A_ia_rspace_sub(ispin))
858 END DO
859 DEALLOCATE (work_matrices%A_ia_rspace_sub, work_matrices%wpw_gspace_sub, &
860 work_matrices%wpw_rspace_sub, work_matrices%wpw_tau_rspace_sub)
861 IF (ASSOCIATED(work_matrices%fxc_rspace_sub)) THEN
862 DO ispin = SIZE(work_matrices%fxc_rspace_sub), 1, -1
863 CALL auxbas_pw_pool%give_back_pw(work_matrices%fxc_rspace_sub(ispin))
864 END DO
865 DEALLOCATE (work_matrices%fxc_rspace_sub)
866 END IF
867 END IF
868
869 IF (ASSOCIATED(work_matrices%rho_aux_fit_struct_sub)) THEN
870 CALL qs_rho_release(work_matrices%rho_aux_fit_struct_sub)
871 DEALLOCATE (work_matrices%rho_aux_fit_struct_sub)
872 END IF
873 IF (ASSOCIATED(work_matrices%rho_orb_struct_sub)) THEN
874 CALL qs_rho_release(work_matrices%rho_orb_struct_sub)
875 DEALLOCATE (work_matrices%rho_orb_struct_sub)
876 END IF
877
878 IF (ASSOCIATED(work_matrices%A_ia_munu_sub)) THEN
879 DO ispin = SIZE(work_matrices%A_ia_munu_sub), 1, -1
880 CALL dbcsr_deallocate_matrix(work_matrices%A_ia_munu_sub(ispin)%matrix)
881 END DO
882 DEALLOCATE (work_matrices%A_ia_munu_sub)
883 END IF
884
885 IF (ASSOCIATED(work_matrices%wfm_aux_orb_sub)) THEN
886 CALL cp_fm_release(work_matrices%wfm_aux_orb_sub)
887 DEALLOCATE (work_matrices%wfm_aux_orb_sub)
888 NULLIFY (work_matrices%wfm_aux_orb_sub)
889 END IF
890 IF (ASSOCIATED(work_matrices%rho_ao_aux_fit_fm_sub)) THEN
891 CALL cp_fm_release(work_matrices%rho_ao_aux_fit_fm_sub)
892 DEALLOCATE (work_matrices%rho_ao_aux_fit_fm_sub)
893 NULLIFY (work_matrices%rho_ao_aux_fit_fm_sub)
894 END IF
895 IF (ASSOCIATED(work_matrices%rho_ao_orb_fm_sub)) THEN
896 CALL cp_fm_release(work_matrices%rho_ao_orb_fm_sub)
897 DEALLOCATE (work_matrices%rho_ao_orb_fm_sub)
898 NULLIFY (work_matrices%rho_ao_orb_fm_sub)
899 END IF
900
901 CALL cp_fm_release(work_matrices%Aop_evects_sub)
902 CALL cp_fm_release(work_matrices%evects_sub)
903
904 CALL cp_fm_release(work_matrices%S_C0)
905 CALL cp_fm_release(work_matrices%S_C0_C0T)
906
907 DO ispin = SIZE(work_matrices%fm_pool_ao_mo_occ), 1, -1
908 CALL fm_pool_release(work_matrices%fm_pool_ao_mo_occ(ispin)%pool)
909 END DO
910 DEALLOCATE (work_matrices%fm_pool_ao_mo_occ)
911
912 ! sTDA
913 IF (ASSOCIATED(work_matrices%gamma_exchange)) THEN
914 CALL dbcsr_deallocate_matrix_set(work_matrices%gamma_exchange)
915 NULLIFY (work_matrices%gamma_exchange)
916 END IF
917 IF (ASSOCIATED(work_matrices%ctransformed)) THEN
918 CALL cp_fm_release(work_matrices%ctransformed)
919 NULLIFY (work_matrices%ctransformed)
920 END IF
921 CALL dbcsr_release_p(work_matrices%shalf)
922 !
923 IF (ASSOCIATED(work_matrices%S_eigenvectors)) THEN
924 CALL cp_fm_release(work_matrices%S_eigenvectors)
925 DEALLOCATE (work_matrices%S_eigenvectors)
926 END IF
927 IF (ASSOCIATED(work_matrices%slambda)) THEN
928 CALL cp_fm_release(work_matrices%slambda)
929 DEALLOCATE (work_matrices%slambda)
930 END IF
931 IF (ASSOCIATED(work_matrices%S_eigenvalues)) &
932 DEALLOCATE (work_matrices%S_eigenvalues)
933 ! Ewald
934 IF (ASSOCIATED(work_matrices%ewald_env)) THEN
935 CALL ewald_env_release(work_matrices%ewald_env)
936 DEALLOCATE (work_matrices%ewald_env)
937 END IF
938 IF (ASSOCIATED(work_matrices%ewald_pw)) THEN
939 CALL ewald_pw_release(work_matrices%ewald_pw)
940 DEALLOCATE (work_matrices%ewald_pw)
941 END IF
942 ! GAPW
943 IF (ASSOCIATED(work_matrices%local_rho_set)) THEN
944 CALL local_rho_set_release(work_matrices%local_rho_set)
945 END IF
946 IF (ASSOCIATED(work_matrices%local_rho_set_admm)) THEN
947 CALL local_rho_set_release(work_matrices%local_rho_set_admm)
948 END IF
949 IF (ASSOCIATED(work_matrices%hartree_local)) THEN
950 CALL hartree_local_release(work_matrices%hartree_local)
951 END IF
952 ! GAPW_XC
953 IF (ASSOCIATED(work_matrices%rho_xc_struct_sub)) THEN
954 CALL qs_rho_release(work_matrices%rho_xc_struct_sub)
955 DEALLOCATE (work_matrices%rho_xc_struct_sub)
956 END IF
957
958 CALL timestop(handle)
959
960 END SUBROUTINE tddfpt_release_work_matrices
961
962END MODULE qs_tddfpt2_types
Types and set/get functions for auxiliary density matrix methods.
Definition admm_types.F:15
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.
Definition admm_types.F:593
Define the atomic kind types and their sub types.
methods related to the blacs parallel environment
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_release_p(matrix)
...
subroutine, public dbcsr_deallocate_matrix(matrix)
...
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_init_p(matrix)
...
subroutine, public dbcsr_complete_redistribute(matrix, redist)
...
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
pool for for elements that are retained and released
subroutine, public fm_pool_create_fm(pool, element, name)
returns an element, allocating it if none is in the pool
subroutine, public fm_pool_create(pool, el_struct)
creates a pool of elements
subroutine, public fm_pool_release(pool)
releases the given pool (see cp2k/doc/ReferenceCounting.html)
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
Definition cp_fm_types.F:15
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp)
creates a new full matrix with the given structure
subroutine, public ewald_env_release(ewald_env)
releases the given ewald_env (see doc/ReferenceCounting.html)
subroutine, public ewald_pw_release(ewald_pw)
releases the memory used by the ewald_pw
subroutine, public init_coulomb_local(hartree_local, natom)
...
subroutine, public hartree_local_release(hartree_local)
...
subroutine, public hartree_local_create(hartree_local)
...
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Interface to the message passing library MPI.
basic linear algebra operations for full matrixes
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
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, sab_cneo, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
Define the quickstep kind type and their sub types.
subroutine, public local_rho_set_create(local_rho_set)
...
subroutine, public local_rho_set_release(local_rho_set)
...
Define the neighbor list data types and the corresponding functionality.
subroutine, public rho0_s_grid_create(pw_env, rho0_mpole)
...
subroutine, public init_rho0(local_rho_set, qs_env, gapw_control, zcore)
...
subroutine, public allocate_rho_atom_internals(rho_atom_set, atomic_kind_set, qs_kind_set, dft_control, para_env)
...
methods of the rho structure (defined in qs_rho_types)
subroutine, public qs_rho_rebuild(rho, qs_env, rebuild_ao, rebuild_grids, admm, pw_env_external)
rebuilds rho (if necessary allocating and initializing it)
superstucture that hold various representations of the density and keeps track of which ones are vali...
subroutine, public qs_rho_set(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)
...
subroutine, public qs_rho_create(rho)
Allocates a new instance of rho.
subroutine, public qs_rho_release(rho_struct)
releases a rho_struct by decreasing the reference count by one and deallocating if it reaches 0 (to b...
subroutine, public tddfpt_dbcsr_create_by_dist(matrix, template, dbcsr_dist, sab)
Create a DBCSR matrix based on a template matrix, distribution object, and the list of neighbours.
subroutine, public hfxsr_create_work_matrices(work_matrices, qs_env, admm_env)
Allocate work matrices for hfxsr.
subroutine, public tddfpt_create_work_matrices(work_matrices, gs_mos, nstates, do_hfx, do_admm, do_hfxlr, do_exck, do_sf, qs_env, sub_env)
Allocate work matrices for full kernel.
subroutine, public tddfpt_release_work_matrices(work_matrices, sub_env)
Release work matrices.
subroutine, public stda_create_work_matrices(work_matrices, gs_mos, nstates, qs_env, sub_env)
Allocate work matrices for sTDA kernel.
stores some data used in wavefunction fitting
Definition admm_types.F:120
Provides all information about an atomic kind.
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
keeps the information about the structure of a full matrix
represent a full matrix
stores all the informations relevant to an mpi environment
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Provides all information about a quickstep kind.
keeps the density in various representations, keeping track of which ones are valid.
Ground state molecular orbitals.
Set of temporary ("work") matrices.