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