26 use,
intrinsic :: iso_fortran_env
56 integer,
public :: method
57 real(real64),
public :: dsmear
58 real(real64) :: dsmear_cond
59 real(real64),
public :: e_fermi
60 real(real64) :: e_fermi_cond
62 integer,
public :: el_per_state
63 real(real64),
public :: ef_occ
64 real(real64) :: ef_occ_cond
65 logical,
public :: integral_occs
67 integer :: fermi_count
72 logical,
public:: photodop
73 real(real64) :: nephotodop
74 integer :: photodop_bandmin
78 integer,
parameter,
public :: &
79 SMEAR_SEMICONDUCTOR = 1, &
86 real(real64),
parameter :: TOL_SMEAR = 1e-6_real64
91 subroutine smear_init(this, namespace, ispin, fixed_occ, integral_occs, kpoints)
92 type(smear_t),
intent(out) :: this
93 type(namespace_t),
intent(in) :: namespace
94 integer,
intent(in) :: ispin
95 logical,
intent(in) :: fixed_occ
96 logical,
intent(in) :: integral_occs
97 type(kpoints_t),
intent(in) :: kpoints
101 this%integral_occs = integral_occs
129 call parse_variable(namespace,
'SmearingFunction', smear_semiconductor, this%method)
143 this%dsmear = 1e-14_real64
144 if (this%method /= smear_semiconductor .and. this%method /=
smear_fixed_occ)
then
157 this%dsmear_cond = this%dsmear
175 this%photodop=.false.
186 call parse_variable(namespace,
'PhotoDopingBand', 1, this%photodop_bandmin)
192 this%el_per_state = 2
194 this%el_per_state = 1
203 if (this%method == smear_semiconductor)
then
206 if (this%nik_factor == 0)
then
207 message(1) =
"k-point weights in KPoints or KPointsReduced blocks must be rational numbers for semiconducting smearing."
230 type(
smear_t),
intent(out) :: to
231 type(
smear_t),
intent(in) :: from
235 to%method = from%method
236 to%dsmear = from%dsmear
237 to%e_fermi = from%e_fermi
238 to%el_per_state = from%el_per_state
239 to%ef_occ = from%ef_occ
241 to%fermi_count = from%fermi_count
242 to%nik_factor = from%nik_factor
250 qtot, nik, nst, kweights)
251 type(
smear_t),
intent(inout) :: this
253 real(real64),
intent(in) :: eigenvalues(:,:), occupations(:,:)
254 real(real64),
intent(in) :: qtot, kweights(:)
255 integer,
intent(in) :: nik, nst
257 real(real64),
parameter :: tol = 1.0e-10_real64
258 integer :: ist, ik, iter, maxq, weight, sumq_int, sum_weight
259 real(real64) :: sumq_frac
261 real(real64),
allocatable :: eigenval_list(:)
262 integer,
allocatable :: k_list(:), reorder(:)
263 integer :: fermi_count_up, fermi_count_down
267 maxq = this%el_per_state * nst * this%nspins
268 if (maxq - qtot <= -tol)
then
269 message(1) =
'Not enough states'
270 write(
message(2),
'(6x,a,f12.6,a,i10)')
'(total charge = ', qtot, &
271 ' max charge = ', maxq
277 ist_cycle:
do ist = nst, 1, -1
279 if (occupations(ist, ik) >
m_min_occ)
then
280 this%e_fermi = eigenvalues(ist, ik)
281 this%ef_occ = occupations(ist, ik) / this%el_per_state
288 else if (this%method == smear_semiconductor)
then
290 safe_allocate(eigenval_list(1:nst * nik))
291 safe_allocate( k_list(1:nst * nik))
292 safe_allocate( reorder(1:nst * nik))
297 eigenval_list(iter) = eigenvalues(ist, ik)
304 call sort(eigenval_list, reorder)
306 sumq_int =
floor(qtot) * this%nik_factor
307 sumq_frac = qtot * this%nik_factor - sumq_int
308 if ( sumq_frac + tol > this%nik_factor )
then
309 sumq_int = sumq_int + this%nik_factor
310 sumq_frac = sumq_frac - this%nik_factor
312 if (sumq_frac < tol) sumq_frac =
m_zero
314 do iter = 1, nst * nik
315 weight = int(kweights(k_list(reorder(iter))) * this%nik_factor +
m_half)
316 if (.not. weight > 0) cycle
317 this%e_fermi = eigenval_list(iter)
318 this%ef_occ = (sumq_int + sumq_frac) / (weight * this%el_per_state)
320 if (sumq_int - weight * this%el_per_state <= 0)
then
328 if (iter - fermi_count_down < 1)
exit
329 if (abs(this%e_fermi - eigenval_list(iter - fermi_count_down)) > tol_smear)
exit
330 weight = int(kweights(k_list(reorder(iter - fermi_count_down))) * this%nik_factor +
m_half)
332 sumq_int = sumq_int + weight * this%el_per_state
333 sum_weight = sum_weight + weight
335 fermi_count_down = fermi_count_down + 1
338 if (iter + fermi_count_up > nst*nik)
exit
339 if (abs(this%e_fermi - eigenval_list(iter + fermi_count_up)) > tol_smear)
exit
340 weight = int(kweights(k_list(reorder(iter + fermi_count_up))) * this%nik_factor +
m_half)
342 sum_weight = sum_weight + weight
344 fermi_count_up = fermi_count_up + 1
346 this%fermi_count = fermi_count_up + fermi_count_down - 1
347 this%ef_occ = (sumq_int + sumq_frac) / (sum_weight * this%el_per_state)
351 sumq_int = sumq_int - weight * this%el_per_state
355 safe_deallocate_a(eigenval_list)
356 safe_deallocate_a(k_list)
357 safe_deallocate_a(reorder)
360 if (this%photodop)
then
363 eigenvalues, kweights, nik, qtot-this%nephotodop, 1, this%photodop_bandmin-1, &
364 this%e_fermi, this%ef_occ)
368 eigenvalues, kweights, nik, this%nephotodop, this%photodop_bandmin, nst, &
369 this%e_fermi_cond, this%ef_occ_cond)
372 eigenvalues, kweights, nik, qtot, 1, nst, this%e_fermi, this%ef_occ)
381 eigenvalues, kweights, nik, q_in, start_band, end_band, e_fermi, ef_occ)
382 type(
smear_t),
intent(inout) :: this
384 real(real64),
intent(in) :: dsmear_in
385 real(real64),
intent(in) :: tol
386 integer,
intent(in) :: nik
387 real(real64),
intent(in) :: eigenvalues(:,:)
388 real(real64),
intent(in) :: kweights(:), q_in
389 integer,
intent(in) :: start_band, end_band
390 real(real64),
intent(out) :: e_fermi, ef_occ
392 integer,
parameter :: nitmax = 200
393 integer :: ist, ik, iter
394 real(real64) :: drange, dsmear, emin, emax, xx, sumq
399 dsmear = max(1e-14_real64, dsmear_in)
400 drange = dsmear *
sqrt(-
log(tol * 0.01_real64))
402 emin = minval(eigenvalues) - drange
403 emax = maxval(eigenvalues) + drange
406 e_fermi =
m_half * (emin + emax)
410 do ist = start_band, end_band
411 xx = (e_fermi - eigenvalues(ist, ik))/dsmear
412 sumq = sumq + kweights(ik) * this%el_per_state * &
417 conv = (abs(sumq - q_in) <= tol)
420 if (sumq <= q_in) emin = e_fermi
421 if (sumq >= q_in) emax = e_fermi
427 message(1) =
'Fermi: did not converge.'
436 type(
smear_t),
intent(in) :: this
437 real(real64),
intent(in) :: eigenvalues(:,:)
438 real(real64),
intent(inout) :: occupations(:,:)
439 integer,
intent(in) :: nik, nst
441 integer :: ik, ist, ifermi
442 real(real64) :: dsmear, xx, dsmear_cond
448 else if (this%method == smear_semiconductor)
then
449 assert(this%fermi_count > 0 .and. this%fermi_count <= nik*nst)
454 xx = eigenvalues(ist, ik) - this%e_fermi
455 if (xx < -tol_smear)
then
456 occupations(ist, ik) = this%el_per_state
457 else if (abs(xx) <= tol_smear .and. ifermi < this%fermi_count)
then
458 occupations(ist, ik) = this%ef_occ * this%el_per_state
461 occupations(ist, ik) =
m_zero
468 dsmear = max(1e-14_real64, this%dsmear)
469 if (this%photodop)
then
470 dsmear_cond = max(1e-14_real64, this%dsmear_cond)
473 if (ist < this%photodop_bandmin)
then
475 xx = (this%e_fermi - eigenvalues(ist, ik))/dsmear
478 xx = (this%e_fermi_cond - eigenvalues(ist, ik))/dsmear_cond
486 xx = (this%e_fermi - eigenvalues(ist, ik))/dsmear
498 real(real64) function smear_calc_entropy(this, eigenvalues, &
499 nik, nst, kweights, occ) result(entropy)
500 type(
smear_t),
intent(inout) :: this
501 real(real64),
intent(in) :: eigenvalues(:,:)
502 real(real64),
intent(in) :: kweights(:)
503 integer,
intent(in) :: nik, nst
504 real(real64),
intent(in) :: occ(:, :)
507 real(real64) :: dsmear, xx, term, ff
509 push_sub(smear_calc_entropy)
513 if (this%method ==
smear_fixed_occ .or. this%method == smear_semiconductor)
then
519 ff = occ(ist, ik) / this%el_per_state
521 term = ff *
log(ff) + (1 - ff) *
log(1 - ff)
525 entropy = entropy - kweights(ik) * this%el_per_state * term
529 dsmear = max(1e-14_real64, this%dsmear)
533 if (eigenvalues(ist, ik) < huge(
m_one))
then
534 xx = (this%e_fermi - eigenvalues(ist, ik)) / dsmear
535 entropy = entropy - kweights(ik) * this%el_per_state * &
542 pop_sub(smear_calc_entropy)
548 type(
smear_t),
intent(in) :: this
549 real(real64),
intent(in) :: xx
551 real(real64),
parameter :: maxarg = 200.0_real64
552 real(real64) :: xp, arg, hd, hp, aa
561 select case (this%method)
563 if (abs(xx) <= m_epsilon)
then
568 if (abs(xx) <= 36.0_real64)
then
569 deltaf = m_one / (m_two +
exp(-xx) +
exp(xx))
573 xp = xx - m_one /
sqrt(m_two)
574 arg = min(maxarg, xp**2)
576 deltaf =
exp(-arg) /
sqrt(m_pi) * (m_two -
sqrt(m_two) * xx)
579 arg = min(maxarg, xx**2)
580 deltaf =
exp(-arg) /
sqrt(m_pi)
582 if (this%MP_n > 0)
then
586 aa = m_one /
sqrt(m_pi)
588 hd = m_two * xx * hp - m_two * ni * hd
590 aa = -aa / (m_four * ii)
591 hp = m_two * xx * hd - m_two * ni * hp
593 deltaf = deltaf + aa * hp
598 xp = abs(xx) + m_one /
sqrt(m_two)
599 deltaf =
sqrt(m_e) * xp *
exp(-xp * xp)
608 type(
smear_t),
intent(in) :: this
609 real(real64),
intent(in) :: xx
611 real(real64),
parameter :: maxarg = 200.0_real64
612 real(real64) :: xp, arg, hd, hp, aa
621 select case (this%method)
623 if (xx > m_zero)
then
625 else if (abs(xx) <= m_epsilon)
then
630 if (xx > maxarg)
then
632 else if (xx > -maxarg)
then
633 stepf = m_one / (m_one +
exp(-xx))
637 xp = xx - m_one /
sqrt(m_two)
638 arg = min(maxarg, xp**2)
640 stepf = m_half * loct_erf(xp) + &
641 m_one /
sqrt(m_two * m_pi) *
exp(-arg) + m_half
644 stepf = m_half * loct_erfc(-xx)
646 if (this%MP_n > 0)
then
648 arg = min(maxarg, xx**2)
651 aa = m_one /
sqrt(m_pi)
653 hd = m_two * xx * hp - m_two * ni * hd
655 aa = -aa / (m_four * ii)
656 stepf = stepf - aa * hd
657 hp = m_two * xx * hd - m_two * ni * hp
663 if (xx <= m_zero)
then
664 xp = xx - m_one /
sqrt(m_two)
665 stepf = m_half *
sqrt(m_e) *
exp(-xp * xp)
667 xp = xx + m_one /
sqrt(m_two)
668 stepf = m_one - m_half *
sqrt(m_e) *
exp(-xp * xp)
680 type(
smear_t),
intent(in) :: this
681 real(real64),
intent(in) :: xx
683 real(real64),
parameter :: maxarg = 200.0_real64
684 real(real64) :: xp, arg, hd, hp, hpm1, aa
693 select case (this%method)
697 if (abs(xx) <= 36.0_real64)
then
698 xp = m_one / (m_one +
exp(-xx))
699 entropyf = xp *
log(xp) + (m_one - xp) *
log(m_one - xp)
703 xp = xx - m_one /
sqrt(m_two)
704 arg = min(maxarg, xp**2)
706 entropyf = m_one /
sqrt(m_two * m_pi) * xp *
exp(-arg)
709 arg = min(maxarg, xx**2)
710 entropyf = -m_half *
exp(-arg) /
sqrt(m_pi)
712 if (this%MP_n > 0)
then
716 aa = m_one /
sqrt(m_pi)
718 hd = m_two * xx * hp - m_two * ni * hd
721 hp = m_two * xx * hd - m_two * ni * hp
723 aa = -aa / (m_four * ii)
724 entropyf = entropyf - aa * (m_half * hp + hpm1 * ni)
729 xp = abs(xx) + m_one /
sqrt(m_two)
730 entropyf = -
sqrt(m_e) * (abs(xx) *
exp(-xp * xp) / m_two +
sqrt(m_pi) / m_four * loct_erfc(xp))
740 type(
smear_t),
intent(in) :: this
747 type(
smear_t),
intent(in) :: this
748 type(namespace_t),
intent(in) :: namespace
749 integer,
optional,
intent(in) :: iunit
753 if (this%photodop)
then
754 write(message(1),
'(a,f12.6,1x,a)')
"Fermi energy (valence ) = ", &
755 units_from_atomic(units_out%energy, this%e_fermi), units_abbrev(units_out%energy)
756 write(message(2),
'(a,f12.6,1x,a)')
"Fermi energy (conduction) = ", &
757 units_from_atomic(units_out%energy, this%e_fermi_cond), units_abbrev(units_out%energy)
758 call messages_info(2, iunit=iunit, namespace=namespace)
760 write(message(1),
'(a,f12.6,1x,a)')
"Fermi energy = ", &
761 units_from_atomic(units_out%energy, this%e_fermi), units_abbrev(units_out%energy)
762 call messages_info(1, iunit=iunit, namespace=namespace)
This is the common interface to a sorting routine. It performs the shell algorithm,...
double log(double __x) __attribute__((__nothrow__
double exp(double __x) __attribute__((__nothrow__
double sqrt(double __x) __attribute__((__nothrow__
double floor(double __x) __attribute__((__nothrow__
real(real64), parameter, public m_two
real(real64), parameter, public m_zero
real(real64), parameter, public p_ry
real(real64), parameter, public m_epsilon
real(real64), parameter, public m_half
real(real64), parameter, public m_one
real(real64), parameter, public m_min_occ
Minimal occupation that is considered to be non-zero.
integer function, public kpoints_kweight_denominator(this)
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)
real(real64) function, public smear_calc_entropy(this, eigenvalues, nik, nst, kweights, occ)
subroutine, public smear_fill_occupations(this, eigenvalues, occupations, nik, nst)
subroutine, public smear_find_fermi_energy(this, namespace, eigenvalues, occupations, qtot, nik, nst, kweights)
real(real64) function, public smear_entropy_function(this, xx)
This function is defined as .
real(real64) function, public smear_delta_function(this, xx)
integer, parameter, public smear_fermi_dirac
integer, parameter, public smear_methfessel_paxton
subroutine, public smear_write_info(this, namespace, iunit)
real(real64) function, public smear_step_function(this, xx)
integer, parameter, public smear_semiconductor
subroutine, public smear_copy(to, from)
integer, parameter, public smear_fixed_occ
integer, parameter, public smear_spline
subroutine bisection_find_fermi_energy(this, namespace, dsmear_in, tol, eigenvalues, kweights, nik, q_in, start_band, end_band, e_fermi, ef_occ)
subroutine, public smear_init(this, namespace, ispin, fixed_occ, integral_occs, kpoints)
integer, parameter, public smear_cold
logical pure function, public smear_is_semiconducting(this)
This module is intended to contain "only mathematical" functions and procedures.
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_system_t), public units_inp
the units systems for reading and writing