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