Octopus
target.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
37module target_oct_m
38 use debug_oct_m
39 use epot_oct_m
40 use global_oct_m
41 use grid_oct_m
44 use ions_oct_m
45 use, intrinsic :: iso_fortran_env
54 use space_oct_m
56 use td_oct_m
57
58 implicit none
59
60 private
61 public :: &
62 target_t, &
64 target_end, &
67 target_inh, &
70 target_j1, &
71 target_chi, &
75
77 type, abstract :: target_t
78 ! Components shared by all target kinds.
79 integer :: type
80 type(states_elec_t) :: st
81 real(real64) :: dt
82 logical :: move_ions
83 integer :: curr_functional
84 contains
85 procedure(target_init_i), deferred :: init
86 procedure(target_j1_i), deferred :: j1
87 procedure(target_chi_i), deferred :: apply_chi
88 procedure(target_output_i), deferred :: output
89 procedure :: cleanup => target_cleanup_default
90 procedure :: tdcalc => target_tdcalc_default
91 procedure :: inh => target_inh_default
92 procedure :: init_propagation => target_init_propagation_default
93 end type target_t
94
95 abstract interface
96
97 subroutine target_init_i(tg, gr, kpoints, namespace, space, ions, qcs, td, w0, oct, ep, restart)
100 class(target_t), intent(inout) :: tg
101 type(grid_t), intent(in) :: gr
102 type(kpoints_t), intent(in) :: kpoints
103 type(namespace_t), intent(in) :: namespace
104 class(space_t), intent(in) :: space
105 type(ions_t), intent(in) :: ions
106 type(opt_control_state_t), intent(inout) :: qcs
107 type(td_t), intent(in) :: td
108 real(real64), intent(in) :: w0
109 type(oct_t), intent(in) :: oct
110 type(epot_t), intent(inout) :: ep
111 type(restart_t), intent(inout) :: restart
112 end subroutine target_init_i
113
115 real(real64) function target_j1_i(tg, namespace, gr, kpoints, qcpsi, ions) result(j1)
117 class(target_t), intent(inout) :: tg
118 type(namespace_t), intent(in) :: namespace
119 type(grid_t), intent(in) :: gr
120 type(kpoints_t), intent(in) :: kpoints
121 type(opt_control_state_t), intent(inout) :: qcpsi
122 type(ions_t), optional, intent(in) :: ions
123 end function target_j1_i
124
126 subroutine target_chi_i(tg, namespace, gr, kpoints, qcpsi_in, qcchi_out, ions)
128 class(target_t), intent(inout) :: tg
129 type(namespace_t), intent(in) :: namespace
130 type(grid_t), intent(in) :: gr
131 type(kpoints_t), intent(in) :: kpoints
132 type(opt_control_state_t), target, intent(inout) :: qcpsi_in
133 type(opt_control_state_t), target, intent(inout) :: qcchi_out
134 type(ions_t), intent(in) :: ions
135 end subroutine target_chi_i
136
138 subroutine target_output_i(tg, namespace, space, gr, dir, ions, hm, outp)
140 class(target_t), intent(inout) :: tg
141 type(namespace_t), intent(in) :: namespace
142 class(space_t), intent(in) :: space
143 type(grid_t), intent(in) :: gr
144 character(len=*), intent(in) :: dir
145 type(ions_t), intent(in) :: ions
146 type(hamiltonian_elec_t), intent(in) :: hm
147 type(output_t), intent(in) :: outp
148 end subroutine target_output_i
149 end interface
150
151 integer, public, parameter :: &
152 oct_tg_groundstate = 1, &
153 oct_tg_excited = 2, &
155 oct_tg_userdefined = 4, &
156 oct_tg_jdensity = 5, &
157 oct_tg_local = 6, &
158 oct_tg_td_local = 7, &
160 oct_tg_hhg = 9, &
161 oct_tg_velocity = 10, &
162 oct_tg_hhgnew = 12, &
163 oct_tg_classical = 13, &
164 oct_tg_spin = 14
165
166 integer, public, parameter :: &
167 oct_targetmode_static = 0, &
169
170 integer, public, parameter :: &
171 oct_no_curr = 0, &
173 oct_max_curr_ring = 2, &
176contains
178 ! ---------------------------------------------------------
182 class(target_t), intent(inout) :: tg
185 call tg%init_propagation()
188 end subroutine target_init_propagation
189
190
191 ! ----------------------------------------------------------------------
193 subroutine target_get_state(tg, st)
194 class(target_t), intent(in) :: tg
195 type(states_elec_t), intent(inout) :: st
196
197 push_sub(target_get_state)
198 call states_elec_copy(st, tg%st)
199
200 pop_sub(target_get_state)
201 end subroutine target_get_state
202 ! ----------------------------------------------------------------------
203
204
205 ! ----------------------------------------------------------------------
206 subroutine target_end(tg, oct)
207 class(target_t), intent(inout) :: tg
208 type(oct_t), intent(in) :: oct
209
210 push_sub(target_end)
211
212 call states_elec_end(tg%st)
213 call tg%cleanup(oct)
214
215 pop_sub(target_end)
216 end subroutine target_end
217 ! ----------------------------------------------------------------------
218
219
220 ! ----------------------------------------------------------------------
221 subroutine target_output(tg, namespace, space, gr, dir, ions, hm, outp)
222 class(target_t), intent(inout) :: tg
223 type(namespace_t), intent(in) :: namespace
224 class(space_t), intent(in) :: space
225 type(grid_t), intent(in) :: gr
226 character(len=*), intent(in) :: dir
227 type(ions_t), intent(in) :: ions
228 type(hamiltonian_elec_t), intent(in) :: hm
229 type(output_t), intent(in) :: outp
230
231 push_sub(target_output)
232
233 call tg%output(namespace, space, gr, dir, ions, hm, outp)
234
235 pop_sub(target_output)
236 end subroutine target_output
237 ! ----------------------------------------------------------------------
238
239
240 ! ---------------------------------------------------------
244 subroutine target_tdcalc(tg, namespace, space, hm, gr, ions, ext_partners, psi, time, max_time)
245 class(target_t), intent(inout) :: tg
246 type(namespace_t), intent(in) :: namespace
247 class(space_t), intent(in) :: space
248 type(hamiltonian_elec_t), intent(inout) :: hm
249 type(grid_t), intent(in) :: gr
250 type(ions_t), intent(inout) :: ions
251 type(partner_list_t), intent(in) :: ext_partners
252 type(states_elec_t), intent(inout) :: psi
253 integer, intent(in) :: time
254 integer, intent(in) :: max_time
255
256 if (target_mode(tg) /= oct_targetmode_td) return
257
258 push_sub(target_tdcalc)
259
260 call tg%tdcalc(namespace, space, hm, gr, ions, ext_partners, psi, time, max_time)
262 pop_sub(target_tdcalc)
263 end subroutine target_tdcalc
264 ! ----------------------------------------------------------------------
266
267 ! ---------------------------------------------------------------
270 subroutine target_inh(psi, gr, kpoints, tg, time, inh, iter)
271 type(states_elec_t), intent(inout) :: psi
272 type(grid_t), intent(in) :: gr
273 type(kpoints_t), intent(in) :: kpoints
274 class(target_t), intent(inout) :: tg
275 real(real64), intent(in) :: time
276 type(states_elec_t), intent(inout) :: inh
277 integer, intent(in) :: iter
278
279 push_sub(target_inh)
280
281 call tg%inh(psi, gr, kpoints, time, inh, iter)
282
283 pop_sub(target_inh)
284 end subroutine target_inh
285 !----------------------------------------------------------
286
287
288 ! ---------------------------------------------------------
293 real(real64) function target_j1(tg, namespace, gr, kpoints, qcpsi, ions) result(j1)
294 class(target_t), intent(inout) :: tg
295 type(namespace_t), intent(in) :: namespace
296 type(grid_t), intent(in) :: gr
297 type(kpoints_t), intent(in) :: kpoints
298 type(opt_control_state_t), intent(inout) :: qcpsi
299 type(ions_t), optional, intent(in) :: ions
300
301 push_sub(target_j1)
302
303 j1 = tg%j1(namespace, gr, kpoints, qcpsi, ions)
304
305 pop_sub(target_j1)
306 end function target_j1
307 ! ---------------------------------------------------------
308
309
310 ! ---------------------------------------------------------
312 subroutine target_chi(tg, namespace, gr, kpoints, qcpsi_in, qcchi_out, ions)
313 class(target_t), intent(inout) :: tg
314 type(namespace_t), intent(in) :: namespace
315 type(grid_t), intent(in) :: gr
316 type(kpoints_t), intent(in) :: kpoints
317 type(opt_control_state_t), target, intent(inout) :: qcpsi_in
318 type(opt_control_state_t), target, intent(inout) :: qcchi_out
319 type(ions_t), intent(in) :: ions
320
321 real(real64), pointer :: q(:, :), p(:, :)
322 push_sub(target_chi)
323
324 call tg%apply_chi(namespace, gr, kpoints, qcpsi_in, qcchi_out, ions)
325
326 ! Unless the target is "classical", the co-state classical variables are zero at time t=T.
327 if (tg%type .ne. oct_tg_classical) then
328 q => opt_control_point_q(qcchi_out)
329 p => opt_control_point_p(qcchi_out)
330 q = m_zero
331 p = m_zero
332 nullify(q)
333 nullify(p)
334 end if
335
336 pop_sub(target_chi)
337 end subroutine target_chi
338
340 ! ----------------------------------------------------------------------
342 subroutine target_cleanup_default(tg, oct)
343 class(target_t), intent(inout) :: tg
344 type(oct_t), intent(in) :: oct
345
346 push_sub(target_cleanup_default)
348 end subroutine target_cleanup_default
349 ! ----------------------------------------------------------------------
350
351
352 ! ----------------------------------------------------------------------
354 subroutine target_tdcalc_default(tg, namespace, space, hm, gr, ions, ext_partners, psi, time, max_time)
355 class(target_t), intent(inout) :: tg
356 type(namespace_t), intent(in) :: namespace
357 class(space_t), intent(in) :: space
358 type(hamiltonian_elec_t), intent(inout) :: hm
359 type(grid_t), intent(in) :: gr
360 type(ions_t), intent(inout) :: ions
361 type(partner_list_t), intent(in) :: ext_partners
362 type(states_elec_t), intent(inout) :: psi
363 integer, intent(in) :: time
364 integer, intent(in) :: max_time
366 ! Static targets do not accumulate a time-dependent fitness.
367 end subroutine target_tdcalc_default
368 ! ----------------------------------------------------------------------
369
370
371 ! ----------------------------------------------------------------------
374 subroutine target_inh_default(tg, psi, gr, kpoints, time, inh, iter)
375 class(target_t), intent(inout) :: tg
376 type(states_elec_t), intent(inout) :: psi
377 type(grid_t), intent(in) :: gr
378 type(kpoints_t), intent(in) :: kpoints
379 real(real64), intent(in) :: time
380 type(states_elec_t), intent(inout) :: inh
381 integer, intent(in) :: iter
382
383 write(message(1),'(a)') 'Internal error in target_inh'
384 call messages_fatal(1)
385 end subroutine target_inh_default
386 ! ----------------------------------------------------------------------
387
389 ! ----------------------------------------------------------------------
392 class(target_t), intent(inout) :: tg
393
397 ! ----------------------------------------------------------------------
398
399
400 ! ----------------------------------------------------------------------
401 integer pure function target_mode(tg)
402 class(target_t), intent(in) :: tg
403
404 select case (tg%type)
407 case default
409 end select
410
411 ! allow specific current functionals to be td
412 ! Attention: yet combined with static density target,
413 ! the total target is considered td.
414 select case (tg%curr_functional)
415 case (oct_curr_square_td)
417 end select
418
419 end function target_mode
420
421
422 ! ----------------------------------------------------------------------
423 integer pure function target_type(tg)
424 class(target_t), intent(in) :: tg
425 target_type = tg%type
426 end function target_type
427 ! ----------------------------------------------------------------------
428
429
430 !-----------------------------------------------------------------------
431 integer pure function target_curr_functional(tg)
432 class(target_t), intent(in) :: tg
433 target_curr_functional = tg%curr_functional
434 end function target_curr_functional
435 !-----------------------------------------------------------------------
436
438 ! ----------------------------------------------------------------------
439 logical pure function target_move_ions(tg)
440 class(target_t), intent(in) :: tg
441 target_move_ions = tg%move_ions
442 end function target_move_ions
443 ! ----------------------------------------------------------------------
444
445
446end module target_oct_m
447
448!! Local Variables:
449!! mode: f90
450!! coding: utf-8
451!! End:
Apply the target operator to build the chi boundary condition.
Definition: target.F90:221
Read the target definition from the input file.
Definition: target.F90:192
Evaluate the target functional J1.
Definition: target.F90:210
Write target-specific output.
Definition: target.F90:233
This module implements the underlying real-space grid.
Definition: grid.F90:119
This module defines classes and functions for interaction partners.
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.
this module contains the low-level part of the output system
Definition: output_low.F90:117
Optimal-control targets: abstract base class and public interface.
Definition: target.F90:132
integer, parameter, public oct_tg_jdensity
Definition: target.F90:246
subroutine target_init_propagation_default(tg)
Default init_propagation: nothing to reset.
Definition: target.F90:487
integer, parameter, public oct_targetmode_static
Definition: target.F90:261
logical pure function, public target_move_ions(tg)
Definition: target.F90:535
integer, parameter, public oct_tg_userdefined
Definition: target.F90:246
integer, parameter, public oct_tg_hhgnew
Definition: target.F90:246
integer, parameter, public oct_tg_spin
Definition: target.F90:246
integer, parameter, public oct_targetmode_td
Definition: target.F90:261
subroutine, public target_init_propagation(tg)
This routine performs all the things that must be initialized prior to a forward evolution,...
Definition: target.F90:277
integer, parameter, public oct_max_curr_ring
Definition: target.F90:265
real(real64) function, public target_j1(tg, namespace, gr, kpoints, qcpsi, ions)
Calculates the J1 functional, i.e.: in the time-independent case, or else in the time-dependent cas...
Definition: target.F90:389
subroutine target_tdcalc_default(tg, namespace, space, hm, gr, ions, ext_partners, psi, time, max_time)
Default tdcalc: static targets accumulate nothing in time.
Definition: target.F90:450
integer, parameter, public oct_curr_square_td
Definition: target.F90:265
integer, parameter, public oct_curr_square
Definition: target.F90:265
integer, parameter, public oct_tg_velocity
Definition: target.F90:246
subroutine target_inh_default(tg, psi, gr, kpoints, time, inh, iter)
Default inh: only time-dependent targets define an inhomogeneous term, so reaching here is an interna...
Definition: target.F90:470
integer, parameter, public oct_tg_excited
Definition: target.F90:246
integer, parameter, public oct_tg_gstransformation
Definition: target.F90:246
integer, parameter, public oct_tg_td_local
Definition: target.F90:246
subroutine, public target_get_state(tg, st)
This just copies the states_elec_t variable present in target, into st.
Definition: target.F90:289
integer, parameter, public oct_tg_local
Definition: target.F90:246
integer pure function, public target_type(tg)
Definition: target.F90:519
subroutine, public target_inh(psi, gr, kpoints, tg, time, inh, iter)
Calculates the inhomogeneous term that appears in the equation for chi, and places it into inh.
Definition: target.F90:366
subroutine, public target_output(tg, namespace, space, gr, dir, ions, hm, outp)
Definition: target.F90:317
subroutine, public target_tdcalc(tg, namespace, space, hm, gr, ions, ext_partners, psi, time, max_time)
Calculates, at a given point in time marked by the integer index, the integrand of the target functio...
Definition: target.F90:340
integer, parameter, public oct_tg_hhg
Definition: target.F90:246
subroutine, public target_chi(tg, namespace, gr, kpoints, qcpsi_in, qcchi_out, ions)
Calculate .
Definition: target.F90:408
subroutine, public target_end(tg, oct)
Definition: target.F90:302
integer pure function, public target_mode(tg)
Definition: target.F90:497
integer pure function, public target_curr_functional(tg)
Definition: target.F90:527
integer, parameter, public oct_tg_classical
Definition: target.F90:246
integer, parameter, public oct_tg_exclude_state
Definition: target.F90:246
subroutine target_cleanup_default(tg, oct)
Default cleanup: nothing to release.
Definition: target.F90:438
Definition: td.F90:116
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:171
!brief The oct_t datatype stores the basic information about how the OCT run is done.
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
Abstract optimal-control target.
Definition: target.F90:172