Octopus
elec_matrix_elements.F90
Go to the documentation of this file.
1!! Copyright (C) 2023 F. Troisi
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
22 use batch_oct_m
25 use debug_oct_m
30 use global_oct_m
31 use grid_oct_m
34 use ions_oct_m
35 use, intrinsic :: iso_fortran_env
38 use lda_u_oct_m
40 use mesh_oct_m
44 use mpi_oct_m
48 use phase_oct_m
55 use space_oct_m
60 use xc_cam_oct_m
61 use xc_oct_m
62
63 implicit none
64
65 private
66
67 public :: elec_momentum_me, &
69 dipole_me, &
76
77 interface dipole_me
78 procedure :: delec_dipole_me, zelec_dipole_me
79 end interface dipole_me
80
81 interface ks_multipoles_1d
82 procedure :: delec_ks_multipoles_1d_me, zelec_ks_multipoles_1d_me
83 end interface ks_multipoles_1d
84
85 interface ks_multipoles_2d
86 procedure :: delec_ks_multipoles_2d_me, zelec_ks_multipoles_2d_me
87 end interface ks_multipoles_2d
88
89 interface ks_multipoles_3d
90 procedure :: delec_ks_multipoles_3d_me, zelec_ks_multipoles_3d_me
91 end interface ks_multipoles_3d
92
93 interface one_body_me
94 procedure :: delec_one_body_me, zelec_one_body_me
95 end interface one_body_me
96
97 interface two_body_me
98 procedure :: delec_two_body_me, zelec_two_body_me
99 end interface two_body_me
100
101contains
102
103 ! -----------------------------------------------------------------------------
104 subroutine elec_momentum_me(namespace, gr, st, space, hm, ions, momentum, non_local)
105 type(namespace_t), intent(in) :: namespace
106 type(grid_t), intent(in) :: gr
107 type(states_elec_t), intent(in) :: st
108 type(space_t), intent(in) :: space
109 type(hamiltonian_elec_t), intent(in) :: hm
110 type(ions_t), intent(in) :: ions
111 real(real64), contiguous, intent(out) :: momentum(:,:,:)
112 logical, optional, intent(in) :: non_local
113
114 push_sub(elec_momentum_me)
115
116 if (states_are_real(st)) then
117 call delec_momentum_me(namespace, gr, st, space, hm, ions, momentum, non_local)
118 else
119 call zelec_momentum_me(namespace, gr, st, space, hm, ions, momentum, non_local)
120 end if
121
122 pop_sub(elec_momentum_me)
123 end subroutine elec_momentum_me
124
125 ! -----------------------------------------------------------------------------
126 subroutine elec_angular_momentum_me(gr, st, space, ll, l2)
127 type(grid_t), intent(in) :: gr
128 type(states_elec_t), intent(in) :: st
129 type(space_t), intent(in) :: space
130 real(real64), contiguous, intent(out) :: ll(:, :, :)
131 real(real64), contiguous, optional, intent(out) :: l2(:, :)
132
134
135 if (states_are_real(st)) then
136 call delec_angular_momentum_me(gr, st, space, ll, l2)
137 else
138 call zelec_angular_momentum_me(gr, st, space, ll, l2)
139 end if
140
142 end subroutine elec_angular_momentum_me
143
144
145 ! -----------------------------------------------------------------------------
165 subroutine zelec_velocity_me_uspp(namespace, gr, st, space, hm, velocity)
166 type(namespace_t), intent(in) :: namespace
167 type(grid_t), intent(in) :: gr
168 type(states_elec_t), intent(in) :: st
169 type(space_t), intent(in) :: space
170 type(hamiltonian_elec_t), intent(in) :: hm
171 real(real64), intent(out) :: velocity(:,:,:)
172
173 integer :: ik, ib, iloc, ist_global, idir, imat, iproj, jproj, nprojs, iprojection, idim, ist
174 complex(real64) :: loc, corr
175 complex(real64), allocatable :: psi(:,:), chi(:,:), xchi(:)
176 real(real64), allocatable :: aug_op_dir(:,:,:,:)
177 type(wfs_elec_t) :: psib_mut, chib, epsib
178 type(projection_t) :: proj_psi, proj_chi
179
180 push_sub_with_profile(zelec_velocity_me_uspp)
181
182 assert(hm%ep%requires_generalized_overlap)
183
184 velocity = m_zero
185
186 safe_allocate(psi(1:gr%np, 1:st%d%dim))
187 safe_allocate(chi(1:gr%np, 1:st%d%dim))
188 safe_allocate(xchi(1:gr%np))
189
190 ! M^alpha_ij = int x_alpha Q_ij(r) dr (geometry-only, state-independent), one per direction.
191 safe_allocate(aug_op_dir(1:hm%vnl%max_nprojs, 1:hm%vnl%max_nprojs, 1:hm%vnl%nprojector_matrices, 1:space%dim))
192 do idir = 1, space%dim
193 call nonlocal_pseudopotential_aug_moment(hm%vnl, gr, hm%ep, gr%x_t(1:gr%np, idir), aug_op_dir(:,:,:,idir))
194 end do
195
196 do ik = st%d%kpt%start, st%d%kpt%end
197 do ib = st%group%block_start, st%group%block_end
198 ! Mutable copy of the (read-only) state block, then chi = S^{-1} H psitilde (= i d/dt psitilde).
199 call st%group%psib(ib, ik)%copy_to(psib_mut, copy_data = .true.)
200 call psib_mut%copy_to(chib)
201 call zhamiltonian_elec_apply_sinvh_batch(hm, namespace, gr, psib_mut, chib)
202
203 ! Local (smooth) term <psitilde|x_alpha|chi>. Both batches are phase-free (stored
204 ! representation), and x_alpha is real, so the phase cancels here.
205 do iloc = 1, st%group%psib(ib, ik)%nst
206 ist_global = st%group%psib(ib, ik)%linear_to_ist(iloc)
207 call batch_get_state(psib_mut, iloc, gr%np, psi)
208 call batch_get_state(chib, iloc, gr%np, chi)
209 do idir = 1, space%dim
210 loc = m_z0
211 do idim = 1, st%d%dim
212 xchi(1:gr%np) = gr%x_t(1:gr%np, idir)*chi(1:gr%np, idim)
213 loc = loc + zmf_dotp(gr, psi(:, idim), xchi)
214 end do
215 velocity(idir, ist_global, ik) = aimag(loc)
216 end do
217 end do
218
219 ! Projector overlaps <beta|psitilde> and <beta|chi> with the gauge phase applied (so the
220 ! augmentation term tracks the vector potential consistently with the overlap operator S).
221 if (hm%phase%is_allocated()) then
222 call psib_mut%copy_to(epsib)
223 call hm%phase%apply_to(gr, gr%np, .false., epsib, src = psib_mut)
224 epsib%has_phase = .true.
225 call znonlocal_pseudopotential_start(hm%vnl, gr, st%d, .false., epsib, proj_psi)
226 call hm%phase%apply_to(gr, gr%np, .false., epsib, src = chib)
227 epsib%has_phase = .true.
228 call znonlocal_pseudopotential_start(hm%vnl, gr, st%d, .false., epsib, proj_chi)
229 call epsib%end()
230 else
231 call znonlocal_pseudopotential_start(hm%vnl, gr, st%d, .false., psib_mut, proj_psi)
232 call znonlocal_pseudopotential_start(hm%vnl, gr, st%d, .false., chib, proj_chi)
233 end if
234 if (gr%parallel_in_domains) then
235 call gr%allreduce(proj_psi%zprojection)
236 call gr%allreduce(proj_chi%zprojection)
237 end if
238
239 ! Augmentation term sum_ij <psitilde|beta_i> M^alpha_ij <beta_j|chi>.
240 do ist = 1, st%group%psib(ib, ik)%nst_linear
241 ist_global = st%group%psib(ib, ik)%linear_to_ist(ist)
242 do idir = 1, space%dim
243 corr = m_zero
244 iprojection = 0
245 do imat = 1, hm%vnl%nprojector_matrices
246 nprojs = hm%vnl%projector_matrices(imat)%nprojs
247 do iproj = 1, nprojs
248 do jproj = 1, nprojs
249 corr = corr + conjg(proj_psi%zprojection(ist, iprojection + iproj)) * &
250 aug_op_dir(iproj, jproj, imat, idir) * proj_chi%zprojection(ist, iprojection + jproj)
251 end do
252 end do
253 iprojection = iprojection + nprojs
254 end do
255 velocity(idir, ist_global, ik) = velocity(idir, ist_global, ik) + aimag(corr)
256 end do
257 end do
258
259 safe_deallocate_a(proj_psi%zprojection)
260 safe_deallocate_a(proj_chi%zprojection)
261 call psib_mut%end()
262 call chib%end()
263 end do
264 end do
265
266 ! velocity currently holds Im[loc + corr]; the conserved current carries the prefactor +2
267 ! (d<X^>/dt = i(<chi|X^|psi> - <psi|X^|chi>) = +2 Im<psi|X^|chi>; matches the norm-conserving
268 ! Ehrenfest d<x>/dt = 2 Im<psi|xH|psi> = <p> computed by elec_momentum_me).
269 velocity = m_two*velocity
270
271 safe_deallocate_a(psi)
272 safe_deallocate_a(chi)
273 safe_deallocate_a(xchi)
274 safe_deallocate_a(aug_op_dir)
275
276 pop_sub_with_profile(zelec_velocity_me_uspp)
277 end subroutine zelec_velocity_me_uspp
278#include "undef.F90"
279#include "complex.F90"
280#include "elec_matrix_elements_inc.F90"
281
282#include "undef.F90"
283#include "real.F90"
284#include "elec_matrix_elements_inc.F90"
285
287
288!! Local Variables:
289!! mode: f90
290!! coding: utf-8
291!! End:
This module implements batches of mesh functions.
Definition: batch.F90:112
This module implements common operations on batches of mesh functions.
Definition: batch_ops.F90:95
Module implementing boundary conditions in Octopus.
Definition: boundaries.F90:101
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
subroutine, public elec_angular_momentum_me(gr, st, space, ll, l2)
subroutine delec_momentum_me(namespace, gr, st, space, hm, ions, momentum, non_local)
The routine calculates the expectation value of the momentum operator.
subroutine, public zelec_velocity_me_uspp(namespace, gr, st, space, hm, velocity)
Ultrasoft/PAW conserved macroscopic current (= dipole velocity), per state.
subroutine zelec_momentum_me(namespace, gr, st, space, hm, ions, momentum, non_local)
The routine calculates the expectation value of the momentum operator.
subroutine zelec_angular_momentum_me(gr, st, space, ll, l2)
It calculates the expectation value of the angular momentum of the states. If l2 is passed,...
subroutine delec_angular_momentum_me(gr, st, space, ll, l2)
It calculates the expectation value of the angular momentum of the states. If l2 is passed,...
subroutine, public elec_momentum_me(namespace, gr, st, space, hm, ions, momentum, non_local)
real(real64), parameter, public m_two
Definition: global.F90:175
real(real64), parameter, public m_zero
Definition: global.F90:173
complex(real64), parameter, public m_z0
Definition: global.F90:183
This module implements the underlying real-space grid.
Definition: grid.F90:96
subroutine, public zhamiltonian_elec_apply_sinvh_batch(hm, namespace, mesh, psib, hspsib, terms, set_bc, set_phase)
Apply the operator A = S^{-1} H to a batch (for ultrasoft/PAW).
A module to handle KS potential, without the external potential.
This module defines functions over batches of mesh functions.
Definition: mesh_batch.F90:95
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:97
This module contains some common usage patterns of MPI routines.
Definition: mpi_lib.F90:94
subroutine, public znonlocal_pseudopotential_start(this, mesh, std, spiral_bnd, psib, projection, async)
Start application of non-local potentials (stored in the Hamiltonian) to the wave functions.
subroutine, public nonlocal_pseudopotential_aug_moment(this, mesh, epot, op, aug_op)
Ultrasoft augmentation moments of a local operator A(r): int A(r) Q_ij(r-R_I) dr.
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
Definition: profiling.F90:122
pure logical function, public states_are_real(st)
This module handles spin dimensions of the states and the k-point distribution.
Definition: xc.F90:97
Class for projections of wave functions.
batches of electronic states
Definition: wfs_elec.F90:120
int true(void)