22 USE dbcsr_api,
ONLY: dbcsr_add,&
24 dbcsr_distribution_type,&
45 neighbor_list_iterator_p_type,&
47 neighbor_list_set_p_type,&
55 #include "./base/base_uses.f90"
61 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'kg_tnadd_mat'
83 SUBROUTINE build_tnadd_mat(kg_env, matrix_p, force, virial, calculate_forces, use_virial, &
84 qs_kind_set, atomic_kind_set, particle_set, sab_orb, dbcsr_dist)
86 TYPE(kg_environment_type),
POINTER :: kg_env
87 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p
88 TYPE(qs_force_type),
DIMENSION(:),
POINTER :: force
89 TYPE(virial_type),
POINTER :: virial
90 LOGICAL,
INTENT(IN) :: calculate_forces
92 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
93 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
94 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
95 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
97 TYPE(dbcsr_distribution_type),
POINTER :: dbcsr_dist
99 CHARACTER(LEN=*),
PARAMETER :: routinen =
'build_tnadd_mat'
100 INTEGER,
PARAMETER :: nexp_max = 10
102 INTEGER :: atom_a, atom_b, atom_c, handle, i, iatom, icol, ikind, img, imol, inode, irow, &
103 iset, jatom, jkind, jmol, jset, katom, kkind, kmol, last_iatom, last_jatom, ldai, ldsab, &
104 maxco, maxder, maxl, maxlgto, maxnset, maxpol, maxsgf, mepos, natom, ncoa, ncob, nder, &
105 ngau, nkind, npol, nseta, nsetb, nthread, sgfa, sgfb
106 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: atom_of_kind
107 INTEGER,
DIMENSION(:),
POINTER :: atom_to_molecule, col_blk_sizes, la_max, &
108 la_min, lb_max, lb_min, npgfa, npgfb, &
109 nsgfa, nsgfb, row_blk_sizes
110 INTEGER,
DIMENSION(:, :),
POINTER :: first_sgfa, first_sgfb
111 INTEGER,
DIMENSION(nexp_max) :: nct
112 LOGICAL :: found, new_atom_pair
113 REAL(kind=
dp) :: dab, dac, dbc, f0, radius
114 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: work
115 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: ppl_fwork, ppl_work
116 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :, :) :: hab, pab
117 REAL(kind=
dp),
DIMENSION(3) :: force_a, force_b, rab, rac, rbc
118 REAL(kind=
dp),
DIMENSION(:),
POINTER :: alpha, set_radius_a, set_radius_b
119 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: ccval, cval, h_block, p_block, rpgfa, &
120 rpgfb, sphi_a, sphi_b, zeta, zetb
121 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_kg
122 TYPE(gto_basis_set_p_type),
DIMENSION(:),
POINTER :: basis_set_list
123 TYPE(gto_basis_set_type),
POINTER :: basis_set_a, basis_set_b
124 TYPE(local_potential_type),
POINTER :: tnadd_potential
125 TYPE(neighbor_list_iterator_p_type), &
126 DIMENSION(:),
POINTER :: ap_iterator, nl_iterator
127 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
130 IF (calculate_forces)
THEN
131 CALL timeset(routinen//
"_forces", handle)
133 CALL timeset(routinen, handle)
137 IF (
ASSOCIATED(kg_env%tnadd_mat))
THEN
140 sac_kin => kg_env%sac_kin
141 atom_to_molecule => kg_env%atom_to_molecule
143 nkind =
SIZE(atomic_kind_set)
144 natom =
SIZE(particle_set)
148 IF (calculate_forces)
THEN
150 IF (
SIZE(matrix_p, 1) == 2)
THEN
151 DO img = 1,
SIZE(matrix_p, 2)
152 CALL dbcsr_add(matrix_p(1, img)%matrix, matrix_p(2, img)%matrix, &
153 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
154 CALL dbcsr_add(matrix_p(2, img)%matrix, matrix_p(1, img)%matrix, &
155 alpha_scalar=-2.0_dp, beta_scalar=1.0_dp)
164 CALL get_qs_kind_set(qs_kind_set, maxpol=maxpol, maxco=maxco, maxlgto=maxlgto, &
165 maxsgf=maxsgf, maxnset=maxnset)
167 maxl = max(maxlgto, maxpol)
170 ldsab = max(maxco,
ncoset(maxpol), maxsgf, maxpol)
171 ldai =
ncoset(maxl + nder + 1)
173 ALLOCATE (basis_set_list(nkind))
175 CALL get_qs_kind(qs_kind_set(ikind), basis_set=basis_set_a)
176 IF (
ASSOCIATED(basis_set_a))
THEN
177 basis_set_list(ikind)%gto_basis_set => basis_set_a
179 NULLIFY (basis_set_list(ikind)%gto_basis_set)
184 ALLOCATE (row_blk_sizes(natom), col_blk_sizes(natom))
191 ALLOCATE (matrix_kg(1)%matrix)
192 CALL dbcsr_create(matrix=matrix_kg(1)%matrix, &
193 name=
"Nonadditive kinetic energy potential", &
194 dist=dbcsr_dist, matrix_type=dbcsr_type_symmetric, &
195 row_blk_size=row_blk_sizes, col_blk_size=col_blk_sizes, &
196 nze=0, reuse_arrays=.true.)
198 CALL dbcsr_set(matrix_kg(1)%matrix, 0.0_dp)
228 ALLOCATE (hab(ldsab, ldsab, maxnset, maxnset), work(ldsab, ldsab*maxder))
229 ldai =
ncoset(2*maxlgto + 2*nder)
230 ALLOCATE (ppl_work(ldai, ldai, max(maxder, 2*maxlgto + 2*nder + 1)))
231 IF (calculate_forces)
THEN
232 ALLOCATE (pab(maxco, maxco, maxnset, maxnset))
234 ALLOCATE (ppl_fwork(ldai, ldai, maxder))
241 CALL get_iterator_info(nl_iterator, mepos=mepos, ikind=ikind, jkind=jkind, inode=inode, &
242 iatom=iatom, jatom=jatom, r=rab)
244 basis_set_a => basis_set_list(ikind)%gto_basis_set
245 IF (.NOT.
ASSOCIATED(basis_set_a)) cycle
246 basis_set_b => basis_set_list(jkind)%gto_basis_set
247 IF (.NOT.
ASSOCIATED(basis_set_b)) cycle
249 atom_a = atom_of_kind(iatom)
250 atom_b = atom_of_kind(jatom)
251 imol = atom_to_molecule(iatom)
252 jmol = atom_to_molecule(jatom)
253 cpassert(imol == jmol)
256 first_sgfa => basis_set_a%first_sgf
257 la_max => basis_set_a%lmax
258 la_min => basis_set_a%lmin
259 npgfa => basis_set_a%npgf
260 nseta = basis_set_a%nset
261 nsgfa => basis_set_a%nsgf_set
262 rpgfa => basis_set_a%pgf_radius
263 set_radius_a => basis_set_a%set_radius
264 sphi_a => basis_set_a%sphi
265 zeta => basis_set_a%zet
267 first_sgfb => basis_set_b%first_sgf
268 lb_max => basis_set_b%lmax
269 lb_min => basis_set_b%lmin
270 npgfb => basis_set_b%npgf
271 nsetb = basis_set_b%nset
272 nsgfb => basis_set_b%nsgf_set
273 rpgfb => basis_set_b%pgf_radius
274 set_radius_b => basis_set_b%set_radius
275 sphi_b => basis_set_b%sphi
276 zetb => basis_set_b%zet
278 dab = sqrt(sum(rab*rab))
280 IF (iatom == last_iatom .AND. jatom == last_jatom)
THEN
281 new_atom_pair = .false.
283 new_atom_pair = .true.
289 IF (iatom == jatom)
THEN
296 IF (new_atom_pair)
THEN
297 IF (iatom <= jatom)
THEN
305 CALL dbcsr_get_block_p(matrix_kg(1)%matrix, irow, icol, h_block, found)
306 IF (
ASSOCIATED(h_block))
THEN
307 IF (calculate_forces)
THEN
308 cpassert(
SIZE(matrix_p, 2) == 1)
310 CALL dbcsr_get_block_p(matrix_p(1, 1)%matrix, irow, icol, p_block, found)
311 IF (
ASSOCIATED(p_block))
THEN
313 ncoa = npgfa(iset)*
ncoset(la_max(iset))
314 sgfa = first_sgfa(1, iset)
316 ncob = npgfb(jset)*
ncoset(lb_max(jset))
317 sgfb = first_sgfb(1, jset)
320 IF (iatom <= jatom)
THEN
321 CALL dgemm(
"N",
"N", ncoa, nsgfb(jset), nsgfa(iset), &
322 1.0_dp, sphi_a(1, sgfa),
SIZE(sphi_a, 1), &
323 p_block(sgfa, sgfb),
SIZE(p_block, 1), &
324 0.0_dp, work(1, 1),
SIZE(work, 1))
326 CALL dgemm(
"N",
"T", ncoa, nsgfb(jset), nsgfa(iset), &
327 1.0_dp, sphi_a(1, sgfa),
SIZE(sphi_a, 1), &
328 p_block(sgfb, sgfa),
SIZE(p_block, 1), &
329 0.0_dp, work(1, 1),
SIZE(work, 1))
332 CALL dgemm(
"N",
"T", ncoa, ncob, nsgfb(jset), &
333 1.0_dp, work(1, 1),
SIZE(work, 1), &
334 sphi_b(1, sgfb),
SIZE(sphi_b, 1), &
335 0.0_dp, pab(1, 1, iset, jset),
SIZE(pab, 1))
348 CALL get_qs_kind(qs_kind_set(kkind), tnadd_potential=tnadd_potential)
349 IF (.NOT.
ASSOCIATED(tnadd_potential)) cycle
350 CALL get_potential(potential=tnadd_potential, &
351 alpha=alpha, cval=cval, ngau=ngau, npol=npol, radius=radius)
353 ALLOCATE (ccval(npol, ngau))
354 ccval(1:npol, 1:ngau) = transpose(cval(1:ngau, 1:npol))
363 kmol = atom_to_molecule(katom)
364 IF (kmol == imol) cycle
366 dac = sqrt(sum(rac*rac))
367 rbc(:) = rac(:) - rab(:)
368 dbc = sqrt(sum(rbc*rbc))
369 IF ((maxval(set_radius_a(:)) + radius < dac) .OR. &
370 (maxval(set_radius_b(:)) + radius < dbc))
THEN
375 IF (set_radius_a(iset) + radius < dac) cycle
376 ncoa = npgfa(iset)*
ncoset(la_max(iset))
377 sgfa = first_sgfa(1, iset)
379 IF (set_radius_b(jset) + radius < dbc) cycle
380 ncob = npgfb(jset)*
ncoset(lb_max(jset))
381 sgfb = first_sgfb(1, jset)
382 IF (set_radius_a(iset) + set_radius_b(jset) < dab) cycle
384 IF (calculate_forces)
THEN
387 la_max(iset), la_min(iset), npgfa(iset), &
388 rpgfa(:, iset), zeta(:, iset), &
389 lb_max(jset), lb_min(jset), npgfb(jset), &
390 rpgfb(:, jset), zetb(:, jset), &
391 ngau, alpha, nct, ccval, radius, &
392 rab, dab, rac, dac, rbc, dbc, &
393 hab(:, :, iset, jset), ppl_work, pab(:, :, iset, jset), &
394 force_a, force_b, ppl_fwork)
398 atom_c = atom_of_kind(katom)
401 force(ikind)%kinetic(1, atom_a) = force(ikind)%kinetic(1, atom_a) + f0*force_a(1)
402 force(ikind)%kinetic(2, atom_a) = force(ikind)%kinetic(2, atom_a) + f0*force_a(2)
403 force(ikind)%kinetic(3, atom_a) = force(ikind)%kinetic(3, atom_a) + f0*force_a(3)
404 force(kkind)%kinetic(1, atom_c) = force(kkind)%kinetic(1, atom_c) - f0*force_a(1)
405 force(kkind)%kinetic(2, atom_c) = force(kkind)%kinetic(2, atom_c) - f0*force_a(2)
406 force(kkind)%kinetic(3, atom_c) = force(kkind)%kinetic(3, atom_c) - f0*force_a(3)
408 force(jkind)%kinetic(1, atom_b) = force(jkind)%kinetic(1, atom_b) + f0*force_b(1)
409 force(jkind)%kinetic(2, atom_b) = force(jkind)%kinetic(2, atom_b) + f0*force_b(2)
410 force(jkind)%kinetic(3, atom_b) = force(jkind)%kinetic(3, atom_b) + f0*force_b(3)
411 force(kkind)%kinetic(1, atom_c) = force(kkind)%kinetic(1, atom_c) - f0*force_b(1)
412 force(kkind)%kinetic(2, atom_c) = force(kkind)%kinetic(2, atom_c) - f0*force_b(2)
413 force(kkind)%kinetic(3, atom_c) = force(kkind)%kinetic(3, atom_c) - f0*force_b(3)
423 la_max(iset), la_min(iset), npgfa(iset), &
424 rpgfa(:, iset), zeta(:, iset), &
425 lb_max(jset), lb_min(jset), npgfb(jset), &
426 rpgfb(:, jset), zetb(:, jset), &
427 ngau, alpha, nct, ccval, radius, &
428 rab, dab, rac, dac, rbc, dbc, hab(:, :, iset, jset), ppl_work)
438 ncoa = npgfa(iset)*
ncoset(la_max(iset))
439 sgfa = first_sgfa(1, iset)
441 ncob = npgfb(jset)*
ncoset(lb_max(jset))
442 sgfb = first_sgfb(1, jset)
444 CALL dgemm(
"N",
"N", ncoa, nsgfb(jset), ncob, &
445 1.0_dp, hab(1, 1, iset, jset),
SIZE(hab, 1), &
446 sphi_b(1, sgfb),
SIZE(sphi_b, 1), &
447 0.0_dp, work(1, 1),
SIZE(work, 1))
450 IF (iatom <= jatom)
THEN
451 CALL dgemm(
"T",
"N", nsgfa(iset), nsgfb(jset), ncoa, &
452 1.0_dp, sphi_a(1, sgfa),
SIZE(sphi_a, 1), &
453 work(1, 1),
SIZE(work, 1), &
454 1.0_dp, h_block(sgfa, sgfb),
SIZE(h_block, 1))
456 CALL dgemm(
"T",
"N", nsgfb(jset), nsgfa(iset), ncoa, &
457 1.0_dp, work(1, 1),
SIZE(work, 1), &
458 sphi_a(1, sgfa),
SIZE(sphi_a, 1), &
459 1.0_dp, h_block(sgfb, sgfa),
SIZE(h_block, 1))
467 DEALLOCATE (hab, work, ppl_work)
469 IF (calculate_forces)
THEN
470 DEALLOCATE (pab, ppl_fwork)
478 DO i = 1,
SIZE(matrix_kg)
479 CALL dbcsr_finalize(matrix_kg(i)%matrix)
481 kg_env%tnadd_mat => matrix_kg
483 DEALLOCATE (basis_set_list)
485 IF (calculate_forces)
THEN
488 IF (
SIZE(matrix_p, 1) == 2)
THEN
489 DO img = 1,
SIZE(matrix_p, 2)
490 CALL dbcsr_add(matrix_p(1, img)%matrix, matrix_p(2, img)%matrix, &
491 alpha_scalar=0.5_dp, beta_scalar=0.5_dp)
492 CALL dbcsr_add(matrix_p(2, img)%matrix, matrix_p(1, img)%matrix, &
493 alpha_scalar=-1.0_dp, beta_scalar=1.0_dp)
498 CALL timestop(handle)
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.
Calculation of three-center overlap integrals over Cartesian Gaussian-type functions for the second t...
subroutine, public ppl_integral(la_max_set, la_min_set, npgfa, rpgfa, zeta, lb_max_set, lb_min_set, npgfb, rpgfb, zetb, nexp_ppl, alpha_ppl, nct_ppl, cexp_ppl, rpgfc, rab, dab, rac, dac, rbc, dbc, vab, s, pab, force_a, force_b, fs, hab2, hab2_work, deltaR, iatom, jatom, katom)
Calculation of three-center overlap integrals <a|c|b> over Cartesian Gaussian functions for the local...
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind_set(atomic_kind_set, atom_of_kind, kind_of, natom_of_kind, maxatom, natom, nshell, fist_potential_present, shell_present, shell_adiabatic, shell_check_distance, damping_present)
Get attributes of an atomic kind set.
Routines that link DBCSR and CP2K concepts together.
subroutine, public cp_dbcsr_alloc_block_from_nbl(matrix, sab_orb, desymmetrize)
allocate the blocks of a dbcsr based on the neighbor list
DBCSR operations in CP2K.
Definition of the atomic potential types.
Types needed for a Kim-Gordon-like partitioning into molecular subunits.
Calculation of the local potential contribution of the nonadditive kinetic energy <a|V(local)|b> = <a...
subroutine, public build_tnadd_mat(kg_env, matrix_p, force, virial, calculate_forces, use_virial, qs_kind_set, atomic_kind_set, particle_set, sab_orb, dbcsr_dist)
...
Defines the basic variable types.
integer, parameter, public dp
Provides Cartesian and spherical orbital pointers and indices.
subroutine, public init_orbital_pointers(maxl)
Initialize or update the orbital pointers.
integer, dimension(:), allocatable, public ncoset
Define methods related to particle_type.
subroutine, public get_particle_set(particle_set, qs_kind_set, first_sgf, last_sgf, nsgf, nmao, basis)
Get the components of a particle set.
Define the data structure for the particle information.
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, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, 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_r3d_rs_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, 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, init_u_ramping_each_scf, reltmat, ghost, floating, name, element_symbol, pao_basis_size, 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, basis_type, total_zeff_corr)
Get attributes of an atomic kind set.
Define the neighbor list data types and the corresponding functionality.
integer function, public nl_sub_iterate(iterator_set, mepos)
...
subroutine, public neighbor_list_iterator_create(iterator_set, nl, search, nthread)
Neighbor list iterator functions.
subroutine, public nl_set_sub_iterator(iterator_set, ikind, jkind, iatom, mepos)
...
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)
...
pure subroutine, public virial_pair_force(pv_virial, f0, force, rab)
Computes the contribution to the stress tensor from two-body pair-wise forces.