(git:27c966b)
Loading...
Searching...
No Matches
qs_linres_current.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief given the response wavefunctions obtained by the application
10!> of the (rxp), p, and ((dk-dl)xp) operators,
11!> here the current density vector (jx, jy, jz)
12!> is computed for the 3 directions of the magnetic field (Bx, By, Bz)
13!> \par History
14!> created 02-2006 [MI]
15!> \author MI
16! **************************************************************************************************
22 USE cell_types, ONLY: cell_type,&
23 pbc
27 USE cp_dbcsr_api, ONLY: &
28 dbcsr_convert_offsets_to_sizes, dbcsr_copy, dbcsr_create, dbcsr_deallocate_matrix, &
30 dbcsr_set, dbcsr_type, dbcsr_type_antisymmetric, dbcsr_type_no_symmetry
41 USE cp_fm_types, ONLY: cp_fm_create,&
50 USE cp_output_handling, ONLY: cp_p_file,&
59 USE grid_api, ONLY: &
70 USE kinds, ONLY: default_path_length,&
72 dp,&
73 int_8
74 USE mathconstants, ONLY: twopi
77 USE orbital_pointers, ONLY: ncoset
81 USE pw_env_types, ONLY: pw_env_get,&
83 USE pw_methods, ONLY: pw_axpy,&
85 pw_scale,&
88 USE pw_types, ONLY: pw_c1d_gs_type,&
92 USE qs_kind_types, ONLY: get_qs_kind,&
98 USE qs_linres_op, ONLY: fac_vecp,&
100 ind_m2,&
101 set_vecp,&
106 USE qs_mo_types, ONLY: get_mo_set,&
116 USE qs_rho_types, ONLY: qs_rho_get
117 USE qs_subsys_types, ONLY: qs_subsys_get,&
133#include "./base/base_uses.f90"
134
135 IMPLICIT NONE
136
137 PRIVATE
138
139 ! *** Public subroutines ***
141
142 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_linres_current'
143
144 TYPE box_type
145 INTEGER :: n = -1
146 REAL(dp), POINTER, DIMENSION(:, :) :: r => null()
147 END TYPE box_type
148 REAL(dp), DIMENSION(3, 3, 3), PARAMETER :: levi_civita = reshape([ &
149 0.0_dp, 0.0_dp, 0.0_dp, 0.0_dp, 0.0_dp, -1.0_dp, 0.0_dp, 1.0_dp, 0.0_dp, &
150 0.0_dp, 0.0_dp, 1.0_dp, 0.0_dp, 0.0_dp, 0.0_dp, -1.0_dp, 0.0_dp, 0.0_dp, &
151 0.0_dp, -1.0_dp, 0.0_dp, 1.0_dp, 0.0_dp, 0.0_dp, 0.0_dp, 0.0_dp, 0.0_dp], [3, 3, 3])
152
153CONTAINS
154
155! **************************************************************************************************
156!> \brief First calculate the density matrixes, for each component of the current
157!> they are 3 because of the r dependent terms
158!> Next it collocates on the grid to have J(r)
159!> In the GAPW case one need to collocate on the PW grid only the soft part
160!> while the rest goes on Lebedev grids
161!> The contributions to the shift and to the susceptibility will be
162!> calculated separately and added only at the end
163!> The calculation of the shift tensor is performed on the position of the atoms
164!> and on other selected points in real space summing up the contributions
165!> from the PW grid current density and the local densities
166!> Spline interpolation is used
167!> \param current_env ...
168!> \param qs_env ...
169!> \param iB ...
170!> \author MI
171!> \note
172!> The susceptibility is needed to compute the G=0 term of the shift
173!> in reciprocal space. \chi_{ij} = \int (r x Jj)_i
174!> (where Jj id the current density generated by the field in direction j)
175!> To calculate the susceptibility on the PW grids it is necessary to apply
176!> the position operator yet another time.
177!> This cannot be done on directly on the full J(r) because it is not localized
178!> Therefore it is done state by state (see linres_nmr_shift)
179! **************************************************************************************************
180 SUBROUTINE current_build_current(current_env, qs_env, iB)
181 !
182 TYPE(current_env_type) :: current_env
183 TYPE(qs_environment_type), POINTER :: qs_env
184 INTEGER, INTENT(IN) :: ib
185
186 CHARACTER(LEN=*), PARAMETER :: routinen = 'current_build_current'
187
188 CHARACTER(LEN=default_path_length) :: ext, filename, my_pos
189 INTEGER :: handle, idir, iib, iiib, ispin, istate, &
190 j, jstate, nao, natom, nmo, nspins, &
191 nstates(2), output_unit, unit_nr
192 INTEGER, ALLOCATABLE, DIMENSION(:) :: first_sgf, last_sgf
193 INTEGER, DIMENSION(:), POINTER :: row_blk_sizes
194 LOGICAL :: append_cube, gapw, mpi_io
195 REAL(dp) :: dk(3), jrho_tot_g(3, 3), &
196 jrho_tot_r(3, 3), maxocc, scale_fac
197 REAL(dp), ALLOCATABLE, DIMENSION(:, :) :: ddk
198 REAL(dp), EXTERNAL :: ddot
199 TYPE(cell_type), POINTER :: cell
200 TYPE(cp_2d_i_p_type), DIMENSION(:), POINTER :: center_list
201 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: p_psi1, psi1
202 TYPE(cp_fm_type), DIMENSION(:), POINTER :: psi0_order
203 TYPE(cp_fm_type), DIMENSION(:, :), POINTER :: psi1_d, psi1_p, psi1_rxp
204 TYPE(cp_fm_type), POINTER :: mo_coeff
205 TYPE(cp_logger_type), POINTER :: logger
206 TYPE(dbcsr_distribution_type), POINTER :: dbcsr_dist
207 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: density_matrix0, density_matrix_a, &
208 density_matrix_ii, density_matrix_iii
209 TYPE(dft_control_type), POINTER :: dft_control
210 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
211 TYPE(mp_para_env_type), POINTER :: para_env
212 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
213 POINTER :: sab_all
214 TYPE(particle_list_type), POINTER :: particles
215 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
216 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: jrho1_g
217 TYPE(pw_env_type), POINTER :: pw_env
218 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
219 TYPE(pw_r3d_rs_type) :: wf_r
220 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: jrho1_r
221 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
222 TYPE(qs_matrix_pools_type), POINTER :: mpools
223 TYPE(qs_subsys_type), POINTER :: subsys
224 TYPE(realspace_grid_desc_type), POINTER :: auxbas_rs_desc
225 TYPE(section_vals_type), POINTER :: current_section
226
227 CALL timeset(routinen, handle)
228 !
229 NULLIFY (logger, current_section, density_matrix0, density_matrix_a, &
230 density_matrix_ii, density_matrix_iii, cell, dft_control, mos, &
231 particle_set, pw_env, auxbas_rs_desc, auxbas_pw_pool, &
232 para_env, center_list, mo_coeff, jrho1_r, jrho1_g, &
233 psi1_p, psi1_d, psi1_rxp, sab_all, qs_kind_set)
234
235 logger => cp_get_default_logger()
236 output_unit = cp_logger_get_default_io_unit(logger)
237 !
238 !
239 CALL get_current_env(current_env=current_env, &
240 center_list=center_list, &
241 psi1_rxp=psi1_rxp, &
242 psi1_d=psi1_d, &
243 psi1_p=psi1_p, &
244 psi0_order=psi0_order, &
245 nstates=nstates, &
246 nao=nao)
247 !
248 !
249 CALL get_qs_env(qs_env=qs_env, &
250 cell=cell, &
251 dft_control=dft_control, &
252 mos=mos, &
253 mpools=mpools, &
254 pw_env=pw_env, &
255 para_env=para_env, &
256 subsys=subsys, &
257 sab_all=sab_all, &
258 particle_set=particle_set, &
259 qs_kind_set=qs_kind_set, &
260 dbcsr_dist=dbcsr_dist)
261
262 CALL qs_subsys_get(subsys, particles=particles)
263
264 gapw = dft_control%qs_control%gapw
265 nspins = dft_control%nspins
266 natom = SIZE(particle_set, 1)
267 !
268 ! allocate temporary arrays
269 ALLOCATE (psi1(nspins), p_psi1(nspins))
270 DO ispin = 1, nspins
271 CALL cp_fm_create(psi1(ispin), psi0_order(ispin)%matrix_struct)
272 CALL cp_fm_create(p_psi1(ispin), psi0_order(ispin)%matrix_struct)
273 CALL cp_fm_set_all(psi1(ispin), 0.0_dp)
274 CALL cp_fm_set_all(p_psi1(ispin), 0.0_dp)
275 END DO
276 !
277 !
278 CALL dbcsr_allocate_matrix_set(density_matrix0, nspins)
279 CALL dbcsr_allocate_matrix_set(density_matrix_a, nspins)
280 CALL dbcsr_allocate_matrix_set(density_matrix_ii, nspins)
281 CALL dbcsr_allocate_matrix_set(density_matrix_iii, nspins)
282 !
283 ! prepare for allocation
284 ALLOCATE (first_sgf(natom))
285 ALLOCATE (last_sgf(natom))
286 CALL get_particle_set(particle_set, qs_kind_set, &
287 first_sgf=first_sgf, &
288 last_sgf=last_sgf)
289 ALLOCATE (row_blk_sizes(natom))
290 CALL dbcsr_convert_offsets_to_sizes(first_sgf, row_blk_sizes, last_sgf)
291 DEALLOCATE (first_sgf)
292 DEALLOCATE (last_sgf)
293 !
294 !
295 DO ispin = 1, nspins
296 !
297 !density_matrix0
298 ALLOCATE (density_matrix0(ispin)%matrix)
299 CALL dbcsr_create(matrix=density_matrix0(ispin)%matrix, &
300 name="density_matrix0", &
301 dist=dbcsr_dist, matrix_type=dbcsr_type_no_symmetry, &
302 row_blk_size=row_blk_sizes, col_blk_size=row_blk_sizes, &
303 mutable_work=.true.)
304 CALL cp_dbcsr_alloc_block_from_nbl(density_matrix0(ispin)%matrix, sab_all)
305 !
306 !density_matrix_a
307 ALLOCATE (density_matrix_a(ispin)%matrix)
308 CALL dbcsr_copy(density_matrix_a(ispin)%matrix, density_matrix0(ispin)%matrix, &
309 name="density_matrix_a")
310 !
311 !density_matrix_ii
312 ALLOCATE (density_matrix_ii(ispin)%matrix)
313 CALL dbcsr_copy(density_matrix_ii(ispin)%matrix, density_matrix0(ispin)%matrix, &
314 name="density_matrix_ii")
315 !
316 !density_matrix_iii
317 ALLOCATE (density_matrix_iii(ispin)%matrix)
318 CALL dbcsr_copy(density_matrix_iii(ispin)%matrix, density_matrix0(ispin)%matrix, &
319 name="density_matrix_iii")
320 END DO
321 !
322 DEALLOCATE (row_blk_sizes)
323 !
324 !
325 current_section => section_vals_get_subs_vals(qs_env%input, "PROPERTIES%LINRES%CURRENT")
326 !
327 !
328 jrho_tot_g = 0.0_dp
329 jrho_tot_r = 0.0_dp
330 !
331 ! Lets go!
332 CALL set_vecp(ib, iib, iiib)
333 DO ispin = 1, nspins
334 nmo = nstates(ispin)
335 mo_coeff => psi0_order(ispin)
336 !maxocc = max_occ(ispin)
337 !
338 CALL get_mo_set(mo_set=mos(ispin), maxocc=maxocc)
339 !
340 !
341 ! Build the first density matrix
342 CALL dbcsr_set(density_matrix0(ispin)%matrix, 0.0_dp)
343 CALL cp_dbcsr_plus_fm_fm_t(sparse_matrix=density_matrix0(ispin)%matrix, &
344 matrix_v=mo_coeff, matrix_g=mo_coeff, &
345 ncol=nmo, alpha=maxocc)
346 !
347 ! Allocate buffer vectors
348 ALLOCATE (ddk(3, nmo))
349 !
350 ! Construct the 3 density matrices for the field in direction iB
351 !
352 ! First the full matrix psi_a_iB
353 associate(psi_a_ib => psi1(ispin), psi_buf => p_psi1(ispin))
354 CALL cp_fm_set_all(psi_a_ib, 0.0_dp)
355 CALL cp_fm_set_all(psi_buf, 0.0_dp)
356 ! psi_a_iB = - (R_\nu-dk)_ii psi1_piiiB + (R_\nu-dk)_iii psi1_piiB
357 !
358 ! contributions from the response psi1_p_ii and psi1_p_iii
359 DO istate = 1, current_env%nbr_center(ispin)
360 dk(1:3) = current_env%centers_set(ispin)%array(1:3, istate)
361 !
362 ! Copy the vector in the full matrix psi1
363 !nstate_loc = center_list(ispin)%array(1,icenter+1)-center_list(ispin)%array(1,icenter)
364 DO j = center_list(ispin)%array(1, istate), center_list(ispin)%array(1, istate + 1) - 1
365 jstate = center_list(ispin)%array(2, j)
366 CALL cp_fm_to_fm(psi1_p(ispin, iib), psi_a_ib, 1, jstate, jstate)
367 CALL cp_fm_to_fm(psi1_p(ispin, iiib), psi_buf, 1, jstate, jstate)
368 ddk(:, jstate) = dk(1:3)
369 END DO
370 END DO ! istate
371 CALL fm_scale_by_pbc_ac(psi_a_ib, current_env%basisfun_center, ddk, cell, iiib)
372 CALL fm_scale_by_pbc_ac(psi_buf, current_env%basisfun_center, ddk, cell, iib)
373 CALL cp_fm_scale_and_add(-1.0_dp, psi_a_ib, 1.0_dp, psi_buf)
374 !
375 !psi_a_iB = psi_a_iB + psi1_rxp
376 !
377 ! contribution from the response psi1_rxp
378 CALL cp_fm_scale_and_add(-1.0_dp, psi_a_ib, 1.0_dp, psi1_rxp(ispin, ib))
379 !
380 !psi_a_iB = psi_a_iB - psi1_D
381 IF (current_env%full) THEN
382 !
383 ! contribution from the response psi1_D
384 CALL cp_fm_scale_and_add(1.0_dp, psi_a_ib, -1.0_dp, psi1_d(ispin, ib))
385 END IF
386 !
387 ! Multiply by the occupation number for the density matrix
388 !
389 ! Build the first density matrix
390 CALL dbcsr_set(density_matrix_a(ispin)%matrix, 0.0_dp)
391 CALL cp_dbcsr_plus_fm_fm_t(sparse_matrix=density_matrix_a(ispin)%matrix, &
392 matrix_v=mo_coeff, matrix_g=psi_a_ib, &
393 ncol=nmo, alpha=maxocc)
394 END associate
395 !
396 ! Build the second density matrix
397 CALL dbcsr_set(density_matrix_iii(ispin)%matrix, 0.0_dp)
398 CALL cp_dbcsr_plus_fm_fm_t(sparse_matrix=density_matrix_iii(ispin)%matrix, &
399 matrix_v=mo_coeff, matrix_g=psi1_p(ispin, iiib), &
400 ncol=nmo, alpha=maxocc)
401 !
402 ! Build the third density matrix
403 CALL dbcsr_set(density_matrix_ii(ispin)%matrix, 0.0_dp)
404 CALL cp_dbcsr_plus_fm_fm_t(sparse_matrix=density_matrix_ii(ispin)%matrix, &
405 matrix_v=mo_coeff, matrix_g=psi1_p(ispin, iib), &
406 ncol=nmo, alpha=maxocc)
407 DO idir = 1, 3
408 !
409 ! Calculate the current density on the pw grid (only soft if GAPW)
410 ! idir is the cartesian component of the response current density
411 ! generated by the magnetic field pointing in cartesian direction iB
412 ! Use the qs_rho_type already used for rho during the scf
413 CALL qs_rho_get(current_env%jrho1_set(idir)%rho, rho_r=jrho1_r)
414 CALL qs_rho_get(current_env%jrho1_set(idir)%rho, rho_g=jrho1_g)
415 associate(jrho_rspace => jrho1_r(ispin), jrho_gspace => jrho1_g(ispin))
416 CALL pw_zero(jrho_rspace)
417 CALL pw_zero(jrho_gspace)
418 CALL calculate_jrho_resp(density_matrix0(ispin)%matrix, &
419 density_matrix_a(ispin)%matrix, &
420 density_matrix_ii(ispin)%matrix, &
421 density_matrix_iii(ispin)%matrix, &
422 ib, idir, jrho_rspace, jrho_gspace, qs_env, &
423 current_env, gapw)
424
425 scale_fac = cell%deth/twopi
426 CALL pw_scale(jrho_rspace, scale_fac)
427 CALL pw_scale(jrho_gspace, scale_fac)
428
429 jrho_tot_g(idir, ib) = pw_integrate_function(jrho_gspace, isign=-1)
430 jrho_tot_r(idir, ib) = pw_integrate_function(jrho_rspace, isign=-1)
431 END associate
432
433 IF (output_unit > 0) THEN
434 WRITE (output_unit, '(T2,2(A,E24.16))') 'Integrated j_'&
435 &//achar(idir + 119)//achar(ib + 119)//'(r): G-space=', &
436 jrho_tot_g(idir, ib), ' R-space=', jrho_tot_r(idir, ib)
437 END IF
438 !
439 END DO ! idir
440 !
441 ! Deallocate buffer vectors
442 DEALLOCATE (ddk)
443 !
444 END DO ! ispin
445
446 IF (gapw) THEN
447 DO idir = 1, 3
448 !
449 ! compute the atomic response current densities on the spherical grids
450 ! First the sparse matrices are multiplied by the expansion coefficients
451 ! this is the equivalent of the CPC for the charge density
452 CALL calculate_jrho_atom_coeff(qs_env, current_env, &
453 density_matrix0, &
454 density_matrix_a, &
455 density_matrix_ii, &
456 density_matrix_iii, &
457 ib, idir)
458 !
459 ! Then the radial parts are computed on the local radial grid, atom by atom
460 ! 8 functions are computed for each atom, per grid point
461 ! and per LM angular momentum. The multiplication by the Clebsh-Gordon
462 ! coefficients or they correspondent for the derivatives, is also done here
463 CALL calculate_jrho_atom_rad(qs_env, current_env, idir)
464 !
465 ! The current on the atomic grids
466 CALL calculate_jrho_atom(current_env, qs_env, ib, idir)
467 END DO ! idir
468 END IF
469 !
470 ! Cube files
471 IF (btest(cp_print_key_should_output(logger%iter_info, current_section,&
472 & "PRINT%CURRENT_CUBES"), cp_p_file)) THEN
473 append_cube = section_get_lval(current_section, "PRINT%CURRENT_CUBES%APPEND")
474 my_pos = "REWIND"
475 IF (append_cube) THEN
476 my_pos = "APPEND"
477 END IF
478 !
479 CALL pw_env_get(pw_env, auxbas_rs_desc=auxbas_rs_desc, &
480 auxbas_pw_pool=auxbas_pw_pool)
481 !
482 CALL auxbas_pw_pool%create_pw(wf_r)
483 !
484 DO idir = 1, 3
485 CALL pw_zero(wf_r)
486 CALL qs_rho_get(current_env%jrho1_set(idir)%rho, rho_r=jrho1_r)
487 DO ispin = 1, nspins
488 CALL pw_axpy(jrho1_r(ispin), wf_r, 1.0_dp)
489 END DO
490 !
491 IF (gapw) THEN
492 ! Add the local hard and soft contributions
493 ! This can be done atom by atom by a spline extrapolation of the values
494 ! on the spherical grid to the grid points.
495 cpabort("GAPW needs to be finalized")
496 END IF
497 filename = "jresp"
498 mpi_io = .true.
499 WRITE (ext, '(a2,I1,a2,I1,a5)') "iB", ib, "_d", idir, ".cube"
500 WRITE (ext, '(a2,a1,a2,a1,a5)') "iB", achar(ib + 119), "_d", achar(idir + 119), ".cube"
501 unit_nr = cp_print_key_unit_nr(logger, current_section, "PRINT%CURRENT_CUBES", &
502 extension=trim(ext), middle_name=trim(filename), &
503 log_filename=.false., file_position=my_pos, &
504 mpi_io=mpi_io)
505
506 CALL cp_pw_to_cube(wf_r, unit_nr, "RESPONSE CURRENT DENSITY ", &
507 particles=particles, &
508 stride=section_get_ivals(current_section, "PRINT%CURRENT_CUBES%STRIDE"), &
509 mpi_io=mpi_io)
510 CALL cp_print_key_finished_output(unit_nr, logger, current_section,&
511 & "PRINT%CURRENT_CUBES", mpi_io=mpi_io)
512 END DO
513 !
514 CALL auxbas_pw_pool%give_back_pw(wf_r)
515 END IF ! current cube
516 !
517 ! Integrated current response checksum
518 IF (output_unit > 0) THEN
519 WRITE (output_unit, '(T2,A,E24.16)') 'CheckSum R-integrated j=', &
520 sqrt(ddot(9, jrho_tot_r(1, 1), 1, jrho_tot_r(1, 1), 1))
521 END IF
522 !
523 !
524 ! Dellocate grids for the calculation of jrho and the shift
525 CALL cp_fm_release(psi1)
526 CALL cp_fm_release(p_psi1)
527
528 CALL dbcsr_deallocate_matrix_set(density_matrix0)
529 CALL dbcsr_deallocate_matrix_set(density_matrix_a)
530 CALL dbcsr_deallocate_matrix_set(density_matrix_ii)
531 CALL dbcsr_deallocate_matrix_set(density_matrix_iii)
532 !
533 ! Finalize
534 CALL timestop(handle)
535 !
536 END SUBROUTINE current_build_current
537
538! **************************************************************************************************
539!> \brief Calculation of the idir component of the response current density
540!> in the presence of a constant magnetic field in direction iB
541!> the current density is collocated on the pw grid in real space
542!> \param mat_d0 ...
543!> \param mat_jp ...
544!> \param mat_jp_rii ...
545!> \param mat_jp_riii ...
546!> \param iB ...
547!> \param idir ...
548!> \param current_rs ...
549!> \param current_gs ...
550!> \param qs_env ...
551!> \param current_env ...
552!> \param soft_valid ...
553!> \param retain_rsgrid ...
554!> \note
555!> The collocate is done in three parts, one for each density matrix
556!> In all cases the density matrices and therefore the collocation
557!> are not symmetric, that means that all the pairs (ab and ba) have
558!> to be considered separately
559!>
560!> mat_jp_{\mu\nu} is multiplied by
561!> f_{\mu\nu} = \phi_{\mu} (d\phi_{\nu}/dr)_{idir} -
562!> (d\phi_{\mu}/dr)_{idir} \phi_{\nu}
563!>
564!> mat_jp_rii_{\mu\nu} is multiplied by
565!> f_{\mu\nu} = \phi_{\mu} (r - R_{\nu})_{iiiB} (d\phi_{\nu}/dr)_{idir} -
566!> (d\phi_{\mu}/dr)_{idir} (r - R_{\nu})_{iiiB} \phi_{\nu} +
567!> \phi_{\mu} \phi_{\nu} (last term only if iiiB=idir)
568!>
569!> mat_jp_riii_{\mu\nu} is multiplied by
570!> (be careful: change in sign with respect to previous)
571!> f_{\mu\nu} = -\phi_{\mu} (r - R_{\nu})_{iiB} (d\phi_{\nu}/dr)_{idir} +
572!> (d\phi_{\mu}/dr)_{idir} (r - R_{\nu})_{iiB} \phi_{\nu} -
573!> \phi_{\mu} \phi_{\nu} (last term only if iiB=idir)
574!>
575!> All the terms sum up to the same grid
576! **************************************************************************************************
577 SUBROUTINE calculate_jrho_resp(mat_d0, mat_jp, mat_jp_rii, mat_jp_riii, iB, idir, &
578 current_rs, current_gs, qs_env, current_env, soft_valid, retain_rsgrid)
579
580 TYPE(dbcsr_type), POINTER :: mat_d0, mat_jp, mat_jp_rii, mat_jp_riii
581 INTEGER, INTENT(IN) :: ib, idir
582 TYPE(pw_r3d_rs_type), INTENT(INOUT) :: current_rs
583 TYPE(pw_c1d_gs_type), INTENT(INOUT) :: current_gs
584 TYPE(qs_environment_type), POINTER :: qs_env
585 TYPE(current_env_type) :: current_env
586 LOGICAL, INTENT(IN), OPTIONAL :: soft_valid, retain_rsgrid
587
588 CHARACTER(LEN=*), PARAMETER :: routinen = 'calculate_jrho_resp'
589 INTEGER, PARAMETER :: max_tasks = 2000
590
591 CHARACTER(LEN=default_string_length) :: basis_type
592 INTEGER :: adbmdab_func, bcol, brow, cindex, curr_tasks, handle, i, iatom, iatom_old, idir2, &
593 igrid_level, iib, iiib, ikind, ikind_old, ipgf, iset, iset_old, itask, ithread, jatom, &
594 jatom_old, jkind, jkind_old, jpgf, jset, jset_old, maxco, maxpgf, maxset, maxsgf, &
595 maxsgf_set, na1, na2, natom, nb1, nb2, ncoa, ncob, nimages, nkind, nseta, nsetb, ntasks, &
596 nthread, sgfa, sgfb
597 INTEGER, DIMENSION(:), POINTER :: la_max, la_min, lb_max, lb_min, npgfa, &
598 npgfb, nsgfa, nsgfb
599 INTEGER, DIMENSION(:, :), POINTER :: first_sgfa, first_sgfb
600 LOGICAL :: atom_pair_changed, den_found, &
601 den_found_a, distributed_rs_grids, &
602 do_igaim, my_retain_rsgrid, my_soft
603 REAL(dp), DIMENSION(:, :, :), POINTER :: my_current, my_gauge, my_rho
604 REAL(kind=dp) :: eps_rho_rspace, f, kind_radius_a, &
605 kind_radius_b, lxo2, lyo2, lzo2, &
606 prefactor, radius, scale, scale2, zetp
607 REAL(kind=dp), DIMENSION(3) :: ra, rab, rb, rp
608 REAL(kind=dp), DIMENSION(:), POINTER :: set_radius_a, set_radius_b
609 REAL(kind=dp), DIMENSION(:, :), POINTER :: jp_block_a, jp_block_b, jp_block_c, jp_block_d, &
610 jpab_a, jpab_b, jpab_c, jpab_d, rpgfa, rpgfb, sphi_a, sphi_b, work, zeta, zetb
611 REAL(kind=dp), DIMENSION(:, :, :), POINTER :: jpabt_a, jpabt_b, jpabt_c, jpabt_d, workt
612 TYPE(atom_pair_type), DIMENSION(:), POINTER :: atom_pair_recv, atom_pair_send
613 TYPE(cell_type), POINTER :: cell
614 TYPE(cube_info_type), DIMENSION(:), POINTER :: cube_info
615 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: deltajp_a, deltajp_b, deltajp_c, &
616 deltajp_d
617 TYPE(dbcsr_type), POINTER :: mat_a, mat_b, mat_c, mat_d
618 TYPE(dft_control_type), POINTER :: dft_control
619 TYPE(gridlevel_info_type), POINTER :: gridlevel_info
620 TYPE(gto_basis_set_p_type), DIMENSION(:), POINTER :: basis_set_list
621 TYPE(gto_basis_set_type), POINTER :: basis_set_a, basis_set_b, orb_basis_set
622 TYPE(mp_para_env_type), POINTER :: para_env
623 TYPE(neighbor_list_iterator_p_type), &
624 DIMENSION(:), POINTER :: nl_iterator
625 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
626 POINTER :: sab_orb
627 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
628 TYPE(pw_env_type), POINTER :: pw_env
629 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
630 TYPE(qs_kind_type), POINTER :: qs_kind
631 TYPE(realspace_grid_desc_p_type), DIMENSION(:), &
632 POINTER :: rs_descs
633 TYPE(realspace_grid_type), DIMENSION(:), POINTER :: rs_current, rs_rho
634 TYPE(realspace_grid_type), DIMENSION(:, :), &
635 POINTER :: rs_gauge
636 TYPE(task_type), DIMENSION(:), POINTER :: tasks
637
638 NULLIFY (qs_kind, cell, dft_control, orb_basis_set, rs_rho, &
639 qs_kind_set, sab_orb, particle_set, rs_current, pw_env, &
640 rs_descs, para_env, set_radius_a, set_radius_b, la_max, la_min, &
641 lb_max, lb_min, npgfa, npgfb, nsgfa, nsgfb, rpgfa, rpgfb, &
642 sphi_a, sphi_b, zeta, zetb, first_sgfa, first_sgfb, tasks, &
643 workt, mat_a, mat_b, mat_c, mat_d, rs_gauge)
644 NULLIFY (deltajp_a, deltajp_b, deltajp_c, deltajp_d)
645 NULLIFY (jp_block_a, jp_block_b, jp_block_c, jp_block_d)
646 NULLIFY (jpabt_a, jpabt_b, jpabt_c, jpabt_d)
647 NULLIFY (atom_pair_send, atom_pair_recv)
648
649 CALL timeset(routinen, handle)
650
651 !
652 ! Set pointers for the different gauge
653 ! If do_igaim is False the current_env is never needed
654 do_igaim = current_env%gauge == current_gauge_atom
655
656 mat_a => mat_jp
657 mat_b => mat_jp_rii
658 mat_c => mat_jp_riii
659 IF (do_igaim) mat_d => mat_d0
660
661 my_retain_rsgrid = .false.
662 IF (PRESENT(retain_rsgrid)) my_retain_rsgrid = retain_rsgrid
663
664 CALL get_qs_env(qs_env=qs_env, &
665 qs_kind_set=qs_kind_set, &
666 cell=cell, &
667 dft_control=dft_control, &
668 particle_set=particle_set, &
669 sab_all=sab_orb, &
670 para_env=para_env, &
671 pw_env=pw_env)
672
673 IF (do_igaim) CALL get_current_env(current_env=current_env, rs_gauge=rs_gauge)
674
675 ! Component of appearing in the vector product rxp, iiB and iiiB
676 CALL set_vecp(ib, iib, iiib)
677 !
678 !
679 scale2 = 0.0_dp
680 idir2 = 1
681 IF (idir /= ib) THEN
682 CALL set_vecp_rev(idir, ib, idir2)
683 scale2 = fac_vecp(idir, ib, idir2)
684 END IF
685 !
686 ! *** assign from pw_env
687 gridlevel_info => pw_env%gridlevel_info
688 cube_info => pw_env%cube_info
689
690 ! Check that the neighbor list with all the pairs is associated
691 cpassert(ASSOCIATED(sab_orb))
692 ! *** set up the pw multi-grids
693 cpassert(ASSOCIATED(pw_env))
694 CALL pw_env_get(pw_env, rs_descs=rs_descs, rs_grids=rs_rho)
695
696 distributed_rs_grids = .false.
697 DO igrid_level = 1, gridlevel_info%ngrid_levels
698 IF (.NOT. all(rs_descs(igrid_level)%rs_desc%perd == 1)) THEN
699 distributed_rs_grids = .true.
700 END IF
701 END DO
702 eps_rho_rspace = dft_control%qs_control%eps_rho_rspace
703 nthread = 1
704
705 ! *** Allocate work storage ***
706 CALL get_qs_kind_set(qs_kind_set=qs_kind_set, &
707 maxco=maxco, &
708 maxsgf=maxsgf, &
709 maxsgf_set=maxsgf_set)
710
711 lxo2 = sqrt(sum(cell%hmat(:, 1)**2))/2.0_dp
712 lyo2 = sqrt(sum(cell%hmat(:, 2)**2))/2.0_dp
713 lzo2 = sqrt(sum(cell%hmat(:, 3)**2))/2.0_dp
714
715 my_soft = .false.
716 IF (PRESENT(soft_valid)) my_soft = soft_valid
717 IF (my_soft) THEN
718 basis_type = "ORB_SOFT"
719 ELSE
720 basis_type = "ORB"
721 END IF
722
723 nkind = SIZE(qs_kind_set)
724
725 CALL reallocate(jpabt_a, 1, maxco, 1, maxco, 0, nthread - 1)
726 CALL reallocate(jpabt_b, 1, maxco, 1, maxco, 0, nthread - 1)
727 CALL reallocate(jpabt_c, 1, maxco, 1, maxco, 0, nthread - 1)
728 CALL reallocate(jpabt_d, 1, maxco, 1, maxco, 0, nthread - 1)
729 CALL reallocate(workt, 1, maxco, 1, maxsgf_set, 0, nthread - 1)
730 CALL reallocate_tasks(tasks, max_tasks)
731
732 ntasks = 0
733 curr_tasks = SIZE(tasks)
734
735 ! get maximum numbers
736 natom = SIZE(particle_set)
737 maxset = 0
738 maxpgf = 0
739
740 ! hard code matrix index (no kpoints)
741 nimages = dft_control%nimages
742 cpassert(nimages == 1)
743 cindex = 1
744
745 DO ikind = 1, nkind
746 qs_kind => qs_kind_set(ikind)
747
748 CALL get_qs_kind(qs_kind=qs_kind, basis_set=orb_basis_set)
749
750 IF (.NOT. ASSOCIATED(orb_basis_set)) cycle
751
752 CALL get_gto_basis_set(gto_basis_set=orb_basis_set, npgf=npgfa, nset=nseta)
753 maxset = max(nseta, maxset)
754 maxpgf = max(maxval(npgfa), maxpgf)
755 END DO
756
757 ! *** Initialize working density matrix ***
758
759 ! distributed rs grids require a matrix that will be changed (distribute_tasks)
760 ! whereas this is not the case for replicated grids
761 ALLOCATE (deltajp_a(1), deltajp_b(1), deltajp_c(1), deltajp_d(1))
762 IF (distributed_rs_grids) THEN
763 ALLOCATE (deltajp_a(1)%matrix, deltajp_b(1)%matrix, deltajp_c(1)%matrix)
764 IF (do_igaim) THEN
765 ALLOCATE (deltajp_d(1)%matrix)
766 END IF
767
768 CALL dbcsr_create(deltajp_a(1)%matrix, template=mat_a, name='deltajp_a')
769 CALL dbcsr_create(deltajp_b(1)%matrix, template=mat_a, name='deltajp_b')
770 CALL dbcsr_create(deltajp_c(1)%matrix, template=mat_a, name='deltajp_c')
771 IF (do_igaim) CALL dbcsr_create(deltajp_d(1)%matrix, template=mat_a, name='deltajp_d')
772 ELSE
773 deltajp_a(1)%matrix => mat_a !mat_jp
774 deltajp_b(1)%matrix => mat_b !mat_jp_rii
775 deltajp_c(1)%matrix => mat_c !mat_jp_riii
776 IF (do_igaim) deltajp_d(1)%matrix => mat_d !mat_d0
777 END IF
778
779 ALLOCATE (basis_set_list(nkind))
780 DO ikind = 1, nkind
781 qs_kind => qs_kind_set(ikind)
782 CALL get_qs_kind(qs_kind=qs_kind, basis_set=basis_set_a, basis_type=basis_type)
783 IF (ASSOCIATED(basis_set_a)) THEN
784 basis_set_list(ikind)%gto_basis_set => basis_set_a
785 ELSE
786 NULLIFY (basis_set_list(ikind)%gto_basis_set)
787 END IF
788 END DO
789 CALL neighbor_list_iterator_create(nl_iterator, sab_orb)
790 DO WHILE (neighbor_list_iterate(nl_iterator) == 0)
791 CALL get_iterator_info(nl_iterator, ikind=ikind, jkind=jkind, iatom=iatom, jatom=jatom, r=rab)
792 basis_set_a => basis_set_list(ikind)%gto_basis_set
793 IF (.NOT. ASSOCIATED(basis_set_a)) cycle
794 basis_set_b => basis_set_list(jkind)%gto_basis_set
795 IF (.NOT. ASSOCIATED(basis_set_b)) cycle
796 ra(:) = pbc(particle_set(iatom)%r, cell)
797 ! basis ikind
798 first_sgfa => basis_set_a%first_sgf
799 la_max => basis_set_a%lmax
800 la_min => basis_set_a%lmin
801 npgfa => basis_set_a%npgf
802 nseta = basis_set_a%nset
803 nsgfa => basis_set_a%nsgf_set
804 rpgfa => basis_set_a%pgf_radius
805 set_radius_a => basis_set_a%set_radius
806 kind_radius_a = basis_set_a%kind_radius
807 sphi_a => basis_set_a%sphi
808 zeta => basis_set_a%zet
809 ! basis jkind
810 first_sgfb => basis_set_b%first_sgf
811 lb_max => basis_set_b%lmax
812 lb_min => basis_set_b%lmin
813 npgfb => basis_set_b%npgf
814 nsetb = basis_set_b%nset
815 nsgfb => basis_set_b%nsgf_set
816 rpgfb => basis_set_b%pgf_radius
817 set_radius_b => basis_set_b%set_radius
818 kind_radius_b = basis_set_b%kind_radius
819 sphi_b => basis_set_b%sphi
820 zetb => basis_set_b%zet
821
822 IF (abs(rab(1)) > lxo2 .OR. abs(rab(2)) > lyo2 .OR. abs(rab(3)) > lzo2) THEN
823 cycle
824 END IF
825
826 brow = iatom
827 bcol = jatom
828
829 CALL dbcsr_get_block_p(matrix=mat_a, row=brow, col=bcol, &
830 block=jp_block_a, found=den_found_a)
831 CALL dbcsr_get_block_p(matrix=mat_b, row=brow, col=bcol, &
832 block=jp_block_b, found=den_found)
833 CALL dbcsr_get_block_p(matrix=mat_c, row=brow, col=bcol, &
834 block=jp_block_c, found=den_found)
835 IF (do_igaim) CALL dbcsr_get_block_p(matrix=mat_d, row=brow, col=bcol, &
836 block=jp_block_d, found=den_found)
837
838 IF (.NOT. ASSOCIATED(jp_block_a)) cycle
839
840 IF (distributed_rs_grids) THEN
841 CALL dbcsr_put_block(deltajp_a(1)%matrix, brow, bcol, jp_block_a)
842 CALL dbcsr_put_block(deltajp_b(1)%matrix, brow, bcol, jp_block_b)
843 CALL dbcsr_put_block(deltajp_c(1)%matrix, brow, bcol, jp_block_c)
844 IF (do_igaim) THEN
845 CALL dbcsr_put_block(deltajp_d(1)%matrix, brow, bcol, jp_block_d)
846 END IF
847 END IF
848
849 CALL task_list_inner_loop(tasks, ntasks, curr_tasks, rs_descs, &
850 dft_control, cube_info, gridlevel_info, cindex, &
851 iatom, jatom, rpgfa, rpgfb, zeta, zetb, kind_radius_b, &
852 set_radius_a, set_radius_b, ra, rab, &
853 la_max, la_min, lb_max, lb_min, npgfa, npgfb, nseta, nsetb)
854
855 END DO
856 CALL neighbor_list_iterator_release(nl_iterator)
857
858 DEALLOCATE (basis_set_list)
859
860 IF (distributed_rs_grids) THEN
861 CALL dbcsr_finalize(deltajp_a(1)%matrix)
862 CALL dbcsr_finalize(deltajp_b(1)%matrix)
863 CALL dbcsr_finalize(deltajp_c(1)%matrix)
864 IF (do_igaim) CALL dbcsr_finalize(deltajp_d(1)%matrix)
865 END IF
866
867 ! sorts / redistributes the task list
868 ! The replicated current matrices above alias owner-local blocks and are not prepared for migration.
869 CALL distribute_tasks(rs_descs=rs_descs, ntasks=ntasks, natoms=natom, tasks=tasks, &
870 atom_pair_send=atom_pair_send, atom_pair_recv=atom_pair_recv, &
871 symmetric=.false., reorder_rs_grid_ranks=.true., &
872 skip_load_balance_distributed=.false., balance_replicated=.false.)
873
874 ALLOCATE (rs_current(gridlevel_info%ngrid_levels))
875
876 DO igrid_level = 1, gridlevel_info%ngrid_levels
877 ! Here we need to reallocate the distributed rs_grids, which may have been reordered
878 ! by distribute_tasks
879 IF (rs_descs(igrid_level)%rs_desc%distributed .AND. .NOT. my_retain_rsgrid) THEN
880 CALL rs_grid_release(rs_rho(igrid_level))
881 CALL rs_grid_create(rs_rho(igrid_level), rs_descs(igrid_level)%rs_desc)
882 END IF
883 CALL rs_grid_zero(rs_rho(igrid_level))
884 CALL rs_grid_create(rs_current(igrid_level), rs_descs(igrid_level)%rs_desc)
885 CALL rs_grid_zero(rs_current(igrid_level))
886 END DO
887
888 !
889 ! we need to build the gauge here
890 IF (.NOT. current_env%gauge_init .AND. do_igaim) THEN
891 CALL current_set_gauge(current_env, qs_env)
892 current_env%gauge_init = .true.
893 END IF
894 !
895 ! for any case double check the bounds !
896 IF (do_igaim) THEN
897 DO igrid_level = 1, gridlevel_info%ngrid_levels
898 my_rho => rs_rho(igrid_level)%r
899 my_current => rs_current(igrid_level)%r
900 IF (lbound(my_rho, 3) /= lbound(my_current, 3) .OR. &
901 lbound(my_rho, 2) /= lbound(my_current, 2) .OR. &
902 lbound(my_rho, 1) /= lbound(my_current, 1) .OR. &
903 ubound(my_rho, 3) /= ubound(my_current, 3) .OR. &
904 ubound(my_rho, 2) /= ubound(my_current, 2) .OR. &
905 ubound(my_rho, 1) /= ubound(my_current, 1)) THEN
906 WRITE (*, *) 'LBOUND(my_rho,3),LBOUND(my_current,3)', lbound(my_rho, 3), lbound(my_current, 3)
907 WRITE (*, *) 'LBOUND(my_rho,2),LBOUND(my_current,2)', lbound(my_rho, 2), lbound(my_current, 2)
908 WRITE (*, *) 'LBOUND(my_rho,1),LBOUND(my_current,1)', lbound(my_rho, 1), lbound(my_current, 1)
909 WRITE (*, *) 'UBOUND(my_rho,3),UBOUND(my_current,3)', ubound(my_rho, 3), ubound(my_current, 3)
910 WRITE (*, *) 'UBOUND(my_rho,2),UBOUND(my_current,2)', ubound(my_rho, 2), ubound(my_current, 2)
911 WRITE (*, *) 'UBOUND(my_rho,1),UBOUND(my_current,1)', ubound(my_rho, 1), ubound(my_current, 1)
912 cpabort("Bug")
913 END IF
914
915 my_gauge => rs_gauge(1, igrid_level)%r
916 IF (lbound(my_rho, 3) /= lbound(my_gauge, 3) .OR. &
917 lbound(my_rho, 2) /= lbound(my_gauge, 2) .OR. &
918 lbound(my_rho, 1) /= lbound(my_gauge, 1) .OR. &
919 ubound(my_rho, 3) /= ubound(my_gauge, 3) .OR. &
920 ubound(my_rho, 2) /= ubound(my_gauge, 2) .OR. &
921 ubound(my_rho, 1) /= ubound(my_gauge, 1)) THEN
922 WRITE (*, *) 'LBOUND(my_rho,3),LBOUND(my_gauge,3)', lbound(my_rho, 3), lbound(my_gauge, 3)
923 WRITE (*, *) 'LBOUND(my_rho,2),LBOUND(my_gauge,2)', lbound(my_rho, 2), lbound(my_gauge, 2)
924 WRITE (*, *) 'LBOUND(my_rho,1),LBOUND(my_gauge,1)', lbound(my_rho, 1), lbound(my_gauge, 1)
925 WRITE (*, *) 'UBOUND(my_rho,3),UbOUND(my_gauge,3)', ubound(my_rho, 3), ubound(my_gauge, 3)
926 WRITE (*, *) 'UBOUND(my_rho,2),UBOUND(my_gauge,2)', ubound(my_rho, 2), ubound(my_gauge, 2)
927 WRITE (*, *) 'UBOUND(my_rho,1),UBOUND(my_gauge,1)', ubound(my_rho, 1), ubound(my_gauge, 1)
928 cpabort("Bug")
929 END IF
930 END DO
931 END IF
932 !
933 !-------------------------------------------------------------
934
935 IF (distributed_rs_grids) THEN
936 CALL rs_distribute_matrix(rs_descs=rs_descs, pmats=deltajp_a, &
937 atom_pair_send=atom_pair_send, atom_pair_recv=atom_pair_recv, &
938 nimages=nimages, scatter=.true.)
939 CALL rs_distribute_matrix(rs_descs=rs_descs, pmats=deltajp_b, &
940 atom_pair_send=atom_pair_send, atom_pair_recv=atom_pair_recv, &
941 nimages=nimages, scatter=.true.)
942 CALL rs_distribute_matrix(rs_descs=rs_descs, pmats=deltajp_c, &
943 atom_pair_send=atom_pair_send, atom_pair_recv=atom_pair_recv, &
944 nimages=nimages, scatter=.true.)
945 IF (do_igaim) CALL rs_distribute_matrix(rs_descs=rs_descs, pmats=deltajp_d, &
946 atom_pair_send=atom_pair_send, atom_pair_recv=atom_pair_recv, &
947 nimages=nimages, scatter=.true.)
948 END IF
949
950 ithread = 0
951 jpab_a => jpabt_a(:, :, ithread)
952 jpab_b => jpabt_b(:, :, ithread)
953 jpab_c => jpabt_c(:, :, ithread)
954 IF (do_igaim) jpab_d => jpabt_d(:, :, ithread)
955 work => workt(:, :, ithread)
956
957 iatom_old = -1; jatom_old = -1; iset_old = -1; jset_old = -1
958 ikind_old = -1; jkind_old = -1
959
960 loop_tasks: DO itask = 1, ntasks
961 igrid_level = tasks(itask)%grid_level
962 cindex = tasks(itask)%image
963 iatom = tasks(itask)%iatom
964 jatom = tasks(itask)%jatom
965 iset = tasks(itask)%iset
966 jset = tasks(itask)%jset
967 ipgf = tasks(itask)%ipgf
968 jpgf = tasks(itask)%jpgf
969
970 ! apparently generalised collocation not implemented correctly yet
971 cpassert(tasks(itask)%dist_type /= 2)
972
973 IF (iatom /= iatom_old .OR. jatom /= jatom_old) THEN
974
975 ikind = particle_set(iatom)%atomic_kind%kind_number
976 jkind = particle_set(jatom)%atomic_kind%kind_number
977
978 IF (iatom /= iatom_old) ra(:) = pbc(particle_set(iatom)%r, cell)
979
980 brow = iatom
981 bcol = jatom
982
983 IF (ikind /= ikind_old) THEN
984 CALL get_qs_kind(qs_kind_set(ikind), basis_set=orb_basis_set, &
985 basis_type=basis_type)
986
987 CALL get_gto_basis_set(gto_basis_set=orb_basis_set, &
988 first_sgf=first_sgfa, &
989 lmax=la_max, &
990 lmin=la_min, &
991 npgf=npgfa, &
992 nset=nseta, &
993 nsgf_set=nsgfa, &
994 pgf_radius=rpgfa, &
995 set_radius=set_radius_a, &
996 sphi=sphi_a, &
997 zet=zeta)
998 END IF
999
1000 IF (jkind /= jkind_old) THEN
1001
1002 CALL get_qs_kind(qs_kind_set(jkind), &
1003 basis_set=orb_basis_set, basis_type=basis_type)
1004
1005 CALL get_gto_basis_set(gto_basis_set=orb_basis_set, &
1006 first_sgf=first_sgfb, &
1007 kind_radius=kind_radius_b, &
1008 lmax=lb_max, &
1009 lmin=lb_min, &
1010 npgf=npgfb, &
1011 nset=nsetb, &
1012 nsgf_set=nsgfb, &
1013 pgf_radius=rpgfb, &
1014 set_radius=set_radius_b, &
1015 sphi=sphi_b, &
1016 zet=zetb)
1017
1018 END IF
1019
1020 CALL dbcsr_get_block_p(matrix=deltajp_a(1)%matrix, row=brow, col=bcol, &
1021 block=jp_block_a, found=den_found)
1022 CALL dbcsr_get_block_p(matrix=deltajp_b(1)%matrix, row=brow, col=bcol, &
1023 block=jp_block_b, found=den_found)
1024 CALL dbcsr_get_block_p(matrix=deltajp_c(1)%matrix, row=brow, col=bcol, &
1025 block=jp_block_c, found=den_found)
1026 IF (do_igaim) CALL dbcsr_get_block_p(matrix=deltajp_d(1)%matrix, row=brow, col=bcol, &
1027 block=jp_block_d, found=den_found)
1028
1029 IF (.NOT. ASSOCIATED(jp_block_a)) THEN
1030 cpabort("p_block not associated in deltap")
1031 END IF
1032
1033 iatom_old = iatom
1034 jatom_old = jatom
1035 ikind_old = ikind
1036 jkind_old = jkind
1037
1038 atom_pair_changed = .true.
1039
1040 ELSE
1041
1042 atom_pair_changed = .false.
1043
1044 END IF
1045
1046 IF (atom_pair_changed .OR. iset_old /= iset .OR. jset_old /= jset) THEN
1047
1048 ncoa = npgfa(iset)*ncoset(la_max(iset))
1049 sgfa = first_sgfa(1, iset)
1050 ncob = npgfb(jset)*ncoset(lb_max(jset))
1051 sgfb = first_sgfb(1, jset)
1052 ! Decontraction step for the selected blocks of the 3 density matrices
1053
1054 CALL dgemm("N", "N", ncoa, nsgfb(jset), nsgfa(iset), &
1055 1.0_dp, sphi_a(1, sgfa), SIZE(sphi_a, 1), &
1056 jp_block_a(sgfa, sgfb), SIZE(jp_block_a, 1), &
1057 0.0_dp, work(1, 1), maxco)
1058 CALL dgemm("N", "T", ncoa, ncob, nsgfb(jset), &
1059 1.0_dp, work(1, 1), maxco, &
1060 sphi_b(1, sgfb), SIZE(sphi_b, 1), &
1061 0.0_dp, jpab_a(1, 1), maxco)
1062
1063 CALL dgemm("N", "N", ncoa, nsgfb(jset), nsgfa(iset), &
1064 1.0_dp, sphi_a(1, sgfa), SIZE(sphi_a, 1), &
1065 jp_block_b(sgfa, sgfb), SIZE(jp_block_b, 1), &
1066 0.0_dp, work(1, 1), maxco)
1067 CALL dgemm("N", "T", ncoa, ncob, nsgfb(jset), &
1068 1.0_dp, work(1, 1), maxco, &
1069 sphi_b(1, sgfb), SIZE(sphi_b, 1), &
1070 0.0_dp, jpab_b(1, 1), maxco)
1071
1072 CALL dgemm("N", "N", ncoa, nsgfb(jset), nsgfa(iset), &
1073 1.0_dp, sphi_a(1, sgfa), SIZE(sphi_a, 1), &
1074 jp_block_c(sgfa, sgfb), SIZE(jp_block_c, 1), &
1075 0.0_dp, work(1, 1), maxco)
1076 CALL dgemm("N", "T", ncoa, ncob, nsgfb(jset), &
1077 1.0_dp, work(1, 1), maxco, &
1078 sphi_b(1, sgfb), SIZE(sphi_b, 1), &
1079 0.0_dp, jpab_c(1, 1), maxco)
1080
1081 IF (do_igaim) THEN
1082 CALL dgemm("N", "N", ncoa, nsgfb(jset), nsgfa(iset), &
1083 1.0_dp, sphi_a(1, sgfa), SIZE(sphi_a, 1), &
1084 jp_block_d(sgfa, sgfb), SIZE(jp_block_d, 1), &
1085 0.0_dp, work(1, 1), maxco)
1086 CALL dgemm("N", "T", ncoa, ncob, nsgfb(jset), &
1087 1.0_dp, work(1, 1), maxco, &
1088 sphi_b(1, sgfb), SIZE(sphi_b, 1), &
1089 0.0_dp, jpab_d(1, 1), maxco)
1090 END IF
1091
1092 iset_old = iset
1093 jset_old = jset
1094
1095 END IF
1096
1097 SELECT CASE (idir)
1098 CASE (1)
1099 adbmdab_func = grid_func_adbmdab_x
1100 CASE (2)
1101 adbmdab_func = grid_func_adbmdab_y
1102 CASE (3)
1103 adbmdab_func = grid_func_adbmdab_z
1104 CASE DEFAULT
1105 cpabort("invalid idir")
1106 END SELECT
1107
1108 rab(:) = tasks(itask)%rab
1109 rb(:) = ra(:) + rab(:)
1110 zetp = zeta(ipgf, iset) + zetb(jpgf, jset)
1111 f = zetb(jpgf, jset)/zetp
1112 prefactor = exp(-zeta(ipgf, iset)*f*dot_product(rab, rab))
1113 rp(:) = ra(:) + f*rab(:)
1114
1115 na1 = (ipgf - 1)*ncoset(la_max(iset)) + 1
1116 na2 = ipgf*ncoset(la_max(iset))
1117 nb1 = (jpgf - 1)*ncoset(lb_max(jset)) + 1
1118 nb2 = jpgf*ncoset(lb_max(jset))
1119
1120 ! Four calls to the general collocate density, to multply the correct function
1121 ! to each density matrix
1122
1123 !
1124 ! here the decontracted mat_jp_{ab} is multiplied by
1125 ! f_{ab} = g_{a} (dg_{b}/dr)_{idir} - (dg_{a}/dr)_{idir} g_{b}
1126 scale = 1.0_dp
1127 radius = exp_radius_very_extended(la_min=la_min(iset), la_max=la_max(iset), &
1128 lb_min=lb_min(jset), lb_max=lb_max(jset), &
1129 ra=ra, rb=rb, rp=rp, zetp=zetp, eps=eps_rho_rspace, &
1130 prefactor=prefactor, cutoff=1.0_dp)
1131
1132 CALL collocate_pgf_product(la_max(iset), zeta(ipgf, iset), &
1133 la_min(iset), lb_max(jset), zetb(jpgf, jset), lb_min(jset), &
1134 ra, rab, scale, jpab_a, na1 - 1, nb1 - 1, &
1135 rs_current(igrid_level), &
1136 radius=radius, ga_gb_function=adbmdab_func)
1137 IF (do_igaim) THEN
1138 ! here the decontracted mat_jb_{ab} is multiplied by
1139 ! f_{ab} = g_{a} * g_{b} ! THIS GOES OUTSIDE THE LOOP !
1140 IF (scale2 /= 0.0_dp) THEN
1141 CALL collocate_pgf_product(la_max(iset), zeta(ipgf, iset), &
1142 la_min(iset), lb_max(jset), zetb(jpgf, jset), lb_min(jset), &
1143 ra, rab, scale2, jpab_d, na1 - 1, nb1 - 1, &
1144 rs_rho(igrid_level), &
1145 radius=radius, ga_gb_function=grid_func_ab)
1146 END IF !rm
1147 ! here the decontracted mat_jp_rii{ab} is multiplied by
1148 ! f_{ab} = g_{a} (d(r) - R_{b})_{iiB} (dg_{b}/dr)_{idir} -
1149 ! (dg_{a}/dr)_{idir} (d(r) - R_{b})_{iiB} g_{b}
1150 scale = 1.0_dp
1151 current_env%rs_buf(igrid_level)%r(:, :, :) = 0.0_dp
1152 CALL collocate_pgf_product(la_max(iset), zeta(ipgf, iset), &
1153 la_min(iset), lb_max(jset), zetb(jpgf, jset), lb_min(jset), &
1154 ra, rab, scale, jpab_b, na1 - 1, nb1 - 1, &
1155 radius=radius, &
1156 ga_gb_function=adbmdab_func, &
1157 rsgrid=current_env%rs_buf(igrid_level))
1158 CALL collocate_gauge_ortho(rsgrid=current_env%rs_buf(igrid_level), &
1159 rsbuf=rs_current(igrid_level), &
1160 rsgauge=rs_gauge(iiib, igrid_level), &
1161 cube_info=cube_info(igrid_level), radius=radius, &
1162 zeta=zeta(ipgf, iset), zetb=zetb(jpgf, jset), &
1163 ra=ra, rab=rab, ir=iiib)
1164
1165 ! here the decontracted mat_jp_riii{ab} is multiplied by
1166 ! f_{ab} = -g_{a} (d(r) - R_{b})_{iiB} (dg_{b}/dr)_{idir} +
1167 ! (dg_{a}/dr)_{idir} (d(r) - R_{b})_{iiB} g_{b}
1168 scale = -1.0_dp
1169 current_env%rs_buf(igrid_level)%r(:, :, :) = 0.0_dp
1170 CALL collocate_pgf_product(la_max(iset), zeta(ipgf, iset), &
1171 la_min(iset), lb_max(jset), zetb(jpgf, jset), lb_min(jset), &
1172 ra, rab, scale, jpab_c, na1 - 1, nb1 - 1, &
1173 radius=radius, &
1174 ga_gb_function=adbmdab_func, &
1175 rsgrid=current_env%rs_buf(igrid_level))
1176 CALL collocate_gauge_ortho(rsgrid=current_env%rs_buf(igrid_level), &
1177 rsbuf=rs_current(igrid_level), &
1178 rsgauge=rs_gauge(iib, igrid_level), &
1179 cube_info=cube_info(igrid_level), radius=radius, &
1180 zeta=zeta(ipgf, iset), zetb=zetb(jpgf, jset), &
1181 ra=ra, rab=rab, ir=iib)
1182 ELSE
1183 ! here the decontracted mat_jp_rii{ab} is multiplied by
1184 ! f_{ab} = g_{a} (r - R_{b})_{iiB} (dg_{b}/dr)_{idir} -
1185 ! (dg_{a}/dr)_{idir} (r - R_{b})_{iiB} g_{b}
1186 scale = 1.0_dp
1187 CALL collocate_pgf_product(la_max(iset), zeta(ipgf, iset), &
1188 la_min(iset), lb_max(jset), zetb(jpgf, jset), lb_min(jset), &
1189 ra, rab, scale, jpab_b, na1 - 1, nb1 - 1, &
1190 rs_current(igrid_level), &
1191 radius=radius, &
1192 ga_gb_function=encode_ardbmdarb_func(idir=idir, ir=iiib))
1193 ! here the decontracted mat_jp_riii{ab} is multiplied by
1194 ! f_{ab} = -g_{a} (r - R_{b})_{iiB} (dg_{b}/dr)_{idir} +
1195 ! (dg_{a}/dr)_{idir} (r - R_{b})_{iiB} g_{b}
1196 scale = -1.0_dp
1197 CALL collocate_pgf_product(la_max(iset), zeta(ipgf, iset), &
1198 la_min(iset), lb_max(jset), zetb(jpgf, jset), lb_min(jset), &
1199 ra, rab, scale, jpab_c, na1 - 1, nb1 - 1, &
1200 rs_current(igrid_level), &
1201 radius=radius, &
1202 ga_gb_function=encode_ardbmdarb_func(idir=idir, ir=iib))
1203 END IF
1204
1205 END DO loop_tasks
1206 !
1207 ! Scale the density with the gauge rho * ( r - d(r) ) if needed
1208 IF (do_igaim) THEN
1209 DO igrid_level = 1, gridlevel_info%ngrid_levels
1210 CALL rs_grid_mult_and_add(rs_current(igrid_level), rs_rho(igrid_level), &
1211 rs_gauge(idir2, igrid_level), 1.0_dp)
1212 END DO
1213 END IF
1214 ! *** Release work storage ***
1215
1216 IF (distributed_rs_grids) THEN
1217 CALL dbcsr_deallocate_matrix(deltajp_a(1)%matrix)
1218 CALL dbcsr_deallocate_matrix(deltajp_b(1)%matrix)
1219 CALL dbcsr_deallocate_matrix(deltajp_c(1)%matrix)
1220 IF (do_igaim) CALL dbcsr_deallocate_matrix(deltajp_d(1)%matrix)
1221 END IF
1222 DEALLOCATE (deltajp_a, deltajp_b, deltajp_c, deltajp_d)
1223
1224 DEALLOCATE (jpabt_a, jpabt_b, jpabt_c, jpabt_d, workt, tasks)
1225
1226 IF (ASSOCIATED(atom_pair_send)) DEALLOCATE (atom_pair_send)
1227 IF (ASSOCIATED(atom_pair_recv)) DEALLOCATE (atom_pair_recv)
1228
1229 CALL density_rs2pw(pw_env, rs_current, current_rs, current_gs)
1230 DO i = 1, SIZE(rs_current)
1231 CALL rs_grid_release(rs_current(i))
1232 END DO
1233
1234 DO i = 1, SIZE(rs_rho)
1235 IF (rs_descs(i)%rs_desc%distributed .AND. .NOT. my_retain_rsgrid) THEN
1236 CALL rs_grid_release(rs_rho(i))
1237 END IF
1238 END DO
1239
1240 ! Free the array of grids (grids themselves are released in density_rs2pw)
1241 DEALLOCATE (rs_current)
1242
1243 CALL timestop(handle)
1244
1245 END SUBROUTINE calculate_jrho_resp
1246
1247! **************************************************************************************************
1248!> \brief ...
1249!> \param idir ...
1250!> \param ir ...
1251!> \return ...
1252! **************************************************************************************************
1253 FUNCTION encode_ardbmdarb_func(idir, ir) RESULT(func)
1254 INTEGER, INTENT(IN) :: idir, ir
1255 INTEGER :: func
1256
1257 cpassert(1 <= idir .AND. idir <= 3 .AND. 1 <= ir .AND. ir <= 3)
1258 SELECT CASE (10*idir + ir)
1259 CASE (11)
1260 func = grid_func_ardbmdarb_xx
1261 CASE (12)
1262 func = grid_func_ardbmdarb_xy
1263 CASE (13)
1264 func = grid_func_ardbmdarb_xz
1265 CASE (21)
1266 func = grid_func_ardbmdarb_yx
1267 CASE (22)
1268 func = grid_func_ardbmdarb_yy
1269 CASE (23)
1270 func = grid_func_ardbmdarb_yz
1271 CASE (31)
1272 func = grid_func_ardbmdarb_zx
1273 CASE (32)
1274 func = grid_func_ardbmdarb_zy
1275 CASE (33)
1276 func = grid_func_ardbmdarb_zz
1277 CASE DEFAULT
1278 cpabort("invalid idir or iiiB")
1279 END SELECT
1280 END FUNCTION encode_ardbmdarb_func
1281
1282! **************************************************************************************************
1283!> \brief ...
1284!> \param rsgrid ...
1285!> \param rsbuf ...
1286!> \param rsgauge ...
1287!> \param cube_info ...
1288!> \param radius ...
1289!> \param ra ...
1290!> \param rab ...
1291!> \param zeta ...
1292!> \param zetb ...
1293!> \param ir ...
1294! **************************************************************************************************
1295 SUBROUTINE collocate_gauge_ortho(rsgrid, rsbuf, rsgauge, cube_info, radius, ra, rab, zeta, zetb, ir)
1296 TYPE(realspace_grid_type) :: rsgrid, rsbuf, rsgauge
1297 TYPE(cube_info_type), INTENT(IN) :: cube_info
1298 REAL(kind=dp), INTENT(IN) :: radius
1299 REAL(kind=dp), DIMENSION(3), INTENT(IN) :: ra, rab
1300 REAL(kind=dp), INTENT(IN) :: zeta, zetb
1301 INTEGER, INTENT(IN) :: ir
1302
1303 INTEGER :: cmax, i, ig, igmax, igmin, j, j2, jg, &
1304 jg2, jgmin, k, k2, kg, kg2, kgmin, &
1305 length, offset, sci, start
1306 INTEGER, ALLOCATABLE, DIMENSION(:, :) :: map
1307 INTEGER, DIMENSION(3) :: cubecenter, lb_cube, ng, ub_cube
1308 INTEGER, DIMENSION(:), POINTER :: sphere_bounds
1309 REAL(kind=dp) :: f, point(3, 4), res(4), x, y, y2, z, z2, &
1310 zetp
1311 REAL(kind=dp), DIMENSION(3) :: dr, rap, rb, rbp, roffset, rp
1312 REAL(kind=dp), DIMENSION(:, :, :), POINTER :: gauge, grid, grid_buf
1313
1314 cpassert(rsgrid%desc%orthorhombic)
1315 NULLIFY (sphere_bounds)
1316
1317 grid => rsgrid%r(:, :, :)
1318 grid_buf => rsbuf%r(:, :, :)
1319 gauge => rsgauge%r(:, :, :)
1320
1321 ! *** center of gaussians and their product
1322 zetp = zeta + zetb
1323 f = zetb/zetp
1324 rap(:) = f*rab(:)
1325 rbp(:) = rap(:) - rab(:)
1326 rp(:) = ra(:) + rap(:)
1327 rb(:) = ra(:) + rab(:)
1328
1329 ! *** properties of the grid ***
1330 ng(:) = rsgrid%desc%npts(:)
1331 dr(1) = rsgrid%desc%dh(1, 1)
1332 dr(2) = rsgrid%desc%dh(2, 2)
1333 dr(3) = rsgrid%desc%dh(3, 3)
1334
1335 ! *** get the sub grid properties for the given radius ***
1336 CALL return_cube(cube_info, radius, lb_cube, ub_cube, sphere_bounds)
1337 cmax = maxval(ub_cube)
1338
1339 ! *** position of the gaussian product
1340 !
1341 ! this is the actual definition of the position on the grid
1342 ! i.e. a point rp(:) gets here grid coordinates
1343 ! MODULO(rp(:)/dr(:),ng(:))+1
1344 ! hence (0.0,0.0,0.0) in real space is rsgrid%lb on the rsgrid ((1,1,1) on grid)
1345 !
1346 ALLOCATE (map(-cmax:cmax, 3))
1347 map(:, :) = -1
1348 CALL compute_cube_center(cubecenter, rsgrid%desc, zeta, zetb, ra, rab)
1349 roffset(:) = rp(:) - real(cubecenter(:), dp)*dr(:)
1350
1351 ! *** a mapping so that the ig corresponds to the right grid point
1352 DO i = 1, 3
1353 IF (rsgrid%desc%perd(i) == 1) THEN
1354 start = lb_cube(i)
1355 DO
1356 offset = modulo(cubecenter(i) + start, ng(i)) + 1 - start
1357 length = min(ub_cube(i), ng(i) - offset) - start
1358 DO ig = start, start + length
1359 map(ig, i) = ig + offset
1360 END DO
1361 IF (start + length >= ub_cube(i)) EXIT
1362 start = start + length + 1
1363 END DO
1364 ELSE
1365 ! this takes partial grid + border regions into account
1366 offset = modulo(cubecenter(i) + lb_cube(i) + rsgrid%desc%lb(i) - rsgrid%lb_local(i), ng(i)) + 1 - lb_cube(i)
1367 ! check for out of bounds
1368 IF (ub_cube(i) + offset > ubound(grid, i) .OR. lb_cube(i) + offset < lbound(grid, i)) THEN
1369 cpabort("Cube bound out of grid bounds")
1370 END IF
1371 DO ig = lb_cube(i), ub_cube(i)
1372 map(ig, i) = ig + offset
1373 END DO
1374 END IF
1375 END DO
1376
1377 ! *** actually loop over the grid
1378 sci = 1
1379 kgmin = sphere_bounds(sci)
1380 sci = sci + 1
1381 DO kg = kgmin, 0
1382 kg2 = 1 - kg
1383 k = map(kg, 3)
1384 k2 = map(kg2, 3)
1385 jgmin = sphere_bounds(sci)
1386 sci = sci + 1
1387 z = (real(kg, dp) + real(cubecenter(3), dp))*dr(3)
1388 z2 = (real(kg2, dp) + real(cubecenter(3), dp))*dr(3)
1389 DO jg = jgmin, 0
1390 jg2 = 1 - jg
1391 j = map(jg, 2)
1392 j2 = map(jg2, 2)
1393 igmin = sphere_bounds(sci)
1394 sci = sci + 1
1395 igmax = 1 - igmin
1396 y = (real(jg, dp) + real(cubecenter(2), dp))*dr(2)
1397 y2 = (real(jg2, dp) + real(cubecenter(2), dp))*dr(2)
1398 DO ig = igmin, igmax
1399 i = map(ig, 1)
1400 x = (real(ig, dp) + real(cubecenter(1), dp))*dr(1)
1401 point(1, 1) = x; point(2, 1) = y; point(3, 1) = z
1402 point(1, 2) = x; point(2, 2) = y2; point(3, 2) = z
1403 point(1, 3) = x; point(2, 3) = y; point(3, 3) = z2
1404 point(1, 4) = x; point(2, 4) = y2; point(3, 4) = z2
1405 !
1406 res(1) = (point(ir, 1) - rb(ir)) - gauge(i, j, k)
1407 res(2) = (point(ir, 2) - rb(ir)) - gauge(i, j2, k)
1408 res(3) = (point(ir, 3) - rb(ir)) - gauge(i, j, k2)
1409 res(4) = (point(ir, 4) - rb(ir)) - gauge(i, j2, k2)
1410 !
1411 grid_buf(i, j, k) = grid_buf(i, j, k) + grid(i, j, k)*res(1)
1412 grid_buf(i, j2, k) = grid_buf(i, j2, k) + grid(i, j2, k)*res(2)
1413 grid_buf(i, j, k2) = grid_buf(i, j, k2) + grid(i, j, k2)*res(3)
1414 grid_buf(i, j2, k2) = grid_buf(i, j2, k2) + grid(i, j2, k2)*res(4)
1415 END DO
1416 END DO
1417 END DO
1418 END SUBROUTINE collocate_gauge_ortho
1419
1420! **************************************************************************************************
1421!> \brief ...
1422!> \param current_env ...
1423!> \param qs_env ...
1424! **************************************************************************************************
1425 SUBROUTINE current_set_gauge(current_env, qs_env)
1426 !
1427 TYPE(current_env_type) :: current_env
1428 TYPE(qs_environment_type), POINTER :: qs_env
1429
1430 CHARACTER(LEN=*), PARAMETER :: routinen = 'current_set_gauge'
1431
1432 INTEGER :: idir
1433 REAL(dp) :: dbox(3)
1434 REAL(dp), ALLOCATABLE, DIMENSION(:, :) :: box_data
1435 INTEGER :: handle, igrid_level, nbox(3), gauge
1436 INTEGER, ALLOCATABLE, DIMENSION(:, :, :) :: box_ptr
1437 TYPE(realspace_grid_desc_p_type), DIMENSION(:), &
1438 POINTER :: rs_descs
1439 TYPE(pw_env_type), POINTER :: pw_env
1440 TYPE(realspace_grid_type), DIMENSION(:, :), POINTER :: rs_gauge
1441
1442 TYPE(box_type), DIMENSION(:, :, :), POINTER :: box
1443 LOGICAL :: use_old_gauge_atom
1444
1445 NULLIFY (rs_gauge, box)
1446
1447 CALL timeset(routinen, handle)
1448
1449 CALL get_current_env(current_env=current_env, &
1450 use_old_gauge_atom=use_old_gauge_atom, &
1451 rs_gauge=rs_gauge, &
1452 gauge=gauge)
1453
1454 IF (gauge == current_gauge_atom) THEN
1455 CALL get_qs_env(qs_env=qs_env, &
1456 pw_env=pw_env)
1457 CALL pw_env_get(pw_env=pw_env, &
1458 rs_descs=rs_descs)
1459 !
1460 ! box the atoms
1461 IF (use_old_gauge_atom) THEN
1462 CALL box_atoms(qs_env)
1463 ELSE
1464 CALL box_atoms_new(current_env, qs_env, box)
1465 END IF
1466 !
1467 ! allocate and build the gauge
1468 DO igrid_level = pw_env%gridlevel_info%ngrid_levels, 1, -1
1469
1470 DO idir = 1, 3
1471 CALL rs_grid_create(rs_gauge(idir, igrid_level), rs_descs(igrid_level)%rs_desc)
1472 END DO
1473
1474 IF (use_old_gauge_atom) THEN
1475 CALL collocate_gauge(current_env, qs_env, &
1476 rs_gauge(1, igrid_level), &
1477 rs_gauge(2, igrid_level), &
1478 rs_gauge(3, igrid_level))
1479 ELSE
1480 CALL collocate_gauge_new(current_env, qs_env, &
1481 rs_gauge(1, igrid_level), &
1482 rs_gauge(2, igrid_level), &
1483 rs_gauge(3, igrid_level), &
1484 box)
1485 END IF
1486 END DO
1487 !
1488 ! allocate the buf
1489 ALLOCATE (current_env%rs_buf(pw_env%gridlevel_info%ngrid_levels))
1490 DO igrid_level = 1, pw_env%gridlevel_info%ngrid_levels
1491 CALL rs_grid_create(current_env%rs_buf(igrid_level), rs_descs(igrid_level)%rs_desc)
1492 END DO
1493 !
1494 DEALLOCATE (box_ptr, box_data)
1495 CALL deallocate_box(box)
1496 END IF
1497
1498 CALL timestop(handle)
1499
1500 CONTAINS
1501
1502! **************************************************************************************************
1503!> \brief ...
1504!> \param qs_env ...
1505! **************************************************************************************************
1506 SUBROUTINE box_atoms(qs_env)
1507 TYPE(qs_environment_type), POINTER :: qs_env
1508
1509 REAL(kind=dp), PARAMETER :: box_size_guess = 5.0_dp
1510
1511 INTEGER :: i, iatom, ibox, ii, jbox, kbox, natms
1512 REAL(dp) :: offset(3)
1513 REAL(dp), ALLOCATABLE, DIMENSION(:, :) :: ratom
1514 TYPE(cell_type), POINTER :: cell
1515 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
1516 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1517
1518 CALL get_qs_env(qs_env=qs_env, &
1519 qs_kind_set=qs_kind_set, &
1520 cell=cell, &
1521 particle_set=particle_set)
1522
1523 natms = SIZE(particle_set, 1)
1524 ALLOCATE (ratom(3, natms))
1525 !
1526 ! box the atoms
1527 nbox(1) = ceiling(cell%hmat(1, 1)/box_size_guess)
1528 nbox(2) = ceiling(cell%hmat(2, 2)/box_size_guess)
1529 nbox(3) = ceiling(cell%hmat(3, 3)/box_size_guess)
1530 !write(*,*) 'nbox',nbox
1531 dbox(1) = cell%hmat(1, 1)/real(nbox(1), dp)
1532 dbox(2) = cell%hmat(2, 2)/real(nbox(2), dp)
1533 dbox(3) = cell%hmat(3, 3)/real(nbox(3), dp)
1534 !write(*,*) 'dbox',dbox
1535 ALLOCATE (box_ptr(0:nbox(1), 0:nbox(2) - 1, 0:nbox(3) - 1), box_data(3, natms))
1536 box_data(:, :) = huge(0.0_dp)
1537 box_ptr(:, :, :) = huge(0)
1538 !
1539 offset(1) = cell%hmat(1, 1)*0.5_dp
1540 offset(2) = cell%hmat(2, 2)*0.5_dp
1541 offset(3) = cell%hmat(3, 3)*0.5_dp
1542 DO iatom = 1, natms
1543 ratom(:, iatom) = pbc(particle_set(iatom)%r(:), cell) + offset(:)
1544 END DO
1545 !
1546 i = 1
1547 DO kbox = 0, nbox(3) - 1
1548 DO jbox = 0, nbox(2) - 1
1549 box_ptr(0, jbox, kbox) = i
1550 DO ibox = 0, nbox(1) - 1
1551 ii = 0
1552 DO iatom = 1, natms
1553 IF (int(ratom(1, iatom)/dbox(1)) == ibox .AND. &
1554 int(ratom(2, iatom)/dbox(2)) == jbox .AND. &
1555 int(ratom(3, iatom)/dbox(3)) == kbox) THEN
1556 box_data(:, i) = ratom(:, iatom) - offset(:)
1557 i = i + 1
1558 ii = ii + 1
1559 END IF
1560 END DO
1561 box_ptr(ibox + 1, jbox, kbox) = box_ptr(ibox, jbox, kbox) + ii
1562 END DO
1563 END DO
1564 END DO
1565 !
1566 IF (.false.) THEN
1567 DO kbox = 0, nbox(3) - 1
1568 DO jbox = 0, nbox(2) - 1
1569 DO ibox = 0, nbox(1) - 1
1570 WRITE (*, *) 'box=', ibox, jbox, kbox
1571 WRITE (*, *) 'nbr atom=', box_ptr(ibox + 1, jbox, kbox) - box_ptr(ibox, jbox, kbox)
1572 DO iatom = box_ptr(ibox, jbox, kbox), box_ptr(ibox + 1, jbox, kbox) - 1
1573 WRITE (*, *) 'iatom=', iatom
1574 WRITE (*, '(A,3E14.6)') 'coor=', box_data(:, iatom)
1575 END DO
1576 END DO
1577 END DO
1578 END DO
1579 END IF
1580 DEALLOCATE (ratom)
1581 END SUBROUTINE box_atoms
1582
1583! **************************************************************************************************
1584!> \brief ...
1585!> \param current_env ...
1586!> \param qs_env ...
1587!> \param rs_grid_x ...
1588!> \param rs_grid_y ...
1589!> \param rs_grid_z ...
1590! **************************************************************************************************
1591 SUBROUTINE collocate_gauge(current_env, qs_env, rs_grid_x, rs_grid_y, rs_grid_z)
1592 !
1593 TYPE(current_env_type) :: current_env
1594 TYPE(qs_environment_type), POINTER :: qs_env
1595 TYPE(realspace_grid_type), INTENT(IN) :: rs_grid_x, rs_grid_y, rs_grid_z
1596
1597 INTEGER :: i, iatom, ibeg, ibox, iend, imax, imin, &
1598 j, jatom, jbox, jmax, jmin, k, kbox, &
1599 kmax, kmin, lb(3), lb_local(3), natms, &
1600 natms_local, ng(3)
1601 REAL(kind=dp) :: ab, buf_tmp, dist, dr(3), &
1602 gauge_atom_radius, offset(3), pa, pb, &
1603 point(3), pra(3), r(3), res(3), summe, &
1604 tmp, x, y, z
1605 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: buf, nrm_atms_pnt
1606 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: atms_pnt, ratom
1607 REAL(kind=dp), DIMENSION(:, :, :), POINTER :: grid_x, grid_y, grid_z
1608 TYPE(cell_type), POINTER :: cell
1609 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
1610 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1611
1612!
1613
1614 CALL get_current_env(current_env=current_env, &
1615 gauge_atom_radius=gauge_atom_radius)
1616 !
1617 CALL get_qs_env(qs_env=qs_env, &
1618 qs_kind_set=qs_kind_set, &
1619 cell=cell, &
1620 particle_set=particle_set)
1621 !
1622 natms = SIZE(particle_set, 1)
1623 dr(1) = rs_grid_x%desc%dh(1, 1)
1624 dr(2) = rs_grid_x%desc%dh(2, 2)
1625 dr(3) = rs_grid_x%desc%dh(3, 3)
1626 lb(:) = rs_grid_x%desc%lb(:)
1627 lb_local(:) = rs_grid_x%lb_local(:)
1628 grid_x => rs_grid_x%r(:, :, :)
1629 grid_y => rs_grid_y%r(:, :, :)
1630 grid_z => rs_grid_z%r(:, :, :)
1631 ng(:) = ubound(grid_x)
1632 offset(1) = cell%hmat(1, 1)*0.5_dp
1633 offset(2) = cell%hmat(2, 2)*0.5_dp
1634 offset(3) = cell%hmat(3, 3)*0.5_dp
1635 ALLOCATE (buf(natms), ratom(3, natms), atms_pnt(3, natms), nrm_atms_pnt(natms))
1636 !
1637 ! go over the grid
1638 DO k = 1, ng(3)
1639 DO j = 1, ng(2)
1640 DO i = 1, ng(1)
1641 !
1642 point(3) = real(k - 1 + lb_local(3) - lb(3), dp)*dr(3)
1643 point(2) = real(j - 1 + lb_local(2) - lb(2), dp)*dr(2)
1644 point(1) = real(i - 1 + lb_local(1) - lb(1), dp)*dr(1)
1645 point = pbc(point, cell)
1646 !
1647 ! run over the overlaping boxes
1648 natms_local = 0
1649 kmin = int((point(3) + offset(3) - gauge_atom_radius)/dbox(3))
1650 kmax = int((point(3) + offset(3) + gauge_atom_radius)/dbox(3))
1651 IF (kmax - kmin + 1 > nbox(3)) THEN
1652 kmin = 0
1653 kmax = nbox(3) - 1
1654 END IF
1655 DO kbox = kmin, kmax
1656 jmin = int((point(2) + offset(2) - gauge_atom_radius)/dbox(2))
1657 jmax = int((point(2) + offset(2) + gauge_atom_radius)/dbox(2))
1658 IF (jmax - jmin + 1 > nbox(2)) THEN
1659 jmin = 0
1660 jmax = nbox(2) - 1
1661 END IF
1662 DO jbox = jmin, jmax
1663 imin = int((point(1) + offset(1) - gauge_atom_radius)/dbox(1))
1664 imax = int((point(1) + offset(1) + gauge_atom_radius)/dbox(1))
1665 IF (imax - imin + 1 > nbox(1)) THEN
1666 imin = 0
1667 imax = nbox(1) - 1
1668 END IF
1669 DO ibox = imin, imax
1670 ibeg = box_ptr(modulo(ibox, nbox(1)), modulo(jbox, nbox(2)), modulo(kbox, nbox(3)))
1671 iend = box_ptr(modulo(ibox, nbox(1)) + 1, modulo(jbox, nbox(2)), modulo(kbox, nbox(3))) - 1
1672 DO iatom = ibeg, iend
1673 r(:) = pbc(box_data(:, iatom) - point(:), cell) + point(:)
1674 dist = (r(1) - point(1))**2 + (r(2) - point(2))**2 + (r(3) - point(3))**2
1675 IF (dist < gauge_atom_radius**2) THEN
1676 natms_local = natms_local + 1
1677 ratom(:, natms_local) = r(:)
1678 !
1679 ! compute the distance atoms-point
1680 x = point(1) - r(1)
1681 y = point(2) - r(2)
1682 z = point(3) - r(3)
1683 atms_pnt(1, natms_local) = x
1684 atms_pnt(2, natms_local) = y
1685 atms_pnt(3, natms_local) = z
1686 nrm_atms_pnt(natms_local) = sqrt(x*x + y*y + z*z)
1687 END IF
1688 END DO
1689 END DO
1690 END DO
1691 END DO
1692 !
1693 IF (natms_local > 0) THEN
1694 !
1695 !
1696 DO iatom = 1, natms_local
1697 buf_tmp = 1.0_dp
1698 pra(1) = atms_pnt(1, iatom)
1699 pra(2) = atms_pnt(2, iatom)
1700 pra(3) = atms_pnt(3, iatom)
1701 pa = nrm_atms_pnt(iatom)
1702 DO jatom = 1, natms_local
1703 IF (iatom == jatom) cycle
1704 pb = nrm_atms_pnt(jatom)
1705 x = pra(1) - atms_pnt(1, jatom)
1706 y = pra(2) - atms_pnt(2, jatom)
1707 z = pra(3) - atms_pnt(3, jatom)
1708 ab = sqrt(x*x + y*y + z*z)
1709 !
1710 tmp = (pa - pb)/ab
1711 tmp = 0.5_dp*(3.0_dp - tmp*tmp)*tmp
1712 tmp = 0.5_dp*(3.0_dp - tmp*tmp)*tmp
1713 tmp = 0.5_dp*(3.0_dp - tmp*tmp)*tmp
1714 buf_tmp = buf_tmp*0.5_dp*(1.0_dp - tmp)
1715 END DO
1716 buf(iatom) = buf_tmp
1717 END DO
1718 res(1) = 0.0_dp
1719 res(2) = 0.0_dp
1720 res(3) = 0.0_dp
1721 summe = 0.0_dp
1722 DO iatom = 1, natms_local
1723 res(1) = res(1) + ratom(1, iatom)*buf(iatom)
1724 res(2) = res(2) + ratom(2, iatom)*buf(iatom)
1725 res(3) = res(3) + ratom(3, iatom)*buf(iatom)
1726 summe = summe + buf(iatom)
1727 END DO
1728 res(1) = res(1)/summe
1729 res(2) = res(2)/summe
1730 res(3) = res(3)/summe
1731 grid_x(i, j, k) = point(1) - res(1)
1732 grid_y(i, j, k) = point(2) - res(2)
1733 grid_z(i, j, k) = point(3) - res(3)
1734 ELSE
1735 grid_x(i, j, k) = 0.0_dp
1736 grid_y(i, j, k) = 0.0_dp
1737 grid_z(i, j, k) = 0.0_dp
1738 END IF
1739 END DO
1740 END DO
1741 END DO
1742
1743 DEALLOCATE (buf, ratom, atms_pnt, nrm_atms_pnt)
1744
1745 END SUBROUTINE collocate_gauge
1746
1747! **************************************************************************************************
1748!> \brief ...
1749!> \param current_env ...
1750!> \param qs_env ...
1751!> \param box ...
1752! **************************************************************************************************
1753 SUBROUTINE box_atoms_new(current_env, qs_env, box)
1754 TYPE(current_env_type) :: current_env
1755 TYPE(qs_environment_type), POINTER :: qs_env
1756 TYPE(box_type), DIMENSION(:, :, :), POINTER :: box
1757
1758 CHARACTER(LEN=*), PARAMETER :: routinen = 'box_atoms_new'
1759
1760 INTEGER :: handle, i, iatom, ibeg, ibox, iend, &
1761 ifind, ii, imax, imin, j, jatom, jbox, &
1762 jmax, jmin, k, kbox, kmax, kmin, &
1763 natms, natms_local
1764 REAL(dp) :: gauge_atom_radius, offset(3), scale
1765 REAL(dp), ALLOCATABLE, DIMENSION(:, :) :: ratom
1766 REAL(dp), DIMENSION(:, :), POINTER :: r_ptr
1767 REAL(kind=dp) :: box_center(3), box_center_wrap(3), &
1768 box_size_guess, r(3)
1769 TYPE(cell_type), POINTER :: cell
1770 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
1771 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1772
1773 CALL timeset(routinen, handle)
1774
1775 CALL get_qs_env(qs_env=qs_env, &
1776 qs_kind_set=qs_kind_set, &
1777 cell=cell, &
1778 particle_set=particle_set)
1779
1780 CALL get_current_env(current_env=current_env, &
1781 gauge_atom_radius=gauge_atom_radius)
1782
1783 scale = 2.0_dp
1784
1785 box_size_guess = gauge_atom_radius/scale
1786
1787 natms = SIZE(particle_set, 1)
1788 ALLOCATE (ratom(3, natms))
1789
1790 !
1791 ! box the atoms
1792 nbox(1) = ceiling(cell%hmat(1, 1)/box_size_guess)
1793 nbox(2) = ceiling(cell%hmat(2, 2)/box_size_guess)
1794 nbox(3) = ceiling(cell%hmat(3, 3)/box_size_guess)
1795 dbox(1) = cell%hmat(1, 1)/real(nbox(1), dp)
1796 dbox(2) = cell%hmat(2, 2)/real(nbox(2), dp)
1797 dbox(3) = cell%hmat(3, 3)/real(nbox(3), dp)
1798 ALLOCATE (box_ptr(0:nbox(1), 0:nbox(2) - 1, 0:nbox(3) - 1), box_data(3, natms))
1799 box_data(:, :) = huge(0.0_dp)
1800 box_ptr(:, :, :) = huge(0)
1801 !
1802 offset(1) = cell%hmat(1, 1)*0.5_dp
1803 offset(2) = cell%hmat(2, 2)*0.5_dp
1804 offset(3) = cell%hmat(3, 3)*0.5_dp
1805 DO iatom = 1, natms
1806 ratom(:, iatom) = pbc(particle_set(iatom)%r(:), cell)
1807 END DO
1808 !
1809 i = 1
1810 DO kbox = 0, nbox(3) - 1
1811 DO jbox = 0, nbox(2) - 1
1812 box_ptr(0, jbox, kbox) = i
1813 DO ibox = 0, nbox(1) - 1
1814 ii = 0
1815 DO iatom = 1, natms
1816 IF (modulo(floor(ratom(1, iatom)/dbox(1)), nbox(1)) == ibox .AND. &
1817 modulo(floor(ratom(2, iatom)/dbox(2)), nbox(2)) == jbox .AND. &
1818 modulo(floor(ratom(3, iatom)/dbox(3)), nbox(3)) == kbox) THEN
1819 box_data(:, i) = ratom(:, iatom)
1820 i = i + 1
1821 ii = ii + 1
1822 END IF
1823 END DO
1824 box_ptr(ibox + 1, jbox, kbox) = box_ptr(ibox, jbox, kbox) + ii
1825 END DO
1826 END DO
1827 END DO
1828 !
1829 IF (.false.) THEN
1830 DO kbox = 0, nbox(3) - 1
1831 DO jbox = 0, nbox(2) - 1
1832 DO ibox = 0, nbox(1) - 1
1833 IF (box_ptr(ibox + 1, jbox, kbox) - box_ptr(ibox, jbox, kbox) > 0) THEN
1834 WRITE (*, *) 'box=', ibox, jbox, kbox
1835 WRITE (*, *) 'nbr atom=', box_ptr(ibox + 1, jbox, kbox) - box_ptr(ibox, jbox, kbox)
1836 DO iatom = box_ptr(ibox, jbox, kbox), box_ptr(ibox + 1, jbox, kbox) - 1
1837 WRITE (*, '(A,I3,3E14.6)') 'coor=', iatom, box_data(:, iatom)
1838 END DO
1839 END IF
1840 END DO
1841 END DO
1842 END DO
1843 END IF
1844 !
1845 NULLIFY (box)
1846 ALLOCATE (box(0:nbox(1) - 1, 0:nbox(2) - 1, 0:nbox(3) - 1))
1847 !
1848 ! build the list
1849 DO k = 0, nbox(3) - 1
1850 DO j = 0, nbox(2) - 1
1851 DO i = 0, nbox(1) - 1
1852 !
1853 box_center(1) = (real(i, dp) + 0.5_dp)*dbox(1)
1854 box_center(2) = (real(j, dp) + 0.5_dp)*dbox(2)
1855 box_center(3) = (real(k, dp) + 0.5_dp)*dbox(3)
1856 box_center_wrap = pbc(box_center, cell)
1857 !
1858 ! find the atoms that are in the overlaping boxes
1859 natms_local = 0
1860 kmin = floor((box_center(3) - gauge_atom_radius)/dbox(3))
1861 kmax = floor((box_center(3) + gauge_atom_radius)/dbox(3))
1862 IF (kmax - kmin + 1 > nbox(3)) THEN
1863 kmin = 0
1864 kmax = nbox(3) - 1
1865 END IF
1866 DO kbox = kmin, kmax
1867 jmin = floor((box_center(2) - gauge_atom_radius)/dbox(2))
1868 jmax = floor((box_center(2) + gauge_atom_radius)/dbox(2))
1869 IF (jmax - jmin + 1 > nbox(2)) THEN
1870 jmin = 0
1871 jmax = nbox(2) - 1
1872 END IF
1873 DO jbox = jmin, jmax
1874 imin = floor((box_center(1) - gauge_atom_radius)/dbox(1))
1875 imax = floor((box_center(1) + gauge_atom_radius)/dbox(1))
1876 IF (imax - imin + 1 > nbox(1)) THEN
1877 imin = 0
1878 imax = nbox(1) - 1
1879 END IF
1880 DO ibox = imin, imax
1881 ibeg = box_ptr(modulo(ibox, nbox(1)), modulo(jbox, nbox(2)), modulo(kbox, nbox(3)))
1882 iend = box_ptr(modulo(ibox, nbox(1)) + 1, modulo(jbox, nbox(2)), modulo(kbox, nbox(3))) - 1
1883 DO iatom = ibeg, iend
1884 r = pbc(box_center_wrap(:) - box_data(:, iatom), cell)
1885 IF (abs(r(1)) <= (scale + 0.5_dp)*dbox(1) .AND. &
1886 abs(r(2)) <= (scale + 0.5_dp)*dbox(2) .AND. &
1887 abs(r(3)) <= (scale + 0.5_dp)*dbox(3)) THEN
1888 natms_local = natms_local + 1
1889 ratom(:, natms_local) = box_data(:, iatom)
1890 END IF
1891 END DO
1892 END DO ! box
1893 END DO
1894 END DO
1895 !
1896 ! set the list
1897 box(i, j, k)%n = natms_local
1898 NULLIFY (box(i, j, k)%r)
1899 IF (natms_local > 0) THEN
1900 ALLOCATE (box(i, j, k)%r(3, natms_local))
1901 r_ptr => box(i, j, k)%r
1902 CALL dcopy(3*natms_local, ratom(1, 1), 1, r_ptr(1, 1), 1)
1903 END IF
1904 END DO ! list
1905 END DO
1906 END DO
1907
1908 IF (.false.) THEN
1909 DO k = 0, nbox(3) - 1
1910 DO j = 0, nbox(2) - 1
1911 DO i = 0, nbox(1) - 1
1912 IF (box(i, j, k)%n > 0) THEN
1913 WRITE (*, *)
1914 WRITE (*, *) 'box=', i, j, k
1915 box_center(1) = (real(i, dp) + 0.5_dp)*dbox(1)
1916 box_center(2) = (real(j, dp) + 0.5_dp)*dbox(2)
1917 box_center(3) = (real(k, dp) + 0.5_dp)*dbox(3)
1918 box_center = pbc(box_center, cell)
1919 WRITE (*, '(A,3E14.6)') 'box_center=', box_center
1920 WRITE (*, *) 'nbr atom=', box(i, j, k)%n
1921 r_ptr => box(i, j, k)%r
1922 DO iatom = 1, box(i, j, k)%n
1923 WRITE (*, '(A,I3,3E14.6)') 'coor=', iatom, r_ptr(:, iatom)
1924 r(:) = pbc(box_center(:) - r_ptr(:, iatom), cell)
1925 IF (abs(r(1)) > (scale + 0.5_dp)*dbox(1) .OR. &
1926 abs(r(2)) > (scale + 0.5_dp)*dbox(2) .OR. &
1927 abs(r(3)) > (scale + 0.5_dp)*dbox(3)) THEN
1928 WRITE (*, *) 'error too many atoms'
1929 WRITE (*, *) 'dist=', abs(r(:))
1930 WRITE (*, *) 'large_dist=', (scale + 0.5_dp)*dbox
1931 cpabort("Some atoms are too far from box center")
1932 END IF
1933 END DO
1934 END IF
1935 END DO ! list
1936 END DO
1937 END DO
1938 END IF
1939
1940 IF (.true.) THEN
1941 DO k = 0, nbox(3) - 1
1942 DO j = 0, nbox(2) - 1
1943 DO i = 0, nbox(1) - 1
1944 box_center(1) = (real(i, dp) + 0.5_dp)*dbox(1)
1945 box_center(2) = (real(j, dp) + 0.5_dp)*dbox(2)
1946 box_center(3) = (real(k, dp) + 0.5_dp)*dbox(3)
1947 box_center = pbc(box_center, cell)
1948 r_ptr => box(i, j, k)%r
1949 DO iatom = 1, natms
1950 r(:) = pbc(box_center(:) - ratom(:, iatom), cell)
1951 ifind = 0
1952 DO jatom = 1, box(i, j, k)%n
1953 IF (sum(abs(ratom(:, iatom) - r_ptr(:, jatom))) < 1e-10_dp) ifind = 1
1954 END DO
1955
1956 IF (ifind == 0) THEN
1957 ! SQRT(DOT_PRODUCT(r, r)) < gauge_atom_radius
1958 IF (dot_product(r, r) < (gauge_atom_radius*gauge_atom_radius)) THEN
1959 WRITE (*, *) 'error atom too close'
1960 WRITE (*, *) 'iatom', iatom
1961 WRITE (*, *) 'box_center', box_center
1962 WRITE (*, *) 'ratom', ratom(:, iatom)
1963 WRITE (*, *) 'gauge_atom_radius', gauge_atom_radius
1964 cpabort("Some atoms are too close within gauge_atom_radius")
1965 END IF
1966 END IF
1967 END DO
1968 END DO ! list
1969 END DO
1970 END DO
1971 END IF
1972
1973 DEALLOCATE (ratom)
1974
1975 CALL timestop(handle)
1976
1977 END SUBROUTINE box_atoms_new
1978
1979! **************************************************************************************************
1980!> \brief ...
1981!> \param current_env ...
1982!> \param qs_env ...
1983!> \param rs_grid_x ...
1984!> \param rs_grid_y ...
1985!> \param rs_grid_z ...
1986!> \param box ...
1987! **************************************************************************************************
1988 SUBROUTINE collocate_gauge_new(current_env, qs_env, rs_grid_x, rs_grid_y, rs_grid_z, box)
1989 !
1990 TYPE(current_env_type) :: current_env
1991 TYPE(qs_environment_type), POINTER :: qs_env
1992 TYPE(realspace_grid_type), INTENT(IN) :: rs_grid_x, rs_grid_y, rs_grid_z
1993 TYPE(box_type), DIMENSION(:, :, :), POINTER :: box
1994
1995 CHARACTER(LEN=*), PARAMETER :: routinen = 'collocate_gauge_new'
1996
1997 INTEGER :: box_end(3), box_start(3), delta_lb(3), grid_end(3), grid_start(3), handle, i, &
1998 iatom, ib, ibox, j, jatom, jb, jbox, k, kb, kbox, lb(3), lb_local(3), natms, &
1999 natms_local0, natms_local1, ng(3)
2000 INTEGER(KIND=int_8) :: box_lower(3), box_upper(3), &
2001 grid_lower(3), grid_upper(3), npts(3)
2002 REAL(dp), DIMENSION(:, :), POINTER :: r_ptr
2003 REAL(kind=dp) :: ab, box_center(3), buf_tmp, dist, dr(3), &
2004 gauge_atom_radius, offset(3), pa, pb, &
2005 point(3), pra(3), r(3), res(3), summe, &
2006 tmp, x, y, z
2007 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: buf, nrm_atms_pnt
2008 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: atms_pnt, ratom
2009 REAL(kind=dp), DIMENSION(:, :, :), POINTER :: grid_x, grid_y, grid_z
2010 TYPE(cell_type), POINTER :: cell
2011 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
2012 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
2013
2014 CALL timeset(routinen, handle)
2015
2016!
2017 CALL get_current_env(current_env=current_env, &
2018 gauge_atom_radius=gauge_atom_radius)
2019 !
2020 CALL get_qs_env(qs_env=qs_env, &
2021 qs_kind_set=qs_kind_set, &
2022 cell=cell, &
2023 particle_set=particle_set)
2024 !
2025 natms = SIZE(particle_set, 1)
2026 dr(1) = rs_grid_x%desc%dh(1, 1)
2027 dr(2) = rs_grid_x%desc%dh(2, 2)
2028 dr(3) = rs_grid_x%desc%dh(3, 3)
2029 lb(:) = rs_grid_x%desc%lb(:)
2030 lb_local(:) = rs_grid_x%lb_local(:)
2031 grid_x => rs_grid_x%r(:, :, :)
2032 grid_y => rs_grid_y%r(:, :, :)
2033 grid_z => rs_grid_z%r(:, :, :)
2034 ng(:) = ubound(grid_x)
2035 npts(:) = int(rs_grid_x%desc%npts(:), kind=int_8)
2036 delta_lb(:) = lb_local(:) - lb(:)
2037 offset(1) = cell%hmat(1, 1)*0.5_dp
2038 offset(2) = cell%hmat(2, 2)*0.5_dp
2039 offset(3) = cell%hmat(3, 3)*0.5_dp
2040 ALLOCATE (buf(natms), ratom(3, natms), atms_pnt(3, natms), nrm_atms_pnt(natms))
2041 !
2042 ! Both the grid and the boxes partition the same cell. Cancel the cell length:
2043 ! g*dr >= b*dbox is equivalent to g*nbox >= b*npts.
2044 ! For a positive divisor d, floor(a/d) = (a - MODULO(a,d))/d,
2045 ! including negative indices in the grid's halo. Use 64-bit products.
2046 grid_lower = int(delta_lb, kind=int_8)*nbox
2047 grid_upper = (int(ng, kind=int_8) - 1_int_8 + delta_lb)*nbox
2048 box_start = int((grid_lower - modulo(grid_lower, npts))/npts)
2049 box_end = int((grid_upper - modulo(grid_upper, npts))/npts)
2050 !
2051 ! go over the box-list
2052 DO kb = box_start(3), box_end(3)
2053 DO jb = box_start(2), box_end(2)
2054 DO ib = box_start(1), box_end(1)
2055 ibox = modulo(ib, nbox(1))
2056 jbox = modulo(jb, nbox(2))
2057 kbox = modulo(kb, nbox(3))
2058 !
2059 ! The existing box intervals include both endpoints. Compute ceil(b*npts/nbox)
2060 ! and floor((b+1)*npts/nbox) exactly, then clip to this rank's local grid.
2061 ! ceil(a/d) = (a + MODULO(-a,d))/d also handles negative box indices.
2062 box_lower = int([ib, jb, kb], kind=int_8)*npts
2063 box_upper = (int([ib, jb, kb], kind=int_8) + 1_int_8)*npts
2064 grid_start = int((box_lower + modulo(-box_lower, int(nbox, kind=int_8)))/nbox)
2065 grid_end = int((box_upper - modulo(box_upper, int(nbox, kind=int_8)))/nbox)
2066 grid_start = max(grid_start, delta_lb) - delta_lb + 1
2067 grid_end = min(grid_end, ng - 1 + delta_lb) - delta_lb + 1
2068 !
2069 ! Check the box boundaries in the same exact integer coordinates.
2070 grid_lower = (int(grid_start, kind=int_8) - 1_int_8 + delta_lb)*nbox
2071 grid_upper = (int(grid_end, kind=int_8) - 1_int_8 + delta_lb)*nbox
2072 cpassert(all(grid_lower >= box_lower))
2073 cpassert(all(grid_upper <= box_upper))
2074 !
2075 ! the center of the box
2076 box_center(1) = (real(ibox, dp) + 0.5_dp)*dbox(1)
2077 box_center(2) = (real(jbox, dp) + 0.5_dp)*dbox(2)
2078 box_center(3) = (real(kbox, dp) + 0.5_dp)*dbox(3)
2079 !
2080 ! find the atoms that are in the overlaping boxes
2081 natms_local0 = box(ibox, jbox, kbox)%n
2082 r_ptr => box(ibox, jbox, kbox)%r
2083 !
2084 ! go over the grid inside the box
2085 IF (natms_local0 > 0) THEN
2086 !
2087 ! here there are some atoms...
2088 DO k = grid_start(3), grid_end(3)
2089 DO j = grid_start(2), grid_end(2)
2090 DO i = grid_start(1), grid_end(1)
2091 point(1) = real(i - 1 + delta_lb(1), dp)*dr(1)
2092 point(2) = real(j - 1 + delta_lb(2), dp)*dr(2)
2093 point(3) = real(k - 1 + delta_lb(3), dp)*dr(3)
2094 point = pbc(point, cell)
2095 !
2096 ! compute atom-point distances
2097 natms_local1 = 0
2098 DO iatom = 1, natms_local0
2099 r(:) = pbc(r_ptr(:, iatom) - point(:), cell) + point(:) !needed?
2100 dist = (r(1) - point(1))**2 + (r(2) - point(2))**2 + (r(3) - point(3))**2
2101 IF (dist < gauge_atom_radius**2) THEN
2102 natms_local1 = natms_local1 + 1
2103 ratom(:, natms_local1) = r(:)
2104 !
2105 ! compute the distance atoms-point
2106 x = point(1) - r(1)
2107 y = point(2) - r(2)
2108 z = point(3) - r(3)
2109 atms_pnt(1, natms_local1) = x
2110 atms_pnt(2, natms_local1) = y
2111 atms_pnt(3, natms_local1) = z
2112 nrm_atms_pnt(natms_local1) = sqrt(x*x + y*y + z*z)
2113 END IF
2114 END DO
2115 !
2116 !
2117 IF (natms_local1 > 0) THEN
2118 !
2119 ! build the step
2120 DO iatom = 1, natms_local1
2121 buf_tmp = 1.0_dp
2122 pra(1) = atms_pnt(1, iatom)
2123 pra(2) = atms_pnt(2, iatom)
2124 pra(3) = atms_pnt(3, iatom)
2125 pa = nrm_atms_pnt(iatom)
2126 DO jatom = 1, natms_local1
2127 IF (iatom == jatom) cycle
2128 pb = nrm_atms_pnt(jatom)
2129 x = pra(1) - atms_pnt(1, jatom)
2130 y = pra(2) - atms_pnt(2, jatom)
2131 z = pra(3) - atms_pnt(3, jatom)
2132 ab = sqrt(x*x + y*y + z*z)
2133 !
2134 tmp = (pa - pb)/ab
2135 tmp = 0.5_dp*(3.0_dp - tmp*tmp)*tmp
2136 tmp = 0.5_dp*(3.0_dp - tmp*tmp)*tmp
2137 tmp = 0.5_dp*(3.0_dp - tmp*tmp)*tmp
2138 buf_tmp = buf_tmp*0.5_dp*(1.0_dp - tmp)
2139 END DO
2140 buf(iatom) = buf_tmp
2141 END DO
2142 res(1) = 0.0_dp
2143 res(2) = 0.0_dp
2144 res(3) = 0.0_dp
2145 summe = 0.0_dp
2146 DO iatom = 1, natms_local1
2147 res(1) = res(1) + ratom(1, iatom)*buf(iatom)
2148 res(2) = res(2) + ratom(2, iatom)*buf(iatom)
2149 res(3) = res(3) + ratom(3, iatom)*buf(iatom)
2150 summe = summe + buf(iatom)
2151 END DO
2152 res(1) = res(1)/summe
2153 res(2) = res(2)/summe
2154 res(3) = res(3)/summe
2155 grid_x(i, j, k) = point(1) - res(1)
2156 grid_y(i, j, k) = point(2) - res(2)
2157 grid_z(i, j, k) = point(3) - res(3)
2158 ELSE
2159 grid_x(i, j, k) = 0.0_dp
2160 grid_y(i, j, k) = 0.0_dp
2161 grid_z(i, j, k) = 0.0_dp
2162 END IF
2163 END DO ! grid
2164 END DO
2165 END DO
2166 !
2167 ELSE
2168 !
2169 ! here there is no atom
2170 DO k = grid_start(3), grid_end(3)
2171 DO j = grid_start(2), grid_end(2)
2172 DO i = grid_start(1), grid_end(1)
2173 grid_x(i, j, k) = 0.0_dp
2174 grid_y(i, j, k) = 0.0_dp
2175 grid_z(i, j, k) = 0.0_dp
2176 END DO ! grid
2177 END DO
2178 END DO
2179 !
2180 END IF
2181 !
2182 END DO ! list
2183 END DO
2184 END DO
2185
2186 DEALLOCATE (buf, ratom, atms_pnt, nrm_atms_pnt)
2187
2188 CALL timestop(handle)
2189
2190 END SUBROUTINE collocate_gauge_new
2191
2192! **************************************************************************************************
2193!> \brief ...
2194!> \param box ...
2195! **************************************************************************************************
2196 SUBROUTINE deallocate_box(box)
2197 TYPE(box_type), DIMENSION(:, :, :), POINTER :: box
2198
2199 INTEGER :: i, j, k
2200
2201 IF (ASSOCIATED(box)) THEN
2202 DO k = lbound(box, 3), ubound(box, 3)
2203 DO j = lbound(box, 2), ubound(box, 2)
2204 DO i = lbound(box, 1), ubound(box, 1)
2205 IF (ASSOCIATED(box(i, j, k)%r)) THEN
2206 DEALLOCATE (box(i, j, k)%r)
2207 END IF
2208 END DO
2209 END DO
2210 END DO
2211 DEALLOCATE (box)
2212 END IF
2213 END SUBROUTINE deallocate_box
2214 END SUBROUTINE current_set_gauge
2215
2216! **************************************************************************************************
2217!> \brief ...
2218!> \param current_env ...
2219!> \param qs_env ...
2220!> \param iB ...
2221! **************************************************************************************************
2222 SUBROUTINE current_build_chi(current_env, qs_env, iB)
2223 !
2224 TYPE(current_env_type) :: current_env
2225 TYPE(qs_environment_type), POINTER :: qs_env
2226 INTEGER, INTENT(IN) :: ib
2227
2228 IF (current_env%full) THEN
2229 CALL current_build_chi_many_centers(current_env, qs_env, ib)
2230 ELSE IF (current_env%nbr_center(1) > 1) THEN
2231 CALL current_build_chi_many_centers(current_env, qs_env, ib)
2232 ELSE
2233 CALL current_build_chi_one_center(current_env, qs_env, ib)
2234 END IF
2235
2236 END SUBROUTINE current_build_chi
2237
2238! **************************************************************************************************
2239!> \brief ...
2240!> \param current_env ...
2241!> \param qs_env ...
2242!> \param iB ...
2243! **************************************************************************************************
2244 SUBROUTINE current_build_chi_many_centers(current_env, qs_env, iB)
2245 !
2246 TYPE(current_env_type) :: current_env
2247 TYPE(qs_environment_type), POINTER :: qs_env
2248 INTEGER, INTENT(IN) :: ib
2249
2250 CHARACTER(LEN=*), PARAMETER :: routinen = 'current_build_chi_many_centers'
2251
2252 CHARACTER(LEN=default_string_length) :: basis_type
2253 INTEGER :: handle, icenter, idir, idir2, ii, iib, iii, iiib, ispin, istate, j, jstate, &
2254 max_states, nao, natom, nbr_center(2), nmo, nspins, nstate_loc, nstates(2), output_unit
2255 INTEGER, ALLOCATABLE, DIMENSION(:) :: first_sgf, last_sgf
2256 INTEGER, DIMENSION(:), POINTER :: row_blk_sizes
2257 LOGICAL :: chi_pbc, gapw
2258 REAL(dp) :: chi(3), chi_tmp, contrib, contrib2, &
2259 dk(3), int_current(3), &
2260 int_current_tmp, maxocc
2261 TYPE(cell_type), POINTER :: cell
2262 TYPE(cp_2d_i_p_type), DIMENSION(:), POINTER :: center_list
2263 TYPE(cp_2d_r_p_type), DIMENSION(:), POINTER :: centers_set
2264 TYPE(cp_fm_struct_type), POINTER :: tmp_fm_struct
2265 TYPE(cp_fm_type) :: psi0, psi_d, psi_p1, psi_p2, psi_rxp
2266 TYPE(cp_fm_type), DIMENSION(3) :: p_rxp, r_p1, r_p2
2267 TYPE(cp_fm_type), DIMENSION(9, 3) :: rr_p1, rr_p2, rr_rxp
2268 TYPE(cp_fm_type), DIMENSION(:), POINTER :: psi0_order
2269 TYPE(cp_fm_type), DIMENSION(:, :), POINTER :: psi1_d, psi1_p, psi1_rxp
2270 TYPE(cp_fm_type), POINTER :: mo_coeff
2271 TYPE(cp_logger_type), POINTER :: logger
2272 TYPE(dbcsr_distribution_type), POINTER :: dbcsr_dist
2273 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: op_mom_ao, op_p_ao
2274 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: op_mom_der_ao
2275 TYPE(dft_control_type), POINTER :: dft_control
2276 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
2277 TYPE(mp_para_env_type), POINTER :: para_env
2278 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
2279 POINTER :: sab_all, sab_orb
2280 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
2281 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
2282
2283!
2284
2285 CALL timeset(routinen, handle)
2286 !
2287 NULLIFY (dft_control, mos, para_env, mo_coeff, op_mom_ao, &
2288 op_mom_der_ao, center_list, centers_set, &
2289 op_p_ao, psi1_p, psi1_rxp, psi1_d, &
2290 cell, particle_set, qs_kind_set)
2291
2292 logger => cp_get_default_logger()
2293 output_unit = cp_logger_get_default_io_unit(logger)
2294
2295 CALL get_qs_env(qs_env=qs_env, &
2296 dft_control=dft_control, &
2297 mos=mos, &
2298 para_env=para_env, &
2299 cell=cell, &
2300 dbcsr_dist=dbcsr_dist, &
2301 particle_set=particle_set, &
2302 qs_kind_set=qs_kind_set, &
2303 sab_all=sab_all, &
2304 sab_orb=sab_orb)
2305
2306 nspins = dft_control%nspins
2307 gapw = dft_control%qs_control%gapw
2308 basis_type = "ORB"
2309 IF (gapw) basis_type = "ORB_SOFT"
2310
2311 CALL get_current_env(current_env=current_env, &
2312 chi_pbc=chi_pbc, &
2313 nao=nao, &
2314 nbr_center=nbr_center, &
2315 center_list=center_list, &
2316 centers_set=centers_set, &
2317 psi1_p=psi1_p, &
2318 psi1_rxp=psi1_rxp, &
2319 psi1_d=psi1_d, &
2320 nstates=nstates, &
2321 psi0_order=psi0_order)
2322 !
2323 ! get max nbr of states per center
2324 max_states = 0
2325 DO ispin = 1, nspins
2326 DO icenter = 1, nbr_center(ispin)
2327 max_states = max(max_states, center_list(ispin)%array(1, icenter + 1)&
2328 & - center_list(ispin)%array(1, icenter))
2329 END DO
2330 END DO
2331 !
2332 ! Allocate sparse matrices for dipole, quadrupole and their derivatives => 9x3
2333 ! Remember the derivatives are antisymmetric
2334 CALL dbcsr_allocate_matrix_set(op_mom_ao, 9)
2335 CALL dbcsr_allocate_matrix_set(op_mom_der_ao, 9, 3)
2336 !
2337 ! prepare for allocation
2338 natom = SIZE(particle_set, 1)
2339 ALLOCATE (first_sgf(natom))
2340 ALLOCATE (last_sgf(natom))
2341 CALL get_particle_set(particle_set, qs_kind_set, &
2342 first_sgf=first_sgf, &
2343 last_sgf=last_sgf)
2344 ALLOCATE (row_blk_sizes(natom))
2345 CALL dbcsr_convert_offsets_to_sizes(first_sgf, row_blk_sizes, last_sgf)
2346 DEALLOCATE (first_sgf)
2347 DEALLOCATE (last_sgf)
2348 !
2349 !
2350 ALLOCATE (op_mom_ao(1)%matrix)
2351 CALL dbcsr_create(matrix=op_mom_ao(1)%matrix, &
2352 name="op_mom", &
2353 dist=dbcsr_dist, matrix_type=dbcsr_type_no_symmetry, &
2354 row_blk_size=row_blk_sizes, col_blk_size=row_blk_sizes, &
2355 mutable_work=.true.)
2356 CALL cp_dbcsr_alloc_block_from_nbl(op_mom_ao(1)%matrix, sab_all)
2357
2358 DO idir2 = 1, 3
2359 ALLOCATE (op_mom_der_ao(1, idir2)%matrix)
2360 CALL dbcsr_copy(op_mom_der_ao(1, idir2)%matrix, op_mom_ao(1)%matrix, &
2361 "op_mom_der_ao"//"-"//trim(adjustl(cp_to_string(idir2))))
2362 END DO
2363
2364 DO idir = 2, SIZE(op_mom_ao, 1)
2365 ALLOCATE (op_mom_ao(idir)%matrix)
2366 CALL dbcsr_copy(op_mom_ao(idir)%matrix, op_mom_ao(1)%matrix, &
2367 "op_mom_ao"//"-"//trim(adjustl(cp_to_string(idir))))
2368 DO idir2 = 1, 3
2369 ALLOCATE (op_mom_der_ao(idir, idir2)%matrix)
2370 CALL dbcsr_copy(op_mom_der_ao(idir, idir2)%matrix, op_mom_ao(1)%matrix, &
2371 "op_mom_der_ao"//"-"//trim(adjustl(cp_to_string(idir*idir2))))
2372 END DO
2373 END DO
2374 !
2375 CALL dbcsr_allocate_matrix_set(op_p_ao, 3)
2376 ALLOCATE (op_p_ao(1)%matrix)
2377 CALL dbcsr_create(matrix=op_p_ao(1)%matrix, &
2378 name="op_p_ao", &
2379 dist=dbcsr_dist, matrix_type=dbcsr_type_antisymmetric, &
2380 row_blk_size=row_blk_sizes, col_blk_size=row_blk_sizes, &
2381 mutable_work=.true.)
2382 CALL cp_dbcsr_alloc_block_from_nbl(op_p_ao(1)%matrix, sab_orb)
2383
2384 DO idir = 2, 3
2385 ALLOCATE (op_p_ao(idir)%matrix)
2386 CALL dbcsr_copy(op_p_ao(idir)%matrix, op_p_ao(1)%matrix, &
2387 "op_p_ao"//"-"//trim(adjustl(cp_to_string(idir))))
2388 END DO
2389 !
2390 !
2391 DEALLOCATE (row_blk_sizes)
2392 !
2393 !
2394 ! Allocate full matrices for only one vector
2395 mo_coeff => psi0_order(1)
2396 NULLIFY (tmp_fm_struct)
2397 CALL cp_fm_struct_create(tmp_fm_struct, nrow_global=nao, &
2398 ncol_global=max_states, para_env=para_env, &
2399 context=mo_coeff%matrix_struct%context)
2400 CALL cp_fm_create(psi0, tmp_fm_struct)
2401 CALL cp_fm_create(psi_d, tmp_fm_struct)
2402 CALL cp_fm_create(psi_rxp, tmp_fm_struct)
2403 CALL cp_fm_create(psi_p1, tmp_fm_struct)
2404 CALL cp_fm_create(psi_p2, tmp_fm_struct)
2405 CALL cp_fm_struct_release(tmp_fm_struct)
2406 !
2407 CALL cp_fm_struct_create(tmp_fm_struct, nrow_global=nao, &
2408 ncol_global=max_states, para_env=para_env, &
2409 context=mo_coeff%matrix_struct%context)
2410 DO idir = 1, 3
2411 CALL cp_fm_create(p_rxp(idir), tmp_fm_struct, set_zero=.true.)
2412 CALL cp_fm_create(r_p1(idir), tmp_fm_struct, set_zero=.true.)
2413 CALL cp_fm_create(r_p2(idir), tmp_fm_struct, set_zero=.true.)
2414 DO idir2 = 1, 9
2415 CALL cp_fm_create(rr_rxp(idir2, idir), tmp_fm_struct, set_zero=.true.)
2416 CALL cp_fm_create(rr_p1(idir2, idir), tmp_fm_struct, set_zero=.true.)
2417 CALL cp_fm_create(rr_p2(idir2, idir), tmp_fm_struct, set_zero=.true.)
2418 END DO
2419 END DO
2420 CALL cp_fm_struct_release(tmp_fm_struct)
2421 !
2422 !
2423 !
2424 ! recompute the linear momentum matrices
2425 CALL build_lin_mom_matrix(qs_env, op_p_ao)
2426 !
2427 !
2428 ! get iiB and iiiB
2429 CALL set_vecp(ib, iib, iiib)
2430 DO ispin = 1, nspins
2431 !
2432 ! get ground state MOS
2433 nmo = nstates(ispin)
2434 mo_coeff => psi0_order(ispin)
2435 CALL get_mo_set(mo_set=mos(ispin), maxocc=maxocc)
2436 !
2437 ! Initialize the temporary vector chi
2438 chi = 0.0_dp
2439 int_current = 0.0_dp
2440 !
2441 ! Start loop over the occupied states
2442 DO icenter = 1, nbr_center(ispin)
2443 !
2444 ! Get the Wannier center of the istate-th ground state orbital
2445 dk(1:3) = centers_set(ispin)%array(1:3, icenter)
2446 !
2447 ! Compute the multipole integrals for the state istate,
2448 ! using as reference center the corresponding Wannier center
2449 DO idir = 1, 9
2450 CALL dbcsr_set(op_mom_ao(idir)%matrix, 0.0_dp)
2451 DO idir2 = 1, 3
2452 CALL dbcsr_set(op_mom_der_ao(idir, idir2)%matrix, 0.0_dp)
2453 END DO
2454 END DO
2455 CALL build_local_moments_der_matrix(qs_env, op_mom_der_ao, 2, 2, ref_point=dk, &
2456 moments=op_mom_ao, basis_type=basis_type, &
2457 minimum_image=.false., ordered=.true.)
2458 !
2459 ! collecte the states that belong to a given center
2460 CALL cp_fm_set_all(psi0, 0.0_dp)
2461 CALL cp_fm_set_all(psi_rxp, 0.0_dp)
2462 CALL cp_fm_set_all(psi_d, 0.0_dp)
2463 CALL cp_fm_set_all(psi_p1, 0.0_dp)
2464 CALL cp_fm_set_all(psi_p2, 0.0_dp)
2465 nstate_loc = center_list(ispin)%array(1, icenter + 1) - center_list(ispin)%array(1, icenter)
2466 jstate = 1
2467 DO j = center_list(ispin)%array(1, icenter), center_list(ispin)%array(1, icenter + 1) - 1
2468 istate = center_list(ispin)%array(2, j)
2469 !
2470 ! block the states that belong to this center
2471 CALL cp_fm_to_fm(mo_coeff, psi0, 1, istate, jstate)
2472 !
2473 CALL cp_fm_to_fm(psi1_rxp(ispin, ib), psi_rxp, 1, istate, jstate)
2474 IF (current_env%full) CALL cp_fm_to_fm(psi1_d(ispin, ib), psi_d, 1, istate, jstate)
2475 !
2476 ! psi1_p_iiB_istate and psi1_p_iiiB_istate
2477 CALL cp_fm_to_fm(psi1_p(ispin, iib), psi_p1, 1, istate, jstate)
2478 CALL cp_fm_to_fm(psi1_p(ispin, iiib), psi_p2, 1, istate, jstate)
2479 !
2480 jstate = jstate + 1
2481 END DO ! istate
2482 !
2483 ! scale the ordered mos
2484 IF (current_env%full) CALL cp_fm_scale_and_add(1.0_dp, psi_rxp, -1.0_dp, psi_d)
2485 !
2486 DO idir = 1, 3
2487 CALL set_vecp(idir, ii, iii)
2488 CALL cp_dbcsr_sm_fm_multiply(op_p_ao(idir)%matrix, psi_rxp, &
2489 p_rxp(idir), ncol=nstate_loc, alpha=1.e0_dp)
2490 IF (iiib == iii .OR. iiib == ii) THEN
2491 CALL cp_dbcsr_sm_fm_multiply(op_mom_ao(idir)%matrix, psi_p1, &
2492 r_p1(idir), ncol=nstate_loc, alpha=1.e0_dp)
2493 END IF
2494 IF (iib == iii .OR. iib == ii) THEN
2495 CALL cp_dbcsr_sm_fm_multiply(op_mom_ao(idir)%matrix, psi_p2, &
2496 r_p2(idir), ncol=nstate_loc, alpha=1.e0_dp)
2497 END IF
2498 DO idir2 = 1, 9
2499 IF (idir2 == ii .OR. idir2 == iii) THEN
2500 CALL cp_dbcsr_sm_fm_multiply(op_mom_der_ao(idir2, idir)%matrix, psi_rxp, &
2501 rr_rxp(idir2, idir), ncol=nstate_loc, alpha=1.e0_dp)
2502 END IF
2503 !
2504 IF (idir2 == ind_m2(ii, iiib) .OR. idir2 == ind_m2(iii, iiib) .OR. idir2 == iiib) THEN
2505 CALL cp_dbcsr_sm_fm_multiply(op_mom_der_ao(idir2, idir)%matrix, psi_p1, &
2506 rr_p1(idir2, idir), ncol=nstate_loc, alpha=1.e0_dp)
2507 END IF
2508 !
2509 IF (idir2 == ind_m2(ii, iib) .OR. idir2 == ind_m2(iii, iib) .OR. idir2 == iib) THEN
2510 CALL cp_dbcsr_sm_fm_multiply(op_mom_der_ao(idir2, idir)%matrix, psi_p2, &
2511 rr_p2(idir2, idir), ncol=nstate_loc, alpha=1.e0_dp)
2512 END IF
2513 END DO
2514 END DO
2515 !
2516 ! Multuply left and right by the appropriate coefficients and sum into the
2517 ! correct component of the chi tensor using the appropriate multiplicative factor
2518 ! (don't forget the occupation number)
2519 ! Loop over the cartesian components of the tensor
2520 ! The loop over the components of the external field is external, thereby
2521 ! only one column of the chi tensor is computed here
2522 DO idir = 1, 3
2523 chi_tmp = 0.0_dp
2524 int_current_tmp = 0.0_dp
2525 !
2526 ! get ii and iii
2527 CALL set_vecp(idir, ii, iii)
2528 !
2529 ! term: 2[C0| (r-dk)_ii |d_iii(C1(rxp-D))]-2[C0| (r-dk)_iii |d_ii(C1(rxp-D))]
2530 ! the factor 2 should be already included in the matrix elements
2531 contrib = 0.0_dp
2532 CALL cp_fm_trace(psi0, rr_rxp(ii, iii), contrib)
2533 chi_tmp = chi_tmp + 2.0_dp*contrib
2534 !
2535 contrib = 0.0_dp
2536 CALL cp_fm_trace(psi0, rr_rxp(iii, ii), contrib)
2537 chi_tmp = chi_tmp - 2.0_dp*contrib
2538 !
2539 ! correction: dk_ii*2[C0| d_iii(C1(rxp-D))] - dk_iii*2[C0| d_ii(C1(rxp-D))]
2540 ! factor 2 not included in the matrix elements
2541 contrib = 0.0_dp
2542 CALL cp_fm_trace(psi0, p_rxp(iii), contrib)
2543 IF (.NOT. chi_pbc) chi_tmp = chi_tmp + 2.0_dp*dk(ii)*contrib
2544 int_current_tmp = int_current_tmp + 2.0_dp*contrib
2545 !
2546 contrib2 = 0.0_dp
2547 CALL cp_fm_trace(psi0, p_rxp(ii), contrib2)
2548 IF (.NOT. chi_pbc) chi_tmp = chi_tmp - 2.0_dp*dk(iii)*contrib2
2549 !
2550 ! term: -2[C0| (r-dk)_ii (r-dk)_iiB | d_iii(C1(piiiB))] \
2551 ! +2[C0| (r-dk)_iii (r-dk)_iiB | d_ii(C1(piiiB))]
2552 ! the factor 2 should be already included in the matrix elements
2553 contrib = 0.0_dp
2554 idir2 = ind_m2(ii, iib)
2555 CALL cp_fm_trace(psi0, rr_p2(idir2, iii), contrib)
2556 chi_tmp = chi_tmp - 2.0_dp*contrib
2557 contrib2 = 0.0_dp
2558 IF (iib == iii) THEN
2559 CALL cp_fm_trace(psi0, r_p2(ii), contrib2)
2560 chi_tmp = chi_tmp - contrib2
2561 END IF
2562 !
2563 contrib = 0.0_dp
2564 idir2 = ind_m2(iii, iib)
2565 CALL cp_fm_trace(psi0, rr_p2(idir2, ii), contrib)
2566 chi_tmp = chi_tmp + 2.0_dp*contrib
2567 contrib2 = 0.0_dp
2568 IF (iib == ii) THEN
2569 CALL cp_fm_trace(psi0, r_p2(iii), contrib2)
2570 chi_tmp = chi_tmp + contrib2
2571 END IF
2572 !
2573 ! correction: -dk_ii * 2[C0|(r-dk)_iiB | d_iii(C1(piiiB))] \
2574 ! +dk_iii * 2[C0|(r-dk)_iiB | d_ii(C1(piiiB))]
2575 ! the factor 2 should be already included in the matrix elements
2576 ! no additional correction terms because of the orthogonality between C0 and C1
2577 contrib = 0.0_dp
2578 CALL cp_fm_trace(psi0, rr_p2(iib, iii), contrib)
2579 IF (.NOT. chi_pbc) chi_tmp = chi_tmp - 2.0_dp*dk(ii)*contrib
2580 int_current_tmp = int_current_tmp - 2.0_dp*contrib
2581 !
2582 contrib2 = 0.0_dp
2583 CALL cp_fm_trace(psi0, rr_p2(iib, ii), contrib2)
2584 IF (.NOT. chi_pbc) chi_tmp = chi_tmp + 2.0_dp*dk(iii)*contrib2
2585 !
2586 ! term: +2[C0| (r-dk)_ii (r-dk)_iiiB | d_iii(C1(piiB))] \
2587 ! -2[C0| (r-dk)_iii (r-dk)_iiiB | d_ii(C1(piiB))]
2588 ! the factor 2 should be already included in the matrix elements
2589 contrib = 0.0_dp
2590 idir2 = ind_m2(ii, iiib)
2591 CALL cp_fm_trace(psi0, rr_p1(idir2, iii), contrib)
2592 chi_tmp = chi_tmp + 2.0_dp*contrib
2593 contrib2 = 0.0_dp
2594 IF (iiib == iii) THEN
2595 CALL cp_fm_trace(psi0, r_p1(ii), contrib2)
2596 chi_tmp = chi_tmp + contrib2
2597 END IF
2598 !
2599 contrib = 0.0_dp
2600 idir2 = ind_m2(iii, iiib)
2601 CALL cp_fm_trace(psi0, rr_p1(idir2, ii), contrib)
2602 chi_tmp = chi_tmp - 2.0_dp*contrib
2603 contrib2 = 0.0_dp
2604 IF (iiib == ii) THEN
2605 CALL cp_fm_trace(psi0, r_p1(iii), contrib2)
2606 chi_tmp = chi_tmp - contrib2
2607 END IF
2608 !
2609 ! correction: +dk_ii * 2[C0|(r-dk)_iiiB | d_iii(C1(piiB))] +\
2610 ! -dk_iii * 2[C0|(r-dk)_iiiB | d_ii(C1(piiB))]
2611 ! the factor 2 should be already included in the matrix elements
2612 contrib = 0.0_dp
2613 CALL cp_fm_trace(psi0, rr_p1(iiib, iii), contrib)
2614 IF (.NOT. chi_pbc) chi_tmp = chi_tmp + 2.0_dp*dk(ii)*contrib
2615 int_current_tmp = int_current_tmp + 2.0_dp*contrib
2616 !
2617 contrib2 = 0.0_dp
2618 CALL cp_fm_trace(psi0, rr_p1(iiib, ii), contrib2)
2619 IF (.NOT. chi_pbc) chi_tmp = chi_tmp - 2.0_dp*dk(iii)*contrib2
2620 !
2621 ! accumulate
2622 chi(idir) = chi(idir) + maxocc*chi_tmp
2623 int_current(iii) = int_current(iii) + int_current_tmp
2624 END DO ! idir
2625
2626 END DO ! icenter
2627 !
2628 DO idir = 1, 3
2629 current_env%chi_tensor(idir, ib, ispin) = current_env%chi_tensor(idir, ib, ispin) + &
2630 chi(idir)
2631 IF (output_unit > 0) THEN
2632 !WRITE(output_unit,'(A,E12.6)') ' chi_'//ACHAR(119+idir)//ACHAR(119+iB)//&
2633 ! & ' = ',chi(idir)
2634 !WRITE(output_unit,'(A,E12.6)') ' analytic \int j_'//ACHAR(119+idir)//ACHAR(119+iB)//&
2635 ! & '(r) d^3r = ',int_current(idir)
2636 END IF
2637 END DO
2638 !
2639 END DO ! ispin
2640 !
2641 ! deallocate the sparse matrices
2642 CALL dbcsr_deallocate_matrix_set(op_mom_ao)
2643 CALL dbcsr_deallocate_matrix_set(op_mom_der_ao)
2644 CALL dbcsr_deallocate_matrix_set(op_p_ao)
2645
2646 CALL cp_fm_release(psi0)
2647 CALL cp_fm_release(psi_rxp)
2648 CALL cp_fm_release(psi_d)
2649 CALL cp_fm_release(psi_p1)
2650 CALL cp_fm_release(psi_p2)
2651 DO idir = 1, 3
2652 CALL cp_fm_release(p_rxp(idir))
2653 CALL cp_fm_release(r_p1(idir))
2654 CALL cp_fm_release(r_p2(idir))
2655 DO idir2 = 1, 9
2656 CALL cp_fm_release(rr_rxp(idir2, idir))
2657 CALL cp_fm_release(rr_p1(idir2, idir))
2658 CALL cp_fm_release(rr_p2(idir2, idir))
2659 END DO
2660 END DO
2661
2662 CALL timestop(handle)
2663
2664 END SUBROUTINE current_build_chi_many_centers
2665
2666! **************************************************************************************************
2667!> \brief ...
2668!> \param current_env ...
2669!> \param qs_env ...
2670!> \param iB ...
2671! **************************************************************************************************
2672 SUBROUTINE current_build_chi_one_center(current_env, qs_env, iB)
2673 !
2674 TYPE(current_env_type) :: current_env
2675 TYPE(qs_environment_type), POINTER :: qs_env
2676 INTEGER, INTENT(IN) :: ib
2677
2678 CHARACTER(LEN=*), PARAMETER :: routinen = 'current_build_chi_one_center'
2679
2680 CHARACTER(LEN=default_string_length) :: basis_type
2681 INTEGER :: handle, idir, idir2, iib, iiib, ispin, jdir, jjdir, kdir, max_states, nao, natom, &
2682 nbr_center(2), nmo, nspins, nstates(2), output_unit
2683 INTEGER, ALLOCATABLE, DIMENSION(:) :: first_sgf, last_sgf
2684 INTEGER, DIMENSION(:), POINTER :: row_blk_sizes
2685 LOGICAL :: chi_pbc, gapw
2686 REAL(dp) :: chi(3), contrib, dk(3), int_current(3), &
2687 maxocc
2688 TYPE(cell_type), POINTER :: cell
2689 TYPE(cp_2d_i_p_type), DIMENSION(:), POINTER :: center_list
2690 TYPE(cp_2d_r_p_type), DIMENSION(:), POINTER :: centers_set
2691 TYPE(cp_fm_type) :: buf
2692 TYPE(cp_fm_type), DIMENSION(:), POINTER :: psi0_order
2693 TYPE(cp_fm_type), DIMENSION(:, :), POINTER :: psi1_p, psi1_rxp
2694 TYPE(cp_fm_type), POINTER :: mo_coeff
2695 TYPE(cp_logger_type), POINTER :: logger
2696 TYPE(dbcsr_distribution_type), POINTER :: dbcsr_dist
2697 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: op_mom_ao, op_p_ao
2698 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: op_mom_der_ao
2699 TYPE(dft_control_type), POINTER :: dft_control
2700 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
2701 TYPE(mp_para_env_type), POINTER :: para_env
2702 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
2703 POINTER :: sab_all, sab_orb
2704 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
2705 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
2706
2707!
2708
2709 CALL timeset(routinen, handle)
2710 !
2711 NULLIFY (dft_control, mos, para_env, mo_coeff, op_mom_ao, &
2712 op_mom_der_ao, center_list, centers_set, &
2713 op_p_ao, psi1_p, psi1_rxp, cell, psi0_order)
2714
2715 logger => cp_get_default_logger()
2716 output_unit = cp_logger_get_default_io_unit(logger)
2717
2718 CALL get_qs_env(qs_env=qs_env, &
2719 dft_control=dft_control, &
2720 mos=mos, &
2721 para_env=para_env, &
2722 cell=cell, &
2723 particle_set=particle_set, &
2724 qs_kind_set=qs_kind_set, &
2725 sab_all=sab_all, &
2726 sab_orb=sab_orb, &
2727 dbcsr_dist=dbcsr_dist)
2728
2729 nspins = dft_control%nspins
2730 gapw = dft_control%qs_control%gapw
2731 basis_type = "ORB"
2732 IF (gapw) basis_type = "ORB_SOFT"
2733
2734 CALL get_current_env(current_env=current_env, &
2735 chi_pbc=chi_pbc, &
2736 nao=nao, &
2737 nbr_center=nbr_center, &
2738 center_list=center_list, &
2739 centers_set=centers_set, &
2740 psi1_p=psi1_p, &
2741 psi1_rxp=psi1_rxp, &
2742 nstates=nstates, &
2743 psi0_order=psi0_order)
2744 !
2745 max_states = maxval(nstates(1:nspins))
2746 !
2747 ! Allocate sparse matrices for dipole, quadrupole and their derivatives => 9x3
2748 ! Remember the derivatives are antisymmetric
2749 CALL dbcsr_allocate_matrix_set(op_mom_ao, 9)
2750 CALL dbcsr_allocate_matrix_set(op_mom_der_ao, 9, 3)
2751 !
2752 ! prepare for allocation
2753 natom = SIZE(particle_set, 1)
2754 ALLOCATE (first_sgf(natom))
2755 ALLOCATE (last_sgf(natom))
2756 CALL get_particle_set(particle_set, qs_kind_set, &
2757 first_sgf=first_sgf, &
2758 last_sgf=last_sgf)
2759 ALLOCATE (row_blk_sizes(natom))
2760 CALL dbcsr_convert_offsets_to_sizes(first_sgf, row_blk_sizes, last_sgf)
2761 DEALLOCATE (first_sgf)
2762 DEALLOCATE (last_sgf)
2763 !
2764 !
2765 ALLOCATE (op_mom_ao(1)%matrix)
2766 CALL dbcsr_create(matrix=op_mom_ao(1)%matrix, &
2767 name="op_mom", &
2768 dist=dbcsr_dist, matrix_type=dbcsr_type_no_symmetry, &
2769 row_blk_size=row_blk_sizes, col_blk_size=row_blk_sizes, &
2770 mutable_work=.true.)
2771 CALL cp_dbcsr_alloc_block_from_nbl(op_mom_ao(1)%matrix, sab_all)
2772
2773 DO idir2 = 1, 3
2774 ALLOCATE (op_mom_der_ao(1, idir2)%matrix)
2775 CALL dbcsr_copy(op_mom_der_ao(1, idir2)%matrix, op_mom_ao(1)%matrix, &
2776 "op_mom_der_ao"//"-"//trim(adjustl(cp_to_string(idir2))))
2777 END DO
2778
2779 DO idir = 2, SIZE(op_mom_ao, 1)
2780 ALLOCATE (op_mom_ao(idir)%matrix)
2781 CALL dbcsr_copy(op_mom_ao(idir)%matrix, op_mom_ao(1)%matrix, &
2782 "op_mom_ao"//"-"//trim(adjustl(cp_to_string(idir))))
2783 DO idir2 = 1, 3
2784 ALLOCATE (op_mom_der_ao(idir, idir2)%matrix)
2785 CALL dbcsr_copy(op_mom_der_ao(idir, idir2)%matrix, op_mom_ao(1)%matrix, &
2786 "op_mom_der_ao"//"-"//trim(adjustl(cp_to_string(idir*idir2))))
2787 END DO
2788 END DO
2789 !
2790 CALL dbcsr_allocate_matrix_set(op_p_ao, 3)
2791 ALLOCATE (op_p_ao(1)%matrix)
2792 CALL dbcsr_create(matrix=op_p_ao(1)%matrix, &
2793 name="op_p_ao", &
2794 dist=dbcsr_dist, matrix_type=dbcsr_type_antisymmetric, &
2795 row_blk_size=row_blk_sizes, col_blk_size=row_blk_sizes, &
2796 mutable_work=.true.)
2797 CALL cp_dbcsr_alloc_block_from_nbl(op_p_ao(1)%matrix, sab_orb)
2798
2799 DO idir = 2, 3
2800 ALLOCATE (op_p_ao(idir)%matrix)
2801 CALL dbcsr_copy(op_p_ao(idir)%matrix, op_p_ao(1)%matrix, &
2802 "op_p_ao"//"-"//trim(adjustl(cp_to_string(idir))))
2803 END DO
2804 !
2805 !
2806 DEALLOCATE (row_blk_sizes)
2807 !
2808 ! recompute the linear momentum matrices
2809 CALL build_lin_mom_matrix(qs_env, op_p_ao)
2810 !
2811 !
2812 ! get iiB and iiiB
2813 CALL set_vecp(ib, iib, iiib)
2814 DO ispin = 1, nspins
2815 !
2816 cpassert(nbr_center(ispin) == 1)
2817 !
2818 ! get ground state MOS
2819 nmo = nstates(ispin)
2820 mo_coeff => psi0_order(ispin)
2821 CALL get_mo_set(mo_set=mos(ispin), maxocc=maxocc)
2822 !
2823 ! Create buffer matrix
2824 CALL cp_fm_create(buf, mo_coeff%matrix_struct)
2825 !
2826 ! Initialize the temporary vector chi
2827 chi = 0.0_dp
2828 int_current = 0.0_dp
2829 !
2830 !
2831 ! Get the Wannier center of the istate-th ground state orbital
2832 dk(1:3) = centers_set(ispin)%array(1:3, 1)
2833 !
2834 ! Compute the multipole integrals for the state istate,
2835 ! using as reference center the corresponding Wannier center
2836 DO idir = 1, 9
2837 CALL dbcsr_set(op_mom_ao(idir)%matrix, 0.0_dp)
2838 DO idir2 = 1, 3
2839 CALL dbcsr_set(op_mom_der_ao(idir, idir2)%matrix, 0.0_dp)
2840 END DO
2841 END DO
2842 CALL build_local_moments_der_matrix(qs_env, op_mom_der_ao, 2, 2, ref_point=dk, &
2843 moments=op_mom_ao, basis_type=basis_type, &
2844 minimum_image=.false., ordered=.true.)
2845 !
2846 !
2847 ! Multuply left and right by the appropriate coefficients and sum into the
2848 ! correct component of the chi tensor using the appropriate multiplicative factor
2849 ! (don't forget the occupation number)
2850 ! Loop over the cartesian components of the tensor
2851 ! The loop over the components of the external field is external, thereby
2852 ! only one column of the chi tensor is computed here
2853 DO idir = 1, 3
2854 !
2855 !
2856 !
2857 ! term: dk_ii*2[C0| d_iii(C1(rxp-D))] - dk_iii*2[C0| d_ii(C1(rxp-D))]
2858 IF (.NOT. chi_pbc) THEN
2859 CALL cp_dbcsr_sm_fm_multiply(op_p_ao(idir)%matrix, mo_coeff, &
2860 buf, ncol=nmo, alpha=1.e0_dp)
2861 DO jdir = 1, 3
2862 DO kdir = 1, 3
2863 IF (levi_civita(kdir, jdir, idir) == 0.0_dp) cycle
2864 CALL cp_fm_trace(buf, psi1_rxp(ispin, ib), contrib)
2865 chi(kdir) = chi(kdir) - levi_civita(kdir, jdir, idir)*2.0_dp*dk(jdir)*contrib
2866 END DO
2867 END DO
2868 END IF
2869 !
2870 !
2871 !
2872 ! term: 2[C0| (r-dk)_ii |d_iii(C1(rxp-D))]-2[C0| (r-dk)_iii |d_ii(C1(rxp-D))]
2873 ! and
2874 ! term: -dk_ii * 2[C0|(r-dk)_iiB | d_iii(C1(piiiB))] +
2875 ! +dk_iii * 2[C0|(r-dk)_iiB | d_ii(C1(piiiB))]
2876 ! and
2877 ! term: +dk_ii * 2[C0|(r-dk)_iiiB | d_iii(C1(piiB))] +
2878 ! -dk_iii * 2[C0|(r-dk)_iiiB | d_ii(C1(piiB))]
2879 DO jdir = 1, 3
2880 CALL cp_dbcsr_sm_fm_multiply(op_mom_der_ao(jdir, idir)%matrix, mo_coeff, &
2881 buf, ncol=nmo, alpha=1.e0_dp)
2882 DO kdir = 1, 3
2883 IF (levi_civita(kdir, jdir, idir) == 0.0_dp) cycle
2884 CALL cp_fm_trace(buf, psi1_rxp(ispin, ib), contrib)
2885 chi(kdir) = chi(kdir) - levi_civita(kdir, jdir, idir)*2.0_dp*contrib
2886 END DO
2887 !
2888 IF (.NOT. chi_pbc) THEN
2889 IF (jdir == iib) THEN
2890 DO jjdir = 1, 3
2891 DO kdir = 1, 3
2892 IF (levi_civita(kdir, jjdir, idir) == 0.0_dp) cycle
2893 CALL cp_fm_trace(buf, psi1_p(ispin, iiib), contrib)
2894 chi(kdir) = chi(kdir) + levi_civita(kdir, jjdir, idir)*2.0_dp*dk(jjdir)*contrib
2895 END DO
2896 END DO
2897 END IF
2898 !
2899 IF (jdir == iiib) THEN
2900 DO jjdir = 1, 3
2901 DO kdir = 1, 3
2902 IF (levi_civita(kdir, jjdir, idir) == 0.0_dp) cycle
2903 CALL cp_fm_trace(buf, psi1_p(ispin, iib), contrib)
2904 chi(kdir) = chi(kdir) - levi_civita(kdir, jjdir, idir)*2.0_dp*dk(jjdir)*contrib
2905 END DO
2906 END DO
2907 END IF
2908 END IF
2909 END DO
2910 !
2911 !
2912 !
2913 ! term1: -2[C0| (r-dk)_ii (r-dk)_iiB | d_iii(C1(piiiB))] +
2914 ! +2[C0| (r-dk)_iii (r-dk)_iiB | d_ii(C1(piiiB))]
2915 ! and
2916 ! term1: +2[C0| (r-dk)_ii (r-dk)_iiiB | d_iii(C1(piiB))] +
2917 ! -2[C0| (r-dk)_iii (r-dk)_iiiB | d_ii(C1(piiB))]
2918 ! HERE THERE IS ONE EXTRA MULTIPLY
2919 DO jdir = 1, 3
2920 CALL cp_dbcsr_sm_fm_multiply(op_mom_der_ao(ind_m2(jdir, iib), idir)%matrix, mo_coeff, &
2921 buf, ncol=nmo, alpha=1.e0_dp)
2922 DO kdir = 1, 3
2923 IF (levi_civita(kdir, jdir, idir) == 0.0_dp) cycle
2924 CALL cp_fm_trace(buf, psi1_p(ispin, iiib), contrib)
2925 chi(kdir) = chi(kdir) + levi_civita(kdir, jdir, idir)*2.0_dp*contrib
2926 END DO
2927 !
2928 CALL cp_dbcsr_sm_fm_multiply(op_mom_der_ao(ind_m2(jdir, iiib), idir)%matrix, mo_coeff, &
2929 buf, ncol=nmo, alpha=1.e0_dp)
2930 DO kdir = 1, 3
2931 IF (levi_civita(kdir, jdir, idir) == 0.0_dp) cycle
2932 CALL cp_fm_trace(buf, psi1_p(ispin, iib), contrib)
2933 chi(kdir) = chi(kdir) - levi_civita(kdir, jdir, idir)*2.0_dp*contrib
2934 END DO
2935 END DO
2936 !
2937 !
2938 !
2939 ! term2: -2[C0| (r-dk)_ii (r-dk)_iiB | d_iii(C1(piiiB))] +
2940 ! +2[C0| (r-dk)_iii (r-dk)_iiB | d_ii(C1(piiiB))]
2941 ! and
2942 ! term2: +2[C0| (r-dk)_ii (r-dk)_iiiB | d_iii(C1(piiB))] +
2943 ! -2[C0| (r-dk)_iii (r-dk)_iiiB | d_ii(C1(piiB))]
2944 CALL cp_dbcsr_sm_fm_multiply(op_mom_ao(idir)%matrix, mo_coeff, &
2945 buf, ncol=nmo, alpha=1.e0_dp)
2946 DO jdir = 1, 3
2947 DO kdir = 1, 3
2948 IF (levi_civita(kdir, idir, jdir) == 0.0_dp) cycle
2949 IF (iib == jdir) THEN
2950 CALL cp_fm_trace(buf, psi1_p(ispin, iiib), contrib)
2951 chi(kdir) = chi(kdir) + levi_civita(kdir, idir, jdir)*contrib
2952 END IF
2953 END DO
2954 END DO
2955 !
2956 DO jdir = 1, 3
2957 DO kdir = 1, 3
2958 IF (levi_civita(kdir, idir, jdir) == 0.0_dp) cycle
2959 IF (iiib == jdir) THEN
2960 CALL cp_fm_trace(buf, psi1_p(ispin, iib), contrib)
2961 chi(kdir) = chi(kdir) - levi_civita(kdir, idir, jdir)*contrib
2962 END IF
2963 !
2964 END DO
2965 END DO
2966 !
2967 !
2968 !
2969 !
2970 END DO ! idir
2971 !
2972 DO idir = 1, 3
2973 current_env%chi_tensor(idir, ib, ispin) = current_env%chi_tensor(idir, ib, ispin) + &
2974 maxocc*chi(idir)
2975 IF (output_unit > 0) THEN
2976 !WRITE(output_unit,'(A,E12.6)') ' chi_'//ACHAR(119+idir)//ACHAR(119+iB)//&
2977 ! & ' = ',maxocc * chi(idir)
2978 END IF
2979 END DO
2980 !
2981 CALL cp_fm_release(buf)
2982 END DO ! ispin
2983 !
2984 ! deallocate the sparse matrices
2985 CALL dbcsr_deallocate_matrix_set(op_mom_ao)
2986 CALL dbcsr_deallocate_matrix_set(op_mom_der_ao)
2987 CALL dbcsr_deallocate_matrix_set(op_p_ao)
2988
2989 CALL timestop(handle)
2990
2991 END SUBROUTINE current_build_chi_one_center
2992
2993END MODULE qs_linres_current
static int imax(int x, int y)
Returns the larger of two given integers (missing from the C standard).
static int imin(int x, int y)
Returns the smaller of the two integers (missing from the C standard).
Definition dbm_miniapp.c:37
static GRID_HOST_DEVICE int ncoset(const int l)
Number of Cartesian orbitals up to given angular momentum quantum.
Definition grid_common.h:82
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
static void dgemm(const char transa, const char transb, const int m, const int n, const int k, const double alpha, const double *a, const int lda, const double *b, const int ldb, const double beta, double *c, const int ldc)
Convenient wrapper to hide Fortran nature of dgemm_, swapping a and b.
All kind of helpful little routines.
Definition ao_util.F:14
real(kind=dp) function, public exp_radius_very_extended(la_min, la_max, lb_min, lb_max, pab, o1, o2, ra, rb, rp, zetp, eps, prefactor, cutoff, epsabs)
computes the radius of the Gaussian outside of which it is smaller than eps
Definition ao_util.F:208
subroutine, public get_gto_basis_set(gto_basis_set, name, aliases, norm_type, kind_radius, ncgf, nset, nsgf, cgf_symbol, sgf_symbol, norm_cgf, set_radius, lmax, lmin, lx, ly, lz, m, ncgf_set, npgf, nsgf_set, nshell, cphi, pgf_radius, sphi, scon, zet, first_cgf, first_sgf, l, last_cgf, last_sgf, n, gcc, maxco, maxl, maxpgf, maxsgf_set, maxshell, maxso, nco_sum, npgf_sum, nshell_sum, maxder, short_kind_radius, npgf_seg_sum, ccon)
...
Handles all functions related to the CELL.
Definition cell_types.F:15
various utilities that regard array of different kinds: output, allocation,... maybe it is not a good...
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_deallocate_matrix(matrix)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_get_block_p(matrix, row, col, block, found, row_size, col_size)
...
subroutine, public dbcsr_finalize(matrix)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_put_block(matrix, row, col, block, summation)
...
DBCSR operations in CP2K.
subroutine, public cp_dbcsr_sm_fm_multiply(matrix, fm_in, fm_out, ncol, alpha, beta)
multiply a dbcsr with a fm matrix
subroutine, public cp_dbcsr_plus_fm_fm_t(sparse_matrix, matrix_v, matrix_g, ncol, alpha, keep_sparsity, symmetry_mode)
performs the multiplication sparse_matrix+dense_mat*dens_mat^T if matrix_g is not explicitly given,...
Basic linear algebra operations for full matrices.
subroutine, public cp_fm_scale_and_add(alpha, matrix_a, beta, matrix_b)
calc A <- alpha*A + beta*B optimized for alpha == 1.0 (just add beta*B) and beta == 0....
represent the structure of a full matrix
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
subroutine, public cp_fm_set_all(matrix, alpha, beta)
set all elements of a matrix to the same value, and optionally the diagonal to a different one
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
integer, parameter, public cp_p_file
integer function, public cp_print_key_should_output(iteration_info, basis_section, print_key_path, used_print_key, first_time)
returns what should be done with the given property if btest(res,cp_p_store) then the property should...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout, file_access)
...
A wrapper around pw_to_cube() which accepts particle_list_type.
subroutine, public cp_pw_to_cube(pw, unit_nr, title, particles, zeff, stride, max_file_size_mb, zero_tails, silent, mpi_io)
...
for a given dr()/dh(r) this will provide the bounds to be used if one wants to go over a sphere-subre...
Definition cube_utils.F:18
subroutine, public compute_cube_center(cube_center, rs_desc, zeta, zetb, ra, rab)
unifies the computation of the cube center, so that differences in implementation,...
Definition cube_utils.F:68
subroutine, public return_cube(info, radius, lb_cube, ub_cube, sphere_bounds)
...
Definition cube_utils.F:142
Fortran API for the grid package, which is written in C.
Definition grid_api.F:12
integer, parameter, public grid_func_adbmdab_z
Definition grid_api.F:31
integer, parameter, public grid_func_adbmdab_y
Definition grid_api.F:30
integer, parameter, public grid_func_ardbmdarb_yx
Definition grid_api.F:35
integer, parameter, public grid_func_ardbmdarb_zz
Definition grid_api.F:40
integer, parameter, public grid_func_ardbmdarb_xy
Definition grid_api.F:33
integer, parameter, public grid_func_ardbmdarb_zx
Definition grid_api.F:38
integer, parameter, public grid_func_ardbmdarb_xx
Definition grid_api.F:32
integer, parameter, public grid_func_ardbmdarb_yz
Definition grid_api.F:37
integer, parameter, public grid_func_ab
Definition grid_api.F:27
integer, parameter, public grid_func_ardbmdarb_yy
Definition grid_api.F:36
integer, parameter, public grid_func_adbmdab_x
Definition grid_api.F:29
subroutine, public collocate_pgf_product(la_max, zeta, la_min, lb_max, zetb, lb_min, ra, rab, scale, pab, o1, o2, rsgrid, ga_gb_function, radius, use_subpatch, subpatch_pattern)
low level collocation of primitive gaussian functions
Definition grid_api.F:116
integer, parameter, public grid_func_ardbmdarb_zy
Definition grid_api.F:39
integer, parameter, public grid_func_ardbmdarb_xz
Definition grid_api.F:34
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public current_gauge_atom
objects that represent the structure of input sections and the data contained in an input section
integer function, dimension(:), pointer, public section_get_ivals(section_vals, keyword_name)
...
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
logical function, public section_get_lval(section_vals, keyword_name)
...
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public int_8
Definition kinds.F:54
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_string_length
Definition kinds.F:57
integer, parameter, public default_path_length
Definition kinds.F:58
Definition of mathematical constants and functions.
real(kind=dp), parameter, public twopi
Utility routines for the memory handling.
Interface to the message passing library MPI.
Provides Cartesian and spherical orbital pointers and indices.
integer, dimension(:), allocatable, public ncoset
represent a simple array based list of the given type
Define methods related to particle_type.
subroutine, public get_particle_set(particle_set, qs_kind_set, first_sgf, last_sgf, nsgf, nmao, basis, ncgf)
Get the components of a particle set.
Define the data structure for the particle information.
container for various plainwaves related things
subroutine, public pw_env_get(pw_env, pw_pools, cube_info, gridlevel_info, auxbas_pw_pool, auxbas_grid, auxbas_rs_desc, auxbas_rs_grid, rs_descs, rs_grids, xc_pw_pool, vdw_pw_pool, poisson_env, interp_section)
returns the various attributes of the pw env
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, mimic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, 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, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, cneo_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, hund_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, proj_shell_charge, lr_atom, do_mtlr, u_j_loop, ao_coef, init_u_ramping_each_scf, reltmat, ghost, monovalent, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
subroutine, public get_qs_kind_set(qs_kind_set, all_potential_present, tnadd_potential_present, gth_potential_present, sgp_potential_present, paw_atom_present, dft_plus_u_atom_present, maxcgf, maxsgf, maxco, maxco_proj, maxgtops, maxlgto, maxlprj, maxnset, maxsgf_set, ncgf, npgf, nset, nsgf, nshell, maxpol, maxlppl, maxlppnl, maxppnl, nelectron, maxder, max_ngrid_rad, max_sph_harm, maxg_iso_not0, lmax_rho0, basis_rcut, do_mtlr_present, basis_type, total_zeff_corr, npgf_seg, cneo_potential_present, nkind_q, natom_q)
Get attributes of an atomic kind set.
given the response wavefunctions obtained by the application of the (rxp), p, and ((dk-dl)xp) operato...
subroutine, public calculate_jrho_atom(current_env, qs_env, ib, idir)
...
subroutine, public calculate_jrho_atom_coeff(qs_env, current_env, mat_d0, mat_jp, mat_jp_rii, mat_jp_riii, ib, idir)
Calculate the expansion coefficients for the atomic terms of the current densitiy in GAPW.
subroutine, public calculate_jrho_atom_rad(qs_env, current_env, idir)
...
given the response wavefunctions obtained by the application of the (rxp), p, and ((dk-dl)xp) operato...
subroutine, public current_build_current(current_env, qs_env, ib)
First calculate the density matrixes, for each component of the current they are 3 because of the r d...
real(dp), dimension(3, 3, 3), parameter levi_civita
subroutine, public calculate_jrho_resp(mat_d0, mat_jp, mat_jp_rii, mat_jp_riii, ib, idir, current_rs, current_gs, qs_env, current_env, soft_valid, retain_rsgrid)
Calculation of the idir component of the response current density in the presence of a constant magne...
subroutine, public current_build_chi(current_env, qs_env, ib)
...
Calculate the operators p rxp and D needed in the optimization of the different contribution of the f...
integer function, public ind_m2(ii, iii)
...
subroutine, public set_vecp(i1, i2, i3)
...
real(dp) function, public fac_vecp(a, b, c)
...
subroutine, public fm_scale_by_pbc_ac(matrix, ra, rc, cell, ixyz)
scale a matrix as a_ij = a_ij * pbc(rc(:,j),ra(:,i))(ixyz)
subroutine, public set_vecp_rev(i1, i2, i3)
...
Type definitiona for linear response calculations.
subroutine, public get_current_env(current_env, simple_done, simple_converged, full_done, nao, nstates, gauge, list_cubes, statetrueindex, gauge_name, basisfun_center, nbr_center, center_list, centers_set, psi1_p, psi1_rxp, psi1_d, p_psi0, rxp_psi0, jrho1_atom_set, jrho1_set, chi_tensor, chi_tensor_loc, gauge_atom_radius, rs_gauge, use_old_gauge_atom, chi_pbc, psi0_order)
...
wrapper for the pools of matrixes
Definition and initialisation of the mo data type.
Definition qs_mo_types.F:22
subroutine, public get_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, eigenvalues, occupation_numbers, mo_coeff, mo_coeff_b, uniform_occupation, kts, mu, flexible_electron_count, cmo_coeff)
Get the components of a MO set data structure.
Calculates the moment integrals <a|r^m|b> and <a|r x d/dr|b>.
Definition qs_moments.F:14
subroutine, public build_local_moments_der_matrix(qs_env, moments_der, nmoments_der, nmoments, ref_point, moments, basis_type, minimum_image, ordered, lambda, deltar, neighbor_image)
Calculate right-hand sided derivatives of multipole moments, e. g. < a | xy d/dz | b > Optionally sto...
Definition qs_moments.F:502
Define the neighbor list data types and the corresponding functionality.
subroutine, public neighbor_list_iterator_create(iterator_set, nl, search, nthread)
Neighbor list iterator functions.
subroutine, public neighbor_list_iterator_release(iterator_set)
...
integer function, public neighbor_list_iterate(iterator_set, mepos)
...
subroutine, public get_iterator_info(iterator_set, mepos, ikind, jkind, nkind, ilist, nlist, inode, nnode, iatom, jatom, r, cell)
...
subroutine, public build_lin_mom_matrix(qs_env, matrix, minimum_image)
Calculation of the linear momentum matrix <mu|∂|nu> over Cartesian Gaussian functions.
superstucture that hold various representations of the density and keeps track of which ones are vali...
subroutine, public qs_rho_get(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)
returns info about the density described by this object. If some representation is not available an e...
types that represent a quickstep subsys
subroutine, public qs_subsys_get(subsys, atomic_kinds, atomic_kind_set, particles, particle_set, local_particles, molecules, molecule_set, molecule_kinds, molecule_kind_set, local_molecules, para_env, colvar_p, shell_particles, core_particles, gci, multipoles, natom, nparticle, ncore, nshell, nkind, atprop, virial, results, cell, cell_ref, use_ref_cell, energy, force, qs_kind_set, cp_subsys, nelectron_total, nelectron_spin)
...
subroutine, public rs_grid_create(rs, desc)
...
subroutine, public rs_grid_mult_and_add(rs1, rs2, rs3, scalar)
rs1(i) = rs1(i) + rs2(i)*rs3(i)
subroutine, public rs_grid_release(rs_grid)
releases the given rs grid (see doc/ReferenceCounting.html)
subroutine, public rs_grid_zero(rs)
Initialize grid to zero.
Transfers densities from PW to RS grids and potentials from PW to RS.
subroutine, public density_rs2pw(pw_env, rs_rho, rho, rho_gspace)
given partial densities on the realspace multigrids, computes the full density on the plane wave grid...
generate the tasks lists used by collocate and integrate routines
subroutine, public rs_distribute_matrix(rs_descs, pmats, atom_pair_send, atom_pair_recv, nimages, scatter, hmats)
redistributes the matrix so that it can be used in realspace operations i.e. according to the task li...
subroutine, public distribute_tasks(rs_descs, ntasks, natoms, tasks, atom_pair_send, atom_pair_recv, symmetric, reorder_rs_grid_ranks, skip_load_balance_distributed, balance_replicated)
Assembles tasks to be performed on local grid.
subroutine, public task_list_inner_loop(tasks, ntasks, curr_tasks, rs_descs, dft_control, cube_info, gridlevel_info, cindex, iatom, jatom, rpgfa, rpgfb, zeta, zetb, kind_radius_b, set_radius_a, set_radius_b, ra, rab, la_max, la_min, lb_max, lb_min, npgfa, npgfb, nseta, nsetb)
...
types for task lists
subroutine, public reallocate_tasks(tasks, new_size)
Grow an array of tasks while preserving the existing entries.
Type defining parameters related to the simulation cell.
Definition cell_types.F:60
represent a pointer to a 2d array
represent a pointer to a 2d array
keeps the information about the structure of a full matrix
represent a full matrix
type of a logger, at the moment it contains just a print level starting at which level it should be l...
stores all the informations relevant to an mpi environment
contained for different pw related things
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Provides all information about a quickstep kind.
container for the pools of matrixes used by qs