Esempio n. 1
0
def force_gmmt():
    wavelengths = np.linspace(400 * nm, 1000 * nm, 100)
    eps = meep_ext.get_eps(material)(wavelengths)
    Au = miepy.data_material(wavelengths, eps)
    # Au = miepy.constant_material(3.5**2)
    # Au = miepy.materials.Au()

    particles = []
    for i in range(9):
        orientation = miepy.quaternion.from_spherical_coords(theta[i], phi[i])
        particles.append(
            miepy.cylinder(position=[x[i], y[i], z[i]],
                           radius=radius,
                           height=height,
                           material=Au,
                           orientation=orientation))

    F = np.zeros([3, 9, len(wavelengths)], dtype=float)

    for i, wavelength in enumerate(pbar(wavelengths)):
        sol = miepy.cluster(particles=particles,
                            source=miepy.sources.plane_wave([1, 0]),
                            wavelength=wavelength,
                            lmax=4)

        F[..., i] = sol.force()
        # if i == 0:
        # miepy.visualize(sol)

    return dict(wavelengths=wavelengths, force=F)
Esempio n. 2
0
def vis():
    fig, ax = plt.subplots()

    norm = job.load(norm_sim)
    scat = job.load(scat_sim)

    ax.plot((1 / nm) / norm.frequency,
            scat.scattering / norm.incident * norm.area,
            'o',
            color='C0',
            label='scattering (FDTD)')
    ax.plot((1 / nm) / norm.frequency,
            scat.absorption / norm.incident * norm.area,
            'o',
            color='C1',
            label='absorption (FDTD)')
    ax.plot((1 / nm) / norm.frequency,
            (scat.scattering + scat.absorption) / norm.incident * norm.area,
            'o',
            color='C2',
            label='extinction (FDTD)')

    wavelengths = np.linspace(400 * nm, 1000 * nm, 100)
    eps = meep_ext.get_eps(material)(wavelengths)
    Au = miepy.data_material(wavelengths, eps)
    # Au = miepy.constant_material(3.5**2)

    C, A, E = [np.zeros_like(wavelengths) for i in range(3)]

    particles = []
    for i in range(9):
        orientation = miepy.quaternion.from_spherical_coords(theta[i], phi[i])
        particles.append(
            miepy.cylinder(position=[x[i], y[i], z[i]],
                           radius=radius,
                           height=height,
                           material=Au,
                           orientation=orientation))

    for i, wavelength in enumerate(pbar(wavelengths)):
        sol = miepy.cluster(particles=particles,
                            source=miepy.sources.plane_wave([1, 0]),
                            wavelength=wavelength,
                            lmax=3)

        C[i], A[i], E[i] = sol.cross_sections()

    ax.axhline(0, linestyle='--', color='black')
    ax.plot(wavelengths / nm, C, color='C0', label='scattering (GMT)')
    ax.plot(wavelengths / nm, A, color='C1', label='absorption (GMT)')
    ax.plot(wavelengths / nm, E, color='C2', label='extinction (GMT)')

    ax.legend()
    ax.set(xlabel='wavelength (nm)', ylabel='cross-section')

    plt.show()
Esempio n. 3
0
def gmt_sim():
    wavelengths = np.linspace(400 * nm, 1000 * nm, 100)
    eps = meep_ext.get_eps(material)(wavelengths)
    Au = miepy.data_material(wavelengths, eps)
    Au = miepy.constant_material(3.5**2)

    C, A, E = [np.zeros_like(wavelengths) for i in range(3)]

    particles = []
    # orientation = miepy.quaternion.from_spherical_coords(theta[i], phi[i])
    particles.append(miepy.cube([0, 0, 0], W, material=Au, orientation=q))

    for i, wavelength in enumerate(tqdm(wavelengths)):
        sol = miepy.cluster(particles=particles,
                            source=miepy.sources.plane_wave([1, 0]),
                            wavelength=wavelength,
                            lmax=4)

        C[i], A[i], E[i] = sol.cross_sections()

    return dict(wavelengths=wavelengths, C=C, A=A, E=E)
