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
121 real(real64) :: hartree_sumrule
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(:)
161 real(real64),
allocatable :: current(:, :, :)
162 real(real64),
allocatable :: current_para(:, :, :)
163 real(real64),
allocatable :: current_dia(:, :, :)
164 real(real64),
allocatable :: current_mag(:, :, :)
165 real(real64),
allocatable :: current_kpt(:,:,:)
170 real(real64),
allocatable :: frozen_rho(:, :)
171 real(real64),
allocatable :: frozen_tau(:, :)
172 real(real64),
allocatable :: frozen_gdens(:,:,:)
173 real(real64),
allocatable :: frozen_ldens(:,:)
175 logical :: uniform_occ
177 real(real64),
allocatable :: eigenval(:,:)
179 logical :: restart_fixed_occ
180 logical :: restart_reorder_occs
181 real(real64),
allocatable :: occ(:,:)
182 real(real64),
allocatable :: kweights(:)
185 logical :: fixed_spins
187 real(real64),
allocatable :: spin(:, :, :)
190 real(real64) :: val_charge
192 type(stress_t) :: stress_tensors
194 logical :: fromScratch
195 type(smear_t) :: smear
198 type(modelmb_particle_t) :: modelmbparticles
202 type(mpi_grp_t) :: mpi_grp
203 type(mpi_grp_t) :: dom_st_mpi_grp
209 logical :: scalapack_compatible
210 logical :: parallel_in_states = .false.
214 integer :: st_start, st_end
215 integer,
allocatable :: node(:)
218 integer,
allocatable :: st_kpt_task(:,:)
221 logical :: symmetrize_density
222 integer :: randomization
223 integer :: orth_method = 0
225 real(real64) :: gpu_states_mem
237 integer,
public,
parameter :: &
281 real(real64),
intent(in) :: valence_charge
283 integer,
optional,
intent(in) :: calc_mode_id
285 real(real64) :: excess_charge, nempty_percent
286 integer :: nempty, ntot, default
287 integer :: nempty_conv, nempty_conv_default
288 logical :: force, adapt_for_chebyshev
289 real(real64),
parameter :: tol = 1e-13_real64
291 integer,
parameter :: rs_chebyshev = 12
292 integer(int64),
parameter :: chebyshev_compatible_modes(3) = &
293 [option__calculationmode__gs, option__calculationmode__go, option__calculationmode__unocc]
302 st%d%ispin = space%ispin
307 if (st%d%ispin /=
unpolarized .and. kpoints%use_time_reversal)
then
308 message(1) =
"Time reversal symmetry is only implemented for unpolarized spins."
309 message(2) =
"Use KPointsUseTimeReversal = no."
341 write(
message(1),
'(a,i5,a)')
"Input: '", ntot,
"' is not a valid value for TotalStates."
363 write(
message(1),
'(a,i5,a)')
"Input: '", nempty,
"' is not a valid value for ExtraStates."
364 message(2) =
'(0 <= ExtraStates)'
368 if (ntot > 0 .and. nempty > 0)
then
369 message(1) =
'You cannot set TotalStates and ExtraStates at the same time.'
384 if (nempty_percent < 0)
then
385 write(
message(1),
'(a,f8.6,a)')
"Input: '", nempty_percent, &
386 "' should be a percentage value x (where x is parts in hundred) larger or equal 0"
390 if (nempty > 0 .and. nempty_percent > 0)
then
391 message(1) =
'You cannot set ExtraStates and ExtraStatesInPercent at the same time.'
396 adapt_for_chebyshev = .false.
397 if (
present(calc_mode_id))
then
398 if (any(calc_mode_id == chebyshev_compatible_modes))
then
401 if (es == rs_chebyshev)
then
403 adapt_for_chebyshev = .
true.
407 if (adapt_for_chebyshev)
then
410 message(1) =
'Chebyshev filtering eigensolver detected. Setting ExtraStatesInPercent = 15'
418 st%val_charge = valence_charge
420 st%qtot = -(st%val_charge + excess_charge)
423 write(
message(1),
'(a,f12.6,a)')
'Total charge = ', st%qtot,
' < 0'
424 message(2) =
'Check Species and ExcessCharge.'
428 select case (st%d%ispin)
431 st%nst = nint(st%qtot/2)
432 if (st%nst*2 - st%qtot < -tol) st%nst = st%nst + 1
434 st%d%spin_channels = 1
437 st%nst = nint(st%qtot/2)
438 if (st%nst*2 - st%qtot < -tol) st%nst = st%nst + 1
440 st%d%spin_channels = 2
443 st%nst = nint(st%qtot)
444 if (st%nst - st%qtot < -tol) st%nst = st%nst + 1
446 st%d%spin_channels = 2
449 if (nempty_percent > 0)
then
450 nempty = ceiling(nempty_percent * st%nst / 100)
470 nempty_conv_default = nempty
471 if (adapt_for_chebyshev)
then
473 nempty_conv_default = min(int(0.8*nempty), nempty - 1)
475 call parse_variable(namespace,
'ExtraStatesToConverge', nempty_conv_default, nempty_conv)
476 if (nempty_conv < 0)
then
477 write(
message(1),
'(a,i5,a)')
"Input: '", nempty_conv,
"' is not a valid value for ExtraStatesToConverge."
478 message(2) =
'(0 <= ExtraStatesToConverge)'
482 if (nempty_conv > nempty)
then
484 message(1) =
'You cannot set ExtraStatesToConverge to a higher value than ExtraStates.'
485 message(2) =
'Capping ExtraStatesToConverge to ExtraStates.'
490 if (ntot < st%nst)
then
491 message(1) =
'TotalStates is smaller than the number of states required by the system.'
498 st%nst_conv = st%nst + nempty_conv
499 st%nst = st%nst + nempty
500 if (st%nst == 0)
then
501 message(1) =
"Cannot run with number of states = zero."
519 default =
accel%warp_size
528 call parse_variable(namespace,
'StatesBlockSize', default, st%block_size)
529 if (st%block_size < 1)
then
530 call messages_write(
"The variable 'StatesBlockSize' must be greater than 0.")
534 st%block_size = min(st%block_size, st%nst)
535 conf%target_states_block_size = st%block_size
537 safe_allocate(st%eigenval(1:st%nst, 1:st%nik))
538 st%eigenval = huge(st%eigenval)
542 if (.not. kpoints%gamma_only())
then
555 call parse_variable(namespace,
'OnlyUserDefinedInitialStates', .false., st%only_userdef_istates)
558 safe_allocate(st%occ (1:st%nst, 1:st%nik))
563 safe_allocate(st%user_def_states(1:st%d%dim, 1:st%nst, 1:st%nik))
565 st%user_def_states(1:st%d%dim, 1:st%nst, 1:st%nik) =
'undefined'
568 if (st%d%ispin ==
spinors)
then
569 safe_allocate(st%spin(1:3, 1:st%nst, 1:st%nik))
596 if (st%smear%photodop)
then
597 if (nempty == 0)
then
598 write(
message(1),
'(a,i5,a)')
"PhotoDoping requires to specify ExtraStates."
599 message(2) =
'(0 == ExtraStates)'
607 safe_allocate(st%node(1:st%nst))
608 st%node(1:st%nst) = 0
611 st%parallel_in_states = .false.
625 call parse_variable(namespace,
'SymmetrizeDensity', kpoints%use_symmetries, st%symmetrize_density)
655 integer,
intent(out) :: nik
656 integer,
intent(out) :: dim
657 integer,
intent(out) :: nst
658 integer,
intent(out) :: ierr
660 character(len=256) :: lines(3)
661 character(len=20) :: char
668 iunit = restart%open(
'states')
669 call restart%read(iunit, lines, 3, ierr)
671 read(lines(1), *) char, nst
672 read(lines(2), *) char, dim
673 read(lines(3), *) char, nik
675 call restart%close(iunit)
693 real(real64),
intent(in) :: excess_charge
696 integer :: ik, ist, ispin, nspin, ncols, nrows, el_per_state, icol, start_pos, spin_n
698 real(real64) :: rr, charge
699 logical :: integral_occs, unoccupied_states
700 real(real64),
allocatable :: read_occs(:, :)
701 real(real64) :: charge_in_block
714 call parse_variable(namespace,
'RestartFixedOccupations', .
true., st%restart_fixed_occ)
787 occ_fix:
if (
parse_block(namespace,
'Occupations', blk) == 0)
then
789 st%fixed_occ = .
true.
792 if (ncols > st%nst)
then
797 if (nrows /= st%nik)
then
798 call messages_input_error(namespace,
"Occupations",
"Wrong number of rows in block Occupations.")
801 do ik = 1, st%nik - 1
804 "All rows in block Occupations must have the same number of columns.")
815 safe_allocate(read_occs(1:ncols, 1:st%nik))
821 charge_in_block = charge_in_block + read_occs(icol, ik) * st%kweights(ik)
826 select case (st%d%ispin)
835 start_pos = nint((st%qtot - charge_in_block)/spin_n)
837 if (start_pos + ncols > st%nst)
then
838 message(1) =
"To balance charge, the first column in block Occupations is taken to refer to state"
839 write(
message(2),
'(a,i6,a)')
"number ", start_pos,
" but there are too many columns for the number of states."
840 write(
message(3),
'(a,i6,a)')
"Solution: set ExtraStates = ", start_pos + ncols - st%nst
845 do ist = 1, start_pos
846 st%occ(ist, ik) = el_per_state
851 do ist = start_pos + 1, start_pos + ncols
852 st%occ(ist, ik) = read_occs(ist - start_pos, ik)
853 integral_occs = integral_occs .and. &
854 abs((st%occ(ist, ik) - el_per_state) * st%occ(ist, ik)) <=
m_epsilon
859 do ist = start_pos + ncols + 1, st%nst
866 safe_deallocate_a(read_occs)
869 st%fixed_occ = .false.
870 integral_occs = .false.
877 st%qtot = -(st%val_charge + excess_charge)
880 if (st%d%nspin == 2) nspin = 2
882 do ik = 1, st%nik, nspin
885 do ispin = ik, ik + nspin - 1
886 st%occ(ist, ispin) = min(rr, -(st%val_charge + excess_charge) - charge)
887 charge = charge + st%occ(ist, ispin)
906 if (st%fixed_occ)
then
907 call parse_variable(namespace,
'RestartReorderOccs', .false., st%restart_reorder_occs)
909 st%restart_reorder_occs = .false.
912 call smear_init(st%smear, namespace, st%d%ispin, st%fixed_occ, integral_occs, kpoints)
914 unoccupied_states = (st%d%ispin /=
spinors .and. st%nst*2 > st%qtot) .or. (st%d%ispin ==
spinors .and. st%nst > st%qtot)
917 if (.not. unoccupied_states)
then
918 call messages_write(
'Smearing needs unoccupied states (via ExtraStates or TotalStates) to be useful.')
926 charge = charge + sum(st%occ(ist, 1:st%nik) * st%kweights(1:st%nik))
928 if (abs(charge - st%qtot) > 1e-6_real64)
then
929 message(1) =
"Initial occupations do not integrate to total charge."
930 write(
message(2),
'(6x,f12.6,a,f12.6)') charge,
' != ', st%qtot
952 integer :: i, j, nrows
957 st%fixed_spins = .false.
958 if (st%d%ispin /=
spinors)
then
997 spin_fix:
if (
parse_block(namespace,
'InitialSpins', blk) == 0)
then
999 if (nrows < st%nst)
then
1000 message(1) =
"Please specify one row for each state in InitialSpins, also for extra states."
1010 st%fixed_spins = .
true.
1012 st%spin(:, :, i) = st%spin(:, :, 1)
1025 class(
mesh_t),
intent(in) :: mesh
1026 type(
type_t),
optional,
intent(in) :: wfs_type
1027 logical,
optional,
intent(in) :: skip(:)
1028 logical,
optional,
intent(in) :: packed
1032 if (
present(wfs_type))
then
1034 st%wfs_type = wfs_type
1062 type(
mesh_t),
intent(in) :: mesh
1063 logical,
optional,
intent(in) :: verbose
1064 logical,
optional,
intent(in) :: skip(:)
1065 logical,
optional,
intent(in) :: packed
1067 integer :: ib, iqn, ist, istmin, istmax
1068 logical :: same_node, verbose_, packed_
1069 integer,
allocatable :: bstart(:), bend(:)
1073 safe_allocate(bstart(1:st%nst))
1074 safe_allocate(bend(1:st%nst))
1075 safe_allocate(st%group%iblock(1:st%nst))
1084 if (
present(skip))
then
1086 if (.not. skip(ist))
then
1094 if (
present(skip))
then
1095 do ist = st%nst, istmin, -1
1096 if (.not. skip(ist))
then
1103 if (
present(skip) .and. verbose_)
then
1113 st%group%nblocks = 0
1115 do ist = istmin, istmax
1118 st%group%iblock(ist) = st%group%nblocks + 1
1121 if (st%parallel_in_states .and. ist /= istmax)
then
1124 same_node = (st%node(ist + 1) == st%node(ist))
1127 if (ib == st%block_size .or. ist == istmax .or. .not. same_node)
then
1129 st%group%nblocks = st%group%nblocks + 1
1130 bend(st%group%nblocks) = ist
1131 if (ist /= istmax) bstart(st%group%nblocks + 1) = ist + 1
1135 safe_allocate(st%group%psib(1:st%group%nblocks, st%d%kpt%start:st%d%kpt%end))
1137 safe_allocate(st%group%block_is_local(1:st%group%nblocks, 1:st%nik))
1138 st%group%block_is_local = .false.
1139 st%group%block_start = -1
1140 st%group%block_end = -2
1142 do ib = 1, st%group%nblocks
1143 if (bstart(ib) >= st%st_start .and. bend(ib) <= st%st_end)
then
1144 if (st%group%block_start == -1) st%group%block_start = ib
1145 st%group%block_end = ib
1146 do iqn = st%d%kpt%start, st%d%kpt%end
1147 st%group%block_is_local(ib, iqn) = .
true.
1150 call dwfs_elec_init(st%group%psib(ib, iqn), st%d%dim, bstart(ib), bend(ib), mesh%np_part, iqn, &
1151 special=.
true., packed=packed_)
1153 call zwfs_elec_init(st%group%psib(ib, iqn), st%d%dim, bstart(ib), bend(ib), mesh%np_part, iqn, &
1154 special=.
true., packed=packed_)
1161 safe_allocate(st%group%block_range(1:st%group%nblocks, 1:2))
1162 safe_allocate(st%group%block_size(1:st%group%nblocks))
1164 st%group%block_range(1:st%group%nblocks, 1) = bstart(1:st%group%nblocks)
1165 st%group%block_range(1:st%group%nblocks, 2) = bend(1:st%group%nblocks)
1166 st%group%block_size(1:st%group%nblocks) = bend(1:st%group%nblocks) - bstart(1:st%group%nblocks) + 1
1168 st%group%block_initialized = .
true.
1170 safe_allocate(st%group%block_node(1:st%group%nblocks, 1:st%nik))
1171 st%group%block_node = 0
1173 assert(
allocated(st%node))
1174 assert(all(st%node >= 0) .and. all(st%node < st%mpi_grp%size))
1176 do iqn = st%d%kpt%start, st%d%kpt%end
1177 do ib = st%group%block_start, st%group%block_end
1178 st%group%block_node(ib, iqn) = st%st_kpt_mpi_grp%rank
1187 do ib = 1, st%group%nblocks
1193 if (st%group%block_size(ib) > 0)
then
1223 safe_deallocate_a(bstart)
1224 safe_deallocate_a(bend)
1245 type(
grid_t),
intent(in) :: gr
1247 real(real64) :: fsize
1251 safe_allocate(st%rho(1:gr%np_part, 1:st%d%nspin))
1254 fsize = gr%np_part*8.0_real64*st%block_size
1266 class(
space_t),
intent(in) :: space
1267 class(
mesh_t),
intent(in) :: mesh
1271 if (.not.
allocated(st%current))
then
1272 safe_allocate(st%current(1:mesh%np_part, 1:space%dim, 1:st%d%nspin))
1276 if (.not.
allocated(st%current_para))
then
1277 safe_allocate(st%current_para(1:mesh%np_part, 1:space%dim, 1:st%d%nspin))
1281 if (.not.
allocated(st%current_dia))
then
1282 safe_allocate(st%current_dia(1:mesh%np_part, 1:space%dim, 1:st%d%nspin))
1286 if (.not.
allocated(st%current_mag))
then
1287 safe_allocate(st%current_mag(1:mesh%np_part, 1:space%dim, 1:st%d%nspin))
1291 if (.not.
allocated(st%current_kpt))
then
1292 safe_allocate(st%current_kpt(1:mesh%np,1:space%dim,st%d%kpt%start:st%d%kpt%end))
1371 default = option__statesorthogonalization__cholesky_serial
1372#ifdef HAVE_SCALAPACK
1374 default = option__statesorthogonalization__cholesky_parallel
1378 call parse_variable(namespace,
'StatesOrthogonalization', default, st%orth_method)
1399 call parse_variable(namespace,
'StatesDeviceMemory', -512.0_real64, st%gpu_states_mem)
1409 subroutine states_elec_copy(stout, stin, exclude_wfns, exclude_eigenval, special)
1412 logical,
optional,
intent(in) :: exclude_wfns
1413 logical,
optional,
intent(in) :: exclude_eigenval
1414 logical,
optional,
intent(in) :: special
1416 logical :: exclude_wfns_
1425 safe_allocate_source_a(stout%kweights, stin%kweights)
1426 stout%nik = stin%nik
1430 stout%wfs_type = stin%wfs_type
1431 stout%nst = stin%nst
1432 stout%block_size = stin%block_size
1433 stout%orth_method = stin%orth_method
1435 stout%gpu_states_mem = stin%gpu_states_mem
1436 stout%pack_states = stin%pack_states
1438 stout%only_userdef_istates = stin%only_userdef_istates
1440 if (.not. exclude_wfns_)
then
1441 safe_allocate_source_a(stout%rho, stin%rho)
1444 stout%uniform_occ = stin%uniform_occ
1447 safe_allocate_source_a(stout%eigenval, stin%eigenval)
1448 safe_allocate_source_a(stout%occ, stin%occ)
1449 safe_allocate_source_a(stout%spin, stin%spin)
1454 stout%group%nblocks = stin%group%nblocks
1456 safe_allocate_source_a(stout%user_def_states, stin%user_def_states)
1458 safe_allocate_source_a(stout%current, stin%current)
1459 safe_allocate_source_a(stout%current_kpt, stin%current_kpt)
1460 safe_allocate_source_a(stout%rho_core, stin%rho_core)
1461 safe_allocate_source_a(stout%frozen_rho, stin%frozen_rho)
1462 safe_allocate_source_a(stout%frozen_tau, stin%frozen_tau)
1463 safe_allocate_source_a(stout%frozen_gdens, stin%frozen_gdens)
1464 safe_allocate_source_a(stout%frozen_ldens, stin%frozen_ldens)
1466 stout%fixed_occ = stin%fixed_occ
1467 stout%restart_fixed_occ = stin%restart_fixed_occ
1469 stout%fixed_spins = stin%fixed_spins
1471 stout%qtot = stin%qtot
1472 stout%val_charge = stin%val_charge
1476 stout%parallel_in_states = stin%parallel_in_states
1478 call mpi_grp_copy(stout%dom_st_kpt_mpi_grp, stin%dom_st_kpt_mpi_grp)
1479 call mpi_grp_copy(stout%st_kpt_mpi_grp, stin%st_kpt_mpi_grp)
1480 call mpi_grp_copy(stout%dom_st_mpi_grp, stin%dom_st_mpi_grp)
1481 safe_allocate_source_a(stout%node, stin%node)
1482 safe_allocate_source_a(stout%st_kpt_task, stin%st_kpt_task)
1484#ifdef HAVE_SCALAPACK
1490 stout%scalapack_compatible = stin%scalapack_compatible
1492 stout%lnst = stin%lnst
1493 stout%st_start = stin%st_start
1494 stout%st_end = stin%st_end
1498 stout%symmetrize_density = stin%symmetrize_density
1502 stout%packed = stin%packed
1504 stout%randomization = stin%randomization
1525 safe_deallocate_a(st%user_def_states)
1527 safe_deallocate_a(st%rho)
1528 safe_deallocate_a(st%eigenval)
1530 safe_deallocate_a(st%current)
1531 safe_deallocate_a(st%current_para)
1532 safe_deallocate_a(st%current_dia)
1533 safe_deallocate_a(st%current_mag)
1534 safe_deallocate_a(st%current_kpt)
1535 safe_deallocate_a(st%rho_core)
1536 safe_deallocate_a(st%frozen_rho)
1537 safe_deallocate_a(st%frozen_tau)
1538 safe_deallocate_a(st%frozen_gdens)
1539 safe_deallocate_a(st%frozen_ldens)
1540 safe_deallocate_a(st%occ)
1541 safe_deallocate_a(st%spin)
1542 safe_deallocate_a(st%kweights)
1545#ifdef HAVE_SCALAPACK
1551 safe_deallocate_a(st%node)
1552 safe_deallocate_a(st%st_kpt_task)
1554 if (st%parallel_in_states)
then
1555 safe_deallocate_a(st%ap%schedule)
1567 class(
mesh_t),
intent(in) :: mesh
1569 integer,
optional,
intent(in) :: ist_start_
1570 integer,
optional,
intent(in) :: ist_end_
1571 integer,
optional,
intent(in) :: ikpt_start_
1572 integer,
optional,
intent(in) :: ikpt_end_
1573 logical,
optional,
intent(in) :: normalized
1576 integer :: ist, ik, id, ist_start, ist_end, jst, ikpt_start, ikpt_end
1577 complex(real64) :: alpha, beta
1578 real(real64),
allocatable :: dpsi(:, :)
1579 complex(real64),
allocatable :: zpsi(:, :), zpsi2(:)
1580 integer :: ikpoint, ip
1583 logical :: normalized_
1594 safe_allocate(dpsi(1:mesh%np, 1:st%d%dim))
1596 safe_allocate(zpsi(1:mesh%np, 1:st%d%dim))
1599 select case (st%d%ispin)
1602 do ik = ikpt_start, ikpt_end
1603 ikpoint = st%d%get_kpoint_index(ik)
1604 do ist = ist_start, ist_end
1608 pre_shift = mesh%pv%xlocal-1, &
1609 post_shift = mesh%pv%np_global - mesh%pv%xlocal - mesh%np + 1, &
1610 normalized = normalized)
1612 if(mesh%parallel_in_domains)
then
1618 call dmf_random(mesh, dpsi(:, 1), normalized = normalized)
1623 zpsi(ip,1) = cmplx(dpsi(ip,1),
m_zero, real64)
1632 pre_shift = mesh%pv%xlocal-1, &
1633 post_shift = mesh%pv%np_global - mesh%pv%xlocal - mesh%np + 1, &
1634 normalized = normalized)
1636 if(mesh%parallel_in_domains)
then
1642 call zmf_random(mesh, zpsi(:, 1), normalized = normalized)
1654 if (st%fixed_spins)
then
1656 do ik = ikpt_start, ikpt_end
1657 ikpoint = st%d%get_kpoint_index(ik)
1658 do ist = ist_start, ist_end
1662 pre_shift = mesh%pv%xlocal-1, &
1663 post_shift = mesh%pv%np_global - mesh%pv%xlocal - mesh%np + 1, &
1664 normalized = normalized)
1666 if(mesh%parallel_in_domains)
then
1672 call dmf_random(mesh, dpsi(:, 1), normalized = normalized)
1676 zpsi(ip,1) = cmplx(dpsi(ip,1),
m_zero, real64)
1682 pre_shift = mesh%pv%xlocal-1, &
1683 post_shift = mesh%pv%np_global - mesh%pv%xlocal - mesh%np + 1, &
1684 normalized = normalized)
1686 if(mesh%parallel_in_domains)
then
1692 call zmf_random(mesh, zpsi(:, 1), normalized = normalized)
1705 safe_allocate(zpsi2(1:mesh%np))
1706 do jst = ist_start, ist - 1
1708 zpsi(1:mesh%np, 1) = zpsi(1:mesh%np, 1) -
zmf_dotp(mesh, zpsi(:, 1), zpsi2)*zpsi2(1:mesh%np)
1710 safe_deallocate_a(zpsi2)
1713 zpsi(1:mesh%np, 2) = zpsi(1:mesh%np, 1)
1717 if (abs(alpha) >
m_zero)
then
1718 beta = cmplx(st%spin(1, ist, ik) / abs(alpha), st%spin(2, ist, ik) / abs(alpha), real64)
1720 zpsi(1:mesh%np, 1) = alpha*zpsi(1:mesh%np, 1)
1721 zpsi(1:mesh%np, 2) = beta*zpsi(1:mesh%np, 2)
1726 do ik = ikpt_start, ikpt_end
1727 do ist = ist_start, ist_end
1731 pre_shift = mesh%pv%xlocal-1, &
1732 post_shift = mesh%pv%np_global - mesh%pv%xlocal - mesh%np + 1, &
1733 normalized = .false.)
1735 if(mesh%parallel_in_domains)
then
1741 call zmf_random(mesh, zpsi(:, id), normalized = .false.)
1757 safe_deallocate_a(dpsi)
1758 safe_deallocate_a(zpsi)
1769 class(
mesh_t),
intent(in) :: mesh
1770 logical,
optional,
intent(in) :: compute_spin
1774 real(real64) :: charge
1775 complex(real64),
allocatable :: zpsi(:, :)
1780 st%nik, st%nst, st%kweights)
1787 charge = charge + sum(st%occ(ist, 1:st%nik) * st%kweights(1:st%nik))
1789 if (abs(charge-st%qtot) > 1e-6_real64)
then
1790 message(1) =
'Occupations do not integrate to total charge.'
1791 write(
message(2),
'(6x,f12.8,a,f12.8)') charge,
' != ', st%qtot
1794 message(1) =
"There don't seem to be any electrons at all!"
1804 safe_allocate(zpsi(1:mesh%np, st%d%dim))
1805 do ik = st%d%kpt%start, st%d%kpt%end
1806 do ist = st%st_start, st%st_end
1808 st%spin(1:3, ist, ik) =
state_spin(mesh, zpsi)
1811 safe_deallocate_a(zpsi)
1813 if (st%parallel_in_states .or. st%d%kpt%parallel)
then
1828 real(real64),
optional,
intent(in) :: alt_eig(st%st_start:, st%d%kpt%start:)
1837 do ik = st%d%kpt%start, st%d%kpt%end
1838 if (
present(alt_eig))
then
1839 tot = tot + st%kweights(ik) * sum(st%occ(st%st_start:st%st_end, ik) * &
1840 alt_eig(st%st_start:st%st_end, ik))
1842 tot = tot + st%kweights(ik) * sum(st%occ(st%st_start:st%st_end, ik) * &
1843 st%eigenval(st%st_start:st%st_end, ik))
1847 if (st%parallel_in_states .or. st%d%kpt%parallel)
call comm_allreduce(st%st_kpt_mpi_grp, tot)
1859 logical :: default_scalapack_compatible
1870 st%parallel_in_states = .false.
1873 call mpi_grp_init(st%dom_st_kpt_mpi_grp, mc%dom_st_kpt_comm)
1877 default_scalapack_compatible =
calc_mode_par%scalapack_compat() .and. .not. st%d%kpt%parallel
1891 call parse_variable(namespace,
'ScaLAPACKCompatible', default_scalapack_compatible, st%scalapack_compatible)
1893#ifdef HAVE_SCALAPACK
1894 if (default_scalapack_compatible .neqv. st%scalapack_compatible)
then
1895 call messages_experimental(
'Setting ScaLAPACKCompatible to other than default', namespace=namespace)
1898 if (st%scalapack_compatible)
then
1905 st%scalapack_compatible = .false.
1911 call multicomm_create_all_pairs(st%mpi_grp, st%ap)
1914 if (st%nst < st%mpi_grp%size)
then
1915 message(1) =
"Have more processors than necessary"
1916 write(
message(2),
'(i4,a,i4,a)') st%mpi_grp%size,
" processors and ", st%nst,
" states."
1920 call distributed_init(st%dist, st%nst, st%mpi_grp%comm,
"states", scalapack_compat = st%scalapack_compatible)
1922 st%parallel_in_states = st%dist%parallel
1925 st%st_start = st%dist%start
1926 st%st_end = st%dist%end
1927 st%lnst = st%dist%nlocal
1928 st%node(1:st%nst) = st%dist%node(1:st%nst)
1945 kinetic_energy_density, paramagnetic_current, density_gradient, density_laplacian, &
1946 gi_kinetic_energy_density, st_end)
1947 type(
grid_t),
intent(in) :: gr
1950 logical,
intent(in) :: nlcc
1951 real(real64),
contiguous,
optional,
target,
intent(out) :: kinetic_energy_density(:,:)
1952 real(real64),
contiguous,
optional,
target,
intent(out) :: paramagnetic_current(:,:,:)
1953 real(real64),
contiguous,
optional,
intent(out) :: density_gradient(:,:,:)
1954 real(real64),
contiguous,
optional,
intent(out) :: density_laplacian(:,:)
1955 real(real64),
contiguous,
optional,
intent(out) :: gi_kinetic_energy_density(:,:)
1956 integer,
optional,
intent(in) :: st_end
1958 real(real64),
pointer,
contiguous :: jp(:, :, :)
1959 real(real64),
pointer,
contiguous :: tau(:, :)
1960 complex(real64),
allocatable :: wf_psi(:,:), gwf_psi(:,:,:), wf_psi_conj(:,:), lwf_psi(:,:)
1961 real(real64),
allocatable :: abs_wf_psi(:,:), abs_gwf_psi(:,:)
1962 complex(real64),
allocatable :: psi_gpsi(:,:)
1963 complex(real64) :: c_tmp
1964 integer :: is, ik, ist, i_dim, st_dim, ii, st_end_
1965 real(real64) :: ww, kpoint(gr%der%dim)
1966 logical :: something_to_do
1974 something_to_do =
present(kinetic_energy_density) .or.
present(gi_kinetic_energy_density) .or. &
1975 present(paramagnetic_current) .or.
present(density_gradient) .or.
present(density_laplacian)
1976 assert(something_to_do)
1978 safe_allocate( wf_psi(1:gr%np_part, 1:st%d%dim))
1979 safe_allocate( wf_psi_conj(1:gr%np_part, 1:st%d%dim))
1980 safe_allocate(gwf_psi(1:gr%np, 1:gr%der%dim, 1:st%d%dim))
1981 safe_allocate(abs_wf_psi(1:gr%np, 1:st%d%dim))
1982 safe_allocate(abs_gwf_psi(1:gr%np, 1:st%d%dim))
1983 safe_allocate(psi_gpsi(1:gr%np, 1:st%d%dim))
1984 if (
present(density_laplacian))
then
1985 safe_allocate(lwf_psi(1:gr%np, 1:st%d%dim))
1989 if (
present(kinetic_energy_density)) tau => kinetic_energy_density
1992 if (
present(paramagnetic_current)) jp => paramagnetic_current
1996 if (
present(gi_kinetic_energy_density))
then
1998 safe_allocate(jp(1:gr%np, 1:gr%der%dim, 1:st%d%nspin))
2000 if (.not.
present(kinetic_energy_density))
then
2001 safe_allocate(tau(1:gr%np, 1:st%d%nspin))
2005 if (
associated(tau)) tau =
m_zero
2006 if (
associated(jp)) jp =
m_zero
2007 if (
present(density_gradient)) density_gradient(:,:,:) =
m_zero
2008 if (
present(density_laplacian)) density_laplacian(:,:) =
m_zero
2009 if (
present(gi_kinetic_energy_density)) gi_kinetic_energy_density =
m_zero
2011 do ik = st%d%kpt%start, st%d%kpt%end
2013 kpoint(1:gr%der%dim) = kpoints%get_point(st%d%get_kpoint_index(ik))
2014 is = st%d%get_spin_index(ik)
2016 do ist = st%st_start, st_end_
2017 ww = st%kweights(ik)*st%occ(ist, ik)
2023 do st_dim = 1, st%d%dim
2028 do st_dim = 1, st%d%dim
2029 call zderivatives_grad(gr%der, wf_psi(:,st_dim), gwf_psi(:,:,st_dim), set_bc = .false.)
2033 if (
present(density_laplacian))
then
2034 do st_dim = 1, st%d%dim
2035 call zderivatives_lapl(gr%der, wf_psi(:,st_dim), lwf_psi(:,st_dim), ghost_update = .false., set_bc = .false.)
2040 wf_psi_conj(1:gr%np, 1:st%d%dim) = conjg(wf_psi(1:gr%np,1:st%d%dim))
2041 abs_wf_psi(1:gr%np, 1:st%d%dim) = real(wf_psi_conj(1:gr%np, 1:st%d%dim) * wf_psi(1:gr%np, 1:st%d%dim), real64)
2043 if (
present(density_laplacian))
then
2044 density_laplacian(1:gr%np, is) = density_laplacian(1:gr%np, is) + &
2045 ww *
m_two*real(wf_psi_conj(1:gr%np, 1) * lwf_psi(1:gr%np, 1), real64)
2046 if (st%d%ispin ==
spinors)
then
2047 density_laplacian(1:gr%np, 2) = density_laplacian(1:gr%np, 2) + &
2048 ww *
m_two*real(wf_psi_conj(1:gr%np, 2) * lwf_psi(1:gr%np, 2), real64)
2051 c_tmp = ww*(lwf_psi(ii, 1) * wf_psi_conj(ii, 2) + wf_psi(ii, 1) * conjg(lwf_psi(ii, 2)))
2052 density_laplacian(ii, 3) = density_laplacian(ii, 3) + real(c_tmp, real64)
2053 density_laplacian(ii, 4) = density_laplacian(ii, 4) + aimag(c_tmp)
2058 if (
associated(tau))
then
2059 tau(1:gr%np, is) = tau(1:gr%np, is) &
2060 + ww * sum(kpoint(1:gr%der%dim)**2) * abs_wf_psi(1:gr%np, 1)
2061 if (st%d%ispin ==
spinors)
then
2062 tau(1:gr%np, 2) = tau(1:gr%np, 2) &
2063 + ww * sum(kpoint(1:gr%der%dim)**2) * abs_wf_psi(1:gr%np, 2)
2067 c_tmp = ww * sum(kpoint(1:gr%der%dim)**2) * wf_psi(ii, 1) * wf_psi_conj(ii, 2)
2068 tau(ii, 3) = tau(ii, 3) + real(c_tmp, real64)
2069 tau(ii, 4) = tau(ii, 4) + aimag(c_tmp)
2074 do i_dim = 1, gr%der%dim
2077 psi_gpsi(1:gr%np, 1:st%d%dim) = wf_psi_conj(1:gr%np, 1:st%d%dim) &
2078 * gwf_psi(1:gr%np,i_dim,1:st%d%dim)
2079 abs_gwf_psi(1:gr%np, 1:st%d%dim) = real(conjg(gwf_psi(1:gr%np, i_dim, 1:st%d%dim)) &
2080 * gwf_psi(1:gr%np, i_dim, 1:st%d%dim), real64)
2082 if (
present(density_gradient))
then
2083 density_gradient(1:gr%np, i_dim, is) = density_gradient(1:gr%np, i_dim, is) &
2084 + ww *
m_two * real(psi_gpsi(1:gr%np, 1), real64)
2085 if (st%d%ispin ==
spinors)
then
2086 density_gradient(1:gr%np, i_dim, 2) = density_gradient(1:gr%np, i_dim, 2) &
2087 + ww *
m_two*real(psi_gpsi(1:gr%np, 2), real64)
2090 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)))
2091 density_gradient(ii, i_dim, 3) = density_gradient(ii, i_dim, 3) + real(c_tmp, real64)
2092 density_gradient(ii, i_dim, 4) = density_gradient(ii, i_dim, 4) + aimag(c_tmp)
2097 if (
present(density_laplacian))
then
2098 call lalg_axpy(gr%np, ww*
m_two, abs_gwf_psi(:,1), density_laplacian(:,is))
2099 if (st%d%ispin ==
spinors)
then
2100 call lalg_axpy(gr%np, ww*
m_two, abs_gwf_psi(:,2), density_laplacian(:,2))
2103 c_tmp =
m_two * ww * gwf_psi(ii, i_dim, 1) * conjg(gwf_psi(ii, i_dim, 2))
2104 density_laplacian(ii, 3) = density_laplacian(ii, 3) + real(c_tmp, real64)
2105 density_laplacian(ii, 4) = density_laplacian(ii, 4) + aimag(c_tmp)
2113 if (
associated(jp))
then
2115 jp(1:gr%np, i_dim, is) = jp(1:gr%np, i_dim, is) + &
2116 ww*(aimag(psi_gpsi(1:gr%np, 1)) - abs_wf_psi(1:gr%np, 1)*kpoint(i_dim))
2117 if (st%d%ispin ==
spinors)
then
2118 jp(1:gr%np, i_dim, 2) = jp(1:gr%np, i_dim, 2) + &
2119 ww*( aimag(psi_gpsi(1:gr%np, 2)) - abs_wf_psi(1:gr%np, 2)*kpoint(i_dim))
2122 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)) &
2123 -
m_two *
m_zi*wf_psi(ii, 1)*wf_psi_conj(ii, 2)*kpoint(i_dim))
2124 jp(ii, i_dim, 3) = jp(ii, i_dim, 3) + real(c_tmp, real64)
2125 jp(ii, i_dim, 4) = jp(ii, i_dim, 4) + aimag(c_tmp)
2134 if (
associated(tau))
then
2135 tau(1:gr%np, is) = tau(1:gr%np, is) + ww*(abs_gwf_psi(1:gr%np,1) &
2136 -
m_two*aimag(psi_gpsi(1:gr%np, 1))*kpoint(i_dim))
2137 if (st%d%ispin ==
spinors)
then
2138 tau(1:gr%np, 2) = tau(1:gr%np, 2) + ww*(abs_gwf_psi(1:gr%np, 2) &
2139 -
m_two*aimag(psi_gpsi(1:gr%np, 2))*kpoint(i_dim))
2142 c_tmp = ww * ( gwf_psi(ii, i_dim, 1)*conjg(gwf_psi(ii, i_dim, 2)) &
2143 +
m_zi * (gwf_psi(ii,i_dim,1)*wf_psi_conj(ii, 2) &
2144 - wf_psi(ii, 1)*conjg(gwf_psi(ii,i_dim,2)))*kpoint(i_dim))
2145 tau(ii, 3) = tau(ii, 3) + real(c_tmp, real64)
2146 tau(ii, 4) = tau(ii, 4) + aimag(c_tmp)
2156 safe_deallocate_a(wf_psi_conj)
2157 safe_deallocate_a(abs_wf_psi)
2158 safe_deallocate_a(abs_gwf_psi)
2159 safe_deallocate_a(psi_gpsi)
2161 if (.not.
present(gi_kinetic_energy_density))
then
2162 if (.not.
present(paramagnetic_current))
then
2163 safe_deallocate_p(jp)
2165 if (.not.
present(kinetic_energy_density))
then
2166 safe_deallocate_p(tau)
2170 if (st%parallel_in_states .or. st%d%kpt%parallel)
call reduce_all(st%st_kpt_mpi_grp)
2175 if (st%symmetrize_density)
then
2176 do is = 1, st%d%nspin
2177 if (
associated(tau))
then
2181 if (
present(density_laplacian))
then
2185 if (
associated(jp))
then
2189 if (
present(density_gradient))
then
2196 if (
allocated(st%rho_core) .and. nlcc .and. (
present(density_laplacian) .or.
present(density_gradient)))
then
2198 wf_psi(ii, 1) = st%rho_core(ii)/st%d%spin_channels
2203 if (
present(density_gradient))
then
2206 do is = 1, st%d%spin_channels
2207 density_gradient(1:gr%np, 1:gr%der%dim, is) = density_gradient(1:gr%np, 1:gr%der%dim, is) + &
2208 real(gwf_psi(1:gr%np, 1:gr%der%dim,1))
2213 if (
present(density_laplacian))
then
2216 do is = 1, st%d%spin_channels
2217 density_laplacian(1:gr%np, is) = density_laplacian(1:gr%np, is) + real(lwf_psi(1:gr%np, 1))
2224 if (
allocated(st%frozen_tau) .and. .not.
present(st_end))
then
2227 if (
allocated(st%frozen_gdens) .and. .not.
present(st_end))
then
2228 do is = 1, st%d%nspin
2229 call lalg_axpy(gr%np, gr%der%dim,
m_one, st%frozen_gdens(:,:,is), density_gradient(:,:,is))
2232 if (
allocated(st%frozen_tau) .and. .not.
present(st_end))
then
2233 call lalg_axpy(gr%np, st%d%nspin,
m_one, st%frozen_ldens, density_laplacian)
2236 safe_deallocate_a(wf_psi)
2237 safe_deallocate_a(gwf_psi)
2238 safe_deallocate_a(lwf_psi)
2242 if (
present(gi_kinetic_energy_density))
then
2243 do is = 1, st%d%nspin
2244 assert(
associated(tau))
2245 gi_kinetic_energy_density(1:gr%np, is) = tau(1:gr%np, is)
2248 assert(
associated(jp))
2249 if (st%d%ispin /=
spinors)
then
2250 do is = 1, st%d%nspin
2253 if (st%rho(ii, is) < 1.0e-7_real64) cycle
2254 gi_kinetic_energy_density(ii, is) = &
2255 gi_kinetic_energy_density(ii, is) - sum(jp(ii,1:gr%der%dim, is)**2)/st%rho(ii, is)
2261 gi_kinetic_energy_density(ii, 1) = gi_kinetic_energy_density(ii, 1) &
2262 - sum(jp(ii,1:gr%der%dim, 1)**2)/(safe_tol(st%rho(ii, 1),
m_epsilon))
2263 gi_kinetic_energy_density(ii, 2) = gi_kinetic_energy_density(ii, 2) &
2264 - sum(jp(ii,1:gr%der%dim, 2)**2)/(safe_tol(st%rho(ii, 2),
m_epsilon))
2265 gi_kinetic_energy_density(ii, 3) = &
2266 gi_kinetic_energy_density(ii, 3) - sum(jp(ii,1:gr%der%dim, 3)**2 + jp(ii,1:gr%der%dim, 4)**2) &
2267 /(safe_tol((st%rho(ii, 3)**2 + st%rho(ii, 4)**2),
m_epsilon))*st%rho(ii, 3)
2268 gi_kinetic_energy_density(ii, 4) = &
2269 gi_kinetic_energy_density(ii, 4) + sum(jp(ii,1:gr%der%dim, 3)**2 + jp(ii,1:gr%der%dim, 4)**2) &
2270 /(safe_tol((st%rho(ii, 3)**2 + st%rho(ii, 4)**2),
m_epsilon))*st%rho(ii, 4)
2276 if (.not.
present(kinetic_energy_density))
then
2277 safe_deallocate_p(tau)
2279 if (.not.
present(paramagnetic_current))
then
2280 safe_deallocate_p(jp)
2295 if (
associated(tau))
call comm_allreduce(grp, tau, dim = (/gr%np, st%d%nspin/))
2297 if (
present(density_laplacian))
call comm_allreduce(grp, density_laplacian, dim = (/gr%np, st%d%nspin/))
2299 do is = 1, st%d%nspin
2300 if (
associated(jp))
call comm_allreduce(grp, jp(:, :, is), dim = (/gr%np, gr%der%dim/))
2302 if (
present(density_gradient))
then
2303 call comm_allreduce(grp, density_gradient(:, :, is), dim = (/gr%np, gr%der%dim/))
2317 type(
mesh_t),
intent(in) :: mesh
2318 complex(real64),
intent(in) :: f1(:, :)
2319 real(real64) :: spin(1:3)
2321 complex(real64) :: z
2325 z =
zmf_dotp(mesh, f1(:, 1) , f1(:, 2))
2327 spin(1) =
m_two*real(z, real64)
2328 spin(2) =
m_two*aimag(z)
2340 integer,
intent(in) :: ist
2354 integer,
intent(in) :: ist
2355 integer,
intent(in) :: ik
2360 ik >= st%d%kpt%start .and. ik <= st%d%kpt%end
2370 class(
mesh_t),
intent(in) :: mesh
2376 memory = memory + real64*real(mesh%np_part_global, real64) *st%d%dim*real(st%nst, real64) *st%d%kpt%nglobal
2386 logical,
optional,
intent(in) :: copy
2389 integer(int64) :: max_mem, mem
2401 if (accel_is_enabled())
then
2402 max_mem = accel_global_memory_size()
2404 if (st%gpu_states_mem > m_one)
then
2405 max_mem = int(st%gpu_states_mem, int64)*(1024_8)**2
2406 else if (st%gpu_states_mem < 0.0_real64)
then
2407 max_mem = max_mem + int(st%gpu_states_mem, int64)*(1024_8)**2
2409 max_mem = int(st%gpu_states_mem*real(max_mem, real64) , int64)
2412 max_mem = huge(max_mem)
2416 qnloop:
do iqn = st%d%kpt%start, st%d%kpt%end
2417 do ib = st%group%block_start, st%group%block_end
2419 mem = mem + st%group%psib(ib, iqn)%pack_total_size()
2421 if (mem > max_mem)
then
2422 call messages_write(
'Not enough CL device memory to store all states simultaneously.', new_line = .
true.)
2423 call messages_write(
'Only ')
2424 call messages_write(ib - st%group%block_start)
2425 call messages_write(
' of ')
2426 call messages_write(st%group%block_end - st%group%block_start + 1)
2427 call messages_write(
' blocks will be stored in device memory.', new_line = .
true.)
2428 call messages_warning()
2432 call st%group%psib(ib, iqn)%do_pack(copy)
2444 logical,
optional,
intent(in) :: copy
2453 do iqn = st%d%kpt%start, st%d%kpt%end
2454 do ib = st%group%block_start, st%group%block_end
2455 if (st%group%psib(ib, iqn)%is_packed())
call st%group%psib(ib, iqn)%do_unpack(copy)
2468 type(namespace_t),
intent(in) :: namespace
2472 call messages_print_with_emphasis(msg=
"States", namespace=namespace)
2474 write(message(1),
'(a,f12.3)')
'Total electronic charge = ', st%qtot
2475 write(message(2),
'(a,i8)')
'Number of states = ', st%nst
2476 write(message(3),
'(a,i8)')
'States block-size = ', st%block_size
2477 call messages_info(3, namespace=namespace)
2479 call messages_print_with_emphasis(namespace=namespace)
2492 do iqn = st%d%kpt%start, st%d%kpt%end
2493 do ib = st%group%block_start, st%group%block_end
2494 call batch_set_zero(st%group%psib(ib, iqn))
2504 integer pure function states_elec_block_min(st, ib) result(range)
2506 integer,
intent(in) :: ib
2508 range = st%group%block_range(ib, 1)
2514 integer pure function states_elec_block_max(st, ib) result(range)
2516 integer,
intent(in) :: ib
2518 range = st%group%block_range(ib, 2)
2524 integer pure function states_elec_block_size(st, ib) result(size)
2526 integer,
intent(in) :: ib
2528 size = st%group%block_size(ib)
2536 type(namespace_t),
intent(in) :: namespace
2537 integer,
intent(out) :: n_pairs
2538 integer,
intent(out) :: n_occ(:)
2539 integer,
intent(out) :: n_unocc(:)
2540 logical,
allocatable,
intent(out) :: is_included(:,:,:)
2542 logical,
intent(out) :: is_frac_occ
2544 integer :: ik, ist, ast, n_filled, n_partially_filled, n_half_filled
2545 character(len=80) :: nst_string, default, wfn_list
2546 real(real64) :: energy_window
2550 is_frac_occ = .false.
2552 call occupied_states(st, namespace, ik, n_filled, n_partially_filled, n_half_filled)
2553 if (n_partially_filled > 0 .or. n_half_filled > 0) is_frac_occ = .
true.
2554 n_occ(ik) = n_filled + n_partially_filled + n_half_filled
2555 n_unocc(ik) = st%nst - n_filled
2568 call parse_variable(namespace,
'CasidaKSEnergyWindow', -m_one, energy_window, units_inp%energy)
2591 safe_allocate(is_included(maxval(n_occ), minval(n_occ) + 1:st%nst , st%nik))
2592 is_included(:,:,:) = .false.
2594 if (energy_window < m_zero)
then
2595 write(nst_string,
'(i6)') st%nst
2596 write(default,
'(a,a)')
"1-", trim(adjustl(nst_string))
2597 call parse_variable(namespace,
'CasidaKohnShamStates', default, wfn_list)
2599 write(message(1),
'(a,a)')
"Info: States that form the basis: ", trim(wfn_list)
2600 call messages_info(1, namespace=namespace)
2605 do ast = n_occ(ik) + 1, st%nst
2606 if (loct_isinstringlist(ast, wfn_list))
then
2607 do ist = 1, n_occ(ik)
2608 if (loct_isinstringlist(ist, wfn_list))
then
2609 n_pairs = n_pairs + 1
2610 is_included(ist, ast, ik) = .
true.
2619 write(message(1),
'(a,f12.6,a)')
"Info: including transitions with energy < ", &
2620 units_from_atomic(units_out%energy, energy_window), trim(units_abbrev(units_out%energy))
2621 call messages_info(1, namespace=namespace)
2626 do ast = n_occ(ik) + 1, st%nst
2627 do ist = 1, n_occ(ik)
2628 if (st%eigenval(ast, ik) - st%eigenval(ist, ik) < energy_window)
then
2629 n_pairs = n_pairs + 1
2630 is_included(ist, ast, ik) = .
true.
2658 subroutine occupied_states(st, namespace, ik, n_filled, n_partially_filled, n_half_filled, &
2659 filled, partially_filled, half_filled)
2661 type(namespace_t),
intent(in) :: namespace
2662 integer,
intent(in) :: ik
2663 integer,
intent(out) :: n_filled, n_partially_filled, n_half_filled
2664 integer,
optional,
intent(out) :: filled(:), partially_filled(:), half_filled(:)
2670 if (
present(filled)) filled(:) = 0
2671 if (
present(partially_filled)) partially_filled(:) = 0
2672 if (
present(half_filled)) half_filled(:) = 0
2674 n_partially_filled = 0
2677 select case (st%d%ispin)
2680 if (abs(st%occ(ist, ik) - m_two) < m_min_occ)
then
2681 n_filled = n_filled + 1
2682 if (
present(filled)) filled(n_filled) = ist
2683 else if (abs(st%occ(ist, ik) - m_one) < m_min_occ)
then
2684 n_half_filled = n_half_filled + 1
2685 if (
present(half_filled)) half_filled(n_half_filled) = ist
2686 else if (st%occ(ist, ik) > m_min_occ)
then
2687 n_partially_filled = n_partially_filled + 1
2688 if (
present(partially_filled)) partially_filled(n_partially_filled) = ist
2689 else if (abs(st%occ(ist, ik)) > m_min_occ)
then
2690 write(message(1),*)
'Internal error in occupied_states: Illegal occupation value ', st%occ(ist, ik)
2691 call messages_fatal(1, namespace=namespace)
2694 case (spin_polarized, spinors)
2696 if (abs(st%occ(ist, ik)-m_one) < m_min_occ)
then
2697 n_filled = n_filled + 1
2698 if (
present(filled)) filled(n_filled) = ist
2699 else if (st%occ(ist, ik) > m_min_occ)
then
2700 n_partially_filled = n_partially_filled + 1
2701 if (
present(partially_filled)) partially_filled(n_partially_filled) = ist
2702 else if (abs(st%occ(ist, ik)) > m_min_occ)
then
2703 write(message(1),*)
'Internal error in occupied_states: Illegal occupation value ', st%occ(ist, ik)
2704 call messages_fatal(1, namespace=namespace)
2716 type(multicomm_t),
intent(in) :: mc
2719 call distributed_init(this%d%kpt, this%nik, mc%group_comm(p_strategy_kpoints),
"k-points")
2734 if (.not.
allocated(st%st_kpt_task))
then
2735 safe_allocate(st%st_kpt_task(0:st%st_kpt_mpi_grp%size-1, 1:4))
2738 st%st_kpt_task(0:st%st_kpt_mpi_grp%size-1, :) = 0
2739 st%st_kpt_task(st%st_kpt_mpi_grp%rank, :) = [st%st_start, st%st_end, st%d%kpt%start, st%d%kpt%end]
2741 if (st%parallel_in_states .or. st%d%kpt%parallel)
then
2742 call comm_allreduce(st%st_kpt_mpi_grp, st%st_kpt_task)
2753 type(kpoints_t),
intent(in) :: kpoints
2754 type(namespace_t),
intent(in) :: namespace
2757 type(states_elec_dim_t),
pointer :: dd
2764 st%nik = kpoints_number(kpoints)
2766 if (dd%ispin == spin_polarized) st%nik = 2*st%nik
2768 safe_allocate(st%kweights(1:st%nik))
2771 ik = dd%get_kpoint_index(iq)
2772 st%kweights(iq) = kpoints%get_weight(ik)
2784 call io_mkdir(
'debug/', namespace)
2785 iunit = io_open(
'debug/kpoints', namespace, action =
'write')
2786 call kpoints%write_info(iunit=iunit, absolute_coordinates = .
true.)
2787 call io_close(iunit)
2801 class(mesh_t),
intent(in) :: gr
2802 real(real64) :: dipole(1:gr%box%dim)
2805 real(real64) :: e_dip(1:gr%box%dim, this%d%spin_channels)
2809 do ispin = 1, this%d%spin_channels
2810 call dmf_dipole(gr, this%rho(:, ispin), e_dip(:, ispin))
2813 dipole(:) = sum(e_dip(:, 1:this%d%spin_channels), 2)
2821#include "states_elec_inc.F90"
2824#include "complex.F90"
2825#include "states_elec_inc.F90"
initialize a batch with existing memory
constant times a vector plus a vector
Prints out to iunit a message in the form: ["InputVariable" = value] where "InputVariable" is given b...
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_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)
@Brief 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
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_fill_occupations(this, eigenvalues, occupations, nik, nst)
subroutine, public smear_find_fermi_energy(this, namespace, eigenvalues, occupations, qtot, nik, nst, kweights)
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)
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)
@Brief. 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_count_pairs(st, namespace, n_pairs, n_occ, n_unocc, is_included, is_frac_occ)
number of occupied-unoccupied pairs for Casida
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), public type_float
type(type_t), public type_cmplx
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.