Octopus
projector.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
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 projector_oct_m
22 use accel_oct_m
23 use batch_oct_m
26 use debug_oct_m
27 use global_oct_m
28 use grid_oct_m
30 use ions_oct_m
33 use mesh_oct_m
35 use mpi_oct_m
38 use ps_oct_m
39 use pseudo_oct_m
46
47 implicit none
48
49 private
50 public :: &
68
69 integer, parameter :: MAX_NPROJECTIONS = 4
70 integer, parameter :: MAX_L = 5
71
82
83 type projector_t
84 private
85 integer, public :: type = proj_none
86 integer :: nprojections
87 integer, public :: lmax
88 integer, public :: lloc
89 integer :: nik
90 integer :: reltype
91
92 type(submesh_t), public :: sphere
93
94
97 type(hgh_projector_t), allocatable, public :: hgh_p(:, :)
98 type(kb_projector_t), allocatable, public :: kb_p(:, :)
99 type(rkb_projector_t), allocatable, public :: rkb_p(:, :)
100 complex(real64), allocatable, public :: phase(:, :, :)
101 end type projector_t
102
103contains
104
105 !---------------------------------------------------------
106 logical elemental function projector_is_null(p)
107 type(projector_t), intent(in) :: p
108
109 projector_is_null = (p%type == proj_none)
110 end function projector_is_null
111
112 !---------------------------------------------------------
113 logical elemental function projector_is(p, type)
114 type(projector_t), intent(in) :: p
115 integer, intent(in) :: type
116 projector_is = (p%type == type)
117 end function projector_is
118
119 !---------------------------------------------------------
120 subroutine projector_init(p, pseudo, namespace, dim, reltype)
121 type(projector_t), intent(inout) :: p
122 type(pseudopotential_t), target, intent(in) :: pseudo
123 type(namespace_t), intent(in) :: namespace
124 integer, intent(in) :: dim
125 integer, intent(in) :: reltype
126
127 type(ps_t), pointer :: ps
128
129 push_sub(projector_init)
130
131 ps => pseudo%ps
132
133 p%reltype = reltype
134 p%lmax = ps%lmax
135
136 if (ps%local) then
137 p%type = proj_none
138 pop_sub(projector_init)
139 return
140 end if
141
142 p%lloc = ps%llocal
143
144 p%type = ps%projector_type
145
146 if (p%type == proj_kb .and. reltype == 1) then
147 if (ps%relativistic_treatment == proj_j_dependent) then
148 p%type = proj_rkb
149 else
150 call messages_write("Spin-orbit coupling for species '"//trim(pseudo%get_label())//" is not available.")
151 call messages_warning(namespace=namespace)
152 end if
153 end if
154
155 select case (p%type)
156 case (proj_kb, proj_rkb)
157 p%nprojections = ps%kbc
158 case (proj_hgh)
159 p%nprojections = 3
160 case default
161 assert(.false.)
162 end select
163
165 end subroutine projector_init
166
167 !---------------------------------------------
168
169 subroutine projector_init_phases(this, dim, std, bnd, kpoints, vec_pot, vec_pot_var)
170 type(projector_t), intent(inout) :: this
171 integer, intent(in) :: dim
172 type(states_elec_dim_t), intent(in) :: std
173 type(boundaries_t), intent(in) :: bnd
174 type(kpoints_t), intent(in) :: kpoints
175 real(real64), optional, allocatable, intent(in) :: vec_pot(:)
176 real(real64), optional, allocatable, intent(in) :: vec_pot_var(:, :)
177
178 integer :: ns, iq, is, ikpoint
179 real(real64) :: kr, kpoint(dim)
180 integer :: nphase, iphase
181 real(real64), allocatable :: diff(:,:)
185 ns = this%sphere%np
186 nphase = 1
187 if (bnd%spiralBC) nphase = 3
188
189 if (.not. allocated(this%phase) .and. ns > 0) then
190 safe_allocate(this%phase(1:ns, 1:nphase, std%kpt%start:std%kpt%end))
191 end if
193 ! Construct vectors which translate the submesh point back into the unit cell:
194 ! The positions this%sphere%x can lie outside the unit cell, while
195 ! this%sphere%mesh%x(this%sphere%map(is), 1:ndim) by construction is the periodic image inside the unit cell.
196 ! If a point of the submesh is inside the unit cell, diff(:,is) = 0.
197 safe_allocate(diff(1:dim, 1:ns))
198 !$omp parallel private(ikpoint, kpoint, iphase, is, kr, iq)
199 !$omp do
200 do is = 1, ns
201 diff(:, is) = this%sphere%rel_x(:,is) + this%sphere%center - this%sphere%mesh%x(:, this%sphere%map(is))
202 end do
203
204 do iq = std%kpt%start, std%kpt%end
205 ikpoint = std%get_kpoint_index(iq)
206
207 ! if this fails, it probably means that sb is not compatible with std
208 assert(ikpoint <= kpoints_number(kpoints))
209
210 kpoint = m_zero
211 kpoint(1:dim) = kpoints%get_point(ikpoint)
212
213 do iphase = 1, nphase
214 !$omp do
215 do is = 1, ns
216 ! this is only the correction to the global phase, that can
217 ! appear if the sphere crossed the boundary of the cell. (diff=0 otherwise)
218
219 kr = sum(kpoint(1:dim)*diff(1:dim, is))
220
221 if (present(vec_pot)) then
222 if (allocated(vec_pot)) kr = kr + sum(vec_pot(1:dim)*diff(1:dim, is))
223 end if
224
225 if (present(vec_pot_var)) then
226 if (allocated(vec_pot_var)) kr = kr + sum(vec_pot_var(1:dim, this%sphere%map(is)) &
227 *(this%sphere%rel_x(:, is)+this%sphere%center))
228 end if
229
230 if (bnd%spiralBC .and. iphase > 1) then
231 kr = kr + (2*(iphase-1)-3)*sum(bnd%spiral_q(1:dim)*diff(1:dim, is))
232 end if
233
234 this%phase(is, iphase, iq) = exp(-m_zi*kr)
235 end do
236 !$omp end do nowait
237 end do
238 end do
239 !$omp end parallel
240
241 safe_deallocate_a(diff)
242
243 pop_sub(projector_init_phases)
244
245 end subroutine projector_init_phases
246
247 !---------------------------------------------------------
248 subroutine projector_build(p, ps, so_strength)
249 type(projector_t), intent(inout) :: p
250 class(pseudopotential_t), intent(in) :: ps
251 real(real64), intent(in) :: so_strength
252
253 integer :: ll, mm
254
255 push_sub(projector_build)
256
257 select case (p%type)
258
259 case (proj_hgh)
260 safe_allocate(p%hgh_p(0:p%lmax, -p%lmax:p%lmax))
261 do ll = 0, p%lmax
262 if (ll == p%lloc) cycle
263 do mm = -ll, ll
264 call hgh_projector_init(p%hgh_p(ll, mm), p%sphere, p%reltype, ps, ll, mm, so_strength)
265 end do
266 end do
267
268 case (proj_kb)
269 safe_allocate(p%kb_p(0:p%lmax, -p%lmax:p%lmax))
270 do ll = 0, p%lmax
271 if (ll == p%lloc) cycle
272 do mm = -ll, ll
273 call kb_projector_init(p%kb_p(ll, mm), p%sphere, ps, ll, mm)
274 end do
275 end do
276
277 case (proj_rkb)
278 safe_allocate(p%rkb_p(1:p%lmax, -p%lmax:p%lmax))
279 do ll = 1, p%lmax
280 if (ll == p%lloc) cycle
281 do mm = -ll, ll
282 call rkb_projector_init(p%rkb_p(ll, mm), p%sphere, ps, ll, mm, so_strength)
283 end do
284 end do
285 ! for rkb, l = 0 is a normal kb
286 if (p%lloc /= 0) then
287 safe_allocate(p%kb_p(1, 1))
288 call kb_projector_init(p%kb_p(1, 1), p%sphere, ps, 0, 0)
289 end if
290
291 end select
292
293 pop_sub(projector_build)
294 end subroutine projector_build
295
296 !---------------------------------------------------------
297 subroutine projector_end(p)
298 type(projector_t), intent(inout) :: p
299
300 integer :: ll, mm
301
302 push_sub(projector_end)
303
304 call submesh_end(p%sphere)
305
306 select case (p%type)
307 case (proj_hgh)
308 do ll = 0, p%lmax
309 if (ll == p%lloc) cycle
310 do mm = -ll, ll
311 call hgh_projector_end(p%hgh_p(ll, mm))
312 end do
313 end do
314 safe_deallocate_a(p%hgh_p)
315
316 case (proj_kb)
317 do ll = 0, p%lmax
318 if (ll == p%lloc) cycle
319 do mm = -ll, ll
320 call kb_projector_end(p%kb_p(ll, mm))
321 end do
322 end do
323 safe_deallocate_a(p%kb_p)
324
325 case (proj_rkb)
326 do ll = 1, p%lmax
327 if (ll == p%lloc) cycle
328 do mm = -ll, ll
329 call rkb_projector_end(p%rkb_p(ll, mm))
330 end do
331 end do
332 safe_deallocate_a(p%rkb_p)
333 if (p%lloc /= 0) then
334 call kb_projector_end(p%kb_p(1, 1))
335 safe_deallocate_a(p%kb_p)
336 end if
337
338 end select
339
340 p%type = proj_none
341
342 safe_deallocate_a(p%phase)
344 pop_sub(projector_end)
345 end subroutine projector_end
346
347#include "undef.F90"
348#include "real.F90"
349#include "projector_inc.F90"
350
351#include "undef.F90"
352#include "complex.F90"
353#include "projector_inc.F90"
354
355end module projector_oct_m
356
357
358
359!! Local Variables:
360!! mode: f90
361!! coding: utf-8
362!! End:
double exp(double __x) __attribute__((__nothrow__
This module implements batches of mesh functions.
Definition: batch.F90:135
This module implements common operations on batches of mesh functions.
Definition: batch_ops.F90:118
Module implementing boundary conditions in Octopus.
Definition: boundaries.F90:124
This module implements the underlying real-space grid.
Definition: grid.F90:119
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:120
real(real64) function, public dprojector_matrix_element(pj, bnd, dim, ik, psia, psib)
dprojector_matrix_element calculates <psia|projector|psib>
Definition: projector.F90:846
subroutine, public projector_build(p, ps, so_strength)
Definition: projector.F90:344
subroutine, public dprojector_commute_r(pj, mesh, bnd, dim, idir, ik, psi, cpsi)
This function calculates |cpsi> += [x, V_nl] |psi>
Definition: projector.F90:965
logical elemental function, public projector_is(p, type)
Definition: projector.F90:209
subroutine, public dproject_psi(mesh, bnd, pj, npj, dim, psi, ppsi, ik)
dproject_psi calculates the action of a projector on the psi wavefunction. The result is summed up to...
Definition: projector.F90:513
subroutine, public projector_init(p, pseudo, namespace, dim, reltype)
Definition: projector.F90:216
subroutine, public projector_init_phases(this, dim, std, bnd, kpoints, vec_pot, vec_pot_var)
Definition: projector.F90:265
subroutine, public dproject_psi_batch(mesh, bnd, pj, npj, dim, psib, ppsib)
To optimize the application of the non-local operator in parallel, the projectors are applied in step...
Definition: projector.F90:548
complex(real64) function, public zprojector_matrix_element(pj, bnd, dim, ik, psia, psib)
zprojector_matrix_element calculates <psia|projector|psib>
Definition: projector.F90:1555
subroutine, public zprojector_commute_r_allatoms_alldir(pj, ions, mesh, dim, bnd, ik, psi, cpsi)
This function calculates |cpsi> += [x, V_nl] |psi>
Definition: projector.F90:1759
subroutine, public projector_end(p)
Definition: projector.F90:393
subroutine, public zproject_psi(mesh, bnd, pj, npj, dim, psi, ppsi, ik)
zproject_psi calculates the action of a projector on the psi wavefunction. The result is summed up to...
Definition: projector.F90:1222
subroutine, public zproject_psi_batch(mesh, bnd, pj, npj, dim, psib, ppsib)
To optimize the application of the non-local operator in parallel, the projectors are applied in step...
Definition: projector.F90:1257
subroutine, public dprojector_commute_r_allatoms_alldir(pj, ions, mesh, dim, bnd, ik, psi, cpsi)
This function calculates |cpsi> += [x, V_nl] |psi>
Definition: projector.F90:1050
subroutine, public zprojector_commute_r(pj, mesh, bnd, dim, idir, ik, psi, cpsi)
This function calculates |cpsi> += [x, V_nl] |psi>
Definition: projector.F90:1674
logical elemental function, public projector_is_null(p)
Definition: projector.F90:202
Definition: ps.F90:116
integer, parameter, public proj_none
Definition: ps.F90:171
This module handles spin dimensions of the states and the k-point distribution.
The projector data type is intended to hold the local and non-local parts of the pseudopotentials....
Definition: projector.F90:178