Esempio n. 4
0
def load_material(name, author):
    """Load a material from the database
              name         material name
              author       author of the experimental data
    """

    # return load_material(miepy.__path__[0] + "/materials/ag.npy")
    filepath = get_filepath(name, author)
    with open(filepath, 'r') as f:
        docs = yaml.load(f, Loader=yaml.SafeLoader)
        str_data = docs['DATA'][0]['data']
        list_data = str_data.splitlines()
        for i, item in enumerate(list_data):
            vals = item.split(' ')
            vals = list(map(float, vals))
            list_data[i] = vals

        data = np.array(list_data)
        wav = data[:, 0] * 1e-6
        n = data[:, 1]
        k = data[:, 2]
        eps = (n + 1j * k)**2

    return miepy.data_material(wav, eps, name=name)
Esempio n. 5
0
    -31.70601405 + 2.53195081j,
    -33.12162576 + 2.52289615j,
    -34.56183069 + 2.51650543j,
    -36.02659057 + 2.51269917j,
    -37.51587153 + 2.51140537j,
    -39.02964358 + 2.51255884j,
    -40.56788003 + 2.51610058j,
    -42.13055709 + 2.52197726j,
])

wavelengths = np.linspace(400 * nm, 1000 * nm, 40)
frequency = np.linspace(1, 1 / 0.4, 40)

separation = 400 * nm
radius = 75 * nm
Au = miepy.data_material(wavelengths, eps)
source = miepy.sources.plane_wave.from_string(polarization='rhc')
gmtF = np.zeros((3, ) + wavelengths.shape)
gmtC = np.zeros((3, ) + wavelengths.shape)

for i, wavelength in enumerate(wavelengths):
    sol = miepy.sphere_cluster(position=[[-separation / 2, 0, 0],
                                         [separation / 2, 0, 0]],
                               radius=radius,
                               material=Au,
                               source=source,
                               wavelength=wavelength,
                               lmax=2)

    gmtF[:, i] = sol.force_on_particle(1)
    gmtC[:, i] = sol.cross_sections()
def vis():
    ### forces
    fig, ax = plt.subplots()

    norm = job.load(dimer_norm)
    scat = job.load(dimer_scat)

    ax.plot((1 / nm) / norm.frequency,
            scat.scattering / norm.incident * norm.area,
            'o',
            color='C0',
            label='scattering (FDTD)')
    ax.plot((1 / nm) / norm.frequency,
            scat.absorption / norm.incident * norm.area,
            'o',
            color='C1',
            label='absorption (FDTD)')
    ax.plot((1 / nm) / norm.frequency,
            (scat.scattering + scat.absorption) / norm.incident * norm.area,
            'o',
            color='C2',
            label='extinction (FDTD)')

    import miepy
    wavelengths = np.linspace(400 * nm, 1000 * nm, 100)
    eps = meep_ext.get_eps(gold)(wavelengths)
    Au = miepy.data_material(wavelengths, eps)
    # Au = miepy.constant_material(3.5**2)

    spheres = miepy.spheres([[-sep / 2, 0, 0], [sep / 2, 0, 0]], radius, Au)
    source = miepy.sources.x_polarized_plane_wave()
    sol = miepy.gmt(spheres, source, wavelengths, 2)
    C, A, E = sol.cross_sections()

    ax.axhline(0, linestyle='--', color='black')
    ax.plot(wavelengths / nm, C, color='C0', label='scattering (GMT)')
    ax.plot(wavelengths / nm, A, color='C1', label='absorption (GMT)')
    ax.plot(wavelengths / nm, E, color='C2', label='extinction (GMT)')

    ax.legend()
    ax.set(xlabel='wavelength (nm)', ylabel='cross-section')

    ### field animation
    fig, ax = plt.subplots()

    x = np.linspace(0, cell[0] / nm, Nx)
    z = np.linspace(0, cell[1] / nm, Nz)
    X, Z = np.meshgrid(x, z, indexing='ij')

    var = job.load(dimer_fields)
    idx = np.s_[10:-10, 10:-10]
    E = var.E[:, 10:-10, 10:-10]
    # E = var.E
    vmax = np.max(np.abs(E)) / 2
    im = ax.pcolormesh(X[idx],
                       Z[idx],
                       E[0],
                       cmap='RdBu',
                       animated=True,
                       vmax=vmax,
                       vmin=-vmax)

    ax.set_aspect('equal')

    def update(i):
        im.set_array(np.ravel(E[i][:-1, :-1]))
        return [im]

    ani = animation.FuncAnimation(fig,
                                  update,
                                  range(E.shape[0]),
                                  interval=50,
                                  blit=True)

    plt.show()
