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