コード例 #1
0
ファイル: indicator.py プロジェクト: NahsiN/MPBParser
def indicator_func(mpb, eps_slab, eps_air, type, TOL=1e-3):
    # type air_slab_bdry, slab_only, air_hole_slab_bdry
    epsilon = readfield(mpb, field_type='epsilon_isotropic_trace')

    if type == 'slab_only':
        indicator_slab = np.zeros(epsilon.dset.shape)
        mask_slab = abs(epsilon.dset[:] - eps_slab) <= TOL
        indicator_slab[mask_slab] = 1
        indicator = indicator_slab


    elif type == 'air_slab_bdry':
        indicator_air_slab_bdry = np.zeros(epsilon.dset.shape)
        # still keeps the slab-hole boundary
        mask_air_slab_bdry = np.logical_not(np.logical_or(abs(epsilon.dset[:]- eps_air) <= TOL, \
            abs(epsilon.dset[:]- eps_slab) <= TOL))
        indicator_air_slab_bdry[mask_slab_hole_bdry] = 1
        indicator = indicator_air_slab_bdry

    elif type == 'air_hole_slab_bdry':
        indicator_air_hole_slab_bdry = np.zeros(epsilon.dset.shape)
        # still keeps the slab-hole boundary
        mask_air_hole_slab_bdry = np.logical_not(np.logical_or(abs(epsilon.dset[:]- eps_air) <= TOL, \
            abs(epsilon.dset[:]- eps_slab) <= TOL))
        # loop over the z dimension and weed out slab-supercell boundary by looking
        # at mean epsilon in the xy cross section
        for k in range(epsilon.dset.shape[2]):
            # 0.5*(eps_air + eps_slab) is a reasonable estimate.
            if np.mean(epsilon.dset[:,:,k]) < 0.5*(eps_air + eps_slab):
                mask_air_hole_slab_bdry[:,:,k] = 0
        indicator_air_hole_slab_bdry[mask_slab_hole_bdry] = 1
        indicator = indicator_air_hole_slab_bdry
        # FOR DEBUGGING
        # plt.figure()
        # plt.imshow(indicator_slab_hole_bdry[:,:, int(epsilon.dset.shape[2]/2)])
        # plt.colorbar()
        # plt.show()
    else:
        print('Invalid type entereted. Valid options are')
        epsilon.close()
        return None
    epsilon.close()
    return indicator
コード例 #2
0
ファイル: indicator.py プロジェクト: NahsiN/MPBParser
def indicator_func(mpb, eps_slab, eps_air, type, TOL=1e-3):
    # type air_slab_bdry, slab_only, air_hole_slab_bdry
    epsilon = readfield(mpb, field_type='epsilon_isotropic_trace')

    if type == 'slab_only':
        indicator_slab = np.zeros(epsilon.dset.shape)
        mask_slab = abs(epsilon.dset[:] - eps_slab) <= TOL
        indicator_slab[mask_slab] = 1
        indicator = indicator_slab

    elif type == 'air_slab_bdry':
        indicator_air_slab_bdry = np.zeros(epsilon.dset.shape)
        # still keeps the slab-hole boundary
        mask_air_slab_bdry = np.logical_not(np.logical_or(abs(epsilon.dset[:]- eps_air) <= TOL, \
            abs(epsilon.dset[:]- eps_slab) <= TOL))
        indicator_air_slab_bdry[mask_slab_hole_bdry] = 1
        indicator = indicator_air_slab_bdry

    elif type == 'air_hole_slab_bdry':
        indicator_air_hole_slab_bdry = np.zeros(epsilon.dset.shape)
        # still keeps the slab-hole boundary
        mask_air_hole_slab_bdry = np.logical_not(np.logical_or(abs(epsilon.dset[:]- eps_air) <= TOL, \
            abs(epsilon.dset[:]- eps_slab) <= TOL))
        # loop over the z dimension and weed out slab-supercell boundary by looking
        # at mean epsilon in the xy cross section
        for k in range(epsilon.dset.shape[2]):
            # 0.5*(eps_air + eps_slab) is a reasonable estimate.
            if np.mean(epsilon.dset[:, :, k]) < 0.5 * (eps_air + eps_slab):
                mask_air_hole_slab_bdry[:, :, k] = 0
        indicator_air_hole_slab_bdry[mask_slab_hole_bdry] = 1
        indicator = indicator_air_hole_slab_bdry
        # FOR DEBUGGING
        # plt.figure()
        # plt.imshow(indicator_slab_hole_bdry[:,:, int(epsilon.dset.shape[2]/2)])
        # plt.colorbar()
        # plt.show()
    else:
        print('Invalid type entereted. Valid options are')
        epsilon.close()
        return None
    epsilon.close()
    return indicator
