Ansys Learning Forum › Forums › Discuss Simulation › Photonics – Chinese › 有限周期光栅的衍射级次和光场分布 › Reply To: 有限周期光栅的衍射级次和光场分布
老师,这个是我构建平顶光束的一个脚本。另外补充一下我们上面的模型的仿真区域大小是50微米*50微米,最大能做到的仿真的光栅区域大小是100微米*100微米,更大的可能要在电脑上重新试一试。
# Clear existing variables
clear;
#switchtolayout;
# Define position vectors for spatial grid
x = linspace(-45e-6, 45e-6, 41); # Updated x range
y = linspace(-45e-6, 45e-6, 41); # Updated y range
z = -0.2e-6; # Set z position to 0.11 micrometers
X = meshgridx(x,y);
Y = meshgridy(x,y);
# Wavelength and wave vector
lambda0 = 0.5e-6;
f = c/lambda0;
k = 2*pi/lambda0;
# Define the flat-top beam profile
w0 = 25e-6; # beam waist
sigma = 0.5e-6; # controls edge smoothness
G = 1.0; # peak amplitude
# Beam envelope: Gaussian edges with a flat top
#envelope = G * exp(-((-(X^2 + Y^2) - w0^2)^2 / (2*sigma^2)));
R =30e-6;#调控平顶的半径
r = (R-sqrt(X^2+Y^2))/lambda0;
n=10;#调控平顶的范围
envelope = ((exp(n*r)-exp(-n*r))/(exp(n*r)+exp(-n*r))+1)/2;
# Define electric field components for radial polarization (as an example)
phi = atan2(Y, X);
Ex = cos(phi) * envelope;
Ey = sin(phi) * envelope;
Ez = 0;
# Package field data into the dataset for Import Source
EM = rectilineardataset("EM fields", x, y, z);
EM.addparameter("lambda", c/f, "f", f);
EM.addattribute("E", Ex, Ey, Ez);
# Save dataset to .mat file
#matlabsave("import_data.mat", EM);
# Load dataset into Import Source
select("import_beam");
importdataset(EM);
set("center wavelength", lambda0);
set("wavelength span", 0);
# Run simulation
#run;
# Visualize the field
#visualize(EM);