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