Octopus
target_gstransformation.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
25 use global_oct_m
26 use grid_oct_m
28 use io_oct_m
29 use ions_oct_m
31 use, intrinsic :: iso_fortran_env
38 use output_oct_m
40 use parser_oct_m
43 use space_oct_m
46 use target_oct_m
47 use td_oct_m
48
49 implicit none
50
51 private
53
55 type, extends(target_t) :: target_gstransformation_t
56 contains
57 procedure :: init => target_init_gstransformation
58 procedure :: j1 => target_j1_gstransformation
59 procedure :: apply_chi => target_chi_gstransformation
60 procedure :: output => target_output_gstransformation
62
63
64contains
65
66 ! ----------------------------------------------------------------------
68 subroutine target_init_gstransformation(tg, gr, kpoints, namespace, space, ions, qcs, td, w0, oct, ep, restart)
69 class(target_gstransformation_t), intent(inout) :: tg
70 type(grid_t), intent(in) :: gr
71 type(kpoints_t), intent(in) :: kpoints
72 type(namespace_t), intent(in) :: namespace
73 class(space_t), intent(in) :: space
74 type(ions_t), intent(in) :: ions
75 type(opt_control_state_t), intent(inout) :: qcs
76 type(td_t), intent(in) :: td
77 real(real64), intent(in) :: w0
78 type(oct_t), intent(in) :: oct
79 type(epot_t), intent(inout) :: ep
80 type(restart_t), intent(inout) :: restart
81
83
84 message(1) = 'Info: Using Superposition of States for TargetOperator'
85 call messages_info(1, namespace=namespace)
86
87 tg%move_ions = td%ions_dyn%ions_move()
88 tg%dt = td%dt
89
90 !%Variable OCTTargetTransformStates
91 !%Type block
92 !%Default no
93 !%Section Calculation Modes::Optimal Control
94 !%Description
95 !% If <tt>OCTTargetOperator = oct_tg_gstransformation</tt>, you must specify a
96 !% <tt>OCTTargetTransformStates</tt> block, in order to specify which linear
97 !% combination of the states present in <tt>restart/gs</tt> is used to
98 !% create the target state.
99 !%
100 !% The syntax is the same as the <tt>TransformStates</tt> block.
101 !%End
102 call states_elec_transform(tg%st, namespace, space, restart, gr, kpoints, prefix = "OCTTarget")
103
104 if (.not. parse_is_defined(namespace, 'OCTTargetTransformStates')) then
105 message(1) = 'If "OCTTargetOperator = oct_tg_superposition", then you must'
106 message(2) = 'supply an "OCTTargetTransformStates" block to create the superposition.'
107 call messages_fatal(2, namespace=namespace)
108 end if
109 call density_calc(tg%st, gr, tg%st%rho)
110
112 end subroutine target_init_gstransformation
113
114
115 ! ----------------------------------------------------------------------
116 subroutine target_output_gstransformation(tg, namespace, space, gr, dir, ions, hm, outp)
117 class(target_gstransformation_t), intent(inout) :: tg
118 type(namespace_t), intent(in) :: namespace
119 class(space_t), intent(in) :: space
120 type(grid_t), intent(in) :: gr
121 character(len=*), intent(in) :: dir
122 type(ions_t), intent(in) :: ions
123 type(hamiltonian_elec_t), intent(in) :: hm
124 type(output_t), intent(in) :: outp
126
127 call io_mkdir(trim(dir), namespace)
128 call output_states(outp, namespace, space, trim(dir), tg%st, gr, ions, hm, -1)
129
131 end subroutine target_output_gstransformation
132 ! ----------------------------------------------------------------------
133
134
135
136 ! ----------------------------------------------------------------------
138 real(real64) function target_j1_gstransformation(tg, namespace, gr, kpoints, qcpsi, ions) result(j1)
139 class(target_gstransformation_t), intent(inout) :: tg
140 type(namespace_t), intent(in) :: namespace
141 type(grid_t), intent(in) :: gr
142 type(kpoints_t), intent(in) :: kpoints
143 type(opt_control_state_t), intent(inout) :: qcpsi
144 type(ions_t), optional, intent(in) :: ions
145
146 integer :: ik, ist
147
148 complex(real64), allocatable :: zpsi(:, :), zst(:, :)
149 type(states_elec_t), pointer :: psi
151 push_sub(target_j1_gstransformation)
155 safe_allocate(zpsi(1:gr%np, 1:tg%st%d%dim))
156 safe_allocate(zst(1:gr%np, 1:tg%st%d%dim))
157
158 j1 = m_zero
159 do ik = 1, psi%nik
160 do ist = psi%st_start, psi%st_end
161
162 call states_elec_get_state(psi, gr, ist, ik, zpsi)
163 call states_elec_get_state(tg%st, gr, ist, ik, zst)
164
165 j1 = j1 + abs(zmf_dotp(gr, psi%d%dim, zpsi, zst))**2
166
167 end do
168 end do
169
170 safe_deallocate_a(zpsi)
171 safe_deallocate_a(zst)
172
173 nullify(psi)
174 pop_sub(target_j1_gstransformation)
175 end function target_j1_gstransformation
176
177
178 ! ----------------------------------------------------------------------
180 subroutine target_chi_gstransformation(tg, namespace, gr, kpoints, qcpsi_in, qcchi_out, ions)
181 class(target_gstransformation_t), intent(inout) :: tg
182 type(namespace_t), intent(in) :: namespace
183 type(grid_t), intent(in) :: gr
184 type(kpoints_t), intent(in) :: kpoints
185 type(opt_control_state_t), target, intent(inout) :: qcpsi_in
186 type(opt_control_state_t), target, intent(inout) :: qcchi_out
187 type(ions_t), intent(in) :: ions
188
189 integer :: ik, ist
190 complex(real64) :: olap
191 complex(real64), allocatable :: zpsi(:, :), zst(:, :), zchi(:, :)
192 type(states_elec_t), pointer :: psi_in, chi_out
193
195
196 psi_in => opt_control_point_qs(qcpsi_in)
197 chi_out => opt_control_point_qs(qcchi_out)
198
199 safe_allocate(zpsi(1:gr%np, 1:tg%st%d%dim))
200 safe_allocate(zst(1:gr%np, 1:tg%st%d%dim))
201 safe_allocate(zchi(1:gr%np, 1:tg%st%d%dim))
202
203 do ik = 1, psi_in%nik
204 do ist = psi_in%st_start, psi_in%st_end
205
206 call states_elec_get_state(psi_in, gr, ist, ik, zpsi)
207 call states_elec_get_state(tg%st, gr, ist, ik, zst)
208
209 olap = zmf_dotp(gr, zst(:, 1), zpsi(:, 1))
210 zchi(1:gr%np, 1:tg%st%d%dim) = olap*zst(1:gr%np, 1:tg%st%d%dim)
212 call states_elec_set_state(chi_out, gr, ist, ik, zchi)
213
214 end do
215 end do
216
217 safe_deallocate_a(zpsi)
218 safe_deallocate_a(zst)
219 safe_deallocate_a(zchi)
220
221 nullify(psi_in)
222 nullify(chi_out)
224 end subroutine target_chi_gstransformation
225
227
228!! Local Variables:
229!! mode: f90
230!! coding: utf-8
231!! End:
This module implements a calculator for the density and defines related functions.
Definition: density.F90:122
subroutine, public density_calc(st, gr, density, istin)
Computes the density from the orbitals in st.
Definition: density.F90:653
real(real64), parameter, public m_zero
Definition: global.F90:200
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.
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
logical function, public parse_is_defined(namespace, name)
Definition: parser.F90:463
This module handles reading and writing restart information for the states_elec_t.
subroutine, public states_elec_transform(st, namespace, space, restart, mesh, kpoints, prefix)
subroutine target_init_gstransformation(tg, gr, kpoints, namespace, space, ions, qcs, td, w0, oct, ep, restart)
subroutine target_chi_gstransformation(tg, namespace, gr, kpoints, qcpsi_in, qcchi_out, ions)
real(real64) function target_j1_gstransformation(tg, namespace, gr, kpoints, qcpsi, ions)
subroutine target_output_gstransformation(tg, namespace, space, gr, dir, ions, hm, outp)
Optimal-control targets: abstract base class and public interface.
Definition: target.F90:132
Definition: td.F90:116
Target projecting onto a transformation of the ground state.
Abstract optimal-control target.
Definition: target.F90:172