Line data Source code
1 : !--------------------------------------------------------------------------------------------------!
2 : ! CP2K: A general program to perform molecular dynamics simulations !
3 : ! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4 : ! !
5 : ! SPDX-License-Identifier: GPL-2.0-or-later !
6 : !--------------------------------------------------------------------------------------------------!
7 : MODULE qs_rho_atom_methods
8 :
9 : USE atomic_kind_types, ONLY: atomic_kind_type,&
10 : get_atomic_kind,&
11 : get_atomic_kind_set
12 : USE basis_set_types, ONLY: get_gto_basis_set,&
13 : gto_basis_set_p_type,&
14 : gto_basis_set_type
15 : USE cp_control_types, ONLY: dft_control_type,&
16 : gapw_control_type
17 : USE cp_dbcsr_api, ONLY: dbcsr_get_block_p,&
18 : dbcsr_p_type
19 : USE gaunt_coefficients, ONLY: real_gaunt_coefficients
20 : USE kinds, ONLY: dp
21 : USE kpoint_types, ONLY: get_kpoint_info,&
22 : kpoint_type
23 : USE lebedev, ONLY: deallocate_lebedev_grids,&
24 : get_number_of_lebedev_grid,&
25 : init_lebedev_grids,&
26 : lebedev_grid
27 : USE mathconstants, ONLY: fourpi,&
28 : pi
29 : USE memory_utilities, ONLY: reallocate
30 : USE message_passing, ONLY: mp_para_env_type
31 : USE orbital_pointers, ONLY: indso,&
32 : nsoset
33 : USE paw_basis_types, ONLY: get_paw_basis_info
34 : USE qs_environment_types, ONLY: get_qs_env,&
35 : qs_environment_type
36 : USE qs_grid_atom, ONLY: create_grid_atom,&
37 : grid_atom_type
38 : USE qs_harmonics_atom, ONLY: create_harmonics_atom,&
39 : get_maxl_CG,&
40 : get_none0_cg_list,&
41 : harmonics_atom_type
42 : USE qs_kind_types, ONLY: get_qs_kind,&
43 : get_qs_kind_set,&
44 : qs_kind_type
45 : USE qs_neighbor_list_types, ONLY: neighbor_list_set_p_type,&
46 : neighbor_list_task_type
47 : USE qs_oce_methods, ONLY: proj_blk
48 : USE qs_oce_types, ONLY: oce_matrix_type
49 : USE qs_rho_atom_types, ONLY: deallocate_rho_atom_set,&
50 : rho_atom_coeff,&
51 : rho_atom_type
52 : USE sap_kind_types, ONLY: alist_pre_align_blk,&
53 : alist_type,&
54 : clist_type,&
55 : get_alist
56 : USE util, ONLY: get_limit
57 : USE whittaker, ONLY: whittaker_c0a,&
58 : whittaker_ci
59 :
60 : !$ USE OMP_LIB, ONLY: omp_lock_kind, &
61 : !$ omp_init_lock, omp_set_lock, &
62 : !$ omp_unset_lock, omp_destroy_lock
63 :
64 : #include "./base/base_uses.f90"
65 :
66 : IMPLICIT NONE
67 :
68 : PRIVATE
69 :
70 : ! *** Global parameters (only in this module)
71 :
72 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_rho_atom_methods'
73 : INTEGER, PARAMETER, PRIVATE :: l2_chunk_dp = 16000
74 :
75 : ! *** Public subroutines ***
76 :
77 : PUBLIC :: allocate_rho_atom_internals, &
78 : calculate_rho_atom, &
79 : calculate_rho_atom_coeff, &
80 : init_rho_atom, &
81 : replicate_rho_atom_radial
82 :
83 : CONTAINS
84 :
85 : ! **************************************************************************************************
86 : !> \brief ...
87 : !> \param para_env ...
88 : !> \param rho_atom_set ...
89 : !> \param qs_kind ...
90 : !> \param atom_list ...
91 : !> \param natom ...
92 : !> \param nspins ...
93 : !> \param tot_rho1_h ...
94 : !> \param tot_rho1_s ...
95 : !> \param rho1_h_spin ...
96 : !> \param rho1_s_spin ...
97 : !> \param rho1_h_aspin ...
98 : !> \param rho1_s_aspin ...
99 : ! **************************************************************************************************
100 81056 : SUBROUTINE calculate_rho_atom(para_env, rho_atom_set, qs_kind, atom_list, &
101 81056 : natom, nspins, tot_rho1_h, tot_rho1_s, &
102 : rho1_h_spin, rho1_s_spin, rho1_h_aspin, rho1_s_aspin)
103 :
104 : TYPE(mp_para_env_type), POINTER :: para_env
105 : TYPE(rho_atom_type), DIMENSION(:), POINTER :: rho_atom_set
106 : TYPE(qs_kind_type), INTENT(IN) :: qs_kind
107 : INTEGER, DIMENSION(:), INTENT(IN) :: atom_list
108 : INTEGER, INTENT(IN) :: natom, nspins
109 : REAL(dp), DIMENSION(:), INTENT(INOUT) :: tot_rho1_h, tot_rho1_s
110 : REAL(dp), INTENT(INOUT) :: rho1_h_spin, rho1_s_spin, rho1_h_aspin, &
111 : rho1_s_aspin
112 :
113 : CHARACTER(len=*), PARAMETER :: routineN = 'calculate_rho_atom'
114 :
115 : INTEGER :: damax_iso_not0_local, handle, i, i1, i2, iat, iatom, icg, ipgf1, ipgf2, ir, &
116 : iset1, iset2, iso, iso1, iso1_coeff, iso1_first, iso1_last, iso2, iso2_coeff, iso2_first, &
117 : iso2_last, j, l, l_iso, l_sub, l_sum, lmax12, lmax_expansion, lmin12, m1s, m2s, &
118 : max_iso_not0, max_iso_not0_local, max_npgf, max_s_harm, maxl, maxso, mepos, n1s, n2s, na, &
119 : nr, nset, num_pe, size1, size2
120 81056 : INTEGER, ALLOCATABLE, DIMENSION(:) :: cg_n_list, dacg_n_list
121 81056 : INTEGER, ALLOCATABLE, DIMENSION(:, :, :) :: cg_list, dacg_list
122 : INTEGER, DIMENSION(2) :: bo
123 81056 : INTEGER, DIMENSION(:), POINTER :: lmax, lmin, npgf, o2nindex
124 81056 : LOGICAL, ALLOCATABLE, DIMENSION(:, :) :: done_vgg
125 : REAL(dp) :: c1, c2, cpc_h, cpc_s, rfun, rho_h, &
126 : rho_s, root_zet12, zet12
127 81056 : REAL(dp), ALLOCATABLE, DIMENSION(:) :: erf_zet12, g1, g2, gg0, int1, int2
128 81056 : REAL(dp), ALLOCATABLE, DIMENSION(:, :) :: dgg, gg, gg_lm1, sfun_h, sfun_s
129 81056 : REAL(dp), ALLOCATABLE, DIMENSION(:, :, :) :: g_rad, vgg
130 81056 : REAL(dp), DIMENSION(:, :), POINTER :: coeff_h, coeff_s, zet
131 : REAL(dp), DIMENSION(:, :, :), POINTER :: my_CG
132 : REAL(dp), DIMENSION(:, :, :, :), POINTER :: my_CG_dxyz
133 : TYPE(grid_atom_type), POINTER :: grid_atom
134 : TYPE(gto_basis_set_type), POINTER :: basis_1c
135 : TYPE(harmonics_atom_type), POINTER :: harmonics
136 :
137 81056 : CALL timeset(routineN, handle)
138 :
139 : !Note: tau is taken care of separately in qs_vxc_atom.F
140 :
141 81056 : NULLIFY (basis_1c)
142 81056 : NULLIFY (harmonics, grid_atom)
143 81056 : NULLIFY (lmin, lmax, npgf, zet, my_CG, my_CG_dxyz, coeff_h, coeff_s)
144 :
145 81056 : CALL get_qs_kind(qs_kind, grid_atom=grid_atom, harmonics=harmonics)
146 81056 : CALL get_qs_kind(qs_kind, basis_set=basis_1c, basis_type="GAPW_1C")
147 :
148 : CALL get_gto_basis_set(gto_basis_set=basis_1c, lmax=lmax, lmin=lmin, &
149 : maxl=maxl, npgf=npgf, nset=nset, zet=zet, &
150 81056 : maxso=maxso)
151 :
152 81056 : CALL get_paw_basis_info(basis_1c, o2nindex=o2nindex)
153 :
154 81056 : max_iso_not0 = harmonics%max_iso_not0
155 81056 : max_s_harm = harmonics%max_s_harm
156 :
157 81056 : nr = grid_atom%nr
158 295452 : max_npgf = MAXVAL(npgf(1:nset))
159 81056 : lmax_expansion = indso(1, max_iso_not0)
160 : ! Distribute the atoms of this kind
161 81056 : num_pe = para_env%num_pe
162 81056 : mepos = para_env%mepos
163 81056 : bo = get_limit(natom, num_pe, mepos)
164 :
165 81056 : my_CG => harmonics%my_CG
166 81056 : my_CG_dxyz => harmonics%my_CG_dxyz
167 :
168 972672 : ALLOCATE (g1(nr), g2(nr), gg0(nr), gg(nr, 0:2*maxl), dgg(nr, 0:2*maxl), gg_lm1(nr, 0:2*maxl))
169 486336 : ALLOCATE (erf_zet12(nr), vgg(nr, 0:2*maxl, 0:indso(1, max_iso_not0)))
170 324224 : ALLOCATE (done_vgg(0:2*maxl, 0:indso(1, max_iso_not0)))
171 243168 : ALLOCATE (int1(nr), int2(nr))
172 : ALLOCATE (cg_list(2, nsoset(maxl)**2, max_s_harm), cg_n_list(max_s_harm), &
173 729504 : dacg_list(2, nsoset(maxl)**2, max_s_harm), dacg_n_list(max_s_harm))
174 405280 : ALLOCATE (g_rad(nr, max_npgf, nset))
175 :
176 295452 : DO iset1 = 1, nset
177 841944 : DO ipgf1 = 1, npgf(iset1)
178 29789144 : g_rad(1:nr, ipgf1, iset1) = EXP(-zet(ipgf1, iset1)*grid_atom%rad2(1:nr))
179 : END DO
180 : END DO
181 :
182 142730 : DO iat = bo(1), bo(2)
183 61674 : iatom = atom_list(iat)
184 212318 : DO i = 1, nspins
185 131262 : IF (.NOT. ASSOCIATED(rho_atom_set(iatom)%rho_rad_h(i)%r_coef)) THEN
186 8637 : CALL allocate_rho_atom_rad(rho_atom_set, iatom, i, nr, max_iso_not0)
187 : ELSE
188 60951 : CALL set2zero_rho_atom_rad(rho_atom_set, iatom, i)
189 : END IF
190 : END DO
191 : END DO
192 :
193 : m1s = 0
194 295452 : DO iset1 = 1, nset
195 : m2s = 0
196 969444 : DO iset2 = 1, nset
197 :
198 : CALL get_none0_cg_list(my_CG, lmin(iset1), lmax(iset1), lmin(iset2), lmax(iset2), &
199 755048 : max_s_harm, lmax_expansion, cg_list, cg_n_list, max_iso_not0_local)
200 755048 : CPASSERT(max_iso_not0_local <= max_iso_not0)
201 : CALL get_none0_cg_list(my_CG_dxyz, lmin(iset1), lmax(iset1), lmin(iset2), lmax(iset2), &
202 755048 : max_s_harm, lmax_expansion, dacg_list, dacg_n_list, damax_iso_not0_local)
203 755048 : n1s = nsoset(lmax(iset1))
204 :
205 2521334 : DO ipgf1 = 1, npgf(iset1)
206 1766286 : iso1_first = nsoset(lmin(iset1) - 1) + 1 + n1s*(ipgf1 - 1) + m1s
207 1766286 : iso1_last = nsoset(lmax(iset1)) + n1s*(ipgf1 - 1) + m1s
208 1766286 : size1 = iso1_last - iso1_first + 1
209 1766286 : iso1_first = o2nindex(iso1_first)
210 1766286 : iso1_last = o2nindex(iso1_last)
211 1766286 : i1 = iso1_last - iso1_first + 1
212 1766286 : CPASSERT(size1 == i1)
213 1766286 : i1 = nsoset(lmin(iset1) - 1) + 1
214 :
215 95000242 : g1(1:nr) = g_rad(1:nr, ipgf1, iset1)
216 :
217 1766286 : n2s = nsoset(lmax(iset2))
218 7497950 : DO ipgf2 = 1, npgf(iset2)
219 4976616 : iso2_first = nsoset(lmin(iset2) - 1) + 1 + n2s*(ipgf2 - 1) + m2s
220 4976616 : iso2_last = nsoset(lmax(iset2)) + n2s*(ipgf2 - 1) + m2s
221 4976616 : size2 = iso2_last - iso2_first + 1
222 4976616 : iso2_first = o2nindex(iso2_first)
223 4976616 : iso2_last = o2nindex(iso2_last)
224 4976616 : i2 = iso2_last - iso2_first + 1
225 4976616 : CPASSERT(size2 == i2)
226 4976616 : i2 = nsoset(lmin(iset2) - 1) + 1
227 :
228 268458840 : g2(1:nr) = g_rad(1:nr, ipgf2, iset2)
229 4976616 : lmin12 = lmin(iset1) + lmin(iset2)
230 4976616 : lmax12 = lmax(iset1) + lmax(iset2)
231 :
232 4976616 : zet12 = zet(ipgf1, iset1) + zet(ipgf2, iset2)
233 4976616 : root_zet12 = SQRT(zet(ipgf1, iset1) + zet(ipgf2, iset2))
234 268458840 : DO ir = 1, nr
235 268458840 : erf_zet12(ir) = erf(root_zet12*grid_atom%rad(ir))
236 : END DO
237 :
238 4976616 : gg = 0.0_dp
239 4976616 : dgg = 0.0_dp
240 4976616 : gg_lm1 = 0.0_dp
241 4976616 : vgg = 0.0_dp
242 4976616 : done_vgg = .FALSE.
243 : ! reduce the number of terms in the expansion local densities
244 4976616 : IF (lmin12 <= lmax_expansion) THEN
245 4974126 : IF (lmin12 == 0) THEN
246 145844980 : gg(1:nr, lmin12) = g1(1:nr)*g2(1:nr)
247 145844980 : gg_lm1(1:nr, lmin12) = 0.0_dp
248 145844980 : gg0(1:nr) = gg(1:nr, lmin12)
249 : ELSE
250 122486870 : gg0(1:nr) = g1(1:nr)*g2(1:nr)
251 122486870 : gg(1:nr, lmin12) = grid_atom%rad2l(1:nr, lmin12)*g1(1:nr)*g2(1:nr)
252 122486870 : gg_lm1(1:nr, lmin12) = grid_atom%rad2l(1:nr, lmin12 - 1)*g1(1:nr)*g2(1:nr)
253 : END IF
254 :
255 : ! reduce the number of terms in the expansion local densities
256 4974126 : IF (lmax12 > lmax_expansion) lmax12 = lmax_expansion
257 :
258 7812526 : DO l = lmin12 + 1, lmax12
259 156376360 : gg(1:nr, l) = grid_atom%rad(1:nr)*gg(1:nr, l - 1)
260 156376360 : gg_lm1(1:nr, l) = gg(1:nr, l - 1)
261 161350486 : dgg(1:nr, l - 1) = -2.0_dp*(zet(ipgf1, iset1) + zet(ipgf2, iset2))*gg(1:nr, l)
262 :
263 : END DO
264 : dgg(1:nr, lmax12) = -2.0_dp*(zet(ipgf1, iset1) + &
265 268331850 : zet(ipgf2, iset2))*grid_atom%rad(1:nr)*gg(1:nr, lmax12)
266 :
267 4974126 : c2 = SQRT(pi*pi*pi/(zet12*zet12*zet12))
268 :
269 41846552 : DO iso = 1, max_iso_not0_local
270 36872426 : l_iso = indso(1, iso)
271 36872426 : c1 = fourpi/(2._dp*REAL(l_iso, dp) + 1._dp)
272 122255406 : DO icg = 1, cg_n_list(iso)
273 80408854 : iso1 = cg_list(1, icg, iso)
274 80408854 : iso2 = cg_list(2, icg, iso)
275 :
276 80408854 : l = indso(1, iso1) + indso(1, iso2)
277 80408854 : CPASSERT(l <= lmax_expansion)
278 80408854 : IF (done_vgg(l, l_iso)) CYCLE
279 10226956 : L_sum = l + l_iso
280 10226956 : L_sub = l - l_iso
281 :
282 10226956 : IF (l_sum == 0) THEN
283 145844980 : vgg(1:nr, l, l_iso) = erf_zet12(1:nr)*grid_atom%oorad2l(1:nr, 1)*c2
284 : ELSE
285 7613000 : CALL whittaker_c0a(int1, grid_atom%rad, gg0, erf_zet12, zet12, l, l_iso, nr)
286 7613000 : CALL whittaker_ci(int2, grid_atom%rad, gg0, zet12, L_sub, nr)
287 :
288 406209300 : DO ir = 1, nr
289 398596300 : int2(ir) = grid_atom%rad2l(ir, l_iso)*int2(ir)
290 406209300 : vgg(ir, l, l_iso) = c1*(int1(ir) + int2(ir))
291 : END DO
292 : END IF
293 117281280 : done_vgg(l, l_iso) = .TRUE.
294 : END DO
295 : END DO
296 : END IF ! lmax_expansion
297 :
298 10108048 : DO iat = bo(1), bo(2)
299 3365146 : iatom = atom_list(iat)
300 :
301 12325489 : DO i = 1, nspins
302 3983727 : coeff_h => rho_atom_set(iatom)%cpc_h(i)%r_coef
303 3983727 : coeff_s => rho_atom_set(iatom)%cpc_s(i)%r_coef
304 :
305 29542307 : DO iso = 1, max_iso_not0_local
306 25558580 : l_iso = indso(1, iso)
307 82740051 : DO icg = 1, cg_n_list(iso)
308 53197744 : iso1 = cg_list(1, icg, iso)
309 53197744 : iso2 = cg_list(2, icg, iso)
310 :
311 53197744 : l = indso(1, iso1) + indso(1, iso2)
312 53197744 : CPASSERT(l <= lmax_expansion)
313 53197744 : iso1_coeff = iso1_first + iso1 - i1
314 53197744 : iso2_coeff = iso2_first + iso2 - i2
315 53197744 : cpc_h = coeff_h(iso1_coeff, iso2_coeff)*my_CG(iso1, iso2, iso)
316 53197744 : cpc_s = coeff_s(iso1_coeff, iso2_coeff)*my_CG(iso1, iso2, iso)
317 :
318 : rho_atom_set(iatom)%rho_rad_h(i)%r_coef(1:nr, iso) = &
319 : rho_atom_set(iatom)%rho_rad_h(i)%r_coef(1:nr, iso) + &
320 2842757778 : gg(1:nr, l)*cpc_h
321 :
322 : rho_atom_set(iatom)%rho_rad_s(i)%r_coef(1:nr, iso) = &
323 : rho_atom_set(iatom)%rho_rad_s(i)%r_coef(1:nr, iso) + &
324 2842757778 : gg(1:nr, l)*cpc_s
325 :
326 : rho_atom_set(iatom)%drho_rad_h(i)%r_coef(1:nr, iso) = &
327 : rho_atom_set(iatom)%drho_rad_h(i)%r_coef(1:nr, iso) + &
328 2842757778 : dgg(1:nr, l)*cpc_h
329 :
330 : rho_atom_set(iatom)%drho_rad_s(i)%r_coef(1:nr, iso) = &
331 : rho_atom_set(iatom)%drho_rad_s(i)%r_coef(1:nr, iso) + &
332 2842757778 : dgg(1:nr, l)*cpc_s
333 :
334 : rho_atom_set(iatom)%vrho_rad_h(i)%r_coef(1:nr, iso) = &
335 : rho_atom_set(iatom)%vrho_rad_h(i)%r_coef(1:nr, iso) + &
336 2842757778 : vgg(1:nr, l, l_iso)*cpc_h
337 :
338 : rho_atom_set(iatom)%vrho_rad_s(i)%r_coef(1:nr, iso) = &
339 : rho_atom_set(iatom)%vrho_rad_s(i)%r_coef(1:nr, iso) + &
340 2868316358 : vgg(1:nr, l, l_iso)*cpc_s
341 :
342 : END DO ! icg
343 :
344 : END DO ! iso
345 :
346 88695040 : DO iso = 1, max_iso_not0 !damax_iso_not0_local
347 81346167 : l_iso = indso(1, iso)
348 172071189 : DO icg = 1, dacg_n_list(iso)
349 86741295 : iso1 = dacg_list(1, icg, iso)
350 86741295 : iso2 = dacg_list(2, icg, iso)
351 86741295 : l = indso(1, iso1) + indso(1, iso2)
352 86741295 : CPASSERT(l <= lmax_expansion)
353 86741295 : iso1_coeff = iso1_first + iso1 - i1
354 86741295 : iso2_coeff = iso2_first + iso2 - i2
355 86741295 : cpc_h = coeff_h(iso1_coeff, iso2_coeff)
356 86741295 : cpc_s = coeff_s(iso1_coeff, iso2_coeff)
357 428311347 : DO j = 1, 3
358 : rho_atom_set(iatom)%rho_rad_h_d(j, i)%r_coef(1:nr, iso) = &
359 : rho_atom_set(iatom)%rho_rad_h_d(j, i)%r_coef(1:nr, iso) + &
360 13757202945 : gg_lm1(1:nr, l)*cpc_h*my_CG_dxyz(j, iso1, iso2, iso)
361 :
362 : rho_atom_set(iatom)%rho_rad_s_d(j, i)%r_coef(1:nr, iso) = &
363 : rho_atom_set(iatom)%rho_rad_s_d(j, i)%r_coef(1:nr, iso) + &
364 13843944240 : gg_lm1(1:nr, l)*cpc_s*my_CG_dxyz(j, iso1, iso2, iso)
365 : END DO
366 : END DO ! icg
367 :
368 : END DO ! iso
369 :
370 : END DO ! i
371 : END DO ! iat
372 :
373 : END DO ! ipgf2
374 : END DO ! ipgf1
375 2479540 : m2s = m2s + maxso
376 : END DO ! iset2
377 295452 : m1s = m1s + maxso
378 : END DO ! iset1
379 :
380 142730 : DO iat = bo(1), bo(2)
381 61674 : iatom = atom_list(iat)
382 :
383 131262 : DO i = 1, nspins
384 :
385 1084890 : DO iso = 1, max_iso_not0
386 : rho_s = 0.0_dp
387 : rho_h = 0.0_dp
388 51846192 : DO ir = 1, nr
389 50892564 : rho_h = rho_h + rho_atom_set(iatom)%rho_rad_h(i)%r_coef(ir, iso)*grid_atom%wr(ir)
390 51846192 : rho_s = rho_s + rho_atom_set(iatom)%rho_rad_s(i)%r_coef(ir, iso)*grid_atom%wr(ir)
391 : END DO ! ir
392 953628 : tot_rho1_h(i) = tot_rho1_h(i) + rho_h*harmonics%slm_int(iso)
393 1023216 : tot_rho1_s(i) = tot_rho1_s(i) + rho_s*harmonics%slm_int(iso)
394 : END DO ! iso
395 :
396 : END DO ! ispin
397 :
398 142730 : IF (nspins == 2) THEN
399 7914 : na = SIZE(harmonics%slm, 1)
400 47484 : ALLOCATE (sfun_h(nr, na), sfun_s(nr, na))
401 7914 : sfun_h = 0.0_dp
402 7914 : sfun_s = 0.0_dp
403 122740 : DO iso = 1, max_iso_not0
404 7258910 : DO ir = 1, nr
405 : rfun = grid_atom%wr(ir)*(rho_atom_set(iatom)%rho_rad_h(1)%r_coef(ir, iso) - &
406 7136170 : rho_atom_set(iatom)%rho_rad_h(2)%r_coef(ir, iso))
407 439838670 : sfun_h(ir, 1:na) = sfun_h(ir, 1:na) + rfun*harmonics%slm(1:na, iso)*grid_atom%wa(1:na)
408 : rfun = grid_atom%wr(ir)*(rho_atom_set(iatom)%rho_rad_s(1)%r_coef(ir, iso) - &
409 7136170 : rho_atom_set(iatom)%rho_rad_s(2)%r_coef(ir, iso))
410 439953496 : sfun_s(ir, 1:na) = sfun_s(ir, 1:na) + rfun*harmonics%slm(1:na, iso)*grid_atom%wa(1:na)
411 : END DO
412 : END DO
413 27221910 : rho1_h_spin = rho1_h_spin + SUM(sfun_h(1:nr, 1:na))
414 27221910 : rho1_s_spin = rho1_s_spin + SUM(sfun_s(1:nr, 1:na))
415 27221910 : rho1_h_aspin = rho1_h_aspin + SUM(ABS(sfun_h(1:nr, 1:na)))
416 27221910 : rho1_s_aspin = rho1_s_aspin + SUM(ABS(sfun_s(1:nr, 1:na)))
417 7914 : DEALLOCATE (sfun_h, sfun_s)
418 : END IF
419 :
420 : END DO ! iat
421 :
422 81056 : DEALLOCATE (g1, g2, gg0, gg, gg_lm1, dgg, vgg, done_vgg, erf_zet12, int1, int2, g_rad)
423 81056 : DEALLOCATE (cg_list, cg_n_list, dacg_list, dacg_n_list)
424 81056 : DEALLOCATE (o2nindex)
425 :
426 81056 : CALL timestop(handle)
427 :
428 243168 : END SUBROUTINE calculate_rho_atom
429 :
430 : ! **************************************************************************************************
431 : !> \brief Replicate the radial hard/soft density data needed to evaluate one-center tails on
432 : !> rank-local target grids. The compact one-center density matrices are already global;
433 : !> this routine performs one packed reduction for the derived radial fields of a kind.
434 : !> \param para_env ...
435 : !> \param rho_atom_set ...
436 : !> \param qs_kind ...
437 : !> \param atom_list ...
438 : !> \param natom ...
439 : !> \param nspins ...
440 : ! **************************************************************************************************
441 160 : SUBROUTINE replicate_rho_atom_radial(para_env, rho_atom_set, qs_kind, atom_list, natom, nspins)
442 : TYPE(mp_para_env_type), POINTER :: para_env
443 : TYPE(rho_atom_type), DIMENSION(:), POINTER :: rho_atom_set
444 : TYPE(qs_kind_type), INTENT(IN) :: qs_kind
445 : INTEGER, DIMENSION(:), INTENT(IN) :: atom_list
446 : INTEGER, INTENT(IN) :: natom, nspins
447 :
448 : CHARACTER(len=*), PARAMETER :: routineN = 'replicate_rho_atom_radial'
449 :
450 : INTEGER :: block_size, bo(2), cursor, handle, iat, &
451 : iatom, ispin, j, max_iso_not0, ncoeff, &
452 : nr
453 : REAL(dp), ALLOCATABLE, DIMENSION(:) :: buffer
454 : TYPE(grid_atom_type), POINTER :: grid_atom
455 : TYPE(harmonics_atom_type), POINTER :: harmonics
456 :
457 160 : CALL timeset(routineN, handle)
458 :
459 160 : NULLIFY (grid_atom, harmonics)
460 160 : CALL get_qs_kind(qs_kind, grid_atom=grid_atom, harmonics=harmonics)
461 160 : CPASSERT(ASSOCIATED(grid_atom))
462 160 : CPASSERT(ASSOCIATED(harmonics))
463 160 : nr = grid_atom%nr
464 160 : max_iso_not0 = harmonics%max_iso_not0
465 160 : ncoeff = nr*max_iso_not0
466 160 : block_size = 10*nspins*ncoeff
467 480 : ALLOCATE (buffer(block_size*natom))
468 160 : buffer = 0.0_dp
469 :
470 160 : bo = get_limit(natom, para_env%num_pe, para_env%mepos)
471 286 : DO iat = bo(1), bo(2)
472 126 : iatom = atom_list(iat)
473 126 : cursor = (iat - 1)*block_size
474 252 : DO ispin = 1, nspins
475 : buffer(cursor + 1:cursor + ncoeff) = &
476 252 : RESHAPE(rho_atom_set(iatom)%rho_rad_h(ispin)%r_coef, [ncoeff])
477 126 : cursor = cursor + ncoeff
478 : buffer(cursor + 1:cursor + ncoeff) = &
479 252 : RESHAPE(rho_atom_set(iatom)%rho_rad_s(ispin)%r_coef, [ncoeff])
480 126 : cursor = cursor + ncoeff
481 : buffer(cursor + 1:cursor + ncoeff) = &
482 252 : RESHAPE(rho_atom_set(iatom)%drho_rad_h(ispin)%r_coef, [ncoeff])
483 126 : cursor = cursor + ncoeff
484 : buffer(cursor + 1:cursor + ncoeff) = &
485 252 : RESHAPE(rho_atom_set(iatom)%drho_rad_s(ispin)%r_coef, [ncoeff])
486 126 : cursor = cursor + ncoeff
487 630 : DO j = 1, 3
488 : buffer(cursor + 1:cursor + ncoeff) = &
489 756 : RESHAPE(rho_atom_set(iatom)%rho_rad_h_d(j, ispin)%r_coef, [ncoeff])
490 378 : cursor = cursor + ncoeff
491 : buffer(cursor + 1:cursor + ncoeff) = &
492 756 : RESHAPE(rho_atom_set(iatom)%rho_rad_s_d(j, ispin)%r_coef, [ncoeff])
493 504 : cursor = cursor + ncoeff
494 : END DO
495 : END DO
496 286 : CPASSERT(cursor == iat*block_size)
497 : END DO
498 160 : CALL para_env%sum(buffer)
499 :
500 412 : DO iat = 1, natom
501 252 : iatom = atom_list(iat)
502 252 : cursor = (iat - 1)*block_size
503 504 : DO ispin = 1, nspins
504 252 : IF (.NOT. ASSOCIATED(rho_atom_set(iatom)%rho_rad_h(ispin)%r_coef)) THEN
505 35 : CALL allocate_rho_atom_rad(rho_atom_set, iatom, ispin, nr, max_iso_not0)
506 : END IF
507 : rho_atom_set(iatom)%rho_rad_h(ispin)%r_coef = &
508 33360 : RESHAPE(buffer(cursor + 1:cursor + ncoeff), [nr, max_iso_not0])
509 252 : cursor = cursor + ncoeff
510 : rho_atom_set(iatom)%rho_rad_s(ispin)%r_coef = &
511 33360 : RESHAPE(buffer(cursor + 1:cursor + ncoeff), [nr, max_iso_not0])
512 252 : cursor = cursor + ncoeff
513 : rho_atom_set(iatom)%drho_rad_h(ispin)%r_coef = &
514 33360 : RESHAPE(buffer(cursor + 1:cursor + ncoeff), [nr, max_iso_not0])
515 252 : cursor = cursor + ncoeff
516 : rho_atom_set(iatom)%drho_rad_s(ispin)%r_coef = &
517 33360 : RESHAPE(buffer(cursor + 1:cursor + ncoeff), [nr, max_iso_not0])
518 252 : cursor = cursor + ncoeff
519 1260 : DO j = 1, 3
520 : rho_atom_set(iatom)%rho_rad_h_d(j, ispin)%r_coef = &
521 100080 : RESHAPE(buffer(cursor + 1:cursor + ncoeff), [nr, max_iso_not0])
522 756 : cursor = cursor + ncoeff
523 : rho_atom_set(iatom)%rho_rad_s_d(j, ispin)%r_coef = &
524 100080 : RESHAPE(buffer(cursor + 1:cursor + ncoeff), [nr, max_iso_not0])
525 1008 : cursor = cursor + ncoeff
526 : END DO
527 : END DO
528 412 : CPASSERT(cursor == iat*block_size)
529 : END DO
530 160 : DEALLOCATE (buffer)
531 :
532 160 : CALL timestop(handle)
533 :
534 160 : END SUBROUTINE replicate_rho_atom_radial
535 :
536 : ! **************************************************************************************************
537 : !> \brief ...
538 : !> \param qs_env QuickStep environment
539 : !> (accessed components: atomic_kind_set, dft_control%nimages,
540 : !> dft_control%nspins, kpoints%cell_to_index)
541 : !> \param rho_ao density matrix in atomic basis set
542 : !> \param rho_atom_set ...
543 : !> \param qs_kind_set list of QuickStep kinds
544 : !> \param oce one-centre expansion coefficients
545 : !> \param sab neighbour pair list
546 : !> \param para_env parallel environment
547 : !> \par History
548 : !> Add OpenMP [Apr 2016, EPCC]
549 : !> Use automatic arrays [Sep 2016, M Tucker]
550 : !> Allow for external non-default kind_set, oce and sab [Dec 2019, A Bussy]
551 : !> \note Consider to declare 'rho_ao' dummy argument as a pointer to the two-dimensional
552 : !> (1:nspins, 1:nimages) set of matrices.
553 : ! **************************************************************************************************
554 47304 : SUBROUTINE calculate_rho_atom_coeff(qs_env, rho_ao, rho_atom_set, qs_kind_set, oce, sab, para_env)
555 :
556 : TYPE(qs_environment_type), POINTER :: qs_env
557 : TYPE(dbcsr_p_type), DIMENSION(*) :: rho_ao
558 : TYPE(rho_atom_type), DIMENSION(:), POINTER :: rho_atom_set
559 : TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
560 : TYPE(oce_matrix_type), POINTER :: oce
561 : TYPE(neighbor_list_set_p_type), DIMENSION(:), &
562 : POINTER :: sab
563 : TYPE(mp_para_env_type), POINTER :: para_env
564 :
565 : CHARACTER(len=*), PARAMETER :: routineN = 'calculate_rho_atom_coeff'
566 :
567 : INTEGER :: bo(2), handle, i, iac, iatom, ibc, ikind, img, inb, ispin, jatom, jkind, kac, &
568 : kac_hi, kac_lo, katom, kbc, kkind, len_PC1, max_gau, max_nb, max_nclist, max_nsgf, mepos, &
569 : n_cont_a, n_cont_b, n_nb, nat_kind, natom, nimages, nkind, nl_size, nsoctot, nspins, &
570 : num_pe, slot, w_alloc, w_total
571 47304 : INTEGER, ALLOCATABLE, DIMENSION(:) :: ia_ptr, ia_work, nsatbas_kind, &
572 47304 : slot_order, w_offset
573 : INTEGER, DIMENSION(3) :: cell_b
574 47304 : INTEGER, DIMENSION(:), POINTER :: a_list, list_a, list_b
575 47304 : INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index
576 : LOGICAL :: dista, distb, found, paw_atom
577 47304 : LOGICAL, ALLOCATABLE, DIMENSION(:) :: has_intac, paw_kind
578 47304 : LOGICAL, ALLOCATABLE, DIMENSION(:, :) :: w_touched
579 : REAL(KIND=dp) :: beta, eps_cpc, factor, pmax
580 47304 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: nb_pmax, proj_work1
581 47304 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: p_matrix, proj_work2, w_buf
582 47304 : REAL(KIND=dp), DIMENSION(:, :), POINTER :: C_coeff_hh_a, C_coeff_hh_b, &
583 47304 : C_coeff_ss_a, C_coeff_ss_b, r_coef_h, &
584 47304 : r_coef_s
585 : TYPE(alist_type), POINTER :: alist_ac, alist_bc
586 47304 : TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
587 : TYPE(clist_type), POINTER :: clist_a, clist_b
588 : TYPE(dft_control_type), POINTER :: dft_control
589 47304 : TYPE(gto_basis_set_p_type), DIMENSION(:), POINTER :: basis_set_list
590 : TYPE(gto_basis_set_type), POINTER :: basis_1c, basis_set_a
591 : TYPE(kpoint_type), POINTER :: kpoints
592 : TYPE(neighbor_list_task_type), POINTER :: task
593 47304 : TYPE(rho_atom_coeff), ALLOCATABLE, DIMENSION(:, :) :: nb_pblk
594 :
595 47304 : !$ INTEGER(kind=omp_lock_kind), ALLOCATABLE, DIMENSION(:) :: locks
596 : !$ INTEGER :: lock, number_of_locks
597 :
598 47304 : CALL timeset(routineN, handle)
599 :
600 : CALL get_qs_env(qs_env=qs_env, &
601 : dft_control=dft_control, &
602 47304 : atomic_kind_set=atomic_kind_set)
603 :
604 47304 : eps_cpc = dft_control%qs_control%gapw_control%eps_cpc
605 :
606 47304 : CPASSERT(ASSOCIATED(qs_kind_set))
607 47304 : CPASSERT(ASSOCIATED(rho_atom_set))
608 47304 : CPASSERT(ASSOCIATED(oce))
609 47304 : CPASSERT(ASSOCIATED(sab))
610 :
611 47304 : nspins = dft_control%nspins
612 47304 : nimages = dft_control%nimages
613 :
614 47304 : NULLIFY (cell_to_index)
615 47304 : IF (nimages > 1) THEN
616 760 : CALL get_qs_env(qs_env=qs_env, kpoints=kpoints)
617 760 : CALL get_kpoint_info(kpoint=kpoints, cell_to_index=cell_to_index)
618 : END IF
619 :
620 47304 : CALL get_atomic_kind_set(atomic_kind_set, natom=natom)
621 47304 : CALL get_qs_kind_set(qs_kind_set, maxsgf=max_nsgf, maxgtops=max_gau, basis_type='GAPW_1C')
622 :
623 47304 : nkind = SIZE(atomic_kind_set)
624 : ! Initialize to 0 the CPC coefficients and the local density arrays
625 139392 : DO ikind = 1, nkind
626 92088 : CALL get_atomic_kind(atomic_kind_set(ikind), atom_list=a_list, natom=nat_kind)
627 92088 : CALL get_qs_kind(qs_kind_set(ikind), paw_atom=paw_atom)
628 :
629 92088 : IF (.NOT. paw_atom) CYCLE
630 211368 : DO i = 1, nat_kind
631 128058 : iatom = a_list(i)
632 355978 : DO ispin = 1, nspins
633 69316442 : rho_atom_set(iatom)%cpc_h(ispin)%r_coef = 0.0_dp
634 69444500 : rho_atom_set(iatom)%cpc_s(ispin)%r_coef = 0.0_dp
635 : END DO ! ispin
636 : END DO ! i
637 :
638 83310 : num_pe = para_env%num_pe
639 83310 : mepos = para_env%mepos
640 83310 : bo = get_limit(nat_kind, num_pe, mepos)
641 286731 : DO i = bo(1), bo(2)
642 64029 : iatom = a_list(i)
643 228422 : DO ispin = 1, nspins
644 195943005 : rho_atom_set(iatom)%ga_Vlocal_gb_h(ispin)%r_coef = 0.0_dp
645 196007034 : rho_atom_set(iatom)%ga_Vlocal_gb_s(ispin)%r_coef = 0.0_dp
646 : END DO ! ispin
647 : END DO ! i
648 : END DO ! ikind
649 :
650 234000 : ALLOCATE (basis_set_list(nkind))
651 283824 : ALLOCATE (paw_kind(nkind), nsatbas_kind(nkind), has_intac(nkind*nkind))
652 47304 : paw_kind(:) = .FALSE.
653 47304 : nsatbas_kind(:) = 0
654 47304 : has_intac(:) = .FALSE.
655 139392 : DO ikind = 1, nkind
656 92088 : CALL get_qs_kind(qs_kind_set(ikind), basis_set=basis_set_a)
657 92088 : IF (ASSOCIATED(basis_set_a)) THEN
658 92088 : basis_set_list(ikind)%gto_basis_set => basis_set_a
659 : ELSE
660 0 : NULLIFY (basis_set_list(ikind)%gto_basis_set)
661 : END IF
662 : CALL get_qs_kind(qs_kind_set(ikind), basis_set=basis_1c, basis_type="GAPW_1C", &
663 92088 : paw_atom=paw_kind(ikind))
664 139392 : IF (paw_kind(ikind)) CALL get_paw_basis_info(basis_1c, nsatbas=nsatbas_kind(ikind))
665 : END DO
666 245136 : DO ikind = 1, nkind*nkind
667 245136 : has_intac(ikind) = ASSOCIATED(oce%intac(ikind)%alist)
668 : END DO
669 :
670 47304 : len_PC1 = MAX(1, max_nsgf*max_gau)
671 47304 : w_alloc = MAX(1, l2_chunk_dp/nspins, len_PC1) ! 16k-double L2 chunk across spins
672 47304 : max_nclist = 1
673 245136 : DO iac = 1, nkind*nkind
674 197832 : IF (.NOT. has_intac(iac)) CYCLE
675 494960 : DO i = 1, SIZE(oce%intac(iac)%alist)
676 467748 : max_nclist = MAX(max_nclist, oce%intac(iac)%alist(i)%nclist)
677 : END DO
678 : END DO
679 :
680 47304 : CPASSERT(ASSOCIATED(sab(1)%nlist_task))
681 47304 : nl_size = sab(1)%nl_size
682 331128 : ALLOCATE (ia_ptr(natom + 1), ia_work(natom), slot_order(MAX(1, nl_size)))
683 47304 : ia_work(:) = 0
684 94608 : DO i = 1, 2
685 2492756 : DO slot = 1, nl_size
686 2398148 : task => sab(1)%nlist_task(slot)
687 2398148 : IF (.NOT. ASSOCIATED(basis_set_list(task%ikind)%gto_basis_set)) CYCLE
688 2398148 : IF (.NOT. ASSOCIATED(basis_set_list(task%jkind)%gto_basis_set)) CYCLE
689 2398148 : iatom = MIN(task%iatom, task%jatom)
690 2398148 : IF (i == 2) slot_order(ia_work(iatom)) = slot
691 2492756 : ia_work(iatom) = ia_work(iatom) + 1
692 : END DO
693 94608 : IF (i == 2) EXIT
694 47304 : ia_ptr(1) = 1
695 194138 : max_nb = MAX(1, MAXVAL(ia_work))
696 241442 : DO iatom = 1, natom
697 146834 : ia_ptr(iatom + 1) = ia_ptr(iatom) + ia_work(iatom)
698 194138 : ia_work(iatom) = ia_ptr(iatom)
699 : END DO
700 : END DO
701 47304 : DEALLOCATE (ia_work)
702 :
703 : !$OMP PARALLEL DEFAULT(NONE) &
704 : !$OMP SHARED(natom, nkind, nspins, nimages, cell_to_index, rho_ao, max_nsgf, max_gau, max_nb, &
705 : !$OMP max_nclist, w_alloc, len_PC1, ia_ptr, slot_order, sab, paw_kind, nsatbas_kind, &
706 : !$OMP has_intac, oce, eps_cpc, rho_atom_set, locks, number_of_locks) &
707 : !$OMP PRIVATE(nb_pblk, nb_pmax, p_matrix, proj_work1, proj_work2, w_buf, w_offset, w_touched, &
708 : !$OMP iatom, ikind, n_nb, inb, TASK, jatom, cell_b, img, pmax, ispin, found, kkind, &
709 : !$OMP nsoctot, iac, alist_ac, kac_lo, kac_hi, w_total, kac, clist_a, n_cont_a, katom, &
710 : !$OMP jkind, ibc, alist_bc, factor, kbc, clist_b, n_cont_b, list_a, list_b, dista, &
711 47304 : !$OMP distb, C_coeff_hh_a, C_coeff_ss_a, C_coeff_hh_b, C_coeff_ss_b, beta, r_coef_h, r_coef_s)
712 :
713 : ALLOCATE (nb_pblk(nspins, max_nb), nb_pmax(max_nb), w_buf(w_alloc, nspins), w_offset(max_nclist))
714 : ALLOCATE (p_matrix(MAX(1, max_nsgf), MAX(1, max_nsgf)), proj_work1(len_PC1), &
715 : proj_work2(MAX(1, max_gau), MAX(1, max_gau)), w_touched(max_nclist, nspins))
716 :
717 : !$OMP SINGLE
718 : !$ number_of_locks = nspins*natom
719 : !$ ALLOCATE (locks(number_of_locks))
720 : !$OMP END SINGLE
721 :
722 : !$OMP DO
723 : !$ DO lock = 1, number_of_locks
724 : !$ call omp_init_lock(locks(lock))
725 : !$ END DO
726 : !$OMP END DO
727 :
728 : ! Factor sum_(A,B) C_A^T P_AB C_B = sum_A C_A^T (sum_B P_AB C_B) across offsite B /= K.
729 : !$OMP DO SCHEDULE(DYNAMIC, 1)
730 : DO iatom = 1, natom
731 : n_nb = ia_ptr(iatom + 1) - ia_ptr(iatom)
732 : IF (n_nb == 0) CYCLE
733 : task => sab(1)%nlist_task(slot_order(ia_ptr(iatom)))
734 : ikind = MERGE(task%jkind, task%ikind, task%iatom > task%jatom)
735 :
736 : DO inb = 1, n_nb
737 : task => sab(1)%nlist_task(slot_order(ia_ptr(iatom) + inb - 1))
738 : jatom = MAX(task%iatom, task%jatom)
739 : img = 1
740 : IF (nimages > 1) img = cell_to_index(task%cell(1), task%cell(2), task%cell(3))
741 : CPASSERT(img > 0)
742 : pmax = 0.0_dp
743 : DO ispin = 1, nspins
744 : CALL dbcsr_get_block_p(rho_ao(nspins*(img - 1) + ispin)%matrix, iatom, jatom, &
745 : nb_pblk(ispin, inb)%r_coef, found)
746 : CPASSERT(found)
747 : pmax = pmax + MAXVAL(ABS(nb_pblk(ispin, inb)%r_coef))
748 : END DO
749 : nb_pmax(inb) = pmax
750 : END DO
751 :
752 : DO kkind = 1, nkind
753 : IF (.NOT. paw_kind(kkind)) CYCLE
754 : nsoctot = nsatbas_kind(kkind)
755 : iac = ikind + nkind*(kkind - 1)
756 : IF (.NOT. has_intac(iac)) CYCLE
757 : CALL get_alist(oce%intac(iac), alist_ac, iatom)
758 : IF (.NOT. ASSOCIATED(alist_ac)) CYCLE
759 :
760 : kac_lo = 1
761 : DO WHILE (kac_lo <= alist_ac%nclist)
762 : w_total = 0
763 : DO kac = kac_lo, alist_ac%nclist
764 : n_cont_a = alist_ac%clist(kac)%nsgf_cnt
765 : IF (n_cont_a == 0) CYCLE
766 : IF (w_total > 0 .AND. w_total + n_cont_a*nsoctot > w_alloc) EXIT
767 : w_offset(kac) = w_total + 1
768 : w_total = w_total + n_cont_a*nsoctot
769 : END DO
770 : kac_hi = kac - 1
771 :
772 : IF (w_total > 0) THEN
773 : w_touched(kac_lo:kac_hi, 1:nspins) = .FALSE.
774 : DO inb = 1, n_nb
775 : pmax = nb_pmax(inb)
776 : IF (pmax <= 0.0_dp) CYCLE
777 : task => sab(1)%nlist_task(slot_order(ia_ptr(iatom) + inb - 1))
778 : jkind = MERGE(task%ikind, task%jkind, task%iatom > task%jatom)
779 : jatom = MAX(task%iatom, task%jatom)
780 : cell_b = MERGE(-task%cell, task%cell, task%iatom > task%jatom)
781 : ibc = jkind + nkind*(kkind - 1)
782 : IF (.NOT. has_intac(ibc)) CYCLE
783 : CALL get_alist(oce%intac(ibc), alist_bc, jatom)
784 : IF (.NOT. ASSOCIATED(alist_bc)) CYCLE
785 : factor = MERGE(0.5_dp, 1.0_dp, iatom == jatom)
786 :
787 : DO kbc = 1, alist_bc%nclist
788 : clist_b => alist_bc%clist(kbc)
789 : n_cont_b = clist_b%nsgf_cnt
790 : IF (n_cont_b == 0) CYCLE
791 : katom = clist_b%catom
792 : DO kac = kac_lo, kac_hi
793 : IF (alist_ac%clist(kac)%catom /= katom) CYCLE
794 : IF (ALL(cell_b + clist_b%cell == alist_ac%clist(kac)%cell)) EXIT
795 : END DO
796 : IF (kac > kac_hi) CYCLE
797 : clist_a => alist_ac%clist(kac)
798 : n_cont_a = clist_a%nsgf_cnt
799 : IF (n_cont_a == 0 .OR. pmax*clist_b%maxac*clist_a%maxac < eps_cpc) CYCLE
800 :
801 : list_a => clist_a%sgf_list
802 : list_b => clist_b%sgf_list
803 : dista = (iatom /= katom .OR. ANY(clist_a%cell /= 0))
804 : distb = (jatom /= katom .OR. ANY(clist_b%cell /= 0))
805 : C_coeff_ss_b => clist_b%acint(:, :, 1)
806 : IF (.NOT. distb) THEN
807 : C_coeff_ss_a => clist_a%acint(:, :, 1)
808 : C_coeff_hh_a => C_coeff_ss_a
809 : IF (.NOT. dista) C_coeff_hh_a => clist_a%achint(:, :, 1)
810 : C_coeff_hh_b => clist_b%achint(:, :, 1)
811 : END IF
812 :
813 : DO ispin = 1, nspins
814 : CALL alist_pre_align_blk(nb_pblk(ispin, inb)%r_coef, &
815 : SIZE(nb_pblk(ispin, inb)%r_coef, 1), p_matrix, SIZE(p_matrix, 1), &
816 : list_a, n_cont_a, list_b, n_cont_b)
817 : IF (distb) THEN
818 : beta = MERGE(1.0_dp, 0.0_dp, w_touched(kac, ispin))
819 : w_touched(kac, ispin) = .TRUE.
820 : CALL DGEMM('N', 'N', n_cont_a, nsoctot, n_cont_b, factor, p_matrix, SIZE(p_matrix, 1), &
821 : C_coeff_ss_b, n_cont_b, beta, w_buf(w_offset(kac):, ispin), n_cont_a)
822 : CYCLE
823 : END IF
824 : r_coef_h => rho_atom_set(katom)%cpc_h(ispin)%r_coef
825 : r_coef_s => rho_atom_set(katom)%cpc_s(ispin)%r_coef
826 : !$ CALL omp_set_lock(locks((katom - 1)*nspins + ispin))
827 : CALL proj_blk(C_coeff_hh_a, C_coeff_ss_a, n_cont_a, C_coeff_hh_b, C_coeff_ss_b, n_cont_b, &
828 : p_matrix, SIZE(p_matrix, 1), r_coef_h, r_coef_s, nsoctot, len_PC1, &
829 : SIZE(proj_work2), factor, .FALSE., proj_work1, proj_work2)
830 : !$ CALL omp_unset_lock(locks((katom - 1)*nspins + ispin))
831 : END DO
832 : END DO
833 : END DO
834 :
835 : DO kac = kac_lo, kac_hi
836 : clist_a => alist_ac%clist(kac)
837 : n_cont_a = clist_a%nsgf_cnt
838 : IF (n_cont_a == 0) CYCLE
839 : katom = clist_a%catom
840 : dista = (iatom /= katom .OR. ANY(clist_a%cell /= 0))
841 : C_coeff_ss_a => clist_a%acint(:, :, 1)
842 : DO ispin = 1, nspins
843 : IF (.NOT. w_touched(kac, ispin)) CYCLE
844 : r_coef_h => rho_atom_set(katom)%cpc_h(ispin)%r_coef
845 : r_coef_s => rho_atom_set(katom)%cpc_s(ispin)%r_coef
846 : CALL DGEMM('T', 'N', nsoctot, nsoctot, n_cont_a, 1.0_dp, C_coeff_ss_a, n_cont_a, &
847 : w_buf(w_offset(kac):, ispin), n_cont_a, 0.0_dp, proj_work2, SIZE(proj_work2, 1))
848 : !$ CALL omp_set_lock(locks((katom - 1)*nspins + ispin))
849 : r_coef_s = r_coef_s + proj_work2(1:nsoctot, 1:nsoctot)
850 : IF (dista) r_coef_h = r_coef_h + proj_work2(1:nsoctot, 1:nsoctot)
851 : IF (.NOT. dista) CALL DGEMM('T', 'N', nsoctot, nsoctot, n_cont_a, 1.0_dp, &
852 : clist_a%achint(:, :, 1), n_cont_a, w_buf(w_offset(kac):, ispin), &
853 : n_cont_a, 1.0_dp, r_coef_h, SIZE(r_coef_h, 1))
854 : !$ CALL omp_unset_lock(locks((katom - 1)*nspins + ispin))
855 : END DO
856 : END DO
857 : END IF
858 : kac_lo = kac_hi + 1
859 : END DO
860 : END DO
861 : END DO
862 : !$OMP END DO
863 : ! Wait for all threads to finish the loop before locks can be freed
864 : !$OMP BARRIER
865 :
866 : !$OMP DO
867 : !$ DO lock = 1, number_of_locks
868 : !$ call omp_destroy_lock(locks(lock))
869 : !$ END DO
870 : !$OMP END DO
871 : !$OMP SINGLE
872 : !$ DEALLOCATE (locks)
873 : !$OMP END SINGLE NOWAIT
874 :
875 : DEALLOCATE (nb_pblk, nb_pmax, p_matrix, proj_work1, proj_work2, w_buf, w_offset, w_touched)
876 : !$OMP END PARALLEL
877 :
878 47304 : DEALLOCATE (ia_ptr, slot_order)
879 47304 : CALL reduce_symmetrize_cpc(rho_atom_set, natom, nspins, max_gau, para_env)
880 :
881 47304 : DEALLOCATE (basis_set_list, paw_kind, nsatbas_kind, has_intac)
882 :
883 47304 : CALL timestop(handle)
884 :
885 141912 : END SUBROUTINE calculate_rho_atom_coeff
886 :
887 : ! **************************************************************************************************
888 : !> \brief ...
889 : !> \param rho_atom_set the type to initialize
890 : !> \param atomic_kind_set list of atomic kinds
891 : !> \param qs_kind_set the kind set from which to take quantum numbers and basis info
892 : !> \param dft_control DFT control type
893 : !> \param para_env parallel environment
894 : !> \par History:
895 : !> - Generalised by providing the rho_atom_set and the qs_kind_set 12.2019 (A.Bussy)
896 : ! **************************************************************************************************
897 5166 : SUBROUTINE init_rho_atom(rho_atom_set, atomic_kind_set, qs_kind_set, dft_control, para_env)
898 :
899 : TYPE(rho_atom_type), DIMENSION(:), POINTER :: rho_atom_set
900 : TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
901 : TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
902 : TYPE(dft_control_type), POINTER :: dft_control
903 : TYPE(mp_para_env_type), POINTER :: para_env
904 :
905 : CHARACTER(len=*), PARAMETER :: routineN = 'init_rho_atom'
906 :
907 : CHARACTER(LEN=4) :: my_ikind, my_la, my_llmax
908 : INTEGER :: handle, ikind, la, ll, llmax, &
909 : lmax_sphere, max_s_harm, max_s_set, &
910 : maxl, maxlgto, maxs, na, nat, natom, &
911 : nr, nspins, quadrature
912 1722 : INTEGER, DIMENSION(:), POINTER :: atom_list
913 : LOGICAL :: paw_atom
914 1722 : REAL(dp), DIMENSION(:, :, :), POINTER :: my_CG
915 : TYPE(gapw_control_type), POINTER :: gapw_control
916 : TYPE(grid_atom_type), POINTER :: grid_atom
917 : TYPE(gto_basis_set_type), POINTER :: basis_1c_set
918 : TYPE(harmonics_atom_type), POINTER :: harmonics
919 :
920 1722 : CALL timeset(routineN, handle)
921 :
922 1722 : NULLIFY (basis_1c_set)
923 1722 : NULLIFY (my_CG, grid_atom, harmonics, atom_list)
924 :
925 1722 : CPASSERT(ASSOCIATED(atomic_kind_set))
926 1722 : CPASSERT(ASSOCIATED(dft_control))
927 1722 : CPASSERT(ASSOCIATED(para_env))
928 1722 : CPASSERT(ASSOCIATED(qs_kind_set))
929 :
930 1722 : CALL get_atomic_kind_set(atomic_kind_set, natom=natom)
931 :
932 1722 : CALL get_qs_kind_set(qs_kind_set, maxlgto=maxlgto, basis_type="GAPW_1C")
933 :
934 1722 : nspins = dft_control%nspins
935 1722 : gapw_control => dft_control%qs_control%gapw_control
936 :
937 1722 : lmax_sphere = gapw_control%lmax_sphere
938 :
939 1722 : llmax = MIN(lmax_sphere, 2*maxlgto)
940 1722 : max_s_harm = nsoset(llmax)
941 1722 : max_s_set = nsoset(maxlgto)
942 :
943 : ! *** calculate the Gaunt coefficients up to the maxl ***
944 1722 : CALL real_gaunt_coefficients(my_CG, maxlgto, maxlgto, llmax)
945 :
946 : ! *** initialize the Lebedev grids ***
947 1722 : CALL init_lebedev_grids()
948 1722 : quadrature = gapw_control%quadrature
949 :
950 4782 : DO ikind = 1, SIZE(atomic_kind_set)
951 3060 : CALL get_atomic_kind(atomic_kind_set(ikind), atom_list=atom_list, natom=nat)
952 : CALL get_qs_kind(qs_kind_set(ikind), &
953 : paw_atom=paw_atom, &
954 : grid_atom=grid_atom, &
955 : harmonics=harmonics, &
956 3060 : ngrid_rad=nr, ngrid_ang=na)
957 :
958 : ! *** determine the Lebedev grid for this kind ***
959 :
960 3060 : ll = get_number_of_lebedev_grid(n=na)
961 3060 : na = lebedev_grid(ll)%n
962 3060 : la = lebedev_grid(ll)%l
963 3060 : grid_atom%ng_sphere = na
964 3060 : grid_atom%nr = nr
965 :
966 3060 : IF (llmax > la) THEN
967 0 : IF (para_env%is_source()) THEN
968 0 : WRITE (my_la, "(I4)") la
969 0 : WRITE (my_ikind, "(I4)") ikind
970 0 : WRITE (my_llmax, "(I4)") llmax
971 : CALL cp_warn(__LOCATION__, &
972 : "The Lebedev grid has been built for angular momentum l up "// &
973 : "to "//TRIM(my_la)//" for atom kind "//TRIM(my_ikind)//", "// &
974 : "but the max l of spherical harmonics "//TRIM(my_llmax)//" is "// &
975 0 : "larger and good integration cannot be guaranteed")
976 : END IF
977 : END IF
978 :
979 : ! *** calculate the radial grid ***
980 3060 : CALL create_grid_atom(grid_atom, nr, na, llmax, ll, quadrature)
981 :
982 : ! *** calculate the spherical harmonics on the grid ***
983 :
984 3060 : CALL get_qs_kind(qs_kind_set(ikind), basis_set=basis_1c_set, basis_type="GAPW_1C")
985 3060 : CALL get_gto_basis_set(gto_basis_set=basis_1c_set, maxl=maxl)
986 3060 : maxs = nsoset(maxl)
987 : CALL create_harmonics_atom(harmonics, &
988 : my_CG, na, llmax, maxs, max_s_harm, ll, grid_atom%wa, &
989 3060 : grid_atom%azi, grid_atom%pol)
990 10902 : CALL get_maxl_CG(harmonics, basis_1c_set, llmax, max_s_harm)
991 :
992 : END DO
993 :
994 1722 : CALL deallocate_lebedev_grids()
995 1722 : DEALLOCATE (my_CG)
996 :
997 1722 : CALL allocate_rho_atom_internals(rho_atom_set, atomic_kind_set, qs_kind_set, dft_control, para_env)
998 :
999 1722 : CALL timestop(handle)
1000 :
1001 1722 : END SUBROUTINE init_rho_atom
1002 :
1003 : ! **************************************************************************************************
1004 : !> \brief ...
1005 : !> \param rho_atom_set ...
1006 : !> \param atomic_kind_set list of atomic kinds
1007 : !> \param qs_kind_set the kind set from which to take quantum numbers and basis info
1008 : !> \param dft_control DFT control type
1009 : !> \param para_env parallel environment
1010 : ! **************************************************************************************************
1011 5884 : SUBROUTINE allocate_rho_atom_internals(rho_atom_set, atomic_kind_set, qs_kind_set, dft_control, para_env)
1012 :
1013 : TYPE(rho_atom_type), DIMENSION(:), POINTER :: rho_atom_set
1014 : TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
1015 : TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1016 : TYPE(dft_control_type), POINTER :: dft_control
1017 : TYPE(mp_para_env_type), POINTER :: para_env
1018 :
1019 : CHARACTER(len=*), PARAMETER :: routineN = 'allocate_rho_atom_internals'
1020 :
1021 : INTEGER :: bo(2), handle, iat, iatom, ikind, ispin, &
1022 : max_iso_not0, maxso, mepos, nat, &
1023 : natom, nsatbas, nset, nsotot, nspins, &
1024 : num_pe
1025 5884 : INTEGER, DIMENSION(:), POINTER :: atom_list
1026 : LOGICAL :: paw_atom
1027 : TYPE(gto_basis_set_type), POINTER :: basis_1c
1028 : TYPE(harmonics_atom_type), POINTER :: harmonics
1029 :
1030 5884 : CALL timeset(routineN, handle)
1031 :
1032 5884 : CPASSERT(ASSOCIATED(atomic_kind_set))
1033 5884 : CPASSERT(ASSOCIATED(dft_control))
1034 5884 : CPASSERT(ASSOCIATED(para_env))
1035 5884 : CPASSERT(ASSOCIATED(qs_kind_set))
1036 :
1037 5884 : CALL get_atomic_kind_set(atomic_kind_set, natom=natom)
1038 :
1039 5884 : nspins = dft_control%nspins
1040 :
1041 5884 : IF (ASSOCIATED(rho_atom_set)) THEN
1042 0 : CALL deallocate_rho_atom_set(rho_atom_set)
1043 : END IF
1044 35500 : ALLOCATE (rho_atom_set(natom))
1045 :
1046 17276 : DO ikind = 1, SIZE(atomic_kind_set)
1047 :
1048 11392 : NULLIFY (atom_list, harmonics)
1049 11392 : CALL get_atomic_kind(atomic_kind_set(ikind), atom_list=atom_list, natom=nat)
1050 : CALL get_qs_kind(qs_kind_set(ikind), &
1051 : paw_atom=paw_atom, &
1052 11392 : harmonics=harmonics)
1053 :
1054 11392 : IF (paw_atom) THEN
1055 10410 : CALL get_qs_kind(qs_kind_set(ikind), basis_set=basis_1c, basis_type="GAPW_1C")
1056 10410 : CALL get_gto_basis_set(gto_basis_set=basis_1c, nset=nset, maxso=maxso)
1057 10410 : nsotot = nset*maxso
1058 10410 : CALL get_paw_basis_info(basis_1c, nsatbas=nsatbas)
1059 : END IF
1060 :
1061 11392 : max_iso_not0 = harmonics%max_iso_not0
1062 29240 : DO iat = 1, nat
1063 17848 : iatom = atom_list(iat)
1064 : ! *** allocate the radial density for each LM,for each atom ***
1065 :
1066 73374 : ALLOCATE (rho_atom_set(iatom)%rho_rad_h(nspins))
1067 55526 : ALLOCATE (rho_atom_set(iatom)%rho_rad_s(nspins))
1068 55526 : ALLOCATE (rho_atom_set(iatom)%vrho_rad_h(nspins))
1069 55526 : ALLOCATE (rho_atom_set(iatom)%vrho_rad_s(nspins))
1070 :
1071 : ALLOCATE (rho_atom_set(iatom)%cpc_h(nspins), &
1072 : rho_atom_set(iatom)%cpc_s(nspins), &
1073 : rho_atom_set(iatom)%drho_rad_h(nspins), &
1074 : rho_atom_set(iatom)%drho_rad_s(nspins), &
1075 : rho_atom_set(iatom)%rho_rad_h_d(3, nspins), &
1076 380744 : rho_atom_set(iatom)%rho_rad_s_d(3, nspins))
1077 : ALLOCATE (rho_atom_set(iatom)%int_scr_h(nspins), &
1078 93204 : rho_atom_set(iatom)%int_scr_s(nspins))
1079 :
1080 29240 : IF (paw_atom) THEN
1081 33612 : DO ispin = 1, nspins
1082 : ALLOCATE (rho_atom_set(iatom)%cpc_h(ispin)%r_coef(1:nsatbas, 1:nsatbas), &
1083 106500 : rho_atom_set(iatom)%cpc_s(ispin)%r_coef(1:nsatbas, 1:nsatbas))
1084 : ALLOCATE (rho_atom_set(iatom)%int_scr_h(ispin)%r_coef(1:nsatbas, 1:nsatbas), &
1085 88750 : rho_atom_set(iatom)%int_scr_s(ispin)%r_coef(1:nsatbas, 1:nsatbas))
1086 :
1087 9018454 : rho_atom_set(iatom)%cpc_h(ispin)%r_coef = 0.0_dp
1088 9034316 : rho_atom_set(iatom)%cpc_s(ispin)%r_coef = 0.0_dp
1089 : END DO
1090 : END IF
1091 :
1092 : END DO ! iat
1093 :
1094 11392 : num_pe = para_env%num_pe
1095 11392 : mepos = para_env%mepos
1096 11392 : bo = get_limit(nat, num_pe, mepos)
1097 37592 : DO iat = bo(1), bo(2)
1098 8924 : iatom = atom_list(iat)
1099 : ALLOCATE (rho_atom_set(iatom)%ga_Vlocal_gb_h(nspins), &
1100 55526 : rho_atom_set(iatom)%ga_Vlocal_gb_s(nspins))
1101 20316 : IF (paw_atom) THEN
1102 16806 : DO ispin = 1, nspins
1103 : CALL reallocate(rho_atom_set(iatom)%ga_Vlocal_gb_h(ispin)%r_coef, &
1104 8875 : 1, nsotot, 1, nsotot)
1105 : CALL reallocate(rho_atom_set(iatom)%ga_Vlocal_gb_s(ispin)%r_coef, &
1106 8875 : 1, nsotot, 1, nsotot)
1107 :
1108 24511325 : rho_atom_set(iatom)%ga_Vlocal_gb_h(ispin)%r_coef = 0.0_dp
1109 24519256 : rho_atom_set(iatom)%ga_Vlocal_gb_s(ispin)%r_coef = 0.0_dp
1110 : END DO
1111 : END IF
1112 :
1113 : END DO ! iat
1114 :
1115 : END DO
1116 :
1117 5884 : CALL timestop(handle)
1118 :
1119 11768 : END SUBROUTINE allocate_rho_atom_internals
1120 :
1121 : ! **************************************************************************************************
1122 : !> \brief ...
1123 : !> \param rho_atom_set ...
1124 : !> \param iatom ...
1125 : !> \param ispin ...
1126 : !> \param nr ...
1127 : !> \param max_iso_not0 ...
1128 : ! **************************************************************************************************
1129 8672 : SUBROUTINE allocate_rho_atom_rad(rho_atom_set, iatom, ispin, nr, max_iso_not0)
1130 :
1131 : TYPE(rho_atom_type), DIMENSION(:), POINTER :: rho_atom_set
1132 : INTEGER, INTENT(IN) :: iatom, ispin, nr, max_iso_not0
1133 :
1134 : CHARACTER(len=*), PARAMETER :: routineN = 'allocate_rho_atom_rad'
1135 :
1136 : INTEGER :: handle, j
1137 :
1138 8672 : CALL timeset(routineN, handle)
1139 :
1140 : ALLOCATE (rho_atom_set(iatom)%rho_rad_h(ispin)%r_coef(1:nr, 1:max_iso_not0), &
1141 : rho_atom_set(iatom)%rho_rad_s(ispin)%r_coef(1:nr, 1:max_iso_not0), &
1142 : rho_atom_set(iatom)%vrho_rad_h(ispin)%r_coef(1:nr, 1:max_iso_not0), &
1143 86720 : rho_atom_set(iatom)%vrho_rad_s(ispin)%r_coef(1:nr, 1:max_iso_not0))
1144 :
1145 7109782 : rho_atom_set(iatom)%rho_rad_h(ispin)%r_coef = 0.0_dp
1146 7109782 : rho_atom_set(iatom)%rho_rad_s(ispin)%r_coef = 0.0_dp
1147 7109782 : rho_atom_set(iatom)%vrho_rad_h(ispin)%r_coef = 0.0_dp
1148 7109782 : rho_atom_set(iatom)%vrho_rad_s(ispin)%r_coef = 0.0_dp
1149 :
1150 : ALLOCATE (rho_atom_set(iatom)%drho_rad_h(ispin)%r_coef(nr, max_iso_not0), &
1151 52032 : rho_atom_set(iatom)%drho_rad_s(ispin)%r_coef(nr, max_iso_not0))
1152 7109782 : rho_atom_set(iatom)%drho_rad_h(ispin)%r_coef = 0.0_dp
1153 7109782 : rho_atom_set(iatom)%drho_rad_s(ispin)%r_coef = 0.0_dp
1154 :
1155 34688 : DO j = 1, 3
1156 : ALLOCATE (rho_atom_set(iatom)%rho_rad_h_d(j, ispin)%r_coef(nr, max_iso_not0), &
1157 130080 : rho_atom_set(iatom)%rho_rad_s_d(j, ispin)%r_coef(nr, max_iso_not0))
1158 21329346 : rho_atom_set(iatom)%rho_rad_h_d(j, ispin)%r_coef = 0.0_dp
1159 21338018 : rho_atom_set(iatom)%rho_rad_s_d(j, ispin)%r_coef = 0.0_dp
1160 : END DO
1161 :
1162 8672 : CALL timestop(handle)
1163 :
1164 8672 : END SUBROUTINE allocate_rho_atom_rad
1165 :
1166 : ! **************************************************************************************************
1167 : !> \brief ...
1168 : !> \param rho_atom_set ...
1169 : !> \param iatom ...
1170 : !> \param ispin ...
1171 : ! **************************************************************************************************
1172 60951 : SUBROUTINE set2zero_rho_atom_rad(rho_atom_set, iatom, ispin)
1173 :
1174 : TYPE(rho_atom_type), DIMENSION(:), POINTER :: rho_atom_set
1175 : INTEGER, INTENT(IN) :: iatom, ispin
1176 :
1177 : INTEGER :: j
1178 :
1179 44813596 : rho_atom_set(iatom)%rho_rad_h(ispin)%r_coef = 0.0_dp
1180 44813596 : rho_atom_set(iatom)%rho_rad_s(ispin)%r_coef = 0.0_dp
1181 :
1182 44813596 : rho_atom_set(iatom)%vrho_rad_h(ispin)%r_coef = 0.0_dp
1183 44813596 : rho_atom_set(iatom)%vrho_rad_s(ispin)%r_coef = 0.0_dp
1184 :
1185 44813596 : rho_atom_set(iatom)%drho_rad_h(ispin)%r_coef = 0.0_dp
1186 44813596 : rho_atom_set(iatom)%drho_rad_s(ispin)%r_coef = 0.0_dp
1187 :
1188 243804 : DO j = 1, 3
1189 134440788 : rho_atom_set(iatom)%rho_rad_h_d(j, ispin)%r_coef = 0.0_dp
1190 134501739 : rho_atom_set(iatom)%rho_rad_s_d(j, ispin)%r_coef = 0.0_dp
1191 : END DO
1192 :
1193 60951 : END SUBROUTINE set2zero_rho_atom_rad
1194 :
1195 : ! **************************************************************************************************
1196 : !> \brief Symmetrize PAW cpc_h/cpc_s blocks and MPI-sum packed lower triangles in L2-sized chunks.
1197 : !> \param rho_atom_set atomic PAW density set holding cpc_h and cpc_s blocks
1198 : !> \param natom total number of atoms
1199 : !> \param nspins number of spin components
1200 : !> \param max_gau maximum size of the one-center basis
1201 : !> \param para_env MPI parallel environment
1202 : ! **************************************************************************************************
1203 47304 : SUBROUTINE reduce_symmetrize_cpc(rho_atom_set, natom, nspins, max_gau, para_env)
1204 : TYPE(rho_atom_type), DIMENSION(:), POINTER :: rho_atom_set
1205 : INTEGER, INTENT(IN) :: natom, nspins, max_gau
1206 : TYPE(mp_para_env_type), POINTER :: para_env
1207 :
1208 : INTEGER :: b_end, b_lo, iat, ispin, jj, m1, n, off, &
1209 : p
1210 47304 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: buf
1211 47304 : REAL(KIND=dp), DIMENSION(:, :), POINTER :: r_h, r_s
1212 :
1213 141912 : ALLOCATE (buf(MAX(l2_chunk_dp, nspins*max_gau*(max_gau + 1))))
1214 94608 : b_lo = 1
1215 94608 : DO WHILE (b_lo <= natom)
1216 : b_end = natom
1217 141912 : DO p = 1, 2
1218 : off = 0
1219 388276 : DO iat = b_lo, b_end
1220 293668 : IF (.NOT. ASSOCIATED(rho_atom_set(iat)%cpc_h(1)%r_coef)) CYCLE
1221 256116 : m1 = SIZE(rho_atom_set(iat)%cpc_h(1)%r_coef, 1)
1222 256116 : IF (p == 1 .AND. off > 0 .AND. off + nspins*m1*(m1 + 1) > SIZE(buf)) EXIT
1223 639944 : DO ispin = 1, nspins
1224 289220 : r_h => rho_atom_set(iat)%cpc_h(ispin)%r_coef
1225 289220 : r_s => rho_atom_set(iat)%cpc_s(ispin)%r_coef
1226 5386196 : DO jj = 1, m1
1227 4803308 : n = m1 - jj + 1
1228 39389224 : IF (p == 1) buf(off + 1:off + n) = r_h(jj:m1, jj) + r_h(jj, jj:m1)
1229 36987570 : IF (p == 1) buf(off + n + 1:off + 2*n) = r_s(jj:m1, jj) + r_s(jj, jj:m1)
1230 39389224 : IF (p == 2) r_h(jj:m1, jj) = buf(off + 1:off + n)
1231 36987570 : IF (p == 2) r_h(jj, jj:m1) = buf(off + 1:off + n)
1232 36987570 : IF (p == 2) r_s(jj:m1, jj) = buf(off + n + 1:off + 2*n)
1233 36987570 : IF (p == 2) r_s(jj, jj:m1) = buf(off + n + 1:off + 2*n)
1234 5092528 : off = off + 2*n
1235 : END DO
1236 : END DO
1237 : END DO
1238 94608 : b_end = iat - 1
1239 141912 : IF (p == 1 .AND. off > 0) CALL para_env%sum(buf(1:off))
1240 : END DO
1241 47304 : b_lo = b_end + 1
1242 : END DO
1243 47304 : DEALLOCATE (buf)
1244 47304 : END SUBROUTINE reduce_symmetrize_cpc
1245 :
1246 : END MODULE qs_rho_atom_methods
|