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 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)