Пример #1
0
def test_kerr():
    """More test than example. Show different approximations for the BPM
    implementation of the Kerr effect."""
    no = 1
    lo = 1.5
    length_z = 50
    dist_z = 0.1
    nbr_z_disp = 1
    dist_x = 0.01
    length_x = 400

    bpm = Bpm(no, lo,
              length_z, dist_z, nbr_z_disp,
              length_x, dist_x)

    [length_z, nbr_z, nbr_z_disp, length_x, nbr_x, x] = bpm.create_x_z()

    dn = np.zeros((nbr_z, nbr_x))

    fwhm = 6

    field = bpm.gauss_light(fwhm)
    irrad = 260e13  # if too high, see big difference between method
    theta_ext = 0

    [progress_pow] = bpm.init_field(field, theta_ext, irrad)

    # Need to overwrite those variables due to changes
    theta = asin(sin(radians(theta_ext)) / no)  # angle in the guide
    nu_max = 1 / (2 * dist_x)  # max frequency due to sampling
    # Spacial frequencies over x (1/µm)
    nu = np.linspace(-nu_max,
                     nu_max*(1 - 2/nbr_x),
                     nbr_x)
    intermed = no * cos(theta) / lo
    fr = -2 * pi * nu**2 / (intermed + np.sqrt(
        intermed**2
        - nu**2
        + 0j))

    bpm.phase_mat = fftshift(np.exp(1j * dist_z * fr))
    bpm.phase_mat_demi = fftshift(np.exp(1j * dist_z / 2 * fr))
    bpm.nl_mat = bpm.ko * bpm.dist_z * dn
    # End overwrite

    kerr_loop = 10
    chi3 = 10 * 1E-20

    nbr_step = nbr_z-1

    print("\n dz/2+lens+dz/2")
    field = bpm.field
    for i in range(nbr_step):
        # Linear propagation over dz/2
        field = ifft(bpm.phase_mat_demi * fft(field))

        # Influence of the index modulation on the field
        field = field * np.exp(1j * bpm.nl_mat[nbr_step, :])  # No changes if
        # no initial guide (exp=1)

        # Linear propagation over dz/2
        field = ifft(bpm.phase_mat_demi * fft(field))

        cur_pow = bpm.epnc * abs2(field)

    field_ref = field
    cur_ref = cur_pow

    print("\n dz+kerr")
    field = bpm.field
    for i in range(nbr_step):
        # Linear propagation over dz
        field = ifft(bpm.phase_mat * fft(field))

        # Influence of the index modulation on the field
        field_x = field * np.exp(1j * bpm.nl_mat[nbr_step, :])

        cur_pow = bpm.epnc * abs2(field_x)

        for k in range(1):  # insensitive to correction loop
            prev_pow = cur_pow
            # influence of the beam intensity on the index modulation
            dn_temp = dn[nbr_step, :] + (3*chi3)/(8*no)*(prev_pow/bpm.epnc)
            nl_mat = bpm.ko * bpm.dist_z * dn_temp
            # influence of the index modulation on the field
            field_x = field * np.exp(1j*nl_mat)  # No changes for the pow

            cur_pow = bpm.epnc * abs2(field_x)

        try:
            bpm.variance(prev_pow, cur_pow)
        except ValueError as error:
            print(error)

        field = field_x

    field_1 = field
    cur_1 = cur_pow
    dn_1 = dn_temp

    print("\n dz/2+kerr+dz/2")
    field = bpm.field
    for i in range(nbr_step):
        # Linear propagation over dz/2
        field = ifft(bpm.phase_mat_demi * fft(field))

        # Influence of the index modulation on the field
        field_x = field * np.exp(1j * bpm.nl_mat[nbr_step, :])

        # Linear propagation over dz/2
        field_x = ifft(bpm.phase_mat_demi * fft(field_x))

        cur_pow = bpm.epnc * abs2(field_x)

        for k in range(kerr_loop):
            prev_pow = cur_pow
            # influence of the beam intensity on the index modulation
            dn_temp = dn[nbr_step, :] + (3*chi3)/(8*no)*(prev_pow/bpm.epnc)
            nl_mat = bpm.ko * bpm.dist_z * dn_temp

            # influence of the index modulation on the field
            field_x = field * np.exp(1j * nl_mat)
            # Linear propagation over dz/2
            field_x = ifft(bpm.phase_mat_demi * fft(field_x))

            cur_pow = bpm.epnc * abs2(field_x)

        try:
            bpm.variance(prev_pow, cur_pow)
        except ValueError as error:
            print(error)

        field = field_x

    field_2 = field
    cur_2 = cur_pow
    dn_2 = dn_temp

    print("\n kerr+dz")
    field = bpm.field
    for i in range(nbr_step):
        # Influence of the index modulation on the field
        field_x = field * np.exp(1j * bpm.nl_mat[nbr_step, :])

        # Linear propagation over dz
        field_x = ifft(bpm.phase_mat * fft(field_x))

        cur_pow = bpm.epnc * abs2(field_x)

        for k in range(kerr_loop):
            prev_pow = cur_pow
            # influence of the beam intensity on the index modulation
            dn_temp = dn[nbr_step, :] + (3*chi3)/(8*no)*(prev_pow/bpm.epnc)
            nl_mat = bpm.ko * bpm.dist_z * dn_temp

            # influence of the index modulation on the field
            field_x = field * np.exp(1j * nl_mat)
            # Linear propagation over dz
            field_x = ifft(bpm.phase_mat * fft(field_x))

            cur_pow = bpm.epnc * abs2(field_x)

        try:
            bpm.variance(prev_pow, cur_pow)
        except ValueError as error:
            print(error)

        field = field_x

    field_3 = field
    cur_3 = cur_pow
    dn_3 = dn_temp

    plt.figure(num="Impact order kerr")

    ax1 = plt.subplot(211)
    ax2 = plt.subplot(212)

    ax1.set_title("phase: comparison")
    ax2.set_title("power: comparison")

    ax1.set_xlim(-15, 15)
    ax2.set_xlim(-15, 15)

    ax1.plot(x, np.angle(field_ref), label="no kerr")
    ax1.plot(x, np.angle(field_1), label="dz+kerr")
    ax1.plot(x, np.angle(field_2), label="dz/2+kerr+dz/2")
    ax1.plot(x, np.angle(field_3), label="kerr+dz")

    ax2.plot(x, cur_ref, label="no kerr")
    ax2.plot(x, cur_1, label="dz+kerr")
    ax2.plot(x, cur_2, label="dz/2+kerr+dz/2")
    ax2.plot(x, cur_3, label="kerr+dz")

    ax1.legend(loc="upper right")
    ax2.legend(loc="upper right")

    plt.show()

    dn_ref = dn[nbr_step, :]

    plt.figure(num="Impact on dn order kerr")

    ax1 = plt.subplot(111)

    ax1.set_title("dn: comparison")

    ax1.set_xlim(-15, 15)

    ax1.plot(x, dn_ref, label="no kerr")
    ax1.plot(x, dn_1, label="dz+kerr")
    ax1.plot(x, dn_2, label="dz/2+kerr+dz/2")
    ax1.plot(x, dn_3, label="kerr+dz")

    ax1.legend(loc="upper right")

    plt.show()
