Beispiel #1
0
def TriHolesSlab3D(
        material, radius, thickness, numbands=8, k_interpolation=11, 
        resolution=32, mesh_size=7, supercell_z=6,
        runmode='sim', num_processors=2,
        save_field_patterns=True, convert_field_patterns=True,
        containing_folder='./',
        job_name_suffix='', bands_title_appendix='',
        custom_k_space=None, modes=('zeven', 'zodd'),
        substrate_material=None):
    """Create a 3D MPB Simulation of a slab with a triangular lattice of
    holes.

    :param material: can be a string (e.g. SiN,
    4H-SiC-anisotropic_c_in_z; defined in data.py) or just the epsilon
    value (float)
    :param radius: the radius of holes in units of the lattice constant
    :param thickness: slab thickness in units of the lattice constant
    :param numbands: number of bands to calculate
    :param k_interpolation: number of the k-vectors between every two of
    the used high symmetry points Gamma, M, K and Gamma again, so the
    total number of simulated k-vectors will be 3*k_interpolation + 4
    :param resolution: described in MPB documentation
    :param mesh_size: described in MPB documentation
    :param supercell_z: the height of the supercell in units of the
    lattice constant
    :param runmode: can be one of the following:
        ''       : just create and return the simulation object
        'ctl'    : create the sim object and save the ctl file
        'sim' (default): run the simulation and do all postprocessing
        'postpc' : do all postprocessing; simulation should have run
                   before!
        'display': display all pngs done during postprocessing. This is
                   the only mode that is interactive.
    :param num_processors: number of processors used during simulation
    :param save_field_patterns: indicates whether field pattern h5 files
    are generated during the simulation (at points of high symmetry)
    :param convert_field_patterns: indicates whether field pattern h5
    files should be converted to png (only when postprocessing)
    :param containing_folder: the path to the folder which will contain
    the simulation subfolder.
    :param job_name_suffix: Optionally specify a job_name_suffix
    (appendix to the folder name etc.) which will be appended to the
    jobname created automatically from the most important parameters.
    :param bands_title_appendix: will be added to the title of the bands
    diagram.
    :param custom_k_space: By default, KSpaceTriangular with
    k_interpolation interpolation steps are used. Provide any KSpace
    object here to customize this. k_interpolation will then be ignored.
    :param modes: a list of modes to run. Possible are 'zeven', 'zodd'
    or '' (latter meaning no distinction). Default: ['zeven', 'zodd']
    :param substrate_material: the material of an optional substrate,
    see param material. Holes will not be extended into the substrate.
    Default: None, i.e. the substrate is air.
    :return: the Simulation object

    """
    mat = Dielectric(material)

    geom = Geometry(
        width=1,
        height=1,
        depth=supercell_z,
        triangular=True,
        objects=[
            Block(
                x=0, y=0, z=0,
                material=mat,
                #make it bigger than computational cell, just in case:
                size=(2, 2, thickness)),
            Rod(
                x=0,
                y=0,
                material='air',
                radius=radius)])

    if substrate_material:
        geom.add_substrate(
            Dielectric(substrate_material),
            start_at=-0.5 * thickness)

    if isinstance(custom_k_space, KSpace):
        kspace = custom_k_space
    else:
        kspace = KSpaceTriangular(
            k_interpolation=k_interpolation,
            use_uniform_interpolation=defaults.newmpb)

    # points of interest: (output mode patterns at these points)
    if save_field_patterns:
        poi = kspace.points()[0:-1]
    else:
        poi = []

    runcode = ''
    for mode in modes:
        if mode == '':
            runcode += (
                '(run %s)\n' % (
                    defaults.default_band_func(
                        poi, ' '.join(defaults.output_funcs_other))
                ) +
                '(print-dos 0 1.2 121)\n\n')
        else:
            if mode == 'zeven':
                outputfunc = ' '.join(defaults.output_funcs_te)
            else:
                outputfunc = ' '.join(defaults.output_funcs_tm)
            runcode += (
                '(run-%s %s)\n' % (
                    mode, defaults.default_band_func(poi, outputfunc)
                ) +
                '(print-dos 0 1.2 121)\n\n')

    jobname = 'TriHolesSlab_{0}_r{1:03.0f}_t{2:03.0f}'.format(
                    mat.name, radius * 1000, thickness * 1000)

    sim = Simulation(
        jobname=jobname + job_name_suffix,
        geometry=geom,
        kspace=kspace,
        numbands=numbands,
        resolution=resolution,
        mesh_size=mesh_size,
        initcode=defaults.default_initcode,
        postcode='',
        runcode=runcode,
        work_in_subfolder=path.join(
            containing_folder, jobname + job_name_suffix),
        clear_subfolder=runmode.startswith('s') or runmode.startswith('c'))

    draw_bands_title = ('Hex. PhC slab; '
                        '{0}, thickness={1:0.3f}, radius={2:0.3f}'.format(
                            mat.name, 
                            geom.objects[0].size[2], 
                            geom.objects[1].radius) +
                        bands_title_appendix)
    return do_runmode(
        sim, runmode, num_processors, draw_bands_title,
        plot_crop_y=0.8 / geom.substrate_index,
        convert_field_patterns=convert_field_patterns,
        field_pattern_plot_filetype=defaults.field_dist_filetype,
        field_pattern_plot_k_selection=None,
        x_axis_hint=[defaults.default_x_axis_hint, kspace][kspace.has_labels()]
    )
