#f.add_volume_source(meep.Ex, src_time_type, srcvolume) ## Replace the f.add_volume_source(meep.Ex, srctype, srcvolume) line with following: ## Option for a custom source (e.g. exciting some waveguide mode) class SrcAmplitudeFactor(meep.Callback): ## The source amplitude is complex -> phase factor modifies its direction ## todo: implement in MEEP: we should define an AmplitudeVolume() object and reuse it for monitors later def __init__(self, Kx=0, Ky=0): meep.Callback.__init__(self) (self.Kx, self.Ky) = Kx, Ky def complex_vec(self, vec): ## Note: the 'vec' coordinates are _relative_ to the source center # (oblique) plane wave source: return np.exp(-1j*(self.Kx*vec.x() + self.Ky*vec.y())) # (oblique) Gaussian beam source: #return np.exp(-1j*(self.Kx*vec.x() + self.Ky*vec.y()) - (vec.x()/100e-6)**2 - (vec.y()/100e-6)**2) af = SrcAmplitudeFactor(Kx=getattr(model, 'Kx', 0), Ky=getattr(model, 'Ky', 0)) meep.set_AMPL_Callback(af.__disown__()) f.add_volume_source(meep.Ex, src_time_type, srcvolume, meep.AMPL) ## Define monitor planes, and the field output for visualisation (controlled by keywords in the 'comment' parameter) monitor_options = {'size_x':model.size_x, 'size_y':model.size_y, 'resolution':model.resolution, 'Kx':getattr(model, 'Kx', 0), 'Ky':getattr(model, 'Ky', 0)} monitor1_Ex = meep_utils.AmplitudeMonitorPlane(f, comp=meep.Ex, z_position=model.monitor_z1, **monitor_options) monitor1_Hy = meep_utils.AmplitudeMonitorPlane(f, comp=meep.Hy, z_position=model.monitor_z1, **monitor_options) monitor2_Ex = meep_utils.AmplitudeMonitorPlane(f, comp=meep.Ex, z_position=model.monitor_z2, **monitor_options) monitor2_Hy = meep_utils.AmplitudeMonitorPlane(f, comp=meep.Hy, z_position=model.monitor_z2, **monitor_options) slices = [] if not "noepssnapshot" in model.comment: slices += [meep_utils.Slice(model=model, field=f, components=(meep.Dielectric), at_t=0, name='EPS')]
#f.add_volume_source(meep.Ex, src_time_type, srcvolume) ## Replace the f.add_volume_source(meep.Ex, srctype, srcvolume) line with following: ## Option for a custom source (e.g. exciting some waveguide mode) class SrcAmplitudeFactor(meep.Callback): ## The source amplitude is complex -> phase factor modifies its direction ## todo: implement in MEEP: we should define an AmplitudeVolume() object and reuse it for monitors later def __init__(self, Kx=0, Ky=0): meep.Callback.__init__(self) (self.Kx, self.Ky) = Kx, Ky def complex_vec(self, vec): ## Note: the 'vec' coordinates are _relative_ to the source center # (oblique) plane wave source: return np.exp(-1j*(self.Kx*vec.x() + self.Ky*vec.y())) # (oblique) Gaussian beam source: #return np.exp(-1j*(self.Kx*vec.x() + self.Ky*vec.y()) - (vec.x()/100e-6)**2 - (vec.y()/100e-6)**2) af = SrcAmplitudeFactor(Kx=getattr(model, 'Kx', 0), Ky=getattr(model, 'Ky', 0)) meep.set_AMPL_Callback(af.__disown__()) #f.add_volume_source(meep.Ex, src_time_type, srcvolume, meep.AMPL) f.add_volume_source(meep.Ez, src_time_type, srcvolume, meep.AMPL) ## Define monitor planes, and the field output for visualisation (controlled by keywords in the 'comment' parameter) monitor_options = {'size_x':model.size_x, 'size_y':model.size_y, 'resolution':model.resolution, 'Kx':getattr(model, 'Kx', 0), 'Ky':getattr(model, 'Ky', 0)} monitor1_Ex = meep_utils.AmplitudeMonitorPlane(f, comp=meep.Ex, z_position=model.monitor_z1, **monitor_options) monitor1_Hy = meep_utils.AmplitudeMonitorPlane(f, comp=meep.Hy, z_position=model.monitor_z1, **monitor_options) monitor2_Ex = meep_utils.AmplitudeMonitorPlane(f, comp=meep.Ex, z_position=model.monitor_z2, **monitor_options) monitor2_Hy = meep_utils.AmplitudeMonitorPlane(f, comp=meep.Hy, z_position=model.monitor_z2, **monitor_options) slices = [] if not "noepssnapshot" in model.comment: