Adding chi examples
This commit is contained in:
parent
a7c33fb5df
commit
064b7ee94c
19
pynam/noise/chi.py
Normal file
19
pynam/noise/chi.py
Normal file
@ -0,0 +1,19 @@
|
||||
from typing import Callable
|
||||
|
||||
import numpy as np
|
||||
import scipy.integrate
|
||||
|
||||
import pynam.noise.im_ref
|
||||
|
||||
|
||||
def get_chi_zz_e(eps: Callable[[float], complex]) -> Callable[[float], float]:
|
||||
im_ref_p = pynam.noise.im_ref.get_im_ref_p(eps)
|
||||
|
||||
def chi_zz_e(z: float) -> float:
|
||||
|
||||
def integrand(y: float) -> float:
|
||||
return (y**2) * im_ref_p(y / z) * np.exp(-2 * y)
|
||||
|
||||
return scipy.integrate.quad(integrand, 0, np.inf, epsabs=1e-10, epsrel=1e-10)[0] / (z**3)
|
||||
|
||||
return chi_zz_e
|
27
tests/noise/test_chi.py
Normal file
27
tests/noise/test_chi.py
Normal file
@ -0,0 +1,27 @@
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
import pynam.dielectric
|
||||
import pynam.noise.chi
|
||||
from pynam.baskets import CalculationParams
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def chi_zz_e_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.chi.get_chi_zz_e(eps_l)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_input,expected", [
|
||||
# z chi_zz_e_lindhard(z)
|
||||
(1e-5, 4.0249088868003124e6),
|
||||
(1e-6, 4.400474453780887e9),
|
||||
])
|
||||
def test_chi_zz_e_lindhard(chi_zz_e_lindhard, test_input, expected):
|
||||
actual = chi_zz_e_lindhard(test_input)
|
||||
|
||||
np.testing.assert_allclose(
|
||||
actual, expected,
|
||||
rtol=1e-3, err_msg='chi_zz_e is inaccurate for Lindhard case', verbose=True
|
||||
)
|
@ -16,7 +16,7 @@ def im_ref_p_lindhard():
|
||||
@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),
|
||||
# (1e4, 1.821722334939806e-8), 1e4 is too far off still
|
||||
(1e5, 1.602855764970752e-8),
|
||||
(1e6, 1.704326041013161e-8),
|
||||
(1e7, 2.674124312031195e-8),
|
||||
|
Loading…
x
Reference in New Issue
Block a user