Example #1
0
def test_smatrix_two_particle_non_interacting():
    m = scattering.Model([0] * 2, [[0, 1, 1]], [0] * 2)
    channels = [
        scattering.Channel(site=0, strength=1),
        scattering.Channel(site=1, strength=1),
    ]
    s = scattering.Setup(m, channels)

    E = 0
    dE = 0
    chls = [[0, 0], [0, 1], [1, 0], [1, 1]]

    S2s = np.zeros((4, 4), np.float64)
    for ci, chlsi in enumerate(chls):
        for co, chlso in enumerate(chls):
            _, _, S2, _ = smatrix.two_particle(s,
                                               chlsi=chlsi,
                                               chlso=chlso,
                                               E=E,
                                               dE=dE)

            S2s[ci, co] = np.sum(np.abs(S2)**2)

    # Test if S2 vanishes
    assert np.allclose(np.ones((4, 4)) + S2s, np.ones((4, 4)), 1e-2), \
        'S2 does not vanish for non-interacting systems, S2 = {0}.'.format(np.abs(S2s))
Example #2
0
def _test_smatrix_optical_theorem2(chlsi):
    m = scattering.Model(omegas=[0] * 2, links=[[0, 1, .5]], U=[5] * 2)

    channels = []
    channels.append(scattering.Channel(site=0, strength=1))
    channels.append(scattering.Channel(site=1, strength=1))

    s = scattering.Setup(m, channels)

    # input statei
    E = 0
    dE = 0
    chlsos = [[0, 0], [0, 1], [1, 0], [1, 1]]

    qs = np.linspace(-100, 100, 8192, endpoint=False)

    D2s, S2s = [], []
    for c, chlso in enumerate(chlsos):
        qs, D2, S2, S2in = smatrix.two_particle(s,
                                                chlsi=chlsi,
                                                chlso=chlso,
                                                E=E,
                                                dE=dE,
                                                qs=qs)

        D2s.append(D2)
        S2s.append(S2)

    iq0 = np.where(qs == E / 2)[0][0]

    dsums = [np.sum(np.abs(D2s[c])**2) for c in xrange(4)]
    ssums = [np.sum(np.abs(S2s[c])**2) * (qs[1] - qs[0]) for c in xrange(4)]
    dssums = [
        2 * np.real(np.sum(D2s[c]).conj() * S2s[c][iq0]) for c in xrange(4)
    ]

    # Test single particle contribution
    assert np.isclose(np.sum(dsums), 2, 1e-3), \
        'S(1)S(1) is not normalized (= {0})'.format(np.sum(dsums))

    # Test optical theorem
    assert np.isclose(np.sum(ssums), -np.sum(dssums), 1e-2), \
        'Optical theorem broken, S2.S2 = {0} != -S1.S2 = {1}.'.format(np.sum(ssums), -np.sum(dssums))
Example #3
0
def g2(s, chlsi, chlso, E, dE):
    """
    Calculate the intensity-intensity correlation function as a function of total energy,
    E, and energy discrepancy, dE.

    Parameters
    ----------
    s : Setup
        Scattering setup object.
    chlsi : list
        Input state channel indices.
    chlso : list
        Output state channel indices.
    E : float
        Total energy of input photonic state.
    dE : float
        Energy difference between the two photons in the input state.
    """
    qs, D2, S2, S2in = smatrix.two_particle(s,
                                            chlsi=chlsi,
                                            chlso=chlso,
                                            E=E,
                                            dE=dE)

    Ee = np.array([.5 * (E - dE), .5 * (E + dE)])
    _, S10 = smatrix.one_particle(s, chlsi[0], chlso[0], Ee)
    _, S11 = smatrix.one_particle(s, chlsi[1], chlso[1], Ee)

    # denominator
    dFS2 = np.sum(np.abs(S10)**2 * np.abs(S11)**2)

    # Fourier transform
    FS2 = np.fft.fft(S2) * (qs[1] - qs[0])

    # frequencies
    freqs = np.fft.fftfreq(len(qs), d=qs[1] - qs[0])

    # add delta function contribution
    FS2 += np.exp(np.pi * 1j * E * freqs) * D2[0] + np.exp(
        np.pi * 1j * E * freqs) * D2[1]

    return FS2, dFS2
