Beispiel #1
0
def main():

    if len(sys.argv) > 1:
        mode = sys.argv[1]
    else:
        mode = 'sim'

    defaults.add_epsilon_as_inset = True

    sim = TriHoles2D(
        material='SiN',
        radius=0.34,
        numbands=4,  #8,
        k_interpolation=5,  #31, 
        resolution=16,
        mesh_size=7,
        runmode=mode,
        num_processors=2,
        save_field_patterns=False,
        convert_field_patterns=False)

    if not sim:
        log.error('an error occurred during simulation. See the .out file')
        return

    log.info(' ##### success! #####\n\n')
Beispiel #2
0
def main():
    if len(sys.argv) > 1:
        mode=sys.argv[1]
    else:
        mode='sim'

    sim = TriHolesSlab3D(
        material='Si',
        substrate_material='glass',
        radius=0.5 * 367 / pitch,
        thickness=116 / pitch,
        numbands=16,
        k_interpolation=31,
        resolution=32,
        mesh_size=7,
        supercell_z=10,
        runmode=mode,
        num_processors=8,
        save_field_patterns=False,
        convert_field_patterns=False,
        job_name_suffix='_on_glass',
        bands_title_appendix=' (on glass)',
        modes=[''] # use (run), not (run-zeven) etc.
    )
        
    if not sim:
        log.error('an error occurred during simulation. See the .out file')
    else:
        log.info(' ##### Si PhC slab on glass - success! #####\n\n')
Beispiel #3
0
def main():

    if len(sys.argv) > 1:
        mode=sys.argv[1]
    else:
        mode='sim'

    defaults.add_epsilon_as_inset = True

    sim = TriHoles2D(
        material='SiN',
        radius=0.34,
        numbands=4,#8,
        k_interpolation=5,#31, 
        resolution=16, 
        mesh_size=7,
        runmode=mode,
        num_processors=2,
        save_field_patterns=False,
        convert_field_patterns=False)
      
    if not sim:
        log.error('an error occurred during simulation. See the .out file')
        return
    
    log.info(' ##### success! #####\n\n')
Beispiel #4
0
def main():
    if len(sys.argv) > 1:
        mode = sys.argv[1]
    else:
        mode = 'sim'

    # monkey patching:
    # (don't output multiple tiles along y)
    # (x and y are switched because of -T)
    defaults.mpbdata_call = (
        'mpb-data -T -rn%(resolution)s '
        '-y%(number_of_tiles_to_output)s '
        '-o%(output_file)s '
        '%(h5_file)s')
    defaults.number_of_tiles_to_output=5

    ksteps = 5

    # width of the supercell:
    supercell_size = 3

    # The bigger the unit cell, the more bands fold in below the
    # waveguide band:
    first_wg_band = int(3 + 2 * (supercell_size - 1))

    sim = TriHolesSlab3D_Waveguide(
        material='SiN',
        radius=0.340,
        thickness=0.8,
        mode='zeven',
        numbands=first_wg_band + 1,
        k_steps=ksteps,
        supercell_size=supercell_size,
        supercell_z=3,
        resolution=16,
        mesh_size=3,
        runmode=mode,
        ydirection=False,
        first_row_longitudinal_shift=0,
        second_row_longitudinal_shift=0,
        num_processors=2,
        projected_bands_folder='./projected_bands_repo',
        plot_crop_y=0.6,
        #save_field_patterns_kvecs=[
        #    (x, 0, 0) for x in np.linspace(0, 0.5, num=ksteps)],
        #save_field_patterns_bandnums=[
        #    1, 2,
        #    first_wg_band, first_wg_band + 1, first_wg_band + 2],
        #convert_field_patterns=True,
        #field_pattern_plot_k_selection=[0, 5, 7, 9, 11, 13, 15, 16]
    )

    if not sim:
        log.error('an error occurred during simulation. See the .out file')
        return
