(git:374b731)
Loading...
Searching...
No Matches
qs_wf_history_types.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief interpolate the wavefunctions to speed up the convergence when
10!> doing MD
11!> \par History
12!> 12.2002 created [fawzi]
13!> 02.2005 wf_mol added [MI]
14!> \author fawzi
15! **************************************************************************************************
18 USE cp_fm_types, ONLY: cp_fm_release,&
20 USE dbcsr_api, ONLY: dbcsr_deallocate_matrix,&
21 dbcsr_p_type,&
22 dbcsr_type
23 USE kinds, ONLY: dp
24 USE pw_types, ONLY: pw_c1d_gs_type,&
26 USE qs_rho_types, ONLY: qs_rho_release,&
28#include "./base/base_uses.f90"
29
30 IMPLICIT NONE
31 PRIVATE
32
33 LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .true.
34 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_wf_history_types'
35
36 PUBLIC :: qs_wf_snapshot_type, &
39
40! **************************************************************************************************
41!> \brief represent a past snapshot of the wavefunction.
42!> some elements might not be associated (to spare memory)
43!> depending on how the snapshot was taken
44!> \param wf the wavefunctions
45!> \param rho_r the density in r space
46!> \param rho_g the density in g space
47!> \param rho_ao the density in ao space
48!> \param overlap the overlap matrix
49!> \param rho_frozen the frozen density structure
50!> \param dt the time of the snapshot (wrf to te previous snapshot!)
51!> \note
52!> keep track also of occupation numbers and energies?
53!> \par History
54!> 02.2003 created [fawzi]
55!> 02.2005 wf_mol added [MI]
56!> \author fawzi
57! **************************************************************************************************
59 TYPE(cp_fm_type), DIMENSION(:), POINTER :: wf
60 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho_r
61 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_g
62 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: rho_ao
63 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: rho_ao_kp
64 TYPE(dbcsr_type), POINTER :: overlap
65 TYPE(qs_rho_type), POINTER :: rho_frozen
66 REAL(kind=dp) :: dt
67 END TYPE qs_wf_snapshot_type
68
69! **************************************************************************************************
70!> \brief pointer to a snapshot
71!> \param snapshot the pointer to the snapshot
72!> \par History
73!> 02.2003 created [fawzi]
74!> \author fawzi
75! **************************************************************************************************
76 TYPE qs_wf_snapshot_p_type
77 TYPE(qs_wf_snapshot_type), POINTER :: snapshot
78 END TYPE qs_wf_snapshot_p_type
79
80! **************************************************************************************************
81!> \brief keeps track of the previous wavefunctions and can extrapolate them
82!> for the next step of md
83!> \param ref_cont reference count (see doc/ReferenceCounting.html)
84!> \param memory_depth how many snapshots should be stored
85!> \param last_state_index index of the latest snapshot
86!> \param past_states array with the past states (index starts at
87!> last_state_index)
88!> \param interpolation_method_nr the tag of the method used to
89!> extrapolate the new start state for qs
90!> \param snapshot_count number of snapshot taken so far (cumulative,
91!> can be bigger than the history depth)
92!> \note
93!> use a linked list for the past states ?
94!> \par History
95!> 02.2003 created [fawzi]
96!> \author fawzi
97! **************************************************************************************************
99 INTEGER :: ref_count, memory_depth, last_state_index, &
100 interpolation_method_nr, snapshot_count
101 LOGICAL :: store_wf, store_rho_r, store_rho_g, store_rho_ao, store_rho_ao_kp, &
102 store_overlap, store_frozen_density
103 TYPE(qs_wf_snapshot_p_type), DIMENSION(:), POINTER :: past_states
104 END TYPE qs_wf_history_type
105
106! **************************************************************************************************
107!> \brief to create arrays of pointers to qs_wf_history_type
108!> \param wf_hist the pointer to the wf history
109!> \author fawzi
110! **************************************************************************************************
112 TYPE(qs_wf_history_type), POINTER :: wf_history
113 END TYPE qs_wf_history_p_type
114
115CONTAINS
116
117! **************************************************************************************************
118!> \brief releases a snapshot of a wavefunction (see doc/ReferenceCounting.html)
119!> \param snapshot the snapshot to release
120!> \par History
121!> 02.2003 created [fawzi]
122!> 02.2005 wf_mol added [MI]
123!> \author fawzi
124! **************************************************************************************************
125 SUBROUTINE wfs_release(snapshot)
126 TYPE(qs_wf_snapshot_type), INTENT(INOUT) :: snapshot
127
128 CALL cp_fm_release(snapshot%wf)
129 ! snapshot%rho_r & snapshot%rho_g is deallocated in wfs_update
130 ! of qs_wf_history_methods, in case you wonder about it.
131 IF (ASSOCIATED(snapshot%rho_ao)) THEN
132 CALL dbcsr_deallocate_matrix_set(snapshot%rho_ao)
133 END IF
134 IF (ASSOCIATED(snapshot%rho_ao_kp)) THEN
135 CALL dbcsr_deallocate_matrix_set(snapshot%rho_ao_kp)
136 END IF
137 IF (ASSOCIATED(snapshot%overlap)) THEN
138 CALL dbcsr_deallocate_matrix(snapshot%overlap)
139 END IF
140 IF (ASSOCIATED(snapshot%rho_frozen)) THEN
141 CALL qs_rho_release(snapshot%rho_frozen)
142 DEALLOCATE (snapshot%rho_frozen)
143 END IF
144
145 END SUBROUTINE wfs_release
146
147! **************************************************************************************************
148!> \brief retains a wf history (see doc/ReferenceCounting.html)
149!> \param wf_history the wf_history to retain
150!> \par History
151!> 02.2003 created [fawzi]
152!> \author fawzi
153! **************************************************************************************************
154 SUBROUTINE wfi_retain(wf_history)
155 TYPE(qs_wf_history_type), POINTER :: wf_history
156
157 cpassert(ASSOCIATED(wf_history))
158 wf_history%ref_count = wf_history%ref_count + 1
159
160 END SUBROUTINE wfi_retain
161
162! **************************************************************************************************
163!> \brief releases a wf_history of a wavefunction
164!> (see doc/ReferenceCounting.html)
165!> \param wf_history the wf_history to release
166!> \par History
167!> 02.2003 created [fawzi]
168!> \author fawzi
169! **************************************************************************************************
170 SUBROUTINE wfi_release(wf_history)
171 TYPE(qs_wf_history_type), POINTER :: wf_history
172
173 INTEGER :: i
174
175 IF (ASSOCIATED(wf_history)) THEN
176 cpassert(wf_history%ref_count > 0)
177 wf_history%ref_count = wf_history%ref_count - 1
178 IF (wf_history%ref_count == 0) THEN
179 IF (ASSOCIATED(wf_history%past_states)) THEN
180 DO i = 1, SIZE(wf_history%past_states)
181 IF (ASSOCIATED(wf_history%past_states(i)%snapshot)) THEN
182 CALL wfs_release(wf_history%past_states(i)%snapshot)
183 DEALLOCATE (wf_history%past_states(i)%snapshot)
184 END IF
185 END DO
186 DEALLOCATE (wf_history%past_states)
187 END IF
188 DEALLOCATE (wf_history)
189 END IF
190 END IF
191 NULLIFY (wf_history)
192 END SUBROUTINE wfi_release
193
194! **************************************************************************************************
195!> \brief returns a snapshot, the first being the latest snapshot
196!> \param wf_history the plage where to get the snapshot
197!> \param wf_index the index of the snapshot you want
198!> \return ...
199!> \par History
200!> 12.2002 created [fawzi]
201!> \author fawzi
202! **************************************************************************************************
203 FUNCTION wfi_get_snapshot(wf_history, wf_index) RESULT(res)
204 TYPE(qs_wf_history_type), POINTER :: wf_history
205 INTEGER, INTENT(in) :: wf_index
206 TYPE(qs_wf_snapshot_type), POINTER :: res
207
208 NULLIFY (res)
209
210 cpassert(ASSOCIATED(wf_history))
211 cpassert(ASSOCIATED(wf_history%past_states))
212 IF (wf_index > wf_history%memory_depth .OR. wf_index > wf_history%snapshot_count) THEN
213 cpabort("")
214 END IF
215 res => wf_history%past_states( &
216 modulo(wf_history%snapshot_count + 1 - wf_index, &
217 wf_history%memory_depth) + 1)%snapshot
218 END FUNCTION wfi_get_snapshot
219
220END MODULE qs_wf_history_types
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
DBCSR operations in CP2K.
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
superstucture that hold various representations of the density and keeps track of which ones are vali...
subroutine, public qs_rho_release(rho_struct)
releases a rho_struct by decreasing the reference count by one and deallocating if it reaches 0 (to b...
interpolate the wavefunctions to speed up the convergence when doing MD
type(qs_wf_snapshot_type) function, pointer, public wfi_get_snapshot(wf_history, wf_index)
returns a snapshot, the first being the latest snapshot
subroutine, public wfi_retain(wf_history)
retains a wf history (see doc/ReferenceCounting.html)
subroutine wfs_release(snapshot)
releases a snapshot of a wavefunction (see doc/ReferenceCounting.html)
subroutine, public wfi_release(wf_history)
releases a wf_history of a wavefunction (see doc/ReferenceCounting.html)
represent a full matrix
keeps the density in various representations, keeping track of which ones are valid.
to create arrays of pointers to qs_wf_history_type
keeps track of the previous wavefunctions and can extrapolate them for the next step of md
represent a past snapshot of the wavefunction. some elements might not be associated (to spare memory...