From 40a157dff1958404c6e91a318daf58f0e92e4fa3 Mon Sep 17 00:00:00 2001 From: lorenzifrancesco Date: Tue, 21 Jan 2025 20:03:14 +0100 Subject: [PATCH] fix: cf overwriting error --- pynlin/raman/solvers.py | 4 ++- scripts/optimize.py | 57 ++++++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/pynlin/raman/solvers.py b/pynlin/raman/solvers.py index 3c26a05..47d9e90 100644 --- a/pynlin/raman/solvers.py +++ b/pynlin/raman/solvers.py @@ -791,9 +791,11 @@ def optim_fun(x0): # Compute the phonon occupancy factor Hinv = np.exp(h_planck * np.abs(frequency_shifts) / (kB * temperature)) - 1 - + # FIXME evidentemente stiamo considerando onde che hanno la stessa frequenza. Dobbiamo + # sommare l'effetto solo sullo stesso modo, e lasciare che il coupling misceli tutto. eta = 1 + 1 / Hinv np.fill_diagonal(eta, 0) + # print(eta) eta = np.repeat(np.repeat(eta, fiber.n_modes, axis=0), fiber.n_modes, axis=1) # Compute the new Raman gain matrix diff --git a/scripts/optimize.py b/scripts/optimize.py index dd31515..a641965 100644 --- a/scripts/optimize.py +++ b/scripts/optimize.py @@ -188,42 +188,47 @@ def repropagate_numpy(fiber, # Configuration recompute = False repropagate = True - use_avg_oi = True + use_avg_oi = False # signal_powers = [-10] - signal_powers = [-10, -5, 0] + signal_powers = [0, -5, -10] + # -10 -> true + # -5 -> true OI + # 0 -> true OI oi_fit = np.load('oi_fit.npy') oi_avg = np.load('oi_avg.npy') + + # prepare the definitions of fiber and wdm + cf = cfg.load_toml_to_struct("./input/config.toml") + num_original_modes = oi_avg[0].shape[0] + matrix_avg = oi_avg + matrix_zeros = np.tile(np.zeros((num_original_modes, num_original_modes))[ + None, :, :], (5, 1, 1)) + oi_avg_complete = np.stack((*matrix_zeros, matrix_avg), axis=0) + if use_avg_oi: + oi_set = oi_avg_complete + else: + oi_set = oi_fit + oi_fit = oi_avg_complete + # + fiber = pynlin.fiber.MMFiber( + effective_area=80e-12, + n_modes=cf.n_modes, + overlap_integrals=oi_set, + group_delay=load_group_delay() + ) + wdm = pynlin.wdm.WDM( + spacing=cf.channel_spacing, + num_channels=cf.n_channels, + center_frequency=cf.center_frequency + ) for signal_power in signal_powers: - cf = cfg.load_toml_to_struct("./input/config.toml") cf.launch_power = signal_power cfg.save_struct_to_toml("./input/config.toml", cf) output_file = f"results/ct_solution{signal_power}_gain_{cf.raman_gain}.npy" - # prepare the definitions of fiber and wdm - num_original_modes = oi_avg[0].shape[0] - matrix_avg = oi_avg - matrix_zeros = np.tile(np.zeros((num_original_modes, num_original_modes))[ - None, :, :], (5, 1, 1)) - oi_avg_complete = np.stack((*matrix_zeros, matrix_avg), axis=0) - if use_avg_oi: - oi_set = oi_avg_complete - else: - oi_set = oi_fit - oi_fit = oi_avg_complete - # - fiber = pynlin.fiber.MMFiber( - effective_area=80e-12, - n_modes=cf.n_modes, - overlap_integrals=oi_set, - group_delay=load_group_delay() - ) - wdm = pynlin.wdm.WDM( - spacing=cf.channel_spacing, - num_channels=cf.n_channels, - center_frequency=cf.center_frequency - ) + signal_wavelengths = wdm.wavelength_grid() if not os.path.exists(output_file) or recompute: