Line data Source code
1 : !--------------------------------------------------------------------------------------------------!
2 : ! CP2K: A general program to perform molecular dynamics simulations !
3 : ! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4 : ! !
5 : ! SPDX-License-Identifier: GPL-2.0-or-later !
6 : !--------------------------------------------------------------------------------------------------!
7 :
8 : ! **************************************************************************************************
9 : !> \brief Types for all cayley transformation methods
10 : !> \par History
11 : !> 2011.06 created [Rustam Z Khaliullin]
12 : !> \author Rustam Z Khaliullin
13 : ! **************************************************************************************************
14 : MODULE ct_types
15 : USE cp_blacs_env, ONLY: cp_blacs_env_type
16 : USE cp_dbcsr_api, ONLY: dbcsr_copy,&
17 : dbcsr_release,&
18 : dbcsr_type
19 : USE input_constants, ONLY: cg_polak_ribiere,&
20 : tensor_orthogonal
21 : USE kinds, ONLY: dp
22 : USE message_passing, ONLY: mp_para_env_type
23 : #include "./base/base_uses.f90"
24 :
25 : IMPLICIT NONE
26 :
27 : PRIVATE
28 :
29 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'ct_types'
30 :
31 : ! Public types
32 : PUBLIC :: ct_step_env_type
33 :
34 : ! Public subroutines
35 : PUBLIC :: ct_step_env_init, ct_step_env_set, ct_step_env_get, ct_step_env_clean
36 :
37 : TYPE ct_step_env_type
38 :
39 : ! this type contains options for cayley transformation routines
40 :
41 : ! use orbitals or projectors?
42 : LOGICAL :: use_occ_orbs = .FALSE., use_virt_orbs = .FALSE.
43 : LOGICAL :: occ_orbs_orthogonal = .FALSE., virt_orbs_orthogonal = .FALSE.
44 : ! tensor properties of matrix indeces:
45 : ! tensor_up_down, tensor_orthogonal
46 : INTEGER :: tensor_type = 0
47 : ! neglect the quadratic term in riccati equations?
48 : LOGICAL :: neglect_quadratic_term = .FALSE.
49 : ! what kind of output do we produce?
50 : LOGICAL :: update_p = .FALSE., update_q = .FALSE., calculate_energy_corr = .FALSE.
51 : ! variety of conjugate gradient
52 : INTEGER :: conjugator = 0
53 :
54 : ! type of preconditioner
55 : LOGICAL :: pp_preconditioner_full = .FALSE., &
56 : qq_preconditioner_full = .FALSE.
57 :
58 : REAL(KIND=dp) :: eps_convergence = 0.0_dp
59 : REAL(KIND=dp) :: eps_filter = 0.0_dp
60 : INTEGER :: max_iter = 0
61 : !INTEGER :: nspins
62 : LOGICAL :: converged = .FALSE.
63 : INTEGER :: order_lanczos = 0
64 : REAL(KIND=dp) :: eps_lancsoz = 0.0_dp
65 : INTEGER :: max_iter_lanczos = 0
66 :
67 : REAL(KIND=dp) :: energy_correction = 0.0_dp
68 :
69 : ! metric matrices for covariant to contravariant transformations
70 : TYPE(dbcsr_type), POINTER :: p_index_up => NULL()
71 : TYPE(dbcsr_type), POINTER :: p_index_down => NULL()
72 : TYPE(dbcsr_type), POINTER :: q_index_up => NULL()
73 : TYPE(dbcsr_type), POINTER :: q_index_down => NULL()
74 :
75 : ! kohn-sham, covariant-covariant representation
76 : TYPE(dbcsr_type), POINTER :: matrix_ks => NULL()
77 : ! density, contravariant-contravariant representation
78 : TYPE(dbcsr_type), POINTER :: matrix_p => NULL()
79 : ! occ orbitals, contravariant-covariant representation
80 : TYPE(dbcsr_type), POINTER :: matrix_t => NULL()
81 : ! virt orbitals, contravariant-covariant representation
82 : TYPE(dbcsr_type), POINTER :: matrix_v => NULL()
83 :
84 : ! to avoid building Occ-by-N and Virt-vy-N matrices inside
85 : ! the ct routines get them from the external code
86 : TYPE(dbcsr_type), POINTER :: matrix_qp_template => NULL()
87 : TYPE(dbcsr_type), POINTER :: matrix_pq_template => NULL()
88 :
89 : ! guess for single excitation amplitudes
90 : ! it is used exclusively as a guess, not modified
91 : ! it should be given in the up_down representation
92 : TYPE(dbcsr_type), POINTER :: matrix_x_guess => NULL()
93 :
94 : ! single excitation amplitudes
95 : TYPE(dbcsr_type) :: matrix_x
96 : ! residuals
97 : TYPE(dbcsr_type) :: matrix_res
98 :
99 : TYPE(mp_para_env_type), POINTER :: para_env => NULL()
100 : TYPE(cp_blacs_env_type), POINTER :: blacs_env => NULL()
101 :
102 : END TYPE ct_step_env_type
103 :
104 : CONTAINS
105 :
106 : ! **************************************************************************************************
107 : !> \brief ...
108 : !> \param env ...
109 : ! **************************************************************************************************
110 0 : SUBROUTINE ct_step_env_init(env)
111 :
112 : TYPE(ct_step_env_type) :: env
113 :
114 0 : env%use_occ_orbs = .TRUE.
115 0 : env%use_virt_orbs = .FALSE.
116 0 : env%occ_orbs_orthogonal = .FALSE.
117 0 : env%virt_orbs_orthogonal = .FALSE.
118 0 : env%tensor_type = tensor_orthogonal
119 0 : env%neglect_quadratic_term = .FALSE.
120 0 : env%calculate_energy_corr = .TRUE.
121 0 : env%update_p = .FALSE.
122 0 : env%update_q = .FALSE.
123 0 : env%pp_preconditioner_full = .TRUE.
124 0 : env%qq_preconditioner_full = .FALSE.
125 :
126 0 : env%eps_convergence = 1.0E-8_dp
127 0 : env%eps_filter = 1.0E-8_dp
128 0 : env%max_iter = 400
129 0 : env%order_lanczos = 3
130 0 : env%eps_lancsoz = 1.0E-4_dp
131 0 : env%max_iter_lanczos = 40
132 0 : env%converged = .FALSE.
133 0 : env%conjugator = cg_polak_ribiere
134 :
135 0 : NULLIFY (env%p_index_up)
136 0 : NULLIFY (env%p_index_down)
137 0 : NULLIFY (env%q_index_up)
138 0 : NULLIFY (env%q_index_down)
139 :
140 0 : NULLIFY (env%matrix_ks)
141 0 : NULLIFY (env%matrix_p)
142 0 : NULLIFY (env%matrix_t)
143 0 : NULLIFY (env%matrix_v)
144 0 : NULLIFY (env%matrix_x_guess)
145 0 : NULLIFY (env%matrix_qp_template)
146 0 : NULLIFY (env%matrix_pq_template)
147 :
148 : !RZK-warning read_parameters_from_input
149 :
150 0 : END SUBROUTINE ct_step_env_init
151 :
152 : ! **************************************************************************************************
153 : !> \brief ...
154 : !> \param env ...
155 : !> \param use_occ_orbs ...
156 : !> \param use_virt_orbs ...
157 : !> \param tensor_type ...
158 : !> \param occ_orbs_orthogonal ...
159 : !> \param virt_orbs_orthogonal ...
160 : !> \param neglect_quadratic_term ...
161 : !> \param update_p ...
162 : !> \param update_q ...
163 : !> \param eps_convergence ...
164 : !> \param eps_filter ...
165 : !> \param max_iter ...
166 : !> \param p_index_up ...
167 : !> \param p_index_down ...
168 : !> \param q_index_up ...
169 : !> \param q_index_down ...
170 : !> \param matrix_ks ...
171 : !> \param matrix_p ...
172 : !> \param matrix_qp_template ...
173 : !> \param matrix_pq_template ...
174 : !> \param matrix_t ...
175 : !> \param matrix_v ...
176 : !> \param copy_matrix_x ...
177 : !> \param energy_correction ...
178 : !> \param calculate_energy_corr ...
179 : !> \param converged ...
180 : !> \param qq_preconditioner_full ...
181 : !> \param pp_preconditioner_full ...
182 : ! **************************************************************************************************
183 0 : SUBROUTINE ct_step_env_get(env, use_occ_orbs, use_virt_orbs, tensor_type, &
184 : occ_orbs_orthogonal, virt_orbs_orthogonal, neglect_quadratic_term, &
185 : update_p, update_q, eps_convergence, eps_filter, max_iter, &
186 : p_index_up, p_index_down, q_index_up, q_index_down, matrix_ks, matrix_p, &
187 : matrix_qp_template, matrix_pq_template, &
188 : matrix_t, matrix_v, copy_matrix_x, energy_correction, calculate_energy_corr, &
189 : converged, qq_preconditioner_full, pp_preconditioner_full)
190 :
191 : TYPE(ct_step_env_type) :: env
192 : LOGICAL, OPTIONAL :: use_occ_orbs, use_virt_orbs
193 : INTEGER, OPTIONAL :: tensor_type
194 : LOGICAL, OPTIONAL :: occ_orbs_orthogonal, &
195 : virt_orbs_orthogonal, &
196 : neglect_quadratic_term, update_p, &
197 : update_q
198 : REAL(KIND=dp), OPTIONAL :: eps_convergence, eps_filter
199 : INTEGER, OPTIONAL :: max_iter
200 : TYPE(dbcsr_type), OPTIONAL, POINTER :: p_index_up, p_index_down, q_index_up, q_index_down, &
201 : matrix_ks, matrix_p, matrix_qp_template, matrix_pq_template, matrix_t, matrix_v
202 : TYPE(dbcsr_type), OPTIONAL :: copy_matrix_x
203 : REAL(KIND=dp), OPTIONAL :: energy_correction
204 : LOGICAL, OPTIONAL :: calculate_energy_corr, converged, &
205 : qq_preconditioner_full, &
206 : pp_preconditioner_full
207 :
208 0 : IF (PRESENT(use_occ_orbs)) use_occ_orbs = env%use_occ_orbs
209 0 : IF (PRESENT(use_virt_orbs)) use_virt_orbs = env%use_virt_orbs
210 0 : IF (PRESENT(occ_orbs_orthogonal)) occ_orbs_orthogonal = &
211 0 : env%occ_orbs_orthogonal
212 0 : IF (PRESENT(virt_orbs_orthogonal)) virt_orbs_orthogonal = &
213 0 : env%virt_orbs_orthogonal
214 0 : IF (PRESENT(tensor_type)) tensor_type = env%tensor_type
215 0 : IF (PRESENT(neglect_quadratic_term)) neglect_quadratic_term = &
216 0 : env%neglect_quadratic_term
217 0 : IF (PRESENT(calculate_energy_corr)) calculate_energy_corr = &
218 0 : env%calculate_energy_corr
219 0 : IF (PRESENT(update_p)) update_p = env%update_p
220 0 : IF (PRESENT(update_q)) update_q = env%update_q
221 0 : IF (PRESENT(pp_preconditioner_full)) pp_preconditioner_full = &
222 0 : env%pp_preconditioner_full
223 0 : IF (PRESENT(qq_preconditioner_full)) qq_preconditioner_full = &
224 0 : env%qq_preconditioner_full
225 0 : IF (PRESENT(eps_convergence)) eps_convergence = env%eps_convergence
226 0 : IF (PRESENT(eps_filter)) eps_filter = env%eps_filter
227 0 : IF (PRESENT(max_iter)) max_iter = env%max_iter
228 0 : IF (PRESENT(matrix_ks)) matrix_ks => env%matrix_ks
229 0 : IF (PRESENT(matrix_p)) matrix_p => env%matrix_p
230 0 : IF (PRESENT(matrix_t)) matrix_t => env%matrix_t
231 0 : IF (PRESENT(matrix_v)) matrix_v => env%matrix_v
232 0 : IF (PRESENT(matrix_qp_template)) matrix_qp_template => &
233 0 : env%matrix_qp_template
234 0 : IF (PRESENT(matrix_pq_template)) matrix_pq_template => &
235 0 : env%matrix_pq_template
236 0 : IF (PRESENT(p_index_up)) p_index_up => env%p_index_up
237 0 : IF (PRESENT(q_index_up)) q_index_up => env%q_index_up
238 0 : IF (PRESENT(p_index_down)) p_index_down => env%p_index_down
239 0 : IF (PRESENT(q_index_down)) q_index_down => env%q_index_down
240 0 : IF (PRESENT(copy_matrix_x)) THEN
241 0 : CALL dbcsr_copy(copy_matrix_x, env%matrix_x)
242 : END IF
243 0 : IF (PRESENT(energy_correction)) energy_correction = env%energy_correction
244 0 : IF (PRESENT(converged)) converged = env%converged
245 :
246 0 : END SUBROUTINE ct_step_env_get
247 :
248 : ! **************************************************************************************************
249 : !> \brief ...
250 : !> \param env ...
251 : !> \param para_env ...
252 : !> \param blacs_env ...
253 : !> \param use_occ_orbs ...
254 : !> \param use_virt_orbs ...
255 : !> \param tensor_type ...
256 : !> \param occ_orbs_orthogonal ...
257 : !> \param virt_orbs_orthogonal ...
258 : !> \param neglect_quadratic_term ...
259 : !> \param update_p ...
260 : !> \param update_q ...
261 : !> \param eps_convergence ...
262 : !> \param eps_filter ...
263 : !> \param max_iter ...
264 : !> \param p_index_up ...
265 : !> \param p_index_down ...
266 : !> \param q_index_up ...
267 : !> \param q_index_down ...
268 : !> \param matrix_ks ...
269 : !> \param matrix_p ...
270 : !> \param matrix_qp_template ...
271 : !> \param matrix_pq_template ...
272 : !> \param matrix_t ...
273 : !> \param matrix_v ...
274 : !> \param matrix_x_guess ...
275 : !> \param calculate_energy_corr ...
276 : !> \param conjugator ...
277 : !> \param qq_preconditioner_full ...
278 : !> \param pp_preconditioner_full ...
279 : ! **************************************************************************************************
280 0 : SUBROUTINE ct_step_env_set(env, para_env, blacs_env, use_occ_orbs, &
281 : use_virt_orbs, tensor_type, &
282 : occ_orbs_orthogonal, virt_orbs_orthogonal, neglect_quadratic_term, &
283 : update_p, update_q, eps_convergence, eps_filter, max_iter, &
284 : p_index_up, p_index_down, q_index_up, q_index_down, matrix_ks, matrix_p, &
285 : matrix_qp_template, matrix_pq_template, &
286 : matrix_t, matrix_v, matrix_x_guess, calculate_energy_corr, conjugator, &
287 : qq_preconditioner_full, pp_preconditioner_full)
288 :
289 : TYPE(ct_step_env_type) :: env
290 : TYPE(mp_para_env_type), POINTER :: para_env
291 : TYPE(cp_blacs_env_type), POINTER :: blacs_env
292 : LOGICAL, OPTIONAL :: use_occ_orbs, use_virt_orbs
293 : INTEGER, OPTIONAL :: tensor_type
294 : LOGICAL, OPTIONAL :: occ_orbs_orthogonal, &
295 : virt_orbs_orthogonal, &
296 : neglect_quadratic_term, update_p, &
297 : update_q
298 : REAL(KIND=dp), OPTIONAL :: eps_convergence, eps_filter
299 : INTEGER, OPTIONAL :: max_iter
300 : TYPE(dbcsr_type), OPTIONAL, TARGET :: p_index_up, p_index_down, q_index_up, q_index_down, &
301 : matrix_ks, matrix_p, matrix_qp_template, matrix_pq_template, matrix_t, matrix_v, &
302 : matrix_x_guess
303 : LOGICAL, OPTIONAL :: calculate_energy_corr
304 : INTEGER, OPTIONAL :: conjugator
305 : LOGICAL, OPTIONAL :: qq_preconditioner_full, &
306 : pp_preconditioner_full
307 :
308 0 : env%para_env => para_env
309 0 : env%blacs_env => blacs_env
310 :
311 0 : IF (PRESENT(use_occ_orbs)) env%use_occ_orbs = use_occ_orbs
312 0 : IF (PRESENT(use_virt_orbs)) env%use_virt_orbs = use_virt_orbs
313 0 : IF (PRESENT(occ_orbs_orthogonal)) env%occ_orbs_orthogonal = &
314 0 : occ_orbs_orthogonal
315 0 : IF (PRESENT(virt_orbs_orthogonal)) env%virt_orbs_orthogonal = &
316 0 : virt_orbs_orthogonal
317 0 : IF (PRESENT(tensor_type)) env%tensor_type = tensor_type
318 0 : IF (PRESENT(neglect_quadratic_term)) env%neglect_quadratic_term = &
319 0 : neglect_quadratic_term
320 0 : IF (PRESENT(calculate_energy_corr)) env%calculate_energy_corr = &
321 0 : calculate_energy_corr
322 0 : IF (PRESENT(update_p)) env%update_p = update_p
323 0 : IF (PRESENT(update_q)) env%update_q = update_q
324 0 : IF (PRESENT(pp_preconditioner_full)) env%pp_preconditioner_full = &
325 0 : pp_preconditioner_full
326 0 : IF (PRESENT(qq_preconditioner_full)) env%qq_preconditioner_full = &
327 0 : qq_preconditioner_full
328 0 : IF (PRESENT(eps_convergence)) env%eps_convergence = eps_convergence
329 0 : IF (PRESENT(eps_filter)) env%eps_filter = eps_filter
330 0 : IF (PRESENT(max_iter)) env%max_iter = max_iter
331 0 : IF (PRESENT(conjugator)) env%conjugator = conjugator
332 0 : IF (PRESENT(matrix_ks)) env%matrix_ks => matrix_ks
333 0 : IF (PRESENT(matrix_p)) env%matrix_p => matrix_p
334 0 : IF (PRESENT(matrix_t)) env%matrix_t => matrix_t
335 0 : IF (PRESENT(matrix_v)) env%matrix_v => matrix_v
336 0 : IF (PRESENT(matrix_x_guess)) env%matrix_x_guess => matrix_x_guess
337 0 : IF (PRESENT(matrix_qp_template)) env%matrix_qp_template => &
338 0 : matrix_qp_template
339 0 : IF (PRESENT(matrix_pq_template)) env%matrix_pq_template => &
340 0 : matrix_pq_template
341 0 : IF (PRESENT(p_index_up)) env%p_index_up => p_index_up
342 0 : IF (PRESENT(q_index_up)) env%q_index_up => q_index_up
343 0 : IF (PRESENT(p_index_down)) env%p_index_down => p_index_down
344 0 : IF (PRESENT(q_index_down)) env%q_index_down => q_index_down
345 :
346 0 : END SUBROUTINE ct_step_env_set
347 :
348 : ! **************************************************************************************************
349 : !> \brief ...
350 : !> \param env ...
351 : ! **************************************************************************************************
352 0 : SUBROUTINE ct_step_env_clean(env)
353 :
354 : TYPE(ct_step_env_type) :: env
355 :
356 0 : NULLIFY (env%para_env)
357 0 : NULLIFY (env%blacs_env)
358 :
359 : !DO ispin=1,env%nspins
360 0 : CALL dbcsr_release(env%matrix_x)
361 0 : CALL dbcsr_release(env%matrix_res)
362 :
363 0 : NULLIFY (env%p_index_up)
364 0 : NULLIFY (env%p_index_down)
365 0 : NULLIFY (env%q_index_up)
366 0 : NULLIFY (env%q_index_down)
367 :
368 0 : NULLIFY (env%matrix_ks)
369 0 : NULLIFY (env%matrix_p)
370 0 : NULLIFY (env%matrix_t)
371 0 : NULLIFY (env%matrix_v)
372 0 : NULLIFY (env%matrix_x_guess)
373 0 : NULLIFY (env%matrix_qp_template)
374 0 : NULLIFY (env%matrix_pq_template)
375 :
376 0 : END SUBROUTINE ct_step_env_clean
377 :
378 0 : END MODULE ct_types
379 :
|