Octopus
target_excited.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
22 use debug_oct_m
24 use epot_oct_m
26 use global_oct_m
27 use grid_oct_m
29 use io_oct_m
30 use ions_oct_m
32 use, intrinsic :: iso_fortran_env
36 use mesh_oct_m
42 use output_oct_m
46 use space_oct_m
50 use target_oct_m
51 use td_oct_m
52 use types_oct_m
53
54 implicit none
55
56 private
57 public :: target_excited_t
58
60 type, extends(target_t) :: target_excited_t
61 private
62 type(excited_states_t) :: est
63 contains
64 procedure :: init => target_init_excited
65 procedure :: j1 => target_j1_excited
66 procedure :: apply_chi => target_chi_excited
67 procedure :: output => target_output_excited
68 end type target_excited_t
69
70
71contains
72
73
74 ! ----------------------------------------------------------------------
76 subroutine target_init_excited(tg, gr, kpoints, namespace, space, ions, qcs, td, w0, oct, ep, restart)
77 class(target_excited_t), intent(inout) :: tg
78 type(grid_t), intent(in) :: gr
79 type(kpoints_t), intent(in) :: kpoints
80 type(namespace_t), intent(in) :: namespace
81 class(space_t), intent(in) :: space
82 type(ions_t), intent(in) :: ions
83 type(opt_control_state_t), intent(inout) :: qcs
84 type(td_t), intent(in) :: td
85 real(real64), intent(in) :: w0
86 type(oct_t), intent(in) :: oct
87 type(epot_t), intent(inout) :: ep
88 type(restart_t), intent(inout) :: restart
89
90 integer :: ierr, nik, dim
91
92 push_sub(target_init_excited)
93
94 message(1) = 'Info: TargetOperator is a linear combination of Slater determinants.'
95 call messages_info(1, namespace=namespace)
96
97 tg%move_ions = td%ions_dyn%ions_move()
98 tg%dt = td%dt
99
100 call states_elec_look(restart, nik, dim, tg%st%nst, ierr)
101 if (ierr /= 0) then
102 message(1) = "Unable to read states information."
103 call messages_fatal(1, namespace=namespace)
104 end if
105 tg%st%st_start = 1
106 tg%st%st_end = tg%st%nst
107
108 safe_deallocate_a(tg%st%occ)
109 safe_deallocate_a(tg%st%eigenval)
110 safe_deallocate_a(tg%st%node)
111
112 safe_allocate( tg%st%occ(1:tg%st%nst, 1:tg%st%nik))
113 safe_allocate(tg%st%eigenval(1:tg%st%nst, 1:tg%st%nik))
114 safe_allocate( tg%st%node(1:tg%st%nst))
115 if (tg%st%d%ispin == spinors) then
116 safe_deallocate_a(tg%st%spin)
117 safe_allocate(tg%st%spin(1:3, 1:tg%st%nst, 1:tg%st%nik))
118 end if
120 tg%st%node(:) = 0
121
122 call states_elec_load(restart, namespace, space, tg%st, gr, kpoints, fixed_occ=.true., ierr=ierr)
123 if (ierr /= 0) then
124 message(1) = "Unable to read wavefunctions."
125 call messages_fatal(1, namespace=namespace)
126 end if
127
128 call excited_states_init(tg%est, tg%st, "oct-excited-state-target", namespace)
129
130 pop_sub(target_init_excited)
131 end subroutine target_init_excited
132
133
134 ! ----------------------------------------------------------------------
135 subroutine target_output_excited(tg, namespace, space, gr, dir, ions, hm, outp)
136 class(target_excited_t), intent(inout) :: tg
137 type(namespace_t), intent(in) :: namespace
138 class(space_t), intent(in) :: space
139 type(grid_t), intent(in) :: gr
140 character(len=*), intent(in) :: dir
141 type(ions_t), intent(in) :: ions
142 type(hamiltonian_elec_t), intent(in) :: hm
143 type(output_t), intent(in) :: outp
144
145 push_sub(target_output_excited)
146
147 call io_mkdir(trim(dir), namespace)
148 call output_states(outp, namespace, space, trim(dir)//'/st', tg%est%st, gr, ions, hm, -1)
149 call excited_states_output(tg%est, trim(dir), namespace)
150
151 pop_sub(target_output_excited)
152 end subroutine target_output_excited
153 ! ----------------------------------------------------------------------
154
156 ! ----------------------------------------------------------------------
158 real(real64) function target_j1_excited(tg, namespace, gr, kpoints, qcpsi, ions) result(j1)
159 class(target_excited_t), intent(inout) :: tg
160 type(namespace_t), intent(in) :: namespace
161 type(grid_t), intent(in) :: gr
162 type(kpoints_t), intent(in) :: kpoints
163 type(opt_control_state_t), intent(inout) :: qcpsi
164 type(ions_t), optional, intent(in) :: ions
165
166 type(states_elec_t), pointer :: psi
167
168 push_sub(target_j1_excited)
169
170 psi => opt_control_point_qs(qcpsi)
172 j1 = abs(zstates_elec_mpdotp(namespace, gr, tg%est, psi))**2
173
174 nullify(psi)
175 pop_sub(target_j1_excited)
176 end function target_j1_excited
177
178
179 ! ----------------------------------------------------------------------
181 subroutine target_chi_excited(tg, namespace, gr, kpoints, qcpsi_in, qcchi_out, ions)
182 class(target_excited_t), intent(inout) :: tg
183 type(namespace_t), intent(in) :: namespace
184 type(grid_t), intent(in) :: gr
185 type(kpoints_t), intent(in) :: kpoints
186 type(opt_control_state_t), target, intent(inout) :: qcpsi_in
187 type(opt_control_state_t), target, intent(inout) :: qcchi_out
188 type(ions_t), intent(in) :: ions
189
190 complex(real64), allocatable :: cI(:), dI(:), mat(:, :, :), mm(:, :, :, :), mk(:, :), lambda(:, :)
191 complex(real64), allocatable :: zpsi(:, :), zchi(:, :)
192 integer :: ik, ist, jst, ia, ib, n_pairs, nst, nik, jj, idim, ip
193 type(states_elec_t), pointer :: psi_in, chi_out
194 push_sub(target_chi_excited)
195
196 psi_in => opt_control_point_qs(qcpsi_in)
197 chi_out => opt_control_point_qs(qcchi_out)
198
199 n_pairs = tg%est%n_pairs
200 nik = psi_in%nik
201 nst = psi_in%nst
202
203
204 safe_allocate(zpsi(1:gr%np, 1:psi_in%d%dim))
205 safe_allocate(zchi(1:gr%np, 1:psi_in%d%dim))
206 safe_allocate(ci(1:n_pairs))
207 safe_allocate(di(1:n_pairs))
208 safe_allocate(mat(1:tg%est%st%nst, 1:nst, 1:psi_in%nik))
209 safe_allocate(mm(1:nst, 1:nst, 1:nik, 1:n_pairs))
210 safe_allocate(mk(1:gr%np_part, 1:psi_in%d%dim))
211 safe_allocate(lambda(1:n_pairs, 1:n_pairs))
212
213 call zstates_elec_matrix(tg%est%st, psi_in, gr, mat)
214
215 do ia = 1, n_pairs
216 ci(ia) = tg%est%weight(ia)
217 call zstates_elec_matrix_swap(mat, tg%est%pair(ia))
218 mm(1:nst, 1:nst, 1:nik, ia) = mat(1:nst, 1:nik, 1:nik)
219 di(ia) = zstates_elec_mpdotp(namespace, gr, tg%est%st, psi_in, mat)
220 if (abs(di(ia)) > 1.0e-12_real64) then
221 do ik = 1, nik
222 call lalg_inverse(nst, mm(1:nst, 1:nst, ik, ia), 'dir')
223 end do
224 end if
225 call zstates_elec_matrix_swap(mat, tg%est%pair(ia))
226 end do
227
228 do ia = 1, n_pairs
229 do ib = 1, n_pairs
230 lambda(ia, ib) = conjg(ci(ib)) * ci(ia) * conjg(di(ia)) * di(ib)
231 end do
232 end do
233
234 select case (psi_in%d%ispin)
235 case (unpolarized)
236 write(message(1), '(a)') 'Internal error in target.target_chi: unpolarized.'
237 call messages_fatal(1, namespace=namespace)
238
239 case (spin_polarized)
240 assert(chi_out%nik == 2)
241
242 do ik = 1, nik
243 do ist = chi_out%st_start, chi_out%st_end
244
245 zchi(1:gr%np, 1:psi_in%d%dim) = m_z0
246
247 do ia = 1, n_pairs
248 if (ik /= tg%est%pair(ia)%kk) cycle
249 if (abs(di(ia)) < 1.0e-12_real64) cycle
250 do ib = 1, n_pairs
251 if (abs(di(ib)) < 1.0e-12_real64) cycle
252 mk = m_z0
254 do jst = 1, nst
255 if (jst == tg%est%pair(ib)%i) jj = tg%est%pair(ia)%a
256 call states_elec_get_state(tg%est%st, gr, jj, ik, zpsi)
257
258 do idim = 1, psi_in%d%dim
259 do ip = 1, gr%np
260 mk(ip, idim) = mk(ip, idim) + conjg(mm(ist, jst, ik, ib))*zpsi(ip, idim)
261 end do
262 end do
263 end do
264
265 call lalg_axpy(gr%np_part, psi_in%d%dim, m_z1*lambda(ib, ia), mk, zchi)
266
267 end do
268 end do
269
270 call states_elec_set_state(chi_out, gr, ist, ik, zchi)
271
272 end do
273 end do
274
275 case (spinors)
276 assert(chi_out%nik == 1)
277
278 do ist = chi_out%st_start, chi_out%st_end
279
280 zchi(1:gr%np, 1:psi_in%d%dim) = m_z0
281
282 do ia = 1, n_pairs
283 if (abs(di(ia)) < 1.0e-12_real64) cycle
284
285 do ib = 1, n_pairs
286 if (abs(di(ib)) < 1.0e-12_real64) cycle
287
288 mk = m_z0
289 do jst = 1, nst
290 if (jst == tg%est%pair(ib)%i) jj = tg%est%pair(ia)%a
291 call states_elec_get_state(tg%est%st, gr, jj, ik, zpsi)
292
293 do idim = 1, psi_in%d%dim
294 do ip = 1, gr%np
295 mk(ip, idim) = mk(ip, idim) + conjg(mm(ist, jst, 1, ib))*zpsi(ip, idim)
296 end do
297 end do
298 end do
299
300 call lalg_axpy(gr%np_part, 2, m_z1*lambda(ib, ia), mk, zchi)
301 end do
302 end do
303
304 call states_elec_set_state(chi_out, gr, ist, ik, zchi)
305
306 end do
307
308 end select
309
310 safe_deallocate_a(zpsi)
311 safe_deallocate_a(zchi)
312 safe_deallocate_a(ci)
313 safe_deallocate_a(di)
314 safe_deallocate_a(mat)
315 safe_deallocate_a(mm)
316 safe_deallocate_a(mk)
317 safe_deallocate_a(lambda)
318 nullify(psi_in)
319 nullify(chi_out)
320 pop_sub(target_chi_excited)
321 end subroutine target_chi_excited
322
323end module target_excited_oct_m
324
325!! Local Variables:
326!! mode: f90
327!! coding: utf-8
328!! End:
integer, parameter, public spinors
subroutine, public excited_states_output(excited_state, dirname, namespace)
subroutine, public excited_states_init(excited_state, ground_state, filename, namespace)
Fills in an excited_state structure, by reading a file called "filename". This file describes the "pr...
This module implements the underlying real-space grid.
Definition: grid.F90:119
Definition: io.F90:116
subroutine, public io_mkdir(fname, namespace, parents)
Definition: io.F90:361
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:120
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:162
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:410
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:594
This module contains the definition of the oct_t data type, which contains some of the basic informat...
This module holds the "opt_control_state_t" datatype, which contains a quantum-classical state.
type(states_elec_t) function, pointer, public opt_control_point_qs(ocs)
this module contains the low-level part of the output system
Definition: output_low.F90:117
this module contains the output system
Definition: output.F90:117
subroutine, public output_states(outp, namespace, space, dir, st, gr, ions, hm, iter)
Definition: output.F90:1091
subroutine, public states_elec_allocate_wfns(st, mesh, wfs_type, skip, packed)
Allocates the KS wavefunctions defined within a states_elec_t structure.
subroutine, public states_elec_look(restart, nik, dim, nst, ierr)
Reads the 'states' file in the restart directory, and finds out the nik, dim, and nst contained in it...
This module handles reading and writing restart information for the states_elec_t.
subroutine, public states_elec_load(restart, namespace, space, st, mesh, kpoints, fixed_occ, ierr, iter, lr, lowest_missing, label, verbose, skip)
returns in ierr: <0 => Fatal error, or nothing read =0 => read all wavefunctions >0 => could only rea...
subroutine target_output_excited(tg, namespace, space, gr, dir, ions, hm, outp)
real(real64) function target_j1_excited(tg, namespace, gr, kpoints, qcpsi, ions)
subroutine target_chi_excited(tg, namespace, gr, kpoints, qcpsi_in, qcchi_out, ions)
subroutine target_init_excited(tg, gr, kpoints, namespace, space, ions, qcs, td, w0, oct, ep, restart)
Optimal-control targets: abstract base class and public interface.
Definition: target.F90:132
Definition: td.F90:116
type(type_t), parameter, public type_cmplx
Definition: types.F90:136
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:171
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.
Target projecting onto a linear combination of Slater determinants.
Abstract optimal-control target.
Definition: target.F90:172
int true(void)