feat!: big breaking change set
All checks were successful
gitea-physics/pynam/pipeline/head This commit looks good

This commit is contained in:
2022-03-28 18:51:52 -05:00
parent e1e8c8490a
commit 6231ecc203
32 changed files with 1514 additions and 773 deletions

View File

@@ -9,38 +9,47 @@ def get_common_lindhard_dielectric():
return pynam.dielectric.get_lindhard_dielectric(params)
@pytest.mark.parametrize("test_input,expected", [
(10, -1222.185185062794 + 1.2249999998777178e8j),
(1000, 16924.14814718176 + 1.2250000020552777e8j),
(1e8, 83.687499999706 + 0.00022417398943752126j)
])
@pytest.mark.parametrize(
"test_input,expected",
[
(10, -1222.185185062794 + 1.2249999998777178e8j),
(1000, 16924.14814718176 + 1.2250000020552777e8j),
(1e8, 83.687499999706 + 0.00022417398943752126j),
],
)
def test_lindhard_dielectric(test_input, expected):
eps_to_test = get_common_lindhard_dielectric()
np.testing.assert_almost_equal(
eps_to_test(test_input), expected,
decimal=6, err_msg='b function is off'
eps_to_test(test_input), expected, decimal=6, err_msg="b function is off"
)
@pytest.mark.parametrize("test_input,expected", [
((100, 100), -883.3001542404703 + 1.2566370613549341e8j),
((100, 1e5), 5.827225842825694e7 + 3.933446612656656e7j),
((100, 1e10), 1.0084823001646925 + 2.0013975538629039e-10j),
((100, 1e7), 8483.300121667038 + 0.6340397839154446)
])
@pytest.mark.parametrize(
"test_input,expected",
[
((100, 100), -883.3001542404703 + 1.2566370613549341e8j),
((100, 1e5), 5.827225842825694e7 + 3.933446612656656e7j),
((100, 1e10), 1.0084823001646925 + 2.0013975538629039e-10j),
((100, 1e7), 8483.300121667038 + 0.6340397839154446),
],
)
def test_zeta_pi_lindhard_dielectric(zeta_p_i_epsilon, test_input, expected):
u, y = test_input
actual = zeta_p_i_epsilon(np.sqrt(u**2 + y**2))
np.testing.assert_allclose(
actual, expected,
rtol=10**3.8, err_msg='lindhard dielectric differs from Mathematica'
actual,
expected,
rtol=10**3.8,
err_msg="lindhard dielectric differs from Mathematica",
)
@pytest.fixture
def zeta_p_i_epsilon():
params = CalculationParams(omega=1e9, omega_p=3.544907701811032e15, tau=1e-14, v_f=2e6)
params = CalculationParams(
omega=1e9, omega_p=3.544907701811032e15, tau=1e-14, v_f=2e6
)
return pynam.dielectric.get_lindhard_dielectric(params)

View File

