Octopus
linear_response.F90
Go to the documentation of this file.
1!! Copyright (C) 2004 E.S. Kadantsev, M. Marques
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
20#include "global.h"
21
23 use batch_oct_m
24 use comm_oct_m
25 use debug_oct_m
27 use global_oct_m
28 use, intrinsic :: iso_fortran_env
30 use mesh_oct_m
35 use smear_oct_m
36 use space_oct_m
40
41 implicit none
42
43 private
44
45 public :: &
46 lr_t, &
47 lr_init, &
49 lr_zero, &
50 lr_copy, &
57 lr_alpha_j, &
58 lr_dealloc, &
66
67
68
69 type lr_t
70 ! Components are public by default
71 logical, private :: is_allocated, is_allocated_rho
72
74 real(real64), allocatable :: ddl_rho(:,:)
75 real(real64), allocatable :: ddl_psi(:,:,:,:)
76
78 complex(real64), allocatable :: zdl_rho(:,:)
79 complex(real64), allocatable :: zdl_psi(:,:,:,:)
80
82 complex(real64), allocatable :: dl_j(:,:,:)
83 end type lr_t
84
85contains
86
87 ! ---------------------------------------------------------
88 subroutine lr_init(lr)
89 type(lr_t), intent(out) :: lr
90
91 push_sub(lr_init)
92
93 lr%is_allocated = .false.
94 lr%is_allocated_rho = .false.
95
96 pop_sub(lr_init)
97
98 end subroutine lr_init
99
100
101
102 ! ---------------------------------------------------------
103 subroutine lr_allocate(lr, st, mesh, allocate_rho)
104 type(lr_t), intent(inout) :: lr
105 type(states_elec_t), intent(in) :: st
106 class(mesh_t), intent(in) :: mesh
107 logical, optional, intent(in) :: allocate_rho
108
109 push_sub(lr_allocate)
110
111 lr%is_allocated_rho = .true.
112 if (present(allocate_rho)) lr%is_allocated_rho = allocate_rho
113
114 if (states_are_complex(st)) then
115 safe_allocate(lr%zdl_psi(1:mesh%np_part, 1:st%d%dim, st%st_start:st%st_end, st%d%kpt%start:st%d%kpt%end))
116 if (lr%is_allocated_rho) then
117 safe_allocate(lr%zdl_rho(1:mesh%np, 1:st%d%nspin))
118 end if
119 else
120 safe_allocate(lr%ddl_psi(1:mesh%np_part, 1:st%d%dim, st%st_start:st%st_end, st%d%kpt%start:st%d%kpt%end))
121 if (lr%is_allocated_rho) then
122 safe_allocate(lr%ddl_rho(1:mesh%np, 1:st%d%nspin))
123 end if
124 end if
125
126 lr%is_allocated = .true.
127
128 call lr_zero(lr, st)
129
130 pop_sub(lr_allocate)
131
132 end subroutine lr_allocate
133
134
135
136 ! ---------------------------------------------------------
137 subroutine lr_zero(lr, st)
138 type(lr_t), intent(inout) :: lr
139 type(states_elec_t), intent(in) :: st
140
141 push_sub(lr_zero)
142
143 assert(lr%is_allocated)
144
145 if (states_are_complex(st)) then
146 lr%zdl_psi = m_zero
147 if (lr%is_allocated_rho) lr%zdl_rho = m_zero
148 else
149 lr%ddl_psi = m_zero
150 if (lr%is_allocated_rho) lr%ddl_rho = m_zero
151 end if
152
153 pop_sub(lr_zero)
154
155 end subroutine lr_zero
156
157
158 ! ---------------------------------------------------------
159 subroutine lr_dealloc(lr)
160 type(lr_t), intent(inout) :: lr
161
162 push_sub(lr_dealloc)
163
164 safe_deallocate_a(lr%ddl_psi)
165 safe_deallocate_a(lr%zdl_psi)
167 safe_deallocate_a(lr%ddl_rho)
168 safe_deallocate_a(lr%zdl_rho)
170 safe_deallocate_a(lr%dl_j)
171 lr%is_allocated = .false.
172 lr%is_allocated_rho = .false.
174 pop_sub(lr_dealloc)
175 end subroutine lr_dealloc
176
178 ! ---------------------------------------------------------
179 subroutine lr_copy(st, mesh, src, dest)
180 type(states_elec_t), intent(in) :: st
181 class(mesh_t), intent(in) :: mesh
182 type(lr_t), intent(in) :: src
183 type(lr_t), intent(inout) :: dest
184
185 integer :: ik, ist
186
187 push_sub(lr_copy)
188
189 if (src%is_allocated_rho .and. dest%is_allocated_rho) then
190 if (states_are_complex(st)) then
191 call lalg_copy(mesh%np, st%d%nspin, src%zdl_rho, dest%zdl_rho)
192 else
193 call lalg_copy(mesh%np, st%d%nspin, src%ddl_rho, dest%ddl_rho)
194 end if
195 else
196 if (dest%is_allocated_rho) then
197 if (states_are_complex(st)) then
198 dest%zdl_rho(:, :) = m_zero
199 else
200 dest%ddl_rho(:, :) = m_zero
201 end if
202 end if
203 end if
204
205 do ik = st%d%kpt%start, st%d%kpt%end
206 do ist = st%st_start, st%st_end
207 if (states_are_complex(st)) then
208 call lalg_copy(mesh%np_part, st%d%dim, src%zdl_psi(:, :, ist, ik), dest%zdl_psi(:, :, ist, ik))
209 else
210 call lalg_copy(mesh%np_part, st%d%dim, src%ddl_psi(:, :, ist, ik), dest%ddl_psi(:, :, ist, ik))
211 end if
212 end do
213 end do
214
215 pop_sub(lr_copy)
216
217 end subroutine lr_copy
218
219
220
221 ! ---------------------------------------------------------
222 logical function lr_is_allocated(this)
223 type(lr_t), intent(in) :: this
224
225 push_sub(lr_is_allocated)
226 lr_is_allocated = this%is_allocated
227
228 pop_sub(lr_is_allocated)
229 end function lr_is_allocated
230
231
233 ! ---------------------------------------------------------
234 real(real64) function lr_alpha_j(st, jst, ik)
235 type(states_elec_t), intent(in) :: st
236 integer, intent(in) :: jst
237 integer, intent(in) :: ik
238
239 real(real64) :: dsmear
240
241 push_sub(lr_alpha_j)
242
243 if (st%smear%method == smear_fixed_occ) then
244 lr_alpha_j = st%occ(jst, ik) / st%smear%el_per_state
245 else
246 dsmear = max(1e-14_real64, st%smear%dsmear)
247 lr_alpha_j = max(st%smear%e_fermi + m_three*dsmear - st%eigenval(jst, ik), m_zero)
248 end if
249
250 pop_sub(lr_alpha_j)
251 end function lr_alpha_j
252
253#include "undef.F90"
254#include "real.F90"
255#include "linear_response_inc.F90"
256
257#include "undef.F90"
258#include "complex.F90"
259#include "linear_response_inc.F90"
260
261end module linear_response_oct_m
262
263!! Local Variables:
264!! mode: f90
265!! coding: utf-8
266!! End:
Copies a vector x, to a vector y.
Definition: lalg_basic.F90:188
This module implements batches of mesh functions.
Definition: batch.F90:135
real(real64), parameter, public m_zero
Definition: global.F90:200
real(real64), parameter, public m_three
Definition: global.F90:203
subroutine, public dlr_load_rho(dl_rho, mesh, nspin, restart, rho_tag, ierr)
subroutine, public zlr_orth_response(mesh, st, lr, omega)
subroutine, public dlr_swap_sigma(st, mesh, plus, minus)
subroutine, public dlr_orth_vector(mesh, st, vec, ist, ik, omega, min_proj)
Orthogonalizes a vector vec against all the occupied states. For details on the metallic part,...
subroutine, public zlr_load_rho(dl_rho, mesh, nspin, restart, rho_tag, ierr)
subroutine, public lr_copy(st, mesh, src, dest)
subroutine, public lr_zero(lr, st)
real(real64) function, public lr_alpha_j(st, jst, ik)
subroutine, public lr_allocate(lr, st, mesh, allocate_rho)
subroutine, public lr_init(lr)
subroutine, public lr_dealloc(lr)
subroutine, public zlr_orth_vector(mesh, st, vec, ist, ik, omega, min_proj)
Orthogonalizes a vector vec against all the occupied states. For details on the metallic part,...
subroutine, public dlr_dump_rho(lr, mesh, nspin, restart, rho_tag, ierr)
subroutine, public zlr_build_dl_rho(mesh, st, lr, nsigma)
Computes the variation of the density for the Sternheimer calculations This is given in Eq....
subroutine, public zlr_dump_rho(lr, mesh, nspin, restart, rho_tag, ierr)
subroutine, public dlr_orth_response(mesh, st, lr, omega)
subroutine, public zlr_swap_sigma(st, mesh, plus, minus)
subroutine, public dlr_build_dl_rho(mesh, st, lr, nsigma)
Computes the variation of the density for the Sternheimer calculations This is given in Eq....
logical function, public lr_is_allocated(this)
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:120
integer, parameter, public smear_fixed_occ
Definition: smear.F90:176
pure logical function, public states_are_complex(st)
Describes mesh distribution to nodes.
Definition: mesh.F90:187
The states_elec_t class contains all electronic wave functions.
int true(void)