Octopus
stress.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2016 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!! Copyright (C) 2023 N. Tancogne-Dejean
3!!
4!! This program is free software; you can redistribute it and/or modify
5!! it under the terms of the GNU General Public License as published by
6!! the Free Software Foundation; either version 2, or (at your option)
7!! any later version.
8!!
9!! This program is distributed in the hope that it will be useful,
10!! but WITHOUT ANY WARRANTY; without even the implied warranty of
11!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12!! GNU General Public License for more details.
13!!
14!! You should have received a copy of the GNU General Public License
15!! along with this program; if not, write to the Free Software
16!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17!! 02110-1301, USA.
18!!
19
20#include "global.h"
21
22! ---------------------------------------------------------
25module stress_oct_m
28 use comm_oct_m
29 use debug_oct_m
33 use energy_oct_m
35 use epot_oct_m
36 use global_oct_m
37 use grid_oct_m
39 use io_oct_m
41 use ions_oct_m
43 use, intrinsic :: iso_fortran_env
47 use lda_u_oct_m
50 use math_oct_m
51 use mesh_oct_m
55 use mpi_oct_m
60 use ps_oct_m
62 use space_oct_m
72 use types_oct_m
73 use unit_oct_m
75 use v_ks_oct_m
77 use xc_oct_m
78 use xc_f03_lib_m
80 implicit none
81
82 private
83 public :: &
87
88contains
89
90 ! ---------------------------------------------------------
92 subroutine stress_calculate(namespace, gr, hm, st, ions, ks, ext_partners)
93 type(namespace_t), intent(in) :: namespace
94 type(grid_t), intent(inout) :: gr
95 type(hamiltonian_elec_t), intent(inout) :: hm
96 type(states_elec_t), target, intent(inout) :: st
97 type(ions_t), intent(inout) :: ions
98 type(v_ks_t), intent(in) :: ks
99 type(partner_list_t), intent(in) :: ext_partners
100
101 real(real64), allocatable :: rho_total(:)
102 real(real64) :: stress(3,3) ! stress tensor in Cartesian coordinate
103 real(real64) :: stress_kin(3,3), stress_Hartree(3,3), stress_xc(3,3), stress_xc_nlcc(3,3)
104 real(real64) :: stress_ps(3,3), stress_ps_nl(3,3), stress_ps_local(3,3), stress_ii(3,3)
105 real(real64) :: stress_hubbard(3,3)
106 integer :: ip
107 real(real64), allocatable :: vh(:)
108 real(real64), allocatable :: grad_vh(:,:)
109 real(real64) :: ehartree
110 real(real64), contiguous, pointer :: rho(:)
111
112 call profiling_in("STRESS_CALCULATE")
113 push_sub(stress_calculate)
114
115 if (st%wfs_type /= type_cmplx) then
116 write(message(1),'(a)') 'The stress tensors for real wavefunctions has not been implemented!'
117
118 if (hm%kpoints%full%npoints == 1) then
119 write(message(2),'(a)') 'For testing this feature, you can add ForceComplex=yes to the input file'
120 call messages_fatal(2, namespace=namespace)
121 end if
122
123 call messages_fatal(1, namespace=namespace)
124 end if
125
126 if (ions%space%periodic_dim == 1) then
127 call messages_not_implemented("Stress tensor for 1D periodic systems", namespace=namespace)
128 end if
129
130 if (.not. ions%space%is_periodic()) then
131 write(message(1),'(a)') 'The stress tensor cannot be computed for isolated systems'
132 call messages_fatal(1, namespace=namespace)
133 end if
134
135 if (ks%vdw%vdw_correction /= option__vdwcorrection__none .and. .not. any(ks%vdw%vdw_correction == d3_lib_options)) then
136 write(message(1),'(a)') 'The stress tensor is currently only implemented with DFT-D3 vdW correction'
137 call messages_fatal(1, namespace=namespace)
138 end if
139
140 if (hm%pcm%run_pcm) then
141 call messages_not_implemented('Stress tensor with PCM', namespace=namespace)
142 end if
143
144 if (allocated(hm%v_static)) then
145 call messages_not_implemented('Stress tensor with static electric fields', namespace=namespace)
146 end if
147
148 if (ks%v_ks_photons%active()) then
149 call messages_not_implemented('Stress tensor with photon modes', namespace=namespace)
150 end if
151
152 ! Projector matrices are absent both for relativistic KB projectors and when there is no
153 ! nonlocal potential at all (local-only pseudopotentials, user-defined or all-electron species)
154 if (.not. hm%vnl%apply_projector_matrices) then
155 if (hm%vnl%has_non_local_potential) then
156 call messages_not_implemented('Stress tensor with relativistic Kleinman-Bylander pseudopotential', namespace=namespace)
157 else
158 call messages_not_implemented('Stress tensor without nonlocal projectors (local-only pseudopotentials, '// &
159 'user-defined or all-electron species)', namespace=namespace)
160 end if
161 end if
162
163 if (hm%ep%reltype == scalar_relativistic_zora .or. hm%ep%reltype == fully_relativistic_zora) then
164 call messages_not_implemented('Stress tensor with ZORA', namespace=namespace)
165 end if
166
167 ! Checks for the xc part of KS-DFT and GKS-DFT
168 if (ks%theory_level == kohn_sham_dft .or. ks%theory_level == generalized_kohn_sham_dft) then
169 if (.not. xc_is_energy_functional(hm%xc)) then
170 call messages_not_implemented("Stress tensor with xc functionals that are not energy functionals")
171 end if
172
173 if ( .not. in_family(hm%xc%family, [xc_family_lda, xc_family_gga, xc_family_mgga])) then
174 write(message(1),'(a)') 'The stress tensor computation is currently only possible at the Kohn-Sham DFT level'
175 write(message(2),'(a)') 'with LDA, GGA and mGGA functionals or for independent particles.'
176 call messages_fatal(2, namespace=namespace)
177 end if
178
179 if (in_family(hm%xc%family, [xc_family_gga, xc_family_mgga]) .and. st%d%ispin == spinors) then
180 call messages_not_implemented("Stress tensor for GGAs and mGGAs with spinors", namespace=namespace)
181 end if
182
183 if (family_is_mgga_with_exc(hm%xc)) then
184 ! The diagonal tau term is taken from hm%energy%intnvxc, which only contains the
185 ! mGGA operator expectation value at the generalized Kohn-Sham level.
186 if (ks%theory_level /= generalized_kohn_sham_dft) then
187 call messages_not_implemented("Stress tensor for mGGAs outside of the generalized Kohn-Sham scheme", &
188 namespace=namespace)
189 end if
190
191 ! The strain derivative of the gauge-invariant kinetic energy density has an extra
192 ! current-dependent term, which is not implemented.
193 if (hm%xc%use_gi_ked) then
194 call messages_not_implemented("Stress tensor for mGGAs with XCUseGaugeIndependentKED = yes", &
195 namespace=namespace)
196 end if
197 end if
198 end if
199
200 if (hm%magnetic_constrain%level /= constrain_none) then
201 call messages_not_implemented("Stress tensor with MagneticConstrain /= constrain_none")
202 end if
203
204 stress(:,:) = m_zero
205
206 safe_allocate(rho_total(1:gr%np_part))
207 do ip = 1, gr%np
208 rho_total(ip) = sum(st%rho(ip, 1:st%d%spin_channels))
209 end do
210
211 ! As we rely on some of the full energy components, we need to recompute it first
212 ! TODO: We should restrict the components of the energy needed to be computed
213 call energy_calc_total(namespace, ions%space, hm, gr, st, ext_partners, iunit = -1, full = .true.)
214
215 ! In order to get the electrostatic part (Hartree and local pseudopotential part),
216 ! we need to get the Hartree potential and its gradient
217 safe_allocate(vh(1:gr%np_part))
218 safe_allocate(grad_vh(1:gr%np, 1:gr%der%dim))
219 if (ks%theory_level /= independent_particles) then
220 call lalg_copy(gr%np, hm%ks_pot%vhartree, vh)
221 else
222 if (hm%d%spin_channels > 1) then
223 safe_allocate(rho(1:gr%np_part))
224 call lalg_copy(gr%np, st%rho(:,1), rho)
225 call lalg_axpy(gr%np, m_one, st%rho(:,2), rho)
226 else
227 rho => st%rho(:,1)
228 end if
229 ! In the case of independent particles, we use the electron density without NLCC
230 call dpoisson_solve(hm%psolver, ions%namespace, vh, rho, all_nodes = .true.)
231 if (hm%d%spin_channels > 1) then
232 safe_deallocate_p(rho)
233 else
234 nullify(rho)
235 end if
236 end if
237 ehartree = hm%energy%hartree
238 ! We also compute the gradient here
239 call dderivatives_grad(gr%der, vh, grad_vh)
240
241 ! We now compute the various contributions to the stress tensor
242
243 ! Stress from kinetic energy of electrons
244 call stress_from_kinetic(gr, ions%space, hm, st, gr%symm, ions%latt%rcell_volume, stress_kin)
245 stress = stress + stress_kin
246
247 if (ks%theory_level == independent_particles) then
248 stress_hartree = m_zero
249 stress_xc = m_zero
250 stress_xc_nlcc = m_zero
251 else
252 call stress_from_hartree(gr, ions%space, ions%latt%rcell_volume, grad_vh, ehartree, stress_hartree)
253 stress = stress + stress_hartree
254
255 call stress_from_xc(gr, hm, st, ions%space, ions%latt%rcell_volume, stress_xc)
256
257 ! Nonlinear core correction contribution
258 if (allocated(st%rho_core)) then
259 call stress_from_xc_nlcc(ions%latt%rcell_volume, gr, st, ions, hm%ks_pot%vxc, stress_xc_nlcc)
260 else
261 stress_xc_nlcc = m_zero
262 end if
263 ! Adds the beyond LDA contribution to the stress tensor
264 stress_xc = stress_xc + ks%stress_xc / ions%latt%rcell_volume
265 stress = stress + stress_xc + stress_xc_nlcc
266 end if
267
268 call stress_from_pseudo_local(gr, hm, ions, rho_total, grad_vh, stress_ps_local)
269 stress_ps = stress_ps_local
270 stress = stress + stress_ps_local
271
272 safe_deallocate_a(vh)
273 safe_deallocate_a(grad_vh)
274
275 call stress_from_pseudo_nonloc(gr, st, hm, ions, stress_ps_nl)
276 stress_ps = stress_ps + stress_ps_nl
277 stress = stress + stress_ps_nl
278
279 call stress_from_hubbard(namespace, gr, st, hm, ions%space, ions%latt%rcell_volume, stress_hubbard)
280 stress = stress + stress_hubbard
281
282 call ion_interaction_stress(ions%ion_interaction, ions%space, ions%latt, ions%atom, ions%natoms, ions%pos, stress_ii)
283 stress = stress + stress_ii
284 ! Stress from kinetic energy of ion
285 ! Stress from ion-field interaction
286
287 ! Sign changed to fit conventional definition
288 stress = -stress
289 st%stress_tensors%kinetic = -stress_kin
290 st%stress_tensors%Hartree = -stress_hartree
291 st%stress_tensors%xc = -stress_xc
292 st%stress_tensors%xc_nlcc = -stress_xc_nlcc
293 st%stress_tensors%ps_local = -stress_ps_local
294 st%stress_tensors%ps_nl = -stress_ps_nl
295 st%stress_tensors%hubbard = -stress_hubbard
296 st%stress_tensors%ion_ion = -stress_ii
297
298 ! Stress contribution from vdW D3
299 if (ks%vdw%vdw_correction /= option__vdwcorrection__none) then
300 st%stress_tensors%vdw = hm%ep%vdw_stress
301 else
302 st%stress_tensors%vdw = m_zero
303 end if
304 stress = stress + st%stress_tensors%vdw
305
306 ! Symmetrize the stress tensor if we use k-point symmetries
307 if (hm%kpoints%use_symmetries) then
308 call dsymmetrize_tensor_cart(gr%symm, stress, use_non_symmorphic=.true.)
309 end if
310 ! We guarantee that the matrix is truly symmetric. There could be small numerical asymmetries after symmetrization
311 call symmetrize_matrix(ions%space%periodic_dim, stress)
312
313 st%stress_tensors%total = stress
314
315 ! Some sumrule for validation
316 ! Sumrule is -3P_{kin}\Omega = 2 E_{kin}
317 st%stress_tensors%kinetic_sumrule = m_zero
318 ! Sumrule is -3P_{Hartree}\Omega = E_{Hartree}
319 st%stress_tensors%Hartree_sumrule = m_zero
320 if(ions%space%periodic_dim == 3) then
321 st%stress_tensors%kinetic_sumrule = (stress_kin(1,1) + stress_kin(2,2) + stress_kin(3,3))*ions%latt%rcell_volume
322 st%stress_tensors%kinetic_sumrule = st%stress_tensors%kinetic_sumrule - m_two * hm%energy%kinetic
323
324 st%stress_tensors%hartree_sumrule = (stress_hartree(1,1) + stress_hartree(2,2) + stress_hartree(3,3))*ions%latt%rcell_volume
325 st%stress_tensors%hartree_sumrule = st%stress_tensors%hartree_sumrule - hm%energy%hartree
326 end if
327
328 safe_deallocate_a(rho_total)
329
330 pop_sub(stress_calculate)
331 call profiling_out("STRESS_CALCULATE")
332 end subroutine stress_calculate
333
334 ! -------------------------------------------------------
349 subroutine stress_from_kinetic(gr, space, hm, st, symm, rcell_volume, stress_kin)
350 type(grid_t), intent(in) :: gr
351 class(space_t), intent(in) :: space
352 type(hamiltonian_elec_t), intent(in) :: hm
353 type(states_elec_t), intent(in) :: st
354 type(symmetries_t), intent(in) :: symm
355 real(real64), intent(in) :: rcell_volume
356 real(real64), intent(out) :: stress_kin(3, 3)
357
358 integer :: ik, ist, idir, jdir, ib, minst, maxst
359 complex(real64), allocatable :: stress_l_block(:)
360 type(wfs_elec_t) :: psib, gpsib(space%dim)
361
362 call profiling_in("STRESS_FROM_KINETIC")
363 push_sub(stress_from_kinetic)
364
365 stress_kin(:,:) = m_zero
366
367 safe_allocate(stress_l_block(1:st%block_size))
368
369 do ik = st%d%kpt%start, st%d%kpt%end
370 if (st%kweights(ik) <= m_epsilon) cycle
371
372 do ib = st%group%block_start, st%group%block_end
373 minst = states_elec_block_min(st, ib)
374 maxst = states_elec_block_max(st, ib)
375
376 call hm%phase%copy_and_set_phase(gr, st%d%kpt, st%group%psib(ib, ik), psib)
377
378 ! calculate the gradient
379 call zderivatives_batch_grad(gr%der, psib, gpsib, set_bc=.false.)
380
381 ! Accumulate the result
382 do idir = 1, space%periodic_dim
383 do jdir = idir, space%periodic_dim
384 call zmesh_batch_dotp_vector(gr, gpsib(idir), gpsib(jdir), stress_l_block)
385
386 do ist = minst, maxst
387 stress_kin(idir,jdir) = stress_kin(idir,jdir) &
388 + st%kweights(ik) * st%occ(ist, ik) &
389 * real(stress_l_block(ist - minst + 1), real64)
390 end do
391 end do
392 end do
393
394 do idir = 1, space%dim
395 call gpsib(idir)%end()
396 end do
397 call psib%end()
398
399 end do
400 end do
401
402 if (st%parallel_in_states .or. st%d%kpt%parallel) then
403 call comm_allreduce(st%st_kpt_mpi_grp, stress_kin)
404 end if
405
406
407 ! Symmetrize the kinetic stress tensor
408 call upper_triangular_to_hermitian(space%periodic_dim, stress_kin)
409
410 ! Symmetrize the stress tensor if we use k-point symmetries
411 if (hm%kpoints%use_symmetries) then
412 call dsymmetrize_tensor_cart(symm, stress_kin, use_non_symmorphic=.true.)
413 end if
414
415 stress_kin = stress_kin / rcell_volume
416
417 call profiling_out("STRESS_FROM_KINETIC")
418 pop_sub(stress_from_kinetic)
419 end subroutine stress_from_kinetic
420
421 ! -------------------------------------------------------
438 subroutine stress_from_hartree(gr, space, volume, grad_vh, ehartree, stress_Hartree)
439 type(grid_t), intent(in) :: gr
440 class(space_t), intent(in) :: space
441 real(real64), intent(in) :: volume
442 real(real64), contiguous, intent(in) :: grad_vh(:,:)
443 real(real64), intent(in) :: ehartree
444 real(real64), intent(out) :: stress_Hartree(3, 3)
445
446 integer :: idir, jdir
447
448 call profiling_in("STRESS_FROM_HARTREE")
449 push_sub(stress_from_hartree)
450
451 stress_hartree(:,:) = m_zero
452
453 do idir = 1, space%periodic_dim
454 do jdir = idir, space%periodic_dim
455 stress_hartree(idir, jdir) = -dmf_dotp(gr, grad_vh(:,idir), grad_vh(:, jdir))/m_four/m_pi
456 end do
457 stress_hartree(idir, idir) = stress_hartree(idir, idir) + ehartree
458 end do
459
460 call upper_triangular_to_hermitian(space%periodic_dim, stress_hartree)
461
462 stress_hartree = stress_hartree/volume
463
464 call profiling_out("STRESS_FROM_HARTREE")
465 pop_sub(stress_from_hartree)
466 end subroutine stress_from_hartree
467
468
469 ! -------------------------------------------------------
494 !
495 ! Note: We assume hm%energy%echange, correlation, and intnvxc
496 ! have already been calculated somewhere else.
497 subroutine stress_from_xc(gr, hm, st, space, rcell_volume, stress_xc)
498 type(grid_t), intent(in) :: gr
499 type(hamiltonian_elec_t), intent(in) :: hm
500 type(states_elec_t), intent(in) :: st
501 class(space_t), intent(in) :: space
502 real(real64), intent(in) :: rcell_volume
503 real(real64), intent(out) :: stress_xc(3, 3)
504
505 integer :: ik, ist, idir, jdir, ib, minst, maxst, ispin
506 real(real64) :: stress_tau(3,3)
507 complex(real64), allocatable :: stress_l_block(:)
508 type(wfs_elec_t) :: psib, gpsib(space%dim), vtau_gpsib(space%dim)
509
510 call profiling_in("STRESS_FROM_XC")
511 push_sub(stress_from_xc)
512
513 ! LDA part
514 stress_xc = m_zero
515 do idir = 1, space%periodic_dim
516 stress_xc(idir, idir) = - hm%energy%exchange - hm%energy%correlation + hm%energy%intnvxc
517 end do
518
519 ! tau-mGGA part.
520 ! Only the term involving the gradients of the orbitals is computed here. The diagonal term
521 ! \f$ \delta_{ij}\int d^3r v_\tau \tau \f$ is not added: it is already contained in
522 ! energy%intnvxc above, where v_ks_calc adds the expectation value of the mGGA operator
523 ! (TERM_MGGA) at the generalized Kohn-Sham level.
524 if (family_is_mgga_with_exc(hm%xc)) then
525 stress_tau = m_zero
526
527 safe_allocate(stress_l_block(1:st%block_size))
528
529 ! TODO: This mostly duplicates the kinetic term. Stress_from_kinetic could return the tau part,
530 ! if performances are critical
531 do ik = st%d%kpt%start, st%d%kpt%end
532 if (st%kweights(ik) <= m_epsilon) cycle
534 ispin = st%d%get_spin_index(ik)
535
536 do ib = st%group%block_start, st%group%block_end
537 minst = states_elec_block_min(st, ib)
538 maxst = states_elec_block_max(st, ib)
539
540 call hm%phase%copy_and_set_phase(gr, st%d%kpt, st%group%psib(ib, ik), psib)
541
542 ! calculate the gradient
543 call zderivatives_batch_grad(gr%der, psib, gpsib, set_bc=.false.)
544
545 ! vtau \nabla \psi
546 do idir = 1, space%periodic_dim
547 call psib%copy_to(vtau_gpsib(idir))
548 call batch_set_zero(vtau_gpsib(idir))
549 call hm%ks_pot%zapply_vtau_psi(gr, hm%d, ispin, gpsib(idir), vtau_gpsib(idir))
550 end do
551
552 ! Accumulate the result
553 do idir = 1, space%periodic_dim
554 do jdir = idir, space%periodic_dim
555 call zmesh_batch_dotp_vector(gr, vtau_gpsib(idir), gpsib(jdir), stress_l_block)
556
557 do ist = minst, maxst
558 stress_tau(idir, jdir) = stress_tau(idir, jdir) &
559 + m_two * st%kweights(ik) * st%occ(ist, ik) * real(stress_l_block(ist - minst + 1), real64)
560 end do
561 end do
562 end do
563
564 do idir = 1, space%dim
565 call gpsib(idir)%end()
566 end do
567 do idir = 1, space%periodic_dim
568 call vtau_gpsib(idir)%end()
569 end do
570 call psib%end()
571
572 end do
573 end do
574
575 safe_deallocate_a(stress_l_block)
576
577 if (st%parallel_in_states .or. st%d%kpt%parallel) then
578 call comm_allreduce(st%st_kpt_mpi_grp, stress_tau)
579 end if
580
581 ! Symmetrize the tau stress tensor
582 call upper_triangular_to_hermitian(space%periodic_dim, stress_tau)
583
584 ! Symmetrize the stress tensor if we use k-point symmetries
585 if (hm%kpoints%use_symmetries) then
586 call dsymmetrize_tensor_cart(gr%symm, stress_tau, use_non_symmorphic=.true.)
587 end if
588
589 stress_xc(:,:) = stress_xc(:,:) + stress_tau(:,:)
590
591 end if
593 stress_xc(:,:) = stress_xc(:,:) / rcell_volume
594
595 call profiling_out("STRESS_FROM_XC")
596 pop_sub(stress_from_xc)
597 end subroutine stress_from_xc
598
599
600 ! -------------------------------------------------------
617 subroutine stress_from_xc_nlcc(rcell_volume, gr, st, ions, vxc, stress_xc_nlcc)
618 real(real64), intent(in) :: rcell_volume
619 type(grid_t), intent(in) :: gr
620 type(states_elec_t), intent(in) :: st
621 type(ions_t), intent(in) :: ions
622 real(real64), contiguous, intent(in) :: vxc(:,:)
623 real(real64), intent(out) :: stress_xc_nlcc(3, 3)
624
625 integer :: idir, jdir, iat
626 real(real64), allocatable :: vxc_tot(:), nlcc_grad_x(:,:,:)
627
628 call profiling_in("STRESS_FROM_XC_NLCC")
629 push_sub(stress_from_xc_nlcc)
630
631 assert(allocated(st%rho_core))
632
633 stress_xc_nlcc = m_zero
634
635 safe_allocate(vxc_tot(1:gr%np))
636 safe_allocate(nlcc_grad_x(1:gr%np, 1:gr%der%dim, 1:gr%der%dim))
637
638 ! Spin average of the xc potential, as the core density is split equally among spin channels
639 call lalg_copy(gr%np, vxc(:, 1), vxc_tot)
640 if (st%d%spin_channels > 1) then
641 call lalg_axpy(gr%np, m_one, vxc(:, 2), vxc_tot)
642 call lalg_scal(gr%np, m_half, vxc_tot)
643 end if
644
645 do iat = ions%atoms_dist%start, ions%atoms_dist%end
646 call species_get_nlcc_grad(ions%atom(iat)%species, ions%space, ions%latt, &
647 ions%pos(:,iat), gr, nlcc_grad_x)
648
649 do idir = 1, ions%space%periodic_dim
650 do jdir = idir, ions%space%periodic_dim
651 stress_xc_nlcc(idir, jdir) = stress_xc_nlcc(idir, jdir) &
652 - dmf_dotp(gr, nlcc_grad_x(:, idir, jdir), vxc_tot)
653 end do
654 end do
655 end do
656 safe_deallocate_a(nlcc_grad_x)
657 safe_deallocate_a(vxc_tot)
658
659 if (ions%atoms_dist%parallel) then
660 call comm_allreduce(ions%atoms_dist%mpi_grp, stress_xc_nlcc)
661 end if
662
663 call upper_triangular_to_hermitian(ions%space%periodic_dim, stress_xc_nlcc)
664
665 stress_xc_nlcc(:,:) = stress_xc_nlcc(:,:) / rcell_volume
666
667 call profiling_out("STRESS_FROM_XC_NLCC")
668 pop_sub(stress_from_xc_nlcc)
669 end subroutine stress_from_xc_nlcc
670
671 ! -------------------------------------------------------
691 subroutine stress_from_pseudo_nonloc(gr, st, hm, ions, stress_ps_nl)
692 type(grid_t), target, intent(in) :: gr
693 type(states_elec_t), intent(inout) :: st
694 type(hamiltonian_elec_t), intent(in) :: hm
695 type(ions_t), intent(in) :: ions
696 real(real64), intent(out) :: stress_ps_nl(3, 3)
697
698 integer :: ik, ist, idir, jdir
699 integer :: ib, minst, maxst
700 type(wfs_elec_t) :: psib, rvnl_psib(3), gpsib(3)
701 complex(real64), allocatable :: stress_tmp(:)
702
703 call profiling_in("STRESS_FROM_PSEUDO_NL")
705
706 assert(st%wfs_type == type_cmplx)
707
708 safe_allocate(stress_tmp(1:st%block_size))
709
710 stress_ps_nl = m_zero
711
712 do ik = st%d%kpt%start, st%d%kpt%end
713
714 if (st%kweights(ik) <= m_epsilon) cycle
715
716 do ib = st%group%block_start, st%group%block_end
717 minst = states_elec_block_min(st, ib)
718 maxst = states_elec_block_max(st, ib)
719
720 call hm%phase%copy_and_set_phase(gr, st%d%kpt, st%group%psib(ib, ik), psib)
721
722 ! calculate the gradient
723 call zderivatives_batch_grad(gr%der, psib, gpsib, set_bc=.false.)
724
725
726 ! Get rV_NL |\psi> for all atoms
727 do idir = 1, gr%der%dim
728 call psib%copy_to(rvnl_psib(idir))
729 call batch_set_zero(rvnl_psib(idir))
730 end do
731 call hm%vnl%zr_vn_local(gr, st%d, gr%der%boundaries%spiral, psib, rvnl_psib)
732
733 do idir = 1, ions%space%periodic_dim
734 do jdir = idir, ions%space%periodic_dim
735 call zmesh_batch_dotp_vector(gr, gpsib(idir), rvnl_psib(jdir), stress_tmp)
736
737 do ist = minst, maxst
738 stress_ps_nl(idir, jdir) = stress_ps_nl(idir, jdir) &
739 + m_two * st%kweights(ik) * st%occ(ist, ik) * real(stress_tmp(ist-minst+1), real64)
740 end do
741
742 end do
743 end do
744
745 do idir = 1, gr%der%dim
746 call rvnl_psib(idir)%end()
747 call gpsib(idir)%end()
748 end do
749 call psib%end()
750 end do
751 end do
752
753 safe_deallocate_a(stress_tmp)
754
755 if (st%parallel_in_states .or. st%d%kpt%parallel) then
756 call comm_allreduce(st%st_kpt_mpi_grp, stress_ps_nl)
757 end if
758
759 ! Symmetrize the kinetic stress tensor
760 call upper_triangular_to_hermitian(ions%space%periodic_dim, stress_ps_nl)
761
762 ! Symmetrize the stress tensor if we use k-point symmetries
763 if (hm%kpoints%use_symmetries) then
764 call dsymmetrize_tensor_cart(gr%symm, stress_ps_nl, use_non_symmorphic=.true.)
765 end if
766
767 ! Add the nonlocal energy
768 do idir = 1, ions%space%periodic_dim
769 stress_ps_nl(idir, idir) = stress_ps_nl(idir, idir) + hm%energy%extern_non_local
770 end do
771
772 stress_ps_nl = stress_ps_nl/ions%latt%rcell_volume
773
774 call profiling_out("STRESS_FROM_PSEUDO_NL")
776
777 end subroutine stress_from_pseudo_nonloc
778
779
780 ! -------------------------------------------------------
800 subroutine stress_from_pseudo_local(gr, hm, ions, rho_total, grad_vh, stress_ps_local)
801 type(grid_t), target, intent(in) :: gr
802 type(hamiltonian_elec_t), intent(in) :: hm
803 type(ions_t), intent(in) :: ions
804 real(real64), contiguous, intent(inout) :: rho_total(:)
805 real(real64), contiguous, intent(in) :: grad_vh(:,:)
806 real(real64), intent(out) :: stress_ps_local(3, 3)
807
808
809 real(real64) :: stress_SR(3, 3), stress_LR(3, 3)
810 real(real64) :: energy_ps_SR, charge, zi
811 real(real64), allocatable :: vloc(:), rvloc(:,:), rho_local_lr(:), rho_lr(:)
812 real(real64), allocatable :: grad_rho(:,:), rho_lr_x(:,:), vlr(:), grad_vlr(:,:)
813 integer :: idir, jdir, iatom
814 type(ps_t), pointer :: spec_ps
815
816 call profiling_in("STRESS_FROM_PSEUDO_LOC")
818
819 ! calculate stress from short-range local pseudopotentials
820 stress_sr = m_zero
821
822 safe_allocate(vloc(1:gr%np))
823 vloc = m_zero
824 safe_allocate(rvloc(1:gr%np, 1:gr%der%dim))
825 rvloc = m_zero
826 do iatom = 1, ions%natoms
827 call epot_local_pseudopotential_sr(gr, ions, iatom, vloc, rvloc)
828 end do
829 safe_deallocate_a(vloc)
830
831 safe_allocate(grad_rho(1:gr%np,1:gr%der%dim))
832 call dderivatives_grad(gr%der, rho_total, grad_rho)
833
834 energy_ps_sr = hm%energy%extern_local
835 do idir = 1, ions%space%periodic_dim
836 do jdir = idir, ions%space%periodic_dim
837 stress_sr(idir, jdir) = stress_sr(idir, jdir) &
838 +dmf_dotp(gr, rvloc(:, jdir), grad_rho(:, idir))
839 end do
840 stress_sr(idir,idir) = stress_sr(idir,idir) + energy_ps_sr
841 end do
842
843 call upper_triangular_to_hermitian(ions%space%periodic_dim, stress_sr)
844
845 stress_sr = stress_sr/ions%latt%rcell_volume
846
847 safe_deallocate_a(rvloc)
848 safe_deallocate_a(grad_rho)
849
850
851 ! calculate stress from long-range local pseudopotentials
852 stress_lr = m_zero
853
854 ! We treat the long-range part of the local potential as the Hartree term
855 ! We first sum the long range densities from atoms
856 safe_allocate(rho_lr(1:gr%np_part))
857 safe_allocate(rho_lr_x(1:gr%np, 1:gr%der%dim))
858 rho_lr = m_zero
859 rho_lr_x = m_zero
860 safe_allocate(rho_local_lr(1:gr%np))
861 do iatom = ions%atoms_dist%start, ions%atoms_dist%end
862 assert(ions%atom(iatom)%species%is_ps())
863 call species_get_long_range_density(ions%atom(iatom)%species, ions%namespace, ions%space, ions%latt, &
864 ions%pos(:, iatom), gr, rho_local_lr, nlr_x=rho_lr_x)
865
866 call lalg_axpy(gr%np, m_one, rho_local_lr, rho_lr)
867 end do
868 safe_deallocate_a(rho_local_lr)
869
870 if (ions%atoms_dist%parallel) then
871 call comm_allreduce(ions%atoms_dist%mpi_grp, rho_lr)
872 call comm_allreduce(ions%atoms_dist%mpi_grp, rho_lr_x)
873 end if
874
875 do idir = 1, ions%space%periodic_dim
876 do jdir = idir, ions%space%periodic_dim
877 stress_lr(idir, jdir) = stress_lr(idir, jdir) + dmf_dotp(gr, rho_lr_x(:,jdir), grad_vh(:, idir))
878 end do
879 end do
880 safe_deallocate_a(rho_lr_x)
881
882 safe_allocate(vlr(1:gr%np_part))
883 call dpoisson_solve(hm%psolver, ions%namespace, vlr, rho_lr, all_nodes = .true.)
884 safe_deallocate_a(rho_lr)
885
886 safe_allocate(grad_vlr(1:gr%np, 1:gr%der%dim))
887 call dderivatives_grad(gr%der, vlr, grad_vlr)
888 safe_deallocate_a(vlr)
889
890 do idir = 1, ions%space%periodic_dim
891 do jdir = idir, ions%space%periodic_dim
892 stress_lr(idir, jdir) = stress_lr(idir, jdir) - dmf_dotp(gr, grad_vh(:,idir), grad_vlr(:, jdir))/m_two/m_pi
893 end do
894 end do
896 call upper_triangular_to_hermitian(ions%space%periodic_dim, stress_lr)
897
898 safe_deallocate_a(grad_vlr)
899
900 ! Contribution from G=0 component of the long-range part
901 !
902 if (ions%space%periodic_dim == 3) then
903 charge = m_zero
904 do iatom = 1, ions%natoms
905 charge = charge + ions%atom(iatom)%species%get_zval()
906 end do
907
908 do iatom = 1, ions%natoms
909 select type(spec => ions%atom(iatom)%species)
910 type is(pseudopotential_t)
911 zi = spec%get_zval()
912 spec_ps => spec%ps
913
914 do idir = 1, ions%space%periodic_dim
915 stress_lr(idir, idir) = stress_lr(idir, idir) &
916 + m_two*m_pi*spec_ps%sigma_erf**2*charge*zi /ions%latt%rcell_volume
917 end do
918 end select
919 end do
920 end if
921
922 stress_lr = stress_lr/ions%latt%rcell_volume
923
924 stress_ps_local = stress_sr + stress_lr
925
926 call profiling_out("STRESS_FROM_PSEUDO_LOC")
928
929 end subroutine stress_from_pseudo_local
930
931 ! -------------------------------------------------------
932 subroutine epot_local_pseudopotential_sr(mesh, ions, iatom, vpsl, rvpsl)
933 class(mesh_t), intent(in) :: mesh
934 type(ions_t), intent(in) :: ions
935 integer, intent(in) :: iatom
936 real(real64), contiguous, intent(inout) :: vpsl(:)
937 real(real64), contiguous, intent(inout) :: rvpsl(:,:)
938
939 integer :: ip
940 real(real64) :: radius, vl_ip
941 type(submesh_t) :: sphere
942 type(ps_t), pointer :: ps
943
945
946 if (.not. ions%atom(iatom)%species%is_ps()) then
948 return
949 endif
950
951 call profiling_in("EPOT_LOCAL_PS_SR")
952
953 select type(spec=>ions%atom(iatom)%species)
954 type is(pseudopotential_t)
955
956 ps => spec%ps
957
958 radius = ps%vl%x_threshold*1.05_real64
959
960 call submesh_init(sphere, ions%space, mesh, ions%latt, ions%pos(:, iatom), radius)
961
962 ! Cannot be written (correctly) as a vector expression since for periodic systems,
963 ! there can be values ip, jp such that sphere%map(ip) == sphere%map(jp).
964 do ip = 1, sphere%np
965 vl_ip = spline_eval(ps%vl, sphere%r(ip))
966 vpsl(sphere%map(ip)) = vpsl(sphere%map(ip)) + vl_ip
967 rvpsl(sphere%map(ip), 1:ions%space%periodic_dim) = rvpsl(sphere%map(ip), 1:ions%space%periodic_dim) &
968 + sphere%rel_x(1:ions%space%periodic_dim, ip) * vl_ip
969 end do
970
971 call submesh_end(sphere)
972
973 nullify(ps)
974
975 end select
976
977 call profiling_out("EPOT_LOCAL_PS_SR")
979 end subroutine epot_local_pseudopotential_sr
980
981
982 ! -------------------------------------------------------
997 subroutine stress_from_hubbard(namespace, gr, st, hm, space, rcell_volume, stress_hubbard)
998 type(namespace_t), intent(in) :: namespace
999 type(grid_t), target, intent(in) :: gr
1000 type(states_elec_t), intent(in) :: st
1001 type(hamiltonian_elec_t), intent(in) :: hm
1002 type(space_t), intent(in) :: space
1003 real(real64), intent(in) :: rcell_volume
1004 real(real64), intent(out) :: stress_hubbard(3, 3)
1005
1006 integer :: ik, ist, idir, jdir
1007 integer :: ib, minst, maxst
1008 type(wfs_elec_t) :: psib, rvu_psib(3), gpsib(3)
1009 complex(real64), allocatable :: stress_tmp(:)
1010
1011 if (hm%lda_u%level == dft_u_none) then
1012 stress_hubbard = m_zero
1013 return
1014 end if
1015
1016 push_sub_with_profile(stress_from_hubbard)
1017
1018 assert(st%wfs_type == type_cmplx)
1019
1020 safe_allocate(stress_tmp(1:st%block_size))
1021
1022 stress_hubbard = m_zero
1023
1024 do ik = st%d%kpt%start, st%d%kpt%end
1025
1026 if (st%kweights(ik) <= m_epsilon) cycle
1028 do ib = st%group%block_start, st%group%block_end
1029 minst = states_elec_block_min(st, ib)
1030 maxst = states_elec_block_max(st, ib)
1031
1032 call hm%phase%copy_and_set_phase(gr, st%d%kpt, st%group%psib(ib, ik), psib)
1033
1034 ! calculate the gradient
1035 call zderivatives_batch_grad(gr%der, psib, gpsib, set_bc=.false.)
1036
1037 ! Get rV_U |\psi> for all atoms
1038 do idir = 1, gr%der%dim
1039 call psib%copy_to(rvu_psib(idir))
1040 call batch_set_zero(rvu_psib(idir))
1041 end do
1042
1043 call zlda_u_rvu(hm%lda_u, gr, space, hm%d, namespace, psib, rvu_psib)
1044
1045 do idir = 1,3
1046 do jdir = idir,3
1047 call zmesh_batch_dotp_vector(gr, gpsib(idir), rvu_psib(jdir), stress_tmp)
1048
1049 do ist = minst, maxst
1050 stress_hubbard(idir, jdir) = stress_hubbard(idir, jdir) &
1051 + m_two * st%kweights(ik) * st%occ(ist, ik) * real(stress_tmp(ist-minst+1), real64)
1052 end do
1053
1054 end do
1055 end do
1056
1057 do idir = 1, gr%der%dim
1058 call rvu_psib(idir)%end()
1059 call gpsib(idir)%end()
1060 end do
1061 call psib%end()
1062 end do
1063 end do
1064
1065 safe_deallocate_a(stress_tmp)
1066
1067 if (st%parallel_in_states .or. st%d%kpt%parallel) then
1068 call comm_allreduce(st%st_kpt_mpi_grp, stress_hubbard)
1069 end if
1070
1071 ! Symmetrize the kinetic stress tensor
1072 call upper_triangular_to_hermitian(gr%der%dim, stress_hubbard)
1073
1074 ! Symmetrize the stress tensor if we use k-point symmetries
1075 if (hm%kpoints%use_symmetries) then
1076 call dsymmetrize_tensor_cart(gr%symm, stress_hubbard)
1077 end if
1078
1079 ! Add the Hubbard energy
1080 do idir = 1,3
1081 stress_hubbard(idir, idir) = stress_hubbard(idir, idir) + hm%energy%int_dft_u
1082 end do
1083
1084 stress_hubbard = stress_hubbard/rcell_volume
1085
1086 pop_sub_with_profile(stress_from_hubbard)
1087 end subroutine stress_from_hubbard
1088
1089
1090 ! -------------------------------------------------------
1091 subroutine output_stress(iunit, space_dim, stress_tensors, mpi_grp, all_terms)
1092 integer, intent(in) :: iunit
1093 integer, intent(in) :: space_dim
1094 type(stress_t), intent(in) :: stress_tensors
1095 type(mpi_grp_t), intent(in) :: mpi_grp
1096 logical, optional, intent(in) :: all_terms
1097
1098 logical :: write_all_terms
1099 character(len=16) :: stress_unit
1100
1101 write_all_terms = optional_default(all_terms, .true.)
1102
1103 write(stress_unit, '(4a,i1)') trim(units_abbrev(units_out%energy)), '/', &
1104 trim(units_abbrev(units_out%length)), '^', space_dim
1105
1106 if (mpi_grp%is_root()) then
1107
1108 if (write_all_terms) then
1109 write(iunit, '(3a)') 'Kinetic stress tensor [', trim(stress_unit), '] ='
1110 call print_stress_tensor(iunit, space_dim, stress_tensors%kinetic)
1111 if (space_dim == 3) then
1112 write(iunit, '(a, es15.6, 3a)') 'Kinetic pressure sumrule violation: ', &
1113 units_from_atomic(units_out%energy, stress_tensors%kinetic_sumrule), &
1114 ' [', trim(units_abbrev(units_out%energy)), ']'
1115 write(iunit,*)
1116 end if
1117
1118
1119 write(iunit, '(3a)') 'Hartree stress tensor [', trim(stress_unit), '] ='
1120 call print_stress_tensor(iunit, space_dim, stress_tensors%Hartree)
1121 if (space_dim == 3) then
1122 write(iunit, '(a, es15.6, 3a)') 'Hartree pressure sumrule violation: ', &
1123 units_from_atomic(units_out%energy, stress_tensors%hartree_sumrule), &
1124 ' [', trim(units_abbrev(units_out%energy)), ']'
1125 write(iunit,*)
1126 end if
1127
1128 write(iunit, '(3a)') 'XC stress tensor [', trim(stress_unit), '] ='
1129 call print_stress_tensor(iunit, space_dim, stress_tensors%xc)
1130
1131 write(iunit, '(3a)') 'XC NLCC stress tensor [', trim(stress_unit), '] ='
1132 call print_stress_tensor(iunit, space_dim, stress_tensors%xc_nlcc)
1133
1134 write(iunit, '(3a)') 'Local pseudo. stress tensor [', trim(stress_unit), '] ='
1135 call print_stress_tensor(iunit, space_dim, stress_tensors%ps_local)
1136
1137 write(iunit, '(3a)') 'Nonlocal pseudo. stress tensor [', trim(stress_unit), '] ='
1138 call print_stress_tensor(iunit, space_dim, stress_tensors%ps_nl)
1139
1140 write(iunit, '(3a)') 'Ion-ion stress tensor [', trim(stress_unit), '] ='
1141 call print_stress_tensor(iunit, space_dim, stress_tensors%ion_ion)
1142
1143 write(iunit, '(3a)') 'vdW stress tensor [', trim(stress_unit), '] ='
1144 call print_stress_tensor(iunit, space_dim, stress_tensors%vdw)
1145
1146 write(iunit, '(3a)') 'Hubbard stress tensor [', trim(stress_unit), '] ='
1147 call print_stress_tensor(iunit, space_dim, stress_tensors%hubbard)
1148 end if
1149
1150 write(iunit, '(3a)') 'Total stress tensor [', trim(stress_unit), '] ='
1151 call print_stress_tensor(iunit, space_dim, stress_tensors%total)
1152
1153 end if
1154 end subroutine output_stress
1155
1156
1157 subroutine output_pressure(iunit, space_dim, total_stress_tensor)
1158 integer, intent(in) :: iunit
1159 integer, intent(in) :: space_dim
1160 real(real64), intent(in) :: total_stress_tensor(3,3)
1161
1162 integer :: idim
1163 real(real64) :: pressure
1164 character(len=16) :: stress_unit
1165
1166 write(stress_unit, '(4a,i1)') trim(units_abbrev(units_out%energy)), '/', &
1167 trim(units_abbrev(units_out%length)), '^', space_dim
1168
1169 pressure = m_zero
1170 do idim = 1, space_dim
1171 pressure = pressure - total_stress_tensor(idim, idim) / real(space_dim, real64)
1172 end do
1173
1174 write(iunit,'(3a,es16.8)', advance="no") 'Pressure [', trim(stress_unit), '] = ', &
1175 units_from_atomic(units_out%energy/units_out%length**space_dim, pressure)
1176 if (space_dim == 3) then
1177 write(iunit,'(2x,a,f16.8)') 'Pressure [GPa] = ', units_from_atomic(unit_gpa, pressure)
1178 else
1179 write(iunit,*)
1180 end if
1181
1182 end subroutine output_pressure
1183
1184 subroutine print_stress_tensor(ounit, space_dim, tensor)
1185 integer, intent(in) :: ounit
1186 integer, intent(in) :: space_dim
1187 real(real64), intent(in) :: tensor(3,3)
1188
1189 real(real64) :: tensor_with_unit(3,3)
1190 integer :: idim, jdim
1191
1192 tensor_with_unit = units_from_atomic(units_out%energy/units_out%length**space_dim, tensor)
1193
1194 write(ounit,'(a9,2x)', advance="no")"T_{ij}"
1195 do jdim = 1, space_dim
1196 write(ounit,'(i18)', advance="no") jdim
1197 end do
1198 write(ounit,*)
1199 do idim = 1, space_dim
1200 write(ounit,'(i9,2x)', advance="no") idim
1201 do jdim = 1, space_dim
1202 write(ounit,'(es18.9)', advance="no") tensor_with_unit(idim, jdim)
1203 end do
1204 write(ounit,*)
1205 end do
1206 write(ounit,*)
1207
1208 end subroutine print_stress_tensor
1209
1210
1211end module stress_oct_m
1212
1213!! Local Variables:
1214!! mode: f90
1215!! coding: utf-8
1216!! End:
constant times a vector plus a vector
Definition: lalg_basic.F90:194
Copies a vector x, to a vector y.
Definition: lalg_basic.F90:220
scales a vector by a constant
Definition: lalg_basic.F90:170
This module implements common operations on batches of mesh functions.
Definition: batch_ops.F90:118
subroutine, public batch_set_zero(this, np, async)
fill all mesh functions of the batch with zero
Definition: batch_ops.F90:280
Module implementing boundary conditions in Octopus.
Definition: boundaries.F90:124
This module implements a calculator for the density and defines related functions.
Definition: density.F90:122
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
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
Definition: epot.F90:168
integer, parameter, public fully_relativistic_zora
Definition: epot.F90:168
real(real64), parameter, public m_two
Definition: global.F90:202
real(real64), parameter, public m_zero
Definition: global.F90:200
real(real64), parameter, public m_four
Definition: global.F90:204
real(real64), parameter, public m_pi
some mathematical constants
Definition: global.F90:198
integer, parameter, public independent_particles
Theory level.
Definition: global.F90:250
integer, parameter, public generalized_kohn_sham_dft
Definition: global.F90:250
integer, parameter, public kohn_sham_dft
Definition: global.F90:250
real(real64), parameter, public m_epsilon
Definition: global.F90:216
real(real64), parameter, public m_half
Definition: global.F90:206
real(real64), parameter, public m_one
Definition: global.F90:201
This module implements the underlying real-space grid.
Definition: grid.F90:119
This module defines classes and functions for interaction partners.
Definition: io.F90:116
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.
integer, parameter, public dft_u_none
Definition: lda_u.F90:205
subroutine, public zlda_u_rvu(this, mesh, space, d, namespace, psib, gpsib)
This routine computes .
Definition: lda_u.F90:5437
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.
Definition: math.F90:117
This module defines functions over batches of mesh functions.
Definition: mesh_batch.F90:118
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.
Definition: mesh.F90:120
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1068
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:162
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:410
subroutine, public dpoisson_solve(this, namespace, pot, rho, all_nodes, kernel, reset)
Calculates the Poisson equation. Given the density returns the corresponding potential.
Definition: poisson.F90:916
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
Definition: profiling.F90:668
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
Definition: profiling.F90:600
Definition: ps.F90:116
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.
real(real64) function, public spline_eval(spl, x)
Definition: splines.F90:441
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.
Definition: stress.F90:120
subroutine stress_from_hartree(gr, space, volume, grad_vh, ehartree, stress_Hartree)
Computes the contribution to the stress tensor from the Hartree energy.
Definition: stress.F90:534
subroutine, public output_stress(iunit, space_dim, stress_tensors, mpi_grp, all_terms)
Definition: stress.F90:1187
subroutine stress_from_kinetic(gr, space, hm, st, symm, rcell_volume, stress_kin)
Computes the contribution to the stress tensor from the kinetic energy.
Definition: stress.F90:445
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.
Definition: stress.F90:896
subroutine print_stress_tensor(ounit, space_dim, tensor)
Definition: stress.F90:1280
subroutine, public output_pressure(iunit, space_dim, total_stress_tensor)
Definition: stress.F90:1253
subroutine epot_local_pseudopotential_sr(mesh, ions, iatom, vpsl, rvpsl)
Definition: stress.F90:1028
subroutine, public stress_calculate(namespace, gr, hm, st, ions, ks, ext_partners)
This computes the total stress on the lattice.
Definition: stress.F90:188
subroutine stress_from_hubbard(namespace, gr, st, hm, space, rcell_volume, stress_hubbard)
Computes the contribution to the stress tensor from the Hubbard energy.
Definition: stress.F90:1093
subroutine stress_from_xc(gr, hm, st, space, rcell_volume, stress_xc)
Computes the contribution to the stress tensor from the xc energy.
Definition: stress.F90:593
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.
Definition: stress.F90:713
subroutine stress_from_pseudo_nonloc(gr, st, hm, ions, stress_ps_nl)
Computes the contribution to the stress tensor from the nonlocal part of the pseudopotentials.
Definition: stress.F90:787
subroutine, public submesh_end(this)
Definition: submesh.F90:716
subroutine, public submesh_init(this, space, mesh, latt, center, rc)
Definition: submesh.F90:232
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
Definition: types.F90:137
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:134
character(len=20) pure function, public units_abbrev(this)
Definition: unit.F90:225
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.
Definition: xc.F90:120
logical pure function, public family_is_mgga_with_exc(xcs)
Is the xc function part of the mGGA family with an energy functional.
Definition: xc.F90:729
logical pure function, public xc_is_energy_functional(xcs)
Is one of the x or c functional is not an energy functional.
Definition: xc.F90:839
pure logical function, public in_family(family, xc_families)
Definition: xc.F90:757
A module that takes care of xc contribution from vdW interactions.
Definition: xc_vdw.F90:118
integer(int64), dimension(5), parameter, public d3_lib_options
VDWCORRECTION options that correspond to the DFT-D3 library.
Definition: xc_vdw.F90:171
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:171
Describes mesh distribution to nodes.
Definition: mesh.F90:188
This is defined even when running serial.
Definition: mpi.F90:144
A type storing the information and data about a pseudopotential.
Definition: ps.F90:188
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 ...
Definition: submesh.F90:177
batches of electronic states
Definition: wfs_elec.F90:143
int true(void)