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 if (gr%parallel_in_domains) then
418 call distributed_init_serial(this%orbs_dist, this%norbsets)
419 else
420 call distributed_init(this%orbs_dist, this%norbsets, mpi_world%comm, "orbsets")
421 end if
422
423 else
424
425 !%Variable DFTUBasisStates
426 !%Type block
427 !%Default none
428 !%Section Hamiltonian::DFT+U
429 !%Description
430 !% This block starts by a line containing a single integer describing the number of
431 !% orbital sets. One orbital set is a group of orbitals on which one adds a Hubbard U.
432 !% Each following line of this block contains the index of a state to be used to construct the
433 !% localized basis, followed by the index of the corresponding orbital set.
434 !% See DFTUBasisFromStates for details.
435 !%End
436 if (parse_block(namespace, 'DFTUBasisStates', blk) == 0) then
437 call parse_block_integer(blk, 0, 0, this%norbsets)
438 this%maxnorbs = parse_block_n(blk)-1
439 if (this%maxnorbs <1) then
440 write(message(1),'(a,i3,a,i3)') 'DFTUBasisStates must contains at least one state.'
441 call messages_fatal(1, namespace=namespace)
442 end if
443 safe_allocate(this%basisstates(1:this%maxnorbs))
444 safe_allocate(this%basisstates_os(1:this%maxnorbs))
445 do is = 1, this%maxnorbs
446 call parse_block_integer(blk, is, 0, this%basisstates(is))
447 call parse_block_integer(blk, is, 1, this%basisstates_os(is))
448 end do
449 call parse_block_end(blk)
450 else
451 write(message(1),'(a,i3,a,i3)') 'DFTUBasisStates must be specified if DFTUBasisFromStates=yes'
452 call messages_fatal(1, namespace=namespace)
453 end if
454
455 if (states_are_real(st)) then
456 call dorbitalbasis_build_empty(this%basis, gr, st%d%dim, this%norbsets, this%basisstates_os)
457 else
458 call zorbitalbasis_build_empty(this%basis, gr, st%d%dim, this%norbsets, this%basisstates_os)
459 end if
460
461 this%max_np = gr%np
462 this%nspins = st%d%nspin
463 this%spin_channels = st%d%spin_channels
464 this%nspecies = 1
465
466 this%orbsets => this%basis%orbsets
467
468 call distributed_init_serial(this%orbs_dist, this%norbsets)
469
470 !We allocate the necessary ressources
471 if (states_are_real(st)) then
472 call dlda_u_allocate(this, st)
473 else
474 call zlda_u_allocate(this, st)
475 end if
476
477 call lda_u_loadbasis(this, namespace, space, st, gr, mc, ierr)
478 if (ierr /= 0) then
479 message(1) = "Unable to load DFT+U basis from selected states."
480 call messages_fatal(1)
481 end if
482
483 end if
484
485 ! Symmetrization of the occupation matrices
486 this%symmetrize_occ_matrices = st%symmetrize_density .or. kpoints%use_symmetries
487 if (this%basisfromstates) this%symmetrize_occ_matrices = .false.
488 if (this%symmetrize_occ_matrices) then
489 call build_symmetrization_map(this, ions, gr)
490 end if
491
492 safe_allocate(this%dc_alpha(this%norbsets))
493 this%dc_alpha = m_one
494
495 call messages_print_with_emphasis(namespace=namespace)
496
497 pop_sub(lda_u_init)
498 end subroutine lda_u_init
499
500
501 ! ---------------------------------------------------------
502 subroutine lda_u_init_coulomb_integrals(this, namespace, space, gr, st, psolver)
503 type(lda_u_t), target, intent(inout) :: this
504 type(namespace_t), intent(in) :: namespace
505 class(space_t), intent(in) :: space
506 type(grid_t), intent(in) :: gr
507 type(states_elec_t), intent(in) :: st
508 type(poisson_t), intent(in) :: psolver
509
510 logical :: complex_coulomb_integrals
511 integer :: ios
512 integer :: norbs
513
515
516 norbs = this%maxnorbs
517
518 if (.not. this%basisfromstates) then
519
520 if (this%level == dft_u_acbn0) then
521
522 complex_coulomb_integrals = .false.
523 do ios = 1, this%norbsets
524 if (this%orbsets(ios)%ndim > 1) complex_coulomb_integrals = .true.
525 end do
526
527 if (.not. complex_coulomb_integrals) then
528 write(message(1),'(a)') 'Computing the Coulomb integrals of the localized basis.'
529 call messages_info(1, namespace=namespace)
530 safe_allocate(this%coulomb(1:norbs,1:norbs,1:norbs,1:norbs, 1:this%norbsets))
531 if (states_are_real(st)) then
532 call dcompute_coulomb_integrals(this, namespace, space, gr, psolver)
533 else
534 call zcompute_coulomb_integrals(this, namespace, space, gr, psolver)
535 end if
536 else
537 assert(.not. states_are_real(st))
538 write(message(1),'(a)') 'Computing complex Coulomb integrals of the localized basis.'
539 call messages_info(1, namespace=namespace)
540 safe_allocate(this%zcoulomb(1:norbs, 1:norbs, 1:norbs, 1:norbs, 1:st%d%dim, 1:st%d%dim, 1:this%norbsets))
541 call compute_complex_coulomb_integrals(this, gr, st, psolver, namespace, space)
542 end if
543 end if
544
545 else
546 write(message(1),'(a)') 'Computing the Coulomb integrals of the localized basis.'
547 call messages_info(1, namespace=namespace)
548 safe_allocate(this%coulomb(1:norbs, 1:norbs, 1:norbs, 1:norbs, 1:this%norbsets))
549 if (states_are_real(st)) then
550 call dcompute_coulomb_integrals(this, namespace, space, gr, psolver)
551 else
552 call zcompute_coulomb_integrals(this, namespace, space, gr, psolver)
553 end if
554
555 end if
556
558
559 end subroutine lda_u_init_coulomb_integrals
560
561
562 ! ---------------------------------------------------------
563 subroutine lda_u_end(this)
564 implicit none
565 type(lda_u_t), intent(inout) :: this
566
567 push_sub(lda_u_end)
568
569 this%level = dft_u_none
570
571 safe_deallocate_a(this%dn)
572 safe_deallocate_a(this%zn)
573 safe_deallocate_a(this%dn_alt)
574 safe_deallocate_a(this%zn_alt)
575 safe_deallocate_a(this%dV)
576 safe_deallocate_a(this%zV)
577 safe_deallocate_a(this%coulomb)
578 safe_deallocate_a(this%zcoulomb)
579 safe_deallocate_a(this%renorm_occ)
580 safe_deallocate_a(this%dn_ij)
581 safe_deallocate_a(this%zn_ij)
582 safe_deallocate_a(this%dn_alt_ij)
583 safe_deallocate_a(this%zn_alt_ij)
584 safe_deallocate_a(this%dn_alt_ii)
585 safe_deallocate_a(this%zn_alt_ii)
586 safe_deallocate_a(this%basisstates)
587 safe_deallocate_a(this%basisstates_os)
588 safe_deallocate_a(this%dc_alpha)
589 safe_deallocate_a(this%inv_map_symm)
590 safe_deallocate_a(this%symm_weight)
591
592 nullify(this%orbsets)
593 call orbitalbasis_end(this%basis)
594
595 this%max_np = 0
596
597 if (.not. this%basisfromstates) then
598 call distributed_end(this%orbs_dist)
599 end if
600
601 pop_sub(lda_u_end)
602 end subroutine lda_u_end
603
604 ! ---------------------------------------------------------
609 subroutine lda_u_rebind_after_copy(this, ions)
610 type(lda_u_t), target, intent(inout) :: this
611 type(ions_t), target, intent(in) :: ions
612
613 integer :: ios, ispec
614
616
617 if (this%level == dft_u_none) then
619 return
620 end if
621
622 this%latt => ions%latt
623
624 if (allocated(this%basis%orbsets)) then
625 this%orbsets => this%basis%orbsets
626 else
627 nullify(this%orbsets)
629 return
630 end if
631
632 do ios = 1, this%norbsets
633 if (.not. associated(this%orbsets(ios)%spec)) cycle
634
635 ispec = this%orbsets(ios)%spec_index
636 if (ispec < 1 .or. ispec > ions%nspecies) then
637 call messages_not_implemented("lda_u_rebind_after_copy with invalid species index")
638 end if
639 if (.not. associated(ions%species(ispec)%s)) then
640 call messages_not_implemented("lda_u_rebind_after_copy with unassociated ion species")
641 end if
642 this%orbsets(ios)%spec => ions%species(ispec)%s
643 end do
644
646 end subroutine lda_u_rebind_after_copy
647
648 ! ---------------------------------------------------------
654 subroutine lda_u_accel_rebuild(this, kpt)
655 type(lda_u_t), intent(inout) :: this
656 type(distributed_t), intent(in) :: kpt
657
658 integer :: ios, ik
659
660 push_sub(lda_u_accel_rebuild)
661
662 if (.not. accel_is_enabled()) then
663 pop_sub(lda_u_accel_rebuild)
664 return
665 end if
666
667 if (this%level == dft_u_none .or. .not. associated(this%orbsets)) then
668 pop_sub(lda_u_accel_rebuild)
669 return
670 end if
671
672 do ios = 1, this%norbsets
673 call accel_detach_buffer(this%orbsets(ios)%dbuff_orb)
674 call accel_detach_buffer(this%orbsets(ios)%zbuff_orb)
675 call accel_detach_buffer(this%orbsets(ios)%sphere%buff_map)
676
677 if (allocated(this%orbsets(ios)%buff_eorb)) then
678 do ik = lbound(this%orbsets(ios)%buff_eorb, dim=1), ubound(this%orbsets(ios)%buff_eorb, dim=1)
679 call accel_detach_buffer(this%orbsets(ios)%buff_eorb(ik))
680 end do
681 safe_deallocate_a(this%orbsets(ios)%buff_eorb)
682 end if
683
684 if (allocated(this%orbsets(ios)%dorb)) then
685 call dorbitalset_transfer_to_device(this%orbsets(ios), kpt, this%orbsets(ios)%allocated_on_mesh)
686 else if (allocated(this%orbsets(ios)%zorb)) then
687 call zorbitalset_transfer_to_device(this%orbsets(ios), kpt, this%orbsets(ios)%allocated_on_mesh)
688 else
689 call messages_not_implemented("lda_u_accel_rebuild with missing orbital arrays")
690 end if
691 end do
692
693 pop_sub(lda_u_accel_rebuild)
694 end subroutine lda_u_accel_rebuild
695
696 ! When moving the ions, the basis must be reconstructed
697 subroutine lda_u_update_basis(this, space, gr, ions, st, psolver, namespace, kpoints, has_phase)
698 type(lda_u_t), target, intent(inout) :: this
699 class(space_t), intent(in) :: space
700 type(grid_t), intent(in) :: gr
701 type(ions_t), target, intent(in) :: ions
702 type(states_elec_t), intent(in) :: st
703 type(poisson_t), intent(in) :: psolver
704 type(namespace_t), intent(in) :: namespace
705 type(kpoints_t), intent(in) :: kpoints
706 logical, intent(in) :: has_phase
707
708 integer :: ios, maxorbs, nspin
709
710 if(this%level == dft_u_none) return
711
712 push_sub(lda_u_update_basis)
713
714 if(.not. this%basisfromstates) then
715 !We clean the orbital basis, to be able to reconstruct it
716 call orbitalbasis_end(this%basis)
717 nullify(this%orbsets)
718
719 !We now reconstruct the basis
720 if (states_are_real(st)) then
721 call dorbitalbasis_build(this%basis, namespace, ions, gr, st%d%kpt, st%d%dim, &
722 this%skipSOrbitals, this%useAllOrbitals, verbose = .false.)
723 else
724 call zorbitalbasis_build(this%basis, namespace, ions, gr, st%d%kpt, st%d%dim, &
725 this%skipSOrbitals, this%useAllOrbitals, verbose = .false.)
726 end if
727 this%orbsets => this%basis%orbsets
728 this%max_np = this%basis%max_np
729 end if
730
731 !In case of intersite interaction we need to reconstruct the basis
732 if (this%intersite) then
733 this%maxneighbors = 0
734 do ios = 1, this%norbsets
735 call orbitalset_init_intersite(this%orbsets(ios), namespace, space, this%grp, ios, ions, gr%der, psolver, &
736 this%orbsets, this%norbsets, this%maxnorbs, this%intersite_radius, st%d%kpt, has_phase, &
737 this%sm_poisson, this%basisfromstates, this%basis%combine_j_orbitals)
738 this%maxneighbors = max(this%maxneighbors, this%orbsets(ios)%nneighbors)
739 end do
740
741 maxorbs = this%maxnorbs
742 nspin = this%nspins
743
744 if (states_are_real(st)) then
745 safe_deallocate_a(this%dn_ij)
746 safe_allocate(this%dn_ij(1:maxorbs,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors))
747 this%dn_ij(1:maxorbs,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors) = m_zero
748 safe_deallocate_a(this%dn_alt_ij)
749 safe_allocate(this%dn_alt_ij(1:maxorbs,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors))
750 this%dn_alt_ij(1:maxorbs,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors) = m_zero
751 safe_deallocate_a(this%dn_alt_ii)
752 safe_allocate(this%dn_alt_ii(1:2,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors))
753 this%dn_alt_ii(1:2,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors) = m_zero
754 else
755 safe_deallocate_a(this%zn_ij)
756 safe_allocate(this%zn_ij(1:maxorbs,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors))
757 this%zn_ij(1:maxorbs,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors) = m_z0
758 safe_deallocate_a(this%zn_alt_ij)
759 safe_allocate(this%zn_alt_ij(1:maxorbs,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors))
760 this%zn_alt_ij(1:maxorbs,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors) = m_z0
761 safe_deallocate_a(this%zn_alt_ii)
762 safe_allocate(this%zn_alt_ii(1:2,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors))
763 this%zn_alt_ii(1:2,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors) = m_z0
764 end if
765 end if
766
767 ! We rebuild the phase for the orbital projection, similarly to the one of the pseudopotentials
768 ! In case of a laser field, the phase is recomputed in hamiltonian_elec_update
769 if (has_phase) then
770 call lda_u_build_phase_correction(this, space, st%d, gr%der%boundaries, namespace, kpoints)
771 else
772 if(.not. this%basisfromstates) then
773 !In case there is no phase, we perform the orthogonalization here
774 if(this%basis%orthogonalization) then
775 call dloewdin_orthogonalize(this%basis, st%d%kpt, namespace)
776 else
777 if(debug%info .and. space%is_periodic()) then
778 call dloewdin_info(this%basis, st%d%kpt, namespace)
779 end if
780 end if
781 end if
782 end if
783
784 ! Rebuild the Coulomb integrals
785 if (allocated(this%coulomb)) then
786 safe_deallocate_a(this%coulomb)
787 end if
788 if (allocated(this%zcoulomb)) then
789 safe_deallocate_a(this%zcoulomb)
790 end if
791 call lda_u_init_coulomb_integrals(this, namespace, space, gr, st, psolver)
793 pop_sub(lda_u_update_basis)
794
795 end subroutine lda_u_update_basis
796
797 ! Interface for the X(update_occ_matrices) routines
798 subroutine lda_u_update_occ_matrices(this, namespace, mesh, st, phase, energy)
799 type(lda_u_t), intent(inout) :: this
800 type(namespace_t), intent(in) :: namespace
801 class(mesh_t), intent(in) :: mesh
802 type(states_elec_t), intent(inout) :: st
803 type(phase_t), intent(in) :: phase
804 type(energy_t), intent(inout) :: energy
805
806 if (this%level == dft_u_none .or. this%freeze_occ) return
808
809 if (states_are_real(st)) then
810 call dupdate_occ_matrices(this, namespace, mesh, st, energy%dft_u)
811 else
812 if (phase%is_allocated()) then
813 call zupdate_occ_matrices(this, namespace, mesh, st, energy%dft_u, phase)
814 else
815 call zupdate_occ_matrices(this, namespace, mesh, st, energy%dft_u)
816 end if
817 end if
818
820 end subroutine lda_u_update_occ_matrices
821
822
824 subroutine lda_u_build_phase_correction(this, space, std, boundaries, namespace, kpoints, vec_pot, vec_pot_var)
825 type(lda_u_t), intent(inout) :: this
826 class(space_t), intent(in) :: space
827 type(states_elec_dim_t), intent(in) :: std
828 type(boundaries_t), intent(in) :: boundaries
829 type(namespace_t), intent(in) :: namespace
830 type(kpoints_t), intent(in) :: kpoints
831 real(real64), optional, allocatable, intent(in) :: vec_pot(:)
832 real(real64), optional, allocatable, intent(in) :: vec_pot_var(:, :)
833
834 integer :: ios
835
836 if (boundaries%spiralBC) call messages_not_implemented("DFT+U with spiral boundary conditions", &
837 namespace=namespace)
838
840
841 write(message(1), '(a)') 'Debug: Building the phase correction for DFT+U orbitals.'
842 call messages_info(1, namespace=namespace, debug_only=.true.)
843
844 do ios = 1, this%norbsets
845 call orbitalset_update_phase(this%orbsets(ios), space%dim, std%kpt, kpoints, &
846 (std%ispin==spin_polarized), vec_pot, vec_pot_var)
847 call orbitalset_update_phase_shift(this%orbsets(ios), space%dim, std%kpt, kpoints, &
848 (std%ispin==spin_polarized), vec_pot, vec_pot_var)
849 end do
850
851 if (.not. this%basisfromstates) then
852 if (this%basis%orthogonalization) then
853 call zloewdin_orthogonalize(this%basis, std%kpt, namespace)
854 else
855 if (debug%info .and. space%is_periodic()) call zloewdin_info(this%basis, std%kpt, namespace)
856 end if
857 end if
858
860
861 end subroutine lda_u_build_phase_correction
862
863 ! ---------------------------------------------------------
864 subroutine compute_acbno_u_kanamori(this, st, kanamori)
865 type(lda_u_t), intent(in) :: this
866 type(states_elec_t), intent(in) :: st
867 real(real64), intent(out) :: kanamori(:,:)
868
869 if (this%nspins == 1) then
870 if (states_are_real(st)) then
871 call dcompute_acbno_u_kanamori_restricted(this, kanamori)
872 else
873 call zcompute_acbno_u_kanamori_restricted(this, kanamori)
874 end if
875 else
876 if (states_are_real(st)) then
877 call dcompute_acbno_u_kanamori(this, kanamori)
878 else
879 call zcompute_acbno_u_kanamori(this, kanamori)
880 end if
881 end if
882
883
884 end subroutine compute_acbno_u_kanamori
885
886 ! ---------------------------------------------------------
887 subroutine lda_u_freeze_occ(this)
888 type(lda_u_t), intent(inout) :: this
889
890 this%freeze_occ = .true.
891 end subroutine lda_u_freeze_occ
892
893 ! ---------------------------------------------------------
894 subroutine lda_u_freeze_u(this)
895 type(lda_u_t), intent(inout) :: this
896
897 this%freeze_u = .true.
898 end subroutine lda_u_freeze_u
899
900 ! ---------------------------------------------------------
901 subroutine lda_u_set_effectiveu(this, Ueff)
902 type(lda_u_t), intent(inout) :: this
903 real(real64), intent(in) :: ueff(:)
904
905 integer :: ios
906
907 push_sub(lda_u_set_effectiveu)
908
909 do ios = 1,this%norbsets
910 this%orbsets(ios)%Ueff = ueff(ios)
911 end do
912
913 pop_sub(lda_u_set_effectiveu)
914 end subroutine lda_u_set_effectiveu
915
916 ! ---------------------------------------------------------
917 subroutine lda_u_get_effectiveu(this, Ueff)
918 type(lda_u_t), intent(in) :: this
919 real(real64), intent(inout) :: ueff(:)
920
921 integer :: ios
922
923 push_sub(lda_u_get_effectiveu)
924
925 do ios = 1,this%norbsets
926 ueff(ios) = this%orbsets(ios)%Ueff
927 end do
928
929 pop_sub(lda_u_get_effectiveu)
930 end subroutine lda_u_get_effectiveu
931
932 ! ---------------------------------------------------------
933 subroutine lda_u_set_effectivev(this, Veff)
934 type(lda_u_t), intent(inout) :: this
935 real(real64), intent(in) :: veff(:)
936
937 integer :: ios, ncount
938
939 push_sub(lda_u_set_effectivev)
940
941 ncount = 0
942 do ios = 1, this%norbsets
943 this%orbsets(ios)%V_ij(1:this%orbsets(ios)%nneighbors,0) = veff(ncount+1:ncount+this%orbsets(ios)%nneighbors)
944 ncount = ncount + this%orbsets(ios)%nneighbors
945 end do
946
947 pop_sub(lda_u_set_effectivev)
948 end subroutine lda_u_set_effectivev
949
950 ! ---------------------------------------------------------
951 subroutine lda_u_get_effectivev(this, Veff)
952 type(lda_u_t), intent(in) :: this
953 real(real64), intent(inout) :: veff(:)
954
955 integer :: ios, ncount
956
957 push_sub(lda_u_get_effectivev)
958
959 ncount = 0
960 do ios = 1, this%norbsets
961 veff(ncount+1:ncount+this%orbsets(ios)%nneighbors) = this%orbsets(ios)%V_ij(1:this%orbsets(ios)%nneighbors,0)
962 ncount = ncount + this%orbsets(ios)%nneighbors
963 end do
964
965 pop_sub(lda_u_get_effectivev)
966 end subroutine lda_u_get_effectivev
967
968 ! ---------------------------------------------------------
969 subroutine lda_u_write_info(this, iunit, namespace)
970 type(lda_u_t), intent(in) :: this
971 integer, optional, intent(in) :: iunit
972 type(namespace_t), optional, intent(in) :: namespace
973
974 push_sub(lda_u_write_info)
975
976 write(message(1), '(1x)')
977 call messages_info(1, iunit=iunit, namespace=namespace)
978 if (this%level == dft_u_empirical) then
979 write(message(1), '(a)') "Method:"
980 write(message(2), '(a)') " [1] Dudarev et al., Phys. Rev. B 57, 1505 (1998)"
981 call messages_info(2, iunit=iunit, namespace=namespace)
982 else
983 if (.not. this%intersite) then
984 write(message(1), '(a)') "Method:"
985 write(message(2), '(a)') " [1] Agapito et al., Phys. Rev. X 5, 011006 (2015)"
986 else
987 write(message(1), '(a)') "Method:"
988 write(message(2), '(a)') " [1] Tancogne-Dejean, and Rubio, Phys. Rev. B 102, 155117 (2020)"
989 end if
990 call messages_info(2, iunit=iunit, namespace=namespace)
991 end if
992 write(message(1), '(a)') "Implementation:"
993 write(message(2), '(a)') " [1] Tancogne-Dejean, Oliveira, and Rubio, Phys. Rev. B 69, 245133 (2017)"
994 write(message(3), '(1x)')
995 call messages_info(3, iunit=iunit, namespace=namespace)
997 pop_sub(lda_u_write_info)
998
999 end subroutine lda_u_write_info
1000
1001 ! ---------------------------------------------------------
1002 subroutine lda_u_loadbasis(this, namespace, space, st, mesh, mc, ierr)
1003 type(lda_u_t), intent(inout) :: this
1004 type(namespace_t), intent(in) :: namespace
1005 class(space_t), intent(in) :: space
1006 type(states_elec_t), intent(in) :: st
1007 class(mesh_t), intent(in) :: mesh
1008 type(multicomm_t), intent(in) :: mc
1009 integer, intent(out) :: ierr
1010
1011 integer :: err, wfns_file, is, ist, idim, ik, ios, iorb
1013 character(len=256) :: lines(3)
1014 character(len=256), allocatable :: restart_file(:, :)
1015 logical, allocatable :: restart_file_present(:, :)
1016 character(len=12) :: filename
1017 character(len=1) :: char
1018 character(len=50) :: str
1019 type(orbitalset_t), pointer :: os
1020 integer, allocatable :: count(:)
1021 real(real64) :: norm, center(space%dim)
1022 real(real64), allocatable :: dpsi(:,:,:)
1023 complex(real64), allocatable :: zpsi(:,:,:)
1024
1025
1026 push_sub(lda_u_loadbasis)
1027
1028 ierr = 0
1029
1030 message(1) = "Debug: Loading DFT+U basis from states."
1031 call messages_info(1, debug_only=.true.)
1032
1033 call restart_gs%init(namespace, restart_proj, restart_type_load, mc, err, mesh=mesh)
1034
1035 ! If any error occured up to this point then it is not worth continuing,
1036 ! as there something fundamentally wrong with the restart files
1037 if (err /= 0) then
1038 call restart_gs%end()
1039 message(1) = "Error loading DFT+U basis from states, cannot proceed with the calculation"
1040 call messages_fatal(1)
1041 pop_sub(lda_u_loadbasis)
1042 return
1043 end if
1044 ! only supported for obf format
1045 if (restart_gs%file_format_states /= option__restartfileformatstates__obf) then
1046 message(1) = "Error: loading DFT+U basis only supported for OBF restart format"
1047 message(2) = "Please set RestartFileFormatStates = obf and re-run the GS calculation."
1048 call messages_fatal(2)
1049 end if
1050
1051 ! open files to read
1052 wfns_file = restart_gs%open('wfns')
1053 call restart_gs%read(wfns_file, lines, 2, err)
1054 if (err /= 0) then
1055 ierr = ierr - 2**5
1056 else if (states_are_real(st)) then
1057 read(lines(2), '(a)') str
1058 if (str(2:8) == 'Complex') then
1059 message(1) = "Cannot read real states from complex wavefunctions."
1060 call messages_fatal(1, namespace=namespace)
1061 else if (str(2:5) /= 'Real') then
1062 message(1) = "Restart file 'wfns' does not specify real/complex; cannot check compatibility."
1063 call messages_warning(1, namespace=namespace)
1064 end if
1065 end if
1066 ! complex can be restarted from real, so there is no problem.
1067
1068 ! If any error occured up to this point then it is not worth continuing,
1069 ! as there something fundamentally wrong with the restart files
1070 if (err /= 0) then
1071 call restart_gs%close(wfns_file)
1072 call restart_gs%end()
1073 message(1) = "Error loading DFT+U basis from states, cannot proceed with the calculation"
1074 call messages_fatal(1)
1075 pop_sub(lda_u_loadbasis)
1076 return
1077 end if
1078
1079 safe_allocate(restart_file(1:st%d%dim, 1:st%nst))
1080 safe_allocate(restart_file_present(1:st%d%dim, 1:st%nst))
1081 restart_file_present = .false.
1082
1083 ! Next we read the list of states from the files.
1084 ! Errors in reading the information of a specific state from the files are ignored
1085 ! at this point, because later we will skip reading the wavefunction of that state.
1086 do
1087 call restart_gs%read(wfns_file, lines, 1, err)
1088 if (err == 0) then
1089 read(lines(1), '(a)') char
1090 if (char == '%') then
1091 !We reached the end of the file
1092 exit
1093 else
1094 read(lines(1), *) ik, char, ist, char, idim, char, filename
1095 end if
1096 end if
1098 if (any(this%basisstates==ist) .and. ik == 1) then
1099 restart_file(idim, ist) = trim(filename)
1100 restart_file_present(idim, ist) = .true.
1101 end if
1102 end do
1103 call restart_gs%close(wfns_file)
1104
1105 !We loop over the states we need
1106 safe_allocate(count(1:this%norbsets))
1107 count = 0
1108 do is = 1, this%maxnorbs
1109 ist = this%basisstates(is)
1110 ios = this%basisstates_os(is)
1111 count(ios) = count(ios)+1
1112 do idim = 1, st%d%dim
1113
1114 if (.not. restart_file_present(idim, ist)) then
1115 write(message(1), '(a,i3,a)') "Cannot read states ", ist, "from the projection folder"
1116 call messages_fatal(1, namespace=namespace)
1117 end if
1118
1119 if (states_are_real(st)) then
1120 call restart_gs%read_mesh_function(restart_file(idim, ist), mesh, &
1121 this%orbsets(ios)%dorb(:,idim,count(ios)), err)
1122 else
1123 call restart_gs%read_mesh_function(restart_file(idim, ist), mesh, &
1124 this%orbsets(ios)%zorb(:,idim,count(ios)), err)
1125 end if
1126 if (err /= 0) then
1127 message(1) = "Error loading mesh function "//trim(restart_file(idim, ist))
1128 call messages_fatal(1)
1129 end if
1130 end do
1131 end do
1132 safe_deallocate_a(count)
1133 safe_deallocate_a(restart_file)
1134 safe_deallocate_a(restart_file_present)
1135 call restart_gs%end()
1136
1137 ! Normalize the orbitals. This is important if we use Wannier orbitals instead of KS states
1138 if(this%basis%normalize) then
1139 do ios = 1, this%norbsets
1140 do iorb = 1, this%orbsets(ios)%norbs
1141 if (states_are_real(st)) then
1142 norm = dmf_nrm2(mesh, st%d%dim, this%orbsets(ios)%dorb(:,:,iorb))
1143 call lalg_scal(mesh%np, st%d%dim, m_one/norm, this%orbsets(ios)%dorb(:,:,iorb))
1144 else
1145 norm = zmf_nrm2(mesh, st%d%dim, this%orbsets(ios)%zorb(:,:,iorb))
1146 call lalg_scal(mesh%np, st%d%dim, m_one/norm, this%orbsets(ios)%zorb(:,:,iorb))
1147 end if
1148 end do
1149 end do
1150 end if
1151
1152 ! We rotate the orbitals in the complex plane to have them as close as possible to real functions
1153 if(states_are_complex(st) .and. st%d%dim == 1) then
1154 do ios = 1, this%norbsets
1155 do iorb = 1, this%orbsets(ios)%norbs
1156 call zmf_fix_phase(mesh, this%orbsets(ios)%zorb(:,1,iorb))
1157 end do
1158 end do
1159 end if
1160
1161 ! We determine the center of charge by computing <w|r|w>
1162 ! We could also determine the spread by \Omega = <w|r^2|w> - <w|r|w>^2
1163 do ios = 1, this%norbsets
1164 if (states_are_real(st)) then
1165 call dorbitalset_get_center_of_mass(this%orbsets(ios), space, mesh, this%latt)
1166 else
1167 call zorbitalset_get_center_of_mass(this%orbsets(ios), space, mesh, this%latt)
1168 end if
1169 end do
1170
1171 message(1) = "Debug: Converting the Wannier states to submeshes."
1172 call messages_info(1, debug_only=.true.)
1173
1174 ! We now transfer the states to a submesh centered on the center of mass of the Wannier orbitals
1175 this%max_np = 0
1176 do ios = 1, this%norbsets
1177 os => this%orbsets(ios)
1178 center = os%sphere%center
1179 safe_deallocate_a(os%sphere%center)
1180 if (states_are_real(st)) then
1181 safe_allocate(dpsi(1:mesh%np, 1:os%ndim, 1:os%norbs))
1182 dpsi(1:mesh%np, 1:os%ndim, 1:os%norbs) = os%dorb(1:mesh%np, 1:os%ndim, 1:os%norbs)
1183
1184 safe_deallocate_a(os%dorb)
1185 !We initialise the submesh corresponding to the orbital
1186 call submesh_init(os%sphere, space, mesh, this%latt, center, os%radius)
1187 safe_allocate(os%dorb(1:os%sphere%np, 1:os%ndim, 1:os%norbs))
1188 do iorb = 1, os%norbs
1189 do idim = 1, os%ndim
1190 call dsubmesh_copy_from_mesh(os%sphere, dpsi(:,idim,iorb), os%dorb(:,idim, iorb))
1191 end do
1192 end do
1193 safe_deallocate_a(dpsi)
1194 else
1195 safe_allocate(zpsi(1:mesh%np, 1:os%ndim, 1:os%norbs))
1196 zpsi(1:mesh%np, 1:os%ndim, 1:os%norbs) = os%zorb(1:mesh%np, 1:os%ndim, 1:os%norbs)
1197 safe_deallocate_a(os%zorb)
1198 !We initialise the submesh corresponding to the orbital
1199 call submesh_init(os%sphere, space, mesh, this%latt, center, os%radius)
1200 safe_allocate(os%zorb(1:os%sphere%np, 1:os%ndim, 1:os%norbs))
1201 do iorb = 1, os%norbs
1202 do idim = 1, os%ndim
1203 call zsubmesh_copy_from_mesh(os%sphere, zpsi(:,idim,iorb), os%zorb(:,idim, iorb))
1204 end do
1205 end do
1206 safe_deallocate_a(zpsi)
1207
1208 safe_allocate(os%phase(1:os%sphere%np, st%d%kpt%start:st%d%kpt%end))
1209 safe_allocate(os%eorb_submesh(1:os%sphere%np, 1:os%ndim, 1:os%norbs, st%d%kpt%start:st%d%kpt%end))
1210 end if
1211 os%use_submesh = .true. ! We are now on a submesh
1212 this%max_np = max(this%max_np, os%sphere%np)
1213 end do
1214
1215 this%basis%use_submesh = .true.
1216
1217 ! If we use GPUs, we need to transfert the orbitals on the device
1218 if (accel_is_enabled() .and. st%d%dim == 1) then
1219 do ios = 1, this%norbsets
1220 os => this%orbsets(ios)
1221
1222 os%ldorbs = max(accel_padded_size(os%sphere%np), 1)
1223 os%ldorbs_eorb = max(accel_padded_size(os%sphere%np), 1)
1224 if (states_are_real(st)) then
1225 call accel_create_buffer(os%dbuff_orb, accel_mem_read_only, type_float, os%ldorbs*os%norbs)
1226 else
1227 call accel_create_buffer(os%zbuff_orb, accel_mem_read_only, type_cmplx, os%ldorbs*os%norbs)
1228 safe_allocate(os%buff_eorb(st%d%kpt%start:st%d%kpt%end))
1229
1230 do ik= st%d%kpt%start, st%d%kpt%end
1231 call accel_create_buffer(os%buff_eorb(ik), accel_mem_read_only, type_cmplx, os%ldorbs_eorb*os%norbs)
1232 end do
1233 end if
1234
1235 call accel_create_buffer(os%sphere%buff_map, accel_mem_read_only, type_integer, max(os%sphere%np, 1))
1236 call accel_write_buffer(os%sphere%buff_map, os%sphere%np, os%sphere%map)
1237
1238 do iorb = 1, os%norbs
1239 if(states_are_complex(st)) then
1240 call accel_write_buffer(os%zbuff_orb, os%sphere%np, os%zorb(:, 1, iorb), &
1241 offset = (iorb - 1)*os%ldorbs)
1242 else
1243 call accel_write_buffer(os%dbuff_orb, os%sphere%np, os%dorb(:, 1, iorb), &
1244 offset = (iorb - 1)*os%ldorbs)
1245 end if
1246 end do
1247 end do
1248 end if
1249
1250
1251 message(1) = "Debug: Loading DFT+U basis from states done."
1252 call messages_info(1, debug_only=.true.)
1253
1254 pop_sub(lda_u_loadbasis)
1255 end subroutine lda_u_loadbasis
1256
1258 subroutine build_symmetrization_map(this, ions, gr)
1259 type(lda_u_t), intent(inout) :: this
1260 type(ions_t), intent(in) :: ions
1261 type(grid_t), intent(in) :: gr
1262
1263 integer :: nsym, iop, ios, iatom, iatom_sym, ios_sym
1264
1265 push_sub(build_symmetrization_map)
1266
1267 nsym = ions%symm%nops
1268 safe_allocate(this%inv_map_symm(1:this%norbsets, 1:nsym))
1269 this%inv_map_symm = -1
1270
1271 this%nsym = nsym
1272
1273 do ios = 1, this%norbsets
1274 iatom = this%orbsets(ios)%iatom
1275 do iop = 1, nsym
1276 iatom_sym = ions%inv_map_symm_atoms(iatom, iop)
1277
1278 do ios_sym = 1, this%norbsets
1279 if (this%orbsets(ios_sym)%iatom == iatom_sym .and. this%orbsets(ios_sym)%norbs == this%orbsets(ios)%norbs &
1280 .and. this%orbsets(ios_sym)%nn == this%orbsets(ios)%nn .and. this%orbsets(ios_sym)%ll == this%orbsets(ios)%ll &
1281 .and. is_close(this%orbsets(ios_sym)%jj, this%orbsets(ios)%jj)) then
1282 this%inv_map_symm(ios, iop) = ios_sym
1283 exit
1284 end if
1285 end do
1286 assert(this%inv_map_symm(ios, iop) > 0)
1287 end do
1288 end do
1289
1290 safe_allocate(this%symm_weight(1:this%maxnorbs, 1:this%maxnorbs, 1:this%nsym, 1:this%norbsets))
1291 this%symm_weight = m_zero
1292
1293 do ios = 1, this%norbsets
1294 ! s-orbitals
1295 if (this%orbsets(ios)%norbs == 1) then
1296 this%symm_weight(1,1, 1:this%nsym, ios) = m_one
1297 cycle
1298 end if
1299
1300 ! Not implemented yet
1301 if (this%orbsets(ios)%ndim > 1) cycle
1302
1303 call orbitals_get_symm_weight(this%orbsets(ios), ions%space, ions%latt, gr, ions%symm, this%symm_weight(:,:,:,ios))
1304 end do
1305
1307 end subroutine build_symmetrization_map
1308
1310 subroutine orbitals_get_symm_weight(os, space, latt, gr, symm, weight)
1311 type(orbitalset_t), intent(in) :: os
1312 type(space_t), intent(in) :: space
1313 type(lattice_vectors_t), intent(in) :: latt
1314 type(grid_t), intent(in) :: gr
1315 type(symmetries_t), intent(in) :: symm
1316 real(real64), intent(inout) :: weight(:,:,:)
1317
1318 integer :: im, imp, iop, mm
1319 real(real64), allocatable :: orb(:,:), orb_sym(:), ylm(:)
1320 type(submesh_t) :: sphere
1321 real(real64) :: rc, norm, origin(space%dim)
1322
1323 push_sub(orbitals_get_symm_weight)
1324
1325 assert(os%ndim == 1)
1326
1327 safe_allocate(orb_sym(1:gr%np))
1328 safe_allocate(orb(1:gr%np, 1:os%norbs))
1329
1330 assert(2*os%ll+1 == os%norbs)
1331
1332 ! We generate an artificial submesh to compute the symmetries on it
1333 ! The radius is such that we fit in 20 points
1334 rc = (50.0_real64 * m_three/m_four/m_pi*product(gr%spacing))**m_third
1335 origin = m_zero
1336 call submesh_init(sphere, space, gr, latt, origin, rc)
1337
1338 safe_allocate(ylm(1:sphere%np))
1339
1340 ! We then compute the spherical harmonics in this submesh
1341 do im = 1, os%norbs
1342 mm = im-1-os%ll
1343 call loct_ylm(sphere%np, sphere%rel_x(1,1), sphere%r(1), os%ll, mm, ylm(1))
1344 orb(:,im) = m_zero
1345 call submesh_add_to_mesh(sphere, ylm, orb(:,im))
1346 norm = dmf_nrm2(gr, orb(:,im))
1347 call lalg_scal(gr%np, m_one / norm, orb(:,im))
1348 end do
1349 safe_deallocate_a(ylm)
1350
1351 ! Then we put them on the grid, rotate them
1352 do im = 1, os%norbs
1353 do iop = 1, symm%nops
1354 call dgrid_symmetrize_single(gr, iop, orb(:,im), orb_sym)
1355
1356 do imp = 1, os%norbs
1357 weight(im, imp, iop) = dmf_dotp(gr, orb(:,imp), orb_sym, reduce=.false.)
1358 end do
1359 end do
1360 end do
1361
1362 call gr%allreduce(weight)
1363
1364 safe_deallocate_a(orb)
1365 safe_deallocate_a(orb_sym)
1366
1368 end subroutine orbitals_get_symm_weight
1369
1370#include "dft_u_noncollinear_inc.F90"
1371
1372#include "undef.F90"
1373#include "real.F90"
1374#include "lda_u_inc.F90"
1375
1376#include "undef.F90"
1377#include "complex.F90"
1378#include "lda_u_inc.F90"
1379end 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:1010
pure logical function, public accel_is_enabled()
Definition: accel.F90:372
integer, parameter, public accel_mem_read_only
Definition: accel.F90:185
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:156
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
subroutine, public distributed_end(this)
subroutine, public distributed_init(this, total, comm, tag, scalapack_compat)
Distribute N instances across M processes of communicator comm
subroutine, public distributed_init_serial(this, total)
Serial initialization of a distributed instance. The calling process is assigned all total instances,...
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:736
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:5087
subroutine zlda_u_allocate(this, st)
Definition: lda_u.F90:5659
subroutine, public lda_u_get_effectiveu(this, Ueff)
Definition: lda_u.F90:1013
subroutine compute_complex_coulomb_integrals(this, gr, st, psolver, namespace, space)
Definition: lda_u.F90:1487
subroutine, public dlda_u_force(this, namespace, space, mesh, st, iq, psib, grad_psib, force)
Definition: lda_u.F90:3272
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:1854
subroutine, public lda_u_set_effectiveu(this, Ueff)
Definition: lda_u.F90:997
subroutine build_symmetrization_map(this, ions, gr)
Builds a mapping between the orbital sets based on symmetries.
Definition: lda_u.F90:1354
subroutine dcompute_acbno_u_kanamori_restricted(this, kanamori)
This routine computes the Kanamori U, Up, and J.
Definition: lda_u.F90:2873
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:3577
subroutine, public dlda_u_rvu(this, mesh, space, d, namespace, psib, gpsib)
This routine computes .
Definition: lda_u.F90:3410
subroutine, public lda_u_update_basis(this, space, gr, ions, st, psolver, namespace, kpoints, has_phase)
Definition: lda_u.F90:793
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:1406
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:1912
subroutine, public lda_u_accel_rebuild(this, kpt)
Rebuild DFT+U accelerator buffers after intrinsic assignment.
Definition: lda_u.F90:750
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:3826
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:4285
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:4845
subroutine dcompute_acbno_u_kanamori(this, kanamori)
This routine computes the Kanamori U, Up, and J.
Definition: lda_u.F90:2774
subroutine, public zlda_u_commute_r_single(this, mesh, space, d, namespace, ist, ik, psi, gpsi, has_phase)
Definition: lda_u.F90:5036
subroutine, public lda_u_freeze_occ(this)
Definition: lda_u.F90:983
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:705
subroutine, public lda_u_freeze_u(this)
Definition: lda_u.F90:990
subroutine, public zlda_u_rvu(this, mesh, space, d, namespace, psib, gpsib)
This routine computes .
Definition: lda_u.F90:5412
subroutine dlda_u_allocate(this, st)
Definition: lda_u.F90:3636
subroutine, public compute_acbno_u_kanamori(this, st, kanamori)
Definition: lda_u.F90:960
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:4359
subroutine lda_u_init_coulomb_integrals(this, namespace, space, gr, st, psolver)
Definition: lda_u.F90:598
subroutine, public lda_u_write_info(this, iunit, namespace)
Definition: lda_u.F90:1065
subroutine, public dlda_u_commute_r(this, mesh, space, d, namespace, psib, gpsib)
This routine computes [r,V_lda+u] .
Definition: lda_u.F90:3115
subroutine, public zlda_u_force(this, namespace, space, mesh, st, iq, psib, grad_psib, force)
Definition: lda_u.F90:5274
subroutine dcompute_coulomb_integrals(this, namespace, space, gr, psolver)
Definition: lda_u.F90:2948
subroutine, public dlda_u_set_occupations(this, occ)
Definition: lda_u.F90:3520
subroutine, public lda_u_get_effectivev(this, Veff)
Definition: lda_u.F90:1047
subroutine lda_u_loadbasis(this, namespace, space, st, mesh, mc, ierr)
Definition: lda_u.F90:1098
subroutine, public dlda_u_commute_r_single(this, mesh, space, d, namespace, ist, ik, psi, gpsi, has_phase)
Definition: lda_u.F90:3064
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:920
subroutine, public lda_u_end(this)
Definition: lda_u.F90:659
subroutine, public lda_u_set_effectivev(this, Veff)
Definition: lda_u.F90:1029
subroutine, public lda_u_update_occ_matrices(this, namespace, mesh, st, phase, energy)
Definition: lda_u.F90:894
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:4746
subroutine zcompute_coulomb_integrals(this, namespace, space, gr, psolver)
Definition: lda_u.F90:4920
subroutine, public zlda_u_get_occupations(this, occ)
Definition: lda_u.F90:5600
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:3884
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:2313
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:2387
subroutine, public zlda_u_set_occupations(this, occ)
Definition: lda_u.F90:5543
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
type(mpi_grp_t), public mpi_world
Definition: mpi.F90:276
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:1786
subroutine, public dsubmesh_copy_from_mesh(this, phi, sphi, conjugate)
Definition: submesh.F90:1232
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)