########################################################################### # Scriptfile: scalar_pupil_example.lsf # # Description: # This example script file shows how to create a half-circle aperture using # a scalar pupil function. The effect of beam rotations is also shown: the pupil # function is defined in the unrotated reference frame of the beam, and the # rotation is applied afterwards # ########################################################################### clear; closeall; switchtolayout; # Settings: source_name = "source"; T_monitor = "T"; source_theta = 20; # azimuthal angle source_phi = 30; # polar angle NA = 0.2; # maximum NA of the beam n = 501; # number of points in each direction of k-space #Define pupil function: ux = linspace(-NA, NA, n); uy = linspace(-NA, NA, n); Ux = meshgridx(ux, uy); Uy = meshgridy(ux, uy); Rho = sqrt(Ux^2+Uy^2); p = (Rho <= NA); #scalar attribute must be named "p" p = p*(Uy>0); #disable to illuminate full circular aperture pupil = matrixdataset("pupil"); pupil.addparameter("ux",ux); pupil.addparameter("uy",uy); pupil.addattribute("p",p); visualize(pupil); matlabsave("scalar_pupil.mat",pupil); # create matlab file that can be imported in source using GUI # Apply pupil function select("source"); set("angle theta", source_theta); set("angle phi", source_phi); set("use custom pupil function",true); importdataset(pupil); # import directly in source #Run simulation run; # Plot fields recorded by a monitor in front of the source E_forward = getresult(T_monitor,"E"); visualize(E_forward); # Plot farfield: ff = farfield3d(T_monitor); ux_ff = farfieldux(T_monitor); uy_ff = farfielduy(T_monitor); polarimage(ux_ff,uy_ff,ff,"ux","uy","Far field result"); # Far field