def force_sim(): """perform scattering simulation""" sim = meep.Simulation(cell_size=cell, boundary_layers=[pml], geometry=geometry, default_material=medium, resolution=resolution) sim.init_fields() source(sim) L = 2*radius + 2*particle_monitor_gap forces = {} for i in range(9): p = meep.Vector3(x[i], y[i], z[i]) key = 'N{i}_F{c}' forces[key.format(i=i, c='x')] = meep_ext.add_force_box(sim, fcen, df, nfreq, p, [L,L,L], meep.X) forces[key.format(i=i, c='y')] = meep_ext.add_force_box(sim, fcen, df, nfreq, p, [L,L,L], meep.Y) forces[key.format(i=i, c='z')] = meep_ext.add_force_box(sim, fcen, df, nfreq, p, [L,L,L], meep.Z) sim.run(until_after_sources=meep.stop_when_fields_decayed(.5*um, decay, pt=meep.Vector3(0,0,monitor_size[2]/2), decay_by=1e-8)) ret = {} for i in range(9): for c in ['x', 'y', 'z']: key = f'N{i}_F{c}' ret[key] = np.array(meep.get_forces(forces[key])) ret['frequency'] = np.array(meep.get_force_freqs(forces['N1_Fx'])) return ret
def force_sim(): """perform scattering simulation""" sim = meep.Simulation(cell_size=cell, boundary_layers=[pml], geometry=geometry, default_material=medium, resolution=resolution) sim.init_fields() source(sim) L = 2**.5 * W + 2 * particle_monitor_gap p = meep.Vector3(sep / 2, 0, 0) Fx_mon = meep_ext.add_force_box(sim, fcen, df, nfreq, p, [L, L, L], meep.X) Fy_mon = meep_ext.add_force_box(sim, fcen, df, nfreq, p, [L, L, L], meep.Y) Fz_mon = meep_ext.add_force_box(sim, fcen, df, nfreq, p, [L, L, L], meep.Z) sim.run(until_after_sources=meep.stop_when_fields_decayed( .5 * um, decay, pt=meep.Vector3(0, 0, monitor_size[2] / 2), decay_by=1e-5)) Fx = np.array(meep.get_forces(Fx_mon)) Fy = np.array(meep.get_forces(Fy_mon)) Fz = np.array(meep.get_forces(Fz_mon)) frequency = np.array(meep.get_force_freqs(Fx_mon)) return dict(frequency=frequency, Fx=Fx, Fy=Fy, Fz=Fz)
def dimer_scat(): """perform scattering simulation""" scat = meep.Simulation(cell_size=cell, boundary_layers=[pml], geometry=geometry, resolution=resolution) scat.init_fields() source(scat) L = 2 * radius + 2 * particle_monitor_gap Fx = meep_ext.add_force_box(scat, fcen, df, nfreq, p2, [L, L, L], meep.X) Fy = meep_ext.add_force_box(scat, fcen, df, nfreq, p2, [L, L, L], meep.Y) Fz = meep_ext.add_force_box(scat, fcen, df, nfreq, p2, [L, L, L], meep.Z) # scat.run(until_after_sources=8*um) scat.run(until_after_sources=meep.stop_when_fields_decayed( .5 * um, meep.Ex, pt=p2 - meep.Vector3(0, 0, L / 2), decay_by=1e-7)) return { 'Fx': np.array(meep.get_forces(Fx)), 'Fy': np.array(meep.get_forces(Fy)), 'Fz': np.array(meep.get_forces(Fz)), 'frequency': np.array(meep.get_force_freqs(Fx)) }
def sim(separation): """perform scattering simulation""" L = separation + 2*radius + 2*pml_monitor_gap + 2*particle_monitor_gap + 2*pml.thickness cell = meep.Vector3(L,L,L) p1 = meep.Vector3(-separation/2, 0, 0) p2 = meep.Vector3(separation/2, 0, 0) geometry = [meep.Sphere(center=p1, radius=radius, material=gold), meep.Sphere(center=p2, radius=radius, material=gold)] scat = meep.Simulation(cell_size=cell, boundary_layers=[pml], geometry=geometry, resolution=resolution) scat.init_fields() source(scat) L = 2*radius + 2*particle_monitor_gap Fx = meep_ext.add_force_box(scat, fcen, 0, 1, p2, [L,L,L], meep.X) Fy = meep_ext.add_force_box(scat, fcen, 0, 1, p2, [L,L,L], meep.Y) Fz = meep_ext.add_force_box(scat, fcen, 0, 1, p2, [L,L,L], meep.Z) # scat.run(until_after_sources=8*um) scat.run(until_after_sources=meep.stop_when_fields_decayed(.5*um, meep.Ex, pt=p2-meep.Vector3(0,0,L/2), decay_by=1e-5)) return {'Fx': np.array(meep.get_forces(Fx))[0], 'Fy': np.array(meep.get_forces(Fy))[0], 'Fz': np.array(meep.get_forces(Fz))[0]}