36 use,
intrinsic :: iso_fortran_env
70 type(grid_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 if(ions_dyn%cell_relax())
then
122 propagate_chi =
present(qcchi)
123 if (propagate_chi)
then
137 safe_allocate(zphi(1:np_part, 1:st%d%dim, st1:st2, kp1:kp2))
138 if (propagate_chi)
then
139 safe_allocate(zchi(1:np_part, 1:st%d%dim, st1:st2, kp1:kp2))
141 if (ions_dyn%ions_move())
then
142 safe_allocate(pos(1:ions%space%dim, 1:ions%natoms))
143 safe_allocate(vel(1:ions%space%dim, 1:ions%natoms))
144 safe_allocate(pos0(1:ions%space%dim, 1:ions%natoms))
145 safe_allocate(vel0(1:ions%space%dim, 1:ions%natoms))
146 safe_allocate(posk(1:ions%space%dim, 1:ions%natoms))
147 safe_allocate(velk(1:ions%space%dim, 1:ions%natoms))
148 safe_allocate(posfinal(1:ions%space%dim, 1:ions%natoms))
149 safe_allocate(velfinal(1:ions%space%dim, 1:ions%natoms))
151 if (propagate_chi)
then
152 safe_allocate(post(1:ions%space%dim, 1:ions%natoms))
153 safe_allocate(velt(1:ions%space%dim, 1:ions%natoms))
154 safe_allocate(pos0t(1:ions%space%dim, 1:ions%natoms))
155 safe_allocate(vel0t(1:ions%space%dim, 1:ions%natoms))
156 safe_allocate(poskt(1:ions%space%dim, 1:ions%natoms))
157 safe_allocate(velkt(1:ions%space%dim, 1:ions%natoms))
158 safe_allocate(posfinalt(1:ions%space%dim, 1:ions%natoms))
159 safe_allocate(velfinalt(1:ions%space%dim, 1:ions%natoms))
160 safe_allocate(coforce(1:ions%natoms, 1:ions%space%dim))
168 if (propagate_chi)
then
174 if (ions_dyn%ions_move())
then
180 if (propagate_chi)
then
181 do iatom = 1, ions%natoms
182 pos0t(1:ions%space%dim, iatom) = q(iatom, 1:ions%space%dim)
183 vel0t(1:ions%space%dim, iatom) = p(iatom, 1:ions%space%dim) / ions%mass(iatom)
196 if (propagate_chi)
then
199 if (ions_dyn%ions_move())
then
202 if (propagate_chi)
then
208 call f_psi(time - dt)
209 if (propagate_chi)
call f_chi(time - dt)
210 if (ions_dyn%ions_move())
call f_ions(time - dt)
218 if (propagate_chi)
then
222 do ik = stphi%d%kpt%start, stphi%d%kpt%end
223 do ib = stphi%group%block_start, stphi%group%block_end
225 if (propagate_chi)
then
231 if (ions_dyn%ions_move())
then
232 pos = pos0 +
m_half * posk
233 vel = vel0 +
m_half * velk
234 if (propagate_chi)
then
235 post = pos0t +
m_half * poskt
236 velt = vel0t +
m_half * velkt
249 if (propagate_chi)
then
253 do ik = stphi%d%kpt%start, stphi%d%kpt%end
254 do ib = stphi%group%block_start, stphi%group%block_end
256 if (propagate_chi)
then
262 if (ions_dyn%ions_move())
then
263 pos = pos0 +
m_half * posk
264 vel = vel0 +
m_half * velk
265 if (propagate_chi)
then
266 post = pos0t +
m_half * poskt
267 velt = vel0t +
m_half * velkt
281 if (propagate_chi)
then
285 do ik = stphi%d%kpt%start, stphi%d%kpt%end
286 do ib = stphi%group%block_start, stphi%group%block_end
287 call batch_axpy(gr%np, -
m_zi*dt, hst%group%psib(ib, ik), stphi%group%psib(ib, ik))
288 if (propagate_chi)
then
289 call batch_axpy(gr%np, -
m_zi*dt, hchi%group%psib(ib, ik), stchi%group%psib(ib, ik))
294 if (ions_dyn%ions_move())
then
297 if (propagate_chi)
then
304 if (propagate_chi)
call f_chi(time)
305 if (ions_dyn%ions_move())
call f_ions(time)
313 if (ions_dyn%ions_move())
then
318 call ions%update_kinetic_energy()
320 if (propagate_chi)
then
321 do iatom = 1, ions%natoms
322 q(iatom, 1:ions%space%dim) = posfinalt(1:ions%space%dim, iatom)
323 p(iatom, 1:ions%space%dim) = ions%mass(iatom) * velfinalt(1:ions%space%dim, iatom)
330 safe_deallocate_a(zphi)
331 if (propagate_chi)
then
334 safe_deallocate_a(zchi)
340 if (ions_dyn%ions_move())
then
341 safe_deallocate_a(pos)
342 safe_deallocate_a(vel)
343 safe_deallocate_a(pos0)
344 safe_deallocate_a(vel0)
345 safe_deallocate_a(posk)
346 safe_deallocate_a(velk)
347 safe_deallocate_a(posfinal)
348 safe_deallocate_a(velfinal)
350 if (propagate_chi)
then
351 safe_deallocate_a(post)
352 safe_deallocate_a(velt)
353 safe_deallocate_a(pos0t)
354 safe_deallocate_a(vel0t)
355 safe_deallocate_a(poskt)
356 safe_deallocate_a(velkt)
357 safe_deallocate_a(posfinalt)
358 safe_deallocate_a(velfinalt)
359 safe_deallocate_a(coforce)
366 subroutine f_psi(tau)
367 real(real64),
intent(in) :: tau
369 if (ions_dyn%ions_move())
then
376 call v_ks_calc(ks, namespace, space, hm, stphi, ions, ext_partners, &
378 time = tau, calc_energy = .false., calc_eigenval = .false.)
380 call hm%update(gr, namespace, space, ext_partners, time = tau)
387 real(real64),
intent(in) :: tau
389 call forces_calculate(gr, namespace, ions, hm, ext_partners, stphi, ks, t = tau, dt = dt)
390 do iatom = 1, ions%natoms
391 posk(:, iatom) = dt * vel(:, iatom)
392 velk(:, iatom) = dt * ions%tot_force(:, iatom) / ions%mass(iatom)
394 if (propagate_chi)
then
396 do iatom = 1, ions%natoms
397 poskt(:, iatom) = dt * velt(:, iatom)
398 velkt(:, iatom) = dt * coforce(iatom, :) / ions%mass(iatom)
403 subroutine f_chi(tau)
404 real(real64),
intent(in) :: tau
426 do ib = 1, st%group%block_start, st%group%block_end
427 call batch_axpy(np,
m_zi, hm%inh_st%group%psib(ib, ik), hchi%group%psib(ib, ik))
434 integer :: idir, idim
435 complex(real64),
allocatable :: psi(:, :), inhpsi(:, :)
438 if (ions_dyn%ions_move())
then
441 safe_allocate(psi(1:gr%np_part, 1:st%d%dim))
442 safe_allocate(inhpsi(1:gr%np_part, 1:st%d%dim))
443 safe_allocate(dvpsi(1:gr%np_part, 1:st%d%dim, 1:space%dim))
451 do iatom = 1, ions%natoms
452 do idir = 1, space%dim
454 call pert%setup_atom(iatom)
455 call pert%setup_dir(idir)
456 call pert%zapply(namespace, space, gr, hm, ik, psi(:, :), dvpsi(:, :, idir))
457 dvpsi(:, :, idir) = - dvpsi(:, :, idir)
458 do idim = 1, stphi%d%dim
459 call lalg_axpy(gr%np, st%occ(ist, ik)*post(idir, iatom), dvpsi(:, idim, idir), inhpsi(:, idim))
461 safe_deallocate_p(pert)
473 safe_deallocate_a(psi)
474 safe_deallocate_a(inhpsi)
475 safe_deallocate_a(dvpsi)
481 real(real64),
intent(in) :: epsilon
483 do ik = stphi%d%kpt%start, stphi%d%kpt%end
484 do ib = stphi%group%block_start, stphi%group%block_end
485 call batch_axpy(gr%np, -
m_zi*dt*epsilon, hst%group%psib(ib, ik), st%group%psib(ib, ik))
486 if (propagate_chi)
then
487 call batch_axpy(gr%np, -
m_zi*dt*epsilon, hchi%group%psib(ib, ik), chi%group%psib(ib, ik))
492 if (ions_dyn%ions_move())
then
493 posfinal = posfinal + posk * epsilon
494 velfinal = velfinal + velk * epsilon
495 if (propagate_chi)
then
496 posfinalt = posfinalt + poskt * epsilon
497 velfinalt = velfinalt + velkt * epsilon
505 subroutine td_runge_kutta2(ks, namespace, space, hm, gr, st, tr, time, dt, ions_dyn, ions, ext_partners)
506 type(
v_ks_t),
target,
intent(inout) :: ks
510 type(
grid_t),
target,
intent(in) :: gr
513 real(real64),
intent(in) :: time
514 real(real64),
intent(in) :: dt
519 integer :: np_part, np, kp1, kp2, st1, st2, nspin, ik, ist, idim, j, ip
522 complex(real64),
allocatable :: zphi(:, :, :, :)
523 complex(real64),
allocatable :: zpsi(:), rhs(:)
524 complex(real64),
allocatable :: k2(:, :, :, :), oldk2(:, :, :, :), rhs1(:, :, :, :)
525 complex(real64),
allocatable :: inhpsi(:)
530 if(ions_dyn%cell_relax())
then
542 move_ions_op = ions_dyn%ions_move()
550 sp_parallel = st%parallel_in_states .or. st%d%kpt%parallel
558 namespace_p => namespace
560 ext_partners_p => ext_partners
562 t_op = time - dt/
m_two
565 safe_allocate(k2(1:np_part, 1:st%d%dim, st1:st2, kp1:kp2))
566 safe_allocate(oldk2(1:np_part, 1:st%d%dim, st1:st2, kp1:kp2))
567 safe_allocate(zphi(1:gr%np_part, st%d%dim, st1:st2, kp1:kp2))
568 safe_allocate(rhs1(1:np_part, 1:st%d%dim, st1:st2, kp1:kp2))
569 safe_allocate(rhs(1:tr%tdsk_size))
570 safe_allocate(zpsi(1:tr%tdsk_size))
571 safe_allocate(vpsl1_op(1:np))
589 call zhamiltonian_elec_apply_single(hm_p, namespace, mesh_p, zphi(:, :, ist, ik), rhs1(:, :, ist, ik), ist, ik)
603 safe_allocate(inhpsi(1:gr%np))
606 do idim = 1, st%d%dim
609 rhs1(ip, idim, ist, ik) = rhs1(ip, idim, ist, ik) + dt * inhpsi(ip)
614 safe_deallocate_a(inhpsi)
631 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, &
633 calc_energy = .false., calc_eigenval = .false.)
635 if (ions_dyn%ions_move())
then
639 vpsl1_op = hm%ep%vpsl
646 call hm%ks_pot%get_interpolated_potentials(tr%vks_old, 0, storage=vhxc1_op)
649 call hm%ks_pot%store_potentials(vhxc1_op)
653 call hm%ks_pot%store_potentials(vhxc1_op)
656 if (ions_dyn%ions_move())
then
663 do idim = 1, st%d%dim
664 rhs(j:j+np-1) = rhs1(1:np, idim, ist, ik)
674 do idim = 1, st%d%dim
675 zpsi(j:j+np-1) = k2(1:np, idim, ist, ik)
688 do idim = 1, st%d%dim
689 k2(1:np, idim, ist, ik) = zpsi(j:j+np-1)
698 do idim = 1, st%d%dim
699 dres = dres + (
zmf_nrm2(gr, k2(:, idim, ist, ik) - oldk2(:, idim, ist, ik), reduce = .false.))**2
706 if (
sqrt(dres) < tr%scf_threshold)
exit
718 safe_deallocate_a(k2)
719 safe_deallocate_a(oldk2)
720 safe_deallocate_a(zphi)
721 safe_deallocate_a(rhs1)
722 safe_deallocate_a(zpsi)
723 safe_deallocate_a(rhs)
724 safe_deallocate_a(vpsl1_op)
731 subroutine td_runge_kutta4(ks, namespace, space, hm, gr, st, tr, time, dt, ions_dyn, ions, ext_partners)
732 type(
v_ks_t),
target,
intent(inout) :: ks
736 type(
grid_t),
target,
intent(in) :: gr
739 real(real64),
intent(in) :: time
740 real(real64),
intent(in) :: dt
742 type(
ions_t),
intent(inout) :: ions
745 integer :: idim, ip, ist, ik, j, kp1, kp2, st1, st2, nspin
747 complex(real64),
allocatable :: inhpsi(:)
748 complex(real64),
allocatable :: zpsi(:), rhs(:)
749 complex(real64),
allocatable :: zphi(:, :, :, :)
752 real(real64) :: a(2, 2), c(2), b(2)
753 complex(real64),
allocatable :: k1(:, :, :, :), k2(:, :, :, :), oldk1(:, :, :, :), &
754 oldk2(:, :, :, :), yn1(:, :, :, :), yn2(:, :, :, :), &
755 rhs1(:, :, :, :), rhs2(:, :, :, :)
759 if(ions_dyn%cell_relax())
then
778 move_ions_op = ions_dyn%ions_move()
786 sp_parallel = st%parallel_in_states .or. st%d%kpt%parallel
794 namespace_p => namespace
796 ext_partners_p => ext_partners
798 t_op = time - dt/
m_two
801 safe_allocate(vpsl1_op(1:gr%np))
802 safe_allocate(vpsl2_op(1:gr%np))
803 safe_allocate(k1(1:gr%np_part, 1:st%d%dim, st1:st2, kp1:kp2))
804 safe_allocate(k2(1:gr%np_part, 1:st%d%dim, st1:st2, kp1:kp2))
805 safe_allocate(oldk1(1:gr%np_part, 1:st%d%dim, st1:st2, kp1:kp2))
806 safe_allocate(oldk2(1:gr%np_part, 1:st%d%dim, st1:st2, kp1:kp2))
807 safe_allocate(yn1(1:gr%np_part, 1:st%d%dim, st1:st2, kp1:kp2))
808 safe_allocate(yn2(1:gr%np_part, 1:st%d%dim, st1:st2, kp1:kp2))
809 safe_allocate(rhs1(1:gr%np_part, 1:st%d%dim, st1:st2, kp1:kp2))
810 safe_allocate(rhs2(1:gr%np_part, 1:st%d%dim, st1:st2, kp1:kp2))
811 safe_allocate(rhs(1:tr%tdsk_size))
812 safe_allocate(zpsi(1:tr%tdsk_size))
813 safe_allocate(zphi(1:gr%np_part, st%d%dim, st1:st2, kp1:kp2))
829 yn1 = zphi + a(1, 1) * k1 + a(1, 2) * k2
830 yn2 = zphi + a(2, 1) * k1 + a(2, 2) * k2
839 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, &
841 calc_energy = .false., calc_eigenval = .false.)
842 if (ions_dyn%ions_move())
then
846 vpsl1_op = hm%ep%vpsl
851 call hm%ks_pot%store_potentials(vhxc1_op)
852 t_op = time - dt + c(1) * dt
856 call zhamiltonian_elec_apply_single(hm_p, namespace, mesh_p, zphi(:, :, ist, ik), rhs1(:, :, ist, ik), ist, ik)
858 safe_allocate(inhpsi(1:gr%np))
859 do idim = 1, st%d%dim
862 rhs1(ip, idim, ist, ik) = rhs1(ip, idim, ist, ik) +
m_zi * inhpsi(ip)
865 safe_deallocate_a(inhpsi)
869 rhs1 = -
m_zi * dt * rhs1
870 if (ions_dyn%ions_move())
then
881 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, &
883 calc_energy = .false., calc_eigenval = .false.)
884 if (ions_dyn%ions_move())
then
888 vpsl2_op = hm%ep%vpsl
893 call hm%ks_pot%store_potentials(vhxc2_op)
894 t_op = time - dt + c(2) * dt
898 call zhamiltonian_elec_apply_single(hm_p, namespace, mesh_p, zphi(:, :, ist, ik), rhs2(:, :, ist, ik), ist, ik)
900 safe_allocate(inhpsi(1:gr%np))
901 do idim = 1, st%d%dim
904 rhs2(ip, idim, ist, ik) = rhs2(ip, idim, ist, ik) +
m_zi * inhpsi(ip)
907 safe_deallocate_a(inhpsi)
911 rhs2 = -
m_zi * dt * rhs2
912 if (ions_dyn%is_active())
then
919 do idim = 1, st%d%dim
920 call lalg_copy(gr%np, rhs1(1:gr%np, idim, ist, ik), rhs(j:j+gr%np-1))
927 do idim = 1, st%d%dim
928 call lalg_copy(gr%np, rhs2(1:gr%np, idim, ist, ik), rhs(j:j+gr%np-1))
938 do idim = 1, st%d%dim
939 call lalg_copy(gr%np, k1(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, k2(1:gr%np, idim, ist, ik), zpsi(j:j+gr%np-1))
961 do idim = 1, st%d%dim
962 call lalg_copy(gr%np, zpsi(j:j+gr%np-1), k1(1:gr%np, idim, ist, ik))
969 do idim = 1, st%d%dim
970 call lalg_copy(gr%np, zpsi(j:j+gr%np-1), k2(1:gr%np, idim, ist, ik))
979 do idim = 1, st%d%dim
980 dres = dres + (
zmf_nrm2(gr, k1(:, idim, ist, ik) - oldk1(:, idim, ist, ik)))**2
981 dres = dres + (
zmf_nrm2(gr, k2(:, idim, ist, ik) - oldk2(:, idim, ist, ik)))**2
988 if (
sqrt(dres) < tr%scf_threshold)
exit
992 zphi = zphi + b(1) * k1 + b(2) * k2
1001 safe_deallocate_a(rhs1)
1002 safe_deallocate_a(rhs2)
1003 safe_deallocate_a(k1)
1004 safe_deallocate_a(k2)
1005 safe_deallocate_a(oldk1)
1006 safe_deallocate_a(oldk2)
1007 safe_deallocate_a(yn1)
1008 safe_deallocate_a(yn2)
1009 safe_deallocate_a(vpsl1_op)
1010 safe_deallocate_a(vpsl2_op)
1011 safe_deallocate_a(zpsi)
1012 safe_deallocate_a(rhs)
1019 subroutine td_rk4op(xre, xim, yre, yim)
1020 real(real64),
intent(in) :: xre(:)
1021 real(real64),
intent(in) :: xim(:)
1022 real(real64),
intent(out) :: yre(:)
1023 real(real64),
intent(out) :: yim(:)
1025 integer :: idim, j, ik, ist, kp1, kp2, st1, st2, dim, k, jj
1026 complex(real64),
allocatable :: zpsi(:, :)
1027 complex(real64),
allocatable :: opzpsi(:, :)
1028 real(real64) :: a(2, 2), c(2)
1029 integer :: np_part, np
1033 np_part = mesh_p%np_part
1037 kp1 = st_p%d%kpt%start
1038 kp2 = st_p%d%kpt%end
1041 safe_allocate(zpsi(1:np_part, 1:dim))
1042 safe_allocate(opzpsi(1:np_part, 1:dim))
1054 call hm_p%ks_pot%restore_potentials(vhxc1_op)
1055 if (move_ions_op) hm_p%ep%vpsl = vpsl1_op
1058 k = np * (kp2 - kp1 + 1) * (st2 - st1 + 1) * dim + 1
1063 zpsi(1:np, idim) = a(1, 1) * cmplx(xre(j:j+np-1), xim(j:j+np-1), real64) + &
1064 a(1, 2) * cmplx(xre(k:k+np-1), xim(k:k+np-1), real64)
1072 yre(jj:jj+np-1) = xre(jj:jj+np-1) - aimag(dt_op * opzpsi(1:np, idim))
1073 yim(jj:jj+np-1) = xim(jj:jj+np-1) + real(dt_op * opzpsi(1:np, idim), real64)
1079 call hm_p%ks_pot%restore_potentials(vhxc2_op)
1081 if (move_ions_op) hm_p%ep%vpsl = vpsl2_op
1084 k = np * (kp2 - kp1 + 1) * (st2 - st1 + 1) * dim + 1
1089 zpsi(1:np, idim) = a(2, 1) * cmplx(xre(j:j+np-1), xim(j:j+np-1), real64) + &
1090 a(2, 2) * cmplx(xre(k:k+np-1), xim(k:k+np-1), real64)
1098 yre(jj:jj+np-1) = xre(jj:jj+np-1) - aimag(dt_op * opzpsi(1:np, idim))
1099 yim(jj:jj+np-1) = xim(jj:jj+np-1) + real(dt_op * opzpsi(1:np, idim), real64)
1105 safe_deallocate_a(zpsi)
1106 safe_deallocate_a(opzpsi)
1115 real(real64),
intent(in) :: xre(:)
1116 real(real64),
intent(in) :: xim(:)
1117 real(real64),
intent(out) :: yre(:)
1118 real(real64),
intent(out) :: yim(:)
1120 integer :: idim, j, ik, ist, kp1, kp2, st1, st2, dim, k, jj
1121 complex(real64),
allocatable :: zpsi(:, :)
1122 complex(real64),
allocatable :: opzpsi(:, :)
1123 real(real64) :: a(2, 2), c(2)
1124 integer :: np_part, np
1128 np_part = mesh_p%np_part
1132 kp1 = st_p%d%kpt%start
1133 kp2 = st_p%d%kpt%end
1136 safe_allocate(zpsi(1:np_part, 1:dim))
1137 safe_allocate(opzpsi(1:np_part, 1:dim))
1149 call hm_p%ks_pot%restore_potentials(vhxc1_op)
1150 if (move_ions_op) hm_p%ep%vpsl = vpsl1_op
1155 k = np * (kp2 - kp1 + 1) * (st2 - st1 + 1) * dim + 1
1160 zpsi(1:np, idim) = a(1, 1) * cmplx(xre(j:j+np-1), -xim(j:j+np-1), real64) + &
1161 a(1, 2) * cmplx(xre(k:k+np-1), -xim(k:k+np-1), real64)
1169 yre(jj:jj+np-1) = xre(jj:jj+np-1) - aimag(dt_op * opzpsi(1:np, idim))
1170 yim(jj:jj+np-1) = xim(jj:jj+np-1) - real(dt_op * opzpsi(1:np, idim), real64)
1176 call hm_p%ks_pot%restore_potentials(vhxc2_op)
1177 if (move_ions_op) hm_p%ep%vpsl = vpsl2_op
1182 k = np * (kp2 - kp1 + 1) * (st2 - st1 + 1) * dim + 1
1187 zpsi(1:np, idim) = a(2, 1) * cmplx(xre(j:j+np-1), -xim(j:j+np-1), real64) + &
1188 a(2, 2) * cmplx(xre(k:k+np-1), -xim(k:k+np-1), real64)
1196 yre(jj:jj+np-1) = xre(jj:jj+np-1) - aimag(dt_op * opzpsi(1:np, idim))
1197 yim(jj:jj+np-1) = xim(jj:jj+np-1) - real(dt_op * opzpsi(1:np, idim), real64)
1203 safe_deallocate_a(zpsi)
1204 safe_deallocate_a(opzpsi)
1212 subroutine td_rk2op(xre, xim, yre, yim)
1213 real(real64),
intent(in) :: xre(:)
1214 real(real64),
intent(in) :: xim(:)
1215 real(real64),
intent(out) :: yre(:)
1216 real(real64),
intent(out) :: yim(:)
1218 integer :: np_part, np, st1, st2, kp1, kp2, dim, idim, ik, ist, jj, j
1219 complex(real64),
allocatable :: zpsi(:, :)
1220 complex(real64),
allocatable :: opzpsi(:, :)
1221 complex(real64),
allocatable :: zpsi_(:, :, :, :)
1225 np_part = mesh_p%np_part
1229 kp1 = st_p%d%kpt%start
1230 kp2 = st_p%d%kpt%end
1233 safe_allocate(zpsi(1:np_part, 1:dim))
1234 safe_allocate(opzpsi(1:np_part, 1:dim))
1235 safe_allocate(zpsi_(1:np_part, 1:dim, st1:st2, kp1:kp2))
1240 call hm_p%ks_pot%restore_potentials(vhxc1_op)
1241 if (move_ions_op) hm_p%ep%vpsl = vpsl1_op
1251 zpsi_(1:np, idim, ist, ik) = cmplx(xre(j:j+np-1), xim(j:j+np-1), real64)
1256 call oct_exchange_prepare(hm_p%oct_exchange, mesh_p, zpsi_, hm_p%xc, hm_p%psolver, namespace_p)
1264 zpsi(1:np, idim) = cmplx(xre(j:j+np-1), xim(j:j+np-1), real64)
1269 yre(jj:jj+np-1) = xre(jj:jj+np-1) - aimag(dt_op *
m_half * opzpsi(1:np, idim))
1270 yim(jj:jj+np-1) = xim(jj:jj+np-1) + real(dt_op *
m_half * opzpsi(1:np, idim), real64)
1282 zpsi(1:np, idim) = cmplx(xre(j:j+np-1), xim(j:j+np-1), real64)
1289 yre(jj:jj+np-1) = yre(jj:jj+np-1) - aimag(dt_op *
m_half * opzpsi(1:np, idim))
1290 yim(jj:jj+np-1) = yim(jj:jj+np-1) + real(dt_op *
m_half * opzpsi(1:np, idim), real64)
1297 safe_deallocate_a(zpsi)
1298 safe_deallocate_a(opzpsi)
1308 real(real64),
intent(in) :: xre(:)
1309 real(real64),
intent(in) :: xim(:)
1310 real(real64),
intent(out) :: yre(:)
1311 real(real64),
intent(out) :: yim(:)
1313 integer :: np_part, np, st1, st2, kp1, kp2, dim, idim, ik, ist, jj, j
1314 complex(real64),
allocatable :: zpsi(:, :)
1315 complex(real64),
allocatable :: opzpsi(:, :)
1316 complex(real64),
allocatable :: zpsi_(:, :, :, :)
1320 np_part = mesh_p%np_part
1324 kp1 = st_p%d%kpt%start
1325 kp2 = st_p%d%kpt%end
1328 safe_allocate(zpsi(1:np_part, 1:dim))
1329 safe_allocate(opzpsi(1:np_part, 1:dim))
1330 safe_allocate(zpsi_(1:np_part, 1:dim, st1:st2, kp1:kp2))
1335 call hm_p%ks_pot%restore_potentials(vhxc1_op)
1336 if (move_ions_op) hm_p%ep%vpsl = vpsl1_op
1346 zpsi_(1:np, idim, ist, ik) = cmplx(xre(j:j+np-1), -xim(j:j+np-1), real64)
1351 call oct_exchange_prepare(hm_p%oct_exchange, mesh_p, zpsi_, hm_p%xc, hm_p%psolver, namespace_p)
1359 zpsi(1:np, idim) = cmplx(xre(j:j+np-1), -xim(j:j+np-1), real64)
1365 yre(jj:jj+np-1) = xre(jj:jj+np-1) - aimag(dt_op *
m_half * opzpsi(1:np, idim))
1366 yim(jj:jj+np-1) = xim(jj:jj+np-1) - real(dt_op *
m_half * opzpsi(1:np, idim), real64)
1378 zpsi(1:np, idim) = cmplx(xre(j:j+np-1), xim(j:j+np-1), real64)
1385 yre(jj:jj+np-1) = yre(jj:jj+np-1) - aimag(dt_op *
m_half * opzpsi(1:np, idim))
1386 yim(jj:jj+np-1) = yim(jj:jj+np-1) - real(dt_op *
m_half * opzpsi(1:np, idim), real64)
1393 safe_deallocate_a(zpsi)
1394 safe_deallocate_a(opzpsi)
batchified version of the BLAS axpy routine:
constant times a vector plus a vector
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
integer, parameter, public independent_particles
Theory level.
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 hamiltonian_elec_remove_inh(hm)
subroutine, public zhamiltonian_elec_apply_all(hm, namespace, gr, st, hst)
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)
Interface for the ion/cell dynamics.
subroutine, public ion_dynamics_save_state(this, ions, state)
A module to handle KS potential, without the external potential.
subroutine, public xc_copied_potentials_end(this)
Finalizer for the copied potentials.
subroutine, public lda_u_update_occ_matrices(this, namespace, mesh, st, 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, public messages_not_implemented(feature, namespace)
subroutine mpi_grp_copy(mpi_grp_out, mpi_grp_in)
MPI_THREAD_FUNNELED allows for calls to MPI from an OMP region if the thread is the team master.
subroutine, public oct_exchange_prepare(this, gr, psi, xc, psolver, namespace)
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)
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.