def inspect(sim, regions):

    ins = inspector.Inspector(sim)
    matplotlib.rc('text', usetex=False)

    # plot
    try:
        plot_field(ins['eps'], 'normal', sim.dev.shape)
        for i in 'ex ey'.split():
            plot_field(ins[i].abs, 'normal', sim.dev.shape)
            plot_field(ins[i].real, 'symetric', sim.dev.shape)
        plot_field(ins['sx'], 'symetric', sim.dev.shape)
        plot_field(ins['sy'], 'symetric', sim.dev.shape)
    except BaseException as e:
        print(f'Plotting failed: {e}')

    # save
    try:
        for f in 'eps ex ey sx sy pwr'.split():
            np.save(f'results/splitter/{f}.npy', ins[f].data)
    except BaseException as e:
        print(f'Saving failed: {e}')

    # splitting
    try:
        f = ins['pwr']
        reg_in1, reg_out1, reg_out2 = regions
        pwr_in1 = reg_in1.cut(f).density
        pwr_out1 = reg_out1.cut(f).density
        pwr_out2 = reg_out2.cut(f).density
        plot_field(ins['pwr'], 'normal', sim.dev.shape, regions=regions)
    except BaseException as e:
        print(f'Plotting pwr failed: {e}')

    return pwr_in1, pwr_out1, pwr_out2
예제 #2
0
def inspect(sim):

    ins = inspector.Inspector(sim)
    matplotlib.rc('text', usetex=False)

    # plot
    try:
        plot_field(ins['eps'], 'normal', sim.dev.shape)
        for i in 'ex ey ez'.split():
            plot_field(ins[i].abs, 'normal', sim.dev.shape)
    except BaseException as e:
        print(f'Plotting failed: {e}')
예제 #3
0
def inspect(sim, regions, name):

    ins = inspector.Inspector(sim)
    matplotlib.rc('text', usetex=False)

    # save
    try:
        for f in 'eps ex ey sx sy pwr'.split():
            np.save(f'results/curve/{name}_{f}.npy', ins[f].data)
    except BaseException as e:
        print(f'Saving failed: {e}')

    # plot
    try:
        prefix = f'{name}_'
        plot_field(ins['eps'], 'normal', sim.dev.shape, prefix)
        for i in 'ex ey'.split():
            plot_field(ins[i].abs, 'normal', sim.dev.shape, prefix)
            plot_field(ins[i].real, 'symetric', sim.dev.shape, prefix)
        plot_field(ins['sx'], 'symetric', sim.dev.shape, prefix)
        plot_field(ins['sy'], 'symetric', sim.dev.shape, prefix)
    except BaseException as e:
        print(f'Plotting failed: {e}')

    # losses
    try:
        f = ins['pwr']
        reg_start, reg_end = regions
        insertion_losses = reg_end.cut(f).density / reg_start.cut(f).density
        plot_field(ins['pwr'],
                   'symetric',
                   sim.dev.shape,
                   prefix,
                   regions,
                   title=fr'Insertion: ${insertion_losses*100:05.2f}\%$')
    except BaseException as e:
        print(f'Plotting pwr failed: {e}')

    return insertion_losses
예제 #4
0
    sim = Simulation('line', dev, res=resolution, pml=pml)
    sim.create_waveguide_source(wavelength=wavelength, pos=[0, 0], width=8)

    # regions
    regions = {}
    for n, p in enumerate(np.linspace(0.15, 0.6, 16)):
        regions[n] = WaveguideRegion(sim.name,
                                     f'region_{n}',
                                     world['line'],
                                     p,
                                     margin=1,
                                     length=0.4)
    sim.run(duration)

    # INSPECTION
    ins = inspector.Inspector(sim)
    matplotlib.rc('text', usetex=True)

    # fields
    plot_field(ins['eps'], 'normal', shape=dev.shape)
    plot_field(ins['ez'].abs, 'normal', shape=dev.shape)
    plot_field(ins['ez'].real, 'symetric', shape=dev.shape)
    plot_field(ins['sx'], 'symetric', shape=dev.shape)
    plot_field(ins['sy'], 'symetric', shape=dev.shape)

    # fluxes
    fig, axes = plt.subplots(1, 2)
    f = ins['pwr']
    ax0 = plt.subplot2grid((2, 2), (0, 0))
    ax1 = plt.subplot2grid((2, 2), (0, 1))
    ax2 = plt.subplot2grid((2, 2), (1, 0), colspan=2, rowspan=1)