35 USE dbcsr_api,
ONLY: &
36 dbcsr_copy, dbcsr_create, dbcsr_init_p, dbcsr_multiply, dbcsr_p_type, dbcsr_release, &
37 dbcsr_set, dbcsr_trace, dbcsr_type, dbcsr_type_no_symmetry
62 #include "./base/base_uses.f90"
68 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'rpa_axk'
95 para_env_sub, para_env_RPA, &
96 eig, fm_mat_S, homo, virtual, omega, &
97 mp2_env, mat_munu, unit_nr, e_axk_corr)
98 TYPE(qs_environment_type),
POINTER :: qs_env
99 TYPE(cp_fm_type),
INTENT(IN) :: fm_mat_q, fm_mat_q_gemm
100 INTEGER,
INTENT(IN) :: dimen_ri, dimen_ia
101 TYPE(mp_para_env_type),
POINTER :: para_env_sub, para_env_rpa
102 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: eig
103 TYPE(cp_fm_type),
INTENT(IN) :: fm_mat_s
104 INTEGER,
INTENT(IN) :: homo, virtual
105 REAL(kind=
dp),
INTENT(IN) :: omega
106 TYPE(mp2_type) :: mp2_env
107 TYPE(dbcsr_p_type),
INTENT(IN) :: mat_munu
108 INTEGER,
INTENT(IN) :: unit_nr
109 REAL(kind=
dp),
INTENT(INOUT) :: e_axk_corr
111 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_axk_ener'
112 REAL(kind=
dp),
PARAMETER :: thresh = 0.0000001_dp
114 INTEGER :: color_sub, handle, iib, iitmp(2), kkb, l_counter, my_group_l_end, &
115 my_group_l_size, my_group_l_start, ncol_local, ngroup
116 INTEGER,
DIMENSION(:),
POINTER :: col_indices
117 REAL(kind=
dp) :: eps_filter, trace_corr
118 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: eigenval
119 TYPE(cp_fm_struct_type),
POINTER :: fm_struct
120 TYPE(cp_fm_type) :: fm_mat_gamma_3, fm_mat_q_tmp, &
121 fm_mat_r_half, fm_mat_r_half_gemm, &
123 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: dbcsr_gamma_3, dbcsr_gamma_inu_p, &
125 TYPE(dbcsr_type),
POINTER :: mo_coeff_o, mo_coeff_v
127 CALL timeset(routinen, handle)
130 ALLOCATE (eigenval(dimen_ri))
138 matrix_struct=fm_struct)
140 CALL cp_fm_create(fm_mat_r_half, fm_struct, name=
"fm_mat_R_half")
141 CALL cp_fm_create(fm_mat_q_tmp, fm_struct, name=
"fm_mat_Q_tmp")
147 CALL cp_fm_to_fm(fm_mat_q, fm_mat_q_tmp)
157 CALL cp_fm_to_fm(fm_mat_u, fm_mat_q_tmp)
161 IF (abs(eigenval(iib)) .GE. thresh)
THEN
163 sqrt((1.0_dp/(eigenval(iib)**2))*log(1.0_dp + eigenval(iib)) &
164 - 1.0_dp/(eigenval(iib)*(eigenval(iib) + 1.0_dp)))
166 eigenval(iib) = 0.707_dp
173 DEALLOCATE (eigenval)
176 CALL parallel_gemm(transa=
"N", transb=
"T", m=dimen_ri, n=dimen_ri, k=dimen_ri, alpha=1.0_dp, &
177 matrix_a=fm_mat_u, matrix_b=fm_mat_q_tmp, beta=0.0_dp, &
178 matrix_c=fm_mat_r_half)
182 CALL cp_fm_struct_create(fm_struct, template_fmstruct=fm_mat_s%matrix_struct, nrow_global=dimen_ia, ncol_global=dimen_ri)
187 ncol_local=ncol_local, &
188 col_indices=col_indices)
199 CALL cp_fm_create(fm_mat_r_half_gemm, fm_mat_q_gemm%matrix_struct)
203 fm_mat_r_half%matrix_struct%context)
206 CALL parallel_gemm(transa=
"T", transb=
"N", m=dimen_ia, n=dimen_ri, k=dimen_ri, alpha=1.0_dp, &
207 matrix_a=fm_mat_s, matrix_b=fm_mat_r_half_gemm, beta=0.0_dp, &
208 matrix_c=fm_mat_gamma_3)
214 CALL cp_fm_release(fm_mat_q_tmp)
215 CALL cp_fm_release(fm_mat_u)
216 CALL cp_fm_release(fm_mat_r_half)
217 CALL cp_fm_release(fm_mat_r_half_gemm)
220 NULLIFY (mo_coeff_o, mo_coeff_v)
221 mo_coeff_o => mp2_env%ri_rpa%mo_coeff_o
222 mo_coeff_v => mp2_env%ri_rpa%mo_coeff_v
225 ngroup = para_env_rpa%num_pe/para_env_sub%num_pe
227 color_sub = para_env_rpa%mepos/para_env_sub%num_pe
229 iitmp =
get_limit(dimen_ri, ngroup, color_sub)
230 my_group_l_start = iitmp(1)
231 my_group_l_end = iitmp(2)
232 my_group_l_size = iitmp(2) - iitmp(1) + 1
235 CALL gamma_fm_to_dbcsr(fm_mat_gamma_3, dbcsr_gamma_3, para_env_rpa, para_env_sub, &
236 homo, virtual, mo_coeff_o, ngroup, my_group_l_start, &
237 my_group_l_end, my_group_l_size)
241 NULLIFY (dbcsr_gamma_inu_p)
244 NULLIFY (dbcsr_gamma_munu_p)
247 eps_filter = mp2_env%mp2_gpw%eps_filter
250 DO kkb = my_group_l_start, my_group_l_end
251 l_counter = l_counter + 1
253 ALLOCATE (dbcsr_gamma_inu_p(l_counter)%matrix)
254 CALL dbcsr_init_p(dbcsr_gamma_inu_p(l_counter)%matrix)
255 CALL dbcsr_create(dbcsr_gamma_inu_p(l_counter)%matrix, template=mo_coeff_o)
256 CALL dbcsr_copy(dbcsr_gamma_inu_p(l_counter)%matrix, mo_coeff_o)
257 CALL dbcsr_set(dbcsr_gamma_inu_p(l_counter)%matrix, 0.0_dp)
259 ALLOCATE (dbcsr_gamma_munu_p(l_counter)%matrix)
260 CALL dbcsr_init_p(dbcsr_gamma_munu_p(l_counter)%matrix)
261 CALL dbcsr_create(dbcsr_gamma_munu_p(l_counter)%matrix, template=mat_munu%matrix, &
262 matrix_type=dbcsr_type_no_symmetry)
263 CALL dbcsr_copy(dbcsr_gamma_munu_p(l_counter)%matrix, mat_munu%matrix)
264 CALL dbcsr_set(dbcsr_gamma_munu_p(l_counter)%matrix, 0.0_dp)
269 DO kkb = my_group_l_start, my_group_l_end
270 l_counter = l_counter + 1
272 CALL dbcsr_multiply(
"N",
"T", 1.0_dp, mo_coeff_v, dbcsr_gamma_3(l_counter)%matrix, &
273 0.0_dp, dbcsr_gamma_inu_p(l_counter)%matrix, filter_eps=eps_filter)
276 CALL dbcsr_multiply(
"N",
"T", 1.0_dp, dbcsr_gamma_inu_p(l_counter)%matrix, mo_coeff_o, &
277 0.0_dp, dbcsr_gamma_munu_p(l_counter)%matrix, filter_eps=eps_filter)
279 CALL dbcsr_trace(dbcsr_gamma_munu_p(l_counter)%matrix, trace_corr)
284 DO kkb = my_group_l_start, my_group_l_end
285 l_counter = l_counter + 1
286 CALL dbcsr_release(dbcsr_gamma_3(l_counter)%matrix)
287 DEALLOCATE (dbcsr_gamma_3(l_counter)%matrix)
289 DEALLOCATE (dbcsr_gamma_3)
293 CALL integrate_exchange(qs_env, dbcsr_gamma_munu_p, mat_munu, para_env_sub, my_group_l_size, eps_filter, e_axk_corr, &
294 my_group_l_start, my_group_l_end)
299 IF (unit_nr > 0)
WRITE (unit_nr,
'(T3,A,T68,F25.14,A4)')
'AXK correlation energy for a quadrature point:', &
303 DO kkb = my_group_l_start, my_group_l_end
304 l_counter = l_counter + 1
305 CALL dbcsr_release(dbcsr_gamma_inu_p(l_counter)%matrix)
306 CALL dbcsr_release(dbcsr_gamma_munu_p(l_counter)%matrix)
307 DEALLOCATE (dbcsr_gamma_inu_p(l_counter)%matrix)
308 DEALLOCATE (dbcsr_gamma_munu_p(l_counter)%matrix)
310 DEALLOCATE (dbcsr_gamma_inu_p)
311 DEALLOCATE (dbcsr_gamma_munu_p)
313 CALL timestop(handle)
330 SUBROUTINE integrate_exchange(qs_env, dbcsr_Gamma_munu_P, mat_munu, para_env_sub, P_stack_size, &
331 eps_filter, axk_corr, &
332 my_group_L_start, my_group_L_end)
333 TYPE(qs_environment_type),
POINTER :: qs_env
334 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: dbcsr_gamma_munu_p
335 TYPE(dbcsr_p_type),
INTENT(IN) :: mat_munu
336 TYPE(mp_para_env_type),
POINTER :: para_env_sub
337 INTEGER,
INTENT(INOUT) :: p_stack_size
338 REAL(kind=
dp),
INTENT(IN) :: eps_filter
339 REAL(kind=
dp),
INTENT(OUT) :: axk_corr
340 INTEGER,
INTENT(IN) :: my_group_l_start, my_group_l_end
342 CHARACTER(LEN=*),
PARAMETER :: routinen =
'integrate_exchange'
344 INTEGER :: aux, handle, irep, kkb, n_rep_hf, ns
345 LOGICAL :: my_recalc_hfx_integrals
346 REAL(kind=
dp) :: e_axk_p, ehfx
347 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: rho_work_ao
348 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_2d, rho_ao_2d
349 TYPE(hfx_type),
DIMENSION(:, :),
POINTER :: x_data
350 TYPE(qs_energy_type),
POINTER :: energy
351 TYPE(section_vals_type),
POINTER :: hfx_sections
353 CALL timeset(routinen, handle)
361 CALL hfx_create_subgroup(qs_env, para_env_sub, hfx_sections, x_data, n_rep_hf)
364 NULLIFY (rho_work_ao)
366 ALLOCATE (rho_work_ao(1)%matrix)
367 CALL dbcsr_init_p(rho_work_ao(1)%matrix)
368 CALL dbcsr_create(rho_work_ao(1)%matrix, template=mat_munu%matrix)
371 my_recalc_hfx_integrals = .true.
375 ALLOCATE (mat_2d(1, 1)%matrix)
376 CALL dbcsr_init_p(mat_2d(1, 1)%matrix)
377 CALL dbcsr_create(mat_2d(1, 1)%matrix, template=mat_munu%matrix, &
378 matrix_type=dbcsr_type_no_symmetry)
379 CALL dbcsr_copy(mat_2d(1, 1)%matrix, mat_munu%matrix)
384 p_stack_size = p_stack_size
386 DO kkb = my_group_l_start, my_group_l_end
389 CALL dbcsr_copy(rho_work_ao(1)%matrix, dbcsr_gamma_munu_p(aux)%matrix)
391 DO irep = 1, n_rep_hf
392 ns =
SIZE(rho_work_ao)
393 rho_ao_2d(1:ns, 1:1) => rho_work_ao(1:ns)
395 CALL dbcsr_set(mat_2d(1, 1)%matrix, 0.0_dp)
397 IF (x_data(irep, 1)%do_hfx_ri)
THEN
399 rho_ao=rho_ao_2d, geometry_did_change=my_recalc_hfx_integrals, &
400 nspins=ns, hf_fraction=x_data(irep, 1)%general_parameter%fraction)
404 para_env_sub, my_recalc_hfx_integrals, irep, .true., &
409 my_recalc_hfx_integrals = .false.
411 CALL dbcsr_multiply(
"T",
"N", 1.0_dp, mat_2d(1, 1)%matrix, rho_work_ao(1)%matrix, &
412 0.0_dp, dbcsr_gamma_munu_p(aux)%matrix, filter_eps=eps_filter)
413 CALL dbcsr_trace(dbcsr_gamma_munu_p(aux)%matrix, e_axk_p)
414 axk_corr = axk_corr + e_axk_p
417 CALL dbcsr_release(mat_2d(1, 1)%matrix)
419 CALL dbcsr_release(mat_2d(1, 1)%matrix)
420 DEALLOCATE (mat_2d(1, 1)%matrix)
422 CALL dbcsr_release(rho_work_ao(1)%matrix)
423 DEALLOCATE (rho_work_ao(1)%matrix)
424 DEALLOCATE (rho_work_ao)
427 CALL timestop(handle)
429 END SUBROUTINE integrate_exchange
440 SUBROUTINE hfx_create_subgroup(qs_env, para_env_sub, hfx_section, x_data, n_rep_hf)
441 TYPE(qs_environment_type),
POINTER :: qs_env
442 TYPE(mp_para_env_type),
POINTER :: para_env_sub
443 TYPE(section_vals_type),
POINTER :: hfx_section
444 TYPE(hfx_type),
DIMENSION(:, :),
POINTER :: x_data
445 INTEGER,
INTENT(OUT) :: n_rep_hf
447 CHARACTER(LEN=*),
PARAMETER :: routinen =
'hfx_create_subgroup'
449 INTEGER :: handle, nelectron_total
451 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
452 TYPE(cell_type),
POINTER :: my_cell
453 TYPE(dft_control_type),
POINTER :: dft_control
454 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
455 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
456 TYPE(qs_subsys_type),
POINTER :: subsys
457 TYPE(scf_control_type),
POINTER :: scf_control
458 TYPE(section_vals_type),
POINTER :: input
460 CALL timeset(routinen, handle)
462 NULLIFY (my_cell, atomic_kind_set, particle_set, dft_control, x_data, qs_kind_set, scf_control)
467 scf_control=scf_control, &
468 nelectron_total=nelectron_total)
472 atomic_kind_set=atomic_kind_set, &
473 qs_kind_set=qs_kind_set, &
474 particle_set=particle_set)
480 CALL get_qs_env(qs_env, dft_control=dft_control)
484 CALL hfx_create(x_data, para_env_sub, hfx_section, atomic_kind_set, &
485 qs_kind_set, particle_set, dft_control, my_cell, orb_basis=
'ORB', &
486 nelectron_total=nelectron_total)
489 CALL timestop(handle)
491 END SUBROUTINE hfx_create_subgroup
Define the atomic kind types and their sub types.
Handles all functions related to the CELL.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
DBCSR operations in CP2K.
basic linear algebra operations for full matrices
subroutine, public cp_fm_column_scale(matrixa, scaling)
scales column i of matrix a with scaling(i)
subroutine, public cp_fm_scale(alpha, matrix_a)
scales a matrix matrix_a = alpha * matrix_b
used for collecting some of the diagonalization schemes available for cp_fm_type. cp_fm_power also mo...
subroutine, public choose_eigv_solver(matrix, eigenvectors, eigenvalues, info)
Choose the Eigensolver depending on which library is available ELPA seems to be unstable for small sy...
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
subroutine, public cp_fm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, nrow_locals, ncol_locals, matrix_struct, para_env)
returns all kind of information about the full matrix
subroutine, public cp_fm_to_fm_submat_general(source, destination, nrows, ncols, s_firstrow, s_firstcol, d_firstrow, d_firstcol, global_context)
General copy of a submatrix of fm matrix to a submatrix of another fm matrix. The two matrices can ha...
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, use_sp)
creates a new full matrix with the given structure
Routines to calculate HFX energy and potential.
subroutine, public integrate_four_center(qs_env, x_data, ks_matrix, ehfx, rho_ao, hfx_section, para_env, geometry_did_change, irep, distribute_fock_matrix, ispin)
computes four center integrals for a full basis set and updates the Kohn-Sham-Matrix and energy....
subroutine, public hfx_ri_update_ks(qs_env, ri_data, ks_matrix, ehfx, mos, rho_ao, geometry_did_change, nspins, hf_fraction)
...
Types and set/get functions for HFX.
subroutine, public hfx_create(x_data, para_env, hfx_section, atomic_kind_set, qs_kind_set, particle_set, dft_control, cell, orb_basis, ri_basis, nelectron_total, nkp_grid)
This routine allocates and initializes all types in hfx_data
subroutine, public hfx_release(x_data)
This routine deallocates all data structures
Defines the basic variable types.
integer, parameter, public dp
Interface to the message passing library MPI.
Types needed for MP2 calculations.
basic linear algebra operations for full matrixes
Define the data structure for the particle information.
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_RI_aux_kp, matrix_s, matrix_s_RI_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, WannierCentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, rhs)
Get the QUICKSTEP environment.
Define the quickstep kind type and their sub types.
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)
...
Auxiliary routines needed for RPA-AXK given blacs_env to another.
subroutine, public compute_axk_ener(qs_env, fm_mat_Q, fm_mat_Q_gemm, dimen_RI, dimen_ia, para_env_sub, para_env_RPA, eig, fm_mat_S, homo, virtual, omega, mp2_env, mat_munu, unit_nr, e_axk_corr)
Main driver for RPA-AXK energies.
Auxiliary routines necessary to redistribute an fm_matrix from a given blacs_env to another.
subroutine, public gamma_fm_to_dbcsr(fm_mat_Gamma_3, dbcsr_Gamma_3, para_env_RPA, para_env_sub, homo, virtual, mo_coeff_o, ngroup, my_group_L_start, my_group_L_end, my_group_L_size)
Redistribute RPA-AXK Gamma_3 density matrices: from fm to dbcsr.
Utility functions for RPA calculations.
subroutine, public calc_fm_mat_s_rpa(fm_mat_S, first_cycle, virtual, Eigenval, homo, omega, omega_old)
...
subroutine, public remove_scaling_factor_rpa(fm_mat_S, virtual, Eigenval_last, homo, omega_old)
...
parameters that control an scf iteration
All kind of helpful little routines.
pure integer function, dimension(2), public get_limit(m, n, me)
divide m entries into n parts, return size of part me