37 use,
intrinsic :: iso_fortran_env
109 real(real64) :: total(3,3) =
m_zero
110 real(real64) :: kinetic(3,3) =
m_zero
111 real(real64) :: Hartree(3,3) =
m_zero
112 real(real64) :: xc(3,3) =
m_zero
113 real(real64) :: xc_nlcc(3,3) =
m_zero
114 real(real64) :: ps_local(3,3) =
m_zero
116 real(real64) :: ion_ion(3,3) =
m_zero
117 real(real64) :: vdw(3,3) =
m_zero
118 real(real64) :: hubbard(3,3) =
m_zero
120 real(real64) :: kinetic_sumrule =
m_zero
121 real(real64) :: hartree_sumrule =
m_zero
136 type(states_elec_dim_t) :: d
139 logical :: only_userdef_istates
141 type(states_elec_group_t) :: group
142 integer :: block_size
146 logical :: pack_states
152 character(len=1024),
allocatable :: user_def_states(:,:,:)
158 real(real64),
allocatable :: rho(:,:)
159 real(real64),
allocatable :: rho_core(:)
162 type(accel_mem_t) :: buff_density
164 real(real64),
allocatable :: current(:, :, :)
165 real(real64),
allocatable :: current_para(:, :, :)
166 real(real64),
allocatable :: current_dia(:, :, :)
167 real(real64),
allocatable :: current_mag(:, :, :)
168 real(real64),
allocatable :: current_kpt(:,:,:)
173 real(real64),
allocatable :: frozen_rho(:, :)
174 real(real64),
allocatable :: frozen_tau(:, :)
175 real(real64),
allocatable :: frozen_gdens(:,:,:)
176 real(real64),
allocatable :: frozen_ldens(:,:)
178 logical :: uniform_occ
180 real(real64),
allocatable :: eigenval(:,:)
182 logical :: restart_fixed_occ
183 logical :: restart_reorder_occs
184 real(real64),
allocatable :: occ(:,:)
185 real(real64),
allocatable :: kweights(:)
188 logical :: fixed_spins
190 real(real64),
allocatable :: spin(:, :, :)
193 real(real64) :: val_charge
195 type(stress_t) :: stress_tensors
197 logical :: fromScratch
198 type(smear_t) :: smear
201 type(modelmb_particle_t) :: modelmbparticles
213 logical :: scalapack_compatible
214 logical :: parallel_in_states = .false.
218 integer :: st_start, st_end
219 integer,
allocatable :: node(:)
222 integer,
allocatable :: st_kpt_task(:,:)
225 logical :: symmetrize_density
226 integer :: randomization
227 integer :: orth_method = 0
229 real(real64) :: gpu_states_mem
241 integer,
public,
parameter :: &
285 real(real64),
intent(in) :: valence_charge
287 integer,
optional,
intent(in) :: calc_mode_id
289 real(real64) :: excess_charge, nempty_percent
290 integer :: nempty, ntot, default
291 integer :: nempty_conv, nempty_conv_default
292 logical :: force, adapt_for_chebyshev
293 real(real64),
parameter :: tol = 1e-13_real64
295 integer,
parameter :: rs_chebyshev = 12
296 integer(int64),
parameter :: chebyshev_compatible_modes(3) = &
297 [option__calculationmode__gs, option__calculationmode__go, option__calculationmode__unocc]
306 st%d%ispin = space%ispin
311 if (st%d%ispin /=
unpolarized .and. kpoints%use_time_reversal)
then
312 message(1) =
"Time reversal symmetry is only implemented for unpolarized spins."
313 message(2) =
"Use KPointsUseTimeReversal = no."
345 write(
message(1),
'(a,i5,a)')
"Input: '", ntot,
"' is not a valid value for TotalStates."
367 write(
message(1),
'(a,i5,a)')
"Input: '", nempty,
"' is not a valid value for ExtraStates."
368 message(2) =
'(0 <= ExtraStates)'
372 if (ntot > 0 .and. nempty > 0)
then
373 message(1) =
'You cannot set TotalStates and ExtraStates at the same time.'
388 if (nempty_percent < 0)
then
389 write(
message(1),
'(a,f8.6,a)')
"Input: '", nempty_percent, &
390 "' should be a percentage value x (where x is parts in hundred) larger or equal 0"
394 if (nempty > 0 .and. nempty_percent > 0)
then
395 message(1) =
'You cannot set ExtraStates and ExtraStatesInPercent at the same time.'
400 adapt_for_chebyshev = .false.
401 if (
present(calc_mode_id))
then
402 if (any(calc_mode_id == chebyshev_compatible_modes))
then
405 if (es == rs_chebyshev)
then
407 adapt_for_chebyshev = .
true.
411 if (adapt_for_chebyshev)
then
414 message(1) =
'Chebyshev filtering eigensolver detected. Setting ExtraStatesInPercent = 15'
422 st%val_charge = valence_charge
424 st%qtot = -(st%val_charge + excess_charge)
427 write(
message(1),
'(a,f12.6,a)')
'Total charge = ', st%qtot,
' < 0'
428 message(2) =
'Check Species and ExcessCharge.'
432 select case (st%d%ispin)
435 st%nst = nint(st%qtot/2)
436 if (st%nst*2 - st%qtot < -tol) st%nst = st%nst + 1
438 st%d%spin_channels = 1
441 st%nst = nint(st%qtot/2)
442 if (st%nst*2 - st%qtot < -tol) st%nst = st%nst + 1
444 st%d%spin_channels = 2
447 st%nst = nint(st%qtot)
448 if (st%nst - st%qtot < -tol) st%nst = st%nst + 1
450 st%d%spin_channels = 2
453 if (nempty_percent > 0)
then
454 nempty = ceiling(nempty_percent * st%nst / 100)
474 nempty_conv_default = nempty
475 if (adapt_for_chebyshev)
then
477 nempty_conv_default = min(int(0.8*nempty), nempty - 1)
479 call parse_variable(namespace,
'ExtraStatesToConverge', nempty_conv_default, nempty_conv)
480 if (nempty_conv < 0)
then
481 write(
message(1),
'(a,i5,a)')
"Input: '", nempty_conv,
"' is not a valid value for ExtraStatesToConverge."
482 message(2) =
'(0 <= ExtraStatesToConverge)'
486 if (nempty_conv > nempty)
then
488 message(1) =
'You cannot set ExtraStatesToConverge to a higher value than ExtraStates.'
489 message(2) =
'Capping ExtraStatesToConverge to ExtraStates.'
494 if (ntot < st%nst)
then
495 message(1) =
'TotalStates is smaller than the number of states required by the system.'
502 st%nst_conv = st%nst + nempty_conv
503 st%nst = st%nst + nempty
504 if (st%nst == 0)
then
505 message(1) =
"Cannot run with number of states = zero."
523 default =
accel%warp_size
532 call parse_variable(namespace,
'StatesBlockSize', default, st%block_size)
533 if (st%block_size < 1)
then
534 call messages_write(
"The variable 'StatesBlockSize' must be greater than 0.")
538 st%block_size = min(st%block_size, st%nst)
539 conf%target_states_block_size = st%block_size
541 safe_allocate(st%eigenval(1:st%nst, 1:st%nik))
542 st%eigenval = huge(st%eigenval)
546 if (.not. kpoints%gamma_only())
then
559 call parse_variable(namespace,
'OnlyUserDefinedInitialStates', .false., st%only_userdef_istates)
562 safe_allocate(st%occ (1:st%nst, 1:st%nik))
567 safe_allocate(st%user_def_states(1:st%d%dim, 1:st%nst, 1:st%nik))
569 st%user_def_states(1:st%d%dim, 1:st%nst, 1:st%nik) =
'undefined'
572 if (st%d%ispin ==
spinors)
then
573 safe_allocate(st%spin(1:3, 1:st%nst, 1:st%nik))
600 if (st%smear%photodop)
then
601 if (nempty == 0)
then
602 write(
message(1),
'(a,i5,a)')
"PhotoDoping requires to specify ExtraStates."
603 message(2) =
'(0 == ExtraStates)'
611 safe_allocate(st%node(1:st%nst))
612 st%node(1:st%nst) = 0
615 st%parallel_in_states = .false.
629 call parse_variable(namespace,
'SymmetrizeDensity', kpoints%use_symmetries, st%symmetrize_density)
659 integer,
intent(out) :: nik
660 integer,
intent(out) :: dim
661 integer,
intent(out) :: nst
662 integer,
intent(out) :: ierr
664 character(len=256) :: lines(3)
665 character(len=20) :: char
672 iunit = restart%open(
'states')
673 call restart%read(iunit, lines, 3, ierr)
675 read(lines(1), *) char, nst
676 read(lines(2), *) char, dim
677 read(lines(3), *) char, nik
679 call restart%close(iunit)
697 real(real64),
intent(in) :: excess_charge
700 integer :: ik, ist, ispin, nspin, ncols, nrows, el_per_state, icol, start_pos, spin_n
702 real(real64) :: rr, charge
703 logical :: integral_occs, unoccupied_states
704 real(real64),
allocatable :: read_occs(:, :)
705 real(real64) :: charge_in_block
720 call parse_variable(namespace,
'RestartFixedOccupations', .
true., st%restart_fixed_occ)
791 integral_occs = .
true.
793 occ_fix:
if (
parse_block(namespace,
'Occupations', blk) == 0)
then
795 st%fixed_occ = .
true.
798 if (ncols > st%nst)
then
803 if (nrows /= st%nik)
then
804 call messages_input_error(namespace,
"Occupations",
"Wrong number of rows in block Occupations.")
807 do ik = 1, st%nik - 1
810 "All rows in block Occupations must have the same number of columns.")
821 safe_allocate(read_occs(1:ncols, 1:st%nik))
827 charge_in_block = charge_in_block + read_occs(icol, ik) * st%kweights(ik)
832 select case (st%d%ispin)
841 start_pos = nint((st%qtot - charge_in_block)/spin_n)
843 if (start_pos + ncols > st%nst)
then
844 message(1) =
"To balance charge, the first column in block Occupations is taken to refer to state"
845 write(
message(2),
'(a,i6,a)')
"number ", start_pos,
" but there are too many columns for the number of states."
846 write(
message(3),
'(a,i6,a)')
"Solution: set ExtraStates = ", start_pos + ncols - st%nst
851 do ist = 1, start_pos
852 st%occ(ist, ik) = el_per_state
857 do ist = start_pos + 1, start_pos + ncols
858 st%occ(ist, ik) = read_occs(ist - start_pos, ik)
859 integral_occs = integral_occs .and. &
860 abs((st%occ(ist, ik) - el_per_state) * st%occ(ist, ik)) <=
m_epsilon
865 do ist = start_pos + ncols + 1, st%nst
872 safe_deallocate_a(read_occs)
875 st%fixed_occ = .false.
876 integral_occs = .false.
883 st%qtot = -(st%val_charge + excess_charge)
886 if (st%d%nspin == 2) nspin = 2
888 do ik = 1, st%nik, nspin
891 do ispin = ik, ik + nspin - 1
892 st%occ(ist, ispin) = min(rr, -(st%val_charge + excess_charge) - charge)
893 charge = charge + st%occ(ist, ispin)
912 if (st%fixed_occ)
then
913 call parse_variable(namespace,
'RestartReorderOccs', .false., st%restart_reorder_occs)
915 st%restart_reorder_occs = .false.
918 call smear_init(st%smear, namespace, st%d%ispin, st%fixed_occ, integral_occs, kpoints)
920 unoccupied_states = (st%d%ispin /=
spinors .and. st%nst*2 > st%qtot) .or. (st%d%ispin ==
spinors .and. st%nst > st%qtot)
923 if (.not. unoccupied_states)
then
924 call messages_write(
'Smearing needs unoccupied states (via ExtraStates or TotalStates) to be useful.')
932 charge = charge + sum(st%occ(ist, 1:st%nik) * st%kweights(1:st%nik))
934 if (abs(charge - st%qtot) > 1e-6_real64)
then
935 message(1) =
"Initial occupations do not integrate to total charge."
936 write(
message(2),
'(6x,f12.6,a,f12.6)') charge,
' != ', st%qtot
958 integer :: i, j, nrows
963 st%fixed_spins = .false.
964 if (st%d%ispin /=
spinors)
then
1003 spin_fix:
if (
parse_block(namespace,
'InitialSpins', blk) == 0)
then
1005 if (nrows < st%nst)
then
1006 message(1) =
"Please specify one row for each state in InitialSpins, also for extra states."
1016 st%fixed_spins = .
true.
1018 st%spin(:, :, i) = st%spin(:, :, 1)
1031 class(
mesh_t),
intent(in) :: mesh
1032 type(
type_t),
optional,
intent(in) :: wfs_type
1033 logical,
optional,
intent(in) :: skip(:)
1034 logical,
optional,
intent(in) :: packed
1038 if (
present(wfs_type))
then
1040 st%wfs_type = wfs_type
1068 type(
mesh_t),
intent(in) :: mesh
1069 logical,
optional,
intent(in) :: verbose
1070 logical,
optional,
intent(in) :: skip(:)
1071 logical,
optional,
intent(in) :: packed
1073 integer :: ib, iqn, ist, istmin, istmax
1074 logical :: same_node, verbose_, packed_
1075 integer,
allocatable :: bstart(:), bend(:)
1079 safe_allocate(bstart(1:st%nst))
1080 safe_allocate(bend(1:st%nst))
1081 safe_allocate(st%group%iblock(1:st%nst))
1090 if (
present(skip))
then
1092 if (.not. skip(ist))
then
1100 if (
present(skip))
then
1101 do ist = st%nst, istmin, -1
1102 if (.not. skip(ist))
then
1109 if (
present(skip) .and. verbose_)
then
1119 st%group%nblocks = 0
1121 do ist = istmin, istmax
1124 st%group%iblock(ist) = st%group%nblocks + 1
1127 if (st%parallel_in_states .and. ist /= istmax)
then
1130 same_node = (st%node(ist + 1) == st%node(ist))
1133 if (ib == st%block_size .or. ist == istmax .or. .not. same_node)
then
1135 st%group%nblocks = st%group%nblocks + 1
1136 bend(st%group%nblocks) = ist
1137 if (ist /= istmax) bstart(st%group%nblocks + 1) = ist + 1
1141 safe_allocate(st%group%psib(1:st%group%nblocks, st%d%kpt%start:st%d%kpt%end))
1143 safe_allocate(st%group%block_is_local(1:st%group%nblocks, 1:st%nik))
1144 st%group%block_is_local = .false.
1145 st%group%block_start = -1
1146 st%group%block_end = -2
1148 do ib = 1, st%group%nblocks
1149 if (bstart(ib) >= st%st_start .and. bend(ib) <= st%st_end)
then
1150 if (st%group%block_start == -1) st%group%block_start = ib
1151 st%group%block_end = ib
1152 do iqn = st%d%kpt%start, st%d%kpt%end
1153 st%group%block_is_local(ib, iqn) = .
true.
1156 call dwfs_elec_init(st%group%psib(ib, iqn), st%d%dim, bstart(ib), bend(ib), mesh%np_part, iqn, &
1157 special=.
true., packed=packed_)
1159 call zwfs_elec_init(st%group%psib(ib, iqn), st%d%dim, bstart(ib), bend(ib), mesh%np_part, iqn, &
1160 special=.
true., packed=packed_)
1167 safe_allocate(st%group%block_range(1:st%group%nblocks, 1:2))
1168 safe_allocate(st%group%block_size(1:st%group%nblocks))
1170 st%group%block_range(1:st%group%nblocks, 1) = bstart(1:st%group%nblocks)
1171 st%group%block_range(1:st%group%nblocks, 2) = bend(1:st%group%nblocks)
1172 st%group%block_size(1:st%group%nblocks) = bend(1:st%group%nblocks) - bstart(1:st%group%nblocks) + 1
1174 st%group%block_initialized = .
true.
1176 safe_allocate(st%group%block_node(1:st%group%nblocks, 1:st%nik))
1177 st%group%block_node = 0
1179 assert(
allocated(st%node))
1180 assert(all(st%node >= 0) .and. all(st%node < st%mpi_grp%size))
1182 do iqn = st%d%kpt%start, st%d%kpt%end
1183 do ib = st%group%block_start, st%group%block_end
1184 st%group%block_node(ib, iqn) = st%st_kpt_mpi_grp%rank
1193 do ib = 1, st%group%nblocks
1199 if (st%group%block_size(ib) > 0)
then
1229 safe_deallocate_a(bstart)
1230 safe_deallocate_a(bend)
1255 type(
grid_t),
intent(in) :: gr
1257 real(real64) :: fsize
1261 safe_allocate(st%rho(1:gr%np_part, 1:st%d%nspin))
1264 fsize = gr%np_part*8.0_real64*st%block_size
1276 class(
space_t),
intent(in) :: space
1277 class(
mesh_t),
intent(in) :: mesh
1281 if (.not.
allocated(st%current))
then
1282 safe_allocate(st%current(1:mesh%np_part, 1:space%dim, 1:st%d%nspin))
1286 if (.not.
allocated(st%current_para))
then
1287 safe_allocate(st%current_para(1:mesh%np_part, 1:space%dim, 1:st%d%nspin))
1291 if (.not.
allocated(st%current_dia))
then
1292 safe_allocate(st%current_dia(1:mesh%np_part, 1:space%dim, 1:st%d%nspin))
1296 if (.not.
allocated(st%current_mag))
then
1297 safe_allocate(st%current_mag(1:mesh%np_part, 1:space%dim, 1:st%d%nspin))
1301 if (.not.
allocated(st%current_kpt))
then
1302 safe_allocate(st%current_kpt(1:mesh%np,1:space%dim,st%d%kpt%start:st%d%kpt%end))
1381 default = option__statesorthogonalization__cholesky_serial
1382#ifdef HAVE_SCALAPACK
1384 default = option__statesorthogonalization__cholesky_parallel
1388 call parse_variable(namespace,
'StatesOrthogonalization', default, st%orth_method)
1409 call parse_variable(namespace,
'StatesDeviceMemory', -512.0_real64, st%gpu_states_mem)
1419 subroutine states_elec_copy(stout, stin, exclude_wfns, exclude_eigenval, special, dest_type, copy_data)
1422 logical,
optional,
intent(in) :: exclude_wfns
1423 logical,
optional,
intent(in) :: exclude_eigenval
1424 logical,
optional,
intent(in) :: special
1425 type(
type_t),
optional,
intent(in) :: dest_type
1427 logical,
optional,
intent(in) :: copy_data
1431 logical :: exclude_wfns_
1440 safe_allocate_source_a(stout%kweights, stin%kweights)
1441 stout%nik = stin%nik
1445 stout%wfs_type = stin%wfs_type
1446 if (
present(dest_type))
then
1447 stout%wfs_type = dest_type
1449 stout%nst = stin%nst
1450 stout%block_size = stin%block_size
1451 stout%orth_method = stin%orth_method
1453 stout%gpu_states_mem = stin%gpu_states_mem
1454 stout%pack_states = stin%pack_states
1456 stout%only_userdef_istates = stin%only_userdef_istates
1458 if (.not. exclude_wfns_)
then
1459 safe_allocate_source_a(stout%rho, stin%rho)
1462 stout%uniform_occ = stin%uniform_occ
1465 safe_allocate_source_a(stout%eigenval, stin%eigenval)
1466 safe_allocate_source_a(stout%occ, stin%occ)
1467 safe_allocate_source_a(stout%spin, stin%spin)
1472 stout%group%nblocks = stin%group%nblocks
1474 safe_allocate_source_a(stout%user_def_states, stin%user_def_states)
1476 safe_allocate_source_a(stout%current, stin%current)
1477 safe_allocate_source_a(stout%current_kpt, stin%current_kpt)
1478 safe_allocate_source_a(stout%rho_core, stin%rho_core)
1479 safe_allocate_source_a(stout%frozen_rho, stin%frozen_rho)
1480 safe_allocate_source_a(stout%frozen_tau, stin%frozen_tau)
1481 safe_allocate_source_a(stout%frozen_gdens, stin%frozen_gdens)
1482 safe_allocate_source_a(stout%frozen_ldens, stin%frozen_ldens)
1484 stout%fixed_occ = stin%fixed_occ
1485 stout%restart_fixed_occ = stin%restart_fixed_occ
1487 stout%fixed_spins = stin%fixed_spins
1489 stout%qtot = stin%qtot
1490 stout%val_charge = stin%val_charge
1494 stout%parallel_in_states = stin%parallel_in_states
1497 call mpi_grp_copy(stout%dom_st_kpt_mpi_grp, stin%dom_st_kpt_mpi_grp)
1498 call mpi_grp_copy(stout%st_kpt_mpi_grp, stin%st_kpt_mpi_grp)
1499 call mpi_grp_copy(stout%dom_st_mpi_grp, stin%dom_st_mpi_grp)
1500 safe_allocate_source_a(stout%node, stin%node)
1501 safe_allocate_source_a(stout%st_kpt_task, stin%st_kpt_task)
1503#ifdef HAVE_SCALAPACK
1509 stout%scalapack_compatible = stin%scalapack_compatible
1511 stout%lnst = stin%lnst
1512 stout%st_start = stin%st_start
1513 stout%st_end = stin%st_end
1517 stout%symmetrize_density = stin%symmetrize_density
1520 copy_data=copy_data, special=special, dest_type=dest_type)
1522 stout%packed = stin%packed
1524 stout%randomization = stin%randomization
1545 safe_deallocate_a(st%user_def_states)
1547 safe_deallocate_a(st%rho)
1548 safe_deallocate_a(st%eigenval)
1550 safe_deallocate_a(st%current)
1551 safe_deallocate_a(st%current_para)
1552 safe_deallocate_a(st%current_dia)
1553 safe_deallocate_a(st%current_mag)
1554 safe_deallocate_a(st%current_kpt)
1555 safe_deallocate_a(st%rho_core)
1556 safe_deallocate_a(st%frozen_rho)
1557 safe_deallocate_a(st%frozen_tau)
1558 safe_deallocate_a(st%frozen_gdens)
1559 safe_deallocate_a(st%frozen_ldens)
1560 safe_deallocate_a(st%occ)
1561 safe_deallocate_a(st%spin)
1562 safe_deallocate_a(st%kweights)
1565#ifdef HAVE_SCALAPACK
1571 safe_deallocate_a(st%node)
1572 safe_deallocate_a(st%st_kpt_task)
1574 if (st%parallel_in_states)
then
1575 safe_deallocate_a(st%ap%schedule)
1589 class(
mesh_t),
intent(in) :: mesh
1591 integer,
optional,
intent(in) :: ist_start_
1592 integer,
optional,
intent(in) :: ist_end_
1593 integer,
optional,
intent(in) :: ikpt_start_
1594 integer,
optional,
intent(in) :: ikpt_end_
1595 logical,
optional,
intent(in) :: normalized
1598 integer :: ist, ik, id, ist_start, ist_end, jst, ikpt_start, ikpt_end
1599 complex(real64) :: alpha, beta, zdotp_tmp
1600 real(real64),
allocatable :: dpsi(:, :)
1601 complex(real64),
allocatable :: zpsi(:, :), zpsi2(:)
1602 integer :: ikpoint, ip
1605 logical :: normalized_
1616 safe_allocate(dpsi(1:mesh%np, 1:st%d%dim))
1618 safe_allocate(zpsi(1:mesh%np, 1:st%d%dim))
1621 select case (st%d%ispin)
1624 do ik = ikpt_start, ikpt_end
1625 ikpoint = st%d%get_kpoint_index(ik)
1626 do ist = ist_start, ist_end
1630 pre_shift = mesh%pv%xlocal-1, &
1631 post_shift = mesh%pv%np_global - mesh%pv%xlocal - mesh%np + 1, &
1632 normalized = normalized)
1634 if(mesh%parallel_in_domains)
then
1640 call dmf_random(mesh, dpsi(:, 1), normalized = normalized)
1645 zpsi(ip,1) = cmplx(dpsi(ip,1),
m_zero, real64)
1654 pre_shift = mesh%pv%xlocal-1, &
1655 post_shift = mesh%pv%np_global - mesh%pv%xlocal - mesh%np + 1, &
1656 normalized = normalized)
1658 if(mesh%parallel_in_domains)
then
1664 call zmf_random(mesh, zpsi(:, 1), normalized = normalized)
1676 if (st%fixed_spins)
then
1678 do ik = ikpt_start, ikpt_end
1679 ikpoint = st%d%get_kpoint_index(ik)
1680 do ist = ist_start, ist_end
1684 pre_shift = mesh%pv%xlocal-1, &
1685 post_shift = mesh%pv%np_global - mesh%pv%xlocal - mesh%np + 1, &
1686 normalized = normalized)
1688 if(mesh%parallel_in_domains)
then
1694 call dmf_random(mesh, dpsi(:, 1), normalized = normalized)
1698 zpsi(ip,1) = cmplx(dpsi(ip,1),
m_zero, real64)
1704 pre_shift = mesh%pv%xlocal-1, &
1705 post_shift = mesh%pv%np_global - mesh%pv%xlocal - mesh%np + 1, &
1706 normalized = normalized)
1708 if(mesh%parallel_in_domains)
then
1714 call zmf_random(mesh, zpsi(:, 1), normalized = normalized)
1727 safe_allocate(zpsi2(1:mesh%np))
1728 do jst = ist_start, ist - 1
1730 zdotp_tmp =
zmf_dotp(mesh, zpsi(:, 1), zpsi2)
1731 call lalg_axpy(mesh%np, -zdotp_tmp, zpsi2, zpsi(:, 1))
1733 safe_deallocate_a(zpsi2)
1736 zpsi(1:mesh%np, 2) = zpsi(1:mesh%np, 1)
1741 beta = cmplx(st%spin(1, ist, ik) / abs(alpha), st%spin(2, ist, ik) / abs(alpha), real64)
1743 call lalg_scal(mesh%np, alpha, zpsi(:, 1))
1744 call lalg_scal(mesh%np, beta, zpsi(:, 2))
1749 do ik = ikpt_start, ikpt_end
1750 do ist = ist_start, ist_end
1754 pre_shift = mesh%pv%xlocal-1, &
1755 post_shift = mesh%pv%np_global - mesh%pv%xlocal - mesh%np + 1, &
1756 normalized = .false.)
1758 if(mesh%parallel_in_domains)
then
1764 call zmf_random(mesh, zpsi(:, id), normalized = .false.)
1780 safe_deallocate_a(dpsi)
1781 safe_deallocate_a(zpsi)
1792 class(
mesh_t),
intent(in) :: mesh
1793 logical,
optional,
intent(in) :: compute_spin
1797 real(real64) :: charge
1798 complex(real64),
allocatable :: zpsi(:, :)
1803 st%nik, st%nst, st%kweights)
1810 charge = charge + sum(st%occ(ist, 1:st%nik) * st%kweights(1:st%nik))
1812 if (abs(charge-st%qtot) > 1e-6_real64)
then
1813 message(1) =
'Occupations do not integrate to total charge.'
1814 write(
message(2),
'(6x,f12.8,a,f12.8)') charge,
' != ', st%qtot
1817 message(1) =
"There don't seem to be any electrons at all!"
1827 safe_allocate(zpsi(1:mesh%np, st%d%dim))
1828 do ik = st%d%kpt%start, st%d%kpt%end
1829 do ist = st%st_start, st%st_end
1831 st%spin(1:3, ist, ik) =
state_spin(mesh, zpsi)
1834 safe_deallocate_a(zpsi)
1836 if (st%parallel_in_states .or. st%d%kpt%parallel)
then
1851 real(real64),
optional,
intent(in) :: alt_eig(st%st_start:, st%d%kpt%start:)
1860 do ik = st%d%kpt%start, st%d%kpt%end
1861 if (
present(alt_eig))
then
1862 tot = tot + st%kweights(ik) * sum(st%occ(st%st_start:st%st_end, ik) * &
1863 alt_eig(st%st_start:st%st_end, ik))
1865 tot = tot + st%kweights(ik) * sum(st%occ(st%st_start:st%st_end, ik) * &
1866 st%eigenval(st%st_start:st%st_end, ik))
1870 if (st%parallel_in_states .or. st%d%kpt%parallel)
call comm_allreduce(st%st_kpt_mpi_grp, tot)
1882 logical :: default_scalapack_compatible
1893 st%parallel_in_states = .false.
1897 call mpi_grp_init(st%dom_st_kpt_mpi_grp, mc%dom_st_kpt_comm)
1901 default_scalapack_compatible =
calc_mode_par%scalapack_compat() .and. .not. st%d%kpt%parallel
1915 call parse_variable(namespace,
'ScaLAPACKCompatible', default_scalapack_compatible, st%scalapack_compatible)
1917#ifdef HAVE_SCALAPACK
1918 if (default_scalapack_compatible .neqv. st%scalapack_compatible)
then
1919 call messages_experimental(
'Setting ScaLAPACKCompatible to other than default', namespace=namespace)
1922 if (st%scalapack_compatible)
then
1929 st%scalapack_compatible = .false.
1935 call multicomm_create_all_pairs(st%mpi_grp, st%ap)
1938 if (st%nst < st%mpi_grp%size)
then
1939 message(1) =
"Have more processors than necessary"
1940 write(
message(2),
'(i4,a,i4,a)') st%mpi_grp%size,
" processors and ", st%nst,
" states."
1944 call distributed_init(st%dist, st%nst, st%mpi_grp%comm,
"states", scalapack_compat = st%scalapack_compatible)
1946 st%parallel_in_states = st%dist%parallel
1949 st%st_start = st%dist%start
1950 st%st_end = st%dist%end
1951 st%lnst = st%dist%nlocal()
1952 st%node(1:st%nst) = st%dist%process(1:st%nst)
1969 kinetic_energy_density, paramagnetic_current, density_gradient, density_laplacian, &
1970 gi_kinetic_energy_density, st_end)
1971 type(
grid_t),
intent(in) :: gr
1974 logical,
intent(in) :: nlcc
1975 real(real64),
contiguous,
optional,
target,
intent(out) :: kinetic_energy_density(:,:)
1976 real(real64),
contiguous,
optional,
target,
intent(out) :: paramagnetic_current(:,:,:)
1977 real(real64),
contiguous,
optional,
intent(out) :: density_gradient(:,:,:)
1978 real(real64),
contiguous,
optional,
intent(out) :: density_laplacian(:,:)
1979 real(real64),
contiguous,
optional,
intent(out) :: gi_kinetic_energy_density(:,:)
1980 integer,
optional,
intent(in) :: st_end
1982 real(real64),
pointer,
contiguous :: jp(:, :, :)
1983 real(real64),
pointer,
contiguous :: tau(:, :)
1984 complex(real64),
allocatable :: wf_psi(:,:), gwf_psi(:,:,:), wf_psi_conj(:,:), lwf_psi(:,:)
1985 real(real64),
allocatable :: abs_wf_psi(:,:), abs_gwf_psi(:,:)
1986 complex(real64),
allocatable :: psi_gpsi(:,:)
1987 complex(real64) :: c_tmp
1988 integer :: is, ik, ist, i_dim, st_dim, ii, st_end_
1989 real(real64) :: ww, kpoint(gr%der%dim)
1990 logical :: something_to_do
1998 something_to_do =
present(kinetic_energy_density) .or.
present(gi_kinetic_energy_density) .or. &
1999 present(paramagnetic_current) .or.
present(density_gradient) .or.
present(density_laplacian)
2000 assert(something_to_do)
2002 safe_allocate( wf_psi(1:gr%np_part, 1:st%d%dim))
2003 safe_allocate( wf_psi_conj(1:gr%np_part, 1:st%d%dim))
2004 safe_allocate(gwf_psi(1:gr%np, 1:gr%der%dim, 1:st%d%dim))
2005 safe_allocate(abs_wf_psi(1:gr%np, 1:st%d%dim))
2006 safe_allocate(abs_gwf_psi(1:gr%np, 1:st%d%dim))
2007 safe_allocate(psi_gpsi(1:gr%np, 1:st%d%dim))
2008 if (
present(density_laplacian))
then
2009 safe_allocate(lwf_psi(1:gr%np, 1:st%d%dim))
2013 if (
present(kinetic_energy_density)) tau => kinetic_energy_density
2016 if (
present(paramagnetic_current)) jp => paramagnetic_current
2020 if (
present(gi_kinetic_energy_density))
then
2022 safe_allocate(jp(1:gr%np, 1:gr%der%dim, 1:st%d%nspin))
2024 if (.not.
present(kinetic_energy_density))
then
2025 safe_allocate(tau(1:gr%np, 1:st%d%nspin))
2029 if (
associated(tau)) tau =
m_zero
2030 if (
associated(jp)) jp =
m_zero
2031 if (
present(density_gradient)) density_gradient(:,:,:) =
m_zero
2032 if (
present(density_laplacian)) density_laplacian(:,:) =
m_zero
2033 if (
present(gi_kinetic_energy_density)) gi_kinetic_energy_density =
m_zero
2035 do ik = st%d%kpt%start, st%d%kpt%end
2037 kpoint(1:gr%der%dim) = kpoints%get_point(st%d%get_kpoint_index(ik))
2038 is = st%d%get_spin_index(ik)
2040 do ist = st%st_start, st_end_
2041 ww = st%kweights(ik)*st%occ(ist, ik)
2047 do st_dim = 1, st%d%dim
2052 do st_dim = 1, st%d%dim
2053 call zderivatives_grad(gr%der, wf_psi(:,st_dim), gwf_psi(:,:,st_dim), set_bc = .false.)
2057 if (
present(density_laplacian))
then
2058 do st_dim = 1, st%d%dim
2059 call zderivatives_lapl(gr%der, wf_psi(:,st_dim), lwf_psi(:,st_dim), ghost_update = .false., set_bc = .false.)
2064 wf_psi_conj(1:gr%np, 1:st%d%dim) = conjg(wf_psi(1:gr%np,1:st%d%dim))
2066 do st_dim = 1, st%d%dim
2068 abs_wf_psi(ii, st_dim) = real(wf_psi_conj(ii, st_dim) * wf_psi(ii, st_dim), real64)
2073 if (
present(density_laplacian))
then
2076 density_laplacian(ii, is) = density_laplacian(ii, is) + &
2077 ww *
m_two*real(wf_psi_conj(ii, 1) * lwf_psi(ii, 1), real64)
2080 if (st%d%ispin ==
spinors)
then
2083 density_laplacian(ii, 2) = density_laplacian(ii, 2) + &
2084 ww *
m_two*real(wf_psi_conj(ii, 2) * lwf_psi(ii, 2), real64)
2089 c_tmp = ww*(lwf_psi(ii, 1) * wf_psi_conj(ii, 2) + wf_psi(ii, 1) * conjg(lwf_psi(ii, 2)))
2090 density_laplacian(ii, 3) = density_laplacian(ii, 3) + real(c_tmp, real64)
2091 density_laplacian(ii, 4) = density_laplacian(ii, 4) + aimag(c_tmp)
2096 if (
associated(tau))
then
2097 call lalg_axpy(gr%np, ww * sum(kpoint(1:gr%der%dim)**2), abs_wf_psi(:, 1), tau(:, is))
2098 if (st%d%ispin ==
spinors)
then
2099 call lalg_axpy(gr%np, ww * sum(kpoint(1:gr%der%dim)**2), abs_wf_psi(:, 2), tau(:, 2))
2103 c_tmp = ww * sum(kpoint(1:gr%der%dim)**2) * wf_psi(ii, 1) * wf_psi_conj(ii, 2)
2104 tau(ii, 3) = tau(ii, 3) + real(c_tmp, real64)
2105 tau(ii, 4) = tau(ii, 4) + aimag(c_tmp)
2110 do i_dim = 1, gr%der%dim
2114 do st_dim = 1, st%d%dim
2117 psi_gpsi(ii, st_dim) = wf_psi_conj(ii, st_dim) * gwf_psi(ii, i_dim, st_dim)
2120 do st_dim = 1, st%d%dim
2123 abs_gwf_psi(ii, st_dim) = real(conjg(gwf_psi(ii, i_dim, st_dim)) &
2124 * gwf_psi(ii, i_dim, st_dim), real64)
2129 if (
present(density_gradient))
then
2132 density_gradient(ii, i_dim, is) = density_gradient(ii, i_dim, is) &
2133 + ww *
m_two * real(psi_gpsi(ii, 1), real64)
2136 if (st%d%ispin ==
spinors)
then
2139 density_gradient(ii, i_dim, 2) = density_gradient(ii, i_dim, 2) &
2140 + ww *
m_two*real(psi_gpsi(ii, 2), real64)
2145 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)))
2146 density_gradient(ii, i_dim, 3) = density_gradient(ii, i_dim, 3) + real(c_tmp, real64)
2147 density_gradient(ii, i_dim, 4) = density_gradient(ii, i_dim, 4) + aimag(c_tmp)
2152 if (
present(density_laplacian))
then
2153 call lalg_axpy(gr%np, ww*
m_two, abs_gwf_psi(:,1), density_laplacian(:,is))
2154 if (st%d%ispin ==
spinors)
then
2155 call lalg_axpy(gr%np, ww*
m_two, abs_gwf_psi(:,2), density_laplacian(:,2))
2158 c_tmp =
m_two * ww * gwf_psi(ii, i_dim, 1) * conjg(gwf_psi(ii, i_dim, 2))
2159 density_laplacian(ii, 3) = density_laplacian(ii, 3) + real(c_tmp, real64)
2160 density_laplacian(ii, 4) = density_laplacian(ii, 4) + aimag(c_tmp)
2168 if (
associated(jp))
then
2172 jp(ii, i_dim, is) = jp(ii, i_dim, is) + &
2173 ww*(aimag(psi_gpsi(ii, 1)) - abs_wf_psi(ii, 1)*kpoint(i_dim))
2176 if (st%d%ispin ==
spinors)
then
2179 jp(ii, i_dim, 2) = jp(ii, i_dim, 2) + &
2180 ww*( aimag(psi_gpsi(ii, 2)) - abs_wf_psi(ii, 2)*kpoint(i_dim))
2185 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)) &
2186 -
m_two *
m_zi*wf_psi(ii, 1)*wf_psi_conj(ii, 2)*kpoint(i_dim))
2187 jp(ii, i_dim, 3) = jp(ii, i_dim, 3) + real(c_tmp, real64)
2188 jp(ii, i_dim, 4) = jp(ii, i_dim, 4) + aimag(c_tmp)
2197 if (
associated(tau))
then
2200 tau(ii, is) = tau(ii, is) + ww*(abs_gwf_psi(ii,1) &
2201 -
m_two*aimag(psi_gpsi(ii, 1))*kpoint(i_dim))
2204 if (st%d%ispin ==
spinors)
then
2207 tau(ii, 2) = tau(ii, 2) + ww*(abs_gwf_psi(ii, 2) &
2208 -
m_two*aimag(psi_gpsi(ii, 2))*kpoint(i_dim))
2213 c_tmp = ww * ( gwf_psi(ii, i_dim, 1)*conjg(gwf_psi(ii, i_dim, 2)) &
2214 +
m_zi * (gwf_psi(ii,i_dim,1)*wf_psi_conj(ii, 2) &
2215 - wf_psi(ii, 1)*conjg(gwf_psi(ii,i_dim,2)))*kpoint(i_dim))
2216 tau(ii, 3) = tau(ii, 3) + real(c_tmp, real64)
2217 tau(ii, 4) = tau(ii, 4) + aimag(c_tmp)
2227 safe_deallocate_a(wf_psi_conj)
2228 safe_deallocate_a(abs_wf_psi)
2229 safe_deallocate_a(abs_gwf_psi)
2230 safe_deallocate_a(psi_gpsi)
2232 if (.not.
present(gi_kinetic_energy_density))
then
2233 if (.not.
present(paramagnetic_current))
then
2234 safe_deallocate_p(jp)
2236 if (.not.
present(kinetic_energy_density))
then
2237 safe_deallocate_p(tau)
2241 if (st%parallel_in_states .or. st%d%kpt%parallel)
call reduce_all(st%st_kpt_mpi_grp)
2246 if (st%symmetrize_density)
then
2247 do is = 1, st%d%nspin
2248 if (
associated(tau))
then
2252 if (
present(density_laplacian))
then
2256 if (
associated(jp))
then
2260 if (
present(density_gradient))
then
2267 if (
allocated(st%rho_core) .and. nlcc .and. (
present(density_laplacian) .or.
present(density_gradient)))
then
2269 wf_psi(ii, 1) = st%rho_core(ii)/st%d%spin_channels
2274 if (
present(density_gradient))
then
2277 do is = 1, st%d%spin_channels
2279 do i_dim = 1, gr%der%dim
2281 density_gradient(ii, i_dim, is) = density_gradient(ii, i_dim, is) + &
2282 real(gwf_psi(ii, i_dim, 1), real64)
2290 if (
present(density_laplacian))
then
2294 do is = 1, st%d%spin_channels
2297 density_laplacian(ii, is) = density_laplacian(ii, is) + real(lwf_psi(ii, 1))
2306 if (
allocated(st%frozen_tau) .and. .not.
present(st_end) .and.
associated(tau))
then
2309 if (
allocated(st%frozen_gdens) .and. .not.
present(st_end) .and.
present(density_gradient))
then
2310 do is = 1, st%d%nspin
2311 call lalg_axpy(gr%np, gr%der%dim,
m_one, st%frozen_gdens(:,:,is), density_gradient(:,:,is))
2314 if (
allocated(st%frozen_ldens) .and. .not.
present(st_end) .and.
present(density_laplacian))
then
2315 call lalg_axpy(gr%np, st%d%nspin,
m_one, st%frozen_ldens, density_laplacian)
2318 safe_deallocate_a(wf_psi)
2319 safe_deallocate_a(gwf_psi)
2320 safe_deallocate_a(lwf_psi)
2324 if (
present(gi_kinetic_energy_density))
then
2325 do is = 1, st%d%nspin
2326 assert(
associated(tau))
2327 gi_kinetic_energy_density(1:gr%np, is) = tau(1:gr%np, is)
2330 assert(
associated(jp))
2331 if (st%d%ispin /=
spinors)
then
2332 do is = 1, st%d%nspin
2335 if (st%rho(ii, is) < 1.0e-7_real64) cycle
2336 gi_kinetic_energy_density(ii, is) = &
2337 gi_kinetic_energy_density(ii, is) - sum(jp(ii,1:gr%der%dim, is)**2)/st%rho(ii, is)
2343 gi_kinetic_energy_density(ii, 1) = gi_kinetic_energy_density(ii, 1) &
2344 - sum(jp(ii,1:gr%der%dim, 1)**2)/(safe_tol(st%rho(ii, 1),
m_epsilon))
2345 gi_kinetic_energy_density(ii, 2) = gi_kinetic_energy_density(ii, 2) &
2346 - sum(jp(ii,1:gr%der%dim, 2)**2)/(safe_tol(st%rho(ii, 2),
m_epsilon))
2347 gi_kinetic_energy_density(ii, 3) = &
2348 gi_kinetic_energy_density(ii, 3) - sum(jp(ii,1:gr%der%dim, 3)**2 + jp(ii,1:gr%der%dim, 4)**2) &
2349 /(safe_tol((st%rho(ii, 3)**2 + st%rho(ii, 4)**2),
m_epsilon))*st%rho(ii, 3)
2350 gi_kinetic_energy_density(ii, 4) = &
2351 gi_kinetic_energy_density(ii, 4) + sum(jp(ii,1:gr%der%dim, 3)**2 + jp(ii,1:gr%der%dim, 4)**2) &
2352 /(safe_tol((st%rho(ii, 3)**2 + st%rho(ii, 4)**2),
m_epsilon))*st%rho(ii, 4)
2358 if (.not.
present(kinetic_energy_density))
then
2359 safe_deallocate_p(tau)
2361 if (.not.
present(paramagnetic_current))
then
2362 safe_deallocate_p(jp)
2377 if (
associated(tau))
call comm_allreduce(grp, tau, dim = (/gr%np, st%d%nspin/))
2379 if (
present(density_laplacian))
call comm_allreduce(grp, density_laplacian, dim = (/gr%np, st%d%nspin/))
2381 do is = 1, st%d%nspin
2382 if (
associated(jp))
call comm_allreduce(grp, jp(:, :, is), dim = (/gr%np, gr%der%dim/))
2384 if (
present(density_gradient))
then
2385 call comm_allreduce(grp, density_gradient(:, :, is), dim = (/gr%np, gr%der%dim/))
2399 type(
mesh_t),
intent(in) :: mesh
2400 complex(real64),
intent(in) :: f1(:, :)
2401 real(real64) :: spin(1:3)
2403 complex(real64) :: z
2407 z =
zmf_dotp(mesh, f1(:, 1) , f1(:, 2))
2409 spin(1) =
m_two*real(z, real64)
2410 spin(2) =
m_two*aimag(z)
2422 integer,
intent(in) :: ist
2436 integer,
intent(in) :: ist
2437 integer,
intent(in) :: ik
2442 ik >= st%d%kpt%start .and. ik <= st%d%kpt%end
2452 class(
mesh_t),
intent(in) :: mesh
2458 memory = memory + real(storage_size(0.0_real64)/8, real64) * &
2459 real(mesh%np_part_global, real64) *st%d%dim *
real(st%nst, real64) *st%d%kpt%nglobal()
2469 logical,
optional,
intent(in) :: copy
2472 integer(int64) :: max_mem, mem
2484 if (accel_is_enabled())
then
2485 max_mem = accel_global_memory_size()
2487 if (st%gpu_states_mem > m_one)
then
2488 max_mem = int(st%gpu_states_mem, int64)*(1024_8)**2
2489 else if (st%gpu_states_mem < 0.0_real64)
then
2490 max_mem = max_mem + int(st%gpu_states_mem, int64)*(1024_8)**2
2492 max_mem = int(st%gpu_states_mem*real(max_mem, real64) , int64)
2495 max_mem = huge(max_mem)
2499 qnloop:
do iqn = st%d%kpt%start, st%d%kpt%end
2500 do ib = st%group%block_start, st%group%block_end
2502 mem = mem + st%group%psib(ib, iqn)%pack_total_size()
2504 if (mem > max_mem)
then
2505 call messages_write(
'Not enough device memory to store all states simultaneously.', new_line = .
true.)
2506 call messages_write(
'Only ')
2507 call messages_write(ib - st%group%block_start)
2508 call messages_write(
' of ')
2509 call messages_write(st%group%block_end - st%group%block_start + 1)
2510 call messages_write(
' blocks will be stored in device memory.', new_line = .
true.)
2511 call messages_warning()
2515 call st%group%psib(ib, iqn)%do_pack(copy)
2527 logical,
optional,
intent(in) :: copy
2536 do iqn = st%d%kpt%start, st%d%kpt%end
2537 do ib = st%group%block_start, st%group%block_end
2538 if (st%group%psib(ib, iqn)%is_packed())
call st%group%psib(ib, iqn)%do_unpack(copy)
2551 type(namespace_t),
intent(in) :: namespace
2555 call messages_print_with_emphasis(msg=
"States", namespace=namespace)
2557 write(message(1),
'(a,f12.3)')
'Total electronic charge = ', st%qtot
2558 write(message(2),
'(a,i8)')
'Number of states = ', st%nst
2559 write(message(3),
'(a,i8)')
'States block-size = ', st%block_size
2560 call messages_info(3, namespace=namespace)
2562 call messages_print_with_emphasis(namespace=namespace)
2575 do iqn = st%d%kpt%start, st%d%kpt%end
2576 do ib = st%group%block_start, st%group%block_end
2577 call batch_set_zero(st%group%psib(ib, iqn))
2587 integer pure function states_elec_block_min(st, ib) result(range)
2589 integer,
intent(in) :: ib
2591 range = st%group%block_range(ib, 1)
2597 integer pure function states_elec_block_max(st, ib) result(range)
2599 integer,
intent(in) :: ib
2601 range = st%group%block_range(ib, 2)
2607 integer pure function states_elec_block_size(st, ib) result(size)
2609 integer,
intent(in) :: ib
2611 size = st%group%block_size(ib)
2617 logical pure function states_elec_all_states_gpu_packed(st) result(all_packed)
2623 do ik = st%d%kpt%start, st%d%kpt%end
2624 do ib = st%group%block_start, st%group%block_end
2625 if (st%group%psib(ib, ik)%status() /= batch_device_packed)
then
2626 all_packed = .false.
2649 subroutine occupied_states(st, namespace, ik, n_filled, n_partially_filled, n_half_filled, &
2650 filled, partially_filled, half_filled)
2652 type(namespace_t),
intent(in) :: namespace
2653 integer,
intent(in) :: ik
2654 integer,
intent(out) :: n_filled, n_partially_filled, n_half_filled
2655 integer,
optional,
intent(out) :: filled(:), partially_filled(:), half_filled(:)
2661 if (
present(filled)) filled(:) = 0
2662 if (
present(partially_filled)) partially_filled(:) = 0
2663 if (
present(half_filled)) half_filled(:) = 0
2665 n_partially_filled = 0
2668 select case (st%d%ispin)
2671 if (abs(st%occ(ist, ik) - m_two) < m_min_occ)
then
2672 n_filled = n_filled + 1
2673 if (
present(filled)) filled(n_filled) = ist
2674 else if (abs(st%occ(ist, ik) - m_one) < m_min_occ)
then
2675 n_half_filled = n_half_filled + 1
2676 if (
present(half_filled)) half_filled(n_half_filled) = ist
2677 else if (st%occ(ist, ik) > m_min_occ)
then
2678 n_partially_filled = n_partially_filled + 1
2679 if (
present(partially_filled)) partially_filled(n_partially_filled) = ist
2680 else if (abs(st%occ(ist, ik)) > m_min_occ)
then
2681 write(message(1),*)
'Internal error in occupied_states: Illegal occupation value ', st%occ(ist, ik)
2682 call messages_fatal(1, namespace=namespace)
2685 case (spin_polarized, spinors)
2687 if (abs(st%occ(ist, ik)-m_one) < m_min_occ)
then
2688 n_filled = n_filled + 1
2689 if (
present(filled)) filled(n_filled) = ist
2690 else if (st%occ(ist, ik) > m_min_occ)
then
2691 n_partially_filled = n_partially_filled + 1
2692 if (
present(partially_filled)) partially_filled(n_partially_filled) = ist
2693 else if (abs(st%occ(ist, ik)) > m_min_occ)
then
2694 write(message(1),*)
'Internal error in occupied_states: Illegal occupation value ', st%occ(ist, ik)
2695 call messages_fatal(1, namespace=namespace)
2707 type(multicomm_t),
intent(in) :: mc
2710 call distributed_init(this%d%kpt, this%nik, mc%group_comm(p_strategy_kpoints),
"k-points")
2725 if (.not.
allocated(st%st_kpt_task))
then
2726 safe_allocate(st%st_kpt_task(0:st%st_kpt_mpi_grp%size-1, 1:4))
2729 st%st_kpt_task(0:st%st_kpt_mpi_grp%size-1, :) = 0
2730 st%st_kpt_task(st%st_kpt_mpi_grp%rank, :) = [st%st_start, st%st_end, st%d%kpt%start, st%d%kpt%end]
2732 if (st%parallel_in_states .or. st%d%kpt%parallel)
then
2733 call comm_allreduce(st%st_kpt_mpi_grp, st%st_kpt_task)
2744 type(kpoints_t),
intent(in) :: kpoints
2745 type(namespace_t),
intent(in) :: namespace
2748 type(states_elec_dim_t),
pointer :: dd
2755 st%nik = kpoints_number(kpoints)
2757 if (dd%ispin == spin_polarized) st%nik = 2*st%nik
2759 safe_allocate(st%kweights(1:st%nik))
2762 ik = dd%get_kpoint_index(iq)
2763 st%kweights(iq) = kpoints%get_weight(ik)
2775 call io_mkdir(
'debug/', namespace)
2776 iunit = io_open(
'debug/kpoints', namespace, action =
'write')
2777 call kpoints%write_info(iunit=iunit, absolute_coordinates = .
true.)
2778 call io_close(iunit)
2792 class(mesh_t),
intent(in) :: gr
2793 real(real64) :: dipole(1:gr%box%dim)
2796 real(real64) :: e_dip(1:gr%box%dim, this%d%spin_channels)
2800 do ispin = 1, this%d%spin_channels
2801 call dmf_dipole(gr, this%rho(:, ispin), e_dip(:, ispin))
2804 dipole(:) = sum(e_dip(:, 1:this%d%spin_channels), 2)
2812#include "states_elec_inc.F90"
2815#include "complex.F90"
2816#include "states_elec_inc.F90"
initialize a batch with existing memory
constant times a vector plus a vector
scales a vector by a constant
Prints out to iunit a message in the form: ["InputVariable" = value] where "InputVariable" is given b...
subroutine, public accel_free_buffer(this, async)
pure logical function, public accel_is_enabled()
type(accel_t), public accel
This module implements batches of mesh functions.
This module implements common operations on batches of mesh functions.
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.
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_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.
subroutine, public distributed_init_serial(this, total)
Serial initialization of a distributed instance. The calling process is assigned all total instances,...
integer, parameter, public unpolarized
Parameters...
integer, parameter, public spinors
integer, parameter, public spin_polarized
real(real64), parameter, public m_two
real(real64), parameter, public m_zero
real(real64), parameter, public m_fourth
complex(real64), parameter, public m_zi
real(real64), parameter, public m_epsilon
type(conf_t), public conf
Global instance of Octopus configuration.
real(real64), parameter, public m_half
real(real64), parameter, public m_one
This module implements the underlying real-space grid.
subroutine, public dgrid_symmetrize_vector_field(gr, field, suppress_warning)
subroutine, public dgrid_symmetrize_scalar_field(gr, field, suppress_warning)
logical pure function, public kpoints_point_is_gamma(this, ik)
System information (time, memory, sysname)
This module is intended to contain "only mathematical" functions and procedures.
integer pure function, public pad_pow2(size)
create array size, which is padded to powers of 2
This module defines functions over batches of mesh functions.
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.
subroutine, public messages_not_implemented(feature, namespace)
subroutine, public messages_warning(no_lines, all_nodes, namespace)
subroutine, public messages_obsolete_variable(namespace, name, rep)
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
subroutine, public messages_input_error(namespace, var, details, row, column)
subroutine, public messages_experimental(name, namespace)
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
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.
type(mpi_comm), parameter, public mpi_comm_undefined
used to indicate a communicator has not been initialized
subroutine mpi_grp_init(grp, comm)
Initialize MPI group instance.
This module handles the communicators for the various parallelization strategies.
logical pure function, public multicomm_strategy_is_parallel(mc, level)
subroutine, public multicomm_all_pairs_copy(apout, apin)
logical pure function, public multicomm_have_slaves(this)
logical function, public parse_is_defined(namespace, name)
integer function, public parse_block(namespace, name, blk, check_varinfo_)
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
subroutine, public smear_find_fermi_energy(this, namespace, eigenvalues, occupations, qtot, nik, nst, kweights)
subroutine, public smear_fill_occupations(this, eigenvalues, occupations, kweights, nik, nst)
subroutine, public smear_copy(to, from)
integer, parameter, public smear_fixed_occ
subroutine, public smear_init(this, namespace, ispin, fixed_occ, integral_occs, kpoints)
logical pure function, public smear_is_semiconducting(this)
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, dest_type)
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, public states_elec_copy(stout, stin, exclude_wfns, exclude_eigenval, special, dest_type, copy_data)
make a (selective) copy of a states_elec_t object
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
logical pure function, public states_elec_all_states_gpu_packed(st)
return boolean indicating whether all states are packed on the GPU
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_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
type(type_t), parameter, public type_float
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
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
subroutine, public dwfs_elec_init(this, dim, st_start, st_end, np, ik, special, packed)
initialize an empty wfs_elec_t object
subroutine reduce_all(grp)
subroutine print_kpoints_debug
Class defining batches of mesh functions.
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.
Describes mesh distribution to nodes.
This is defined even when running serial.
An all-pairs communication schedule for a given group.
Stores all communicators and groups.
abstract class for states
The states_elec_t class contains all electronic wave functions.