adding tighter error tolerances and adding checks for imrpl
This commit is contained in:
parent
622af16142
commit
a7c33fb5df
15
pynam/noise/im_ref.py
Normal file
15
pynam/noise/im_ref.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
from typing import Callable
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
import pynam.noise.zeta
|
||||||
|
|
||||||
|
|
||||||
|
def get_im_ref_p(eps: Callable[[float], complex]) -> Callable[[float], float]:
|
||||||
|
zeta_p = pynam.noise.zeta.get_zeta_p_function(eps)
|
||||||
|
|
||||||
|
def im_ref_p(u: float) -> float:
|
||||||
|
zeta_p_val = zeta_p(u)
|
||||||
|
return np.imag((np.pi * 1j * u - zeta_p_val) / (np.pi * 1j * u + zeta_p_val))
|
||||||
|
|
||||||
|
return im_ref_p
|
@ -62,10 +62,10 @@ def get_zeta_p_function(eps: Callable[[float], complex]):
|
|||||||
def zeta_p(u: float) -> complex:
|
def zeta_p(u: float) -> complex:
|
||||||
zeta_p_integrand = get_zeta_p_integrand(eps)
|
zeta_p_integrand = get_zeta_p_integrand(eps)
|
||||||
|
|
||||||
i1_small = pynam.util.complex_quad(lambda x: integrand1_small_x(x, u), 0, SMALL_X_BOUNDARY)
|
i1_small = pynam.util.complex_quad(lambda x: integrand1_small_x(x, u), 0, SMALL_X_BOUNDARY, epsabs=1e-12)
|
||||||
i1_big = pynam.util.complex_quad(lambda x: integrand1_big_x(x, u), SMALL_X_BOUNDARY, np.inf)
|
i1_big = pynam.util.complex_quad(lambda x: integrand1_big_x(x, u), SMALL_X_BOUNDARY, np.inf, epsabs=1e-12)
|
||||||
i2_small = pynam.util.complex_quad(lambda x: integrand2_small_x(x, u), 0, SMALL_X_BOUNDARY)
|
i2_small = pynam.util.complex_quad(lambda x: integrand2_small_x(x, u), 0, SMALL_X_BOUNDARY, epsabs=1e-12)
|
||||||
i2_big = pynam.util.complex_quad(lambda x: integrand2_big_x(x, u), SMALL_X_BOUNDARY, np.inf)
|
i2_big = pynam.util.complex_quad(lambda x: integrand2_big_x(x, u), SMALL_X_BOUNDARY, np.inf, epsabs=1e-12)
|
||||||
|
|
||||||
integral = sum(term[0] for term in [i1_small, i2_small, i1_big, i2_big])
|
integral = sum(term[0] for term in [i1_small, i2_small, i1_big, i2_big])
|
||||||
|
|
||||||
|
31
tests/noise/test_im_ref.py
Normal file
31
tests/noise/test_im_ref.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import numpy as np
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
import pynam.dielectric
|
||||||
|
import pynam.noise.im_ref
|
||||||
|
from pynam.baskets import CalculationParams
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def im_ref_p_lindhard():
|
||||||
|
params = CalculationParams(omega=1e9, v_f=2e6, omega_p=3.544907701811032e15, tau=1e-14)
|
||||||
|
eps_l = pynam.dielectric.get_lindhard_dielectric(params)
|
||||||
|
return pynam.noise.im_ref.get_im_ref_p(eps_l)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("test_input,expected", [
|
||||||
|
# u im_ref_p_l(u)
|
||||||
|
# needs to be close in range around 1/z, so from 1e4 to 1e8
|
||||||
|
(1e4, 1.821722334939806e-8),
|
||||||
|
(1e5, 1.602855764970752e-8),
|
||||||
|
(1e6, 1.704326041013161e-8),
|
||||||
|
(1e7, 2.674124312031195e-8),
|
||||||
|
(1e8, 7.441319151047531e-8),
|
||||||
|
])
|
||||||
|
def test_im_ref_p_lindhard(im_ref_p_lindhard, test_input, expected):
|
||||||
|
actual = im_ref_p_lindhard(test_input)
|
||||||
|
|
||||||
|
np.testing.assert_allclose(
|
||||||
|
actual, expected,
|
||||||
|
rtol=1e-4, err_msg='imrp is inaccurate for Lindhard case', verbose=True
|
||||||
|
)
|
@ -38,7 +38,13 @@ def zeta_p_lindhard():
|
|||||||
@pytest.mark.parametrize("test_input,expected", [
|
@pytest.mark.parametrize("test_input,expected", [
|
||||||
# u zeta_p(u)
|
# u zeta_p(u)
|
||||||
(1, 0.000199609 - 0.000199608j),
|
(1, 0.000199609 - 0.000199608j),
|
||||||
|
# (10, 0.00019960929309663014 - 0.00019927000998506335j),
|
||||||
|
# (100, 0.0001996175250684056 - 0.0001654898843938523j),
|
||||||
|
# (1e3, 0.0002003339895748246 + 0.003212370020888438j),
|
||||||
|
# (1e4, 0.00028616168676982363 + 0.34096962141224463j),
|
||||||
(1e5, 0.0025183067257958545 + 34.11087430547122j),
|
(1e5, 0.0025183067257958545 + 34.11087430547122j),
|
||||||
|
(1e6, 0.026829658454640887 + 3411.0870128247902j),
|
||||||
|
(1e7, 0.4292211181081069 + 341088.797211291j),
|
||||||
(1e8, 14.348462224076096 + 3.391157983312813e7j)
|
(1e8, 14.348462224076096 + 3.391157983312813e7j)
|
||||||
])
|
])
|
||||||
def test_zeta_p(zeta_p_lindhard, test_input, expected):
|
def test_zeta_p(zeta_p_lindhard, test_input, expected):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user