Octopus
states_elec.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
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#include "global.h"
19
21 use accel_oct_m
22 use batch_oct_m
26 use batch_oct_m
29 use comm_oct_m
30 use debug_oct_m
34 use global_oct_m
35 use grid_oct_m
36 use io_oct_m
37 use, intrinsic :: iso_fortran_env
40 use loct_oct_m
41 use math_oct_m
42 use mesh_oct_m
47 use mpi_oct_m
50#ifdef HAVE_OPENMP
51 use omp_lib
52#endif
53 use parser_oct_m
57 use smear_oct_m
58 use space_oct_m
62 use types_oct_m
63 use unit_oct_m
67
68 implicit none
69
70 private
71
72 public :: &
102 stress_t, &
104
105
106 ! this type must be moved to stress module but due to circular dependency it is not possible now
107 type stress_t
108 real(real64) :: total(3,3) = m_zero
109 real(real64) :: kinetic(3,3) = m_zero
110 real(real64) :: Hartree(3,3) = m_zero
111 real(real64) :: xc(3,3) = m_zero
112 real(real64) :: xc_nlcc(3,3) = m_zero
113 real(real64) :: ps_local(3,3) = m_zero
114 real(real64) :: ps_nl(3,3) = m_zero
115 real(real64) :: ion_ion(3,3) = m_zero
116 real(real64) :: vdw(3,3) = m_zero
117 real(real64) :: hubbard(3,3) = m_zero
118
119 real(real64) :: kinetic_sumrule = m_zero
120 real(real64) :: hartree_sumrule = m_zero
121 end type stress_t
122
123 ! TODO(Alex) Issue #672 Decouple k-point info from `states_elec_dim_t`
124
132 !
133 type, extends(states_abst_t) :: states_elec_t
134 ! Components are public by default
135 type(states_elec_dim_t) :: d
136 integer :: nst_conv
137
138 logical :: only_userdef_istates
139
140 type(states_elec_group_t) :: group
141 integer :: block_size
145 logical :: pack_states
149
150
151 character(len=1024), allocatable :: user_def_states(:,:,:)
154
155 ! TODO(Alex) Issue #821. Collate current quantities into an object.
156 ! the densities and currents (after all we are doing DFT :)
157 real(real64), allocatable :: rho(:,:)
158 real(real64), allocatable :: rho_core(:)
159
160 ! Buffer density
161 type(accel_mem_t) :: buff_density
162
163 real(real64), allocatable :: current(:, :, :)
164 real(real64), allocatable :: current_para(:, :, :)
165 real(real64), allocatable :: current_dia(:, :, :)
166 real(real64), allocatable :: current_mag(:, :, :)
167 real(real64), allocatable :: current_kpt(:,:,:)
168
169 ! TODO(Alex) Issue #673. Create frozen density class and replace in states_elec_t
170 ! It may be required to "freeze" the deepest orbitals during the evolution; the density
171 ! of these orbitals is kept in frozen_rho. It is different from rho_core.
172 real(real64), allocatable :: frozen_rho(:, :)
173 real(real64), allocatable :: frozen_tau(:, :)
174 real(real64), allocatable :: frozen_gdens(:,:,:)
175 real(real64), allocatable :: frozen_ldens(:,:)
176
177 logical :: uniform_occ
178
179 real(real64), allocatable :: eigenval(:,:)
180 logical :: fixed_occ
181 logical :: restart_fixed_occ
182 logical :: restart_reorder_occs
183 real(real64), allocatable :: occ(:,:)
184 real(real64), allocatable :: kweights(:)
185 integer :: nik
186
187 logical :: fixed_spins
189 real(real64), allocatable :: spin(:, :, :)
190
191 real(real64) :: qtot
192 real(real64) :: val_charge
193
194 type(stress_t) :: stress_tensors
195
196 logical :: fromScratch
197 type(smear_t) :: smear
198
199 ! TODO(Alex) Issue #823 Move modelmbparticles out of states_elec_t
200 type(modelmb_particle_t) :: modelmbparticles
201
202 ! TODO(Alex) Issue #824. Package the communicators in a single instance prior to removing
203 ! or consider creating a distributed_t instance for each (as distributed_t contains the an instance of mpi_grp_t)
204 type(mpi_grp_t) :: mpi_grp
205 type(mpi_grp_t) :: dom_st_mpi_grp
206 type(mpi_grp_t) :: st_kpt_mpi_grp
207 type(mpi_grp_t) :: dom_st_kpt_mpi_grp
208 type(mpi_grp_t) :: system_grp
209 type(blacs_proc_grid_t) :: dom_st_proc_grid
211 type(distributed_t) :: dist
212 logical :: scalapack_compatible
213 logical :: parallel_in_states = .false.
215 ! TODO(Alex) Issue #820. Remove lnst, st_start, st_end and node, as they are all contained within dist
216 integer :: lnst
217 integer :: st_start, st_end
218 integer, allocatable :: node(:)
219
220 ! TODO(Alex) Issue #824. Either change from data to a method, or package with `st_kpt_mpi_grp`
221 integer, allocatable :: st_kpt_task(:,:)
222
223 type(multicomm_all_pairs_t), private :: ap
224 logical :: symmetrize_density
225 integer :: randomization
226 integer :: orth_method = 0
227
228 real(real64) :: gpu_states_mem
229
230 contains
231 procedure :: nullify => states_elec_null
232 procedure :: write_info => states_elec_write_info
233 procedure :: pack => states_elec_pack
234 procedure :: unpack => states_elec_unpack
236 procedure :: dipole => states_elec_calculate_dipole
237 end type states_elec_t
238
240 integer, public, parameter :: &
241 par_independent = 1, &
242 par_dependent = 2
243
244
245 interface states_elec_get_state
248 end interface states_elec_get_state
249
250 interface states_elec_set_state
254
255 interface states_elec_get_points
257 end interface states_elec_get_points
261 end interface
263contains
264
265 ! TODO(Alex): Issue #826. Rename to something like "states_elec_default_wfs_type", or remove
266 subroutine states_elec_null(st)
267 class(states_elec_t), intent(inout) :: st
271 st%wfs_type = type_float ! By default, calculations use real wavefunctions
273 st%packed = .false.
276 end subroutine states_elec_null
280 subroutine states_elec_init(st, namespace, space, valence_charge, kpoints, calc_mode_id)
281 type(states_elec_t), target, intent(inout) :: st
282 type(namespace_t), intent(in) :: namespace
283 type(electron_space_t), intent(in) :: space
284 real(real64), intent(in) :: valence_charge
285 type(kpoints_t), intent(in) :: kpoints
286 integer, optional, intent(in) :: calc_mode_id
288 real(real64) :: excess_charge, nempty_percent
289 integer :: nempty, ntot, default
290 integer :: nempty_conv, nempty_conv_default
291 logical :: force, adapt_for_chebyshev
292 real(real64), parameter :: tol = 1e-13_real64
293 integer :: es
294 integer, parameter :: rs_chebyshev = 12
295 integer(int64), parameter :: chebyshev_compatible_modes(3) = &
296 [option__calculationmode__gs, option__calculationmode__go, option__calculationmode__unocc]
297
298 push_sub_with_profile(states_elec_init)
300 st%fromScratch = .true. ! this will be reset if restart_read is called
303 ! We get the spin dimension from the electronic space
304 ! TODO: Remove spin space information from states_elec_dim
305 st%d%ispin = space%ispin
307 ! Use of spinors requires complex wavefunctions.
308 if (st%d%ispin == spinors) call states_set_complex(st)
309
310 if (st%d%ispin /= unpolarized .and. kpoints%use_time_reversal) then
311 message(1) = "Time reversal symmetry is only implemented for unpolarized spins."
312 message(2) = "Use KPointsUseTimeReversal = no."
313 call messages_fatal(2, namespace=namespace)
314 end if
315
317 !%Variable ExcessCharge
318 !%Type float
319 !%Default 0.0
320 !%Section States
321 !%Description
322 !% The net charge of the system. A negative value means that we are adding
323 !% electrons, while a positive value means we are taking electrons
324 !% from the system.
325 !%End
326 call parse_variable(namespace, 'ExcessCharge', m_zero, excess_charge)
328 !%Variable TotalStates
329 !%Type integer
330 !%Default 0
331 !%Section States
332 !%Description
333 !% This variable sets the total number of states that Octopus will
334 !% use. This is normally not necessary since by default Octopus
335 !% sets the number of states to the minimum necessary to hold the
336 !% electrons present in the system. (This default behavior is
337 !% obtained by setting <tt>TotalStates</tt> to 0).
338 !%
339 !% If you want to add some unoccupied states, probably it is more convenient to use the variable
340 !% <tt>ExtraStates</tt>.
341 !%End
342 call parse_variable(namespace, 'TotalStates', 0, ntot)
343 if (ntot < 0) then
344 write(message(1), '(a,i5,a)') "Input: '", ntot, "' is not a valid value for TotalStates."
345 call messages_fatal(1, namespace=namespace)
346 end if
347
348 !%Variable ExtraStates
349 !%Type integer
350 !%Default 0
351 !%Section States
352 !%Description
353 !% The number of states is in principle calculated considering the minimum
354 !% numbers of states necessary to hold the electrons present in the system.
355 !% The number of electrons is
356 !% in turn calculated considering the nature of the species supplied in the
357 !% <tt>Species</tt> block, and the value of the <tt>ExcessCharge</tt> variable.
358 !% However, one may command <tt>Octopus</tt> to use more states, which is necessary if one wants to
359 !% use fractional occupational numbers, either fixed from the beginning through
360 !% the <tt>Occupations</tt> block or by prescribing
361 !% an electronic temperature with <tt>Smearing</tt>, or in order to calculate
362 !% excited states (including with <tt>CalculationMode = unocc</tt>).
363 !%End
364 call parse_variable(namespace, 'ExtraStates', 0, nempty)
365 if (nempty < 0) then
366 write(message(1), '(a,i5,a)') "Input: '", nempty, "' is not a valid value for ExtraStates."
367 message(2) = '(0 <= ExtraStates)'
368 call messages_fatal(2, namespace=namespace)
369 end if
370
371 if (ntot > 0 .and. nempty > 0) then
372 message(1) = 'You cannot set TotalStates and ExtraStates at the same time.'
373 call messages_fatal(1, namespace=namespace)
374 end if
376 !%Variable ExtraStatesInPercent
377 !%Type float
378 !%Default 0
379 !%Section States
380 !%Description
381 !% This variable allows to set the number of extra/empty states as percentage of the
382 !% used occupied states. For example, a value 35 for ExtraStatesInPercent would amount
383 !% to ceiling(35/100 * nstates) extra states, where nstates denotes the amount of occupied
384 !% states Octopus is using for the system at hand.
385 !%End
386 call parse_variable(namespace, 'ExtraStatesInPercent', m_zero, nempty_percent)
387 if (nempty_percent < 0) then
388 write(message(1), '(a,f8.6,a)') "Input: '", nempty_percent, &
389 "' should be a percentage value x (where x is parts in hundred) larger or equal 0"
390 call messages_fatal(1, namespace=namespace)
391 end if
392
393 if (nempty > 0 .and. nempty_percent > 0) then
394 message(1) = 'You cannot set ExtraStates and ExtraStatesInPercent at the same time.'
395 call messages_fatal(1, namespace=namespace)
396 end if
397
398 ! Only use extra states for Chebyshev filtering in ground state or geometry optimization runs
399 adapt_for_chebyshev = .false.
400 if (present(calc_mode_id)) then
401 if (any(calc_mode_id == chebyshev_compatible_modes)) then
402 ! this variable is documented in electrons/eigensolver.F90
403 call parse_variable(namespace, 'Eigensolver', rs_chebyshev, es)
404 if (es == rs_chebyshev) then
405 ! reuse this condition below
406 adapt_for_chebyshev = .true.
407 end if
408 end if
409 end if
410 if (adapt_for_chebyshev) then
411 if (nempty == 0 .and. is_close(nempty_percent, m_zero)) then
412 nempty_percent = 15
413 message(1) = 'Chebyshev filtering eigensolver detected. Setting ExtraStatesInPercent = 15'
414 call messages_info(1, namespace=namespace)
415 end if
416 end if
417
418 ! For non-periodic systems this should just return the Gamma point
419 call states_elec_choose_kpoints(st, kpoints, namespace)
420
421 st%val_charge = valence_charge
422
423 st%qtot = -(st%val_charge + excess_charge)
424
425 if (st%qtot < -m_epsilon) then
426 write(message(1),'(a,f12.6,a)') 'Total charge = ', st%qtot, ' < 0'
427 message(2) = 'Check Species and ExcessCharge.'
428 call messages_fatal(2, only_root_writes = .true., namespace=namespace)
429 end if
430
431 select case (st%d%ispin)
432 case (unpolarized)
433 st%d%dim = 1
434 st%nst = nint(st%qtot/2)
435 if (st%nst*2 - st%qtot < -tol) st%nst = st%nst + 1
436 st%d%nspin = 1
437 st%d%spin_channels = 1
438 case (spin_polarized)
439 st%d%dim = 1
440 st%nst = nint(st%qtot/2)
441 if (st%nst*2 - st%qtot < -tol) st%nst = st%nst + 1
442 st%d%nspin = 2
443 st%d%spin_channels = 2
444 case (spinors)
445 st%d%dim = 2
446 st%nst = nint(st%qtot)
447 if (st%nst - st%qtot < -tol) st%nst = st%nst + 1
448 st%d%nspin = 4
449 st%d%spin_channels = 2
450 end select
451
452 if (nempty_percent > 0) then
453 nempty = ceiling(nempty_percent * st%nst / 100)
454 end if
455
456 !%Variable ExtraStatesToConverge
457 !%Type integer
458 !%Default <tt>ExtraStates</tt> (Default 0)
459 !%Section States
460 !%Description
461 !% For <tt>gs</tt> and <tt>unocc</tt> calculations.
462 !% (For the <tt>gs</tt> calculation one needs to set <tt>ConvEigenError=yes</tt>)
463 !% Specifies the number of extra states that will be considered for reaching the convergence.
464 !% The calculation will consider the number off occupied states plus
465 !% <tt>ExtraStatesToConverge</tt> for the convergence criteria.
466 !% By default, all extra states need to be converged (For <tt>gs</tt> calculations only with <tt>ConvEigenError=yes</tt>).
467 !% Thus, together with <tt>ExtraStates</tt>, one can have some more states which will not be
468 !% considered for the convergence criteria, thus making the convergence of the
469 !% unocc calculation faster.
470 !%
471 !% If chebyshev filtering is used, the default is <tt>min(0.8*ExtraStates, ExtraStates - 1)</tt>.
472 !%End
473 nempty_conv_default = nempty
474 if (adapt_for_chebyshev) then
475 ! use 80% of the extra states, but at least do not converge one extra state
476 nempty_conv_default = min(int(0.8*nempty), nempty - 1)
477 end if
478 call parse_variable(namespace, 'ExtraStatesToConverge', nempty_conv_default, nempty_conv)
479 if (nempty_conv < 0) then
480 write(message(1), '(a,i5,a)') "Input: '", nempty_conv, "' is not a valid value for ExtraStatesToConverge."
481 message(2) = '(0 <= ExtraStatesToConverge)'
482 call messages_fatal(2, namespace=namespace)
483 end if
484
485 if (nempty_conv > nempty) then
486 nempty_conv = nempty
487 message(1) = 'You cannot set ExtraStatesToConverge to a higher value than ExtraStates.'
488 message(2) = 'Capping ExtraStatesToConverge to ExtraStates.'
489 call messages_warning(2, namespace=namespace)
490 endif
491
492 if (ntot > 0) then
493 if (ntot < st%nst) then
494 message(1) = 'TotalStates is smaller than the number of states required by the system.'
495 call messages_fatal(1, namespace=namespace)
496 end if
497
498 st%nst = ntot
499 end if
500
501 st%nst_conv = st%nst + nempty_conv
502 st%nst = st%nst + nempty
503 if (st%nst == 0) then
504 message(1) = "Cannot run with number of states = zero."
505 call messages_fatal(1, namespace=namespace)
506 end if
507
508 !%Variable StatesBlockSize
509 !%Type integer
510 !%Section Execution::Optimization
511 !%Description
512 !% Some routines work over blocks of eigenfunctions, which
513 !% generally improves performance at the expense of increased
514 !% memory consumption. This variable selects the size of the
515 !% blocks to be used. If GPUs are used, the default is the
516 !% warp size (32 for NVIDIA, 32 or 64 for AMD);
517 !% otherwise it is 4.
518 !%End
519
520 if (accel_is_enabled()) then
521 ! use the warp size (usually 32, for some AMD GPUs it is 64)
522 default = accel%warp_size
523 else
524 default = 4
525 end if
526
527 if (default > pad_pow2(st%nst)) default = pad_pow2(st%nst)
528
529 assert(default > 0)
530
531 call parse_variable(namespace, 'StatesBlockSize', default, st%block_size)
532 if (st%block_size < 1) then
533 call messages_write("The variable 'StatesBlockSize' must be greater than 0.")
534 call messages_fatal(namespace=namespace)
535 end if
536
537 st%block_size = min(st%block_size, st%nst)
538 conf%target_states_block_size = st%block_size
539
540 safe_allocate(st%eigenval(1:st%nst, 1:st%nik))
541 st%eigenval = huge(st%eigenval)
542
543 ! Periodic systems require complex wavefunctions
544 ! but not if it is Gamma-point only
545 if (.not. kpoints%gamma_only()) then
546 call states_set_complex(st)
547 end if
548
549 !%Variable OnlyUserDefinedInitialStates
550 !%Type logical
551 !%Default no
552 !%Section States
553 !%Description
554 !% If true, then only user-defined states from the block <tt>UserDefinedStates</tt>
555 !% will be used as initial states for a time-propagation. No attempt is made
556 !% to load ground-state orbitals from a previous ground-state run.
557 !%End
558 call parse_variable(namespace, 'OnlyUserDefinedInitialStates', .false., st%only_userdef_istates)
559
560 ! we now allocate some arrays
561 safe_allocate(st%occ (1:st%nst, 1:st%nik))
562 st%occ = m_zero
563 ! allocate space for formula strings that define user-defined states
564 if (parse_is_defined(namespace, 'UserDefinedStates') .or. parse_is_defined(namespace, 'OCTInitialUserdefined') &
565 .or. parse_is_defined(namespace, 'OCTTargetUserdefined')) then
566 safe_allocate(st%user_def_states(1:st%d%dim, 1:st%nst, 1:st%nik))
567 ! initially we mark all 'formulas' as undefined
568 st%user_def_states(1:st%d%dim, 1:st%nst, 1:st%nik) = 'undefined'
569 end if
570
571 if (st%d%ispin == spinors) then
572 safe_allocate(st%spin(1:3, 1:st%nst, 1:st%nik))
573 end if
574
575 !%Variable StatesRandomization
576 !%Type integer
577 !%Default par_independent
578 !%Section States
579 !%Description
580 !% The randomization of states can be done in two ways:
581 !% i) a parallelisation independent way (default), where the random states are identical,
582 !% irrespectively of the number of tasks and
583 !% ii) a parallelisation dependent way, which can prevent linear dependency
584 !% to occur for large systems.
585 !%Option par_independent 1
586 !% Parallelisation-independent randomization of states.
587 !%Option par_dependent 2
588 !% The randomization depends on the number of taks used in the calculation.
589 !%End
590 call parse_variable(namespace, 'StatesRandomization', par_independent, st%randomization)
591
592
593 call states_elec_read_initial_occs(st, namespace, excess_charge, kpoints)
594 call states_elec_read_initial_spins(st, namespace)
595
596 ! This test can only be done here, as smear_init is called inside states_elec_read_initial_occs, and
597 ! only there smear%photodop is set.
598
599 if (st%smear%photodop) then
600 if (nempty == 0) then
601 write(message(1), '(a,i5,a)') "PhotoDoping requires to specify ExtraStates."
602 message(2) = '(0 == ExtraStates)'
603 call messages_fatal(2, namespace=namespace)
604 end if
605 end if
606
607 st%st_start = 1
608 st%st_end = st%nst
609 st%lnst = st%nst
610 safe_allocate(st%node(1:st%nst))
611 st%node(1:st%nst) = 0
612
613 call mpi_grp_init(st%mpi_grp, mpi_comm_undefined)
614 st%parallel_in_states = .false.
615
616 call distributed_nullify(st%d%kpt, st%nik)
617
618 call modelmb_particles_init(st%modelmbparticles, namespace, space, st%nst)
619
620 !%Variable SymmetrizeDensity
621 !%Type logical
622 !%Default no
623 !%Section States
624 !%Description
625 !% When enabled the density is symmetrized. Currently, this can
626 !% only be done for periodic systems. (Experimental.)
627 !%End
628 call parse_variable(namespace, 'SymmetrizeDensity', kpoints%use_symmetries, st%symmetrize_density)
629 call messages_print_var_value('SymmetrizeDensity', st%symmetrize_density, namespace=namespace)
630
631 !%Variable ForceComplex
632 !%Type logical
633 !%Default no
634 !%Section Execution::Debug
635 !%Description
636 !% Normally <tt>Octopus</tt> determines automatically the type necessary
637 !% for the wavefunctions. When set to yes this variable will
638 !% force the use of complex wavefunctions.
639 !%
640 !% Warning: This variable is designed for testing and
641 !% benchmarking and normal users need not use it.
642 !%End
643 call parse_variable(namespace, 'ForceComplex', .false., force)
644
645 if (force) call states_set_complex(st)
646
647 st%packed = .false.
648
649 pop_sub_with_profile(states_elec_init)
650 end subroutine states_elec_init
651
652 ! ---------------------------------------------------------
655 !
656 subroutine states_elec_look(restart, nik, dim, nst, ierr)
657 class(restart_t), intent(in) :: restart
658 integer, intent(out) :: nik
659 integer, intent(out) :: dim
660 integer, intent(out) :: nst
661 integer, intent(out) :: ierr
662
663 character(len=256) :: lines(3)
664 character(len=20) :: char
665 integer :: iunit
666
667 push_sub(states_elec_look)
668
669 ierr = 0
670
671 iunit = restart%open('states')
672 call restart%read(iunit, lines, 3, ierr)
673 if (ierr == 0) then
674 read(lines(1), *) char, nst
675 read(lines(2), *) char, dim
676 read(lines(3), *) char, nik
677 end if
678 call restart%close(iunit)
679
680 pop_sub(states_elec_look)
681 end subroutine states_elec_look
682
683 ! ---------------------------------------------------------
692 !
693 subroutine states_elec_read_initial_occs(st, namespace, excess_charge, kpoints)
694 type(states_elec_t), intent(inout) :: st
695 type(namespace_t), intent(in) :: namespace
696 real(real64), intent(in) :: excess_charge
697 type(kpoints_t), intent(in) :: kpoints
698
699 integer :: ik, ist, ispin, nspin, ncols, nrows, el_per_state, icol, start_pos, spin_n
700 type(block_t) :: blk
701 real(real64) :: rr, charge
702 logical :: integral_occs, unoccupied_states
703 real(real64), allocatable :: read_occs(:, :)
704 real(real64) :: charge_in_block
705
707
708 !%Variable RestartFixedOccupations
709 !%Type logical
710 !%Section States
711 !%Description
712 !% Setting this variable will make the restart proceed as
713 !% if the occupations from the previous calculation had been set via the <tt>Occupations</tt> block,
714 !% <i>i.e.</i> fixed. Otherwise, occupations will be determined by smearing.
715 !%
716 !% Linear response calculations and self-consistent calculations are unaffected by this variable.
717 !% This is however used for Sternheimer calculations.
718 !%End
719 call parse_variable(namespace, 'RestartFixedOccupations', .true., st%restart_fixed_occ)
720 ! we will turn on st%fixed_occ if restart_read is ever called
721
722 !%Variable Occupations
723 !%Type block
724 !%Section States
725 !%Description
726 !% The occupation numbers of the orbitals can be fixed through the use of this
727 !% variable. For example:
728 !%
729 !% <tt>%Occupations
730 !% <br>&nbsp;&nbsp;2 | 2 | 2 | 2 | 2
731 !% <br>%</tt>
732 !%
733 !% would fix the occupations of the five states to 2. There can be
734 !% at most as many columns as states in the calculation. If there are fewer columns
735 !% than states, then the code will assume that the user is indicating the occupations
736 !% of the uppermost states where all lower states have full occupation (i.e. 2 for spin-unpolarized
737 !% calculations, 1 otherwise) and all higher states have zero occupation. The first column
738 !% will be taken to refer to the lowest state such that the occupations would be consistent
739 !% with the correct total charge. For example, if there are 8 electrons and 10 states (from
740 !% <tt>ExtraStates = 6</tt>), then an abbreviated specification
741 !%
742 !% <tt>%Occupations
743 !% <br>&nbsp;&nbsp;1 | 0 | 1
744 !% <br>%</tt>
745 !%
746 !% would be equivalent to a full specification
747 !%
748 !% <tt>%Occupations
749 !% <br>&nbsp;&nbsp;2 | 2 | 2 | 1 | 0 | 1 | 0 | 0 | 0 | 0
750 !% <br>%</tt>
751 !%
752 !% This is an example of use for constrained density-functional theory,
753 !% crudely emulating a HOMO->LUMO+1 optical excitation.
754 !% The number of rows should be equal
755 !% to the number of k-points times the number of spins. For example, for a finite system
756 !% with <tt>SpinComponents == spin_polarized</tt>,
757 !% this block should contain two lines, one for each spin channel.
758 !% All rows must have the same number of columns.
759 !%
760 !% The <tt>Occupations</tt> block is useful for the ground state of highly symmetric
761 !% small systems (like an open-shell atom), to fix the occupation numbers
762 !% of degenerate states in order to help <tt>octopus</tt> to converge. This is to
763 !% be used in conjuction with <tt>ExtraStates</tt>. For example, to calculate the
764 !% carbon atom, one would do:
765 !%
766 !% <tt>ExtraStates = 2
767 !% <br>%Occupations
768 !% <br>&nbsp;&nbsp;2 | 2/3 | 2/3 | 2/3
769 !% <br>%</tt>
770 !%
771 !% If you want the calculation to be spin-polarized (which makes more sense), you could do:
772 !%
773 !% <tt>ExtraStates = 2
774 !% <br>%Occupations
775 !% <br>&nbsp;&nbsp; 2/3 | 2/3 | 2/3
776 !% <br>&nbsp;&nbsp; 0 | 0 | 0
777 !% <br>%</tt>
778 !%
779 !% Note that in this case the first state is absent, the code will calculate four states
780 !% (two because there are four electrons, plus two because <tt>ExtraStates</tt> = 2), and since
781 !% it finds only three columns, it will occupy the first state with one electron for each
782 !% of the spin options.
783 !%
784 !% If the sum of occupations is not equal to the total charge set by <tt>ExcessCharge</tt>,
785 !% an error message is printed.
786 !% If <tt>FromScratch = no</tt> and <tt>RestartFixedOccupations = yes</tt>,
787 !% this block will be ignored.
788 !%End
789
790 integral_occs = .true.
791
792 occ_fix: if (parse_block(namespace, 'Occupations', blk) == 0) then
793 ! read in occupations
794 st%fixed_occ = .true.
795
796 ncols = parse_block_cols(blk, 0)
797 if (ncols > st%nst) then
798 call messages_input_error(namespace, "Occupations", "Too many columns in block Occupations.")
799 end if
800
801 nrows = parse_block_n(blk)
802 if (nrows /= st%nik) then
803 call messages_input_error(namespace, "Occupations", "Wrong number of rows in block Occupations.")
804 end if
805
806 do ik = 1, st%nik - 1
807 if (parse_block_cols(blk, ik) /= ncols) then
808 call messages_input_error(namespace, "Occupations", &
809 "All rows in block Occupations must have the same number of columns.")
810 end if
811 end do
812
813 ! Now we fill all the "missing" states with the maximum occupation.
814 if (st%d%ispin == unpolarized) then
815 el_per_state = 2
816 else
817 el_per_state = 1
818 end if
819
820 safe_allocate(read_occs(1:ncols, 1:st%nik))
821
822 charge_in_block = m_zero
823 do ik = 1, st%nik
824 do icol = 1, ncols
825 call parse_block_float(blk, ik - 1, icol - 1, read_occs(icol, ik))
826 charge_in_block = charge_in_block + read_occs(icol, ik) * st%kweights(ik)
827 end do
828 end do
829
830 spin_n = 2
831 select case (st%d%ispin)
832 case (unpolarized)
833 spin_n = 2
834 case (spin_polarized)
835 spin_n = 2
836 case (spinors)
837 spin_n = 1
838 end select
839
840 start_pos = nint((st%qtot - charge_in_block)/spin_n)
841
842 if (start_pos + ncols > st%nst) then
843 message(1) = "To balance charge, the first column in block Occupations is taken to refer to state"
844 write(message(2),'(a,i6,a)') "number ", start_pos, " but there are too many columns for the number of states."
845 write(message(3),'(a,i6,a)') "Solution: set ExtraStates = ", start_pos + ncols - st%nst
846 call messages_fatal(3, namespace=namespace)
847 end if
848
849 do ik = 1, st%nik
850 do ist = 1, start_pos
851 st%occ(ist, ik) = el_per_state
852 end do
853 end do
854
855 do ik = 1, st%nik
856 do ist = start_pos + 1, start_pos + ncols
857 st%occ(ist, ik) = read_occs(ist - start_pos, ik)
858 integral_occs = integral_occs .and. &
859 abs((st%occ(ist, ik) - el_per_state) * st%occ(ist, ik)) <= m_epsilon
860 end do
861 end do
862
863 do ik = 1, st%nik
864 do ist = start_pos + ncols + 1, st%nst
865 st%occ(ist, ik) = m_zero
866 end do
867 end do
868
869 call parse_block_end(blk)
870
871 safe_deallocate_a(read_occs)
872
873 else
874 st%fixed_occ = .false.
875 integral_occs = .false.
876
877 ! first guess for occupation...paramagnetic configuration
878 rr = m_one
879 if (st%d%ispin == unpolarized) rr = m_two
880
881 st%occ = m_zero
882 st%qtot = -(st%val_charge + excess_charge)
883
884 nspin = 1
885 if (st%d%nspin == 2) nspin = 2
886
887 do ik = 1, st%nik, nspin
888 charge = m_zero
889 do ist = 1, st%nst
890 do ispin = ik, ik + nspin - 1
891 st%occ(ist, ispin) = min(rr, -(st%val_charge + excess_charge) - charge)
892 charge = charge + st%occ(ist, ispin)
893 end do
894 end do
895 end do
896
897 end if occ_fix
898
899 !%Variable RestartReorderOccs
900 !%Type logical
901 !%Default no
902 !%Section States
903 !%Description
904 !% Consider doing a ground-state calculation, and then restarting with new occupations set
905 !% with the <tt>Occupations</tt> block, in an attempt to populate the orbitals of the original
906 !% calculation. However, the eigenvalues may reorder as the density changes, in which case the
907 !% occupations will now be referring to different orbitals. Setting this variable to yes will
908 !% try to solve this issue when the restart data is being read, by reordering the occupations
909 !% according to the order of the expectation values of the restart wavefunctions.
910 !%End
911 if (st%fixed_occ) then
912 call parse_variable(namespace, 'RestartReorderOccs', .false., st%restart_reorder_occs)
913 else
914 st%restart_reorder_occs = .false.
915 end if
916
917 call smear_init(st%smear, namespace, st%d%ispin, st%fixed_occ, integral_occs, kpoints)
918
919 unoccupied_states = (st%d%ispin /= spinors .and. st%nst*2 > st%qtot) .or. (st%d%ispin == spinors .and. st%nst > st%qtot)
920
921 if (.not. smear_is_semiconducting(st%smear) .and. .not. st%smear%method == smear_fixed_occ) then
922 if (.not. unoccupied_states) then
923 call messages_write('Smearing needs unoccupied states (via ExtraStates or TotalStates) to be useful.')
924 call messages_warning(namespace=namespace)
925 end if
926 end if
927
928 ! sanity check
929 charge = m_zero
930 do ist = 1, st%nst
931 charge = charge + sum(st%occ(ist, 1:st%nik) * st%kweights(1:st%nik))
932 end do
933 if (abs(charge - st%qtot) > 1e-6_real64) then
934 message(1) = "Initial occupations do not integrate to total charge."
935 write(message(2), '(6x,f12.6,a,f12.6)') charge, ' != ', st%qtot
936 call messages_fatal(2, only_root_writes = .true., namespace=namespace)
937 end if
938
939 st%uniform_occ = smear_is_semiconducting(st%smear) .and. .not. unoccupied_states
940
942 end subroutine states_elec_read_initial_occs
943
944
945 ! ---------------------------------------------------------
952 !
953 subroutine states_elec_read_initial_spins(st, namespace)
954 type(states_elec_t), intent(inout) :: st
955 type(namespace_t), intent(in) :: namespace
956
957 integer :: i, j, nrows
958 type(block_t) :: blk
959
961
962 st%fixed_spins = .false.
963 if (st%d%ispin /= spinors) then
965 return
966 end if
967
968 !%Variable InitialSpins
969 !%Type block
970 !%Section States
971 !%Description
972 !% The spin character of the initial random guesses for the spinors can
973 !% be fixed by making use of this block. Note that this will not "fix" the
974 !% the spins during the calculation (this cannot be done in spinors mode, in
975 !% being able to change the spins is why the spinors mode exists in the first
976 !% place).
977 !%
978 !% This block is meaningless and ignored if the run is not in spinors mode
979 !% (<tt>SpinComponents = spinors</tt>).
980 !%
981 !% The structure of the block is very simple: each column contains the desired
982 !% <math>\left< S_x \right>, \left< S_y \right>, \left< S_z \right> </math> for each spinor.
983 !% If the calculation is for a periodic system
984 !% and there is more than one <i>k</i>-point, the spins of all the <i>k</i>-points are
985 !% the same.
986 !%
987 !% For example, if we have two spinors, and we want one in the <math>S_x</math> "down" state,
988 !% and another one in the <math>S_x</math> "up" state:
989 !%
990 !% <tt>%InitialSpins
991 !% <br>&nbsp;&nbsp;&nbsp; 0.5 | 0.0 | 0.0
992 !% <br>&nbsp;&nbsp; -0.5 | 0.0 | 0.0
993 !% <br>%</tt>
994 !%
995 !% WARNING: if the calculation is for a system described by pseudopotentials (as
996 !% opposed to user-defined potentials or model systems), this option is
997 !% meaningless since the random spinors are overwritten by the atomic orbitals.
998 !%
999 !% This constraint must be fulfilled:
1000 !% <br><math> \left< S_x \right>^2 + \left< S_y \right>^2 + \left< S_z \right>^2 = \frac{1}{4} </math>
1001 !%End
1002 spin_fix: if (parse_block(namespace, 'InitialSpins', blk) == 0) then
1003 nrows = parse_block_n(blk)
1004 if (nrows < st%nst) then
1005 message(1) = "Please specify one row for each state in InitialSpins, also for extra states."
1006 call messages_fatal(1, namespace=namespace)
1007 end if
1008 do i = 1, st%nst
1009 do j = 1, 3
1010 call parse_block_float(blk, i-1, j-1, st%spin(j, i, 1))
1011 end do
1012 if (abs(sum(st%spin(1:3, i, 1)**2) - m_fourth) > 1.0e-6_real64) call messages_input_error(namespace, 'InitialSpins')
1013 end do
1014 call parse_block_end(blk)
1015 st%fixed_spins = .true.
1016 do i = 2, st%nik
1017 st%spin(:, :, i) = st%spin(:, :, 1)
1018 end do
1019 end if spin_fix
1020
1022 end subroutine states_elec_read_initial_spins
1023
1024
1025 ! ---------------------------------------------------------
1027 !
1028 subroutine states_elec_allocate_wfns(st, mesh, wfs_type, skip, packed)
1029 type(states_elec_t), intent(inout) :: st
1030 class(mesh_t), intent(in) :: mesh
1031 type(type_t), optional, intent(in) :: wfs_type
1032 logical, optional, intent(in) :: skip(:)
1033 logical, optional, intent(in) :: packed
1034
1036
1037 if (present(wfs_type)) then
1038 assert(wfs_type == type_float .or. wfs_type == type_cmplx)
1039 st%wfs_type = wfs_type
1040 end if
1041
1042 call states_elec_init_block(st, mesh, skip = skip, packed=packed)
1043 call states_elec_set_zero(st)
1044
1046 end subroutine states_elec_allocate_wfns
1047
1048 !---------------------------------------------------------------------
1065 subroutine states_elec_init_block(st, mesh, verbose, skip, packed)
1066 type(states_elec_t), intent(inout) :: st
1067 type(mesh_t), intent(in) :: mesh
1068 logical, optional, intent(in) :: verbose
1069 logical, optional, intent(in) :: skip(:)
1070 logical, optional, intent(in) :: packed
1071
1072 integer :: ib, iqn, ist, istmin, istmax
1073 logical :: same_node, verbose_, packed_
1074 integer, allocatable :: bstart(:), bend(:)
1075
1076 push_sub(states_elec_init_block)
1077
1078 safe_allocate(bstart(1:st%nst))
1079 safe_allocate(bend(1:st%nst))
1080 safe_allocate(st%group%iblock(1:st%nst))
1081
1082 st%group%iblock = 0
1083
1084 verbose_ = optional_default(verbose, .true.)
1085 packed_ = optional_default(packed, .false.)
1086
1087 !In case we have a list of state to skip, we do not allocate them
1088 istmin = 1
1089 if (present(skip)) then
1090 do ist = 1, st%nst
1091 if (.not. skip(ist)) then
1092 istmin = ist
1093 exit
1094 end if
1095 end do
1096 end if
1097
1098 istmax = st%nst
1099 if (present(skip)) then
1100 do ist = st%nst, istmin, -1
1101 if (.not. skip(ist)) then
1102 istmax = ist
1103 exit
1104 end if
1105 end do
1106 end if
1107
1108 if (present(skip) .and. verbose_) then
1109 call messages_write('Info: Allocating states from ')
1110 call messages_write(istmin, fmt = 'i8')
1111 call messages_write(' to ')
1112 call messages_write(istmax, fmt = 'i8')
1113 call messages_info()
1114 end if
1115
1116 ! count and assign blocks
1117 ib = 0
1118 st%group%nblocks = 0
1119 bstart(1) = istmin
1120 do ist = istmin, istmax
1121 ib = ib + 1
1122
1123 st%group%iblock(ist) = st%group%nblocks + 1
1124
1125 same_node = .true.
1126 if (st%parallel_in_states .and. ist /= istmax) then
1127 ! We have to avoid that states that are in different nodes end
1128 ! up in the same block
1129 same_node = (st%node(ist + 1) == st%node(ist))
1130 end if
1131
1132 if (ib == st%block_size .or. ist == istmax .or. .not. same_node) then
1133 ib = 0
1134 st%group%nblocks = st%group%nblocks + 1
1135 bend(st%group%nblocks) = ist
1136 if (ist /= istmax) bstart(st%group%nblocks + 1) = ist + 1
1137 end if
1138 end do
1139
1140 safe_allocate(st%group%psib(1:st%group%nblocks, st%d%kpt%start:st%d%kpt%end))
1141
1142 safe_allocate(st%group%block_is_local(1:st%group%nblocks, 1:st%nik))
1143 st%group%block_is_local = .false.
1144 st%group%block_start = -1
1145 st%group%block_end = -2 ! this will make that loops block_start:block_end do not run if not initialized
1146
1147 do ib = 1, st%group%nblocks
1148 if (bstart(ib) >= st%st_start .and. bend(ib) <= st%st_end) then
1149 if (st%group%block_start == -1) st%group%block_start = ib
1150 st%group%block_end = ib
1151 do iqn = st%d%kpt%start, st%d%kpt%end
1152 st%group%block_is_local(ib, iqn) = .true.
1153
1154 if (states_are_real(st)) then
1155 call dwfs_elec_init(st%group%psib(ib, iqn), st%d%dim, bstart(ib), bend(ib), mesh%np_part, iqn, &
1156 special=.true., packed=packed_)
1157 else
1158 call zwfs_elec_init(st%group%psib(ib, iqn), st%d%dim, bstart(ib), bend(ib), mesh%np_part, iqn, &
1159 special=.true., packed=packed_)
1160 end if
1161
1162 end do
1163 end if
1164 end do
1165
1166 safe_allocate(st%group%block_range(1:st%group%nblocks, 1:2))
1167 safe_allocate(st%group%block_size(1:st%group%nblocks))
1168
1169 st%group%block_range(1:st%group%nblocks, 1) = bstart(1:st%group%nblocks)
1170 st%group%block_range(1:st%group%nblocks, 2) = bend(1:st%group%nblocks)
1171 st%group%block_size(1:st%group%nblocks) = bend(1:st%group%nblocks) - bstart(1:st%group%nblocks) + 1
1172
1173 st%group%block_initialized = .true.
1174
1175 safe_allocate(st%group%block_node(1:st%group%nblocks, 1:st%nik))
1176 st%group%block_node = 0
1177
1178 assert(allocated(st%node))
1179 assert(all(st%node >= 0) .and. all(st%node < st%mpi_grp%size))
1180
1181 do iqn = st%d%kpt%start, st%d%kpt%end
1182 do ib = st%group%block_start, st%group%block_end
1183 st%group%block_node(ib, iqn) = st%st_kpt_mpi_grp%rank
1184 end do
1185 end do
1186
1187 call comm_allreduce(st%st_kpt_mpi_grp, st%group%block_node)
1188
1189 if (verbose_) then
1190 call messages_write('Info: Blocks of states')
1191 call messages_info()
1192 do ib = 1, st%group%nblocks
1193 call messages_write(' Block ')
1194 call messages_write(ib, fmt = 'i8')
1195 call messages_write(' contains ')
1196 call messages_write(st%group%block_size(ib), fmt = 'i8')
1197 call messages_write(' states')
1198 if (st%group%block_size(ib) > 0) then
1199 call messages_write(':')
1200 call messages_write(st%group%block_range(ib, 1), fmt = 'i8')
1201 call messages_write(' - ')
1202 call messages_write(st%group%block_range(ib, 2), fmt = 'i8')
1203 end if
1204 call messages_info()
1205 end do
1206 end if
1207
1208!!$!!!!DEBUG
1209!!$ ! some debug output that I will keep here for the moment
1210!!$ if (st%system_grp%is_root()) then
1211!!$ print*, "NST ", st%nst
1212!!$ print*, "BLOCKSIZE ", st%block_size
1213!!$ print*, "NBLOCKS ", st%group%nblocks
1214!!$
1215!!$ print*, "==============="
1216!!$ do ist = 1, st%nst
1217!!$ print*, st%node(ist), ist, st%group%iblock(ist)
1218!!$ end do
1219!!$ print*, "==============="
1220!!$
1221!!$ do ib = 1, st%group%nblocks
1222!!$ print*, ib, bstart(ib), bend(ib)
1223!!$ end do
1224!!$
1225!!$ end if
1226!!$!!!!ENDOFDEBUG
1227
1228 safe_deallocate_a(bstart)
1229 safe_deallocate_a(bend)
1230 pop_sub(states_elec_init_block)
1231 end subroutine states_elec_init_block
1232
1233
1234 ! ---------------------------------------------------------
1236 subroutine states_elec_deallocate_wfns(st)
1237 type(states_elec_t), intent(inout) :: st
1238
1240
1241 call states_elec_group_end(st%group, st%d)
1242 ! The wave functions (and their device buffers) are gone, so the batches
1243 ! are no longer packed. Reset the flag so a subsequent st%pack() actually
1244 ! repacks instead of returning early on a stale value.
1245 st%packed = .false.
1246
1248 end subroutine states_elec_deallocate_wfns
1249
1250
1251 ! ---------------------------------------------------------
1252 subroutine states_elec_densities_init(st, gr)
1253 type(states_elec_t), target, intent(inout) :: st
1254 type(grid_t), intent(in) :: gr
1255
1256 real(real64) :: fsize
1257
1259
1260 safe_allocate(st%rho(1:gr%np_part, 1:st%d%nspin))
1261 st%rho = m_zero
1262
1263 fsize = gr%np_part*8.0_real64*st%block_size
1264
1265 call messages_write('Info: states-block size = ')
1266 call messages_write(fsize, fmt = '(f10.1)', align_left = .true., units = unit_megabytes, print_units = .true.)
1267 call messages_info()
1268
1270 end subroutine states_elec_densities_init
1271
1272 !---------------------------------------------------------------------
1273 subroutine states_elec_allocate_current(st, space, mesh)
1274 type(states_elec_t), intent(inout) :: st
1275 class(space_t), intent(in) :: space
1276 class(mesh_t), intent(in) :: mesh
1277
1279
1280 if (.not. allocated(st%current)) then
1281 safe_allocate(st%current(1:mesh%np_part, 1:space%dim, 1:st%d%nspin))
1282 st%current = m_zero
1283 end if
1284
1285 if (.not. allocated(st%current_para)) then
1286 safe_allocate(st%current_para(1:mesh%np_part, 1:space%dim, 1:st%d%nspin))
1287 st%current_para = m_zero
1288 end if
1289
1290 if (.not. allocated(st%current_dia)) then
1291 safe_allocate(st%current_dia(1:mesh%np_part, 1:space%dim, 1:st%d%nspin))
1292 st%current_dia= m_zero
1293 end if
1294
1295 if (.not. allocated(st%current_mag)) then
1296 safe_allocate(st%current_mag(1:mesh%np_part, 1:space%dim, 1:st%d%nspin))
1297 st%current_mag= m_zero
1298 end if
1299
1300 if (.not. allocated(st%current_kpt)) then
1301 safe_allocate(st%current_kpt(1:mesh%np,1:space%dim,st%d%kpt%start:st%d%kpt%end))
1302 st%current_kpt = m_zero
1303 end if
1304
1306 end subroutine states_elec_allocate_current
1307
1308 !---------------------------------------------------------------------
1316 subroutine states_elec_exec_init(st, namespace, mc)
1317 type(states_elec_t), intent(inout) :: st
1318 type(namespace_t), intent(in) :: namespace
1319 type(multicomm_t), intent(in) :: mc
1320
1321 integer :: default
1322
1323 push_sub(states_elec_exec_init)
1324
1325 !%Variable StatesPack
1326 !%Type logical
1327 !%Section Execution::Optimization
1328 !%Description
1329 !% When set to yes, states are stored in packed mode, which improves
1330 !% performance considerably. Not all parts of the code will profit from
1331 !% this, but should nevertheless work regardless of how the states are
1332 !% stored.
1333 !%
1334 !% If GPUs are used and this variable is set to yes, Octopus
1335 !% will store the wave-functions in device (GPU) memory. If
1336 !% there is not enough memory to store all the wave-functions,
1337 !% execution will stop with an error.
1338 !%
1339 !% See also the related <tt>HamiltonianApplyPacked</tt> variable.
1340 !%
1341 !% The default is yes.
1342 !%End
1343
1344 call parse_variable(namespace, 'StatesPack', .true., st%pack_states)
1345
1346 call messages_print_var_value('StatesPack', st%pack_states, namespace=namespace)
1348 call messages_obsolete_variable(namespace, 'StatesMirror')
1349
1350 !%Variable StatesOrthogonalization
1351 !%Type integer
1352 !%Section SCF::Eigensolver
1353 !%Description
1354 !% The full orthogonalization method used by some
1355 !% eigensolvers. The default is <tt>cholesky_serial</tt>, except with state
1356 !% parallelization, the default is <tt>cholesky_parallel</tt>.
1357 !%Option cholesky_serial 1
1358 !% Cholesky decomposition implemented using
1359 !% BLAS/LAPACK. Can be used with domain parallelization but not
1360 !% state parallelization.
1361 !%Option cholesky_parallel 2
1362 !% Cholesky decomposition implemented using
1363 !% ScaLAPACK. Compatible with states parallelization.
1364 !%Option cgs 3
1365 !% Classical Gram-Schmidt (CGS) orthogonalization.
1366 !% Can be used with domain parallelization but not state parallelization.
1367 !% The algorithm is defined in Giraud et al., Computers and Mathematics with Applications 50, 1069 (2005).
1368 !%Option mgs 4
1369 !% Modified Gram-Schmidt (MGS) orthogonalization.
1370 !% Can be used with domain parallelization but not state parallelization.
1371 !% The algorithm is defined in Giraud et al., Computers and Mathematics with Applications 50, 1069 (2005).
1372 !%Option drcgs 5
1373 !% Classical Gram-Schmidt orthogonalization with double-step reorthogonalization.
1374 !% Can be used with domain parallelization but not state parallelization.
1375 !% The algorithm is taken from Giraud et al., Computers and Mathematics with Applications 50, 1069 (2005).
1376 !% According to this reference, this is much more precise than CGS or MGS algorithms.
1377 !% The MGS version seems not to improve much the stability and would require more communications over the domains.
1378 !%End
1379
1380 default = option__statesorthogonalization__cholesky_serial
1381#ifdef HAVE_SCALAPACK
1383 default = option__statesorthogonalization__cholesky_parallel
1384 end if
1385#endif
1386
1387 call parse_variable(namespace, 'StatesOrthogonalization', default, st%orth_method)
1388
1389 if (.not. varinfo_valid_option('StatesOrthogonalization', st%orth_method)) then
1390 call messages_input_error(namespace, 'StatesOrthogonalization')
1391 end if
1392 call messages_print_var_option('StatesOrthogonalization', st%orth_method, namespace=namespace)
1393
1394 !%Variable StatesDeviceMemory
1395 !%Type float
1396 !%Section Execution::Optimization
1397 !%Default -512
1398 !%Description
1399 !% This variable selects the amount of device memory that
1400 !% will be used by Octopus to store the states.
1401 !%
1402 !% A positive number smaller than 1 indicates a fraction of the total
1403 !% device memory. A number larger than one indicates an absolute
1404 !% amount of memory in megabytes. A negative number indicates an
1405 !% amount of memory in megabytes that would be subtracted from
1406 !% the total device memory.
1407 !%End
1408 call parse_variable(namespace, 'StatesDeviceMemory', -512.0_real64, st%gpu_states_mem)
1409 call messages_obsolete_variable(namespace, 'StatesCLDeviceMemory', 'StatesDeviceMemory')
1410
1412 end subroutine states_elec_exec_init
1413
1414
1415 ! ---------------------------------------------------------
1417 !
1418 subroutine states_elec_copy(stout, stin, exclude_wfns, exclude_eigenval, special)
1419 type(states_elec_t), target, intent(inout) :: stout
1420 type(states_elec_t), intent(in) :: stin
1421 logical, optional, intent(in) :: exclude_wfns
1422 logical, optional, intent(in) :: exclude_eigenval
1423 logical, optional, intent(in) :: special
1424
1425 logical :: exclude_wfns_
1426
1427 push_sub(states_elec_copy)
1428
1429 exclude_wfns_ = optional_default(exclude_wfns, .false.)
1430
1431 call states_elec_null(stout)
1432
1433 call states_elec_dim_copy(stout%d, stin%d)
1434 safe_allocate_source_a(stout%kweights, stin%kweights)
1435 stout%nik = stin%nik
1436
1437 call modelmb_particles_copy(stout%modelmbparticles, stin%modelmbparticles)
1438
1439 stout%wfs_type = stin%wfs_type
1440 stout%nst = stin%nst
1441 stout%block_size = stin%block_size
1442 stout%orth_method = stin%orth_method
1443
1444 stout%gpu_states_mem = stin%gpu_states_mem
1445 stout%pack_states = stin%pack_states
1446
1447 stout%only_userdef_istates = stin%only_userdef_istates
1448
1449 if (.not. exclude_wfns_) then
1450 safe_allocate_source_a(stout%rho, stin%rho)
1451 end if
1452
1453 stout%uniform_occ = stin%uniform_occ
1454
1455 if (.not. optional_default(exclude_eigenval, .false.)) then
1456 safe_allocate_source_a(stout%eigenval, stin%eigenval)
1457 safe_allocate_source_a(stout%occ, stin%occ)
1458 safe_allocate_source_a(stout%spin, stin%spin)
1459 end if
1460
1461 ! the call to init_block is done at the end of this subroutine
1462 ! it allocates iblock, psib, block_is_local
1463 stout%group%nblocks = stin%group%nblocks
1464
1465 safe_allocate_source_a(stout%user_def_states, stin%user_def_states)
1466
1467 safe_allocate_source_a(stout%current, stin%current)
1468 safe_allocate_source_a(stout%current_kpt, stin%current_kpt)
1469 safe_allocate_source_a(stout%rho_core, stin%rho_core)
1470 safe_allocate_source_a(stout%frozen_rho, stin%frozen_rho)
1471 safe_allocate_source_a(stout%frozen_tau, stin%frozen_tau)
1472 safe_allocate_source_a(stout%frozen_gdens, stin%frozen_gdens)
1473 safe_allocate_source_a(stout%frozen_ldens, stin%frozen_ldens)
1474
1475 stout%fixed_occ = stin%fixed_occ
1476 stout%restart_fixed_occ = stin%restart_fixed_occ
1477
1478 stout%fixed_spins = stin%fixed_spins
1479
1480 stout%qtot = stin%qtot
1481 stout%val_charge = stin%val_charge
1482
1483 call smear_copy(stout%smear, stin%smear)
1484
1485 stout%parallel_in_states = stin%parallel_in_states
1486 call mpi_grp_copy(stout%mpi_grp, stin%mpi_grp)
1487 call mpi_grp_copy(stout%system_grp, stin%system_grp)
1488 call mpi_grp_copy(stout%dom_st_kpt_mpi_grp, stin%dom_st_kpt_mpi_grp)
1489 call mpi_grp_copy(stout%st_kpt_mpi_grp, stin%st_kpt_mpi_grp)
1490 call mpi_grp_copy(stout%dom_st_mpi_grp, stin%dom_st_mpi_grp)
1491 safe_allocate_source_a(stout%node, stin%node)
1492 safe_allocate_source_a(stout%st_kpt_task, stin%st_kpt_task)
1493
1494#ifdef HAVE_SCALAPACK
1495 call blacs_proc_grid_copy(stin%dom_st_proc_grid, stout%dom_st_proc_grid)
1496#endif
1497
1498 call distributed_copy(stin%dist, stout%dist)
1499
1500 stout%scalapack_compatible = stin%scalapack_compatible
1501
1502 stout%lnst = stin%lnst
1503 stout%st_start = stin%st_start
1504 stout%st_end = stin%st_end
1505
1506 if (stin%parallel_in_states) call multicomm_all_pairs_copy(stout%ap, stin%ap)
1507
1508 stout%symmetrize_density = stin%symmetrize_density
1509
1510 if (.not. exclude_wfns_) call states_elec_group_copy(stin%d, stin%group, stout%group, special=special)
1511
1512 stout%packed = stin%packed
1514 stout%randomization = stin%randomization
1515
1516 pop_sub(states_elec_copy)
1517 end subroutine states_elec_copy
1518
1519
1520 ! ---------------------------------------------------------
1522 !
1523 subroutine states_elec_end(st)
1524 type(states_elec_t), intent(inout) :: st
1525
1526 push_sub(states_elec_end)
1527
1528 call states_elec_dim_end(st%d)
1529
1530 call modelmb_particles_end(st%modelmbparticles)
1531
1532 ! this deallocates dpsi, zpsi, psib, iblock, iblock
1534
1535 safe_deallocate_a(st%user_def_states)
1536
1537 safe_deallocate_a(st%rho)
1538 safe_deallocate_a(st%eigenval)
1539
1540 safe_deallocate_a(st%current)
1541 safe_deallocate_a(st%current_para)
1542 safe_deallocate_a(st%current_dia)
1543 safe_deallocate_a(st%current_mag)
1544 safe_deallocate_a(st%current_kpt)
1545 safe_deallocate_a(st%rho_core)
1546 safe_deallocate_a(st%frozen_rho)
1547 safe_deallocate_a(st%frozen_tau)
1548 safe_deallocate_a(st%frozen_gdens)
1549 safe_deallocate_a(st%frozen_ldens)
1550 safe_deallocate_a(st%occ)
1551 safe_deallocate_a(st%spin)
1552 safe_deallocate_a(st%kweights)
1553
1554
1555#ifdef HAVE_SCALAPACK
1556 call blacs_proc_grid_end(st%dom_st_proc_grid)
1557#endif
1558
1559 call distributed_end(st%dist)
1560
1561 safe_deallocate_a(st%node)
1562 safe_deallocate_a(st%st_kpt_task)
1563
1564 if (st%parallel_in_states) then
1565 safe_deallocate_a(st%ap%schedule)
1566 end if
1567
1568 if (st%buff_density%allocated) call accel_free_buffer(st%buff_density)
1569
1570 pop_sub(states_elec_end)
1571 end subroutine states_elec_end
1572
1573
1574 ! TODO(Alex) Issue #684. Abstract duplicate code in states_elec_generate_random, to get it to
1575 ! a point where it can be refactored.
1577 subroutine states_elec_generate_random(st, mesh, kpoints, ist_start_, ist_end_, ikpt_start_, ikpt_end_, normalized)
1578 type(states_elec_t), intent(inout) :: st
1579 class(mesh_t), intent(in) :: mesh
1580 type(kpoints_t), intent(in) :: kpoints
1581 integer, optional, intent(in) :: ist_start_
1582 integer, optional, intent(in) :: ist_end_
1583 integer, optional, intent(in) :: ikpt_start_
1584 integer, optional, intent(in) :: ikpt_end_
1585 logical, optional, intent(in) :: normalized
1587
1588 integer :: ist, ik, id, ist_start, ist_end, jst, ikpt_start, ikpt_end
1589 complex(real64) :: alpha, beta, zdotp_tmp
1590 real(real64), allocatable :: dpsi(:, :)
1591 complex(real64), allocatable :: zpsi(:, :), zpsi2(:)
1592 integer :: ikpoint, ip
1593 type(batch_t) :: ffb
1594
1595 logical :: normalized_
1596
1597 normalized_ = optional_default(normalized, .true.)
1598
1600
1601 ist_start = optional_default(ist_start_, 1)
1602 ist_end = optional_default(ist_end_, st%nst)
1603 ikpt_start = optional_default(ikpt_start_, 1)
1604 ikpt_end = optional_default(ikpt_end_, st%nik)
1605
1606 safe_allocate(dpsi(1:mesh%np, 1:st%d%dim))
1607 if (states_are_complex(st)) then
1608 safe_allocate(zpsi(1:mesh%np, 1:st%d%dim))
1609 end if
1610
1611 select case (st%d%ispin)
1613
1614 do ik = ikpt_start, ikpt_end
1615 ikpoint = st%d%get_kpoint_index(ik)
1616 do ist = ist_start, ist_end
1617 if (states_are_real(st).or.kpoints_point_is_gamma(kpoints, ikpoint)) then
1618 if (st%randomization == par_independent) then
1619 call dmf_random(mesh, dpsi(:, 1), &
1620 pre_shift = mesh%pv%xlocal-1, &
1621 post_shift = mesh%pv%np_global - mesh%pv%xlocal - mesh%np + 1, &
1622 normalized = normalized)
1623 ! Ensures that the grid points are properly distributed in the domain parallel case
1624 if(mesh%parallel_in_domains) then
1625 call batch_init(ffb, dpsi(:,1))
1626 call dmesh_batch_exchange_points(mesh, ffb, backward_map = .true.)
1627 call ffb%end()
1628 end if
1629 else
1630 call dmf_random(mesh, dpsi(:, 1), normalized = normalized)
1631 end if
1632 if (.not. state_kpt_is_local(st, ist, ik)) cycle
1633 if (states_are_complex(st)) then !Gamma point
1634 do ip = 1, mesh%np
1635 zpsi(ip,1) = cmplx(dpsi(ip,1), m_zero, real64)
1636 end do
1637 call states_elec_set_state(st, mesh, ist, ik, zpsi)
1638 else
1639 call states_elec_set_state(st, mesh, ist, ik, dpsi)
1640 end if
1641 else
1642 if (st%randomization == par_independent) then
1643 call zmf_random(mesh, zpsi(:, 1), &
1644 pre_shift = mesh%pv%xlocal-1, &
1645 post_shift = mesh%pv%np_global - mesh%pv%xlocal - mesh%np + 1, &
1646 normalized = normalized)
1647 ! Ensures that the grid points are properly distributed in the domain parallel case
1648 if(mesh%parallel_in_domains) then
1649 call batch_init(ffb, zpsi(:,1))
1650 call zmesh_batch_exchange_points(mesh, ffb, backward_map = .true.)
1651 call ffb%end()
1652 end if
1653 else
1654 call zmf_random(mesh, zpsi(:, 1), normalized = normalized)
1655 end if
1656 if (.not. state_kpt_is_local(st, ist, ik)) cycle
1657 call states_elec_set_state(st, mesh, ist, ik, zpsi)
1658 end if
1659 end do
1660 end do
1661
1662 case (spinors)
1663
1664 assert(states_are_complex(st))
1665
1666 if (st%fixed_spins) then
1667
1668 do ik = ikpt_start, ikpt_end
1669 ikpoint = st%d%get_kpoint_index(ik)
1670 do ist = ist_start, ist_end
1671 if (kpoints_point_is_gamma(kpoints, ikpoint)) then
1672 if (st%randomization == par_independent) then
1673 call dmf_random(mesh, dpsi(:, 1), &
1674 pre_shift = mesh%pv%xlocal-1, &
1675 post_shift = mesh%pv%np_global - mesh%pv%xlocal - mesh%np + 1, &
1676 normalized = normalized)
1677 ! Ensures that the grid points are properly distributed in the domain parallel case
1678 if(mesh%parallel_in_domains) then
1679 call batch_init(ffb, dpsi(:,1))
1680 call dmesh_batch_exchange_points(mesh, ffb, backward_map = .true.)
1681 call ffb%end()
1682 end if
1683 else
1684 call dmf_random(mesh, dpsi(:, 1), normalized = normalized)
1685 if (.not. state_kpt_is_local(st, ist, ik)) cycle
1686 end if
1687 do ip = 1, mesh%np
1688 zpsi(ip,1) = cmplx(dpsi(ip,1), m_zero, real64)
1689 end do
1690 call states_elec_set_state(st, mesh, ist, ik, zpsi)
1691 else
1692 if (st%randomization == par_independent) then
1693 call zmf_random(mesh, zpsi(:, 1), &
1694 pre_shift = mesh%pv%xlocal-1, &
1695 post_shift = mesh%pv%np_global - mesh%pv%xlocal - mesh%np + 1, &
1696 normalized = normalized)
1697 ! Ensures that the grid points are properly distributed in the domain parallel case
1698 if(mesh%parallel_in_domains) then
1699 call batch_init(ffb, zpsi(:,1))
1700 call zmesh_batch_exchange_points(mesh, ffb, backward_map = .true.)
1701 call ffb%end()
1702 end if
1703 else
1704 call zmf_random(mesh, zpsi(:, 1), normalized = normalized)
1705 if (.not. state_kpt_is_local(st, ist, ik)) cycle
1706 end if
1707 end if
1708 if (.not. state_kpt_is_local(st, ist, ik)) cycle
1709 ! In this case, the spinors are made of a spatial part times a vector [alpha beta]^T in
1710 ! spin space (i.e., same spatial part for each spin component). So (alpha, beta)
1711 ! determines the spin values. The values of (alpha, beta) can be be obtained
1712 ! with simple formulae from <Sx>, <Sy>, <Sz>.
1713 !
1714 ! Note that here we orthonormalize the orbital part. This ensures that the spinors
1715 ! are untouched later in the general orthonormalization, and therefore the spin values
1716 ! of each spinor remain the same.
1717 safe_allocate(zpsi2(1:mesh%np))
1718 do jst = ist_start, ist - 1
1719 call states_elec_get_state(st, mesh, 1, jst, ik, zpsi2)
1720 zdotp_tmp = zmf_dotp(mesh, zpsi(:, 1), zpsi2)
1721 call lalg_axpy(mesh%np, -zdotp_tmp, zpsi2, zpsi(:, 1))
1722 end do
1723 safe_deallocate_a(zpsi2)
1724
1725 call zmf_normalize(mesh, 1, zpsi)
1726 zpsi(1:mesh%np, 2) = zpsi(1:mesh%np, 1)
1727
1728 alpha = cmplx(sqrt(m_half + st%spin(3, ist, ik)), m_zero, real64)
1729 beta = cmplx(sqrt(m_one - abs(alpha)**2), m_zero, real64)
1730 if (abs(alpha) > m_epsilon) then
1731 beta = cmplx(st%spin(1, ist, ik) / abs(alpha), st%spin(2, ist, ik) / abs(alpha), real64)
1732 end if
1733 call lalg_scal(mesh%np, alpha, zpsi(:, 1))
1734 call lalg_scal(mesh%np, beta, zpsi(:, 2))
1735 call states_elec_set_state(st, mesh, ist, ik, zpsi)
1736 end do
1737 end do
1738 else
1739 do ik = ikpt_start, ikpt_end
1740 do ist = ist_start, ist_end
1741 do id = 1, st%d%dim
1742 if (st%randomization == par_independent) then
1743 call zmf_random(mesh, zpsi(:, id), &
1744 pre_shift = mesh%pv%xlocal-1, &
1745 post_shift = mesh%pv%np_global - mesh%pv%xlocal - mesh%np + 1, &
1746 normalized = .false.)
1747 ! Ensures that the grid points are properly distributed in the domain parallel case
1748 if(mesh%parallel_in_domains) then
1749 call batch_init(ffb, zpsi(:, id))
1750 call zmesh_batch_exchange_points(mesh, ffb, backward_map = .true.)
1751 call ffb%end()
1752 end if
1753 else
1754 call zmf_random(mesh, zpsi(:, id), normalized = .false.)
1755 end if
1756 end do
1757 ! We need to generate the wave functions even if not using them in order to be consistent
1758 ! with the random seed in parallel runs.
1759 if (.not. state_kpt_is_local(st, ist, ik)) cycle
1760 ! Note that mf_random normalizes each spin channel independently to 1.
1761 ! Therefore we need to renormalize the spinor:
1762 if (normalized_) call zmf_normalize(mesh, st%d%dim, zpsi)
1763 call states_elec_set_state(st, mesh, ist, ik, zpsi)
1764 end do
1765 end do
1766 end if
1767
1768 end select
1769
1770 safe_deallocate_a(dpsi)
1771 safe_deallocate_a(zpsi)
1772
1774 end subroutine states_elec_generate_random
1775
1776 ! ---------------------------------------------------------
1778 !
1779 subroutine states_elec_fermi(st, namespace, mesh, compute_spin)
1780 type(states_elec_t), intent(inout) :: st
1781 type(namespace_t), intent(in) :: namespace
1782 class(mesh_t), intent(in) :: mesh
1783 logical, optional, intent(in) :: compute_spin
1784
1786 integer :: ist, ik
1787 real(real64) :: charge
1788 complex(real64), allocatable :: zpsi(:, :)
1789
1790 push_sub(states_elec_fermi)
1791
1792 call smear_find_fermi_energy(st%smear, namespace, st%eigenval, st%occ, st%qtot, &
1793 st%nik, st%nst, st%kweights)
1794
1795 call smear_fill_occupations(st%smear, st%eigenval, st%occ, st%kweights, st%nik, st%nst)
1796
1797 ! check if everything is OK
1798 charge = m_zero
1799 do ist = 1, st%nst
1800 charge = charge + sum(st%occ(ist, 1:st%nik) * st%kweights(1:st%nik))
1801 end do
1802 if (abs(charge-st%qtot) > 1e-6_real64) then
1803 message(1) = 'Occupations do not integrate to total charge.'
1804 write(message(2), '(6x,f12.8,a,f12.8)') charge, ' != ', st%qtot
1805 call messages_warning(2, namespace=namespace)
1806 if (charge < m_epsilon) then
1807 message(1) = "There don't seem to be any electrons at all!"
1808 call messages_fatal(1, namespace=namespace)
1809 end if
1810 end if
1811
1812 if (st%d%ispin == spinors .and. optional_default(compute_spin,.true.)) then
1813 assert(states_are_complex(st))
1814
1815 st%spin(:,:,:) = m_zero
1816
1817 safe_allocate(zpsi(1:mesh%np, st%d%dim))
1818 do ik = st%d%kpt%start, st%d%kpt%end
1819 do ist = st%st_start, st%st_end
1820 call states_elec_get_state(st, mesh, ist, ik, zpsi)
1821 st%spin(1:3, ist, ik) = state_spin(mesh, zpsi)
1822 end do
1823 end do
1824 safe_deallocate_a(zpsi)
1825
1826 if (st%parallel_in_states .or. st%d%kpt%parallel) then
1827 call comm_allreduce(st%st_kpt_mpi_grp, st%spin)
1828 end if
1829
1830 end if
1831
1832 pop_sub(states_elec_fermi)
1833 end subroutine states_elec_fermi
1834
1835
1836 ! ---------------------------------------------------------
1838 !
1839 function states_elec_eigenvalues_sum(st, alt_eig) result(tot)
1840 type(states_elec_t), intent(in) :: st
1841 real(real64), optional, intent(in) :: alt_eig(st%st_start:, st%d%kpt%start:)
1843 real(real64) :: tot
1844
1845 integer :: ik
1846
1848
1849 tot = m_zero
1850 do ik = st%d%kpt%start, st%d%kpt%end
1851 if (present(alt_eig)) then
1852 tot = tot + st%kweights(ik) * sum(st%occ(st%st_start:st%st_end, ik) * &
1853 alt_eig(st%st_start:st%st_end, ik))
1854 else
1855 tot = tot + st%kweights(ik) * sum(st%occ(st%st_start:st%st_end, ik) * &
1856 st%eigenval(st%st_start:st%st_end, ik))
1857 end if
1858 end do
1859
1860 if (st%parallel_in_states .or. st%d%kpt%parallel) call comm_allreduce(st%st_kpt_mpi_grp, tot)
1861
1863 end function states_elec_eigenvalues_sum
1864
1865
1867 subroutine states_elec_distribute_nodes(st, namespace, mc)
1868 type(states_elec_t), intent(inout) :: st
1869 type(namespace_t), intent(in) :: namespace
1870 type(multicomm_t), intent(in) :: mc
1871
1872 logical :: default_scalapack_compatible
1873
1875
1876 ! TODO(Alex) Issue #820. This is superflous. These defaults are set in initialisation of
1877 ! states, and in the state distribution instance
1878 ! Defaults.
1879 st%node(:) = 0
1880 st%st_start = 1
1881 st%st_end = st%nst
1882 st%lnst = st%nst
1883 st%parallel_in_states = .false.
1884
1885 call mpi_grp_init(st%mpi_grp, mc%group_comm(p_strategy_states))
1886 call mpi_grp_init(st%system_grp, mc%master_comm)
1887 call mpi_grp_init(st%dom_st_kpt_mpi_grp, mc%dom_st_kpt_comm)
1888 call mpi_grp_init(st%dom_st_mpi_grp, mc%dom_st_comm)
1889 call mpi_grp_init(st%st_kpt_mpi_grp, mc%st_kpt_comm)
1890
1891 default_scalapack_compatible = calc_mode_par%scalapack_compat() .and. .not. st%d%kpt%parallel
1892
1893 !%Variable ScaLAPACKCompatible
1894 !%Type logical
1895 !%Section Execution::Parallelization
1896 !%Description
1897 !% Whether to use a layout for states parallelization which is compatible with ScaLAPACK.
1898 !% The default is yes for <tt>CalculationMode = gs, unocc, go</tt> without k-point parallelization,
1899 !% and no otherwise. (Setting to other than default is experimental.)
1900 !% The value must be yes if any ScaLAPACK routines are called in the course of the run;
1901 !% it must be set by hand for <tt>td</tt> with <tt>TDDynamics = bo</tt>.
1902 !% This variable has no effect unless you are using states parallelization and have linked ScaLAPACK.
1903 !% Note: currently, use of ScaLAPACK is not compatible with task parallelization (<i>i.e.</i> slaves).
1904 !%End
1905 call parse_variable(namespace, 'ScaLAPACKCompatible', default_scalapack_compatible, st%scalapack_compatible)
1906
1907#ifdef HAVE_SCALAPACK
1908 if (default_scalapack_compatible .neqv. st%scalapack_compatible) then
1909 call messages_experimental('Setting ScaLAPACKCompatible to other than default', namespace=namespace)
1910 end if
1911
1912 if (st%scalapack_compatible) then
1913 if (multicomm_have_slaves(mc)) then
1914 call messages_not_implemented("ScaLAPACK usage with task parallelization (slaves)", namespace=namespace)
1915 end if
1916 call blacs_proc_grid_init(st%dom_st_proc_grid, st%dom_st_mpi_grp)
1917 end if
1918#else
1919 st%scalapack_compatible = .false.
1920#endif
1921
1923
1924#ifdef HAVE_MPI
1925 call multicomm_create_all_pairs(st%mpi_grp, st%ap)
1926#endif
1927
1928 if (st%nst < st%mpi_grp%size) then
1929 message(1) = "Have more processors than necessary"
1930 write(message(2),'(i4,a,i4,a)') st%mpi_grp%size, " processors and ", st%nst, " states."
1931 call messages_fatal(2, namespace=namespace)
1932 end if
1933
1934 call distributed_init(st%dist, st%nst, st%mpi_grp%comm, "states", scalapack_compat = st%scalapack_compatible)
1935
1936 st%parallel_in_states = st%dist%parallel
1937
1938 ! TODO(Alex) Issue #820. Remove lnst, st_start, st_end and node, as they are all contained within dist
1939 st%st_start = st%dist%start
1940 st%st_end = st%dist%end
1941 st%lnst = st%dist%nlocal
1942 st%node(1:st%nst) = st%dist%node(1:st%nst)
1943
1944 end if
1945
1947
1949 end subroutine states_elec_distribute_nodes
1950
1951
1957 !
1958 subroutine states_elec_calc_quantities(gr, st, kpoints, nlcc, &
1959 kinetic_energy_density, paramagnetic_current, density_gradient, density_laplacian, &
1960 gi_kinetic_energy_density, st_end)
1961 type(grid_t), intent(in) :: gr
1962 type(states_elec_t), intent(in) :: st
1963 type(kpoints_t), intent(in) :: kpoints
1964 logical, intent(in) :: nlcc
1965 real(real64), contiguous, optional, target, intent(out) :: kinetic_energy_density(:,:)
1966 real(real64), contiguous, optional, target, intent(out) :: paramagnetic_current(:,:,:)
1967 real(real64), contiguous, optional, intent(out) :: density_gradient(:,:,:)
1968 real(real64), contiguous, optional, intent(out) :: density_laplacian(:,:)
1969 real(real64), contiguous, optional, intent(out) :: gi_kinetic_energy_density(:,:)
1970 integer, optional, intent(in) :: st_end
1971
1972 real(real64), pointer, contiguous :: jp(:, :, :)
1973 real(real64), pointer, contiguous :: tau(:, :)
1974 complex(real64), allocatable :: wf_psi(:,:), gwf_psi(:,:,:), wf_psi_conj(:,:), lwf_psi(:,:)
1975 real(real64), allocatable :: abs_wf_psi(:,:), abs_gwf_psi(:,:)
1976 complex(real64), allocatable :: psi_gpsi(:,:)
1977 complex(real64) :: c_tmp
1978 integer :: is, ik, ist, i_dim, st_dim, ii, st_end_
1979 real(real64) :: ww, kpoint(gr%der%dim)
1980 logical :: something_to_do
1981
1982 call profiling_in("STATES_CALC_QUANTITIES")
1983
1985
1986 st_end_ = min(st%st_end, optional_default(st_end, st%st_end))
1987
1988 something_to_do = present(kinetic_energy_density) .or. present(gi_kinetic_energy_density) .or. &
1989 present(paramagnetic_current) .or. present(density_gradient) .or. present(density_laplacian)
1990 assert(something_to_do)
1991
1992 safe_allocate( wf_psi(1:gr%np_part, 1:st%d%dim))
1993 safe_allocate( wf_psi_conj(1:gr%np_part, 1:st%d%dim))
1994 safe_allocate(gwf_psi(1:gr%np, 1:gr%der%dim, 1:st%d%dim))
1995 safe_allocate(abs_wf_psi(1:gr%np, 1:st%d%dim))
1996 safe_allocate(abs_gwf_psi(1:gr%np, 1:st%d%dim))
1997 safe_allocate(psi_gpsi(1:gr%np, 1:st%d%dim))
1998 if (present(density_laplacian)) then
1999 safe_allocate(lwf_psi(1:gr%np, 1:st%d%dim))
2000 end if
2001
2002 nullify(tau)
2003 if (present(kinetic_energy_density)) tau => kinetic_energy_density
2004
2005 nullify(jp)
2006 if (present(paramagnetic_current)) jp => paramagnetic_current
2007
2008 ! for the gauge-invariant kinetic energy density we need the
2009 ! current and the kinetic energy density
2010 if (present(gi_kinetic_energy_density)) then
2011 if (.not. present(paramagnetic_current) .and. states_are_complex(st)) then
2012 safe_allocate(jp(1:gr%np, 1:gr%der%dim, 1:st%d%nspin))
2013 end if
2014 if (.not. present(kinetic_energy_density)) then
2015 safe_allocate(tau(1:gr%np, 1:st%d%nspin))
2016 end if
2017 end if
2018
2019 if (associated(tau)) tau = m_zero
2020 if (associated(jp)) jp = m_zero
2021 if (present(density_gradient)) density_gradient(:,:,:) = m_zero
2022 if (present(density_laplacian)) density_laplacian(:,:) = m_zero
2023 if (present(gi_kinetic_energy_density)) gi_kinetic_energy_density = m_zero
2024
2025 do ik = st%d%kpt%start, st%d%kpt%end
2026
2027 kpoint(1:gr%der%dim) = kpoints%get_point(st%d%get_kpoint_index(ik))
2028 is = st%d%get_spin_index(ik)
2029
2030 do ist = st%st_start, st_end_
2031 ww = st%kweights(ik)*st%occ(ist, ik)
2032 if (abs(ww) <= m_epsilon) cycle
2033
2034 ! all calculations will be done with complex wavefunctions
2035 call states_elec_get_state(st, gr, ist, ik, wf_psi)
2036
2037 do st_dim = 1, st%d%dim
2038 call boundaries_set(gr%der%boundaries, gr, wf_psi(:, st_dim))
2039 end do
2040
2041 ! calculate gradient of the wavefunction
2042 do st_dim = 1, st%d%dim
2043 call zderivatives_grad(gr%der, wf_psi(:,st_dim), gwf_psi(:,:,st_dim), set_bc = .false.)
2044 end do
2045
2046 ! calculate the Laplacian of the wavefunction
2047 if (present(density_laplacian)) then
2048 do st_dim = 1, st%d%dim
2049 call zderivatives_lapl(gr%der, wf_psi(:,st_dim), lwf_psi(:,st_dim), ghost_update = .false., set_bc = .false.)
2050 end do
2051 end if
2052
2053 ! We precompute some quantites, to avoid to compute it many times
2054 wf_psi_conj(1:gr%np, 1:st%d%dim) = conjg(wf_psi(1:gr%np,1:st%d%dim))
2055 !$omp parallel do collapse(2)
2056 do st_dim = 1, st%d%dim
2057 do ii = 1, gr%np
2058 abs_wf_psi(ii, st_dim) = real(wf_psi_conj(ii, st_dim) * wf_psi(ii, st_dim), real64)
2059 end do
2060 end do
2061 !$omp end parallel do
2062
2063 if (present(density_laplacian)) then
2064 !$omp parallel do
2065 do ii = 1, gr%np
2066 density_laplacian(ii, is) = density_laplacian(ii, is) + &
2067 ww * m_two*real(wf_psi_conj(ii, 1) * lwf_psi(ii, 1), real64)
2068 end do
2069 !$omp end parallel do
2070 if (st%d%ispin == spinors) then
2071 !$omp parallel do
2072 do ii = 1, gr%np
2073 density_laplacian(ii, 2) = density_laplacian(ii, 2) + &
2074 ww * m_two*real(wf_psi_conj(ii, 2) * lwf_psi(ii, 2), real64)
2075 end do
2076 !$omp end parallel do
2077 !$omp parallel do private(c_tmp)
2078 do ii = 1, gr%np
2079 c_tmp = ww*(lwf_psi(ii, 1) * wf_psi_conj(ii, 2) + wf_psi(ii, 1) * conjg(lwf_psi(ii, 2)))
2080 density_laplacian(ii, 3) = density_laplacian(ii, 3) + real(c_tmp, real64)
2081 density_laplacian(ii, 4) = density_laplacian(ii, 4) + aimag(c_tmp)
2082 end do
2083 end if
2084 end if
2085
2086 if (associated(tau)) then
2087 call lalg_axpy(gr%np, ww * sum(kpoint(1:gr%der%dim)**2), abs_wf_psi(:, 1), tau(:, is))
2088 if (st%d%ispin == spinors) then
2089 call lalg_axpy(gr%np, ww * sum(kpoint(1:gr%der%dim)**2), abs_wf_psi(:, 2), tau(:, 2))
2090
2091 !$omp parallel do private(c_tmp)
2092 do ii = 1, gr%np
2093 c_tmp = ww * sum(kpoint(1:gr%der%dim)**2) * wf_psi(ii, 1) * wf_psi_conj(ii, 2)
2094 tau(ii, 3) = tau(ii, 3) + real(c_tmp, real64)
2095 tau(ii, 4) = tau(ii, 4) + aimag(c_tmp)
2096 end do
2097 end if
2098 end if
2099
2100 do i_dim = 1, gr%der%dim
2101
2102 ! We precompute some quantites, to avoid to compute them many times
2103 !$omp parallel private(st_dim, ii)
2104 do st_dim = 1, st%d%dim
2105 !$omp do
2106 do ii = 1, gr%np
2107 psi_gpsi(ii, st_dim) = wf_psi_conj(ii, st_dim) * gwf_psi(ii, i_dim, st_dim)
2108 end do
2109 end do
2110 do st_dim = 1, st%d%dim
2111 !$omp do
2112 do ii = 1, gr%np
2113 abs_gwf_psi(ii, st_dim) = real(conjg(gwf_psi(ii, i_dim, st_dim)) &
2114 * gwf_psi(ii, i_dim, st_dim), real64)
2115 end do
2116 end do
2117 !$omp end parallel
2118
2119 if (present(density_gradient)) then
2120 !$omp parallel do
2121 do ii = 1, gr%np
2122 density_gradient(ii, i_dim, is) = density_gradient(ii, i_dim, is) &
2123 + ww * m_two * real(psi_gpsi(ii, 1), real64)
2124 end do
2125 !$omp end parallel do
2126 if (st%d%ispin == spinors) then
2127 !$omp parallel do
2128 do ii = 1, gr%np
2129 density_gradient(ii, i_dim, 2) = density_gradient(ii, i_dim, 2) &
2130 + ww * m_two*real(psi_gpsi(ii, 2), real64)
2131 end do
2132 !$omp end parallel do
2133 !$omp parallel do private(c_tmp)
2134 do ii = 1, gr%np
2135 c_tmp = ww * (gwf_psi(ii, i_dim, 1) * wf_psi_conj(ii, 2) + wf_psi(ii, 1) * conjg(gwf_psi(ii, i_dim, 2)))
2136 density_gradient(ii, i_dim, 3) = density_gradient(ii, i_dim, 3) + real(c_tmp, real64)
2137 density_gradient(ii, i_dim, 4) = density_gradient(ii, i_dim, 4) + aimag(c_tmp)
2138 end do
2139 end if
2140 end if
2141
2142 if (present(density_laplacian)) then
2143 call lalg_axpy(gr%np, ww*m_two, abs_gwf_psi(:,1), density_laplacian(:,is))
2144 if (st%d%ispin == spinors) then
2145 call lalg_axpy(gr%np, ww*m_two, abs_gwf_psi(:,2), density_laplacian(:,2))
2146 !$omp parallel do private(c_tmp)
2147 do ii = 1, gr%np
2148 c_tmp = m_two * ww * gwf_psi(ii, i_dim, 1) * conjg(gwf_psi(ii, i_dim, 2))
2149 density_laplacian(ii, 3) = density_laplacian(ii, 3) + real(c_tmp, real64)
2150 density_laplacian(ii, 4) = density_laplacian(ii, 4) + aimag(c_tmp)
2151 end do
2152 end if
2153 end if
2154
2155 ! the expression for the paramagnetic current with spinors is
2156 ! j = ( jp(1) jp(3) + i jp(4) )
2157 ! (-jp(3) + i jp(4) jp(2) )
2158 if (associated(jp)) then
2159 if (.not.(states_are_real(st))) then
2160 !$omp parallel do
2161 do ii = 1, gr%np
2162 jp(ii, i_dim, is) = jp(ii, i_dim, is) + &
2163 ww*(aimag(psi_gpsi(ii, 1)) - abs_wf_psi(ii, 1)*kpoint(i_dim))
2164 end do
2165 !$omp end parallel do
2166 if (st%d%ispin == spinors) then
2167 !$omp parallel do
2168 do ii = 1, gr%np
2169 jp(ii, i_dim, 2) = jp(ii, i_dim, 2) + &
2170 ww*( aimag(psi_gpsi(ii, 2)) - abs_wf_psi(ii, 2)*kpoint(i_dim))
2171 end do
2172 !$omp end parallel do
2173 !$omp parallel do private(c_tmp)
2174 do ii = 1, gr%np
2175 c_tmp = -ww*m_half*m_zi*(gwf_psi(ii, i_dim, 1)*wf_psi_conj(ii, 2) - wf_psi(ii, 1)*conjg(gwf_psi(ii, i_dim, 2)) &
2176 - m_two * m_zi*wf_psi(ii, 1)*wf_psi_conj(ii, 2)*kpoint(i_dim))
2177 jp(ii, i_dim, 3) = jp(ii, i_dim, 3) + real(c_tmp, real64)
2178 jp(ii, i_dim, 4) = jp(ii, i_dim, 4) + aimag(c_tmp)
2179 end do
2180 end if
2181 end if
2182 end if
2183
2184 ! the expression for the paramagnetic current with spinors is
2185 ! t = ( tau(1) tau(3) + i tau(4) )
2186 ! ( tau(3) - i tau(4) tau(2) )
2187 if (associated(tau)) then
2188 !$omp parallel do
2189 do ii = 1, gr%np
2190 tau(ii, is) = tau(ii, is) + ww*(abs_gwf_psi(ii,1) &
2191 - m_two*aimag(psi_gpsi(ii, 1))*kpoint(i_dim))
2192 end do
2193 !$omp end parallel do
2194 if (st%d%ispin == spinors) then
2195 !$omp parallel do
2196 do ii = 1, gr%np
2197 tau(ii, 2) = tau(ii, 2) + ww*(abs_gwf_psi(ii, 2) &
2198 - m_two*aimag(psi_gpsi(ii, 2))*kpoint(i_dim))
2199 end do
2200 !$omp end parallel do
2201 !$omp parallel do private(c_tmp)
2202 do ii = 1, gr%np
2203 c_tmp = ww * ( gwf_psi(ii, i_dim, 1)*conjg(gwf_psi(ii, i_dim, 2)) &
2204 + m_zi * (gwf_psi(ii,i_dim,1)*wf_psi_conj(ii, 2) &
2205 - wf_psi(ii, 1)*conjg(gwf_psi(ii,i_dim,2)))*kpoint(i_dim))
2206 tau(ii, 3) = tau(ii, 3) + real(c_tmp, real64)
2207 tau(ii, 4) = tau(ii, 4) + aimag(c_tmp)
2208 end do
2209 end if
2210 end if
2211
2212 end do
2213
2214 end do
2215 end do
2216
2217 safe_deallocate_a(wf_psi_conj)
2218 safe_deallocate_a(abs_wf_psi)
2219 safe_deallocate_a(abs_gwf_psi)
2220 safe_deallocate_a(psi_gpsi)
2221
2222 if (.not. present(gi_kinetic_energy_density)) then
2223 if (.not. present(paramagnetic_current)) then
2224 safe_deallocate_p(jp)
2225 end if
2226 if (.not. present(kinetic_energy_density)) then
2227 safe_deallocate_p(tau)
2228 end if
2229 end if
2230
2231 if (st%parallel_in_states .or. st%d%kpt%parallel) call reduce_all(st%st_kpt_mpi_grp)
2232
2233 ! We have to symmetrize everything as they are calculated from the
2234 ! wavefunctions.
2235 ! This must be done before compute the gauge-invariant kinetic energy density
2236 if (st%symmetrize_density) then
2237 do is = 1, st%d%nspin
2238 if (associated(tau)) then
2239 call dgrid_symmetrize_scalar_field(gr, tau(:, is), suppress_warning = .true.)
2240 end if
2241
2242 if (present(density_laplacian)) then
2243 call dgrid_symmetrize_scalar_field(gr, density_laplacian(:, is), suppress_warning = .true.)
2244 end if
2245
2246 if (associated(jp)) then
2247 call dgrid_symmetrize_vector_field(gr, jp(:, :, is), suppress_warning = .true.)
2248 end if
2249
2250 if (present(density_gradient)) then
2251 call dgrid_symmetrize_vector_field(gr, density_gradient(:, :, is), suppress_warning = .true.)
2252 end if
2253 end do
2254 end if
2255
2256
2257 if (allocated(st%rho_core) .and. nlcc .and. (present(density_laplacian) .or. present(density_gradient))) then
2258 do ii = 1, gr%np
2259 wf_psi(ii, 1) = st%rho_core(ii)/st%d%spin_channels
2260 end do
2261
2262 call boundaries_set(gr%der%boundaries, gr, wf_psi(:, 1))
2263
2264 if (present(density_gradient)) then
2265 ! calculate gradient of the NLCC
2266 call zderivatives_grad(gr%der, wf_psi(:,1), gwf_psi(:,:,1), set_bc = .false.)
2267 do is = 1, st%d%spin_channels
2268 !$omp parallel do collapse(2)
2269 do i_dim = 1, gr%der%dim
2270 do ii = 1, gr%np
2271 density_gradient(ii, i_dim, is) = density_gradient(ii, i_dim, is) + &
2272 real(gwf_psi(ii, i_dim, 1), real64)
2273 end do
2274 end do
2275 !$omp end parallel do
2276 end do
2277 end if
2278
2279 ! calculate the Laplacian of the wavefunction
2280 if (present(density_laplacian)) then
2281 call zderivatives_lapl(gr%der, wf_psi(:,1), lwf_psi(:,1), set_bc = .false.)
2282
2283 !$omp parallel private(is, ii)
2284 do is = 1, st%d%spin_channels
2285 !$omp do
2286 do ii = 1, gr%np
2287 density_laplacian(ii, is) = density_laplacian(ii, is) + real(lwf_psi(ii, 1))
2288 end do
2289 end do
2290 !$omp end parallel
2291 end if
2292 end if
2293
2294 !If we freeze some of the orbitals, we need to had the contributions here
2295 !Only in the case we are not computing it
2296 if (allocated(st%frozen_tau) .and. .not. present(st_end) .and. associated(tau)) then
2297 call lalg_axpy(gr%np, st%d%nspin, m_one, st%frozen_tau, tau)
2298 end if
2299 if (allocated(st%frozen_gdens) .and. .not. present(st_end) .and. present(density_gradient)) then
2300 do is = 1, st%d%nspin
2301 call lalg_axpy(gr%np, gr%der%dim, m_one, st%frozen_gdens(:,:,is), density_gradient(:,:,is))
2302 end do
2303 end if
2304 if (allocated(st%frozen_ldens) .and. .not. present(st_end) .and. present(density_laplacian)) then
2305 call lalg_axpy(gr%np, st%d%nspin, m_one, st%frozen_ldens, density_laplacian)
2306 end if
2307
2308 safe_deallocate_a(wf_psi)
2309 safe_deallocate_a(gwf_psi)
2310 safe_deallocate_a(lwf_psi)
2311
2312
2313 !We compute the gauge-invariant kinetic energy density
2314 if (present(gi_kinetic_energy_density)) then
2315 do is = 1, st%d%nspin
2316 assert(associated(tau))
2317 gi_kinetic_energy_density(1:gr%np, is) = tau(1:gr%np, is)
2318 end do
2319 if (states_are_complex(st)) then
2320 assert(associated(jp))
2321 if (st%d%ispin /= spinors) then
2322 do is = 1, st%d%nspin
2323 !$omp parallel do
2324 do ii = 1, gr%np
2325 if (st%rho(ii, is) < 1.0e-7_real64) cycle
2326 gi_kinetic_energy_density(ii, is) = &
2327 gi_kinetic_energy_density(ii, is) - sum(jp(ii,1:gr%der%dim, is)**2)/st%rho(ii, is)
2328 end do
2329 end do
2330 else ! Note that this is only the U(1) part of the gauge-invariant KED
2331 !$omp parallel do
2332 do ii = 1, gr%np
2333 gi_kinetic_energy_density(ii, 1) = gi_kinetic_energy_density(ii, 1) &
2334 - sum(jp(ii,1:gr%der%dim, 1)**2)/(safe_tol(st%rho(ii, 1),m_epsilon))
2335 gi_kinetic_energy_density(ii, 2) = gi_kinetic_energy_density(ii, 2) &
2336 - sum(jp(ii,1:gr%der%dim, 2)**2)/(safe_tol(st%rho(ii, 2),m_epsilon))
2337 gi_kinetic_energy_density(ii, 3) = &
2338 gi_kinetic_energy_density(ii, 3) - sum(jp(ii,1:gr%der%dim, 3)**2 + jp(ii,1:gr%der%dim, 4)**2) &
2339 /(safe_tol((st%rho(ii, 3)**2 + st%rho(ii, 4)**2), m_epsilon))*st%rho(ii, 3)
2340 gi_kinetic_energy_density(ii, 4) = &
2341 gi_kinetic_energy_density(ii, 4) + sum(jp(ii,1:gr%der%dim, 3)**2 + jp(ii,1:gr%der%dim, 4)**2) &
2342 /(safe_tol((st%rho(ii, 3)**2 + st%rho(ii, 4)**2), m_epsilon))*st%rho(ii, 4)
2343 end do
2344 end if
2345 end if
2346 end if
2347
2348 if (.not. present(kinetic_energy_density)) then
2349 safe_deallocate_p(tau)
2350 end if
2351 if (.not. present(paramagnetic_current)) then
2352 safe_deallocate_p(jp)
2353 end if
2354
2355
2357
2358 call profiling_out("STATES_CALC_QUANTITIES")
2359
2360 contains
2361
2362 subroutine reduce_all(grp)
2363 type(mpi_grp_t), intent(in) :: grp
2364
2366
2367 if (associated(tau)) call comm_allreduce(grp, tau, dim = (/gr%np, st%d%nspin/))
2368
2369 if (present(density_laplacian)) call comm_allreduce(grp, density_laplacian, dim = (/gr%np, st%d%nspin/))
2370
2371 do is = 1, st%d%nspin
2372 if (associated(jp)) call comm_allreduce(grp, jp(:, :, is), dim = (/gr%np, gr%der%dim/))
2373
2374 if (present(density_gradient)) then
2375 call comm_allreduce(grp, density_gradient(:, :, is), dim = (/gr%np, gr%der%dim/))
2376 end if
2377 end do
2378
2380 end subroutine reduce_all
2381
2382 end subroutine states_elec_calc_quantities
2383
2384
2385 ! ---------------------------------------------------------
2387 !
2388 function state_spin(mesh, f1) result(spin)
2389 type(mesh_t), intent(in) :: mesh
2390 complex(real64), intent(in) :: f1(:, :)
2391 real(real64) :: spin(1:3)
2392
2393 complex(real64) :: z
2394
2395 push_sub(state_spin)
2396
2397 z = zmf_dotp(mesh, f1(:, 1) , f1(:, 2))
2398
2399 spin(1) = m_two*real(z, real64)
2400 spin(2) = m_two*aimag(z)
2401 spin(3) = zmf_nrm2(mesh, f1(:, 1))**2 - zmf_nrm2(mesh, f1(:, 2))**2
2402 spin = m_half*spin ! spin is half the sigma matrix.
2403
2404 pop_sub(state_spin)
2405 end function state_spin
2406
2407 ! ---------------------------------------------------------
2409 !
2410 logical function state_is_local(st, ist)
2411 type(states_elec_t), intent(in) :: st
2412 integer, intent(in) :: ist
2413
2414 push_sub(state_is_local)
2415
2416 state_is_local = ist >= st%st_start.and.ist <= st%st_end
2417
2418 pop_sub(state_is_local)
2419 end function state_is_local
2420
2421 ! ---------------------------------------------------------
2423 !
2424 logical function state_kpt_is_local(st, ist, ik)
2425 type(states_elec_t), intent(in) :: st
2426 integer, intent(in) :: ist
2427 integer, intent(in) :: ik
2428
2429 push_sub(state_kpt_is_local)
2430
2431 state_kpt_is_local = ist >= st%st_start .and. ist <= st%st_end .and. &
2432 ik >= st%d%kpt%start .and. ik <= st%d%kpt%end
2433
2434 pop_sub(state_kpt_is_local)
2435 end function state_kpt_is_local
2436
2437
2438 ! ---------------------------------------------------------
2440 real(real64) function states_elec_wfns_memory(st, mesh) result(memory)
2441 type(states_elec_t), intent(in) :: st
2442 class(mesh_t), intent(in) :: mesh
2443
2444 push_sub(states_elec_wfns_memory)
2445 memory = m_zero
2446
2447 ! orbitals
2448 memory = memory + real(storage_size(0.0_real64)/8, real64) * &
2449 real(mesh%np_part_global, real64) *st%d%dim * real(st%nst, real64) *st%d%kpt%nglobal
2450
2452 end function states_elec_wfns_memory
2453
2454 ! ---------------------------------------------------------
2456 !
2457 subroutine states_elec_pack(st, copy)
2458 class(states_elec_t), intent(inout) :: st
2459 logical, optional, intent(in) :: copy
2460
2461 integer :: iqn, ib
2462 integer(int64) :: max_mem, mem
2463
2464 push_sub(states_elec_pack)
2465
2466 ! nothing to do, already packed
2467 if (st%packed) then
2468 pop_sub(states_elec_pack)
2469 return
2470 end if
2472 st%packed = .true.
2473
2474 if (accel_is_enabled()) then
2475 max_mem = accel_global_memory_size()
2476
2477 if (st%gpu_states_mem > m_one) then
2478 max_mem = int(st%gpu_states_mem, int64)*(1024_8)**2
2479 else if (st%gpu_states_mem < 0.0_real64) then
2480 max_mem = max_mem + int(st%gpu_states_mem, int64)*(1024_8)**2
2481 else
2482 max_mem = int(st%gpu_states_mem*real(max_mem, real64) , int64)
2483 end if
2484 else
2485 max_mem = huge(max_mem)
2486 end if
2487
2488 mem = 0
2489 qnloop: do iqn = st%d%kpt%start, st%d%kpt%end
2490 do ib = st%group%block_start, st%group%block_end
2491
2492 mem = mem + st%group%psib(ib, iqn)%pack_total_size()
2494 if (mem > max_mem) then
2495 call messages_write('Not enough CL device memory to store all states simultaneously.', new_line = .true.)
2496 call messages_write('Only ')
2497 call messages_write(ib - st%group%block_start)
2498 call messages_write(' of ')
2499 call messages_write(st%group%block_end - st%group%block_start + 1)
2500 call messages_write(' blocks will be stored in device memory.', new_line = .true.)
2501 call messages_warning()
2502 exit qnloop
2503 end if
2504
2505 call st%group%psib(ib, iqn)%do_pack(copy)
2506 end do
2507 end do qnloop
2508
2509 pop_sub(states_elec_pack)
2510 end subroutine states_elec_pack
2511
2512 ! ------------------------------------------------------------
2514 !
2515 subroutine states_elec_unpack(st, copy)
2516 class(states_elec_t), intent(inout) :: st
2517 logical, optional, intent(in) :: copy
2518
2519 integer :: iqn, ib
2520
2521 push_sub(states_elec_unpack)
2522
2523 if (st%packed) then
2524 st%packed = .false.
2525
2526 do iqn = st%d%kpt%start, st%d%kpt%end
2527 do ib = st%group%block_start, st%group%block_end
2528 if (st%group%psib(ib, iqn)%is_packed()) call st%group%psib(ib, iqn)%do_unpack(copy)
2529 end do
2530 end do
2531 end if
2532
2533 pop_sub(states_elec_unpack)
2534 end subroutine states_elec_unpack
2535
2536 ! -----------------------------------------------------------
2538 !
2539 subroutine states_elec_write_info(st, namespace)
2540 class(states_elec_t), intent(in) :: st
2541 type(namespace_t), intent(in) :: namespace
2542
2543 push_sub(states_elec_write_info)
2544
2545 call messages_print_with_emphasis(msg="States", namespace=namespace)
2546
2547 write(message(1), '(a,f12.3)') 'Total electronic charge = ', st%qtot
2548 write(message(2), '(a,i8)') 'Number of states = ', st%nst
2549 write(message(3), '(a,i8)') 'States block-size = ', st%block_size
2550 call messages_info(3, namespace=namespace)
2551
2552 call messages_print_with_emphasis(namespace=namespace)
2553
2554 pop_sub(states_elec_write_info)
2555 end subroutine states_elec_write_info
2556
2558 subroutine states_elec_set_zero(st)
2559 class(states_elec_t), intent(inout) :: st
2560
2561 integer :: iqn, ib
2562
2563 push_sub(states_elec_set_zero)
2564
2565 do iqn = st%d%kpt%start, st%d%kpt%end
2566 do ib = st%group%block_start, st%group%block_end
2567 call batch_set_zero(st%group%psib(ib, iqn))
2568 end do
2569 end do
2570
2571 pop_sub(states_elec_set_zero)
2572 end subroutine states_elec_set_zero
2573
2574 ! ------------------------------------------------------------
2576 !
2577 integer pure function states_elec_block_min(st, ib) result(range)
2578 type(states_elec_t), intent(in) :: st
2579 integer, intent(in) :: ib
2580
2581 range = st%group%block_range(ib, 1)
2582 end function states_elec_block_min
2583
2584 ! ------------------------------------------------------------
2586 !
2587 integer pure function states_elec_block_max(st, ib) result(range)
2588 type(states_elec_t), intent(in) :: st
2589 integer, intent(in) :: ib
2590
2591 range = st%group%block_range(ib, 2)
2592 end function states_elec_block_max
2593
2594 ! ------------------------------------------------------------
2596 !
2597 integer pure function states_elec_block_size(st, ib) result(size)
2598 type(states_elec_t), intent(in) :: st
2599 integer, intent(in) :: ib
2600
2601 size = st%group%block_size(ib)
2602 end function states_elec_block_size
2603
2619 !
2620 subroutine occupied_states(st, namespace, ik, n_filled, n_partially_filled, n_half_filled, &
2621 filled, partially_filled, half_filled)
2622 type(states_elec_t), intent(in) :: st
2623 type(namespace_t), intent(in) :: namespace
2624 integer, intent(in) :: ik
2625 integer, intent(out) :: n_filled, n_partially_filled, n_half_filled
2626 integer, optional, intent(out) :: filled(:), partially_filled(:), half_filled(:)
2627
2628 integer :: ist
2629
2630 push_sub(occupied_states)
2631
2632 if (present(filled)) filled(:) = 0
2633 if (present(partially_filled)) partially_filled(:) = 0
2634 if (present(half_filled)) half_filled(:) = 0
2635 n_filled = 0
2636 n_partially_filled = 0
2637 n_half_filled = 0
2638
2639 select case (st%d%ispin)
2640 case (unpolarized)
2641 do ist = 1, st%nst
2642 if (abs(st%occ(ist, ik) - m_two) < m_min_occ) then
2643 n_filled = n_filled + 1
2644 if (present(filled)) filled(n_filled) = ist
2645 else if (abs(st%occ(ist, ik) - m_one) < m_min_occ) then
2646 n_half_filled = n_half_filled + 1
2647 if (present(half_filled)) half_filled(n_half_filled) = ist
2648 else if (st%occ(ist, ik) > m_min_occ) then
2649 n_partially_filled = n_partially_filled + 1
2650 if (present(partially_filled)) partially_filled(n_partially_filled) = ist
2651 else if (abs(st%occ(ist, ik)) > m_min_occ) then
2652 write(message(1),*) 'Internal error in occupied_states: Illegal occupation value ', st%occ(ist, ik)
2653 call messages_fatal(1, namespace=namespace)
2654 end if
2655 end do
2656 case (spin_polarized, spinors)
2657 do ist = 1, st%nst
2658 if (abs(st%occ(ist, ik)-m_one) < m_min_occ) then
2659 n_filled = n_filled + 1
2660 if (present(filled)) filled(n_filled) = ist
2661 else if (st%occ(ist, ik) > m_min_occ) then
2662 n_partially_filled = n_partially_filled + 1
2663 if (present(partially_filled)) partially_filled(n_partially_filled) = ist
2664 else if (abs(st%occ(ist, ik)) > m_min_occ) then
2665 write(message(1),*) 'Internal error in occupied_states: Illegal occupation value ', st%occ(ist, ik)
2666 call messages_fatal(1, namespace=namespace)
2667 end if
2668 end do
2669 end select
2671 pop_sub(occupied_states)
2672 end subroutine occupied_states
2673
2674
2676 subroutine kpoints_distribute(this, mc)
2677 type(states_elec_t), intent(inout) :: this
2678 type(multicomm_t), intent(in) :: mc
2679
2681 call distributed_init(this%d%kpt, this%nik, mc%group_comm(p_strategy_kpoints), "k-points")
2682
2683 pop_sub(kpoints_distribute)
2684 end subroutine kpoints_distribute
2685
2686
2687 ! TODO(Alex) Issue #824. Consider converting this to a function to returns `st_kpt_task`
2688 ! as this is only called in a couple of places, or package with the `st_kpt_mpi_grp` when split
2689 ! from st instance
2692 type(states_elec_t), intent(inout) :: st
2693
2695
2696 if (.not. allocated(st%st_kpt_task)) then
2697 safe_allocate(st%st_kpt_task(0:st%st_kpt_mpi_grp%size-1, 1:4))
2698 end if
2699
2700 st%st_kpt_task(0:st%st_kpt_mpi_grp%size-1, :) = 0
2701 st%st_kpt_task(st%st_kpt_mpi_grp%rank, :) = [st%st_start, st%st_end, st%d%kpt%start, st%d%kpt%end]
2702
2703 if (st%parallel_in_states .or. st%d%kpt%parallel) then
2704 call comm_allreduce(st%st_kpt_mpi_grp, st%st_kpt_task)
2705 end if
2706
2709
2710 ! ---------------------------------------------------------
2712 !
2713 subroutine states_elec_choose_kpoints(st, kpoints, namespace)
2714 type(states_elec_t), target, intent(inout) :: st
2715 type(kpoints_t), intent(in) :: kpoints
2716 type(namespace_t), intent(in) :: namespace
2717
2718 integer :: ik, iq
2719 type(states_elec_dim_t), pointer :: dd
2720
2721
2723
2724 dd => st%d
2725
2726 st%nik = kpoints_number(kpoints)
2727
2728 if (dd%ispin == spin_polarized) st%nik = 2*st%nik
2729
2730 safe_allocate(st%kweights(1:st%nik))
2731
2732 do iq = 1, st%nik
2733 ik = dd%get_kpoint_index(iq)
2734 st%kweights(iq) = kpoints%get_weight(ik)
2735 end do
2736
2737 if (debug%info) call print_kpoints_debug
2739
2740 contains
2741 subroutine print_kpoints_debug
2742 integer :: iunit
2743
2745
2746 call io_mkdir('debug/', namespace)
2747 iunit = io_open('debug/kpoints', namespace, action = 'write')
2748 call kpoints%write_info(iunit=iunit, absolute_coordinates = .true.)
2749 call io_close(iunit)
2750
2752 end subroutine print_kpoints_debug
2753
2754 end subroutine states_elec_choose_kpoints
2755
2760 !
2761 function states_elec_calculate_dipole(this, gr) result(dipole)
2762 class(states_elec_t), intent(in) :: this
2763 class(mesh_t), intent(in) :: gr
2764 real(real64) :: dipole(1:gr%box%dim)
2765
2766 integer :: ispin
2767 real(real64) :: e_dip(1:gr%box%dim, this%d%spin_channels)
2768
2770
2771 do ispin = 1, this%d%spin_channels
2772 call dmf_dipole(gr, this%rho(:, ispin), e_dip(:, ispin))
2773 end do
2775 dipole(:) = sum(e_dip(:, 1:this%d%spin_channels), 2) ! dipole moment <mu_el> = \sum_i -e <x_i>
2776
2778 end function states_elec_calculate_dipole
2779
2780
2781#include "undef.F90"
2782#include "real.F90"
2783#include "states_elec_inc.F90"
2784
2785#include "undef.F90"
2786#include "complex.F90"
2787#include "states_elec_inc.F90"
2788#include "undef.F90"
2789
2790end module states_elec_oct_m
2791
2792
2793!! Local Variables:
2794!! mode: f90
2795!! coding: utf-8
2796!! End:
initialize a batch with existing memory
Definition: batch.F90:277
constant times a vector plus a vector
Definition: lalg_basic.F90:173
scales a vector by a constant
Definition: lalg_basic.F90:159
Prints out to iunit a message in the form: ["InputVariable" = value] where "InputVariable" is given b...
Definition: messages.F90:182
subroutine, public accel_free_buffer(this, async)
Definition: accel.F90:1006
pure logical function, public accel_is_enabled()
Definition: accel.F90:403
type(accel_t), public accel
Definition: accel.F90:251
This module implements batches of mesh functions.
Definition: batch.F90:135
This module implements common operations on batches of mesh functions.
Definition: batch_ops.F90:118
This module provides the BLACS processor grid.
subroutine, public blacs_proc_grid_init(this, mpi_grp, procdim)
Initializes a blacs context from an MPI communicator with topological information.
subroutine, public blacs_proc_grid_end(this)
subroutine, public blacs_proc_grid_copy(cin, cout)
Module implementing boundary conditions in Octopus.
Definition: boundaries.F90:124
This module handles the calculation mode.
type(calc_mode_par_t), public calc_mode_par
Singleton instance of parallel calculation mode.
integer, parameter, public p_strategy_states
parallelization in states
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
subroutine, public zderivatives_grad(der, ff, op_ff, ghost_update, set_bc, to_cartesian)
apply the gradient to a mesh function
subroutine, public zderivatives_lapl(der, ff, op_ff, ghost_update, set_bc, factor)
apply the Laplacian to a mesh 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
subroutine, public distributed_copy(in, out)
Create a copy of a distributed instance.
integer, parameter, public unpolarized
Parameters...
integer, parameter, public spinors
integer, parameter, public spin_polarized
real(real64), parameter, public m_two
Definition: global.F90:202
real(real64), parameter, public m_zero
Definition: global.F90:200
real(real64), parameter, public m_fourth
Definition: global.F90:209
complex(real64), parameter, public m_zi
Definition: global.F90:214
real(real64), parameter, public m_epsilon
Definition: global.F90:216
type(conf_t), public conf
Global instance of Octopus configuration.
Definition: global.F90:190
real(real64), parameter, public m_half
Definition: global.F90:206
real(real64), parameter, public m_one
Definition: global.F90:201
This module implements the underlying real-space grid.
Definition: grid.F90:119
subroutine, public dgrid_symmetrize_vector_field(gr, field, suppress_warning)
Definition: grid.F90:688
subroutine, public dgrid_symmetrize_scalar_field(gr, field, suppress_warning)
Definition: grid.F90:662
Definition: io.F90:116
logical pure function, public kpoints_point_is_gamma(this, ik)
Definition: kpoints.F90:1720
System information (time, memory, sysname)
Definition: loct.F90:117
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:117
integer pure function, public pad_pow2(size)
create array size, which is padded to powers of 2
Definition: math.F90:846
This module defines functions over batches of mesh functions.
Definition: mesh_batch.F90:118
subroutine, public zmesh_batch_exchange_points(mesh, aa, forward_map, backward_map)
This functions exchanges points of a mesh according to a certain map. Two possible maps can be given....
subroutine, public dmesh_batch_exchange_points(mesh, aa, forward_map, backward_map)
This functions exchanges points of a mesh according to a certain map. Two possible maps can be given....
This module defines various routines, operating on mesh functions.
subroutine, public zmf_random(mesh, ff, pre_shift, post_shift, seed, normalized)
This subroutine fills a function with random values.
subroutine, public dmf_random(mesh, ff, pre_shift, post_shift, seed, normalized)
This subroutine fills a function with random values.
subroutine, public zmf_normalize(mesh, dim, psi, norm)
Normalize a mesh function psi.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:120
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1068
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:525
subroutine, public messages_obsolete_variable(namespace, name, rep)
Definition: messages.F90:1000
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:162
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:410
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:691
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1040
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:594
general module for modelmb particles
subroutine, public modelmb_particles_end(this)
subroutine, public modelmb_particles_init(this, namespace, space, nst)
==============================================================
subroutine, public modelmb_particles_copy(modelmb_out, modelmb_in)
subroutine mpi_grp_copy(mpi_grp_out, mpi_grp_in)
MPI_THREAD_FUNNELED allows for calls to MPI from an OMP region if the thread is the team master.
Definition: mpi.F90:383
type(mpi_comm), parameter, public mpi_comm_undefined
used to indicate a communicator has not been initialized
Definition: mpi.F90:138
subroutine mpi_grp_init(grp, comm)
Initialize MPI group instance.
Definition: mpi.F90:341
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:147
logical pure function, public multicomm_strategy_is_parallel(mc, level)
Definition: multicomm.F90:728
subroutine, public multicomm_all_pairs_copy(apout, apin)
Definition: multicomm.F90:251
logical pure function, public multicomm_have_slaves(this)
Definition: multicomm.F90:854
logical function, public parse_is_defined(namespace, name)
Definition: parser.F90:463
integer function, public parse_block(namespace, name, blk, check_varinfo_)
Definition: parser.F90:623
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
Definition: profiling.F90:631
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
Definition: profiling.F90:554
subroutine, public smear_find_fermi_energy(this, namespace, eigenvalues, occupations, qtot, nik, nst, kweights)
Definition: smear.F90:380
subroutine, public smear_fill_occupations(this, eigenvalues, occupations, kweights, nik, nst)
Definition: smear.F90:673
subroutine, public smear_copy(to, from)
Definition: smear.F90:349
integer, parameter, public smear_fixed_occ
Definition: smear.F90:176
subroutine, public smear_init(this, namespace, ispin, fixed_occ, integral_occs, kpoints)
Definition: smear.F90:194
logical pure function, public smear_is_semiconducting(this)
Definition: smear.F90:1042
subroutine, public states_set_complex(st)
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 states_elec_dim_copy(dout, din)
subroutine, public states_elec_dim_end(dim)
This module handles groups of electronic batches and their parallel distribution.
subroutine, public states_elec_group_copy(d, group_in, group_out, copy_data, special)
make a copy of a group
subroutine, public states_elec_group_end(this, d)
finalize the local blocks of wave functions and release local arrays
real(real64) function, public states_elec_wfns_memory(st, mesh)
return the memory usage of a states_elec_t object
integer pure function, public states_elec_block_max(st, ib)
return index of last state in block ib
subroutine zstates_elec_generate_random_vector(mesh, st, vector, normalized, reset_seed)
Generate a random vector.
subroutine, public states_elec_null(st)
subroutine, public states_elec_distribute_nodes(st, namespace, mc)
Distribute states over the processes for states parallelization.
subroutine, public states_elec_fermi(st, namespace, mesh, compute_spin)
calculate the Fermi level for the states in this object
logical function, public state_kpt_is_local(st, ist, ik)
check whether a given state (ist, ik) is on the local node
subroutine, public states_elec_calc_quantities(gr, st, kpoints, nlcc, kinetic_energy_density, paramagnetic_current, density_gradient, density_laplacian, gi_kinetic_energy_density, st_end)
calculated selected quantities
real(real64) function, dimension(1:gr%box%dim) states_elec_calculate_dipole(this, gr)
calculate the expectation value of the dipole moment of electrons
subroutine, public states_elec_densities_init(st, gr)
subroutine, public states_elec_end(st)
finalize the states_elec_t object
subroutine zstates_elec_get_state1(st, mesh, idim, ist, iqn, psi)
Write one component (dim) of a wave function into a state_elec_t object.
subroutine, public states_elec_deallocate_wfns(st)
Deallocates the KS wavefunctions defined within a states_elec_t structure.
subroutine, public states_elec_allocate_wfns(st, mesh, wfs_type, skip, packed)
Allocates the KS wavefunctions defined within a states_elec_t structure.
subroutine zstates_elec_get_points1(st, start_point, end_point, iqn, psi)
Returns the value of all the states for given k-point in the range of points [start_point:end_point].
subroutine states_elec_read_initial_occs(st, namespace, excess_charge, kpoints)
Reads from the input file the initial occupations, if the block "Occupations" is present....
subroutine zstates_elec_set_state1(st, mesh, idim, ist, iqn, psi)
get one dimension of local wave function for given k-point and states index from a states_elec_t obje...
real(real64) function, public states_elec_eigenvalues_sum(st, alt_eig)
function to calculate the eigenvalues sum using occupations as weights
integer, parameter, public par_independent
Method used to generate random states.
subroutine dstates_elec_generate_random_vector(mesh, st, vector, normalized, reset_seed)
Generate a random vector.
subroutine, public occupied_states(st, namespace, ik, n_filled, n_partially_filled, n_half_filled, filled, partially_filled, half_filled)
return information about occupied orbitals in many-body state
subroutine dstates_elec_get_state2(st, mesh, ist, iqn, psi)
Write a wave function into a state_elec_t object.
subroutine zstates_elec_set_state2(st, mesh, ist, iqn, psi)
get local wave function for given k-point and states index from a states_elec_t object
subroutine zstates_elec_get_state2(st, mesh, ist, iqn, psi)
Write a wave function into a state_elec_t object.
subroutine dstates_elec_get_points1(st, start_point, end_point, iqn, psi)
Returns the value of all the states for given k-point in the range of points [start_point:end_point].
integer pure function, public states_elec_block_size(st, ib)
return number of states in block ib
subroutine, public kpoints_distribute(this, mc)
distribute k-points over the nodes in the corresponding communicator
integer, parameter, public par_dependent
subroutine states_elec_pack(st, copy)
pack the batches in this states object
subroutine, public states_elec_choose_kpoints(st, kpoints, namespace)
double up k-points for SPIN_POLARIZED calculations
subroutine zstates_elec_get_state3(st, mesh, iqn, psi)
get local wave functions for given k-point from a states_elec_t object
logical function, public state_is_local(st, ist)
check whether a given state (ist) is on the local node
subroutine dstates_elec_set_state1(st, mesh, idim, ist, iqn, psi)
get one dimension of local wave function for given k-point and states index from a states_elec_t obje...
subroutine, public states_elec_exec_init(st, namespace, mc)
Further initializations.
subroutine dstates_elec_set_state4(st, mesh, psi)
set all local wave functions in a states_elec_t object
subroutine dstates_elec_set_state3(st, mesh, iqn, psi)
set local wave functions for given k-point in a states_elec_t object
subroutine states_elec_write_info(st, namespace)
write information about the states object
subroutine states_elec_init_block(st, mesh, verbose, skip, packed)
Initializes the data components in st that describe how the states are distributed in blocks:
real(real64) function, dimension(1:3) state_spin(mesh, f1)
calculate the spin vector for a spinor wave function f1
subroutine states_elec_kpoints_distribution(st)
Assign the start and end indices for states and kpoints, for "st_kpt_mpi_grp" communicator.
subroutine zstates_elec_get_state4(st, mesh, psi)
get all local wave functions from a states_elec_t object
subroutine, public states_elec_copy(stout, stin, exclude_wfns, exclude_eigenval, special)
make a (selective) copy of a states_elec_t object
subroutine, public states_elec_init(st, namespace, space, valence_charge, kpoints, calc_mode_id)
Initialize a new states_elec_t object.
subroutine, public states_elec_generate_random(st, mesh, kpoints, ist_start_, ist_end_, ikpt_start_, ikpt_end_, normalized)
randomize states
subroutine dstates_elec_get_state1(st, mesh, idim, ist, iqn, psi)
Write one component (dim) of a wave function into a state_elec_t object.
subroutine dstates_elec_set_state2(st, mesh, ist, iqn, psi)
get local wave function for given k-point and states index from a states_elec_t object
subroutine zstates_elec_set_state4(st, mesh, psi)
set all local wave functions in a states_elec_t object
subroutine states_elec_read_initial_spins(st, namespace)
Reads, if present, the "InitialSpins" block.
subroutine dstates_elec_get_state3(st, mesh, iqn, psi)
get local wave functions for given k-point from a states_elec_t object
subroutine dstates_elec_get_points2(st, start_point, end_point, psi)
Returns the value of all the states in the range of points [start_point:end_point].
integer pure function, public states_elec_block_min(st, ib)
return index of first state in block ib
subroutine states_elec_unpack(st, copy)
unpack the batches in this states object
subroutine, public states_elec_look(restart, nik, dim, nst, ierr)
Reads the 'states' file in the restart directory, and finds out the nik, dim, and nst contained in it...
subroutine dstates_elec_get_state4(st, mesh, psi)
get all local wave functions from a states_elec_t object
subroutine, public states_elec_allocate_current(st, space, mesh)
subroutine, public states_elec_set_zero(st)
Explicitly set all wave functions in the states to zero.
subroutine zstates_elec_set_state3(st, mesh, iqn, psi)
set local wave functions for given k-point in a states_elec_t object
subroutine zstates_elec_get_points2(st, start_point, end_point, psi)
Returns the value of all the states in the range of points [start_point:end_point].
type(type_t), parameter, public type_cmplx
Definition: types.F90:136
type(type_t), parameter, public type_float
Definition: types.F90:135
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:134
This module defines the unit system, used for input and output.
type(unit_t), public unit_megabytes
For large amounts of data (natural code units are bytes)
subroutine, public zwfs_elec_init(this, dim, st_start, st_end, np, ik, special, packed)
initialize an empty wfs_elec_t object
Definition: wfs_elec.F90:562
subroutine, public dwfs_elec_init(this, dim, st_start, st_end, np, ik, special, packed)
initialize an empty wfs_elec_t object
Definition: wfs_elec.F90:418
subroutine reduce_all(grp)
subroutine print_kpoints_debug
Class defining batches of mesh functions.
Definition: batch.F90:161
Distribution of N instances over mpi_grpsize processes, for the local rank mpi_grprank....
Extension of space that contains the knowledge of the spin dimension.
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:171
Describes mesh distribution to nodes.
Definition: mesh.F90:187
This is defined even when running serial.
Definition: mpi.F90:144
An all-pairs communication schedule for a given group.
Definition: multicomm.F90:240
Stores all communicators and groups.
Definition: multicomm.F90:208
abstract class for states
The states_elec_t class contains all electronic wave functions.
int true(void)