Octopus
target_userdefined.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 target_oct_m
44 use td_oct_m
45 use space_oct_m
47 use string_oct_m
48
49 implicit none
50
51 private
52 public :: target_userdefined_t
53
55 type, extends(target_t) :: target_userdefined_t
56 contains
57 procedure :: init => target_init_userdefined
58 procedure :: j1 => target_j1_userdefined
59 procedure :: apply_chi => target_chi_userdefined
60 procedure :: output => target_output_userdefined
62
63
64contains
65
66 ! ----------------------------------------------------------------------
68 subroutine target_init_userdefined(tg, gr, kpoints, namespace, space, ions, qcs, td, w0, oct, ep, restart)
69 class(target_userdefined_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
82 integer :: no_states, ib, ip, idim, inst, inik, id, ist, ik
83 type(block_t) :: blk
84 real(real64) :: xx(1:gr%box%dim), rr, psi_re, psi_im
85 complex(real64), allocatable :: zpsi(:, :)
86
88
89 message(1) = 'Info: Target is a user-defined state.'
90 call messages_info(1, namespace=namespace)
91
92 tg%move_ions = td%ions_dyn%ions_move()
93 tg%dt = td%dt
94
95 safe_allocate(zpsi(gr%np, 1:tg%st%d%dim))
96
97 !%Variable OCTTargetUserdefined
98 !%Type block
99 !%Section Calculation Modes::Optimal Control
100 !%Description
101 !% Define a target state. Syntax follows the one of the <tt>UserDefinedStates</tt> block.
102 !% Example:
103 !%
104 !% <tt>%OCTTargetUserdefined
105 !% <br>&nbsp;&nbsp; 1 | 1 | 1 | "exp(-r^2)*exp(-i*0.2*x)"
106 !% <br>%</tt>
107 !%
108 !%End
109 if (parse_block(namespace, 'OCTTargetUserdefined', blk) == 0) then
110
111 no_states = parse_block_n(blk)
112 do ib = 1, no_states
113 call parse_block_integer(blk, ib - 1, 0, idim)
114 call parse_block_integer(blk, ib - 1, 1, inst)
115 call parse_block_integer(blk, ib - 1, 2, inik)
117 ! read formula strings and convert to C strings
118 do id = 1, tg%st%d%dim
119 do ist = 1, tg%st%nst
120 do ik = 1, tg%st%nik
121
122 ! does the block entry match and is this node responsible?
123 if (.not. (id == idim .and. ist == inst .and. ik == inik &
124 .and. tg%st%st_start <= ist .and. tg%st%st_end >= ist)) cycle
125
126 ! parse formula string
127 call parse_block_string( &
128 blk, ib - 1, 3, tg%st%user_def_states(id, ist, ik))
129 ! convert to C string
130 call conv_to_c_string(tg%st%user_def_states(id, ist, ik))
131
132 do ip = 1, gr%np
133 xx = gr%x(:, ip)
134 rr = norm2(xx)
135
136 ! parse user-defined expressions
137 call parse_expression(psi_re, psi_im, &
138 gr%box%dim, xx, rr, m_zero, tg%st%user_def_states(id, ist, ik))
139 ! fill state
140 zpsi(ip, id) = cmplx(psi_re, psi_im, real64)
141 end do
142
143 ! normalize orbital
144 call zmf_normalize(gr, tg%st%d%dim, zpsi)
145
146 call states_elec_set_state(tg%st, gr, ist, ik, zpsi)
147
148 end do
149 end do
150 end do
151 end do
153 call density_calc(tg%st, gr, tg%st%rho)
154 else
155 call messages_variable_is_block(namespace, 'OCTTargetUserdefined')
156 end if
157
158 safe_deallocate_a(zpsi)
159
161 end subroutine target_init_userdefined
162
164 ! ----------------------------------------------------------------------
165 subroutine target_output_userdefined(tg, namespace, space, gr, dir, ions, hm, outp)
166 class(target_userdefined_t), intent(inout) :: tg
167 type(namespace_t), intent(in) :: namespace
168 class(space_t), intent(in) :: space
169 type(grid_t), intent(in) :: gr
170 character(len=*), intent(in) :: dir
171 type(ions_t), intent(in) :: ions
172 type(hamiltonian_elec_t), intent(in) :: hm
173 type(output_t), intent(in) :: outp
175
176 call io_mkdir(trim(dir), namespace)
177 call output_states(outp, namespace, space, trim(dir), tg%st, gr, ions, hm, -1)
178
180 end subroutine target_output_userdefined
181 ! ----------------------------------------------------------------------
182
183
184 ! ----------------------------------------------------------------------
186 real(real64) function target_j1_userdefined(tg, namespace, gr, kpoints, qcpsi, ions) result(j1)
187 class(target_userdefined_t), intent(inout) :: tg
188 type(namespace_t), intent(in) :: namespace
189 type(grid_t), intent(in) :: gr
190 type(kpoints_t), intent(in) :: kpoints
191 type(opt_control_state_t), intent(inout) :: qcpsi
192 type(ions_t), optional, intent(in) :: ions
193
194 integer :: ik, ist
195 complex(real64), allocatable :: zpsi(:, :), zst(:, :)
196 type(states_elec_t), pointer :: psi
197
198 push_sub(target_j1_userdefined)
199
200 psi => opt_control_point_qs(qcpsi)
201
202 safe_allocate(zpsi(1:gr%np, 1:tg%st%d%dim))
203 safe_allocate(zst(1:gr%np, 1:tg%st%d%dim))
204
205 j1 = m_zero
206 do ik = 1, psi%nik
207 do ist = psi%st_start, psi%st_end
208
209 call states_elec_get_state(psi, gr, ist, ik, zpsi)
210 call states_elec_get_state(tg%st, gr, ist, ik, zst)
211
212 j1 = j1 + psi%occ(ist, ik)*abs(zmf_dotp(gr, psi%d%dim, zpsi, zst))**2
213 end do
214 end do
215
216 safe_deallocate_a(zpsi)
217 safe_deallocate_a(zst)
218
219 nullify(psi)
220 pop_sub(target_j1_userdefined)
221 end function target_j1_userdefined
222
223
224 ! ----------------------------------------------------------------------
226 subroutine target_chi_userdefined(tg, namespace, gr, kpoints, qcpsi_in, qcchi_out, ions)
227 class(target_userdefined_t), intent(inout) :: tg
228 type(namespace_t), intent(in) :: namespace
229 type(grid_t), intent(in) :: gr
230 type(kpoints_t), intent(in) :: kpoints
231 type(opt_control_state_t), target, intent(inout) :: qcpsi_in
232 type(opt_control_state_t), target, intent(inout) :: qcchi_out
233 type(ions_t), intent(in) :: ions
234
235 integer :: ik, ist
236 complex(real64) :: olap
237 complex(real64), allocatable :: zpsi(:, :), zst(:, :), zchi(:, :)
238 type(states_elec_t), pointer :: psi_in, chi_out
239
240 push_sub(target_chi_userdefined)
241
242 psi_in => opt_control_point_qs(qcpsi_in)
243 chi_out => opt_control_point_qs(qcchi_out)
244
245 safe_allocate(zpsi(1:gr%np, 1:tg%st%d%dim))
246 safe_allocate(zst(1:gr%np, 1:tg%st%d%dim))
247 safe_allocate(zchi(1:gr%np, 1:tg%st%d%dim))
248
249 do ik = 1, psi_in%nik
250 do ist = psi_in%st_start, psi_in%st_end
251
252 call states_elec_get_state(psi_in, gr, ist, ik, zpsi)
253 call states_elec_get_state(tg%st, gr, ist, ik, zst)
254
255 olap = zmf_dotp(gr, zst(:, 1), zpsi(:, 1))
256 zchi(1:gr%np, 1:tg%st%d%dim) = olap*zst(1:gr%np, 1:tg%st%d%dim)
257
258 call states_elec_set_state(chi_out, gr, ist, ik, zchi)
259
260 end do
261 end do
262
263 safe_deallocate_a(zpsi)
264 safe_deallocate_a(zst)
265 safe_deallocate_a(zchi)
266
267 nullify(psi_in)
268 nullify(chi_out)
270 end subroutine target_chi_userdefined
271
273
274!! Local Variables:
275!! mode: f90
276!! coding: utf-8
277!! 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.
subroutine, public zmf_normalize(mesh, dim, psi, norm)
Normalize a mesh function psi.
subroutine, public messages_variable_is_block(namespace, name)
Definition: messages.F90:1024
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:162
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 parse_block_string(blk, l, c, res, convert_to_c)
Definition: parser.F90:818
integer function, public parse_block(namespace, name, blk, check_varinfo_)
Definition: parser.F90:623
subroutine, public conv_to_c_string(str)
converts to c string
Definition: string.F90:234
Optimal-control targets: abstract base class and public interface.
Definition: target.F90:132
subroutine target_output_userdefined(tg, namespace, space, gr, dir, ions, hm, outp)
subroutine target_chi_userdefined(tg, namespace, gr, kpoints, qcpsi_in, qcchi_out, ions)
subroutine target_init_userdefined(tg, gr, kpoints, namespace, space, ions, qcs, td, w0, oct, ep, restart)
real(real64) function target_j1_userdefined(tg, namespace, gr, kpoints, qcpsi, ions)
Definition: td.F90:116
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...
output handler class
Definition: output_low.F90:166
The states_elec_t class contains all electronic wave functions.
Abstract optimal-control target.
Definition: target.F90:172
Target projecting onto a user-defined state.