Octopus
opt_control_state.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
21
25 use debug_oct_m
26 use global_oct_m
27 use ions_oct_m
32
33 implicit none
34
35 private
36 public :: &
48
49
54 private
55 type(states_elec_t) :: psi
56 real(real64), allocatable :: q(:, :)
57 real(real64), allocatable :: p(:, :)
58 integer :: natoms, ndim
59 end type opt_control_state_t
60
61contains
62
63
64 subroutine opt_control_state_null(ocs)
65 type(opt_control_state_t), intent(inout) :: ocs
66
68
69 safe_deallocate_a(ocs%q)
70 safe_deallocate_a(ocs%p)
71 call ocs%psi%nullify()
72
74 end subroutine opt_control_state_null
75
76
77 function opt_control_point_qs(ocs)
78 type(opt_control_state_t), target, intent(in) :: ocs
79 type(states_elec_t), pointer :: opt_control_point_qs
80
81 push_sub(opt_control_point_qs)
82
83 opt_control_point_qs => ocs%psi
84
85 pop_sub(opt_control_point_qs)
86 end function opt_control_point_qs
87
88 function opt_control_point_q(ocs)
89 type(opt_control_state_t), target, intent(in) :: ocs
90 real(real64), pointer :: opt_control_point_q(:, :)
91
92 push_sub(opt_control_point_q)
93
94 opt_control_point_q => ocs%q
95
96 pop_sub(opt_control_point_q)
97 end function opt_control_point_q
98
99 function opt_control_point_p(ocs)
100 type(opt_control_state_t), target, intent(in) :: ocs
101 real(real64), pointer :: opt_control_point_p(:, :)
102
103 push_sub(opt_control_point_p)
104
105 opt_control_point_p => ocs%p
106
107 pop_sub(opt_control_point_p)
108 end function opt_control_point_p
109
110 subroutine opt_control_get_qs(qstate, ocs)
111 type(states_elec_t), intent(inout) :: qstate
112 type(opt_control_state_t), intent(in) :: ocs
113
114 push_sub(opt_control_get_qs)
115
116 call states_elec_copy(qstate, ocs%psi)
118 pop_sub(opt_control_get_qs)
119 end subroutine opt_control_get_qs
120
121 subroutine opt_control_get_classical(ions, ocs)
122 type(ions_t), intent(inout) :: ions
123 type(opt_control_state_t), intent(in) :: ocs
124
125 integer :: idim, iatom
126
128
129 do idim = 1, ions%space%dim
130 do iatom = 1, ions%natoms
131 ions%pos(idim, iatom) = ocs%q(iatom, idim)
132 ions%vel(idim, iatom) = ocs%p(iatom, idim) / ions%mass(iatom)
133 end do
134 end do
135
137 end subroutine opt_control_get_classical
138
139 subroutine opt_control_set_classical(ions, ocs)
140 type(ions_t), intent(inout) :: ions
141 type(opt_control_state_t), intent(inout) :: ocs
142
143 integer :: idim, iatom
144
147 do idim = 1, ions%space%dim
148 do iatom = 1, ions%natoms
149 ocs%q(iatom, idim) = ions%pos(idim, iatom)
150 ocs%p(iatom, idim) = ions%vel(idim, iatom) * ions%mass(iatom)
151 end do
152 end do
153
155 end subroutine opt_control_set_classical
156
157 subroutine opt_control_state_init(ocs, qstate, ions)
158 type(opt_control_state_t), intent(inout) :: ocs
159 type(states_elec_t), intent(in) :: qstate
160 type(ions_t), intent(in) :: ions
161
162 integer :: iatom, idim
163
164 push_sub(opt_control_state_init)
165
166 call states_elec_copy(ocs%psi, qstate)
167
168 safe_deallocate_a(ocs%q)
169 safe_deallocate_a(ocs%p)
171 ocs%ndim = ions%space%dim
172 ocs%natoms = ions%natoms
173
174 safe_allocate(ocs%q(1:ocs%natoms, 1:ocs%ndim))
175 safe_allocate(ocs%p(1:ocs%natoms, 1:ocs%ndim))
176
177 do idim = 1, ions%space%dim
178 do iatom = 1, ions%natoms
179 ocs%q(iatom, idim) = ions%pos(idim, iatom)
180 ocs%p(iatom, idim) = ions%mass(iatom) * ions%vel(idim, iatom)
181 end do
182 end do
183
185 end subroutine opt_control_state_init
186
187 subroutine opt_control_state_end(ocs)
188 type(opt_control_state_t), intent(inout) :: ocs
189
190 push_sub(opt_control_state_end)
191
192 call states_elec_end(ocs%psi)
193
194 safe_deallocate_a(ocs%q)
195 safe_deallocate_a(ocs%p)
196
197 pop_sub(opt_control_state_end)
198 end subroutine opt_control_state_end
199
200 subroutine opt_control_state_copy(ocsout, ocsin)
201 type(opt_control_state_t), intent(in) :: ocsin
202 type(opt_control_state_t), intent(inout) :: ocsout
204 push_sub(opt_control_state_copy)
205
206 call states_elec_end(ocsout%psi)
207 call states_elec_copy(ocsout%psi, ocsin%psi)
208 ocsout%ndim = ocsin%ndim
209 ocsout%natoms = ocsin%natoms
210 safe_deallocate_a(ocsout%q)
211 safe_deallocate_a(ocsout%p)
212 if (allocated(ocsin%q)) then
213 safe_allocate(ocsout%q(1:ocsout%natoms, 1:ocsout%ndim))
214 ocsout%q = ocsin%q
215 end if
216 if (allocated(ocsin%p)) then
217 safe_allocate(ocsout%p(1:ocsout%natoms, 1:ocsout%ndim))
218 ocsout%p = ocsin%p
219 end if
220
222 end subroutine opt_control_state_copy
223
This module holds the "opt_control_state_t" datatype, which contains a quantum-classical state.
real(real64) function, dimension(:, :), pointer, public opt_control_point_p(ocs)
subroutine, public opt_control_set_classical(ions, ocs)
real(real64) function, dimension(:, :), pointer, public opt_control_point_q(ocs)
type(states_elec_t) function, pointer, public opt_control_point_qs(ocs)
subroutine, public opt_control_state_end(ocs)
subroutine, public opt_control_state_null(ocs)
subroutine, public opt_control_state_copy(ocsout, ocsin)
subroutine, public opt_control_state_init(ocs, qstate, ions)
subroutine, public opt_control_get_classical(ions, ocs)
subroutine, public opt_control_get_qs(qstate, ocs)
subroutine, public states_elec_end(st)
finalize the states_elec_t object
subroutine, public states_elec_copy(stout, stin, exclude_wfns, exclude_eigenval, special)
make a (selective) copy of a states_elec_t object
This is the datatype that contains the objects that are propagated: in principle this could be both t...
The states_elec_t class contains all electronic wave functions.