-
Notifications
You must be signed in to change notification settings - Fork 1
/
ct_types.F
447 lines (397 loc) · 20.6 KB
/
ct_types.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
!--------------------------------------------------------------------------------------------------!
! 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 Types for all cayley transformation methods
!> \par History
!> 2011.06 created [Rustam Z Khaliullin]
!> \author Rustam Z Khaliullin
! **************************************************************************************************
MODULE ct_types
USE cp_blacs_env, ONLY: cp_blacs_env_type
USE cp_dbcsr_api, ONLY: dbcsr_copy,&
dbcsr_release,&
dbcsr_type
USE input_constants, ONLY: cg_polak_ribiere,&
tensor_orthogonal
USE kinds, ONLY: dp
USE message_passing, ONLY: mp_para_env_type
#include "./base/base_uses.f90"
IMPLICIT NONE
PRIVATE
CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'ct_types'
! Public types
PUBLIC :: ct_step_env_type
! Public subroutines
PUBLIC :: ct_step_env_init, ct_step_env_set, ct_step_env_get, ct_step_env_clean
TYPE ct_step_env_type
! this type contains options for cayley transformation routines
! use orbitals or projectors?
LOGICAL :: use_occ_orbs = .FALSE., use_virt_orbs = .FALSE.
LOGICAL :: occ_orbs_orthogonal = .FALSE., virt_orbs_orthogonal = .FALSE.
! tensor properties of matrix indeces:
! tensor_up_down, tensor_orthogonal
INTEGER :: tensor_type = 0
! neglect the quadratic term in riccati equations?
LOGICAL :: neglect_quadratic_term = .FALSE.
! what kind of output do we produce?
LOGICAL :: update_p = .FALSE., update_q = .FALSE., calculate_energy_corr = .FALSE.
! variety of conjugate gradient
INTEGER :: conjugator = 0
! type of preconditioner
LOGICAL :: pp_preconditioner_full = .FALSE., &
qq_preconditioner_full = .FALSE.
REAL(KIND=dp) :: eps_convergence = 0.0_dp
REAL(KIND=dp) :: eps_filter = 0.0_dp
INTEGER :: max_iter = 0
!INTEGER :: nspins
LOGICAL :: converged = .FALSE.
INTEGER :: order_lanczos = 0
REAL(KIND=dp) :: eps_lancsoz = 0.0_dp
INTEGER :: max_iter_lanczos = 0
REAL(KIND=dp) :: energy_correction = 0.0_dp
!SPIN!!! ! metric matrices for covariant to contravariant transformations
!SPIN!!! TYPE(dbcsr_type), DIMENSION(:), POINTER :: p_index_up=>NULL()
!SPIN!!! TYPE(dbcsr_type), DIMENSION(:), POINTER :: p_index_down=>NULL()
!SPIN!!! TYPE(dbcsr_type), DIMENSION(:), POINTER :: q_index_up=>NULL()
!SPIN!!! TYPE(dbcsr_type), DIMENSION(:), POINTER :: q_index_down=>NULL()
!SPIN!!!
!SPIN!!! ! kohn-sham, covariant-covariant representation
!SPIN!!! TYPE(dbcsr_type), DIMENSION(:), POINTER :: matrix_ks=>NULL()
!SPIN!!! ! density, contravariant-contravariant representation
!SPIN!!! TYPE(dbcsr_type), DIMENSION(:), POINTER :: matrix_p=>NULL()
!SPIN!!! ! occ orbitals, contravariant-covariant representation
!SPIN!!! TYPE(dbcsr_type), DIMENSION(:), POINTER :: matrix_t=>NULL()
!SPIN!!! ! virt orbitals, contravariant-covariant representation
!SPIN!!! TYPE(dbcsr_type), DIMENSION(:), POINTER :: matrix_v=>NULL()
!SPIN!!!
!SPIN!!! ! to avoid building Occ-by-N and Virt-vy-N matrices inside
!SPIN!!! ! the ct routines get them from the external code
!SPIN!!! TYPE(dbcsr_type), DIMENSION(:), POINTER :: matrix_qp_template=>NULL()
!SPIN!!! TYPE(dbcsr_type), DIMENSION(:), POINTER :: matrix_pq_template=>NULL()
!SPIN!!!
!SPIN!!! ! single excitation amplitudes
!SPIN!!! TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_x
!SPIN!!! ! residuals
!SPIN!!! TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_res
! metric matrices for covariant to contravariant transformations
TYPE(dbcsr_type), POINTER :: p_index_up => NULL()
TYPE(dbcsr_type), POINTER :: p_index_down => NULL()
TYPE(dbcsr_type), POINTER :: q_index_up => NULL()
TYPE(dbcsr_type), POINTER :: q_index_down => NULL()
! kohn-sham, covariant-covariant representation
TYPE(dbcsr_type), POINTER :: matrix_ks => NULL()
! density, contravariant-contravariant representation
TYPE(dbcsr_type), POINTER :: matrix_p => NULL()
! occ orbitals, contravariant-covariant representation
TYPE(dbcsr_type), POINTER :: matrix_t => NULL()
! virt orbitals, contravariant-covariant representation
TYPE(dbcsr_type), POINTER :: matrix_v => NULL()
! to avoid building Occ-by-N and Virt-vy-N matrices inside
! the ct routines get them from the external code
TYPE(dbcsr_type), POINTER :: matrix_qp_template => NULL()
TYPE(dbcsr_type), POINTER :: matrix_pq_template => NULL()
! guess for single excitation amplitudes
! it is used exclusively as a guess, not modified
! it should be given in the up_down representation
TYPE(dbcsr_type), POINTER :: matrix_x_guess => NULL()
! single excitation amplitudes
TYPE(dbcsr_type) :: matrix_x
! residuals
TYPE(dbcsr_type) :: matrix_res
TYPE(mp_para_env_type), POINTER :: para_env => NULL()
TYPE(cp_blacs_env_type), POINTER :: blacs_env => NULL()
END TYPE
CONTAINS
! **************************************************************************************************
!> \brief ...
!> \param env ...
! **************************************************************************************************
SUBROUTINE ct_step_env_init(env)
TYPE(ct_step_env_type) :: env
env%use_occ_orbs = .TRUE.
env%use_virt_orbs = .FALSE.
env%occ_orbs_orthogonal = .FALSE.
env%virt_orbs_orthogonal = .FALSE.
env%tensor_type = tensor_orthogonal
env%neglect_quadratic_term = .FALSE.
env%calculate_energy_corr = .TRUE.
env%update_p = .FALSE.
env%update_q = .FALSE.
env%pp_preconditioner_full = .TRUE.
env%qq_preconditioner_full = .FALSE.
env%eps_convergence = 1.0E-8_dp
env%eps_filter = 1.0E-8_dp
env%max_iter = 400
env%order_lanczos = 3
env%eps_lancsoz = 1.0E-4_dp
env%max_iter_lanczos = 40
!env%nspins = -1
env%converged = .FALSE.
env%conjugator = cg_polak_ribiere
NULLIFY (env%p_index_up)
NULLIFY (env%p_index_down)
NULLIFY (env%q_index_up)
NULLIFY (env%q_index_down)
NULLIFY (env%matrix_ks)
NULLIFY (env%matrix_p)
NULLIFY (env%matrix_t)
NULLIFY (env%matrix_v)
NULLIFY (env%matrix_x_guess)
NULLIFY (env%matrix_qp_template)
NULLIFY (env%matrix_pq_template)
!RZK-warning read_parameters_from_input
END SUBROUTINE ct_step_env_init
! **************************************************************************************************
!> \brief ...
!> \param env ...
!> \param use_occ_orbs ...
!> \param use_virt_orbs ...
!> \param tensor_type ...
!> \param occ_orbs_orthogonal ...
!> \param virt_orbs_orthogonal ...
!> \param neglect_quadratic_term ...
!> \param update_p ...
!> \param update_q ...
!> \param eps_convergence ...
!> \param eps_filter ...
!> \param max_iter ...
!> \param p_index_up ...
!> \param p_index_down ...
!> \param q_index_up ...
!> \param q_index_down ...
!> \param matrix_ks ...
!> \param matrix_p ...
!> \param matrix_qp_template ...
!> \param matrix_pq_template ...
!> \param matrix_t ...
!> \param matrix_v ...
!> \param copy_matrix_x ...
!> \param energy_correction ...
!> \param calculate_energy_corr ...
!> \param converged ...
!> \param qq_preconditioner_full ...
!> \param pp_preconditioner_full ...
! **************************************************************************************************
SUBROUTINE ct_step_env_get(env, use_occ_orbs, use_virt_orbs, tensor_type, &
occ_orbs_orthogonal, virt_orbs_orthogonal, neglect_quadratic_term, &
update_p, update_q, eps_convergence, eps_filter, max_iter, &
p_index_up, p_index_down, q_index_up, q_index_down, matrix_ks, matrix_p, &
matrix_qp_template, matrix_pq_template, &
matrix_t, matrix_v, copy_matrix_x, energy_correction, calculate_energy_corr, &
converged, qq_preconditioner_full, pp_preconditioner_full)
TYPE(ct_step_env_type) :: env
LOGICAL, OPTIONAL :: use_occ_orbs, use_virt_orbs
INTEGER, OPTIONAL :: tensor_type
LOGICAL, OPTIONAL :: occ_orbs_orthogonal, &
virt_orbs_orthogonal, &
neglect_quadratic_term, update_p, &
update_q
REAL(KIND=dp), OPTIONAL :: eps_convergence, eps_filter
INTEGER, OPTIONAL :: max_iter
TYPE(dbcsr_type), OPTIONAL, POINTER :: p_index_up, p_index_down, q_index_up, q_index_down, &
matrix_ks, matrix_p, matrix_qp_template, matrix_pq_template, matrix_t, matrix_v
TYPE(dbcsr_type), OPTIONAL :: copy_matrix_x
REAL(KIND=dp), OPTIONAL :: energy_correction
LOGICAL, OPTIONAL :: calculate_energy_corr, converged, &
qq_preconditioner_full, &
pp_preconditioner_full
!INTEGER , OPTIONAL :: nspins
!SPIN!!! TYPE(dbcsr_type), DIMENSION(:), POINTER, OPTIONAL :: p_index_up
!SPIN!!! TYPE(dbcsr_type), DIMENSION(:), POINTER, OPTIONAL :: p_index_down
!SPIN!!! TYPE(dbcsr_type), DIMENSION(:), POINTER, OPTIONAL :: q_index_up
!SPIN!!! TYPE(dbcsr_type), DIMENSION(:), POINTER, OPTIONAL :: q_index_down
!SPIN!!! TYPE(dbcsr_type), DIMENSION(:), POINTER, OPTIONAL :: matrix_ks
!SPIN!!! TYPE(dbcsr_type), DIMENSION(:), POINTER, OPTIONAL :: matrix_p
!SPIN!!! TYPE(dbcsr_type), DIMENSION(:), POINTER, OPTIONAL :: matrix_t
!SPIN!!! TYPE(dbcsr_type), DIMENSION(:), POINTER, OPTIONAL :: matrix_v
!SPIN!!! TYPE(dbcsr_type), DIMENSION(:), POINTER, OPTIONAL :: matrix_qp_template
!SPIN!!! TYPE(dbcsr_type), DIMENSION(:), POINTER, OPTIONAL :: matrix_pq_template
!SPIN!!! TYPE(dbcsr_type), DIMENSION(:), POINTER, OPTIONAL :: matrix_x
!SPIN!!!
!SPIN!!! TYPE(dbcsr_type), DIMENSION(:), OPTIONAL :: copy_matrix_x
!INTEGER :: ispin
IF (PRESENT(use_occ_orbs)) use_occ_orbs = env%use_occ_orbs
IF (PRESENT(use_virt_orbs)) use_virt_orbs = env%use_virt_orbs
IF (PRESENT(occ_orbs_orthogonal)) occ_orbs_orthogonal = &
env%occ_orbs_orthogonal
IF (PRESENT(virt_orbs_orthogonal)) virt_orbs_orthogonal = &
env%virt_orbs_orthogonal
IF (PRESENT(tensor_type)) tensor_type = env%tensor_type
IF (PRESENT(neglect_quadratic_term)) neglect_quadratic_term = &
env%neglect_quadratic_term
IF (PRESENT(calculate_energy_corr)) calculate_energy_corr = &
env%calculate_energy_corr
IF (PRESENT(update_p)) update_p = env%update_p
IF (PRESENT(update_q)) update_q = env%update_q
IF (PRESENT(pp_preconditioner_full)) pp_preconditioner_full = &
env%pp_preconditioner_full
IF (PRESENT(qq_preconditioner_full)) qq_preconditioner_full = &
env%qq_preconditioner_full
IF (PRESENT(eps_convergence)) eps_convergence = env%eps_convergence
IF (PRESENT(eps_filter)) eps_filter = env%eps_filter
IF (PRESENT(max_iter)) max_iter = env%max_iter
!IF (PRESENT(nspins)) nspins = env%nspins
IF (PRESENT(matrix_ks)) matrix_ks => env%matrix_ks
IF (PRESENT(matrix_p)) matrix_p => env%matrix_p
IF (PRESENT(matrix_t)) matrix_t => env%matrix_t
IF (PRESENT(matrix_v)) matrix_v => env%matrix_v
IF (PRESENT(matrix_qp_template)) matrix_qp_template => &
env%matrix_qp_template
IF (PRESENT(matrix_pq_template)) matrix_pq_template => &
env%matrix_pq_template
IF (PRESENT(p_index_up)) p_index_up => env%p_index_up
IF (PRESENT(q_index_up)) q_index_up => env%q_index_up
IF (PRESENT(p_index_down)) p_index_down => env%p_index_down
IF (PRESENT(q_index_down)) q_index_down => env%q_index_down
IF (PRESENT(copy_matrix_x)) THEN
!DO ispin=1,env%nspins
!CALL dbcsr_copy(copy_matrix_x(ispin),env%matrix_x(ispin))
CALL dbcsr_copy(copy_matrix_x, env%matrix_x)
!ENDDO
END IF
!IF (PRESENT(matrix_x)) matrix_x => env%matrix_x
IF (PRESENT(energy_correction)) energy_correction = env%energy_correction
IF (PRESENT(converged)) converged = env%converged
END SUBROUTINE ct_step_env_get
! **************************************************************************************************
!> \brief ...
!> \param env ...
!> \param para_env ...
!> \param blacs_env ...
!> \param use_occ_orbs ...
!> \param use_virt_orbs ...
!> \param tensor_type ...
!> \param occ_orbs_orthogonal ...
!> \param virt_orbs_orthogonal ...
!> \param neglect_quadratic_term ...
!> \param update_p ...
!> \param update_q ...
!> \param eps_convergence ...
!> \param eps_filter ...
!> \param max_iter ...
!> \param p_index_up ...
!> \param p_index_down ...
!> \param q_index_up ...
!> \param q_index_down ...
!> \param matrix_ks ...
!> \param matrix_p ...
!> \param matrix_qp_template ...
!> \param matrix_pq_template ...
!> \param matrix_t ...
!> \param matrix_v ...
!> \param matrix_x_guess ...
!> \param calculate_energy_corr ...
!> \param conjugator ...
!> \param qq_preconditioner_full ...
!> \param pp_preconditioner_full ...
! **************************************************************************************************
SUBROUTINE ct_step_env_set(env, para_env, blacs_env, use_occ_orbs, &
use_virt_orbs, tensor_type, &
occ_orbs_orthogonal, virt_orbs_orthogonal, neglect_quadratic_term, &
update_p, update_q, eps_convergence, eps_filter, max_iter, &
p_index_up, p_index_down, q_index_up, q_index_down, matrix_ks, matrix_p, &
matrix_qp_template, matrix_pq_template, &
matrix_t, matrix_v, matrix_x_guess, calculate_energy_corr, conjugator, &
qq_preconditioner_full, pp_preconditioner_full)
TYPE(ct_step_env_type) :: env
TYPE(mp_para_env_type), POINTER :: para_env
TYPE(cp_blacs_env_type), POINTER :: blacs_env
LOGICAL, OPTIONAL :: use_occ_orbs, use_virt_orbs
INTEGER, OPTIONAL :: tensor_type
LOGICAL, OPTIONAL :: occ_orbs_orthogonal, &
virt_orbs_orthogonal, &
neglect_quadratic_term, update_p, &
update_q
REAL(KIND=dp), OPTIONAL :: eps_convergence, eps_filter
INTEGER, OPTIONAL :: max_iter
TYPE(dbcsr_type), OPTIONAL, TARGET :: p_index_up, p_index_down, q_index_up, q_index_down, &
matrix_ks, matrix_p, matrix_qp_template, matrix_pq_template, matrix_t, matrix_v, &
matrix_x_guess
LOGICAL, OPTIONAL :: calculate_energy_corr
INTEGER, OPTIONAL :: conjugator
LOGICAL, OPTIONAL :: qq_preconditioner_full, &
pp_preconditioner_full
!INTEGER , OPTIONAL :: nspins
!SPIN!!! TYPE(dbcsr_type), TARGET, DIMENSION(:), OPTIONAL :: p_index_up
!SPIN!!! TYPE(dbcsr_type), TARGET, DIMENSION(:), OPTIONAL :: p_index_down
!SPIN!!! TYPE(dbcsr_type), TARGET, DIMENSION(:), OPTIONAL :: q_index_up
!SPIN!!! TYPE(dbcsr_type), TARGET, DIMENSION(:), OPTIONAL :: q_index_down
!SPIN!!! TYPE(dbcsr_type), TARGET, DIMENSION(:), OPTIONAL :: matrix_ks
!SPIN!!! TYPE(dbcsr_type), TARGET, DIMENSION(:), OPTIONAL :: matrix_p
!SPIN!!! TYPE(dbcsr_type), TARGET, DIMENSION(:), OPTIONAL :: matrix_t
!SPIN!!! TYPE(dbcsr_type), TARGET, DIMENSION(:), OPTIONAL :: matrix_v
!SPIN!!! TYPE(dbcsr_type), TARGET, DIMENSION(:), OPTIONAL :: matrix_qp_template
!SPIN!!! TYPE(dbcsr_type), TARGET, DIMENSION(:), OPTIONAL :: matrix_pq_template
! set para_env and blacs_env which are needed to operate with full matrices
! it would be nice to have everything with cp_dbcsr matrices, well maybe later
env%para_env => para_env
env%blacs_env => blacs_env
IF (PRESENT(use_occ_orbs)) env%use_occ_orbs = use_occ_orbs
IF (PRESENT(use_virt_orbs)) env%use_virt_orbs = use_virt_orbs
IF (PRESENT(occ_orbs_orthogonal)) env%occ_orbs_orthogonal = &
occ_orbs_orthogonal
IF (PRESENT(virt_orbs_orthogonal)) env%virt_orbs_orthogonal = &
virt_orbs_orthogonal
IF (PRESENT(tensor_type)) env%tensor_type = tensor_type
IF (PRESENT(neglect_quadratic_term)) env%neglect_quadratic_term = &
neglect_quadratic_term
IF (PRESENT(calculate_energy_corr)) env%calculate_energy_corr = &
calculate_energy_corr
IF (PRESENT(update_p)) env%update_p = update_p
IF (PRESENT(update_q)) env%update_q = update_q
IF (PRESENT(pp_preconditioner_full)) env%pp_preconditioner_full = &
pp_preconditioner_full
IF (PRESENT(qq_preconditioner_full)) env%qq_preconditioner_full = &
qq_preconditioner_full
IF (PRESENT(eps_convergence)) env%eps_convergence = eps_convergence
IF (PRESENT(eps_filter)) env%eps_filter = eps_filter
IF (PRESENT(max_iter)) env%max_iter = max_iter
!IF (PRESENT(nspins)) env%nspins = nspins
IF (PRESENT(conjugator)) env%conjugator = conjugator
IF (PRESENT(matrix_ks)) env%matrix_ks => matrix_ks
IF (PRESENT(matrix_p)) env%matrix_p => matrix_p
IF (PRESENT(matrix_t)) env%matrix_t => matrix_t
IF (PRESENT(matrix_v)) env%matrix_v => matrix_v
IF (PRESENT(matrix_x_guess)) env%matrix_x_guess => matrix_x_guess
IF (PRESENT(matrix_qp_template)) env%matrix_qp_template => &
matrix_qp_template
IF (PRESENT(matrix_pq_template)) env%matrix_pq_template => &
matrix_pq_template
IF (PRESENT(p_index_up)) env%p_index_up => p_index_up
IF (PRESENT(q_index_up)) env%q_index_up => q_index_up
IF (PRESENT(p_index_down)) env%p_index_down => p_index_down
IF (PRESENT(q_index_down)) env%q_index_down => q_index_down
END SUBROUTINE ct_step_env_set
! **************************************************************************************************
!> \brief ...
!> \param env ...
! **************************************************************************************************
SUBROUTINE ct_step_env_clean(env)
TYPE(ct_step_env_type) :: env
!INTEGER :: ispin
NULLIFY (env%para_env)
NULLIFY (env%blacs_env)
!DO ispin=1,env%nspins
CALL dbcsr_release(env%matrix_x)
CALL dbcsr_release(env%matrix_res)
!CALL dbcsr_release(env%matrix_x(ispin))
!CALL dbcsr_release(env%matrix_res(ispin))
!ENDDO
!DEALLOCATE(env%matrix_x,env%matrix_res)
NULLIFY (env%p_index_up)
NULLIFY (env%p_index_down)
NULLIFY (env%q_index_up)
NULLIFY (env%q_index_down)
NULLIFY (env%matrix_ks)
NULLIFY (env%matrix_p)
NULLIFY (env%matrix_t)
NULLIFY (env%matrix_v)
NULLIFY (env%matrix_x_guess)
NULLIFY (env%matrix_qp_template)
NULLIFY (env%matrix_pq_template)
END SUBROUTINE ct_step_env_clean
END MODULE ct_types