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
47
48 implicit none
49
50 private
51 public :: &
70
71 integer, parameter :: MAX_NPROJECTIONS = 4
72 integer, parameter :: MAX_L = 5
73
84
85 type projector_t
86 private
87 integer, public :: type = proj_none
88 integer :: nprojections
89 integer, public :: lmax
90 integer, public :: lloc
91 integer :: nik
92 integer :: reltype
93
94 type(submesh_t), public :: sphere
95
96
99 type(hgh_projector_t), allocatable, public :: hgh_p(:, :)
100 type(kb_projector_t), allocatable, public :: kb_p(:, :)
101 type(rkb_projector_t), allocatable, public :: rkb_p(:, :)
102 complex(real64), allocatable, public :: phase(:, :, :)
103 end type projector_t
104
105contains
106
107 !---------------------------------------------------------
108 logical elemental function projector_is_null(p)
109 type(projector_t), intent(in) :: p
110
111 projector_is_null = (p%type == proj_none)
112 end function projector_is_null
113
114 !---------------------------------------------------------
115 logical elemental function projector_is(p, type)
116 type(projector_t), intent(in) :: p
117 integer, intent(in) :: type
118 projector_is = (p%type == type)
119 end function projector_is
120
121 !---------------------------------------------------------
122 subroutine projector_init(p, pseudo, namespace, dim, reltype)
123 type(projector_t), intent(inout) :: p
124 type(pseudopotential_t), target, intent(in) :: pseudo
125 type(namespace_t), intent(in) :: namespace
126 integer, intent(in) :: dim
127 integer, intent(in) :: reltype
128
129 type(ps_t), pointer :: ps
130
131 push_sub(projector_init)
132
133 ps => pseudo%ps
134
135 p%reltype = reltype
136 p%lmax = ps%lmax
137
138 if (ps%local) then
139 p%type = proj_none
140 pop_sub(projector_init)
141 return
142 end if
143
144 p%lloc = ps%llocal
145
146 p%type = ps%projector_type
147
148 if (p%type == proj_kb .and. reltype == 1) then
149 if (ps%relativistic_treatment == proj_j_dependent) then
150 p%type = proj_rkb
151 else
152 call messages_write("Spin-orbit coupling for species '"//trim(pseudo%get_label())//" is not available.")
153 call messages_warning(namespace=namespace)
154 end if
155 end if
156
157 select case (p%type)
158 case (proj_kb, proj_rkb)
159 p%nprojections = ps%kbc
160 case (proj_hgh)
161 p%nprojections = 3
162 case default
163 assert(.false.)
164 end select
165
167 end subroutine projector_init
168
169 !---------------------------------------------
170
171 subroutine projector_init_phases(this, dim, std, bnd, kpoints, vec_pot, vec_pot_var)
172 type(projector_t), intent(inout) :: this
173 integer, intent(in) :: dim
174 type(states_elec_dim_t), intent(in) :: std
175 type(boundaries_t), intent(in) :: bnd
176 type(kpoints_t), intent(in) :: kpoints
177 real(real64), optional, allocatable, intent(in) :: vec_pot(:)
178 real(real64), optional, allocatable, intent(in) :: vec_pot_var(:, :)
179
180 integer :: ns, iq, is, ikpoint
181 real(real64) :: kr, kpoint(dim)
182 integer :: nphase, iphase
183 real(real64), allocatable :: diff(:,:)
187 ns = this%sphere%np
188 nphase = 1
189 if (bnd%spiralBC) nphase = 3
190
191 if (.not. allocated(this%phase) .and. ns > 0) then
192 safe_allocate(this%phase(1:ns, 1:nphase, std%kpt%start:std%kpt%end))
193 end if
195 ! Construct vectors which translate the submesh point back into the unit cell:
196 ! The positions this%sphere%x can lie outside the unit cell, while
197 ! this%sphere%mesh%x(this%sphere%map(is), 1:ndim) by construction is the periodic image inside the unit cell.
198 ! If a point of the submesh is inside the unit cell, diff(:,is) = 0.
199 safe_allocate(diff(1:dim, 1:ns))
200 !$omp parallel private(ikpoint, kpoint, iphase, is, kr, iq)
201 !$omp do
202 do is = 1, ns
203 diff(:, is) = this%sphere%rel_x(:,is) + this%sphere%center - this%sphere%mesh%x(:, this%sphere%map(is))
204 end do
205
206 do iq = std%kpt%start, std%kpt%end
207 ikpoint = std%get_kpoint_index(iq)
208
209 ! if this fails, it probably means that sb is not compatible with std
210 assert(ikpoint <= kpoints_number(kpoints))
211
212 kpoint = m_zero
213 kpoint(1:dim) = kpoints%get_point(ikpoint)
214
215 do iphase = 1, nphase
216 !$omp do
217 do is = 1, ns
218 ! this is only the correction to the global phase, that can
219 ! appear if the sphere crossed the boundary of the cell. (diff=0 otherwise)
220
221 kr = sum(kpoint(1:dim)*diff(1:dim, is))
222
223 if (present(vec_pot)) then
224 if (allocated(vec_pot)) kr = kr + sum(vec_pot(1:dim)*diff(1:dim, is))
225 end if
226
227 if (present(vec_pot_var)) then
228 if (allocated(vec_pot_var)) kr = kr + sum(vec_pot_var(1:dim, this%sphere%map(is)) &
229 *(this%sphere%rel_x(:, is)+this%sphere%center))
230 end if
231
232 if (bnd%spiralBC .and. iphase > 1) then
233 kr = kr + (2*(iphase-1)-3)*sum(bnd%spiral_q(1:dim)*diff(1:dim, is))
234 end if
235
236 this%phase(is, iphase, iq) = exp(-m_zi*kr)
237 end do
238 !$omp end do nowait
239 end do
240 end do
241 !$omp end parallel
242
243 safe_deallocate_a(diff)
244
245 pop_sub(projector_init_phases)
246
247 end subroutine projector_init_phases
248
249 !---------------------------------------------------------
250 subroutine projector_build(p, ps, so_strength)
251 type(projector_t), intent(inout) :: p
252 class(pseudopotential_t), intent(in) :: ps
253 real(real64), intent(in) :: so_strength
254
255 integer :: ll, mm
256
257 push_sub(projector_build)
258
259 select case (p%type)
260
261 case (proj_hgh)
262 safe_allocate(p%hgh_p(0:p%lmax, -p%lmax:p%lmax))
263 do ll = 0, p%lmax
264 if (ll == p%lloc) cycle
265 do mm = -ll, ll
266 call hgh_projector_init(p%hgh_p(ll, mm), p%sphere, p%reltype, ps, ll, mm, so_strength)
267 end do
268 end do
269
270 case (proj_kb)
271 safe_allocate(p%kb_p(0:p%lmax, -p%lmax:p%lmax))
272 do ll = 0, p%lmax
273 if (ll == p%lloc) cycle
274 do mm = -ll, ll
275 call kb_projector_init(p%kb_p(ll, mm), p%sphere, ps, ll, mm)
276 end do
277 end do
278
279 case (proj_rkb)
280 safe_allocate(p%rkb_p(1:p%lmax, -p%lmax:p%lmax))
281 do ll = 1, p%lmax
282 if (ll == p%lloc) cycle
283 do mm = -ll, ll
284 call rkb_projector_init(p%rkb_p(ll, mm), p%sphere, ps, ll, mm, so_strength)
285 end do
286 end do
287 ! for rkb, l = 0 is a normal kb
288 if (p%lloc /= 0) then
289 safe_allocate(p%kb_p(1, 1))
290 call kb_projector_init(p%kb_p(1, 1), p%sphere, ps, 0, 0)
291 end if
292
293 end select
294
295 pop_sub(projector_build)
296 end subroutine projector_build
297
298 !---------------------------------------------------------
305 subroutine projector_check_discretization(pseudo, sm, namespace)
306 class(pseudopotential_t), target, intent(in) :: pseudo
307 type(submesh_t), intent(in) :: sm
308 type(namespace_t), intent(in) :: namespace
309
310 integer :: ll, mm, ic, ir, nc
311 real(real64) :: rc, dr, rr, norm_rad, norm_grid, dev
312 real(real64), allocatable :: uv(:)
313 type(ps_t), pointer :: ps
314
315 integer, parameter :: quad_points = 2000
317 real(real64), parameter :: norm_dev_warning = 0.05_real64
318
320
321 ps => pseudo%ps
322
323 dev = m_zero
324 safe_allocate(uv(1:max(sm%np, 1)))
325
326 do ll = 0, ps%lmax
327 if (ll == ps%llocal) cycle
328
329 nc = ps%kbc
330 if (ps%projector_type == proj_kb) nc = min(nc, ps%projectors_per_l(ll+1))
331
332 do ic = 1, nc
333 ! Norm^2 of the projector on the radial grid
334 rc = ps%kb(ll, ic)%x_threshold
335 if (rc <= m_epsilon) cycle
336 dr = rc/quad_points
337 norm_rad = m_zero
338 do ir = 1, quad_points
339 rr = (ir - m_half)*dr
340 norm_rad = norm_rad + spline_eval(ps%kb(ll, ic), rr)**2 * rr**2
341 end do
342 norm_rad = norm_rad*dr
343 if (norm_rad <= 1.0e-10_real64) cycle
344
345 ! Norm^2 of the same projector discretized on the grid, for all values of m
346 do mm = -ll, ll
347 call pseudopotential_real_nl_projector(pseudo, sm%np, sm%rel_x, sm%r, ll, mm, ic, uv)
348 norm_grid = dsm_nrm2(sm, uv)**2
349 dev = max(dev, abs(norm_grid - norm_rad)/norm_rad)
350 end do
351 end do
352 end do
353
354 safe_deallocate_a(uv)
355
356 write(message(1), '(a,es9.2)') "Debug: projector discretization error for species '" &
357 //trim(pseudo%get_label())//"' = ", dev
358 call messages_info(1, namespace=namespace, debug_only=.true.)
359
360 if (dev > norm_dev_warning) then
361 write(message(1), '(a)') "The nonlocal projectors of species '"//trim(pseudo%get_label())//"'"
362 write(message(2), '(a)') "are not well resolved on the real-space grid: at least one projector norm"
363 write(message(3), '(a,f8.1,a)') "deviates by ", dev*100, "% from its radial-grid value."
364 write(message(4), '(a)') "This can produce spurious (ghost) states. Please reduce the grid Spacing."
365 call messages_warning(4, namespace=namespace)
366 end if
367
369 end subroutine projector_check_discretization
370
371 !---------------------------------------------------------
372 subroutine projector_end(p)
373 type(projector_t), intent(inout) :: p
374
375 integer :: ll, mm
376
377 push_sub(projector_end)
378
379 call submesh_end(p%sphere)
380
381 select case (p%type)
382 case (proj_hgh)
383 do ll = 0, p%lmax
384 if (ll == p%lloc) cycle
385 do mm = -ll, ll
386 call hgh_projector_end(p%hgh_p(ll, mm))
387 end do
388 end do
389 safe_deallocate_a(p%hgh_p)
390
391 case (proj_kb)
392 do ll = 0, p%lmax
393 if (ll == p%lloc) cycle
394 do mm = -ll, ll
395 call kb_projector_end(p%kb_p(ll, mm))
396 end do
397 end do
398 safe_deallocate_a(p%kb_p)
399
400 case (proj_rkb)
401 do ll = 1, p%lmax
402 if (ll == p%lloc) cycle
403 do mm = -ll, ll
404 call rkb_projector_end(p%rkb_p(ll, mm))
405 end do
406 end do
407 safe_deallocate_a(p%rkb_p)
408 if (p%lloc /= 0) then
409 call kb_projector_end(p%kb_p(1, 1))
410 safe_deallocate_a(p%kb_p)
411 end if
412
413 end select
414
415 p%type = proj_none
416
417 safe_deallocate_a(p%phase)
418
419 pop_sub(projector_end)
420 end subroutine projector_end
421
422#include "undef.F90"
423#include "real.F90"
424#include "projector_inc.F90"
425
426#include "undef.F90"
427#include "complex.F90"
428#include "projector_inc.F90"
429
430end module projector_oct_m
431
432
433
434!! Local Variables:
435!! mode: f90
436!! coding: utf-8
437!! 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:920
subroutine, public projector_build(p, ps, so_strength)
Definition: projector.F90:346
subroutine, public dprojector_commute_r(pj, mesh, bnd, dim, idir, ik, psi, cpsi)
This function calculates |cpsi> += [x, V_nl] |psi>
Definition: projector.F90:1039
logical elemental function, public projector_is(p, type)
Definition: projector.F90:211
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:588
subroutine, public projector_init(p, pseudo, namespace, dim, reltype)
Definition: projector.F90:218
subroutine, public projector_init_phases(this, dim, std, bnd, kpoints, vec_pot, vec_pot_var)
Definition: projector.F90:267
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:623
complex(real64) function, public zprojector_matrix_element(pj, bnd, dim, ik, psia, psib)
zprojector_matrix_element calculates <psia|projector|psib>
Definition: projector.F90:1628
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:1832
subroutine, public projector_end(p)
Definition: projector.F90:468
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:1296
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:1331
subroutine, public projector_check_discretization(pseudo, sm, namespace)
Check how well the nonlocal projectors are resolved on the real-space grid.
Definition: projector.F90:401
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:1124
subroutine, public zprojector_commute_r(pj, mesh, bnd, dim, idir, ik, psi, cpsi)
This function calculates |cpsi> += [x, V_nl] |psi>
Definition: projector.F90:1747
logical elemental function, public projector_is_null(p)
Definition: projector.F90:204
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:180
int true(void)