@@ -3,101 +3,115 @@ import numpy as np
import pytest
@pytest.mark.parametrize("test_input,expected", [
((1, 2), 7 / (2 * np.sqrt(6))),
((2, 0.25), -5j / np.sqrt(39))
])
@pytest.mark.parametrize(
"test_input,expected",
[((1, 2), 7 / (2 * np.sqrt(6))), ((2, 0.25), -5j / np.sqrt(39))],
)
def test_g(test_input, expected):
np.testing.assert_almost_equal(
pynam.dielectric.low_k_nam.g(*test_input), expected,
decimal=7, err_msg='g function is off'
pynam.dielectric.low_k_nam.g(*test_input),
expected,
decimal=7,
err_msg="g function is off",
)
@pytest.mark.parametrize("test_input,expected", [
((1, 1, 0), 8 / 5),
((1, 1, 1), 3 / 5 + 11j / 15),
((1, 0, 1), 16j / 15)
])
@pytest.mark.parametrize(
"test_input,expected",
[((1, 1, 0), 8 / 5), ((1, 1, 1), 3 / 5 + 11j / 15), ((1, 0, 1), 16j / 15)],
)
def test_f(test_input, expected):
np.testing.assert_almost_equal(
pynam.dielectric.low_k_nam.f(*test_input), expected,
decimal=7, err_msg='f function is off'
pynam.dielectric.low_k_nam.f(*test_input),
expected,
decimal=7,
err_msg="f function is off",
)
@pytest.mark.parametrize("test_input,expected", [
((2, 3, 1, 0), 1.42546694754),
((1, 2, 3, 4), 0.0206212167 + 0.4411134527j)
])
@pytest.mark.parametrize(
"test_input,expected",
[((2, 3, 1, 0), 1.42546694754), ((1, 2, 3, 4), 0.0206212167 + 0.4411134527j)],
)
def test_i1(test_input, expected):
np.testing.assert_almost_equal(
pynam.dielectric.low_k_nam.i1(*test_input), expected,
decimal=7, err_msg='i1 function is off'
pynam.dielectric.low_k_nam.i1(*test_input),
expected,
decimal=7,
err_msg="i1 function is off",
)
@pytest.mark.parametrize("test_input,expected", [
((2, 3, 1, 0), 1.47903168398),
((1, 2, 3, 4), 0.079491440779 + 0.441113452718j)
])
@pytest.mark.parametrize(
"test_input,expected",
[((2, 3, 1, 0), 1.47903168398), ((1, 2, 3, 4), 0.079491440779 + 0.441113452718j)],
)
def test_i2(test_input, expected):
np.testing.assert_almost_equal(
pynam.dielectric.low_k_nam.i2(*test_input), expected,
decimal=7, err_msg='i1 function is off'
pynam.dielectric.low_k_nam.i2(*test_input),
expected,
decimal=7,
err_msg="i1 function is off",
)
@pytest.mark.parametrize("test_input,expected", [
((1, 2, 3, 4), 0.228292),
])
@pytest.mark.parametrize(
"test_input,expected",
[
((1, 2, 3, 4), 0.228292),
],
)
def test_a(test_input, expected):
actual = np.real_if_close(pynam.dielectric.low_k_nam.a(*test_input))
np.testing.assert_almost_equal(
actual, expected,
decimal=6, err_msg='a function is off'
actual, expected, decimal=6, err_msg="a function is off"
)
@pytest.mark.parametrize("test_input,expected", [
((2, 1, 2, 0, 4), 0.479529593125),
((100, 1, 2, 3, 4), -2.62529549942e-6 + 2.60588e-12j),
])
@pytest.mark.parametrize(
"test_input,expected",
[
((2, 1, 2, 0, 4), 0.479529593125),
((100, 1, 2, 3, 4), -2.62529549942e-6 + 2.60588e-12j),
],
)
def test_b_int(test_input, expected):
actual = np.real_if_close(pynam.dielectric.low_k_nam.b_int(*test_input))
np.testing.assert_almost_equal(
actual, expected,
decimal=6, err_msg='b int function is off'
actual, expected, decimal=6, err_msg="b int function is off"
)
@pytest.mark.parametrize("test_input,expected", [
((1, 2, 0, 4), 3.514889721181435),
((1, 2, 3, 4), -0.0598057 + 0.437146j),
])
@pytest.mark.parametrize(
"test_input,expected",
[
((1, 2, 0, 4), 3.514889721181435),
((1, 2, 3, 4), -0.0598057 + 0.437146j),
],
)
def test_b(test_input, expected):
actual = np.real_if_close(pynam.dielectric.low_k_nam.b(*test_input))
np.testing.assert_almost_equal(
actual, expected,
decimal=6, err_msg='b function is off'
actual, expected, decimal=6, err_msg="b function is off"
)
@pytest.mark.parametrize("test_input,expected", [
((1, 2, 0, 4), 0),
((1, 2, 3, 4), 0.98358 + 0.648221j),
])
@pytest.mark.parametrize(
"test_input,expected",
[
((1, 2, 0, 4), 0),
((1, 2, 3, 4), 0.98358 + 0.648221j),
],
)
def test_sigma_alk(test_input, expected):
actual = np.real_if_close(pynam.dielectric.low_k_nam.sigma_nam_alk(*test_input))
np.testing.assert_almost_equal(
actual, expected,
decimal=6, err_msg='b function is off'
actual, expected, decimal=6, err_msg="b function is off"
)
def test_sigma_alk_benchmark(benchmark):
result = benchmark(pynam.dielectric.low_k_nam.sigma_nam_alk, 1, 2, 3, 4)
np.testing.assert_almost_equal(
result, 0.98358 + 0.648221j,
decimal=6, err_msg='b function is off'
result, 0.98358 + 0.648221j, decimal=6, err_msg="b function is off"
)

View File