コード例 #3
0
ファイル: plotsmpb.py プロジェクト: NahsiN/MPBParser
def plotfields(mpb, field_type, kindex=None, band=None, comp=None, mpbpostprocess=False,
    epsilon_contour_options={}, figsize=None, field_file=None, epsilon_file=None, plot_options={}):
    """
    Plots fields

    Inputs
    ------
    mpbpostprocess : False (default), assumes no post processing of the fields
                     has been performed using mpb-data
    field_type : 'e', 'epsilon', 'epsilon-ft'
    plot_options : specifies extra plot options such as axes limits
    """

    if figsize is not None:
        plt.figure(figsize=figsize)
    else:
        plt.figure()

    if epsilon_file is None:
        epsilon = readfield(mpb, field_type='epsilon_isotropic_trace', mpbpostprocess=mpbpostprocess)
    elif isinstance(epsilon_file, str):
        epsilon = readfield(mpb, field_type='epsilon_isotropic_trace', mpbpostprocess=mpbpostprocess, field_file=epsilon_file)

    if field_type == 'e':
        if field_file is None:
            E = readfield(mpb, kindex, band, field_type, mpbpostprocess=mpbpostprocess)
        elif isinstance(field_file, str):
            E = readfield(mpb, kindex, band, field_type, mpbpostprocess=mpbpostprocess, field_file=field_file)

        E.create_complex()
        if comp is None:
            E2 = np.abs(E.x)**2 + np.abs(E.y)**2 + np.abs(E.z)**2
            if E2.ndim == 1:
                # (x) = getscale(mpb)
                # (xgrid, ygrid) = np.meshgrid(x, x)
                # creates a E2.ndim x E2.ndim square grid
                E2grid = np.tile(E2, (E2.shape[0], 1))
                epsilon_grid = np.tile(epsilon.dset, (epsilon.dset.shape[0], 1))
                # plt.contourf(xgrid, ygrid, E2grid)
                # plt.pcolormesh(E2grid)
                plt.imshow(E2grid)
                plt.colorbar()
                # plt.contour(xgrid, ygrid, epsilon_grid, colors='k', linewidths=lw)
                plt.contour(epsilon_grid, colors='w', **epsilon_contour_options)
                ax = plt.gca()
                ax.set_xticks(())
                ax.set_yticks(())
                plt.xlim(0, E2grid.shape[0]-1)
                plt.ylim(0, E2grid.shape[1]-1)

            elif E2.ndim == 2:
                # (x, y) = getscale(mpb)
                # (xgrid, ygrid) = np.meshgrid(x, y)
                # plt.contourf(xgrid, ygrid, E2)
                # plt.pcolormesh(E2)
                plt.imshow(E2)
                plt.colorbar()
                # plt.contour(xgrid, ygrid, epsilon.dset, colors='k', linewidths=lw)
                plt.contour(epsilon.dset, colors='w', **epsilon_contour_options)
                ax = plt.gca()
                ax.set_xticks(())
                ax.set_yticks(())
                # Determine which grid is on the axis. If Ny > Nx, the yindices
                # are placed on the x-axis
                if E2.shape[0] >= E2.shape[1]:
                    plt.xlim(0, E2.shape[0]-1)
                    plt.ylim(0, E2.shape[1]-1)
                else:
                    plt.xlim(0, E2.shape[1]-1)
                    plt.ylim(0, E2.shape[0]-1)

            elif E2.ndim == 3:
                # ASSUME SLAB GEOMETRY
                # xy cross section
                plt.imshow(E2[:, :, E2.shape[2]/2], aspect='equal')
                plt.colorbar()
                plt.contour(epsilon.dset[:, :, epsilon.dset.shape[2]/2], colors='w', **epsilon_contour_options)
                ax = plt.gca()
                ax.set_xticks(())
                ax.set_yticks(())

                # Determine which grid is on the axis. If Ny > Nx, the yindices
                # are placed on the x-axis
                if E2.shape[0] >= E2.shape[1]:
                    plt.xlim(0, E2.shape[0]-1)
                    plt.ylim(0, E2.shape[1]-1)
                else:
                    plt.xlim(0, E2.shape[1]-1)
                    plt.ylim(0, E2.shape[0]-1)

    elif field_type == 'epsilon':
        if len(epsilon.dset.shape) == 1:
            epsilon_grid = np.tile(epsilon.dset, (epsilon.dset.shape[0], 1))
            # epsilon_grid_ft = fftshift(fft2(epsilon_grid))
            (x) = getscale(mpb)
            (xgrid, ygrid) = np.meshgrid(x, x)
            # plt.pcolormesh(xgrid, ygrid, epsilon_grid, cmap='Greys')
            plt.imshow(epsilon_grid, cmap='Greys')
            plt.colorbar()
            ax = plt.gca()
            ax.set_xticks(())
            ax.set_yticks(())
            plt.xlim(0, epsilon_grid.shape[0]-1)
            plt.ylim(0, epsilon_grid.shape[1]-1)
            # plt.figure()
            # plt.imshow(np.abs(epsilon_grid_ft)**2)
            # plt.colorbar()

        elif len(epsilon.dset.shape) == 2:
            # Greys or gray
            # plt.pcolor(epsilon.dset, cmap='Greys')
            # filter out DC_component
            # epsilon_ft[np.unravel_index(np.argmax(epsilon_ft), np.shape(epsilon_ft))] = 0

            plt.imshow(epsilon.dset, cmap='Greys')
            plt.colorbar()
            plt.xlim(0, epsilon.dset.shape[0]-1)
            plt.ylim(0, epsilon.dset.shape[1]-1)
            ax = plt.gca()
            ax.set_xticks(())
            ax.set_yticks(())

        elif len(epsilon.dset.shape) == 3:
            # ASSUME PC SLAB GEOMETRY ONLY
            # plot in middle of slab
            # xy cross section
            # plt.imshow(epsilon.dset[:, :, epsilon.dset.shape[2]/2], cmap='Greys', aspect='equal')
            # yz cross section
            # plt.imshow(epsilon.dset[epsilon.dset.shape[0]/2, :, :], cmap='Greys', aspect='equal')
            plt.imshow(epsilon.dset[0, :, :], cmap='Greys', aspect='equal')
            plt.colorbar()
            # plt.xlim(0, epsilon.dset.shape[0]-1)
            # plt.ylim(0, epsilon.dset.shape[1]-1)
            ax = plt.gca()
            ax.set_xticks(())
            ax.set_yticks(())

    elif field_type == 'epsilon-ft':
        if len(epsilon.dset.shape) == 1:
            pass
        elif len(epsilon.dset.shape) == 2:
            # zero pad
            epsilon_ft = fftshift(fft2(np.pad(epsilon.dset[:,:], (512, 512), 'constant')))
            plt.imshow((np.abs(epsilon_ft)/np.max(np.abs(epsilon_ft)))**2, cmap='Greys', vmin=0, vmax=0.1)
            ax = plt.gca()
            ax.set_xticks(())
            ax.set_yticks(())

        elif len(epsilon.dset.shape) == 3:
            pass

        ax = plt.gca()
        ax.set_xticks(())
        ax.set_yticks(())

        if 'xlims' in plot_options:
            xa = plot_options['xlims'][0]
            xb = plot_options['xlims'][1]
            plt.xlim(xa, xb)

        if 'ylims' in plot_options:
            ya = plot_options['ylims'][0]
            yb = plot_options['ylims'][1]
            plt.ylim(ya, yb)

    epsilon.close()
