Octopus
orbitalset.F90
Go to the documentation of this file.
1!! Copyright (C) 2016 N. Tancogne-Dejean
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
22 use accel_oct_m
23 use batch_oct_m
25 use blas_oct_m
26 use comm_oct_m
27 use debug_oct_m
29 use global_oct_m
31 use ions_oct_m
34 use math_oct_m
35 use mesh_oct_m
42 use types_oct_m
44
45 implicit none
46
47 private
48
49 public :: &
66
67 type orbitalset_t
68 ! Components are public by default
69 integer :: nn, ll, ii
70 real(real64) :: jj
71 integer :: norbs
72 integer :: ndim
73 integer :: iatom
74 type(submesh_t) :: sphere
75 complex(real64), allocatable :: phase(:,:)
76 ! !< if the sphere cross the border of the box
77 real(real64) :: Ueff
78 real(real64) :: Ubar, Jbar
79 real(real64) :: alpha
80 integer :: nneighbors
81 ! !< interaction is considered
82 real(real64), allocatable :: V_ij(:,:)
83 real(real64), allocatable :: coulomb_IIJJ(:,:,:,:,:)
84 complex(real64), allocatable :: zcoulomb_IIJJ(:,:,:,:,:,:,:)
85 integer, allocatable:: map_os(:)
86 complex(real64), allocatable :: phase_shift(:,:)
87
88 real(real64) :: radius
89 class(species_t), pointer :: spec => null()
90 integer :: spec_index
91
92 real(real64), allocatable :: dorb(:,:,:)
93 complex(real64), allocatable :: zorb(:,:,:)
94 complex(real64), allocatable :: eorb_submesh(:,:,:,:)
95 complex(real64), allocatable :: eorb_mesh(:,:,:,:)
96 integer :: ldorbs
97 type(accel_mem_t) :: dbuff_orb, zbuff_orb
98 type(accel_mem_t), allocatable :: buff_eorb (:)
99
100 logical :: use_submesh
101
102 type(poisson_t) :: poisson
103 contains
104 procedure :: set_species_index => orbitalset_set_species_index
105 end type orbitalset_t
106
107contains
108
109 subroutine orbitalset_init(this)
110 type(orbitalset_t), intent(inout) :: this
111
112 push_sub(orbitalset_init)
113
114 this%iatom = -1
115 this%nneighbors = 0
116 this%nn = 0
117 this%ll = 0
118 this%jj = m_one
119 this%ii = 0
120 this%iatom = 0
121 this%ndim = 1
122 this%spec_index = 0
123 this%norbs = 0
124
125 this%Ueff = m_zero
126 this%Ubar = m_zero
127 this%Jbar = m_zero
128 this%alpha = m_zero
129 this%radius = m_zero
130
131 pop_sub(orbitalset_init)
132 end subroutine orbitalset_init
133
134
135 subroutine orbitalset_end(this)
136 type(orbitalset_t), intent(inout) :: this
137
138 integer :: ik
139
140 push_sub(orbitalset_end)
141
142 safe_deallocate_a(this%phase)
143 safe_deallocate_a(this%dorb)
144 safe_deallocate_a(this%zorb)
145 safe_deallocate_a(this%eorb_submesh)
146 safe_deallocate_a(this%eorb_mesh)
147 nullify(this%spec)
148 call submesh_end(this%sphere)
149
150 safe_deallocate_a(this%V_ij)
151 safe_deallocate_a(this%coulomb_IIJJ)
152 safe_deallocate_a(this%map_os)
153 safe_deallocate_a(this%phase_shift)
154
155 if(accel_is_enabled()) then
156 call accel_release_buffer(this%dbuff_orb)
157 call accel_release_buffer(this%zbuff_orb)
158 if(allocated(this%buff_eorb)) then
159 do ik = lbound(this%buff_eorb, dim=1), ubound(this%buff_eorb, dim=1)
160 call accel_release_buffer(this%buff_eorb(ik))
161 end do
162 safe_deallocate_a(this%buff_eorb)
163 end if
164 end if
167 end subroutine orbitalset_end
169 subroutine orbitalset_set_jln(this, jj, ll, nn)
170 type(orbitalset_t), intent(inout) :: this
171 real(real64), intent(in) :: jj
172 integer, intent(in) :: ll, nn
174 push_sub(orbitalset_set_jln)
176 this%jj = jj
177 this%ll = ll
178 this%nn = nn
180 pop_sub(orbitalset_set_jln)
181 end subroutine orbitalset_set_jln
185 subroutine orbitalset_update_phase(os, dim, kpt, kpoints, spin_polarized, vec_pot, vec_pot_var, kpt_max)
186 type(orbitalset_t), intent(inout) :: os
187 integer, intent(in) :: dim
188 type(distributed_t), intent(in) :: kpt
189 type(kpoints_t), intent(in) :: kpoints
190 logical, intent(in) :: spin_polarized
191 real(real64), optional, allocatable, intent(in) :: vec_pot(:)
192 real(real64), optional, allocatable, intent(in) :: vec_pot_var(:, :)
193 integer, optional, intent(in) :: kpt_max
194
195 integer :: ns, iq, is, ikpoint, im, idim, kpt_end
196 real(real64) :: kr, kpoint(1:dim), dx(1:dim)
197 integer :: iorb
198
200
201 ns = os%sphere%np
203 kpt_end = kpt%end
204 if (present(kpt_max)) kpt_end = min(kpt_max, kpt_end)
205
206 do iq = kpt%start, kpt_end
207 !This is durty but avoids to refer to states_get_kpoint_index
208 if (spin_polarized) then
209 ikpoint = 1 + (iq - 1)/2
210 else
211 ikpoint = iq
212 end if
213
214 ! if this fails, it probably means that sb is not compatible with std
215 assert(ikpoint <= kpoints_number(kpoints))
216
217 kpoint(1:dim) = kpoints%get_point(ikpoint)
218
219 !$omp parallel do private(dx, kr)
220 do is = 1, ns
221 ! this is only the correction to the global phase, that can
222 ! appear if the sphere crossed the boundary of the cell.
223 dx = os%sphere%rel_x(1:dim, is) - os%sphere%mesh%x(os%sphere%map(is), 1:dim) + os%sphere%center(1:dim)
224 kr = dot_product(kpoint, dx)
225 if (present(vec_pot)) then
226 if (allocated(vec_pot)) kr = kr + dot_product(vec_pot, dx)
227 end if
229 if (present(vec_pot_var)) then
230 if (allocated(vec_pot_var)) kr = kr + sum(vec_pot_var(1:dim, os%sphere%map(is)) &
231 *(os%sphere%rel_x(1:dim, is)+os%sphere%center))
232 end if
233
234 os%phase(is, iq) = exp(m_zi*kr)
235 end do
236
237 if (.not. os%use_submesh) then
238 ! We now compute the so-called Bloch sum of the localized orbitals
239 do idim = 1, os%ndim
240 do im = 1, os%norbs
241 os%eorb_mesh(:, im, idim, iq) = m_z0
242 do is = 1, ns
243 os%eorb_mesh(os%sphere%map(is),im,idim,iq) = os%eorb_mesh(os%sphere%map(is),im,idim,iq) &
244 + os%zorb(is, idim, im) * os%phase(is, iq)
245 end do
246 end do
247 end do
248 else ! In the case of the isolated system, we still use the submesh
249 !$omp parallel private(idim, is)
250 do im = 1, os%norbs
251 do idim = 1, os%ndim
252 !$omp do simd
253 do is = 1, ns
254 os%eorb_submesh(is,idim,im,iq) = os%zorb(is,idim,im)*os%phase(is, iq)
255 end do
256 !$omp end do simd
257 end do
258 end do
259 !$omp end parallel
260 end if
261
262 if(accel_is_enabled() .and. os%ndim == 1) then
263 if(os%use_submesh) then
264 do iorb = 1, os%norbs
265 call accel_write_buffer(os%buff_eorb(iq), ns, os%eorb_submesh(:, 1, iorb, iq), offset = (iorb - 1)*os%ldorbs)
266 end do
267 else
268 do iorb = 1, os%norbs
269 call accel_write_buffer(os%buff_eorb(iq), os%sphere%mesh%np, &
270 os%eorb_mesh(:, iorb, 1, iq), offset = (iorb - 1)*os%ldorbs)
271 end do
272 end if
273 end if
274 end do
275
277 end subroutine orbitalset_update_phase
279
281 subroutine orbitalset_update_phase_shift(os, dim, kpt, kpoints, spin_polarized, vec_pot, vec_pot_var, kpt_max)
282 type(orbitalset_t), intent(inout) :: os
283 integer, intent(in) :: dim
284 type(distributed_t), intent(in) :: kpt
285 type(kpoints_t), intent(in) :: kpoints
286 logical, intent(in) :: spin_polarized
287 real(real64), optional, allocatable, intent(in) :: vec_pot(:)
288 real(real64), optional, allocatable, intent(in) :: vec_pot_var(:, :)
289 integer, optional, intent(in) :: kpt_max
290
291 integer :: iq, ikpoint
292 real(real64) :: kr, kpoint(dim), dx(dim)
293 integer :: inn, kpt_end
294
296
297 kpt_end = kpt%end
298 if(present(kpt_max)) kpt_end = min(kpt_max, kpt_end)
299
300 do iq = kpt%start, kpt_end
301 !This is durty but avoids to refer to states_get_kpoint_index
302 if(spin_polarized) then
303 ikpoint = 1 + (iq - 1)/2
304 else
305 ikpoint = iq
306 end if
307
308 ! if this fails, it probably means that sb is not compatible with std
309 assert(ikpoint <= kpoints_number(kpoints))
310
311 kpoint(1:dim) = kpoints%get_point(ikpoint)
312
313 if (os%nneighbors > 0) then
314 do inn = 1, os%nneighbors
315 dx(1:dim) = os%V_ij(inn,1:dim)
316 kr = sum(kpoint(1:dim)*dx(1:dim))
317 if (present(vec_pot)) then
318 if (allocated(vec_pot)) kr = kr + sum(vec_pot(1:dim)*dx(1:dim))
319 end if
320
321 !At the moment the uniform vector potential is in vec_pot_var
322 if (present(vec_pot_var)) then
323 if (allocated(vec_pot_var)) kr = kr + sum(vec_pot_var(1:dim, 1)*dx(1:dim))
324 end if
325
326 !The sign is different as this is applied on the wavefunction and not the orbitals
327 os%phase_shift(inn, iq) = exp(-m_zi*kr)
328 end do
329 end if
330 end do
331
332
334 end subroutine orbitalset_update_phase_shift
335
336 ! ---------------------------------------------------------
342 subroutine orbitalset_set_species_index(os, ions)
343 class(orbitalset_t), intent(inout) :: os
344 type(ions_t), intent(in) :: ions
345
346 integer :: ja
347
349
350 os%spec_index = os%spec%get_index()
351 do ja = 1, ions%natoms
352 if(ions%atom(ja)%species == os%spec) then
353 os%spec_index = min(os%spec_index, ions%atom(ja)%species%get_index())
354 end if
355 end do
356
358 end subroutine orbitalset_set_species_index
359
360#include "undef.F90"
361#include "real.F90"
362#include "orbitalset_inc.F90"
363
364#include "undef.F90"
365#include "complex.F90"
366#include "orbitalset_inc.F90"
367
368end module orbitalset_oct_m
double exp(double __x) __attribute__((__nothrow__
subroutine, public accel_release_buffer(this)
Definition: accel.F90:1246
pure logical function, public accel_is_enabled()
Definition: accel.F90:400
This module implements batches of mesh functions.
Definition: batch.F90:133
This module implements common operations on batches of mesh functions.
Definition: batch_ops.F90:116
This module contains interfaces for BLAS routines You should not use these routines directly....
Definition: blas.F90:118
real(real64), parameter, public m_zero
Definition: global.F90:187
complex(real64), parameter, public m_z0
Definition: global.F90:197
complex(real64), parameter, public m_zi
Definition: global.F90:201
real(real64), parameter, public m_one
Definition: global.F90:188
integer pure function, public kpoints_number(this)
Definition: kpoints.F90:1099
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:115
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:118
subroutine, public zorbitalset_get_position_matrix_elem(os, ndim, psib, idir, dot)
subroutine, public orbitalset_update_phase_shift(os, dim, kpt, kpoints, spin_polarized, vec_pot, vec_pot_var, kpt_max)
Build the phase shift for the intersite interaction.
Definition: orbitalset.F90:375
subroutine, public dorbitalset_get_coeff_batch(os, ndim, psib, dot)
Definition: orbitalset.F90:595
subroutine orbitalset_set_species_index(os, ions)
Set the species index for a given orbital set.
Definition: orbitalset.F90:436
subroutine, public orbitalset_init(this)
Definition: orbitalset.F90:203
subroutine, public orbitalset_end(this)
Definition: orbitalset.F90:229
subroutine, public dorbitalset_add_to_batch(os, ndim, psib, weight)
Definition: orbitalset.F90:739
subroutine, public dorbitalset_get_position_matrix_elem(os, ndim, psib, idir, dot)
Definition: orbitalset.F90:993
subroutine, public zorbitalset_add_to_batch(os, ndim, psib, weight)
subroutine, public orbitalset_update_phase(os, dim, kpt, kpoints, spin_polarized, vec_pot, vec_pot_var, kpt_max)
Build the phase correction to the global phase in case the orbital crosses the border of the simulato...
Definition: orbitalset.F90:279
subroutine, public dorbitalset_get_coefficients(os, ndim, psi, ik, has_phase, dot, reduce)
Definition: orbitalset.F90:521
subroutine, public dorbitalset_get_coeff_batch_accel(os, ndim, psib, dot)
Definition: orbitalset.F90:632
subroutine, public orbitalset_set_jln(this, jj, ll, nn)
Definition: orbitalset.F90:263
subroutine, public zorbitalset_get_coeff_batch_accel(os, ndim, psib, dot)
subroutine, public zorbitalset_get_coeff_batch(os, ndim, psib, dot)
subroutine, public zorbitalset_get_coefficients(os, ndim, psi, ik, has_phase, dot, reduce)
subroutine, public submesh_end(this)
Definition: submesh.F90:737
Distribution of N instances over mpi_grpsize processes, for the local rank mpi_grprank....