Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
775e9ce3f0
|
|||
|
2b22267f36
|
|||
|
20db727015
|
|||
|
4d59f9c09c
|
|||
|
5e830f623e
|
|||
|
d2dd960000
|
|||
|
71a969aeda
|
|||
|
f73d5546ce
|
|||
|
b3ea3da54f
|
19
CHANGELOG.md
19
CHANGELOG.md
@@ -2,6 +2,25 @@
|
||||
|
||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||
|
||||
## [0.3.0](https://gitea.deepak.science:2222/physics/pyewjn/compare/0.2.1...0.3.0) (2022-03-29)
|
||||
|
||||
|
||||
### ⚠ BREAKING CHANGES
|
||||
|
||||
* pushes type checking earlier in the docket
|
||||
|
||||
### Features
|
||||
|
||||
* adds unapproximated nam calc ([20db727](https://gitea.deepak.science:2222/physics/pyewjn/commit/20db72701500da4bcf32205d7dd7baf7e911744a))
|
||||
* pushes type checking earlier in the docket ([d2dd960](https://gitea.deepak.science:2222/physics/pyewjn/commit/d2dd9600002da3e531b9946f4c388cca0cc32930))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* fixes stuff with nam integration ([2b22267](https://gitea.deepak.science:2222/physics/pyewjn/commit/2b22267f36294270834473b68884bdca668b65fa))
|
||||
* removes unnecessary None checks ([4d59f9c](https://gitea.deepak.science:2222/physics/pyewjn/commit/4d59f9c09cfba92d5c2de54e8b4b62295a9313e4))
|
||||
* removes unnecessary None checks ([5e830f6](https://gitea.deepak.science:2222/physics/pyewjn/commit/5e830f623e185c04d170ef642bbd9323b0dd7043))
|
||||
|
||||
### 0.2.1 (2022-03-29)
|
||||
|
||||
|
||||
|
||||
19
README.md
19
README.md
@@ -1,3 +1,16 @@
|
||||
# pyewjn
|
||||
|
||||
python port of `nam_analysis`
|
||||
# pyewjn
|
||||
|
||||
[](https://conventionalcommits.org)
|
||||
[](https://pypi.org/project/pyewjn/)
|
||||
[](https://jenkins.deepak.science/job/gitea-physics/job/pyewjn/job/master/)
|
||||

|
||||

|
||||

|
||||
|
||||
python port of `nam_analysis`
|
||||
|
||||
## Getting started
|
||||
|
||||
`poetry install` to start locally
|
||||
|
||||
Commit using [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/), and when commits are on master, release with `doo release`.
|
||||
|
||||
2
do.sh
2
do.sh
@@ -30,7 +30,7 @@ release() {
|
||||
}
|
||||
|
||||
all() {
|
||||
build && test
|
||||
build && fmt && test
|
||||
}
|
||||
|
||||
"$@" # <- execute the task
|
||||
|
||||
@@ -27,13 +27,13 @@ class CalculationParams(object):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
omega: float = None,
|
||||
omega_p: float = None,
|
||||
tau: float = None,
|
||||
v_f: float = None,
|
||||
t_rel: float = None,
|
||||
t_c: float = None,
|
||||
dipole_moment: float = None,
|
||||
omega: float,
|
||||
omega_p: float,
|
||||
tau: float,
|
||||
v_f: float,
|
||||
t_rel: float = 0.8,
|
||||
t_c: float = 1e11,
|
||||
dipole_moment: float = 1,
|
||||
):
|
||||
"""Creates parameter object, SI units
|
||||
|
||||
@@ -46,6 +46,19 @@ class CalculationParams(object):
|
||||
:param dipole_moment:
|
||||
"""
|
||||
|
||||
if omega is None:
|
||||
raise ValueError("omega expected to not be None")
|
||||
if v_f is None:
|
||||
raise ValueError("v_f expected to not be None")
|
||||
if omega_p is None:
|
||||
raise ValueError("omega_p expected to not be None")
|
||||
if tau is None:
|
||||
raise ValueError("tau expected to not be None")
|
||||
if t_rel is None:
|
||||
raise ValueError("relative temp expected to not be None")
|
||||
if t_c is None:
|
||||
raise ValueError("critical temp expected to not be None")
|
||||
|
||||
self.omega = omega
|
||||
self.omega_p = omega_p
|
||||
self.tau = tau
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
from pyewjn.dielectric.nam_dielectric_coefficient_approximator import get_nam_dielectric
|
||||
from pyewjn.dielectric.nam_dielectric_coefficient_approximator import (
|
||||
get_nam_dielectric,
|
||||
get_unapproximated_nam_dielectric,
|
||||
)
|
||||
from pyewjn.dielectric.lindhard_dielectric import get_lindhard_dielectric
|
||||
|
||||
__all__ = ["get_nam_dielectric", "get_lindhard_dielectric"]
|
||||
__all__ = [
|
||||
"get_nam_dielectric",
|
||||
"get_lindhard_dielectric",
|
||||
"get_unapproximated_nam_dielectric",
|
||||
]
|
||||
|
||||
@@ -11,14 +11,6 @@ class LindhardDielectric(object):
|
||||
constants: CalculationConstants = CalculationConstants(),
|
||||
thres=LINDHARD_SERIES_THRESHOLD,
|
||||
):
|
||||
if params.omega is None:
|
||||
raise ValueError("omega expected to not be None")
|
||||
if params.v_f is None:
|
||||
raise ValueError("v_f expected to not be None")
|
||||
if params.omega_p is None:
|
||||
raise ValueError("omega_p expected to not be None")
|
||||
if params.tau is None:
|
||||
raise ValueError("tau expected to not be None")
|
||||
|
||||
self.series_threshold = thres
|
||||
self.omega = params.omega
|
||||
|
||||
@@ -4,9 +4,15 @@ 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
|
||||
WRT_TC_THRESHOLD = 0.98
|
||||
|
||||
|
||||
class DedimensionalisedParameters(object):
|
||||
@@ -19,16 +25,24 @@ class DedimensionalisedParameters(object):
|
||||
temp: float,
|
||||
critical_temp: float,
|
||||
c_light: float,
|
||||
wrt_tc: bool = False,
|
||||
):
|
||||
gap = 0
|
||||
if temp < critical_temp:
|
||||
# else, problems will happen
|
||||
gap = 3.06 * np.sqrt(critical_temp * (critical_temp - temp))
|
||||
self.xi = omega / gap
|
||||
self.nu = 1 / (tau * gap)
|
||||
self.t = temp / gap
|
||||
self.a = omega * v_f / (c_light * gap)
|
||||
|
||||
if wrt_tc:
|
||||
scale = critical_temp
|
||||
else:
|
||||
scale = gap
|
||||
|
||||
self.xi = omega / scale
|
||||
self.nu = 1 / (tau * scale)
|
||||
self.t = temp / scale
|
||||
self.a = omega * v_f / (c_light * scale)
|
||||
self.b = sigma_n / omega
|
||||
self.delta = gap / scale
|
||||
|
||||
|
||||
class NamDielectricCoefficients(object):
|
||||
@@ -60,9 +74,11 @@ def get_dedimensionalised_parameters(
|
||||
temp: float,
|
||||
critical_temp: float,
|
||||
c_light: float,
|
||||
wrt_tc: bool = False,
|
||||
) -> DedimensionalisedParameters:
|
||||
|
||||
return DedimensionalisedParameters(
|
||||
omega, sigma_n, tau, v_f, temp, critical_temp, c_light
|
||||
omega, sigma_n, tau, v_f, temp, critical_temp, c_light, wrt_tc
|
||||
)
|
||||
|
||||
|
||||
@@ -123,18 +139,7 @@ def get_nam_dielectric(
|
||||
params: CalculationParams,
|
||||
constants: CalculationConstants = CalculationConstants(),
|
||||
):
|
||||
if params.omega is None:
|
||||
raise ValueError("omega expected to not be None")
|
||||
if params.v_f is None:
|
||||
raise ValueError("v_f expected to not be None")
|
||||
if params.omega_p is None:
|
||||
raise ValueError("omega_p expected to not be None")
|
||||
if params.tau is None:
|
||||
raise ValueError("tau expected to not be None")
|
||||
if params.t_rel is None:
|
||||
raise ValueError("relative temp expected to not be None")
|
||||
if params.t_c is None:
|
||||
raise ValueError("critical temp expected to not be None")
|
||||
|
||||
sigma_n = params.omega_p**2 * params.tau / (4 * np.pi)
|
||||
coeffs = get_nam_dielectric_coefficients(
|
||||
params.omega,
|
||||
@@ -146,3 +151,38 @@ def get_nam_dielectric(
|
||||
constants.c_light,
|
||||
)
|
||||
return coeffs.eps(u_c)
|
||||
|
||||
|
||||
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)
|
||||
dedim = get_dedimensionalised_parameters(
|
||||
params.omega,
|
||||
sigma_n,
|
||||
params.tau,
|
||||
params.v_f,
|
||||
params.t_rel * params.t_c,
|
||||
params.t_c,
|
||||
constants.c_light,
|
||||
wrt_tc=params.t_rel > WRT_TC_THRESHOLD,
|
||||
)
|
||||
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
|
||||
|
||||
67
pyewjn/dielectric/sigma_nam_keep_gap.py
Normal file
67
pyewjn/dielectric/sigma_nam_keep_gap.py
Normal file
@@ -0,0 +1,67 @@
|
||||
import numpy as np
|
||||
from numpy.lib.scimath import sqrt as csqrt
|
||||
|
||||
import pyewjn.util
|
||||
|
||||
|
||||
def g(w, wp, d):
|
||||
return ((wp * (w + wp)) + d**2) / (
|
||||
csqrt(wp**2 - d**2) * csqrt((w + wp) ** 2 - d**2)
|
||||
)
|
||||
|
||||
|
||||
def s(k, e, v):
|
||||
return (e - 1j * v) / k
|
||||
|
||||
|
||||
def f(k, e, v):
|
||||
sv = s(k, e, v)
|
||||
logv = np.log(np.real_if_close((sv + 1) / (sv - 1)) + 0j)
|
||||
return (1 / k) * (2 * sv + ((1 - sv**2) * logv))
|
||||
|
||||
|
||||
def i1(w, wp, k, v, d):
|
||||
gv = g(w, wp, d)
|
||||
e1 = csqrt((w + wp) ** 2 - d**2)
|
||||
e2 = csqrt(wp**2 - d**2)
|
||||
|
||||
f_upper = f(k, np.real(e1 - e2), np.imag(e1 + e2) + 2 * v) * (gv + 1)
|
||||
f_lower = f(k, np.real(-e1 - e2), np.imag(e1 + e2) + 2 * v) * (gv - 1)
|
||||
|
||||
return f_upper + f_lower
|
||||
|
||||
|
||||
def i2(w, wp, k, v, d):
|
||||
gv = g(w, wp, d)
|
||||
e1 = csqrt((w + wp) ** 2 - d**2)
|
||||
e2 = csqrt(wp**2 - d**2)
|
||||
|
||||
f_upper = f(k, np.real(e1 - e2), np.imag(e1 + e2) + 2 * v) * (gv + 1)
|
||||
f_lower = f(k, np.real(e1 + e2), np.imag(e1 + e2) + 2 * v) * (gv - 1)
|
||||
|
||||
return f_upper + f_lower
|
||||
|
||||
|
||||
def a(w, k, v, t, d):
|
||||
result = pyewjn.util.complex_quad(
|
||||
lambda wp: np.tanh((w + wp) / (2 * t)) * (i1(w, wp, k, v, d)),
|
||||
1 - w,
|
||||
1,
|
||||
epsabs=1e-10,
|
||||
)
|
||||
|
||||
return result[0]
|
||||
|
||||
|
||||
def b_int(wp, w, k, v, t, d):
|
||||
return (np.tanh((w + wp) / (2 * t)) * i1(w, wp, k, v, d)) - (
|
||||
np.tanh(wp / (2 * t)) * i2(w, wp, k, v, d)
|
||||
)
|
||||
|
||||
|
||||
def b(w, k, v, t, d, b_max=np.inf):
|
||||
return pyewjn.util.complex_quad(lambda wp: b_int(wp, w, k, v, t, d), 1, b_max)[0]
|
||||
|
||||
|
||||
def sigma_nam_keep_gap(w, k, v, t, d):
|
||||
return -1j * (3 / 4) * (v / w) * (-a(w, k, v, t, d) + b(w, k, v, t, d))
|
||||
@@ -3,9 +3,10 @@ from scipy.integrate import quad, quadrature
|
||||
|
||||
|
||||
def complex_quad(func, a, b, **kwargs):
|
||||
'''
|
||||
Extends scipy.integrate for complex functions.
|
||||
'''
|
||||
"""
|
||||
Extends scipy.integrate for complex functions.
|
||||
"""
|
||||
|
||||
def real_func(x):
|
||||
return np.real(func(x))
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "pyewjn"
|
||||
version = "0.2.1"
|
||||
version = "0.3.0"
|
||||
description = ""
|
||||
authors = ["Deepak <dmallubhotla+github@gmail.com>"]
|
||||
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
58
tests/noise/test_chi_nam.py
Normal file
58
tests/noise/test_chi_nam.py
Normal file
@@ -0,0 +1,58 @@
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
import pyewjn.dielectric
|
||||
import pyewjn.noise.chi
|
||||
from pyewjn.baskets import CalculationParams
|
||||
|
||||
|
||||
cutoff_to_use = 5.4596e9
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def chi_zz_e_nam():
|
||||
params = CalculationParams(
|
||||
omega=1e9, v_f=2e6, omega_p=3.544907701811032e15, tau=1e-14, t_rel=0.99999
|
||||
)
|
||||
eps_l = pyewjn.dielectric.get_nam_dielectric(cutoff_to_use, params)
|
||||
return pyewjn.noise.chi.get_chi_zz_e(eps_l)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"test_input,expected",
|
||||
[
|
||||
# z chi_zz_e_nam(z)
|
||||
(1e-5, 4.07695673649665e6),
|
||||
(1e-6, 4.095895777068543e9),
|
||||
# (1e-7, 5.012885033150058e12), commenting this one out because it seems numerically too unstable
|
||||
# (1e-8, 1.441261982619894e16), commenting this one out because it seems numerically too unstable
|
||||
],
|
||||
)
|
||||
def test_chi_zz_e_nam(chi_zz_e_nam, test_input, expected):
|
||||
actual = chi_zz_e_nam(test_input)
|
||||
|
||||
np.testing.assert_allclose(
|
||||
actual,
|
||||
expected,
|
||||
rtol=0.05,
|
||||
err_msg="chi_zz_e is inaccurate for nam case",
|
||||
verbose=True,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"test_input,expected",
|
||||
[
|
||||
# z chi_zz_e_nam(z)
|
||||
(1e-6, 4.095895777068543e9),
|
||||
],
|
||||
)
|
||||
def test_chi_zz_e_nam_benchmark(benchmark, chi_zz_e_nam, test_input, expected):
|
||||
actual = benchmark(chi_zz_e_nam, test_input)
|
||||
np.testing.assert_allclose(
|
||||
actual,
|
||||
expected,
|
||||
rtol=0.05,
|
||||
err_msg="chi_zz_e is inaccurate for nam case",
|
||||
verbose=True,
|
||||
)
|
||||
Reference in New Issue
Block a user