diff --git a/pyewjn/dielectric/nam_dielectric_coefficient_approximator.py b/pyewjn/dielectric/nam_dielectric_coefficient_approximator.py index f39a4d4..c906bdd 100644 --- a/pyewjn/dielectric/nam_dielectric_coefficient_approximator.py +++ b/pyewjn/dielectric/nam_dielectric_coefficient_approximator.py @@ -4,7 +4,12 @@ import pyewjn.dielectric.low_k_nam from pyewjn.baskets import CalculationParams, CalculationConstants -from typing import Tuple +from typing import Tuple, Callable +import logging + + +_logger = logging.getLogger(__name__) + FIXED_LARGE_MOMENTUM = 1e8 @@ -141,10 +146,10 @@ def get_unapproximated_nam_dielectric( u_c: float, params: CalculationParams, constants: CalculationConstants = CalculationConstants(), -): +) -> Callable[[float], float]: sigma_n = params.omega_p**2 * params.tau / (4 * np.pi) - coeffs = get_nam_dielectric_coefficients( + dedim = get_dedimensionalised_parameters( params.omega, sigma_n, params.tau, @@ -153,4 +158,19 @@ def get_unapproximated_nam_dielectric( params.t_c, constants.c_light, ) - return coeffs.eps(u_c) + prefactor = 4j * np.pi * dedim.b + + def eps_ret(u: float) -> float: + if u * dedim.a * 100 < abs(dedim.xi + 1j * dedim.nu): + _logger.info("Falling to low k version") + return prefactor * pyewjn.dielectric.low_k_nam.sigma_nam_alk( + dedim.xi, u * dedim.a, dedim.nu, dedim.t + ) + elif u < u_c: + return prefactor * pyewjn.dielectric.sigma_nam.sigma_nam( + dedim.xi, u * dedim.a, dedim.nu, dedim.t + ) + else: + return 1 + + return eps_ret diff --git a/tests/dielectric/test_nam_dielectric_coefficient_approximator.py b/tests/dielectric/test_nam_dielectric_coefficient_approximator.py index dbe7199..f0c241d 100644 --- a/tests/dielectric/test_nam_dielectric_coefficient_approximator.py +++ b/tests/dielectric/test_nam_dielectric_coefficient_approximator.py @@ -137,3 +137,31 @@ def test_nam_eps(): np.testing.assert_allclose( eps_to_test(1e17), 1, rtol=1e-6, err_msg="above cutoff bad" ) + + +def test_unapproximated_nam_eps(): + u_c = 1e15 + eps_to_test = pyewjn.dielectric.nam_dielectric_coefficient_approximator.get_unapproximated_nam_dielectric( + u_c, + CalculationParams( + omega=1e9, omega_p=3.54491e15, tau=1e-14, v_f=2e6, t_rel=0.8, t_c=1e11 + ), + ) + + np.testing.assert_allclose( + eps_to_test(10), + -3.789672906817707e10 + 3.257134605133221e8j, + rtol=1e-3, + err_msg="below u_l bad", + ) + + np.testing.assert_allclose( + eps_to_test(1e10), + -2.645743e8 + 2.293455422222e6j, + rtol=1e-3, + err_msg="linear region bad", + ) + + np.testing.assert_allclose( + eps_to_test(1e17), 1, rtol=1e-6, err_msg="above cutoff bad" + )