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 comm_oct_m
24 use debug_oct_m
26 use global_oct_m
27 use, intrinsic :: iso_fortran_env
29 use mesh_oct_m
34 use smear_oct_m
35 use space_oct_m
39
40 implicit none
41
42 private
43
44 public :: &
45 lr_t, &
46 lr_init, &
48 lr_zero, &
49 lr_copy, &
56 lr_alpha_j, &
57 lr_dealloc, &
65
66
67
68 type lr_t
69 ! Components are public by default
70 logical, private :: is_allocated, is_allocated_rho
71
73 real(real64), allocatable :: ddl_rho(:,:)
74 real(real64), allocatable :: ddl_psi(:,:,:,:)
75
77 complex(real64), allocatable :: zdl_rho(:,:)
78 complex(real64), allocatable :: zdl_psi(:,:,:,:)
79
81 complex(real64), allocatable :: dl_j(:,:,:)
82 real(real64), allocatable :: ddl_de(:,:)
83 real(real64), allocatable :: ddl_elf(:,:)
84 complex(real64), allocatable :: zdl_de(:,:)
85 complex(real64), allocatable :: zdl_elf(:,:)
86
87 end type lr_t
88
89contains
90
91 ! ---------------------------------------------------------
92 subroutine lr_init(lr)
93 type(lr_t), intent(out) :: lr
94
95 push_sub(lr_init)
96
97 lr%is_allocated = .false.
98 lr%is_allocated_rho = .false.
99
100 pop_sub(lr_init)
101
102 end subroutine lr_init
103
104
105
106 ! ---------------------------------------------------------
107 subroutine lr_allocate(lr, st, mesh, allocate_rho)
108 type(lr_t), intent(inout) :: lr
109 type(states_elec_t), intent(in) :: st
110 class(mesh_t), intent(in) :: mesh
111 logical, optional, intent(in) :: allocate_rho
112
113 push_sub(lr_allocate)
114
115 lr%is_allocated_rho = .true.
116 if (present(allocate_rho)) lr%is_allocated_rho = allocate_rho
117
118 if (states_are_complex(st)) then
119 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))
120 if (lr%is_allocated_rho) then
121 safe_allocate(lr%zdl_rho(1:mesh%np, 1:st%d%nspin))
122 end if
123 else
124 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))
125 if (lr%is_allocated_rho) then
126 safe_allocate(lr%ddl_rho(1:mesh%np, 1:st%d%nspin))
127 end if
128 end if
129
130 lr%is_allocated = .true.
131
132 call lr_zero(lr, st)
133
134 pop_sub(lr_allocate)
135
136 end subroutine lr_allocate
137
138
139
140 ! ---------------------------------------------------------
141 subroutine lr_zero(lr, st)
142 type(lr_t), intent(inout) :: lr
143 type(states_elec_t), intent(in) :: st
144
145 push_sub(lr_zero)
146
147 assert(lr%is_allocated)
148
149 if (states_are_complex(st)) then
150 lr%zdl_psi = m_zero
151 if (lr%is_allocated_rho) lr%zdl_rho = m_zero
152 else
153 lr%ddl_psi = m_zero
154 if (lr%is_allocated_rho) lr%ddl_rho = m_zero
155 end if
156
157 pop_sub(lr_zero)
158
159 end subroutine lr_zero
160
162 ! ---------------------------------------------------------
163 subroutine lr_dealloc(lr)
164 type(lr_t), intent(inout) :: lr
165
166 push_sub(lr_dealloc)
168 safe_deallocate_a(lr%ddl_psi)
169 safe_deallocate_a(lr%zdl_psi)
171 safe_deallocate_a(lr%ddl_rho)
172 safe_deallocate_a(lr%zdl_rho)
173
174 safe_deallocate_a(lr%dl_j)
175 safe_deallocate_a(lr%ddl_de)
176 safe_deallocate_a(lr%ddl_elf)
177 safe_deallocate_a(lr%zdl_de)
178 safe_deallocate_a(lr%zdl_elf)
179
180 lr%is_allocated = .false.
181 lr%is_allocated_rho = .false.
182
183 pop_sub(lr_dealloc)
184 end subroutine lr_dealloc
186
187 ! ---------------------------------------------------------
188 subroutine lr_copy(st, mesh, src, dest)
189 type(states_elec_t), intent(in) :: st
190 class(mesh_t), intent(in) :: mesh
191 type(lr_t), intent(in) :: src
192 type(lr_t), intent(inout) :: dest
193
194 integer :: ik, ist
195
196 push_sub(lr_copy)
197
198 if (src%is_allocated_rho .and. dest%is_allocated_rho) then
199 if (states_are_complex(st)) then
200 call lalg_copy(mesh%np, st%d%nspin, src%zdl_rho, dest%zdl_rho)
201 else
202 call lalg_copy(mesh%np, st%d%nspin, src%ddl_rho, dest%ddl_rho)
203 end if
204 else
205 if (dest%is_allocated_rho) then
206 if (states_are_complex(st)) then
207 dest%zdl_rho(:, :) = m_zero
208 else
209 dest%ddl_rho(:, :) = m_zero
210 end if
211 end if
212 end if
213
214 do ik = st%d%kpt%start, st%d%kpt%end
215 do ist = st%st_start, st%st_end
216 if (states_are_complex(st)) then
217 call lalg_copy(mesh%np_part, st%d%dim, src%zdl_psi(:, :, ist, ik), dest%zdl_psi(:, :, ist, ik))
218 else
219 call lalg_copy(mesh%np_part, st%d%dim, src%ddl_psi(:, :, ist, ik), dest%ddl_psi(:, :, ist, ik))
220 end if
221 end do
222 end do
223
224 pop_sub(lr_copy)
225
226 end subroutine lr_copy
227
228
229
230 ! ---------------------------------------------------------
231 logical function lr_is_allocated(this)
232 type(lr_t), intent(in) :: this
233
235 lr_is_allocated = this%is_allocated
236
237 pop_sub(lr_is_allocated)
238 end function lr_is_allocated
239
240
241
242 ! ---------------------------------------------------------
243 real(real64) function lr_alpha_j(st, jst, ik)
244 type(states_elec_t), intent(in) :: st
245 integer, intent(in) :: jst
246 integer, intent(in) :: ik
247
248 real(real64) :: dsmear
249
250 push_sub(lr_alpha_j)
251
252 if (st%smear%method == smear_fixed_occ) then
253 lr_alpha_j = st%occ(jst, ik) / st%smear%el_per_state
254 else
255 dsmear = max(1e-14_real64, st%smear%dsmear)
256 lr_alpha_j = max(st%smear%e_fermi + m_three*dsmear - st%eigenval(jst, ik), m_zero)
257 end if
258
259 pop_sub(lr_alpha_j)
260 end function lr_alpha_j
261
262#include "undef.F90"
263#include "real.F90"
264#include "linear_response_inc.F90"
265
266#include "undef.F90"
267#include "complex.F90"
268#include "linear_response_inc.F90"
269
270end module linear_response_oct_m
271
272!! Local Variables:
273!! mode: f90
274!! coding: utf-8
275!! End:
Copies a vector x, to a vector y.
Definition: lalg_basic.F90:186
real(real64), parameter, public m_zero
Definition: global.F90:188
real(real64), parameter, public m_three
Definition: global.F90:191
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 vec against all the occupied states. For details on the metallic part,...
subroutine, public lr_copy(st, mesh, src, dest)
subroutine, public lr_zero(lr, st)
subroutine, public zlr_dump_rho(lr, space, mesh, nspin, restart, rho_tag, ierr)
real(real64) function, public lr_alpha_j(st, jst, ik)
subroutine, public dlr_load_rho(dl_rho, space, mesh, nspin, restart, rho_tag, ierr)
subroutine, public dlr_dump_rho(lr, space, mesh, nspin, restart, rho_tag, ierr)
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 vec against all the occupied states. For details on the metallic part,...
subroutine, public zlr_build_dl_rho(mesh, st, lr, nsigma)
subroutine, public zlr_load_rho(dl_rho, space, 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)
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:118
integer, parameter, public smear_fixed_occ
Definition: smear.F90:171
pure logical function, public states_are_complex(st)
Describes mesh distribution to nodes.
Definition: mesh.F90:186
The states_elec_t class contains all electronic wave functions.
int true(void)