43 use,
intrinsic :: iso_fortran_env
93 integer :: number_checkpoints
94 integer,
allocatable :: iter(:)
96 character(len=100) :: dirname
97 type(restart_t) :: restart_load
98 type(restart_t) :: restart_dump
104 integer :: number_checkpoints_
106 real(real64) :: delta_
108 logical :: 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
125 assert(.not. (zbr98 .and. gradients))
132 number_checkpoints_ = number_checkpoints
134 gradients_ = gradients
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
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
162 real(real64) :: init_time, final_time
166 message(1) =
"Info: Forward propagation."
171 write_iter_ = .false.
172 if (
present(write_iter)) write_iter_ = write_iter
175 if (sys%st%pack_states .and. sys%hm%apply_packed())
call psi%pack()
178 if (write_iter_)
then
179 call td_write_init(write_handler, sys%namespace, sys%space, sys%outp, sys%gr, sys%st, sys%hm, &
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)
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)
204 safe_allocate_source_a(x_initial, sys%ions%pos)
207 sys%ions%tot_force =
m_zero
212 call target_tdcalc(tg, sys%namespace, sys%space, sys%hm, sys%gr, sys%ions, sys%ext_partners, psi, 0, td%max_iter)
214 if (
present(prop))
then
217 message(1) =
"Unable to write OCT states restart."
226 do istep = 1, td%max_iter
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%outp, td%write_handler)
232 if (
present(prop))
then
235 message(1) =
"Unable to write OCT states restart."
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)
247 call target_tdcalc(tg, sys%namespace, sys%space, sys%hm, sys%gr, sys%ions, sys%ext_partners, psi, istep, td%max_iter)
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)
254 if (any(ii == sys%outp%output_interval + 1) .or. istep == td%max_iter)
then
255 if (istep == td%max_iter) sys%outp%output_interval = ii - 1
266 write(
message(1),
'(a,f12.2,a)')
'Propagation time: ', final_time - init_time,
' seconds.'
269 if (vel_target_)
then
270 sys%ions%pos = x_initial
271 safe_deallocate_a(x_initial)
277 if (sys%st%pack_states .and. sys%hm%apply_packed())
call psi%unpack()
290 type(
td_t),
intent(inout) :: td
294 integer :: istep, ierr
299 message(1) =
"Info: Backward propagation."
303 if (sys%st%pack_states .and. sys%hm%apply_packed())
call psi%pack()
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)
314 message(1) =
"Unable to write OCT states restart."
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%outp, td%write_handler)
326 message(1) =
"Unable to write OCT states restart."
330 call v_ks_calc(sys%ks, sys%namespace, sys%space, sys%hm, psi, sys%ions, sys%ext_partners)
334 if (sys%st%pack_states .and. sys%hm%apply_packed())
call psi%unpack()
354 subroutine fwd_step(sys, td, tg, par, par_chi, qcpsi, prop_chi, prop_psi)
356 type(
td_t),
intent(inout) :: td
365 logical :: aux_fwd_propagation
374 message(1) =
"Info: Forward propagation."
392 .not. sys%ks%frozen_hxc))
393 if (aux_fwd_propagation)
then
396 if (sys%st%pack_states .and. sys%hm%apply_packed())
call psi2%pack()
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
406 call sys%hm%ks_pot%run_zero_iter(tr_psi2%vks_old)
411 message(1) =
"Unable to write OCT states restart."
414 call oct_prop_load_states(prop_chi, sys%namespace, sys%space, chi, sys%gr, sys%kpoints, 0, ierr)
416 message(1) =
"Unable to read OCT states restart."
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()
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')
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%outp, td%write_handler)
430 if (aux_fwd_propagation)
then
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%outp, td%write_handler)
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%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)
445 message(1) =
"Unable to write OCT states restart."
448 call oct_prop_check(prop_chi, sys%namespace, sys%space, chi, sys%gr, sys%kpoints, i)
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')
453 call v_ks_calc(sys%ks, sys%namespace, sys%space, sys%hm, psi, sys%ions, sys%ext_partners)
465 if (sys%st%pack_states .and. sys%hm%apply_packed())
call psi%unpack()
482 subroutine bwd_step(sys, td, tg, par, par_chi, qcchi, prop_chi, prop_psi)
484 type(
td_t),
intent(inout) :: td
499 message(1) =
"Info: Backward propagation."
514 call oct_prop_load_states(prop_psi, sys%namespace, sys%space, psi, sys%gr, sys%kpoints, td%max_iter, ierr)
516 message(1) =
"Unable to read OCT states restart."
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()
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)
531 message(1) =
"Unable to write OCT states restart."
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')
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%outp, td%write_handler)
545 message(1) =
"Unable to write OCT states restart."
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%outp, td%write_handler)
555 call update_field(0, par_chi, sys%space, sys%gr, sys%hm, sys%ext_partners, sys%ions, qcpsi, qcchi, par, dir =
'b')
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)
564 if (sys%st%pack_states .and. sys%hm%apply_packed())
call chi%unpack()
584 subroutine bwd_step_2(sys, td, tg, par, par_chi, qcchi, prop_chi, prop_psi)
586 type(
td_t),
intent(inout) :: td
594 integer :: i, ierr, ik, ib
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
606 real(real64) :: init_time, final_time
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))
625 call oct_prop_load_states(prop_psi, sys%namespace, sys%space, psi, sys%gr, sys%kpoints, td%max_iter, ierr)
627 message(1) =
"Unable to read OCT states restart."
631 safe_allocate(vhxc(1:sys%gr%np, 1:sys%hm%d%nspin))
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)
641 message(1) =
"Unable to write OCT states restart."
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()
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)
654 message(1) =
"Info: Backward propagation."
660 do i = td%max_iter, 1, -1
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')
665 select case (td%tr%method)
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%outp, td%write_handler, qcchi = qcchi)
681 qinitial = sys%ions%pos
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))
696 td, tg, par, psi, sys%ions)
698 do ik = psi%d%kpt%start, psi%d%kpt%end
699 do ib = psi%group%block_start, psi%group%block_end
700 call psi%group%psib(ib, ik)%copy_data_to(sys%gr%np, st_ref%group%psib(ib, ik))
704 vhxc(:, :) = sys%hm%ks_pot%vhxc(:, :)
705 call propagator_elec_dt(sys%ks, sys%namespace, sys%space, sys%hm, sys%gr, psi, td%tr, abs((i-1)*td%dt), td%dt, &
706 i-1, td%ions_dyn, sys%ions, sys%ext_partners, sys%outp, td%write_handler)
710 sys%ions%pos = qinitial
712 sys%ext_partners, psi, time = abs((i-1)*td%dt))
715 do ik = psi%d%kpt%start, psi%d%kpt%end
716 do ib = psi%group%block_start, psi%group%block_end
718 st_ref%group%psib(ib, ik))
720 psi%group%psib(ib, ik), st_ref%group%psib(ib, ik))
724 sys%hm%ks_pot%vhxc(:, :) =
m_half * (sys%hm%ks_pot%vhxc(:, :) + vhxc(:, :))
726 td, tg, par, sys%ions, st_ref, qtildehalf)
728 call propagator_elec_dt(sys%ks, sys%namespace, sys%space, sys%hm, sys%gr, chi, tr_chi, abs((i-1)*td%dt), td%dt, &
729 i-1, td%ions_dyn, sys%ions, sys%ext_partners, sys%outp, td%write_handler)
735 sys%ext_partners, psi, time = abs((i-1)*td%dt))
736 call forces_calculate(sys%gr, sys%namespace, sys%ions, sys%hm, sys%ext_partners, &
737 psi, sys%ks, t = abs((i-1)*td%dt), dt = td%dt)
740 safe_deallocate_a(fold)
741 safe_deallocate_a(fnew)
744 sys%hm%ks_pot%vhxc(:, :) = vhxc(:, :)
750 message(1) =
"Unable to write OCT states restart."
758 write(stdout,
'(1x)')
762 write(
message(1),
'(a,f12.2,a)')
'Propagation time: ', final_time - init_time,
' seconds.'
769 td, tg, par, psi, sys%ions)
770 call update_field(0, par_chi, sys%space, sys%gr, sys%hm, sys%ext_partners, sys%ions, qcpsi, qcchi, par, dir =
'b')
773 call v_ks_calc(sys%ks, sys%namespace, sys%space, sys%hm, psi, sys%ions, sys%ext_partners)
774 call sys%hm%update(sys%gr, sys%namespace, sys%space, sys%ext_partners)
778 safe_deallocate_a(vhxc)
785 safe_deallocate_a(qtildehalf)
786 safe_deallocate_a(qinitial)
795 subroutine update_hamiltonian_elec_chi(iter, namespace, space, gr, ks, hm, ext_partners, td, tg, par_chi, ions, st, qtildehalf)
796 integer,
intent(in) :: iter
798 class(
space_t),
intent(in) :: space
799 type(
grid_t),
intent(inout) :: gr
800 type(
v_ks_t),
intent(inout) :: ks
803 type(
td_t),
intent(inout) :: td
806 type(
ions_t),
intent(in) :: ions
808 real(real64),
optional,
intent(in) :: qtildehalf(:, :)
812 integer :: j, iatom, idim
813 complex(real64),
allocatable :: dvpsi(:, :, :), zpsi(:, :), inhzpsi(:, :)
814 integer :: ist, ik, ib
818 assert(.not. st%parallel_in_states)
819 assert(.not. st%d%kpt%parallel)
823 call target_inh(st, gr, hm%kpoints, tg, abs(td%dt)*iter, inh, iter)
830 safe_allocate(dvpsi(1:gr%np_part, 1:st%d%dim, 1:space%dim))
831 do ik = inh%d%kpt%start, inh%d%kpt%end
832 do ib = inh%group%block_start, inh%group%block_end
836 safe_allocate(zpsi(1:gr%np_part, 1:st%d%dim))
837 safe_allocate(inhzpsi(1:gr%np_part, 1:st%d%dim))
845 do iatom = 1, ions%natoms
846 call pert%setup_atom(iatom)
847 do idim = 1, space%dim
848 call pert%setup_dir(idim)
849 call pert%zapply(namespace, space, gr, hm, ik, zpsi(:, :), dvpsi(:, :, idim))
851 call lalg_axpy(gr%np, st%d%dim, -st%occ(ist, ik)*qtildehalf(iatom, idim), &
852 dvpsi(:, :, idim), inhzpsi(:, :))
855 safe_deallocate_p(pert)
860 safe_deallocate_a(zpsi)
861 safe_deallocate_a(inhzpsi)
862 safe_deallocate_a(dvpsi)
874 do j = iter - 2, iter + 2
875 if (j >= 0 .and. j <= td%max_iter)
then
888 subroutine update_hamiltonian_elec_psi(iter, namespace, space, gr, ks, hm, ext_partners, td, tg, par, st, ions)
889 integer,
intent(in) :: iter
892 type(
grid_t),
intent(inout) :: gr
893 type(
v_ks_t),
intent(inout) :: ks
896 type(
td_t),
intent(inout) :: td
900 type(
ions_t),
intent(in) :: ions
920 do j = iter - 2, iter + 2
921 if (j >= 0 .and. j <= td%max_iter)
then
927 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners)
928 call hm%update(gr, namespace, space, ext_partners)
937 subroutine calculate_g(space, gr, hm, lasers, psi, chi, dl, dq)
938 class(
space_t),
intent(in) :: space
939 type(
grid_t),
intent(inout) :: gr
941 type(
lasers_t),
intent(in) :: lasers
944 complex(real64),
intent(inout) :: dl(:), dq(:)
946 complex(real64),
allocatable :: zpsi(:, :), zoppsi(:, :)
947 integer :: no_parameters, j, ik, p
951 no_parameters = lasers%no_lasers
953 safe_allocate(zpsi(1:gr%np_part, 1:chi%d%dim))
954 safe_allocate(zoppsi(1:gr%np_part, 1:chi%d%dim))
956 do j = 1, no_parameters
965 if (
allocated(hm%ep%a_static))
then
967 zoppsi, ik, hm%ep%gyromagnetic_ratio, hm%ep%a_static)
970 zoppsi, ik, hm%ep%gyromagnetic_ratio)
974 dl(j) = dl(j) +
zmf_dotp(gr, psi%d%dim, zpsi, zoppsi)
990 dq(j) = dq(j) +
zmf_dotp(gr, psi%d%dim, zpsi, zoppsi)
1000 safe_deallocate_a(zpsi)
1001 safe_deallocate_a(zoppsi)
1022 subroutine update_field(iter, cp, space, gr, hm, ext_partners, ions, qcpsi, qcchi, cpp, dir)
1023 class(
space_t),
intent(in) :: space
1024 integer,
intent(in) :: iter
1026 type(
grid_t),
intent(inout) :: gr
1029 type(
ions_t),
intent(in) :: ions
1033 character(len=1),
intent(in) :: dir
1035 complex(real64) :: d1, pol(3)
1036 complex(real64),
allocatable :: dl(:), dq(:), zpsi(:, :), zchi(:, :)
1037 real(real64),
allocatable :: d(:)
1038 integer :: j, no_parameters, iatom
1040 real(real64),
pointer :: q(:, :)
1051 safe_allocate(dl(1:no_parameters))
1052 safe_allocate(dq(1:no_parameters))
1053 safe_allocate( d(1:no_parameters))
1057 if(
associated(lasers))
then
1058 call calculate_g(space, gr, hm, lasers, psi, chi, dl, dq)
1063 safe_allocate(zpsi(1:gr%np, 1:psi%d%dim))
1064 safe_allocate(zchi(1:gr%np, 1:chi%d%dim))
1069 d1 =
zmf_dotp(gr, psi%d%dim, zpsi, zchi)
1070 do j = 1, no_parameters
1074 safe_deallocate_a(zpsi)
1075 safe_deallocate_a(zchi)
1077 elseif (gradients_)
then
1078 do j = 1, no_parameters
1079 d(j) =
m_two * aimag(dl(j))
1082 do j = 1, no_parameters
1088 if (dir ==
'b' .and.
associated(lasers))
then
1090 do iatom = 1, ions%natoms
1091 d(1) = d(1) - ions%charge(iatom) * real(sum(pol(1:ions%space%dim)*q(iatom, 1:ions%space%dim)), real64)
1096 if (dir ==
'f')
then
1105 safe_deallocate_a(d)
1106 safe_deallocate_a(dl)
1107 safe_deallocate_a(dq)
1114 subroutine oct_prop_init(prop, namespace, dirname, mesh, mc)
1117 character(len=*),
intent(in) :: dirname
1118 class(
mesh_t),
intent(in) :: mesh
1125 prop%dirname = dirname
1127 prop%number_checkpoints = number_checkpoints_
1134 safe_allocate(prop%iter(1:prop%number_checkpoints+2))
1136 do j = 1, prop%number_checkpoints
1137 prop%iter(j+1) = nint(real(niter_, real64) /(prop%number_checkpoints+1) * j)
1139 prop%iter(prop%number_checkpoints+2) = niter_
1155 safe_deallocate_a(prop%iter)
1164 subroutine oct_prop_check(prop, namespace, space, psi, mesh, kpoints, iter)
1167 class(
space_t),
intent(in) :: space
1169 class(
mesh_t),
intent(in) :: mesh
1171 integer,
intent(in) :: iter
1174 character(len=80) :: dirname
1176 complex(real64) :: overlap, prev_overlap
1177 real(real64),
parameter :: WARNING_THRESHOLD = 1.0e-2_real64
1181 do j = 1, prop%number_checkpoints + 2
1182 if (prop%iter(j) == iter)
then
1184 write(dirname,
'(a, i4.4)') trim(prop%dirname), j
1187 call states_elec_load(prop%restart_load, namespace, space, stored_st, mesh, kpoints, ierr, verbose=.false.)
1190 message(1) =
"Unable to read wavefunctions from '"//trim(dirname)//
"'."
1196 if (abs(overlap - prev_overlap) > warning_threshold)
then
1197 write(
message(1),
'(a,es13.4)') &
1198 "Forward-backward propagation produced an error of", abs(overlap-prev_overlap)
1199 write(
message(2),
'(a,i8)')
"Iter = ", iter
1203 if (prop%number_checkpoints > 0)
then
1218 class(
space_t),
intent(in) :: space
1219 integer,
intent(in) :: iter
1221 class(
mesh_t),
intent(in) :: mesh
1223 integer,
intent(out) :: ierr
1226 character(len=80) :: dirname
1237 message(1) =
"Debug: Writing OCT propagation states restart."
1240 do j = 1, prop%number_checkpoints + 2
1241 if (prop%iter(j) == iter)
then
1242 write(dirname,
'(a,i4.4)') trim(prop%dirname), j
1245 call states_elec_dump(prop%restart_dump, space, psi, mesh, kpoints, err, iter, verbose = .false.)
1248 message(1) =
"Unable to write wavefunctions to '"//trim(dirname)//
"'."
1256 message(1) =
"Debug: Writing OCT propagation states restart done."
1268 class(
space_t),
intent(in) :: space
1270 class(
mesh_t),
intent(in) :: mesh
1272 integer,
intent(in) :: iter
1273 integer,
intent(out) :: ierr
1276 character(len=80) :: dirname
1288 message(1) =
"Debug: Reading OCT propagation states restart."
1291 do j = 1, prop%number_checkpoints + 2
1292 if (prop%iter(j) == iter)
then
1293 write(dirname,
'(a, i4.4)') trim(prop%dirname), j
1296 call states_elec_load(prop%restart_load, namespace, space, psi, mesh, kpoints, err, verbose=.false.)
1299 message(1) =
"Unable to read wavefunctions from '"//trim(dirname)//
"'."
1307 message(1) =
"Debug: Reading OCT propagation states restart done."
1316 type(
laser_t),
intent(in) :: laser
1317 class(
mesh_t),
intent(in) :: mesh
1318 class(
space_t),
intent(in) :: space
1319 complex(real64),
intent(inout) :: psi(:,:)
1320 complex(real64),
intent(inout) :: hpsi(:,:)
1323 logical :: vector_potential, magnetic_field
1325 real(real64) :: a_field(3), a_field_prime(3), bb(3), b_prime(3)
1326 real(real64),
allocatable :: aa(:, :), a_prime(:, :)
1332 vector_potential = .false.
1333 magnetic_field = .false.
1338 if (.not.
allocated(aa))
then
1339 safe_allocate(aa(1:mesh%np_part, 1:space%dim))
1341 safe_allocate(a_prime(1:mesh%np_part, 1:space%dim))
1349 magnetic_field = .
true.
1352 call laser_field(laser, a_field_prime(1:space%dim))
1353 a_field = a_field + a_field_prime
1354 vector_potential = .
true.
1357 if (magnetic_field)
then
1359 hpsi(ip, :) = hpsi(ip, :) +
m_half * &
1360 dot_product(aa(ip, 1:space%dim), aa(ip, 1:space%dim)) * psi(ip, :) /
p_c**2
1362 safe_deallocate_a(aa)
1363 safe_deallocate_a(a_prime)
1365 if (vector_potential)
then
1367 hpsi(ip, :) = hpsi(ip, :) +
m_half * &
1368 dot_product(a_field(1:space%dim), a_field(1:space%dim))*psi(ip, :) /
p_c**2
1377 type(
laser_t),
intent(in) :: laser
1380 complex(real64),
intent(inout) :: psi(:,:)
1381 complex(real64),
intent(inout) :: hpsi(:,:)
1382 integer,
intent(in) :: ik
1383 real(real64),
intent(in) :: gyromagnetic_ratio
1384 real(real64),
optional,
intent(in) :: a_static(:,:)
1387 logical :: electric_field, vector_potential, magnetic_field
1388 complex(real64),
allocatable :: grad(:, :, :), lhpsi(:, :)
1390 real(real64) :: a_field(3), a_field_prime(3), bb(3), b_prime(3)
1392 real(real64),
allocatable :: vv(:), pot(:), aa(:, :), a_prime(:, :)
1398 electric_field = .false.
1399 vector_potential = .false.
1400 magnetic_field = .false.
1404 if (.not.
allocated(vv))
then
1405 safe_allocate(vv(1:der%mesh%np))
1409 electric_field = .
true.
1412 if (.not.
allocated(vv))
then
1413 safe_allocate(vv(1:der%mesh%np))
1415 safe_allocate(pot(1:der%mesh%np))
1420 electric_field = .
true.
1421 safe_deallocate_a(pot)
1424 if (.not.
allocated(aa))
then
1425 safe_allocate(aa(1:der%mesh%np_part, 1:der%dim))
1427 safe_allocate(a_prime(1:der%mesh%np_part, 1:der%dim))
1435 magnetic_field = .
true.
1439 a_field = a_field + a_field_prime
1440 vector_potential = .
true.
1443 if (electric_field)
then
1444 do idim = 1, std%dim
1445 hpsi(1:der%mesh%np, idim)= hpsi(1:der%mesh%np, idim) + vv(1:der%mesh%np) * psi(1:der%mesh%np, idim)
1447 safe_deallocate_a(vv)
1450 if (magnetic_field)
then
1451 safe_allocate(grad(1:der%mesh%np_part, 1:der%dim, 1:std%dim))
1453 do idim = 1, std%dim
1465 if (
present(a_static))
then
1466 do ip = 1, der%mesh%np
1467 hpsi(ip, :) = hpsi(ip, :) - dot_product(aa(ip, 1:der%dim), a_static(ip, 1:der%dim)) * psi(ip, :) /
p_c
1471 select case (std%ispin)
1473 do ip = 1, der%mesh%np
1474 hpsi(ip, 1) = hpsi(ip, 1) -
m_zi * dot_product(aa(ip, 1:der%dim), grad(ip, 1:der%dim, 1)) /
p_c
1477 do ip = 1, der%mesh%np
1478 do idim = 1, std%dim
1479 hpsi(ip, idim) = hpsi(ip, idim) -
m_zi * &
1480 dot_product(aa(ip, 1:der%dim), grad(ip, 1:der%dim, idim)) /
p_c
1486 select case (std%ispin)
1488 safe_allocate(lhpsi(1:der%mesh%np, 1:std%dim))
1489 if (modulo(ik+1, 2) == 0)
then
1490 lhpsi(1:der%mesh%np, 1) = -
m_half /
p_c * norm2(bb) * psi(1:der%mesh%np, 1)
1492 lhpsi(1:der%mesh%np, 1) = +
m_half /
p_c * norm2(bb) * psi(1:der%mesh%np, 1)
1494 hpsi(1:der%mesh%np, :) = hpsi(1:der%mesh%np, :) + (gyromagnetic_ratio *
m_half) * lhpsi(1:der%mesh%np, :)
1495 safe_deallocate_a(lhpsi)
1498 safe_allocate(lhpsi(1:der%mesh%np, 1:std%dim))
1499 lhpsi(1:der%mesh%np, 1) =
m_half /
p_c * (bb(3) * psi(1:der%mesh%np, 1) &
1500 + cmplx(bb(1), -bb(2), real64) * psi(1:der%mesh%np, 2))
1501 lhpsi(1:der%mesh%np, 2) =
m_half /
p_c * (-bb(3) * psi(1:der%mesh%np, 2) &
1502 + cmplx(bb(1), bb(2), real64) * psi(1:der%mesh%np, 1))
1503 hpsi(1:der%mesh%np, :) = hpsi(1:der%mesh%np, :) + (gyromagnetic_ratio *
m_half) * lhpsi(1:der%mesh%np, :)
1504 safe_deallocate_a(lhpsi)
1507 safe_deallocate_a(grad)
1508 safe_deallocate_a(aa)
1509 safe_deallocate_a(a_prime)
1512 if (vector_potential)
then
1513 safe_allocate(grad(1:der%mesh%np_part, 1:der%dim, 1:std%dim))
1515 do idim = 1, std%dim
1519 select case (std%ispin)
1521 do ip = 1, der%mesh%np
1522 hpsi(ip, 1) = hpsi(ip, 1) -
m_zi * dot_product(a_field(1:der%dim), grad(ip, 1:der%dim, 1)) /
p_c
1525 do ip = 1, der%mesh%np
1526 do idim = 1, std%dim
1527 hpsi(ip, idim) = hpsi(ip, idim) -
m_zi * &
1528 dot_product(a_field(1:der%dim), grad(ip, 1:der%dim, idim)) /
p_c
1532 safe_deallocate_a(grad)
batchified version of the BLAS axpy routine:
scale a batch by a constant or vector
constant times a vector plus a vector
integer, parameter, public mask_absorbing
This module implements batches of mesh functions.
This module implements common operations on batches of mesh functions.
subroutine, public batch_set_zero(this, np, async)
fill all mesh functions of the batch with zero
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.
subroutine, public density_calc(st, gr, density, istin)
Computes the density from the orbitals in st.
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)
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)
subroutine, public forces_calculate(gr, namespace, ions, hm, ext_partners, st, ks, vhxc_old, t, dt)
real(real64), parameter, public m_two
real(real64), parameter, public m_zero
complex(real64), parameter, public m_z0
complex(real64), parameter, public m_zi
complex(real64), parameter, public m_z1
real(real64), parameter, public m_half
real(real64), parameter, public p_c
Electron gyromagnetic ratio, see Phys. Rev. Lett. 130, 071801 (2023)
This module implements the underlying real-space grid.
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)
subroutine, public ion_dynamics_save_state(this, ions, state)
logical pure function, public ion_dynamics_ions_move(this)
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)
subroutine, public laser_vector_potential(laser, mesh, aa, time)
integer, parameter, public e_field_electric
integer, parameter, public e_field_vector_potential
subroutine, public laser_potential(laser, mesh, pot, time)
integer, parameter, public e_field_scalar_potential
integer pure elemental function, public laser_kind(laser)
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...
integer, parameter, public e_field_magnetic
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
subroutine, public messages_warning(no_lines, all_nodes, namespace)
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
logical function mpi_grp_is_root(grp)
Is the current MPI process of grpcomm, root.
type(mpi_grp_t), public mpi_world
This module handles the communicators for the various parallelization strategies.
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_dt(ks, namespace, space, hm, gr, st, tr, time, dt, nt, ions_dyn, ions, ext_partners, 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_remove_scf_prop(tr)
subroutine, public propagator_elec_end(tr)
integer, parameter, public restart_oct
subroutine, public restart_init(restart, namespace, data_type, type, mc, ierr, mesh, dir, exact)
Initializes a restart object.
integer, parameter, public restart_type_dump
logical pure function, public restart_skip(restart)
Returns true if the restart information should neither be read nor written. This might happen because...
subroutine, public restart_open_dir(restart, dirname, ierr)
Change the restart directory to dirname, where "dirname" is a subdirectory of the base restart direct...
integer, parameter, public restart_type_load
subroutine, public restart_end(restart)
subroutine, public restart_close_dir(restart)
Change back to the base directory. To be called after restart_open_dir.
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, 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
integer, parameter, public oct_tg_hhgnew
integer pure function, public target_type(tg)
integer, parameter, public oct_targetmode_td
integer pure function, public target_mode(tg)
logical pure function, public target_move_ions(tg)
subroutine, public target_init_propagation(tg)
This routine performs all the things that must be initialized prior to a forward evolution,...
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.
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...
subroutine, public td_write_data(writ)
subroutine, public td_write_end(writ)
subroutine, public td_write_iter(writ, namespace, space, outp, gr, st, hm, ions, ext_partners, kick, ks, dt, iter, mc, recalculate_gs)
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.
subroutine, public v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_eigenval, time, calc_energy, calc_current, force_semilocal)
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.
Description of the grid, containing information on derivatives, stencil, and symmetries.
Describes mesh distribution to nodes.
Stores all communicators and groups.
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.