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 mesh_oct_m
46 use mpi_oct_m
52 use parser_oct_m
54 use phase_oct_m
57 use space_oct_m
64 use types_oct_m
67
68 implicit none
69
70 private
71
72 public :: &
73 lda_u_t, &
74 lda_u_init, &
79 lda_u_end, &
99 dlda_u_rvu, &
100 zlda_u_rvu, &
105
106
107 integer, public, parameter :: &
108 DFT_U_NONE = 0, &
109 dft_u_empirical = 1, &
110 dft_u_acbn0 = 2
111
112 integer, public, parameter :: &
113 DFT_U_FLL = 0, &
115 dft_u_mix = 2
116
117
120 type lda_u_t
121 private
122 integer, public :: level = dft_u_none
123
124 ! DFT+U basic variables
125 real(real64), allocatable, public :: dn(:,:,:,:)
126 real(real64), allocatable :: dV(:,:,:,:)
127
128 ! ACBN0 variables
129 complex(real64), allocatable, public :: zn(:,:,:,:)
130 complex(real64), allocatable :: zV(:,:,:,:)
131 real(real64), allocatable, public :: dn_alt(:,:,:,:)
132 complex(real64), allocatable, public :: zn_alt(:,:,:,:)
133
134 real(real64), allocatable :: renorm_occ(:,:,:,:,:)
135
136 ! Coulomb integrales
137 real(real64), allocatable, public :: coulomb(:,:,:,:,:)
138 ! !<(for the ACBN0 functional)
139 complex(real64), allocatable, public :: zcoulomb(:,:,:,:,:,:,:)
140 ! !< (for the ACBN0 functional with spinors)
141
142 type(orbitalbasis_t), public :: basis
143 type(orbitalset_t), pointer, public :: orbsets(:) => null()
144 integer, public :: norbsets = 0
145
146 integer, public :: nspins = 0
147 integer, public :: spin_channels = 0
148 integer :: nspecies = 0
149 integer, public :: maxnorbs = 0
150 integer :: max_np = 0
151
152 logical :: useAllOrbitals = .false.
153 logical :: skipSOrbitals = .true.
154 logical :: freeze_occ = .false.
155 logical :: freeze_u = .false.
156 logical, public :: intersite = .false.
157 real(real64) :: intersite_radius = m_zero
158 logical, public :: basisfromstates = .false.
159 real(real64) :: acbn0_screening = m_one
160 integer, allocatable :: basisstates(:)
161 integer, allocatable :: basisstates_os(:)
162 logical :: rot_inv = .false.
163 integer :: double_couting = dft_u_fll
164 integer :: sm_poisson = sm_poisson_direct
165 real(real64), allocatable :: dc_alpha(:)
166
167 type(lattice_vectors_t), pointer :: latt
168
169 type(distributed_t) :: orbs_dist
170
171 ! Intersite interaction variables
172 integer, public :: maxneighbors = 0
173 real(real64), allocatable, public :: dn_ij(:,:,:,:,:), dn_alt_ij(:,:,:,:,:), dn_alt_ii(:,:,:,:,:)
174 complex(real64), allocatable, public :: zn_ij(:,:,:,:,:), zn_alt_ij(:,:,:,:,:), zn_alt_ii(:,:,:,:,:)
175
176 ! Symmetrization-related variables
177 logical :: symmetrize_occ_matrices
178 integer, allocatable :: inv_map_symm(:,:)
179 integer :: nsym
180 real(real64), allocatable :: symm_weight(:,:,:,:)
181 end type lda_u_t
182
183contains
184
185 ! ---------------------------------------------------------
186 subroutine lda_u_init(this, namespace, space, level, gr, ions, st, mc, kpoints, has_phase)
187 type(lda_u_t), target, intent(inout) :: this
188 type(namespace_t), intent(in) :: namespace
189 class(space_t), intent(in) :: space
190 integer, intent(in) :: level
191 type(grid_t), intent(in) :: gr
192 type(ions_t), target, intent(in) :: ions
193 type(states_elec_t), intent(in) :: st
194 type(multicomm_t), intent(in) :: mc
195 type(kpoints_t), intent(in) :: kpoints
196 logical, intent(in) :: has_phase
197
198 integer :: is, ierr
199 type(block_t) :: blk
201 push_sub(lda_u_init)
202
203 assert(.not. (level == dft_u_none))
204
205 call messages_print_with_emphasis(msg="DFT+U", namespace=namespace)
206 if (gr%parallel_in_domains) call messages_experimental("dft+u parallel in domains", namespace=namespace)
207 this%level = level
208
209 this%latt => ions%latt
210
211 !%Variable DFTUBasisFromStates
212 !%Type logical
213 !%Default no
214 !%Section Hamiltonian::DFT+U
215 !%Description
216 !% If set to yes, Octopus will construct the localized basis from
217 !% user-defined states. The states are taken at the Gamma point (or the first k-point of the
218 !% states in the restart_proj folder.
219 !% The states are defined via the block DFTUBasisStates
220 !%End
221 call parse_variable(namespace, 'DFTUBasisFromStates', .false., this%basisfromstates)
222 if (this%basisfromstates) call messages_experimental("DFTUBasisFromStates", namespace=namespace)
224 !%Variable DFTUDoubleCounting
225 !%Type integer
226 !%Default dft_u_fll
227 !%Section Hamiltonian::DFT+U
228 !%Description
229 !% This variable selects which DFT+U
230 !% double counting term is used.
231 !%Option dft_u_fll 0
232 !% (Default) The Fully Localized Limit (FLL)
233 !%Option dft_u_amf 1
234 !% (Experimental) Around mean field double counting, as defined in PRB 44, 943 (1991) and PRB 49, 14211 (1994).
235 !%Option dft_u_mix 2
236 !% (Experimental) Mixed double countind term as introduced by Petukhov et al., PRB 67, 153106 (2003).
237 !% This recovers the FLL and AMF as limiting cases.
238 !%End
239 call parse_variable(namespace, 'DFTUDoubleCounting', dft_u_fll, this%double_couting)
240 call messages_print_var_option('DFTUDoubleCounting', this%double_couting, namespace=namespace)
241 if (this%double_couting /= dft_u_fll) call messages_experimental("DFTUDoubleCounting /= dft_u_ffl", namespace=namespace)
242 if (st%d%ispin == spinors .and. this%double_couting /= dft_u_fll) then
243 call messages_not_implemented("AMF and MIX double counting with spinors", namespace=namespace)
244 end if
246 !%Variable DFTUPoissonSolver
247 !%Type integer
248 !%Section Hamiltonian::DFT+U
249 !%Description
250 !% This variable selects which Poisson solver
251 !% is used to compute the Coulomb integrals over a submesh.
252 !% These are non-periodic Poisson solvers.
253 !% The FFT Poisson solver with spherical cutoff is used by default.
254 !%
255 !%Option dft_u_poisson_direct 0
256 !% Direct Poisson solver. Slow but working in all cases.
257 !%Option dft_u_poisson_isf 1
258 !% (Experimental) ISF Poisson solver on a submesh.
259 !% This does not work for non-orthogonal cells nor domain parallelization.
260 !%Option dft_u_poisson_psolver 2
261 !% (Experimental) PSolver Poisson solver on a submesh.
262 !% This does not work for non-orthogonal cells nor domain parallelization.
263 !% Requires the PSolver external library.
264 !%Option dft_u_poisson_fft 3
265 !% (Default) FFT Poisson solver on a submesh.
266 !% This uses the 0D periodic version of the FFT kernels.
267 !%End
268 call parse_variable(namespace, 'DFTUPoissonSolver', sm_poisson_fft, this%sm_poisson)
269 call messages_print_var_option('DFTUPoissonSolver', this%sm_poisson, namespace=namespace)
270 if (this%sm_poisson /= sm_poisson_direct .and. this%sm_poisson /= sm_poisson_fft) then
271 call messages_experimental("DFTUPoissonSolver different from dft_u_poisson_direct", namespace=namespace)
272 call messages_experimental("and dft_u_poisson_fft", namespace=namespace)
273 end if
274 if (this%sm_poisson == sm_poisson_isf) then
275 if (gr%parallel_in_domains) then
276 call messages_not_implemented("DFTUPoissonSolver=dft_u_poisson_isf with domain parallelization", namespace=namespace)
277 end if
278 if (ions%latt%nonorthogonal) then
279 call messages_not_implemented("DFTUPoissonSolver=dft_u_poisson_isf with non-orthogonal cells", namespace=namespace)
280 end if
281 end if
282 if (this%sm_poisson == sm_poisson_psolver) then
283#if !(defined HAVE_PSOLVER)
284 message(1) = "The PSolver Poisson solver cannot be used since the code was not compiled with the PSolver library."
285 call messages_fatal(1, namespace=namespace)
286#endif
287 if (gr%parallel_in_domains) then
288 call messages_not_implemented("DFTUPoissonSolver=dft_u_poisson_psolver with domain parallelization", namespace=namespace)
289 end if
290 if (ions%latt%nonorthogonal) then
291 call messages_not_implemented("DFTUPoissonSolver=dft_u_poisson_psolver with non-orthogonal cells", namespace=namespace)
292 end if
293 end if
294
295 if (this%level == dft_u_acbn0) then
296 !%Variable UseAllAtomicOrbitals
297 !%Type logical
298 !%Default no
299 !%Section Hamiltonian::DFT+U
300 !%Description
301 !% If set to yes, Octopus will determine the effective U for all atomic orbitals
302 !% from the peusopotential. Only available with ACBN0 functional.
303 !% It is strongly recommended to set AOLoewdin=yes when using the option.
304 !%End
305 call parse_variable(namespace, 'UseAllAtomicOrbitals', .false., this%useAllOrbitals)
306 if (this%useAllOrbitals) call messages_experimental("UseAllAtomicOrbitals", namespace=namespace)
307
308 !%Variable SkipSOrbitals
309 !%Type logical
310 !%Default no
311 !%Section Hamiltonian::DFT+U
312 !%Description
313 !% If set to yes, Octopus will determine the effective U for all atomic orbitals
314 !% from the peusopotential but s orbitals. Only available with ACBN0 functional.
315 !%End
316 call parse_variable(namespace, 'SkipSOrbitals', .true., this%skipSOrbitals)
317 if (.not. this%SkipSOrbitals) call messages_experimental("SkipSOrbitals", namespace=namespace)
318
319 !%Variable ACBN0Screening
320 !%Type float
321 !%Default 1.0
322 !%Section Hamiltonian::DFT+U
323 !%Description
324 !% If set to 0, no screening will be included in the ACBN0 functional, and the U
325 !% will be estimated from bare Hartree-Fock. If set to 1 (default), the full screening
326 !% of the U, as defined in the ACBN0 functional, is used.
327 !%End
328 call parse_variable(namespace, 'ACBN0Screening', m_one, this%acbn0_screening)
329 call messages_print_var_value('ACBN0Screening', this%acbn0_screening, namespace=namespace)
330
331 !%Variable ACBN0RotationallyInvariant
332 !%Type logical
333 !%Section Hamiltonian::DFT+U
334 !%Description
335 !% If set to yes, Octopus will use for U and J a formula which is rotationally invariant.
336 !% This is different from the original formula for U and J.
337 !% This is activated by default, except in the case of spinors, as this is not yet implemented in this case.
338 !%End
339 call parse_variable(namespace, 'ACBN0RotationallyInvariant', st%d%ispin /= spinors, this%rot_inv)
340 call messages_print_var_value('ACBN0RotationallyInvariant', this%rot_inv, namespace=namespace)
341 if (this%rot_inv .and. st%d%ispin == spinors) then
342 call messages_not_implemented("Rotationally invariant ACBN0 with spinors", namespace=namespace)
343 end if
344
345 !%Variable ACBN0IntersiteInteraction
346 !%Type logical
347 !%Default no
348 !%Section Hamiltonian::DFT+U
349 !%Description
350 !% If set to yes, Octopus will determine the effective intersite interaction V
351 !% Only available with ACBN0 functional.
352 !% It is strongly recommended to set AOLoewdin=yes when using the option.
353 !%End
354 call parse_variable(namespace, 'ACBN0IntersiteInteraction', .false., this%intersite)
355 call messages_print_var_value('ACBN0IntersiteInteraction', this%intersite, namespace=namespace)
356 if (this%intersite) call messages_experimental("ACBN0IntersiteInteraction", namespace=namespace)
357
358 if (this%intersite) then
359
360 !This is a non local operator. To make this working, one probably needs to apply the
361 ! symmetries to the generalized occupation matrices
362 if (kpoints%use_symmetries) then
363 call messages_not_implemented("Intersite interaction with kpoint symmetries", namespace=namespace)
364 end if
365
366 !%Variable ACBN0IntersiteCutoff
367 !%Type float
368 !%Section Hamiltonian::DFT+U
369 !%Description
370 !% The cutoff radius defining the maximal intersite distance considered.
371 !% Only available with ACBN0 functional with intersite interaction.
372 !%End
373 call parse_variable(namespace, 'ACBN0IntersiteCutoff', m_zero, this%intersite_radius, unit = units_inp%length)
374 if (abs(this%intersite_radius) < m_epsilon) then
375 call messages_write("ACBN0IntersiteCutoff must be greater than 0")
376 call messages_fatal(1, namespace=namespace)
377 end if
378
379 end if
380
381 end if
382
383 call lda_u_write_info(this, namespace=namespace)
384
385 if (.not. this%basisfromstates) then
386
387 call orbitalbasis_init(this%basis, namespace, space%periodic_dim)
388
389 if (states_are_real(st)) then
390 call dorbitalbasis_build(this%basis, namespace, ions, gr, st%d%kpt, st%d%dim, &
391 this%skipSOrbitals, this%useAllOrbitals)
392 else
393 call zorbitalbasis_build(this%basis, namespace, ions, gr, st%d%kpt, st%d%dim, &
394 this%skipSOrbitals, this%useAllOrbitals)
395 end if
396 this%orbsets => this%basis%orbsets
397 this%norbsets = this%basis%norbsets
398 this%maxnorbs = this%basis%maxnorbs
399 this%max_np = this%basis%max_np
400 this%nspins = st%d%nspin
401 this%spin_channels = st%d%spin_channels
402 this%nspecies = ions%nspecies
403
404 !We allocate the necessary ressources
405 if (states_are_real(st)) then
406 call dlda_u_allocate(this, st)
407 else
408 call zlda_u_allocate(this, st)
409 end if
410
411 call distributed_nullify(this%orbs_dist, this%norbsets)
412#ifdef HAVE_MPI
413 if (.not. gr%parallel_in_domains) then
414 call distributed_init(this%orbs_dist, this%norbsets, mpi_comm_world, "orbsets")
415 end if
416#endif
417
418 else
419
420 !%Variable DFTUBasisStates
421 !%Type block
422 !%Default none
423 !%Section Hamiltonian::DFT+U
424 !%Description
425 !% This block starts by a line containing a single integer describing the number of
426 !% orbital sets. One orbital set is a group of orbitals on which one adds a Hubbard U.
427 !% Each following line of this block contains the index of a state to be used to construct the
428 !% localized basis, followed by the index of the corresponding orbital set.
429 !% See DFTUBasisFromStates for details.
430 !%End
431 if (parse_block(namespace, 'DFTUBasisStates', blk) == 0) then
432 call parse_block_integer(blk, 0, 0, this%norbsets)
433 this%maxnorbs = parse_block_n(blk)-1
434 if (this%maxnorbs <1) then
435 write(message(1),'(a,i3,a,i3)') 'DFTUBasisStates must contains at least one state.'
436 call messages_fatal(1, namespace=namespace)
437 end if
438 safe_allocate(this%basisstates(1:this%maxnorbs))
439 safe_allocate(this%basisstates_os(1:this%maxnorbs))
440 do is = 1, this%maxnorbs
441 call parse_block_integer(blk, is, 0, this%basisstates(is))
442 call parse_block_integer(blk, is, 1, this%basisstates_os(is))
443 end do
444 call parse_block_end(blk)
445 else
446 write(message(1),'(a,i3,a,i3)') 'DFTUBasisStates must be specified if DFTUBasisFromStates=yes'
447 call messages_fatal(1, namespace=namespace)
448 end if
449
450 if (states_are_real(st)) then
451 call dorbitalbasis_build_empty(this%basis, gr, st%d%kpt, st%d%dim, this%norbsets, this%basisstates_os)
452 else
453 call zorbitalbasis_build_empty(this%basis, gr, st%d%kpt, st%d%dim, this%norbsets, this%basisstates_os)
454 end if
455
456 this%max_np = gr%np
457 this%nspins = st%d%nspin
458 this%spin_channels = st%d%spin_channels
459 this%nspecies = 1
460
461 this%orbsets => this%basis%orbsets
462
463 call distributed_nullify(this%orbs_dist, this%norbsets)
464
465 !We allocate the necessary ressources
466 if (states_are_real(st)) then
467 call dlda_u_allocate(this, st)
468 else
469 call zlda_u_allocate(this, st)
470 end if
471
472 call lda_u_loadbasis(this, namespace, space, st, gr, mc, ierr)
473 if (ierr /= 0) then
474 message(1) = "Unable to load DFT+U basis from selected states."
475 call messages_fatal(1)
476 end if
477
478 end if
479
480 ! Symmetrization of the occupation matrices
481 this%symmetrize_occ_matrices = st%symmetrize_density .or. kpoints%use_symmetries
482 if (this%basisfromstates) this%symmetrize_occ_matrices = .false.
483 if (this%symmetrize_occ_matrices) then
484 call build_symmetrization_map(this, ions, gr, st)
485 end if
486
487 safe_allocate(this%dc_alpha(this%norbsets))
488 this%dc_alpha = m_one
489
490 call messages_print_with_emphasis(namespace=namespace)
491
492 pop_sub(lda_u_init)
493 end subroutine lda_u_init
494
495
496 ! ---------------------------------------------------------
497 subroutine lda_u_init_coulomb_integrals(this, namespace, space, gr, st, psolver, has_phase)
498 type(lda_u_t), target, intent(inout) :: this
499 type(namespace_t), intent(in) :: namespace
500 class(space_t), intent(in) :: space
501 type(grid_t), intent(in) :: gr
502 type(states_elec_t), intent(in) :: st
503 type(poisson_t), intent(in) :: psolver
504 logical, intent(in) :: has_phase
505
506 logical :: complex_coulomb_integrals
507 integer :: ios
508 integer :: norbs
509
511
512 norbs = this%maxnorbs
513
514 if (.not. this%basisfromstates) then
515
516 if (this%level == dft_u_acbn0) then
517
518 complex_coulomb_integrals = .false.
519 do ios = 1, this%norbsets
520 if (this%orbsets(ios)%ndim > 1) complex_coulomb_integrals = .true.
521 end do
522
523 if (.not. complex_coulomb_integrals) then
524 write(message(1),'(a)') 'Computing the Coulomb integrals of the localized basis.'
525 call messages_info(1, namespace=namespace)
526 safe_allocate(this%coulomb(1:norbs,1:norbs,1:norbs,1:norbs, 1:this%norbsets))
527 if (states_are_real(st)) then
528 call dcompute_coulomb_integrals(this, namespace, space, gr, psolver)
529 else
530 call zcompute_coulomb_integrals(this, namespace, space, gr, psolver)
531 end if
532 else
533 assert(.not. states_are_real(st))
534 write(message(1),'(a)') 'Computing complex Coulomb integrals of the localized basis.'
535 call messages_info(1, namespace=namespace)
536 safe_allocate(this%zcoulomb(1:norbs, 1:norbs, 1:norbs, 1:norbs, 1:st%d%dim, 1:st%d%dim, 1:this%norbsets))
537 call compute_complex_coulomb_integrals(this, gr, st, psolver, namespace, space)
538 end if
539 end if
540
541 else
542 write(message(1),'(a)') 'Computing the Coulomb integrals of the localized basis.'
543 call messages_info(1, namespace=namespace)
544 safe_allocate(this%coulomb(1:norbs, 1:norbs, 1:norbs, 1:norbs, 1:this%norbsets))
545 if (states_are_real(st)) then
546 call dcompute_coulomb_integrals(this, namespace, space, gr, psolver)
547 else
548 call zcompute_coulomb_integrals(this, namespace, space, gr, psolver)
549 end if
550
551 end if
552
554
555 end subroutine lda_u_init_coulomb_integrals
556
557
558 ! ---------------------------------------------------------
559 subroutine lda_u_end(this)
560 implicit none
561 type(lda_u_t), intent(inout) :: this
562
563 push_sub(lda_u_end)
564
565 this%level = dft_u_none
566
567 safe_deallocate_a(this%dn)
568 safe_deallocate_a(this%zn)
569 safe_deallocate_a(this%dn_alt)
570 safe_deallocate_a(this%zn_alt)
571 safe_deallocate_a(this%dV)
572 safe_deallocate_a(this%zV)
573 safe_deallocate_a(this%coulomb)
574 safe_deallocate_a(this%zcoulomb)
575 safe_deallocate_a(this%renorm_occ)
576 safe_deallocate_a(this%dn_ij)
577 safe_deallocate_a(this%zn_ij)
578 safe_deallocate_a(this%dn_alt_ij)
579 safe_deallocate_a(this%zn_alt_ij)
580 safe_deallocate_a(this%dn_alt_ii)
581 safe_deallocate_a(this%zn_alt_ii)
582 safe_deallocate_a(this%basisstates)
583 safe_deallocate_a(this%basisstates_os)
584 safe_deallocate_a(this%dc_alpha)
585 safe_deallocate_a(this%inv_map_symm)
586 safe_deallocate_a(this%symm_weight)
587
588 nullify(this%orbsets)
589 call orbitalbasis_end(this%basis)
591 this%max_np = 0
592
593 if (.not. this%basisfromstates) then
594 call distributed_end(this%orbs_dist)
595 end if
596
597 pop_sub(lda_u_end)
598 end subroutine lda_u_end
599
600 ! When moving the ions, the basis must be reconstructed
601 subroutine lda_u_update_basis(this, space, gr, ions, st, psolver, namespace, kpoints, has_phase)
602 type(lda_u_t), target, intent(inout) :: this
603 class(space_t), intent(in) :: space
604 type(grid_t), intent(in) :: gr
605 type(ions_t), target, intent(in) :: ions
606 type(states_elec_t), intent(in) :: st
607 type(poisson_t), intent(in) :: psolver
608 type(namespace_t), intent(in) :: namespace
609 type(kpoints_t), intent(in) :: kpoints
610 logical, intent(in) :: has_phase
611
612 integer :: ios, maxorbs, nspin
613
614 if(this%level == dft_u_none) return
615
616 push_sub(lda_u_update_basis)
617
618 if(.not. this%basisfromstates) then
619 !We clean the orbital basis, to be able to reconstruct it
620 call orbitalbasis_end(this%basis)
621 nullify(this%orbsets)
622
623 !We now reconstruct the basis
624 if (states_are_real(st)) then
625 call dorbitalbasis_build(this%basis, namespace, ions, gr, st%d%kpt, st%d%dim, &
626 this%skipSOrbitals, this%useAllOrbitals, verbose = .false.)
627 else
628 call zorbitalbasis_build(this%basis, namespace, ions, gr, st%d%kpt, st%d%dim, &
629 this%skipSOrbitals, this%useAllOrbitals, verbose = .false.)
630 end if
631 this%orbsets => this%basis%orbsets
632 this%max_np = this%basis%max_np
633 end if
634
635 !In case of intersite interaction we need to reconstruct the basis
636 if (this%intersite) then
637 this%maxneighbors = 0
638 do ios = 1, this%norbsets
639 call orbitalset_init_intersite(this%orbsets(ios), namespace, space, ios, ions, gr%der, psolver, &
640 this%orbsets, this%norbsets, this%maxnorbs, this%intersite_radius, st%d%kpt, has_phase, &
641 this%sm_poisson, this%basisfromstates, this%basis%combine_j_orbitals)
642 this%maxneighbors = max(this%maxneighbors, this%orbsets(ios)%nneighbors)
643 end do
644
645 maxorbs = this%maxnorbs
646 nspin = this%nspins
647
648 if (states_are_real(st)) then
649 safe_deallocate_a(this%dn_ij)
650 safe_allocate(this%dn_ij(1:maxorbs,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors))
651 this%dn_ij(1:maxorbs,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors) = m_zero
652 safe_deallocate_a(this%dn_alt_ij)
653 safe_allocate(this%dn_alt_ij(1:maxorbs,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors))
654 this%dn_alt_ij(1:maxorbs,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors) = m_zero
655 safe_deallocate_a(this%dn_alt_ii)
656 safe_allocate(this%dn_alt_ii(1:2,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors))
657 this%dn_alt_ii(1:2,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors) = m_zero
658 else
659 safe_deallocate_a(this%zn_ij)
660 safe_allocate(this%zn_ij(1:maxorbs,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors))
661 this%zn_ij(1:maxorbs,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors) = m_z0
662 safe_deallocate_a(this%zn_alt_ij)
663 safe_allocate(this%zn_alt_ij(1:maxorbs,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors))
664 this%zn_alt_ij(1:maxorbs,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors) = m_z0
665 safe_deallocate_a(this%zn_alt_ii)
666 safe_allocate(this%zn_alt_ii(1:2,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors))
667 this%zn_alt_ii(1:2,1:maxorbs,1:nspin,1:this%norbsets,1:this%maxneighbors) = m_z0
668 end if
669 end if
670
671 ! We rebuild the phase for the orbital projection, similarly to the one of the pseudopotentials
672 ! In case of a laser field, the phase is recomputed in hamiltonian_elec_update
673 if (has_phase) then
674 call lda_u_build_phase_correction(this, space, st%d, gr%der%boundaries, namespace, kpoints)
675 else
676 if(.not. this%basisfromstates) then
677 !In case there is no phase, we perform the orthogonalization here
678 if(this%basis%orthogonalization) then
679 call dloewdin_orthogonalize(this%basis, st%d%kpt, namespace)
680 else
681 if(debug%info .and. space%is_periodic()) then
682 call dloewdin_info(this%basis, st%d%kpt, namespace)
683 end if
684 end if
685 end if
686 end if
687
688 ! Rebuild the Coulomb integrals
689 if (allocated(this%coulomb)) then
690 safe_deallocate_a(this%coulomb)
691 end if
692 if (allocated(this%zcoulomb)) then
693 safe_deallocate_a(this%zcoulomb)
694 end if
695 call lda_u_init_coulomb_integrals(this, namespace, space, gr, st, psolver, has_phase)
696
697 pop_sub(lda_u_update_basis)
698
699 end subroutine lda_u_update_basis
700
701 ! Interface for the X(update_occ_matrices) routines
702 subroutine lda_u_update_occ_matrices(this, namespace, mesh, st, hm_base, phase, energy)
703 type(lda_u_t), intent(inout) :: this
704 type(namespace_t), intent(in) :: namespace
705 class(mesh_t), intent(in) :: mesh
706 type(states_elec_t), intent(inout) :: st
707 type(hamiltonian_elec_base_t), intent(in) :: hm_base
708 type(phase_t), intent(in) :: phase
709 type(energy_t), intent(inout) :: energy
710
711 if (this%level == dft_u_none .or. this%freeze_occ) return
713
714 if (states_are_real(st)) then
715 call dupdate_occ_matrices(this, namespace, mesh, st, energy%dft_u)
716 else
717 if (phase%is_allocated()) then
718 call zupdate_occ_matrices(this, namespace, mesh, st, energy%dft_u, phase)
719 else
720 call zupdate_occ_matrices(this, namespace, mesh, st, energy%dft_u)
721 end if
722 end if
723
725 end subroutine lda_u_update_occ_matrices
726
727
729 subroutine lda_u_build_phase_correction(this, space, std, boundaries, namespace, kpoints, vec_pot, vec_pot_var)
730 type(lda_u_t), intent(inout) :: this
731 class(space_t), intent(in) :: space
732 type(states_elec_dim_t), intent(in) :: std
733 type(boundaries_t), intent(in) :: boundaries
734 type(namespace_t), intent(in) :: namespace
735 type(kpoints_t), intent(in) :: kpoints
736 real(real64), optional, allocatable, intent(in) :: vec_pot(:)
737 real(real64), optional, allocatable, intent(in) :: vec_pot_var(:, :)
738
739 integer :: ios
740
741 if (boundaries%spiralBC) call messages_not_implemented("DFT+U with spiral boundary conditions", &
742 namespace=namespace)
743
745
746 if(debug%info) then
747 write(message(1), '(a)') 'Debug: Building the phase correction for DFT+U orbitals.'
748 call messages_info(1, namespace=namespace)
749 end if
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
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 if (debug%info) then
938 message(1) = "Debug: Loading DFT+U basis from states."
939 call messages_info(1)
940 end if
941
942 call restart_init(restart_gs, namespace, restart_proj, restart_type_load, mc, err, mesh=mesh)
943
944 ! If any error occured up to this point then it is not worth continuing,
945 ! as there something fundamentally wrong with the restart files
946 if (err /= 0) then
948 message(1) = "Error loading DFT+U basis from states, cannot proceed with the calculation"
949 call messages_fatal(1)
950 pop_sub(lda_u_loadbasis)
951 return
952 end if
953
954 ! open files to read
955 wfns_file = restart_open(restart_gs, 'wfns')
956 call restart_read(restart_gs, wfns_file, lines, 2, err)
957 if (err /= 0) then
958 ierr = ierr - 2**5
959 else if (states_are_real(st)) then
960 read(lines(2), '(a)') str
961 if (str(2:8) == 'Complex') then
962 message(1) = "Cannot read real states from complex wavefunctions."
963 call messages_fatal(1, namespace=namespace)
964 else if (str(2:5) /= 'Real') then
965 message(1) = "Restart file 'wfns' does not specify real/complex; cannot check compatibility."
966 call messages_warning(1, namespace=namespace)
967 end if
968 end if
969 ! complex can be restarted from real, so there is no problem.
970
971 ! If any error occured up to this point then it is not worth continuing,
972 ! as there something fundamentally wrong with the restart files
973 if (err /= 0) then
974 call restart_close(restart_gs, wfns_file)
976 message(1) = "Error loading DFT+U basis from states, cannot proceed with the calculation"
977 call messages_fatal(1)
978 pop_sub(lda_u_loadbasis)
979 return
980 end if
981
982 safe_allocate(restart_file(1:st%d%dim, 1:st%nst))
983 safe_allocate(restart_file_present(1:st%d%dim, 1:st%nst))
984 restart_file_present = .false.
985
986 ! Next we read the list of states from the files.
987 ! Errors in reading the information of a specific state from the files are ignored
988 ! at this point, because later we will skip reading the wavefunction of that state.
989 do
990 call restart_read(restart_gs, wfns_file, lines, 1, err)
991 if (err == 0) then
992 read(lines(1), '(a)') char
993 if (char == '%') then
994 !We reached the end of the file
995 exit
996 else
997 read(lines(1), *) ik, char, ist, char, idim, char, filename
998 end if
999 end if
1000
1001 if (any(this%basisstates==ist) .and. ik == 1) then
1002 restart_file(idim, ist) = trim(filename)
1003 restart_file_present(idim, ist) = .true.
1004 end if
1005 end do
1006 call restart_close(restart_gs, wfns_file)
1007
1008 !We loop over the states we need
1009 safe_allocate(count(1:this%norbsets))
1010 count = 0
1011 do is = 1, this%maxnorbs
1012 ist = this%basisstates(is)
1013 ios = this%basisstates_os(is)
1014 count(ios) = count(ios)+1
1015 do idim = 1, st%d%dim
1016
1017 if (.not. restart_file_present(idim, ist)) then
1018 write(message(1), '(a,i3,a)') "Cannot read states ", ist, "from the projection folder"
1019 call messages_fatal(1, namespace=namespace)
1020 end if
1021
1022 if (states_are_real(st)) then
1023 call restart_read_mesh_function(restart_gs, space, restart_file(idim, ist), mesh, &
1024 this%orbsets(ios)%dorb(:,idim,count(ios)), err)
1025 else
1026 call restart_read_mesh_function(restart_gs, space, restart_file(idim, ist), mesh, &
1027 this%orbsets(ios)%zorb(:,idim,count(ios)), err)
1028 end if
1029
1030 end do
1031 end do
1032 safe_deallocate_a(count)
1033 safe_deallocate_a(restart_file)
1034 safe_deallocate_a(restart_file_present)
1036
1037 ! Normalize the orbitals. This is important if we use Wannier orbitals instead of KS states
1038 if(this%basis%normalize) then
1039 do ios = 1, this%norbsets
1040 do iorb = 1, this%orbsets(ios)%norbs
1041 if (states_are_real(st)) then
1042 norm = dmf_nrm2(mesh, st%d%dim, this%orbsets(ios)%dorb(:,:,iorb))
1043 call lalg_scal(mesh%np, st%d%dim, m_one/norm, this%orbsets(ios)%dorb(:,:,iorb))
1044 else
1045 norm = zmf_nrm2(mesh, st%d%dim, this%orbsets(ios)%zorb(:,:,iorb))
1046 call lalg_scal(mesh%np, st%d%dim, m_one/norm, this%orbsets(ios)%zorb(:,:,iorb))
1047 end if
1048 end do
1049 end do
1050 end if
1051
1052 ! We rotate the orbitals in the complex plane to have them as close as possible to real functions
1053 if(states_are_complex(st) .and. st%d%dim == 1) then
1054 do ios = 1, this%norbsets
1055 do iorb = 1, this%orbsets(ios)%norbs
1056 call zmf_fix_phase(mesh, this%orbsets(ios)%zorb(:,1,iorb))
1057 end do
1058 end do
1059 end if
1060
1061 ! We determine the center of charge by computing <w|r|w>
1062 ! We could also determine the spread by \Omega = <w|r^2|w> - <w|r|w>^2
1063 do ios = 1, this%norbsets
1064 if (states_are_real(st)) then
1065 call dorbitalset_get_center_of_mass(this%orbsets(ios), space, mesh, this%latt)
1066 else
1067 call zorbitalset_get_center_of_mass(this%orbsets(ios), space, mesh, this%latt)
1068 end if
1069 end do
1070
1071 if (debug%info) then
1072 message(1) = "Debug: Converting the Wannier states to submeshes."
1073 call messages_info(1)
1074 end if
1075
1076 ! We now transfer the states to a submesh centered on the center of mass of the Wannier orbitals
1077 this%max_np = 0
1078 do ios = 1, this%norbsets
1079 os => this%orbsets(ios)
1080 center = os%sphere%center
1081 safe_deallocate_a(os%sphere%center)
1082 if (states_are_real(st)) then
1083 safe_allocate(dpsi(1:mesh%np, 1:os%ndim, 1:os%norbs))
1084 dpsi(1:mesh%np, 1:os%ndim, 1:os%norbs) = os%dorb(1:mesh%np, 1:os%ndim, 1:os%norbs)
1085
1086 safe_deallocate_a(os%dorb)
1087 !We initialise the submesh corresponding to the orbital
1088 call submesh_init(os%sphere, space, mesh, this%latt, center, os%radius)
1089 safe_allocate(os%dorb(1:os%sphere%np, 1:os%ndim, 1:os%norbs))
1090 do iorb = 1, os%norbs
1091 do idim = 1, os%ndim
1092 call dsubmesh_copy_from_mesh(os%sphere, dpsi(:,idim,iorb), os%dorb(:,idim, iorb))
1093 end do
1094 end do
1095 safe_deallocate_a(dpsi)
1096 else
1097 safe_allocate(zpsi(1:mesh%np, 1:os%ndim, 1:os%norbs))
1098 zpsi(1:mesh%np, 1:os%ndim, 1:os%norbs) = os%zorb(1:mesh%np, 1:os%ndim, 1:os%norbs)
1099 safe_deallocate_a(os%zorb)
1100 !We initialise the submesh corresponding to the orbital
1101 call submesh_init(os%sphere, space, mesh, this%latt, center, os%radius)
1102 safe_allocate(os%zorb(1:os%sphere%np, 1:os%ndim, 1:os%norbs))
1103 do iorb = 1, os%norbs
1104 do idim = 1, os%ndim
1105 call zsubmesh_copy_from_mesh(os%sphere, zpsi(:,idim,iorb), os%zorb(:,idim, iorb))
1106 end do
1107 end do
1108 safe_deallocate_a(zpsi)
1109
1110 safe_allocate(os%phase(1:os%sphere%np, st%d%kpt%start:st%d%kpt%end))
1111 safe_allocate(os%eorb_submesh(1:os%sphere%np, 1:os%ndim, 1:os%norbs, st%d%kpt%start:st%d%kpt%end))
1112 end if
1113 os%use_submesh = .true. ! We are now on a submesh
1114 this%max_np = max(this%max_np, os%sphere%np)
1115 end do
1116
1117 this%basis%use_submesh = .true.
1118
1119 ! If we use GPUs, we need to transfert the orbitals on the device
1120 if (accel_is_enabled() .and. st%d%dim == 1) then
1121 do ios = 1, this%norbsets
1122 os => this%orbsets(ios)
1123
1124 os%ldorbs = max(accel_padded_size(os%sphere%np), 1)
1125 if (states_are_real(st)) then
1126 call accel_create_buffer(os%dbuff_orb, accel_mem_read_only, type_float, os%ldorbs*os%norbs)
1127 else
1128 call accel_create_buffer(os%zbuff_orb, accel_mem_read_only, type_cmplx, os%ldorbs*os%norbs)
1129 safe_allocate(os%buff_eorb(st%d%kpt%start:st%d%kpt%end))
1130
1131 do ik= st%d%kpt%start, st%d%kpt%end
1132 call accel_create_buffer(os%buff_eorb(ik), accel_mem_read_only, type_cmplx, os%ldorbs*os%norbs)
1133 end do
1134 end if
1135
1136 call accel_create_buffer(os%sphere%buff_map, accel_mem_read_only, type_integer, max(os%sphere%np, 1))
1137 call accel_write_buffer(os%sphere%buff_map, os%sphere%np, os%sphere%map)
1138
1139 do iorb = 1, os%norbs
1140 if(states_are_complex(st)) then
1141 call accel_write_buffer(os%zbuff_orb, os%sphere%np, os%zorb(:, 1, iorb), &
1142 offset = (iorb - 1)*os%ldorbs)
1143 else
1144 call accel_write_buffer(os%dbuff_orb, os%sphere%np, os%dorb(:, 1, iorb), &
1145 offset = (iorb - 1)*os%ldorbs)
1146 end if
1147 end do
1148 end do
1149 end if
1150
1151
1152 if (debug%info) then
1153 message(1) = "Debug: Loading DFT+U basis from states done."
1154 call messages_info(1)
1155 end if
1156
1157 pop_sub(lda_u_loadbasis)
1158 end subroutine lda_u_loadbasis
1159
1161 subroutine build_symmetrization_map(this, ions, gr, st)
1162 type(lda_u_t), intent(inout) :: this
1163 type(ions_t), intent(in) :: ions
1164 type(grid_t), intent(in) :: gr
1165 type(states_elec_t), intent(in) :: st
1166
1167 integer :: nsym, iop, ios, iatom, iatom_sym, ios_sym
1168
1169 push_sub(build_symmetrization_map)
1170
1171 nsym = ions%symm%nops
1172 safe_allocate(this%inv_map_symm(1:this%norbsets, 1:nsym))
1173 this%inv_map_symm = -1
1174
1175 this%nsym = nsym
1176
1177 do ios = 1, this%norbsets
1178 iatom = this%orbsets(ios)%iatom
1179 do iop = 1, nsym
1180 iatom_sym = ions%inv_map_symm_atoms(iatom, iop)
1181
1182 do ios_sym = 1, this%norbsets
1183 if (this%orbsets(ios_sym)%iatom == iatom_sym .and. this%orbsets(ios_sym)%norbs == this%orbsets(ios)%norbs &
1184 .and. this%orbsets(ios_sym)%nn == this%orbsets(ios)%nn .and. this%orbsets(ios_sym)%ll == this%orbsets(ios)%ll &
1185 .and. this%orbsets(ios_sym)%jj == this%orbsets(ios)%jj) then
1186 this%inv_map_symm(ios, iop) = ios_sym
1187 exit
1188 end if
1189 end do
1190 assert(this%inv_map_symm(ios, iop) > 0)
1191 end do
1192 end do
1193
1194 safe_allocate(this%symm_weight(1:this%maxnorbs, 1:this%maxnorbs, 1:this%nsym, 1:this%norbsets))
1195 this%symm_weight = m_zero
1196
1197 do ios = 1, this%norbsets
1198 ! s-orbitals
1199 if (this%orbsets(ios)%norbs == 1) then
1200 this%symm_weight(1,1, 1:this%nsym, ios) = m_one
1201 cycle
1202 end if
1203
1204 ! Not implemented yet
1205 if (this%orbsets(ios)%ndim > 1) cycle
1206
1207 call orbitals_get_symm_weight(this%orbsets(ios), ions%space, ions%latt, gr, ions%symm, this%symm_weight(:,:,:,ios))
1208 end do
1209
1211 end subroutine build_symmetrization_map
1212
1214 subroutine orbitals_get_symm_weight(os, space, latt, gr, symm, weight)
1215 type(orbitalset_t), intent(in) :: os
1216 type(space_t), intent(in) :: space
1217 type(lattice_vectors_t), intent(in) :: latt
1218 type(grid_t), intent(in) :: gr
1219 type(symmetries_t), intent(in) :: symm
1220 real(real64), intent(inout) :: weight(:,:,:)
1221
1222 integer :: im, imp, iop, mm
1223 real(real64), allocatable :: orb(:,:), orb_sym(:), ylm(:)
1224 type(submesh_t) :: sphere
1225 real(real64) :: rc, norm, origin(space%dim)
1226
1227 push_sub(orbitals_get_symm_weight)
1228
1229 assert(os%ndim == 1)
1230
1231 safe_allocate(orb_sym(1:gr%np))
1232 safe_allocate(orb(1:gr%np, 1:os%norbs))
1233
1234 assert(2*os%ll+1 == os%norbs)
1235
1236 ! We generate an artificial submesh to compute the symmetries on it
1237 ! The radius is such that we fit in 20 points
1238 rc = (50.0_real64 * m_three/m_four/m_pi*product(gr%spacing))**m_third
1239 origin = m_zero
1240 call submesh_init(sphere, space, gr, latt, origin, rc)
1241
1242 safe_allocate(ylm(1:sphere%np))
1243
1244 ! We then compute the spherical harmonics in this submesh
1245 do im = 1, os%norbs
1246 mm = im-1-os%ll
1247 call loct_ylm(sphere%np, sphere%rel_x(1,1), sphere%r(1), os%ll, mm, ylm(1))
1248 orb(:,im) = m_zero
1249 call submesh_add_to_mesh(sphere, ylm, orb(:,im))
1250 norm = dmf_nrm2(gr, orb(:,im))
1251 call lalg_scal(gr%np, m_one / norm, orb(:,im))
1252 end do
1253 safe_deallocate_a(ylm)
1255 ! Then we put them on the grid, rotate them
1256 do im = 1, os%norbs
1257 do iop = 1, symm%nops
1258 call dgrid_symmetrize_single(gr, iop, orb(:,im), orb_sym)
1259
1260 do imp = 1, os%norbs
1261 weight(im, imp, iop) = dmf_dotp(gr, orb(:,imp), orb_sym, reduce=.false.)
1262 end do
1263 end do
1264 end do
1265
1266 if(gr%parallel_in_domains) then
1267 call gr%allreduce(weight)
1268 end if
1269
1270 safe_deallocate_a(orb)
1271 safe_deallocate_a(orb_sym)
1272
1274 end subroutine orbitals_get_symm_weight
1275
1276#include "dft_u_noncollinear_inc.F90"
1277
1278#include "undef.F90"
1279#include "real.F90"
1280#include "lda_u_inc.F90"
1281
1282#include "undef.F90"
1283#include "complex.F90"
1284#include "lda_u_inc.F90"
1285end module lda_u_oct_m
scales a vector by a constant
Definition: lalg_basic.F90:156
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:400
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:154
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:187
real(real64), parameter, public m_four
Definition: global.F90:191
real(real64), parameter, public m_third
Definition: global.F90:194
real(real64), parameter, public m_pi
some mathematical constants
Definition: global.F90:185
complex(real64), parameter, public m_z0
Definition: global.F90:197
real(real64), parameter, public m_epsilon
Definition: global.F90:203
real(real64), parameter, public m_one
Definition: global.F90:188
real(real64), parameter, public m_three
Definition: global.F90:190
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:715
integer, parameter, public dft_u_amf
Definition: lda_u.F90:205
subroutine, public zlda_u_commute_r(this, mesh, space, d, namespace, psib, gpsib)
This routine computes [r,V_lda+u] .
Definition: lda_u.F90:5026
subroutine zlda_u_allocate(this, st)
Definition: lda_u.F90:5597
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:1391
subroutine, public dlda_u_apply(this, d, mesh, psib, hpsib)
Definition: lda_u.F90:1762
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:2795
subroutine, public dlda_u_get_occupations(this, occ)
Definition: lda_u.F90:3502
subroutine, public dlda_u_rvu(this, mesh, space, d, namespace, psib, gpsib)
This routine computes .
Definition: lda_u.F90:3335
subroutine, public lda_u_update_basis(this, space, gr, ions, st, psolver, namespace, kpoints, has_phase)
Definition: lda_u.F90:695
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:1308
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:1834
subroutine, public zlda_u_apply(this, d, mesh, psib, hpsib)
Definition: lda_u.F90:3749
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:4222
integer, parameter, public dft_u_empirical
Definition: lda_u.F90:200
subroutine lda_u_init_coulomb_integrals(this, namespace, space, gr, st, psolver, has_phase)
Definition: lda_u.F90:591
subroutine zcompute_acbno_u_kanamori_restricted(this, kanamori)
This routine computes the Kanamori U, Up, and J.
Definition: lda_u.F90:4782
subroutine dcompute_acbno_u_kanamori(this, kanamori)
This routine computes the Kanamori U, Up, and J.
Definition: lda_u.F90:2696
subroutine, public zlda_u_commute_r_single(this, mesh, space, d, namespace, ist, ik, psi, gpsi, has_phase)
Definition: lda_u.F90:4975
subroutine, public dlda_u_force(this, namespace, space, mesh, st, iq, psib, grad_psib, force, phase)
Definition: lda_u.F90:3196
subroutine, public lda_u_freeze_occ(this)
Definition: lda_u.F90:888
integer, parameter, public dft_u_mix
Definition: lda_u.F90:205
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:5352
subroutine dlda_u_allocate(this, st)
Definition: lda_u.F90:3559
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:4296
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:3039
subroutine dcompute_coulomb_integrals(this, namespace, space, gr, psolver)
Definition: lda_u.F90:2870
subroutine, public dlda_u_set_occupations(this, occ)
Definition: lda_u.F90:3445
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:5213
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:2988
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:823
subroutine, public lda_u_end(this)
Definition: lda_u.F90:653
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:280
integer, parameter, public dft_u_acbn0
Definition: lda_u.F90:200
subroutine zcompute_acbno_u_kanamori(this, kanamori)
This routine computes the Kanamori U, Up, and J.
Definition: lda_u.F90:4683
subroutine, public lda_u_update_occ_matrices(this, namespace, mesh, st, hm_base, phase, energy)
Definition: lda_u.F90:796
subroutine zcompute_coulomb_integrals(this, namespace, space, gr, psolver)
Definition: lda_u.F90:4857
subroutine, public zlda_u_get_occupations(this, occ)
Definition: lda_u.F90:5540
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:3821
subroutine build_symmetrization_map(this, ions, gr, st)
Builds a mapping between the orbital sets based on symmetries.
Definition: lda_u.F90:1255
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:2235
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:2309
subroutine, public zlda_u_set_occupations(this, occ)
Definition: lda_u.F90:5483
subroutine, public dloewdin_orthogonalize(basis, kpt, namespace)
Definition: loewdin.F90:212
subroutine, public zloewdin_info(basis, kpt, namespace)
Definition: loewdin.F90:753
subroutine, public zloewdin_orthogonalize(basis, kpt, namespace)
Definition: loewdin.F90:541
subroutine, public dloewdin_info(basis, kpt, namespace)
Definition: loewdin.F90:417
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:930
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1125
character(len=512), private msg
Definition: messages.F90:165
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:543
subroutine, public messages_info(no_lines, iunit, verbose_limit, stress, all_nodes, namespace)
Definition: messages.F90:624
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:420
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1097
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:933
subroutine, public restart_close(restart, iunit)
Close a file previously opened with restart_open.
Definition: restart.F90:950
integer, parameter, public restart_gs
Definition: restart.F90:229
subroutine, public restart_init(restart, namespace, data_type, type, mc, ierr, mesh, dir, exact)
Initializes a restart object.
Definition: restart.F90:514
integer, parameter, public restart_proj
Definition: restart.F90:229
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:859
integer, parameter, public restart_type_load
Definition: restart.F90:225
subroutine, public restart_end(restart)
Definition: restart.F90:720
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:1866
subroutine, public dsubmesh_copy_from_mesh(this, phi, sphi, conjugate)
Definition: submesh.F90:1284
subroutine, public submesh_init(this, space, mesh, latt, center, rc)
Definition: submesh.F90:282
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:168
The basic Hamiltonian for electronic system.
Class to describe DFT+U parameters.
Definition: lda_u.F90:213
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:177
int true(void)