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 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))
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 inhpsi(1:gr%np, 1:stphi%d%dim) = inhpsi(1:gr%np, 1:stphi%d%dim) &
459 + st%occ(ist, ik)*post(idir, iatom)*dvpsi(1:gr%np, 1:stphi%d%dim, idir)
460 safe_deallocate_p(pert)
472 safe_deallocate_a(psi)
473 safe_deallocate_a(inhpsi)
474 safe_deallocate_a(dvpsi)
480 real(real64),
intent(in) :: epsilon
482 do ik = stphi%d%kpt%start, stphi%d%kpt%end
483 do ib = stphi%group%block_start, stphi%group%block_end
484 call batch_axpy(gr%np, -
m_zi*dt*epsilon, hst%group%psib(ib, ik), st%group%psib(ib, ik))
485 if (propagate_chi)
then
486 call batch_axpy(gr%np, -
m_zi*dt*epsilon, hchi%group%psib(ib, ik), chi%group%psib(ib, ik))
491 if (ions_dyn%ions_move())
then
492 posfinal = posfinal + posk * epsilon
493 velfinal = velfinal + velk * epsilon
494 if (propagate_chi)
then
495 posfinalt = posfinalt + poskt * epsilon
496 velfinalt = velfinalt + velkt * epsilon
504 subroutine td_runge_kutta2(ks, namespace, space, hm, gr, st, tr, time, dt, ions_dyn, ions, ext_partners)
505 type(
v_ks_t),
target,
intent(inout) :: ks
509 type(
grid_t),
target,
intent(in) :: gr
512 real(real64),
intent(in) :: time
513 real(real64),
intent(in) :: dt
515 type(
ions_t),
intent(inout) :: ions
518 integer :: np_part, np, kp1, kp2, st1, st2, nspin, ik, ist, idim, j, ip
521 complex(real64),
allocatable :: zphi(:, :, :, :)
522 complex(real64),
allocatable :: zpsi(:), rhs(:)
523 complex(real64),
allocatable :: k2(:, :, :, :), oldk2(:, :, :, :), rhs1(:, :, :, :)
524 complex(real64),
allocatable :: inhpsi(:)
529 if(ions_dyn%cell_relax())
then
541 move_ions_op = ions_dyn%ions_move()
549 sp_parallel = st%parallel_in_states .or. st%d%kpt%parallel
557 namespace_p => namespace
559 ext_partners_p => ext_partners
561 t_op = time - dt/
m_two
564 safe_allocate(k2(1:np_part, 1:st%d%dim, st1:st2, kp1:kp2))
565 safe_allocate(oldk2(1:np_part, 1:st%d%dim, st1:st2, kp1:kp2))
566 safe_allocate(zphi(1:gr%np_part, st%d%dim, st1:st2, kp1:kp2))
567 safe_allocate(rhs1(1:np_part, 1:st%d%dim, st1:st2, kp1:kp2))
568 safe_allocate(rhs(1:tr%tdsk_size))
569 safe_allocate(zpsi(1:tr%tdsk_size))
570 safe_allocate(vpsl1_op(1:np))
588 call zhamiltonian_elec_apply_single(hm_p, namespace, mesh_p, zphi(:, :, ist, ik), rhs1(:, :, ist, ik), ist, ik)
602 safe_allocate(inhpsi(1:gr%np))
605 do idim = 1, st%d%dim
608 rhs1(ip, idim, ist, ik) = rhs1(ip, idim, ist, ik) + dt * inhpsi(ip)
613 safe_deallocate_a(inhpsi)
630 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, &
632 calc_energy = .false., calc_eigenval = .false.)
634 if (ions_dyn%ions_move())
then
638 vpsl1_op = hm%ep%vpsl
645 call hm%ks_pot%get_interpolated_potentials(tr%vks_old, 0, storage=vhxc1_op)
648 call hm%ks_pot%store_potentials(vhxc1_op)
652 call hm%ks_pot%store_potentials(vhxc1_op)
655 if (ions_dyn%ions_move())
then
662 do idim = 1, st%d%dim
663 rhs(j:j+np-1) = rhs1(1:np, idim, ist, ik)
673 do idim = 1, st%d%dim
674 zpsi(j:j+np-1) = k2(1:np, idim, ist, ik)
687 do idim = 1, st%d%dim
688 k2(1:np, idim, ist, ik) = zpsi(j:j+np-1)
697 do idim = 1, st%d%dim
698 dres = dres + (
zmf_nrm2(gr, k2(:, idim, ist, ik) - oldk2(:, idim, ist, ik), reduce = .false.))**2
705 if (
sqrt(dres) < tr%scf_threshold)
exit
717 safe_deallocate_a(k2)
718 safe_deallocate_a(oldk2)
719 safe_deallocate_a(zphi)
720 safe_deallocate_a(rhs1)
721 safe_deallocate_a(zpsi)
722 safe_deallocate_a(rhs)
723 safe_deallocate_a(vpsl1_op)
730 subroutine td_runge_kutta4(ks, namespace, space, hm, gr, st, tr, time, dt, ions_dyn, ions, ext_partners)
731 type(
v_ks_t),
target,
intent(inout) :: ks
735 type(
grid_t),
target,
intent(in) :: gr
738 real(real64),
intent(in) :: time
739 real(real64),
intent(in) :: dt
741 type(
ions_t),
intent(inout) :: ions
744 integer :: idim, ip, ist, ik, j, kp1, kp2, st1, st2, nspin
746 complex(real64),
allocatable :: inhpsi(:)
747 complex(real64),
allocatable :: zpsi(:), rhs(:)
748 complex(real64),
allocatable :: zphi(:, :, :, :)
751 real(real64) :: a(2, 2), c(2), b(2)
752 complex(real64),
allocatable :: k1(:, :, :, :), k2(:, :, :, :), oldk1(:, :, :, :), &
753 oldk2(:, :, :, :), yn1(:, :, :, :), yn2(:, :, :, :), &
754 rhs1(:, :, :, :), rhs2(:, :, :, :)
758 if(ions_dyn%cell_relax())
then
777 move_ions_op = ions_dyn%ions_move()
785 sp_parallel = st%parallel_in_states .or. st%d%kpt%parallel
793 namespace_p => namespace
795 ext_partners_p => ext_partners
797 t_op = time - dt/
m_two
800 safe_allocate(vpsl1_op(1:gr%np))
801 safe_allocate(vpsl2_op(1:gr%np))
802 safe_allocate(k1(1:gr%np_part, 1:st%d%dim, st1:st2, kp1:kp2))
803 safe_allocate(k2(1:gr%np_part, 1:st%d%dim, st1:st2, kp1:kp2))
804 safe_allocate(oldk1(1:gr%np_part, 1:st%d%dim, st1:st2, kp1:kp2))
805 safe_allocate(oldk2(1:gr%np_part, 1:st%d%dim, st1:st2, kp1:kp2))
806 safe_allocate(yn1(1:gr%np_part, 1:st%d%dim, st1:st2, kp1:kp2))
807 safe_allocate(yn2(1:gr%np_part, 1:st%d%dim, st1:st2, kp1:kp2))
808 safe_allocate(rhs1(1:gr%np_part, 1:st%d%dim, st1:st2, kp1:kp2))
809 safe_allocate(rhs2(1:gr%np_part, 1:st%d%dim, st1:st2, kp1:kp2))
810 safe_allocate(rhs(1:tr%tdsk_size))
811 safe_allocate(zpsi(1:tr%tdsk_size))
812 safe_allocate(zphi(1:gr%np_part, st%d%dim, st1:st2, kp1:kp2))
828 yn1 = zphi + a(1, 1) * k1 + a(1, 2) * k2
829 yn2 = zphi + a(2, 1) * k1 + a(2, 2) * k2
838 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, &
840 calc_energy = .false., calc_eigenval = .false.)
841 if (ions_dyn%ions_move())
then
845 vpsl1_op = hm%ep%vpsl
850 call hm%ks_pot%store_potentials(vhxc1_op)
851 t_op = time - dt + c(1) * dt
855 call zhamiltonian_elec_apply_single(hm_p, namespace, mesh_p, zphi(:, :, ist, ik), rhs1(:, :, ist, ik), ist, ik)
857 safe_allocate(inhpsi(1:gr%np))
858 do idim = 1, st%d%dim
861 rhs1(ip, idim, ist, ik) = rhs1(ip, idim, ist, ik) +
m_zi * inhpsi(ip)
864 safe_deallocate_a(inhpsi)
868 rhs1 = -
m_zi * dt * rhs1
869 if (ions_dyn%ions_move())
then
880 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, &
882 calc_energy = .false., calc_eigenval = .false.)
883 if (ions_dyn%ions_move())
then
887 vpsl2_op = hm%ep%vpsl
892 call hm%ks_pot%store_potentials(vhxc2_op)
893 t_op = time - dt + c(2) * dt
897 call zhamiltonian_elec_apply_single(hm_p, namespace, mesh_p, zphi(:, :, ist, ik), rhs2(:, :, ist, ik), ist, ik)
899 safe_allocate(inhpsi(1:gr%np))
900 do idim = 1, st%d%dim
903 rhs2(ip, idim, ist, ik) = rhs2(ip, idim, ist, ik) +
m_zi * inhpsi(ip)
906 safe_deallocate_a(inhpsi)
910 rhs2 = -
m_zi * dt * rhs2
911 if (ions_dyn%is_active())
then
918 do idim = 1, st%d%dim
919 call lalg_copy(gr%np, rhs1(1:gr%np, idim, ist, ik), rhs(j:j+gr%np-1))
926 do idim = 1, st%d%dim
927 call lalg_copy(gr%np, rhs2(1:gr%np, idim, ist, ik), rhs(j:j+gr%np-1))
937 do idim = 1, st%d%dim
938 call lalg_copy(gr%np, k1(1:gr%np, idim, ist, ik), zpsi(j:j+gr%np-1))
945 do idim = 1, st%d%dim
946 call lalg_copy(gr%np, k2(1:gr%np, idim, ist, ik), zpsi(j:j+gr%np-1))
960 do idim = 1, st%d%dim
961 call lalg_copy(gr%np, zpsi(j:j+gr%np-1), k1(1:gr%np, idim, ist, ik))
968 do idim = 1, st%d%dim
969 call lalg_copy(gr%np, zpsi(j:j+gr%np-1), k2(1:gr%np, idim, ist, ik))
978 do idim = 1, st%d%dim
979 dres = dres + (
zmf_nrm2(gr, k1(:, idim, ist, ik) - oldk1(:, idim, ist, ik)))**2
980 dres = dres + (
zmf_nrm2(gr, k2(:, idim, ist, ik) - oldk2(:, idim, ist, ik)))**2
987 if (
sqrt(dres) < tr%scf_threshold)
exit
991 zphi = zphi + b(1) * k1 + b(2) * k2
1000 safe_deallocate_a(rhs1)
1001 safe_deallocate_a(rhs2)
1002 safe_deallocate_a(k1)
1003 safe_deallocate_a(k2)
1004 safe_deallocate_a(oldk1)
1005 safe_deallocate_a(oldk2)
1006 safe_deallocate_a(yn1)
1007 safe_deallocate_a(yn2)
1008 safe_deallocate_a(vpsl1_op)
1009 safe_deallocate_a(vpsl2_op)
1010 safe_deallocate_a(zpsi)
1011 safe_deallocate_a(rhs)
1018 subroutine td_rk4op(xre, xim, yre, yim)
1019 real(real64),
intent(in) :: xre(:)
1020 real(real64),
intent(in) :: xim(:)
1021 real(real64),
intent(out) :: yre(:)
1022 real(real64),
intent(out) :: yim(:)
1024 integer :: idim, j, ik, ist, kp1, kp2, st1, st2, dim, k, jj
1025 complex(real64),
allocatable :: zpsi(:, :)
1026 complex(real64),
allocatable :: opzpsi(:, :)
1027 real(real64) :: a(2, 2), c(2)
1028 integer :: np_part, np
1032 np_part = mesh_p%np_part
1036 kp1 = st_p%d%kpt%start
1037 kp2 = st_p%d%kpt%end
1040 safe_allocate(zpsi(1:np_part, 1:dim))
1041 safe_allocate(opzpsi(1:np_part, 1:dim))
1053 call hm_p%ks_pot%restore_potentials(vhxc1_op)
1054 if (move_ions_op) hm_p%ep%vpsl = vpsl1_op
1057 k = np * (kp2 - kp1 + 1) * (st2 - st1 + 1) * dim + 1
1062 zpsi(1:np, idim) = a(1, 1) * cmplx(xre(j:j+np-1), xim(j:j+np-1), real64) + &
1063 a(1, 2) * cmplx(xre(k:k+np-1), xim(k:k+np-1), real64)
1071 yre(jj:jj+np-1) = xre(jj:jj+np-1) - aimag(dt_op * opzpsi(1:np, idim))
1072 yim(jj:jj+np-1) = xim(jj:jj+np-1) + real(dt_op * opzpsi(1:np, idim), real64)
1078 call hm_p%ks_pot%restore_potentials(vhxc2_op)
1080 if (move_ions_op) hm_p%ep%vpsl = vpsl2_op
1083 k = np * (kp2 - kp1 + 1) * (st2 - st1 + 1) * dim + 1
1088 zpsi(1:np, idim) = a(2, 1) * cmplx(xre(j:j+np-1), xim(j:j+np-1), real64) + &
1089 a(2, 2) * cmplx(xre(k:k+np-1), xim(k:k+np-1), real64)
1097 yre(jj:jj+np-1) = xre(jj:jj+np-1) - aimag(dt_op * opzpsi(1:np, idim))
1098 yim(jj:jj+np-1) = xim(jj:jj+np-1) + real(dt_op * opzpsi(1:np, idim), real64)
1104 safe_deallocate_a(zpsi)
1105 safe_deallocate_a(opzpsi)
1113 subroutine td_rk4opt(xre, xim, yre, yim)
1114 real(real64),
intent(in) :: xre(:)
1115 real(real64),
intent(in) :: xim(:)
1116 real(real64),
intent(out) :: yre(:)
1117 real(real64),
intent(out) :: yim(:)
1119 integer :: idim, j, ik, ist, kp1, kp2, st1, st2, dim, k, jj
1120 complex(real64),
allocatable :: zpsi(:, :)
1121 complex(real64),
allocatable :: opzpsi(:, :)
1122 real(real64) :: a(2, 2), c(2)
1123 integer :: np_part, np
1127 np_part = mesh_p%np_part
1131 kp1 = st_p%d%kpt%start
1132 kp2 = st_p%d%kpt%end
1135 safe_allocate(zpsi(1:np_part, 1:dim))
1136 safe_allocate(opzpsi(1:np_part, 1:dim))
1148 call hm_p%ks_pot%restore_potentials(vhxc1_op)
1149 if (move_ions_op) hm_p%ep%vpsl = vpsl1_op
1154 k = np * (kp2 - kp1 + 1) * (st2 - st1 + 1) * dim + 1
1159 zpsi(1:np, idim) = a(1, 1) * cmplx(xre(j:j+np-1), -xim(j:j+np-1), real64) + &
1160 a(1, 2) * cmplx(xre(k:k+np-1), -xim(k:k+np-1), real64)
1168 yre(jj:jj+np-1) = xre(jj:jj+np-1) - aimag(dt_op * opzpsi(1:np, idim))
1169 yim(jj:jj+np-1) = xim(jj:jj+np-1) - real(dt_op * opzpsi(1:np, idim), real64)
1175 call hm_p%ks_pot%restore_potentials(vhxc2_op)
1176 if (move_ions_op) hm_p%ep%vpsl = vpsl2_op
1181 k = np * (kp2 - kp1 + 1) * (st2 - st1 + 1) * dim + 1
1186 zpsi(1:np, idim) = a(2, 1) * cmplx(xre(j:j+np-1), -xim(j:j+np-1), real64) + &
1187 a(2, 2) * cmplx(xre(k:k+np-1), -xim(k:k+np-1), real64)
1195 yre(jj:jj+np-1) = xre(jj:jj+np-1) - aimag(dt_op * opzpsi(1:np, idim))
1196 yim(jj:jj+np-1) = xim(jj:jj+np-1) - real(dt_op * opzpsi(1:np, idim), real64)
1202 safe_deallocate_a(zpsi)
1203 safe_deallocate_a(opzpsi)
1211 subroutine td_rk2op(xre, xim, yre, yim)
1212 real(real64),
intent(in) :: xre(:)
1213 real(real64),
intent(in) :: xim(:)
1214 real(real64),
intent(out) :: yre(:)
1215 real(real64),
intent(out) :: yim(:)
1217 integer :: np_part, np, st1, st2, kp1, kp2, dim, idim, ik, ist, jj, j
1218 complex(real64),
allocatable :: zpsi(:, :)
1219 complex(real64),
allocatable :: opzpsi(:, :)
1220 complex(real64),
allocatable :: zpsi_(:, :, :, :)
1224 np_part = mesh_p%np_part
1228 kp1 = st_p%d%kpt%start
1229 kp2 = st_p%d%kpt%end
1232 safe_allocate(zpsi(1:np_part, 1:dim))
1233 safe_allocate(opzpsi(1:np_part, 1:dim))
1234 safe_allocate(zpsi_(1:np_part, 1:dim, st1:st2, kp1:kp2))
1239 call hm_p%ks_pot%restore_potentials(vhxc1_op)
1240 if (move_ions_op) hm_p%ep%vpsl = vpsl1_op
1250 zpsi_(1:np, idim, ist, ik) = cmplx(xre(j:j+np-1), xim(j:j+np-1), real64)
1255 call oct_exchange_prepare(hm_p%oct_exchange, mesh_p, zpsi_, hm_p%xc, hm_p%psolver, namespace_p)
1263 zpsi(1:np, idim) = cmplx(xre(j:j+np-1), xim(j:j+np-1), real64)
1268 yre(jj:jj+np-1) = xre(jj:jj+np-1) - aimag(dt_op *
m_half * opzpsi(1:np, idim))
1269 yim(jj:jj+np-1) = xim(jj:jj+np-1) + real(dt_op *
m_half * opzpsi(1:np, idim), real64)
1281 zpsi(1:np, idim) = cmplx(xre(j:j+np-1), xim(j:j+np-1), real64)
1288 yre(jj:jj+np-1) = yre(jj:jj+np-1) - aimag(dt_op *
m_half * opzpsi(1:np, idim))
1289 yim(jj:jj+np-1) = yim(jj:jj+np-1) + real(dt_op *
m_half * opzpsi(1:np, idim), real64)
1296 safe_deallocate_a(zpsi)
1297 safe_deallocate_a(opzpsi)
1306 subroutine td_rk2opt(xre, xim, yre, yim)
1307 real(real64),
intent(in) :: xre(:)
1308 real(real64),
intent(in) :: xim(:)
1309 real(real64),
intent(out) :: yre(:)
1310 real(real64),
intent(out) :: yim(:)
1312 integer :: np_part, np, st1, st2, kp1, kp2, dim, idim, ik, ist, jj, j
1313 complex(real64),
allocatable :: zpsi(:, :)
1314 complex(real64),
allocatable :: opzpsi(:, :)
1315 complex(real64),
allocatable :: zpsi_(:, :, :, :)
1319 np_part = mesh_p%np_part
1323 kp1 = st_p%d%kpt%start
1324 kp2 = st_p%d%kpt%end
1327 safe_allocate(zpsi(1:np_part, 1:dim))
1328 safe_allocate(opzpsi(1:np_part, 1:dim))
1329 safe_allocate(zpsi_(1:np_part, 1:dim, st1:st2, kp1:kp2))
1334 call hm_p%ks_pot%restore_potentials(vhxc1_op)
1335 if (move_ions_op) hm_p%ep%vpsl = vpsl1_op
1345 zpsi_(1:np, idim, ist, ik) = cmplx(xre(j:j+np-1), -xim(j:j+np-1), real64)
1350 call oct_exchange_prepare(hm_p%oct_exchange, mesh_p, zpsi_, hm_p%xc, hm_p%psolver, namespace_p)
1358 zpsi(1:np, idim) = cmplx(xre(j:j+np-1), -xim(j:j+np-1), real64)
1364 yre(jj:jj+np-1) = xre(jj:jj+np-1) - aimag(dt_op *
m_half * opzpsi(1:np, idim))
1365 yim(jj:jj+np-1) = xim(jj:jj+np-1) - real(dt_op *
m_half * opzpsi(1:np, idim), real64)
1377 zpsi(1:np, idim) = cmplx(xre(j:j+np-1), xim(j:j+np-1), real64)
1384 yre(jj:jj+np-1) = yre(jj:jj+np-1) - aimag(dt_op *
m_half * opzpsi(1:np, idim))
1385 yim(jj:jj+np-1) = yim(jj:jj+np-1) - real(dt_op *
m_half * opzpsi(1:np, idim), real64)
1392 safe_deallocate_a(zpsi)
1393 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)
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.
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, public messages_not_implemented(feature, namespace)
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.