Beispiel #5
0
def main():
    if len(sys.argv) > 1:
        mode = sys.argv[1]
    else:
        mode = 'sim'

    # monkey patching:
    # (don't output multiple tiles along y)
    # (x and y are switched because of -T)
    defaults.mpbdata_call = ('mpb-data -T -rn%(resolution)s '
                             '-y%(number_of_tiles_to_output)s '
                             '-o%(output_file)s '
                             '%(h5_file)s')
    defaults.number_of_tiles_to_output = 5

    ksteps = 5

    # width of the supercell:
    supercell_size = 3

    # The bigger the unit cell, the more bands fold in below the
    # waveguide band:
    first_wg_band = int(3 + 2 * (supercell_size - 1))

    sim = TriHolesSlab3D_Waveguide(
        material='SiN',
        radius=0.340,
        thickness=0.8,
        mode='zeven',
        numbands=first_wg_band + 1,
        k_steps=ksteps,
        supercell_size=supercell_size,
        supercell_z=3,
        resolution=16,
        mesh_size=3,
        runmode=mode,
        ydirection=False,
        first_row_longitudinal_shift=0,
        second_row_longitudinal_shift=0,
        num_processors=2,
        projected_bands_folder='./projected_bands_repo',
        plot_crop_y=0.6,
        #save_field_patterns_kvecs=[
        #    (x, 0, 0) for x in np.linspace(0, 0.5, num=ksteps)],
        #save_field_patterns_bandnums=[
        #    1, 2,
        #    first_wg_band, first_wg_band + 1, first_wg_band + 2],
        #convert_field_patterns=True,
        #field_pattern_plot_k_selection=[0, 5, 7, 9, 11, 13, 15, 16]
    )

    if not sim:
        log.error('an error occurred during simulation. See the .out file')
        return
def main():
    if len(sys.argv) > 1:
        mode=sys.argv[1]
    else:
        mode='sim'
    minstep = 1
    maxstep = 8.0
    stepsize = 0.5
    numsteps = int((maxstep - minstep) / stepsize + 1.5)
    steps = np.linspace(minstep, maxstep, num=numsteps, endpoint=True)
    # save previous step's data, needed for comparison with current data:
    prev_step_data = None

    for i, step in enumerate(steps):

        log.info("running simulation with {0:n} supercell height steps:\n{1}".format(
            numsteps, steps) +
            '\n  ### current step: #{0} ({1}) ###\n'.format(i+1, step))


        ### create and run simulation (according to mode) ###

        sim = TriHolesSlab3D(
            material='SiN',
            radius=0.375,
            thickness=0.8,
            numbands=8,
            k_interpolation=31,
            resolution=32,
            mesh_size=7,
            supercell_z=step,
            runmode=mode,
            num_processors=8,
            save_field_patterns=True,
            convert_field_patterns=True,
            job_name_suffix='_sct{0:03.0f}'.format(step*10),
            bands_title_appendix=', supercell thickness={0:02.1f}'.format(step))
        
        if not sim:
            log.error('an error occurred during simulation. See the .out file')
            return


        ### load some data ###

        # load zeven mode band data:
        fname = path.join(sim.workingdir, sim.jobname + '_zevenfreqs.csv')
        data = np.loadtxt(fname, delimiter=',', skiprows=1)
        gapbands = get_gap_bands(data[:, 5:], light_line=data[:, 4])


        ### save comparison data to file ###

        # If this is not the first step, we have previous data to compare
        # with:
        if prev_step_data is not None:
            sums = []
            # compare the first 3 zeven bands:
            for j in range(3):
                sums.append(
                    sum_of_squares(
                        prev_step_data[:, 5 + j],
                        data[:, 5 + j],
                        data[:, 4]
                    )
                )
            with open("sum_of_squares.dat", "a") as f:
                f.write('\t'.join([str(step)] + map(str, sums)) + '\n')
        # save data for next iteration:
        prev_step_data = data


        ### save the gap to file ###

        # maybe there is no gap?
        if len(gapbands) == 0:
            gap = 0
        elif gapbands[0][0] != 1:
            # it must be a gap between band 1 and 2
            gap = 0
        else:
            gap = gapbands[0][3]

        # save gap sizes to file (first z-even gap):
        with open("gaps.dat", "a") as f:
            f.write("{0}\t{1}\n".format(step, gap))
    


        log.info(' ##### step={0} - success! #####\n\n'.format(step))

        # reset logger; the next stuff logged is going to next step's file:
        log.reset_logger()

    ### finally, save some plots ###

    data = np.loadtxt('sum_of_squares.dat')
    fig = plt.figure()
    ax = fig.add_subplot(111)
    # make double-logarithmic plot for every band:
    for i in range(data.shape[1] -1):
        ax.loglog(data[:,0], data[:,i + 1], 'o-',
                  label='band {0}'.format(i+1))

    compdata = np.power(data[:,0], -2)
    ax.loglog(data[:,0], compdata, '.:', label='$x^{-2}$')
    compdata = np.power(data[:,0], -4)
    ax.loglog(data[:,0], compdata, '.:', label='$x^{-4}$')
    compdata = np.power(data[:,0], -6)
    ax.loglog(data[:,0], compdata, '.:', label='$x^{-6}$')
    plt.legend()
    plt.title('sum of squared differences between simulation steps')
    fig.savefig('sum_of_squares.png')

    data = np.loadtxt('gaps.dat')
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.plot(data[:,0], data[:,1], 'o-')
    plt.title('First z-even band gap for each simulation step')
    fig.savefig('gaps.png')
