36 use,
intrinsic :: iso_fortran_env
70 class(mesh_t),
pointer :: mesh_p
71 type(hamiltonian_elec_t),
pointer :: hm_p
72 type(states_elec_t),
pointer :: st_p
73 type(propagator_base_t),
pointer :: tr_p
74 type(namespace_t),
pointer :: namespace_p
75 type(electron_space_t),
pointer :: space_p
76 type(partner_list_t),
pointer :: ext_partners_p
78 real(real64) :: t_op, dt_op
79 real(real64),
allocatable :: vpsl1_op(:), vpsl2_op(:)
80 logical :: move_ions_op
81 type(xc_copied_potentials_t) :: vhxc1_op, vhxc2_op
85 subroutine td_explicit_runge_kutta4(ks, namespace, space, hm, gr, st, time, dt, ions_dyn, ions, ext_partners, qcchi)
86 type(v_ks_t),
target,
intent(inout) :: ks
87 type(namespace_t),
intent(in) :: namespace
88 type(electron_space_t),
intent(in) :: space
89 type(hamiltonian_elec_t),
target,
intent(inout) :: hm
90 type(grid_t),
target,
intent(in) :: gr
91 type(states_elec_t),
target,
intent(inout) :: st
92 real(real64),
intent(in) :: time
93 real(real64),
intent(in) :: dt
94 type(ion_dynamics_t),
intent(inout) :: ions_dyn
95 type(ions_t),
intent(inout) :: ions
96 type(partner_list_t),
intent(in) :: ext_partners
97 type(opt_control_state_t),
optional,
target,
intent(inout) :: qcchi
99 type(states_elec_t),
pointer :: chi
100 real(real64),
pointer :: q(:, :), p(:, :)
102 integer :: np_part, np, kp1, kp2, st1, st2, nspin, ik, ist, iatom, ib
103 complex(real64),
allocatable :: zphi(:, :, :, :), zchi(:, :, :, :), dvpsi(:, :, :)
104 type(states_elec_t) :: hst, stphi, inh, hchi, stchi
105 logical :: propagate_chi
106 real(real64),
allocatable :: pos0(:, :), vel0(:, :), &
107 posk(:, :), velk(:, :), &
108 pos(:, :), vel(:, :), &
109 posfinal(:, :), velfinal(:, :), &
110 pos0t(:, :), vel0t(:, :), &
111 poskt(:, :), velkt(:, :), &
112 post(:, :), velt(:, :), &
113 posfinalt(:, :), velfinalt(:, :), &
118 propagate_chi =
present(qcchi)
119 if (propagate_chi)
then
133 safe_allocate(zphi(1:np_part, 1:st%d%dim, st1:st2, kp1:kp2))
134 if (propagate_chi)
then
135 safe_allocate(zchi(1:np_part, 1:st%d%dim, st1:st2, kp1:kp2))
138 safe_allocate(pos(1:ions%space%dim, 1:ions%natoms))
139 safe_allocate(vel(1:ions%space%dim, 1:ions%natoms))
140 safe_allocate(pos0(1:ions%space%dim, 1:ions%natoms))
141 safe_allocate(vel0(1:ions%space%dim, 1:ions%natoms))
142 safe_allocate(posk(1:ions%space%dim, 1:ions%natoms))
143 safe_allocate(velk(1:ions%space%dim, 1:ions%natoms))
144 safe_allocate(posfinal(1:ions%space%dim, 1:ions%natoms))
145 safe_allocate(velfinal(1:ions%space%dim, 1:ions%natoms))
147 if (propagate_chi)
then
148 safe_allocate(post(1:ions%space%dim, 1:ions%natoms))
149 safe_allocate(velt(1:ions%space%dim, 1:ions%natoms))
150 safe_allocate(pos0t(1:ions%space%dim, 1:ions%natoms))
151 safe_allocate(vel0t(1:ions%space%dim, 1:ions%natoms))
152 safe_allocate(poskt(1:ions%space%dim, 1:ions%natoms))
153 safe_allocate(velkt(1:ions%space%dim, 1:ions%natoms))
154 safe_allocate(posfinalt(1:ions%space%dim, 1:ions%natoms))
155 safe_allocate(velfinalt(1:ions%space%dim, 1:ions%natoms))
156 safe_allocate(coforce(1:ions%natoms, 1:ions%space%dim))
164 if (propagate_chi)
then
176 if (propagate_chi)
then
177 do iatom = 1, ions%natoms
178 pos0t(1:ions%space%dim, iatom) = q(iatom, 1:ions%space%dim)
179 vel0t(1:ions%space%dim, iatom) = p(iatom, 1:ions%space%dim) / ions%mass(iatom)
192 if (propagate_chi)
then
198 if (propagate_chi)
then
204 call f_psi(time - dt)
205 if (propagate_chi)
call f_chi(time - dt)
214 if (propagate_chi)
then
218 do ik = stphi%d%kpt%start, stphi%d%kpt%end
219 do ib = stphi%group%block_start, stphi%group%block_end
221 if (propagate_chi)
then
228 pos = pos0 +
m_half * posk
229 vel = vel0 +
m_half * velk
230 if (propagate_chi)
then
231 post = pos0t +
m_half * poskt
232 velt = vel0t +
m_half * velkt
245 if (propagate_chi)
then
249 do ik = stphi%d%kpt%start, stphi%d%kpt%end
250 do ib = stphi%group%block_start, stphi%group%block_end
252 if (propagate_chi)
then
259 pos = pos0 +
m_half * posk
260 vel = vel0 +
m_half * velk
261 if (propagate_chi)
then
262 post = pos0t +
m_half * poskt
263 velt = vel0t +
m_half * velkt
277 if (propagate_chi)
then
281 do ik = stphi%d%kpt%start, stphi%d%kpt%end
282 do ib = stphi%group%block_start, stphi%group%block_end
283 call batch_axpy(gr%np, -
m_zi*dt, hst%group%psib(ib, ik), stphi%group%psib(ib, ik))
284 if (propagate_chi)
then
285 call batch_axpy(gr%np, -
m_zi*dt, hchi%group%psib(ib, ik), stchi%group%psib(ib, ik))
293 if (propagate_chi)
then
300 if (propagate_chi)
call f_chi(time)
314 call ions%update_kinetic_energy()
316 if (propagate_chi)
then
317 do iatom = 1, ions%natoms
318 q(iatom, 1:ions%space%dim) = posfinalt(1:ions%space%dim, iatom)
319 p(iatom, 1:ions%space%dim) = ions%mass(iatom) * velfinalt(1:ions%space%dim, iatom)
326 safe_deallocate_a(zphi)
327 if (propagate_chi)
then
330 safe_deallocate_a(zchi)
337 safe_deallocate_a(pos)
338 safe_deallocate_a(vel)
339 safe_deallocate_a(pos0)
340 safe_deallocate_a(vel0)
341 safe_deallocate_a(posk)
342 safe_deallocate_a(velk)
343 safe_deallocate_a(posfinal)
344 safe_deallocate_a(velfinal)
346 if (propagate_chi)
then
347 safe_deallocate_a(post)
348 safe_deallocate_a(velt)
349 safe_deallocate_a(pos0t)
350 safe_deallocate_a(vel0t)
351 safe_deallocate_a(poskt)
352 safe_deallocate_a(velkt)
353 safe_deallocate_a(posfinalt)
354 safe_deallocate_a(velfinalt)
355 safe_deallocate_a(coforce)
362 subroutine f_psi(tau)
363 real(real64),
intent(in) :: tau
372 call v_ks_calc(ks, namespace, space, hm, stphi, ions, ext_partners, &
374 time = tau, calc_energy = .false., calc_eigenval = .false.)
376 call hm%update(gr, namespace, space, ext_partners, time = tau)
383 real(real64),
intent(in) :: tau
385 call forces_calculate(gr, namespace, ions, hm, ext_partners, stphi, ks, t = tau, dt = dt)
386 do iatom = 1, ions%natoms
387 posk(:, iatom) = dt * vel(:, iatom)
388 velk(:, iatom) = dt * ions%tot_force(:, iatom) / ions%mass(iatom)
390 if (propagate_chi)
then
392 do iatom = 1, ions%natoms
393 poskt(:, iatom) = dt * velt(:, iatom)
394 velkt(:, iatom) = dt * coforce(iatom, :) / ions%mass(iatom)
399 subroutine f_chi(tau)
400 real(real64),
intent(in) :: tau
422 do ib = 1, st%group%block_start, st%group%block_end
423 call batch_axpy(np,
m_zi, hm%inh_st%group%psib(ib, ik), hchi%group%psib(ib, ik))
431 complex(real64),
allocatable :: psi(:, :), inhpsi(:, :)
437 safe_allocate(psi(1:gr%np_part, 1:st%d%dim))
438 safe_allocate(inhpsi(1:gr%np_part, 1:st%d%dim))
439 safe_allocate(dvpsi(1:gr%np_part, 1:st%d%dim, 1:space%dim))
447 do iatom = 1, ions%natoms
448 do idir = 1, space%dim
450 call pert%setup_atom(iatom)
451 call pert%setup_dir(idir)
452 call pert%zapply(namespace, space, gr, hm, ik, psi(:, :), dvpsi(:, :, idir))
453 dvpsi(:, :, idir) = - dvpsi(:, :, idir)
454 inhpsi(1:gr%np, 1:stphi%d%dim) = inhpsi(1:gr%np, 1:stphi%d%dim) &
455 + st%occ(ist, ik)*post(idir, iatom)*dvpsi(1:gr%np, 1:stphi%d%dim, idir)
456 safe_deallocate_p(pert)
468 safe_deallocate_a(psi)
469 safe_deallocate_a(inhpsi)
470 safe_deallocate_a(dvpsi)
476 real(real64),
intent(in) :: epsilon
478 do ik = stphi%d%kpt%start, stphi%d%kpt%end
479 do ib = stphi%group%block_start, stphi%group%block_end
480 call batch_axpy(gr%np, -
m_zi*dt*epsilon, hst%group%psib(ib, ik), st%group%psib(ib, ik))
481 if (propagate_chi)
then
482 call batch_axpy(gr%np, -
m_zi*dt*epsilon, hchi%group%psib(ib, ik), chi%group%psib(ib, ik))
488 posfinal = posfinal + posk * epsilon
489 velfinal = velfinal + velk * epsilon
490 if (propagate_chi)
then
491 posfinalt = posfinalt + poskt * epsilon
492 velfinalt = velfinalt + velkt * epsilon
500 subroutine td_runge_kutta2(ks, namespace, space, hm, gr, st, tr, time, dt, ions_dyn, ions, ext_partners)
501 type(
v_ks_t),
target,
intent(inout) :: ks
505 type(
grid_t),
target,
intent(in) :: gr
508 real(real64),
intent(in) :: time
509 real(real64),
intent(in) :: dt
511 type(
ions_t),
intent(inout) :: ions
514 integer :: np_part, np, kp1, kp2, st1, st2, nspin, ik, ist, idim, j, ip
517 complex(real64),
allocatable :: zphi(:, :, :, :)
518 complex(real64),
allocatable :: zpsi(:), rhs(:)
519 complex(real64),
allocatable :: k2(:, :, :, :), oldk2(:, :, :, :), rhs1(:, :, :, :)
520 complex(real64),
allocatable :: inhpsi(:)
540 sp_parallel = st%parallel_in_states .or. st%d%kpt%parallel
548 namespace_p => namespace
550 ext_partners_p => ext_partners
552 t_op = time - dt/
m_two
555 safe_allocate(k2(1:np_part, 1:st%d%dim, st1:st2, kp1:kp2))
556 safe_allocate(oldk2(1:np_part, 1:st%d%dim, st1:st2, kp1:kp2))
557 safe_allocate(zphi(1:gr%np_part, st%d%dim, st1:st2, kp1:kp2))
558 safe_allocate(rhs1(1:np_part, 1:st%d%dim, st1:st2, kp1:kp2))
559 safe_allocate(rhs(1:tr%tdsk_size))
560 safe_allocate(zpsi(1:tr%tdsk_size))
561 safe_allocate(vpsl1_op(1:np))
579 call zhamiltonian_elec_apply_single(hm_p, namespace, mesh_p, zphi(:, :, ist, ik), rhs1(:, :, ist, ik), ist, ik)
593 safe_allocate(inhpsi(1:gr%np))
596 do idim = 1, st%d%dim
599 rhs1(ip, idim, ist, ik) = rhs1(ip, idim, ist, ik) + dt * inhpsi(ip)
604 safe_deallocate_a(inhpsi)
621 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, &
623 calc_energy = .false., calc_eigenval = .false.)
629 vpsl1_op = hm%ep%vpsl
636 call hm%ks_pot%get_interpolated_potentials(tr%vks_old, 0, storage=vhxc1_op)
639 call hm%ks_pot%store_potentials(vhxc1_op)
643 call hm%ks_pot%store_potentials(vhxc1_op)
653 do idim = 1, st%d%dim
654 rhs(j:j+np-1) = rhs1(1:np, idim, ist, ik)
664 do idim = 1, st%d%dim
665 zpsi(j:j+np-1) = k2(1:np, idim, ist, ik)
678 do idim = 1, st%d%dim
679 k2(1:np, idim, ist, ik) = zpsi(j:j+np-1)
688 do idim = 1, st%d%dim
689 dres = dres + (
zmf_nrm2(gr, k2(:, idim, ist, ik) - oldk2(:, idim, ist, ik), reduce = .false.))**2
696 if (
sqrt(dres) < tr%scf_threshold)
exit
708 safe_deallocate_a(k2)
709 safe_deallocate_a(oldk2)
710 safe_deallocate_a(zphi)
711 safe_deallocate_a(rhs1)
712 safe_deallocate_a(zpsi)
713 safe_deallocate_a(rhs)
714 safe_deallocate_a(vpsl1_op)
721 subroutine td_runge_kutta4(ks, namespace, space, hm, gr, st, tr, time, dt, ions_dyn, ions, ext_partners)
722 type(
v_ks_t),
target,
intent(inout) :: ks
726 type(
grid_t),
target,
intent(in) :: gr
729 real(real64),
intent(in) :: time
730 real(real64),
intent(in) :: dt
732 type(
ions_t),
intent(inout) :: ions
735 integer :: idim, ip, ist, ik, j, kp1, kp2, st1, st2, nspin
737 complex(real64),
allocatable :: inhpsi(:)
738 complex(real64),
allocatable :: zpsi(:), rhs(:)
739 complex(real64),
allocatable :: zphi(:, :, :, :)
742 real(real64) :: a(2, 2), c(2), b(2)
743 complex(real64),
allocatable :: k1(:, :, :, :), k2(:, :, :, :), oldk1(:, :, :, :), &
744 oldk2(:, :, :, :), yn1(:, :, :, :), yn2(:, :, :, :), &
745 rhs1(:, :, :, :), rhs2(:, :, :, :)
771 sp_parallel = st%parallel_in_states .or. st%d%kpt%parallel
779 namespace_p => namespace
781 ext_partners_p => ext_partners
783 t_op = time - dt/
m_two
786 safe_allocate(vpsl1_op(1:gr%np))
787 safe_allocate(vpsl2_op(1:gr%np))
788 safe_allocate(k1(1:gr%np_part, 1:st%d%dim, st1:st2, kp1:kp2))
789 safe_allocate(k2(1:gr%np_part, 1:st%d%dim, st1:st2, kp1:kp2))
790 safe_allocate(oldk1(1:gr%np_part, 1:st%d%dim, st1:st2, kp1:kp2))
791 safe_allocate(oldk2(1:gr%np_part, 1:st%d%dim, st1:st2, kp1:kp2))
792 safe_allocate(yn1(1:gr%np_part, 1:st%d%dim, st1:st2, kp1:kp2))
793 safe_allocate(yn2(1:gr%np_part, 1:st%d%dim, st1:st2, kp1:kp2))
794 safe_allocate(rhs1(1:gr%np_part, 1:st%d%dim, st1:st2, kp1:kp2))
795 safe_allocate(rhs2(1:gr%np_part, 1:st%d%dim, st1:st2, kp1:kp2))
796 safe_allocate(rhs(1:tr%tdsk_size))
797 safe_allocate(zpsi(1:tr%tdsk_size))
798 safe_allocate(zphi(1:gr%np_part, st%d%dim, st1:st2, kp1:kp2))
814 yn1 = zphi + a(1, 1) * k1 + a(1, 2) * k2
815 yn2 = zphi + a(2, 1) * k1 + a(2, 2) * k2
824 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, &
826 calc_energy = .false., calc_eigenval = .false.)
831 vpsl1_op = hm%ep%vpsl
836 call hm%ks_pot%store_potentials(vhxc1_op)
837 t_op = time - dt + c(1) * dt
841 call zhamiltonian_elec_apply_single(hm_p, namespace, mesh_p, zphi(:, :, ist, ik), rhs1(:, :, ist, ik), ist, ik)
843 safe_allocate(inhpsi(1:gr%np))
844 do idim = 1, st%d%dim
847 rhs1(ip, idim, ist, ik) = rhs1(ip, idim, ist, ik) +
m_zi * inhpsi(ip)
850 safe_deallocate_a(inhpsi)
854 rhs1 = -
m_zi * dt * rhs1
866 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, &
868 calc_energy = .false., calc_eigenval = .false.)
873 vpsl2_op = hm%ep%vpsl
878 call hm%ks_pot%store_potentials(vhxc2_op)
879 t_op = time - dt + c(2) * dt
883 call zhamiltonian_elec_apply_single(hm_p, namespace, mesh_p, zphi(:, :, ist, ik), rhs2(:, :, ist, ik), ist, ik)
885 safe_allocate(inhpsi(1:gr%np))
886 do idim = 1, st%d%dim
889 rhs2(ip, idim, ist, ik) = rhs2(ip, idim, ist, ik) +
m_zi * inhpsi(ip)
892 safe_deallocate_a(inhpsi)
896 rhs2 = -
m_zi * dt * rhs2
904 do idim = 1, st%d%dim
905 call lalg_copy(gr%np, rhs1(1:gr%np, idim, ist, ik), rhs(j:j+gr%np-1))
912 do idim = 1, st%d%dim
913 call lalg_copy(gr%np, rhs2(1:gr%np, idim, ist, ik), rhs(j:j+gr%np-1))
923 do idim = 1, st%d%dim
924 call lalg_copy(gr%np, k1(1:gr%np, idim, ist, ik), zpsi(j:j+gr%np-1))
931 do idim = 1, st%d%dim
932 call lalg_copy(gr%np, k2(1:gr%np, idim, ist, ik), zpsi(j:j+gr%np-1))
946 do idim = 1, st%d%dim
947 call lalg_copy(gr%np, zpsi(j:j+gr%np-1), k1(1:gr%np, idim, ist, ik))
954 do idim = 1, st%d%dim
955 call lalg_copy(gr%np, zpsi(j:j+gr%np-1), k2(1:gr%np, idim, ist, ik))
964 do idim = 1, st%d%dim
965 dres = dres + (
zmf_nrm2(gr, k1(:, idim, ist, ik) - oldk1(:, idim, ist, ik)))**2
966 dres = dres + (
zmf_nrm2(gr, k2(:, idim, ist, ik) - oldk2(:, idim, ist, ik)))**2
973 if (
sqrt(dres) < tr%scf_threshold)
exit
977 zphi = zphi + b(1) * k1 + b(2) * k2
986 safe_deallocate_a(rhs1)
987 safe_deallocate_a(rhs2)
988 safe_deallocate_a(k1)
989 safe_deallocate_a(k2)
990 safe_deallocate_a(oldk1)
991 safe_deallocate_a(oldk2)
992 safe_deallocate_a(yn1)
993 safe_deallocate_a(yn2)
994 safe_deallocate_a(vpsl1_op)
995 safe_deallocate_a(vpsl2_op)
996 safe_deallocate_a(zpsi)
997 safe_deallocate_a(rhs)
1004 subroutine td_rk4op(xre, xim, yre, yim)
1005 real(real64),
intent(in) :: xre(:)
1006 real(real64),
intent(in) :: xim(:)
1007 real(real64),
intent(out) :: yre(:)
1008 real(real64),
intent(out) :: yim(:)
1010 integer :: idim, j, ik, ist, kp1, kp2, st1, st2, dim, k, jj
1011 complex(real64),
allocatable :: zpsi(:, :)
1012 complex(real64),
allocatable :: opzpsi(:, :)
1013 real(real64) :: a(2, 2), c(2)
1014 integer :: np_part, np
1018 np_part = mesh_p%np_part
1022 kp1 = st_p%d%kpt%start
1023 kp2 = st_p%d%kpt%end
1026 safe_allocate(zpsi(1:np_part, 1:dim))
1027 safe_allocate(opzpsi(1:np_part, 1:dim))
1039 call hm_p%ks_pot%restore_potentials(vhxc1_op)
1040 if (move_ions_op) hm_p%ep%vpsl = vpsl1_op
1043 k = np * (kp2 - kp1 + 1) * (st2 - st1 + 1) * dim + 1
1048 zpsi(1:np, idim) = a(1, 1) * cmplx(xre(j:j+np-1), xim(j:j+np-1), real64) + &
1049 a(1, 2) * cmplx(xre(k:k+np-1), xim(k:k+np-1), real64)
1057 yre(jj:jj+np-1) = xre(jj:jj+np-1) - aimag(dt_op * opzpsi(1:np, idim))
1058 yim(jj:jj+np-1) = xim(jj:jj+np-1) + real(dt_op * opzpsi(1:np, idim), real64)
1064 call hm_p%ks_pot%restore_potentials(vhxc2_op)
1066 if (move_ions_op) hm_p%ep%vpsl = vpsl2_op
1069 k = np * (kp2 - kp1 + 1) * (st2 - st1 + 1) * dim + 1
1074 zpsi(1:np, idim) = a(2, 1) * cmplx(xre(j:j+np-1), xim(j:j+np-1), real64) + &
1075 a(2, 2) * cmplx(xre(k:k+np-1), xim(k:k+np-1), real64)
1083 yre(jj:jj+np-1) = xre(jj:jj+np-1) - aimag(dt_op * opzpsi(1:np, idim))
1084 yim(jj:jj+np-1) = xim(jj:jj+np-1) + real(dt_op * opzpsi(1:np, idim), real64)
1090 safe_deallocate_a(zpsi)
1091 safe_deallocate_a(opzpsi)
1099 subroutine td_rk4opt(xre, xim, yre, yim)
1100 real(real64),
intent(in) :: xre(:)
1101 real(real64),
intent(in) :: xim(:)
1102 real(real64),
intent(out) :: yre(:)
1103 real(real64),
intent(out) :: yim(:)
1105 integer :: idim, j, ik, ist, kp1, kp2, st1, st2, dim, k, jj
1106 complex(real64),
allocatable :: zpsi(:, :)
1107 complex(real64),
allocatable :: opzpsi(:, :)
1108 real(real64) :: a(2, 2), c(2)
1109 integer :: np_part, np
1113 np_part = mesh_p%np_part
1117 kp1 = st_p%d%kpt%start
1118 kp2 = st_p%d%kpt%end
1121 safe_allocate(zpsi(1:np_part, 1:dim))
1122 safe_allocate(opzpsi(1:np_part, 1:dim))
1134 call hm_p%ks_pot%restore_potentials(vhxc1_op)
1135 if (move_ions_op) hm_p%ep%vpsl = vpsl1_op
1140 k = np * (kp2 - kp1 + 1) * (st2 - st1 + 1) * dim + 1
1145 zpsi(1:np, idim) = a(1, 1) * cmplx(xre(j:j+np-1), -xim(j:j+np-1), real64) + &
1146 a(1, 2) * cmplx(xre(k:k+np-1), -xim(k:k+np-1), real64)
1154 yre(jj:jj+np-1) = xre(jj:jj+np-1) - aimag(dt_op * opzpsi(1:np, idim))
1155 yim(jj:jj+np-1) = xim(jj:jj+np-1) - real(dt_op * opzpsi(1:np, idim), real64)
1161 call hm_p%ks_pot%restore_potentials(vhxc2_op)
1162 if (move_ions_op) hm_p%ep%vpsl = vpsl2_op
1167 k = np * (kp2 - kp1 + 1) * (st2 - st1 + 1) * dim + 1
1172 zpsi(1:np, idim) = a(2, 1) * cmplx(xre(j:j+np-1), -xim(j:j+np-1), real64) + &
1173 a(2, 2) * cmplx(xre(k:k+np-1), -xim(k:k+np-1), real64)
1181 yre(jj:jj+np-1) = xre(jj:jj+np-1) - aimag(dt_op * opzpsi(1:np, idim))
1182 yim(jj:jj+np-1) = xim(jj:jj+np-1) - real(dt_op * opzpsi(1:np, idim), real64)
1188 safe_deallocate_a(zpsi)
1189 safe_deallocate_a(opzpsi)
1197 subroutine td_rk2op(xre, xim, yre, yim)
1198 real(real64),
intent(in) :: xre(:)
1199 real(real64),
intent(in) :: xim(:)
1200 real(real64),
intent(out) :: yre(:)
1201 real(real64),
intent(out) :: yim(:)
1203 integer :: np_part, np, st1, st2, kp1, kp2, dim, idim, ik, ist, jj, j
1204 complex(real64),
allocatable :: zpsi(:, :)
1205 complex(real64),
allocatable :: opzpsi(:, :)
1206 complex(real64),
allocatable :: zpsi_(:, :, :, :)
1210 np_part = mesh_p%np_part
1214 kp1 = st_p%d%kpt%start
1215 kp2 = st_p%d%kpt%end
1218 safe_allocate(zpsi(1:np_part, 1:dim))
1219 safe_allocate(opzpsi(1:np_part, 1:dim))
1220 safe_allocate(zpsi_(1:np_part, 1:dim, st1:st2, kp1:kp2))
1225 call hm_p%ks_pot%restore_potentials(vhxc1_op)
1226 if (move_ions_op) hm_p%ep%vpsl = vpsl1_op
1236 zpsi_(1:np, idim, ist, ik) = cmplx(xre(j:j+np-1), xim(j:j+np-1), real64)
1241 call oct_exchange_prepare(hm_p%oct_exchange, mesh_p, zpsi_, hm_p%xc, hm_p%psolver, namespace_p)
1249 zpsi(1:np, idim) = cmplx(xre(j:j+np-1), xim(j:j+np-1), real64)
1254 yre(jj:jj+np-1) = xre(jj:jj+np-1) - aimag(dt_op *
m_half * opzpsi(1:np, idim))
1255 yim(jj:jj+np-1) = xim(jj:jj+np-1) + real(dt_op *
m_half * opzpsi(1:np, idim), real64)
1267 zpsi(1:np, idim) = cmplx(xre(j:j+np-1), xim(j:j+np-1), real64)
1274 yre(jj:jj+np-1) = yre(jj:jj+np-1) - aimag(dt_op *
m_half * opzpsi(1:np, idim))
1275 yim(jj:jj+np-1) = yim(jj:jj+np-1) + real(dt_op *
m_half * opzpsi(1:np, idim), real64)
1282 safe_deallocate_a(zpsi)
1283 safe_deallocate_a(opzpsi)
1292 subroutine td_rk2opt(xre, xim, yre, yim)
1293 real(real64),
intent(in) :: xre(:)
1294 real(real64),
intent(in) :: xim(:)
1295 real(real64),
intent(out) :: yre(:)
1296 real(real64),
intent(out) :: yim(:)
1298 integer :: np_part, np, st1, st2, kp1, kp2, dim, idim, ik, ist, jj, j
1299 complex(real64),
allocatable :: zpsi(:, :)
1300 complex(real64),
allocatable :: opzpsi(:, :)
1301 complex(real64),
allocatable :: zpsi_(:, :, :, :)
1305 np_part = mesh_p%np_part
1309 kp1 = st_p%d%kpt%start
1310 kp2 = st_p%d%kpt%end
1313 safe_allocate(zpsi(1:np_part, 1:dim))
1314 safe_allocate(opzpsi(1:np_part, 1:dim))
1315 safe_allocate(zpsi_(1:np_part, 1:dim, st1:st2, kp1:kp2))
1320 call hm_p%ks_pot%restore_potentials(vhxc1_op)
1321 if (move_ions_op) hm_p%ep%vpsl = vpsl1_op
1331 zpsi_(1:np, idim, ist, ik) = cmplx(xre(j:j+np-1), -xim(j:j+np-1), real64)
1336 call oct_exchange_prepare(hm_p%oct_exchange, mesh_p, zpsi_, hm_p%xc, hm_p%psolver, namespace_p)
1344 zpsi(1:np, idim) = cmplx(xre(j:j+np-1), -xim(j:j+np-1), real64)
1350 yre(jj:jj+np-1) = xre(jj:jj+np-1) - aimag(dt_op *
m_half * opzpsi(1:np, idim))
1351 yim(jj:jj+np-1) = xim(jj:jj+np-1) - real(dt_op *
m_half * opzpsi(1:np, idim), real64)
1363 zpsi(1:np, idim) = cmplx(xre(j:j+np-1), xim(j:j+np-1), real64)
1370 yre(jj:jj+np-1) = yre(jj:jj+np-1) - aimag(dt_op *
m_half * opzpsi(1:np, idim))
1371 yim(jj:jj+np-1) = yim(jj:jj+np-1) - real(dt_op *
m_half * opzpsi(1:np, idim), real64)
1378 safe_deallocate_a(zpsi)
1379 safe_deallocate_a(opzpsi)
batchified version of the BLAS axpy routine:
Copies a vector x, to a vector y.
double sqrt(double __x) __attribute__((__nothrow__
This module implements common operations on batches of mesh functions.
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.
logical function, public list_has_gauge_field(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
real(real64), parameter, public m_third
real(real64), parameter, public m_fourth
complex(real64), parameter, public m_z0
complex(real64), parameter, public m_zi
real(real64), parameter, public m_half
real(real64), parameter, public m_one
real(real64), parameter, public m_three
This module implements the underlying real-space grid.
subroutine, public hamiltonian_elec_set_inh(hm, st)
subroutine, public hamiltonian_elec_adjoint(hm)
subroutine, public zhamiltonian_elec_apply_single(hm, namespace, mesh, psi, hpsi, ist, ik, terms, set_bc, set_phase)
subroutine, public hamiltonian_elec_epot_generate(this, namespace, space, gr, ions, ext_partners, st, time)
subroutine, public zhamiltonian_elec_apply_all(hm, namespace, mesh, st, hst)
subroutine, public hamiltonian_elec_remove_inh(hm)
pure logical function, public hamiltonian_elec_inh_term(hm)
subroutine, public hamiltonian_elec_not_adjoint(hm)
This module defines classes and functions for interaction partners.
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)
A module to handle KS potential, without the external potential.
integer, parameter, public independent_particles
subroutine, public xc_copied_potentials_end(this)
Finalizer for the copied potentials.
subroutine, public lda_u_update_occ_matrices(this, namespace, mesh, st, hm_base, phase, energy)
This module defines various routines, operating on mesh functions.
logical, public sp_parallel
type(mpi_grp_t), public sp_grp
This module defines the meshes, which are used in Octopus.
subroutine mpi_grp_copy(mpi_grp_out, mpi_grp_in)
logical function, public oct_exchange_enabled(this)
subroutine, public oct_exchange_remove(this)
subroutine, public oct_exchange_set(this, st, mesh)
subroutine, public oct_exchange_operator(this, namespace, mesh, hpsi, ist, ik)
subroutine, public oct_exchange_prepare(this, mesh, psi, xc, psolver, namespace)
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)
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 propagation_ops_elec_update_hamiltonian(namespace, space, st, mesh, hm, ext_partners, time)
subroutine, public td_runge_kutta2(ks, namespace, space, hm, gr, st, tr, time, dt, ions_dyn, ions, ext_partners)
subroutine, public td_runge_kutta4(ks, namespace, space, hm, gr, st, tr, time, dt, ions_dyn, ions, ext_partners)
subroutine td_rk2op(xre, xim, yre, yim)
operator for the RK2 propagator
subroutine td_rk4op(xre, xim, yre, yim)
operators for Crank-Nicolson scheme
subroutine, public td_explicit_runge_kutta4(ks, namespace, space, hm, gr, st, time, dt, ions_dyn, ions, ext_partners, qcchi)
subroutine, public propagator_rk_end()
subroutine td_rk2opt(xre, xim, yre, yim)
operator for the RK2 propagator
subroutine td_rk4opt(xre, xim, yre, yim)
Transpose of H (called e.g. by bi-conjugate gradient solver)
subroutine, public zsparskit_solver_run(namespace, sk, op, opt, sol, rhs)
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
subroutine, public v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_eigenval, time, calc_energy, calc_current, force_semilocal)
subroutine update_state(epsilon)
Extension of space that contains the knowledge of the spin dimension.
Description of the grid, containing information on derivatives, stencil, and symmetries.
The states_elec_t class contains all electronic wave functions.