(git:ccc2433)
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-2024 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,&
11  USE atomic_kind_types, ONLY: atomic_kind_type
12  USE cp_blacs_env, ONLY: cp_blacs_env_type
13  USE cp_control_types, ONLY: dft_control_type
17  USE cp_fm_pool_types, ONLY: cp_fm_pool_p_type,&
22  cp_fm_struct_p_type,&
24  cp_fm_struct_type
25  USE cp_fm_types, ONLY: cp_fm_create,&
26  cp_fm_release,&
27  cp_fm_type
28  USE dbcsr_api, ONLY: &
29  dbcsr_complete_redistribute, dbcsr_create, dbcsr_deallocate_matrix, &
30  dbcsr_distribution_type, dbcsr_get_info, dbcsr_init_p, dbcsr_p_type, dbcsr_release_p, &
31  dbcsr_type, dbcsr_type_antisymmetric
33  ewald_environment_type
34  USE ewald_pw_types, ONLY: ewald_pw_release,&
35  ewald_pw_type
39  hartree_local_type
40  USE kinds, ONLY: dp
41  USE message_passing, ONLY: mp_para_env_type
42  USE parallel_gemm_api, ONLY: parallel_gemm
43  USE pw_env_types, ONLY: pw_env_get
44  USE pw_pool_types, ONLY: pw_pool_type
45  USE pw_types, ONLY: pw_c1d_gs_type,&
46  pw_r3d_rs_type
47  USE qs_environment_types, ONLY: get_qs_env,&
48  qs_environment_type
49  USE qs_kind_types, ONLY: qs_kind_type
52  local_rho_type
53  USE qs_neighbor_list_types, ONLY: neighbor_list_set_p_type
55  USE qs_rho0_methods, ONLY: init_rho0
58  USE qs_rho_types, ONLY: qs_rho_create,&
60  qs_rho_set,&
61  qs_rho_type
63  tddfpt_subgroup_env_type
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 
77  PUBLIC :: tddfpt_ground_state_mos, tddfpt_work_matrices
80 
81 ! **************************************************************************************************
82 !> \brief Ground state molecular orbitals.
83 !> \par History
84 !> * 06.2016 created [Sergey Chulkov]
85 ! **************************************************************************************************
86  TYPE tddfpt_ground_state_mos
87  !> occupied MOs stored in a matrix form [nao x nmo_occ]
88  TYPE(cp_fm_type), POINTER :: mos_occ
89  !> virtual MOs stored in a matrix form [nao x nmo_virt]
90  TYPE(cp_fm_type), POINTER :: mos_virt
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
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
103  END TYPE tddfpt_ground_state_mos
104 
105 ! **************************************************************************************************
106 !> \brief Set of temporary ("work") matrices.
107 !> \par History
108 !> * 01.2017 created [Sergey Chulkov]
109 ! **************************************************************************************************
110  TYPE tddfpt_work_matrices
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
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
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
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
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
153  !> electron density for XC in GAPW_XC
154  TYPE(qs_rho_type), POINTER :: rho_xc_struct_sub
155  !> electron density in terms of auxiliary basis set
156  TYPE(qs_rho_type), POINTER :: rho_aux_fit_struct_sub
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
159  !> group-specific copy of a reciprocal-space grid
160  TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: wpw_gspace_sub
161  !> group-specific copy of a real-space grid
162  TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: wpw_rspace_sub
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
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
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
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, hfx_rho_ao_asymm
177  !> exact exchange expressed in terms of auxiliary or primary basis set
178  TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: hfx_hmat_symm, hfx_hmat_asymm
179  !> SR exact exchage matrices
180  TYPE(cp_fm_type), POINTER :: hfxsr_fm_ao_ao
181  TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: hfxsr_rho_ao_symm, hfxsr_rho_ao_asymm
182  TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: hfxsr_hmat_symm, hfxsr_hmat_asymm
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
188  !Lowdin MO coefficients: NAO*NOCC
189  TYPE(cp_fm_type), DIMENSION(:), POINTER :: ctransformed
190  !S^1/2
191  TYPE(dbcsr_type), POINTER :: shalf
192  !Eigenvalues/eigenvectors of the overlap matrix, used in sTDA forces (Lowdin derivatives)
193  REAL(KIND=dp), DIMENSION(:), POINTER :: s_eigenvalues
194  TYPE(cp_fm_type), POINTER :: S_eigenvectors
195  TYPE(cp_fm_type), POINTER :: slambda
196  !Ewald environments
197  TYPE(ewald_environment_type), POINTER :: ewald_env
198  TYPE(ewald_pw_type), POINTER :: ewald_pw
199  !> GAPW local atomic grids
200  TYPE(hartree_local_type), POINTER :: hartree_local
201  TYPE(local_rho_type), POINTER :: local_rho_set
202  TYPE(local_rho_type), POINTER :: local_rho_set_admm
203  END TYPE tddfpt_work_matrices
204 
205 CONTAINS
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 qs_env Quickstep environment
218 !> \param sub_env parallel group environment
219 !> \par History
220 !> * 02.2017 created [Sergey Chulkov]
221 ! **************************************************************************************************
222  SUBROUTINE tddfpt_create_work_matrices(work_matrices, gs_mos, nstates, do_hfx, do_admm, &
223  do_hfxlr, do_exck, qs_env, sub_env)
224  TYPE(tddfpt_work_matrices), INTENT(out) :: work_matrices
225  TYPE(tddfpt_ground_state_mos), DIMENSION(:), &
226  INTENT(in) :: gs_mos
227  INTEGER, INTENT(in) :: nstates
228  LOGICAL, INTENT(in) :: do_hfx, do_admm, do_hfxlr, do_exck
229  TYPE(qs_environment_type), POINTER :: qs_env
230  TYPE(tddfpt_subgroup_env_type), INTENT(in) :: sub_env
231 
232  CHARACTER(LEN=*), PARAMETER :: routinen = 'tddfpt_create_work_matrices'
233 
234  INTEGER :: handle, igroup, ispin, istate, nao, &
235  nao_aux, natom, ngroups, nspins
236  INTEGER, DIMENSION(maxspins) :: nmo_occ, nmo_virt
237  TYPE(admm_type), POINTER :: admm_env
238  TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
239  TYPE(cp_blacs_env_type), POINTER :: blacs_env
240  TYPE(cp_fm_struct_p_type), DIMENSION(maxspins) :: fm_struct_evects
241  TYPE(cp_fm_struct_type), POINTER :: fm_struct
242  TYPE(dbcsr_distribution_type), POINTER :: dbcsr_dist
243  TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s, matrix_s_aux_fit, rho_ia_ao, &
244  rho_xc_ao
245  TYPE(dbcsr_type), POINTER :: dbcsr_template_hfx
246  TYPE(dft_control_type), POINTER :: dft_control
247  TYPE(mp_para_env_type), POINTER :: para_env
248  TYPE(neighbor_list_set_p_type), DIMENSION(:), &
249  POINTER :: sab_hfx
250  TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
251  TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
252 
253  CALL timeset(routinen, handle)
254 
255  ! sTDA
256  NULLIFY (work_matrices%shalf)
257  NULLIFY (work_matrices%ewald_env)
258  NULLIFY (work_matrices%ewald_pw)
259  NULLIFY (work_matrices%gamma_exchange)
260  NULLIFY (work_matrices%ctransformed)
261  NULLIFY (work_matrices%S_eigenvalues)
262  NULLIFY (work_matrices%S_eigenvectors)
263  NULLIFY (work_matrices%slambda)
264 
265  ! GAPW
266  NULLIFY (work_matrices%hartree_local)
267  NULLIFY (work_matrices%local_rho_set)
268  NULLIFY (work_matrices%local_rho_set_admm)
269 
270  ! EXCK
271  NULLIFY (work_matrices%rho_xc_struct_sub)
272 
273  nspins = SIZE(gs_mos)
274  CALL get_qs_env(qs_env, blacs_env=blacs_env, matrix_s=matrix_s)
275  CALL dbcsr_get_info(matrix_s(1)%matrix, nfullrows_total=nao)
276 
277  DO ispin = 1, nspins
278  nmo_occ(ispin) = SIZE(gs_mos(ispin)%evals_occ)
279  nmo_virt(ispin) = SIZE(gs_mos(ispin)%evals_virt)
280  END DO
281 
282  IF (do_admm) THEN
283  cpassert(do_hfx)
284  cpassert(ASSOCIATED(sub_env%admm_A))
285  CALL get_admm_env(qs_env%admm_env, matrix_s_aux_fit=matrix_s_aux_fit)
286  CALL dbcsr_get_info(matrix_s_aux_fit(1)%matrix, nfullrows_total=nao_aux)
287  END IF
288 
289  NULLIFY (fm_struct)
290  ALLOCATE (work_matrices%fm_pool_ao_mo_occ(nspins))
291  DO ispin = 1, nspins
292  NULLIFY (work_matrices%fm_pool_ao_mo_occ(ispin)%pool)
293  CALL cp_fm_struct_create(fm_struct, nrow_global=nao, ncol_global=nmo_occ(ispin), context=blacs_env)
294  CALL fm_pool_create(work_matrices%fm_pool_ao_mo_occ(ispin)%pool, fm_struct)
295  CALL cp_fm_struct_release(fm_struct)
296  END DO
297 
298  ALLOCATE (work_matrices%S_C0_C0T(nspins))
299  CALL cp_fm_struct_create(fm_struct, nrow_global=nao, ncol_global=nao, context=blacs_env)
300  DO ispin = 1, nspins
301  CALL cp_fm_create(work_matrices%S_C0_C0T(ispin), fm_struct)
302  END DO
303  CALL cp_fm_struct_release(fm_struct)
304 
305  ALLOCATE (work_matrices%S_C0(nspins))
306  DO ispin = 1, nspins
307  CALL fm_pool_create_fm(work_matrices%fm_pool_ao_mo_occ(ispin)%pool, work_matrices%S_C0(ispin))
308 
309  CALL cp_dbcsr_sm_fm_multiply(matrix_s(1)%matrix, gs_mos(ispin)%mos_occ, work_matrices%S_C0(ispin), &
310  ncol=nmo_occ(ispin), alpha=1.0_dp, beta=0.0_dp)
311  CALL parallel_gemm('N', 'T', nao, nao, nmo_occ(ispin), 1.0_dp, work_matrices%S_C0(ispin), &
312  gs_mos(ispin)%mos_occ, 0.0_dp, work_matrices%S_C0_C0T(ispin))
313  END DO
314 
315  IF (sub_env%is_split) THEN
316  DO ispin = 1, nspins
317  CALL cp_fm_struct_create(fm_struct_evects(ispin)%struct, nrow_global=nao, &
318  ncol_global=nmo_occ(ispin), context=sub_env%blacs_env)
319  END DO
320 
321  ALLOCATE (work_matrices%evects_sub(nspins, nstates), work_matrices%Aop_evects_sub(nspins, nstates))
322 
323  CALL blacs_env%get(para_env=para_env)
324  igroup = sub_env%group_distribution(para_env%mepos)
325  ngroups = sub_env%ngroups
326 
327  DO istate = ngroups - igroup, nstates, ngroups
328  DO ispin = 1, nspins
329  CALL cp_fm_create(work_matrices%evects_sub(ispin, istate), fm_struct_evects(ispin)%struct)
330  CALL cp_fm_create(work_matrices%Aop_evects_sub(ispin, istate), fm_struct_evects(ispin)%struct)
331  END DO
332  END DO
333 
334  DO ispin = nspins, 1, -1
335  CALL cp_fm_struct_release(fm_struct_evects(ispin)%struct)
336  END DO
337  END IF
338 
339  CALL cp_fm_struct_create(fm_struct, nrow_global=nao, ncol_global=nao, context=sub_env%blacs_env)
340  ALLOCATE (work_matrices%rho_ao_orb_fm_sub)
341  CALL cp_fm_create(work_matrices%rho_ao_orb_fm_sub, fm_struct)
342  CALL cp_fm_struct_release(fm_struct)
343 
344  NULLIFY (work_matrices%rho_ao_aux_fit_fm_sub, work_matrices%wfm_aux_orb_sub)
345  IF (do_admm) THEN
346  CALL cp_fm_struct_create(fm_struct, nrow_global=nao_aux, ncol_global=nao_aux, context=sub_env%blacs_env)
347  ALLOCATE (work_matrices%rho_ao_aux_fit_fm_sub)
348  CALL cp_fm_create(work_matrices%rho_ao_aux_fit_fm_sub, fm_struct)
349  CALL cp_fm_struct_release(fm_struct)
350 
351  CALL cp_fm_struct_create(fm_struct, nrow_global=nao_aux, ncol_global=nao, context=sub_env%blacs_env)
352  ALLOCATE (work_matrices%wfm_aux_orb_sub)
353  CALL cp_fm_create(work_matrices%wfm_aux_orb_sub, fm_struct)
354  CALL cp_fm_struct_release(fm_struct)
355  END IF
356 
357  ! group-specific dbcsr matrices
358  NULLIFY (work_matrices%A_ia_munu_sub)
359  CALL dbcsr_allocate_matrix_set(work_matrices%A_ia_munu_sub, nspins)
360  DO ispin = 1, nspins
361  CALL dbcsr_init_p(work_matrices%A_ia_munu_sub(ispin)%matrix)
362  CALL tddfpt_dbcsr_create_by_dist(work_matrices%A_ia_munu_sub(ispin)%matrix, template=matrix_s(1)%matrix, &
363  dbcsr_dist=sub_env%dbcsr_dist, sab=sub_env%sab_orb)
364  END DO
365 
366  ! group-specific response density
367  NULLIFY (rho_ia_ao)
368  CALL dbcsr_allocate_matrix_set(rho_ia_ao, nspins)
369  DO ispin = 1, nspins
370  CALL dbcsr_init_p(rho_ia_ao(ispin)%matrix)
371  CALL tddfpt_dbcsr_create_by_dist(rho_ia_ao(ispin)%matrix, template=matrix_s(1)%matrix, &
372  dbcsr_dist=sub_env%dbcsr_dist, sab=sub_env%sab_orb)
373  END DO
374 
375  NULLIFY (work_matrices%rho_orb_struct_sub)
376  ALLOCATE (work_matrices%rho_orb_struct_sub)
377  CALL qs_rho_create(work_matrices%rho_orb_struct_sub)
378  CALL qs_rho_set(work_matrices%rho_orb_struct_sub, rho_ao=rho_ia_ao)
379  CALL qs_rho_rebuild(work_matrices%rho_orb_struct_sub, qs_env, rebuild_ao=.false., &
380  rebuild_grids=.true., pw_env_external=sub_env%pw_env)
381  CALL get_qs_env(qs_env, dft_control=dft_control)
382  IF (dft_control%qs_control%gapw_xc) THEN
383  NULLIFY (rho_xc_ao)
384  CALL dbcsr_allocate_matrix_set(rho_xc_ao, nspins)
385  DO ispin = 1, nspins
386  CALL dbcsr_init_p(rho_xc_ao(ispin)%matrix)
387  CALL tddfpt_dbcsr_create_by_dist(rho_xc_ao(ispin)%matrix, template=matrix_s(1)%matrix, &
388  dbcsr_dist=sub_env%dbcsr_dist, sab=sub_env%sab_orb)
389  END DO
390  NULLIFY (work_matrices%rho_xc_struct_sub)
391  ALLOCATE (work_matrices%rho_xc_struct_sub)
392  CALL qs_rho_create(work_matrices%rho_xc_struct_sub)
393  CALL qs_rho_set(work_matrices%rho_xc_struct_sub, rho_ao=rho_xc_ao)
394  CALL qs_rho_rebuild(work_matrices%rho_xc_struct_sub, qs_env, rebuild_ao=.false., &
395  rebuild_grids=.true., pw_env_external=sub_env%pw_env)
396  END IF
397 
398  NULLIFY (work_matrices%rho_aux_fit_struct_sub)
399  IF (do_admm) THEN
400  NULLIFY (rho_ia_ao)
401  CALL dbcsr_allocate_matrix_set(rho_ia_ao, nspins)
402  DO ispin = 1, nspins
403  CALL dbcsr_init_p(rho_ia_ao(ispin)%matrix)
404  CALL tddfpt_dbcsr_create_by_dist(rho_ia_ao(ispin)%matrix, template=matrix_s_aux_fit(1)%matrix, &
405  dbcsr_dist=sub_env%dbcsr_dist, sab=sub_env%sab_aux_fit)
406  END DO
407 
408  ALLOCATE (work_matrices%rho_aux_fit_struct_sub)
409  CALL qs_rho_create(work_matrices%rho_aux_fit_struct_sub)
410  CALL qs_rho_set(work_matrices%rho_aux_fit_struct_sub, rho_ao=rho_ia_ao)
411  CALL qs_rho_rebuild(work_matrices%rho_aux_fit_struct_sub, qs_env, rebuild_ao=.false., &
412  rebuild_grids=.true., pw_env_external=sub_env%pw_env)
413  END IF
414 
415  ! work plain-wave grids
416  CALL pw_env_get(sub_env%pw_env, auxbas_pw_pool=auxbas_pw_pool)
417  ALLOCATE (work_matrices%A_ia_rspace_sub(nspins))
418  ALLOCATE (work_matrices%wpw_gspace_sub(nspins), work_matrices%wpw_rspace_sub(nspins), &
419  work_matrices%wpw_tau_rspace_sub(nspins))
420  DO ispin = 1, nspins
421  CALL auxbas_pw_pool%create_pw(work_matrices%A_ia_rspace_sub(ispin))
422  CALL auxbas_pw_pool%create_pw(work_matrices%wpw_gspace_sub(ispin))
423  CALL auxbas_pw_pool%create_pw(work_matrices%wpw_rspace_sub(ispin))
424  CALL auxbas_pw_pool%create_pw(work_matrices%wpw_tau_rspace_sub(ispin))
425  END DO
426 
427  ! fxc kernel potential real space grid
428  IF (do_exck) THEN
429  ! we need spins: aa, ab, bb
430  ALLOCATE (work_matrices%fxc_rspace_sub(3))
431  DO ispin = 1, 3
432  CALL auxbas_pw_pool%create_pw(work_matrices%fxc_rspace_sub(ispin))
433  END DO
434  ELSE
435  NULLIFY (work_matrices%fxc_rspace_sub)
436  END IF
437 
438  ! GAPW initializations
439  IF (dft_control%qs_control%gapw) THEN
440  CALL get_qs_env(qs_env, &
441  atomic_kind_set=atomic_kind_set, &
442  natom=natom, &
443  qs_kind_set=qs_kind_set)
444  CALL local_rho_set_create(work_matrices%local_rho_set)
445  CALL allocate_rho_atom_internals(work_matrices%local_rho_set%rho_atom_set, atomic_kind_set, &
446  qs_kind_set, dft_control, sub_env%para_env)
447  CALL init_rho0(work_matrices%local_rho_set, qs_env, dft_control%qs_control%gapw_control, &
448  zcore=0.0_dp)
449  CALL rho0_s_grid_create(sub_env%pw_env, work_matrices%local_rho_set%rho0_mpole)
450  CALL hartree_local_create(work_matrices%hartree_local)
451  CALL init_coulomb_local(work_matrices%hartree_local, natom)
452  ELSEIF (dft_control%qs_control%gapw_xc) THEN
453  CALL get_qs_env(qs_env, &
454  atomic_kind_set=atomic_kind_set, &
455  qs_kind_set=qs_kind_set)
456  CALL local_rho_set_create(work_matrices%local_rho_set)
457  CALL allocate_rho_atom_internals(work_matrices%local_rho_set%rho_atom_set, atomic_kind_set, &
458  qs_kind_set, dft_control, sub_env%para_env)
459  END IF
460 
461  ! HFX-related globally distributed matrices
462  NULLIFY (work_matrices%hfx_fm_ao_ao, work_matrices%hfx_rho_ao_symm, work_matrices%hfx_hmat_symm, &
463  work_matrices%hfx_rho_ao_asymm, work_matrices%hfx_hmat_asymm)
464  IF (do_hfx) THEN
465  IF (do_admm) THEN
466  CALL get_qs_env(qs_env, dbcsr_dist=dbcsr_dist)
467  CALL get_admm_env(qs_env%admm_env, sab_aux_fit=sab_hfx)
468  dbcsr_template_hfx => matrix_s_aux_fit(1)%matrix
469  IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc) THEN
470  CALL get_qs_env(qs_env, admm_env=admm_env, atomic_kind_set=atomic_kind_set)
471  CALL local_rho_set_create(work_matrices%local_rho_set_admm)
472  CALL allocate_rho_atom_internals(work_matrices%local_rho_set_admm%rho_atom_set, &
473  atomic_kind_set, admm_env%admm_gapw_env%admm_kind_set, &
474  dft_control, sub_env%para_env)
475  END IF
476  ELSE
477  CALL get_qs_env(qs_env, dbcsr_dist=dbcsr_dist, sab_orb=sab_hfx)
478  dbcsr_template_hfx => matrix_s(1)%matrix
479  END IF
480 
481  CALL cp_fm_struct_create(fm_struct, nrow_global=nao, ncol_global=nao, context=blacs_env)
482  ALLOCATE (work_matrices%hfx_fm_ao_ao)
483  CALL cp_fm_create(work_matrices%hfx_fm_ao_ao, fm_struct)
484  CALL cp_fm_struct_release(fm_struct)
485 
486  CALL dbcsr_allocate_matrix_set(work_matrices%hfx_rho_ao_symm, nspins)
487  CALL dbcsr_allocate_matrix_set(work_matrices%hfx_rho_ao_asymm, nspins)
488  DO ispin = 1, nspins
489  CALL dbcsr_init_p(work_matrices%hfx_rho_ao_symm(ispin)%matrix)
490  CALL tddfpt_dbcsr_create_by_dist(work_matrices%hfx_rho_ao_symm(ispin)%matrix, &
491  template=dbcsr_template_hfx, dbcsr_dist=dbcsr_dist, sab=sab_hfx)
492 
493  CALL dbcsr_init_p(work_matrices%hfx_rho_ao_asymm(ispin)%matrix)
494  CALL dbcsr_create(work_matrices%hfx_rho_ao_asymm(ispin)%matrix, matrix_type=dbcsr_type_antisymmetric, &
495  template=work_matrices%hfx_rho_ao_symm(ispin)%matrix)
496  CALL dbcsr_complete_redistribute(work_matrices%hfx_rho_ao_symm(ispin)%matrix, &
497  work_matrices%hfx_rho_ao_asymm(ispin)%matrix)
498  END DO
499 
500  CALL dbcsr_allocate_matrix_set(work_matrices%hfx_hmat_symm, nspins)
501  CALL dbcsr_allocate_matrix_set(work_matrices%hfx_hmat_asymm, nspins)
502  DO ispin = 1, nspins
503  CALL dbcsr_init_p(work_matrices%hfx_hmat_symm(ispin)%matrix)
504  CALL tddfpt_dbcsr_create_by_dist(work_matrices%hfx_hmat_symm(ispin)%matrix, &
505  template=dbcsr_template_hfx, dbcsr_dist=dbcsr_dist, sab=sab_hfx)
506 
507  CALL dbcsr_init_p(work_matrices%hfx_hmat_asymm(ispin)%matrix)
508  CALL dbcsr_create(work_matrices%hfx_hmat_asymm(ispin)%matrix, matrix_type=dbcsr_type_antisymmetric, &
509  template=work_matrices%hfx_hmat_symm(ispin)%matrix)
510  CALL dbcsr_complete_redistribute(work_matrices%hfx_hmat_symm(ispin)%matrix, &
511  work_matrices%hfx_hmat_asymm(ispin)%matrix)
512  END DO
513  END IF
514 
515  ! matrices needed to do HFX short range calllculations
516  NULLIFY (work_matrices%hfxsr_fm_ao_ao, work_matrices%hfxsr_rho_ao_symm, work_matrices%hfxsr_hmat_symm, &
517  work_matrices%hfxsr_rho_ao_asymm, work_matrices%hfxsr_hmat_asymm)
518  ! matrices needed to do HFX long range calllculations
519  IF (do_hfxlr) THEN
520  DO ispin = 1, nspins
521  CALL cp_fm_struct_create(fm_struct_evects(ispin)%struct, nrow_global=nao, &
522  ncol_global=nmo_occ(ispin), context=sub_env%blacs_env)
523  END DO
524  CALL dbcsr_init_p(work_matrices%shalf)
525  CALL dbcsr_create(work_matrices%shalf, template=matrix_s(1)%matrix)
526  ALLOCATE (work_matrices%ctransformed(nspins))
527  DO ispin = 1, nspins
528  CALL cp_fm_create(work_matrices%ctransformed(ispin), fm_struct_evects(ispin)%struct)
529  END DO
530  ! forces
531  ALLOCATE (work_matrices%S_eigenvalues(nao))
532  NULLIFY (fm_struct)
533  CALL cp_fm_struct_create(fm_struct, nrow_global=nao, ncol_global=nao, context=blacs_env)
534  ALLOCATE (work_matrices%S_eigenvectors, work_matrices%slambda)
535  CALL cp_fm_create(work_matrices%S_eigenvectors, fm_struct)
536  CALL cp_fm_create(work_matrices%slambda, fm_struct)
537  !
538  CALL cp_fm_struct_release(fm_struct)
539  DO ispin = 1, nspins
540  CALL cp_fm_struct_release(fm_struct_evects(ispin)%struct)
541  END DO
542  END IF
543 
544  CALL timestop(handle)
545 
546  END SUBROUTINE tddfpt_create_work_matrices
547 
548 ! **************************************************************************************************
549 !> \brief Allocate work matrices for hfxsr
550 !> \param work_matrices work matrices (allocated on exit)
551 !> \param qs_env ...
552 !> \param admm_env ...
553 ! **************************************************************************************************
554  SUBROUTINE hfxsr_create_work_matrices(work_matrices, qs_env, admm_env)
555  TYPE(tddfpt_work_matrices), INTENT(inout) :: work_matrices
556  TYPE(qs_environment_type), POINTER :: qs_env
557  TYPE(admm_type), POINTER :: admm_env
558 
559  CHARACTER(LEN=*), PARAMETER :: routinen = 'hfxsr_create_work_matrices'
560 
561  INTEGER :: handle, ispin, nao, nao_aux, nspins
562  TYPE(cp_blacs_env_type), POINTER :: blacs_env
563  TYPE(cp_fm_struct_type), POINTER :: fm_struct
564  TYPE(dbcsr_distribution_type), POINTER :: dbcsr_dist
565  TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s, matrix_s_aux_fit
566  TYPE(dbcsr_type), POINTER :: dbcsr_template_hfx
567  TYPE(dft_control_type), POINTER :: dft_control
568  TYPE(neighbor_list_set_p_type), DIMENSION(:), &
569  POINTER :: sab_hfx
570 
571  CALL timeset(routinen, handle)
572 
573  ! matrices needed to do HFX short range calllculations
574  NULLIFY (work_matrices%hfxsr_fm_ao_ao, work_matrices%hfxsr_rho_ao_symm, work_matrices%hfxsr_hmat_symm, &
575  work_matrices%hfxsr_rho_ao_asymm, work_matrices%hfxsr_hmat_asymm)
576 
577  CALL get_qs_env(qs_env, dft_control=dft_control, matrix_s=matrix_s, &
578  blacs_env=blacs_env, dbcsr_dist=dbcsr_dist)
579  nspins = dft_control%nspins
580  CALL dbcsr_get_info(matrix_s(1)%matrix, nfullrows_total=nao)
581  CALL get_admm_env(admm_env, matrix_s_aux_fit=matrix_s_aux_fit)
582  dbcsr_template_hfx => matrix_s_aux_fit(1)%matrix
583  CALL dbcsr_get_info(dbcsr_template_hfx, nfullrows_total=nao_aux)
584 
585  CALL cp_fm_struct_create(fm_struct, nrow_global=nao, ncol_global=nao, context=blacs_env)
586  ALLOCATE (work_matrices%hfxsr_fm_ao_ao)
587  CALL cp_fm_create(work_matrices%hfxsr_fm_ao_ao, fm_struct)
588  CALL cp_fm_struct_release(fm_struct)
589 
590  CALL get_admm_env(admm_env, sab_aux_fit=sab_hfx)
591  CALL dbcsr_allocate_matrix_set(work_matrices%hfxsr_rho_ao_symm, nspins)
592  CALL dbcsr_allocate_matrix_set(work_matrices%hfxsr_rho_ao_asymm, nspins)
593  DO ispin = 1, nspins
594  CALL dbcsr_init_p(work_matrices%hfxsr_rho_ao_symm(ispin)%matrix)
595  CALL tddfpt_dbcsr_create_by_dist(work_matrices%hfxsr_rho_ao_symm(ispin)%matrix, &
596  template=dbcsr_template_hfx, dbcsr_dist=dbcsr_dist, sab=sab_hfx)
597 
598  CALL dbcsr_init_p(work_matrices%hfxsr_rho_ao_asymm(ispin)%matrix)
599  CALL dbcsr_create(work_matrices%hfxsr_rho_ao_asymm(ispin)%matrix, matrix_type=dbcsr_type_antisymmetric, &
600  template=work_matrices%hfxsr_rho_ao_symm(ispin)%matrix)
601  CALL dbcsr_complete_redistribute(work_matrices%hfxsr_rho_ao_symm(ispin)%matrix, &
602  work_matrices%hfxsr_rho_ao_asymm(ispin)%matrix)
603  END DO
604 
605  CALL dbcsr_allocate_matrix_set(work_matrices%hfxsr_hmat_symm, nspins)
606  CALL dbcsr_allocate_matrix_set(work_matrices%hfxsr_hmat_asymm, nspins)
607  DO ispin = 1, nspins
608  CALL dbcsr_init_p(work_matrices%hfxsr_hmat_symm(ispin)%matrix)
609  CALL tddfpt_dbcsr_create_by_dist(work_matrices%hfxsr_hmat_symm(ispin)%matrix, &
610  template=dbcsr_template_hfx, dbcsr_dist=dbcsr_dist, sab=sab_hfx)
611 
612  CALL dbcsr_init_p(work_matrices%hfxsr_hmat_asymm(ispin)%matrix)
613  CALL dbcsr_create(work_matrices%hfxsr_hmat_asymm(ispin)%matrix, matrix_type=dbcsr_type_antisymmetric, &
614  template=work_matrices%hfxsr_hmat_symm(ispin)%matrix)
615  CALL dbcsr_complete_redistribute(work_matrices%hfxsr_hmat_symm(ispin)%matrix, &
616  work_matrices%hfxsr_hmat_asymm(ispin)%matrix)
617  END DO
618 
619  CALL timestop(handle)
620 
621  END SUBROUTINE hfxsr_create_work_matrices
622 
623 ! **************************************************************************************************
624 !> \brief Allocate work matrices for sTDA kernel
625 !> \param work_matrices work matrices (allocated on exit)
626 !> \param gs_mos occupied and virtual molecular orbitals optimised for the ground state
627 !> \param nstates number of excited states to converge
628 !> \param qs_env Quickstep environment
629 !> \param sub_env parallel group environment
630 !> \par History
631 !> * 04.2019 created from full kernel version [JHU]
632 ! **************************************************************************************************
633  SUBROUTINE stda_create_work_matrices(work_matrices, gs_mos, nstates, qs_env, sub_env)
634  TYPE(tddfpt_work_matrices), INTENT(out) :: work_matrices
635  TYPE(tddfpt_ground_state_mos), DIMENSION(:), &
636  INTENT(in) :: gs_mos
637  INTEGER, INTENT(in) :: nstates
638  TYPE(qs_environment_type), POINTER :: qs_env
639  TYPE(tddfpt_subgroup_env_type), INTENT(in) :: sub_env
640 
641  CHARACTER(LEN=*), PARAMETER :: routinen = 'stda_create_work_matrices'
642 
643  INTEGER :: handle, igroup, ispin, istate, nao, &
644  ngroups, nspins
645  INTEGER, DIMENSION(maxspins) :: nmo_occ, nmo_virt
646  TYPE(cp_blacs_env_type), POINTER :: blacs_env
647  TYPE(cp_fm_struct_p_type), DIMENSION(maxspins) :: fm_struct_evects
648  TYPE(cp_fm_struct_type), POINTER :: fm_struct
649  TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
650  TYPE(mp_para_env_type), POINTER :: para_env
651 
652  CALL timeset(routinen, handle)
653 
654  NULLIFY (work_matrices%gamma_exchange, work_matrices%ctransformed)
655 
656  nspins = SIZE(gs_mos)
657  CALL get_qs_env(qs_env, blacs_env=blacs_env, matrix_s=matrix_s)
658  CALL dbcsr_get_info(matrix_s(1)%matrix, nfullrows_total=nao)
659 
660  DO ispin = 1, nspins
661  nmo_occ(ispin) = SIZE(gs_mos(ispin)%evals_occ)
662  nmo_virt(ispin) = SIZE(gs_mos(ispin)%evals_virt)
663  END DO
664 
665  NULLIFY (fm_struct)
666  ALLOCATE (work_matrices%fm_pool_ao_mo_occ(nspins))
667  DO ispin = 1, nspins
668  NULLIFY (work_matrices%fm_pool_ao_mo_occ(ispin)%pool)
669  CALL cp_fm_struct_create(fm_struct, nrow_global=nao, ncol_global=nmo_occ(ispin), context=blacs_env)
670  CALL fm_pool_create(work_matrices%fm_pool_ao_mo_occ(ispin)%pool, fm_struct)
671  CALL cp_fm_struct_release(fm_struct)
672  END DO
673 
674  ALLOCATE (work_matrices%S_C0_C0T(nspins))
675  CALL cp_fm_struct_create(fm_struct, nrow_global=nao, ncol_global=nao, context=blacs_env)
676  DO ispin = 1, nspins
677  CALL cp_fm_create(work_matrices%S_C0_C0T(ispin), fm_struct)
678  END DO
679  CALL cp_fm_struct_release(fm_struct)
680 
681  ALLOCATE (work_matrices%S_C0(nspins))
682  DO ispin = 1, nspins
683  CALL fm_pool_create_fm(work_matrices%fm_pool_ao_mo_occ(ispin)%pool, work_matrices%S_C0(ispin))
684 
685  CALL cp_dbcsr_sm_fm_multiply(matrix_s(1)%matrix, gs_mos(ispin)%mos_occ, work_matrices%S_C0(ispin), &
686  ncol=nmo_occ(ispin), alpha=1.0_dp, beta=0.0_dp)
687  CALL parallel_gemm('N', 'T', nao, nao, nmo_occ(ispin), 1.0_dp, work_matrices%S_C0(ispin), &
688  gs_mos(ispin)%mos_occ, 0.0_dp, work_matrices%S_C0_C0T(ispin))
689  END DO
690 
691  DO ispin = 1, nspins
692  CALL cp_fm_struct_create(fm_struct_evects(ispin)%struct, nrow_global=nao, &
693  ncol_global=nmo_occ(ispin), context=sub_env%blacs_env)
694  END DO
695 
696  IF (sub_env%is_split) THEN
697  ALLOCATE (work_matrices%evects_sub(nspins, nstates), work_matrices%Aop_evects_sub(nspins, nstates))
698 
699  CALL blacs_env%get(para_env=para_env)
700  igroup = sub_env%group_distribution(para_env%mepos)
701  ngroups = sub_env%ngroups
702 
703  DO istate = ngroups - igroup, nstates, ngroups
704  DO ispin = 1, nspins
705  CALL cp_fm_create(work_matrices%evects_sub(ispin, istate), fm_struct_evects(ispin)%struct)
706  CALL cp_fm_create(work_matrices%Aop_evects_sub(ispin, istate), fm_struct_evects(ispin)%struct)
707  END DO
708  END DO
709  END IF
710 
711  ! sTDA specific work arrays
712  ALLOCATE (work_matrices%ctransformed(nspins))
713  DO ispin = 1, nspins
714  CALL cp_fm_create(work_matrices%ctransformed(ispin), fm_struct_evects(ispin)%struct)
715  END DO
716  NULLIFY (work_matrices%shalf)
717  CALL dbcsr_init_p(work_matrices%shalf)
718  CALL dbcsr_create(work_matrices%shalf, template=matrix_s(1)%matrix)
719  ! forces
720  ALLOCATE (work_matrices%S_eigenvalues(nao))
721  NULLIFY (fm_struct)
722  CALL cp_fm_struct_create(fm_struct, nrow_global=nao, ncol_global=nao, context=blacs_env)
723  ALLOCATE (work_matrices%S_eigenvectors, work_matrices%slambda)
724  CALL cp_fm_create(work_matrices%S_eigenvectors, fm_struct)
725  CALL cp_fm_create(work_matrices%slambda, fm_struct)
726  CALL cp_fm_struct_release(fm_struct)
727 
728  DO ispin = nspins, 1, -1
729  CALL cp_fm_struct_release(fm_struct_evects(ispin)%struct)
730  END DO
731 
732  NULLIFY (work_matrices%rho_ao_orb_fm_sub)
733  NULLIFY (work_matrices%rho_ao_aux_fit_fm_sub, work_matrices%wfm_aux_orb_sub)
734  NULLIFY (work_matrices%rho_aux_fit_struct_sub)
735  NULLIFY (work_matrices%rho_orb_struct_sub)
736  NULLIFY (work_matrices%hfx_fm_ao_ao, work_matrices%hfx_rho_ao_symm, work_matrices%hfx_hmat_symm, &
737  work_matrices%hfx_rho_ao_asymm, work_matrices%hfx_hmat_asymm)
738  NULLIFY (work_matrices%hfxsr_fm_ao_ao, work_matrices%hfxsr_rho_ao_symm, work_matrices%hfxsr_hmat_symm, &
739  work_matrices%hfxsr_rho_ao_asymm, work_matrices%hfxsr_hmat_asymm)
740  NULLIFY (work_matrices%A_ia_rspace_sub, work_matrices%wpw_gspace_sub, &
741  work_matrices%wpw_rspace_sub)
742  NULLIFY (work_matrices%fxc_rspace_sub)
743  NULLIFY (work_matrices%A_ia_munu_sub)
744 
745  NULLIFY (work_matrices%ewald_env)
746  NULLIFY (work_matrices%ewald_pw)
747 
748  NULLIFY (work_matrices%hartree_local)
749  NULLIFY (work_matrices%local_rho_set)
750  NULLIFY (work_matrices%local_rho_set_admm)
751  NULLIFY (work_matrices%rho_xc_struct_sub)
752 
753  CALL timestop(handle)
754 
755  END SUBROUTINE stda_create_work_matrices
756 
757 ! **************************************************************************************************
758 !> \brief Release work matrices.
759 !> \param work_matrices work matrices (destroyed on exit)
760 !> \param sub_env parallel group environment
761 !> \par History
762 !> * 02.2017 created [Sergey Chulkov]
763 ! **************************************************************************************************
764  SUBROUTINE tddfpt_release_work_matrices(work_matrices, sub_env)
765  TYPE(tddfpt_work_matrices), INTENT(inout) :: work_matrices
766  TYPE(tddfpt_subgroup_env_type), INTENT(in) :: sub_env
767 
768  CHARACTER(LEN=*), PARAMETER :: routinen = 'tddfpt_release_work_matrices'
769 
770  INTEGER :: handle, ispin
771  TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
772 
773  CALL timeset(routinen, handle)
774 
775  ! HFX-related matrices
776  IF (ASSOCIATED(work_matrices%hfx_hmat_symm)) THEN
777  DO ispin = SIZE(work_matrices%hfx_hmat_symm), 1, -1
778  CALL dbcsr_deallocate_matrix(work_matrices%hfx_hmat_symm(ispin)%matrix)
779  END DO
780  DEALLOCATE (work_matrices%hfx_hmat_symm)
781  END IF
782 
783  IF (ASSOCIATED(work_matrices%hfx_hmat_asymm)) THEN
784  DO ispin = SIZE(work_matrices%hfx_hmat_asymm), 1, -1
785  CALL dbcsr_deallocate_matrix(work_matrices%hfx_hmat_asymm(ispin)%matrix)
786  END DO
787  DEALLOCATE (work_matrices%hfx_hmat_asymm)
788  END IF
789 
790  IF (ASSOCIATED(work_matrices%hfx_rho_ao_symm)) THEN
791  DO ispin = SIZE(work_matrices%hfx_rho_ao_symm), 1, -1
792  CALL dbcsr_deallocate_matrix(work_matrices%hfx_rho_ao_symm(ispin)%matrix)
793  END DO
794  DEALLOCATE (work_matrices%hfx_rho_ao_symm)
795  END IF
796 
797  IF (ASSOCIATED(work_matrices%hfx_rho_ao_asymm)) THEN
798  DO ispin = SIZE(work_matrices%hfx_rho_ao_asymm), 1, -1
799  CALL dbcsr_deallocate_matrix(work_matrices%hfx_rho_ao_asymm(ispin)%matrix)
800  END DO
801  DEALLOCATE (work_matrices%hfx_rho_ao_asymm)
802  END IF
803 
804  IF (ASSOCIATED(work_matrices%hfx_fm_ao_ao)) THEN
805  CALL cp_fm_release(work_matrices%hfx_fm_ao_ao)
806  DEALLOCATE (work_matrices%hfx_fm_ao_ao)
807  END IF
808 
809  ! HFXSR-related matrices
810  IF (ASSOCIATED(work_matrices%hfxsr_hmat_symm)) THEN
811  DO ispin = SIZE(work_matrices%hfxsr_hmat_symm), 1, -1
812  CALL dbcsr_deallocate_matrix(work_matrices%hfxsr_hmat_symm(ispin)%matrix)
813  END DO
814  DEALLOCATE (work_matrices%hfxsr_hmat_symm)
815  END IF
816 
817  IF (ASSOCIATED(work_matrices%hfxsr_hmat_asymm)) THEN
818  DO ispin = SIZE(work_matrices%hfxsr_hmat_asymm), 1, -1
819  CALL dbcsr_deallocate_matrix(work_matrices%hfxsr_hmat_asymm(ispin)%matrix)
820  END DO
821  DEALLOCATE (work_matrices%hfxsr_hmat_asymm)
822  END IF
823 
824  IF (ASSOCIATED(work_matrices%hfxsr_rho_ao_symm)) THEN
825  DO ispin = SIZE(work_matrices%hfxsr_rho_ao_symm), 1, -1
826  CALL dbcsr_deallocate_matrix(work_matrices%hfxsr_rho_ao_symm(ispin)%matrix)
827  END DO
828  DEALLOCATE (work_matrices%hfxsr_rho_ao_symm)
829  END IF
830 
831  IF (ASSOCIATED(work_matrices%hfxsr_rho_ao_asymm)) THEN
832  DO ispin = SIZE(work_matrices%hfxsr_rho_ao_asymm), 1, -1
833  CALL dbcsr_deallocate_matrix(work_matrices%hfxsr_rho_ao_asymm(ispin)%matrix)
834  END DO
835  DEALLOCATE (work_matrices%hfxsr_rho_ao_asymm)
836  END IF
837 
838  IF (ASSOCIATED(work_matrices%hfxsr_fm_ao_ao)) THEN
839  CALL cp_fm_release(work_matrices%hfxsr_fm_ao_ao)
840  DEALLOCATE (work_matrices%hfxsr_fm_ao_ao)
841  END IF
842 
843  ! real-space and reciprocal-space grids
844  IF (ASSOCIATED(sub_env%pw_env)) THEN
845  CALL pw_env_get(sub_env%pw_env, auxbas_pw_pool=auxbas_pw_pool)
846  DO ispin = SIZE(work_matrices%wpw_rspace_sub), 1, -1
847  CALL auxbas_pw_pool%give_back_pw(work_matrices%wpw_rspace_sub(ispin))
848  CALL auxbas_pw_pool%give_back_pw(work_matrices%wpw_tau_rspace_sub(ispin))
849  CALL auxbas_pw_pool%give_back_pw(work_matrices%wpw_gspace_sub(ispin))
850  CALL auxbas_pw_pool%give_back_pw(work_matrices%A_ia_rspace_sub(ispin))
851  END DO
852  DEALLOCATE (work_matrices%A_ia_rspace_sub, work_matrices%wpw_gspace_sub, &
853  work_matrices%wpw_rspace_sub, work_matrices%wpw_tau_rspace_sub)
854  IF (ASSOCIATED(work_matrices%fxc_rspace_sub)) THEN
855  DO ispin = SIZE(work_matrices%fxc_rspace_sub), 1, -1
856  CALL auxbas_pw_pool%give_back_pw(work_matrices%fxc_rspace_sub(ispin))
857  END DO
858  DEALLOCATE (work_matrices%fxc_rspace_sub)
859  END IF
860  END IF
861 
862  IF (ASSOCIATED(work_matrices%rho_aux_fit_struct_sub)) THEN
863  CALL qs_rho_release(work_matrices%rho_aux_fit_struct_sub)
864  DEALLOCATE (work_matrices%rho_aux_fit_struct_sub)
865  END IF
866  IF (ASSOCIATED(work_matrices%rho_orb_struct_sub)) THEN
867  CALL qs_rho_release(work_matrices%rho_orb_struct_sub)
868  DEALLOCATE (work_matrices%rho_orb_struct_sub)
869  END IF
870 
871  IF (ASSOCIATED(work_matrices%A_ia_munu_sub)) THEN
872  DO ispin = SIZE(work_matrices%A_ia_munu_sub), 1, -1
873  CALL dbcsr_deallocate_matrix(work_matrices%A_ia_munu_sub(ispin)%matrix)
874  END DO
875  DEALLOCATE (work_matrices%A_ia_munu_sub)
876  END IF
877 
878  IF (ASSOCIATED(work_matrices%wfm_aux_orb_sub)) THEN
879  CALL cp_fm_release(work_matrices%wfm_aux_orb_sub)
880  DEALLOCATE (work_matrices%wfm_aux_orb_sub)
881  NULLIFY (work_matrices%wfm_aux_orb_sub)
882  END IF
883  IF (ASSOCIATED(work_matrices%rho_ao_aux_fit_fm_sub)) THEN
884  CALL cp_fm_release(work_matrices%rho_ao_aux_fit_fm_sub)
885  DEALLOCATE (work_matrices%rho_ao_aux_fit_fm_sub)
886  NULLIFY (work_matrices%rho_ao_aux_fit_fm_sub)
887  END IF
888  IF (ASSOCIATED(work_matrices%rho_ao_orb_fm_sub)) THEN
889  CALL cp_fm_release(work_matrices%rho_ao_orb_fm_sub)
890  DEALLOCATE (work_matrices%rho_ao_orb_fm_sub)
891  NULLIFY (work_matrices%rho_ao_orb_fm_sub)
892  END IF
893 
894  CALL cp_fm_release(work_matrices%Aop_evects_sub)
895  CALL cp_fm_release(work_matrices%evects_sub)
896 
897  CALL cp_fm_release(work_matrices%S_C0)
898  CALL cp_fm_release(work_matrices%S_C0_C0T)
899 
900  DO ispin = SIZE(work_matrices%fm_pool_ao_mo_occ), 1, -1
901  CALL fm_pool_release(work_matrices%fm_pool_ao_mo_occ(ispin)%pool)
902  END DO
903  DEALLOCATE (work_matrices%fm_pool_ao_mo_occ)
904 
905  ! sTDA
906  IF (ASSOCIATED(work_matrices%gamma_exchange)) THEN
907  CALL dbcsr_deallocate_matrix_set(work_matrices%gamma_exchange)
908  NULLIFY (work_matrices%gamma_exchange)
909  END IF
910  IF (ASSOCIATED(work_matrices%ctransformed)) THEN
911  CALL cp_fm_release(work_matrices%ctransformed)
912  NULLIFY (work_matrices%ctransformed)
913  END IF
914  CALL dbcsr_release_p(work_matrices%shalf)
915  !
916  IF (ASSOCIATED(work_matrices%S_eigenvectors)) THEN
917  CALL cp_fm_release(work_matrices%S_eigenvectors)
918  DEALLOCATE (work_matrices%S_eigenvectors)
919  END IF
920  IF (ASSOCIATED(work_matrices%slambda)) THEN
921  CALL cp_fm_release(work_matrices%slambda)
922  DEALLOCATE (work_matrices%slambda)
923  END IF
924  IF (ASSOCIATED(work_matrices%S_eigenvalues)) &
925  DEALLOCATE (work_matrices%S_eigenvalues)
926  ! Ewald
927  IF (ASSOCIATED(work_matrices%ewald_env)) THEN
928  CALL ewald_env_release(work_matrices%ewald_env)
929  DEALLOCATE (work_matrices%ewald_env)
930  END IF
931  IF (ASSOCIATED(work_matrices%ewald_pw)) THEN
932  CALL ewald_pw_release(work_matrices%ewald_pw)
933  DEALLOCATE (work_matrices%ewald_pw)
934  END IF
935  ! GAPW
936  IF (ASSOCIATED(work_matrices%local_rho_set)) THEN
937  CALL local_rho_set_release(work_matrices%local_rho_set)
938  END IF
939  IF (ASSOCIATED(work_matrices%local_rho_set_admm)) THEN
940  CALL local_rho_set_release(work_matrices%local_rho_set_admm)
941  END IF
942  IF (ASSOCIATED(work_matrices%hartree_local)) THEN
943  CALL hartree_local_release(work_matrices%hartree_local)
944  END IF
945  ! GAPW_XC
946  IF (ASSOCIATED(work_matrices%rho_xc_struct_sub)) THEN
947  CALL qs_rho_release(work_matrices%rho_xc_struct_sub)
948  DEALLOCATE (work_matrices%rho_xc_struct_sub)
949  END IF
950 
951  CALL timestop(handle)
952 
953  END SUBROUTINE tddfpt_release_work_matrices
954 
955 END 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
Definition: cp_blacs_env.F:15
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
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
Definition: cp_fm_struct.F:14
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
Definition: cp_fm_struct.F:125
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
Definition: cp_fm_struct.F:320
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
Definition: cp_fm_types.F:167
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
Definition: pw_env_types.F:14
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
Definition: pw_env_types.F:113
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Definition: pw_pool_types.F:24
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.
Define the quickstep kind type and their sub types.
Definition: qs_kind_types.F:23
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...
Definition: qs_rho_types.F:18
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)
...
Definition: qs_rho_types.F:308
subroutine, public qs_rho_create(rho)
Allocates a new instance of rho.
Definition: qs_rho_types.F:99
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...
Definition: qs_rho_types.F:113
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_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.
subroutine, public tddfpt_create_work_matrices(work_matrices, gs_mos, nstates, do_hfx, do_admm, do_hfxlr, do_exck, qs_env, sub_env)
Allocate work matrices for full kernel.