Example #4
0
def g2_coherent_s(s, chlsi, chlso, E, qs=None):
    """
    g2 for a coherent state (or partially coherent)

    Parameters
    ----------
    s : Setup
        Scattering setup
    chlsi : list
        List of incoming channel indices
    chlso : list
        List of outgoing channel indices
    E : float
        Energy of the two-particle state
    """
    qs, D2, S2, _ = smatrix.two_particle(s,
                                         chlsi=chlsi,
                                         chlso=chlso,
                                         E=E,
                                         dE=0,
                                         qs=qs)

    # Single particle scattering
    Ee = np.array([.5 * E])
    _, S10 = smatrix.one_particle(s, chlsi[0], chlso[0], Ee)
    _, S11 = smatrix.one_particle(s, chlsi[1], chlso[1], Ee)

    dFS2 = np.abs(S10[0])**2 * np.abs(S11[0])**2

    # Fourier transform
    FS2 = np.fft.fft(S2) * (qs[1] - qs[0])

    # times
    times = np.fft.fftfreq(len(qs), d=qs[1] - qs[0])

    # add delta function contribution
    FS2 += np.exp(2 * np.pi * 1j * E / 2 * times) * np.sum(D2)

    return np.abs(FS2[0])**2, dFS2
Example #5
0
chlsi = [0, 0]

# output state
chlsos = [[0, 0], [0, 1], [1, 0], [1, 1]]
qs = np.linspace(-.1, .1, 8192, endpoint=False)

d = 120
# qs = np.linspace(-d, d, 8192, endpoint=False)
qs, iq0 = scattering.energies(E, dE, N=2*8192, WE=2 * d)

plt.figure(figsize=(6, 6))
D2s, S2s = [], []
for c, chlso in enumerate(chlsos):
    qs, D2, S2, S2in = smatrix.two_particle(s,
                                            chlsi=chlsi,
                                            chlso=chlso,
                                            E=E,
                                            dE=dE,
                                            qs=qs)

    D2s.append(D2)
    S2s.append(S2)
    plt.subplot(2, 2, c + 1)
    plt.plot(qs, np.real(S2))
    plt.plot(qs, np.imag(S2))

for c, chlso in enumerate(chlsos):
    dsums = [np.sum(np.abs(D2s[c]) ** 2) for c in xrange(4)]
    ssums = [np.sum(np.abs(S2s[c]) ** 2) * (qs[1] - qs[0]) for c in xrange(4)]
    dssums = [2 * np.real(np.sum(D2s[c]).conj() * S2s[c][iq0]) for c in xrange(4)]

Example #6
0
def _test_smatrix_optical_theorem(domega, dE, chlsi, verbose=False):

    E = 0

    m = scattering.Model(omegas=[0] * 2, links=[[0, 1, .5]], U=[5] * 2)

    channels = []
    channels.append(scattering.Channel(site=0, strength=1))
    channels.append(scattering.Channel(site=1, strength=1))

    s = scattering.Setup(m, channels)

    # input statei
    chlsos = [[0, 0], [0, 1], [1, 0], [1, 1]]

    d = 100
    # 50 / np.max(np.abs(dE), .5)
    print(d)
    qs, iq0 = scattering.energies(E, dE, N=8192, WE=2 * d)

    D2s, S2s = [], []
    for c, chlso in enumerate(chlsos):
        qs, D2, S2, S2in = smatrix.two_particle(s,
                                                chlsi=chlsi,
                                                chlso=chlso,
                                                E=E,
                                                dE=dE,
                                                qs=qs)

        D2s.append(D2)
        S2s.append(S2)

    # iq0s = [np.where(np.isclose(qs, (E - dE) / 2))[0][0], np.where(np.isclose(qs, (E + dE) / 2))[0][0]]

    dsums = [.5 * np.sum(np.abs(D2s[c])**2) for c in xrange(4)]
    ssums = [
        .5 * np.sum(np.abs(S2s[c])**2) * (qs[1] - qs[0]) for c in xrange(4)
    ]
    dssums = [
        .5 * 2 * np.real(np.sum(D2s[c]).conj() * S2s[c][iq0])
        for c in xrange(4)
    ]

    # dsums = [.5 * np.sum(np.abs(D2s[c]) ** 2) for c in xrange(4)]
    # ssums = [.5 * np.sum(np.abs(S2s[c]) ** 2) * (qs[1] - qs[0]) for c in xrange(4)]
    # dssums = [.5 * 2 * np.real(np.sum(D2s[c].conj() * S2s[c][iq0])) for c in xrange(4)]

    if verbose:
        print('For d(2) = {} and dE = {}:'.format(domega, dE))

    # Test single particle contribution
    assert np.isclose(np.sum(dsums), 1, 1e-3), \
        'S(1)S(1) is not normalized (= {0})'.format(np.sum(dsums))

    if verbose:
        print('S1.S1 norm is: {0}'.format(np.sum(dsums)))

    # Test optical theorem
    assert np.isclose(np.sum(ssums), -np.sum(dssums), 1e-2), \
        'Optical theorem broken for parameters: E={0}, dE={1}, chlsi={2}.'.format(E, dE, chlsi) + \
        '\n' + \
        'Compare S2.S2 = {0} != -S1.S2 = {1}.'.format(np.sum(ssums), -np.sum(dssums))

    if verbose:
        print('Compare S2.S2 = {0} to -S1.S2 = {1}.'.format(
            np.sum(ssums), -np.sum(dssums)))