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)
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()
def vis(): ### forces fig, ax = plt.subplots() force = np.zeros([3, len(separations)]) for i, separation in enumerate(separations): var = job.load(sim, f'p{i}') force[0, i] = var.Fx force[1, i] = var.Fy force[2, i] = var.Fz norm = job.load(norm_sim) ax.axhline(0, linestyle='--', color='black') ax.plot(separations / nm, force[0] / norm.norm * norm.area * constants.epsilon_0 / 2, 'o', color='C0', label='Fx (FDTD)') ax.plot(separations / nm, force[1] / norm.norm * norm.area * constants.epsilon_0 / 2, 'o', color='C1', label='Fy (FDTD)') ax.plot(separations / nm, force[2] / norm.norm * norm.area * constants.epsilon_0 / 2, 'o', color='C2', label='Fz (FDTD)') import miepy eps = meep_ext.get_eps(gold)(wavelength) Au = miepy.constant_material(eps * scale**2) water = miepy.constant_material(nb**2) source = miepy.sources.rhc_polarized_plane_wave() seps = np.linspace(300 * nm / scale, 900 * nm / scale, 100) force = np.zeros([3, len(seps)]) for i, sep in enumerate(seps): spheres = miepy.spheres([[-sep / 2, 0, 0], [sep / 2, 0, 0]], radius / scale, Au) sol = miepy.gmt(spheres, source, wavelength, 2, medium=water) F = sol.force_on_particle(1) force[:, i] = F.squeeze() ax.plot(seps * scale / nm, force[0], color='C0', label='Fx (GMT)') ax.plot(seps * scale / nm, force[1], color='C1', label='Fy (GMT)') ax.plot(seps * scale / nm, force[2], color='C2', label='Fz (GMT)') ax.set(xlabel='separation (nm)', ylabel='force') ax.legend() plt.show()
def vis(): ### cross-sections fig, ax = plt.subplots() scat = np.zeros([len(separations)]) absorb = np.zeros([len(separations)]) for i, separation in enumerate(separations): norm = job.load(norm_sim, f'p{i}') var = job.load(sim, f'p{i}') scat[i] = var.scattering / norm.norm * norm.area absorb[i] = var.absorption / norm.norm * norm.area ax.plot(separations / nm, scat, 'o', color='C0', label='scattering (FDTD)') ax.plot(separations / nm, absorb, 'o', color='C1', label='absorption (FDTD)') ax.plot(separations / nm, scat + absorb, 'o', color='C2', label='extinction (FDTD)') import miepy eps = meep_ext.get_eps(gold)(wavelength) Au = miepy.constant_material(eps) source = miepy.sources.rhc_polarized_plane_wave() seps = np.linspace(300 * nm, 900 * nm, 100) scat = np.zeros([len(seps)]) absorb = np.zeros([len(seps)]) extinct = np.zeros([len(seps)]) for i, sep in enumerate(seps): spheres = miepy.spheres([[-sep / 2, 0, 0], [sep / 2, 0, 0]], radius, Au) sol = miepy.gmt(spheres, source, wavelength, 2) scat[i], absorb[i], extinct[i] = sol.cross_sections() ax.plot(seps / nm, scat, color='C0', label='scattering (GMT)') ax.plot(seps / nm, absorb, color='C1', label='absorption (GMT)') ax.plot(seps / nm, extinct, color='C2', label='extinction (GMT)') ax.set(xlabel='separation (nm)', ylabel='cross-section') ax.legend() plt.show()
def vis(): ### forces fig, axes = plt.subplots(nrows=2, figsize=(7,6), sharex=True, gridspec_kw=dict(height_ratios=[2,1], hspace=0.05)) force = np.zeros([3,len(separations)]) for i,separation in enumerate(separations): var = job.load(sim, f'p{i}') force[0,i] = var.Fx force[1,i] = var.Fy force[2,i] = var.Fz norm = job.load(norm_sim) for ax in axes: ax.axhline(0, linestyle='--', color='black') ax.plot(separations/nm, force[0]/norm.norm*norm.area*constants.epsilon_0/2*1e25, 'o', color='C0', label='Fx (FDTD)') ax.plot(separations/nm, force[1]/norm.norm*norm.area*constants.epsilon_0/2*1e25, 'o', color='C1', label='Fy (FDTD)') ax.plot(separations/nm, force[2]/norm.norm*norm.area*constants.epsilon_0/2*1e25, 'o', color='C2', label='Fz (FDTD)') import miepy eps = meep_ext.get_eps(gold)(wavelength) Au = miepy.constant_material(eps) # Au = miepy.constant_material(3.5**2) source = miepy.sources.rhc_polarized_plane_wave() seps = np.linspace(300*nm, 900*nm, 100) force = np.zeros([3,len(seps)]) for i,sep in enumerate(seps): spheres = miepy.spheres([[-sep/2,0,0],[sep/2,0,0]], radius, Au) sol = miepy.gmt(spheres, source, wavelength, 2) F = sol.force_on_particle(1) force[:,i] = F.squeeze() for ax in axes: ax.plot(seps/nm, force[0]*1e25, color='C0', label='Fx (GMT)') ax.plot(seps/nm, force[1]*1e25, color='C1', label='Fy (GMT)') ax.plot(seps/nm, force[2]*1e25, color='C2', label='Fz (GMT)') axes[0].legend() axes[0].set(ylabel='force') axes[1].set(xlabel='separation (nm)', ylabel='force', ylim=[-3e-2, 3e-2]) plt.show()
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)
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()
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()
""" Compare material to raw eps data """ import numpy as np import meep_ext import matplotlib.pyplot as plt import miepy nm = 1e-3 wavelengths = np.linspace(400 * nm, 1000 * nm, 100) eps = meep_ext.get_eps(meep_ext.material.Au())(wavelengths) plt.plot(wavelengths * 1e3, eps.real, color='C0', label='Re (meep)') plt.plot(wavelengths * 1e3, eps.imag, color='C1', label='Im (meep)') gold = miepy.materials.predefined.Au() eps = gold.eps(wavelengths * 1e-6) plt.plot(wavelengths * 1e3, eps.real, '--', color='C0', label='Re (JC)') plt.plot(wavelengths * 1e3, eps.imag, '--', color='C1', label='Im (JC)') plt.legend() plt.show()