Beispiel #7
0
def main():
    if len(sys.argv) > 1:
        mode=sys.argv[1]
    else:
        mode='sim'
    minrad = 0.2
    maxrad = 0.4
    radstep = 0.05
    numsteps = int((maxrad - minrad) / radstep + 1.5)
    steps = np.linspace(minrad, maxrad, num=numsteps, endpoint=True)
    
    for i, radius in enumerate(steps):

        log.info("running simulation with {0:n} radius steps:\n{1}".format(
            numsteps, steps) +
            '\n  ### current step: #{0} ({1}) ###\n'.format(i+1, radius))

        sim = TriHolesSlab3D(
            material='SiN',
            radius=radius,
            thickness=0.8,
            numbands=4,#8,
            k_interpolation=5,#31,
            resolution=16,#32,
            mesh_size=3,#7,
            supercell_z=6,
            runmode=mode,
            num_processors=2,
            save_field_patterns=True,
            convert_field_patterns=True)
        
        if not sim:
            log.error('an error occurred during simulation. See the .out file')
            return
    
        # load zeven mode band data:
        fname = path.join(sim.workingdir, sim.jobname + '_zevenfreqs.csv')
        data = np.loadtxt(fname, delimiter=',', skiprows=1)
        gapbands = get_gap_bands(data[:, 5:], light_line=data[:, 4])

        # maybe there is no gap?
        if len(gapbands) == 0:
            gap = 0
        elif gapbands[0][0] != 1:
            # it must be a gap between band 1 and 2
            gap = 0
        else:
            gap = gapbands[0][3]

        # save gap sizes to file (first TE gap):
        with open("gaps.dat", "a") as f:
            f.write("{0}\t{1}\n".format(radius, gap))
    
        log.info(' ##### radius={0} - success! #####\n\n'.format(radius))

        # reset logger; the next stuff logged is going to next step's file:
        log.reset_logger()
        
    data = np.loadtxt('gaps.dat')
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.plot(data[:,0], data[:,1], 'o-')
    fig.savefig('gaps.png')
