Octopus
propagation.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
23 use batch_oct_m
26 use debug_oct_m
32 use epot_oct_m
35 use forces_oct_m
37 use global_oct_m
38 use grid_oct_m
42 use ions_oct_m
43 use, intrinsic :: iso_fortran_env
46 use lasers_oct_m
48 use loct_oct_m
49 use mesh_oct_m
52 use mpi_oct_m
57 use parser_oct_m
64 use space_oct_m
68 use target_oct_m
70 use td_oct_m
72 use v_ks_oct_m
73
74 implicit none
75
76 private
77
78 public :: &
82 fwd_step, &
83 bwd_step, &
84 bwd_step_2, &
85 oct_prop_t, &
89
90
91 type oct_prop_t
92 private
93 integer :: number_checkpoints
94 integer, allocatable :: iter(:)
95 integer :: niter
96 character(len=100) :: dirname
97 type(restart_t) :: restart_load
98 type(restart_t) :: restart_dump
99 end type oct_prop_t
100
101
103 integer :: niter_
104 integer :: number_checkpoints_
105 real(real64) :: eta_
106 real(real64) :: delta_
107 logical :: zbr98_
108 logical :: gradients_
109
110contains
111
117 subroutine propagation_mod_init(niter, eta, delta, number_checkpoints, zbr98, gradients)
118 integer, intent(in) :: niter
119 real(real64), intent(in) :: eta
120 real(real64), intent(in) :: delta
121 integer, intent(in) :: number_checkpoints
122 logical, intent(in) :: zbr98
123 logical, intent(in) :: gradients
124
125 assert(.not. (zbr98 .and. gradients))
126
127 push_sub(propagation_mod_init)
128
129 niter_ = niter
130 eta_ = eta
131 delta_ = delta
132 number_checkpoints_ = number_checkpoints
133 zbr98_ = zbr98
134 gradients_ = gradients
135
136 pop_sub(propagation_mod_init)
137 end subroutine propagation_mod_init
138 ! ---------------------------------------------------------
139
140
146 subroutine propagate_forward(sys, td, par, tg, qcpsi, prop, write_iter)
147 type(electrons_t), intent(inout) :: sys
148 type(td_t), intent(inout) :: td
149 type(controlfunction_t), intent(in) :: par
150 type(target_t), intent(inout) :: tg
151 type(opt_control_state_t), intent(inout) :: qcpsi
152 type(oct_prop_t), optional, intent(inout) :: prop
153 logical, optional, intent(in) :: write_iter
154
155 integer :: ii, istep, ierr
156 logical :: write_iter_ = .false.
157 type(td_write_t) :: write_handler
158 real(real64), allocatable :: x_initial(:,:)
159 logical :: vel_target_ = .false.
160 type(states_elec_t), pointer :: psi
161
162 real(real64) :: init_time, final_time
163
164 push_sub(propagate_forward)
165
166 message(1) = "Info: Forward propagation."
167 call messages_info(1, namespace=sys%namespace)
168
169 call controlfunction_to_h(par, sys%ext_partners)
170
171 write_iter_ = .false.
172 if (present(write_iter)) write_iter_ = write_iter
173
174 psi => opt_control_point_qs(qcpsi)
175 if (sys%st%pack_states .and. sys%hm%apply_packed()) call psi%pack()
176 call opt_control_get_classical(sys%ions, qcpsi)
177
178 if (write_iter_) then
179 call td_write_init(write_handler, sys%namespace, sys%space, sys%outp, sys%gr, sys%st, sys%hm, &
180 sys%ions, sys%ext_partners, sys%ks, td%ions_dyn%ions_move(), &
181 list_has_gauge_field(sys%ext_partners), sys%hm%kick, td%iter, td%max_iter, &
182 td%dt, sys%mc)
183 call td_write_data(write_handler)
184 end if
185
188 ! setup the Hamiltonian
189 call density_calc(psi, sys%gr, psi%rho)
190 call v_ks_calc(sys%ks, sys%namespace, sys%space, sys%hm, psi, sys%ions, sys%ext_partners, time = m_zero)
191 call sys%hm%ks_pot%run_zero_iter(td%tr%vks_old)
192 if (td%ions_dyn%ions_move()) then
193 call hamiltonian_elec_epot_generate(sys%hm, sys%namespace, sys%space, sys%gr, sys%ions, &
194 sys%ext_partners, psi, time = m_zero)
195 call forces_calculate(sys%gr, sys%namespace, sys%ions, sys%hm, sys%ext_partners, psi, sys%ks, t = m_zero, dt = td%dt)
196 end if
199 if (target_type(tg) == oct_tg_hhgnew) then
201 end if
202
203 if (target_type(tg) == oct_tg_velocity .or. target_type(tg) == oct_tg_hhgnew) then
204 safe_allocate_source_a(x_initial, sys%ions%pos)
205 vel_target_ = .true.
206 sys%ions%vel = m_zero
207 sys%ions%tot_force = m_zero
208 end if
209
210 if (.not. target_move_ions(tg)) call epot_precalc_local_potential(sys%hm%ep, sys%namespace, sys%gr, sys%ions)
211
212 call target_tdcalc(tg, sys%namespace, sys%space, sys%hm, sys%gr, sys%ions, sys%ext_partners, psi, 0, td%max_iter)
213
214 if (present(prop)) then
215 call oct_prop_dump_states(prop, sys%space, 0, psi, sys%gr, sys%kpoints, ierr)
216 if (ierr /= 0) then
217 message(1) = "Unable to write OCT states restart."
218 call messages_warning(1, namespace=sys%namespace)
219 end if
220 end if
221
222 init_time = loct_clock()
223 if (mpi_grp_is_root(mpi_world)) call loct_progress_bar(-1, td%max_iter)
224
225 ii = 1
226 do istep = 1, td%max_iter
227 ! time-iterate wavefunctions
228
229 call propagator_elec_dt(sys%ks, sys%namespace, sys%space, sys%hm, sys%gr, psi, td%tr, istep*td%dt, td%dt, istep, &
230 td%ions_dyn, sys%ions, sys%ext_partners, sys%mc, sys%outp, td%write_handler)
231
232 if (present(prop)) then
233 call oct_prop_dump_states(prop, sys%space, istep, psi, sys%gr, sys%kpoints, ierr)
234 if (ierr /= 0) then
235 message(1) = "Unable to write OCT states restart."
236 call messages_warning(1, namespace=sys%namespace)
237 end if
238 end if
240 ! update
241 call v_ks_calc(sys%ks, sys%namespace, sys%space, sys%hm, psi, sys%ions, sys%ext_partners, time = istep*td%dt)
242 call energy_calc_total(sys%namespace, sys%space, sys%hm, sys%gr, psi, sys%ext_partners)
243
244 if (sys%hm%abs_boundaries%abtype == mask_absorbing) call zvmask(sys%gr, sys%hm, psi)
245
246 ! if td_target
247 call target_tdcalc(tg, sys%namespace, sys%space, sys%hm, sys%gr, sys%ions, sys%ext_partners, psi, istep, td%max_iter)
248
249 ! only write in final run
250 if (write_iter_) then
251 call td_write_iter(write_handler, sys%namespace, sys%space, sys%outp, sys%gr, psi, sys%hm, sys%ions, &
252 sys%ext_partners, sys%hm%kick, sys%ks, td%dt, istep, sys%mc, sys%td%recalculate_gs)
253 ii = ii + 1
254 if (any(ii == sys%outp%output_interval + 1) .or. istep == td%max_iter) then ! output
255 if (istep == td%max_iter) sys%outp%output_interval = ii - 1
256 ii = istep
257 call td_write_data(write_handler)
258 end if
259 end if
260
261 if ((mod(istep, 100) == 0) .and. mpi_grp_is_root(mpi_world)) call loct_progress_bar(istep, td%max_iter)
262 end do
263 if (mpi_grp_is_root(mpi_world)) write(stdout, '(1x)')
264
265 final_time = loct_clock()
266 write(message(1),'(a,f12.2,a)') 'Propagation time: ', final_time - init_time, ' seconds.'
267 call messages_info(1, namespace=sys%namespace)
268
269 if (vel_target_) then
270 sys%ions%pos = x_initial
271 safe_deallocate_a(x_initial)
272 end if
273
274 call opt_control_set_classical(sys%ions, qcpsi)
275
276 if (write_iter_) call td_write_end(write_handler)
277 if (sys%st%pack_states .and. sys%hm%apply_packed()) call psi%unpack()
278 nullify(psi)
279 pop_sub(propagate_forward)
280 end subroutine propagate_forward
281 ! ---------------------------------------------------------
282
283
288 subroutine propagate_backward(sys, td, qcpsi, prop)
289 type(electrons_t), intent(inout) :: sys
290 type(td_t), intent(inout) :: td
291 type(opt_control_state_t), intent(inout) :: qcpsi
292 type(oct_prop_t), intent(inout) :: prop
293
294 integer :: istep, ierr
295 type(states_elec_t), pointer :: psi
296
297 push_sub(propagate_backward)
298
299 message(1) = "Info: Backward propagation."
300 call messages_info(1, namespace=sys%namespace)
301
302 psi => opt_control_point_qs(qcpsi)
303 if (sys%st%pack_states .and. sys%hm%apply_packed()) call psi%pack()
304
305 call hamiltonian_elec_adjoint(sys%hm)
306
307 ! setup the Hamiltonian
308 call density_calc(psi, sys%gr, psi%rho)
309 call v_ks_calc(sys%ks, sys%namespace, sys%space, sys%hm, psi, sys%ions, sys%ext_partners)
310 call sys%hm%ks_pot%run_zero_iter(td%tr%vks_old)
311
312 call oct_prop_dump_states(prop, sys%space, td%max_iter, psi, sys%gr, sys%kpoints, ierr)
313 if (ierr /= 0) then
314 message(1) = "Unable to write OCT states restart."
315 call messages_warning(1, namespace=sys%namespace)
316 end if
317
318 if (mpi_grp_is_root(mpi_world)) call loct_progress_bar(-1, td%max_iter)
319
320 do istep = td%max_iter, 1, -1
321 call propagator_elec_dt(sys%ks, sys%namespace, sys%space, sys%hm, sys%gr, psi, td%tr, &
322 (istep - 1)*td%dt, -td%dt, istep-1, td%ions_dyn, sys%ions, sys%ext_partners, sys%mc, sys%outp, td%write_handler)
323
324 call oct_prop_dump_states(prop, sys%space, istep - 1, psi, sys%gr, sys%kpoints, ierr)
325 if (ierr /= 0) then
326 message(1) = "Unable to write OCT states restart."
327 call messages_warning(1, namespace=sys%namespace)
328 end if
329
330 call v_ks_calc(sys%ks, sys%namespace, sys%space, sys%hm, psi, sys%ions, sys%ext_partners)
331 if (mod(istep, 100) == 0 .and. mpi_grp_is_root(mpi_world)) call loct_progress_bar(td%max_iter - istep + 1, td%max_iter)
332 end do
333
334 if (sys%st%pack_states .and. sys%hm%apply_packed()) call psi%unpack()
335 nullify(psi)
336 pop_sub(propagate_backward)
337 end subroutine propagate_backward
338 ! ---------------------------------------------------------
339
340
354 subroutine fwd_step(sys, td, tg, par, par_chi, qcpsi, prop_chi, prop_psi)
355 type(electrons_t), intent(inout) :: sys
356 type(td_t), intent(inout) :: td
357 type(target_t), intent(inout) :: tg
358 type(controlfunction_t), intent(inout) :: par
359 type(controlfunction_t), intent(in) :: par_chi
360 type(opt_control_state_t), intent(inout) :: qcpsi
361 type(oct_prop_t), intent(inout) :: prop_chi
362 type(oct_prop_t), intent(inout) :: prop_psi
363
364 integer :: i, ierr
365 logical :: aux_fwd_propagation
366 type(states_elec_t) :: psi2
367 type(opt_control_state_t) :: qcchi
368 type(controlfunction_t) :: par_prev
369 type(propagator_base_t) :: tr_chi, tr_psi2
370 type(states_elec_t), pointer :: psi, chi
371
372 push_sub(fwd_step)
373
374 message(1) = "Info: Forward propagation."
375 call messages_info(1, namespace=sys%namespace)
376
378
379 call opt_control_state_null(qcchi)
380 call opt_control_state_copy(qcchi, qcpsi)
382 psi => opt_control_point_qs(qcpsi)
383 chi => opt_control_point_qs(qcchi)
384 call propagator_elec_copy(tr_chi, td%tr)
385 ! The propagation of chi should not be self-consistent, because the Kohn-Sham
386 ! potential used is the one created by psi. Note, however, that it is likely that
387 ! the first two iterations are done self-consistently nonetheless.
389
390 aux_fwd_propagation = (target_mode(tg) == oct_targetmode_td .or. &
391 (sys%hm%theory_level /= independent_particles .and. &
392 .not. sys%ks%frozen_hxc))
393 if (aux_fwd_propagation) then
394 call states_elec_copy(psi2, psi)
395 call controlfunction_copy(par_prev, par)
396 if (sys%st%pack_states .and. sys%hm%apply_packed()) call psi2%pack()
397 end if
398
399 ! setup forward propagation
400 call density_calc(psi, sys%gr, psi%rho)
401 call v_ks_calc(sys%ks, sys%namespace, sys%space, sys%hm, psi, sys%ions, sys%ext_partners)
402 call sys%hm%ks_pot%run_zero_iter(td%tr%vks_old)
403 call sys%hm%ks_pot%run_zero_iter(tr_chi%vks_old)
404 if (aux_fwd_propagation) then
405 call propagator_elec_copy(tr_psi2, td%tr)
406 call sys%hm%ks_pot%run_zero_iter(tr_psi2%vks_old)
407 end if
408
409 call oct_prop_dump_states(prop_psi, sys%space, 0, psi, sys%gr, sys%kpoints, ierr)
410 if (ierr /= 0) then
411 message(1) = "Unable to write OCT states restart."
412 call messages_warning(1, namespace=sys%namespace)
413 end if
414 call oct_prop_load_states(prop_chi, sys%namespace, sys%space, chi, sys%gr, sys%kpoints, 0, ierr)
415 if (ierr /= 0) then
416 message(1) = "Unable to read OCT states restart."
417 call messages_fatal(1, namespace=sys%namespace)
418 end if
419
420 if (sys%st%pack_states .and. sys%hm%apply_packed()) call psi%pack()
421 if (sys%st%pack_states .and. sys%hm%apply_packed()) call chi%pack()
422
423 do i = 1, td%max_iter
424 call update_field(i, par, sys%space, sys%gr, sys%hm, sys%ext_partners, sys%ions, qcpsi, qcchi, par_chi, dir = 'f')
425 call update_hamiltonian_elec_chi(i, sys%namespace, sys%space, sys%gr, sys%ks, sys%hm, sys%ext_partners, &
426 td, tg, par_chi, sys%ions, psi2)
427 call sys%hm%update(sys%gr, sys%namespace, sys%space, sys%ext_partners, time = (i - 1)*td%dt)
428 call propagator_elec_dt(sys%ks, sys%namespace, sys%space, sys%hm, sys%gr, chi, tr_chi, i*td%dt, td%dt, i, &
429 td%ions_dyn, sys%ions, sys%ext_partners, sys%mc, sys%outp, td%write_handler)
430 if (aux_fwd_propagation) then
431 call update_hamiltonian_elec_psi(i, sys%namespace, sys%space, sys%gr, sys%ks, sys%hm, sys%ext_partners, &
432 td, tg, par_prev, psi2, sys%ions)
433 call propagator_elec_dt(sys%ks, sys%namespace, sys%space, sys%hm, sys%gr, psi2, tr_psi2, i*td%dt, td%dt, i, &
434 td%ions_dyn, sys%ions, sys%ext_partners, sys%mc, sys%outp, td%write_handler)
435 end if
436 call update_hamiltonian_elec_psi(i, sys%namespace, sys%space, sys%gr, sys%ks, sys%hm, &
437 sys%ext_partners, td, tg, par, psi, sys%ions)
438 call sys%hm%update(sys%gr, sys%namespace, sys%space, sys%ext_partners, time = (i - 1)*td%dt)
439 call propagator_elec_dt(sys%ks, sys%namespace, sys%space, sys%hm, sys%gr, psi, td%tr, i*td%dt, td%dt, i, &
440 td%ions_dyn, sys%ions, sys%ext_partners, sys%mc, sys%outp, td%write_handler)
441 call target_tdcalc(tg, sys%namespace, sys%space, sys%hm, sys%gr, sys%ions, sys%ext_partners, psi, i, td%max_iter)
442
443 call oct_prop_dump_states(prop_psi, sys%space, i, psi, sys%gr, sys%kpoints, ierr)
444 if (ierr /= 0) then
445 message(1) = "Unable to write OCT states restart."
446 call messages_warning(1, namespace=sys%namespace)
447 end if
448 call oct_prop_check(prop_chi, sys%namespace, sys%space, chi, sys%gr, sys%kpoints, i)
449 end do
450 call update_field(td%max_iter+1, par, sys%space, sys%gr, sys%hm, sys%ext_partners, sys%ions, qcpsi, qcchi, par_chi, dir = 'f')
451
452 call density_calc(psi, sys%gr, psi%rho)
453 call v_ks_calc(sys%ks, sys%namespace, sys%space, sys%hm, psi, sys%ions, sys%ext_partners)
454
455 if (target_mode(tg) == oct_targetmode_td .or. &
456 (sys%hm%theory_level /= independent_particles .and. (.not. sys%ks%frozen_hxc))) then
457 call states_elec_end(psi2)
458 call controlfunction_end(par_prev)
459 end if
460
462 if (aux_fwd_propagation) call propagator_elec_end(tr_psi2)
463 call states_elec_end(chi)
464 call propagator_elec_end(tr_chi)
465 if (sys%st%pack_states .and. sys%hm%apply_packed()) call psi%unpack()
466 nullify(psi)
467 nullify(chi)
468 pop_sub(fwd_step)
469 end subroutine fwd_step
470 ! ---------------------------------------------------------
471
472
482 subroutine bwd_step(sys, td, tg, par, par_chi, qcchi, prop_chi, prop_psi)
483 type(electrons_t), intent(inout) :: sys
484 type(td_t), intent(inout) :: td
485 type(target_t), intent(inout) :: tg
486 type(controlfunction_t), intent(in) :: par
487 type(controlfunction_t), intent(inout) :: par_chi
488 type(opt_control_state_t), intent(inout) :: qcchi
489 type(oct_prop_t), intent(inout) :: prop_chi
490 type(oct_prop_t), intent(inout) :: prop_psi
491
492 integer :: i, ierr
493 type(propagator_base_t) :: tr_chi
494 type(opt_control_state_t) :: qcpsi
495 type(states_elec_t), pointer :: chi, psi
496
497 push_sub(bwd_step)
498
499 message(1) = "Info: Backward propagation."
500 call messages_info(1, namespace=sys%namespace)
501
502 call controlfunction_to_realtime(par_chi)
503
504 chi => opt_control_point_qs(qcchi)
505 psi => opt_control_point_qs(qcpsi)
506
507 call propagator_elec_copy(tr_chi, td%tr)
508 ! The propagation of chi should not be self-consistent, because the Kohn-Sham
509 ! potential used is the one created by psi. Note, however, that it is likely that
510 ! the first two iterations are done self-consistently nonetheless.
512
513 call states_elec_copy(psi, chi)
514 call oct_prop_load_states(prop_psi, sys%namespace, sys%space, psi, sys%gr, sys%kpoints, td%max_iter, ierr)
515 if (ierr /= 0) then
516 message(1) = "Unable to read OCT states restart."
517 call messages_fatal(1, namespace=sys%namespace)
518 end if
519 if (sys%st%pack_states .and. sys%hm%apply_packed()) call psi%pack()
520 if (sys%st%pack_states .and. sys%hm%apply_packed()) call chi%pack()
521
522 call density_calc(psi, sys%gr, psi%rho)
523 call v_ks_calc(sys%ks, sys%namespace, sys%space, sys%hm, psi, sys%ions, sys%ext_partners)
524 call sys%hm%update(sys%gr, sys%namespace, sys%space, sys%ext_partners)
525 call sys%hm%ks_pot%run_zero_iter(td%tr%vks_old)
526 call sys%hm%ks_pot%run_zero_iter(tr_chi%vks_old)
527
528 td%dt = -td%dt
529 call oct_prop_dump_states(prop_chi, sys%space, td%max_iter, chi, sys%gr, sys%kpoints, ierr)
530 if (ierr /= 0) then
531 message(1) = "Unable to write OCT states restart."
532 call messages_warning(1, namespace=sys%namespace)
533 end if
534
535 do i = td%max_iter, 1, -1
536 call oct_prop_check(prop_psi, sys%namespace, sys%space, psi, sys%gr, sys%kpoints, i)
537 call update_field(i, par_chi, sys%space, sys%gr, sys%hm, sys%ext_partners, sys%ions, qcpsi, qcchi, par, dir = 'b')
538 call update_hamiltonian_elec_chi(i-1, sys%namespace, sys%space, sys%gr, sys%ks, sys%hm, sys%ext_partners, &
539 td, tg, par_chi, sys%ions, psi)
540 call sys%hm%update(sys%gr, sys%namespace, sys%space, sys%ext_partners, time = abs(i*td%dt))
541 call propagator_elec_dt(sys%ks, sys%namespace, sys%space, sys%hm, sys%gr, chi, tr_chi, abs((i-1)*td%dt), td%dt, &
542 i-1, td%ions_dyn, sys%ions, sys%ext_partners, sys%mc, sys%outp, td%write_handler)
543 call oct_prop_dump_states(prop_chi, sys%space, i-1, chi, sys%gr, sys%kpoints, ierr)
544 if (ierr /= 0) then
545 message(1) = "Unable to write OCT states restart."
546 call messages_warning(1, namespace=sys%namespace)
547 end if
548 call update_hamiltonian_elec_psi(i-1, sys%namespace, sys%space, sys%gr, sys%ks, sys%hm, sys%ext_partners, &
549 td, tg, par, psi, sys%ions)
550 call sys%hm%update(sys%gr, sys%namespace, sys%space, sys%ext_partners, time = abs(i*td%dt))
551 call propagator_elec_dt(sys%ks, sys%namespace, sys%space, sys%hm, sys%gr, psi, td%tr, abs((i-1)*td%dt), td%dt, &
552 i-1, td%ions_dyn, sys%ions, sys%ext_partners, sys%mc, sys%outp, td%write_handler)
553 end do
554 td%dt = -td%dt
555 call update_field(0, par_chi, sys%space, sys%gr, sys%hm, sys%ext_partners, sys%ions, qcpsi, qcchi, par, dir = 'b')
556
557 call density_calc(psi, sys%gr, psi%rho)
558 call v_ks_calc(sys%ks, sys%namespace, sys%space, sys%hm, psi, sys%ions, sys%ext_partners)
559 call sys%hm%update(sys%gr, sys%namespace, sys%space, sys%ext_partners)
560
561 call controlfunction_to_basis(par_chi)
562 call states_elec_end(psi)
563 call propagator_elec_end(tr_chi)
564 if (sys%st%pack_states .and. sys%hm%apply_packed()) call chi%unpack()
565 nullify(chi)
566 nullify(psi)
567 pop_sub(bwd_step)
568 end subroutine bwd_step
569 ! ---------------------------------------------------------
570
571
584 subroutine bwd_step_2(sys, td, tg, par, par_chi, qcchi, prop_chi, prop_psi)
585 type(electrons_t), intent(inout) :: sys
586 type(td_t), intent(inout) :: td
587 type(target_t), intent(inout) :: tg
588 type(controlfunction_t), intent(in) :: par
589 type(controlfunction_t), intent(inout) :: par_chi
590 type(opt_control_state_t), intent(inout) :: qcchi
591 type(oct_prop_t), intent(inout) :: prop_chi
592 type(oct_prop_t), intent(inout) :: prop_psi
593
594 integer :: i, ierr, ik, ib
595 logical :: freeze
596 type(propagator_base_t) :: tr_chi
597 type(opt_control_state_t) :: qcpsi
598 type(states_elec_t) :: st_ref
599 type(states_elec_t), pointer :: chi, psi
600 real(real64), pointer :: q(:, :), p(:, :)
601 real(real64), allocatable :: qtildehalf(:, :), qinitial(:, :)
602 real(real64), allocatable :: vhxc(:, :)
603 real(real64), allocatable :: fold(:, :), fnew(:, :)
604 type(ion_state_t) :: ions_state_initial, ions_state_final
605
606 real(real64) :: init_time, final_time
607
608 push_sub(bwd_step_2)
609
610 chi => opt_control_point_qs(qcchi)
611 q => opt_control_point_q(qcchi)
612 p => opt_control_point_p(qcchi)
613 safe_allocate(qtildehalf(1:sys%ions%natoms, 1:sys%ions%space%dim))
614 safe_allocate(qinitial(1:sys%ions%space%dim, 1:sys%ions%natoms))
615
616 call propagator_elec_copy(tr_chi, td%tr)
617 ! The propagation of chi should not be self-consistent, because the Kohn-Sham
618 ! potential used is the one created by psi. Note, however, that it is likely that
619 ! the first two iterations are done self-consistently nonetheless.
621
622 call opt_control_state_null(qcpsi)
623 call opt_control_state_copy(qcpsi, qcchi)
624 psi => opt_control_point_qs(qcpsi)
625 call oct_prop_load_states(prop_psi, sys%namespace, sys%space, psi, sys%gr, sys%kpoints, td%max_iter, ierr)
626 if (ierr /= 0) then
627 message(1) = "Unable to read OCT states restart."
628 call messages_fatal(1, namespace=sys%namespace)
629 end if
630
631 safe_allocate(vhxc(1:sys%gr%np, 1:sys%hm%d%nspin))
632
633 call density_calc(psi, sys%gr, psi%rho)
634 call v_ks_calc(sys%ks, sys%namespace, sys%space, sys%hm, psi, sys%ions, sys%ext_partners)
635 call sys%hm%update(sys%gr, sys%namespace, sys%space, sys%ext_partners)
636 call sys%hm%ks_pot%run_zero_iter(td%tr%vks_old)
637 call sys%hm%ks_pot%run_zero_iter(tr_chi%vks_old)
638 td%dt = -td%dt
639 call oct_prop_dump_states(prop_chi, sys%space, td%max_iter, chi, sys%gr, sys%kpoints, ierr)
640 if (ierr /= 0) then
641 message(1) = "Unable to write OCT states restart."
642 call messages_warning(1, namespace=sys%namespace)
643 end if
644
645 call states_elec_copy(st_ref, psi)
646 if (sys%st%pack_states .and. sys%hm%apply_packed()) call psi%pack()
647 if (sys%st%pack_states .and. sys%hm%apply_packed()) call st_ref%pack()
648
649 if (td%ions_dyn%ions_move()) then
650 call forces_calculate(sys%gr, sys%namespace, sys%ions, sys%hm, sys%ext_partners, &
651 psi, sys%ks, t = td%max_iter*abs(td%dt), dt = td%dt)
652 end if
653
654 message(1) = "Info: Backward propagation."
655 call messages_info(1, namespace=sys%namespace)
656 if (mpi_grp_is_root(mpi_world)) call loct_progress_bar(-1, td%max_iter)
657
658 init_time = loct_clock()
659
660 do i = td%max_iter, 1, -1
661
662 call oct_prop_check(prop_psi, sys%namespace, sys%space, psi, sys%gr, sys%kpoints, i)
663 call update_field(i, par_chi, sys%space, sys%gr, sys%hm, sys%ext_partners, sys%ions, qcpsi, qcchi, par, dir = 'b')
664
665 select case (td%tr%method)
666
668
669 call update_hamiltonian_elec_psi(i-1, sys%namespace, sys%space, sys%gr, sys%ks, sys%hm, sys%ext_partners, &
670 td, tg, par, psi, sys%ions)
671 call propagator_elec_dt(sys%ks, sys%namespace, sys%space, sys%hm, sys%gr, psi, td%tr, abs((i-1)*td%dt), td%dt, &
672 i-1, td%ions_dyn, sys%ions, sys%ext_partners, sys%mc, sys%outp, td%write_handler, qcchi = qcchi)
673
674 case default
675
676 if (td%ions_dyn%ions_move()) then
677 qtildehalf = q
678
679 call ion_dynamics_save_state(td%ions_dyn, sys%ions, ions_state_initial)
680 call ion_dynamics_propagate(td%ions_dyn, sys%ions, abs((i-1)*td%dt), m_half * td%dt, sys%namespace)
681 qinitial = sys%ions%pos
682 call ion_dynamics_restore_state(td%ions_dyn, sys%ions, ions_state_initial)
683
684 safe_allocate(fold(1:sys%ions%natoms, 1:sys%ions%space%dim))
685 safe_allocate(fnew(1:sys%ions%natoms, 1:sys%ions%space%dim))
686 call forces_costate_calculate(sys%gr, sys%namespace, sys%ions, sys%hm, psi, chi, fold, q)
687
688 call ion_dynamics_verlet_step1(sys%ions, qtildehalf, p, fold, m_half * td%dt)
689 call ion_dynamics_verlet_step1(sys%ions, q, p, fold, td%dt)
690 end if
691
692 if (td%ions_dyn%cell_relax()) then
693 call messages_not_implemented("OCT with cell dynamics")
694 end if
695
696 ! Here propagate psi one full step, and then simply interpolate to get the state
697 ! at half the time interval. Perhaps one could gain some accuracy by performing two
698 ! successive propagations of half time step.
699 call update_hamiltonian_elec_psi(i-1, sys%namespace, sys%space, sys%gr, sys%ks, sys%hm, sys%ext_partners, &
700 td, tg, par, psi, sys%ions)
701
702 do ik = psi%d%kpt%start, psi%d%kpt%end
703 do ib = psi%group%block_start, psi%group%block_end
704 call psi%group%psib(ib, ik)%copy_data_to(sys%gr%np, st_ref%group%psib(ib, ik))
705 end do
706 end do
707
708 vhxc(:, :) = sys%hm%ks_pot%vhxc(:, :)
709 call propagator_elec_dt(sys%ks, sys%namespace, sys%space, sys%hm, sys%gr, psi, td%tr, abs((i-1)*td%dt), td%dt, &
710 i-1, td%ions_dyn, sys%ions, sys%ext_partners, sys%mc, sys%outp, td%write_handler)
711
712 if (td%ions_dyn%ions_move()) then
713 call ion_dynamics_save_state(td%ions_dyn, sys%ions, ions_state_final)
714 sys%ions%pos = qinitial
715 call hamiltonian_elec_epot_generate(sys%hm, sys%namespace, sys%space, sys%gr, sys%ions, &
716 sys%ext_partners, psi, time = abs((i-1)*td%dt))
717 end if
718
719 do ik = psi%d%kpt%start, psi%d%kpt%end
720 do ib = psi%group%block_start, psi%group%block_end
721 call batch_scal(sys%gr%np, cmplx(m_half, m_zero, real64) , &
722 st_ref%group%psib(ib, ik))
723 call batch_axpy(sys%gr%np, cmplx(m_half, m_zero, real64) , &
724 psi%group%psib(ib, ik), st_ref%group%psib(ib, ik))
725 end do
726 end do
727
728 sys%hm%ks_pot%vhxc(:, :) = m_half * (sys%hm%ks_pot%vhxc(:, :) + vhxc(:, :))
729 call update_hamiltonian_elec_chi(i-1, sys%namespace, sys%space, sys%gr, sys%ks, sys%hm, sys%ext_partners, &
730 td, tg, par, sys%ions, st_ref, qtildehalf)
731 freeze = ion_dynamics_freeze(td%ions_dyn)
732 call propagator_elec_dt(sys%ks, sys%namespace, sys%space, sys%hm, sys%gr, chi, tr_chi, abs((i-1)*td%dt), td%dt, &
733 i-1, td%ions_dyn, sys%ions, sys%ext_partners, sys%mc, sys%outp, td%write_handler)
734 if (freeze) call ion_dynamics_unfreeze(td%ions_dyn)
735
736 if (td%ions_dyn%ions_move()) then
737 call ion_dynamics_restore_state(td%ions_dyn, sys%ions, ions_state_final)
738 call hamiltonian_elec_epot_generate(sys%hm, sys%namespace, sys%space, sys%gr, sys%ions, &
739 sys%ext_partners, psi, time = abs((i-1)*td%dt))
740 call forces_calculate(sys%gr, sys%namespace, sys%ions, sys%hm, sys%ext_partners, &
741 psi, sys%ks, t = abs((i-1)*td%dt), dt = td%dt)
742 call forces_costate_calculate(sys%gr, sys%namespace, sys%ions, sys%hm, psi, chi, fnew, q)
743 call ion_dynamics_verlet_step2(sys%ions, p, fold, fnew, td%dt)
744 safe_deallocate_a(fold)
745 safe_deallocate_a(fnew)
746 end if
747
748 sys%hm%ks_pot%vhxc(:, :) = vhxc(:, :)
749
750 end select
751
752 call oct_prop_dump_states(prop_chi, sys%space, i-1, chi, sys%gr, sys%kpoints, ierr)
753 if (ierr /= 0) then
754 message(1) = "Unable to write OCT states restart."
755 call messages_warning(1, namespace=sys%namespace)
756 end if
757
758 if ((mod(i, 100) == 0).and. mpi_grp_is_root(mpi_world)) call loct_progress_bar(td%max_iter-i, td%max_iter)
759 end do
760 if (mpi_grp_is_root(mpi_world)) then
761 call loct_progress_bar(td%max_iter, td%max_iter)
762 write(stdout, '(1x)')
763 end if
764
765 final_time = loct_clock()
766 write(message(1),'(a,f12.2,a)') 'Propagation time: ', final_time - init_time, ' seconds.'
767 call messages_info(1, namespace=sys%namespace)
768
769 call states_elec_end(st_ref)
770
771 td%dt = -td%dt
772 call update_hamiltonian_elec_psi(0, sys%namespace, sys%space, sys%gr, sys%ks, sys%hm, sys%ext_partners, &
773 td, tg, par, psi, sys%ions)
774 call update_field(0, par_chi, sys%space, sys%gr, sys%hm, sys%ext_partners, sys%ions, qcpsi, qcchi, par, dir = 'b')
775
776 call density_calc(psi, sys%gr, psi%rho)
777 call v_ks_calc(sys%ks, sys%namespace, sys%space, sys%hm, psi, sys%ions, sys%ext_partners)
778 call sys%hm%update(sys%gr, sys%namespace, sys%space, sys%ext_partners)
779
780 call propagator_elec_end(tr_chi)
781
782 safe_deallocate_a(vhxc)
783 call states_elec_end(psi)
784
785 nullify(chi)
786 nullify(psi)
787 nullify(q)
788 nullify(p)
789 safe_deallocate_a(qtildehalf)
790 safe_deallocate_a(qinitial)
791 pop_sub(bwd_step_2)
792 end subroutine bwd_step_2
793 ! ----------------------------------------------------------
794
795
796 ! ----------------------------------------------------------
797 !
798 ! ----------------------------------------------------------
799 subroutine update_hamiltonian_elec_chi(iter, namespace, space, gr, ks, hm, ext_partners, td, tg, par_chi, ions, st, qtildehalf)
800 integer, intent(in) :: iter
801 type(namespace_t), intent(in) :: namespace
802 class(space_t), intent(in) :: space
803 type(grid_t), intent(inout) :: gr
804 type(v_ks_t), intent(inout) :: ks
805 type(hamiltonian_elec_t), intent(inout) :: hm
806 type(partner_list_t), intent(in) :: ext_partners
807 type(td_t), intent(inout) :: td
808 type(target_t), intent(inout) :: tg
809 type(controlfunction_t), intent(in) :: par_chi
810 type(ions_t), intent(in) :: ions
811 type(states_elec_t), intent(inout) :: st
812 real(real64), optional, intent(in) :: qtildehalf(:, :)
813
814 type(states_elec_t) :: inh
815 type(perturbation_ionic_t), pointer :: pert
816 integer :: j, iatom, idim
817 complex(real64), allocatable :: dvpsi(:, :, :), zpsi(:, :), inhzpsi(:, :)
818 integer :: ist, ik, ib
819
821
822 assert(.not. st%parallel_in_states)
823 assert(.not. st%d%kpt%parallel)
824
825 if (target_mode(tg) == oct_targetmode_td) then
826 call states_elec_copy(inh, st)
827 call target_inh(st, gr, hm%kpoints, tg, abs(td%dt)*iter, inh, iter)
828 call hamiltonian_elec_set_inh(hm, inh)
829 call states_elec_end(inh)
830 end if
831
832 if (td%ions_dyn%ions_move()) then
833 assert(present(qtildehalf))
834
835 call states_elec_copy(inh, st)
836 safe_allocate(dvpsi(1:gr%np_part, 1:st%d%dim, 1:space%dim))
837 do ik = inh%d%kpt%start, inh%d%kpt%end
838 do ib = inh%group%block_start, inh%group%block_end
839 call batch_set_zero(inh%group%psib(ib, ik))
840 end do
841 end do
842 safe_allocate(zpsi(1:gr%np_part, 1:st%d%dim))
843 safe_allocate(inhzpsi(1:gr%np_part, 1:st%d%dim))
844 do ist = 1, st%nst
845 do ik = 1, st%nik
846
847 call states_elec_get_state(st, gr, ist, ik, zpsi)
848 call states_elec_get_state(inh, gr, ist, ik, inhzpsi)
849
850 pert => perturbation_ionic_t(namespace, ions)
851 do iatom = 1, ions%natoms
852 call pert%setup_atom(iatom)
853 do idim = 1, space%dim
854 call pert%setup_dir(idim)
855 call pert%zapply(namespace, space, gr, hm, ik, zpsi(:, :), dvpsi(:, :, idim))
856
857 call lalg_axpy(gr%np, st%d%dim, -st%occ(ist, ik)*qtildehalf(iatom, idim), &
858 dvpsi(:, :, idim), inhzpsi(:, :))
859 end do
860 end do
861 safe_deallocate_p(pert)
862 call states_elec_set_state(inh, gr, ist, ik, inhzpsi)
863 end do
864 end do
865
866 safe_deallocate_a(zpsi)
867 safe_deallocate_a(inhzpsi)
868 safe_deallocate_a(dvpsi)
869 call hamiltonian_elec_set_inh(hm, inh)
870 call states_elec_end(inh)
871 end if
872
873 if (hm%theory_level /= independent_particles .and. (.not. ks%frozen_hxc)) then
874 call density_calc(st, gr, st%rho)
875 call oct_exchange_set(hm%oct_exchange, st, gr)
876 end if
877
879
880 do j = iter - 2, iter + 2
881 if (j >= 0 .and. j <= td%max_iter) then
882 call controlfunction_to_h_val(par_chi, ext_partners, j+1)
883 end if
884 end do
885
887 end subroutine update_hamiltonian_elec_chi
888 ! ---------------------------------------------------------
889
890
891 ! ----------------------------------------------------------
893 ! ----------------------------------------------------------
894 subroutine update_hamiltonian_elec_psi(iter, namespace, space, gr, ks, hm, ext_partners, td, tg, par, st, ions)
895 integer, intent(in) :: iter
896 type(namespace_t), intent(in) :: namespace
897 type(electron_space_t), intent(in) :: space
898 type(grid_t), intent(inout) :: gr
899 type(v_ks_t), intent(inout) :: ks
900 type(hamiltonian_elec_t), intent(inout) :: hm
901 type(partner_list_t), intent(in) :: ext_partners
902 type(td_t), intent(inout) :: td
903 type(target_t), intent(inout) :: tg
904 type(controlfunction_t), intent(in) :: par
905 type(states_elec_t), intent(inout) :: st
906 type(ions_t), intent(in) :: ions
907
908 integer :: j
909
911
912 if (target_mode(tg) == oct_targetmode_td) then
914 end if
915
916 if (td%ions_dyn%ions_move()) then
918 end if
919
920 if (hm%theory_level /= independent_particles .and. (.not. ks%frozen_hxc)) then
921 call oct_exchange_remove(hm%oct_exchange)
922 end if
923
925
926 do j = iter - 2, iter + 2
927 if (j >= 0 .and. j <= td%max_iter) then
928 call controlfunction_to_h_val(par, ext_partners, j+1)
929 end if
930 end do
931 if (hm%theory_level /= independent_particles .and. (.not. ks%frozen_hxc)) then
932 call density_calc(st, gr, st%rho)
933 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners)
934 call hm%update(gr, namespace, space, ext_partners)
935 end if
936
938 end subroutine update_hamiltonian_elec_psi
939 ! ---------------------------------------------------------
940
941
942 ! ---------------------------------------------------------
943 subroutine calculate_g(space, gr, hm, lasers, psi, chi, dl, dq)
944 class(space_t), intent(in) :: space
945 type(grid_t), intent(inout) :: gr
946 type(hamiltonian_elec_t), intent(in) :: hm
947 type(lasers_t), intent(in) :: lasers
948 type(states_elec_t), intent(inout) :: psi
949 type(states_elec_t), intent(inout) :: chi
950 complex(real64), intent(inout) :: dl(:), dq(:)
951
952 complex(real64), allocatable :: zpsi(:, :), zoppsi(:, :)
953 integer :: no_parameters, j, ik, p
954
955 push_sub(calculate_g)
956
957 no_parameters = lasers%no_lasers
958
959 safe_allocate(zpsi(1:gr%np_part, 1:chi%d%dim))
960 safe_allocate(zoppsi(1:gr%np_part, 1:chi%d%dim))
961
962 do j = 1, no_parameters
963
964 dl(j) = m_z0
965 do ik = 1, psi%nik
966 do p = 1, psi%nst
967
968 call states_elec_get_state(psi, gr, p, ik, zpsi)
969
970 zoppsi = m_z0
971 if (allocated(hm%ep%a_static)) then
972 call vlaser_operator_linear(lasers%lasers(j), gr%der, hm%d, zpsi, &
973 zoppsi, ik, hm%ep%gyromagnetic_ratio, hm%ep%a_static)
974 else
975 call vlaser_operator_linear(lasers%lasers(j), gr%der, hm%d, zpsi, &
976 zoppsi, ik, hm%ep%gyromagnetic_ratio)
977 end if
978
979 call states_elec_get_state(chi, gr, p, ik, zpsi)
980 dl(j) = dl(j) + zmf_dotp(gr, psi%d%dim, zpsi, zoppsi)
981 end do
982 end do
983
984 ! The quadratic part should only be computed if necessary.
985 if (laser_kind(lasers%lasers(j)) == e_field_magnetic) then
986
987 dq(j) = m_z0
988 do ik = 1, psi%nik
989 do p = 1, psi%nst
990 zoppsi = m_z0
991
992 call states_elec_get_state(psi, gr, p, ik, zpsi)
993 call vlaser_operator_quadratic(lasers%lasers(j), gr, space, zpsi, zoppsi)
994
995 call states_elec_get_state(chi, gr, p, ik, zpsi)
996 dq(j) = dq(j) + zmf_dotp(gr, psi%d%dim, zpsi, zoppsi)
997
998 end do
999 end do
1000
1001 else
1002 dq(j) = m_z0
1003 end if
1004 end do
1005
1006 safe_deallocate_a(zpsi)
1007 safe_deallocate_a(zoppsi)
1008
1009 pop_sub(calculate_g)
1010 end subroutine calculate_g
1011 ! ---------------------------------------------------------
1012
1013
1014
1015
1028 subroutine update_field(iter, cp, space, gr, hm, ext_partners, ions, qcpsi, qcchi, cpp, dir)
1029 class(space_t), intent(in) :: space
1030 integer, intent(in) :: iter
1031 type(controlfunction_t), intent(inout) :: cp
1032 type(grid_t), intent(inout) :: gr
1033 type(hamiltonian_elec_t), intent(in) :: hm
1034 type(partner_list_t), intent(in) :: ext_partners
1035 type(ions_t), intent(in) :: ions
1036 type(opt_control_state_t), intent(inout) :: qcpsi
1037 type(opt_control_state_t), intent(inout) :: qcchi
1038 type(controlfunction_t), intent(in) :: cpp
1039 character(len=1), intent(in) :: dir
1040
1041 complex(real64) :: d1, pol(3)
1042 complex(real64), allocatable :: dl(:), dq(:), zpsi(:, :), zchi(:, :)
1043 real(real64), allocatable :: d(:)
1044 integer :: j, no_parameters, iatom
1045 type(states_elec_t), pointer :: psi, chi
1046 real(real64), pointer :: q(:, :)
1047 type(lasers_t), pointer :: lasers
1048
1049 push_sub(update_field)
1050
1051 psi => opt_control_point_qs(qcpsi)
1052 chi => opt_control_point_qs(qcchi)
1053 q => opt_control_point_q(qcchi)
1054
1055 no_parameters = controlfunction_number(cp)
1056
1057 safe_allocate(dl(1:no_parameters))
1058 safe_allocate(dq(1:no_parameters))
1059 safe_allocate( d(1:no_parameters))
1060
1061
1062 lasers => list_get_lasers(ext_partners)
1063 if(associated(lasers)) then
1064 call calculate_g(space, gr, hm, lasers, psi, chi, dl, dq)
1065 end if
1066
1067 d1 = m_z1
1068 if (zbr98_) then
1069 safe_allocate(zpsi(1:gr%np, 1:psi%d%dim))
1070 safe_allocate(zchi(1:gr%np, 1:chi%d%dim))
1071
1072 call states_elec_get_state(psi, gr, 1, 1, zpsi)
1073 call states_elec_get_state(chi, gr, 1, 1, zchi)
1074
1075 d1 = zmf_dotp(gr, psi%d%dim, zpsi, zchi)
1076 do j = 1, no_parameters
1077 d(j) = aimag(d1*dl(j)) / controlfunction_alpha(cp, j)
1078 end do
1079
1080 safe_deallocate_a(zpsi)
1081 safe_deallocate_a(zchi)
1082
1083 elseif (gradients_) then
1084 do j = 1, no_parameters
1085 d(j) = m_two * aimag(dl(j))
1086 end do
1087 else
1088 do j = 1, no_parameters
1089 d(j) = aimag(dl(j)) / controlfunction_alpha(cp, j)
1090 end do
1091 end if
1092
1093 ! This is for the classical target.
1094 if (dir == 'b' .and. associated(lasers)) then
1095 pol = laser_polarization(lasers%lasers(1))
1096 do iatom = 1, ions%natoms
1097 d(1) = d(1) - ions%charge(iatom) * real(sum(pol(1:ions%space%dim)*q(iatom, 1:ions%space%dim)), real64)
1098 end do
1099 end if
1100
1101
1102 if (dir == 'f') then
1103 call controlfunction_update(cp, cpp, dir, iter, delta_, d, dq)
1104 else
1105 call controlfunction_update(cp, cpp, dir, iter, eta_, d, dq)
1106 end if
1107
1108 nullify(q)
1109 nullify(psi)
1110 nullify(chi)
1111 safe_deallocate_a(d)
1112 safe_deallocate_a(dl)
1113 safe_deallocate_a(dq)
1114 pop_sub(update_field)
1115 end subroutine update_field
1116 ! ---------------------------------------------------------
1117
1118
1119 ! ---------------------------------------------------------
1120 subroutine oct_prop_init(prop, namespace, dirname, mesh, mc)
1121 type(oct_prop_t), intent(inout) :: prop
1122 type(namespace_t), intent(in) :: namespace
1123 character(len=*), intent(in) :: dirname
1124 class(mesh_t), intent(in) :: mesh
1125 type(multicomm_t), intent(in) :: mc
1126
1127 integer :: j, ierr
1128
1129 push_sub(oct_prop_init)
1130
1131 prop%dirname = dirname
1132 prop%niter = niter_
1133 prop%number_checkpoints = number_checkpoints_
1134
1135 ! The OCT_DIR//trim(dirname) will be used to write and read information during the calculation,
1136 ! so they need to use the same path.
1137 call restart_init(prop%restart_dump, namespace, restart_oct, restart_type_dump, mc, ierr, mesh=mesh)
1138 call restart_init(prop%restart_load, namespace, restart_oct, restart_type_load, mc, ierr, mesh=mesh)
1139
1140 safe_allocate(prop%iter(1:prop%number_checkpoints+2))
1141 prop%iter(1) = 0
1142 do j = 1, prop%number_checkpoints
1143 prop%iter(j+1) = nint(real(niter_, real64) /(prop%number_checkpoints+1) * j)
1144 end do
1145 prop%iter(prop%number_checkpoints+2) = niter_
1146
1147 pop_sub(oct_prop_init)
1148 end subroutine oct_prop_init
1149 ! ---------------------------------------------------------
1150
1151
1152 ! ---------------------------------------------------------
1153 subroutine oct_prop_end(prop)
1154 type(oct_prop_t), intent(inout) :: prop
1155
1156 push_sub(oct_prop_end)
1157
1158 call restart_end(prop%restart_load)
1159 call restart_end(prop%restart_dump)
1160
1161 safe_deallocate_a(prop%iter)
1162 ! This routine should maybe delete the files?
1163
1164 pop_sub(oct_prop_end)
1165 end subroutine oct_prop_end
1166 ! ---------------------------------------------------------
1167
1168
1169 ! ---------------------------------------------------------
1170 subroutine oct_prop_check(prop, namespace, space, psi, mesh, kpoints, iter)
1171 type(oct_prop_t), intent(inout) :: prop
1172 type(namespace_t), intent(in) :: namespace
1173 class(space_t), intent(in) :: space
1174 type(states_elec_t), intent(inout) :: psi
1175 class(mesh_t), intent(in) :: mesh
1176 type(kpoints_t), intent(in) :: kpoints
1177 integer, intent(in) :: iter
1178
1179 type(states_elec_t) :: stored_st
1180 character(len=80) :: dirname
1181 integer :: j, ierr
1182 complex(real64) :: overlap, prev_overlap
1183 real(real64), parameter :: WARNING_THRESHOLD = 1.0e-2_real64
1184
1185 push_sub(oct_prop_check)
1186
1187 do j = 1, prop%number_checkpoints + 2
1188 if (prop%iter(j) == iter) then
1189 call states_elec_copy(stored_st, psi)
1190 write(dirname,'(a, i4.4)') trim(prop%dirname), j
1191 call restart_open_dir(prop%restart_load, dirname, ierr)
1192 if (ierr == 0) then
1193 call states_elec_load(prop%restart_load, namespace, space, stored_st, mesh, kpoints, &
1194 fixed_occ=.true., ierr=ierr, verbose=.false.)
1195 end if
1196 if (ierr /= 0) then
1197 message(1) = "Unable to read wavefunctions from '"//trim(dirname)//"'."
1198 call messages_fatal(1, namespace=namespace)
1199 end if
1200 call restart_close_dir(prop%restart_load)
1201 prev_overlap = zstates_elec_mpdotp(namespace, mesh, stored_st, stored_st)
1202 overlap = zstates_elec_mpdotp(namespace, mesh, stored_st, psi)
1203 if (abs(overlap - prev_overlap) > warning_threshold) then
1204 write(message(1), '(a,es13.4)') &
1205 "Forward-backward propagation produced an error of", abs(overlap-prev_overlap)
1206 write(message(2), '(a,i8)') "Iter = ", iter
1207 call messages_warning(2, namespace=namespace)
1208 end if
1209 ! Restore state only if the number of checkpoints is larger than zero.
1210 if (prop%number_checkpoints > 0) then
1211 call states_elec_end(psi)
1212 call states_elec_copy(psi, stored_st)
1213 end if
1214 call states_elec_end(stored_st)
1215 end if
1216 end do
1217 pop_sub(oct_prop_check)
1218 end subroutine oct_prop_check
1219 ! ---------------------------------------------------------
1220
1221
1222 ! ---------------------------------------------------------
1223 subroutine oct_prop_dump_states(prop, space, iter, psi, mesh, kpoints, ierr)
1224 type(oct_prop_t), intent(inout) :: prop
1225 class(space_t), intent(in) :: space
1226 integer, intent(in) :: iter
1227 type(states_elec_t), intent(in) :: psi
1228 class(mesh_t), intent(in) :: mesh
1229 type(kpoints_t), intent(in) :: kpoints
1230 integer, intent(out) :: ierr
1231
1232 integer :: j, err
1233 character(len=80) :: dirname
1234
1235 push_sub(oct_prop_dump_states)
1236
1237 ierr = 0
1238
1239 if (restart_skip(prop%restart_dump)) then
1240 pop_sub(oct_prop_dump_states)
1241 return
1242 end if
1243
1244 message(1) = "Debug: Writing OCT propagation states restart."
1245 call messages_info(1, debug_only=.true.)
1247 do j = 1, prop%number_checkpoints + 2
1248 if (prop%iter(j) == iter) then
1249 write(dirname,'(a,i4.4)') trim(prop%dirname), j
1250 call restart_open_dir(prop%restart_dump, dirname, err)
1251 if (err == 0) then
1252 call states_elec_dump(prop%restart_dump, space, psi, mesh, kpoints, err, iter, verbose = .false.)
1253 end if
1254 if (err /= 0) then
1255 message(1) = "Unable to write wavefunctions to '"//trim(dirname)//"'."
1256 call messages_warning(1)
1257 ierr = ierr + 2**j
1258 end if
1259 call restart_close_dir(prop%restart_dump)
1260 end if
1261 end do
1262
1263 message(1) = "Debug: Writing OCT propagation states restart done."
1264 call messages_info(1, debug_only=.true.)
1265
1266 pop_sub(oct_prop_dump_states)
1267 end subroutine oct_prop_dump_states
1268 ! ---------------------------------------------------------
1269
1270
1271 ! ---------------------------------------------------------
1272 subroutine oct_prop_load_states(prop, namespace, space, psi, mesh, kpoints, iter, ierr)
1273 type(oct_prop_t), intent(inout) :: prop
1274 type(namespace_t), intent(in) :: namespace
1275 class(space_t), intent(in) :: space
1276 type(states_elec_t), intent(inout) :: psi
1277 class(mesh_t), intent(in) :: mesh
1278 type(kpoints_t), intent(in) :: kpoints
1279 integer, intent(in) :: iter
1280 integer, intent(out) :: ierr
1281
1282 integer :: j, err
1283 character(len=80) :: dirname
1284
1285 push_sub(oct_prop_load_states)
1286
1287 ierr = 0
1288
1289 if (restart_skip(prop%restart_load)) then
1290 ierr = -1
1291 pop_sub(oct_prop_load_states)
1292 return
1293 end if
1294
1295 message(1) = "Debug: Reading OCT propagation states restart."
1296 call messages_info(1, namespace=namespace, debug_only=.true.)
1297
1298 do j = 1, prop%number_checkpoints + 2
1299 if (prop%iter(j) == iter) then
1300 write(dirname,'(a, i4.4)') trim(prop%dirname), j
1301 call restart_open_dir(prop%restart_load, dirname, err)
1302 if (err == 0) then
1303 call states_elec_load(prop%restart_load, namespace, space, psi, mesh, kpoints, &
1304 fixed_occ=.true., ierr=err, verbose=.false.)
1305 end if
1306 if (err /= 0) then
1307 message(1) = "Unable to read wavefunctions from '"//trim(dirname)//"'."
1308 call messages_warning(1, namespace=namespace)
1309 ierr = ierr + 2**j
1310 end if
1311 call restart_close_dir(prop%restart_load)
1312 end if
1313 end do
1314
1315 message(1) = "Debug: Reading OCT propagation states restart done."
1316 call messages_info(1, namespace=namespace, debug_only=.true.)
1317
1318 pop_sub(oct_prop_load_states)
1319 end subroutine oct_prop_load_states
1320 ! ---------------------------------------------------------
1321
1322 ! ---------------------------------------------------------
1323 subroutine vlaser_operator_quadratic(laser, mesh, space, psi, hpsi)
1324 type(laser_t), intent(in) :: laser
1325 class(mesh_t), intent(in) :: mesh
1326 class(space_t), intent(in) :: space
1327 complex(real64), intent(inout) :: psi(:,:)
1328 complex(real64), intent(inout) :: hpsi(:,:)
1329
1330 integer :: ip
1331 logical :: vector_potential, magnetic_field
1332
1333 real(real64) :: a_field(3), a_field_prime(3), b_prime(3)
1334 real(real64), allocatable :: aa(:, :), a_prime(:, :)
1335
1337
1338 a_field = m_zero
1339
1340 vector_potential = .false.
1341 magnetic_field = .false.
1342
1343 select case (laser_kind(laser))
1344 case (e_field_electric) ! do nothing
1345 case (e_field_magnetic)
1346 if (.not. allocated(aa)) then
1347 safe_allocate(aa(1:mesh%np_part, 1:space%dim))
1348 aa = m_zero
1349 safe_allocate(a_prime(1:mesh%np_part, 1:space%dim))
1350 end if
1351 a_prime = m_zero
1352 call laser_vector_potential(laser, mesh, a_prime)
1353 aa = aa + a_prime
1354 b_prime = m_zero
1355 call laser_field(laser, b_prime(1:space%dim))
1356 magnetic_field = .true.
1358 a_field_prime = m_zero
1359 call laser_field(laser, a_field_prime(1:space%dim))
1360 a_field = a_field + a_field_prime
1361 vector_potential = .true.
1362 end select
1363
1364 if (magnetic_field) then
1365 do ip = 1, mesh%np
1366 hpsi(ip, :) = hpsi(ip, :) + m_half * &
1367 dot_product(aa(ip, 1:space%dim), aa(ip, 1:space%dim)) * psi(ip, :) / p_c**2
1368 end do
1369 safe_deallocate_a(aa)
1370 safe_deallocate_a(a_prime)
1371 end if
1372 if (vector_potential) then
1373 do ip = 1, mesh%np
1374 hpsi(ip, :) = hpsi(ip, :) + m_half * &
1375 dot_product(a_field(1:space%dim), a_field(1:space%dim))*psi(ip, :) / p_c**2
1376 end do
1377 end if
1378
1380 end subroutine vlaser_operator_quadratic
1381
1382 ! ---------------------------------------------------------
1383 subroutine vlaser_operator_linear(laser, der, std, psi, hpsi, ik, gyromagnetic_ratio, a_static)
1384 type(laser_t), intent(in) :: laser
1385 type(derivatives_t), intent(in) :: der
1386 type(states_elec_dim_t), intent(in) :: std
1387 complex(real64), contiguous, intent(inout) :: psi(:,:)
1388 complex(real64), intent(inout) :: hpsi(:,:)
1389 integer, intent(in) :: ik
1390 real(real64), intent(in) :: gyromagnetic_ratio
1391 real(real64), optional, intent(in) :: a_static(:,:)
1392
1393 integer :: ip, idim
1394 logical :: electric_field, vector_potential, magnetic_field
1395 complex(real64), allocatable :: grad(:, :, :), lhpsi(:, :)
1396
1397 real(real64) :: a_field(3), a_field_prime(3), bb(3), b_prime(3)
1398
1399 real(real64), allocatable :: vv(:), pot(:), aa(:, :), a_prime(:, :)
1400
1401 push_sub(vlaser_operator_linear)
1402
1403 a_field = m_zero
1404 bb = m_zero
1405
1406 electric_field = .false.
1407 vector_potential = .false.
1408 magnetic_field = .false.
1409
1410 select case (laser_kind(laser))
1412 if (.not. allocated(vv)) then
1413 safe_allocate(vv(1:der%mesh%np))
1414 end if
1415 vv = m_zero
1416 call laser_potential(laser, der%mesh, vv)
1417 electric_field = .true.
1418
1419 case (e_field_electric)
1420 if (.not. allocated(vv)) then
1421 safe_allocate(vv(1:der%mesh%np))
1422 vv = m_zero
1423 safe_allocate(pot(1:der%mesh%np))
1424 end if
1425 pot = m_zero
1426 call laser_potential(laser, der%mesh, pot)
1427 call lalg_axpy(der%mesh%np, m_one, pot, vv)
1428 electric_field = .true.
1429 safe_deallocate_a(pot)
1430
1431 case (e_field_magnetic)
1432 if (.not. allocated(aa)) then
1433 safe_allocate(aa(1:der%mesh%np_part, 1:der%dim))
1434 aa = m_zero
1435 safe_allocate(a_prime(1:der%mesh%np_part, 1:der%dim))
1436 end if
1437 a_prime = m_zero
1438 call laser_vector_potential(laser, der%mesh, a_prime)
1439 aa = aa + a_prime
1440 b_prime = m_zero
1441 call laser_field(laser, b_prime(1:der%dim))
1442 bb = bb + b_prime
1443 magnetic_field = .true.
1445 a_field_prime = m_zero
1446 call laser_field(laser, a_field_prime(1:der%dim))
1447 a_field = a_field + a_field_prime
1448 vector_potential = .true.
1449 end select
1450
1451 if (electric_field) then
1452 do idim = 1, std%dim
1453 hpsi(1:der%mesh%np, idim)= hpsi(1:der%mesh%np, idim) + vv(1:der%mesh%np) * psi(1:der%mesh%np, idim)
1454 end do
1455 safe_deallocate_a(vv)
1456 end if
1457
1458 if (magnetic_field) then
1459 safe_allocate(grad(1:der%mesh%np_part, 1:der%dim, 1:std%dim))
1460
1461 do idim = 1, std%dim
1462 call zderivatives_grad(der, psi(:, idim), grad(:, :, idim))
1463 end do
1464
1465 ! If there is a static magnetic field, its associated vector potential is coupled with
1466 ! the time-dependent one defined as a "laser" (ideally one should just add them all and
1467 ! do the calculation only once...). Note that h%ep%a_static already has been divided
1468 ! by P_c, and therefore here we only divide by P_c, and not P_c**2.
1469 !
1470 ! We put a minus sign, since for the moment vector potential for
1471 ! lasers and for the static magnetic field use a different
1472 ! convetion.
1473 if (present(a_static)) then
1474 do ip = 1, der%mesh%np
1475 hpsi(ip, :) = hpsi(ip, :) - dot_product(aa(ip, 1:der%dim), a_static(ip, 1:der%dim)) * psi(ip, :) / p_c
1476 end do
1477 end if
1478
1479 select case (std%ispin)
1481 do ip = 1, der%mesh%np
1482 hpsi(ip, 1) = hpsi(ip, 1) - m_zi * dot_product(aa(ip, 1:der%dim), grad(ip, 1:der%dim, 1)) / p_c
1483 end do
1484 case (spinors)
1485 do ip = 1, der%mesh%np
1486 do idim = 1, std%dim
1487 hpsi(ip, idim) = hpsi(ip, idim) - m_zi * &
1488 dot_product(aa(ip, 1:der%dim), grad(ip, 1:der%dim, idim)) / p_c
1489 end do
1490 end do
1491 end select
1492
1493
1494 select case (std%ispin)
1495 case (spin_polarized)
1496 safe_allocate(lhpsi(1:der%mesh%np, 1:std%dim))
1497 if (modulo(ik+1, 2) == 0) then ! we have a spin down
1498 lhpsi(1:der%mesh%np, 1) = - m_half / p_c * norm2(bb) * psi(1:der%mesh%np, 1)
1499 else
1500 lhpsi(1:der%mesh%np, 1) = + m_half / p_c * norm2(bb) * psi(1:der%mesh%np, 1)
1501 end if
1502 hpsi(1:der%mesh%np, :) = hpsi(1:der%mesh%np, :) + (gyromagnetic_ratio * m_half) * lhpsi(1:der%mesh%np, :)
1503 safe_deallocate_a(lhpsi)
1504
1505 case (spinors)
1506 safe_allocate(lhpsi(1:der%mesh%np, 1:std%dim))
1507 lhpsi(1:der%mesh%np, 1) = m_half / p_c * (bb(3) * psi(1:der%mesh%np, 1) &
1508 + cmplx(bb(1), -bb(2), real64) * psi(1:der%mesh%np, 2))
1509 lhpsi(1:der%mesh%np, 2) = m_half / p_c * (-bb(3) * psi(1:der%mesh%np, 2) &
1510 + cmplx(bb(1), bb(2), real64) * psi(1:der%mesh%np, 1))
1511 hpsi(1:der%mesh%np, :) = hpsi(1:der%mesh%np, :) + (gyromagnetic_ratio * m_half) * lhpsi(1:der%mesh%np, :)
1512 safe_deallocate_a(lhpsi)
1513 end select
1514
1515 safe_deallocate_a(grad)
1516 safe_deallocate_a(aa)
1517 safe_deallocate_a(a_prime)
1518 end if
1519
1520 if (vector_potential) then
1521 safe_allocate(grad(1:der%mesh%np_part, 1:der%dim, 1:std%dim))
1522
1523 do idim = 1, std%dim
1524 call zderivatives_grad(der, psi(:, idim), grad(:, :, idim))
1525 end do
1526
1527 select case (std%ispin)
1529 do ip = 1, der%mesh%np
1530 hpsi(ip, 1) = hpsi(ip, 1) - m_zi * dot_product(a_field(1:der%dim), grad(ip, 1:der%dim, 1)) / p_c
1531 end do
1532 case (spinors)
1533 do ip = 1, der%mesh%np
1534 do idim = 1, std%dim
1535 hpsi(ip, idim) = hpsi(ip, idim) - m_zi * &
1536 dot_product(a_field(1:der%dim), grad(ip, 1:der%dim, idim)) / p_c
1537 end do
1538 end do
1539 end select
1540 safe_deallocate_a(grad)
1541 end if
1542
1543 pop_sub(vlaser_operator_linear)
1544 end subroutine vlaser_operator_linear
1545
1546
1547end module propagation_oct_m
1548
1549!! Local Variables:
1550!! mode: f90
1551!! coding: utf-8
1552!! End:
batchified version of the BLAS axpy routine:
Definition: batch_ops.F90:154
scale a batch by a constant or vector
Definition: batch_ops.F90:162
constant times a vector plus a vector
Definition: lalg_basic.F90:171
integer, parameter, public mask_absorbing
This module implements batches of mesh functions.
Definition: batch.F90:133
This module implements common operations on batches of mesh functions.
Definition: batch_ops.F90:116
subroutine, public batch_set_zero(this, np, async)
fill all mesh functions of the batch with zero
Definition: batch_ops.F90:242
This module contains the definition of the data type that holds a "control function" used for OCT run...
subroutine, public controlfunction_to_h_val(cp, ext_partners, val)
subroutine, public controlfunction_to_realtime(par)
subroutine, public controlfunction_update(cp, cpp, dir, iter, mu, dd, dq)
Update the control function(s) given in "cp", according to the formula cp = (1 - mu) * cpp + mu * dd ...
subroutine, public controlfunction_end(cp)
real(real64) pure function, public controlfunction_alpha(par, ipar)
integer pure function, public controlfunction_number(par)
subroutine, public controlfunction_copy(cp_out, cp_in)
subroutine, public controlfunction_to_h(cp, ext_partners)
subroutine, public controlfunction_to_basis(par)
This module implements a calculator for the density and defines related functions.
Definition: density.F90:120
subroutine, public density_calc(st, gr, density, istin)
Computes the density from the orbitals in st.
Definition: density.F90:612
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
subroutine, public zderivatives_grad(der, ff, op_ff, ghost_update, set_bc, to_cartesian)
apply the gradient to a mesh function
integer, parameter, public unpolarized
Parameters...
integer, parameter, public spinors
integer, parameter, public spin_polarized
subroutine, public energy_calc_total(namespace, space, hm, gr, st, ext_partners, iunit, full)
This subroutine calculates the total energy of the system. Basically, it adds up the KS eigenvalues,...
subroutine, public epot_precalc_local_potential(ep, namespace, gr, ions)
Definition: epot.F90:574
logical function, public list_has_gauge_field(partners)
type(lasers_t) function, pointer, public list_get_lasers(partners)
subroutine, public forces_costate_calculate(gr, namespace, ions, hm, psi, chi, ff, qq)
Definition: forces.F90:218
subroutine, public forces_calculate(gr, namespace, ions, hm, ext_partners, st, ks, vhxc_old, t, dt)
Definition: forces.F90:339
real(real64), parameter, public m_two
Definition: global.F90:190
real(real64), parameter, public m_zero
Definition: global.F90:188
complex(real64), parameter, public m_z0
Definition: global.F90:198
complex(real64), parameter, public m_zi
Definition: global.F90:202
complex(real64), parameter, public m_z1
Definition: global.F90:199
real(real64), parameter, public m_half
Definition: global.F90:194
real(real64), parameter, public p_c
Electron gyromagnetic ratio, see Phys. Rev. Lett. 130, 071801 (2023)
Definition: global.F90:224
real(real64), parameter, public m_one
Definition: global.F90:189
This module implements the underlying real-space grid.
Definition: grid.F90:117
subroutine, public hamiltonian_elec_set_inh(hm, st)
subroutine, public zvmask(mesh, hm, st)
subroutine, public hamiltonian_elec_adjoint(hm)
subroutine, public hamiltonian_elec_epot_generate(this, namespace, space, gr, ions, ext_partners, st, time)
subroutine, public hamiltonian_elec_remove_inh(hm)
subroutine, public hamiltonian_elec_not_adjoint(hm)
This module defines classes and functions for interaction partners.
subroutine, public ion_dynamics_verlet_step2(ions, v, fold, fnew, dt)
A bare verlet integrator.
subroutine, public ion_dynamics_verlet_step1(ions, q, v, fold, dt)
A bare verlet integrator.
subroutine, public ion_dynamics_restore_state(this, ions, state)
subroutine, public ion_dynamics_propagate(this, ions, time, dt, namespace)
Interface for the ion/cell dynamics.
subroutine, public ion_dynamics_save_state(this, ions, state)
subroutine, public ion_dynamics_unfreeze(this)
Unfreezes the ionic movement.
logical function, public ion_dynamics_freeze(this)
Freezes the ionic movement.
A module to handle KS potential, without the external potential.
integer, parameter, public independent_particles
complex(real64) function, dimension(3), public laser_polarization(laser)
Definition: lasers.F90:728
subroutine, public laser_vector_potential(laser, mesh, aa, time)
Definition: lasers.F90:1082
integer, parameter, public e_field_electric
Definition: lasers.F90:177
integer, parameter, public e_field_vector_potential
Definition: lasers.F90:177
subroutine, public laser_potential(laser, mesh, pot, time)
Definition: lasers.F90:1047
integer, parameter, public e_field_scalar_potential
Definition: lasers.F90:177
integer pure elemental function, public laser_kind(laser)
Definition: lasers.F90:717
subroutine, public laser_field(laser, field, time)
Retrieves the value of either the electric or the magnetic field. If the laser is given by a scalar p...
Definition: lasers.F90:1119
integer, parameter, public e_field_magnetic
Definition: lasers.F90:177
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:118
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1114
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:538
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:161
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:415
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:617
logical function mpi_grp_is_root(grp)
Is the current MPI process of grpcomm, root.
Definition: mpi.F90:430
type(mpi_grp_t), public mpi_world
Definition: mpi.F90:266
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:145
subroutine, public oct_exchange_remove(this)
subroutine, public oct_exchange_set(this, st, mesh)
This module holds the "opt_control_state_t" datatype, which contains a quantum-classical state.
real(real64) function, dimension(:, :), pointer, public opt_control_point_p(ocs)
subroutine, public opt_control_set_classical(ions, ocs)
real(real64) function, dimension(:, :), pointer, public opt_control_point_q(ocs)
type(states_elec_t) function, pointer, public opt_control_point_qs(ocs)
subroutine, public opt_control_state_null(ocs)
subroutine, public opt_control_state_copy(ocsout, ocsin)
subroutine, public opt_control_get_classical(ions, ocs)
subroutine, public propagation_mod_init(niter, eta, delta, number_checkpoints, zbr98, gradients)
This subroutine must be called before any QOCT propagations are done. It simply stores in the module ...
subroutine, public oct_prop_end(prop)
subroutine update_hamiltonian_elec_chi(iter, namespace, space, gr, ks, hm, ext_partners, td, tg, par_chi, ions, st, qtildehalf)
subroutine update_hamiltonian_elec_psi(iter, namespace, space, gr, ks, hm, ext_partners, td, tg, par, st, ions)
subroutine oct_prop_load_states(prop, namespace, space, psi, mesh, kpoints, iter, ierr)
subroutine, public bwd_step(sys, td, tg, par, par_chi, qcchi, prop_chi, prop_psi)
subroutine update_field(iter, cp, space, gr, hm, ext_partners, ions, qcpsi, qcchi, cpp, dir)
Calculates the value of the control functions at iteration iter, from the state psi and the Lagrange-...
subroutine vlaser_operator_linear(laser, der, std, psi, hpsi, ik, gyromagnetic_ratio, a_static)
subroutine, public propagate_forward(sys, td, par, tg, qcpsi, prop, write_iter)
subroutine calculate_g(space, gr, hm, lasers, psi, chi, dl, dq)
subroutine, public oct_prop_check(prop, namespace, space, psi, mesh, kpoints, iter)
subroutine, public fwd_step(sys, td, tg, par, par_chi, qcpsi, prop_chi, prop_psi)
subroutine, public propagate_backward(sys, td, qcpsi, prop)
subroutine vlaser_operator_quadratic(laser, mesh, space, psi, hpsi)
subroutine, public oct_prop_init(prop, namespace, dirname, mesh, mc)
subroutine oct_prop_dump_states(prop, space, iter, psi, mesh, kpoints, ierr)
subroutine, public bwd_step_2(sys, td, tg, par, par_chi, qcchi, prop_chi, prop_psi)
integer, parameter, public prop_explicit_runge_kutta4
subroutine, public propagator_elec_copy(tro, tri)
subroutine, public propagator_elec_remove_scf_prop(tr)
subroutine, public propagator_elec_dt(ks, namespace, space, hm, gr, st, tr, time, dt, nt, ions_dyn, ions, ext_partners, mc, outp, write_handler, scsteps, update_energy, qcchi)
Propagates st from time - dt to t. If dt<0, it propagates backwards from t+|dt| to t.
subroutine, public propagator_elec_end(tr)
integer, parameter, public restart_oct
Definition: restart.F90:200
subroutine, public restart_init(restart, namespace, data_type, type, mc, ierr, mesh, dir, exact)
Initializes a restart object.
Definition: restart.F90:516
integer, parameter, public restart_type_dump
Definition: restart.F90:245
logical pure function, public restart_skip(restart)
Returns true if the restart information should neither be read nor written. This might happen because...
Definition: restart.F90:969
subroutine, public restart_open_dir(restart, dirname, ierr)
Change the restart directory to dirname, where "dirname" is a subdirectory of the base restart direct...
Definition: restart.F90:772
integer, parameter, public restart_type_load
Definition: restart.F90:245
subroutine, public restart_end(restart)
Definition: restart.F90:722
subroutine, public restart_close_dir(restart)
Change back to the base directory. To be called after restart_open_dir.
Definition: restart.F90:806
This module handles spin dimensions of the states and the k-point distribution.
subroutine, public states_elec_end(st)
finalize the states_elec_t object
subroutine, public states_elec_copy(stout, stin, exclude_wfns, exclude_eigenval, special)
make a (selective) copy of a states_elec_t object
This module handles reading and writing restart information for the states_elec_t.
subroutine, public states_elec_dump(restart, space, st, mesh, kpoints, ierr, iter, lr, st_start_writing, verbose)
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...
integer, parameter, public oct_tg_velocity
Definition: target_low.F90:212
integer, parameter, public oct_tg_hhgnew
Definition: target_low.F90:212
integer pure function, public target_type(tg)
Definition: target_low.F90:265
integer, parameter, public oct_targetmode_td
Definition: target_low.F90:227
integer pure function, public target_mode(tg)
Definition: target_low.F90:243
logical pure function, public target_move_ions(tg)
Definition: target_low.F90:281
subroutine, public target_init_propagation(tg)
This routine performs all the things that must be initialized prior to a forward evolution,...
Definition: target.F90:186
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:483
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:440
Definition: td.F90:114
subroutine, public td_write_data(writ)
Definition: td_write.F90:1208
subroutine, public td_write_end(writ)
Definition: td_write.F90:991
subroutine, public td_write_iter(writ, namespace, space, outp, gr, st, hm, ions, ext_partners, kick, ks, dt, iter, mc, recalculate_gs)
Definition: td_write.F90:1038
subroutine, public td_write_init(writ, namespace, space, outp, gr, st, hm, ions, ext_partners, ks, ions_move, with_gauge_field, kick, iter, max_iter, dt, mc)
Initialize files to write when prograting in time.
Definition: td_write.F90:374
subroutine, public v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_eigenval, time, calc_energy, calc_current, force_semilocal)
Definition: v_ks.F90:744
This is the data type used to hold a control function.
class representing derivatives
Extension of space that contains the knowledge of the spin dimension.
Class describing the electron system.
Definition: electrons.F90:218
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:168
Describes mesh distribution to nodes.
Definition: mesh.F90:186
Stores all communicators and groups.
Definition: multicomm.F90:206
This is the datatype that contains the objects that are propagated: in principle this could be both t...
class for organizing spins and k-points
The states_elec_t class contains all electronic wave functions.
int true(void)