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 = optional_default(allocate_rho, .true.)
112
113 if (states_are_complex(st)) then
114 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))
115 if (lr%is_allocated_rho) then
116 safe_allocate(lr%zdl_rho(1:mesh%np, 1:st%d%nspin))
117 end if
118 else
119 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))
120 if (lr%is_allocated_rho) then
121 safe_allocate(lr%ddl_rho(1:mesh%np, 1:st%d%nspin))
122 end if
123 end if
124
125 lr%is_allocated = .true.
126
127 call lr_zero(lr, st)
128
129 pop_sub(lr_allocate)
130
131 end subroutine lr_allocate
132
133
134
135 ! ---------------------------------------------------------
136 subroutine lr_zero(lr, st)
137 type(lr_t), intent(inout) :: lr
138 type(states_elec_t), intent(in) :: st
139
140 push_sub(lr_zero)
141
142 assert(lr%is_allocated)
143
144 if (states_are_complex(st)) then
145 lr%zdl_psi = m_zero
146 if (lr%is_allocated_rho) lr%zdl_rho = m_zero
147 else
148 lr%ddl_psi = m_zero
149 if (lr%is_allocated_rho) lr%ddl_rho = m_zero
150 end if
151
152 pop_sub(lr_zero)
153
154 end subroutine lr_zero
155
156
157 ! ---------------------------------------------------------
158 subroutine lr_dealloc(lr)
159 type(lr_t), intent(inout) :: lr
160
161 push_sub(lr_dealloc)
162
163 safe_deallocate_a(lr%ddl_psi)
164 safe_deallocate_a(lr%zdl_psi)
165
166 safe_deallocate_a(lr%ddl_rho)
167 safe_deallocate_a(lr%zdl_rho)
168
169 safe_deallocate_a(lr%dl_j)
170 lr%is_allocated = .false.
171 lr%is_allocated_rho = .false.
172
173 pop_sub(lr_dealloc)
174 end subroutine lr_dealloc
175
176
177 ! ---------------------------------------------------------
178 subroutine lr_copy(st, mesh, src, dest)
179 type(states_elec_t), intent(in) :: st
180 class(mesh_t), intent(in) :: mesh
181 type(lr_t), intent(in) :: src
182 type(lr_t), intent(inout) :: dest
184 integer :: ik, ist
185
186 push_sub(lr_copy)
187
188 if (src%is_allocated_rho .and. dest%is_allocated_rho) then
189 if (states_are_complex(st)) then
190 call lalg_copy(mesh%np, st%d%nspin, src%zdl_rho, dest%zdl_rho)
191 else
192 call lalg_copy(mesh%np, st%d%nspin, src%ddl_rho, dest%ddl_rho)
193 end if
194 else
195 if (dest%is_allocated_rho) then
196 if (states_are_complex(st)) then
197 dest%zdl_rho(:, :) = m_zero
198 else
199 dest%ddl_rho(:, :) = m_zero
200 end if
201 end if
202 end if
203
204 do ik = st%d%kpt%start, st%d%kpt%end
205 do ist = st%st_start, st%st_end
206 if (states_are_complex(st)) then
207 call lalg_copy(mesh%np_part, st%d%dim, src%zdl_psi(:, :, ist, ik), dest%zdl_psi(:, :, ist, ik))
208 else
209 call lalg_copy(mesh%np_part, st%d%dim, src%ddl_psi(:, :, ist, ik), dest%ddl_psi(:, :, ist, ik))
210 end if
211 end do
212 end do
213
214 pop_sub(lr_copy)
215
216 end subroutine lr_copy
217
218
219
220 ! ---------------------------------------------------------
221 logical function lr_is_allocated(this)
222 type(lr_t), intent(in) :: this
223
224 push_sub(lr_is_allocated)
225 lr_is_allocated = this%is_allocated
226
227 pop_sub(lr_is_allocated)
228 end function lr_is_allocated
229
230
232 ! ---------------------------------------------------------
233 real(real64) function lr_alpha_j(st, jst, ik)
234 type(states_elec_t), intent(in) :: st
235 integer, intent(in) :: jst
236 integer, intent(in) :: ik
237
238 real(real64) :: dsmear
239
240 push_sub(lr_alpha_j)
241
242 if (st%smear%method == smear_fixed_occ) then
243 lr_alpha_j = st%occ(jst, ik) / st%smear%el_per_state
244 else
245 dsmear = max(1e-14_real64, st%smear%dsmear)
246 lr_alpha_j = max(st%smear%e_fermi + m_three*dsmear - st%eigenval(jst, ik), m_zero)
247 end if
248
249 pop_sub(lr_alpha_j)
250 end function lr_alpha_j
251
252#include "undef.F90"
253#include "real.F90"
254#include "linear_response_inc.F90"
255
256#include "undef.F90"
257#include "complex.F90"
258#include "linear_response_inc.F90"
259
260end module linear_response_oct_m
261
262!! Local Variables:
263!! mode: f90
264!! coding: utf-8
265!! End:
Copies a vector x, to a vector y.
Definition: lalg_basic.F90:220
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)