Octopus
elf.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2011 M. Marques, A. Castro, A. Rubio, G. Bertsch, M. Oliveira
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
21module elf_oct_m
22 use debug_oct_m
26 use global_oct_m
27 use grid_oct_m
28 use, intrinsic :: iso_fortran_env
31 use mesh_oct_m
34 use parser_oct_m
36 use space_oct_m
39
40 implicit none
41
42 private
43 public :: &
44 elf_init, &
46
47 logical :: with_current_term = .true.
48
49contains
50
51 subroutine elf_init(namespace)
52 type(namespace_t), intent(in) :: namespace
53
54 push_sub(elf_init)
55
56 !%Variable ELFWithCurrentTerm
57 !%Type logical
58 !%Default true
59 !%Section Output
60 !%Description
61 !% The ELF, when calculated for complex wavefunctions, should contain
62 !% a term dependent on the current. This term is properly calculated by
63 !% default; however, for research purposes it may be useful not to add it.
64 !% If this feature proves to be useless, this option should go away.
65 !%End
66 call parse_variable(namespace, 'ELFWithCurrentTerm', .true., with_current_term)
67
68 pop_sub(elf_init)
69 end subroutine elf_init
70
71 ! ---------------------------------------------------------
73 ! ---------------------------------------------------------
74 subroutine elf_calc(space, st, gr, kpoints, elf, de, rho_paw, tau_paw)
75 class(space_t), intent(in) :: space
76 type(states_elec_t), intent(inout) :: st
77 type(grid_t), intent(in) :: gr
78 type(kpoints_t), intent(in) :: kpoints
83 real(real64), contiguous, intent(inout) :: elf(:,:)
84 real(real64), contiguous, optional, intent(inout):: de(:,:)
88 real(real64), contiguous, optional, intent(in) :: rho_paw(:,:)
89 real(real64), contiguous, optional, intent(in) :: tau_paw(:,:)
90
91 real(real64) :: factor, D0, dens
92 integer :: ip, is, nelfs
93 real(real64), allocatable :: rho(:,:), grho(:,:,:), jj(:,:,:), rho_ae(:)
94 real(real64), allocatable :: kappa(:,:)
95 real(real64), parameter :: dmin = 1e-10_real64
96
97 push_sub(elf_calc)
98
99 assert(space%dim == 2 .or. space%dim == 3)
100
101 ! We may or may not want the total ELF.
102 ! If we want it, the argument elf should have three components.
103 nelfs = size(elf, 2)
104
105 safe_allocate( rho(1:gr%np, 1:st%d%nspin))
106 safe_allocate(kappa(1:gr%np, 1:st%d%nspin))
107 rho = m_zero
108 kappa = m_zero
109 if (st%requires_generalized_overlap) then
110 ! For ultrasoft/PAW the plain density_calc path does not carry the augmentation charge
111 rho(1:gr%np, 1:st%d%nspin) = st%rho(1:gr%np, 1:st%d%nspin)
112 else
113 call density_calc(st, gr, rho)
114 end if
115
116 safe_allocate(grho(1:gr%np, 1:space%dim, 1:st%d%nspin))
117 safe_allocate( jj(1:gr%np, 1:space%dim, 1:st%d%nspin))
118
119 call states_elec_calc_quantities(gr, st, kpoints, .false., kinetic_energy_density = kappa, &
120 paramagnetic_current = jj, density_gradient = grho)
121
122 ! PAW: add the one-center corrections to reconstruct the all-electron density and
123 ! kinetic-energy density before forming the ELF
124 if (present(tau_paw)) call lalg_axpy(gr%np, st%d%nspin, m_one, tau_paw, kappa)
125 if (present(rho_paw)) then
126 ! rho_paw is n^1 - (ntilde^1 + nhat), to be added to a mesh density that carries nhat
127 assert(st%requires_generalized_overlap)
128 call lalg_axpy(gr%np, st%d%nspin, m_one, rho_paw, rho)
129
130 ! The gradient returned by states_elec_calc_quantities is the one of the smooth density
131 ! built from the pseudo-wavefunctions, which does not contain the compensation charge nhat.
132 ! Adding grad(rho_paw) to it would therefore leave a spurious -grad(nhat). The gradient is
133 ! instead taken from the all-electron density itself, so that it is consistent with rho.
134 safe_allocate(rho_ae(1:gr%np_part))
135 do is = 1, st%d%nspin
136 rho_ae(1:gr%np) = rho(1:gr%np, is)
137 call dderivatives_grad(gr%der, rho_ae, grho(:, :, is))
138 end do
139 safe_deallocate_a(rho_ae)
140 end if
141
142 ! spin-dependent quantities
143 if (st%d%ispin == unpolarized) then
144 rho = rho/m_two
145 kappa = kappa/m_two
146 jj = jj/m_two
147 grho = grho/m_two
148 end if
149
150 if (.not. with_current_term) jj = m_zero
151
152 ! kappa will contain rho * D
153 do_is: do is = 1, st%d%nspin
154 do ip = 1, gr%np
155 kappa(ip, is) = kappa(ip, is)*rho(ip, is) & ! + tau * rho
156 - m_fourth*sum(grho(ip, 1:space%dim, is)**2) & ! - | nabla rho |^2 / 4
157 - sum(jj(ip, 1:space%dim, is)**2) ! - j^2
158 end do
159
160 ! pass this information to the caller if requested
161 if (present(de)) de(1:gr%np,is) = kappa(1:gr%np,is)
162
163 end do do_is
164
165 safe_deallocate_a(grho)
166 safe_deallocate_a(jj) ! these are no longer needed
167
168 select case (space%dim)
169 case (3)
170 factor = m_three / m_five * (6.0_real64 * m_pi**2)**m_twothird
171 case (2)
172 factor = m_two * m_pi
173 end select
174
175 select case (st%d%ispin)
176 case (unpolarized)
177 do ip = 1, gr%np
178 if (rho(ip, 1) >= dmin) then
179 select case (space%dim)
180 case (3)
181 d0 = factor * rho(ip, 1)**(8.0_real64 / m_three)
182 case (2)
183 d0 = factor * rho(ip, 1)**3
184 end select
185 elf(ip, 1) = d0 * d0 / (d0 * d0 + kappa(ip, 1)**2)
186 else
187 elf(ip, 1) = m_zero
188 end if
189 end do
190
191 case (spin_polarized, spinors)
192 if (nelfs == 3) then
193 do ip = 1, gr%np
194 dens = rho(ip, 1) + rho(ip, 2)
195 if (dens >= dmin) then
196 select case (space%dim)
197 case (3)
198 d0 = factor * dens ** (m_five/m_three) * rho(ip, 1) * rho(ip, 2)
199 case (2)
200 d0 = factor * dens ** 2 * rho(ip, 1) * rho(ip, 2)
201 end select
202 elf(ip, 3) = d0 * d0 / (d0 * d0 + (kappa(ip, 1) * rho(ip, 2) + kappa(ip,2) * rho(ip, 1))**2)
203 else
204 elf(ip, 3) = m_zero
205 end if
206 end do
207 end if
208 do ip = 1, gr%np
209 do is = 1, st%d%spin_channels
210 if (rho(ip, is) >= dmin) then
211 select case (space%dim)
212 case (3)
213 d0 = factor * rho(ip, is)**(8.0_real64/m_three)
214 case (2)
215 d0 = factor * rho(ip, is)**3
216 end select
217 elf(ip, is) = d0 * d0 / (d0 * d0 + kappa(ip,is)**2)
218 else
219 elf(ip, is) = m_zero
220 end if
221 end do
222 end do
223 end select
224
225 safe_deallocate_a(rho)
226 safe_deallocate_a(kappa)
227
228 pop_sub(elf_calc)
229 end subroutine elf_calc
230
231end module elf_oct_m
232
233!! Local Variables:
234!! mode: f90
235!! coding: utf-8
236!! End:
constant times a vector plus a vector
Definition: lalg_basic.F90:171
This module implements a calculator for the density and defines related functions.
Definition: density.F90:99
subroutine, public density_calc(st, gr, density, istin, ep, vnl, phase)
Computes the density from the orbitals in st.
Definition: density.F90:839
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
integer, parameter, public unpolarized
Parameters...
integer, parameter, public spinors
integer, parameter, public spin_polarized
subroutine, public elf_calc(space, st, gr, kpoints, elf, de, rho_paw, tau_paw)
(time-dependent) electron localization function, (TD)ELF.
Definition: elf.F90:147
subroutine, public elf_init(namespace)
Definition: elf.F90:124
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_pi
some mathematical constants
Definition: global.F90:171
real(real64), parameter, public m_fourth
Definition: global.F90:182
real(real64), parameter, public m_twothird
Definition: global.F90:181
real(real64), parameter, public m_one
Definition: global.F90:174
real(real64), parameter, public m_three
Definition: global.F90:176
real(real64), parameter, public m_five
Definition: global.F90:178
This module implements the underlying real-space grid.
Definition: grid.F90:96
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:97
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
Definition: profiling.F90:122
This module handles spin dimensions of the states and the k-point distribution.
subroutine, public states_elec_calc_quantities(gr, st, kpoints, nlcc, kinetic_energy_density, paramagnetic_current, density_gradient, density_laplacian, gi_kinetic_energy_density, st_end)
calculated selected quantities
int true(void)