def get_far_data_from_one(nearfield, nsize): # simulation data are saved in nearfield freqs = mp.get_near2far_freqs(nearfield) r = 1000 * 3.8 # 1000 wavelengths out from the source thetas = np.concatenate( [np.arange(0.5, 20, 1), np.arange(22.5, 89, 3)]) # polar angle phis = [ 45, ] # azimuthal angle data = np.empty(shape=[0, 16]) for phi in phis: for theta in thetas: phi0 = np.radians(phi) theta0 = np.radians(theta) pt = r * mp.Vector3( math.sin(theta0) * math.cos(phi0), math.sin(theta0) * math.sin(phi0), math.cos(theta0)) fields = sim.get_farfield(nearfield, pt) mat = np.vstack((np.real(fields), np.imag(fields))) fields = mat.T.reshape((1, -1)).reshape((-1, 12)) infos = np.vstack( (freqs, nsize * np.ones(len(freqs)), theta * np.ones(len(freqs)), phi * np.ones(len(freqs)))) data = np.vstack((data, np.hstack((infos.T, fields)))) return data
boundary_layers=pml_layers, geometry=geometry, k_point=k_point, sources=sources, symmetries=symmetries) n2f_obj = sim.add_near2far(fcen, df, nfreq, mp.Near2FarRegion(center=n2f_pt, size=mp.Vector3(y=sy-2*dpml))) sim.run(until_after_sources=mp.stop_when_fields_decayed(50, mp.Ez, n2f_pt, 1e-9)) ff_supercell = sim.get_farfields(n2f_obj, ff_res, center=mp.Vector3(ff_distance,0.5*ff_length), size=mp.Vector3(y=ff_length)) norm_err = LA.norm(ff_unitcell['Ez']-ff_supercell['Ez'])/nperiods print("error:, {}, {}".format(nperiods,norm_err)) freqs = mp.get_near2far_freqs(n2f_obj) wvl = np.divide(1,freqs) ff_lengths = np.linspace(0,ff_length,ff_npts) angles = [math.degrees(math.atan(f)) for f in ff_lengths/ff_distance] wvl_slice = 0.5 idx_slice = np.where(np.asarray(freqs) == 1/wvl_slice)[0][0] rel_enh = np.absolute(ff_unitcell['Ez'])**2/np.absolute(ff_source['Ez'])**2 plt.figure(dpi=150) plt.subplot(1,2,1) plt.pcolormesh(wvl,angles,rel_enh,cmap='Blues',shading='flat') plt.axis([wvl_min,wvl_max,0,ff_angle]) plt.xlabel("wavelength (μm)")