44 use,
intrinsic :: iso_fortran_env
95 type(namespace_t),
intent(in) :: namespace
96 type(grid_t),
intent(inout) :: gr
97 type(hamiltonian_elec_t),
intent(inout) :: hm
98 type(states_elec_t),
target,
intent(inout) :: st
99 type(ions_t),
intent(inout) :: ions
100 type(v_ks_t),
intent(in) :: ks
101 type(partner_list_t),
intent(in) :: ext_partners
103 real(real64),
allocatable :: rho_total(:)
104 real(real64) :: stress(3,3)
105 real(real64) :: stress_kin(3,3), stress_Hartree(3,3), stress_xc(3,3), stress_xc_nlcc(3,3)
106 real(real64) :: stress_ps(3,3), stress_ps_nl(3,3), stress_ps_local(3,3), stress_ii(3,3)
107 real(real64) :: stress_ps_aug(3,3)
108 real(real64) :: stress_hubbard(3,3)
110 real(real64),
allocatable :: vh(:)
111 real(real64),
allocatable :: grad_vh(:,:)
112 real(real64) :: ehartree
113 real(real64),
contiguous,
pointer :: rho(:)
118 if (st%requires_generalized_overlap .and. st%d%ispin ==
spinors)
then
122 if (hm%ep%has_paw)
then
127 write(
message(1),
'(a)')
'The stress tensors for real wavefunctions has not been implemented!'
129 if (hm%kpoints%full%npoints == 1)
then
130 write(
message(2),
'(a)')
'For testing this feature, you can add ForceComplex=yes to the input file'
137 if (ions%space%periodic_dim == 1)
then
141 if (.not. ions%space%is_periodic())
then
142 write(
message(1),
'(a)')
'The stress tensor cannot be computed for isolated systems'
146 if (ks%vdw%vdw_correction /= option__vdwcorrection__none .and. .not. any(ks%vdw%vdw_correction ==
d3_lib_options))
then
147 write(
message(1),
'(a)')
'The stress tensor is currently only implemented with DFT-D3 vdW correction'
151 if (hm%pcm%run_pcm)
then
155 if (
allocated(hm%v_static))
then
159 if (ks%v_ks_photons%active())
then
165 if (.not. hm%vnl%apply_projector_matrices)
then
166 if (hm%vnl%has_non_local_potential)
then
167 call messages_not_implemented(
'Stress tensor with relativistic Kleinman-Bylander pseudopotential', namespace=namespace)
170 'user-defined or all-electron species)', namespace=namespace)
184 if ( .not.
in_family(hm%xc%family, [xc_family_lda, xc_family_gga, xc_family_mgga]))
then
185 write(
message(1),
'(a)')
'The stress tensor computation is currently only possible at the Kohn-Sham DFT level'
186 write(
message(2),
'(a)')
'with LDA, GGA and mGGA functionals or for independent particles.'
190 if (
in_family(hm%xc%family, [xc_family_gga, xc_family_mgga]) .and. st%d%ispin ==
spinors)
then
204 if (hm%xc%use_gi_ked)
then
217 safe_allocate(rho_total(1:gr%np_part))
219 rho_total(ip) = sum(st%rho(ip, 1:st%d%spin_channels))
228 safe_allocate(vh(1:gr%np_part))
229 safe_allocate(grad_vh(1:gr%np, 1:gr%der%dim))
231 call lalg_copy(gr%np, hm%ks_pot%vhartree, vh)
233 if (hm%d%spin_channels > 1)
then
234 safe_allocate(rho(1:gr%np_part))
242 if (hm%d%spin_channels > 1)
then
243 safe_deallocate_p(rho)
248 ehartree = hm%energy%hartree
255 call stress_from_kinetic(gr, ions%space, hm, st, gr%symm, ions%latt%rcell_volume, stress_kin)
256 stress = stress + stress_kin
263 call stress_from_hartree(gr, ions%space, ions%latt%rcell_volume, grad_vh, ehartree, stress_hartree)
264 stress = stress + stress_hartree
266 call stress_from_xc(gr, hm, st, ions%space, ions%latt%rcell_volume, stress_xc)
269 if (
allocated(st%rho_core))
then
270 call stress_from_xc_nlcc(ions%latt%rcell_volume, gr, st, ions, hm%ks_pot%vxc, stress_xc_nlcc)
275 stress_xc = stress_xc + ks%stress_xc / ions%latt%rcell_volume
276 stress = stress + stress_xc + stress_xc_nlcc
280 stress_ps = stress_ps_local
281 stress = stress + stress_ps_local
283 safe_deallocate_a(vh)
284 safe_deallocate_a(grad_vh)
287 stress_ps = stress_ps + stress_ps_nl + stress_ps_aug
288 stress = stress + stress_ps_nl + stress_ps_aug
290 call stress_from_hubbard(namespace, gr, st, hm, ions%space, ions%latt%rcell_volume, stress_hubbard)
291 stress = stress + stress_hubbard
293 call ion_interaction_stress(ions%ion_interaction, ions%space, ions%latt, ions%atom, ions%natoms, ions%pos, stress_ii)
294 stress = stress + stress_ii
300 st%stress_tensors%kinetic = -stress_kin
301 st%stress_tensors%Hartree = -stress_hartree
302 st%stress_tensors%xc = -stress_xc
303 st%stress_tensors%xc_nlcc = -stress_xc_nlcc
304 st%stress_tensors%ps_local = -stress_ps_local
305 st%stress_tensors%ps_nl = -stress_ps_nl
306 st%stress_tensors%ps_aug = -stress_ps_aug
307 st%stress_tensors%hubbard = -stress_hubbard
308 st%stress_tensors%ion_ion = -stress_ii
311 if (ks%vdw%vdw_correction /= option__vdwcorrection__none)
then
312 st%stress_tensors%vdw = hm%ep%vdw_stress
314 st%stress_tensors%vdw =
m_zero
316 stress = stress + st%stress_tensors%vdw
319 if (hm%kpoints%use_symmetries)
then
325 st%stress_tensors%total = stress
329 st%stress_tensors%kinetic_sumrule =
m_zero
331 st%stress_tensors%Hartree_sumrule =
m_zero
332 if(ions%space%periodic_dim == 3)
then
333 st%stress_tensors%kinetic_sumrule = (stress_kin(1,1) + stress_kin(2,2) + stress_kin(3,3))*ions%latt%rcell_volume
334 st%stress_tensors%kinetic_sumrule = st%stress_tensors%kinetic_sumrule -
m_two * hm%energy%kinetic
336 st%stress_tensors%hartree_sumrule = (stress_hartree(1,1) + stress_hartree(2,2) + stress_hartree(3,3))*ions%latt%rcell_volume
337 st%stress_tensors%hartree_sumrule = st%stress_tensors%hartree_sumrule - hm%energy%hartree
340 safe_deallocate_a(rho_total)
362 type(
grid_t),
intent(in) :: gr
363 class(
space_t),
intent(in) :: space
367 real(real64),
intent(in) :: rcell_volume
368 real(real64),
intent(out) :: stress_kin(3, 3)
370 integer :: ik, ist, idir, jdir, ib, minst, maxst
371 complex(real64),
allocatable :: stress_l_block(:)
379 safe_allocate(stress_l_block(1:st%block_size))
381 do ik = st%d%kpt%start, st%d%kpt%end
384 do ib = st%group%block_start, st%group%block_end
388 call hm%phase%copy_and_set_phase(gr, st%d%kpt, st%group%psib(ib, ik), psib)
394 do idir = 1, space%periodic_dim
395 do jdir = idir, space%periodic_dim
398 do ist = minst, maxst
399 stress_kin(idir,jdir) = stress_kin(idir,jdir) &
400 + st%kweights(ik) * st%occ(ist, ik) &
401 * real(stress_l_block(ist - minst + 1), real64)
406 do idir = 1, space%dim
407 call gpsib(idir)%end()
414 if (st%parallel_in_states .or. st%d%kpt%parallel)
then
423 if (hm%kpoints%use_symmetries)
then
427 stress_kin = stress_kin / rcell_volume
451 type(
grid_t),
intent(in) :: gr
452 class(
space_t),
intent(in) :: space
453 real(real64),
intent(in) :: volume
454 real(real64),
contiguous,
intent(in) :: grad_vh(:,:)
455 real(real64),
intent(in) :: ehartree
456 real(real64),
intent(out) :: stress_Hartree(3, 3)
458 integer :: idir, jdir
463 stress_hartree(:,:) =
m_zero
465 do idir = 1, space%periodic_dim
466 do jdir = idir, space%periodic_dim
467 stress_hartree(idir, jdir) = -
dmf_dotp(gr, grad_vh(:,idir), grad_vh(:, jdir))/
m_four/
m_pi
469 stress_hartree(idir, idir) = stress_hartree(idir, idir) + ehartree
474 stress_hartree = stress_hartree/volume
509 subroutine stress_from_xc(gr, hm, st, space, rcell_volume, stress_xc)
510 type(
grid_t),
intent(in) :: gr
513 class(
space_t),
intent(in) :: space
514 real(real64),
intent(in) :: rcell_volume
515 real(real64),
intent(out) :: stress_xc(3, 3)
517 integer :: ik, ist, idir, jdir, ib, minst, maxst, ispin
518 real(real64) :: stress_tau(3,3)
519 complex(real64),
allocatable :: stress_l_block(:)
520 type(
wfs_elec_t) :: psib, gpsib(space%dim), vtau_gpsib(space%dim)
527 do idir = 1, space%periodic_dim
528 stress_xc(idir, idir) = - hm%energy%exchange - hm%energy%correlation + hm%energy%intnvxc
539 safe_allocate(stress_l_block(1:st%block_size))
543 do ik = st%d%kpt%start, st%d%kpt%end
546 ispin = st%d%get_spin_index(ik)
548 do ib = st%group%block_start, st%group%block_end
552 call hm%phase%copy_and_set_phase(gr, st%d%kpt, st%group%psib(ib, ik), psib)
558 do idir = 1, space%periodic_dim
559 call psib%copy_to(vtau_gpsib(idir))
561 call hm%ks_pot%zapply_vtau_psi(gr, hm%d, ispin, gpsib(idir), vtau_gpsib(idir))
565 do idir = 1, space%periodic_dim
566 do jdir = idir, space%periodic_dim
569 do ist = minst, maxst
570 stress_tau(idir, jdir) = stress_tau(idir, jdir) &
571 +
m_two * st%kweights(ik) * st%occ(ist, ik) * real(stress_l_block(ist - minst + 1), real64)
576 do idir = 1, space%dim
577 call gpsib(idir)%end()
579 do idir = 1, space%periodic_dim
580 call vtau_gpsib(idir)%end()
587 safe_deallocate_a(stress_l_block)
589 if (st%parallel_in_states .or. st%d%kpt%parallel)
then
597 if (hm%kpoints%use_symmetries)
then
601 stress_xc(:,:) = stress_xc(:,:) + stress_tau(:,:)
605 stress_xc(:,:) = stress_xc(:,:) / rcell_volume
630 real(real64),
intent(in) :: rcell_volume
631 type(
grid_t),
intent(in) :: gr
633 type(
ions_t),
intent(in) :: ions
634 real(real64),
contiguous,
intent(in) :: vxc(:,:)
635 real(real64),
intent(out) :: stress_xc_nlcc(3, 3)
637 integer :: idir, jdir, iat
638 real(real64),
allocatable :: vxc_tot(:), nlcc_grad_x(:,:,:)
643 assert(
allocated(st%rho_core))
647 safe_allocate(vxc_tot(1:gr%np))
648 safe_allocate(nlcc_grad_x(1:gr%np, 1:gr%der%dim, 1:gr%der%dim))
651 call lalg_copy(gr%np, vxc(:, 1), vxc_tot)
652 if (st%d%spin_channels > 1)
then
657 do iat = ions%atoms_dist%start, ions%atoms_dist%end
659 ions%pos(:,iat), gr, nlcc_grad_x)
661 do idir = 1, ions%space%periodic_dim
662 do jdir = idir, ions%space%periodic_dim
663 stress_xc_nlcc(idir, jdir) = stress_xc_nlcc(idir, jdir) &
664 -
dmf_dotp(gr, nlcc_grad_x(:, idir, jdir), vxc_tot)
668 safe_deallocate_a(nlcc_grad_x)
669 safe_deallocate_a(vxc_tot)
671 if (ions%atoms_dist%parallel)
then
677 stress_xc_nlcc(:,:) = stress_xc_nlcc(:,:) / rcell_volume
714 type(
grid_t),
target,
intent(in) :: gr
717 type(
ions_t),
intent(in) :: ions
718 real(real64),
intent(out) :: stress_ps_nl(3, 3)
719 real(real64),
intent(out) :: stress_ps_aug(3, 3)
721 integer :: ik, ist, idir, jdir
722 integer :: ib, minst, maxst
723 type(
wfs_elec_t) :: psib, rvnl_psib(3), gpsib(3)
724 complex(real64),
allocatable :: stress_tmp(:)
726 integer :: ncomp, icomp, imat, nprojs, ispin_pot
728 real(real64),
allocatable :: onsite_density_matrix(:, :, :, :), onsite_density_matrix_eps(:, :, :, :)
729 real(real64),
allocatable :: us_weight(:), us_weight_eps(:)
730 real(real64),
allocatable :: veff(:), grad_veff(:, :, :)
738 safe_allocate(stress_tmp(1:st%block_size))
746 uspp = hm%ep%requires_generalized_overlap
751 safe_allocate(onsite_density_matrix(1:hm%vnl%max_nprojs, 1:hm%vnl%max_nprojs, 1:hm%vnl%nprojector_matrices, 1:ncomp))
752 safe_allocate(onsite_density_matrix_eps(1:hm%vnl%max_nprojs, 1:hm%vnl%max_nprojs, 1:hm%vnl%nprojector_matrices, 1:ncomp))
753 onsite_density_matrix =
m_zero
754 onsite_density_matrix_eps =
m_zero
757 do ik = st%d%kpt%start, st%d%kpt%end
761 do ib = st%group%block_start, st%group%block_end
765 call hm%phase%copy_and_set_phase(gr, st%d%kpt, st%group%psib(ib, ik), psib)
773 do idir = 1, gr%der%dim
774 call psib%copy_to(rvnl_psib(idir))
777 call hm%vnl%zr_vn_local(gr, st%d, gr%der%boundaries%spiral, psib, rvnl_psib, st%eigenval(:, ik))
779 do idir = 1, ions%space%periodic_dim
780 do jdir = idir, ions%space%periodic_dim
783 do ist = minst, maxst
784 stress_ps_nl(idir, jdir) = stress_ps_nl(idir, jdir) &
785 +
m_two * st%kweights(ik) * st%occ(ist, ik) * real(stress_tmp(ist-minst+1), real64)
794 safe_allocate(us_weight(1:psib%nst))
795 safe_allocate(us_weight_eps(1:psib%nst))
797 us_weight(ist) = st%kweights(ik)*st%occ(psib%ist(ist), ik)
798 us_weight_eps(ist) = us_weight(ist)*st%eigenval(psib%ist(ist), ik)
801 weight2 = us_weight_eps, beta_density2 = onsite_density_matrix_eps)
802 safe_deallocate_a(us_weight)
803 safe_deallocate_a(us_weight_eps)
806 do idir = 1, gr%der%dim
807 call rvnl_psib(idir)%end()
808 call gpsib(idir)%end()
814 safe_deallocate_a(stress_tmp)
816 if (st%parallel_in_states .or. st%d%kpt%parallel)
then
828 if (hm%kpoints%use_symmetries)
then
836 evps = hm%energy%extern_non_local
838 do imat = 1, hm%vnl%nprojector_matrices
839 pmat => hm%vnl%projector_matrices(imat)
840 if (.not.
allocated(pmat%qmix)) cycle
843 evps = evps - sum(pmat%qmix(1:nprojs, 1:nprojs)*onsite_density_matrix_eps(1:nprojs, 1:nprojs, imat, icomp))
847 do idir = 1, ions%space%periodic_dim
848 stress_ps_nl(idir, idir) = stress_ps_nl(idir, idir) + evps
851 stress_ps_nl = stress_ps_nl/ions%latt%rcell_volume
857 safe_allocate(veff(1:gr%np_part))
858 safe_allocate(grad_veff(1:gr%np, 1:gr%der%dim, 1:ncomp))
859 do ispin_pot = 1, ncomp
860 veff(1:gr%np) = hm%hm_base%potential(1:gr%np, ispin_pot)
864 onsite_density_matrix, stress_ps_aug)
865 safe_deallocate_a(veff)
866 safe_deallocate_a(grad_veff)
869 stress_ps_aug =
m_half*(stress_ps_aug + transpose(stress_ps_aug))
872 if (hm%kpoints%use_symmetries)
then
876 stress_ps_aug = stress_ps_aug/ions%latt%rcell_volume
878 safe_deallocate_a(onsite_density_matrix)
879 safe_deallocate_a(onsite_density_matrix_eps)
909 type(
grid_t),
target,
intent(in) :: gr
911 type(
ions_t),
intent(in) :: ions
912 real(real64),
contiguous,
intent(inout) :: rho_total(:)
913 real(real64),
contiguous,
intent(in) :: grad_vh(:,:)
914 real(real64),
intent(out) :: stress_ps_local(3, 3)
917 real(real64) :: stress_SR(3, 3), stress_LR(3, 3)
918 real(real64) :: energy_ps_SR, charge, zi
919 real(real64),
allocatable :: vloc(:), rvloc(:,:), rho_local_lr(:), rho_lr(:)
920 real(real64),
allocatable :: grad_rho(:,:), rho_lr_x(:,:), vlr(:), grad_vlr(:,:)
921 integer :: idir, jdir, iatom
922 type(
ps_t),
pointer :: spec_ps
933 safe_allocate(vloc(1:gr%np))
935 safe_allocate(rvloc(1:gr%np, 1:gr%der%dim))
937 do iatom = hm%ep%atoms_dist_plane%start, hm%ep%atoms_dist_plane%end
940 if (hm%ep%atoms_dist_plane%parallel)
then
943 safe_deallocate_a(vloc)
945 safe_allocate(grad_rho(1:gr%np,1:gr%der%dim))
948 if (hm%ep%requires_generalized_overlap)
then
951 energy_ps_sr =
dmf_dotp(gr, rho_total, hm%ep%vpsl)
953 energy_ps_sr = hm%energy%extern_local
955 do idir = 1, ions%space%periodic_dim
956 do jdir = idir, ions%space%periodic_dim
957 stress_sr(idir, jdir) = stress_sr(idir, jdir) &
958 +
dmf_dotp(gr, rvloc(:, jdir), grad_rho(:, idir))
960 stress_sr(idir,idir) = stress_sr(idir,idir) + energy_ps_sr
965 stress_sr = stress_sr/ions%latt%rcell_volume
967 safe_deallocate_a(rvloc)
968 safe_deallocate_a(grad_rho)
976 safe_allocate(rho_lr(1:gr%np_part))
977 safe_allocate(rho_lr_x(1:gr%np, 1:gr%der%dim))
980 safe_allocate(rho_local_lr(1:gr%np))
981 do iatom = ions%atoms_dist%start, ions%atoms_dist%end
982 assert(ions%atom(iatom)%species%is_ps())
984 ions%pos(:, iatom), gr, rho_local_lr, nlr_x=rho_lr_x)
988 safe_deallocate_a(rho_local_lr)
990 if (ions%atoms_dist%parallel)
then
995 do idir = 1, ions%space%periodic_dim
996 do jdir = idir, ions%space%periodic_dim
997 stress_lr(idir, jdir) = stress_lr(idir, jdir) +
dmf_dotp(gr, rho_lr_x(:,jdir), grad_vh(:, idir))
1000 safe_deallocate_a(rho_lr_x)
1002 safe_allocate(vlr(1:gr%np_part))
1004 safe_deallocate_a(rho_lr)
1006 safe_allocate(grad_vlr(1:gr%np, 1:gr%der%dim))
1008 safe_deallocate_a(vlr)
1010 do idir = 1, ions%space%periodic_dim
1011 do jdir = idir, ions%space%periodic_dim
1012 stress_lr(idir, jdir) = stress_lr(idir, jdir) -
dmf_dotp(gr, grad_vh(:,idir), grad_vlr(:, jdir))/
m_two/
m_pi
1018 safe_deallocate_a(grad_vlr)
1022 if (ions%space%periodic_dim == 3)
then
1024 do iatom = 1, ions%natoms
1025 charge = charge + ions%atom(iatom)%species%get_zval()
1028 do iatom = 1, ions%natoms
1029 select type(spec => ions%atom(iatom)%species)
1031 zi = spec%get_zval()
1034 do idir = 1, ions%space%periodic_dim
1035 stress_lr(idir, idir) = stress_lr(idir, idir) &
1036 +
m_two*
m_pi*spec_ps%sigma_erf**2*charge*zi /ions%latt%rcell_volume
1042 stress_lr = stress_lr/ions%latt%rcell_volume
1044 stress_ps_local = stress_sr + stress_lr
1053 class(
mesh_t),
intent(in) :: mesh
1054 type(
ions_t),
intent(in) :: ions
1055 integer,
intent(in) :: iatom
1056 real(real64),
contiguous,
intent(inout) :: vpsl(:)
1057 real(real64),
contiguous,
intent(inout) :: rvpsl(:,:)
1060 integer :: ip, idir, pd
1061 real(real64) :: radius
1062 real(real64),
allocatable :: vl_sm(:, :)
1064 type(
ps_t),
pointer :: ps
1068 if (.not. ions%atom(iatom)%species%is_ps())
then
1075 select type(spec=>ions%atom(iatom)%species)
1080 radius = ps%vl%x_threshold*1.05_real64
1082 call submesh_init(sphere, ions%space, mesh, ions%latt, ions%pos(:, iatom), &
1087 pd = ions%space%periodic_dim
1088 safe_allocate(vl_sm(1:sphere%np, 1:pd + 1))
1090 [(0, idir = 0, pd)], [(radius, idir = 0, pd)], vl_sm, cart_dir = [(idir, idir = 0, pd)])
1094 do ip = 1, sphere%np
1095 vpsl(sphere%map(ip)) = vpsl(sphere%map(ip)) + vl_sm(ip, 1)
1096 rvpsl(sphere%map(ip), 1:pd) = rvpsl(sphere%map(ip), 1:pd) + vl_sm(ip, 2:pd + 1)
1099 safe_deallocate_a(vl_sm)
1126 subroutine stress_from_hubbard(namespace, gr, st, hm, space, rcell_volume, stress_hubbard)
1128 type(
grid_t),
target,
intent(in) :: gr
1131 type(
space_t),
intent(in) :: space
1132 real(real64),
intent(in) :: rcell_volume
1133 real(real64),
intent(out) :: stress_hubbard(3, 3)
1135 integer :: ik, ist, idir, jdir
1136 integer :: ib, minst, maxst
1138 real(real64) :: hub_diag
1139 type(
wfs_elec_t) :: psib, rvu_psib(3), gpsib(3)
1140 type(
wfs_elec_t) :: spsib, chib, gspsib(3), gchib(3), rvnlq_psib(3), rvnlq_chib(3)
1141 complex(real64),
allocatable :: stress_tmp(:), stress_tmp2(:)
1163 uspp = hm%ep%requires_generalized_overlap
1165 safe_allocate(stress_tmp(1:st%block_size))
1166 safe_allocate(stress_tmp2(1:st%block_size))
1171 do ik = st%d%kpt%start, st%d%kpt%end
1175 do ib = st%group%block_start, st%group%block_end
1179 call hm%phase%copy_and_set_phase(gr, st%d%kpt, st%group%psib(ib, ik), psib)
1185 do idir = 1, gr%der%dim
1186 call psib%copy_to(rvu_psib(idir))
1192 call psib%copy_to(spsib)
1194 call hm%phase%set_boundaries(gr, gr%der%boundaries, spsib)
1198 call zlda_u_rvu(hm%lda_u, gr, space, hm%d, namespace, spsib, rvu_psib)
1201 call psib%copy_to(chib)
1204 call hm%phase%set_boundaries(gr, gr%der%boundaries, chib)
1208 do idir = 1, gr%der%dim
1209 call psib%copy_to(rvnlq_psib(idir))
1211 call psib%copy_to(rvnlq_chib(idir))
1214 call hm%vnl%zr_vn_local(gr, st%d, gr%der%boundaries%spiral, psib, rvnlq_psib, only_qmix=.
true.)
1215 call hm%vnl%zr_vn_local(gr, st%d, gr%der%boundaries%spiral, chib, rvnlq_chib, only_qmix=.
true.)
1217 call zlda_u_rvu(hm%lda_u, gr, space, hm%d, namespace, psib, rvu_psib)
1220 do idir = 1, gr%der%dim
1221 do jdir = idir, gr%der%dim
1228 do ist = minst, maxst
1229 stress_hubbard(idir, jdir) = stress_hubbard(idir, jdir) &
1230 +
m_two * st%kweights(ik) * st%occ(ist, ik) * real(stress_tmp(ist-minst+1), real64)
1237 do ist = minst, maxst
1238 stress_hubbard(idir, jdir) = stress_hubbard(idir, jdir) &
1239 +
m_two * st%kweights(ik) * st%occ(ist, ik) &
1240 * real(stress_tmp(ist-minst+1) + stress_tmp2(ist-minst+1), real64)
1251 do ist = minst, maxst
1252 hub_diag = hub_diag +
m_two * st%kweights(ik) * st%occ(ist, ik) &
1253 * real(stress_tmp(ist-minst+1) - stress_tmp2(ist-minst+1), real64)
1257 do idir = 1, gr%der%dim
1258 call rvu_psib(idir)%end()
1259 call gpsib(idir)%end()
1262 do idir = 1, gr%der%dim
1263 call gspsib(idir)%end()
1264 call gchib(idir)%end()
1265 call rvnlq_psib(idir)%end()
1266 call rvnlq_chib(idir)%end()
1275 safe_deallocate_a(stress_tmp)
1276 safe_deallocate_a(stress_tmp2)
1278 if (st%parallel_in_states .or. st%d%kpt%parallel)
then
1287 if (hm%kpoints%use_symmetries)
then
1293 stress_hubbard(idir, idir) = stress_hubbard(idir, idir) + hm%energy%int_dft_u + hub_diag
1296 stress_hubbard = stress_hubbard/rcell_volume
1304 subroutine output_stress(iunit, space_dim, stress_tensors, mpi_grp, all_terms)
1305 integer,
intent(in) :: iunit
1306 integer,
intent(in) :: space_dim
1307 type(
stress_t),
intent(in) :: stress_tensors
1309 logical,
optional,
intent(in) :: all_terms
1311 logical :: write_all_terms
1312 character(len=16) :: stress_unit
1319 if (mpi_grp%is_root())
then
1321 if (write_all_terms)
then
1322 write(iunit,
'(3a)')
'Kinetic stress tensor [', trim(stress_unit),
'] ='
1324 if (space_dim == 3)
then
1325 write(iunit,
'(a, es15.6, 3a)')
'Kinetic pressure sumrule violation: ', &
1332 write(iunit,
'(3a)')
'Hartree stress tensor [', trim(stress_unit),
'] ='
1334 if (space_dim == 3)
then
1335 write(iunit,
'(a, es15.6, 3a)')
'Hartree pressure sumrule violation: ', &
1341 write(iunit,
'(3a)')
'XC stress tensor [', trim(stress_unit),
'] ='
1344 write(iunit,
'(3a)')
'XC NLCC stress tensor [', trim(stress_unit),
'] ='
1347 write(iunit,
'(3a)')
'Local pseudo. stress tensor [', trim(stress_unit),
'] ='
1350 write(iunit,
'(3a)')
'Nonlocal pseudo. stress tensor [', trim(stress_unit),
'] ='
1355 if (any(abs(stress_tensors%ps_aug) >
m_epsilon))
then
1356 write(iunit,
'(3a)')
'Augmentation stress tensor [', trim(stress_unit),
'] ='
1360 write(iunit,
'(3a)')
'Ion-ion stress tensor [', trim(stress_unit),
'] ='
1363 write(iunit,
'(3a)')
'vdW stress tensor [', trim(stress_unit),
'] ='
1366 write(iunit,
'(3a)')
'Hubbard stress tensor [', trim(stress_unit),
'] ='
1370 write(iunit,
'(3a)')
'Total stress tensor [', trim(stress_unit),
'] ='
1378 integer,
intent(in) :: iunit
1379 integer,
intent(in) :: space_dim
1380 real(real64),
intent(in) :: total_stress_tensor(3,3)
1383 real(real64) :: pressure
1384 character(len=16) :: stress_unit
1390 do idim = 1, space_dim
1391 pressure = pressure - total_stress_tensor(idim, idim) / real(space_dim, real64)
1394 write(iunit,
'(3a,es16.8)', advance=
"no")
'Pressure [', trim(stress_unit),
'] = ', &
1396 if (space_dim == 3)
then
1405 integer,
intent(in) :: ounit
1406 integer,
intent(in) :: space_dim
1407 real(real64),
intent(in) :: tensor(3,3)
1409 real(real64) :: tensor_with_unit(3,3)
1410 integer :: idim, jdim
1414 write(ounit,
'(a9,2x)', advance=
"no")
"T_{ij}"
1415 do jdim = 1, space_dim
1416 write(ounit,
'(i18)', advance=
"no") jdim
1419 do idim = 1, space_dim
1420 write(ounit,
'(i9,2x)', advance=
"no") idim
1421 do jdim = 1, space_dim
1422 write(ounit,
'(es18.9)', advance=
"no") tensor_with_unit(idim, jdim)
constant times a vector plus a vector
Copies a vector x, to a vector y.
scales a vector by a constant
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
Module implementing boundary conditions in Octopus.
This module implements a calculator for the density and defines related functions.
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
subroutine, public dderivatives_grad(der, ff, op_ff, ghost_update, set_bc, to_cartesian)
apply the gradient to a mesh function
subroutine, public zderivatives_batch_grad(der, ffb, opffb, ghost_update, set_bc, to_cartesian, factor)
apply the gradient to a batch of mesh functions
The Ono-Hirose double-grid technique [T. Ono and K. Hirose, Phys. Rev. Lett. 82, 5016 (1999); Phys....
real(real64) function, public double_grid_margin(this, mesh)
Submesh radius enlargement needed to contain the effective support of a transformed function: the ten...
subroutine, public double_grid_transform(this, sm, nf, spl, ll, mm, rcut, feff, cart_dir, cache)
Evaluate a batch of localized functions f_jf(x) = spl_jf(r) * Y_{ll,mm}(x) (or a purely radial spl_jf...
integer, parameter, public spinors
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,...
integer, parameter, public scalar_relativistic_zora
integer, parameter, public fully_relativistic_zora
real(real64), parameter, public m_two
real(real64), parameter, public m_zero
real(real64), parameter, public m_four
real(real64), parameter, public m_pi
some mathematical constants
integer, parameter, public independent_particles
Theory level.
integer, parameter, public generalized_kohn_sham_dft
integer, parameter, public kohn_sham_dft
real(real64), parameter, public m_epsilon
real(real64), parameter, public m_half
real(real64), parameter, public m_one
This module implements the underlying real-space grid.
This module defines classes and functions for interaction partners.
subroutine, public ion_interaction_stress(this, space, latt, atom, natoms, pos, stress_ii)
Computes the contribution to the stress tensor the ion-ion energy.
A module to handle KS potential, without the external potential.
subroutine, public zlda_u_apply_overlap(aug_overlap, mesh, std, psib, spsib)
Apply the ultrasoft/PAW generalized overlap S = 1 + sum_ij |beta_i> q_ij <beta_j| to an (already phas...
integer, parameter, public dft_u_none
subroutine, public zlda_u_add_plus_u_ket(this, d, mesh, psib, kpsib, aug_overlap)
Add the bare +U ket chi = sum_m |phi_m> sum_mp V_mmp <phi_mp|psi> to kpsib.
subroutine, public zlda_u_rvu(this, mesh, space, d, namespace, psib, gpsib)
This routine computes .
This modules implements the routines for doing constrain DFT for noncollinear magnetism.
integer, parameter, public constrain_none
This module is intended to contain "only mathematical" functions and procedures.
This module defines functions over batches of mesh functions.
subroutine, public zmesh_batch_dotp_vector(mesh, aa, bb, dot, reduce, cproduct)
A simple switch between specialized kernels and generic kernels.
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
subroutine, public messages_not_implemented(feature, 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 nonlocal_pseudopotential_stress_uspp(this, mesh, epot, periodic_dim, grad_pot, aug_weight, stress_aug)
Ultrasoft augmentation contribution to the stress tensor.
subroutine, public znonlocal_pseudopotential_density_matrix(this, mesh, std, spiral_bnd, psib, weight, beta_density, weight2, beta_density2, beta_current)
Accumulate occupation-weighted beta-projector density matrices for USPP density.
subroutine, public dpoisson_solve(this, namespace, pot, rho, all_nodes, kernel, reset)
Calculates the Poisson equation. Given the density returns the corresponding potential.
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
subroutine, public species_get_long_range_density(species, namespace, space, latt, pos, mesh, rho, sphere_inout, nlr_x)
subroutine, public species_get_nlcc_grad(species, space, latt, pos, mesh, rho_core_grad_x)
Returns the (r-R_I)-weighted analytic gradient of the NLCC core density.
This module handles spin dimensions of the states and the k-point distribution.
integer pure function, public states_elec_block_max(st, ib)
return index of last state in block ib
integer pure function, public states_elec_block_min(st, ib)
return index of first state in block ib
This module implements the calculation of the stress tensor.
subroutine stress_from_hartree(gr, space, volume, grad_vh, ehartree, stress_Hartree)
Computes the contribution to the stress tensor from the Hartree energy.
subroutine, public output_stress(iunit, space_dim, stress_tensors, mpi_grp, all_terms)
subroutine stress_from_kinetic(gr, space, hm, st, symm, rcell_volume, stress_kin)
Computes the contribution to the stress tensor from the kinetic energy.
subroutine stress_from_pseudo_local(gr, hm, ions, rho_total, grad_vh, stress_ps_local)
Computes the contribution from the local part of the pseudopotential.
subroutine print_stress_tensor(ounit, space_dim, tensor)
subroutine, public output_pressure(iunit, space_dim, total_stress_tensor)
subroutine, public stress_calculate(namespace, gr, hm, st, ions, ks, ext_partners)
This computes the total stress on the lattice.
subroutine stress_from_hubbard(namespace, gr, st, hm, space, rcell_volume, stress_hubbard)
Computes the contribution to the stress tensor from the Hubbard energy.
subroutine stress_from_xc(gr, hm, st, space, rcell_volume, stress_xc)
Computes the contribution to the stress tensor from the xc energy.
subroutine epot_local_pseudopotential_sr(mesh, ions, iatom, vpsl, rvpsl, dgrid)
subroutine stress_from_pseudo_nonloc(gr, st, hm, ions, stress_ps_nl, stress_ps_aug)
Computes the contribution to the stress tensor from the nonlocal part of the pseudopotentials.
subroutine stress_from_xc_nlcc(rcell_volume, gr, st, ions, vxc, stress_xc_nlcc)
Computes the NLCC contribution to the stress tensor from the xc energy.
subroutine, public submesh_end(this)
subroutine, public submesh_init(this, space, mesh, latt, center, rc)
subroutine, public dsymmetrize_tensor_cart(symm, tensor, use_non_symmorphic)
Symmetric a rank-2 tensor defined in Cartesian space.
type(type_t), parameter, public type_cmplx
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
character(len=20) pure function, public units_abbrev(this)
This module defines the unit system, used for input and output.
type(unit_system_t), public units_out
type(unit_t), public unit_gpa
For output pressure in GPa.
logical pure function, public family_is_mgga_with_exc(xcs)
Is the xc function part of the mGGA family with an energy functional.
logical pure function, public xc_is_energy_functional(xcs)
Is one of the x or c functional is not an energy functional.
pure logical function, public in_family(family, xc_families)
A module that takes care of xc contribution from vdW interactions.
integer(int64), dimension(5), parameter, public d3_lib_options
VDWCORRECTION options that correspond to the DFT-D3 library.
Description of the grid, containing information on derivatives, stencil, and symmetries.
Describes mesh distribution to nodes.
This is defined even when running serial.
A set of projectors defined on a submesh.
A type storing the information and data about a pseudopotential.
The states_elec_t class contains all electronic wave functions.
A submesh is a type of mesh, used for the projectors in the pseudopotentials It contains points on a ...
batches of electronic states