Esempio n. 7
0
def vis():
    ### forces
    fig, axes = plt.subplots(nrows=2,
                             figsize=(7, 6),
                             sharex=True,
                             gridspec_kw=dict(height_ratios=[2, 1],
                                              hspace=0.05))

    norm = job.load(dimer_norm)
    scat = job.load(dimer_scat)

    for ax in axes:
        ax.plot((1 / nm) / norm.frequency,
                scat.Fx / norm.incident * norm.area * constants.epsilon_0 / 2 *
                1e25,
                'o',
                color='C0',
                label='Fx (FDTD)')
        ax.plot((1 / nm) / norm.frequency,
                scat.Fy / norm.incident * norm.area * constants.epsilon_0 / 2 *
                1e25,
                'o',
                color='C1',
                label='Fy (FDTD)')
        ax.plot((1 / nm) / norm.frequency,
                scat.Fz / norm.incident * norm.area * constants.epsilon_0 / 2 *
                1e25,
                'o',
                color='C2',
                label='Fz (FDTD)')

    import miepy
    wavelengths = np.linspace(400 * nm, 1000 * nm, 100)
    eps = meep_ext.get_eps(gold)(wavelengths)
    Au = miepy.data_material(wavelengths, eps)
    # Au = miepy.constant_material(3.5**2)

    spheres = miepy.spheres([[-sep / 2, 0, 0], [sep / 2, 0, 0]], radius, Au)
    source = miepy.sources.rhc_polarized_plane_wave()
    sol = miepy.gmt(spheres, source, wavelengths, 2)
    F = sol.force_on_particle(1)

    for ax in axes:
        ax.axhline(0, linestyle='--', color='black')
        ax.plot(wavelengths / nm, F[0] * 1e25, color='C0', label='Fx (GMT)')
        ax.plot(wavelengths / nm, F[1] * 1e25, color='C1', label='Fy (GMT)')
        ax.plot(wavelengths / nm, F[2] * 1e25, color='C2', label='Fz (GMT)')

    axes[0].legend()
    axes[0].set(ylabel='force')
    axes[1].set(xlabel='wavelength (nm)', ylabel='force', ylim=[-0.035, 0.01])

    ### field animation
    fig, ax = plt.subplots()

    x = np.linspace(0, cell[0] / nm, Nx)
    z = np.linspace(0, cell[1] / nm, Nz)
    X, Z = np.meshgrid(x, z, indexing='ij')

    var = job.load(dimer_fields)
    idx = np.s_[10:-10, 10:-10]
    E = var.E[:, 10:-10, 10:-10]
    # E = var.E
    vmax = np.max(np.abs(E)) / 2
    im = ax.pcolormesh(X[idx],
                       Z[idx],
                       E[0],
                       cmap='RdBu',
                       animated=True,
                       vmax=vmax,
                       vmin=-vmax)

    ax.set_aspect('equal')

    def update(i):
        im.set_array(np.ravel(E[i][:-1, :-1]))
        return [im]

    ani = animation.FuncAnimation(fig,
                                  update,
                                  range(E.shape[0]),
                                  interval=50,
                                  blit=True)

    plt.show()