Пример #2
0
def stability():
    """Show the possible BPM approximations for implementing a refractive
    index variation"""

    width = 6
    no = 2.14
    wavelength = 1.55
    delta_no = 0.0014
    length_z = 200
    dist_z = 1
    nbr_z_disp = 1
    dist_x = 0.2
    length_x = 1000

    bpm = Bpm(no, wavelength,
              length_z, dist_z, nbr_z_disp,
              length_x, dist_x)

    [length_z, nbr_z, nbr_z_disp, length_x, nbr_x, x] = bpm.create_x_z()

    shape = bpm.squared_guide(width)

    nbr_p = 1
    p = 0

    [peaks, dn] = bpm.create_guides(shape, delta_no, nbr_p, p)

    fwhm = 6
    lo = 1.5

    field = bpm.gauss_light(fwhm)
    irrad = 1
    theta_ext = 0

    [progress_pow] = bpm.init_field(field, theta_ext, irrad)

    nbr_step = nbr_z-1

    # Need to overwrite those variables due to changes
    theta = asin(sin(radians(theta_ext)) / no)  # angle in the guide
    nu_max = 1 / (2 * dist_x)  # max frequency due to sampling
    # Spacial frequencies over x (1/µm)
    nu = np.linspace(-nu_max,
                     nu_max * (1 - 2/nbr_x),
                     nbr_x)
    intermed = no * cos(theta) / lo
    fr = -2 * pi * nu**2 / (intermed + np.sqrt(
        intermed**2
        - nu**2
        + 0j))

    bpm.phase_mat = fftshift(np.exp(1j * dist_z * fr))
    bpm.phase_mat_demi = fftshift(np.exp(1j * dist_z / 2 * fr))
    bpm.nl_mat = bpm.ko * bpm.dist_z * dn
    # End overwrite

    field = bpm.field
    for i in range(nbr_step):
        field = ifft(bpm.phase_mat * fft(field))
        field *= np.exp(1j * bpm.nl_mat[nbr_step, :])
    test1 = field

    field = bpm.field
    for i in range(nbr_step):
        field = ifft(bpm.phase_mat_demi * fft(field))
        field *= np.exp(1j * bpm.nl_mat[nbr_step, :])
        field = ifft(bpm.phase_mat_demi * fft(field))
    test2 = field

    field = bpm.field
    for i in range(nbr_step):
        field *= np.exp(1j * bpm.nl_mat[nbr_step, :])
        field = ifft(bpm.phase_mat * fft(field))
    test3 = field

    plt.figure("Power")
    plt.title("Power: Impact of the chosen algorithm on the free propagation")
    plt.xlim(-20, 20)
#    plt.ylim(-1, 350)

    plt.plot(x, abs2(test1), label='dz+lens')
    plt.plot(x, abs2(test2), label='dz/2+lens+dz/2')
    plt.plot(x, abs2(test3), label='lens+dz')
    plt.legend()
    plt.show()
    plt.figure("Phase")
    plt.title("Phase: Impact of the chosen algorithm on the free propagation")
    plt.xlim(-30, 30)
    plt.plot(x, np.angle(test1), label='dz+lens')
    plt.plot(x, np.angle(test2), label='dz/2+lens+dz/2')
    plt.plot(x, np.angle(test3), label='lens+dz')
    plt.legend()
    plt.show()