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