@@ -4,102 +4,136 @@ import pynam.dielectric.nam_dielectric_coefficient_approximator
from pynam.baskets import CalculationParams
@pytest.mark.parametrize("test_input,expected", [
# (
# (omega, sigma_n, tau, v_f, T, T_c, c_light),
# (xi, nu, t, A, B)
# )
(
@pytest.mark.parametrize(
"test_input,expected",
[
# (
# (omega, sigma_n, tau, v_f, T, T_c, c_light),
# (xi, nu, t, A, B)
# )
(
(1e9, 1e16, 1e-14, 2e6, 0.8e11, 1e11, 3e8),
(0.007307411691175783, 730.7411691175784, 0.5845929352940626, 0.00004871607794117188, 10000000)
)
])
(
0.007307411691175783,
730.7411691175784,
0.5845929352940626,
0.00004871607794117188,
10000000,
),
)
],
)
def test_dedimensionalise_parameters(test_input, expected):
actual_parameters = pynam.dielectric.nam_dielectric_coefficient_approximator.get_dedimensionalised_parameters(
*test_input)
np.testing.assert_almost_equal(
actual_parameters.xi, expected[0],
decimal=6, err_msg='xi incorrectly calculated'
*test_input
)
np.testing.assert_almost_equal(
actual_parameters.nu, expected[1],
decimal=6, err_msg='nu incorrectly calculated'
actual_parameters.xi,
expected[0],
decimal=6,
err_msg="xi incorrectly calculated",
)
np.testing.assert_almost_equal(
actual_parameters.nu,
expected[1],
decimal=6,
err_msg="nu incorrectly calculated",
)
np.testing.assert_almost_equal(
actual_parameters.t, expected[2],
decimal=6, err_msg='t incorrectly calculated'
actual_parameters.t, expected[2], decimal=6, err_msg="t incorrectly calculated"
)
np.testing.assert_almost_equal(
actual_parameters.a, expected[3],
decimal=6, err_msg='A incorrectly calculated'
actual_parameters.a, expected[3], decimal=6, err_msg="A incorrectly calculated"
)
np.testing.assert_almost_equal(
actual_parameters.b, expected[4],
decimal=6, err_msg='B incorrectly calculated'
actual_parameters.b, expected[4], decimal=6, err_msg="B incorrectly calculated"
)
@pytest.mark.parametrize("test_input,expected", [
# (
# (omega, sigma_n, tau, v_f, T, T_c, c_light),
# (a, b, c, d, u_l)
# )
(
@pytest.mark.parametrize(
"test_input,expected",
[
# (
# (omega, sigma_n, tau, v_f, T, T_c, c_light),
# (a, b, c, d, u_l)
# )
(
(1e9, 1e16, 1e-14, 2e6, 0.8e11, 1e11, 3e8),
(3.789672906817707e10, 3.257134605133221e8, 2.655709897616547e18, 2.15e16, 7.007759408279888e7)
)
])
(
3.789672906817707e10,
3.257134605133221e8,
2.655709897616547e18,
2.15e16,
7.007759408279888e7,
),
)
],
)
def test_nam_coefficients(test_input, expected):
actual_coefficients = pynam.dielectric.nam_dielectric_coefficient_approximator.get_nam_dielectric_coefficients(
*test_input)
np.testing.assert_allclose(
actual_coefficients.a, expected[0],
rtol=1e-6, err_msg='a incorrectly calculated'
*test_input
)
np.testing.assert_allclose(
actual_coefficients.b, expected[1],
rtol=1e-6, err_msg='b incorrectly calculated'
actual_coefficients.a,
expected[0],
rtol=1e-6,
err_msg="a incorrectly calculated",
)
np.testing.assert_allclose(
actual_coefficients.b,
expected[1],
rtol=1e-6,
err_msg="b incorrectly calculated",
)
np.testing.assert_allclose(
actual_coefficients.c, expected[2],
rtol=1e-2, err_msg='c incorrectly calculated'
actual_coefficients.c,
expected[2],
rtol=1e-2,
err_msg="c incorrectly calculated",
)
np.testing.assert_allclose(
actual_coefficients.d, expected[3],
rtol=1e-2, err_msg='d incorrectly calculated'
actual_coefficients.d,
expected[3],
rtol=1e-2,
err_msg="d incorrectly calculated",
)
np.testing.assert_allclose(
actual_coefficients.u_l, expected[4],
rtol=1e-5, err_msg='u_l incorrectly calculated'
actual_coefficients.u_l,
expected[4],
rtol=1e-5,
err_msg="u_l incorrectly calculated",
)
def test_nam_eps():
u_c = 1e15
eps_to_test = pynam.dielectric.nam_dielectric_coefficient_approximator.get_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'
eps_to_test = (
pynam.dielectric.nam_dielectric_coefficient_approximator.get_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(1e10), -2.655709887616547e8 + 2.302290450767144e6j,
rtol=1e-3, err_msg='linear region bad'
eps_to_test(10),
-3.789672906817707e10 + 3.257134605133221e8j,
rtol=1e-3,
err_msg="below u_l bad",
)
np.testing.assert_allclose(
eps_to_test(1e17), 1,
rtol=1e-6, err_msg='above cutoff bad'
eps_to_test(1e10),
-2.655709887616547e8 + 2.302290450767144e6j,
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"
)

