uses scipy expit to handle overflow smarter
All checks were successful
gitea-physics/pysuperconductor/pipeline/head This commit looks good
All checks were successful
gitea-physics/pysuperconductor/pipeline/head This commit looks good
This commit is contained in:
parent
54917655cd
commit
bba1643c76
@ -1,6 +1,7 @@
|
|||||||
import numpy # type: ignore
|
import numpy # type: ignore
|
||||||
import scipy.integrate as integrate # type: ignore
|
import scipy.integrate as integrate # type: ignore
|
||||||
import scipy.optimize # type: ignore
|
import scipy.optimize # type: ignore
|
||||||
|
import scipy.special # type: ignore
|
||||||
import logging
|
import logging
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
@ -59,8 +60,8 @@ def n_integrand_function(
|
|||||||
xi: float, temp: float, delta: float, mu_star: float
|
xi: float, temp: float, delta: float, mu_star: float
|
||||||
) -> float:
|
) -> float:
|
||||||
big_e = energy(xi, delta)
|
big_e = energy(xi, delta)
|
||||||
left = 1 / (1 + numpy.exp((big_e - mu_star) / temp))
|
left = scipy.special.expit((mu_star - big_e) / temp)
|
||||||
right = 1 / (1 + numpy.exp(big_e / temp))
|
right = scipy.special.expit(- big_e / temp)
|
||||||
return left - right
|
return left - right
|
||||||
|
|
||||||
|
|
||||||
@ -70,10 +71,8 @@ def n_integral(temp: float, delta: float, mu_star: float) -> float:
|
|||||||
return n_integrand_function(xi, temp, delta, mu_star)
|
return n_integrand_function(xi, temp, delta, mu_star)
|
||||||
intermediate = 20 * numpy.sqrt(delta ** 2 + mu_star ** 2)
|
intermediate = 20 * numpy.sqrt(delta ** 2 + mu_star ** 2)
|
||||||
lower = integrate.quad(integrand, 0, intermediate)[0]
|
lower = integrate.quad(integrand, 0, intermediate)[0]
|
||||||
# upper = integrate.quad(integrand, intermediate, numpy.inf)[0]
|
upper = integrate.quad(integrand, intermediate, numpy.inf)[0]
|
||||||
# This upper portion of the integral will typically be completely
|
return lower + upper
|
||||||
# negligible, because we're 20x the relevant scale here.
|
|
||||||
return lower
|
|
||||||
|
|
||||||
|
|
||||||
def find_gap_for_n(
|
def find_gap_for_n(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user