def TriHolesSlab3D(material,
                   radius,
                   thickness,
                   numbands=8,
                   k_interpolation=11,
                   resolution=32,
                   mesh_size=7,
                   supercell_z=6,
                   runmode='sim',
                   num_processors=2,
                   save_field_patterns=True,
                   convert_field_patterns=True,
                   containing_folder='./',
                   job_name_suffix='',
                   bands_title_appendix='',
                   custom_k_space=None,
                   modes=('zeven', 'zodd'),
                   substrate_material=None):
    """Create a 3D MPB Simulation of a slab with a triangular lattice of
    holes.

    :param material: can be a string (e.g. SiN,
    4H-SiC-anisotropic_c_in_z; defined in data.py) or just the epsilon
    value (float)
    :param radius: the radius of holes in units of the lattice constant
    :param thickness: slab thickness in units of the lattice constant
    :param numbands: number of bands to calculate
    :param k_interpolation: number of the k-vectors between every two of
    the used high symmetry points Gamma, M, K and Gamma again, so the
    total number of simulated k-vectors will be 3*k_interpolation + 4
    :param resolution: described in MPB documentation
    :param mesh_size: described in MPB documentation
    :param supercell_z: the height of the supercell in units of the
    lattice constant
    :param runmode: can be one of the following:
        ''       : just create and return the simulation object
        'ctl'    : create the sim object and save the ctl file
        'sim' (default): run the simulation and do all postprocessing
        'postpc' : do all postprocessing; simulation should have run
                   before!
        'display': display all pngs done during postprocessing. This is
                   the only mode that is interactive.
    :param num_processors: number of processors used during simulation
    :param save_field_patterns: indicates whether field pattern h5 files
    are generated during the simulation (at points of high symmetry)
    :param convert_field_patterns: indicates whether field pattern h5
    files should be converted to png (only when postprocessing)
    :param containing_folder: the path to the folder which will contain
    the simulation subfolder.
    :param job_name_suffix: Optionally specify a job_name_suffix
    (appendix to the folder name etc.) which will be appended to the
    jobname created automatically from the most important parameters.
    :param bands_title_appendix: will be added to the title of the bands
    diagram.
    :param custom_k_space: By default, KSpaceTriangular with
    k_interpolation interpolation steps are used. Provide any KSpace
    object here to customize this. k_interpolation will then be ignored.
    :param modes: a list of modes to run. Possible are 'zeven', 'zodd'
    or '' (latter meaning no distinction). Default: ['zeven', 'zodd']
    :param substrate_material: the material of an optional substrate,
    see param material. Holes will not be extended into the substrate.
    Default: None, i.e. the substrate is air.
    :return: the Simulation object

    """
    mat = Dielectric(material)

    geom = Geometry(
        width=1,
        height=1,
        depth=supercell_z,
        triangular=True,
        objects=[
            Block(
                x=0,
                y=0,
                z=0,
                material=mat,
                #make it bigger than computational cell, just in case:
                size=(2, 2, thickness)),
            Rod(x=0, y=0, material='air', radius=radius)
        ])

    if substrate_material:
        geom.add_substrate(Dielectric(substrate_material),
                           start_at=-0.5 * thickness)

    if isinstance(custom_k_space, KSpace):
        kspace = custom_k_space
    else:
        kspace = KSpaceTriangular(k_interpolation=k_interpolation,
                                  use_uniform_interpolation=defaults.newmpb)

    # points of interest: (output mode patterns at these points)
    if save_field_patterns:
        poi = kspace.points()[0:-1]
    else:
        poi = []

    runcode = ''
    for mode in modes:
        if mode == '':
            runcode += ('(run %s)\n' % (defaults.default_band_func(
                poi, ' '.join(defaults.output_funcs_other))) +
                        '(print-dos 0 1.2 121)\n\n')
        else:
            if mode == 'zeven':
                outputfunc = ' '.join(defaults.output_funcs_te)
            else:
                outputfunc = ' '.join(defaults.output_funcs_tm)
            runcode += ('(run-%s %s)\n' %
                        (mode, defaults.default_band_func(poi, outputfunc)) +
                        '(print-dos 0 1.2 121)\n\n')

    jobname = 'TriHolesSlab_{0}_r{1:03.0f}_t{2:03.0f}'.format(
        mat.name, radius * 1000, thickness * 1000)

    sim = Simulation(jobname=jobname + job_name_suffix,
                     geometry=geom,
                     kspace=kspace,
                     numbands=numbands,
                     resolution=resolution,
                     mesh_size=mesh_size,
                     initcode=defaults.default_initcode,
                     postcode='',
                     runcode=runcode,
                     work_in_subfolder=path.join(containing_folder,
                                                 jobname + job_name_suffix),
                     clear_subfolder=runmode.startswith('s')
                     or runmode.startswith('c'))

    draw_bands_title = (
        'Hex. PhC slab; '
        '{0}, thickness={1:0.3f}, radius={2:0.3f}'.format(
            mat.name, geom.objects[0].size[2], geom.objects[1].radius) +
        bands_title_appendix)
    return do_runmode(sim,
                      runmode,
                      num_processors,
                      draw_bands_title,
                      plot_crop_y=0.8 / geom.substrate_index,
                      convert_field_patterns=convert_field_patterns,
                      field_pattern_plot_filetype=defaults.field_dist_filetype,
                      field_pattern_plot_k_selection=None,
                      x_axis_hint=[defaults.default_x_axis_hint,
                                   kspace][kspace.has_labels()])