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