Removes warnings from overflow and from scipy bug
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
3cda66441e
commit
54917655cd
@ -2,6 +2,7 @@ import numpy # type: ignore
|
||||
import scipy.integrate as integrate # type: ignore
|
||||
import scipy.optimize # type: ignore
|
||||
import logging
|
||||
import warnings
|
||||
|
||||
from typing import Tuple
|
||||
|
||||
@ -69,8 +70,10 @@ def n_integral(temp: float, delta: float, mu_star: float) -> float:
|
||||
return n_integrand_function(xi, temp, delta, mu_star)
|
||||
intermediate = 20 * numpy.sqrt(delta ** 2 + mu_star ** 2)
|
||||
lower = integrate.quad(integrand, 0, intermediate)[0]
|
||||
upper = integrate.quad(integrand, intermediate, numpy.inf)[0]
|
||||
return lower + upper
|
||||
# upper = integrate.quad(integrand, intermediate, numpy.inf)[0]
|
||||
# This upper portion of the integral will typically be completely
|
||||
# negligible, because we're 20x the relevant scale here.
|
||||
return lower
|
||||
|
||||
|
||||
def find_gap_for_n(
|
||||
@ -81,12 +84,17 @@ def find_gap_for_n(
|
||||
) -> Tuple[float, float]:
|
||||
n = n_bare * find_gap(0, 0, debye_frequency, nv)
|
||||
nv_inv = 1 / nv
|
||||
sol = scipy.optimize.root(
|
||||
lambda x: [
|
||||
gap_integral(temp, x[0], x[1], debye_frequency) - nv_inv,
|
||||
n_integral(temp, x[0], x[1]) - n
|
||||
],
|
||||
x0=[debye_frequency / (numpy.sinh(nv_inv)), 0]
|
||||
)
|
||||
logging.debug(sol)
|
||||
return sol.x
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings(
|
||||
"ignore",
|
||||
message="Creating an ndarray from ragged nested"
|
||||
)
|
||||
sol = scipy.optimize.root(
|
||||
lambda x: [
|
||||
gap_integral(temp, x[0], x[1], debye_frequency) - nv_inv,
|
||||
n_integral(temp, x[0], x[1]) - n
|
||||
],
|
||||
x0=[debye_frequency / (numpy.sinh(nv_inv)), 0]
|
||||
)
|
||||
logging.debug(sol)
|
||||
return sol.x
|
||||
|
@ -70,9 +70,12 @@ def test_n_integral():
|
||||
|
||||
|
||||
def test_find_n_gap():
|
||||
actual = pysuperconductor.os_gap_calc.find_gap_for_n(.3, .1, 100, .2)
|
||||
actual = None
|
||||
with pytest.warns(None) as record:
|
||||
actual = pysuperconductor.os_gap_calc.find_gap_for_n(.3, .1, 100, .2)
|
||||
numpy.testing.assert_almost_equal(
|
||||
actual[0], 1.0296692197710933,
|
||||
decimal=7, err_msg="did not find correct delta",
|
||||
verbose=True
|
||||
)
|
||||
assert not record
|
||||
|
Loading…
x
Reference in New Issue
Block a user