Added uniform w helper method, better derivative
This commit is contained in:
@@ -14,14 +14,18 @@ from scgenerator.parameter import Parameters
|
||||
from scgenerator.physics.fiber import beta2, n_eff_hasan, n_eff_marcatili
|
||||
from scgenerator.physics.materials import n_gas_2
|
||||
from scgenerator.physics.simulate import RK4IP
|
||||
from scgenerator.physics.units import c
|
||||
from scgenerator.physics.units import c, nm
|
||||
|
||||
try:
|
||||
from tqdm import tqdm
|
||||
except ModuleNotFoundError:
|
||||
tqdm = None
|
||||
|
||||
__all__ = ["capillary_dispersion", "capillary_zdw", "revolver_dispersion","quick_sim"]
|
||||
__all__ = ["capillary_dispersion", "capillary_zdw", "revolver_dispersion", "quick_sim", "w_from_wl"]
|
||||
|
||||
|
||||
def w_from_wl(wl_min_nm: float, wl_max_nm: float, n: int) -> np.ndarray:
|
||||
return np.linspace(nm(wl_max_nm), nm(wl_min_nm), n)
|
||||
|
||||
|
||||
def capillary_dispersion(
|
||||
@@ -156,7 +160,7 @@ def extend_axis(axis: np.ndarray) -> np.ndarray:
|
||||
return axis
|
||||
|
||||
|
||||
def quick_sim(params: dict[str, Any] | Parameters, **_params:Any) -> tuple[Parameters, np.ndarray]:
|
||||
def quick_sim(params: dict[str, Any] | Parameters, **_params: Any) -> tuple[Parameters, np.ndarray]:
|
||||
"""
|
||||
run a quick simulation
|
||||
|
||||
@@ -176,9 +180,9 @@ def quick_sim(params: dict[str, Any] | Parameters, **_params:Any) -> tuple[Param
|
||||
|
||||
"""
|
||||
if isinstance(params, Mapping):
|
||||
params = Parameters(**(params|_params))
|
||||
params = Parameters(**(params | _params))
|
||||
else:
|
||||
params = Parameters(**(tomli.loads(Path(params).read_text())|_params))
|
||||
params = Parameters(**(tomli.loads(Path(params).read_text()) | _params))
|
||||
|
||||
sim = RK4IP(params)
|
||||
if tqdm:
|
||||
|
||||
@@ -619,12 +619,14 @@ def stencil_coefficients_set(n: int, order: int) -> tuple[np.ndarray, np.ndarray
|
||||
|
||||
|
||||
def differentiate_arr(
|
||||
values: np.ndarray, diff_order: int, extent: int, correct_edges=True
|
||||
values: np.ndarray,
|
||||
diff_order: int,
|
||||
extent: int | None = None,
|
||||
h: float = 1.0,
|
||||
correct_edges=True,
|
||||
) -> np.ndarray:
|
||||
"""
|
||||
takes a derivative of order `diff_order` using equally spaced values
|
||||
**NOTE** : this function doesn't actually know about your grid spacing `h`, so you need to
|
||||
divide the result by `h**diff_order` to get a correct result.
|
||||
|
||||
Parameters
|
||||
---------
|
||||
@@ -632,10 +634,12 @@ def differentiate_arr(
|
||||
equally spaced values
|
||||
diff_order : int
|
||||
order of differentiation
|
||||
extent : int
|
||||
extent : int, optional
|
||||
how many points away from the center the scheme uses. This determines accuracy.
|
||||
example: extent=6 means that 13 (6 on either side + center) points are used to evaluate the
|
||||
derivative at each point.
|
||||
derivative at each point. by default diff_order + 2
|
||||
h : float, optional
|
||||
step size, by default 1.0
|
||||
correct_edges : bool, optional
|
||||
avoid artifacts by using forward/backward schemes on the edges, by default True
|
||||
|
||||
@@ -644,17 +648,20 @@ def differentiate_arr(
|
||||
https://en.wikipedia.org/wiki/Finite_difference_coefficient
|
||||
|
||||
"""
|
||||
if extent is None:
|
||||
extent = diff_order + 2
|
||||
n_points = (diff_order + extent) // 2
|
||||
|
||||
if not correct_edges:
|
||||
central_coefs = central_stencil_coefficients(n_points, diff_order)
|
||||
return np.convolve(values, central_coefs[::-1], mode="same")
|
||||
|
||||
left_coefs, central_coefs, right_coefs = stencil_coefficients_set(n_points, diff_order)
|
||||
return np.concatenate(
|
||||
(
|
||||
np.convolve(values[: 2 * n_points], left_coefs[::-1], mode="valid"),
|
||||
np.convolve(values, central_coefs[::-1], mode="valid"),
|
||||
np.convolve(values[-2 * n_points :], right_coefs[::-1], mode="valid"),
|
||||
result = np.convolve(values, central_coefs[::-1], mode="same")
|
||||
else:
|
||||
left_coefs, central_coefs, right_coefs = stencil_coefficients_set(n_points, diff_order)
|
||||
result = np.concatenate(
|
||||
(
|
||||
np.convolve(values[: 2 * n_points], left_coefs[::-1], mode="valid"),
|
||||
np.convolve(values, central_coefs[::-1], mode="valid"),
|
||||
np.convolve(values[-2 * n_points :], right_coefs[::-1], mode="valid"),
|
||||
)
|
||||
)
|
||||
)
|
||||
return result / h**diff_order
|
||||
|
||||
@@ -926,6 +926,11 @@ def gap_from_capillaries(core_radius: float, tube_radius: float, n_tubes: int) -
|
||||
return 2 * (s * (tube_radius + core_radius) - tube_radius)
|
||||
|
||||
|
||||
def tube_radius_from_gap(core_radius: float, gap: float, n_tubes: int) -> float:
|
||||
s = np.sin(np.pi / n_tubes)
|
||||
return (core_radius * s - 0.5 * gap) / (1 - s)
|
||||
|
||||
|
||||
def normalized_frequency_vincetti(
|
||||
wl: np.ndarray, thickness: float, n_clad_2: np.ndarray, n_gas_2: np.ndarray
|
||||
) -> np.ndarray:
|
||||
@@ -1136,4 +1141,3 @@ def n_eff_vincetti(
|
||||
|
||||
# eq. (21) in [1]
|
||||
return n_gas - 0.125 / n_gas * (u_nm(1, 1) * wl_for_disp / (np.pi * r_co_eff)) ** 2 + d_n_eff
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ from typing import TypeVar
|
||||
|
||||
import numpy as np
|
||||
|
||||
import scgenerator.math as math
|
||||
from scgenerator import utils
|
||||
from scgenerator.cache import np_cache
|
||||
from scgenerator.logger import get_logger
|
||||
@@ -74,6 +75,28 @@ class Sellmeier:
|
||||
def n(self, wl: T, temperature: float | None = None, pressure: float | None = None) -> T:
|
||||
return np.sqrt(self.n_gas_2(wl, temperature, pressure))
|
||||
|
||||
def delta(self, wl: np.ndarray, wl_zero_disp: float) -> np.ndarray:
|
||||
"""
|
||||
'delta' quantity that describes the gas dispersion according to eq. S7 in [1]
|
||||
|
||||
Parameters
|
||||
----------
|
||||
wl : ndarray
|
||||
wavelength in m
|
||||
wl_zero_disp : float
|
||||
zero dispersion wavelength in m
|
||||
|
||||
Reference
|
||||
---------
|
||||
[1] TRAVERS, John C., GRIGOROVA, Teodora F., BRAHMS, Christian, et al. High-energy
|
||||
pulse self-compression and ultraviolet generation through soliton dynamics in hollow
|
||||
capillary fibres. Nature Photonics, 2019, vol. 13, no 8, p. 547-554.
|
||||
"""
|
||||
factor = (math.u_nm(1, 1) / c) ** 2 * (0.5 * wl / np.pi) ** 3
|
||||
f = np.gradient(np.gradient(self.chi(wl), wl), wl)
|
||||
ind = math.argclosest(wl, wl_zero_disp)
|
||||
return factor * (f / f[ind] - 1)
|
||||
|
||||
|
||||
class Gas:
|
||||
name: str
|
||||
|
||||
Reference in New Issue
Block a user