-
Notifications
You must be signed in to change notification settings - Fork 1
/
rtp_admm_methods.F
539 lines (447 loc) · 25.9 KB
/
rtp_admm_methods.F
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
!--------------------------------------------------------------------------------------------------!
! CP2K: A general program to perform molecular dynamics simulations !
! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
! !
! SPDX-License-Identifier: GPL-2.0-or-later !
!--------------------------------------------------------------------------------------------------!
! **************************************************************************************************
!> \brief Utilities for rtp in combination with admm methods
!> adapted routines from admm_method (author Manuel Guidon)
!>
!> \par History Use new "force only" overlap routine [07.2014,JGH]
!> \author Florian Schiffmann
! **************************************************************************************************
MODULE rtp_admm_methods
USE admm_types, ONLY: admm_env_create,&
admm_type,&
get_admm_env
USE cp_control_types, ONLY: admm_control_type,&
dft_control_type
USE cp_dbcsr_api, ONLY: &
dbcsr_add, dbcsr_copy, dbcsr_create, dbcsr_deallocate_matrix, dbcsr_desymmetrize, &
dbcsr_get_info, dbcsr_p_type, dbcsr_release, dbcsr_set, dbcsr_type, dbcsr_type_no_symmetry
USE cp_dbcsr_operations, ONLY: copy_dbcsr_to_fm,&
copy_fm_to_dbcsr,&
cp_dbcsr_plus_fm_fm_t
USE cp_fm_basic_linalg, ONLY: cp_fm_upper_to_full
USE cp_fm_cholesky, ONLY: cp_fm_cholesky_decompose,&
cp_fm_cholesky_invert
USE cp_fm_types, ONLY: cp_fm_get_info,&
cp_fm_to_fm,&
cp_fm_type
USE hfx_admm_utils, ONLY: create_admm_xc_section
USE input_constants, ONLY: do_admm_basis_projection,&
do_admm_purify_none
USE input_section_types, ONLY: section_vals_get_subs_vals,&
section_vals_type
USE kinds, ONLY: default_string_length,&
dp
USE mathconstants, ONLY: one,&
zero
USE message_passing, ONLY: mp_para_env_type
USE parallel_gemm_api, ONLY: parallel_gemm
USE pw_types, ONLY: pw_c1d_gs_type,&
pw_r3d_rs_type
USE qs_collocate_density, ONLY: calculate_rho_elec
USE qs_environment_types, ONLY: get_qs_env,&
qs_environment_type,&
set_qs_env
USE qs_gapw_densities, ONLY: prepare_gapw_den
USE qs_kind_types, ONLY: get_qs_kind_set,&
qs_kind_type
USE qs_ks_types, ONLY: qs_ks_env_type
USE qs_mo_types, ONLY: get_mo_set,&
mo_set_type
USE qs_rho_atom_methods, ONLY: calculate_rho_atom_coeff
USE qs_rho_types, ONLY: qs_rho_get,&
qs_rho_set,&
qs_rho_type
USE rt_propagation_types, ONLY: get_rtp,&
rt_prop_type
USE task_list_types, ONLY: task_list_type
#include "./base/base_uses.f90"
IMPLICIT NONE
PRIVATE
! *** Public subroutines ***
PUBLIC :: rtp_admm_calc_rho_aux, rtp_admm_merge_ks_matrix
CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'rtp_admm_methods'
CONTAINS
! **************************************************************************************************
!> \brief Compute the ADMM density matrix in case of rtp (complex MO's)
!>
!> \param qs_env ...
!> \par History
! **************************************************************************************************
SUBROUTINE rtp_admm_calc_rho_aux(qs_env)
TYPE(qs_environment_type), POINTER :: qs_env
CHARACTER(LEN=*), PARAMETER :: routineN = 'rtp_admm_calc_rho_aux'
CHARACTER(LEN=default_string_length) :: basis_type
INTEGER :: handle, ispin, nspins
LOGICAL :: gapw, s_mstruct_changed
REAL(KIND=dp), DIMENSION(:), POINTER :: tot_rho_r_aux
TYPE(admm_type), POINTER :: admm_env
TYPE(cp_fm_type), DIMENSION(:), POINTER :: rtp_coeff_aux_fit
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_p_aux, matrix_p_aux_im, &
matrix_s_aux_fit, &
matrix_s_aux_fit_vs_orb
TYPE(dft_control_type), POINTER :: dft_control
TYPE(mo_set_type), DIMENSION(:), POINTER :: mos, mos_aux_fit
TYPE(mp_para_env_type), POINTER :: para_env
TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_g_aux
TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho_r_aux
TYPE(qs_ks_env_type), POINTER :: ks_env
TYPE(qs_rho_type), POINTER :: rho, rho_aux_fit
TYPE(rt_prop_type), POINTER :: rtp
TYPE(task_list_type), POINTER :: task_list_aux_fit
CALL timeset(routineN, handle)
NULLIFY (admm_env, matrix_p_aux, matrix_p_aux_im, mos, &
mos_aux_fit, para_env, matrix_s_aux_fit, matrix_s_aux_fit_vs_orb, rho, &
ks_env, dft_control, tot_rho_r_aux, rho_r_aux, rho_g_aux, task_list_aux_fit)
CALL get_qs_env(qs_env, &
admm_env=admm_env, &
ks_env=ks_env, &
dft_control=dft_control, &
para_env=para_env, &
mos=mos, &
rtp=rtp, &
rho=rho, &
s_mstruct_changed=s_mstruct_changed)
CALL get_admm_env(admm_env, matrix_s_aux_fit=matrix_s_aux_fit, task_list_aux_fit=task_list_aux_fit, &
matrix_s_aux_fit_vs_orb=matrix_s_aux_fit_vs_orb, mos_aux_fit=mos_aux_fit, &
rho_aux_fit=rho_aux_fit)
gapw = admm_env%do_gapw
nspins = dft_control%nspins
CALL get_rtp(rtp=rtp, admm_mos=rtp_coeff_aux_fit)
CALL rtp_admm_fit_mo_coeffs(qs_env, admm_env, dft_control%admm_control, para_env, &
matrix_s_aux_fit, matrix_s_aux_fit_vs_orb, &
mos, mos_aux_fit, rtp, rtp_coeff_aux_fit, &
s_mstruct_changed)
DO ispin = 1, nspins
CALL qs_rho_get(rho_aux_fit, &
rho_ao=matrix_p_aux, &
rho_ao_im=matrix_p_aux_im, &
rho_r=rho_r_aux, &
rho_g=rho_g_aux, &
tot_rho_r=tot_rho_r_aux)
CALL rtp_admm_calculate_dm(admm_env, rtp_coeff_aux_fit, &
matrix_p_aux(ispin)%matrix, &
matrix_p_aux_im(ispin)%matrix, &
ispin)
!IF GAPW, only do the soft basis with PW
basis_type = "AUX_FIT"
IF (gapw) THEN
basis_type = "AUX_FIT_SOFT"
task_list_aux_fit => admm_env%admm_gapw_env%task_list
END IF
CALL calculate_rho_elec(matrix_p=matrix_p_aux(ispin)%matrix, &
rho=rho_r_aux(ispin), &
rho_gspace=rho_g_aux(ispin), &
total_rho=tot_rho_r_aux(ispin), &
ks_env=ks_env, soft_valid=.FALSE., &
basis_type="AUX_FIT", &
task_list_external=task_list_aux_fit)
!IF GAPW, also need to atomic densities
IF (gapw) THEN
CALL calculate_rho_atom_coeff(qs_env, matrix_p_aux, &
rho_atom_set=admm_env%admm_gapw_env%local_rho_set%rho_atom_set, &
qs_kind_set=admm_env%admm_gapw_env%admm_kind_set, &
oce=admm_env%admm_gapw_env%oce, sab=admm_env%sab_aux_fit, &
para_env=para_env)
CALL prepare_gapw_den(qs_env, local_rho_set=admm_env%admm_gapw_env%local_rho_set, &
do_rho0=.FALSE., kind_set_external=admm_env%admm_gapw_env%admm_kind_set)
END IF
END DO
CALL set_qs_env(qs_env, admm_env=admm_env)
CALL qs_rho_set(rho_aux_fit, rho_r_valid=.TRUE., rho_g_valid=.TRUE.)
CALL timestop(handle)
END SUBROUTINE rtp_admm_calc_rho_aux
! **************************************************************************************************
!> \brief ...
!> \param admm_env ...
!> \param rtp_coeff_aux_fit ...
!> \param density_matrix_aux ...
!> \param density_matrix_aux_im ...
!> \param ispin ...
! **************************************************************************************************
SUBROUTINE rtp_admm_calculate_dm(admm_env, rtp_coeff_aux_fit, density_matrix_aux, &
density_matrix_aux_im, ispin)
TYPE(admm_type), POINTER :: admm_env
TYPE(cp_fm_type), DIMENSION(:), POINTER :: rtp_coeff_aux_fit
TYPE(dbcsr_type), POINTER :: density_matrix_aux, density_matrix_aux_im
INTEGER, INTENT(in) :: ispin
CHARACTER(len=*), PARAMETER :: routineN = 'rtp_admm_calculate_dm'
INTEGER :: handle
CALL timeset(routineN, handle)
SELECT CASE (admm_env%purification_method)
CASE (do_admm_purify_none)
CALL calculate_rtp_admm_density(density_matrix_aux, density_matrix_aux_im, &
rtp_coeff_aux_fit, ispin)
CASE DEFAULT
CPWARN("only purification NONE possible with RTP/EMD at the moment")
END SELECT
CALL timestop(handle)
END SUBROUTINE rtp_admm_calculate_dm
! **************************************************************************************************
!> \brief ...
!> \param qs_env ...
!> \param admm_env ...
!> \param admm_control ...
!> \param para_env ...
!> \param matrix_s_aux_fit ...
!> \param matrix_s_mixed ...
!> \param mos ...
!> \param mos_aux_fit ...
!> \param rtp ...
!> \param rtp_coeff_aux_fit ...
!> \param geometry_did_change ...
! **************************************************************************************************
SUBROUTINE rtp_admm_fit_mo_coeffs(qs_env, admm_env, admm_control, para_env, matrix_s_aux_fit, matrix_s_mixed, &
mos, mos_aux_fit, rtp, rtp_coeff_aux_fit, geometry_did_change)
TYPE(qs_environment_type), POINTER :: qs_env
TYPE(admm_type), POINTER :: admm_env
TYPE(admm_control_type), POINTER :: admm_control
TYPE(mp_para_env_type), POINTER :: para_env
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s_aux_fit, matrix_s_mixed
TYPE(mo_set_type), DIMENSION(:), INTENT(IN) :: mos, mos_aux_fit
TYPE(rt_prop_type), POINTER :: rtp
TYPE(cp_fm_type), DIMENSION(:), POINTER :: rtp_coeff_aux_fit
LOGICAL, INTENT(IN) :: geometry_did_change
CHARACTER(LEN=*), PARAMETER :: routineN = 'rtp_admm_fit_mo_coeffs'
INTEGER :: handle, nao_aux_fit, natoms
LOGICAL :: recalc_S
TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
TYPE(section_vals_type), POINTER :: input, xc_section
CALL timeset(routineN, handle)
NULLIFY (xc_section, qs_kind_set)
IF (.NOT. (ASSOCIATED(admm_env))) THEN
! setup admm environment
CALL get_qs_env(qs_env, input=input, natom=natoms, qs_kind_set=qs_kind_set)
CALL get_qs_kind_set(qs_kind_set, nsgf=nao_aux_fit, basis_type="AUX_FIT")
CALL admm_env_create(admm_env, admm_control, mos, para_env, natoms, nao_aux_fit)
xc_section => section_vals_get_subs_vals(input, "DFT%XC")
CALL create_admm_xc_section(x_data=qs_env%x_data, xc_section=xc_section, &
admm_env=admm_env)
IF (admm_control%method /= do_admm_basis_projection) THEN
CPWARN("RTP requires BASIS_PROJECTION.")
END IF
END IF
recalc_S = geometry_did_change .OR. (rtp%iter == 0 .AND. (rtp%istep == rtp%i_start))
SELECT CASE (admm_env%purification_method)
CASE (do_admm_purify_none)
CALL rtp_fit_mo_coeffs_none(qs_env, admm_env, para_env, matrix_s_aux_fit, matrix_s_mixed, &
mos, mos_aux_fit, rtp, rtp_coeff_aux_fit, recalc_S)
CASE DEFAULT
CPWARN("Purification method not implemented in combination with RTP")
END SELECT
CALL timestop(handle)
END SUBROUTINE rtp_admm_fit_mo_coeffs
! **************************************************************************************************
!> \brief Calculates the MO coefficients for the auxiliary fitting basis set
!> by minimizing int (psi_i - psi_aux_i)^2 using Lagrangian Multipliers
!>
!> \param qs_env ...
!> \param admm_env The ADMM env
!> \param para_env The parallel env
!> \param matrix_s_aux_fit the overlap matrix of the auxiliary fitting basis set
!> \param matrix_s_mixed the mixed overlap matrix of the auxiliary fitting basis
!> set and the orbital basis set
!> \param mos the MO's of the orbital basis set
!> \param mos_aux_fit the MO's of the auxiliary fitting basis set
!> \param rtp ...
!> \param rtp_coeff_aux_fit ...
!> \param geometry_did_change flag to indicate if the geomtry changed
!> \par History
!> 05.2008 created [Manuel Guidon]
!> \author Manuel Guidon
! **************************************************************************************************
SUBROUTINE rtp_fit_mo_coeffs_none(qs_env, admm_env, para_env, matrix_s_aux_fit, matrix_s_mixed, &
mos, mos_aux_fit, rtp, rtp_coeff_aux_fit, geometry_did_change)
TYPE(qs_environment_type), POINTER :: qs_env
TYPE(admm_type), POINTER :: admm_env
TYPE(mp_para_env_type), POINTER :: para_env
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s_aux_fit, matrix_s_mixed
TYPE(mo_set_type), DIMENSION(:), INTENT(IN) :: mos, mos_aux_fit
TYPE(rt_prop_type), POINTER :: rtp
TYPE(cp_fm_type), DIMENSION(:), POINTER :: rtp_coeff_aux_fit
LOGICAL, INTENT(IN) :: geometry_did_change
CHARACTER(LEN=*), PARAMETER :: routineN = 'rtp_fit_mo_coeffs_none'
INTEGER :: handle, ispin, nao_aux_fit, nao_orb, &
natoms, nmo, nmo_mos, nspins
REAL(KIND=dp), DIMENSION(:), POINTER :: occ_num, occ_num_aux
TYPE(cp_fm_type), DIMENSION(:), POINTER :: mos_new
TYPE(cp_fm_type), POINTER :: mo_coeff, mo_coeff_aux_fit
TYPE(dft_control_type), POINTER :: dft_control
TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
TYPE(section_vals_type), POINTER :: input, xc_section
CALL timeset(routineN, handle)
NULLIFY (dft_control, qs_kind_set)
IF (.NOT. (ASSOCIATED(admm_env))) THEN
CALL get_qs_env(qs_env, input=input, natom=natoms, dft_control=dft_control, qs_kind_set=qs_kind_set)
CALL get_qs_kind_set(qs_kind_set, nsgf=nao_aux_fit, basis_type="AUX_FIT")
CALL admm_env_create(admm_env, dft_control%admm_control, mos, para_env, natoms, nao_aux_fit)
xc_section => section_vals_get_subs_vals(input, "DFT%XC")
CALL create_admm_xc_section(x_data=qs_env%x_data, xc_section=xc_section, &
admm_env=admm_env)
END IF
nao_aux_fit = admm_env%nao_aux_fit
nao_orb = admm_env%nao_orb
nspins = SIZE(mos)
! *** This part only depends on overlap matrices ==> needs only to be calculated if the geometry changed
IF (geometry_did_change) THEN
CALL copy_dbcsr_to_fm(matrix_s_aux_fit(1)%matrix, admm_env%S_inv)
CALL cp_fm_upper_to_full(admm_env%S_inv, admm_env%work_aux_aux)
CALL cp_fm_to_fm(admm_env%S_inv, admm_env%S)
CALL copy_dbcsr_to_fm(matrix_s_mixed(1)%matrix, admm_env%Q)
!! Calculate S'_inverse
CALL cp_fm_cholesky_decompose(admm_env%S_inv)
CALL cp_fm_cholesky_invert(admm_env%S_inv)
!! Symmetrize the guy
CALL cp_fm_upper_to_full(admm_env%S_inv, admm_env%work_aux_aux)
!! Calculate A=S'^(-1)*P
CALL parallel_gemm('N', 'N', nao_aux_fit, nao_orb, nao_aux_fit, &
1.0_dp, admm_env%S_inv, admm_env%Q, 0.0_dp, &
admm_env%A)
END IF
! *** Calculate the mo_coeffs for the fitting basis
DO ispin = 1, nspins
nmo = admm_env%nmo(ispin)
IF (nmo == 0) CYCLE
!! Lambda = C^(T)*B*C
CALL get_rtp(rtp=rtp, mos_new=mos_new)
CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff, occupation_numbers=occ_num, nmo=nmo_mos)
CALL get_mo_set(mos_aux_fit(ispin), mo_coeff=mo_coeff_aux_fit, &
occupation_numbers=occ_num_aux)
CALL parallel_gemm('N', 'N', nao_aux_fit, nmo, nao_orb, &
1.0_dp, admm_env%A, mos_new(2*ispin - 1), 0.0_dp, &
rtp_coeff_aux_fit(2*ispin - 1))
CALL parallel_gemm('N', 'N', nao_aux_fit, nmo, nao_orb, &
1.0_dp, admm_env%A, mos_new(2*ispin), 0.0_dp, &
rtp_coeff_aux_fit(2*ispin))
CALL cp_fm_to_fm(rtp_coeff_aux_fit(2*ispin - 1), mo_coeff_aux_fit)
END DO
CALL timestop(handle)
END SUBROUTINE rtp_fit_mo_coeffs_none
! **************************************************************************************************
!> \brief ...
!> \param density_matrix_aux ...
!> \param density_matrix_aux_im ...
!> \param rtp_coeff_aux_fit ...
!> \param ispin ...
! **************************************************************************************************
SUBROUTINE calculate_rtp_admm_density(density_matrix_aux, density_matrix_aux_im, &
rtp_coeff_aux_fit, ispin)
TYPE(dbcsr_type), POINTER :: density_matrix_aux, density_matrix_aux_im
TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: rtp_coeff_aux_fit
INTEGER, INTENT(in) :: ispin
CHARACTER(len=*), PARAMETER :: routineN = 'calculate_rtp_admm_density'
REAL(KIND=dp), PARAMETER :: one = 1.0_dp, zero = 0.0_dp
INTEGER :: handle, im, ncol, re
REAL(KIND=dp) :: alpha
CALL timeset(routineN, handle)
re = 2*ispin - 1; im = 2*ispin
alpha = 3*one - REAL(SIZE(rtp_coeff_aux_fit)/2, dp)
CALL dbcsr_set(density_matrix_aux, zero)
CALL cp_fm_get_info(rtp_coeff_aux_fit(re), ncol_global=ncol)
CALL cp_dbcsr_plus_fm_fm_t(sparse_matrix=density_matrix_aux, &
matrix_v=rtp_coeff_aux_fit(re), &
ncol=ncol, &
alpha=alpha)
! It is actually complex conjugate but i*i=-1 therefore it must be added
CALL cp_dbcsr_plus_fm_fm_t(sparse_matrix=density_matrix_aux, &
matrix_v=rtp_coeff_aux_fit(im), &
ncol=ncol, &
alpha=alpha)
! compute the imaginary part of the dm
CALL dbcsr_set(density_matrix_aux_im, zero)
CALL cp_dbcsr_plus_fm_fm_t(sparse_matrix=density_matrix_aux_im, &
matrix_v=rtp_coeff_aux_fit(im), &
matrix_g=rtp_coeff_aux_fit(re), &
ncol=ncol, &
alpha=2.0_dp*alpha, &
symmetry_mode=-1)
CALL timestop(handle)
END SUBROUTINE calculate_rtp_admm_density
! **************************************************************************************************
!> \brief ...
!> \param qs_env ...
! **************************************************************************************************
SUBROUTINE rtp_admm_merge_ks_matrix(qs_env)
TYPE(qs_environment_type), POINTER :: qs_env
CHARACTER(LEN=*), PARAMETER :: routineN = 'rtp_admm_merge_ks_matrix'
INTEGER :: handle, ispin
TYPE(admm_type), POINTER :: admm_env
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks, matrix_ks_aux_fit, &
matrix_ks_aux_fit_im, matrix_ks_im
TYPE(dft_control_type), POINTER :: dft_control
NULLIFY (admm_env, dft_control, matrix_ks, matrix_ks_im, matrix_ks_aux_fit, matrix_ks_aux_fit_im)
CALL timeset(routineN, handle)
CALL get_qs_env(qs_env, &
admm_env=admm_env, &
dft_control=dft_control, &
matrix_ks=matrix_ks, &
matrix_ks_im=matrix_ks_im)
CALL get_admm_env(admm_env, matrix_ks_aux_fit=matrix_ks_aux_fit, matrix_ks_aux_fit_im=matrix_ks_aux_fit_im)
!note: the GAPW contribution to ks_aux_fit taken care of in qs_ks_methods.F/update_admm_ks_atom
DO ispin = 1, dft_control%nspins
SELECT CASE (admm_env%purification_method)
CASE (do_admm_purify_none)
CALL rt_merge_ks_matrix_none(ispin, admm_env, &
matrix_ks, matrix_ks_aux_fit)
CALL rt_merge_ks_matrix_none(ispin, admm_env, &
matrix_ks_im, matrix_ks_aux_fit_im)
CASE DEFAULT
CPWARN("only purification NONE possible with RTP/EMD at the moment")
END SELECT
END DO !spin loop
CALL timestop(handle)
END SUBROUTINE rtp_admm_merge_ks_matrix
! **************************************************************************************************
!> \brief ...
!> \param ispin ...
!> \param admm_env ...
!> \param matrix_ks ...
!> \param matrix_ks_aux_fit ...
! **************************************************************************************************
SUBROUTINE rt_merge_ks_matrix_none(ispin, admm_env, &
matrix_ks, matrix_ks_aux_fit)
INTEGER, INTENT(IN) :: ispin
TYPE(admm_type), POINTER :: admm_env
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks, matrix_ks_aux_fit
CHARACTER(LEN=*), PARAMETER :: routineN = 'rt_merge_ks_matrix_none'
CHARACTER :: matrix_type_fit
INTEGER :: handle, nao_aux_fit, nao_orb, nmo
INTEGER, SAVE :: counter = 0
TYPE(dbcsr_type) :: matrix_ks_nosym
TYPE(dbcsr_type), POINTER :: matrix_k_tilde
CALL timeset(routineN, handle)
counter = counter + 1
nao_aux_fit = admm_env%nao_aux_fit
nao_orb = admm_env%nao_orb
nmo = admm_env%nmo(ispin)
CALL dbcsr_create(matrix_ks_nosym, template=matrix_ks_aux_fit(ispin)%matrix, &
matrix_type=dbcsr_type_no_symmetry)
CALL dbcsr_set(matrix_ks_nosym, 0.0_dp)
CALL dbcsr_desymmetrize(matrix_ks_aux_fit(ispin)%matrix, matrix_ks_nosym)
CALL copy_dbcsr_to_fm(matrix_ks_nosym, admm_env%K(ispin))
!! K*A
CALL parallel_gemm('N', 'N', nao_aux_fit, nao_orb, nao_aux_fit, &
1.0_dp, admm_env%K(ispin), admm_env%A, 0.0_dp, &
admm_env%work_aux_orb)
!! A^T*K*A
CALL parallel_gemm('T', 'N', nao_orb, nao_orb, nao_aux_fit, &
1.0_dp, admm_env%A, admm_env%work_aux_orb, 0.0_dp, &
admm_env%work_orb_orb)
CALL dbcsr_get_info(matrix_ks_aux_fit(ispin)%matrix, matrix_type=matrix_type_fit)
NULLIFY (matrix_k_tilde)
ALLOCATE (matrix_k_tilde)
CALL dbcsr_create(matrix_k_tilde, template=matrix_ks(ispin)%matrix, &
name='MATRIX K_tilde', matrix_type=matrix_type_fit)
CALL dbcsr_copy(matrix_k_tilde, matrix_ks(ispin)%matrix)
CALL dbcsr_set(matrix_k_tilde, 0.0_dp)
CALL copy_fm_to_dbcsr(admm_env%work_orb_orb, matrix_k_tilde, keep_sparsity=.TRUE.)
CALL dbcsr_add(matrix_ks(ispin)%matrix, matrix_k_tilde, 1.0_dp, 1.0_dp)
CALL dbcsr_deallocate_matrix(matrix_k_tilde)
CALL dbcsr_release(matrix_ks_nosym)
CALL timestop(handle)
END SUBROUTINE rt_merge_ks_matrix_none
END MODULE rtp_admm_methods