40#include "./base/base_uses.f90"
47 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'admm_dm_methods'
59 CHARACTER(len=*),
PARAMETER :: routinen =
'admm_dm_calc_rho_aux'
65 CALL timeset(routinen, handle)
68 SELECT CASE (admm_dm%method)
70 CALL map_dm_projection(qs_env)
73 CALL map_dm_blocked(qs_env)
76 cpabort(
"admm_dm_calc_rho_aux: unknown method")
79 IF (admm_dm%purify)
THEN
83 CALL update_rho_aux(qs_env)
96 CHARACTER(LEN=*),
PARAMETER :: routinen =
'admm_dm_merge_ks_matrix'
100 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks_merge
102 CALL timeset(routinen, handle)
103 NULLIFY (admm_dm, matrix_ks_merge)
107 IF (admm_dm%purify)
THEN
108 CALL revert_purify_mcweeny(qs_env, matrix_ks_merge)
110 CALL get_admm_env(qs_env%admm_env, matrix_ks_aux_fit=matrix_ks_merge)
113 SELECT CASE (admm_dm%method)
115 CALL merge_dm_projection(qs_env, matrix_ks_merge)
118 CALL merge_dm_blocked(qs_env, matrix_ks_merge)
121 cpabort(
"admm_dm_merge_ks_matrix: unknown method")
124 IF (admm_dm%purify)
THEN
128 CALL timestop(handle)
137 SUBROUTINE map_dm_projection(qs_env)
141 LOGICAL :: s_mstruct_changed
142 REAL(kind=
dp) :: threshold
144 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s_aux, matrix_s_mixed, rho_ao, &
146 TYPE(
dbcsr_type) :: matrix_s_aux_inv, matrix_tmp
150 NULLIFY (dft_control, admm_dm, matrix_s_aux, matrix_s_mixed, rho, rho_aux)
151 NULLIFY (rho_ao, rho_ao_aux)
153 CALL get_qs_env(qs_env, dft_control=dft_control, s_mstruct_changed=s_mstruct_changed, rho=rho)
154 CALL get_admm_env(qs_env%admm_env, matrix_s_aux_fit=matrix_s_aux, rho_aux_fit=rho_aux, &
155 matrix_s_aux_fit_vs_orb=matrix_s_mixed, admm_dm=admm_dm)
160 IF (s_mstruct_changed)
THEN
162 CALL dbcsr_create(matrix_s_aux_inv, template=matrix_s_aux(1)%matrix, matrix_type=
"N")
163 threshold = max(admm_dm%eps_filter, 1.0e-12_dp)
166 IF (.NOT.
ASSOCIATED(admm_dm%matrix_A))
THEN
167 ALLOCATE (admm_dm%matrix_A)
168 CALL dbcsr_create(admm_dm%matrix_A, template=matrix_s_mixed(1)%matrix, matrix_type=
"N")
170 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, matrix_s_aux_inv, matrix_s_mixed(1)%matrix, &
171 0.0_dp, admm_dm%matrix_A)
176 CALL dbcsr_create(matrix_tmp, template=admm_dm%matrix_A)
177 DO ispin = 1, dft_control%nspins
178 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, admm_dm%matrix_A, rho_ao(ispin)%matrix, &
180 CALL dbcsr_multiply(
"N",
"T", 1.0_dp, matrix_tmp, admm_dm%matrix_A, &
181 0.0_dp, rho_ao_aux(ispin)%matrix)
185 END SUBROUTINE map_dm_projection
192 SUBROUTINE map_dm_blocked(qs_env)
195 INTEGER :: iatom, ispin, jatom
197 REAL(
dp),
DIMENSION(:, :),
POINTER :: sparse_block, sparse_block_aux
200 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: rho_ao, rho_ao_aux
204 NULLIFY (dft_control, admm_dm, rho, rho_aux, rho_ao, rho_ao_aux)
206 CALL get_qs_env(qs_env, dft_control=dft_control, rho=rho)
207 CALL get_admm_env(qs_env%admm_env, rho_aux_fit=rho_aux, admm_dm=admm_dm)
213 DO ispin = 1, dft_control%nspins
214 CALL dbcsr_set(rho_ao_aux(ispin)%matrix, 0.0_dp)
219 IF (admm_dm%block_map(iatom, jatom) == 1)
THEN
221 row=iatom, col=jatom, block=sparse_block_aux, found=found)
223 sparse_block_aux = sparse_block
230 END SUBROUTINE map_dm_blocked
236 SUBROUTINE update_rho_aux(qs_env)
240 REAL(kind=
dp),
DIMENSION(:),
POINTER :: tot_rho_r_aux
250 NULLIFY (dft_control, admm_dm, rho_aux, rho_ao_aux, rho_r_aux, rho_g_aux, tot_rho_r_aux, &
251 task_list_aux_fit, ks_env)
253 CALL get_qs_env(qs_env, ks_env=ks_env, dft_control=dft_control)
254 CALL get_admm_env(qs_env%admm_env, task_list_aux_fit=task_list_aux_fit, rho_aux_fit=rho_aux, &
261 tot_rho_r=tot_rho_r_aux)
263 DO ispin = 1, dft_control%nspins
265 matrix_p=rho_ao_aux(ispin)%matrix, &
266 rho=rho_r_aux(ispin), &
267 rho_gspace=rho_g_aux(ispin), &
268 total_rho=tot_rho_r_aux(ispin), &
269 soft_valid=.false., &
270 basis_type=
"AUX_FIT", &
271 task_list_external=task_list_aux_fit)
274 CALL qs_rho_set(rho_aux, rho_r_valid=.true., rho_g_valid=.true.)
276 END SUBROUTINE update_rho_aux
284 SUBROUTINE merge_dm_projection(qs_env, matrix_ks_merge)
286 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks_merge
294 NULLIFY (admm_dm, dft_control, matrix_ks)
296 CALL get_qs_env(qs_env, dft_control=dft_control, matrix_ks=matrix_ks)
300 CALL dbcsr_create(matrix_tmp, template=admm_dm%matrix_A, matrix_type=
"N")
302 DO ispin = 1, dft_control%nspins
303 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, matrix_ks_merge(ispin)%matrix, admm_dm%matrix_A, &
305 CALL dbcsr_multiply(
"T",
"N", 1.0_dp, admm_dm%matrix_A, matrix_tmp, &
306 1.0_dp, matrix_ks(ispin)%matrix)
311 END SUBROUTINE merge_dm_projection
319 SUBROUTINE merge_dm_blocked(qs_env, matrix_ks_merge)
321 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks_merge
323 INTEGER :: iatom, ispin, jatom
324 REAL(
dp),
DIMENSION(:, :),
POINTER :: sparse_block
330 NULLIFY (admm_dm, dft_control, matrix_ks)
332 CALL get_qs_env(qs_env, dft_control=dft_control, matrix_ks=matrix_ks)
335 DO ispin = 1, dft_control%nspins
339 IF (admm_dm%block_map(iatom, jatom) == 0)
THEN
340 sparse_block = 0.0_dp
344 CALL dbcsr_add(matrix_ks(ispin)%matrix, matrix_ks_merge(ispin)%matrix, 1.0_dp, 1.0_dp)
347 END SUBROUTINE merge_dm_blocked
357 CHARACTER(LEN=*),
PARAMETER :: routinen =
'purify_mcweeny'
359 INTEGER :: handle, ispin, istep, nspins, unit_nr
360 REAL(kind=
dp) :: frob_norm
362 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s_aux_fit, rho_ao_aux
363 TYPE(
dbcsr_type) :: matrix_ps, matrix_psp, matrix_test
364 TYPE(
dbcsr_type),
POINTER :: matrix_p, matrix_s
369 CALL timeset(routinen, handle)
370 NULLIFY (dft_control, admm_dm, matrix_s_aux_fit, rho_aux_fit, new_hist_entry, &
371 matrix_p, matrix_s, rho_ao_aux)
374 CALL get_qs_env(qs_env, dft_control=dft_control)
375 CALL get_admm_env(qs_env%admm_env, matrix_s_aux_fit=matrix_s_aux_fit, &
376 rho_aux_fit=rho_aux_fit, admm_dm=admm_dm)
378 CALL qs_rho_get(rho_aux_fit, rho_ao=rho_ao_aux)
380 matrix_p => rho_ao_aux(1)%matrix
381 CALL dbcsr_create(matrix_ps, template=matrix_p, matrix_type=
"N")
382 CALL dbcsr_create(matrix_psp, template=matrix_p, matrix_type=
"S")
383 CALL dbcsr_create(matrix_test, template=matrix_p, matrix_type=
"S")
385 nspins = dft_control%nspins
387 matrix_p => rho_ao_aux(ispin)%matrix
388 matrix_s => matrix_s_aux_fit(1)%matrix
389 history => admm_dm%mcweeny_history(ispin)%p
390 IF (
ASSOCIATED(history)) cpabort(
"purify_dm_mcweeny: history already associated")
391 IF (nspins == 1)
CALL dbcsr_scale(matrix_p, 0.5_dp)
393 DO istep = 1, admm_dm%mcweeny_max_steps
395 ALLOCATE (new_hist_entry)
396 new_hist_entry%next => history
397 history => new_hist_entry
398 history%count = istep
399 NULLIFY (new_hist_entry)
400 CALL dbcsr_create(history%m, template=matrix_p, matrix_type=
"N")
401 CALL dbcsr_copy(history%m, matrix_p, name=
"P from McWeeny")
412 CALL dbcsr_add(matrix_test, matrix_p, 1.0_dp, -1.0_dp)
414 IF (unit_nr > 0)
WRITE (unit_nr,
'(t3,a,i5,a,f16.8)')
"McWeeny-Step", istep, &
415 ": Deviation of idempotency", frob_norm
416 IF (frob_norm < 1000_dp*admm_dm%eps_filter .AND. istep > 1)
EXIT
419 CALL dbcsr_copy(matrix_p, matrix_psp, name=
"P from McWeeny")
423 admm_dm%mcweeny_history(ispin)%p => history
424 IF (nspins == 1)
CALL dbcsr_scale(matrix_p, 2.0_dp)
431 CALL timestop(handle)
440 SUBROUTINE revert_purify_mcweeny(qs_env, matrix_ks_merge)
442 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks_merge
444 CHARACTER(LEN=*),
PARAMETER :: routinen =
'revert_purify_mcweeny'
446 INTEGER :: handle, ispin, nspins, unit_nr
448 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_ks_aux_fit, &
450 matrix_s_aux_fit_vs_orb
455 CALL timeset(routinen, handle)
457 NULLIFY (admm_dm, dft_control, matrix_ks, matrix_ks_aux_fit, &
458 matrix_s_aux_fit, matrix_s_aux_fit_vs_orb, &
459 history_next, history_curr, matrix_k)
461 CALL get_qs_env(qs_env, dft_control=dft_control, matrix_ks=matrix_ks)
462 CALL get_admm_env(qs_env%admm_env, matrix_s_aux_fit=matrix_s_aux_fit, admm_dm=admm_dm, &
463 matrix_s_aux_fit_vs_orb=matrix_s_aux_fit_vs_orb, matrix_ks_aux_fit=matrix_ks_aux_fit)
465 nspins = dft_control%nspins
466 ALLOCATE (matrix_ks_merge(nspins))
469 ALLOCATE (matrix_ks_merge(ispin)%matrix)
470 matrix_k => matrix_ks_merge(ispin)%matrix
471 CALL dbcsr_copy(matrix_k, matrix_ks_aux_fit(ispin)%matrix, name=
"K")
472 history_curr => admm_dm%mcweeny_history(ispin)%p
473 NULLIFY (admm_dm%mcweeny_history(ispin)%p)
476 DO WHILE (
ASSOCIATED(history_curr))
477 IF (unit_nr > 0)
WRITE (unit_nr,
'(t3,a,i5)')
"Reverse McWeeny-Step ", history_curr%count
478 CALL reverse_mcweeny_step(matrix_k=matrix_k, &
479 matrix_s=matrix_s_aux_fit(1)%matrix, &
480 matrix_p=history_curr%m)
482 history_next => history_curr%next
483 DEALLOCATE (history_curr)
484 history_curr => history_next
485 NULLIFY (history_next)
491 CALL timestop(handle)
493 END SUBROUTINE revert_purify_mcweeny
502 SUBROUTINE reverse_mcweeny_step(matrix_k, matrix_s, matrix_p)
503 TYPE(
dbcsr_type) :: matrix_k, matrix_s, matrix_p
505 CHARACTER(LEN=*),
PARAMETER :: routinen =
'reverse_mcweeny_step'
508 TYPE(
dbcsr_type) :: matrix_ps, matrix_sp, matrix_sum, &
511 CALL timeset(routinen, handle)
512 CALL dbcsr_create(matrix_ps, template=matrix_p, matrix_type=
"N")
513 CALL dbcsr_create(matrix_sp, template=matrix_p, matrix_type=
"N")
514 CALL dbcsr_create(matrix_tmp, template=matrix_p, matrix_type=
"N")
515 CALL dbcsr_create(matrix_sum, template=matrix_p, matrix_type=
"N")
543 CALL dbcsr_copy(matrix_k, matrix_sum, name=
"K from reverse McWeeny")
550 CALL timestop(handle)
551 END SUBROUTINE reverse_mcweeny_step
Contains ADMM methods which only require the density matrix.
subroutine, public admm_dm_merge_ks_matrix(qs_env)
Entry methods: Merges auxiliary Kohn-Sham matrix into primary one.
subroutine, public admm_dm_calc_rho_aux(qs_env)
Entry methods: Calculates auxiliary density matrix from primary one.
Types and set/get functions for auxiliary density matrix methods.
Types and set/get functions for auxiliary density matrix methods.
subroutine, public get_admm_env(admm_env, mo_derivs_aux_fit, mos_aux_fit, sab_aux_fit, sab_aux_fit_asymm, sab_aux_fit_vs_orb, matrix_s_aux_fit, matrix_s_aux_fit_kp, matrix_s_aux_fit_vs_orb, matrix_s_aux_fit_vs_orb_kp, task_list_aux_fit, matrix_ks_aux_fit, matrix_ks_aux_fit_kp, matrix_ks_aux_fit_im, matrix_ks_aux_fit_dft, matrix_ks_aux_fit_hfx, matrix_ks_aux_fit_dft_kp, matrix_ks_aux_fit_hfx_kp, rho_aux_fit, rho_aux_fit_buffer, admm_dm)
Get routine for the ADMM env.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_scale(matrix, alpha_scalar)
...
logical function, public dbcsr_iterator_blocks_left(iterator)
...
subroutine, public dbcsr_iterator_stop(iterator)
...
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_multiply(transa, transb, alpha, matrix_a, matrix_b, beta, matrix_c, first_row, last_row, first_column, last_column, first_k, last_k, retain_sparsity, filter_eps, flop)
...
subroutine, public dbcsr_iterator_next_block(iterator, row, column, block, block_number_argument_has_been_removed, row_size, col_size, row_offset, col_offset, transposed)
...
subroutine, public dbcsr_iterator_start(iterator, matrix, shared, dynamic, dynamic_byrows)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
real(dp) function, public dbcsr_frobenius_norm(matrix)
Compute the frobenius norm of a dbcsr matrix.
DBCSR operations in CP2K.
various routines to log and control the output. The idea is that decisions about where to log should ...
recursive integer function, public cp_logger_get_default_unit_nr(logger, local, skip_not_ionode)
asks the default unit number of the given logger. try to use cp_logger_get_unit_nr
Routines useful for iterative matrix calculations.
subroutine, public invert_hotelling(matrix_inverse, matrix, threshold, use_inv_as_guess, norm_convergence, filter_eps, accelerator_order, max_iter_lanczos, eps_lanczos, silent)
invert a symmetric positive definite matrix by Hotelling's method explicit symmetrization makes this ...
Defines the basic variable types.
integer, parameter, public dp
Calculate the plane wave density by collocating the primitive Gaussian functions (pgf).
subroutine, public calculate_rho_elec(matrix_p, matrix_p_kp, rho, rho_gspace, total_rho, ks_env, soft_valid, compute_tau, compute_grad, basis_type, der_type, idir, task_list_external, pw_env_external)
computes the density corresponding to a given density matrix on the grid
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.
superstucture that hold various representations of the density and keeps track of which ones are vali...
subroutine, public qs_rho_set(rho_struct, rho_ao, rho_ao_im, rho_ao_kp, rho_ao_im_kp, rho_r, drho_r, rho_g, drho_g, tau_r, tau_g, rho_r_valid, drho_r_valid, rho_g_valid, drho_g_valid, tau_r_valid, tau_g_valid, tot_rho_r, tot_rho_g, rho_r_sccs, soft_valid, complex_rho_ao)
...
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...
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...
keeps the density in various representations, keeping track of which ones are valid.