Octopus
target_local.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
20#include "global.h"
21
23 use debug_oct_m
24 use epot_oct_m
25 use global_oct_m
26 use grid_oct_m
28 use ions_oct_m
30 use io_oct_m
32 use, intrinsic :: iso_fortran_env
34 use mesh_oct_m
41 use parser_oct_m
44 use space_oct_m
46 use string_oct_m
47 use target_oct_m
48 use td_oct_m
49 use unit_oct_m
51
52
53 implicit none
54
55 private
56 public :: target_local_t
57
59 type, extends(target_t) :: target_local_t
60 private
61 real(real64), allocatable :: rho(:)
62 contains
63 procedure :: init => target_init_local
64 procedure :: cleanup => target_end_local
65 procedure :: j1 => target_j1_local
66 procedure :: apply_chi => target_chi_local
67 procedure :: output => target_output_local
68 end type target_local_t
69
70
71contains
72
73
74 ! ----------------------------------------------------------------------
76 subroutine target_init_local(tg, gr, kpoints, namespace, space, ions, qcs, td, w0, oct, ep, restart)
77 class(target_local_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 :: ip
91 real(real64) :: xx(1:gr%box%dim), rr, psi_re, psi_im
92 character(len=1024) :: expression
93 push_sub(target_init_local)
94
95 tg%move_ions = td%ions_dyn%ions_move()
96 tg%dt = td%dt
97
98 !%Variable OCTLocalTarget
99 !%Type string
100 !%Section Calculation Modes::Optimal Control
101 !%Description
102 !% If <tt>OCTTargetOperator = oct_tg_local</tt>, then one must supply a function
103 !% that defines the target. This should be done by defining it through a string, using
104 !% the variable <tt>OCTLocalTarget</tt>.
105 !%End
106 if (parse_is_defined(namespace, 'OCTLocalTarget')) then
107 safe_allocate(tg%rho(1:gr%np))
108 tg%rho = m_zero
109 call parse_variable(namespace, 'OCTLocalTarget', "0", expression)
110 call conv_to_c_string(expression)
111 do ip = 1, gr%np
112 call mesh_r(gr, ip, rr, coords = xx)
113 ! parse user-defined expression
114 call parse_expression(psi_re, psi_im, gr%box%dim, xx, rr, m_zero, expression)
115 tg%rho(ip) = psi_re
116 end do
117 else
118 message(1) = 'If OCTTargetOperator = oct_tg_local, then you must give the shape'
119 message(2) = 'of this target in variable "OCTLocalTarget".'
120 call messages_fatal(2, namespace=namespace)
121 end if
122
123 pop_sub(target_init_local)
124 end subroutine target_init_local
125
126
127 ! ----------------------------------------------------------------------
129 subroutine target_end_local(tg, oct)
130 class(target_local_t), intent(inout) :: tg
131 type(oct_t), intent(in) :: oct
132
133 push_sub(target_end_local)
134
135 safe_deallocate_a(tg%rho)
136
137 pop_sub(target_end_local)
138 end subroutine target_end_local
139
140
141 ! ----------------------------------------------------------------------
142 subroutine target_output_local(tg, namespace, space, gr, dir, ions, hm, outp)
143 class(target_local_t), intent(inout) :: tg
144 type(namespace_t), intent(in) :: namespace
145 class(space_t), intent(in) :: space
146 type(grid_t), intent(in) :: gr
147 character(len=*), intent(in) :: dir
148 type(ions_t), intent(in) :: ions
149 type(hamiltonian_elec_t), intent(in) :: hm
150 type(output_t), intent(in) :: outp
151
152 integer :: ierr
153 push_sub(target_output_local)
155 call io_mkdir(trim(dir), namespace)
156 call dio_function_output(outp%how(0), trim(dir), 'local_target', namespace, space, gr, &
157 tg%rho, units_out%length**(-space%dim), ierr, pos=ions%pos, atoms=ions%atom)
161 end subroutine target_output_local
162 ! ----------------------------------------------------------------------
163
164
165 ! ----------------------------------------------------------------------
167 real(real64) function target_j1_local(tg, namespace, gr, kpoints, qcpsi, ions) result(j1)
168 class(target_local_t), intent(inout) :: tg
169 type(namespace_t), intent(in) :: namespace
170 type(grid_t), intent(in) :: gr
171 type(kpoints_t), intent(in) :: kpoints
172 type(opt_control_state_t), intent(inout) :: qcpsi
173 type(ions_t), optional, intent(in) :: ions
174
175 integer :: is
176 type(states_elec_t), pointer :: psi
177 push_sub(target_j1_local)
178
179 psi => opt_control_point_qs(qcpsi)
180
181 j1 = m_zero
182 do is = 1, psi%d%spin_channels
183 j1 = j1 + dmf_dotp(gr, tg%rho, psi%rho(:, is))
184 end do
185
186 nullify(psi)
187 pop_sub(target_j1_local)
188 end function target_j1_local
189
190
191 ! ----------------------------------------------------------------------
193 subroutine target_chi_local(tg, namespace, gr, kpoints, qcpsi_in, qcchi_out, ions)
194 class(target_local_t), intent(inout) :: tg
195 type(namespace_t), intent(in) :: namespace
196 type(grid_t), intent(in) :: gr
197 type(kpoints_t), intent(in) :: kpoints
198 type(opt_control_state_t), target, intent(inout) :: qcpsi_in
199 type(opt_control_state_t), target, intent(inout) :: qcchi_out
200 type(ions_t), intent(in) :: ions
201
202 integer :: ik, idim, ist, ip
203 complex(real64), allocatable :: zpsi(:, :)
204 type(states_elec_t), pointer :: psi_in, chi_out
205
206 push_sub(target_chi_local)
207
208 psi_in => opt_control_point_qs(qcpsi_in)
209 chi_out => opt_control_point_qs(qcchi_out)
210
211 safe_allocate(zpsi(1:gr%np, 1:psi_in%d%dim))
212
213 do ik = 1, psi_in%nik
214 do idim = 1, psi_in%d%dim
215 do ist = psi_in%st_start, psi_in%st_end
216 call states_elec_get_state(psi_in, gr, ist, ik, zpsi)
217 do ip = 1, gr%np
218 zpsi(ip, idim) = psi_in%occ(ist, ik)*tg%rho(ip)*zpsi(ip, idim)
219 end do
220 call states_elec_set_state(chi_out, gr, ist, ik, zpsi)
221 end do
222 end do
223 end do
225 safe_deallocate_a(zpsi)
226
227 nullify(psi_in)
228 nullify(chi_out)
229 pop_sub(target_chi_local)
230 end subroutine target_chi_local
231
232end module target_local_oct_m
233
234!! Local Variables:
235!! mode: f90
236!! coding: utf-8
237!! End:
real(real64), parameter, public m_zero
Definition: global.F90:200
This module implements the underlying real-space grid.
Definition: grid.F90:119
subroutine, public dio_function_output(how, dir, fname, namespace, space, mesh, ff, unit, ierr, pos, atoms, grp, root)
Top-level IO routine for functions defined on the mesh.
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
pure subroutine, public mesh_r(mesh, ip, rr, origin, coords)
return the distance to the origin for a given grid point
Definition: mesh.F90:342
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
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
logical function, public parse_is_defined(namespace, name)
Definition: parser.F90:463
subroutine, public conv_to_c_string(str)
converts to c string
Definition: string.F90:234
subroutine target_init_local(tg, gr, kpoints, namespace, space, ions, qcs, td, w0, oct, ep, restart)
subroutine target_output_local(tg, namespace, space, gr, dir, ions, hm, outp)
subroutine target_end_local(tg, oct)
subroutine target_chi_local(tg, namespace, gr, kpoints, qcpsi_in, qcchi_out, ions)
real(real64) function target_j1_local(tg, namespace, gr, kpoints, qcpsi, ions)
Optimal-control targets: abstract base class and public interface.
Definition: target.F90:132
Definition: td.F90:116
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:134
This module defines the unit system, used for input and output.
type(unit_system_t), public units_out
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 that is a local (static) operator.
Abstract optimal-control target.
Definition: target.F90:172