def efield_at(self, phase):
     '''
     Returns the EField circulating in the cavity at given phase
     '''
     E_out = EField.from_EField(self.input_efield)
     E_out.E = self.compute_total_field(phase)
     return E_out
    def plot_fields(self, fig=None):
        '''
        Plots the fields at 7 round trips distributed through
        all the round trips.
        '''
        if not self.fields_are_calculated():
            self.logger.error('Fields are not calculated')
            message = 'Calculate fields before ploting'
            raise NotReady(message)
        if fig is None:
            fig, (axI, axP) = EField.create_figure()

        step = round_to_odd(self.fields.shape[0] / 7)
        for i in range(0, self.fields.shape[0], step):
            efield = EField(self.input_efield.x, self.fields[i, :])
            fig, (axI, axP) = efield.plot(fig,
                                          label='# {}'.format(i),
                                          normalize=True)
        axI.legend()
        return fig, (axI, axP)
예제 #3
0
def hg_efield(n,
              x,
              w,
              amplitude=1.0,
              x0=0.0,
              normalize_power=True,
              *args,
              **kwargs):
    if normalize_power:
        factor = np.sqrt(2**(1 - n) / np.pi / math.factorial(n)) / w
    else:
        factor = amplitude
    field = hermite(n, np.sqrt(2) * (x - x0) / w) * np.exp(-(x - x0)**2 / w**2)
    return EField(x=x, E=factor * field, *args, **kwargs)
    def power(phase):
        u = x[len(x) // 2:]
        v = E.E[len(x) // 2:]
        b = base[len(x) // 2:]
        return np.trapz(x=u,
                        y=(2 * np.pi * u *
                           abs(v * np.sqrt(T) /
                               (1 - b * np.exp(1j * phase)))**2))

    S = Spectrum(power_fun=power)
    S.compute_resonances()
    phases, spectrum = S.spectrum()

    fig, ax = plt.subplots()
    ax.semilogy(phases, spectrum)
    ax.grid(which='both')
    ax.grid(which='minor', color=[0.9] * 3, linewidth=0.5)

    modes = [
        E.transmit(((np.sqrt(T) / (1 - base * np.exp(1j * phase)))))
        for phase in S.resonance_phases
    ]

    fig, (axI, axP) = EField.create_figure()
    for mode in modes:
        print(mode.P)
        mode.plot(fig, normalize=False)

    plt.show()
    n = int(np.ceil(n))
    return n + 1 if n % 2 == 0 else n


if __name__ == '__main__':
    """ Input Field """
    win = 2e-3
    N = 2**14
    x0 = 20 * win
    x = np.linspace(-x0, x0, N)

    lda = 770e-9
    E_ref = EField(x,
                   E=gaussian(x,
                              amplitude=1,
                              center=0 * win,
                              waist=win,
                              offset=0),
                   lda=lda,
                   normalize=True)
    E_ref = HG_efield(n=0,
                      x=x,
                      w=win,
                      amplitude=1.0,
                      x0=0.0,
                      normalize=True,
                      lda=771e-9)
    # E_ref += HG_efield(n=1, x=x, w=win, amplitude=1.0, x0=0.0,
    #                    normalize=True, lda=771e-9)
    # E_ref = EField(x, E=fermi_dirac(x, amplitude=1, center=0*win,
    #                                 radius=win, beta=16.25, offset=0),
    #                lda=lda, normalize=True)
 def calculate_fields(self, input_efield, N=None):
     '''
     Gets the fields propagated inside the cavity at every round trip.
     '''
     self.input_efield = EField.from_EField(input_efield)
     self.fields = self.cavity.propagate_efield(input_efield, N=N)
예제 #7
0
def fd_efield(x, R0, b, amplitude=1.0, x0=0.0, *args, **kwargs):
    return EField(x=x, E=fermidirac(x, amplitude, R0, x0, b), *args, **kwargs)
예제 #8
0
def lg_efield(n, x, w, amplitude=1.0, x0=0.0, *args, **kwargs):
    factor = np.sqrt(2**(1 - n) / np.pi / math.factorial(n)) / w
    field = laguerre(n, 2 * abs(x - x0)**2 / w**2) * np.exp(
        -(x - x0)**2 / w**2)
    return EField(x=x, E=factor * field, *args, **kwargs)
cavity = cavities.MIGACavity(f=f, d1=f+1000e-6, d2=f,
                             R1=0.98, R2=0.98, TL=1.0)
# cavity = cavities.PlanePlaneCavity(R1=0.98, R2=0.99, L=10e-2/5.0)
# cavity = cavities.TwoMirrorCavity(R1=0.97, R2=0.99, L=100e-3,
#                                   radius1=1e10, radius2=0.5)
handler = CavityHandler(cavity)

# print(cavity.waist(771e-9))
# cavity.M2.tilt(10e-6)
print(cavity[1:] + cavity[-2::-1])

"""Defining the input field"""
win = 2e-3
x0, N = 40*win, 2**14
x = np.linspace(-x0, x0, N)
E_ref = EField(x, gaussian(x, 1, 0*win, win, 0),
               lda=771e-9, normalize=True)
# E_ref = HG_efield(n=0, x=x, w=win, amplitude=1.0, x0=0*win,
#                   normalize=True, lda=771e-9)
# E_ref += HG_efield(n=0, x=x, w=win, amplitude=1.0, x0=0.0,
#                    normalize=True, lda=771e-9)
E_in = E_ref.tilt(0e-4)

r_zernike = 3e-3
u = x / r_zernike
phase_map = np.zeros(u.size)
phase_map[abs(u) < 1.0] = zernike.zernike(4, 0, 5.0, abs(u[abs(u) < 1.0]))
# cavity.insert(2, interfaces.PhaseMask(phase_map))

"""Computation"""
N_rt = int(2*cavity.finess)
E = HG_efield(n=0, x=x, w=win,)
E.E = E.E / np.sqrt(E.I.max())

angle = 1e-2

print('Electric Field E : {}'.format(E))
print('Power : {:.5f}'.format(E.P))
print(len(E))

dist = 2.0
E_prop = E.tilt(angle).propagate(dist=dist)

zr = np.pi * win**2 / E.lda
w_th = win*np.sqrt(1+(dist/zr)**2)
E_theo = EField(x, gaussian(x, amplitude=np.sqrt(win/w_th),
                            center=angle * dist, waist=w_th, offset=0))
E_theo = HG_efield(n=0, x=x, amplitude=np.sqrt(win/w_th),
                   w=w_th, x0=angle*dist)


# plt.figure()
# plt.plot(x, abs(E_theo.I/E_theo.I.max()-E_prop.I/E_prop.I.max()))

s = 'Result agrees with theory : {}'
print(s.format(np.allclose(E_theo.I,  E_prop.I)))

fig, (axI, _) = E.plot(label='Reference')
E_prop.plot(fig, label='Propagated')
E_theo.plot(fig, linestyle='--', label='Theoretic')
axI.legend()
plt.show()
import scipy.optimize as so
from test_cavity_fft import round_to_odd


def gaussian(x, amplitude, center, waist, offset):
    return amplitude * np.exp(-(x - center)**2 / waist**2) + offset


win = 5e-3
N = 2**14
x0 = 50 * win
x = np.linspace(-x0, x0, N)

lda = 770e-9
E_ref = EField(x,
               E=gaussian(x, amplitude=1, center=0 * win, waist=win, offset=0),
               lda=lda,
               normalize=True)

angle_beam = 0e-3
angle_m1 = 0e-6
angle_m2 = 0e-3

r1 = np.sqrt(0.99)
r2 = np.sqrt(0.99)
L = 1e-3


def cavity_fun(efield):
    return efield.propagate(L).tilt(2 * angle_m2).propagate(L).tilt(2 *
                                                                    angle_m1)