Octopus
lda_u.F90
Go to the documentation of this file.
1!! Copyright (C) 2016-2020 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
21module lda_u_oct_m
22 use accel_oct_m
25 use batch_oct_m
27 use comm_oct_m
28 use debug_oct_m
32 use energy_oct_m
33 use global_oct_m
34 use grid_oct_m
36 use ions_oct_m
40 use loct_oct_m
43 use math_oct_m
44 use mesh_oct_m
47 use mpi_oct_m
53 use parser_oct_m
55 use phase_oct_m
58 use space_oct_m
65 use types_oct_m
68
69 implicit none
70
71 private
72
73 public :: &
74 lda_u_t, &
75 lda_u_init, &
82 lda_u_end, &
100 dlda_u_force, &
101 zlda_u_force, &
102 dlda_u_rvu, &
103 zlda_u_rvu, &
108
109
110 integer, public, parameter :: &
111 DFT_U_NONE = 0, &
112 dft_u_empirical = 1, &
113 dft_u_acbn0 = 2
114
115 integer, public, parameter :: &
116 DFT_U_FLL = 0, &
117 dft_u_amf = 1, &
118 dft_u_mix = 2
119
120
123 type lda_u_t
124 private
125 integer, public :: level = dft_u_none
126
127 ! DFT+U basic variables
128 real(real64), allocatable, public :: dn(:,:,:,:)
129 real(real64), allocatable :: dV(:,:,:,:)
130
131 ! ACBN0 variables
132 complex(real64), allocatable, public :: zn(:,:,:,:)
133 complex(real64), allocatable :: zV(:,:,:,:)
134 real(real64), allocatable, public :: dn_alt(:,:,:,:)
135 complex(real64), allocatable, public :: zn_alt(:,:,:,:)
136
137 real(real64), allocatable :: renorm_occ(:,:,:,:,:)
138
139 ! Coulomb integrales
140 real(real64), allocatable, public :: coulomb(:,:,:,:,:)
141 ! !<(for the ACBN0 functional)
142 complex(real64), allocatable, public :: zcoulomb(:,:,:,:,:,:,:)
143 ! !< (for the ACBN0 functional with spinors)
144
145 type(orbitalbasis_t), public :: basis
146 type(orbitalset_t), pointer, public :: orbsets(:) => null()
147 integer, public :: norbsets = 0
148
149 integer, public :: nspins = 0
150 integer, public :: spin_channels = 0
151 integer :: nspecies = 0
152 integer, public :: maxnorbs = 0
153 integer :: max_np = 0
154
155 logical :: useAllOrbitals = .false.
156 logical :: skipSOrbitals = .true.
157 logical :: freeze_occ = .false.
158 logical :: freeze_u = .false.
159 logical, public :: intersite = .false.
160 real(real64) :: intersite_radius = m_zero
161 logical, public :: basisfromstates = .false.
162 real(real64) :: acbn0_screening = m_one
163 integer, allocatable :: basisstates(:)
164 integer, allocatable :: basisstates_os(:)
165 ! !! the state specified in basisstate(:)
166 logical :: rot_inv = .false.
167 integer :: double_couting = dft_u_fll
168 integer :: sm_poisson = sm_poisson_direct
169 real(real64), allocatable :: dc_alpha(:)
170
171 type(lattice_vectors_t), pointer :: latt
172
173 type(distributed_t) :: orbs_dist
174 type(mpi_grp_t) :: grp
175
176 ! Intersite interaction variables
177 integer, public :: maxneighbors = 0
178 real(real64), allocatable, public :: dn_ij(:,:,:,:,:), dn_alt_ij(:,:,:,:,:), dn_alt_ii(:,:,:,:,:)
179 complex(real64), allocatable, public :: zn_ij(:,:,:,:,:), zn_alt_ij(:,:,:,:,:), zn_alt_ii(:,:,:,:,:)
180
181 ! Symmetrization-related variables
182 logical :: symmetrize_occ_matrices
183 integer, allocatable :: inv_map_symm(:,:)
184 integer :: nsym
185 real(real64), allocatable :: symm_weight(:,:,:,:)
186 end type lda_u_t
187
188contains
189
190 ! ---------------------------------------------------------
191 subroutine lda_u_init(this, namespace, space, level, gr, ions, st, mc, kpoints)
192 type(lda_u_t), target, intent(inout) :: this
193 type(namespace_t), intent(in) :: namespace
194 class(space_t), intent(in) :: space
195 integer, intent(in) :: level
196 type(grid_t), intent(in) :: gr
197 type(ions_t), target, intent(in) :: ions
198 type(states_elec_t), intent(in) :: st
199 type(multicomm_t), intent(in) :: mc
200 type(kpoints_t), intent(in) :: kpoints
201
202 integer :: is, ierr
203 type(block_t) :: blk
204
205 push_sub(lda_u_init)
206
207 assert(.not. (level == dft_u_none))
208
209 call messages_print_with_emphasis(msg="DFT+U", namespace=namespace)
210 if (gr%parallel_in_domains) call messages_experimental("dft+u parallel in domains", namespace=namespace)
211 this%level = level
212
213 this%latt => ions%latt
214
215 this%grp = mc%master_grp
216
217 !%Variable DFTUBasisFromStates
218 !%Type logical
219 !%Default no
220 !%Section Hamiltonian::DFT+U
221 !%Description
222 !% If set to yes, Octopus will construct the localized basis from
223 !% user-defined states. The states are taken at the Gamma point (or the first k-point of the
224 !% states in the restart_proj folder.
225 !% The states are defined via the block DFTUBasisStates
226 !%End
227 call parse_variable(namespace, 'DFTUBasisFromStates', .false., this%basisfromstates)
228 if (this%basisfromstates) call messages_experimental("DFTUBasisFromStates", namespace=namespace)
230 !%Variable DFTUDoubleCounting
231 !%Type integer
232 !%Default dft_u_fll
233 !%Section Hamiltonian::DFT+U
234 !%Description
235 !% This variable selects which DFT+U
236 !% double counting term is used.
237 !%Option dft_u_fll 0
238 !% (Default) The Fully Localized Limit (FLL)
239 !%Option dft_u_amf 1
240 !% (Experimental) Around mean field double counting, as defined in PRB 44, 943 (1991) and PRB 49, 14211 (1994).
241 !%Option dft_u_mix 2
242 !% (Experimental) Mixed double countind term as introduced by Petukhov et al., PRB 67, 153106 (2003).
243 !% This recovers the FLL and AMF as limiting cases.
244 !%End
245 call parse_variable(namespace, 'DFTUDoubleCounting', dft_u_fll, this%double_couting)
246 call messages_print_var_option('DFTUDoubleCounting', this%double_couting, namespace=namespace)
247 if (this%double_couting /= dft_u_fll) call messages_experimental("DFTUDoubleCounting /= dft_u_ffl", namespace=namespace)
248 if (st%d%ispin == spinors .and. this%double_couting /= dft_u_fll) then
249 call messages_not_implemented("AMF and MIX double counting with spinors", namespace=namespace)
250 end if
252 !%Variable DFTUPoissonSolver
253 !%Type integer
254 !%Section Hamiltonian::DFT+U
255 !%Description
256 !% This variable selects which Poisson solver
257 !% is used to compute the Coulomb integrals over a submesh.
258 !% These are non-periodic Poisson solvers.
259 !% The FFT Poisson solver with spherical cutoff is used by default.
260 !%
261 !%Option dft_u_poisson_direct 0
262 !% Direct Poisson solver. Slow but working in all cases.
263 !%Option dft_u_poisson_isf 1
264 !% (Experimental) ISF Poisson solver on a submesh.
265 !% This does not work for non-orthogonal cells nor domain parallelization.
266 !%Option dft_u_poisson_psolver 2
267 !% (Experimental) PSolver Poisson solver on a submesh.
268 !% This does not work for non-orthogonal cells nor domain parallelization.
269 !% Requires the PSolver external library.
270 !%Option dft_u_poisson_fft 3
271 !% (Default) FFT Poisson solver on a submesh.
272 !% This uses the 0D periodic version of the FFT kernels.
273 !%End
274 call parse_variable(namespace, 'DFTUPoissonSolver', sm_poisson_fft, this%sm_poisson)
275 call messages_print_var_option('DFTUPoissonSolver', this%sm_poisson, namespace=namespace)
276 if (this%sm_poisson /= sm_poisson_direct .and. this%sm_poisson /= sm_poisson_fft) then
277 call messages_experimental("DFTUPoissonSolver different from dft_u_poisson_direct", namespace=namespace)
278 call messages_experimental("and dft_u_poisson_fft", namespace=namespace)
279 end if
280 if (this%sm_poisson == sm_poisson_isf) then
281 if (gr%parallel_in_domains) then
282 call messages_not_implemented("DFTUPoissonSolver=dft_u_poisson_isf with domain parallelization", namespace=namespace)
283 end if
284 if (ions%latt%nonorthogonal) then
285 call messages_not_implemented("DFTUPoissonSolver=dft_u_poisson_isf with non-orthogonal cells", namespace=namespace)
286 end if
287 end if
288 if (this%sm_poisson == sm_poisson_psolver) then
289#if !(defined HAVE_PSOLVER)
290 message(1) = "The PSolver Poisson solver cannot be used since the code was not compiled with the PSolver library."
291 call messages_fatal(1, namespace=namespace)
292#endif
293 if (gr%parallel_in_domains) then
294 call messages_not_implemented("DFTUPoissonSolver=dft_u_poisson_psolver with domain parallelization", namespace=namespace)
295 end if
296 if (ions%latt%nonorthogonal) then
297 call messages_not_implemented("DFTUPoissonSolver=dft_u_poisson_psolver with non-orthogonal cells", namespace=namespace)
298 end if
299 end if
300
301 if (this%level == dft_u_acbn0) then
302 !%Variable UseAllAtomicOrbitals
303 !%Type logical
304 !%Default no
305 !%Section Hamiltonian::DFT+U
306 !%Description
307 !% If set to yes, Octopus will determine the effective U for all atomic orbitals
308 !% from the peusopotential. Only available with ACBN0 functional.
309 !% It is strongly recommended to set AOLoewdin=yes when using the option.
310 !%End
311 call parse_variable(namespace, 'UseAllAtomicOrbitals', .false., this%useAllOrbitals)
312 if (this%useAllOrbitals) call messages_experimental("UseAllAtomicOrbitals", namespace=namespace)
313
314 !%Variable SkipSOrbitals
315 !%Type logical
316 !%Default no
317 !%Section Hamiltonian::DFT+U
318 !%Description
319 !% If set to yes, Octopus will determine the effective U for all atomic orbitals
320 !% from the peusopotential but s orbitals. Only available with ACBN0 functional.
321 !%End
322 call parse_variable(namespace, 'SkipSOrbitals', .true., this%skipSOrbitals)
323 if (.not. this%SkipSOrbitals) call messages_experimental("SkipSOrbitals", namespace=namespace)
324
325 !%Variable ACBN0Screening
326 !%Type float
327 !%Default 1.0
328 !%Section Hamiltonian::DFT+U
329 !%Description
330 !% If set to 0, no screening will be included in the ACBN0 functional, and the U
331 !% will be estimated from bare Hartree-Fock. If set to 1 (default), the full screening
332 !% of the U, as defined in the ACBN0 functional, is used.
333 !%End
334 call parse_variable(namespace, 'ACBN0Screening', m_one, this%acbn0_screening)
335 call messages_print_var_value('ACBN0Screening', this%acbn0_screening, namespace=namespace)
336
337 !%Variable ACBN0RotationallyInvariant
338 !%Type logical
339 !%Section Hamiltonian::DFT+U
340 !%Description
341 !% If set to yes, Octopus will use for U and J a formula which is rotationally invariant.
342 !% This is different from the original formula for U and J.
343 !% This is activated by default, except in the case of spinors, as this is not yet implemented in this case.
344 !%End
345 call parse_variable(namespace, 'ACBN0RotationallyInvariant', st%d%ispin /= spinors, this%rot_inv)
346 call messages_print_var_value('ACBN0RotationallyInvariant', this%rot_inv, namespace=namespace)
347 if (this%rot_inv .and. st%d%ispin == spinors) then
348 call messages_not_implemented("Rotationally invariant ACBN0 with spinors", namespace=namespace)
349 end if
350
351 !%Variable ACBN0IntersiteInteraction
352 !%Type logical
353 !%Default no
354 !%Section Hamiltonian::DFT+U
355 !%Description
356 !% If set to yes, Octopus will determine the effective intersite interaction V
357 !% Only available with ACBN0 functional.
358 !% It is strongly recommended to set AOLoewdin=yes when using the option.
359 !%End
360 call parse_variable(namespace, 'ACBN0IntersiteInteraction', .false., this%intersite)
361 call messages_print_var_value('ACBN0IntersiteInteraction', this%intersite, namespace=namespace)
362 if (this%intersite) call messages_experimental("ACBN0IntersiteInteraction", namespace=namespace)
363
364 if (this%intersite) then
365
366 !This is a non local operator. To make this working, one probably needs to apply the
367 ! symmetries to the generalized occupation matrices
368 if (kpoints%use_symmetries) then
369 call messages_not_implemented("Intersite interaction with kpoint symmetries", namespace=namespace)
370 end if
371
372 !%Variable ACBN0IntersiteCutoff
373 !%Type float
374 !%Section Hamiltonian::DFT+U
375 !%Description
376 !% The cutoff radius defining the maximal intersite distance considered.
377 !% Only available with ACBN0 functional with intersite interaction.
378 !%End
379 call parse_variable(namespace, 'ACBN0IntersiteCutoff', m_zero, this%intersite_radius, unit = units_inp%length)
380 if (abs(this%intersite_radius) < m_epsilon) then
381 call messages_write("ACBN0IntersiteCutoff must be greater than 0")
382 call messages_fatal(1, namespace=namespace)
383 end if
384
385 end if
386
387 end if
388
389 call lda_u_write_info(this, namespace=namespace)
390
391 if (.not. this%basisfromstates) then
392
393 call orbitalbasis_init(this%basis, namespace, space%periodic_dim)
394
395 if (states_are_real(st)) then
396 call dorbitalbasis_build(this%basis, namespace, ions, gr, st%d%kpt, st%d%dim, &
397 this%skipSOrbitals, this%useAllOrbitals)
398 else
399 call zorbitalbasis_build(this%basis, namespace, ions, gr, st%d%kpt, st%d%dim, &
400 this%skipSOrbitals, this%useAllOrbitals)
401 end if
402 this%orbsets => this%basis%orbsets
403 this%norbsets = this%basis%norbsets
404 this%maxnorbs = this%basis%maxnorbs
405 this%max_np = this%basis%max_np
406 this%nspins = st%d%nspin
407 this%spin_channels = st%d%spin_channels
408 this%nspecies = ions%nspecies
409
410 !We allocate the necessary ressources
411 if (states_are_real(st)) then
412 call dlda_u_allocate(this, st)
413 else
414 call zlda_u_allocate(this, st)
415 end if
416
417 call distributed_nullify(this%orbs_dist, this%norbsets)
418#ifdef HAVE_MPI
419 if (.not. gr%parallel_in_domains) then
420 call distributed_init(this%orbs_dist, this%norbsets, mpi_comm_world, "orbsets")
421 end if
422#endif
423
424 else
425
426 !%Variable DFTUBasisStates
427 !%Type block
428 !%Default none
429 !%Section Hamiltonian::DFT+U
430 !%Description
431 !% This block starts by a line containing a single integer describing the number of
432 !% orbital sets. One orbital set is a group of orbitals on which one adds a Hubbard U.
433 !% Each following line of this block contains the index of a state to be used to construct the
434 !% localized basis, followed by the index of the corresponding orbital set.
435 !% See DFTUBasisFromStates for details.
436 !%End
437 if (parse_block(namespace, 'DFTUBasisStates', blk) == 0) then
438 call parse_block_integer(blk, 0, 0, this%norbsets)
439 this%maxnorbs = parse_block_n(blk)-1
440 if (this%maxnorbs <1) then
441 write(message(1),'(a,i3,a,i3)') 'DFTUBasisStates must contains at least one state.'
442 call messages_fatal(1, namespace=namespace)
443 end if
444 safe_allocate(this%basisstates(1:this%maxnorbs))
445 safe_allocate(this%basisstates_os(1:this%maxnorbs))
446 do is = 1, this%maxnorbs
447 call parse_block_integer(blk, is, 0, this%basisstates(is))
448 call parse_block_integer(blk, is, 1, this%basisstates_os(is))
449 end do
450 call parse_block_end(blk)
451 else
452 write(message(1),'(a,i3,a,i3)') 'DFTUBasisStates must be specified if DFTUBasisFromStates=yes'
453 call messages_fatal(1, namespace=namespace)
454 end if
455
456 if (states_are_real(st)) then
457 call dorbitalbasis_build_empty(this%basis, gr, st%d%dim, this%norbsets, this%basisstates_os)
458 else
459 call zorbitalbasis_build_empty(this%basis, gr, st%d%dim, this%norbsets, this%basisstates_os)
460 end if
461
462 this%max_np = gr%np
463 this%nspins = st%d%nspin
464 this%spin_channels = st%d%spin_channels
465 this%nspecies = 1
466
467 this%orbsets => this%basis%orbsets
468
469 call distributed_nullify(this%orbs_dist, this%norbsets)
470
471 !We allocate the necessary ressources
472 if (states_are_real(st)) then
473 call dlda_u_allocate(this, st)
474 else
475 call zlda_u_allocate(this, st)
476 end if
477
478 call lda_u_loadbasis(this, namespace, space, st, gr, mc, ierr)
479 if (ierr /= 0) then
480 message(1) = "Unable to load DFT+U basis from selected states."
481 call messages_fatal(1)
482 end if
483
484 end if
485
486 ! Symmetrization of the occupation matrices
487 this%symmetrize_occ_matrices = st%symmetrize_density .or. kpoints%use_symmetries
488 if (this%basisfromstates) this%symmetrize_occ_matrices = .false.
489 if (this%symmetrize_occ_matrices) then
490 call build_symmetrization_map(this, ions, gr)
491 end if
492
493 safe_allocate(this%dc_alpha(this%norbsets))
494 this%dc_alpha = m_one
495
496 call messages_print_with_emphasis(namespace=namespace)
497
498 pop_sub(lda_u_init)
499 end subroutine lda_u_init
500
501
502 ! ---------------------------------------------------------
503 subroutine lda_u_init_coulomb_integrals(this, namespace, space, gr, st, psolver)
504 type(lda_u_t), target, intent(inout) :: this
505 type(namespace_t), intent(in) :: namespace
506 class(space_t), intent(in) :: space
507 type(grid_t), intent(in) :: gr
508 type(states_elec_t), intent(in) :: st
509 type(poisson_t), intent(in) :: psolver
510
511 logical :: complex_coulomb_integrals
512 integer :: ios
513 integer :: norbs
514
516
517 norbs = this%maxnorbs
518
519 if (.not. this%basisfromstates) then
520
521 if (this%level == dft_u_acbn0) then
522
523 complex_coulomb_integrals = .false.
524 do ios = 1, this%norbsets
525 if (this%orbsets(ios)%ndim > 1) complex_coulomb_integrals = .true.
526 end do
527
528 if (.not. complex_coulomb_integrals) then
529 write(message(1),'(a)') 'Computing the Coulomb integrals of the localized basis.'
530 call messages_info(1, namespace=namespace)
531 safe_allocate(this%coulomb(1:norbs,1:norbs,1:norbs,1:norbs, 1:this%norbsets))
532 if (states_are_real(st)) then
533 call dcompute_coulomb_integrals(this, namespace, space, gr, psolver)
534 else
535 call zcompute_coulomb_integrals(this, namespace, space, gr, psolver)
536 end if
537 else
538 assert(.not. states_are_real(st))
539 write(message(1),'(a)') 'Computing complex Coulomb integrals of the localized basis.'
540 call messages_info(1, namespace=namespace)
541 safe_allocate(this%zcoulomb(1:norbs, 1:norbs, 1:norbs, 1:norbs, 1:st%d%dim, 1:st%d%dim, 1:this%norbsets))
542 call compute_complex_coulomb_integrals(this, gr, st, psolver, namespace, space)
543 end if
544 end if
545
546 else
547 write(message(1),'(a)') 'Computing the Coulomb integrals of the localized basis.'
548 call messages_info(1, namespace=namespace)
549 safe_allocate(this%coulomb(1:norbs, 1:norbs, 1:norbs, 1:norbs, 1:this%norbsets))
550 if (states_are_real(st)) then
551 call dcompute_coulomb_integrals(this, namespace, space, gr, psolver)
552 else
553 call zcompute_coulomb_integrals(this, namespace, space, gr, psolver)
554 end if
555
556 end if
557
559
560 end subroutine lda_u_init_coulomb_integrals
561
562
563 ! ---------------------------------------------------------
564 subroutine lda_u_end(this)
565 implicit none
566 type(lda_u_t), intent(inout) :: this
567
568 push_sub(lda_u_end)
569
570 this%level = dft_u_none
571
572 safe_deallocate_a(this%dn)
573 safe_deallocate_a(this%zn)
574 safe_deallocate_a(this%dn_alt)
575 safe_deallocate_a(this%zn_alt)
576 safe_deallocate_a(this%dV)
577 safe_deallocate_a(this%zV)
578 safe_deallocate_a(this%coulomb)
579 safe_deallocate_a(this%zcoulomb)
580 safe_deallocate_a(this%renorm_occ)
581 safe_deallocate_a(this%dn_ij)
582 safe_deallocate_a(this%zn_ij)
583 safe_deallocate_a(this%dn_alt_ij)
584 safe_deallocate_a(this%zn_alt_ij)
585 safe_deallocate_a(this%dn_alt_ii)
586 safe_deallocate_a(this%zn_alt_ii)
587 safe_deallocate_a(this%basisstates)
588 safe_deallocate_a(this%basisstates_os)
589 safe_deallocate_a(this%dc_alpha)
590 safe_deallocate_a(this%inv_map_symm)
591 safe_deallocate_a(this%symm_weight)
592
593 nullify(this%orbsets)
594 call orbitalbasis_end(this%basis)
595
596 this%max_np = 0
597
598 if (.not. this%basisfromstates) then
599 call distributed_end(this%orbs_dist)
600 end if
601
602 pop_sub(lda_u_end)
603 end subroutine lda_u_end
604
605 ! ---------------------------------------------------------
610 subroutine lda_u_rebind_after_copy(this, ions)
611 type(lda_u_t), target, intent(inout) :: this
612 type(ions_t), target, intent(in) :: ions
613
614 integer :: ios, ispec
615
617
618 if (this%level == dft_u_none) then
620 return
621 end if
622
623 this%latt => ions%latt
624
625 if (allocated(this%basis%orbsets)) then
626 this%orbsets => this%basis%orbsets
627 else
628 nullify(this%orbsets)
630 return
631 end if
632
633 do ios = 1, this%norbsets
634 if (.not. associated(this%orbsets(ios)%spec)) cycle
635
636 ispec = this%orbsets(ios)%spec_index
637 if (ispec < 1 .or. ispec > ions%nspecies) then
638 call messages_not_implemented("lda_u_rebind_after_copy with invalid species index")
639 end if
640 if (.not. associated(ions%species(ispec)%s)) then
641 call messages_not_implemented("lda_u_rebind_after_copy with unassociated ion species")
642 end if
643 this%orbsets(ios)%spec => ions%species(ispec)%s
644 end do
645
647 end subroutine lda_u_rebind_after_copy
648
649 ! ---------------------------------------------------------
655 subroutine lda_u_accel_rebuild(this, kpt)
656 type(lda_u_t), intent(inout) :: this
657 type(distributed_t), intent(in) :: kpt
658
659 integer :: ios, ik
660
661 push_sub(lda_u_accel_rebuild)
662
663 if (.not. accel_is_enabled()) then
664 pop_sub(lda_u_accel_rebuild)
665 return
666 end if
667
668 if (this%level == dft_u_none .or. .not. associated(this%orbsets)) then
669 pop_sub(lda_u_accel_rebuild)
670 return
671 end if
672
673 do ios = 1, this%norbsets
674 call accel_detach_buffer(this%orbsets(ios)%dbuff_orb)
675 call accel_detach_buffer(this%orbsets(ios)%zbuff_orb)
676 call accel_detach_buffer(this%orbsets(ios)%sphere%buff_map)
677
678 if (allocated(this%orbsets(ios)%buff_eorb)) then
679 do ik = lbound(this%orbsets(ios)%buff_eorb, dim=1), ubound(this%orbsets(ios)%buff_eorb, dim=1)
680 call accel_detach_buffer(this%orbsets(ios)%buff_eorb(ik))
681 end do
682 safe_deallocate_a(this%orbsets(ios)%buff_eorb)
683 end if
684
685 if (allocated(this%orbsets(ios)%dorb)) then
686 call dorbitalset_transfer_to_device(this%orbsets(ios), kpt, this%orbsets(ios)%allocated_on_mesh)
687 else if (allocated(this%orbsets(ios)%zorb)) then
688 call zorbitalset_transfer_to_device(this%orbsets(ios), kpt, this%orbsets(ios)%allocated_on_mesh)
689 else
690 call messages_not_implemented("lda_u_accel_rebuild with missing orbital arrays")
691 end if
692 end do
693
694 pop_sub(lda_u_accel_rebuild)
695 end subroutine lda_u_accel_rebuild
696
697 ! When moving the ions, the basis must be reconstructed
698 subroutine lda_u_update_basis(this, space, gr, ions, st, psolver, namespace, kpoints, has_phase)
699 type(lda_u_t), target, intent(inout) :: this
700 class(space_t), intent(in) :: space
701 type(grid_t), intent(in) :: gr
702 type(ions_t), target, intent(in) :: ions
703 type(states_elec_t), intent(in) :: st
704 type(poisson_t), intent(in) :: psolver
705 type(namespace_t), intent(in) :: namespace
706 type(kpoints_t), intent(in) :: kpoints
707 logical, intent(in) :: has_phase
708
709 integer :: ios, maxorbs, nspin
710
711 if(this%level == dft_u_none) return
712
713 push_sub(lda_u_update_basis)
714
715 if(.not. this%basisfromstates) then
716 !We clean the orbital basis, to be able to reconstruct it
717 call orbitalbasis_end(this%basis)
718 nullify(this%orbsets)
719
720 !We now reconstruct the basis
721 if (states_are_real(st)) then
722 call dorbitalbasis_build(this%basis, namespace, ions, gr, st%d%kpt, st%d%dim, &
723 this%skipSOrbitals, this%useAllOrbitals, verbose = .false.)
724 else
725 call zorbitalbasis_build(this%basis, namespace, ions, gr, st%d%kpt, st%d%dim, &
726 this%skipSOrbitals, this%useAllOrbitals, verbose = .false.)
727 end if
728 this%orbsets => this%basis%orbsets
729 this%max_np = this%basis%max_np
730 end if
731
732 !In case of intersite interaction we need to reconstruct the basis
733 if (this%intersite) then
734 this%maxneighbors = 0
735 do ios = 1, this%norbsets
736 call orbitalset_init_intersite(this%orbsets(ios), namespace, space, this%grp, ios, ions, gr%der, psolver, &
737 this%orbsets, this%norbsets, this%maxnorbs, this%intersite_radius, st%d%kpt, has_phase, &
738 this%sm_poisson, this%basisfromstates, this%basis%combine_j_orbitals)
739 this%maxneighbors = max(this%maxneighbors, this%orbsets(ios)%nneighbors)
740 end do
741
742 maxorbs = this%maxnorbs
743 nspin = this%nspins
744
745 if (states_are_real(st)) then
746 safe_deallocate_a(this%dn_ij)
747 safe_allocate(this%dn_ij(1:maxorbs,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors))
748 this%dn_ij(1:maxorbs,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors) = m_zero
749 safe_deallocate_a(this%dn_alt_ij)
750 safe_allocate(this%dn_alt_ij(1:maxorbs,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors))
751 this%dn_alt_ij(1:maxorbs,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors) = m_zero
752 safe_deallocate_a(this%dn_alt_ii)
753 safe_allocate(this%dn_alt_ii(1:2,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors))
754 this%dn_alt_ii(1:2,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors) = m_zero
755 else
756 safe_deallocate_a(this%zn_ij)
757 safe_allocate(this%zn_ij(1:maxorbs,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors))
758 this%zn_ij(1:maxorbs,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors) = m_z0
759 safe_deallocate_a(this%zn_alt_ij)
760 safe_allocate(this%zn_alt_ij(1:maxorbs,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors))
761 this%zn_alt_ij(1:maxorbs,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors) = m_z0
762 safe_deallocate_a(this%zn_alt_ii)
763 safe_allocate(this%zn_alt_ii(1:2,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors))
764 this%zn_alt_ii(1:2,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors) = m_z0
765 end if
766 end if
767
768 ! We rebuild the phase for the orbital projection, similarly to the one of the pseudopotentials
769 ! In case of a laser field, the phase is recomputed in hamiltonian_elec_update
770 if (has_phase) then
771 call lda_u_build_phase_correction(this, space, st%d, gr%der%boundaries, namespace, kpoints)
772 else
773 if(.not. this%basisfromstates) then
774 !In case there is no phase, we perform the orthogonalization here
775 if(this%basis%orthogonalization) then
776 call dloewdin_orthogonalize(this%basis, st%d%kpt, namespace)
777 else
778 if(debug%info .and. space%is_periodic()) then
779 call dloewdin_info(this%basis, st%d%kpt, namespace)
780 end if
781 end if
782 end if
783 end if
784
785 ! Rebuild the Coulomb integrals
786 if (allocated(this%coulomb)) then
787 safe_deallocate_a(this%coulomb)
788 end if
789 if (allocated(this%zcoulomb)) then
790 safe_deallocate_a(this%zcoulomb)
791 end if
792 call lda_u_init_coulomb_integrals(this, namespace, space, gr, st, psolver)
794 pop_sub(lda_u_update_basis)
795
796 end subroutine lda_u_update_basis
797
798 ! Interface for the X(update_occ_matrices) routines
799 subroutine lda_u_update_occ_matrices(this, namespace, mesh, st, phase, energy)
800 type(lda_u_t), intent(inout) :: this
801 type(namespace_t), intent(in) :: namespace
802 class(mesh_t), intent(in) :: mesh
803 type(states_elec_t), intent(inout) :: st
804 type(phase_t), intent(in) :: phase
805 type(energy_t), intent(inout) :: energy
806
807 if (this%level == dft_u_none .or. this%freeze_occ) return
809
810 if (states_are_real(st)) then
811 call dupdate_occ_matrices(this, namespace, mesh, st, energy%dft_u)
812 else
813 if (phase%is_allocated()) then
814 call zupdate_occ_matrices(this, namespace, mesh, st, energy%dft_u, phase)
815 else
816 call zupdate_occ_matrices(this, namespace, mesh, st, energy%dft_u)
817 end if
818 end if
819
821 end subroutine lda_u_update_occ_matrices
822
823
825 subroutine lda_u_build_phase_correction(this, space, std, boundaries, namespace, kpoints, vec_pot, vec_pot_var)
826 type(lda_u_t), intent(inout) :: this
827 class(space_t), intent(in) :: space
828 type(states_elec_dim_t), intent(in) :: std
829 type(boundaries_t), intent(in) :: boundaries
830 type(namespace_t), intent(in) :: namespace
831 type(kpoints_t), intent(in) :: kpoints
832 real(real64), optional, allocatable, intent(in) :: vec_pot(:)
833 real(real64), optional, allocatable, intent(in) :: vec_pot_var(:, :)
834
835 integer :: ios
836
837 if (boundaries%spiralBC) call messages_not_implemented("DFT+U with spiral boundary conditions", &
838 namespace=namespace)
839
841
842 write(message(1), '(a)') 'Debug: Building the phase correction for DFT+U orbitals.'
843 call messages_info(1, namespace=namespace, debug_only=.true.)
844
845 do ios = 1, this%norbsets
846 call orbitalset_update_phase(this%orbsets(ios), space%dim, std%kpt, kpoints, &
847 (std%ispin==spin_polarized), vec_pot, vec_pot_var)
848 call orbitalset_update_phase_shift(this%orbsets(ios), space%dim, std%kpt, kpoints, &
849 (std%ispin==spin_polarized), vec_pot, vec_pot_var)
850 end do
851
852 if (.not. this%basisfromstates) then
853 if (this%basis%orthogonalization) then
854 call zloewdin_orthogonalize(this%basis, std%kpt, namespace)
855 else
856 if (debug%info .and. space%is_periodic()) call zloewdin_info(this%basis, std%kpt, namespace)
857 end if
858 end if
859
861
862 end subroutine lda_u_build_phase_correction
863
864 ! ---------------------------------------------------------
865 subroutine compute_acbno_u_kanamori(this, st, kanamori)
866 type(lda_u_t), intent(in) :: this
867 type(states_elec_t), intent(in) :: st
868 real(real64), intent(out) :: kanamori(:,:)
869
870 if (this%nspins == 1) then
871 if (states_are_real(st)) then
872 call dcompute_acbno_u_kanamori_restricted(this, kanamori)
873 else
874 call zcompute_acbno_u_kanamori_restricted(this, kanamori)
875 end if
876 else
877 if (states_are_real(st)) then
878 call dcompute_acbno_u_kanamori(this, kanamori)
879 else
880 call zcompute_acbno_u_kanamori(this, kanamori)
881 end if
882 end if
883
884
885 end subroutine compute_acbno_u_kanamori
886
887 ! ---------------------------------------------------------
888 subroutine lda_u_freeze_occ(this)
889 type(lda_u_t), intent(inout) :: this
890
891 this%freeze_occ = .true.
892 end subroutine lda_u_freeze_occ
893
894 ! ---------------------------------------------------------
895 subroutine lda_u_freeze_u(this)
896 type(lda_u_t), intent(inout) :: this
897
898 this%freeze_u = .true.
899 end subroutine lda_u_freeze_u
900
901 ! ---------------------------------------------------------
902 subroutine lda_u_set_effectiveu(this, Ueff)
903 type(lda_u_t), intent(inout) :: this
904 real(real64), intent(in) :: ueff(:)
905
906 integer :: ios
907
908 push_sub(lda_u_set_effectiveu)
909
910 do ios = 1,this%norbsets
911 this%orbsets(ios)%Ueff = ueff(ios)
912 end do
913
914 pop_sub(lda_u_set_effectiveu)
915 end subroutine lda_u_set_effectiveu
916
917 ! ---------------------------------------------------------
918 subroutine lda_u_get_effectiveu(this, Ueff)
919 type(lda_u_t), intent(in) :: this
920 real(real64), intent(inout) :: ueff(:)
921
922 integer :: ios
923
924 push_sub(lda_u_get_effectiveu)
925
926 do ios = 1,this%norbsets
927 ueff(ios) = this%orbsets(ios)%Ueff
928 end do
929
930 pop_sub(lda_u_get_effectiveu)
931 end subroutine lda_u_get_effectiveu
932
933 ! ---------------------------------------------------------
934 subroutine lda_u_set_effectivev(this, Veff)
935 type(lda_u_t), intent(inout) :: this
936 real(real64), intent(in) :: veff(:)
937
938 integer :: ios, ncount
939
940 push_sub(lda_u_set_effectivev)
941
942 ncount = 0
943 do ios = 1, this%norbsets
944 this%orbsets(ios)%V_ij(1:this%orbsets(ios)%nneighbors,0) = veff(ncount+1:ncount+this%orbsets(ios)%nneighbors)
945 ncount = ncount + this%orbsets(ios)%nneighbors
946 end do
947
948 pop_sub(lda_u_set_effectivev)
949 end subroutine lda_u_set_effectivev
950
951 ! ---------------------------------------------------------
952 subroutine lda_u_get_effectivev(this, Veff)
953 type(lda_u_t), intent(in) :: this
954 real(real64), intent(inout) :: veff(:)
955
956 integer :: ios, ncount
957
958 push_sub(lda_u_get_effectivev)
959
960 ncount = 0
961 do ios = 1, this%norbsets
962 veff(ncount+1:ncount+this%orbsets(ios)%nneighbors) = this%orbsets(ios)%V_ij(1:this%orbsets(ios)%nneighbors,0)
963 ncount = ncount + this%orbsets(ios)%nneighbors
964 end do
965
966 pop_sub(lda_u_get_effectivev)
967 end subroutine lda_u_get_effectivev
968
969 ! ---------------------------------------------------------
970 subroutine lda_u_write_info(this, iunit, namespace)
971 type(lda_u_t), intent(in) :: this
972 integer, optional, intent(in) :: iunit
973 type(namespace_t), optional, intent(in) :: namespace
974
975 push_sub(lda_u_write_info)
976
977 write(message(1), '(1x)')
978 call messages_info(1, iunit=iunit, namespace=namespace)
979 if (this%level == dft_u_empirical) then
980 write(message(1), '(a)') "Method:"
981 write(message(2), '(a)') " [1] Dudarev et al., Phys. Rev. B 57, 1505 (1998)"
982 call messages_info(2, iunit=iunit, namespace=namespace)
983 else
984 if (.not. this%intersite) then
985 write(message(1), '(a)') "Method:"
986 write(message(2), '(a)') " [1] Agapito et al., Phys. Rev. X 5, 011006 (2015)"
987 else
988 write(message(1), '(a)') "Method:"
989 write(message(2), '(a)') " [1] Tancogne-Dejean, and Rubio, Phys. Rev. B 102, 155117 (2020)"
990 end if
991 call messages_info(2, iunit=iunit, namespace=namespace)
992 end if
993 write(message(1), '(a)') "Implementation:"
994 write(message(2), '(a)') " [1] Tancogne-Dejean, Oliveira, and Rubio, Phys. Rev. B 69, 245133 (2017)"
995 write(message(3), '(1x)')
996 call messages_info(3, iunit=iunit, namespace=namespace)
998 pop_sub(lda_u_write_info)
999
1000 end subroutine lda_u_write_info
1001
1002 ! ---------------------------------------------------------
1003 subroutine lda_u_loadbasis(this, namespace, space, st, mesh, mc, ierr)
1004 type(lda_u_t), intent(inout) :: this
1005 type(namespace_t), intent(in) :: namespace
1006 class(space_t), intent(in) :: space
1007 type(states_elec_t), intent(in) :: st
1008 class(mesh_t), intent(in) :: mesh
1009 type(multicomm_t), intent(in) :: mc
1010 integer, intent(out) :: ierr
1011
1012 integer :: err, wfns_file, is, ist, idim, ik, ios, iorb
1014 character(len=256) :: lines(3)
1015 character(len=256), allocatable :: restart_file(:, :)
1016 logical, allocatable :: restart_file_present(:, :)
1017 character(len=12) :: filename
1018 character(len=1) :: char
1019 character(len=50) :: str
1020 type(orbitalset_t), pointer :: os
1021 integer, allocatable :: count(:)
1022 real(real64) :: norm, center(space%dim)
1023 real(real64), allocatable :: dpsi(:,:,:)
1024 complex(real64), allocatable :: zpsi(:,:,:)
1025
1026
1027 push_sub(lda_u_loadbasis)
1028
1029 ierr = 0
1030
1031 message(1) = "Debug: Loading DFT+U basis from states."
1032 call messages_info(1, debug_only=.true.)
1033
1034 call restart_gs%init(namespace, restart_proj, restart_type_load, mc, err, mesh=mesh)
1035
1036 ! If any error occured up to this point then it is not worth continuing,
1037 ! as there something fundamentally wrong with the restart files
1038 if (err /= 0) then
1039 call restart_gs%end()
1040 message(1) = "Error loading DFT+U basis from states, cannot proceed with the calculation"
1041 call messages_fatal(1)
1042 pop_sub(lda_u_loadbasis)
1043 return
1044 end if
1045 ! only supported for obf format
1046 if (restart_gs%file_format_states /= option__restartfileformatstates__obf) then
1047 message(1) = "Error: loading DFT+U basis only supported for OBF restart format"
1048 message(2) = "Please set RestartFileFormatStates = obf and re-run the GS calculation."
1049 call messages_fatal(2)
1050 end if
1051
1052 ! open files to read
1053 wfns_file = restart_gs%open('wfns')
1054 call restart_gs%read(wfns_file, lines, 2, err)
1055 if (err /= 0) then
1056 ierr = ierr - 2**5
1057 else if (states_are_real(st)) then
1058 read(lines(2), '(a)') str
1059 if (str(2:8) == 'Complex') then
1060 message(1) = "Cannot read real states from complex wavefunctions."
1061 call messages_fatal(1, namespace=namespace)
1062 else if (str(2:5) /= 'Real') then
1063 message(1) = "Restart file 'wfns' does not specify real/complex; cannot check compatibility."
1064 call messages_warning(1, namespace=namespace)
1065 end if
1066 end if
1067 ! complex can be restarted from real, so there is no problem.
1068
1069 ! If any error occured up to this point then it is not worth continuing,
1070 ! as there something fundamentally wrong with the restart files
1071 if (err /= 0) then
1072 call restart_gs%close(wfns_file)
1073 call restart_gs%end()
1074 message(1) = "Error loading DFT+U basis from states, cannot proceed with the calculation"
1075 call messages_fatal(1)
1076 pop_sub(lda_u_loadbasis)
1077 return
1078 end if
1079
1080 safe_allocate(restart_file(1:st%d%dim, 1:st%nst))
1081 safe_allocate(restart_file_present(1:st%d%dim, 1:st%nst))
1082 restart_file_present = .false.
1083
1084 ! Next we read the list of states from the files.
1085 ! Errors in reading the information of a specific state from the files are ignored
1086 ! at this point, because later we will skip reading the wavefunction of that state.
1087 do
1088 call restart_gs%read(wfns_file, lines, 1, err)
1089 if (err == 0) then
1090 read(lines(1), '(a)') char
1091 if (char == '%') then
1092 !We reached the end of the file
1093 exit
1094 else
1095 read(lines(1), *) ik, char, ist, char, idim, char, filename
1096 end if
1097 end if
1099 if (any(this%basisstates==ist) .and. ik == 1) then
1100 restart_file(idim, ist) = trim(filename)
1101 restart_file_present(idim, ist) = .true.
1102 end if
1103 end do
1104 call restart_gs%close(wfns_file)
1105
1106 !We loop over the states we need
1107 safe_allocate(count(1:this%norbsets))
1108 count = 0
1109 do is = 1, this%maxnorbs
1110 ist = this%basisstates(is)
1111 ios = this%basisstates_os(is)
1112 count(ios) = count(ios)+1
1113 do idim = 1, st%d%dim
1114
1115 if (.not. restart_file_present(idim, ist)) then
1116 write(message(1), '(a,i3,a)') "Cannot read states ", ist, "from the projection folder"
1117 call messages_fatal(1, namespace=namespace)
1118 end if
1119
1120 if (states_are_real(st)) then
1121 call restart_gs%read_mesh_function(restart_file(idim, ist), mesh, &
1122 this%orbsets(ios)%dorb(:,idim,count(ios)), err)
1123 else
1124 call restart_gs%read_mesh_function(restart_file(idim, ist), mesh, &
1125 this%orbsets(ios)%zorb(:,idim,count(ios)), err)
1126 end if
1127 if (err /= 0) then
1128 message(1) = "Error loading mesh function "//trim(restart_file(idim, ist))
1129 call messages_fatal(1)
1130 end if
1131 end do
1132 end do
1133 safe_deallocate_a(count)
1134 safe_deallocate_a(restart_file)
1135 safe_deallocate_a(restart_file_present)
1136 call restart_gs%end()
1137
1138 ! Normalize the orbitals. This is important if we use Wannier orbitals instead of KS states
1139 if(this%basis%normalize) then
1140 do ios = 1, this%norbsets
1141 do iorb = 1, this%orbsets(ios)%norbs
1142 if (states_are_real(st)) then
1143 norm = dmf_nrm2(mesh, st%d%dim, this%orbsets(ios)%dorb(:,:,iorb))
1144 call lalg_scal(mesh%np, st%d%dim, m_one/norm, this%orbsets(ios)%dorb(:,:,iorb))
1145 else
1146 norm = zmf_nrm2(mesh, st%d%dim, this%orbsets(ios)%zorb(:,:,iorb))
1147 call lalg_scal(mesh%np, st%d%dim, m_one/norm, this%orbsets(ios)%zorb(:,:,iorb))
1148 end if
1149 end do
1150 end do
1151 end if
1152
1153 ! We rotate the orbitals in the complex plane to have them as close as possible to real functions
1154 if(states_are_complex(st) .and. st%d%dim == 1) then
1155 do ios = 1, this%norbsets
1156 do iorb = 1, this%orbsets(ios)%norbs
1157 call zmf_fix_phase(mesh, this%orbsets(ios)%zorb(:,1,iorb))
1158 end do
1159 end do
1160 end if
1161
1162 ! We determine the center of charge by computing <w|r|w>
1163 ! We could also determine the spread by \Omega = <w|r^2|w> - <w|r|w>^2
1164 do ios = 1, this%norbsets
1165 if (states_are_real(st)) then
1166 call dorbitalset_get_center_of_mass(this%orbsets(ios), space, mesh, this%latt)
1167 else
1168 call zorbitalset_get_center_of_mass(this%orbsets(ios), space, mesh, this%latt)
1169 end if
1170 end do
1171
1172 message(1) = "Debug: Converting the Wannier states to submeshes."
1173 call messages_info(1, debug_only=.true.)
1174
1175 ! We now transfer the states to a submesh centered on the center of mass of the Wannier orbitals
1176 this%max_np = 0
1177 do ios = 1, this%norbsets
1178 os => this%orbsets(ios)
1179 center = os%sphere%center
1180 safe_deallocate_a(os%sphere%center)
1181 if (states_are_real(st)) then
1182 safe_allocate(dpsi(1:mesh%np, 1:os%ndim, 1:os%norbs))
1183 dpsi(1:mesh%np, 1:os%ndim, 1:os%norbs) = os%dorb(1:mesh%np, 1:os%ndim, 1:os%norbs)
1184
1185 safe_deallocate_a(os%dorb)
1186 !We initialise the submesh corresponding to the orbital
1187 call submesh_init(os%sphere, space, mesh, this%latt, center, os%radius)
1188 safe_allocate(os%dorb(1:os%sphere%np, 1:os%ndim, 1:os%norbs))
1189 do iorb = 1, os%norbs
1190 do idim = 1, os%ndim
1191 call dsubmesh_copy_from_mesh(os%sphere, dpsi(:,idim,iorb), os%dorb(:,idim, iorb))
1192 end do
1193 end do
1194 safe_deallocate_a(dpsi)
1195 else
1196 safe_allocate(zpsi(1:mesh%np, 1:os%ndim, 1:os%norbs))
1197 zpsi(1:mesh%np, 1:os%ndim, 1:os%norbs) = os%zorb(1:mesh%np, 1:os%ndim, 1:os%norbs)
1198 safe_deallocate_a(os%zorb)
1199 !We initialise the submesh corresponding to the orbital
1200 call submesh_init(os%sphere, space, mesh, this%latt, center, os%radius)
1201 safe_allocate(os%zorb(1:os%sphere%np, 1:os%ndim, 1:os%norbs))
1202 do iorb = 1, os%norbs
1203 do idim = 1, os%ndim
1204 call zsubmesh_copy_from_mesh(os%sphere, zpsi(:,idim,iorb), os%zorb(:,idim, iorb))
1205 end do
1206 end do
1207 safe_deallocate_a(zpsi)
1208
1209 safe_allocate(os%phase(1:os%sphere%np, st%d%kpt%start:st%d%kpt%end))
1210 safe_allocate(os%eorb_submesh(1:os%sphere%np, 1:os%ndim, 1:os%norbs, st%d%kpt%start:st%d%kpt%end))
1211 end if
1212 os%use_submesh = .true. ! We are now on a submesh
1213 this%max_np = max(this%max_np, os%sphere%np)
1214 end do
1215
1216 this%basis%use_submesh = .true.
1217
1218 ! If we use GPUs, we need to transfert the orbitals on the device
1219 if (accel_is_enabled() .and. st%d%dim == 1) then
1220 do ios = 1, this%norbsets
1221 os => this%orbsets(ios)
1222
1223 os%ldorbs = max(accel_padded_size(os%sphere%np), 1)
1224 os%ldorbs_eorb = max(accel_padded_size(os%sphere%np), 1)
1225 if (states_are_real(st)) then
1226 call accel_create_buffer(os%dbuff_orb, accel_mem_read_only, type_float, os%ldorbs*os%norbs)
1227 else
1228 call accel_create_buffer(os%zbuff_orb, accel_mem_read_only, type_cmplx, os%ldorbs*os%norbs)
1229 safe_allocate(os%buff_eorb(st%d%kpt%start:st%d%kpt%end))
1230
1231 do ik= st%d%kpt%start, st%d%kpt%end
1232 call accel_create_buffer(os%buff_eorb(ik), accel_mem_read_only, type_cmplx, os%ldorbs_eorb*os%norbs)
1233 end do
1234 end if
1235
1236 call accel_create_buffer(os%sphere%buff_map, accel_mem_read_only, type_integer, max(os%sphere%np, 1))
1237 call accel_write_buffer(os%sphere%buff_map, os%sphere%np, os%sphere%map)
1238
1239 do iorb = 1, os%norbs
1240 if(states_are_complex(st)) then
1241 call accel_write_buffer(os%zbuff_orb, os%sphere%np, os%zorb(:, 1, iorb), &
1242 offset = (iorb - 1)*os%ldorbs)
1243 else
1244 call accel_write_buffer(os%dbuff_orb, os%sphere%np, os%dorb(:, 1, iorb), &
1245 offset = (iorb - 1)*os%ldorbs)
1246 end if
1247 end do
1248 end do
1249 end if
1250
1251
1252 message(1) = "Debug: Loading DFT+U basis from states done."
1253 call messages_info(1, debug_only=.true.)
1254
1255 pop_sub(lda_u_loadbasis)
1256 end subroutine lda_u_loadbasis
1257
1259 subroutine build_symmetrization_map(this, ions, gr)
1260 type(lda_u_t), intent(inout) :: this
1261 type(ions_t), intent(in) :: ions
1262 type(grid_t), intent(in) :: gr
1263
1264 integer :: nsym, iop, ios, iatom, iatom_sym, ios_sym
1265
1266 push_sub(build_symmetrization_map)
1267
1268 nsym = ions%symm%nops
1269 safe_allocate(this%inv_map_symm(1:this%norbsets, 1:nsym))
1270 this%inv_map_symm = -1
1271
1272 this%nsym = nsym
1273
1274 do ios = 1, this%norbsets
1275 iatom = this%orbsets(ios)%iatom
1276 do iop = 1, nsym
1277 iatom_sym = ions%inv_map_symm_atoms(iatom, iop)
1278
1279 do ios_sym = 1, this%norbsets
1280 if (this%orbsets(ios_sym)%iatom == iatom_sym .and. this%orbsets(ios_sym)%norbs == this%orbsets(ios)%norbs &
1281 .and. this%orbsets(ios_sym)%nn == this%orbsets(ios)%nn .and. this%orbsets(ios_sym)%ll == this%orbsets(ios)%ll &
1282 .and. is_close(this%orbsets(ios_sym)%jj, this%orbsets(ios)%jj)) then
1283 this%inv_map_symm(ios, iop) = ios_sym
1284 exit
1285 end if
1286 end do
1287 assert(this%inv_map_symm(ios, iop) > 0)
1288 end do
1289 end do
1290
1291 safe_allocate(this%symm_weight(1:this%maxnorbs, 1:this%maxnorbs, 1:this%nsym, 1:this%norbsets))
1292 this%symm_weight = m_zero
1293
1294 do ios = 1, this%norbsets
1295 ! s-orbitals
1296 if (this%orbsets(ios)%norbs == 1) then
1297 this%symm_weight(1,1, 1:this%nsym, ios) = m_one
1298 cycle
1299 end if
1300
1301 ! Not implemented yet
1302 if (this%orbsets(ios)%ndim > 1) cycle
1303
1304 call orbitals_get_symm_weight(this%orbsets(ios), ions%space, ions%latt, gr, ions%symm, this%symm_weight(:,:,:,ios))
1305 end do
1306
1308 end subroutine build_symmetrization_map
1309
1311 subroutine orbitals_get_symm_weight(os, space, latt, gr, symm, weight)
1312 type(orbitalset_t), intent(in) :: os
1313 type(space_t), intent(in) :: space
1314 type(lattice_vectors_t), intent(in) :: latt
1315 type(grid_t), intent(in) :: gr
1316 type(symmetries_t), intent(in) :: symm
1317 real(real64), intent(inout) :: weight(:,:,:)
1318
1319 integer :: im, imp, iop, mm
1320 real(real64), allocatable :: orb(:,:), orb_sym(:), ylm(:)
1321 type(submesh_t) :: sphere
1322 real(real64) :: rc, norm, origin(space%dim)
1323
1324 push_sub(orbitals_get_symm_weight)
1325
1326 assert(os%ndim == 1)
1327
1328 safe_allocate(orb_sym(1:gr%np))
1329 safe_allocate(orb(1:gr%np, 1:os%norbs))
1330
1331 assert(2*os%ll+1 == os%norbs)
1332
1333 ! We generate an artificial submesh to compute the symmetries on it
1334 ! The radius is such that we fit in 20 points
1335 rc = (50.0_real64 * m_three/m_four/m_pi*product(gr%spacing))**m_third
1336 origin = m_zero
1337 call submesh_init(sphere, space, gr, latt, origin, rc)
1338
1339 safe_allocate(ylm(1:sphere%np))
1340
1341 ! We then compute the spherical harmonics in this submesh
1342 do im = 1, os%norbs
1343 mm = im-1-os%ll
1344 call loct_ylm(sphere%np, sphere%rel_x(1,1), sphere%r(1), os%ll, mm, ylm(1))
1345 orb(:,im) = m_zero
1346 call submesh_add_to_mesh(sphere, ylm, orb(:,im))
1347 norm = dmf_nrm2(gr, orb(:,im))
1348 call lalg_scal(gr%np, m_one / norm, orb(:,im))
1349 end do
1350 safe_deallocate_a(ylm)
1351
1352 ! Then we put them on the grid, rotate them
1353 do im = 1, os%norbs
1354 do iop = 1, symm%nops
1355 call dgrid_symmetrize_single(gr, iop, orb(:,im), orb_sym)
1356
1357 do imp = 1, os%norbs
1358 weight(im, imp, iop) = dmf_dotp(gr, orb(:,imp), orb_sym, reduce=.false.)
1359 end do
1360 end do
1361 end do
1362
1363 call gr%allreduce(weight)
1364
1365 safe_deallocate_a(orb)
1366 safe_deallocate_a(orb_sym)
1367
1369 end subroutine orbitals_get_symm_weight
1370
1371#include "dft_u_noncollinear_inc.F90"
1372
1373#include "undef.F90"
1374#include "real.F90"
1375#include "lda_u_inc.F90"
1376
1377#include "undef.F90"
1378#include "complex.F90"
1379#include "lda_u_inc.F90"
1380end module lda_u_oct_m
scales a vector by a constant
Definition: lalg_basic.F90:159
Prints out to iunit a message in the form: ["InputVariable" = value] where "InputVariable" is given b...
Definition: messages.F90:182
subroutine, public accel_detach_buffer(this)
Clear a buffer handle without freeing device memory.
Definition: accel.F90:1075
pure logical function, public accel_is_enabled()
Definition: accel.F90:403
integer, parameter, public accel_mem_read_only
Definition: accel.F90:186
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
type(debug_t), save, public debug
Definition: debug.F90:158
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
subroutine, public distributed_end(this)
subroutine, public distributed_nullify(this, total)
subroutine, public distributed_init(this, total, comm, tag, scalapack_compat)
Distribute N instances across M processes of communicator comm
integer, parameter, public spinors
integer, parameter, public spin_polarized
real(real64), parameter, public m_zero
Definition: global.F90:200
real(real64), parameter, public m_four
Definition: global.F90:204
real(real64), parameter, public m_third
Definition: global.F90:207
real(real64), parameter, public m_pi
some mathematical constants
Definition: global.F90:198
complex(real64), parameter, public m_z0
Definition: global.F90:210
real(real64), parameter, public m_epsilon
Definition: global.F90:216
real(real64), parameter, public m_one
Definition: global.F90:201
real(real64), parameter, public m_three
Definition: global.F90:203
This module implements the underlying real-space grid.
Definition: grid.F90:119
subroutine, public dgrid_symmetrize_single(gr, iop, field, symm_field)
Definition: grid.F90:716
integer, parameter, public dft_u_amf
Definition: lda_u.F90:210
subroutine, public zlda_u_commute_r(this, mesh, space, d, namespace, psib, gpsib)
This routine computes [r,V_lda+u] .
Definition: lda_u.F90:5086
subroutine zlda_u_allocate(this, st)
Definition: lda_u.F90:5656
subroutine, public lda_u_get_effectiveu(this, Ueff)
Definition: lda_u.F90:1014
subroutine compute_complex_coulomb_integrals(this, gr, st, psolver, namespace, space)
Definition: lda_u.F90:1488
subroutine, public dlda_u_force(this, namespace, space, mesh, st, iq, psib, grad_psib, force)
Definition: lda_u.F90:3273
subroutine, public dlda_u_apply(this, d, mesh, psib, hpsib)
Apply the +U nonlocal potential to psib and adds the result to hpsib.
Definition: lda_u.F90:1855
subroutine, public lda_u_set_effectiveu(this, Ueff)
Definition: lda_u.F90:998
subroutine build_symmetrization_map(this, ions, gr)
Builds a mapping between the orbital sets based on symmetries.
Definition: lda_u.F90:1355
subroutine dcompute_acbno_u_kanamori_restricted(this, kanamori)
This routine computes the Kanamori U, Up, and J.
Definition: lda_u.F90:2874
subroutine, public lda_u_init(this, namespace, space, level, gr, ions, st, mc, kpoints)
Definition: lda_u.F90:287
subroutine, public dlda_u_get_occupations(this, occ)
Definition: lda_u.F90:3578
subroutine, public dlda_u_rvu(this, mesh, space, d, namespace, psib, gpsib)
This routine computes .
Definition: lda_u.F90:3411
subroutine, public lda_u_update_basis(this, space, gr, ions, st, psolver, namespace, kpoints, has_phase)
Definition: lda_u.F90:794
subroutine orbitals_get_symm_weight(os, space, latt, gr, symm, weight)
Computes the weight of each rotated orbitals in the basis of the same localized subspace.
Definition: lda_u.F90:1407
subroutine dupdate_occ_matrices(this, namespace, mesh, st, lda_u_energy, phase)
This routine computes the values of the occupation matrices.
Definition: lda_u.F90:1913
subroutine, public lda_u_accel_rebuild(this, kpt)
Rebuild DFT+U accelerator buffers after intrinsic assignment.
Definition: lda_u.F90:751
subroutine, public zlda_u_apply(this, d, mesh, psib, hpsib)
Apply the +U nonlocal potential to psib and adds the result to hpsib.
Definition: lda_u.F90:3825
subroutine, public zcompute_dftu_energy(this, energy, st)
This routine computes the value of the double counting term in the DFT+U energy.
Definition: lda_u.F90:4284
integer, parameter, public dft_u_empirical
Definition: lda_u.F90:205
subroutine zcompute_acbno_u_kanamori_restricted(this, kanamori)
This routine computes the Kanamori U, Up, and J.
Definition: lda_u.F90:4844
subroutine dcompute_acbno_u_kanamori(this, kanamori)
This routine computes the Kanamori U, Up, and J.
Definition: lda_u.F90:2775
subroutine, public zlda_u_commute_r_single(this, mesh, space, d, namespace, ist, ik, psi, gpsi, has_phase)
Definition: lda_u.F90:5035
subroutine, public lda_u_freeze_occ(this)
Definition: lda_u.F90:984
integer, parameter, public dft_u_mix
Definition: lda_u.F90:210
subroutine, public lda_u_rebind_after_copy(this, ions)
Rebind non-owning pointers after intrinsic assignment of lda_u_t.
Definition: lda_u.F90:706
subroutine, public lda_u_freeze_u(this)
Definition: lda_u.F90:991
subroutine, public zlda_u_rvu(this, mesh, space, d, namespace, psib, gpsib)
This routine computes .
Definition: lda_u.F90:5411
subroutine dlda_u_allocate(this, st)
Definition: lda_u.F90:3635
subroutine, public compute_acbno_u_kanamori(this, st, kanamori)
Definition: lda_u.F90:961
subroutine, public zlda_u_update_potential(this, st)
This routine computes the potential that, once multiplied by the projector Pmm' and summed over m and...
Definition: lda_u.F90:4358
subroutine lda_u_init_coulomb_integrals(this, namespace, space, gr, st, psolver)
Definition: lda_u.F90:599
subroutine, public lda_u_write_info(this, iunit, namespace)
Definition: lda_u.F90:1066
subroutine, public dlda_u_commute_r(this, mesh, space, d, namespace, psib, gpsib)
This routine computes [r,V_lda+u] .
Definition: lda_u.F90:3116
subroutine, public zlda_u_force(this, namespace, space, mesh, st, iq, psib, grad_psib, force)
Definition: lda_u.F90:5273
subroutine dcompute_coulomb_integrals(this, namespace, space, gr, psolver)
Definition: lda_u.F90:2949
subroutine, public dlda_u_set_occupations(this, occ)
Definition: lda_u.F90:3521
subroutine, public lda_u_get_effectivev(this, Veff)
Definition: lda_u.F90:1048
subroutine lda_u_loadbasis(this, namespace, space, st, mesh, mc, ierr)
Definition: lda_u.F90:1099
subroutine, public dlda_u_commute_r_single(this, mesh, space, d, namespace, ist, ik, psi, gpsi, has_phase)
Definition: lda_u.F90:3065
subroutine, public lda_u_build_phase_correction(this, space, std, boundaries, namespace, kpoints, vec_pot, vec_pot_var)
Build the phase correction to the global phase for all orbitals.
Definition: lda_u.F90:921
subroutine, public lda_u_end(this)
Definition: lda_u.F90:660
subroutine, public lda_u_set_effectivev(this, Veff)
Definition: lda_u.F90:1030
subroutine, public lda_u_update_occ_matrices(this, namespace, mesh, st, phase, energy)
Definition: lda_u.F90:895
integer, parameter, public dft_u_acbn0
Definition: lda_u.F90:205
subroutine zcompute_acbno_u_kanamori(this, kanamori)
This routine computes the Kanamori U, Up, and J.
Definition: lda_u.F90:4745
subroutine zcompute_coulomb_integrals(this, namespace, space, gr, psolver)
Definition: lda_u.F90:4919
subroutine, public zlda_u_get_occupations(this, occ)
Definition: lda_u.F90:5599
subroutine zupdate_occ_matrices(this, namespace, mesh, st, lda_u_energy, phase)
This routine computes the values of the occupation matrices.
Definition: lda_u.F90:3883
subroutine, public dcompute_dftu_energy(this, energy, st)
This routine computes the value of the double counting term in the DFT+U energy.
Definition: lda_u.F90:2314
subroutine, public dlda_u_update_potential(this, st)
This routine computes the potential that, once multiplied by the projector Pmm' and summed over m and...
Definition: lda_u.F90:2388
subroutine, public zlda_u_set_occupations(this, occ)
Definition: lda_u.F90:5542
System information (time, memory, sysname)
Definition: loct.F90:117
subroutine, public dloewdin_orthogonalize(basis, kpt, namespace)
Definition: loewdin.F90:214
subroutine, public zloewdin_info(basis, kpt, namespace)
Definition: loewdin.F90:778
subroutine, public zloewdin_orthogonalize(basis, kpt, namespace)
Definition: loewdin.F90:558
subroutine, public dloewdin_info(basis, kpt, namespace)
Definition: loewdin.F90:434
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:117
This module defines various routines, operating on mesh functions.
subroutine, public zmf_fix_phase(mesh, ff)
Fix the phase of complex function.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:120
subroutine, public messages_print_with_emphasis(msg, iunit, namespace)
Definition: messages.F90:898
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1068
character(len=512), private msg
Definition: messages.F90:167
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:525
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:162
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:410
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1040
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:594
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:147
subroutine, public orbitalbasis_end(this)
subroutine, public zorbitalbasis_build(this, namespace, ions, mesh, kpt, ndim, skip_s_orb, use_all_orb, verbose)
This routine is an interface for constructing the orbital basis.
subroutine, public dorbitalbasis_build(this, namespace, ions, mesh, kpt, ndim, skip_s_orb, use_all_orb, verbose)
This routine is an interface for constructing the orbital basis.
subroutine, public dorbitalbasis_build_empty(this, mesh, ndim, norbsets, map_os, verbose)
This routine constructd an empty orbital basis.
subroutine, public zorbitalbasis_build_empty(this, mesh, ndim, norbsets, map_os, verbose)
This routine constructd an empty orbital basis.
subroutine, public orbitalbasis_init(this, namespace, periodic_dim)
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:381
subroutine, public dorbitalset_transfer_to_device(os, kpt, use_mesh)
Allocate and transfer the orbitals to the device.
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:285
subroutine, public zorbitalset_transfer_to_device(os, kpt, use_mesh)
Allocate and transfer the orbitals to the device.
integer, parameter, public sm_poisson_psolver
integer, parameter, public sm_poisson_isf
subroutine, public zorbitalset_get_center_of_mass(os, space, mesh, latt)
integer, parameter, public sm_poisson_direct
subroutine, public dorbitalset_get_center_of_mass(os, space, mesh, latt)
subroutine, public orbitalset_init_intersite(this, namespace, space, grp, ind, ions, der, psolver, os, nos, maxnorbs, rcut, kpt, has_phase, sm_poisson, basis_from_states, combine_j_orbitals)
integer, parameter, public sm_poisson_fft
integer function, public parse_block(namespace, name, blk, check_varinfo_)
Definition: parser.F90:623
integer, parameter, public restart_gs
Definition: restart.F90:156
integer, parameter, public restart_proj
Definition: restart.F90:156
integer, parameter, public restart_type_load
Definition: restart.F90:184
pure logical function, public states_are_complex(st)
pure logical function, public states_are_real(st)
This module handles spin dimensions of the states and the k-point distribution.
subroutine, public zsubmesh_copy_from_mesh(this, phi, sphi, conjugate)
Definition: submesh.F90:1749
subroutine, public dsubmesh_copy_from_mesh(this, phi, sphi, conjugate)
Definition: submesh.F90:1212
subroutine, public submesh_init(this, space, mesh, latt, center, rc)
Definition: submesh.F90:226
type(type_t), parameter, public type_cmplx
Definition: types.F90:136
type(type_t), parameter, public type_integer
Definition: types.F90:137
type(type_t), parameter, public type_float
Definition: types.F90:135
This module defines the unit system, used for input and output.
type(unit_system_t), public units_inp
the units systems for reading and writing
This class contains information about the boundary conditions.
Definition: boundaries.F90:159
Distribution of N instances over mpi_grpsize processes, for the local rank mpi_grprank....
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:171
Class to describe DFT+U parameters.
Definition: lda_u.F90:218
Describes mesh distribution to nodes.
Definition: mesh.F90:187
Stores all communicators and groups.
Definition: multicomm.F90:208
A container for the phase.
Definition: phase.F90:180
class for organizing spins and k-points
The states_elec_t class contains all electronic wave functions.
A submesh is a type of mesh, used for the projectors in the pseudopotentials It contains points on a ...
Definition: submesh.F90:174
int true(void)