def main():
    if len(sys.argv) > 1:
        mode=sys.argv[1]
    else:
        mode='sim'

    # monkey patching:
    # (don't output multiple tiles along y)
    # (x and y are switched because of -T)
    defaults.mpbdata_call = (
        'mpb-data -T -rn%(resolution)s '
        '-y%(number_of_tiles_to_output)s '
        '-o%(output_file)s '
        '%(h5_file)s')
    defaults.number_of_tiles_to_output = 5
    # defaults.add_epsilon_as_inset = True
    defaults.output_funcs_te = [
        'fix-hfield-phase', 'output-hfield-z',
        'output-dpwr', 'output-hpwr', 'output-tot-pwr']

    # the knots of the cubic spline describing the
    # k dependent epsilon function:
    fknots = np.array(
        [0.     ,  0.03125,  0.0625 ,  0.09375,  0.125  ,  0.15625,
         0.1875 ,  0.21875,  0.25   ,  0.28125,  0.3125 ,  0.34375,
         0.375  ,  0.40625,  0.4375 ,  0.46875,  0.5    ])

    # the coefficients of the cubic spline describing the
    # k dependent epsilon function:
    fcoeffs = np.array(
        [[-1.26479352e-02,   3.79438056e-02,  -1.39127287e-01,
           5.18565342e-01,  -1.93513408e+00,   7.22197099e+00,
          -2.69527499e+01,   6.47721598e+01,  -7.50651090e+01,
          -1.26125949e+01,   2.63548544e+02,  -2.26207933e+02,
          -5.13747147e+01,   1.41246898e+02,  -3.11230826e+01,
           4.84425567e+01],
        [  3.95247975e-04,  -7.90495950e-04,   2.76673582e-03,
          -1.02764473e-02,   3.83390535e-02,  -1.43079767e-01,
           5.33980013e-01,  -1.99284029e+00,   4.07954969e+00,
          -2.95780428e+00,  -4.14023504e+00,   2.05674410e+01,
          -6.39552710e-01,  -5.45593221e+00,   7.78596450e+00,
           4.86817550e+00],
        [ -1.70254597e+00,  -1.70255832e+00,  -1.70249656e+00,
          -1.70273124e+00,  -1.70185428e+00,  -1.70512743e+00,
          -1.69291180e+00,  -1.73850118e+00,  -1.67329151e+00,
          -1.63823697e+00,  -1.86005070e+00,  -1.34670051e+00,
          -7.23954002e-01,  -9.14437905e-01,  -8.41624396e-01,
          -4.46182521e-01],
        [  3.64596772e+00,   3.59276316e+00,   3.53955860e+00,
           3.48635403e+00,   3.43314947e+00,   3.37994491e+00,
           3.32674035e+00,   3.27353579e+00,   3.21923818e+00,
           3.16864095e+00,   3.11417266e+00,   3.06004574e+00,
           3.03114342e+00,   3.00632747e+00,   2.97673374e+00,
           2.95708665e+00]])

    ksteps = np.linspace(0., 0.5, num=17)
    supcellsize = 13

    # The bigger the unit cell, the more bands fold in below the
    # waveguide band:
    first_wg_band = int(3 + 2 * (supcellsize - 1))

    sim = TriHoles2D_Waveguide_effective_epsilon_k_dependent(
        epsilon_cubspline_knots=fknots,
        epsilon_cubspline_coeffs=fcoeffs,
        band_number=first_wg_band,
        extra_bands=10,
        radius=0.38,
        mode='te',
        k_steps=ksteps,
        supercell_size=supcellsize,
        resolution=16,
        mesh_size=7,
        ensure_y_parity='odd',
        runmode=mode,
        num_processors=2,
        save_field_patterns_kvecs=[
            (x, 0, 0) for x in ksteps],
        plot_crop_y=False,
        convert_field_patterns=True,
        gap=(0.44090, 0.52120))

    if not sim:
        log.error('an error occurred during simulation. See the .out file')
        return

    log.info(' ##### success! #####\n\n')