View File

@@ -3,120 +3,163 @@ import numpy as np
import pytest
@pytest.mark.parametrize("test_input,expected", [
((1, 2), 7 / (2 * np.sqrt(6))),
((2, 0.25), -5j / np.sqrt(39))
])
@pytest.mark.parametrize(
"test_input,expected",
[((1, 2), 7 / (2 * np.sqrt(6))), ((2, 0.25), -5j / np.sqrt(39))],
)
def test_g(test_input, expected):
np.testing.assert_almost_equal(
pynam.dielectric.sigma_nam.g(*test_input), expected,
decimal=7, err_msg='g function is off'
pynam.dielectric.sigma_nam.g(*test_input),
expected,
decimal=7,
err_msg="g function is off",
)
@pytest.mark.parametrize("test_input,expected", [
((1, 2, 0), 2),
((1, 2, 3), 2 - 3j),
((1, 0, 3), -3j)
])
@pytest.mark.parametrize(
"test_input,expected", [((1, 2, 0), 2), ((1, 2, 3), 2 - 3j), ((1, 0, 3), -3j)]
)
def test_s(test_input, expected):
np.testing.assert_almost_equal(
pynam.dielectric.sigma_nam.s(*test_input), expected,
decimal=7, err_msg='s function is off'
pynam.dielectric.sigma_nam.s(*test_input),
expected,
decimal=7,
err_msg="s function is off",
)
@pytest.mark.parametrize("test_input,expected", [
((1, 2, 0), 4 - 3 * np.log(3)),
((1, 1, 0.1), 1.7258022209219421 + 0.4146045220413866j),
((1, 2, 1), 0.535971651563 + 0.291580606867j),
((1, 0, 1), (np.pi - 2)*1j),
((2, 1.09637631718, 0), 0.97892512273 + 1.09875591859j),
((2, 1, 0), 0.91197960825 + 1.17809724510j)
])
@pytest.mark.parametrize(
"test_input,expected",
[
((1, 2, 0), 4 - 3 * np.log(3)),
((1, 1, 0.1), 1.7258022209219421 + 0.4146045220413866j),
((1, 2, 1), 0.535971651563 + 0.291580606867j),
((1, 0, 1), (np.pi - 2) * 1j),
((2, 1.09637631718, 0), 0.97892512273 + 1.09875591859j),
((2, 1, 0), 0.91197960825 + 1.17809724510j),
],
)
def test_f(test_input, expected):
np.testing.assert_almost_equal(
pynam.dielectric.sigma_nam.f(*test_input), expected,
decimal=7, err_msg='f function is off'
pynam.dielectric.sigma_nam.f(*test_input),
expected,
decimal=7,
err_msg="f function is off",
)
@pytest.mark.parametrize("test_input,expected", [
((2, 3, 1, 0), 1.43292419807),
((1, 2, 3, 4), 0.020963572915 + 0.441546735048j),
((1, 2, 2, 0), 2.24702466263660598724031013350450660504 + 2.6687342075059525776833106878900822165j)
])
@pytest.mark.parametrize(
"test_input,expected",
[
((2, 3, 1, 0), 1.43292419807),
((1, 2, 3, 4), 0.020963572915 + 0.441546735048j),
(
(1, 2, 2, 0),
2.24702466263660598724031013350450660504
+ 2.6687342075059525776833106878900822165j,
),
],
)
def test_i1(test_input, expected):
np.testing.assert_almost_equal(
pynam.dielectric.sigma_nam.i1(*test_input), expected,
decimal=7, err_msg='i1 function is off'
pynam.dielectric.sigma_nam.i1(*test_input),
expected,
decimal=7,
err_msg="i1 function is off",
)
@pytest.mark.parametrize("test_input,expected", [
((2, 3, 1, 0), 1.48649022993),
((1, 2, 3, 4), 0.079899419983 + 0.441546735048j),
((1, 2, 2, 0), 2.5083371377336783093007366990156440969 + 2.6687342075059525776833106878900822165j)
])
@pytest.mark.parametrize(
"test_input,expected",
[
((2, 3, 1, 0), 1.48649022993),
((1, 2, 3, 4), 0.079899419983 + 0.441546735048j),
(
(1, 2, 2, 0),
2.5083371377336783093007366990156440969
+ 2.6687342075059525776833106878900822165j,
),
],
)
def test_i2(test_input, expected):
np.testing.assert_almost_equal(
pynam.dielectric.sigma_nam.i2(*test_input), expected,
decimal=7, err_msg='i1 function is off'
pynam.dielectric.sigma_nam.i2(*test_input),
expected,
decimal=7,
err_msg="i1 function is off",
)
@pytest.mark.parametrize("test_input,expected", [
((1, 2, 3, 4), 0.228396),
((0.007307411691175783, 1e8, 730.7411691175784, 0.5845929352940626), 1.37272e-7)
])
@pytest.mark.parametrize(
"test_input,expected",
[
((1, 2, 3, 4), 0.228396),
(
(0.007307411691175783, 1e8, 730.7411691175784, 0.5845929352940626),
1.37272e-7,
),
],
)
def test_a(test_input, expected):
actual = np.real_if_close(pynam.dielectric.sigma_nam.a(*test_input))
np.testing.assert_allclose(
actual, expected,
rtol=1e-5, err_msg='a function is off'
)
np.testing.assert_allclose(actual, expected, rtol=1e-5, err_msg="a function is off")
@pytest.mark.parametrize("test_input,expected", [
((2, 1, 2, 0, 4), 0.19089933550122580816258795500979108668 + 0.30273783507819906415704926284048453889j),
((100, 1, 2, 3, 4), -2.62529549976e-6 + 2.60765e-12j),
])
@pytest.mark.parametrize(
"test_input,expected",
[
(
(2, 1, 2, 0, 4),
0.19089933550122580816258795500979108668
+ 0.30273783507819906415704926284048453889j,
),
((100, 1, 2, 3, 4), -2.62529549976e-6 + 2.60765e-12j),
],
)
def test_b_int(test_input, expected):
actual = np.real_if_close(pynam.dielectric.sigma_nam.b_int(*test_input))
np.testing.assert_almost_equal(
actual, expected,
decimal=6, err_msg='b int function is off'
actual, expected, decimal=6, err_msg="b int function is off"
)
@pytest.mark.parametrize("test_input,expected", [
((1, 2, 0, 4), 1.23149 + 2.08627j),
((1, 2, 3, 4), -0.0595819 + 0.437385j),
])
@pytest.mark.parametrize(
"test_input,expected",
[
((1, 2, 0, 4), 1.23149 + 2.08627j),
((1, 2, 3, 4), -0.0595819 + 0.437385j),
],
)
def test_b(test_input, expected):
actual = np.real_if_close(pynam.dielectric.sigma_nam.b(*test_input))
np.testing.assert_almost_equal(
actual, expected,
decimal=6, err_msg='b function is off'
actual, expected, decimal=6, err_msg="b function is off"
)
@pytest.mark.parametrize("test_input,expected", [
((1, 2, 0, 4), 0),
((1, 2, 3, 4), 0.984117 + 0.647951j),
((0.007307411691175783, 1e8, 730.7411691175784, 0.5845929352940626), 0.00008925294700016892 + 0.0102953966846717j)
])
@pytest.mark.parametrize(
"test_input,expected",
[
((1, 2, 0, 4), 0),
((1, 2, 3, 4), 0.984117 + 0.647951j),
(
(0.007307411691175783, 1e8, 730.7411691175784, 0.5845929352940626),
0.00008925294700016892 + 0.0102953966846717j,
),
],
)
def test_sigma_nam(test_input, expected):
actual = np.real_if_close(pynam.dielectric.sigma_nam.sigma_nam(*test_input))
np.testing.assert_allclose(
actual, expected,
rtol=1e-3, err_msg='sigma_nam function is off'
actual, expected, rtol=1e-3, err_msg="sigma_nam function is off"
)
def test_sigma_nam_benchmark(benchmark):
result = benchmark(pynam.dielectric.sigma_nam.sigma_nam, 1, 2, 3, 4)
np.testing.assert_almost_equal(
result, 0.984117 + 0.647951j,
decimal=6, err_msg='sigma nam benchmrak function is off'
result,
0.984117 + 0.647951j,
decimal=6,
err_msg="sigma nam benchmrak function is off",
)