def __call__(self, domain: Domain) -> Tuple[List[int], List[Field]]: output_ports: List[int] = [] output_fields: List[Field] = [] field = Field(domain, cst.OPTI, self.field_name) # Check offset ------------------------------------------------- for i in range(len(self.offset_nu)): if (abs(self.offset_nu[i]) > domain.nu_window): self.offset_nu[i] = 0.0 util.warning_terminal( "The offset of channel {} in component " "{} is bigger than half the frequency window, offset will " "be ignored.".format(str(i), self.name)) # Field initialization ----------------------------------------- if (self.energy): peak_power: List[float] = [] time_window = domain.time_window * 1e-12 # ps -> s for i in range(len(self.energy)): peak_power.append(self.energy[i] / time_window) else: peak_power = self.peak_power rep_freq = np.nan for i in range(self.channels): # Nbr of channels res = np.zeros(domain.time.shape, dtype=cst.NPFT) phi = (self.init_phi[i] - Domain.nu_to_omega(self.offset_nu[i]) * domain.time) res += math.sqrt(peak_power[i]) * np.exp(1j * phi) field.add_channel(res, Domain.lambda_to_omega(self.center_lambda[i]), rep_freq) output_fields.append(field) output_ports.append(0) return output_ports, output_fields
def __call__(self, domain: Domain) -> Tuple[List[int], List[Field]]: output_ports: List[int] = [] output_fields: List[Field] = [] field = Field(domain, cst.OPTI) # Bit rate initialization -------------------------------------- nbr_pulses = [] for i in range(self.channels): if (self.bit_rate[i]): nbr_temp = math.floor(domain.time_window * self.bit_rate[i]) if (nbr_temp): nbr_pulses.append(nbr_temp) else: util.warning_terminal( "In component {}: the time window " "is too thin for the bit rate specified, bit rate " "will be ignored".format(self.name)) nbr_pulses.append(1) else: nbr_pulses.append(1) rel_pos = [] for i in range(self.channels): pos_step = 1 / nbr_pulses[i] if (nbr_pulses[i] % 2): # Odd dist_from_center = nbr_pulses[i] // 2 * pos_step else: dist_from_center = (nbr_pulses[i] // 2 - 1) * pos_step + pos_step / 2 rel_pos.append( np.linspace(self.position[i] - dist_from_center, self.position[i] + dist_from_center, num=nbr_pulses[i])) # Check offset ------------------------------------------------- for i in range(len(self.offset_nu)): if (abs(self.offset_nu[i]) > domain.nu_window): self.offset_nu[i] = 0.0 util.warning_terminal( "The offset of channel {} in component " "{} is bigger than half the frequency window, offset will " "be ignored.".format(str(i), self.name)) # Field initialization ----------------------------------------- for i in range(self.channels): # Nbr of channels res = np.zeros(domain.time.shape, dtype=cst.NPFT) for j in range(len(rel_pos[i])): norm_time = domain.get_shift_time( rel_pos[i][j]) / self.width[i] var_time = np.power(norm_time, 2) phi = (self.init_phi[i] - Domain.nu_to_omega(self.offset_nu[i]) * domain.time - 0.5 * self.chirp[i] * var_time) res += (math.sqrt(self.peak_power[i]) / np.cosh(norm_time) * np.exp(1j * phi)) field.append(res, Domain.lambda_to_omega(self.center_lambda[i])) output_fields.append(field) output_ports.append(0) return output_ports, output_fields
def __call__(self, domain: Domain) -> Tuple[List[int], List[Field]]: output_ports: List[int] = [] output_fields: List[Field] = [] field: Field = Field(domain, cst.OPTI, self.field_name) # Bit rate initialization -------------------------------------- rel_pos: List[np.ndarray] rel_pos = util.pulse_positions_in_time_window(self.channels, self.rep_freq, domain.time_window, self.position) # Check offset ------------------------------------------------- for i in range(len(self.offset_nu)): if (abs(self.offset_nu[i]) > domain.nu_window): self.offset_nu[i] = 0.0 util.warning_terminal( "The offset of channel {} in component " "{} is bigger than half the frequency window, offset will " "be ignored.".format(str(i), self.name)) # Field initialization ----------------------------------------- width: float for i in range(self.channels): # Nbr of channels if (self.fwhm is None): width = self.width[i] else: width = self.fwhm_to_width(self.fwhm[i]) res: np.ndarray = np.zeros(domain.time.shape, dtype=cst.NPFT) for j in range(len(rel_pos[i])): norm_time = domain.get_shift_time(rel_pos[i][j]) / width var_time = np.power(norm_time, 2) phi = (self.init_phi[i] - Domain.nu_to_omega(self.offset_nu[i]) * domain.time - 0.5 * self.chirp[i] * var_time) res += (math.sqrt(self.peak_power[i]) / np.cosh(norm_time) * np.exp(1j * phi)) field.add_channel(res, Domain.lambda_to_omega(self.center_lambda[i]), self.rep_freq[i]) if (self.noise is not None): field.noise = self.noise output_fields.append(field) output_ports.append(0) return output_ports, output_fields
return 1.0 / (power * nl_coeff) if __name__ == "__main__": import numpy as np import optcom.utils.plot as plot from optcom.domain import Domain from optcom.parameters.fiber.effective_area import EffectiveArea from optcom.parameters.fiber.nl_index import NLIndex medium = "SiO2" # With float omega = Domain.lambda_to_omega(1552.0) core_radius = 5.0 n_core = 1.43 n_clad = 1.425 eff_area = EffectiveArea.calc_effective_area(omega, core_radius=core_radius, n_core=n_core, n_clad=n_clad) nl_index = NLIndex.calc_nl_index(omega, medium=medium) print( NLCoefficient.calc_nl_coefficient(omega, nl_index=nl_index, eff_area=eff_area)) # With numpy ndarray
return Dispersion.calc_dispersion(beta_2, Lambda) * length if __name__ == "__main__": import optcom.utils.plot as plot from optcom.domain import Domain from optcom.equations.sellmeier import Sellmeier center_omega = 1929.97086814 #Domain.lambda_to_omega(976.0) sellmeier = Sellmeier("Sio2") betas = Dispersion.calc_beta_coeffs(center_omega, 13, sellmeier) print('betas: ', betas) Lambda = np.linspace(900, 1600, 1000) omega = Domain.lambda_to_omega(Lambda) beta_2 = Dispersion.calc_beta_deriv(omega, 2, "SiO2") x_data = [Lambda] y_data = [beta_2] x_labels = ['Lambda'] y_labels = ['beta2'] plot_titles = ["Group velocity dispersion coefficients in Silica"] disp = Dispersion.calc_dispersion(Lambda, beta_2) x_data.append(Lambda) y_data.append(disp) x_labels.append('Lambda') y_labels.append('dispersion') plot_titles.append('Dispersion of Silica')
res = math.sqrt(res) else: # numpy.ndarray res = np.ones(Lambda.shape) for i in range(len(self._Bs)): res += (self._Bs[i]*Lambda**2) / (Lambda**2 - self._Cs[i]) res = np.sqrt(res) return res if __name__ == "__main__": import optcom.utils.plot as plot from optcom.domain import Domain sellmeier = Sellmeier("sio2") center_omega = Domain.lambda_to_omega(1050.0) print(sellmeier.n(center_omega)) Lambda = np.linspace(120, 2120, 2000) omega = Domain.lambda_to_omega(Lambda) n = sellmeier.n(omega) x_labels = ['Lambda'] y_labels = ['Refractive index'] plot_titles = ["Refractive index of Silica from Sellmeier equations"] plot.plot2d(Lambda, n, x_labels=x_labels, y_labels=y_labels, plot_titles=plot_titles, opacity=0.0)
# dopant_range = {dopant:(bottom, up), \ldots} # in nm dopant_range = {"yb": (900, 1050), "er": (1400, 1650)} folder = './data/fiber_amp/cross_section/emission/' files = ['yb'] file_range = [(900.0, 1050.0)] x_data = [] y_data = [] plot_titles = [] for dopant in dopants: nbr_samples = 1000 lambdas = np.linspace(dopant_range[dopant][0], dopant_range[dopant][1], nbr_samples) omegas = Domain.lambda_to_omega(lambdas) center_lambda = (dopant_range[dopant][0] + dopant_range[dopant][1]) / 2 center_omega = Domain.lambda_to_omega(center_lambda) N_0 = 0.01 # nm^-3 N_1 = 0.01 * 1.5 # nm^-3 T = 293.5 stimu = StimulatedEmission(dopant=dopant) sigmas = stimu.get_cross_section(omegas, center_omega, N_0, N_1, T) x_data.append(lambdas) y_data.append(sigmas) dopant_name = dopant[0].upper() + dopant[1:] plot_titles.append("Cross sections {} from formula and McCumber " "relations".format(dopant_name)) for i, file in enumerate(files): nbr_samples = 1000
import optcom.utils.constants as cst import optcom.utils.plot as plot from optcom.domain import Domain from optcom.utils.fft import FFT samples = 1000 time, dtime = np.linspace(0.0, 0.3, samples, False, True) # ps freq_window = 1.0 / dtime x_data = [] y_data = [] plot_labels = [] f_R: float = cst.F_R n_0: float = 1.40 center_omega = Domain.lambda_to_omega(1550.0) f_a: float = cst.F_A f_b: float = cst.F_B f_c: float = cst.F_C x_data.append(time) h_R = Raman.calc_h_R(time, f_a=f_a, f_b=f_b, f_c=f_c) y_data.append(h_R) plot_labels.append('Isotropic and anisotropic part') f_a = 1.0 f_b = 0.0 f_c = 1.0 x_data.append(time) h_R = Raman.calc_h_R(time, f_a=f_a, f_b=f_b, f_c=f_c) y_data.append(h_R) plot_labels.append('W/o anisotropic part')
Lambda: float = 1030.0 pulse: Gaussian = Gaussian(channels=1, peak_power=[1.0, 1.0], center_lambda=[Lambda]) steps: int = int(1e1) beta_01: float = 1e5 beta_02: float = 1e5 beta: List[Union[List[float], Callable, None]] =\ [[beta_01,10.0,-0.0],[beta_02,10.0,-0.0]] v_nbr_value = 2.0 v_nbr: List[Union[float, Callable, None]] = [v_nbr_value] core_radius: List[float] = [5.0] c2c_spacing: List[List[float]] = [[15.0]] n_clad: float = 1.02 omega: float = Domain.lambda_to_omega(Lambda) kappa_: Union[float, Callable] kappa_ = CouplingCoeff.calc_kappa(omega, v_nbr_value, core_radius[0], c2c_spacing[0][0], n_clad) kappa: List[List[Union[List[float], Callable, None]]] = [[None]] delta_a: float = 0.5 * (beta_01 - beta_02) length_c: float = cst.PI / (2 * math.sqrt(delta_a**2 + kappa_**2)) length: float = length_c / 2 for j, method in enumerate(ode_methods): coupler = FiberCoupler(length=length, kappa=kappa, v_nbr=v_nbr, core_radius=core_radius, n_clad=n_clad, c2c_spacing=c2c_spacing,