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 write(message(1), '(a)') 'Debug: Building the phase correction for DFT+U orbitals.'
747 call messages_info(1, namespace=namespace, debug_only=.true.)
748
749 do ios = 1, this%norbsets
750 call orbitalset_update_phase(this%orbsets(ios), space%dim, std%kpt, kpoints, &
751 (std%ispin==spin_polarized), vec_pot, vec_pot_var)
752 call orbitalset_update_phase_shift(this%orbsets(ios), space%dim, std%kpt, kpoints, &
753 (std%ispin==spin_polarized), vec_pot, vec_pot_var)
754 end do
755
756 if (.not. this%basisfromstates) then
757 if (this%basis%orthogonalization) then
758 call zloewdin_orthogonalize(this%basis, std%kpt, namespace)
759 else
760 if (debug%info .and. space%is_periodic()) call zloewdin_info(this%basis, std%kpt, namespace)
761 end if
762 end if
763
765
766 end subroutine lda_u_build_phase_correction
767
768 ! ---------------------------------------------------------
769 subroutine compute_acbno_u_kanamori(this, st, kanamori)
770 type(lda_u_t), intent(in) :: this
771 type(states_elec_t), intent(in) :: st
772 real(real64), intent(out) :: kanamori(:,:)
773
774 if (this%nspins == 1) then
775 if (states_are_real(st)) then
776 call dcompute_acbno_u_kanamori_restricted(this, kanamori)
777 else
778 call zcompute_acbno_u_kanamori_restricted(this, kanamori)
779 end if
780 else
781 if (states_are_real(st)) then
782 call dcompute_acbno_u_kanamori(this, kanamori)
783 else
784 call zcompute_acbno_u_kanamori(this, kanamori)
785 end if
786 end if
787
788
789 end subroutine compute_acbno_u_kanamori
790
791 ! ---------------------------------------------------------
792 subroutine lda_u_freeze_occ(this)
793 type(lda_u_t), intent(inout) :: this
794
795 this%freeze_occ = .true.
796 end subroutine lda_u_freeze_occ
797
798 ! ---------------------------------------------------------
799 subroutine lda_u_freeze_u(this)
800 type(lda_u_t), intent(inout) :: this
801
802 this%freeze_u = .true.
803 end subroutine lda_u_freeze_u
804
805 ! ---------------------------------------------------------
806 subroutine lda_u_set_effectiveu(this, Ueff)
807 type(lda_u_t), intent(inout) :: this
808 real(real64), intent(in) :: ueff(:)
809
810 integer :: ios
811
812 push_sub(lda_u_set_effectiveu)
813
814 do ios = 1,this%norbsets
815 this%orbsets(ios)%Ueff = ueff(ios)
816 end do
817
818 pop_sub(lda_u_set_effectiveu)
819 end subroutine lda_u_set_effectiveu
820
821 ! ---------------------------------------------------------
822 subroutine lda_u_get_effectiveu(this, Ueff)
823 type(lda_u_t), intent(in) :: this
824 real(real64), intent(inout) :: ueff(:)
825
826 integer :: ios
827
828 push_sub(lda_u_get_effectiveu)
829
830 do ios = 1,this%norbsets
831 ueff(ios) = this%orbsets(ios)%Ueff
832 end do
833
834 pop_sub(lda_u_get_effectiveu)
835 end subroutine lda_u_get_effectiveu
836
837 ! ---------------------------------------------------------
838 subroutine lda_u_set_effectivev(this, Veff)
839 type(lda_u_t), intent(inout) :: this
840 real(real64), intent(in) :: veff(:)
841
842 integer :: ios, ncount
843
844 push_sub(lda_u_set_effectivev)
845
846 ncount = 0
847 do ios = 1, this%norbsets
848 this%orbsets(ios)%V_ij(1:this%orbsets(ios)%nneighbors,0) = veff(ncount+1:ncount+this%orbsets(ios)%nneighbors)
849 ncount = ncount + this%orbsets(ios)%nneighbors
850 end do
851
852 pop_sub(lda_u_set_effectivev)
853 end subroutine lda_u_set_effectivev
854
855 ! ---------------------------------------------------------
856 subroutine lda_u_get_effectivev(this, Veff)
857 type(lda_u_t), intent(in) :: this
858 real(real64), intent(inout) :: veff(:)
859
860 integer :: ios, ncount
861
863
864 ncount = 0
865 do ios = 1, this%norbsets
866 veff(ncount+1:ncount+this%orbsets(ios)%nneighbors) = this%orbsets(ios)%V_ij(1:this%orbsets(ios)%nneighbors,0)
867 ncount = ncount + this%orbsets(ios)%nneighbors
868 end do
869
870 pop_sub(lda_u_get_effectivev)
871 end subroutine lda_u_get_effectivev
872
873 ! ---------------------------------------------------------
874 subroutine lda_u_write_info(this, iunit, namespace)
875 type(lda_u_t), intent(in) :: this
876 integer, optional, intent(in) :: iunit
877 type(namespace_t), optional, intent(in) :: namespace
878
879 push_sub(lda_u_write_info)
880
881 write(message(1), '(1x)')
882 call messages_info(1, iunit=iunit, namespace=namespace)
883 if (this%level == dft_u_empirical) then
884 write(message(1), '(a)') "Method:"
885 write(message(2), '(a)') " [1] Dudarev et al., Phys. Rev. B 57, 1505 (1998)"
886 call messages_info(2, iunit=iunit, namespace=namespace)
887 else
888 if (.not. this%intersite) then
889 write(message(1), '(a)') "Method:"
890 write(message(2), '(a)') " [1] Agapito et al., Phys. Rev. X 5, 011006 (2015)"
891 else
892 write(message(1), '(a)') "Method:"
893 write(message(2), '(a)') " [1] Tancogne-Dejean, and Rubio, Phys. Rev. B 102, 155117 (2020)"
894 end if
895 call messages_info(2, iunit=iunit, namespace=namespace)
896 end if
897 write(message(1), '(a)') "Implementation:"
898 write(message(2), '(a)') " [1] Tancogne-Dejean, Oliveira, and Rubio, Phys. Rev. B 69, 245133 (2017)"
899 write(message(3), '(1x)')
900 call messages_info(3, iunit=iunit, namespace=namespace)
901
902 pop_sub(lda_u_write_info)
903
904 end subroutine lda_u_write_info
905
906 ! ---------------------------------------------------------
907 subroutine lda_u_loadbasis(this, namespace, space, st, mesh, mc, ierr)
908 type(lda_u_t), intent(inout) :: this
909 type(namespace_t), intent(in) :: namespace
910 class(space_t), intent(in) :: space
911 type(states_elec_t), intent(in) :: st
912 class(mesh_t), intent(in) :: mesh
913 type(multicomm_t), intent(in) :: mc
914 integer, intent(out) :: ierr
916 integer :: err, wfns_file, is, ist, idim, ik, ios, iorb
917 type(restart_t) :: restart_gs
918 character(len=256) :: lines(3)
919 character(len=256), allocatable :: restart_file(:, :)
920 logical, allocatable :: restart_file_present(:, :)
921 character(len=12) :: filename
922 character(len=1) :: char
923 character(len=50) :: str
924 type(orbitalset_t), pointer :: os
925 integer, allocatable :: count(:)
926 real(real64) :: norm, center(space%dim)
927 real(real64), allocatable :: dpsi(:,:,:)
928 complex(real64), allocatable :: zpsi(:,:,:)
929
930
932
933 ierr = 0
934
935 message(1) = "Debug: Loading DFT+U basis from states."
936 call messages_info(1, debug_only=.true.)
937
938 call restart_init(restart_gs, namespace, restart_proj, restart_type_load, mc, err, mesh=mesh)
939
940 ! If any error occured up to this point then it is not worth continuing,
941 ! as there something fundamentally wrong with the restart files
942 if (err /= 0) then
944 message(1) = "Error loading DFT+U basis from states, cannot proceed with the calculation"
945 call messages_fatal(1)
946 pop_sub(lda_u_loadbasis)
947 return
948 end if
950 ! open files to read
951 wfns_file = restart_open(restart_gs, 'wfns')
952 call restart_read(restart_gs, wfns_file, lines, 2, err)
953 if (err /= 0) then
954 ierr = ierr - 2**5
955 else if (states_are_real(st)) then
956 read(lines(2), '(a)') str
957 if (str(2:8) == 'Complex') then
958 message(1) = "Cannot read real states from complex wavefunctions."
959 call messages_fatal(1, namespace=namespace)
960 else if (str(2:5) /= 'Real') then
961 message(1) = "Restart file 'wfns' does not specify real/complex; cannot check compatibility."
962 call messages_warning(1, namespace=namespace)
963 end if
964 end if
965 ! complex can be restarted from real, so there is no problem.
966
967 ! If any error occured up to this point then it is not worth continuing,
968 ! as there something fundamentally wrong with the restart files
969 if (err /= 0) then
970 call restart_close(restart_gs, wfns_file)
972 message(1) = "Error loading DFT+U basis from states, cannot proceed with the calculation"
973 call messages_fatal(1)
974 pop_sub(lda_u_loadbasis)
975 return
976 end if
977
978 safe_allocate(restart_file(1:st%d%dim, 1:st%nst))
979 safe_allocate(restart_file_present(1:st%d%dim, 1:st%nst))
980 restart_file_present = .false.
981
982 ! Next we read the list of states from the files.
983 ! Errors in reading the information of a specific state from the files are ignored
984 ! at this point, because later we will skip reading the wavefunction of that state.
985 do
986 call restart_read(restart_gs, wfns_file, lines, 1, err)
987 if (err == 0) then
988 read(lines(1), '(a)') char
989 if (char == '%') then
990 !We reached the end of the file
991 exit
992 else
993 read(lines(1), *) ik, char, ist, char, idim, char, filename
994 end if
995 end if
996
997 if (any(this%basisstates==ist) .and. ik == 1) then
998 restart_file(idim, ist) = trim(filename)
999 restart_file_present(idim, ist) = .true.
1000 end if
1001 end do
1002 call restart_close(restart_gs, wfns_file)
1003
1004 !We loop over the states we need
1005 safe_allocate(count(1:this%norbsets))
1006 count = 0
1007 do is = 1, this%maxnorbs
1008 ist = this%basisstates(is)
1009 ios = this%basisstates_os(is)
1010 count(ios) = count(ios)+1
1011 do idim = 1, st%d%dim
1012
1013 if (.not. restart_file_present(idim, ist)) then
1014 write(message(1), '(a,i3,a)') "Cannot read states ", ist, "from the projection folder"
1015 call messages_fatal(1, namespace=namespace)
1016 end if
1017
1018 if (states_are_real(st)) then
1019 call restart_read_mesh_function(restart_gs, space, restart_file(idim, ist), mesh, &
1020 this%orbsets(ios)%dorb(:,idim,count(ios)), err)
1021 else
1022 call restart_read_mesh_function(restart_gs, space, restart_file(idim, ist), mesh, &
1023 this%orbsets(ios)%zorb(:,idim,count(ios)), err)
1024 end if
1025
1026 end do
1027 end do
1028 safe_deallocate_a(count)
1029 safe_deallocate_a(restart_file)
1030 safe_deallocate_a(restart_file_present)
1032
1033 ! Normalize the orbitals. This is important if we use Wannier orbitals instead of KS states
1034 if(this%basis%normalize) then
1035 do ios = 1, this%norbsets
1036 do iorb = 1, this%orbsets(ios)%norbs
1037 if (states_are_real(st)) then
1038 norm = dmf_nrm2(mesh, st%d%dim, this%orbsets(ios)%dorb(:,:,iorb))
1039 call lalg_scal(mesh%np, st%d%dim, m_one/norm, this%orbsets(ios)%dorb(:,:,iorb))
1040 else
1041 norm = zmf_nrm2(mesh, st%d%dim, this%orbsets(ios)%zorb(:,:,iorb))
1042 call lalg_scal(mesh%np, st%d%dim, m_one/norm, this%orbsets(ios)%zorb(:,:,iorb))
1043 end if
1044 end do
1045 end do
1046 end if
1047
1048 ! We rotate the orbitals in the complex plane to have them as close as possible to real functions
1049 if(states_are_complex(st) .and. st%d%dim == 1) then
1050 do ios = 1, this%norbsets
1051 do iorb = 1, this%orbsets(ios)%norbs
1052 call zmf_fix_phase(mesh, this%orbsets(ios)%zorb(:,1,iorb))
1053 end do
1054 end do
1055 end if
1056
1057 ! We determine the center of charge by computing <w|r|w>
1058 ! We could also determine the spread by \Omega = <w|r^2|w> - <w|r|w>^2
1059 do ios = 1, this%norbsets
1060 if (states_are_real(st)) then
1061 call dorbitalset_get_center_of_mass(this%orbsets(ios), space, mesh, this%latt)
1062 else
1063 call zorbitalset_get_center_of_mass(this%orbsets(ios), space, mesh, this%latt)
1064 end if
1065 end do
1066
1067 message(1) = "Debug: Converting the Wannier states to submeshes."
1068 call messages_info(1, debug_only=.true.)
1069
1070 ! We now transfer the states to a submesh centered on the center of mass of the Wannier orbitals
1071 this%max_np = 0
1072 do ios = 1, this%norbsets
1073 os => this%orbsets(ios)
1074 center = os%sphere%center
1075 safe_deallocate_a(os%sphere%center)
1076 if (states_are_real(st)) then
1077 safe_allocate(dpsi(1:mesh%np, 1:os%ndim, 1:os%norbs))
1078 dpsi(1:mesh%np, 1:os%ndim, 1:os%norbs) = os%dorb(1:mesh%np, 1:os%ndim, 1:os%norbs)
1079
1080 safe_deallocate_a(os%dorb)
1081 !We initialise the submesh corresponding to the orbital
1082 call submesh_init(os%sphere, space, mesh, this%latt, center, os%radius)
1083 safe_allocate(os%dorb(1:os%sphere%np, 1:os%ndim, 1:os%norbs))
1084 do iorb = 1, os%norbs
1085 do idim = 1, os%ndim
1086 call dsubmesh_copy_from_mesh(os%sphere, dpsi(:,idim,iorb), os%dorb(:,idim, iorb))
1087 end do
1088 end do
1089 safe_deallocate_a(dpsi)
1090 else
1091 safe_allocate(zpsi(1:mesh%np, 1:os%ndim, 1:os%norbs))
1092 zpsi(1:mesh%np, 1:os%ndim, 1:os%norbs) = os%zorb(1:mesh%np, 1:os%ndim, 1:os%norbs)
1093 safe_deallocate_a(os%zorb)
1094 !We initialise the submesh corresponding to the orbital
1095 call submesh_init(os%sphere, space, mesh, this%latt, center, os%radius)
1096 safe_allocate(os%zorb(1:os%sphere%np, 1:os%ndim, 1:os%norbs))
1097 do iorb = 1, os%norbs
1098 do idim = 1, os%ndim
1099 call zsubmesh_copy_from_mesh(os%sphere, zpsi(:,idim,iorb), os%zorb(:,idim, iorb))
1100 end do
1101 end do
1102 safe_deallocate_a(zpsi)
1103
1104 safe_allocate(os%phase(1:os%sphere%np, st%d%kpt%start:st%d%kpt%end))
1105 safe_allocate(os%eorb_submesh(1:os%sphere%np, 1:os%ndim, 1:os%norbs, st%d%kpt%start:st%d%kpt%end))
1106 end if
1107 os%use_submesh = .true. ! We are now on a submesh
1108 this%max_np = max(this%max_np, os%sphere%np)
1109 end do
1110
1111 this%basis%use_submesh = .true.
1112
1113 ! If we use GPUs, we need to transfert the orbitals on the device
1114 if (accel_is_enabled() .and. st%d%dim == 1) then
1115 do ios = 1, this%norbsets
1116 os => this%orbsets(ios)
1117
1118 os%ldorbs = max(accel_padded_size(os%sphere%np), 1)
1119 if (states_are_real(st)) then
1120 call accel_create_buffer(os%dbuff_orb, accel_mem_read_only, type_float, os%ldorbs*os%norbs)
1121 else
1122 call accel_create_buffer(os%zbuff_orb, accel_mem_read_only, type_cmplx, os%ldorbs*os%norbs)
1123 safe_allocate(os%buff_eorb(st%d%kpt%start:st%d%kpt%end))
1124
1125 do ik= st%d%kpt%start, st%d%kpt%end
1126 call accel_create_buffer(os%buff_eorb(ik), accel_mem_read_only, type_cmplx, os%ldorbs*os%norbs)
1127 end do
1128 end if
1129
1130 call accel_create_buffer(os%sphere%buff_map, accel_mem_read_only, type_integer, max(os%sphere%np, 1))
1131 call accel_write_buffer(os%sphere%buff_map, os%sphere%np, os%sphere%map)
1132
1133 do iorb = 1, os%norbs
1134 if(states_are_complex(st)) then
1135 call accel_write_buffer(os%zbuff_orb, os%sphere%np, os%zorb(:, 1, iorb), &
1136 offset = (iorb - 1)*os%ldorbs)
1137 else
1138 call accel_write_buffer(os%dbuff_orb, os%sphere%np, os%dorb(:, 1, iorb), &
1139 offset = (iorb - 1)*os%ldorbs)
1140 end if
1141 end do
1142 end do
1143 end if
1144
1145
1146 message(1) = "Debug: Loading DFT+U basis from states done."
1147 call messages_info(1, debug_only=.true.)
1148
1149 pop_sub(lda_u_loadbasis)
1150 end subroutine lda_u_loadbasis
1151
1153 subroutine build_symmetrization_map(this, ions, gr, st)
1154 type(lda_u_t), intent(inout) :: this
1155 type(ions_t), intent(in) :: ions
1156 type(grid_t), intent(in) :: gr
1157 type(states_elec_t), intent(in) :: st
1158
1159 integer :: nsym, iop, ios, iatom, iatom_sym, ios_sym
1160
1161 push_sub(build_symmetrization_map)
1162
1163 nsym = ions%symm%nops
1164 safe_allocate(this%inv_map_symm(1:this%norbsets, 1:nsym))
1165 this%inv_map_symm = -1
1166
1167 this%nsym = nsym
1168
1169 do ios = 1, this%norbsets
1170 iatom = this%orbsets(ios)%iatom
1171 do iop = 1, nsym
1172 iatom_sym = ions%inv_map_symm_atoms(iatom, iop)
1173
1174 do ios_sym = 1, this%norbsets
1175 if (this%orbsets(ios_sym)%iatom == iatom_sym .and. this%orbsets(ios_sym)%norbs == this%orbsets(ios)%norbs &
1176 .and. this%orbsets(ios_sym)%nn == this%orbsets(ios)%nn .and. this%orbsets(ios_sym)%ll == this%orbsets(ios)%ll &
1177 .and. this%orbsets(ios_sym)%jj == this%orbsets(ios)%jj) then
1178 this%inv_map_symm(ios, iop) = ios_sym
1179 exit
1180 end if
1181 end do
1182 assert(this%inv_map_symm(ios, iop) > 0)
1183 end do
1184 end do
1185
1186 safe_allocate(this%symm_weight(1:this%maxnorbs, 1:this%maxnorbs, 1:this%nsym, 1:this%norbsets))
1187 this%symm_weight = m_zero
1188
1189 do ios = 1, this%norbsets
1190 ! s-orbitals
1191 if (this%orbsets(ios)%norbs == 1) then
1192 this%symm_weight(1,1, 1:this%nsym, ios) = m_one
1193 cycle
1194 end if
1195
1196 ! Not implemented yet
1197 if (this%orbsets(ios)%ndim > 1) cycle
1198
1199 call orbitals_get_symm_weight(this%orbsets(ios), ions%space, ions%latt, gr, ions%symm, this%symm_weight(:,:,:,ios))
1200 end do
1201
1203 end subroutine build_symmetrization_map
1204
1206 subroutine orbitals_get_symm_weight(os, space, latt, gr, symm, weight)
1207 type(orbitalset_t), intent(in) :: os
1208 type(space_t), intent(in) :: space
1209 type(lattice_vectors_t), intent(in) :: latt
1210 type(grid_t), intent(in) :: gr
1211 type(symmetries_t), intent(in) :: symm
1212 real(real64), intent(inout) :: weight(:,:,:)
1213
1214 integer :: im, imp, iop, mm
1215 real(real64), allocatable :: orb(:,:), orb_sym(:), ylm(:)
1216 type(submesh_t) :: sphere
1217 real(real64) :: rc, norm, origin(space%dim)
1218
1219 push_sub(orbitals_get_symm_weight)
1220
1221 assert(os%ndim == 1)
1222
1223 safe_allocate(orb_sym(1:gr%np))
1224 safe_allocate(orb(1:gr%np, 1:os%norbs))
1225
1226 assert(2*os%ll+1 == os%norbs)
1227
1228 ! We generate an artificial submesh to compute the symmetries on it
1229 ! The radius is such that we fit in 20 points
1230 rc = (50.0_real64 * m_three/m_four/m_pi*product(gr%spacing))**m_third
1231 origin = m_zero
1232 call submesh_init(sphere, space, gr, latt, origin, rc)
1233
1234 safe_allocate(ylm(1:sphere%np))
1235
1236 ! We then compute the spherical harmonics in this submesh
1237 do im = 1, os%norbs
1238 mm = im-1-os%ll
1239 call loct_ylm(sphere%np, sphere%rel_x(1,1), sphere%r(1), os%ll, mm, ylm(1))
1240 orb(:,im) = m_zero
1241 call submesh_add_to_mesh(sphere, ylm, orb(:,im))
1242 norm = dmf_nrm2(gr, orb(:,im))
1243 call lalg_scal(gr%np, m_one / norm, orb(:,im))
1244 end do
1245 safe_deallocate_a(ylm)
1247 ! Then we put them on the grid, rotate them
1248 do im = 1, os%norbs
1249 do iop = 1, symm%nops
1250 call dgrid_symmetrize_single(gr, iop, orb(:,im), orb_sym)
1251
1252 do imp = 1, os%norbs
1253 weight(im, imp, iop) = dmf_dotp(gr, orb(:,imp), orb_sym, reduce=.false.)
1254 end do
1255 end do
1256 end do
1257
1258 if(gr%parallel_in_domains) then
1259 call gr%allreduce(weight)
1260 end if
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: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:5018
subroutine zlda_u_allocate(this, st)
Definition: lda_u.F90:5589
subroutine, public lda_u_get_effectiveu(this, Ueff)
Definition: lda_u.F90:916
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)
Definition: lda_u.F90:1754
subroutine, public lda_u_set_effectiveu(this, Ueff)
Definition: lda_u.F90:900
subroutine dcompute_acbno_u_kanamori_restricted(this, kanamori)
This routine computes the Kanamori U, Up, and J.
Definition: lda_u.F90:2787
subroutine, public dlda_u_get_occupations(this, occ)
Definition: lda_u.F90:3494
subroutine, public dlda_u_rvu(this, mesh, space, d, namespace, psib, gpsib)
This routine computes .
Definition: lda_u.F90:3327
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:1300
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:1826
subroutine, public zlda_u_apply(this, d, mesh, psib, hpsib)
Definition: lda_u.F90:3741
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:4214
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:4774
subroutine dcompute_acbno_u_kanamori(this, kanamori)
This routine computes the Kanamori U, Up, and J.
Definition: lda_u.F90:2688
subroutine, public zlda_u_commute_r_single(this, mesh, space, d, namespace, ist, ik, psi, gpsi, has_phase)
Definition: lda_u.F90:4967
subroutine, public dlda_u_force(this, namespace, space, mesh, st, iq, psib, grad_psib, force, phase)
Definition: lda_u.F90:3188
subroutine, public lda_u_freeze_occ(this)
Definition: lda_u.F90:886
integer, parameter, public dft_u_mix
Definition: lda_u.F90:205
subroutine, public lda_u_freeze_u(this)
Definition: lda_u.F90:893
subroutine, public zlda_u_rvu(this, mesh, space, d, namespace, psib, gpsib)
This routine computes .
Definition: lda_u.F90:5344
subroutine dlda_u_allocate(this, st)
Definition: lda_u.F90:3551
subroutine, public compute_acbno_u_kanamori(this, st, kanamori)
Definition: lda_u.F90:863
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:4288
subroutine, public lda_u_write_info(this, iunit, namespace)
Definition: lda_u.F90:968
subroutine, public dlda_u_commute_r(this, mesh, space, d, namespace, psib, gpsib)
This routine computes [r,V_lda+u] .
Definition: lda_u.F90:3031
subroutine dcompute_coulomb_integrals(this, namespace, space, gr, psolver)
Definition: lda_u.F90:2862
subroutine, public dlda_u_set_occupations(this, occ)
Definition: lda_u.F90:3437
subroutine, public lda_u_get_effectivev(this, Veff)
Definition: lda_u.F90:950
subroutine, public zlda_u_force(this, namespace, space, mesh, st, iq, psib, grad_psib, force, phase)
Definition: lda_u.F90:5205
subroutine lda_u_loadbasis(this, namespace, space, st, mesh, mc, ierr)
Definition: lda_u.F90:1001
subroutine, public dlda_u_commute_r_single(this, mesh, space, d, namespace, ist, ik, psi, gpsi, has_phase)
Definition: lda_u.F90:2980
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:932
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:4675
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:4849
subroutine, public zlda_u_get_occupations(this, occ)
Definition: lda_u.F90:5532
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:3813
subroutine build_symmetrization_map(this, ions, gr, st)
Builds a mapping between the orbital sets based on symmetries.
Definition: lda_u.F90:1247
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:2227
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:2301
subroutine, public zlda_u_set_occupations(this, occ)
Definition: lda_u.F90:5475
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 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
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
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:624
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:935
subroutine, public restart_close(restart, iunit)
Close a file previously opened with restart_open.
Definition: restart.F90:952
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:516
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:861
integer, parameter, public restart_type_load
Definition: restart.F90:245
subroutine, public restart_end(restart)
Definition: restart.F90:722
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:1819
subroutine, public dsubmesh_copy_from_mesh(this, phi, sphi, conjugate)
Definition: submesh.F90:1282
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: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:175
int true(void)