better A_eff with add numerical_aperture param
This commit is contained in:
55
play.py
55
play.py
@@ -1,47 +1,18 @@
|
|||||||
from typing import Any, Generator
|
import os
|
||||||
import scgenerator as sc
|
|
||||||
import itertools
|
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import scgenerator as sc
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
class DataPather:
|
def main():
|
||||||
def __init__(self, dl: list[dict[str, Any]]):
|
drr = os.getcwd()
|
||||||
self.dict_list = dl
|
os.chdir("/Users/benoitsierro/Nextcloud/PhD/Supercontinuum/PCF Simulations")
|
||||||
self.n = len(self.dict_list)
|
try:
|
||||||
self.final_list = list(self.dico_iterator(self.n))
|
sc.run_simulation("PM1550+PM2000D/Pos30000.toml")
|
||||||
|
finally:
|
||||||
def dico_iterator(self, index: int) -> Generator[list[list[tuple[str, Any]]], None, None]:
|
os.chdir(drr)
|
||||||
d_tem_list = [el for d in self.dict_list[: index + 1] for el in d.items()]
|
|
||||||
dict_pos = np.cumsum([0] + [len(d) for d in self.dict_list[: index + 1]])
|
|
||||||
ranges = [range(len(l)) for _, l in d_tem_list]
|
|
||||||
|
|
||||||
for r in itertools.product(*ranges):
|
|
||||||
flat = [(d_tem_list[i][0], d_tem_list[i][1][j]) for i, j in enumerate(r)]
|
|
||||||
out = [flat[left:right] for left, right in zip(dict_pos[:-1], dict_pos[1:])]
|
|
||||||
yield out
|
|
||||||
|
|
||||||
def all_vary_list(self, index):
|
|
||||||
for l in self.dico_iterator(index):
|
|
||||||
yield sc.utils.parameter.format_variable_list(
|
|
||||||
sc.utils.parameter.reduce_all_variable(l[:index])
|
|
||||||
), sc.utils.parameter.format_variable_list(
|
|
||||||
sc.utils.parameter.reduce_all_variable(l)
|
|
||||||
), l[
|
|
||||||
index
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
configs, name = sc.utils.load_config_sequence(
|
if __name__ == "__main__":
|
||||||
"/Users/benoitsierro/Nextcloud/PhD/Supercontinuum/PCF Simulations/Test/NewStyle.toml"
|
main()
|
||||||
)
|
|
||||||
|
|
||||||
dp = DataPather([config["variable"] for config in configs])
|
|
||||||
# pprint(list(dp.dico_iterator(1)))
|
|
||||||
for i in range(3):
|
|
||||||
for prev_path, this_path, this_vary in dp.all_vary_list(i):
|
|
||||||
print(prev_path)
|
|
||||||
print(this_path)
|
|
||||||
print(this_vary)
|
|
||||||
print()
|
|
||||||
print()
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
__version__ = "0.2.2rules"
|
__version__ = "0.2.3rules"
|
||||||
|
|
||||||
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
from typing import Any, Dict, Iterable, List, Literal, Optional, Tuple, Union, TypeVar
|
from typing import Any, Iterable, Literal, TypeVar
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from numpy.ma import core
|
|
||||||
from numpy.fft import fft, ifft
|
from numpy.fft import fft, ifft
|
||||||
from numpy.polynomial.chebyshev import Chebyshev, cheb2poly
|
from numpy.polynomial.chebyshev import Chebyshev, cheb2poly
|
||||||
from scipy.interpolate import interp1d
|
from scipy.interpolate import interp1d
|
||||||
@@ -280,13 +279,42 @@ def A_eff_hasan(core_radius, capillary_num, capillary_spacing):
|
|||||||
return M_f * core_radius ** 2 * np.exp((capillary_spacing / 22e-6) ** 2.5)
|
return M_f * core_radius ** 2 * np.exp((capillary_spacing / 22e-6) ** 2.5)
|
||||||
|
|
||||||
|
|
||||||
def V_eff_marcuse(l: T, core_radius: float, numerical_aperture: float) -> T:
|
def V_eff_step_index(
|
||||||
return 2 * pi * core_radius * numerical_aperture / l
|
l: T,
|
||||||
|
core_radius: float,
|
||||||
|
numerical_aperture: float,
|
||||||
|
interpolation_range: tuple[float, float] = None,
|
||||||
|
) -> T:
|
||||||
|
"""computes the V parameter of a step-index fiber
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
l : T
|
||||||
|
wavelength
|
||||||
|
core_radius : float
|
||||||
|
radius of the core
|
||||||
|
numerical_aperture : float
|
||||||
|
as a decimal number
|
||||||
|
interpolation_range : tuple[float, float], optional
|
||||||
|
when provided, only computes V over this range, wavelengths outside this range will
|
||||||
|
yield V=inf, by default None
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
T
|
||||||
|
V parameter
|
||||||
|
"""
|
||||||
|
pi2cn = 2 * pi * core_radius * numerical_aperture
|
||||||
|
if interpolation_range is not None and isinstance(l, np.ndarray):
|
||||||
|
low, high = interpolation_range
|
||||||
|
l = np.where((l >= low) & (l <= high), l, np.inf)
|
||||||
|
return pi2cn / l
|
||||||
|
|
||||||
|
|
||||||
def V_parameter_koshiba(l: np.ndarray, pitch: float, pitch_ratio: float) -> float:
|
def V_parameter_koshiba(l: np.ndarray, pitch: float, pitch_ratio: float) -> float:
|
||||||
"""returns the V parameter according to Koshiba2004
|
"""returns the V parameter according to Koshiba2004
|
||||||
|
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
l : np.ndarray, shape (n,)
|
l : np.ndarray, shape (n,)
|
||||||
@@ -322,19 +350,21 @@ def A_eff_from_V(core_radius: float, V_eff: T) -> T:
|
|||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
wl : T
|
|
||||||
wavelength
|
|
||||||
core_radius : float
|
core_radius : float
|
||||||
in m
|
in m
|
||||||
numerical_aperture : float
|
V_eff : T
|
||||||
NA
|
effective V parameter.
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
T
|
T
|
||||||
A_eff as function of wl
|
A_eff
|
||||||
"""
|
"""
|
||||||
return core_radius * (0.65 + 1.619 / V_eff ** 1.5 + 2.879 / V_eff ** 6)
|
out = np.ones_like(V_eff)
|
||||||
|
out[V_eff > 0] = core_radius * (
|
||||||
|
0.65 + 1.619 / V_eff[V_eff > 0] ** 1.5 + 2.879 / V_eff[V_eff > 0] ** 6
|
||||||
|
)
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
def HCPCF_find_with_given_ZDW(
|
def HCPCF_find_with_given_ZDW(
|
||||||
@@ -547,15 +577,15 @@ def HCPCF_dispersion(
|
|||||||
|
|
||||||
def dynamic_HCPCF_dispersion(
|
def dynamic_HCPCF_dispersion(
|
||||||
wl_for_disp: np.ndarray,
|
wl_for_disp: np.ndarray,
|
||||||
pressure_values: List[float],
|
pressure_values: list[float],
|
||||||
core_radius: float,
|
core_radius: float,
|
||||||
fiber_model: str,
|
fiber_model: str,
|
||||||
model_params: Dict[str, Any],
|
model_params: dict[str, Any],
|
||||||
temperature: float,
|
temperature: float,
|
||||||
ideal_gas: bool,
|
ideal_gas: bool,
|
||||||
w0: float,
|
w0: float,
|
||||||
interp_range: Tuple[float, float],
|
interp_range: tuple[float, float],
|
||||||
material_dico: Dict[str, Any],
|
material_dico: dict[str, Any],
|
||||||
deg: int,
|
deg: int,
|
||||||
):
|
):
|
||||||
"""returns functions for beta2 coefficients and gamma instead of static values
|
"""returns functions for beta2 coefficients and gamma instead of static values
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import os
|
|||||||
import random
|
import random
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Generator, Type
|
from typing import Any, Generator, Type, Union
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from send2trash import send2trash
|
from send2trash import send2trash
|
||||||
@@ -423,7 +423,7 @@ class Simulations:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def new(
|
def new(
|
||||||
cls, configuration: Configuration, task_id, method: Type["Simulations"] = None
|
cls, configuration: Configuration, task_id, method: Union[str, Type["Simulations"]] = None
|
||||||
) -> "Simulations":
|
) -> "Simulations":
|
||||||
"""Prefered method to create a new simulations object
|
"""Prefered method to create a new simulations object
|
||||||
|
|
||||||
@@ -697,7 +697,7 @@ class RaySimulations(Simulations, priority=2):
|
|||||||
|
|
||||||
def run_simulation(
|
def run_simulation(
|
||||||
config_file: os.PathLike,
|
config_file: os.PathLike,
|
||||||
method=None,
|
method: Union[str, Type[Simulations]] = None,
|
||||||
):
|
):
|
||||||
config = Configuration(config_file)
|
config = Configuration(config_file)
|
||||||
|
|
||||||
@@ -718,7 +718,7 @@ def run_simulation(
|
|||||||
|
|
||||||
def new_simulation(
|
def new_simulation(
|
||||||
configuration: Configuration,
|
configuration: Configuration,
|
||||||
method: Type[Simulations] = None,
|
method: Union[str, Type[Simulations]] = None,
|
||||||
) -> Simulations:
|
) -> Simulations:
|
||||||
logger = get_logger(__name__)
|
logger = get_logger(__name__)
|
||||||
task_id = random.randint(1e9, 1e12)
|
task_id = random.randint(1e9, 1e12)
|
||||||
@@ -743,7 +743,7 @@ def __parallel_RK4IP_worker(
|
|||||||
|
|
||||||
|
|
||||||
def parallel_RK4IP(
|
def parallel_RK4IP(
|
||||||
config,
|
config: os.PathLike,
|
||||||
) -> Generator[
|
) -> Generator[
|
||||||
tuple[tuple[list[tuple[str, Any]], Parameters, int, int, np.ndarray], ...], None, None
|
tuple[tuple[list[tuple[str, Any]], Parameters, int, int, np.ndarray], ...], None, None
|
||||||
]:
|
]:
|
||||||
@@ -769,7 +769,7 @@ def parallel_RK4IP(
|
|||||||
for q in pipes:
|
for q in pipes:
|
||||||
q[1].send(0)
|
q[1].send(0)
|
||||||
logger.debug("msg sent")
|
logger.debug("msg sent")
|
||||||
computed_dict = {}
|
computed_dict: dict[int, np.ndarray] = {}
|
||||||
for j in range(n):
|
for j in range(n):
|
||||||
w_id, computed = data_queue.get()
|
w_id, computed = data_queue.get()
|
||||||
computed_dict[w_id] = computed
|
computed_dict[w_id] = computed
|
||||||
|
|||||||
@@ -331,6 +331,7 @@ class Parameters:
|
|||||||
effective_mode_diameter: float = Parameter(positive(float, int))
|
effective_mode_diameter: float = Parameter(positive(float, int))
|
||||||
A_eff: float = Parameter(non_negative(float, int))
|
A_eff: float = Parameter(non_negative(float, int))
|
||||||
A_eff_file: str = Parameter(string)
|
A_eff_file: str = Parameter(string)
|
||||||
|
numerical_aperture: float = Parameter(in_range_excl(0, 1))
|
||||||
pitch: float = Parameter(in_range_excl(0, 1e-3))
|
pitch: float = Parameter(in_range_excl(0, 1e-3))
|
||||||
pitch_ratio: float = Parameter(in_range_excl(0, 1))
|
pitch_ratio: float = Parameter(in_range_excl(0, 1))
|
||||||
core_radius: float = Parameter(in_range_excl(0, 1e-3))
|
core_radius: float = Parameter(in_range_excl(0, 1e-3))
|
||||||
@@ -1371,15 +1372,19 @@ default_rules: list[Rule] = [
|
|||||||
["wavelength", "pitch", "pitch_ratio"],
|
["wavelength", "pitch", "pitch_ratio"],
|
||||||
conditions=dict(model="pcf"),
|
conditions=dict(model="pcf"),
|
||||||
),
|
),
|
||||||
Rule("V_eff", fiber.V_eff_marcuse, ["wavelength", "core_radius", "numerical_aperture"]),
|
Rule("V_eff", fiber.V_eff_step_index, ["wavelength", "core_radius", "numerical_aperture"]),
|
||||||
Rule("V_eff_arr", fiber.V_parameter_koshiba, conditions=dict(model="pcf")),
|
Rule("V_eff_arr", fiber.V_parameter_koshiba, conditions=dict(model="pcf")),
|
||||||
Rule("V_eff_arr", fiber.V_eff_marcuse),
|
Rule(
|
||||||
|
"V_eff_arr",
|
||||||
|
fiber.V_eff_step_index,
|
||||||
|
["l", "core_radius", "numerical_aperture", "interpolation_range"],
|
||||||
|
),
|
||||||
Rule("gamma", lambda gamma_arr: gamma_arr[0]),
|
Rule("gamma", lambda gamma_arr: gamma_arr[0]),
|
||||||
Rule("gamma_arr", fiber.gamma_parameter, ["n2", "w0", "A_eff_arr"]),
|
Rule("gamma_arr", fiber.gamma_parameter, ["n2", "w0", "A_eff_arr"]),
|
||||||
# Fiber loss
|
# Fiber loss
|
||||||
Rule("alpha_arr", fiber.compute_capillary_loss),
|
Rule("alpha_arr", fiber.compute_capillary_loss),
|
||||||
Rule("alpha_arr", fiber.load_custom_loss),
|
Rule("alpha_arr", fiber.load_custom_loss),
|
||||||
Rule("alpha_arr", lambda alpha, t: np.ones_like(t) * alpha),
|
Rule("alpha_arr", lambda alpha, t: np.ones_like(t) * alpha, priorities=-1),
|
||||||
# gas
|
# gas
|
||||||
Rule("n_gas_2", materials.n_gas_2),
|
Rule("n_gas_2", materials.n_gas_2),
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user