def main():
    if len(sys.argv) > 1:
        mode=sys.argv[1]
    else:
        mode='sim'

    # monkey patching:
    # (don't output multiple tiles along y)
    # (x and y are switched because of -T)
    defaults.mpbdata_call = (
        'mpb-data -T -rn%(resolution)s '
        '-y%(number_of_tiles_to_output)s '
        '-o%(output_file)s '
        '%(h5_file)s')
    defaults.number_of_tiles_to_output = 5
    # defaults.add_epsilon_as_inset = True
    defaults.output_funcs_te = [
        'fix-hfield-phase', 'output-hfield-z',
        'output-dpwr', 'output-hpwr', 'output-tot-pwr']

    # the knots of the cubic spline describing the
    # frequency dependent epsilon function:
    fknots = np.array(
        [ 0.43606492,  0.43632591,  0.43699937,  0.43826107,  0.43987166,
          0.4405708 ,  0.44359142,  0.4540687 ,  0.46606201,  0.47865032,
          0.49139404,  0.50431241,  0.51692864,  0.53029386,  0.54260207,
          0.55531914,  0.56803985])
    # the coefficients of the cubic spline describing the
    # frequency dependent epsilon function:
    fcoeffs = np.array(
        [[  1.05325162e+07,  -7.53192904e+06,  -5.34491361e+05,
            7.35887805e+06,  -1.78975790e+07,   1.11124611e+06,
            3.50296450e+04,  -7.75123125e+03,   2.52814337e+03,
           -7.88904847e+02,  -1.88305373e+02,  -3.86288083e+02,
            8.09187014e+03,  -2.33155197e+04,   3.20396213e+04,
           -1.69215816e+04],
         [  2.72848411e-11,   8.24663379e+03,  -6.97063083e+03,
           -8.99373723e+03,   2.65628394e+04,  -1.09756189e+04,
           -9.05673628e+02,   1.95372830e+02,  -8.35160080e+01,
            1.19591551e+01,  -1.82015878e+01,  -2.54993856e+01,
           -4.01198768e+01,   2.84329111e+02,  -5.76587375e+02,
            6.45763294e+02],
         [  2.43974026e+01,   2.65496888e+01,   2.74090204e+01,
            7.26674591e+00,   3.55635018e+01,   4.64610694e+01,
            1.05722403e+01,   3.13021818e+00,   4.47175210e+00,
            3.57097220e+00,   3.49142039e+00,   2.92687487e+00,
            2.09900754e+00,   5.36291884e+00,   1.76574464e+00,
            2.64545990e+00],
         [  2.95227326e+00,   2.95882797e+00,   2.97814765e+00,
            3.00055966e+00,   3.01967836e+00,   3.05140955e+00,
            3.12223419e+00,   3.17387217e+00,   3.22614445e+00,
            3.27424502e+00,   3.32006195e+00,   3.36172191e+00,
            3.39381359e+00,   3.43401941e+00,   3.49962690e+00,
            3.49472848e+00]])

    ksteps = np.linspace(0., 0.5, num=17)
    supcellsize = 13

    # The bigger the unit cell, the more bands fold in below the
    # waveguide band:
    first_wg_band = int(3 + 2 * (supcellsize - 1))

    sim = TriHoles2D_Waveguide_effective_epsilon_frequency_dependent(
        epsilon_cubspline_knots=fknots,
        epsilon_cubspline_coeffs=fcoeffs,
        band_number=first_wg_band,
        extra_bands=4,
        init_frequency=0.5,
        radius=0.38,
        mode='te',
        k_steps=ksteps,
        supercell_size=supcellsize,
        resolution=16,
        mesh_size=7,
        ensure_y_parity='odd',
        runmode=mode,
        num_processors=2,
        save_field_patterns_kvecs=[
            (x, 0, 0) for x in ksteps],
        plot_crop_y=False,
        convert_field_patterns=True)

    if not sim:
        log.error('an error occurred during simulation. See the .out file')
        return

    log.info(' ##### success! #####\n\n')
