示例#1
0
 def f(mode, fname):
     wavef = lambda x: wavefs[mode-1](x, 0)
     (fig, reax, imax) = plotting.setup_figure_topbottom(title=u'Wavefunction for n=%i mode' % mode,
     #fig, reax) = plotting.setup_figure_standard(title=u'Wavefunction for n=%i mode' % mode,
         xlabel=u'Distance accross waveguide (m)',
         ylabel=u'Wavefunction (arbitrary units)')
     d = plotting.plot_wavefunction(reax, imax, wavef, waveguide.slab_gap)
     plotting.save_figure(fig, fname)
     sio.savemat(fname + '.mat', d)
示例#2
0
def sp_plot_wavefunction(waveguide, wavelength, angle, out_file, verbose=False):
    """
    This method produces a wavefunction hitting the waveguide at angle, and splits it into the guided modes of the
    waveguide. The resultant wavefunction is plotted
    @param waveguide: The waveguide being illuminated
    @type waveguide: PlanarWaveguide
    @param wavelength: The wavelength of light illuminating the waveguide
    @type wavelength: float
    @param angle: The angle of the plane waves striking the waveguide, in radian
    @type angle: float
    @param out_file: The filename to write output to
    @type out_file: str
    @param verbose: Whether or not to give verbose output
    @type verbose: bool
    @return: None
    """

    solver = modesolvers.ExpLossySolver(waveguide, wavelength)
    kxs = solver.solve_transcendental(verbose=verbose)
    wavefs = solver.get_wavefunctions(kxs, verbose=verbose)

    k = 2*np.pi/wavelength
    inkx = k*np.sin(angle)
    inwave = lambda x: np.exp(1j*inkx*x)

    splitter = splitters.ModeSplitter(inwave, wavefs)
    cm = splitter.get_coupling_constants()
    wffull = splitter.get_wavefunction(cm)
    wf = functools.partial(lambda z,x: wffull(x,z), 0.005)

    if verbose:
        print 'Coupling coefficients: '
        for (i,c) in enumerate(cm):
            print '\t %i: Magnitude: %f, Phase: %f, Square: %f' % (i+1, np.abs(c), np.angle(c), np.abs(c)**2)

    (fig, reax, imax) = plotting.setup_figure_topbottom(title=ur'Wavefunction for incidence angle $\theta=%f$ rad' % angle,
        xlabel=u'Distance accross waveguide (m)',
        ylabel=u'Wavefunction (arbitrary units)')
    #plotting.plot_intensity(reax, wf, waveguide.slab_gap)
    #phasef = lambda x: np.angle(wf(x))

    plotting.plot_wavefunction(reax, imax, wf, waveguide.slab_gap)
    plotting.save_figure(fig, unicode(out_file))