From c9d23a262916f9befd3ad8b39750340160edde11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Sierro?= Date: Wed, 16 Aug 2023 10:15:34 +0200 Subject: [PATCH] change: dispersion wl shrinked the wavelength vector used for dipserion calculation has been shrinked. The new way to determine dt via wavelength_window made it so that there wasn't 2 extra points to take gradients with. --- src/scgenerator/physics/fiber.py | 17 +++++------------ tests/test_grid.py | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 tests/test_grid.py diff --git a/src/scgenerator/physics/fiber.py b/src/scgenerator/physics/fiber.py index 40d311e..094c722 100644 --- a/src/scgenerator/physics/fiber.py +++ b/src/scgenerator/physics/fiber.py @@ -34,21 +34,14 @@ def lambda_for_envelope_dispersion( indices of the original l where the values are valid (i.e. without the two extra on each side) """ - su = np.where((l >= wavelength_window[0]) & (l <= wavelength_window[1]))[0] - if l[su].min() > 1.01 * wavelength_window[0]: + raw_indices = np.where((l >= wavelength_window[0]) & (l <= wavelength_window[1]))[0] + if l[raw_indices].min() > 1.01 * wavelength_window[0]: raise ValueError( f"lower range of {1e9*wavelength_window[0]:.1f}nm is not reached by the grid. " - f"Minimum of grid is {1e9*l[su].min():.1f}nm. Try a finer grid" + f"Minimum of grid is {1e9*l[raw_indices].min():.1f}nm. Try a finer grid" ) - - ind_above_cond = su >= len(l) // 2 - ind_above = su[ind_above_cond] - ind_below = su[~ind_above_cond] - fu = np.concatenate((ind_below, (ind_below + 2)[-2:], (ind_above - 2)[:2], ind_above)) - fs = fu[np.argsort(l[fu])[::-1]] - l_out = l[fs] - ind_out = fs[2:-2] - return l_out, ind_out + sorted_ind = raw_indices[np.argsort(l[raw_indices])] + return l[sorted_ind], sorted_ind[2:-2] def lambda_for_full_field_dispersion( diff --git a/tests/test_grid.py b/tests/test_grid.py new file mode 100644 index 0000000..cb4cad3 --- /dev/null +++ b/tests/test_grid.py @@ -0,0 +1,22 @@ +import numpy as np +import pytest + +import scgenerator as sc + + +def test_scaling(): + period = 2 + nt = 512 + t = sc.tspace(period, nt) + w = sc.wspace(t) + dt = t[1] - t[0] + assert w[1] - w[0] == pytest.approx(2 * np.pi / (period + dt)) + assert dt == pytest.approx(period / (nt - 1)) + + +def test_wl_dispersion(): + t = sc.tspace(t_num=1 << 15, dt=3.8e-15) + w = sc.wspace(t) + wl = sc.units.m.inv(w + sc.units.nm(1546)) + wl_disp, ind_disp = sc.fiber.lambda_for_envelope_dispersion(wl, (950e-9, 4000e-9)) + assert all(np.diff(wl_disp) > 0)