Beispiel #10
0
def main():
    if len(sys.argv) > 1:
        mode = sys.argv[1]
    else:
        mode = 'sim'

    # monkey patching:
    # (don't output multiple tiles along y)
    # (x and y are switched because of -T)
    defaults.mpbdata_call = ('mpb-data -T -rn%(resolution)s '
                             '-y%(number_of_tiles_to_output)s '
                             '-o%(output_file)s '
                             '%(h5_file)s')
    defaults.number_of_tiles_to_output = 5
    # defaults.add_epsilon_as_inset = True
    defaults.output_funcs_te = [
        'fix-hfield-phase', 'output-hfield-z', 'output-dpwr', 'output-hpwr',
        'output-tot-pwr'
    ]

    # the knots of the cubic spline describing the
    # frequency dependent epsilon function:
    fknots = np.array([
        0.43606492, 0.43632591, 0.43699937, 0.43826107, 0.43987166, 0.4405708,
        0.44359142, 0.4540687, 0.46606201, 0.47865032, 0.49139404, 0.50431241,
        0.51692864, 0.53029386, 0.54260207, 0.55531914, 0.56803985
    ])
    # the coefficients of the cubic spline describing the
    # frequency dependent epsilon function:
    fcoeffs = np.array(
        [[
            1.05325162e+07, -7.53192904e+06, -5.34491361e+05, 7.35887805e+06,
            -1.78975790e+07, 1.11124611e+06, 3.50296450e+04, -7.75123125e+03,
            2.52814337e+03, -7.88904847e+02, -1.88305373e+02, -3.86288083e+02,
            8.09187014e+03, -2.33155197e+04, 3.20396213e+04, -1.69215816e+04
        ],
         [
             2.72848411e-11, 8.24663379e+03, -6.97063083e+03, -8.99373723e+03,
             2.65628394e+04, -1.09756189e+04, -9.05673628e+02, 1.95372830e+02,
             -8.35160080e+01, 1.19591551e+01, -1.82015878e+01, -2.54993856e+01,
             -4.01198768e+01, 2.84329111e+02, -5.76587375e+02, 6.45763294e+02
         ],
         [
             2.43974026e+01, 2.65496888e+01, 2.74090204e+01, 7.26674591e+00,
             3.55635018e+01, 4.64610694e+01, 1.05722403e+01, 3.13021818e+00,
             4.47175210e+00, 3.57097220e+00, 3.49142039e+00, 2.92687487e+00,
             2.09900754e+00, 5.36291884e+00, 1.76574464e+00, 2.64545990e+00
         ],
         [
             2.95227326e+00, 2.95882797e+00, 2.97814765e+00, 3.00055966e+00,
             3.01967836e+00, 3.05140955e+00, 3.12223419e+00, 3.17387217e+00,
             3.22614445e+00, 3.27424502e+00, 3.32006195e+00, 3.36172191e+00,
             3.39381359e+00, 3.43401941e+00, 3.49962690e+00, 3.49472848e+00
         ]])

    ksteps = np.linspace(0., 0.5, num=17)
    supcellsize = 13

    # The bigger the unit cell, the more bands fold in below the
    # waveguide band:
    first_wg_band = int(3 + 2 * (supcellsize - 1))

    sim = TriHoles2D_Waveguide_effective_epsilon_frequency_dependent(
        epsilon_cubspline_knots=fknots,
        epsilon_cubspline_coeffs=fcoeffs,
        band_number=first_wg_band,
        extra_bands=4,
        init_frequency=0.5,
        radius=0.38,
        mode='te',
        k_steps=ksteps,
        supercell_size=supcellsize,
        resolution=16,
        mesh_size=7,
        ensure_y_parity='odd',
        runmode=mode,
        num_processors=2,
        save_field_patterns_kvecs=[(x, 0, 0) for x in ksteps],
        plot_crop_y=False,
        convert_field_patterns=True)

    if not sim:
        log.error('an error occurred during simulation. See the .out file')
        return

    log.info(' ##### success! #####\n\n')