コード例 #4
0
ファイル: integral_test.py プロジェクト: NahsiN/MPBParser
from MPBParser import MPBBandStructure, readfield, getscale
import numpy as np
import matplotlib.pyplot as plt
import scipy.integrate as spintegrate
from indicator import indicator_func

mpb = MPBBandStructure('/home/nishan/Code/thales/MPB/w14/nonbloch/w14.out', symm='zeven')
# mpb.csvparser()
mpb.readbanddata()
#E_nonbloch = readfield(mpbobj=mpb, field_type='e.nonbloch.v', kindex=3, band=16)
E_nonbloch = readfield(field_file='/home/nishan/Code/thales/MPB/w14/nonbloch/e.nonbloch.v.k10.b16.zeven.h5', field_type='e.nonbloch.v')
E_nonbloch.create_complex()

# (x, dx, y, dy, z, dz) = getscale(mpb, retstep=True)

ind = indicator_func(mpb, 10.0489, 1.0, 'slab_only')
# for DEBUGGING
# plt.figure()
# plt.imshow(ind[:,:, 50])
# plt.colorbar()
# plt.show()


def nlo_coeffs(efield, indicator, ccnl):
    """
    Returns the nonlinear coupling coeffs after integration
    efield is assumed to be nonbloch
    """

    (x, y, z) = getscale(mpb)
    # (x, dx, y, dy, z, dz) = getscale(mpb, retstep=True)